aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2025-05-24 22:25:17 +0100
committermlugg <mlugg@mlugg.co.uk>2025-05-25 04:43:43 +0100
commitaeed5f9ebd02b376411f3ee82dd3222f9c3b6e85 (patch)
tree94dbee0a2039f286612c069b965f0875783121ba /src/Compilation.zig
parent35ba8d95a1afd0bebba3c32cf68990f5129fabfe (diff)
downloadzig-aeed5f9ebd02b376411f3ee82dd3222f9c3b6e85.tar.gz
zig-aeed5f9ebd02b376411f3ee82dd3222f9c3b6e85.zip
compiler: introduce incremental debug server
In a compiler built with debug extensions, pass `--debug-incremental` to spawn the "incremental debug server". This is a TCP server exposing a REPL which allows querying a bunch of compiler state, some of which is stored only when that flag is passed. Eventually, this will probably move into `std.zig.Server`/`std.zig.Client`, but this is easier to work with right now. The easiest way to interact with the server is `telnet`.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 6a546648b2..8f986a5cdf 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -190,6 +190,8 @@ time_report: bool,
stack_report: bool,
debug_compiler_runtime_libs: bool,
debug_compile_errors: bool,
+/// Do not check this field directly. Instead, use the `debugIncremental` wrapper function.
+debug_incremental: bool,
incremental: bool,
alloc_failure_occurred: bool = false,
last_update_was_cache_hit: bool = false,
@@ -768,6 +770,14 @@ pub const Directories = struct {
}
};
+/// This small wrapper function just checks whether debug extensions are enabled before checking
+/// `comp.debug_incremental`. It is inline so that comptime-known `false` propagates to the caller,
+/// preventing debugging features from making it into release builds of the compiler.
+pub inline fn debugIncremental(comp: *const Compilation) bool {
+ if (!build_options.enable_debug_extensions) return false;
+ return comp.debug_incremental;
+}
+
pub const default_stack_protector_buffer_size = target_util.default_stack_protector_buffer_size;
pub const SemaError = Zcu.SemaError;
@@ -1598,6 +1608,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
@@ -1968,6 +1979,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,
.root_name = root_name,
.sysroot = sysroot,