Skip to content

Commit 8414638

Browse files
authored
Sema: fixes (#24617)
* Sema: remove redundant comptime-known initializer tracking This logic predates certain Sema enhancements whose behavior it essentially tries to emulate in one specific case in a problematic way. In particular, this logic handled initializing comptime-known `const`s through RLS, which was reworked a few years back in 644041b to not rely on this logic, and catching runtime fields in comptime-only initializers, which has since been *correctly* fixed with better checks in `Sema.storePtr2`. That made the highly complex logic in `validateStructInit`, `validateUnionInit`, and `zirValidatePtrArrayInit` entirely redundant. Worse, it was also causing some tracked bugs, as well as a bug which I have identified and fixed in this PR (a corresponding behavior test is added). This commit simplifies union initialization by bringing the runtime logic more in line with the comptime logic: the tag is now always populated by `Sema.unionFieldPtr` based on `initializing`, where this previously happened only in the comptime case (with `validateUnionInit` instead handling it in the runtime case). Notably, this means that backends are now able to consider getting a pointer to an inactive union field as Illegal Behavior, because the `set_union_tag` instruction now appears *before* the `struct_field_ptr` instruction as you would probably expect it to. Resolves: #24520 Resolves: #24595 * Sema: fix comptime-known union initialization with OPV field The previous commit uncovered this existing OPV bug by triggering this logic more frequently. * Sema: remove dead logic This is redundant because `storePtr2` will coerce to the return type which (in `Sema.coerceInMemoryAllowedErrorSets`) will add errors to the current function's IES if necessary. * Sema: don't rely on Liveness We're currently experimenting with backends which effectively do their own liveness analysis, so this old trick of mine isn't necessarily valid anymore. However, we can fix that trivially: just make the "nop" instruction we jam into here have the right type. That way, the leftover field/element pointer instructions are perfectly valid, but still unused.
2 parents 3fbdd58 + 08f1d63 commit 8414638

File tree

6 files changed

+138
-569
lines changed

6 files changed

+138
-569
lines changed

lib/std/fmt.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,8 @@ test "float.libc.sanity" {
11011101
}
11021102

11031103
test "union" {
1104+
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
1105+
11041106
const TU = union(enum) {
11051107
float: f32,
11061108
int: u32,

0 commit comments

Comments
 (0)