authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-03 15:02:38-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-03 15:02:38-07:00
log17f36566de1cf549907d20dfd963596784691c73
tree9abc926510af3bc78fe7e01d37f8239e217d2e59
parentf2bbd8a548c9a707aa121c58fe8c8a97666b84f2

stage2: upgrade Scope.Container decls from ArrayList to HashMap


1 files changed, 9 insertions(+), 15 deletions(-)

src-self-hosted/Module.zig+9-15
......@@ -230,8 +230,7 @@ pub const Decl = struct {
230230 const src_decl = module.decls[self.src_index];
231231 return src_decl.inst.src;
232232 },
233 .file,
234 .block => unreachable,
233 .file, .block => unreachable,
235234 .gen_zir => unreachable,
236235 .local_val => unreachable,
237236 .local_ptr => unreachable,
......@@ -544,7 +543,7 @@ pub const Scope = struct {
544543 file_scope: *Scope.File,
545544
546545 /// Direct children of the file.
547 decls: ArrayListUnmanaged(*Decl),
546 decls: std.AutoArrayHashMapUnmanaged(*Decl, void),
548547
549548 // TODO implement container types and put this in a status union
550549 // ty: Type
......@@ -555,12 +554,7 @@ pub const Scope = struct {
555554 }
556555
557556 pub fn removeDecl(self: *Container, child: *Decl) void {
558 for (self.decls.items) |item, i| {
559 if (item == child) {
560 _ = self.decls.swapRemove(i);
561 return;
562 }
563 }
557 _ = self.decls.remove(child);
564558 }
565559
566560 pub fn fullyQualifiedNameHash(self: *Container, name: []const u8) NameHash {
......@@ -1796,9 +1790,9 @@ fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void {
17961790 // we know which ones have been deleted.
17971791 var deleted_decls = std.AutoArrayHashMap(*Decl, void).init(self.gpa);
17981792 defer deleted_decls.deinit();
1799 try deleted_decls.ensureCapacity(container_scope.decls.items.len);
1800 for (container_scope.decls.items) |file_decl| {
1801 deleted_decls.putAssumeCapacityNoClobber(file_decl, {});
1793 try deleted_decls.ensureCapacity(container_scope.decls.items().len);
1794 for (container_scope.decls.items()) |entry| {
1795 deleted_decls.putAssumeCapacityNoClobber(entry.key, {});
18021796 }
18031797
18041798 for (decls) |src_decl, decl_i| {
......@@ -1839,7 +1833,7 @@ fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void {
18391833 }
18401834 } else {
18411835 const new_decl = try self.createNewDecl(&container_scope.base, name, decl_i, name_hash, contents_hash);
1842 container_scope.decls.appendAssumeCapacity(new_decl);
1836 container_scope.decls.putAssumeCapacity(new_decl, {});
18431837 if (fn_proto.getExternExportInlineToken()) |maybe_export_token| {
18441838 if (tree.token_ids[maybe_export_token] == .Keyword_export) {
18451839 self.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = new_decl });
......@@ -1866,7 +1860,7 @@ fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void {
18661860 }
18671861 } else {
18681862 const new_decl = try self.createNewDecl(&container_scope.base, name, decl_i, name_hash, contents_hash);
1869 container_scope.decls.appendAssumeCapacity(new_decl);
1863 container_scope.decls.putAssumeCapacity(new_decl, {});
18701864 if (var_decl.getExternExportToken()) |maybe_export_token| {
18711865 if (tree.token_ids[maybe_export_token] == .Keyword_export) {
18721866 self.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = new_decl });
......@@ -1882,7 +1876,7 @@ fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void {
18821876 const contents_hash = std.zig.hashSrc(tree.getNodeSource(src_decl));
18831877
18841878 const new_decl = try self.createNewDecl(&container_scope.base, name, decl_i, name_hash, contents_hash);
1885 container_scope.decls.appendAssumeCapacity(new_decl);
1879 container_scope.decls.putAssumeCapacity(new_decl, {});
18861880 self.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = new_decl });
18871881 } else if (src_decl.castTag(.ContainerField)) |container_field| {
18881882 log.err("TODO: analyze container field", .{});