| author | |
| committer | |
| log | 28dd9d478d24190ab5c8c4b892d7dfc16c380ae0 |
| tree | f717633b02bdd9cf1c7bc724908e8d19ef097981 |
| parent | 03156e589939993bba339162d27d24fd511601c6 |
The C backend depends on insertion order into this map so that type
definitions will be declared before they are used.5 files changed, 22 insertions(+), 14 deletions(-)
src/codegen/c.zig+3-3| ... | ... | @@ -39,11 +39,11 @@ const BlockData = struct { |
| 39 | 39 | }; |
| 40 | 40 | |
| 41 | 41 | pub const CValueMap = std.AutoHashMap(*Inst, CValue); |
| 42 | pub const TypedefMap = std.HashMap( | |
| 42 | pub const TypedefMap = std.ArrayHashMap( | |
| 43 | 43 | Type, |
| 44 | 44 | struct { name: []const u8, rendered: []u8 }, |
| 45 | Type.HashContext, | |
| 46 | std.hash_map.default_max_load_percentage, | |
| 45 | Type.HashContext32, | |
| 46 | true, | |
| 47 | 47 | ); |
| 48 | 48 | |
| 49 | 49 | fn formatTypeAsCIdentifier( |
src/codegen/spirv.zig+1-1| ... | ... | @@ -18,7 +18,7 @@ const Inst = ir.Inst; |
| 18 | 18 | pub const Word = u32; |
| 19 | 19 | pub const ResultId = u32; |
| 20 | 20 | |
| 21 | pub const TypeMap = std.HashMap(Type, u32, Type.HashContext, std.hash_map.default_max_load_percentage); | |
| 21 | pub const TypeMap = std.HashMap(Type, u32, Type.HashContext64, std.hash_map.default_max_load_percentage); | |
| 22 | 22 | pub const InstMap = std.AutoHashMap(*Inst, ResultId); |
| 23 | 23 | |
| 24 | 24 | const IncomingBlock = struct { |
src/link.zig+1-1| ... | ... | @@ -168,7 +168,7 @@ pub const File = struct { |
| 168 | 168 | }; |
| 169 | 169 | |
| 170 | 170 | /// For DWARF .debug_info. |
| 171 | pub const DbgInfoTypeRelocsTable = std.HashMapUnmanaged(Type, DbgInfoTypeReloc, Type.HashContext, std.hash_map.default_max_load_percentage); | |
| 171 | pub const DbgInfoTypeRelocsTable = std.HashMapUnmanaged(Type, DbgInfoTypeReloc, Type.HashContext64, std.hash_map.default_max_load_percentage); | |
| 172 | 172 | |
| 173 | 173 | /// For DWARF .debug_info. |
| 174 | 174 | pub const DbgInfoTypeReloc = struct { |
src/link/C.zig+5-8| ... | ... | @@ -89,8 +89,7 @@ pub fn freeDecl(self: *C, decl: *Module.Decl) void { |
| 89 | 89 | fn deinitDecl(gpa: *Allocator, decl: *Module.Decl) void { |
| 90 | 90 | decl.link.c.code.deinit(gpa); |
| 91 | 91 | decl.fn_link.c.fwd_decl.deinit(gpa); |
| 92 | var it = decl.fn_link.c.typedefs.valueIterator(); | |
| 93 | while (it.next()) |value| { | |
| 92 | for (decl.fn_link.c.typedefs.values()) |value| { | |
| 94 | 93 | gpa.free(value.rendered); |
| 95 | 94 | } |
| 96 | 95 | decl.fn_link.c.typedefs.deinit(gpa); |
| ... | ... | @@ -108,8 +107,7 @@ pub fn updateDecl(self: *C, module: *Module, decl: *Module.Decl) !void { |
| 108 | 107 | const code = &decl.link.c.code; |
| 109 | 108 | fwd_decl.shrinkRetainingCapacity(0); |
| 110 | 109 | { |
| 111 | var it = typedefs.valueIterator(); | |
| 112 | while (it.next()) |value| { | |
| 110 | for (typedefs.values()) |value| { | |
| 113 | 111 | module.gpa.free(value.rendered); |
| 114 | 112 | } |
| 115 | 113 | } |
| ... | ... | @@ -135,8 +133,7 @@ pub fn updateDecl(self: *C, module: *Module, decl: *Module.Decl) !void { |
| 135 | 133 | object.blocks.deinit(module.gpa); |
| 136 | 134 | object.code.deinit(); |
| 137 | 135 | object.dg.fwd_decl.deinit(); |
| 138 | var it = object.dg.typedefs.valueIterator(); | |
| 139 | while (it.next()) |value| { | |
| 136 | for (object.dg.typedefs.values()) |value| { | |
| 140 | 137 | module.gpa.free(value.rendered); |
| 141 | 138 | } |
| 142 | 139 | object.dg.typedefs.deinit(); |
| ... | ... | @@ -207,7 +204,7 @@ pub fn flushModule(self: *C, comp: *Compilation) !void { |
| 207 | 204 | } |
| 208 | 205 | |
| 209 | 206 | var fn_count: usize = 0; |
| 210 | var typedefs = std.HashMap(Type, void, Type.HashContext, std.hash_map.default_max_load_percentage).init(comp.gpa); | |
| 207 | var typedefs = std.HashMap(Type, void, Type.HashContext64, std.hash_map.default_max_load_percentage).init(comp.gpa); | |
| 211 | 208 | defer typedefs.deinit(); |
| 212 | 209 | |
| 213 | 210 | // Typedefs, forward decls and non-functions first. |
| ... | ... | @@ -217,7 +214,7 @@ pub fn flushModule(self: *C, comp: *Compilation) !void { |
| 217 | 214 | if (!decl.has_tv) continue; |
| 218 | 215 | const buf = buf: { |
| 219 | 216 | if (decl.val.castTag(.function)) |_| { |
| 220 | try typedefs.ensureUnusedCapacity(decl.fn_link.c.typedefs.count()); | |
| 217 | try typedefs.ensureUnusedCapacity(@intCast(u32, decl.fn_link.c.typedefs.count())); | |
| 221 | 218 | var it = decl.fn_link.c.typedefs.iterator(); |
| 222 | 219 | while (it.next()) |new| { |
| 223 | 220 | const gop = typedefs.getOrPutAssumeCapacity(new.key_ptr.*); |
src/type.zig+12-1| ... | ... | @@ -602,7 +602,7 @@ pub const Type = extern union { |
| 602 | 602 | return hasher.final(); |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | pub const HashContext = struct { | |
| 605 | pub const HashContext64 = struct { | |
| 606 | 606 | pub fn hash(self: @This(), t: Type) u64 { |
| 607 | 607 | _ = self; |
| 608 | 608 | return t.hash(); |
| ... | ... | @@ -613,6 +613,17 @@ pub const Type = extern union { |
| 613 | 613 | } |
| 614 | 614 | }; |
| 615 | 615 | |
| 616 | pub const HashContext32 = struct { | |
| 617 | pub fn hash(self: @This(), t: Type) u32 { | |
| 618 | _ = self; | |
| 619 | return @truncate(u32, t.hash()); | |
| 620 | } | |
| 621 | pub fn eql(self: @This(), a: Type, b: Type) bool { | |
| 622 | _ = self; | |
| 623 | return a.eql(b); | |
| 624 | } | |
| 625 | }; | |
| 626 | ||
| 616 | 627 | pub fn copy(self: Type, allocator: *Allocator) error{OutOfMemory}!Type { |
| 617 | 628 | if (self.tag_if_small_enough < Tag.no_payload_count) { |
| 618 | 629 | return Type{ .tag_if_small_enough = self.tag_if_small_enough }; |