authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-09 23:52:36-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-15 19:06:39-07:00
loga4bb7c8bb17a4ac692401946df6b9f4cc3e5b1b2
tree8ee1dbaf12c60c57df253bafa18d624937365f49
parentf458192e56b13500ff6eb7c3e94dcf48240f4170

stage2: remove redundant source hash


2 files changed, 9 insertions(+), 29 deletions(-)

src/Compilation.zig+5-13
......@@ -1484,22 +1484,14 @@ pub fn update(self: *Compilation) !void {
14841484 continue;
14851485 }
14861486
1487 const prev_hash = file.source_hash;
1488 file.unloadSource(module.gpa);
1489 // TODO handle error here by populating a retryable compile error
1490 try file.finishGettingSource(module.gpa, f, stat);
1491 assert(file.source_loaded);
1492 if (mem.eql(u8, &prev_hash, &file.source_hash)) {
1493 file.updateTreeToNewSource();
1494 log.debug("unmodified source hash of file: {s}", .{file.sub_file_path});
1495 continue;
1496 }
1497
1498 log.debug("source contents changed: {s}", .{file.sub_file_path});
1487 log.debug("metadata changed: {s}", .{file.sub_file_path});
14991488 if (file.status == .unloaded_parse_failure) {
15001489 module.failed_files.swapRemove(file).?.value.destroy(module.gpa);
15011490 }
1502 file.unloadTree(module.gpa);
1491
1492 file.unload(module.gpa);
1493 // TODO handle error here by populating a retryable compile error
1494 try file.finishGettingSource(module.gpa, f, stat);
15031495
15041496 module.analyzeFile(file) catch |err| switch (err) {
15051497 error.OutOfMemory => return error.OutOfMemory,
src/Module.zig+4-16
......@@ -26,7 +26,6 @@ const trace = @import("tracy.zig").trace;
2626const AstGen = @import("AstGen.zig");
2727const Sema = @import("Sema.zig");
2828const target_util = @import("target.zig");
29const Cache = @import("Cache.zig");
3029
3130/// General-purpose allocator. Used for both temporary and long-term storage.
3231gpa: *Allocator,
......@@ -706,8 +705,6 @@ pub const Scope = struct {
706705 stat_inode: std.fs.File.INode,
707706 /// Whether this is populated depends on `status`.
708707 stat_mtime: i128,
709 /// Whether this is populated depends on `status`.
710 source_hash: Cache.BinDigest,
711708 /// Whether this is populated or not depends on `status`.
712709 tree: ast.Tree,
713710 /// Package that this file is a part of, managed externally.
......@@ -734,13 +731,6 @@ pub const Scope = struct {
734731 }
735732 }
736733
737 pub fn updateTreeToNewSource(file: *File) void {
738 assert(file.source_loaded);
739 if (file.status == .loaded_success) {
740 file.tree.source = file.source;
741 }
742 }
743
744734 pub fn deinit(file: *File, gpa: *Allocator) void {
745735 file.unload(gpa);
746736 file.* = undefined;
......@@ -781,14 +771,11 @@ pub const Scope = struct {
781771 return error.FileTooBig;
782772
783773 const source = try gpa.allocSentinel(u8, stat.size, 0);
774 errdefer gpa.free(source);
784775 const amt = try f.readAll(source);
785776 if (amt != stat.size)
786777 return error.UnexpectedEndOfFile;
787778
788 var hasher = Cache.hasher_init;
789 hasher.update(source);
790 hasher.final(&file.source_hash);
791
792779 file.stat_size = stat.size;
793780 file.stat_inode = stat.inode;
794781 file.stat_mtime = stat.mtime;
......@@ -3316,7 +3303,6 @@ pub fn importFile(mod: *Module, cur_pkg: *Package, import_string: []const u8) !*
33163303 new_file.* = .{
33173304 .sub_file_path = resolved_path,
33183305 .source = undefined,
3319 .source_hash = undefined,
33203306 .source_loaded = false,
33213307 .stat_size = undefined,
33223308 .stat_inode = undefined,
......@@ -3343,12 +3329,13 @@ pub fn importFile(mod: *Module, cur_pkg: *Package, import_string: []const u8) !*
33433329 .parent_name_hash = parent_name_hash,
33443330 .ty = Type.initTag(.type),
33453331 };
3332
33463333 const top_decl = try mod.createNewDecl(
33473334 &tmp_namespace,
33483335 resolved_path,
33493336 0,
33503337 parent_name_hash,
3351 new_file.source_hash,
3338 std.zig.hashSrc(tree.source),
33523339 );
33533340 defer {
33543341 mod.decl_table.removeAssertDiscard(parent_name_hash);
......@@ -3421,6 +3408,7 @@ pub fn importFile(mod: *Module, cur_pkg: *Package, import_string: []const u8) !*
34213408 const struct_ty = try val.toType(&gen_scope_arena.allocator);
34223409 const struct_decl = struct_ty.getOwnerDecl();
34233410
3411 struct_decl.contents_hash = top_decl.contents_hash;
34243412 new_file.namespace = struct_ty.getNamespace().?;
34253413 new_file.namespace.parent = null;
34263414 new_file.namespace.parent_name_hash = tmp_namespace.parent_name_hash;