authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-08-12 15:28:05-07:00
committergravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-08-25 15:18:20-07:00
logce92ccccc961992c00a10e714ce9e799956c50f2
tree39d25560175d0787a0891c0f8fa25f68bb1ba7cd
parent472f3ac419386327a3ed464256509af456092785
signaturelock-open Commit is signed but in an unrecognized format.

sema: `resolve{Struct,Union}Inner` don't throw away Semas

before this, calls to `resolveTypeFieldsStruct` (now renamed to the more correct `resolveStructFieldTypes`) would just throw away the sema that `resolveStructInner` created and create its own. There is no reason to do this, and we fix it to preserve the sema through it all.

4 files changed, 64 insertions(+), 87 deletions(-)

src/InternPool.zig+2-2
...@@ -457,7 +457,7 @@ pub const Cau = struct {...@@ -457,7 +457,7 @@ pub const Cau = struct {
457 unwrapped.index);457 unwrapped.index);
458 }458 }
459 };459 };
460 fn unwrap(cau_index: Cau.Index, ip: *const InternPool) Unwrapped {460 pub fn unwrap(cau_index: Cau.Index, ip: *const InternPool) Unwrapped {
461 return .{461 return .{
462 .tid = @enumFromInt(@intFromEnum(cau_index) >> ip.tid_shift_31 & ip.getTidMask()),462 .tid = @enumFromInt(@intFromEnum(cau_index) >> ip.tid_shift_31 & ip.getTidMask()),
463 .index = @intFromEnum(cau_index) & ip.getIndexMask(u31),463 .index = @intFromEnum(cau_index) & ip.getIndexMask(u31),
...@@ -1464,7 +1464,7 @@ pub const NamespaceIndex = enum(u32) {...@@ -1464,7 +1464,7 @@ pub const NamespaceIndex = enum(u32) {
1464 unwrapped.index);1464 unwrapped.index);
1465 }1465 }
1466 };1466 };
1467 fn unwrap(namespace_index: NamespaceIndex, ip: *const InternPool) Unwrapped {1467 pub fn unwrap(namespace_index: NamespaceIndex, ip: *const InternPool) Unwrapped {
1468 const index = @intFromEnum(namespace_index) & ip.getIndexMask(u32);1468 const index = @intFromEnum(namespace_index) & ip.getIndexMask(u32);
1469 return .{1469 return .{
1470 .tid = @enumFromInt(@intFromEnum(namespace_index) >> ip.tid_shift_32 & ip.getTidMask()),1470 .tid = @enumFromInt(@intFromEnum(namespace_index) >> ip.tid_shift_32 & ip.getTidMask()),
src/Sema.zig+47-80
...@@ -35277,7 +35277,7 @@ pub fn resolveStructAlignment(...@@ -35277,7 +35277,7 @@ pub fn resolveStructAlignment(
35277 // might require explicit alignment.35277 // might require explicit alignment.
35278 if (struct_type.assumePointerAlignedIfFieldTypesWip(ip, ptr_align)) return;35278 if (struct_type.assumePointerAlignedIfFieldTypesWip(ip, ptr_align)) return;
3527935279
35280 try sema.resolveTypeFieldsStruct(ty, struct_type);35280 try sema.resolveStructFieldTypes(ty, struct_type);
3528135281
35282 // We'll guess "pointer-aligned", if the struct has an35282 // We'll guess "pointer-aligned", if the struct has an
35283 // underaligned pointer field then some allocations35283 // underaligned pointer field then some allocations
...@@ -35316,7 +35316,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35316,7 +35316,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
35316 try sema.resolveTypeFieldsStruct(ty.toIntern(), struct_type);35316 try sema.resolveTypeFieldsStruct(ty.toIntern(), struct_type);
3531735317
35318 if (struct_type.layout == .@"packed") {35318 if (struct_type.layout == .@"packed") {
35319 semaBackingIntType(pt, struct_type) catch |err| switch (err) {35319 sema.backingIntType(struct_type) catch |err| switch (err) {
35320 error.OutOfMemory, error.AnalysisFail => |e| return e,35320 error.OutOfMemory, error.AnalysisFail => |e| return e,
35321 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,35321 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,
35322 };35322 };
...@@ -35444,38 +35444,26 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35444,38 +35444,26 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
35444 _ = try ty.comptimeOnlySema(pt);35444 _ = try ty.comptimeOnlySema(pt);
35445}35445}
3544635446
35447fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructType) CompileError!void {35447fn backingIntType(
35448 sema: *Sema,
35449 struct_type: InternPool.LoadedStructType,
35450) CompileError!void {
35451 const pt = sema.pt;
35448 const zcu = pt.zcu;35452 const zcu = pt.zcu;
35449 const gpa = zcu.gpa;35453 const gpa = zcu.gpa;
35450 const ip = &zcu.intern_pool;35454 const ip = &zcu.intern_pool;
3545135455
35452 const cau_index = struct_type.cau.unwrap().?;35456 const cau_index = struct_type.cau.unwrap().?;
3545335457
35454 const zir = zcu.namespacePtr(struct_type.namespace.unwrap().?).fileScope(zcu).zir;
35455
35456 var analysis_arena = std.heap.ArenaAllocator.init(gpa);35458 var analysis_arena = std.heap.ArenaAllocator.init(gpa);
35457 defer analysis_arena.deinit();35459 defer analysis_arena.deinit();
3545835460
35459 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);35461 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
35460 defer comptime_err_ret_trace.deinit();35462 defer comptime_err_ret_trace.deinit();
3546135463
35462 var sema: Sema = .{
35463 .pt = pt,
35464 .gpa = gpa,
35465 .arena = analysis_arena.allocator(),
35466 .code = zir,
35467 .owner = AnalUnit.wrap(.{ .cau = cau_index }),
35468 .func_index = .none,
35469 .func_is_naked = false,
35470 .fn_ret_ty = Type.void,
35471 .fn_ret_ty_ies = null,
35472 .comptime_err_ret_trace = &comptime_err_ret_trace,
35473 };
35474 defer sema.deinit();
35475
35476 var block: Block = .{35464 var block: Block = .{
35477 .parent = null,35465 .parent = null,
35478 .sema = &sema,35466 .sema = sema,
35479 .namespace = ip.getCau(cau_index).namespace,35467 .namespace = ip.getCau(cau_index).namespace,
35480 .instructions = .{},35468 .instructions = .{},
35481 .inlining = null,35469 .inlining = null,
...@@ -35494,6 +35482,7 @@ fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructTyp...@@ -35494,6 +35482,7 @@ fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructTyp
35494 break :blk accumulator;35482 break :blk accumulator;
35495 };35483 };
3549635484
35485 const zir = zcu.namespacePtr(struct_type.namespace.unwrap().?).fileScope(zcu).zir;
35497 const zir_index = struct_type.zir_index.unwrap().?.resolve(ip) orelse return error.AnalysisFail;35486 const zir_index = struct_type.zir_index.unwrap().?.resolve(ip) orelse return error.AnalysisFail;
35498 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;35487 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;
35499 assert(extended.opcode == .struct_decl);35488 assert(extended.opcode == .struct_decl);
...@@ -35618,7 +35607,7 @@ pub fn resolveUnionAlignment(...@@ -35618,7 +35607,7 @@ pub fn resolveUnionAlignment(
35618 // might require explicit alignment.35607 // might require explicit alignment.
35619 if (union_type.assumePointerAlignedIfFieldTypesWip(ip, ptr_align)) return;35608 if (union_type.assumePointerAlignedIfFieldTypesWip(ip, ptr_align)) return;
3562035609
35621 try sema.resolveTypeFieldsUnion(ty, union_type);35610 try sema.resolveUnionFieldTypes(ty, union_type);
3562235611
35623 var max_align: Alignment = .@"1";35612 var max_align: Alignment = .@"1";
35624 for (0..union_type.field_types.len) |field_index| {35613 for (0..union_type.field_types.len) |field_index| {
...@@ -35642,7 +35631,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35642,7 +35631,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
35642 const pt = sema.pt;35631 const pt = sema.pt;
35643 const ip = &pt.zcu.intern_pool;35632 const ip = &pt.zcu.intern_pool;
3564435633
35645 try sema.resolveTypeFieldsUnion(ty, ip.loadUnionType(ty.ip_index));35634 try sema.resolveUnionFieldTypes(ty, ip.loadUnionType(ty.ip_index));
3564635635
35647 // Load again, since the tag type might have changed due to resolution.35636 // Load again, since the tag type might have changed due to resolution.
35648 const union_type = ip.loadUnionType(ty.ip_index);35637 const union_type = ip.loadUnionType(ty.ip_index);
...@@ -35810,7 +35799,7 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {...@@ -35810,7 +35799,7 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
35810 _ = try ty.comptimeOnlySema(pt);35799 _ = try ty.comptimeOnlySema(pt);
35811}35800}
3581235801
35813pub fn resolveTypeFieldsStruct(35802pub fn resolveStructFieldTypes(
35814 sema: *Sema,35803 sema: *Sema,
35815 ty: InternPool.Index,35804 ty: InternPool.Index,
35816 struct_type: InternPool.LoadedStructType,35805 struct_type: InternPool.LoadedStructType,
...@@ -35833,7 +35822,7 @@ pub fn resolveTypeFieldsStruct(...@@ -35833,7 +35822,7 @@ pub fn resolveTypeFieldsStruct(
35833 }35822 }
35834 defer struct_type.clearFieldTypesWip(ip);35823 defer struct_type.clearFieldTypesWip(ip);
3583535824
35836 semaStructFields(pt, sema.arena, struct_type) catch |err| switch (err) {35825 sema.structFields(struct_type) catch |err| switch (err) {
35837 error.AnalysisFail, error.OutOfMemory => |e| return e,35826 error.AnalysisFail, error.OutOfMemory => |e| return e,
35838 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,35827 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,
35839 };35828 };
...@@ -35862,14 +35851,14 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) SemaError!void {...@@ -35862,14 +35851,14 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) SemaError!void {
35862 }35851 }
35863 defer struct_type.clearInitsWip(ip);35852 defer struct_type.clearInitsWip(ip);
3586435853
35865 semaStructFieldInits(pt, sema.arena, struct_type) catch |err| switch (err) {35854 sema.structFieldInits(struct_type) catch |err| switch (err) {
35866 error.AnalysisFail, error.OutOfMemory => |e| return e,35855 error.AnalysisFail, error.OutOfMemory => |e| return e,
35867 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,35856 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,
35868 };35857 };
35869 struct_type.setHaveFieldInits(ip);35858 struct_type.setHaveFieldInits(ip);
35870}35859}
3587135860
35872pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.LoadedUnionType) SemaError!void {35861pub fn resolveUnionFieldTypes(sema: *Sema, ty: Type, union_type: InternPool.LoadedUnionType) SemaError!void {
35873 const pt = sema.pt;35862 const pt = sema.pt;
35874 const zcu = pt.zcu;35863 const zcu = pt.zcu;
35875 const ip = &zcu.intern_pool;35864 const ip = &zcu.intern_pool;
...@@ -35896,7 +35885,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load...@@ -35896,7 +35885,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
3589635885
35897 union_type.setStatus(ip, .field_types_wip);35886 union_type.setStatus(ip, .field_types_wip);
35898 errdefer union_type.setStatus(ip, .none);35887 errdefer union_type.setStatus(ip, .none);
35899 semaUnionFields(pt, sema.arena, ty.toIntern(), union_type) catch |err| switch (err) {35888 sema.unionFields(ty.toIntern(), union_type) catch |err| switch (err) {
35900 error.AnalysisFail, error.OutOfMemory => |e| return e,35889 error.AnalysisFail, error.OutOfMemory => |e| return e,
35901 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,35890 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,
35902 };35891 };
...@@ -36099,11 +36088,11 @@ fn structZirInfo(zir: Zir, zir_index: Zir.Inst.Index) struct {...@@ -36099,11 +36088,11 @@ fn structZirInfo(zir: Zir, zir_index: Zir.Inst.Index) struct {
36099 return .{ fields_len, small, extra_index };36088 return .{ fields_len, small, extra_index };
36100}36089}
3610136090
36102fn semaStructFields(36091fn structFields(
36103 pt: Zcu.PerThread,36092 sema: *Sema,
36104 arena: Allocator,
36105 struct_type: InternPool.LoadedStructType,36093 struct_type: InternPool.LoadedStructType,
36106) CompileError!void {36094) CompileError!void {
36095 const pt = sema.pt;
36107 const zcu = pt.zcu;36096 const zcu = pt.zcu;
36108 const gpa = zcu.gpa;36097 const gpa = zcu.gpa;
36109 const ip = &zcu.intern_pool;36098 const ip = &zcu.intern_pool;
...@@ -36116,7 +36105,7 @@ fn semaStructFields(...@@ -36116,7 +36105,7 @@ fn semaStructFields(
3611636105
36117 if (fields_len == 0) switch (struct_type.layout) {36106 if (fields_len == 0) switch (struct_type.layout) {
36118 .@"packed" => {36107 .@"packed" => {
36119 try semaBackingIntType(pt, struct_type);36108 try sema.backingIntType(struct_type);
36120 return;36109 return;
36121 },36110 },
36122 .auto, .@"extern" => {36111 .auto, .@"extern" => {
...@@ -36128,23 +36117,9 @@ fn semaStructFields(...@@ -36128,23 +36117,9 @@ fn semaStructFields(
36128 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);36117 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
36129 defer comptime_err_ret_trace.deinit();36118 defer comptime_err_ret_trace.deinit();
3613036119
36131 var sema: Sema = .{
36132 .pt = pt,
36133 .gpa = gpa,
36134 .arena = arena,
36135 .code = zir,
36136 .owner = AnalUnit.wrap(.{ .cau = cau_index }),
36137 .func_index = .none,
36138 .func_is_naked = false,
36139 .fn_ret_ty = Type.void,
36140 .fn_ret_ty_ies = null,
36141 .comptime_err_ret_trace = &comptime_err_ret_trace,
36142 };
36143 defer sema.deinit();
36144
36145 var block_scope: Block = .{36120 var block_scope: Block = .{
36146 .parent = null,36121 .parent = null,
36147 .sema = &sema,36122 .sema = sema,
36148 .namespace = namespace_index,36123 .namespace = namespace_index,
36149 .instructions = .{},36124 .instructions = .{},
36150 .inlining = null,36125 .inlining = null,
...@@ -36318,12 +36293,12 @@ fn semaStructFields(...@@ -36318,12 +36293,12 @@ fn semaStructFields(
36318 try sema.flushExports();36293 try sema.flushExports();
36319}36294}
3632036295
36321// This logic must be kept in sync with `semaStructFields`36296// This logic must be kept in sync with `structFields`
36322fn semaStructFieldInits(36297fn structFieldInits(
36323 pt: Zcu.PerThread,36298 sema: *Sema,
36324 arena: Allocator,
36325 struct_type: InternPool.LoadedStructType,36299 struct_type: InternPool.LoadedStructType,
36326) CompileError!void {36300) CompileError!void {
36301 const pt = sema.pt;
36327 const zcu = pt.zcu;36302 const zcu = pt.zcu;
36328 const gpa = zcu.gpa;36303 const gpa = zcu.gpa;
36329 const ip = &zcu.intern_pool;36304 const ip = &zcu.intern_pool;
...@@ -36339,23 +36314,9 @@ fn semaStructFieldInits(...@@ -36339,23 +36314,9 @@ fn semaStructFieldInits(
36339 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);36314 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
36340 defer comptime_err_ret_trace.deinit();36315 defer comptime_err_ret_trace.deinit();
3634136316
36342 var sema: Sema = .{
36343 .pt = pt,
36344 .gpa = gpa,
36345 .arena = arena,
36346 .code = zir,
36347 .owner = AnalUnit.wrap(.{ .cau = cau_index }),
36348 .func_index = .none,
36349 .func_is_naked = false,
36350 .fn_ret_ty = Type.void,
36351 .fn_ret_ty_ies = null,
36352 .comptime_err_ret_trace = &comptime_err_ret_trace,
36353 };
36354 defer sema.deinit();
36355
36356 var block_scope: Block = .{36317 var block_scope: Block = .{
36357 .parent = null,36318 .parent = null,
36358 .sema = &sema,36319 .sema = sema,
36359 .namespace = namespace_index,36320 .namespace = namespace_index,
36360 .instructions = .{},36321 .instructions = .{},
36361 .inlining = null,36322 .inlining = null,
...@@ -36458,14 +36419,18 @@ fn semaStructFieldInits(...@@ -36458,14 +36419,18 @@ fn semaStructFieldInits(
36458 try sema.flushExports();36419 try sema.flushExports();
36459}36420}
3646036421
36461fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Index, union_type: InternPool.LoadedUnionType) CompileError!void {36422fn unionFields(
36423 sema: *Sema,
36424 union_ty: InternPool.Index,
36425 union_type: InternPool.LoadedUnionType,
36426) CompileError!void {
36462 const tracy = trace(@src());36427 const tracy = trace(@src());
36463 defer tracy.end();36428 defer tracy.end();
3646436429
36430 const pt = sema.pt;
36465 const zcu = pt.zcu;36431 const zcu = pt.zcu;
36466 const gpa = zcu.gpa;36432 const gpa = zcu.gpa;
36467 const ip = &zcu.intern_pool;36433 const ip = &zcu.intern_pool;
36468 const cau_index = union_type.cau;
36469 const zir = zcu.namespacePtr(union_type.namespace).fileScope(zcu).zir;36434 const zir = zcu.namespacePtr(union_type.namespace).fileScope(zcu).zir;
36470 const zir_index = union_type.zir_index.resolve(ip) orelse return error.AnalysisFail;36435 const zir_index = union_type.zir_index.resolve(ip) orelse return error.AnalysisFail;
36471 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;36436 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;
...@@ -36513,10 +36478,12 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind...@@ -36513,10 +36478,12 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind
36513 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);36478 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
36514 defer comptime_err_ret_trace.deinit();36479 defer comptime_err_ret_trace.deinit();
3651536480
36516 var sema: Sema = .{36481 const cau_index = union_type.cau;
36482
36483 var inner_sema: Sema = .{
36517 .pt = pt,36484 .pt = pt,
36518 .gpa = gpa,36485 .gpa = gpa,
36519 .arena = arena,36486 .arena = sema.arena,
36520 .code = zir,36487 .code = zir,
36521 .owner = AnalUnit.wrap(.{ .cau = cau_index }),36488 .owner = AnalUnit.wrap(.{ .cau = cau_index }),
36522 .func_index = .none,36489 .func_index = .none,
...@@ -36525,11 +36492,11 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind...@@ -36525,11 +36492,11 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind
36525 .fn_ret_ty_ies = null,36492 .fn_ret_ty_ies = null,
36526 .comptime_err_ret_trace = &comptime_err_ret_trace,36493 .comptime_err_ret_trace = &comptime_err_ret_trace,
36527 };36494 };
36528 defer sema.deinit();36495 defer inner_sema.deinit();
3652936496
36530 var block_scope: Block = .{36497 var block_scope: Block = .{
36531 .parent = null,36498 .parent = null,
36532 .sema = &sema,36499 .sema = &inner_sema,
36533 .namespace = union_type.namespace,36500 .namespace = union_type.namespace,
36534 .instructions = .{},36501 .instructions = .{},
36535 .inlining = null,36502 .inlining = null,
...@@ -36672,7 +36639,10 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind...@@ -36672,7 +36639,10 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind
3667236639
36673 if (enum_field_vals.capacity() > 0) {36640 if (enum_field_vals.capacity() > 0) {
36674 const enum_tag_val = if (tag_ref != .none) blk: {36641 const enum_tag_val = if (tag_ref != .none) blk: {
36675 const val = try sema.semaUnionFieldVal(&block_scope, value_src, int_tag_ty, tag_ref);36642 const coerced = try sema.coerce(&block_scope, int_tag_ty, tag_ref, value_src);
36643 const val = try sema.resolveConstDefinedValue(&block_scope, value_src, coerced, .{
36644 .needed_comptime_reason = "enum tag value must be comptime-known",
36645 });
36676 last_tag_val = val;36646 last_tag_val = val;
3667736647
36678 break :blk val;36648 break :blk val;
...@@ -36692,7 +36662,11 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind...@@ -36692,7 +36662,11 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind
36692 .offset = .{ .container_field_value = @intCast(gop.index) },36662 .offset = .{ .container_field_value = @intCast(gop.index) },
36693 };36663 };
36694 const msg = msg: {36664 const msg = msg: {
36695 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{enum_tag_val.fmtValueSema(pt, &sema)});36665 const msg = try sema.errMsg(
36666 value_src,
36667 "enum tag value {} already taken",
36668 .{enum_tag_val.fmtValueSema(pt, sema)},
36669 );
36696 errdefer msg.destroy(gpa);36670 errdefer msg.destroy(gpa);
36697 try sema.errNote(other_value_src, msg, "other occurrence here", .{});36671 try sema.errNote(other_value_src, msg, "other occurrence here", .{});
36698 break :msg msg;36672 break :msg msg;
...@@ -36832,13 +36806,6 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind...@@ -36832,13 +36806,6 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind
36832 try sema.flushExports();36806 try sema.flushExports();
36833}36807}
3683436808
36835fn semaUnionFieldVal(sema: *Sema, block: *Block, src: LazySrcLoc, int_tag_ty: Type, tag_ref: Air.Inst.Ref) CompileError!Value {
36836 const coerced = try sema.coerce(block, int_tag_ty, tag_ref, src);
36837 return sema.resolveConstDefinedValue(block, src, coerced, .{
36838 .needed_comptime_reason = "enum tag value must be comptime-known",
36839 });
36840}
36841
36842fn generateUnionTagTypeNumbered(36809fn generateUnionTagTypeNumbered(
36843 sema: *Sema,36810 sema: *Sema,
36844 block: *Block,36811 block: *Block,
src/Type.zig+10-4
...@@ -3911,11 +3911,12 @@ fn resolveStructInner(...@@ -3911,11 +3911,12 @@ fn resolveStructInner(
3911 var comptime_err_ret_trace = std.ArrayList(Zcu.LazySrcLoc).init(gpa);3911 var comptime_err_ret_trace = std.ArrayList(Zcu.LazySrcLoc).init(gpa);
3912 defer comptime_err_ret_trace.deinit();3912 defer comptime_err_ret_trace.deinit();
39133913
3914 const zir = zcu.namespacePtr(struct_obj.namespace.unwrap().?).fileScope(zcu).zir;
3914 var sema: Sema = .{3915 var sema: Sema = .{
3915 .pt = pt,3916 .pt = pt,
3916 .gpa = gpa,3917 .gpa = gpa,
3917 .arena = analysis_arena.allocator(),3918 .arena = analysis_arena.allocator(),
3918 .code = undefined, // This ZIR will not be used.3919 .code = zir,
3919 .owner = owner,3920 .owner = owner,
3920 .func_index = .none,3921 .func_index = .none,
3921 .func_is_naked = false,3922 .func_is_naked = false,
...@@ -3925,8 +3926,10 @@ fn resolveStructInner(...@@ -3925,8 +3926,10 @@ fn resolveStructInner(
3925 };3926 };
3926 defer sema.deinit();3927 defer sema.deinit();
39273928
3929 assert(sema.owner.unwrap().cau == struct_obj.cau.unwrap().?);
3930
3928 (switch (resolution) {3931 (switch (resolution) {
3929 .fields => sema.resolveTypeFieldsStruct(ty.toIntern(), struct_obj),3932 .fields => sema.resolveStructFieldTypes(ty.toIntern(), struct_obj),
3930 .inits => sema.resolveStructFieldInits(ty),3933 .inits => sema.resolveStructFieldInits(ty),
3931 .alignment => sema.resolveStructAlignment(ty.toIntern(), struct_obj),3934 .alignment => sema.resolveStructAlignment(ty.toIntern(), struct_obj),
3932 .layout => sema.resolveStructLayout(ty),3935 .layout => sema.resolveStructLayout(ty),
...@@ -3964,11 +3967,12 @@ fn resolveUnionInner(...@@ -3964,11 +3967,12 @@ fn resolveUnionInner(
3964 var comptime_err_ret_trace = std.ArrayList(Zcu.LazySrcLoc).init(gpa);3967 var comptime_err_ret_trace = std.ArrayList(Zcu.LazySrcLoc).init(gpa);
3965 defer comptime_err_ret_trace.deinit();3968 defer comptime_err_ret_trace.deinit();
39663969
3970 const zir = zcu.namespacePtr(union_obj.namespace).fileScope(zcu).zir;
3967 var sema: Sema = .{3971 var sema: Sema = .{
3968 .pt = pt,3972 .pt = pt,
3969 .gpa = gpa,3973 .gpa = gpa,
3970 .arena = analysis_arena.allocator(),3974 .arena = analysis_arena.allocator(),
3971 .code = undefined, // This ZIR will not be used.3975 .code = zir,
3972 .owner = owner,3976 .owner = owner,
3973 .func_index = .none,3977 .func_index = .none,
3974 .func_is_naked = false,3978 .func_is_naked = false,
...@@ -3978,8 +3982,10 @@ fn resolveUnionInner(...@@ -3978,8 +3982,10 @@ fn resolveUnionInner(
3978 };3982 };
3979 defer sema.deinit();3983 defer sema.deinit();
39803984
3985 assert(sema.owner.unwrap().cau == union_obj.cau);
3986
3981 (switch (resolution) {3987 (switch (resolution) {
3982 .fields => sema.resolveTypeFieldsUnion(ty, union_obj),3988 .fields => sema.resolveUnionFieldTypes(ty, union_obj),
3983 .alignment => sema.resolveUnionAlignment(ty, union_obj),3989 .alignment => sema.resolveUnionAlignment(ty, union_obj),
3984 .layout => sema.resolveUnionLayout(ty),3990 .layout => sema.resolveUnionLayout(ty),
3985 .full => sema.resolveUnionFully(ty),3991 .full => sema.resolveUnionFully(ty),
src/target.zig+5-1
...@@ -526,7 +526,11 @@ pub fn zigBackend(target: std.Target, use_llvm: bool) std.builtin.CompilerBacken...@@ -526,7 +526,11 @@ pub fn zigBackend(target: std.Target, use_llvm: bool) std.builtin.CompilerBacken
526pub inline fn backendSupportsFeature(backend: std.builtin.CompilerBackend, comptime feature: Feature) bool {526pub inline fn backendSupportsFeature(backend: std.builtin.CompilerBackend, comptime feature: Feature) bool {
527 return switch (feature) {527 return switch (feature) {
528 .panic_fn => switch (backend) {528 .panic_fn => switch (backend) {
529 .stage2_c, .stage2_llvm, .stage2_x86_64, .stage2_riscv64 => true,529 .stage2_c,
530 .stage2_llvm,
531 .stage2_x86_64,
532 .stage2_riscv64,
533 => true,
530 else => false,534 else => false,
531 },535 },
532 .panic_unwrap_error => switch (backend) {536 .panic_unwrap_error => switch (backend) {