authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-06-17 06:08:37-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-06-18 17:12:56-04:00
log7e443022609e31ff2636d2c43c32f3c5570793d1
treec849830cd2116c009252fb7d4f5112bc5c7c2865
parent81f766eecd98287463888a725c3cc053a132c66e

stage2: explicit hash and equality function for the DeclTable


1 files changed, 12 insertions(+), 2 deletions(-)

src-self-hosted/Module.zig+12-2
......@@ -37,7 +37,7 @@ decl_exports: std.AutoHashMap(*Decl, []*Export),
3737/// This table owns the Export memory.
3838export_owners: std.AutoHashMap(*Decl, []*Export),
3939/// Maps fully qualified namespaced names to the Decl struct for them.
40decl_table: std.AutoHashMap(Scope.NameHash, *Decl),
40decl_table: DeclTable,
4141
4242optimize_mode: std.builtin.Mode,
4343link_error_flags: link.ElfFile.ErrorFlags = .{},
......@@ -66,6 +66,8 @@ generation: u32 = 0,
6666/// contains Decls that need to be deleted if they end up having no references to them.
6767deletion_set: std.ArrayListUnmanaged(*Decl) = .{},
6868
69const DeclTable = std.HashMap(Scope.NameHash, *Decl, Scope.name_hash_hash, Scope.name_hash_eql);
70
6971const WorkItem = union(enum) {
7072 /// Write the machine code for a Decl to the output file.
7173 codegen_decl: *Decl,
......@@ -417,6 +419,14 @@ pub const Scope = struct {
417419 }
418420 }
419421
422 fn name_hash_hash(x: NameHash) u32 {
423 return @truncate(u32, @bitCast(u128, x));
424 }
425
426 fn name_hash_eql(a: NameHash, b: NameHash) bool {
427 return @bitCast(u128, a) == @bitCast(u128, b);
428 }
429
420430 pub const Tag = enum {
421431 /// .zir source code.
422432 zir_module,
......@@ -711,7 +721,7 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module {
711721 .bin_file_path = options.bin_file_path,
712722 .bin_file = bin_file,
713723 .optimize_mode = options.optimize_mode,
714 .decl_table = std.AutoHashMap(Scope.NameHash, *Decl).init(gpa),
724 .decl_table = DeclTable.init(gpa),
715725 .decl_exports = std.AutoHashMap(*Decl, []*Export).init(gpa),
716726 .export_owners = std.AutoHashMap(*Decl, []*Export).init(gpa),
717727 .failed_decls = std.AutoHashMap(*Decl, *ErrorMsg).init(gpa),