5#ifndef V8_TORQUE_DECLARABLE_H_
6#define V8_TORQUE_DECLARABLE_H_
11#include <unordered_map>
23class TypeArgumentInference;
34 name(
std::move(name)) {}
91 virtual const char*
type_name()
const {
return "<<unknown>>"; }
127#define DECLARE_DECLARABLE_BOILERPLATE(x, y) \
128 static x* cast(Declarable* declarable) { \
129 DCHECK(declarable->Is##x()); \
130 return static_cast<x*>(declarable); \
132 static const x* cast(const Declarable* declarable) { \
133 DCHECK(declarable->Is##x()); \
134 return static_cast<const x*>(declarable); \
136 const char* type_name() const override { return #y; } \
137 static x* DynamicCast(Declarable* declarable) { \
138 if (!declarable) return nullptr; \
139 if (!declarable->Is##x()) return nullptr; \
140 return static_cast<x*>(declarable); \
142 static const x* DynamicCast(const Declarable* declarable) { \
143 if (!declarable) return nullptr; \
144 if (!declarable->Is##x()) return nullptr; \
145 return static_cast<const x*>(declarable); \
178 if (!name.HasNamespaceQualification())
return declarations_[name.name];
179 Scope* child =
nullptr;
182 if (
Scope* scope = Scope::DynamicCast(declarable)) {
183 if (child !=
nullptr) {
185 name.namespace_qualification.front());
190 if (child ==
nullptr)
return {};
191 return child->
LookupShallow(name.DropFirstNamespaceQualification());
231 Scope* scope = CurrentScope::Get();
233 if (
Namespace* n = Namespace::DynamicCast(scope)) {
316 std::optional<Statement*>
body()
const {
return body_; }
331 return "TqRuntime" +
name;
338 return "TqDebug" +
name;
354 std::optional<Statement*>
body)
379 if (type->StructSupertype())
return true;
394 std::optional<Statement*>
body)
398 if (
signature.parameter_types.var_args) {
399 ReportError(
"Varargs are not supported for macros.");
456 std::optional<Statement*>
body,
bool is_user_defined,
457 bool exported_to_csa)
468 bool is_user_defined,
bool exported_to_csa)
482 .parameter_types.types[
signature().implicit_count]
520 Builtin(std::string external_name, std::string readable_name,
523 std::optional<Statement*>
body)
554 if (
signature.parameter_types.var_args) {
555 ReportError(
"Varargs are not supported for intrinsics.");
576 const std::vector<const Type*>& types,
577 const std::vector<TypeConstraint>& constraints);
582template <
class SpecializationType,
class DeclarationType>
590 SpecializationType specialization) {
623 DeclarationType generic_declaration)
627 DCHECK(!generic_declaration->generic_parameters.empty());
645 const TypeVector& explicit_specialization_types,
646 const std::vector<std::optional<const Type*>>& arguments);
688 const Type* type,
bool redeclaration,
704 mutable std::optional<const Type*>
type_;
714#undef DECLARE_DECLARABLE_BOILERPLATE
@ kCustomInterfaceDescriptor
bool IsFixedArgsJavaScript() const
bool HasCustomInterfaceDescriptor() const
std::optional< std::string > use_counter_name() const
Builtin(std::string external_name, std::string readable_name, Builtin::Kind kind, Flags flags, const Signature &signature, std::optional< std::string > use_counter_name, std::optional< Statement * > body)
std::optional< std::string > use_counter_name_
bool IsJavaScript() const
bool IsVarArgsJavaScript() const
std::string external_name_
bool HasReturnValue() const
virtual std::string CCDebugName() const
std::optional< Statement * > body_
virtual bool ShouldBeInlined(OutputType output_type) const
Callable(Declarable::Kind kind, std::string external_name, std::string readable_name, Signature signature, std::optional< Statement * > body)
const Signature & signature() const
const NameVector & parameter_names() const
const std::string & ExternalName() const
static std::string PrefixNameForCCOutput(const std::string &name)
std::string readable_name_
bool ShouldGenerateExternalCode(OutputType output_type) const
static std::string PrefixNameForCCDebugOutput(const std::string &name)
const std::string & ReadableName() const
bool IsTransitioning() const
std::optional< Statement * > body() const
virtual std::string CCName() const
SourcePosition identifier_position_
Scope *const parent_scope_
Scope * ParentScope() const
bool IsExternConstant() const
bool IsGenericType() const
bool IsGenericCallable() const
bool IsExternMacro() const
bool IsNamespaceConstant() const
SourcePosition IdentifierPosition() const
virtual ~Declarable()=default
bool IsTorqueMacro() const
void SetIdentifierPosition(const SourcePosition &position)
bool IsUserDefined() const
void SetPosition(const SourcePosition &position)
bool IsRuntimeFunction() const
SourcePosition Position() const
virtual const char * type_name() const
void SetIsUserDefined(bool is_user_defined)
ExternConstant(Identifier *name, const Type *type, std::string value)
std::string CCName() const override
ExternMacro(const std::string &name, std::string external_assembler_name, Signature signature)
std::string CCDebugName() const override
const std::string & external_assembler_name() const
std::string external_assembler_name_
TypeArgumentInference InferSpecializationTypes(const TypeVector &explicit_specialization_types, const std::vector< std::optional< const Type * > > &arguments)
std::optional< Statement * > CallableBody()
GenericCallable(const std::string &name, GenericCallableDeclaration *generic_declaration)
std::optional< std::vector< TypeConstraint > > constraints_
DeclarationType generic_declaration_
void AddSpecialization(const TypeVector &type_arguments, SpecializationType specialization)
const std::string & name() const
GenericDeclarable(Declarable::Kind kind, const std::string &name, DeclarationType generic_declaration)
std::unordered_map< TypeVector, SpecializationType, base::hash< TypeVector > > Map
const std::vector< TypeConstraint > & Constraints()
typename Map::const_iterator iterator
std::optional< SpecializationType > GetSpecialization(const TypeVector &type_arguments) const
const GenericParameters & generic_parameters() const
GenericType(const std::string &name, GenericTypeDeclaration *generic_declaration)
Intrinsic(std::string name, const Signature &signature)
Macro(Declarable::Kind kind, std::string external_name, std::string readable_name, const Signature &signature, std::optional< Statement * > body)
bool ShouldBeInlined(OutputType output_type) const override
bool ShouldBeInlined(OutputType output_type) const override
AggregateType * aggregate_type() const
AggregateType * aggregate_type_
Method(AggregateType *aggregate_type, std::string external_name, std::string readable_name, const Signature &signature, Statement *body)
Expression * body() const
const std::string & external_name() const
NamespaceConstant(Identifier *constant_name, std::string external_name, const Type *type, Expression *body)
std::string external_name_
bool IsDefaultNamespace() const
const std::string & name() const
bool IsTestNamespace() const
RuntimeFunction(const std::string &name, const Signature &signature)
T * AddDeclarable(const std::string &name, T *declarable)
std::unordered_map< std::string, std::vector< Declarable * > > declarations_
std::vector< Declarable * > LookupShallow(const QualifiedName &name)
const SpecializationRequester & GetSpecializationRequester() const
void SetSpecializationRequester(const SpecializationRequester &requester)
SpecializationRequester requester_
std::vector< Declarable * > Lookup(const QualifiedName &name)
std::string CCDebugName() const override
bool IsExportedToCSA() const
TorqueMacro(Declarable::Kind kind, std::string external_name, std::string readable_name, const Signature &signature, std::optional< Statement * > body, bool is_user_defined, bool exported_to_csa)
std::string CCName() const override
TorqueMacro(std::string external_name, std::string readable_name, const Signature &signature, std::optional< Statement * > body, bool is_user_defined, bool exported_to_csa)
std::optional< TypeDeclaration * > delayed_
TypeAlias(TypeDeclaration *type, bool redeclaration, SourcePosition declaration_position=SourcePosition::Invalid())
const Type * Resolve() const
bool IsRedeclaration() const
const SourcePosition declaration_position_
TypeAlias(const Type *type, bool redeclaration, SourcePosition declaration_position=SourcePosition::Invalid())
std::optional< const Type * > type_
SourcePosition GetDeclarationPosition() const
static TypeConstraint SubtypeConstraint(const Type *upper_bound)
std::optional< const Type * > upper_bound
static TypeConstraint Unconstrained()
std::optional< std::string > IsViolated(const Type *) const
const Type * type() const
std::optional< VisitResult > value_
Value(Kind kind, const Type *type, Identifier *name)
VisitResult value() const
void set_value(VisitResult value)
virtual bool IsConst() const
#define DECLARE_CONTEXTUAL_VARIABLE(VarName,...)
#define DECLARE_DECLARABLE_BOILERPLATE(x, y)
ZoneVector< RpoNumber > & result
std::ostream & operator<<(std::ostream &os, Identifier *id)
void ReportError(Args &&... args)
std::vector< GenericParameter > GenericParameters
std::vector< Identifier * > NameVector
std::vector< const Type * > TypeVector
std::optional< std::string > FindConstraintViolation(const std::vector< const Type * > &types, const std::vector< TypeConstraint > &constraints)
Namespace * CurrentNamespace()
std::vector< TypeConstraint > ComputeConstraints(Scope *scope, const GenericParameters ¶meters)
MessageBuilder Error(Args &&... args)
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in name
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)
QualifiedName(std::vector< std::string > namespace_qualification, std::string name)
friend std::ostream & operator<<(std::ostream &os, const QualifiedName &name)
std::vector< std::string > namespace_qualification
QualifiedName DropFirstNamespaceQualification() const
static QualifiedName Parse(std::string qualified_name)
QualifiedName(std::string name)
bool HasNamespaceQualification() const
NameVector parameter_names
static SourcePosition Invalid()
SpecializationRequester(SourcePosition position, Scope *scope, std::string name)
static SpecializationRequester None()