18std::vector<T> EnsureNonempty(std::vector<T> list,
const std::string& name,
23 return std::move(list);
26template <
class T,
class Name>
27T EnsureUnique(
const std::vector<T>& list,
const Name& name,
const char*
kind) {
31 if (list.size() >= 2) {
38void CheckAlreadyDeclared(
const std::string& name,
const char* new_type) {
39 std::vector<T*> declarations =
41 if (!declarations.empty()) {
42 Scope* scope = CurrentScope::Get();
43 ReportError(
"cannot redeclare ", name,
" (type ", *new_type, scope,
")");
51 std::vector<Declarable*> d =
55 s <<
"cannot find \"" << name <<
"\" in global scope";
83 if (decls.empty())
return std::nullopt;
84 return EnsureUnique(std::move(decls), name,
"type")->type();
96 if (
Builtin* builtin = Builtin::DynamicCast(declarable.get())) {
98 builtin->signature().return_type == type->return_type() &&
99 builtin->signature().parameter_types.types ==
100 type->parameter_types()) {
115 for (
auto&
m : macros) {
116 auto signature_types =
m->signature().GetExplicitTypes();
117 if (signature_types == types && !
m->signature().parameter_types.var_args) {
127 if (builtins.empty())
return std::nullopt;
128 return EnsureUnique(builtins, name.name,
"builtin");
132 const std::string& name) {
133 return EnsureNonempty(
149 const std::string& name) {
152 name,
"generic type");
158 if (results.empty())
return std::nullopt;
159 return EnsureUnique(results, name.name,
"generic type");
163 return Declare(name, std::make_unique<Namespace>(name));
167 CheckAlreadyDeclared<TypeAlias>(name->value,
"type");
168 return Declare(name->value, std::unique_ptr<TypeAlias>(
174 bool redeclaration) {
175 CheckAlreadyDeclared<TypeAlias>(name->value,
"type");
176 std::unique_ptr<TypeAlias> alias_ptr(
177 new TypeAlias(type, redeclaration, name->pos));
178 return Declare(name->value, std::move(alias_ptr));
182 std::string external_name, std::string readable_name,
bool exported_to_csa,
183 Signature signature, std::optional<Statement*> body,
bool is_user_defined) {
186 std::move(external_name), std::move(readable_name), std::move(signature),
187 body, is_user_defined, exported_to_csa)));
191 std::string name, std::string external_assembler_name,
194 new ExternMacro(std::move(name), std::move(external_assembler_name),
195 std::move(signature))));
199 const std::string& name,
bool accessible_from_csa,
200 std::optional<std::string> external_assembler_name,
201 const Signature& signature, std::optional<Statement*> body,
202 std::optional<std::string> op,
bool is_user_defined) {
203 if (
Macro* existing_macro =
205 if (existing_macro->ParentScope() == CurrentScope::Get()) {
207 " with identical explicit parameters");
211 if (external_assembler_name) {
223 " with identical explicit parameters");
231 const std::string& name,
Signature signature,
234 "Method_" + container_type->
SimpleName() +
"_" + name);
236 container_type, generated_name, name, std::move(signature), body)));
244 new Intrinsic(std::move(name), std::move(signature))));
258 std::optional<std::string> use_counter_name,
259 std::optional<Statement*> body) {
261 std::move(external_name), std::move(readable_name),
kind, flags,
262 std::move(signature), std::move(use_counter_name), body)));
266 const std::string& name,
const Signature& signature) {
267 CheckAlreadyDeclared<RuntimeFunction>(name,
"runtime function");
275 CheckAlreadyDeclared<Value>(name->value,
"constant");
276 return Declare(name->value, std::unique_ptr<ExternConstant>(
283 CheckAlreadyDeclared<Value>(name->value,
"constant");
285 std::unique_ptr<NamespaceConstant> namespaceConstant(
288 Declare(name->value, std::move(namespaceConstant));
294 return Declare(name, std::unique_ptr<GenericCallable>(
301 std::unique_ptr<GenericType>(
new GenericType(name, ast_node)));
305 const std::string& name,
const TypeVector& specialized_types) {
307 for (
auto type : specialized_types) {
308 result +=
"_" + type->SimpleName();
void RegisterMethod(Method *method)
static Value * LookupValue(const QualifiedName &name)
static std::optional< Builtin * > TryLookupBuiltin(const QualifiedName &name)
static Intrinsic * CreateIntrinsic(const std::string &name, const Signature &signature)
static TypeAlias * DeclareType(const Identifier *name, const Type *type)
static TorqueMacro * CreateTorqueMacro(std::string external_name, std::string readable_name, bool exported_to_csa, Signature signature, std::optional< Statement * > body, bool is_user_defined)
static Macro * TryLookupMacro(const std::string &name, const TypeVector &types)
static std::vector< Declarable * > LookupGlobalScope(const QualifiedName &name)
static T * Declare(const std::string &name, T *d)
static Macro * DeclareMacro(const std::string &name, bool accessible_from_csa, std::optional< std::string > external_assembler_name, const Signature &signature, std::optional< Statement * > body, std::optional< std::string > op={}, bool is_user_defined=true)
static std::vector< Declarable * > TryLookupShallow(const QualifiedName &name)
static ExternConstant * DeclareExternConstant(Identifier *name, const Type *type, std::string value)
static Builtin * CreateBuiltin(std::string external_name, std::string readable_name, Builtin::Kind kind, Builtin::Flags flags, Signature signature, std::optional< std::string > use_counter_name, std::optional< Statement * > body)
static Namespace * DeclareNamespace(const std::string &name)
static Method * CreateMethod(AggregateType *class_type, const std::string &name, Signature signature, Statement *body)
static std::vector< GenericCallable * > LookupGeneric(const std::string &name)
static RuntimeFunction * DeclareRuntimeFunction(const std::string &name, const Signature &signature)
static ExternMacro * CreateExternMacro(std::string name, std::string external_assembler_name, Signature signature)
static std::vector< Declarable * > TryLookup(const QualifiedName &name)
static GenericCallable * LookupUniqueGeneric(const QualifiedName &name)
static Intrinsic * DeclareIntrinsic(const std::string &name, const Signature &signature)
static GenericCallable * DeclareGenericCallable(const std::string &name, GenericCallableDeclaration *ast_node)
static const Type * LookupGlobalType(const QualifiedName &name)
static std::string GetGeneratedCallableName(const std::string &name, const TypeVector &specialized_types)
static const TypeAlias * LookupTypeAlias(const QualifiedName &name)
static Macro * DeclareOperator(const std::string &name, Macro *m)
static GenericType * LookupGlobalUniqueGenericType(const std::string &name)
static const Type * LookupType(const QualifiedName &name)
static NamespaceConstant * DeclareNamespaceConstant(Identifier *name, const Type *type, Expression *body)
static Builtin * FindSomeInternalBuiltinWithType(const BuiltinPointerType *type)
static TypeAlias * PredeclareTypeAlias(const Identifier *name, TypeDeclaration *type, bool redeclaration)
static GenericType * LookupUniqueGenericType(const QualifiedName &name)
static std::vector< Declarable * > Lookup(const QualifiedName &name)
static std::optional< GenericType * > TryLookupGenericType(const QualifiedName &name)
static GenericType * DeclareGenericType(const std::string &name, GenericTypeDeclaration *ast_node)
static std::optional< const Type * > TryLookupType(const QualifiedName &name)
static const std::vector< std::unique_ptr< Declarable > > & AllDeclarables()
static Namespace * GetDefaultNamespace()
static bool collect_language_server_data()
static std::string MakeUniqueName(const std::string &base)
static V8_EXPORT_PRIVATE void AddDefinition(SourcePosition token, SourcePosition definition)
T * AddDeclarable(const std::string &name, T *declarable)
std::vector< Declarable * > Lookup(const QualifiedName &name)
const Type * type() const
SourcePosition GetDeclarationPosition() const
virtual std::string SimpleName() const
ZoneVector< RpoNumber > & result
T * RegisterDeclarable(std::unique_ptr< T > d)
void ReportError(Args &&... args)
std::vector< T * > FilterDeclarables(const std::vector< Declarable * > list)
std::vector< const Type * > TypeVector
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
TypeVector GetExplicitTypes() const