authorgravatar for spexguy070@gmail.comMartin Wickham <spexguy070@gmail.com> 2021-10-01 00:42:50-05:00
committergravatar for spexguy070@gmail.comMartin Wickham <spexguy070@gmail.com> 2021-10-02 15:21:48-05:00
logf7c11acb7f487806b14ada9d13d6afe8d3fe54d5
tree834666b13ed58fc9fbf25b2a9aec82ce4737fe0b
parent806eee8e99fbbd86f01b62b4306bd48f1cd3c872

Resolve struct fields in a separate sema context


2 files changed, 109 insertions(+), 99 deletions(-)

src/Module.zig-6
...@@ -3584,12 +3584,6 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {...@@ -3584,12 +3584,6 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {
3584 try mod.comp.work_queue.writeItem(.{ .emit_h_decl = decl });3584 try mod.comp.work_queue.writeItem(.{ .emit_h_decl = decl });
3585 }3585 }
3586 }3586 }
3587 // In case this Decl is a struct or union, we need to resolve the fields
3588 // while we still have the `Sema` in scope, so that the field type expressions
3589 // can use the resolved AIR instructions that they possibly reference.
3590 // We do this after the decl is populated and set to `complete` so that a `Decl`
3591 // may reference itself.
3592 try sema.resolvePendingTypes(&block_scope);
35933587
3594 if (decl.is_exported) {3588 if (decl.is_exported) {
3595 const export_src = src; // TODO point to the export token3589 const export_src = src; // TODO point to the export token
src/Sema.zig+109-93
...@@ -60,9 +60,6 @@ comptime_args_fn_inst: Zir.Inst.Index = 0,...@@ -60,9 +60,6 @@ comptime_args_fn_inst: Zir.Inst.Index = 0,
60/// extra hash table lookup in the `monomorphed_funcs` set.60/// extra hash table lookup in the `monomorphed_funcs` set.
61/// Sema will set this to null when it takes ownership.61/// Sema will set this to null when it takes ownership.
62preallocated_new_func: ?*Module.Fn = null,62preallocated_new_func: ?*Module.Fn = null,
63/// Collects struct, union, enum, and opaque decls which need to have their
64/// fields resolved before this Sema is deinitialized.
65types_pending_resolution: std.ArrayListUnmanaged(Type) = .{},
6663
67const std = @import("std");64const std = @import("std");
68const mem = std.mem;65const mem = std.mem;
...@@ -99,7 +96,6 @@ pub fn deinit(sema: *Sema) void {...@@ -99,7 +96,6 @@ pub fn deinit(sema: *Sema) void {
99 sema.air_values.deinit(gpa);96 sema.air_values.deinit(gpa);
100 sema.inst_map.deinit(gpa);97 sema.inst_map.deinit(gpa);
101 sema.decl_val_table.deinit(gpa);98 sema.decl_val_table.deinit(gpa);
102 sema.types_pending_resolution.deinit(gpa);
103 sema.* = undefined;99 sema.* = undefined;
104}100}
105101
...@@ -1093,9 +1089,7 @@ fn zirStructDecl(...@@ -1093,9 +1089,7 @@ fn zirStructDecl(
1093 &struct_obj.namespace, new_decl, new_decl.name,1089 &struct_obj.namespace, new_decl, new_decl.name,
1094 });1090 });
1095 try sema.analyzeStructDecl(new_decl, inst, struct_obj);1091 try sema.analyzeStructDecl(new_decl, inst, struct_obj);
1096 try sema.types_pending_resolution.ensureUnusedCapacity(sema.gpa, 1);
1097 try new_decl.finalizeNewArena(&new_decl_arena);1092 try new_decl.finalizeNewArena(&new_decl_arena);
1098 sema.types_pending_resolution.appendAssumeCapacity(struct_ty);
1099 return sema.analyzeDeclVal(block, src, new_decl);1093 return sema.analyzeDeclVal(block, src, new_decl);
1100}1094}
11011095
...@@ -1396,9 +1390,7 @@ fn zirUnionDecl(...@@ -1396,9 +1390,7 @@ fn zirUnionDecl(
13961390
1397 new_decl.namespace = &union_obj.namespace;1391 new_decl.namespace = &union_obj.namespace;
13981392
1399 try sema.types_pending_resolution.ensureUnusedCapacity(sema.gpa, 1);
1400 try new_decl.finalizeNewArena(&new_decl_arena);1393 try new_decl.finalizeNewArena(&new_decl_arena);
1401 sema.types_pending_resolution.appendAssumeCapacity(union_ty);
1402 return sema.analyzeDeclVal(block, src, new_decl);1394 return sema.analyzeDeclVal(block, src, new_decl);
1403}1395}
14041396
...@@ -3176,12 +3168,6 @@ fn analyzeCall(...@@ -3176,12 +3168,6 @@ fn analyzeCall(
3176 });3168 });
3177 delete_memoized_call_key = false;3169 delete_memoized_call_key = false;
3178 }3170 }
3179
3180 // Much like in `Module.semaDecl`, if the result is a struct or union type,
3181 // we need to resolve the field type expressions right here, right now, while
3182 // the child `Sema` is still available, with the AIR instruction map intact,
3183 // because the field type expressions may reference into it.
3184 try sema.resolvePendingTypes(&child_block);
3185 }3171 }
31863172
3187 break :res2 result;3173 break :res2 result;
...@@ -11792,70 +11778,23 @@ pub fn resolveTypeLayout(...@@ -11792,70 +11778,23 @@ pub fn resolveTypeLayout(
11792 }11778 }
11793}11779}
1179411780
11795pub fn resolvePendingTypes(sema: *Sema, block: *Scope.Block) !void {11781fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) CompileError!Type {
11796 for (sema.types_pending_resolution.items) |ty| {
11797 // If an error happens resolving the fields of a struct, it will be marked
11798 // invalid and a proper compile error set up. But we should still look at the
11799 // other types pending resolution.
11800 const src: LazySrcLoc = .{ .node_offset = 0 };
11801 sema.resolveDeclFields(block, src, ty) catch continue;
11802 }
11803}
11804
11805/// `sema` and `block` are expected to be the same ones used for the `Decl`.
11806pub fn resolveDeclFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) !void {
11807 switch (ty.tag()) {11782 switch (ty.tag()) {
11808 .@"struct" => {11783 .@"struct" => {
11809 const struct_obj = ty.castTag(.@"struct").?.data;11784 const struct_obj = ty.castTag(.@"struct").?.data;
11810 if (struct_obj.owner_decl.namespace.parent != block.src_decl.namespace) return;
11811 switch (struct_obj.status) {11785 switch (struct_obj.status) {
11812 .none => {},11786 .none => {},
11813 .field_types_wip => {11787 .field_types_wip => {
11814 return sema.mod.fail(&block.base, src, "struct {} depends on itself", .{ty});11788 return sema.mod.fail(&block.base, src, "struct {} depends on itself", .{ty});
11815 },11789 },
11816 .have_field_types, .have_layout, .layout_wip => return,11790 .have_field_types, .have_layout, .layout_wip => return ty,
11817 }11791 }
11818 const old_src = block.src_decl;
11819 defer block.src_decl = old_src;
11820 block.src_decl = struct_obj.owner_decl;
1182111792
11822 struct_obj.status = .field_types_wip;11793 struct_obj.status = .field_types_wip;
11823 try sema.analyzeStructFields(block, struct_obj);11794 try semaStructFields(sema.mod, struct_obj);
11824 struct_obj.status = .have_field_types;11795 struct_obj.status = .have_field_types;
11825 },
11826 .@"union", .union_tagged => {
11827 const union_obj = ty.cast(Type.Payload.Union).?.data;
11828 if (union_obj.owner_decl.namespace.parent != block.src_decl.namespace) return;
11829 switch (union_obj.status) {
11830 .none => {},
11831 .field_types_wip => {
11832 return sema.mod.fail(&block.base, src, "union {} depends on itself", .{ty});
11833 },
11834 .have_field_types, .have_layout, .layout_wip => return,
11835 }
11836 const old_src = block.src_decl;
11837 defer block.src_decl = old_src;
11838 block.src_decl = union_obj.owner_decl;
11839
11840 union_obj.status = .field_types_wip;
11841 try sema.analyzeUnionFields(block, union_obj);
11842 union_obj.status = .have_field_types;
11843 },
11844 else => return,
11845 }
11846}
1184711796
11848fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) CompileError!Type {11797 return ty;
11849 switch (ty.tag()) {
11850 .@"struct" => {
11851 const struct_obj = ty.castTag(.@"struct").?.data;
11852 switch (struct_obj.status) {
11853 .none => unreachable,
11854 .field_types_wip => {
11855 return sema.mod.fail(&block.base, src, "struct {} depends on itself", .{ty});
11856 },
11857 .have_field_types, .have_layout, .layout_wip => return ty,
11858 }
11859 },11798 },
11860 .type_info => return sema.resolveBuiltinTypeFields(block, src, "TypeInfo"),11799 .type_info => return sema.resolveBuiltinTypeFields(block, src, "TypeInfo"),
11861 .extern_options => return sema.resolveBuiltinTypeFields(block, src, "ExternOptions"),11800 .extern_options => return sema.resolveBuiltinTypeFields(block, src, "ExternOptions"),
...@@ -11871,12 +11810,18 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type...@@ -11871,12 +11810,18 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type
11871 .@"union", .union_tagged => {11810 .@"union", .union_tagged => {
11872 const union_obj = ty.cast(Type.Payload.Union).?.data;11811 const union_obj = ty.cast(Type.Payload.Union).?.data;
11873 switch (union_obj.status) {11812 switch (union_obj.status) {
11874 .none => unreachable,11813 .none => {},
11875 .field_types_wip => {11814 .field_types_wip => {
11876 return sema.mod.fail(&block.base, src, "union {} depends on itself", .{ty});11815 return sema.mod.fail(&block.base, src, "union {} depends on itself", .{ty});
11877 },11816 },
11878 .have_field_types, .have_layout, .layout_wip => return ty,11817 .have_field_types, .have_layout, .layout_wip => return ty,
11879 }11818 }
11819
11820 union_obj.status = .field_types_wip;
11821 try semaUnionFields(sema.mod, union_obj);
11822 union_obj.status = .have_field_types;
11823
11824 return ty;
11880 },11825 },
11881 else => return ty,11826 else => return ty,
11882 }11827 }
...@@ -11892,16 +11837,16 @@ fn resolveBuiltinTypeFields(...@@ -11892,16 +11837,16 @@ fn resolveBuiltinTypeFields(
11892 return sema.resolveTypeFields(block, src, resolved_ty);11837 return sema.resolveTypeFields(block, src, resolved_ty);
11893}11838}
1189411839
11895fn analyzeStructFields(11840fn semaStructFields(
11896 sema: *Sema,11841 mod: *Module,
11897 block: *Scope.Block,
11898 struct_obj: *Module.Struct,11842 struct_obj: *Module.Struct,
11899) CompileError!void {11843) CompileError!void {
11900 const tracy = trace(@src());11844 const tracy = trace(@src());
11901 defer tracy.end();11845 defer tracy.end();
1190211846
11903 const gpa = sema.gpa;11847 const gpa = mod.gpa;
11904 const zir = sema.code;11848 const decl = struct_obj.owner_decl;
11849 const zir = struct_obj.namespace.file_scope.zir;
11905 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;11850 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;
11906 assert(extended.opcode == .struct_decl);11851 assert(extended.opcode == .struct_decl);
11907 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);11852 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
...@@ -11940,15 +11885,50 @@ fn analyzeStructFields(...@@ -11940,15 +11885,50 @@ fn analyzeStructFields(
11940 }11885 }
11941 extra_index += body.len;11886 extra_index += body.len;
1194211887
11943 var decl_arena = struct_obj.owner_decl.value_arena.?.promote(gpa);11888 var decl_arena = decl.value_arena.?.promote(gpa);
11944 defer struct_obj.owner_decl.value_arena.?.* = decl_arena.state;11889 defer decl.value_arena.?.* = decl_arena.state;
11890
11891 var analysis_arena = std.heap.ArenaAllocator.init(gpa);
11892 defer analysis_arena.deinit();
11893
11894 var sema: Sema = .{
11895 .mod = mod,
11896 .gpa = gpa,
11897 .arena = &analysis_arena.allocator,
11898 .perm_arena = &decl_arena.allocator,
11899 .code = zir,
11900 .owner_decl = decl,
11901 .func = null,
11902 .fn_ret_ty = Type.initTag(.void),
11903 .owner_func = null,
11904 };
11905 defer sema.deinit();
1194511906
11946 try struct_obj.fields.ensureTotalCapacity(&decl_arena.allocator, fields_len);11907 var wip_captures = try WipCaptureScope.init(gpa, &decl_arena.allocator, decl.src_scope);
11908 defer wip_captures.deinit();
11909
11910 var block_scope: Scope.Block = .{
11911 .parent = null,
11912 .sema = &sema,
11913 .src_decl = decl,
11914 .wip_capture_scope = wip_captures.scope,
11915 .instructions = .{},
11916 .inlining = null,
11917 .is_comptime = true,
11918 };
11919 defer {
11920 assert(block_scope.instructions.items.len == 0);
11921 block_scope.params.deinit(gpa);
11922 }
1194711923
11948 if (body.len != 0) {11924 if (body.len != 0) {
11949 _ = try sema.analyzeBody(block, body);11925 _ = try sema.analyzeBody(&block_scope, body);
11950 }11926 }
1195111927
11928 try wip_captures.finalize();
11929
11930 try struct_obj.fields.ensureTotalCapacity(&decl_arena.allocator, fields_len);
11931
11952 const bits_per_field = 4;11932 const bits_per_field = 4;
11953 const fields_per_u32 = 32 / bits_per_field;11933 const fields_per_u32 = 32 / bits_per_field;
11954 const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable;11934 const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable;
...@@ -11985,7 +11965,7 @@ fn analyzeStructFields(...@@ -11985,7 +11965,7 @@ fn analyzeStructFields(
11985 // TODO: if we need to report an error here, use a source location11965 // TODO: if we need to report an error here, use a source location
11986 // that points to this type expression rather than the struct.11966 // that points to this type expression rather than the struct.
11987 // But only resolve the source location if we need to emit a compile error.11967 // But only resolve the source location if we need to emit a compile error.
11988 try sema.resolveType(block, src, field_type_ref);11968 try sema.resolveType(&block_scope, src, field_type_ref);
1198911969
11990 const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name);11970 const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name);
11991 assert(!gop.found_existing);11971 assert(!gop.found_existing);
...@@ -12003,7 +11983,7 @@ fn analyzeStructFields(...@@ -12003,7 +11983,7 @@ fn analyzeStructFields(
12003 // TODO: if we need to report an error here, use a source location11983 // TODO: if we need to report an error here, use a source location
12004 // that points to this alignment expression rather than the struct.11984 // that points to this alignment expression rather than the struct.
12005 // But only resolve the source location if we need to emit a compile error.11985 // But only resolve the source location if we need to emit a compile error.
12006 const abi_align_val = (try sema.resolveInstConst(block, src, align_ref)).val;11986 const abi_align_val = (try sema.resolveInstConst(&block_scope, src, align_ref)).val;
12007 gop.value_ptr.abi_align = try abi_align_val.copy(&decl_arena.allocator);11987 gop.value_ptr.abi_align = try abi_align_val.copy(&decl_arena.allocator);
12008 }11988 }
12009 if (has_default) {11989 if (has_default) {
...@@ -12013,23 +11993,23 @@ fn analyzeStructFields(...@@ -12013,23 +11993,23 @@ fn analyzeStructFields(
12013 // TODO: if we need to report an error here, use a source location11993 // TODO: if we need to report an error here, use a source location
12014 // that points to this default value expression rather than the struct.11994 // that points to this default value expression rather than the struct.
12015 // But only resolve the source location if we need to emit a compile error.11995 // But only resolve the source location if we need to emit a compile error.
12016 const default_val = (try sema.resolveMaybeUndefVal(block, src, default_inst)) orelse11996 const default_val = (try sema.resolveMaybeUndefVal(&block_scope, src, default_inst)) orelse
12017 return sema.failWithNeededComptime(block, src);11997 return sema.failWithNeededComptime(&block_scope, src);
12018 gop.value_ptr.default_val = try default_val.copy(&decl_arena.allocator);11998 gop.value_ptr.default_val = try default_val.copy(&decl_arena.allocator);
12019 }11999 }
12020 }12000 }
12021}12001}
1202212002
12023fn analyzeUnionFields(12003fn semaUnionFields(
12024 sema: *Sema,12004 mod: *Module,
12025 block: *Scope.Block,
12026 union_obj: *Module.Union,12005 union_obj: *Module.Union,
12027) CompileError!void {12006) CompileError!void {
12028 const tracy = trace(@src());12007 const tracy = trace(@src());
12029 defer tracy.end();12008 defer tracy.end();
1203012009
12031 const gpa = sema.gpa;12010 const gpa = mod.gpa;
12032 const zir = sema.code;12011 const decl = union_obj.owner_decl;
12012 const zir = union_obj.namespace.file_scope.zir;
12033 const extended = zir.instructions.items(.data)[union_obj.zir_index].extended;12013 const extended = zir.instructions.items(.data)[union_obj.zir_index].extended;
12034 assert(extended.opcode == .union_decl);12014 assert(extended.opcode == .union_decl);
12035 const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small);12015 const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small);
...@@ -12077,20 +12057,56 @@ fn analyzeUnionFields(...@@ -12077,20 +12057,56 @@ fn analyzeUnionFields(
12077 var decl_arena = union_obj.owner_decl.value_arena.?.promote(gpa);12057 var decl_arena = union_obj.owner_decl.value_arena.?.promote(gpa);
12078 defer union_obj.owner_decl.value_arena.?.* = decl_arena.state;12058 defer union_obj.owner_decl.value_arena.?.* = decl_arena.state;
1207912059
12080 try union_obj.fields.ensureTotalCapacity(&decl_arena.allocator, fields_len);12060 var analysis_arena = std.heap.ArenaAllocator.init(gpa);
12061 defer analysis_arena.deinit();
12062
12063 var sema: Sema = .{
12064 .mod = mod,
12065 .gpa = gpa,
12066 .arena = &analysis_arena.allocator,
12067 .perm_arena = &decl_arena.allocator,
12068 .code = zir,
12069 .owner_decl = decl,
12070 .func = null,
12071 .fn_ret_ty = Type.initTag(.void),
12072 .owner_func = null,
12073 };
12074 defer sema.deinit();
12075
12076 var wip_captures = try WipCaptureScope.init(gpa, &decl_arena.allocator, decl.src_scope);
12077 defer wip_captures.deinit();
12078
12079 var block_scope: Scope.Block = .{
12080 .parent = null,
12081 .sema = &sema,
12082 .src_decl = decl,
12083 .wip_capture_scope = wip_captures.scope,
12084 .instructions = .{},
12085 .inlining = null,
12086 .is_comptime = true,
12087 };
12088 defer {
12089 assert(block_scope.instructions.items.len == 0);
12090 block_scope.params.deinit(gpa);
12091 }
1208112092
12082 if (body.len != 0) {12093 if (body.len != 0) {
12083 _ = try sema.analyzeBody(block, body);12094 _ = try sema.analyzeBody(&block_scope, body);
12084 }12095 }
12096
12097 try wip_captures.finalize();
12098
12099 try union_obj.fields.ensureTotalCapacity(&decl_arena.allocator, fields_len);
12100
12085 var int_tag_ty: Type = undefined;12101 var int_tag_ty: Type = undefined;
12086 var enum_field_names: ?*Module.EnumNumbered.NameMap = null;12102 var enum_field_names: ?*Module.EnumNumbered.NameMap = null;
12087 var enum_value_map: ?*Module.EnumNumbered.ValueMap = null;12103 var enum_value_map: ?*Module.EnumNumbered.ValueMap = null;
12088 if (tag_type_ref != .none) {12104 if (tag_type_ref != .none) {
12089 const provided_ty = try sema.resolveType(block, src, tag_type_ref);12105 const provided_ty = try sema.resolveType(&block_scope, src, tag_type_ref);
12090 if (small.auto_enum_tag) {12106 if (small.auto_enum_tag) {
12091 // The provided type is an integer type and we must construct the enum tag type here.12107 // The provided type is an integer type and we must construct the enum tag type here.
12092 int_tag_ty = provided_ty;12108 int_tag_ty = provided_ty;
12093 union_obj.tag_ty = try sema.generateUnionTagTypeNumbered(block, fields_len, provided_ty);12109 union_obj.tag_ty = try sema.generateUnionTagTypeNumbered(&block_scope, fields_len, provided_ty);
12094 enum_field_names = &union_obj.tag_ty.castTag(.enum_numbered).?.data.fields;12110 enum_field_names = &union_obj.tag_ty.castTag(.enum_numbered).?.data.fields;
12095 enum_value_map = &union_obj.tag_ty.castTag(.enum_numbered).?.data.values;12111 enum_value_map = &union_obj.tag_ty.castTag(.enum_numbered).?.data.values;
12096 } else {12112 } else {
...@@ -12101,7 +12117,7 @@ fn analyzeUnionFields(...@@ -12101,7 +12117,7 @@ fn analyzeUnionFields(
12101 // If auto_enum_tag is false, this is an untagged union. However, for semantic analysis12117 // If auto_enum_tag is false, this is an untagged union. However, for semantic analysis
12102 // purposes, we still auto-generate an enum tag type the same way. That the union is12118 // purposes, we still auto-generate an enum tag type the same way. That the union is
12103 // untagged is represented by the Type tag (union vs union_tagged).12119 // untagged is represented by the Type tag (union vs union_tagged).
12104 union_obj.tag_ty = try sema.generateUnionTagTypeSimple(block, fields_len);12120 union_obj.tag_ty = try sema.generateUnionTagTypeSimple(&block_scope, fields_len);
12105 enum_field_names = &union_obj.tag_ty.castTag(.enum_simple).?.data.fields;12121 enum_field_names = &union_obj.tag_ty.castTag(.enum_simple).?.data.fields;
12106 }12122 }
1210712123
...@@ -12150,8 +12166,8 @@ fn analyzeUnionFields(...@@ -12150,8 +12166,8 @@ fn analyzeUnionFields(
1215012166
12151 if (enum_value_map) |map| {12167 if (enum_value_map) |map| {
12152 const tag_src = src; // TODO better source location12168 const tag_src = src; // TODO better source location
12153 const coerced = try sema.coerce(block, int_tag_ty, tag_ref, tag_src);12169 const coerced = try sema.coerce(&block_scope, int_tag_ty, tag_ref, tag_src);
12154 const val = try sema.resolveConstValue(block, tag_src, coerced);12170 const val = try sema.resolveConstValue(&block_scope, tag_src, coerced);
12155 map.putAssumeCapacityContext(val, {}, .{ .ty = int_tag_ty });12171 map.putAssumeCapacityContext(val, {}, .{ .ty = int_tag_ty });
12156 }12172 }
1215712173
...@@ -12167,7 +12183,7 @@ fn analyzeUnionFields(...@@ -12167,7 +12183,7 @@ fn analyzeUnionFields(
12167 // TODO: if we need to report an error here, use a source location12183 // TODO: if we need to report an error here, use a source location
12168 // that points to this type expression rather than the union.12184 // that points to this type expression rather than the union.
12169 // But only resolve the source location if we need to emit a compile error.12185 // But only resolve the source location if we need to emit a compile error.
12170 try sema.resolveType(block, src, field_type_ref);12186 try sema.resolveType(&block_scope, src, field_type_ref);
1217112187
12172 const gop = union_obj.fields.getOrPutAssumeCapacity(field_name);12188 const gop = union_obj.fields.getOrPutAssumeCapacity(field_name);
12173 assert(!gop.found_existing);12189 assert(!gop.found_existing);
...@@ -12180,7 +12196,7 @@ fn analyzeUnionFields(...@@ -12180,7 +12196,7 @@ fn analyzeUnionFields(
12180 // TODO: if we need to report an error here, use a source location12196 // TODO: if we need to report an error here, use a source location
12181 // that points to this alignment expression rather than the struct.12197 // that points to this alignment expression rather than the struct.
12182 // But only resolve the source location if we need to emit a compile error.12198 // But only resolve the source location if we need to emit a compile error.
12183 const abi_align_val = (try sema.resolveInstConst(block, src, align_ref)).val;12199 const abi_align_val = (try sema.resolveInstConst(&block_scope, src, align_ref)).val;
12184 gop.value_ptr.abi_align = try abi_align_val.copy(&decl_arena.allocator);12200 gop.value_ptr.abi_align = try abi_align_val.copy(&decl_arena.allocator);
12185 } else {12201 } else {
12186 gop.value_ptr.abi_align = Value.initTag(.abi_align_default);12202 gop.value_ptr.abi_align = Value.initTag(.abi_align_default);