aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-07-07 20:47:21 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-07-07 20:47:21 -0700
commitc2e66d9bab396a69514ec7c3c41fb0404e542f21 (patch)
treefbc8b06cd459cd5e4ad2b39384c9d5d73e25c8ee /src/Module.zig
parent5c8bd443d92c6306f60857720103ae46ca7b8b3e (diff)
downloadzig-c2e66d9bab396a69514ec7c3c41fb0404e542f21.tar.gz
zig-c2e66d9bab396a69514ec7c3c41fb0404e542f21.zip
stage2: basic inferred error set support
* Inferred error sets are stored in the return Type of the function, owned by the Module.Fn. So it cleans up that memory in deinit(). * Sema: update the inferred error set in zirRetErrValue - Update relevant code in wrapErrorUnion * C backend: improve some some instructions to take advantage of liveness analysis to avoid being emitted when unused. * C backend: when an error union has a payload type with no runtime bits, emit the error union as the same type as the error set.
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/Module.zig b/src/Module.zig
index c48440ccc2..8ae184a377 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -777,8 +777,19 @@ pub const Fn = struct {
}
pub fn deinit(func: *Fn, gpa: *Allocator) void {
- _ = func;
- _ = gpa;
+ if (func.getInferredErrorSet()) |map| {
+ map.deinit(gpa);
+ }
+ }
+
+ pub fn getInferredErrorSet(func: *Fn) ?*std.StringHashMapUnmanaged(void) {
+ const ret_ty = func.owner_decl.ty.fnReturnType();
+ if (ret_ty.zigTypeTag() == .ErrorUnion) {
+ if (ret_ty.errorUnionSet().castTag(.error_set_inferred)) |payload| {
+ return &payload.data.map;
+ }
+ }
+ return null;
}
};