authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-11-24 11:58:24-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-11-24 14:34:18-08:00
logece62a0223cfad5e49a5c75a944a21e735a01a05
tree225c943cd10757137362c4073244d8e4d294ff19
parent3f34f5e43349214c862882a83bd951701a6c735f

frontend: introduce error.Canceled


7 files changed, 55 insertions(+), 35 deletions(-)

src/Compilation.zig+15-15
...@@ -2851,6 +2851,7 @@ fn cleanupAfterUpdate(comp: *Compilation, tmp_dir_rand_int: u64) void {...@@ -2851,6 +2851,7 @@ fn cleanupAfterUpdate(comp: *Compilation, tmp_dir_rand_int: u64) void {
28512851
2852pub const UpdateError = error{2852pub const UpdateError = error{
2853 OutOfMemory,2853 OutOfMemory,
2854 Canceled,
2854 Unexpected,2855 Unexpected,
2855 CurrentWorkingDirectoryUnlinked,2856 CurrentWorkingDirectoryUnlinked,
2856};2857};
...@@ -2930,6 +2931,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE...@@ -2930,6 +2931,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
2930 },2931 },
2931 },2932 },
2932 error.OutOfMemory => return error.OutOfMemory,2933 error.OutOfMemory => return error.OutOfMemory,
2934 error.Canceled => return error.Canceled,
2933 error.InvalidFormat => return comp.setMiscFailure(2935 error.InvalidFormat => return comp.setMiscFailure(
2934 .check_whole_cache,2936 .check_whole_cache,
2935 "failed to check cache: invalid manifest file format",2937 "failed to check cache: invalid manifest file format",
...@@ -5010,7 +5012,7 @@ fn performAllTheWork(...@@ -5010,7 +5012,7 @@ fn performAllTheWork(
5010 }5012 }
5011}5013}
50125014
5013const JobError = Allocator.Error;5015const JobError = Allocator.Error || Io.Cancelable;
50145016
5015pub fn queueJob(comp: *Compilation, job: Job) !void {5017pub fn queueJob(comp: *Compilation, job: Job) !void {
5016 try comp.work_queues[Job.stage(job)].pushBack(comp.gpa, job);5018 try comp.work_queues[Job.stage(job)].pushBack(comp.gpa, job);
...@@ -5117,6 +5119,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {...@@ -5117,6 +5119,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {
51175119
5118 pt.ensureFuncBodyUpToDate(func) catch |err| switch (err) {5120 pt.ensureFuncBodyUpToDate(func) catch |err| switch (err) {
5119 error.OutOfMemory => |e| return e,5121 error.OutOfMemory => |e| return e,
5122 error.Canceled => |e| return e,
5120 error.AnalysisFail => return,5123 error.AnalysisFail => return,
5121 };5124 };
5122 },5125 },
...@@ -5137,6 +5140,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {...@@ -5137,6 +5140,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {
5137 };5140 };
5138 maybe_err catch |err| switch (err) {5141 maybe_err catch |err| switch (err) {
5139 error.OutOfMemory => |e| return e,5142 error.OutOfMemory => |e| return e,
5143 error.Canceled => |e| return e,
5140 error.AnalysisFail => return,5144 error.AnalysisFail => return,
5141 };5145 };
51425146
...@@ -5166,7 +5170,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {...@@ -5166,7 +5170,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {
5166 const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));5170 const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
5167 defer pt.deactivate();5171 defer pt.deactivate();
5168 Type.fromInterned(ty).resolveFully(pt) catch |err| switch (err) {5172 Type.fromInterned(ty).resolveFully(pt) catch |err| switch (err) {
5169 error.OutOfMemory => return error.OutOfMemory,5173 error.OutOfMemory, error.Canceled => |e| return e,
5170 error.AnalysisFail => return,5174 error.AnalysisFail => return,
5171 };5175 };
5172 },5176 },
...@@ -5177,7 +5181,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {...@@ -5177,7 +5181,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {
5177 const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));5181 const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid));
5178 defer pt.deactivate();5182 defer pt.deactivate();
5179 pt.semaMod(mod) catch |err| switch (err) {5183 pt.semaMod(mod) catch |err| switch (err) {
5180 error.OutOfMemory => return error.OutOfMemory,5184 error.OutOfMemory, error.Canceled => |e| return e,
5181 error.AnalysisFail => return,5185 error.AnalysisFail => return,
5182 };5186 };
5183 },5187 },
...@@ -5190,8 +5194,8 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {...@@ -5190,8 +5194,8 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job) JobError!void {
5190 // TODO Surface more error details.5194 // TODO Surface more error details.
5191 comp.lockAndSetMiscFailure(5195 comp.lockAndSetMiscFailure(
5192 .windows_import_lib,5196 .windows_import_lib,
5193 "unable to generate DLL import .lib file for {s}: {s}",5197 "unable to generate DLL import .lib file for {s}: {t}",
5194 .{ link_lib, @errorName(err) },5198 .{ link_lib, err },
5195 );5199 );
5196 };5200 };
5197 },5201 },
...@@ -6066,14 +6070,10 @@ fn buildLibZigC(comp: *Compilation, prog_node: std.Progress.Node) void {...@@ -6066,14 +6070,10 @@ fn buildLibZigC(comp: *Compilation, prog_node: std.Progress.Node) void {
6066 };6070 };
6067}6071}
60686072
6069fn reportRetryableCObjectError(6073fn reportRetryableCObjectError(comp: *Compilation, c_object: *CObject, err: anyerror) error{OutOfMemory}!void {
6070 comp: *Compilation,
6071 c_object: *CObject,
6072 err: anyerror,
6073) error{OutOfMemory}!void {
6074 c_object.status = .failure_retryable;6074 c_object.status = .failure_retryable;
60756075
6076 switch (comp.failCObj(c_object, "{s}", .{@errorName(err)})) {6076 switch (comp.failCObj(c_object, "{t}", .{err})) {
6077 error.AnalysisFail => return,6077 error.AnalysisFail => return,
6078 else => |e| return e,6078 else => |e| return e,
6079 }6079 }
...@@ -7317,7 +7317,7 @@ fn failCObj(...@@ -7317,7 +7317,7 @@ fn failCObj(
7317 c_object: *CObject,7317 c_object: *CObject,
7318 comptime format: []const u8,7318 comptime format: []const u8,
7319 args: anytype,7319 args: anytype,
7320) SemaError {7320) error{ OutOfMemory, AnalysisFail } {
7321 @branchHint(.cold);7321 @branchHint(.cold);
7322 const diag_bundle = blk: {7322 const diag_bundle = blk: {
7323 const diag_bundle = try comp.gpa.create(CObject.Diag.Bundle);7323 const diag_bundle = try comp.gpa.create(CObject.Diag.Bundle);
...@@ -7341,7 +7341,7 @@ fn failCObjWithOwnedDiagBundle(...@@ -7341,7 +7341,7 @@ fn failCObjWithOwnedDiagBundle(
7341 comp: *Compilation,7341 comp: *Compilation,
7342 c_object: *CObject,7342 c_object: *CObject,
7343 diag_bundle: *CObject.Diag.Bundle,7343 diag_bundle: *CObject.Diag.Bundle,
7344) SemaError {7344) error{ OutOfMemory, AnalysisFail } {
7345 @branchHint(.cold);7345 @branchHint(.cold);
7346 assert(diag_bundle.diags.len > 0);7346 assert(diag_bundle.diags.len > 0);
7347 {7347 {
...@@ -7357,7 +7357,7 @@ fn failCObjWithOwnedDiagBundle(...@@ -7357,7 +7357,7 @@ fn failCObjWithOwnedDiagBundle(
7357 return error.AnalysisFail;7357 return error.AnalysisFail;
7358}7358}
73597359
7360fn failWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, comptime format: []const u8, args: anytype) SemaError {7360fn failWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, comptime format: []const u8, args: anytype) error{ OutOfMemory, AnalysisFail } {
7361 @branchHint(.cold);7361 @branchHint(.cold);
7362 var bundle: ErrorBundle.Wip = undefined;7362 var bundle: ErrorBundle.Wip = undefined;
7363 try bundle.init(comp.gpa);7363 try bundle.init(comp.gpa);
...@@ -7384,7 +7384,7 @@ fn failWin32ResourceWithOwnedBundle(...@@ -7384,7 +7384,7 @@ fn failWin32ResourceWithOwnedBundle(
7384 comp: *Compilation,7384 comp: *Compilation,
7385 win32_resource: *Win32Resource,7385 win32_resource: *Win32Resource,
7386 err_bundle: ErrorBundle,7386 err_bundle: ErrorBundle,
7387) SemaError {7387) error{ OutOfMemory, AnalysisFail } {
7388 @branchHint(.cold);7388 @branchHint(.cold);
7389 {7389 {
7390 comp.mutex.lock();7390 comp.mutex.lock();
src/Sema.zig+8-6
...@@ -6696,7 +6696,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref...@@ -6696,7 +6696,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
6696 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) {6696 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) {
6697 error.AnalysisFail => @panic("std.builtin.StackTrace is corrupt"),6697 error.AnalysisFail => @panic("std.builtin.StackTrace is corrupt"),
6698 error.ComptimeReturn, error.ComptimeBreak => unreachable,6698 error.ComptimeReturn, error.ComptimeBreak => unreachable,
6699 error.OutOfMemory => |e| return e,6699 error.OutOfMemory, error.Canceled => |e| return e,
6700 };6700 };
67016701
6702 return try block.addInst(.{6702 return try block.addInst(.{
...@@ -13924,6 +13924,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -13924,6 +13924,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
13924 return sema.fail(block, operand_src, "unable to resolve '{s}': working directory has been unlinked", .{name});13924 return sema.fail(block, operand_src, "unable to resolve '{s}': working directory has been unlinked", .{name});
13925 },13925 },
13926 error.OutOfMemory => |e| return e,13926 error.OutOfMemory => |e| return e,
13927 error.Canceled => |e| return e,
13927 };13928 };
13928 try sema.declareDependency(.{ .embed_file = ef_idx });13929 try sema.declareDependency(.{ .embed_file = ef_idx });
1392913930
...@@ -34345,7 +34346,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -34345,7 +34346,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3434534346
34346 if (struct_type.layout == .@"packed") {34347 if (struct_type.layout == .@"packed") {
34347 sema.backingIntType(struct_type) catch |err| switch (err) {34348 sema.backingIntType(struct_type) catch |err| switch (err) {
34348 error.OutOfMemory, error.AnalysisFail => |e| return e,34349 error.AnalysisFail, error.OutOfMemory, error.Canceled => |e| return e,
34349 error.ComptimeBreak, error.ComptimeReturn => unreachable,34350 error.ComptimeBreak, error.ComptimeReturn => unreachable,
34350 };34351 };
34351 return;34352 return;
...@@ -34893,7 +34894,7 @@ pub fn resolveStructFieldTypes(...@@ -34893,7 +34894,7 @@ pub fn resolveStructFieldTypes(
34893 defer tracked_unit.end(zcu);34894 defer tracked_unit.end(zcu);
3489434895
34895 sema.structFields(struct_type) catch |err| switch (err) {34896 sema.structFields(struct_type) catch |err| switch (err) {
34896 error.AnalysisFail, error.OutOfMemory => |e| return e,34897 error.AnalysisFail, error.OutOfMemory, error.Canceled => |e| return e,
34897 error.ComptimeBreak, error.ComptimeReturn => unreachable,34898 error.ComptimeBreak, error.ComptimeReturn => unreachable,
34898 };34899 };
34899}34900}
...@@ -34926,7 +34927,7 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) SemaError!void {...@@ -34926,7 +34927,7 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) SemaError!void {
34926 defer tracked_unit.end(zcu);34927 defer tracked_unit.end(zcu);
3492734928
34928 sema.structFieldInits(struct_type) catch |err| switch (err) {34929 sema.structFieldInits(struct_type) catch |err| switch (err) {
34929 error.AnalysisFail, error.OutOfMemory => |e| return e,34930 error.AnalysisFail, error.OutOfMemory, error.Canceled => |e| return e,
34930 error.ComptimeBreak, error.ComptimeReturn => unreachable,34931 error.ComptimeBreak, error.ComptimeReturn => unreachable,
34931 };34932 };
34932 struct_type.setHaveFieldInits(ip);34933 struct_type.setHaveFieldInits(ip);
...@@ -34960,7 +34961,7 @@ pub fn resolveUnionFieldTypes(sema: *Sema, ty: Type, union_type: InternPool.Load...@@ -34960,7 +34961,7 @@ pub fn resolveUnionFieldTypes(sema: *Sema, ty: Type, union_type: InternPool.Load
34960 union_type.setStatus(ip, .field_types_wip);34961 union_type.setStatus(ip, .field_types_wip);
34961 errdefer union_type.setStatus(ip, .none);34962 errdefer union_type.setStatus(ip, .none);
34962 sema.unionFields(ty.toIntern(), union_type) catch |err| switch (err) {34963 sema.unionFields(ty.toIntern(), union_type) catch |err| switch (err) {
34963 error.AnalysisFail, error.OutOfMemory => |e| return e,34964 error.AnalysisFail, error.OutOfMemory, error.Canceled => |e| return e,
34964 error.ComptimeBreak, error.ComptimeReturn => unreachable,34965 error.ComptimeBreak, error.ComptimeReturn => unreachable,
34965 };34966 };
34966 union_type.setStatus(ip, .have_field_types);34967 union_type.setStatus(ip, .have_field_types);
...@@ -37027,6 +37028,7 @@ fn notePathToComptimeAllocPtr(...@@ -37027,6 +37028,7 @@ fn notePathToComptimeAllocPtr(
3702737028
37028 const derivation = comptime_ptr.pointerDerivationAdvanced(arena, pt, false, sema) catch |err| switch (err) {37029 const derivation = comptime_ptr.pointerDerivationAdvanced(arena, pt, false, sema) catch |err| switch (err) {
37029 error.OutOfMemory => |e| return e,37030 error.OutOfMemory => |e| return e,
37031 error.Canceled => @panic("TODO"), // pls don't be cancelable mlugg
37030 error.AnalysisFail => unreachable,37032 error.AnalysisFail => unreachable,
37031 };37033 };
3703237034
...@@ -37367,7 +37369,7 @@ pub fn resolveDeclaredEnum(...@@ -37367,7 +37369,7 @@ pub fn resolveDeclaredEnum(
37367 ) catch |err| switch (err) {37369 ) catch |err| switch (err) {
37368 error.ComptimeBreak => unreachable,37370 error.ComptimeBreak => unreachable,
37369 error.ComptimeReturn => unreachable,37371 error.ComptimeReturn => unreachable,
37370 error.OutOfMemory => |e| return e,37372 error.OutOfMemory, error.Canceled => |e| return e,
37371 error.AnalysisFail => {37373 error.AnalysisFail => {
37372 if (!zcu.failed_analysis.contains(sema.owner)) {37374 if (!zcu.failed_analysis.contains(sema.owner)) {
37373 try zcu.transitive_failed_analysis.put(gpa, sema.owner, {});37375 try zcu.transitive_failed_analysis.put(gpa, sema.owner, {});
src/Type.zig+2-1
...@@ -3837,7 +3837,7 @@ fn resolveStructInner(...@@ -3837,7 +3837,7 @@ fn resolveStructInner(
3837 }3837 }
3838 return error.AnalysisFail;3838 return error.AnalysisFail;
3839 },3839 },
3840 error.OutOfMemory => |e| return e,3840 error.OutOfMemory, error.Canceled => |e| return e,
3841 };3841 };
3842}3842}
38433843
...@@ -3896,6 +3896,7 @@ fn resolveUnionInner(...@@ -3896,6 +3896,7 @@ fn resolveUnionInner(
3896 return error.AnalysisFail;3896 return error.AnalysisFail;
3897 },3897 },
3898 error.OutOfMemory => |e| return e,3898 error.OutOfMemory => |e| return e,
3899 error.Canceled => |e| return e,
3899 };3900 };
3900}3901}
39013902
src/Value.zig+7-3
...@@ -1,12 +1,15 @@...@@ -1,12 +1,15 @@
1const std = @import("std");
2const builtin = @import("builtin");
3const build_options = @import("build_options");1const build_options = @import("build_options");
4const Type = @import("Type.zig");2const builtin = @import("builtin");
3
4const std = @import("std");
5const Io = std.Io;
5const assert = std.debug.assert;6const assert = std.debug.assert;
6const BigIntConst = std.math.big.int.Const;7const BigIntConst = std.math.big.int.Const;
7const BigIntMutable = std.math.big.int.Mutable;8const BigIntMutable = std.math.big.int.Mutable;
8const Target = std.Target;9const Target = std.Target;
9const Allocator = std.mem.Allocator;10const Allocator = std.mem.Allocator;
11
12const Type = @import("Type.zig");
10const Zcu = @import("Zcu.zig");13const Zcu = @import("Zcu.zig");
11const Sema = @import("Sema.zig");14const Sema = @import("Sema.zig");
12const InternPool = @import("InternPool.zig");15const InternPool = @import("InternPool.zig");
...@@ -2410,6 +2413,7 @@ pub const PointerDeriveStep = union(enum) {...@@ -2410,6 +2413,7 @@ pub const PointerDeriveStep = union(enum) {
2410pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread) Allocator.Error!PointerDeriveStep {2413pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread) Allocator.Error!PointerDeriveStep {
2411 return ptr_val.pointerDerivationAdvanced(arena, pt, false, null) catch |err| switch (err) {2414 return ptr_val.pointerDerivationAdvanced(arena, pt, false, null) catch |err| switch (err) {
2412 error.OutOfMemory => |e| return e,2415 error.OutOfMemory => |e| return e,
2416 error.Canceled => @panic("TODO"), // pls remove from error set mlugg
2413 error.AnalysisFail => unreachable,2417 error.AnalysisFail => unreachable,
2414 };2418 };
2415}2419}
src/Zcu.zig+3-1
...@@ -2755,9 +2755,11 @@ pub const LazySrcLoc = struct {...@@ -2755,9 +2755,11 @@ pub const LazySrcLoc = struct {
2755 }2755 }
2756};2756};
27572757
2758pub const SemaError = error{ OutOfMemory, AnalysisFail };2758pub const SemaError = error{ OutOfMemory, Canceled, AnalysisFail };
2759pub const CompileError = error{2759pub const CompileError = error{
2760 OutOfMemory,2760 OutOfMemory,
2761 /// The compilation update is no longer desired.
2762 Canceled,
2761 /// When this is returned, the compile error for the failure has already been recorded.2763 /// When this is returned, the compile error for the failure has already been recorded.
2762 AnalysisFail,2764 AnalysisFail,
2763 /// In a comptime scope, a return instruction was encountered. This error is only seen when2765 /// In a comptime scope, a return instruction was encountered. This error is only seen when
src/Zcu/PerThread.zig+18-9
...@@ -1,26 +1,31 @@...@@ -1,26 +1,31 @@
1//! This type provides a wrapper around a `*Zcu` for uses which require a thread `Id`.1//! This type provides a wrapper around a `*Zcu` for uses which require a thread `Id`.
2//! Any operation which mutates `InternPool` state lives here rather than on `Zcu`.2//! Any operation which mutates `InternPool` state lives here rather than on `Zcu`.
33
4const Air = @import("../Air.zig");4const std = @import("std");
5const Allocator = std.mem.Allocator;5const Allocator = std.mem.Allocator;
6const assert = std.debug.assert;6const assert = std.debug.assert;
7const Ast = std.zig.Ast;7const Ast = std.zig.Ast;
8const AstGen = std.zig.AstGen;8const AstGen = std.zig.AstGen;
9const BigIntConst = std.math.big.int.Const;9const BigIntConst = std.math.big.int.Const;
10const BigIntMutable = std.math.big.int.Mutable;10const BigIntMutable = std.math.big.int.Mutable;
11const Cache = std.Build.Cache;
12const log = std.log.scoped(.zcu);
13const mem = std.mem;
14const Zir = std.zig.Zir;
15const Zoir = std.zig.Zoir;
16const ZonGen = std.zig.ZonGen;
17const Io = std.Io;
18
19const Air = @import("../Air.zig");
11const Builtin = @import("../Builtin.zig");20const Builtin = @import("../Builtin.zig");
12const build_options = @import("build_options");21const build_options = @import("build_options");
13const builtin = @import("builtin");22const builtin = @import("builtin");
14const Cache = std.Build.Cache;
15const dev = @import("../dev.zig");23const dev = @import("../dev.zig");
16const InternPool = @import("../InternPool.zig");24const InternPool = @import("../InternPool.zig");
17const AnalUnit = InternPool.AnalUnit;25const AnalUnit = InternPool.AnalUnit;
18const introspect = @import("../introspect.zig");26const introspect = @import("../introspect.zig");
19const log = std.log.scoped(.zcu);
20const Module = @import("../Package.zig").Module;27const Module = @import("../Package.zig").Module;
21const Sema = @import("../Sema.zig");28const Sema = @import("../Sema.zig");
22const std = @import("std");
23const mem = std.mem;
24const target_util = @import("../target.zig");29const target_util = @import("../target.zig");
25const trace = @import("../tracy.zig").trace;30const trace = @import("../tracy.zig").trace;
26const Type = @import("../Type.zig");31const Type = @import("../Type.zig");
...@@ -29,9 +34,6 @@ const Zcu = @import("../Zcu.zig");...@@ -29,9 +34,6 @@ const Zcu = @import("../Zcu.zig");
29const Compilation = @import("../Compilation.zig");34const Compilation = @import("../Compilation.zig");
30const codegen = @import("../codegen.zig");35const codegen = @import("../codegen.zig");
31const crash_report = @import("../crash_report.zig");36const crash_report = @import("../crash_report.zig");
32const Zir = std.zig.Zir;
33const Zoir = std.zig.Zoir;
34const ZonGen = std.zig.ZonGen;
3537
36zcu: *Zcu,38zcu: *Zcu,
3739
...@@ -678,6 +680,7 @@ pub fn ensureMemoizedStateUpToDate(pt: Zcu.PerThread, stage: InternPool.Memoized...@@ -678,6 +680,7 @@ pub fn ensureMemoizedStateUpToDate(pt: Zcu.PerThread, stage: InternPool.Memoized
678 // TODO: same as for `ensureComptimeUnitUpToDate` etc680 // TODO: same as for `ensureComptimeUnitUpToDate` etc
679 return error.OutOfMemory;681 return error.OutOfMemory;
680 },682 },
683 error.Canceled => |e| return e,
681 error.ComptimeReturn => unreachable,684 error.ComptimeReturn => unreachable,
682 error.ComptimeBreak => unreachable,685 error.ComptimeBreak => unreachable,
683 };686 };
...@@ -842,6 +845,7 @@ pub fn ensureComptimeUnitUpToDate(pt: Zcu.PerThread, cu_id: InternPool.ComptimeU...@@ -842,6 +845,7 @@ pub fn ensureComptimeUnitUpToDate(pt: Zcu.PerThread, cu_id: InternPool.ComptimeU
842 // for reporting OOM errors without allocating.845 // for reporting OOM errors without allocating.
843 return error.OutOfMemory;846 return error.OutOfMemory;
844 },847 },
848 error.Canceled => |e| return e,
845 error.ComptimeReturn => unreachable,849 error.ComptimeReturn => unreachable,
846 error.ComptimeBreak => unreachable,850 error.ComptimeBreak => unreachable,
847 };851 };
...@@ -1030,6 +1034,7 @@ pub fn ensureNavValUpToDate(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu...@@ -1030,6 +1034,7 @@ pub fn ensureNavValUpToDate(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu
1030 // for reporting OOM errors without allocating.1034 // for reporting OOM errors without allocating.
1031 return error.OutOfMemory;1035 return error.OutOfMemory;
1032 },1036 },
1037 error.Canceled => |e| return e,
1033 error.ComptimeReturn => unreachable,1038 error.ComptimeReturn => unreachable,
1034 error.ComptimeBreak => unreachable,1039 error.ComptimeBreak => unreachable,
1035 };1040 };
...@@ -1443,6 +1448,7 @@ pub fn ensureNavTypeUpToDate(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zc...@@ -1443,6 +1448,7 @@ pub fn ensureNavTypeUpToDate(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zc
1443 // for reporting OOM errors without allocating.1448 // for reporting OOM errors without allocating.
1444 return error.OutOfMemory;1449 return error.OutOfMemory;
1445 },1450 },
1451 error.Canceled => |e| return e,
1446 error.ComptimeReturn => unreachable,1452 error.ComptimeReturn => unreachable,
1447 error.ComptimeBreak => unreachable,1453 error.ComptimeBreak => unreachable,
1448 };1454 };
...@@ -1668,6 +1674,7 @@ pub fn ensureFuncBodyUpToDate(pt: Zcu.PerThread, func_index: InternPool.Index) Z...@@ -1668,6 +1674,7 @@ pub fn ensureFuncBodyUpToDate(pt: Zcu.PerThread, func_index: InternPool.Index) Z
1668 // for reporting OOM errors without allocating.1674 // for reporting OOM errors without allocating.
1669 return error.OutOfMemory;1675 return error.OutOfMemory;
1670 },1676 },
1677 error.Canceled => |e| return e,
1671 };1678 };
16721679
1673 if (was_outdated) {1680 if (was_outdated) {
...@@ -2360,6 +2367,7 @@ pub fn embedFile(...@@ -2360,6 +2367,7 @@ pub fn embedFile(
2360 import_string: []const u8,2367 import_string: []const u8,
2361) error{2368) error{
2362 OutOfMemory,2369 OutOfMemory,
2370 Canceled,
2363 ImportOutsideModulePath,2371 ImportOutsideModulePath,
2364 CurrentWorkingDirectoryUnlinked,2372 CurrentWorkingDirectoryUnlinked,
2365}!Zcu.EmbedFile.Index {2373}!Zcu.EmbedFile.Index {
...@@ -4123,7 +4131,7 @@ fn recreateEnumType(...@@ -4123,7 +4131,7 @@ fn recreateEnumType(
4123 pt: Zcu.PerThread,4131 pt: Zcu.PerThread,
4124 old_ty: InternPool.Index,4132 old_ty: InternPool.Index,
4125 key: InternPool.Key.NamespaceType.Declared,4133 key: InternPool.Key.NamespaceType.Declared,
4126) Allocator.Error!InternPool.Index {4134) (Allocator.Error || Io.Cancelable)!InternPool.Index {
4127 const zcu = pt.zcu;4135 const zcu = pt.zcu;
4128 const gpa = zcu.gpa;4136 const gpa = zcu.gpa;
4129 const ip = &zcu.intern_pool;4137 const ip = &zcu.intern_pool;
...@@ -4234,6 +4242,7 @@ fn recreateEnumType(...@@ -4234,6 +4242,7 @@ fn recreateEnumType(
4234 body_end,4242 body_end,
4235 ) catch |err| switch (err) {4243 ) catch |err| switch (err) {
4236 error.OutOfMemory => |e| return e,4244 error.OutOfMemory => |e| return e,
4245 error.Canceled => |e| return e,
4237 error.AnalysisFail => {}, // call sites are responsible for checking `[transitive_]failed_analysis` to detect this4246 error.AnalysisFail => {}, // call sites are responsible for checking `[transitive_]failed_analysis` to detect this
4238 };4247 };
42394248
src/print_value.zig+2
...@@ -27,6 +27,7 @@ pub fn formatSema(ctx: FormatContext, writer: *Writer) Writer.Error!void {...@@ -27,6 +27,7 @@ pub fn formatSema(ctx: FormatContext, writer: *Writer) Writer.Error!void {
27 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function27 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
28 error.ComptimeBreak, error.ComptimeReturn => unreachable,28 error.ComptimeBreak, error.ComptimeReturn => unreachable,
29 error.AnalysisFail => unreachable, // TODO: re-evaluate when we use `sema` more fully29 error.AnalysisFail => unreachable, // TODO: re-evaluate when we use `sema` more fully
30 error.Canceled => @panic("TODO"), // pls stop returning this error mlugg
30 else => |e| return e,31 else => |e| return e,
31 };32 };
32}33}
...@@ -36,6 +37,7 @@ pub fn format(ctx: FormatContext, writer: *Writer) Writer.Error!void {...@@ -36,6 +37,7 @@ pub fn format(ctx: FormatContext, writer: *Writer) Writer.Error!void {
36 return print(ctx.val, writer, ctx.depth, ctx.pt, null) catch |err| switch (err) {37 return print(ctx.val, writer, ctx.depth, ctx.pt, null) catch |err| switch (err) {
37 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function38 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
38 error.ComptimeBreak, error.ComptimeReturn, error.AnalysisFail => unreachable,39 error.ComptimeBreak, error.ComptimeReturn, error.AnalysisFail => unreachable,
40 error.Canceled => @panic("TODO"), // pls stop returning this error mlugg
39 else => |e| return e,41 else => |e| return e,
40 };42 };
41}43}