From 105efe1fe2de1cff24664e7ea1f2c6e81d076c60 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Mon, 23 Oct 2023 20:51:54 +0200 Subject: [PATCH] take InternPool in `DeclStringAdapter` and `DeclContext` --- src/analyser/Module.zig | 16 ++++++++-------- src/analyser/Sema.zig | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/analyser/Module.zig b/src/analyser/Module.zig index a2f669a4d..4f01cef94 100644 --- a/src/analyser/Module.zig +++ b/src/analyser/Module.zig @@ -59,35 +59,35 @@ pub const Namespace = struct { usingnamespace_set: std.AutoHashMapUnmanaged(Decl.Index, bool) = .{}, pub const DeclStringAdapter = struct { - mod: *Module, + ip: *InternPool, pub fn hash(self: @This(), s: InternPool.StringPool.String) u32 { var hasher = std.hash.Wyhash.init(0); - self.mod.ip.string_pool.hashString(&hasher, s); + self.ip.string_pool.hashString(&hasher, s); return @truncate(hasher.final()); } pub fn eql(self: @This(), a: InternPool.StringPool.String, b_decl_index: Decl.Index, b_index: usize) bool { _ = b_index; - const b_decl = self.mod.declPtr(b_decl_index); + const b_decl = self.ip.getDecl(b_decl_index); return a == b_decl.name; } }; pub const DeclContext = struct { - mod: *Module, + ip: *InternPool, pub fn hash(ctx: @This(), decl_index: Decl.Index) u32 { - const name_index = ctx.mod.ip.getDecl(decl_index).name; + const name_index = ctx.ip.getDecl(decl_index).name; var hasher = std.hash.Wyhash.init(0); - ctx.mod.ip.string_pool.hashString(&hasher, name_index); + ctx.ip.string_pool.hashString(&hasher, name_index); return @truncate(hasher.final()); } pub fn eql(ctx: @This(), a_decl_index: Decl.Index, b_decl_index: Decl.Index, b_index: usize) bool { _ = b_index; - const a_decl_name_index = ctx.mod.ip.getDecl(a_decl_index).name; - const b_decl_name_index = ctx.mod.ip.getDecl(b_decl_index).name; + const a_decl_name_index = ctx.ip.getDecl(a_decl_index).name; + const b_decl_name_index = ctx.ip.getDecl(b_decl_index).name; return a_decl_name_index == b_decl_name_index; } }; diff --git a/src/analyser/Sema.zig b/src/analyser/Sema.zig index d2dac9bcb..27322457d 100644 --- a/src/analyser/Sema.zig +++ b/src/analyser/Sema.zig @@ -1289,11 +1289,11 @@ fn lookupInNamespace( namespace: *Namespace, ident_name: []const u8, ) Allocator.Error!LookupResult { - const mod = sema.mod; + const ip = sema.mod.ip; _ = block; - const ident_name_index = sema.mod.ip.string_pool.getString(ident_name) orelse return .missing; - if (namespace.decls.getKeyAdapted(ident_name_index, Namespace.DeclStringAdapter{ .mod = mod })) |decl_index| { + const ident_name_index = ip.string_pool.getString(ident_name) orelse return .missing; + if (namespace.decls.getKeyAdapted(ident_name_index, Namespace.DeclStringAdapter{ .ip = ip })) |decl_index| { return .{ .found = decl_index }; } @@ -2396,7 +2396,7 @@ pub fn scanNamespace( const zir = namespace.handle.getCachedZir(); try namespace.decls.ensureTotalCapacityContext(sema.gpa, decls_len, Namespace.DeclContext{ - .mod = sema.mod, + .ip = sema.mod.ip, }); const bit_bags_count = std.math.divCeil(u32, decls_len, 8) catch unreachable; @@ -2505,14 +2505,14 @@ fn scanDecl(sema: *Sema, iter: *ScanDeclIter, decl_sub_index: u32, flags: u4) Al const is_exported = export_bit and decl_name_index != 0; if (kind == .@"usingnamespace") try namespace.usingnamespace_set.ensureUnusedCapacity(gpa, 1); - const decl_name_string_index = try mod.ip.string_pool.getOrPutString(mod.gpa, decl_name); + const decl_name_string_index = try mod.ip.string_pool.getOrPutString(gpa, decl_name); // We create a Decl for it regardless of analysis status. const gop = try namespace.decls.getOrPutContextAdapted( gpa, decl_name_string_index, - Namespace.DeclStringAdapter{ .mod = mod }, - Namespace.DeclContext{ .mod = mod }, + Namespace.DeclStringAdapter{ .ip = mod.ip }, + Namespace.DeclContext{ .ip = mod.ip }, ); if (!gop.found_existing) {