Begin interning ScopeMap strings

This commit is contained in:
gingerBill
2026-03-17 11:04:32 +00:00
parent d5a78a9cf1
commit 04cb889aed
18 changed files with 277 additions and 212 deletions

View File

@@ -183,11 +183,11 @@ gb_internal void populate_check_did_you_mean_objc_entity(StringSet *set, Entity
if (is_type) {
for (auto const &entry : objc_metadata->type_entries) {
string_set_add(set, entry.name);
string_set_add(set, entry.interned.string());
}
} else {
for (auto const &entry : objc_metadata->value_entries) {
string_set_add(set, entry.name);
string_set_add(set, entry.interned.string());
}
}
@@ -1329,7 +1329,7 @@ gb_internal bool polymorphic_assign_index(Type **gt_, i64 *dst_count, i64 source
Type *gt = *gt_;
GB_ASSERT(gt->kind == Type_Generic);
Entity *e = scope_lookup(gt->Generic.scope, gt->Generic.name);
Entity *e = scope_lookup(gt->Generic.scope, gt->Generic.interned_name);
GB_ASSERT(e != nullptr);
if (e->kind == Entity_TypeName) {
*gt_ = nullptr;
@@ -1430,7 +1430,7 @@ gb_internal bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, T
if (poly->Array.generic_count != nullptr) {
Type *gt = poly->Array.generic_count;
GB_ASSERT(gt->kind == Type_Generic);
Entity *e = scope_lookup(gt->Generic.scope, gt->Generic.name);
Entity *e = scope_lookup(gt->Generic.scope, gt->Generic.interned_name);
GB_ASSERT(e != nullptr);
if (e->kind == Entity_TypeName) {
Type *index = source->EnumeratedArray.index;
@@ -1770,9 +1770,9 @@ gb_internal Entity *check_ident(CheckerContext *c, Operand *o, Ast *n, Type *nam
GB_ASSERT(n->kind == Ast_Ident);
o->mode = Addressing_Invalid;
o->expr = n;
String name = n->Ident.token.string;
auto name = n->Ident.token.string;
Entity *e = scope_lookup(c->scope, name, n->Ident.hash);
Entity *e = scope_lookup(c->scope, n->Ident.interned);
if (e == nullptr) {
if (is_blank_ident(name)) {
error(n, "'_' cannot be used as a value");
@@ -5192,7 +5192,7 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v
continue;
}
ast_node(fv, FieldValue, elem);
String name = fv->field->Ident.token.string;
auto name = fv->field->Ident.interned;
Selection sub_sel = lookup_field(node->tav.type, name, false);
if (sub_sel.index.count > 0 &&
sub_sel.index[0] == index) {
@@ -5459,7 +5459,7 @@ gb_internal Entity *check_entity_from_ident_or_selector(CheckerContext *c, Ast *
}
} else */if (node->kind == Ast_Ident) {
String name = node->Ident.token.string;
return scope_lookup(c->scope, name, node->Ident.hash);
return scope_lookup(c->scope, node->Ident.interned);
} else if (!ident_only) if (node->kind == Ast_SelectorExpr) {
ast_node(se, SelectorExpr, node);
if (se->token.kind == Token_ArrowRight) {
@@ -5481,7 +5481,7 @@ gb_internal Entity *check_entity_from_ident_or_selector(CheckerContext *c, Ast *
if (op_expr->kind == Ast_Ident) {
String op_name = op_expr->Ident.token.string;
Entity *e = scope_lookup(c->scope, op_name, op_expr->Ident.hash);
Entity *e = scope_lookup(c->scope,op_expr->Ident.interned);
if (e == nullptr) {
return nullptr;
}
@@ -5494,7 +5494,7 @@ gb_internal Entity *check_entity_from_ident_or_selector(CheckerContext *c, Ast *
// If you can clean this up, please do but be really careful
String import_name = op_name;
Scope *import_scope = e->ImportName.scope;
String entity_name = selector->Ident.token.string;
auto entity_name = selector->Ident.interned;
check_op_expr = false;
entity = scope_lookup_current(import_scope, entity_name);
@@ -5520,7 +5520,7 @@ gb_internal Entity *check_entity_from_ident_or_selector(CheckerContext *c, Ast *
}
if (entity == nullptr && selector->kind == Ast_Ident) {
String field_name = selector->Ident.token.string;
auto field_name = selector->Ident.interned;
if (is_type_dynamic_array(type_deref(operand.type))) {
init_mem_allocator(c->checker);
}
@@ -5578,7 +5578,7 @@ gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *nod
if (op_expr->kind == Ast_Ident) {
String op_name = op_expr->Ident.token.string;
Entity *e = scope_lookup(c->scope, op_name, op_expr->Ident.hash);
Entity *e = scope_lookup(c->scope, op_expr->Ident.interned);
add_entity_use(c, op_expr, e);
expr_entity = e;
@@ -5596,6 +5596,7 @@ gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *nod
String import_name = op_name;
Scope *import_scope = e->ImportName.scope;
String entity_name = selector->Ident.token.string;
InternedString entity_name_interned = selector->Ident.interned;
if (import_scope == nullptr) {
ERROR_BLOCK();
@@ -5606,7 +5607,7 @@ gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *nod
}
check_op_expr = false;
entity = scope_lookup_current(import_scope, entity_name);
entity = scope_lookup_current(import_scope, entity_name_interned);
bool allow_builtin = false;
if (!is_entity_declared_for_selector(entity, import_scope, &allow_builtin)) {
ERROR_BLOCK();
@@ -5654,7 +5655,7 @@ gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *nod
}
if (entity == nullptr && selector->kind == Ast_Ident) {
String field_name = selector->Ident.token.string;
auto field_name = selector->Ident.interned;
Type *t = type_deref(operand->type);
if (t == nullptr) {
error(operand->expr, "Cannot use a selector expression on 0-value expression");
@@ -5993,15 +5994,14 @@ gb_internal bool is_type_valid_atomic_type(Type *elem) {
gb_internal bool check_identifier_exists(Scope *s, Ast *node, bool nested = false, Scope **out_scope = nullptr) {
switch (node->kind) {
case_ast_node(i, Ident, node);
String name = i->token.string;
if (nested) {
Entity *e = scope_lookup_current(s, name);
Entity *e = scope_lookup_current(s, i->interned, i->hash);
if (e != nullptr) {
if (out_scope) *out_scope = e->scope;
return true;
}
} else {
Entity *e = scope_lookup(s, name, i->hash);
Entity *e = scope_lookup(s, i->interned);
if (e != nullptr) {
if (out_scope) *out_scope = e->scope;
return true;
@@ -8972,7 +8972,7 @@ gb_internal bool attempt_implicit_selector_expr(CheckerContext *c, Operand *o, A
Type *enum_type = base_type(th);
GB_ASSERT(enum_type->kind == Type_Enum);
String name = ise->selector->Ident.token.string;
auto name = ise->selector->Ident.interned;
Entity *e = scope_lookup_current(enum_type->Enum.scope, name);
if (e == nullptr) {
@@ -9907,8 +9907,9 @@ gb_internal void check_compound_literal_field_values(CheckerContext *c, Slice<As
continue;
}
String name = ident->Ident.token.string;
auto interned = ident->Ident.interned;
Selection sel = lookup_field(type, name, o->mode == Addressing_Type);
Selection sel = lookup_field(type, interned, o->mode == Addressing_Type);
bool is_unknown = sel.entity == nullptr;
if (is_unknown) {
error(ident, "Unknown field '%.*s' in structure literal", LIT(name));
@@ -10863,8 +10864,9 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
continue;
}
String name = fv->field->Ident.token.string;
auto interned = fv->field->Ident.interned;
Selection sel = lookup_field(type, name, o->mode == Addressing_Type);
Selection sel = lookup_field(type, interned, o->mode == Addressing_Type);
if (sel.entity == nullptr) {
error(elem, "Unknown field '%.*s' in 'any' literal", LIT(name));
continue;