diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-12-02 18:46:59 +0200 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-12-02 18:46:59 +0200 |
| commit | 59dad43de26a89ca72a97224a171d724dcc6ee41 (patch) | |
| tree | 63377949939557a1edf03c90be77508051d9354f /src/type.zig | |
| parent | 86e6acb37b242a60917f5552999d918c24fdf791 (diff) | |
| download | zig-59dad43de26a89ca72a97224a171d724dcc6ee41.tar.gz zig-59dad43de26a89ca72a97224a171d724dcc6ee41.zip | |
Sema: add error for failed assumption about struct having runtime bits
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/type.zig b/src/type.zig index 21cfdf9d73..5fcd0f6a26 100644 --- a/src/type.zig +++ b/src/type.zig @@ -2459,6 +2459,7 @@ pub const Type = extern union { if (struct_obj.status == .field_types_wip) { // In this case, we guess that hasRuntimeBits() for this type is true, // and then later if our guess was incorrect, we emit a compile error. + struct_obj.assumed_runtime_bits = true; return true; } switch (strat) { @@ -2491,6 +2492,12 @@ pub const Type = extern union { .@"union" => { const union_obj = ty.castTag(.@"union").?.data; + if (union_obj.status == .field_types_wip) { + // In this case, we guess that hasRuntimeBits() for this type is true, + // and then later if our guess was incorrect, we emit a compile error. + union_obj.assumed_runtime_bits = true; + return true; + } switch (strat) { .sema => |sema| _ = try sema.resolveTypeFields(ty), .eager => assert(union_obj.haveFieldTypes()), @@ -3027,8 +3034,9 @@ pub const Type = extern union { const struct_obj = ty.castTag(.@"struct").?.data; if (opt_sema) |sema| { if (struct_obj.status == .field_types_wip) { - // We'll guess "pointer-aligned" and if we guess wrong, emit - // a compile error later. + // We'll guess "pointer-aligned", if the struct has an + // underaligned pointer field then some allocations + // might require explicit alignment. return AbiAlignmentAdvanced{ .scalar = @divExact(target.cpu.arch.ptrBitWidth(), 8) }; } _ = try sema.resolveTypeFields(ty); @@ -3153,8 +3161,9 @@ pub const Type = extern union { }; if (opt_sema) |sema| { if (union_obj.status == .field_types_wip) { - // We'll guess "pointer-aligned" and if we guess wrong, emit - // a compile error later. + // We'll guess "pointer-aligned", if the union has an + // underaligned pointer field then some allocations + // might require explicit alignment. return AbiAlignmentAdvanced{ .scalar = @divExact(target.cpu.arch.ptrBitWidth(), 8) }; } _ = try sema.resolveTypeFields(ty); @@ -5234,7 +5243,12 @@ pub const Type = extern union { .@"struct" => { const struct_obj = ty.castTag(.@"struct").?.data; switch (struct_obj.requires_comptime) { - .wip, .unknown => unreachable, // This function asserts types already resolved. + .wip, .unknown => { + // Return false to avoid incorrect dependency loops. + // This will be handled correctly once merged with + // `Sema.typeRequiresComptime`. + return false; + }, .no => return false, .yes => return true, } @@ -5243,7 +5257,12 @@ pub const Type = extern union { .@"union", .union_safety_tagged, .union_tagged => { const union_obj = ty.cast(Type.Payload.Union).?.data; switch (union_obj.requires_comptime) { - .wip, .unknown => unreachable, // This function asserts types already resolved. + .wip, .unknown => { + // Return false to avoid incorrect dependency loops. + // This will be handled correctly once merged with + // `Sema.typeRequiresComptime`. + return false; + }, .no => return false, .yes => return true, } |
