aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-07-15 01:27:23 -0700
committerGitHub <noreply@github.com>2024-07-15 01:27:23 -0700
commit9d38e82b5c0f28ea6a2d8d31ebd73b6e2a8aad26 (patch)
treeba3290d61fd4c856f73a14b6346c674a1a178ffb /src
parent583e698256a2a26f26738c983e319d76926ef048 (diff)
parent445bd7a06fc34c9a59c6458774769bfaa2757a2f (diff)
downloadzig-9d38e82b5c0f28ea6a2d8d31ebd73b6e2a8aad26.tar.gz
zig-9d38e82b5c0f28ea6a2d8d31ebd73b6e2a8aad26.zip
Merge pull request #20633 from ziglang/long-live-zig
make zig compiler processes live across rebuilds
Diffstat (limited to 'src')
-rw-r--r--src/Compilation.zig9
-rw-r--r--src/Sema.zig12
-rw-r--r--src/Zcu.zig2
-rw-r--r--src/Zcu/PerThread.zig10
-rw-r--r--src/main.zig23
5 files changed, 35 insertions, 21 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index a785351df5..76dc42fc64 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -169,7 +169,7 @@ time_report: bool,
stack_report: bool,
debug_compiler_runtime_libs: bool,
debug_compile_errors: bool,
-debug_incremental: bool,
+incremental: bool,
job_queued_compiler_rt_lib: bool = false,
job_queued_compiler_rt_obj: bool = false,
job_queued_update_builtin_zig: bool,
@@ -1134,7 +1134,7 @@ pub const CreateOptions = struct {
verbose_llvm_cpu_features: bool = false,
debug_compiler_runtime_libs: bool = false,
debug_compile_errors: bool = false,
- debug_incremental: bool = false,
+ incremental: bool = false,
/// Normally when you create a `Compilation`, Zig will automatically build
/// and link in required dependencies, such as compiler-rt and libc. When
/// building such dependencies themselves, this flag must be set to avoid
@@ -1363,6 +1363,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
cache.addPrefix(.{ .path = null, .handle = std.fs.cwd() });
cache.addPrefix(options.zig_lib_directory);
cache.addPrefix(options.local_cache_directory);
+ cache.addPrefix(options.global_cache_directory);
errdefer cache.manifest_dir.close();
// This is shared hasher state common to zig source and all C source files.
@@ -1515,7 +1516,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
.test_name_prefix = options.test_name_prefix,
.debug_compiler_runtime_libs = options.debug_compiler_runtime_libs,
.debug_compile_errors = options.debug_compile_errors,
- .debug_incremental = options.debug_incremental,
+ .incremental = options.incremental,
.libcxx_abi_version = options.libcxx_abi_version,
.root_name = root_name,
.sysroot = sysroot,
@@ -2358,7 +2359,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
}
}
-fn appendFileSystemInput(
+pub fn appendFileSystemInput(
comp: *Compilation,
file_system_inputs: *std.ArrayListUnmanaged(u8),
root: Cache.Path,
diff --git a/src/Sema.zig b/src/Sema.zig
index fdaad29995..5c43c2e431 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -2726,7 +2726,7 @@ fn maybeRemoveOutdatedType(sema: *Sema, ty: InternPool.Index) !bool {
const pt = sema.pt;
const zcu = pt.zcu;
- if (!zcu.comp.debug_incremental) return false;
+ if (!zcu.comp.incremental) return false;
const decl_index = Type.fromInterned(ty).getOwnerDecl(zcu);
const decl_as_depender = AnalUnit.wrap(.{ .decl = decl_index });
@@ -2826,7 +2826,7 @@ fn zirStructDecl(
mod.declPtr(new_decl_index).owns_tv = true;
errdefer pt.abortAnonDecl(new_decl_index);
- if (pt.zcu.comp.debug_incremental) {
+ if (pt.zcu.comp.incremental) {
try ip.addDependency(
sema.gpa,
AnalUnit.wrap(.{ .decl = new_decl_index }),
@@ -3064,7 +3064,7 @@ fn zirEnumDecl(
new_decl.owns_tv = true;
errdefer if (!done) pt.abortAnonDecl(new_decl_index);
- if (pt.zcu.comp.debug_incremental) {
+ if (pt.zcu.comp.incremental) {
try mod.intern_pool.addDependency(
gpa,
AnalUnit.wrap(.{ .decl = new_decl_index }),
@@ -3331,7 +3331,7 @@ fn zirUnionDecl(
mod.declPtr(new_decl_index).owns_tv = true;
errdefer pt.abortAnonDecl(new_decl_index);
- if (pt.zcu.comp.debug_incremental) {
+ if (pt.zcu.comp.incremental) {
try mod.intern_pool.addDependency(
gpa,
AnalUnit.wrap(.{ .decl = new_decl_index }),
@@ -3421,7 +3421,7 @@ fn zirOpaqueDecl(
mod.declPtr(new_decl_index).owns_tv = true;
errdefer pt.abortAnonDecl(new_decl_index);
- if (pt.zcu.comp.debug_incremental) {
+ if (pt.zcu.comp.incremental) {
try ip.addDependency(
gpa,
AnalUnit.wrap(.{ .decl = new_decl_index }),
@@ -38104,7 +38104,7 @@ fn isKnownZigType(sema: *Sema, ref: Air.Inst.Ref, tag: std.builtin.TypeId) bool
pub fn declareDependency(sema: *Sema, dependee: InternPool.Dependee) !void {
const zcu = sema.pt.zcu;
- if (!zcu.comp.debug_incremental) return;
+ if (!zcu.comp.incremental) return;
// Avoid creating dependencies on ourselves. This situation can arise when we analyze the fields
// of a type and they use `@This()`. This dependency would be unnecessary, and in fact would
diff --git a/src/Zcu.zig b/src/Zcu.zig
index 15f418c6fe..36b4c95571 100644
--- a/src/Zcu.zig
+++ b/src/Zcu.zig
@@ -2679,7 +2679,7 @@ fn markTransitiveDependersPotentiallyOutdated(zcu: *Zcu, maybe_outdated: AnalUni
}
pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?AnalUnit {
- if (!zcu.comp.debug_incremental) return null;
+ if (!zcu.comp.incremental) return null;
if (zcu.outdated.count() == 0 and zcu.potentially_outdated.count() == 0) {
log.debug("findOutdatedToAnalyze: no outdated depender", .{});
diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig
index 59b6b6bf0b..c3f569cc7d 100644
--- a/src/Zcu/PerThread.zig
+++ b/src/Zcu/PerThread.zig
@@ -888,7 +888,7 @@ fn getFileRootStruct(
};
errdefer wip_ty.cancel(ip, pt.tid);
- if (zcu.comp.debug_incremental) {
+ if (zcu.comp.incremental) {
try ip.addDependency(
gpa,
InternPool.AnalUnit.wrap(.{ .decl = decl_index }),
@@ -1418,6 +1418,10 @@ pub fn importPkg(pt: Zcu.PerThread, mod: *Module) !Zcu.ImportFileResult {
const sub_file_path = try gpa.dupe(u8, mod.root_src_path);
errdefer gpa.free(sub_file_path);
+ const comp = zcu.comp;
+ if (comp.file_system_inputs) |fsi|
+ try comp.appendFileSystemInput(fsi, mod.root, sub_file_path);
+
const new_file = try gpa.create(Zcu.File);
errdefer gpa.destroy(new_file);
@@ -1527,6 +1531,10 @@ pub fn importFile(
resolved_root_path, resolved_path, sub_file_path, import_string,
});
+ const comp = zcu.comp;
+ if (comp.file_system_inputs) |fsi|
+ try comp.appendFileSystemInput(fsi, mod.root, sub_file_path);
+
const path_digest = zcu.computePathDigest(mod, sub_file_path);
const new_file_index = try ip.createFile(gpa, pt.tid, .{
.bin_digest = path_digest,
diff --git a/src/main.zig b/src/main.zig
index 06c20d514c..2b36c31865 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -404,6 +404,8 @@ const usage_build_generic =
\\ -h, --help Print this help and exit
\\ --color [auto|off|on] Enable or disable colored error messages
\\ -j<N> Limit concurrent jobs (default is to use all CPU cores)
+ \\ -fincremental Enable incremental compilation
+ \\ -fno-incremental Disable incremental compilation
\\ -femit-bin[=path] (default) Output machine code
\\ -fno-emit-bin Do not output machine code
\\ -femit-asm[=path] Output .s (assembly code)
@@ -642,7 +644,6 @@ const usage_build_generic =
\\ --debug-log [scope] Enable printing debug/info log messages for scope
\\ --debug-compile-errors Crash with helpful diagnostics at the first compile error
\\ --debug-link-snapshot Enable dumping of the linker's state in JSON format
- \\ --debug-incremental Enable experimental feature: incremental compilation
\\
;
@@ -904,7 +905,7 @@ fn buildOutputType(
var minor_subsystem_version: ?u16 = null;
var mingw_unicode_entry_point: bool = false;
var enable_link_snapshots: bool = false;
- var debug_incremental: bool = false;
+ var opt_incremental: ?bool = null;
var install_name: ?[]const u8 = null;
var hash_style: link.File.Elf.HashStyle = .both;
var entitlements: ?[]const u8 = null;
@@ -1357,8 +1358,10 @@ fn buildOutputType(
} else {
enable_link_snapshots = true;
}
- } else if (mem.eql(u8, arg, "--debug-incremental")) {
- debug_incremental = true;
+ } else if (mem.eql(u8, arg, "-fincremental")) {
+ opt_incremental = true;
+ } else if (mem.eql(u8, arg, "-fno-incremental")) {
+ opt_incremental = false;
} else if (mem.eql(u8, arg, "--entitlements")) {
entitlements = args_iter.nextOrFatal();
} else if (mem.eql(u8, arg, "-fcompiler-rt")) {
@@ -3225,6 +3228,8 @@ fn buildOutputType(
break :b .incremental;
};
+ const incremental = opt_incremental orelse false;
+
process.raiseFileDescriptorLimit();
var file_system_inputs: std.ArrayListUnmanaged(u8) = .{};
@@ -3336,7 +3341,7 @@ fn buildOutputType(
.cache_mode = cache_mode,
.subsystem = subsystem,
.debug_compile_errors = debug_compile_errors,
- .debug_incremental = debug_incremental,
+ .incremental = incremental,
.enable_link_snapshots = enable_link_snapshots,
.install_name = install_name,
.entitlements = entitlements,
@@ -3443,7 +3448,7 @@ fn buildOutputType(
updateModule(comp, color, root_prog_node) catch |err| switch (err) {
error.SemanticAnalyzeFail => {
assert(listen == .none);
- saveState(comp, debug_incremental);
+ saveState(comp, incremental);
process.exit(1);
},
else => |e| return e,
@@ -3451,7 +3456,7 @@ fn buildOutputType(
}
if (build_options.only_c) return cleanExit();
try comp.makeBinFileExecutable();
- saveState(comp, debug_incremental);
+ saveState(comp, incremental);
if (test_exec_args.items.len == 0 and target.ofmt == .c) default_exec_args: {
// Default to using `zig run` to execute the produced .c code from `zig test`.
@@ -4032,8 +4037,8 @@ fn createModule(
return mod;
}
-fn saveState(comp: *Compilation, debug_incremental: bool) void {
- if (debug_incremental) {
+fn saveState(comp: *Compilation, incremental: bool) void {
+ if (incremental) {
comp.saveState() catch |err| {
warn("unable to save incremental compilation state: {s}", .{@errorName(err)});
};