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

@@ -484,7 +484,7 @@ gb_internal Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, O
}
if (ident_node != nullptr) {
ast_node(i, Ident, ident_node);
e = scope_lookup(ctx->scope, i->token.string, i->hash);
e = scope_lookup(ctx->scope, i->interned, i->hash);
if (e != nullptr && e->kind == Entity_Variable) {
used = (e->flags & EntityFlag_Used) != 0; // NOTE(bill): Make backup just in case
}
@@ -791,10 +791,10 @@ gb_internal bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us,
for (auto const &entry : scope->elements) {
Entity *decl = entry.value;
if (!is_entity_exported(decl, true)) continue;
String name = scope->elements.keys[entry.hash & (scope->elements.cap-1)];
u32 hash = entry.hash;
auto interned = scope->elements.keys[hash & (scope->elements.cap-1)];
Entity *found = scope_insert_with_name(ctx->scope, name, hash, decl);
Entity *found = scope_insert_with_name(ctx->scope, interned, hash, decl);
if (found != nullptr) {
gbString expr_str = expr_to_string(expr);
error(us->token,
@@ -1067,7 +1067,7 @@ gb_internal void check_unroll_range_stmt(CheckerContext *ctx, Ast *node, u32 mod
Entity *found = nullptr;
if (!is_blank_ident(str)) {
found = scope_lookup_current(ctx->scope, str);
found = scope_lookup_current(ctx->scope, name->Ident.interned, name->Ident.hash);
}
if (found == nullptr) {
entity = alloc_entity_variable(ctx->scope, token, type, EntityState_Resolved);
@@ -1836,10 +1836,10 @@ gb_internal void check_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags)
}
if (rs->vals.count == 1 && rs->vals[0] && rs->vals[0]->kind == Ast_Ident) {
AstIdent *ident = &rs->vals[0]->Ident;
String name = ident->token.string;
Entity *found = scope_lookup(ctx->scope, name, ident->hash);
Entity *found = scope_lookup(ctx->scope, ident->interned, ident->hash);
if (found && are_types_identical(found->type, t->BitSet.elem)) {
ERROR_BLOCK();
String name = ident->token.string;
gbString s = expr_to_string(expr);
error(rs->vals[0], "'%.*s' shadows a previous declaration which might be ambiguous with 'for (%.*s in %s)'", LIT(name), LIT(name), s);
error_line("\tSuggestion: Use a different identifier if iteration is wanted, or surround in parentheses if a normal for loop is wanted\n");
@@ -1888,10 +1888,10 @@ gb_internal void check_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags)
}
if (rs->vals.count == 1 && rs->vals[0] && rs->vals[0]->kind == Ast_Ident) {
AstIdent *ident = &rs->vals[0]->Ident;
String name = ident->token.string;
Entity *found = scope_lookup(ctx->scope, name, ident->hash);
Entity *found = scope_lookup(ctx->scope, ident->interned, ident->hash);
if (found && are_types_identical(found->type, t->Map.key)) {
ERROR_BLOCK();
String name = ident->token.string;
gbString s = expr_to_string(expr);
error(rs->vals[0], "'%.*s' shadows a previous declaration which might be ambiguous with 'for (%.*s in %s)'", LIT(name), LIT(name), s);
error_line("\tSuggestion: Use a different identifier if iteration is wanted, or surround in parentheses if a normal for loop is wanted\n");
@@ -2032,7 +2032,7 @@ gb_internal void check_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags)
Entity *found = nullptr;
if (!is_blank_ident(str)) {
found = scope_lookup_current(ctx->scope, str);
found = scope_lookup_current(ctx->scope, name->Ident.interned, name->Ident.hash);
}
if (found == nullptr) {
entity = alloc_entity_variable(ctx->scope, token, type, EntityState_Resolved);
@@ -2126,7 +2126,7 @@ gb_internal void check_value_decl_stmt(CheckerContext *ctx, Ast *node, u32 mod_f
Entity *found = nullptr;
// NOTE(bill): Ignore assignments to '_'
if (!is_blank_ident(str)) {
found = scope_lookup_current(ctx->scope, str);
found = scope_lookup_current(ctx->scope, name->Ident.interned, name->Ident.hash);
new_name_count += 1;
}
if (found == nullptr) {