Skip to content

Commit

Permalink
take InternPool in DeclStringAdapter and DeclContext
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed Nov 8, 2023
1 parent 8078387 commit 105efe1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/analyser/Module.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down
14 changes: 7 additions & 7 deletions src/analyser/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 105efe1

Please sign in to comment.