aboutsummaryrefslogtreecommitdiff
path: root/src/Zcu.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-12-03 20:35:23 -0800
committerAndrew Kelley <andrew@ziglang.org>2025-01-15 15:11:35 -0800
commit9bf715de74a7d5badeae932afb594b7c6b33afa3 (patch)
tree302e2c5a42d30e379c5bb2e86c24360ea49ab3fb /src/Zcu.zig
parent77accf597d845245847b143e42ec4109c9468480 (diff)
downloadzig-9bf715de74a7d5badeae932afb594b7c6b33afa3.tar.gz
zig-9bf715de74a7d5badeae932afb594b7c6b33afa3.zip
rework error handling in the backends
Diffstat (limited to 'src/Zcu.zig')
-rw-r--r--src/Zcu.zig40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/Zcu.zig b/src/Zcu.zig
index 731905d166..ccc4177f33 100644
--- a/src/Zcu.zig
+++ b/src/Zcu.zig
@@ -4072,15 +4072,53 @@ pub fn navValIsConst(zcu: *const Zcu, val: InternPool.Index) bool {
};
}
+pub const CodegenFailError = error{
+ /// Indicates the error message has been already stored at `Zcu.failed_codegen`.
+ CodegenFail,
+ OutOfMemory,
+};
+
pub fn codegenFail(
zcu: *Zcu,
nav_index: InternPool.Nav.Index,
comptime format: []const u8,
args: anytype,
-) error{ CodegenFail, OutOfMemory } {
+) CodegenFailError {
const gpa = zcu.gpa;
try zcu.failed_codegen.ensureUnusedCapacity(gpa, 1);
const msg = try Zcu.ErrorMsg.create(gpa, zcu.navSrcLoc(nav_index), format, args);
zcu.failed_codegen.putAssumeCapacityNoClobber(nav_index, msg);
return error.CodegenFail;
}
+
+pub fn codegenFailMsg(zcu: *Zcu, nav_index: InternPool.Nav.Index, msg: *ErrorMsg) CodegenFailError {
+ const gpa = zcu.gpa;
+ {
+ errdefer msg.deinit(gpa);
+ try zcu.failed_codegen.putNoClobber(gpa, nav_index, msg);
+ }
+ return error.CodegenFail;
+}
+
+pub fn codegenFailType(
+ zcu: *Zcu,
+ ty_index: InternPool.Index,
+ comptime format: []const u8,
+ args: anytype,
+) CodegenFailError {
+ const gpa = zcu.gpa;
+ try zcu.failed_types.ensureUnusedCapacity(gpa, 1);
+ const msg = try Zcu.ErrorMsg.create(gpa, zcu.typeSrcLoc(ty_index), format, args);
+ zcu.failed_types.putAssumeCapacityNoClobber(ty_index, msg);
+ return error.CodegenFail;
+}
+
+pub fn codegenFailTypeMsg(zcu: *Zcu, ty_index: InternPool.Index, msg: *ErrorMsg) CodegenFailError {
+ const gpa = zcu.gpa;
+ {
+ errdefer msg.deinit(gpa);
+ try zcu.failed_types.ensureUnusedCapacity(gpa, 1);
+ }
+ zcu.failed_types.putAssumeCapacityNoClobber(ty_index, msg);
+ return error.CodegenFail;
+}