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,
156156stack_report: bool,
157157debug_compiler_runtime_libs: bool,
158158debug_compile_errors: bool,
159debug_incremental: bool,
159160job_queued_compiler_rt_lib: bool = false,
160161job_queued_compiler_rt_obj: bool = false,
161162job_queued_update_builtin_zig: bool,
......@@ -1079,6 +1080,7 @@ pub const CreateOptions = struct {
10791080 verbose_llvm_cpu_features: bool = false,
10801081 debug_compiler_runtime_libs: bool = false,
10811082 debug_compile_errors: bool = false,
1083 debug_incremental: bool = false,
10821084 /// Normally when you create a `Compilation`, Zig will automatically build
10831085 /// and link in required dependencies, such as compiler-rt and libc. When
10841086 /// 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
15081510 .test_name_prefix = options.test_name_prefix,
15091511 .debug_compiler_runtime_libs = options.debug_compiler_runtime_libs,
15101512 .debug_compile_errors = options.debug_compile_errors,
1513 .debug_incremental = options.debug_incremental,
15111514 .libcxx_abi_version = options.libcxx_abi_version,
15121515 .root_name = root_name,
15131516 .sysroot = sysroot,
src/Module.zig+2
......@@ -3139,6 +3139,8 @@ fn markDeclDependenciesPotentiallyOutdated(zcu: *Zcu, decl_index: Decl.Index) !v
31393139}
31403140
31413141pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.Depender {
3142 if (!zcu.comp.debug_incremental) return null;
3143
31423144 if (zcu.outdated.count() == 0 and zcu.potentially_outdated.count() == 0) {
31433145 log.debug("findOutdatedToAnalyze: no outdated depender", .{});
31443146 return null;
src/Sema.zig+30-21
......@@ -2788,11 +2788,13 @@ fn zirStructDecl(
27882788 new_decl.owns_tv = true;
27892789 errdefer mod.abortAnonDecl(new_decl_index);
27902790
2791 try ip.addDependency(
2792 sema.gpa,
2793 InternPool.Depender.wrap(.{ .decl = new_decl_index }),
2794 .{ .src_hash = try ip.trackZir(sema.gpa, block.getFileScope(mod), inst) },
2795 );
2791 if (sema.mod.comp.debug_incremental) {
2792 try ip.addDependency(
2793 sema.gpa,
2794 InternPool.Depender.wrap(.{ .decl = new_decl_index }),
2795 .{ .src_hash = try ip.trackZir(sema.gpa, block.getFileScope(mod), inst) },
2796 );
2797 }
27962798
27972799 const new_namespace_index = try mod.createNamespace(.{
27982800 .parent = block.namespace.toOptional(),
......@@ -2978,11 +2980,13 @@ fn zirEnumDecl(
29782980 new_decl.owns_tv = true;
29792981 errdefer if (!done) mod.abortAnonDecl(new_decl_index);
29802982
2981 try mod.intern_pool.addDependency(
2982 sema.gpa,
2983 InternPool.Depender.wrap(.{ .decl = new_decl_index }),
2984 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },
2985 );
2983 if (sema.mod.comp.debug_incremental) {
2984 try mod.intern_pool.addDependency(
2985 sema.gpa,
2986 InternPool.Depender.wrap(.{ .decl = new_decl_index }),
2987 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },
2988 );
2989 }
29862990
29872991 const new_namespace_index = try mod.createNamespace(.{
29882992 .parent = block.namespace.toOptional(),
......@@ -3237,11 +3241,13 @@ fn zirUnionDecl(
32373241 new_decl.owns_tv = true;
32383242 errdefer mod.abortAnonDecl(new_decl_index);
32393243
3240 try mod.intern_pool.addDependency(
3241 sema.gpa,
3242 InternPool.Depender.wrap(.{ .decl = new_decl_index }),
3243 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },
3244 );
3244 if (sema.mod.comp.debug_incremental) {
3245 try mod.intern_pool.addDependency(
3246 sema.gpa,
3247 InternPool.Depender.wrap(.{ .decl = new_decl_index }),
3248 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },
3249 );
3250 }
32453251
32463252 const new_namespace_index = try mod.createNamespace(.{
32473253 .parent = block.namespace.toOptional(),
......@@ -3336,11 +3342,13 @@ fn zirOpaqueDecl(
33363342 new_decl.owns_tv = true;
33373343 errdefer mod.abortAnonDecl(new_decl_index);
33383344
3339 try mod.intern_pool.addDependency(
3340 sema.gpa,
3341 InternPool.Depender.wrap(.{ .decl = new_decl_index }),
3342 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },
3343 );
3345 if (sema.mod.comp.debug_incremental) {
3346 try mod.intern_pool.addDependency(
3347 sema.gpa,
3348 InternPool.Depender.wrap(.{ .decl = new_decl_index }),
3349 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },
3350 );
3351 }
33443352
33453353 const new_namespace_index = try mod.createNamespace(.{
33463354 .parent = block.namespace.toOptional(),
......@@ -32435,7 +32443,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: InternPool.DeclIndex, analyze_fn
3243532443
3243632444 const decl = mod.declPtr(decl_index);
3243732445 const decl_tv = try decl.typedValue();
32438 // TODO: if this is a `decl_ref`, only depend on decl type
32446 // TODO: if this is a `decl_ref` of a non-variable decl, only depend on decl type
3243932447 try sema.declareDependency(.{ .decl_val = decl_index });
3244032448 const ptr_ty = try sema.ptrType(.{
3244132449 .child = decl_tv.ty.toIntern(),
......@@ -38925,6 +38933,7 @@ fn ptrType(sema: *Sema, info: InternPool.Key.PtrType) CompileError!Type {
3892538933}
3892638934
3892738935pub fn declareDependency(sema: *Sema, dependee: InternPool.Dependee) !void {
38936 if (!sema.mod.comp.debug_incremental) return;
3892838937 const depender = InternPool.Depender.wrap(
3892938938 if (sema.owner_func_index != .none)
3893038939 .{ .func = sema.owner_func_index }
src/main.zig+1
......@@ -3255,6 +3255,7 @@ fn buildOutputType(
32553255 .cache_mode = cache_mode,
32563256 .subsystem = subsystem,
32573257 .debug_compile_errors = debug_compile_errors,
3258 .debug_incremental = debug_incremental,
32583259 .enable_link_snapshots = enable_link_snapshots,
32593260 .install_name = install_name,
32603261 .entitlements = entitlements,