authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-24 21:52:37-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-24 21:52:37-07:00
log67463c4357d0d0f43b8962231659fb8a1cc4869a
treea0530424b2ddc645faee6ccf88c89cebfed10fef
parent4f0850fe285937e37a7e9260c399867d3f61a487

correct `@cImport` caching to handle "unhit" case

if you hit() you have to unhit() to get the same digest if you don't end up treating it as a hit.

1 files changed, 11 insertions(+), 2 deletions(-)

src/Compilation.zig+11-2
...@@ -1242,7 +1242,16 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {...@@ -1242,7 +1242,16 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
12421242
1243 // If the previous invocation resulted in clang errors, we will see a hit1243 // If the previous invocation resulted in clang errors, we will see a hit
1244 // here with 0 files in the manifest, in which case it is actually a miss.1244 // here with 0 files in the manifest, in which case it is actually a miss.
1245 const actual_hit = (try man.hit()) and man.files.items.len != 0;1245 // We need to "unhit" in this case, to keep the digests matching.
1246 const prev_hash_state = man.hash.peekBin();
1247 const actual_hit = hit: {
1248 const is_hit = try man.hit();
1249 if (man.files.items.len == 0) {
1250 man.unhit(prev_hash_state, 0);
1251 break :hit false;
1252 }
1253 break :hit true;
1254 };
1246 const digest = if (!actual_hit) digest: {1255 const digest = if (!actual_hit) digest: {
1247 var arena_allocator = std.heap.ArenaAllocator.init(comp.gpa);1256 var arena_allocator = std.heap.ArenaAllocator.init(comp.gpa);
1248 defer arena_allocator.deinit();1257 defer arena_allocator.deinit();
...@@ -1396,7 +1405,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void {...@@ -1396,7 +1405,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void {
1396 mem.split(c_source_basename, ".").next().?;1405 mem.split(c_source_basename, ".").next().?;
1397 const o_basename = try std.fmt.allocPrint(arena, "{}{}", .{ o_basename_noext, comp.getTarget().oFileExt() });1406 const o_basename = try std.fmt.allocPrint(arena, "{}{}", .{ o_basename_noext, comp.getTarget().oFileExt() });
13981407
1399 const digest = if ((try man.hit()) and !comp.disable_c_depfile) man.final() else blk: {1408 const digest = if (!comp.disable_c_depfile and try man.hit()) man.final() else blk: {
1400 var argv = std.ArrayList([]const u8).init(comp.gpa);1409 var argv = std.ArrayList([]const u8).init(comp.gpa);
1401 defer argv.deinit();1410 defer argv.deinit();
14021411