authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-07-04 22:25:49+00:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-07-05 21:11:42+00:00
log3a89f214aa672c5844def1704845ad38ea60bdcd
tree0beea13a328bf74507509bb249211406e11bdb09
parent3c8b13d998c5c58c8171d36d7506ea3a181d0db9

update more HashMap API usage


8 files changed, 112 insertions(+), 153 deletions(-)

doc/docgen.zig+1-1
...@@ -392,7 +392,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {...@@ -392,7 +392,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
392 .n = header_stack_size,392 .n = header_stack_size,
393 },393 },
394 });394 });
395 if (try urls.put(urlized, tag_token)) |entry| {395 if (try urls.fetchPut(urlized, tag_token)) |entry| {
396 parseError(tokenizer, tag_token, "duplicate header url: #{}", .{urlized}) catch {};396 parseError(tokenizer, tag_token, "duplicate header url: #{}", .{urlized}) catch {};
397 parseError(tokenizer, entry.value, "other tag here", .{}) catch {};397 parseError(tokenizer, entry.value, "other tag here", .{}) catch {};
398 return error.ParseError;398 return error.ParseError;
doc/langref.html.in+3-11
...@@ -5363,11 +5363,11 @@ const std = @import("std");...@@ -5363,11 +5363,11 @@ const std = @import("std");
5363const assert = std.debug.assert;5363const assert = std.debug.assert;
53645364
5365test "turn HashMap into a set with void" {5365test "turn HashMap into a set with void" {
5366 var map = std.HashMap(i32, void, hash_i32, eql_i32).init(std.testing.allocator);5366 var map = std.AutoHashMap(i32, void).init(std.testing.allocator);
5367 defer map.deinit();5367 defer map.deinit();
53685368
5369 _ = try map.put(1, {});5369 try map.put(1, {});
5370 _ = try map.put(2, {});5370 try map.put(2, {});
53715371
5372 assert(map.contains(2));5372 assert(map.contains(2));
5373 assert(!map.contains(3));5373 assert(!map.contains(3));
...@@ -5375,14 +5375,6 @@ test "turn HashMap into a set with void" {...@@ -5375,14 +5375,6 @@ test "turn HashMap into a set with void" {
5375 _ = map.remove(2);5375 _ = map.remove(2);
5376 assert(!map.contains(2));5376 assert(!map.contains(2));
5377}5377}
5378
5379fn hash_i32(x: i32) u32 {
5380 return @bitCast(u32, x);
5381}
5382
5383fn eql_i32(a: i32, b: i32) bool {
5384 return a == b;
5385}
5386 {#code_end#}5378 {#code_end#}
5387 <p>Note that this is different from using a dummy value for the hash map value.5379 <p>Note that this is different from using a dummy value for the hash map value.
5388 By using {#syntax#}void{#endsyntax#} as the type of the value, the hash map entry type has no value field, and5380 By using {#syntax#}void{#endsyntax#} as the type of the value, the hash map entry type has no value field, and
lib/std/debug.zig+3-3
...@@ -1132,7 +1132,7 @@ pub const DebugInfo = struct {...@@ -1132,7 +1132,7 @@ pub const DebugInfo = struct {
1132 const seg_end = seg_start + segment_cmd.vmsize;1132 const seg_end = seg_start + segment_cmd.vmsize;
11331133
1134 if (rebased_address >= seg_start and rebased_address < seg_end) {1134 if (rebased_address >= seg_start and rebased_address < seg_end) {
1135 if (self.address_map.getValue(base_address)) |obj_di| {1135 if (self.address_map.get(base_address)) |obj_di| {
1136 return obj_di;1136 return obj_di;
1137 }1137 }
11381138
...@@ -1204,7 +1204,7 @@ pub const DebugInfo = struct {...@@ -1204,7 +1204,7 @@ pub const DebugInfo = struct {
1204 const seg_end = seg_start + info.SizeOfImage;1204 const seg_end = seg_start + info.SizeOfImage;
12051205
1206 if (address >= seg_start and address < seg_end) {1206 if (address >= seg_start and address < seg_end) {
1207 if (self.address_map.getValue(seg_start)) |obj_di| {1207 if (self.address_map.get(seg_start)) |obj_di| {
1208 return obj_di;1208 return obj_di;
1209 }1209 }
12101210
...@@ -1441,7 +1441,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {...@@ -1441,7 +1441,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
1441 const o_file_path = mem.spanZ(self.strings[symbol.ofile.?.n_strx..]);1441 const o_file_path = mem.spanZ(self.strings[symbol.ofile.?.n_strx..]);
14421442
1443 // Check if its debug infos are already in the cache1443 // Check if its debug infos are already in the cache
1444 var o_file_di = self.ofiles.getValue(o_file_path) orelse1444 var o_file_di = self.ofiles.get(o_file_path) orelse
1445 (self.loadOFile(o_file_path) catch |err| switch (err) {1445 (self.loadOFile(o_file_path) catch |err| switch (err) {
1446 error.FileNotFound,1446 error.FileNotFound,
1447 error.MissingDebugInfo,1447 error.MissingDebugInfo,
lib/std/hash_map.zig+1-1
...@@ -458,7 +458,7 @@ pub fn HashMapUnmanaged(...@@ -458,7 +458,7 @@ pub fn HashMapUnmanaged(
458 }458 }
459459
460 /// Inserts a new `Entry` into the hash map, returning the previous one, if any.460 /// Inserts a new `Entry` into the hash map, returning the previous one, if any.
461 /// If insertion happuns, asserts there is enough capacity without allocating.461 /// If insertion happens, asserts there is enough capacity without allocating.
462 pub fn fetchPutAssumeCapacity(self: *Self, key: K, value: V) ?Entry {462 pub fn fetchPutAssumeCapacity(self: *Self, key: K, value: V) ?Entry {
463 const gop = self.getOrPutAssumeCapacity(key);463 const gop = self.getOrPutAssumeCapacity(key);
464 var result: ?Entry = null;464 var result: ?Entry = null;
src-self-hosted/Module.zig+83-114
...@@ -75,7 +75,7 @@ deletion_set: std.ArrayListUnmanaged(*Decl) = .{},...@@ -75,7 +75,7 @@ deletion_set: std.ArrayListUnmanaged(*Decl) = .{},
7575
76keep_source_files_loaded: bool,76keep_source_files_loaded: bool,
7777
78const DeclTable = std.HashMap(Scope.NameHash, *Decl, Scope.name_hash_hash, Scope.name_hash_eql);78const DeclTable = std.HashMap(Scope.NameHash, *Decl, Scope.name_hash_hash, Scope.name_hash_eql, false);
7979
80const WorkItem = union(enum) {80const WorkItem = union(enum) {
81 /// Write the machine code for a Decl to the output file.81 /// Write the machine code for a Decl to the output file.
...@@ -795,49 +795,38 @@ pub fn deinit(self: *Module) void {...@@ -795,49 +795,38 @@ pub fn deinit(self: *Module) void {
795 const allocator = self.allocator;795 const allocator = self.allocator;
796 self.deletion_set.deinit(allocator);796 self.deletion_set.deinit(allocator);
797 self.work_queue.deinit();797 self.work_queue.deinit();
798 {798
799 var it = self.decl_table.iterator();799 for (self.decl_table.items()) |entry| {
800 while (it.next()) |kv| {800 entry.value.destroy(allocator);
801 kv.value.destroy(allocator);
802 }
803 self.decl_table.deinit();
804 }801 }
805 {802 self.decl_table.deinit();
806 var it = self.failed_decls.iterator();803
807 while (it.next()) |kv| {804 for (self.failed_decls.items()) |entry| {
808 kv.value.destroy(allocator);805 entry.value.destroy(allocator);
809 }
810 self.failed_decls.deinit();
811 }806 }
812 {807 self.failed_decls.deinit();
813 var it = self.failed_files.iterator();808
814 while (it.next()) |kv| {809 for (self.failed_files.items()) |entry| {
815 kv.value.destroy(allocator);810 entry.value.destroy(allocator);
816 }
817 self.failed_files.deinit();
818 }811 }
819 {812 self.failed_files.deinit();
820 var it = self.failed_exports.iterator();813
821 while (it.next()) |kv| {814 for (self.failed_exports.items()) |entry| {
822 kv.value.destroy(allocator);815 entry.value.destroy(allocator);
823 }
824 self.failed_exports.deinit();
825 }816 }
826 {817 self.failed_exports.deinit();
827 var it = self.decl_exports.iterator();818
828 while (it.next()) |kv| {819 for (self.decl_exports.items()) |entry| {
829 const export_list = kv.value;820 const export_list = entry.value;
830 allocator.free(export_list);821 allocator.free(export_list);
831 }
832 self.decl_exports.deinit();
833 }822 }
834 {823 self.decl_exports.deinit();
835 var it = self.export_owners.iterator();824
836 while (it.next()) |kv| {825 for (self.export_owners.items()) |entry| {
837 freeExportList(allocator, kv.value);826 freeExportList(allocator, entry.value);
838 }
839 self.export_owners.deinit();
840 }827 }
828 self.export_owners.deinit();
829
841 self.symbol_exports.deinit();830 self.symbol_exports.deinit();
842 self.root_scope.destroy(allocator);831 self.root_scope.destroy(allocator);
843 self.* = undefined;832 self.* = undefined;
...@@ -918,9 +907,9 @@ pub fn makeBinFileWritable(self: *Module) !void {...@@ -918,9 +907,9 @@ pub fn makeBinFileWritable(self: *Module) !void {
918}907}
919908
920pub fn totalErrorCount(self: *Module) usize {909pub fn totalErrorCount(self: *Module) usize {
921 const total = self.failed_decls.size +910 const total = self.failed_decls.items().len +
922 self.failed_files.size +911 self.failed_files.items().len +
923 self.failed_exports.size;912 self.failed_exports.items().len;
924 return if (total == 0) @boolToInt(self.link_error_flags.no_entry_point_found) else total;913 return if (total == 0) @boolToInt(self.link_error_flags.no_entry_point_found) else total;
925}914}
926915
...@@ -931,32 +920,23 @@ pub fn getAllErrorsAlloc(self: *Module) !AllErrors {...@@ -931,32 +920,23 @@ pub fn getAllErrorsAlloc(self: *Module) !AllErrors {
931 var errors = std.ArrayList(AllErrors.Message).init(self.allocator);920 var errors = std.ArrayList(AllErrors.Message).init(self.allocator);
932 defer errors.deinit();921 defer errors.deinit();
933922
934 {923 for (self.failed_files.items()) |entry| {
935 var it = self.failed_files.iterator();924 const scope = entry.key;
936 while (it.next()) |kv| {925 const err_msg = entry.value;
937 const scope = kv.key;926 const source = try scope.getSource(self);
938 const err_msg = kv.value;927 try AllErrors.add(&arena, &errors, scope.subFilePath(), source, err_msg.*);
939 const source = try scope.getSource(self);
940 try AllErrors.add(&arena, &errors, scope.subFilePath(), source, err_msg.*);
941 }
942 }928 }
943 {929 for (self.failed_decls.items()) |entry| {
944 var it = self.failed_decls.iterator();930 const decl = entry.key;
945 while (it.next()) |kv| {931 const err_msg = entry.value;
946 const decl = kv.key;932 const source = try decl.scope.getSource(self);
947 const err_msg = kv.value;933 try AllErrors.add(&arena, &errors, decl.scope.subFilePath(), source, err_msg.*);
948 const source = try decl.scope.getSource(self);
949 try AllErrors.add(&arena, &errors, decl.scope.subFilePath(), source, err_msg.*);
950 }
951 }934 }
952 {935 for (self.failed_exports.items()) |entry| {
953 var it = self.failed_exports.iterator();936 const decl = entry.key.owner_decl;
954 while (it.next()) |kv| {937 const err_msg = entry.value;
955 const decl = kv.key.owner_decl;938 const source = try decl.scope.getSource(self);
956 const err_msg = kv.value;939 try AllErrors.add(&arena, &errors, decl.scope.subFilePath(), source, err_msg.*);
957 const source = try decl.scope.getSource(self);
958 try AllErrors.add(&arena, &errors, decl.scope.subFilePath(), source, err_msg.*);
959 }
960 }940 }
961941
962 if (errors.items.len == 0 and self.link_error_flags.no_entry_point_found) {942 if (errors.items.len == 0 and self.link_error_flags.no_entry_point_found) {
...@@ -1016,7 +996,7 @@ pub fn performAllTheWork(self: *Module) error{OutOfMemory}!void {...@@ -1016,7 +996,7 @@ pub fn performAllTheWork(self: *Module) error{OutOfMemory}!void {
1016 decl.analysis = .dependency_failure;996 decl.analysis = .dependency_failure;
1017 },997 },
1018 else => {998 else => {
1019 try self.failed_decls.ensureCapacity(self.failed_decls.size + 1);999 try self.failed_decls.ensureCapacity(self.failed_decls.items().len + 1);
1020 self.failed_decls.putAssumeCapacityNoClobber(decl, try ErrorMsg.create(1000 self.failed_decls.putAssumeCapacityNoClobber(decl, try ErrorMsg.create(
1021 self.allocator,1001 self.allocator,
1022 decl.src(),1002 decl.src(),
...@@ -1086,7 +1066,7 @@ fn ensureDeclAnalyzed(self: *Module, decl: *Decl) InnerError!void {...@@ -1086,7 +1066,7 @@ fn ensureDeclAnalyzed(self: *Module, decl: *Decl) InnerError!void {
1086 error.OutOfMemory => return error.OutOfMemory,1066 error.OutOfMemory => return error.OutOfMemory,
1087 error.AnalysisFail => return error.AnalysisFail,1067 error.AnalysisFail => return error.AnalysisFail,
1088 else => {1068 else => {
1089 try self.failed_decls.ensureCapacity(self.failed_decls.size + 1);1069 try self.failed_decls.ensureCapacity(self.failed_decls.items().len + 1);
1090 self.failed_decls.putAssumeCapacityNoClobber(decl, try ErrorMsg.create(1070 self.failed_decls.putAssumeCapacityNoClobber(decl, try ErrorMsg.create(
1091 self.allocator,1071 self.allocator,
1092 decl.src(),1072 decl.src(),
...@@ -1636,7 +1616,7 @@ fn declareDeclDependency(self: *Module, depender: *Decl, dependee: *Decl) !void...@@ -1636,7 +1616,7 @@ fn declareDeclDependency(self: *Module, depender: *Decl, dependee: *Decl) !void
1636fn getSrcModule(self: *Module, root_scope: *Scope.ZIRModule) !*zir.Module {1616fn getSrcModule(self: *Module, root_scope: *Scope.ZIRModule) !*zir.Module {
1637 switch (root_scope.status) {1617 switch (root_scope.status) {
1638 .never_loaded, .unloaded_success => {1618 .never_loaded, .unloaded_success => {
1639 try self.failed_files.ensureCapacity(self.failed_files.size + 1);1619 try self.failed_files.ensureCapacity(self.failed_files.items().len + 1);
16401620
1641 const source = try root_scope.getSource(self);1621 const source = try root_scope.getSource(self);
16421622
...@@ -1677,7 +1657,7 @@ fn getAstTree(self: *Module, root_scope: *Scope.File) !*ast.Tree {...@@ -1677,7 +1657,7 @@ fn getAstTree(self: *Module, root_scope: *Scope.File) !*ast.Tree {
16771657
1678 switch (root_scope.status) {1658 switch (root_scope.status) {
1679 .never_loaded, .unloaded_success => {1659 .never_loaded, .unloaded_success => {
1680 try self.failed_files.ensureCapacity(self.failed_files.size + 1);1660 try self.failed_files.ensureCapacity(self.failed_files.items().len + 1);
16811661
1682 const source = try root_scope.getSource(self);1662 const source = try root_scope.getSource(self);
16831663
...@@ -1745,8 +1725,7 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void {...@@ -1745,8 +1725,7 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void {
1745 const name = tree.tokenSliceLoc(name_loc);1725 const name = tree.tokenSliceLoc(name_loc);
1746 const name_hash = root_scope.fullyQualifiedNameHash(name);1726 const name_hash = root_scope.fullyQualifiedNameHash(name);
1747 const contents_hash = std.zig.hashSrc(tree.getNodeSource(src_decl));1727 const contents_hash = std.zig.hashSrc(tree.getNodeSource(src_decl));
1748 if (self.decl_table.get(name_hash)) |kv| {1728 if (self.decl_table.get(name_hash)) |decl| {
1749 const decl = kv.value;
1750 // Update the AST Node index of the decl, even if its contents are unchanged, it may1729 // Update the AST Node index of the decl, even if its contents are unchanged, it may
1751 // have been re-ordered.1730 // have been re-ordered.
1752 decl.src_index = decl_i;1731 decl.src_index = decl_i;
...@@ -1774,14 +1753,11 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void {...@@ -1774,14 +1753,11 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void {
1774 // TODO also look for global variable declarations1753 // TODO also look for global variable declarations
1775 // TODO also look for comptime blocks and exported globals1754 // TODO also look for comptime blocks and exported globals
1776 }1755 }
1777 {1756 // Handle explicitly deleted decls from the source code. Not to be confused
1778 // Handle explicitly deleted decls from the source code. Not to be confused1757 // with when we delete decls because they are no longer referenced.
1779 // with when we delete decls because they are no longer referenced.1758 for (deleted_decls.items()) |entry| {
1780 var it = deleted_decls.iterator();1759 //std.debug.warn("noticed '{}' deleted from source\n", .{entry.key.name});
1781 while (it.next()) |kv| {1760 try self.deleteDecl(entry.key);
1782 //std.debug.warn("noticed '{}' deleted from source\n", .{kv.key.name});
1783 try self.deleteDecl(kv.key);
1784 }
1785 }1761 }
1786}1762}
17871763
...@@ -1800,18 +1776,14 @@ fn analyzeRootZIRModule(self: *Module, root_scope: *Scope.ZIRModule) !void {...@@ -1800,18 +1776,14 @@ fn analyzeRootZIRModule(self: *Module, root_scope: *Scope.ZIRModule) !void {
1800 // we know which ones have been deleted.1776 // we know which ones have been deleted.
1801 var deleted_decls = std.AutoHashMap(*Decl, void).init(self.allocator);1777 var deleted_decls = std.AutoHashMap(*Decl, void).init(self.allocator);
1802 defer deleted_decls.deinit();1778 defer deleted_decls.deinit();
1803 try deleted_decls.ensureCapacity(self.decl_table.size);1779 try deleted_decls.ensureCapacity(self.decl_table.items().len);
1804 {1780 for (self.decl_table.items()) |entry| {
1805 var it = self.decl_table.iterator();1781 deleted_decls.putAssumeCapacityNoClobber(entry.value, {});
1806 while (it.next()) |kv| {
1807 deleted_decls.putAssumeCapacityNoClobber(kv.value, {});
1808 }
1809 }1782 }
18101783
1811 for (src_module.decls) |src_decl, decl_i| {1784 for (src_module.decls) |src_decl, decl_i| {
1812 const name_hash = root_scope.fullyQualifiedNameHash(src_decl.name);1785 const name_hash = root_scope.fullyQualifiedNameHash(src_decl.name);
1813 if (self.decl_table.get(name_hash)) |kv| {1786 if (self.decl_table.get(name_hash)) |decl| {
1814 const decl = kv.value;
1815 deleted_decls.removeAssertDiscard(decl);1787 deleted_decls.removeAssertDiscard(decl);
1816 //std.debug.warn("'{}' contents: '{}'\n", .{ src_decl.name, src_decl.contents });1788 //std.debug.warn("'{}' contents: '{}'\n", .{ src_decl.name, src_decl.contents });
1817 if (!srcHashEql(src_decl.contents_hash, decl.contents_hash)) {1789 if (!srcHashEql(src_decl.contents_hash, decl.contents_hash)) {
...@@ -1835,14 +1807,11 @@ fn analyzeRootZIRModule(self: *Module, root_scope: *Scope.ZIRModule) !void {...@@ -1835,14 +1807,11 @@ fn analyzeRootZIRModule(self: *Module, root_scope: *Scope.ZIRModule) !void {
1835 for (exports_to_resolve.items) |export_decl| {1807 for (exports_to_resolve.items) |export_decl| {
1836 _ = try self.resolveZirDecl(&root_scope.base, export_decl);1808 _ = try self.resolveZirDecl(&root_scope.base, export_decl);
1837 }1809 }
1838 {1810 // Handle explicitly deleted decls from the source code. Not to be confused
1839 // Handle explicitly deleted decls from the source code. Not to be confused1811 // with when we delete decls because they are no longer referenced.
1840 // with when we delete decls because they are no longer referenced.1812 for (deleted_decls.items()) |entry| {
1841 var it = deleted_decls.iterator();1813 //std.debug.warn("noticed '{}' deleted from source\n", .{entry.key.name});
1842 while (it.next()) |kv| {1814 try self.deleteDecl(entry.key);
1843 //std.debug.warn("noticed '{}' deleted from source\n", .{kv.key.name});
1844 try self.deleteDecl(kv.key);
1845 }
1846 }1815 }
1847}1816}
18481817
...@@ -1888,7 +1857,7 @@ fn deleteDeclExports(self: *Module, decl: *Decl) void {...@@ -1888,7 +1857,7 @@ fn deleteDeclExports(self: *Module, decl: *Decl) void {
1888 const kv = self.export_owners.remove(decl) orelse return;1857 const kv = self.export_owners.remove(decl) orelse return;
18891858
1890 for (kv.value) |exp| {1859 for (kv.value) |exp| {
1891 if (self.decl_exports.get(exp.exported_decl)) |decl_exports_kv| {1860 if (self.decl_exports.getEntry(exp.exported_decl)) |decl_exports_kv| {
1892 // Remove exports with owner_decl matching the regenerating decl.1861 // Remove exports with owner_decl matching the regenerating decl.
1893 const list = decl_exports_kv.value;1862 const list = decl_exports_kv.value;
1894 var i: usize = 0;1863 var i: usize = 0;
...@@ -1983,7 +1952,7 @@ fn createNewDecl(...@@ -1983,7 +1952,7 @@ fn createNewDecl(
1983 name_hash: Scope.NameHash,1952 name_hash: Scope.NameHash,
1984 contents_hash: std.zig.SrcHash,1953 contents_hash: std.zig.SrcHash,
1985) !*Decl {1954) !*Decl {
1986 try self.decl_table.ensureCapacity(self.decl_table.size + 1);1955 try self.decl_table.ensureCapacity(self.decl_table.items().len + 1);
1987 const new_decl = try self.allocateNewDecl(scope, src_index, contents_hash);1956 const new_decl = try self.allocateNewDecl(scope, src_index, contents_hash);
1988 errdefer self.allocator.destroy(new_decl);1957 errdefer self.allocator.destroy(new_decl);
1989 new_decl.name = try mem.dupeZ(self.allocator, u8, decl_name);1958 new_decl.name = try mem.dupeZ(self.allocator, u8, decl_name);
...@@ -2043,7 +2012,7 @@ fn resolveZirDecl(self: *Module, scope: *Scope, src_decl: *zir.Decl) InnerError!...@@ -2043,7 +2012,7 @@ fn resolveZirDecl(self: *Module, scope: *Scope, src_decl: *zir.Decl) InnerError!
20432012
2044fn resolveZirDeclHavingIndex(self: *Module, scope: *Scope, src_decl: *zir.Decl, src_index: usize) InnerError!*Decl {2013fn resolveZirDeclHavingIndex(self: *Module, scope: *Scope, src_decl: *zir.Decl, src_index: usize) InnerError!*Decl {
2045 const name_hash = scope.namespace().fullyQualifiedNameHash(src_decl.name);2014 const name_hash = scope.namespace().fullyQualifiedNameHash(src_decl.name);
2046 const decl = self.decl_table.getValue(name_hash).?;2015 const decl = self.decl_table.get(name_hash).?;
2047 decl.src_index = src_index;2016 decl.src_index = src_index;
2048 try self.ensureDeclAnalyzed(decl);2017 try self.ensureDeclAnalyzed(decl);
2049 return decl;2018 return decl;
...@@ -2148,8 +2117,8 @@ fn analyzeExport(self: *Module, scope: *Scope, src: usize, symbol_name: []const...@@ -2148,8 +2117,8 @@ fn analyzeExport(self: *Module, scope: *Scope, src: usize, symbol_name: []const
2148 else => return self.fail(scope, src, "unable to export type '{}'", .{typed_value.ty}),2117 else => return self.fail(scope, src, "unable to export type '{}'", .{typed_value.ty}),
2149 }2118 }
21502119
2151 try self.decl_exports.ensureCapacity(self.decl_exports.size + 1);2120 try self.decl_exports.ensureCapacity(self.decl_exports.items().len + 1);
2152 try self.export_owners.ensureCapacity(self.export_owners.size + 1);2121 try self.export_owners.ensureCapacity(self.export_owners.items().len + 1);
21532122
2154 const new_export = try self.allocator.create(Export);2123 const new_export = try self.allocator.create(Export);
2155 errdefer self.allocator.destroy(new_export);2124 errdefer self.allocator.destroy(new_export);
...@@ -2168,23 +2137,23 @@ fn analyzeExport(self: *Module, scope: *Scope, src: usize, symbol_name: []const...@@ -2168,23 +2137,23 @@ fn analyzeExport(self: *Module, scope: *Scope, src: usize, symbol_name: []const
2168 // Add to export_owners table.2137 // Add to export_owners table.
2169 const eo_gop = self.export_owners.getOrPut(owner_decl) catch unreachable;2138 const eo_gop = self.export_owners.getOrPut(owner_decl) catch unreachable;
2170 if (!eo_gop.found_existing) {2139 if (!eo_gop.found_existing) {
2171 eo_gop.kv.value = &[0]*Export{};2140 eo_gop.entry.value = &[0]*Export{};
2172 }2141 }
2173 eo_gop.kv.value = try self.allocator.realloc(eo_gop.kv.value, eo_gop.kv.value.len + 1);2142 eo_gop.entry.value = try self.allocator.realloc(eo_gop.entry.value, eo_gop.entry.value.len + 1);
2174 eo_gop.kv.value[eo_gop.kv.value.len - 1] = new_export;2143 eo_gop.entry.value[eo_gop.entry.value.len - 1] = new_export;
2175 errdefer eo_gop.kv.value = self.allocator.shrink(eo_gop.kv.value, eo_gop.kv.value.len - 1);2144 errdefer eo_gop.entry.value = self.allocator.shrink(eo_gop.entry.value, eo_gop.entry.value.len - 1);
21762145
2177 // Add to exported_decl table.2146 // Add to exported_decl table.
2178 const de_gop = self.decl_exports.getOrPut(exported_decl) catch unreachable;2147 const de_gop = self.decl_exports.getOrPut(exported_decl) catch unreachable;
2179 if (!de_gop.found_existing) {2148 if (!de_gop.found_existing) {
2180 de_gop.kv.value = &[0]*Export{};2149 de_gop.entry.value = &[0]*Export{};
2181 }2150 }
2182 de_gop.kv.value = try self.allocator.realloc(de_gop.kv.value, de_gop.kv.value.len + 1);2151 de_gop.entry.value = try self.allocator.realloc(de_gop.entry.value, de_gop.entry.value.len + 1);
2183 de_gop.kv.value[de_gop.kv.value.len - 1] = new_export;2152 de_gop.entry.value[de_gop.entry.value.len - 1] = new_export;
2184 errdefer de_gop.kv.value = self.allocator.shrink(de_gop.kv.value, de_gop.kv.value.len - 1);2153 errdefer de_gop.entry.value = self.allocator.shrink(de_gop.entry.value, de_gop.entry.value.len - 1);
21852154
2186 if (self.symbol_exports.get(symbol_name)) |_| {2155 if (self.symbol_exports.get(symbol_name)) |_| {
2187 try self.failed_exports.ensureCapacity(self.failed_exports.size + 1);2156 try self.failed_exports.ensureCapacity(self.failed_exports.items().len + 1);
2188 self.failed_exports.putAssumeCapacityNoClobber(new_export, try ErrorMsg.create(2157 self.failed_exports.putAssumeCapacityNoClobber(new_export, try ErrorMsg.create(
2189 self.allocator,2158 self.allocator,
2190 src,2159 src,
...@@ -2197,10 +2166,10 @@ fn analyzeExport(self: *Module, scope: *Scope, src: usize, symbol_name: []const...@@ -2197,10 +2166,10 @@ fn analyzeExport(self: *Module, scope: *Scope, src: usize, symbol_name: []const
2197 }2166 }
21982167
2199 try self.symbol_exports.putNoClobber(symbol_name, new_export);2168 try self.symbol_exports.putNoClobber(symbol_name, new_export);
2200 self.bin_file.updateDeclExports(self, exported_decl, de_gop.kv.value) catch |err| switch (err) {2169 self.bin_file.updateDeclExports(self, exported_decl, de_gop.entry.value) catch |err| switch (err) {
2201 error.OutOfMemory => return error.OutOfMemory,2170 error.OutOfMemory => return error.OutOfMemory,
2202 else => {2171 else => {
2203 try self.failed_exports.ensureCapacity(self.failed_exports.size + 1);2172 try self.failed_exports.ensureCapacity(self.failed_exports.items().len + 1);
2204 self.failed_exports.putAssumeCapacityNoClobber(new_export, try ErrorMsg.create(2173 self.failed_exports.putAssumeCapacityNoClobber(new_export, try ErrorMsg.create(
2205 self.allocator,2174 self.allocator,
2206 src,2175 src,
...@@ -2494,7 +2463,7 @@ fn getNextAnonNameIndex(self: *Module) usize {...@@ -2494,7 +2463,7 @@ fn getNextAnonNameIndex(self: *Module) usize {
2494fn lookupDeclName(self: *Module, scope: *Scope, ident_name: []const u8) ?*Decl {2463fn lookupDeclName(self: *Module, scope: *Scope, ident_name: []const u8) ?*Decl {
2495 const namespace = scope.namespace();2464 const namespace = scope.namespace();
2496 const name_hash = namespace.fullyQualifiedNameHash(ident_name);2465 const name_hash = namespace.fullyQualifiedNameHash(ident_name);
2497 return self.decl_table.getValue(name_hash);2466 return self.decl_table.get(name_hash);
2498}2467}
24992468
2500fn analyzeInstExport(self: *Module, scope: *Scope, export_inst: *zir.Inst.Export) InnerError!*Inst {2469fn analyzeInstExport(self: *Module, scope: *Scope, export_inst: *zir.Inst.Export) InnerError!*Inst {
...@@ -3489,8 +3458,8 @@ fn failNode(...@@ -3489,8 +3458,8 @@ fn failNode(
3489fn failWithOwnedErrorMsg(self: *Module, scope: *Scope, src: usize, err_msg: *ErrorMsg) InnerError {3458fn failWithOwnedErrorMsg(self: *Module, scope: *Scope, src: usize, err_msg: *ErrorMsg) InnerError {
3490 {3459 {
3491 errdefer err_msg.destroy(self.allocator);3460 errdefer err_msg.destroy(self.allocator);
3492 try self.failed_decls.ensureCapacity(self.failed_decls.size + 1);3461 try self.failed_decls.ensureCapacity(self.failed_decls.items().len + 1);
3493 try self.failed_files.ensureCapacity(self.failed_files.size + 1);3462 try self.failed_files.ensureCapacity(self.failed_files.items().len + 1);
3494 }3463 }
3495 switch (scope.tag) {3464 switch (scope.tag) {
3496 .decl => {3465 .decl => {
src-self-hosted/codegen.zig+2-2
...@@ -705,7 +705,7 @@ const Function = struct {...@@ -705,7 +705,7 @@ const Function = struct {
705 }705 }
706706
707 fn resolveInst(self: *Function, inst: *ir.Inst) !MCValue {707 fn resolveInst(self: *Function, inst: *ir.Inst) !MCValue {
708 if (self.inst_table.getValue(inst)) |mcv| {708 if (self.inst_table.get(inst)) |mcv| {
709 return mcv;709 return mcv;
710 }710 }
711 if (inst.cast(ir.Inst.Constant)) |const_inst| {711 if (inst.cast(ir.Inst.Constant)) |const_inst| {
...@@ -713,7 +713,7 @@ const Function = struct {...@@ -713,7 +713,7 @@ const Function = struct {
713 try self.inst_table.putNoClobber(inst, mcvalue);713 try self.inst_table.putNoClobber(inst, mcvalue);
714 return mcvalue;714 return mcvalue;
715 } else {715 } else {
716 return self.inst_table.getValue(inst).?;716 return self.inst_table.get(inst).?;
717 }717 }
718 }718 }
719719
src-self-hosted/link.zig+3-3
...@@ -1071,7 +1071,7 @@ pub const ElfFile = struct {...@@ -1071,7 +1071,7 @@ pub const ElfFile = struct {
1071 try self.file.?.pwriteAll(code, file_offset);1071 try self.file.?.pwriteAll(code, file_offset);
10721072
1073 // Since we updated the vaddr and the size, each corresponding export symbol also needs to be updated.1073 // Since we updated the vaddr and the size, each corresponding export symbol also needs to be updated.
1074 const decl_exports = module.decl_exports.getValue(decl) orelse &[0]*Module.Export{};1074 const decl_exports = module.decl_exports.get(decl) orelse &[0]*Module.Export{};
1075 return self.updateDeclExports(module, decl, decl_exports);1075 return self.updateDeclExports(module, decl, decl_exports);
1076 }1076 }
10771077
...@@ -1093,7 +1093,7 @@ pub const ElfFile = struct {...@@ -1093,7 +1093,7 @@ pub const ElfFile = struct {
1093 for (exports) |exp| {1093 for (exports) |exp| {
1094 if (exp.options.section) |section_name| {1094 if (exp.options.section) |section_name| {
1095 if (!mem.eql(u8, section_name, ".text")) {1095 if (!mem.eql(u8, section_name, ".text")) {
1096 try module.failed_exports.ensureCapacity(module.failed_exports.size + 1);1096 try module.failed_exports.ensureCapacity(module.failed_exports.items().len + 1);
1097 module.failed_exports.putAssumeCapacityNoClobber(1097 module.failed_exports.putAssumeCapacityNoClobber(
1098 exp,1098 exp,
1099 try Module.ErrorMsg.create(self.allocator, 0, "Unimplemented: ExportOptions.section", .{}),1099 try Module.ErrorMsg.create(self.allocator, 0, "Unimplemented: ExportOptions.section", .{}),
...@@ -1111,7 +1111,7 @@ pub const ElfFile = struct {...@@ -1111,7 +1111,7 @@ pub const ElfFile = struct {
1111 },1111 },
1112 .Weak => elf.STB_WEAK,1112 .Weak => elf.STB_WEAK,
1113 .LinkOnce => {1113 .LinkOnce => {
1114 try module.failed_exports.ensureCapacity(module.failed_exports.size + 1);1114 try module.failed_exports.ensureCapacity(module.failed_exports.items().len + 1);
1115 module.failed_exports.putAssumeCapacityNoClobber(1115 module.failed_exports.putAssumeCapacityNoClobber(
1116 exp,1116 exp,
1117 try Module.ErrorMsg.create(self.allocator, 0, "Unimplemented: GlobalLinkage.LinkOnce", .{}),1117 try Module.ErrorMsg.create(self.allocator, 0, "Unimplemented: GlobalLinkage.LinkOnce", .{}),
src-self-hosted/zir.zig+16-18
...@@ -758,7 +758,7 @@ pub const Module = struct {...@@ -758,7 +758,7 @@ pub const Module = struct {
758 }758 }
759759
760 fn writeInstParamToStream(self: Module, stream: var, inst: *Inst, inst_table: *const InstPtrTable) !void {760 fn writeInstParamToStream(self: Module, stream: var, inst: *Inst, inst_table: *const InstPtrTable) !void {
761 if (inst_table.getValue(inst)) |info| {761 if (inst_table.get(inst)) |info| {
762 if (info.index) |i| {762 if (info.index) |i| {
763 try stream.print("%{}", .{info.index});763 try stream.print("%{}", .{info.index});
764 } else {764 } else {
...@@ -843,7 +843,7 @@ const Parser = struct {...@@ -843,7 +843,7 @@ const Parser = struct {
843 skipSpace(self);843 skipSpace(self);
844 const decl = try parseInstruction(self, &body_context, ident);844 const decl = try parseInstruction(self, &body_context, ident);
845 const ident_index = body_context.instructions.items.len;845 const ident_index = body_context.instructions.items.len;
846 if (try body_context.name_map.put(ident, decl.inst)) |_| {846 if (try body_context.name_map.fetchPut(ident, decl.inst)) |_| {
847 return self.fail("redefinition of identifier '{}'", .{ident});847 return self.fail("redefinition of identifier '{}'", .{ident});
848 }848 }
849 try body_context.instructions.append(decl.inst);849 try body_context.instructions.append(decl.inst);
...@@ -929,7 +929,7 @@ const Parser = struct {...@@ -929,7 +929,7 @@ const Parser = struct {
929 skipSpace(self);929 skipSpace(self);
930 const decl = try parseInstruction(self, null, ident);930 const decl = try parseInstruction(self, null, ident);
931 const ident_index = self.decls.items.len;931 const ident_index = self.decls.items.len;
932 if (try self.global_name_map.put(ident, decl.inst)) |_| {932 if (try self.global_name_map.fetchPut(ident, decl.inst)) |_| {
933 return self.fail("redefinition of identifier '{}'", .{ident});933 return self.fail("redefinition of identifier '{}'", .{ident});
934 }934 }
935 try self.decls.append(self.allocator, decl);935 try self.decls.append(self.allocator, decl);
...@@ -1153,7 +1153,7 @@ const Parser = struct {...@@ -1153,7 +1153,7 @@ const Parser = struct {
1153 else => continue,1153 else => continue,
1154 };1154 };
1155 const ident = self.source[name_start..self.i];1155 const ident = self.source[name_start..self.i];
1156 const kv = map.get(ident) orelse {1156 return map.get(ident) orelse {
1157 const bad_name = self.source[name_start - 1 .. self.i];1157 const bad_name = self.source[name_start - 1 .. self.i];
1158 const src = name_start - 1;1158 const src = name_start - 1;
1159 if (local_ref) {1159 if (local_ref) {
...@@ -1172,7 +1172,6 @@ const Parser = struct {...@@ -1172,7 +1172,6 @@ const Parser = struct {
1172 return &declval.base;1172 return &declval.base;
1173 }1173 }
1174 };1174 };
1175 return kv.value;
1176 }1175 }
11771176
1178 fn generateName(self: *Parser) ![]u8 {1177 fn generateName(self: *Parser) ![]u8 {
...@@ -1219,13 +1218,12 @@ const EmitZIR = struct {...@@ -1219,13 +1218,12 @@ const EmitZIR = struct {
1219 // by the hash table.1218 // by the hash table.
1220 var src_decls = std.ArrayList(*IrModule.Decl).init(self.allocator);1219 var src_decls = std.ArrayList(*IrModule.Decl).init(self.allocator);
1221 defer src_decls.deinit();1220 defer src_decls.deinit();
1222 try src_decls.ensureCapacity(self.old_module.decl_table.size);1221 try src_decls.ensureCapacity(self.old_module.decl_table.items().len);
1223 try self.decls.ensureCapacity(self.allocator, self.old_module.decl_table.size);1222 try self.decls.ensureCapacity(self.allocator, self.old_module.decl_table.items().len);
1224 try self.names.ensureCapacity(self.old_module.decl_table.size);1223 try self.names.ensureCapacity(self.old_module.decl_table.items().len);
12251224
1226 var decl_it = self.old_module.decl_table.iterator();1225 for (self.old_module.decl_table.items()) |entry| {
1227 while (decl_it.next()) |kv| {1226 const decl = entry.value;
1228 const decl = kv.value;
1229 src_decls.appendAssumeCapacity(decl);1227 src_decls.appendAssumeCapacity(decl);
1230 self.names.putAssumeCapacityNoClobber(mem.spanZ(decl.name), {});1228 self.names.putAssumeCapacityNoClobber(mem.spanZ(decl.name), {});
1231 }1229 }
...@@ -1248,7 +1246,7 @@ const EmitZIR = struct {...@@ -1248,7 +1246,7 @@ const EmitZIR = struct {
1248 .codegen_failure,1246 .codegen_failure,
1249 .dependency_failure,1247 .dependency_failure,
1250 .codegen_failure_retryable,1248 .codegen_failure_retryable,
1251 => if (self.old_module.failed_decls.getValue(ir_decl)) |err_msg| {1249 => if (self.old_module.failed_decls.get(ir_decl)) |err_msg| {
1252 const fail_inst = try self.arena.allocator.create(Inst.CompileError);1250 const fail_inst = try self.arena.allocator.create(Inst.CompileError);
1253 fail_inst.* = .{1251 fail_inst.* = .{
1254 .base = .{1252 .base = .{
...@@ -1270,7 +1268,7 @@ const EmitZIR = struct {...@@ -1270,7 +1268,7 @@ const EmitZIR = struct {
1270 continue;1268 continue;
1271 },1269 },
1272 }1270 }
1273 if (self.old_module.export_owners.getValue(ir_decl)) |exports| {1271 if (self.old_module.export_owners.get(ir_decl)) |exports| {
1274 for (exports) |module_export| {1272 for (exports) |module_export| {
1275 const symbol_name = try self.emitStringLiteral(module_export.src, module_export.options.name);1273 const symbol_name = try self.emitStringLiteral(module_export.src, module_export.options.name);
1276 const export_inst = try self.arena.allocator.create(Inst.Export);1274 const export_inst = try self.arena.allocator.create(Inst.Export);
...@@ -1314,7 +1312,7 @@ const EmitZIR = struct {...@@ -1314,7 +1312,7 @@ const EmitZIR = struct {
1314 try new_body.inst_table.putNoClobber(inst, new_inst);1312 try new_body.inst_table.putNoClobber(inst, new_inst);
1315 return new_inst;1313 return new_inst;
1316 } else {1314 } else {
1317 return new_body.inst_table.getValue(inst).?;1315 return new_body.inst_table.get(inst).?;
1318 }1316 }
1319 }1317 }
13201318
...@@ -1424,7 +1422,7 @@ const EmitZIR = struct {...@@ -1424,7 +1422,7 @@ const EmitZIR = struct {
1424 try self.emitBody(body, &inst_table, &instructions);1422 try self.emitBody(body, &inst_table, &instructions);
1425 },1423 },
1426 .sema_failure => {1424 .sema_failure => {
1427 const err_msg = self.old_module.failed_decls.getValue(module_fn.owner_decl).?;1425 const err_msg = self.old_module.failed_decls.get(module_fn.owner_decl).?;
1428 const fail_inst = try self.arena.allocator.create(Inst.CompileError);1426 const fail_inst = try self.arena.allocator.create(Inst.CompileError);
1429 fail_inst.* = .{1427 fail_inst.* = .{
1430 .base = .{1428 .base = .{
...@@ -1841,7 +1839,7 @@ const EmitZIR = struct {...@@ -1841,7 +1839,7 @@ const EmitZIR = struct {
1841 self.next_auto_name += 1;1839 self.next_auto_name += 1;
1842 const gop = try self.names.getOrPut(proposed_name);1840 const gop = try self.names.getOrPut(proposed_name);
1843 if (!gop.found_existing) {1841 if (!gop.found_existing) {
1844 gop.kv.value = {};1842 gop.entry.value = {};
1845 return proposed_name;1843 return proposed_name;
1846 }1844 }
1847 }1845 }
...@@ -1861,9 +1859,9 @@ const EmitZIR = struct {...@@ -1861,9 +1859,9 @@ const EmitZIR = struct {
1861 },1859 },
1862 .kw_args = .{},1860 .kw_args = .{},
1863 };1861 };
1864 gop.kv.value = try self.emitUnnamedDecl(&primitive_inst.base);1862 gop.entry.value = try self.emitUnnamedDecl(&primitive_inst.base);
1865 }1863 }
1866 return gop.kv.value;1864 return gop.entry.value;
1867 }1865 }
18681866
1869 fn emitStringLiteral(self: *EmitZIR, src: usize, str: []const u8) !*Decl {1867 fn emitStringLiteral(self: *EmitZIR, src: usize, str: []const u8) !*Decl {