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 {...@@ -230,8 +230,7 @@ pub const Decl = struct {
230 const src_decl = module.decls[self.src_index];230 const src_decl = module.decls[self.src_index];
231 return src_decl.inst.src;231 return src_decl.inst.src;
232 },232 },
233 .file,233 .file, .block => unreachable,
234 .block => unreachable,
235 .gen_zir => unreachable,234 .gen_zir => unreachable,
236 .local_val => unreachable,235 .local_val => unreachable,
237 .local_ptr => unreachable,236 .local_ptr => unreachable,
...@@ -544,7 +543,7 @@ pub const Scope = struct {...@@ -544,7 +543,7 @@ pub const Scope = struct {
544 file_scope: *Scope.File,543 file_scope: *Scope.File,
545544
546 /// Direct children of the file.545 /// Direct children of the file.
547 decls: ArrayListUnmanaged(*Decl),546 decls: std.AutoArrayHashMapUnmanaged(*Decl, void),
548547
549 // TODO implement container types and put this in a status union548 // TODO implement container types and put this in a status union
550 // ty: Type549 // ty: Type
...@@ -555,12 +554,7 @@ pub const Scope = struct {...@@ -555,12 +554,7 @@ pub const Scope = struct {
555 }554 }
556555
557 pub fn removeDecl(self: *Container, child: *Decl) void {556 pub fn removeDecl(self: *Container, child: *Decl) void {
558 for (self.decls.items) |item, i| {557 _ = self.decls.remove(child);
559 if (item == child) {
560 _ = self.decls.swapRemove(i);
561 return;
562 }
563 }
564 }558 }
565559
566 pub fn fullyQualifiedNameHash(self: *Container, name: []const u8) NameHash {560 pub fn fullyQualifiedNameHash(self: *Container, name: []const u8) NameHash {
...@@ -1796,9 +1790,9 @@ fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void {...@@ -1796,9 +1790,9 @@ fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void {
1796 // we know which ones have been deleted.1790 // we know which ones have been deleted.
1797 var deleted_decls = std.AutoArrayHashMap(*Decl, void).init(self.gpa);1791 var deleted_decls = std.AutoArrayHashMap(*Decl, void).init(self.gpa);
1798 defer deleted_decls.deinit();1792 defer deleted_decls.deinit();
1799 try deleted_decls.ensureCapacity(container_scope.decls.items.len);1793 try deleted_decls.ensureCapacity(container_scope.decls.items().len);
1800 for (container_scope.decls.items) |file_decl| {1794 for (container_scope.decls.items()) |entry| {
1801 deleted_decls.putAssumeCapacityNoClobber(file_decl, {});1795 deleted_decls.putAssumeCapacityNoClobber(entry.key, {});
1802 }1796 }
18031797
1804 for (decls) |src_decl, decl_i| {1798 for (decls) |src_decl, decl_i| {
...@@ -1839,7 +1833,7 @@ fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void {...@@ -1839,7 +1833,7 @@ fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void {
1839 }1833 }
1840 } else {1834 } else {
1841 const new_decl = try self.createNewDecl(&container_scope.base, name, decl_i, name_hash, contents_hash);1835 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, {});
1843 if (fn_proto.getExternExportInlineToken()) |maybe_export_token| {1837 if (fn_proto.getExternExportInlineToken()) |maybe_export_token| {
1844 if (tree.token_ids[maybe_export_token] == .Keyword_export) {1838 if (tree.token_ids[maybe_export_token] == .Keyword_export) {
1845 self.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = new_decl });1839 self.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = new_decl });
...@@ -1866,7 +1860,7 @@ fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void {...@@ -1866,7 +1860,7 @@ fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void {
1866 }1860 }
1867 } else {1861 } else {
1868 const new_decl = try self.createNewDecl(&container_scope.base, name, decl_i, name_hash, contents_hash);1862 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, {});
1870 if (var_decl.getExternExportToken()) |maybe_export_token| {1864 if (var_decl.getExternExportToken()) |maybe_export_token| {
1871 if (tree.token_ids[maybe_export_token] == .Keyword_export) {1865 if (tree.token_ids[maybe_export_token] == .Keyword_export) {
1872 self.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = new_decl });1866 self.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = new_decl });
...@@ -1882,7 +1876,7 @@ fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void {...@@ -1882,7 +1876,7 @@ fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void {
1882 const contents_hash = std.zig.hashSrc(tree.getNodeSource(src_decl));1876 const contents_hash = std.zig.hashSrc(tree.getNodeSource(src_decl));
18831877
1884 const new_decl = try self.createNewDecl(&container_scope.base, name, decl_i, name_hash, contents_hash);1878 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, {});
1886 self.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = new_decl });1880 self.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = new_decl });
1887 } else if (src_decl.castTag(.ContainerField)) |container_field| {1881 } else if (src_decl.castTag(.ContainerField)) |container_field| {
1888 log.err("TODO: analyze container field", .{});1882 log.err("TODO: analyze container field", .{});