authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-02-04 17:46:04+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-02-04 19:17:20+00:00
log0784d389844a127248bb724352ce7101bc49784c
tree731c64a78aa6118823bb3579c679fea5a31b5900
parent0d8207c29236bf731f7d3bad189beb3a1e1b1d0c
signaturelock-open Commit is signed but in an unrecognized format.

compiler: lock incremental dependency tracking behind --debug-incremental

This logic (currently) has a non-trivial cost (particularly in terms of peak RSS) for tracking dependencies. Until incremental compilation is in use in the wild, it doesn't make sense for users to pay that cost.

4 files changed, 36 insertions(+), 21 deletions(-)

src/Compilation.zig+3
...@@ -156,6 +156,7 @@ time_report: bool,...@@ -156,6 +156,7 @@ time_report: bool,
156stack_report: bool,156stack_report: bool,
157debug_compiler_runtime_libs: bool,157debug_compiler_runtime_libs: bool,
158debug_compile_errors: bool,158debug_compile_errors: bool,
159debug_incremental: bool,
159job_queued_compiler_rt_lib: bool = false,160job_queued_compiler_rt_lib: bool = false,
160job_queued_compiler_rt_obj: bool = false,161job_queued_compiler_rt_obj: bool = false,
161job_queued_update_builtin_zig: bool,162job_queued_update_builtin_zig: bool,
...@@ -1079,6 +1080,7 @@ pub const CreateOptions = struct {...@@ -1079,6 +1080,7 @@ pub const CreateOptions = struct {
1079 verbose_llvm_cpu_features: bool = false,1080 verbose_llvm_cpu_features: bool = false,
1080 debug_compiler_runtime_libs: bool = false,1081 debug_compiler_runtime_libs: bool = false,
1081 debug_compile_errors: bool = false,1082 debug_compile_errors: bool = false,
1083 debug_incremental: bool = false,
1082 /// Normally when you create a `Compilation`, Zig will automatically build1084 /// Normally when you create a `Compilation`, Zig will automatically build
1083 /// and link in required dependencies, such as compiler-rt and libc. When1085 /// and link in required dependencies, such as compiler-rt and libc. When
1084 /// building such dependencies themselves, this flag must be set to avoid1086 /// building such dependencies themselves, this flag must be set to avoid
...@@ -1508,6 +1510,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil...@@ -1508,6 +1510,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
1508 .test_name_prefix = options.test_name_prefix,1510 .test_name_prefix = options.test_name_prefix,
1509 .debug_compiler_runtime_libs = options.debug_compiler_runtime_libs,1511 .debug_compiler_runtime_libs = options.debug_compiler_runtime_libs,
1510 .debug_compile_errors = options.debug_compile_errors,1512 .debug_compile_errors = options.debug_compile_errors,
1513 .debug_incremental = options.debug_incremental,
1511 .libcxx_abi_version = options.libcxx_abi_version,1514 .libcxx_abi_version = options.libcxx_abi_version,
1512 .root_name = root_name,1515 .root_name = root_name,
1513 .sysroot = sysroot,1516 .sysroot = sysroot,
src/Module.zig+2
...@@ -3139,6 +3139,8 @@ fn markDeclDependenciesPotentiallyOutdated(zcu: *Zcu, decl_index: Decl.Index) !v...@@ -3139,6 +3139,8 @@ fn markDeclDependenciesPotentiallyOutdated(zcu: *Zcu, decl_index: Decl.Index) !v
3139}3139}
31403140
3141pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.Depender {3141pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.Depender {
3142 if (!zcu.comp.debug_incremental) return null;
3143
3142 if (zcu.outdated.count() == 0 and zcu.potentially_outdated.count() == 0) {3144 if (zcu.outdated.count() == 0 and zcu.potentially_outdated.count() == 0) {
3143 log.debug("findOutdatedToAnalyze: no outdated depender", .{});3145 log.debug("findOutdatedToAnalyze: no outdated depender", .{});
3144 return null;3146 return null;
src/Sema.zig+30-21
...@@ -2788,11 +2788,13 @@ fn zirStructDecl(...@@ -2788,11 +2788,13 @@ fn zirStructDecl(
2788 new_decl.owns_tv = true;2788 new_decl.owns_tv = true;
2789 errdefer mod.abortAnonDecl(new_decl_index);2789 errdefer mod.abortAnonDecl(new_decl_index);
27902790
2791 try ip.addDependency(2791 if (sema.mod.comp.debug_incremental) {
2792 sema.gpa,2792 try ip.addDependency(
2793 InternPool.Depender.wrap(.{ .decl = new_decl_index }),2793 sema.gpa,
2794 .{ .src_hash = try ip.trackZir(sema.gpa, block.getFileScope(mod), inst) },2794 InternPool.Depender.wrap(.{ .decl = new_decl_index }),
2795 );2795 .{ .src_hash = try ip.trackZir(sema.gpa, block.getFileScope(mod), inst) },
2796 );
2797 }
27962798
2797 const new_namespace_index = try mod.createNamespace(.{2799 const new_namespace_index = try mod.createNamespace(.{
2798 .parent = block.namespace.toOptional(),2800 .parent = block.namespace.toOptional(),
...@@ -2978,11 +2980,13 @@ fn zirEnumDecl(...@@ -2978,11 +2980,13 @@ fn zirEnumDecl(
2978 new_decl.owns_tv = true;2980 new_decl.owns_tv = true;
2979 errdefer if (!done) mod.abortAnonDecl(new_decl_index);2981 errdefer if (!done) mod.abortAnonDecl(new_decl_index);
29802982
2981 try mod.intern_pool.addDependency(2983 if (sema.mod.comp.debug_incremental) {
2982 sema.gpa,2984 try mod.intern_pool.addDependency(
2983 InternPool.Depender.wrap(.{ .decl = new_decl_index }),2985 sema.gpa,
2984 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },2986 InternPool.Depender.wrap(.{ .decl = new_decl_index }),
2985 );2987 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },
2988 );
2989 }
29862990
2987 const new_namespace_index = try mod.createNamespace(.{2991 const new_namespace_index = try mod.createNamespace(.{
2988 .parent = block.namespace.toOptional(),2992 .parent = block.namespace.toOptional(),
...@@ -3237,11 +3241,13 @@ fn zirUnionDecl(...@@ -3237,11 +3241,13 @@ fn zirUnionDecl(
3237 new_decl.owns_tv = true;3241 new_decl.owns_tv = true;
3238 errdefer mod.abortAnonDecl(new_decl_index);3242 errdefer mod.abortAnonDecl(new_decl_index);
32393243
3240 try mod.intern_pool.addDependency(3244 if (sema.mod.comp.debug_incremental) {
3241 sema.gpa,3245 try mod.intern_pool.addDependency(
3242 InternPool.Depender.wrap(.{ .decl = new_decl_index }),3246 sema.gpa,
3243 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },3247 InternPool.Depender.wrap(.{ .decl = new_decl_index }),
3244 );3248 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },
3249 );
3250 }
32453251
3246 const new_namespace_index = try mod.createNamespace(.{3252 const new_namespace_index = try mod.createNamespace(.{
3247 .parent = block.namespace.toOptional(),3253 .parent = block.namespace.toOptional(),
...@@ -3336,11 +3342,13 @@ fn zirOpaqueDecl(...@@ -3336,11 +3342,13 @@ fn zirOpaqueDecl(
3336 new_decl.owns_tv = true;3342 new_decl.owns_tv = true;
3337 errdefer mod.abortAnonDecl(new_decl_index);3343 errdefer mod.abortAnonDecl(new_decl_index);
33383344
3339 try mod.intern_pool.addDependency(3345 if (sema.mod.comp.debug_incremental) {
3340 sema.gpa,3346 try mod.intern_pool.addDependency(
3341 InternPool.Depender.wrap(.{ .decl = new_decl_index }),3347 sema.gpa,
3342 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },3348 InternPool.Depender.wrap(.{ .decl = new_decl_index }),
3343 );3349 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },
3350 );
3351 }
33443352
3345 const new_namespace_index = try mod.createNamespace(.{3353 const new_namespace_index = try mod.createNamespace(.{
3346 .parent = block.namespace.toOptional(),3354 .parent = block.namespace.toOptional(),
...@@ -32435,7 +32443,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: InternPool.DeclIndex, analyze_fn...@@ -32435,7 +32443,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: InternPool.DeclIndex, analyze_fn
3243532443
32436 const decl = mod.declPtr(decl_index);32444 const decl = mod.declPtr(decl_index);
32437 const decl_tv = try decl.typedValue();32445 const decl_tv = try decl.typedValue();
32438 // TODO: if this is a `decl_ref`, only depend on decl type32446 // TODO: if this is a `decl_ref` of a non-variable decl, only depend on decl type
32439 try sema.declareDependency(.{ .decl_val = decl_index });32447 try sema.declareDependency(.{ .decl_val = decl_index });
32440 const ptr_ty = try sema.ptrType(.{32448 const ptr_ty = try sema.ptrType(.{
32441 .child = decl_tv.ty.toIntern(),32449 .child = decl_tv.ty.toIntern(),
...@@ -38925,6 +38933,7 @@ fn ptrType(sema: *Sema, info: InternPool.Key.PtrType) CompileError!Type {...@@ -38925,6 +38933,7 @@ fn ptrType(sema: *Sema, info: InternPool.Key.PtrType) CompileError!Type {
38925}38933}
3892638934
38927pub fn declareDependency(sema: *Sema, dependee: InternPool.Dependee) !void {38935pub fn declareDependency(sema: *Sema, dependee: InternPool.Dependee) !void {
38936 if (!sema.mod.comp.debug_incremental) return;
38928 const depender = InternPool.Depender.wrap(38937 const depender = InternPool.Depender.wrap(
38929 if (sema.owner_func_index != .none)38938 if (sema.owner_func_index != .none)
38930 .{ .func = sema.owner_func_index }38939 .{ .func = sema.owner_func_index }
src/main.zig+1
...@@ -3255,6 +3255,7 @@ fn buildOutputType(...@@ -3255,6 +3255,7 @@ fn buildOutputType(
3255 .cache_mode = cache_mode,3255 .cache_mode = cache_mode,
3256 .subsystem = subsystem,3256 .subsystem = subsystem,
3257 .debug_compile_errors = debug_compile_errors,3257 .debug_compile_errors = debug_compile_errors,
3258 .debug_incremental = debug_incremental,
3258 .enable_link_snapshots = enable_link_snapshots,3259 .enable_link_snapshots = enable_link_snapshots,
3259 .install_name = install_name,3260 .install_name = install_name,
3260 .entitlements = entitlements,3261 .entitlements = entitlements,