diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-10-25 15:06:47 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-25 15:11:21 -0700 |
| commit | 8509e7111d80a07e778aa2a57d58d2bea6945014 (patch) | |
| tree | e7eedaf980ada713a6c3d2da3e6153751d03bed6 /src/AstGen.zig | |
| parent | a132190cad80669306705b72276e9641401426fb (diff) | |
| download | zig-8509e7111d80a07e778aa2a57d58d2bea6945014.tar.gz zig-8509e7111d80a07e778aa2a57d58d2bea6945014.zip | |
stage2: fix switch on tagged union capture-by-pointer
* AstGen: always use `typeof` and never `typeof_elem` on the
`switch_cond`/`switch_cond_ref` instruction because both variants
return a value and not a pointer.
- Delete the `typeof_elem` ZIR instruction since it is no longer
needed.
* Sema: validateUnionInit now recognizes a comptime mutable value and
no longer emits a compile error saying "cannot evaluate constant
expression"
- Still to-do is detecting comptime union values in a function that
is not being executed at compile-time.
- This is still to-do for structs too.
* Sema: when emitting a call AIR instruction, call resolveTypeLayout on
all the parameter types as well as the return type.
* `Type.structFieldOffset` now works for unions in addition to structs.
Diffstat (limited to 'src/AstGen.zig')
| -rw-r--r-- | src/AstGen.zig | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index eb7d29893c..59643d5279 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -2109,7 +2109,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner .negate, .negate_wrap, .typeof, - .typeof_elem, .xor, .optional_type, .optional_payload_safe, @@ -6028,8 +6027,7 @@ fn switchExpr( const cond_tag: Zir.Inst.Tag = if (any_payload_is_ref) .switch_cond_ref else .switch_cond; const cond = try parent_gz.addUnNode(cond_tag, raw_operand, operand_node); // We need the type of the operand to use as the result location for all the prong items. - const typeof_tag: Zir.Inst.Tag = if (any_payload_is_ref) .typeof_elem else .typeof; - const cond_ty_inst = try parent_gz.addUnNode(typeof_tag, cond, operand_node); + const cond_ty_inst = try parent_gz.addUnNode(.typeof, cond, operand_node); const item_rl: ResultLoc = .{ .ty = cond_ty_inst }; // These contain the data that goes into the `extra` array for the SwitchBlock/SwitchBlockMulti. @@ -6214,7 +6212,7 @@ fn switchExpr( .has_multi_cases = multi_cases_len != 0, .has_else = special_prong == .@"else", .has_under = special_prong == .under, - .scalar_cases_len = @intCast(u28, scalar_cases_len), + .scalar_cases_len = @intCast(Zir.Inst.SwitchBlock.Bits.ScalarCasesLen, scalar_cases_len), }, }); |
