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),...@@ -37,7 +37,7 @@ decl_exports: std.AutoHashMap(*Decl, []*Export),
37/// This table owns the Export memory.37/// This table owns the Export memory.
38export_owners: std.AutoHashMap(*Decl, []*Export),38export_owners: std.AutoHashMap(*Decl, []*Export),
39/// Maps fully qualified namespaced names to the Decl struct for them.39/// Maps fully qualified namespaced names to the Decl struct for them.
40decl_table: std.AutoHashMap(Scope.NameHash, *Decl),40decl_table: DeclTable,
4141
42optimize_mode: std.builtin.Mode,42optimize_mode: std.builtin.Mode,
43link_error_flags: link.ElfFile.ErrorFlags = .{},43link_error_flags: link.ElfFile.ErrorFlags = .{},
...@@ -66,6 +66,8 @@ generation: u32 = 0,...@@ -66,6 +66,8 @@ generation: u32 = 0,
66/// contains Decls that need to be deleted if they end up having no references to them.66/// contains Decls that need to be deleted if they end up having no references to them.
67deletion_set: std.ArrayListUnmanaged(*Decl) = .{},67deletion_set: std.ArrayListUnmanaged(*Decl) = .{},
6868
69const DeclTable = std.HashMap(Scope.NameHash, *Decl, Scope.name_hash_hash, Scope.name_hash_eql);
70
69const WorkItem = union(enum) {71const WorkItem = union(enum) {
70 /// Write the machine code for a Decl to the output file.72 /// Write the machine code for a Decl to the output file.
71 codegen_decl: *Decl,73 codegen_decl: *Decl,
...@@ -417,6 +419,14 @@ pub const Scope = struct {...@@ -417,6 +419,14 @@ pub const Scope = struct {
417 }419 }
418 }420 }
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
420 pub const Tag = enum {430 pub const Tag = enum {
421 /// .zir source code.431 /// .zir source code.
422 zir_module,432 zir_module,
...@@ -711,7 +721,7 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module {...@@ -711,7 +721,7 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module {
711 .bin_file_path = options.bin_file_path,721 .bin_file_path = options.bin_file_path,
712 .bin_file = bin_file,722 .bin_file = bin_file,
713 .optimize_mode = options.optimize_mode,723 .optimize_mode = options.optimize_mode,
714 .decl_table = std.AutoHashMap(Scope.NameHash, *Decl).init(gpa),724 .decl_table = DeclTable.init(gpa),
715 .decl_exports = std.AutoHashMap(*Decl, []*Export).init(gpa),725 .decl_exports = std.AutoHashMap(*Decl, []*Export).init(gpa),
716 .export_owners = std.AutoHashMap(*Decl, []*Export).init(gpa),726 .export_owners = std.AutoHashMap(*Decl, []*Export).init(gpa),
717 .failed_decls = std.AutoHashMap(*Decl, *ErrorMsg).init(gpa),727 .failed_decls = std.AutoHashMap(*Decl, *ErrorMsg).init(gpa),