diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-02-09 00:10:53 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-02-09 00:10:53 -0700 |
| commit | 97019bc56d27349e0aeb44faa9d3f738887abe7f (patch) | |
| tree | 4c9ceb095fa8885a21a77030108d8cae90173e3e /src/type.zig | |
| parent | f4fa32a63219917e8fb26f43cbd2d97b17e0aeee (diff) | |
| download | zig-97019bc56d27349e0aeb44faa9d3f738887abe7f.tar.gz zig-97019bc56d27349e0aeb44faa9d3f738887abe7f.zip | |
Sema: handle inferred error set tail call
When Sema sees a store_node instruction, it now checks for
the possibility of this pattern:
%a = ret_ptr
%b = store(%a, %c)
Where %c is an error union. In such case we need to add to the
current function's inferred error set, if any.
Coercion from error union to error union will be handled ideally if the
operand is comptime known. In such case it does the appropriate
unwrapping, then wraps again.
In the future, coercion from error union to error union should do the
same thing for a runtime value; emitting a runtime branch to check if
the value is an error or not.
`Value.arrayLen` for structs returns the number of fields. This is so
that Liveness can use it for the `vector_init` instruction (soon to be
renamed to `aggregate_init`).
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/type.zig b/src/type.zig index 769e48ccc5..0827b2e2d7 100644 --- a/src/type.zig +++ b/src/type.zig @@ -3013,7 +3013,7 @@ pub const Type = extern union { } } - /// Asserts the type is an array or vector. + /// Asserts the type is an array or vector or struct. pub fn arrayLen(ty: Type) u64 { return switch (ty.tag()) { .vector => ty.castTag(.vector).?.data.len, @@ -3022,6 +3022,7 @@ pub const Type = extern union { .array_u8 => ty.castTag(.array_u8).?.data, .array_u8_sentinel_0 => ty.castTag(.array_u8_sentinel_0).?.data, .tuple => ty.castTag(.tuple).?.data.types.len, + .@"struct" => ty.castTag(.@"struct").?.data.fields.count(), else => unreachable, }; |
