authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-03 19:55:27+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-09 11:59:10+03:00
logc76b5c1a31ebe09726cd29e7a6da69613eabfd10
treebb714ca03635ecf990829cf6d2a5e31a8de203db
parentd769fd0102dee7ea24f957c3c96e2336d1c18839

stage2: correct node offset of nested declarations


9 files changed, 106 insertions(+), 114 deletions(-)

src/AstGen.zig+17-4
...@@ -4278,7 +4278,7 @@ fn structDeclInner(...@@ -4278,7 +4278,7 @@ fn structDeclInner(
4278 var known_non_opv = false;4278 var known_non_opv = false;
4279 var known_comptime_only = false;4279 var known_comptime_only = false;
4280 for (container_decl.ast.members) |member_node| {4280 for (container_decl.ast.members) |member_node| {
4281 const member = switch (try containerMember(gz, &namespace.base, &wip_members, member_node)) {4281 const member = switch (try containerMember(&block_scope, &namespace.base, &wip_members, member_node)) {
4282 .decl => continue,4282 .decl => continue,
4283 .field => |field| field,4283 .field => |field| field,
4284 };4284 };
...@@ -4445,7 +4445,7 @@ fn unionDeclInner(...@@ -4445,7 +4445,7 @@ fn unionDeclInner(
4445 defer wip_members.deinit();4445 defer wip_members.deinit();
44464446
4447 for (members) |member_node| {4447 for (members) |member_node| {
4448 const member = switch (try containerMember(gz, &namespace.base, &wip_members, member_node)) {4448 const member = switch (try containerMember(&block_scope, &namespace.base, &wip_members, member_node)) {
4449 .decl => continue,4449 .decl => continue,
4450 .field => |field| field,4450 .field => |field| field,
4451 };4451 };
...@@ -4732,7 +4732,7 @@ fn containerDecl(...@@ -4732,7 +4732,7 @@ fn containerDecl(
4732 for (container_decl.ast.members) |member_node| {4732 for (container_decl.ast.members) |member_node| {
4733 if (member_node == counts.nonexhaustive_node)4733 if (member_node == counts.nonexhaustive_node)
4734 continue;4734 continue;
4735 const member = switch (try containerMember(gz, &namespace.base, &wip_members, member_node)) {4735 const member = switch (try containerMember(&block_scope, &namespace.base, &wip_members, member_node)) {
4736 .decl => continue,4736 .decl => continue,
4737 .field => |field| field,4737 .field => |field| field,
4738 };4738 };
...@@ -4810,13 +4810,26 @@ fn containerDecl(...@@ -4810,13 +4810,26 @@ fn containerDecl(
4810 };4810 };
4811 defer namespace.deinit(gpa);4811 defer namespace.deinit(gpa);
48124812
4813 astgen.advanceSourceCursorToNode(node);
4814 var block_scope: GenZir = .{
4815 .parent = &namespace.base,
4816 .decl_node_index = node,
4817 .decl_line = astgen.source_line,
4818 .astgen = astgen,
4819 .force_comptime = true,
4820 .in_defer = false,
4821 .instructions = gz.instructions,
4822 .instructions_top = gz.instructions.items.len,
4823 };
4824 defer block_scope.unstack();
4825
4813 const decl_count = try astgen.scanDecls(&namespace, container_decl.ast.members);4826 const decl_count = try astgen.scanDecls(&namespace, container_decl.ast.members);
48144827
4815 var wip_members = try WipMembers.init(gpa, &astgen.scratch, decl_count, 0, 0, 0);4828 var wip_members = try WipMembers.init(gpa, &astgen.scratch, decl_count, 0, 0, 0);
4816 defer wip_members.deinit();4829 defer wip_members.deinit();
48174830
4818 for (container_decl.ast.members) |member_node| {4831 for (container_decl.ast.members) |member_node| {
4819 const res = try containerMember(gz, &namespace.base, &wip_members, member_node);4832 const res = try containerMember(&block_scope, &namespace.base, &wip_members, member_node);
4820 if (res == .field) {4833 if (res == .field) {
4821 return astgen.failNode(member_node, "opaque types cannot have fields", .{});4834 return astgen.failNode(member_node, "opaque types cannot have fields", .{});
4822 }4835 }
src/Module.zig+9-24
...@@ -853,8 +853,6 @@ pub const EmitH = struct {...@@ -853,8 +853,6 @@ pub const EmitH = struct {
853pub const ErrorSet = struct {853pub const ErrorSet = struct {
854 /// The Decl that corresponds to the error set itself.854 /// The Decl that corresponds to the error set itself.
855 owner_decl: Decl.Index,855 owner_decl: Decl.Index,
856 /// Offset from Decl node index, points to the error set AST node.
857 node_offset: i32,
858 /// The string bytes are stored in the owner Decl arena.856 /// The string bytes are stored in the owner Decl arena.
859 /// These must be in sorted order. See sortNames.857 /// These must be in sorted order. See sortNames.
860 names: NameMap,858 names: NameMap,
...@@ -866,7 +864,7 @@ pub const ErrorSet = struct {...@@ -866,7 +864,7 @@ pub const ErrorSet = struct {
866 return .{864 return .{
867 .file_scope = owner_decl.getFileScope(),865 .file_scope = owner_decl.getFileScope(),
868 .parent_decl_node = owner_decl.src_node,866 .parent_decl_node = owner_decl.src_node,
869 .lazy = LazySrcLoc.nodeOffset(self.node_offset),867 .lazy = LazySrcLoc.nodeOffset(0),
870 };868 };
871 }869 }
872870
...@@ -893,8 +891,6 @@ pub const Struct = struct {...@@ -893,8 +891,6 @@ pub const Struct = struct {
893 namespace: Namespace,891 namespace: Namespace,
894 /// The Decl that corresponds to the struct itself.892 /// The Decl that corresponds to the struct itself.
895 owner_decl: Decl.Index,893 owner_decl: Decl.Index,
896 /// Offset from `owner_decl`, points to the struct AST node.
897 node_offset: i32,
898 /// Index of the struct_decl ZIR instruction.894 /// Index of the struct_decl ZIR instruction.
899 zir_index: Zir.Inst.Index,895 zir_index: Zir.Inst.Index,
900896
...@@ -953,7 +949,7 @@ pub const Struct = struct {...@@ -953,7 +949,7 @@ pub const Struct = struct {
953 return .{949 return .{
954 .file_scope = owner_decl.getFileScope(),950 .file_scope = owner_decl.getFileScope(),
955 .parent_decl_node = owner_decl.src_node,951 .parent_decl_node = owner_decl.src_node,
956 .lazy = LazySrcLoc.nodeOffset(s.node_offset),952 .lazy = LazySrcLoc.nodeOffset(0),
957 };953 };
958 }954 }
959955
...@@ -968,7 +964,7 @@ pub const Struct = struct {...@@ -968,7 +964,7 @@ pub const Struct = struct {
968 });964 });
969 return s.srcLoc(mod);965 return s.srcLoc(mod);
970 };966 };
971 const node = owner_decl.relativeToNodeIndex(s.node_offset);967 const node = owner_decl.relativeToNodeIndex(0);
972 const node_tags = tree.nodes.items(.tag);968 const node_tags = tree.nodes.items(.tag);
973 switch (node_tags[node]) {969 switch (node_tags[node]) {
974 .container_decl,970 .container_decl,
...@@ -1060,8 +1056,6 @@ pub const Struct = struct {...@@ -1060,8 +1056,6 @@ pub const Struct = struct {
1060pub const EnumSimple = struct {1056pub const EnumSimple = struct {
1061 /// The Decl that corresponds to the enum itself.1057 /// The Decl that corresponds to the enum itself.
1062 owner_decl: Decl.Index,1058 owner_decl: Decl.Index,
1063 /// Offset from `owner_decl`, points to the enum decl AST node.
1064 node_offset: i32,
1065 /// Set of field names in declaration order.1059 /// Set of field names in declaration order.
1066 fields: NameMap,1060 fields: NameMap,
10671061
...@@ -1072,7 +1066,7 @@ pub const EnumSimple = struct {...@@ -1072,7 +1066,7 @@ pub const EnumSimple = struct {
1072 return .{1066 return .{
1073 .file_scope = owner_decl.getFileScope(),1067 .file_scope = owner_decl.getFileScope(),
1074 .parent_decl_node = owner_decl.src_node,1068 .parent_decl_node = owner_decl.src_node,
1075 .lazy = LazySrcLoc.nodeOffset(self.node_offset),1069 .lazy = LazySrcLoc.nodeOffset(0),
1076 };1070 };
1077 }1071 }
1078};1072};
...@@ -1083,8 +1077,6 @@ pub const EnumSimple = struct {...@@ -1083,8 +1077,6 @@ pub const EnumSimple = struct {
1083pub const EnumNumbered = struct {1077pub const EnumNumbered = struct {
1084 /// The Decl that corresponds to the enum itself.1078 /// The Decl that corresponds to the enum itself.
1085 owner_decl: Decl.Index,1079 owner_decl: Decl.Index,
1086 /// Offset from `owner_decl`, points to the enum decl AST node.
1087 node_offset: i32,
1088 /// An integer type which is used for the numerical value of the enum.1080 /// An integer type which is used for the numerical value of the enum.
1089 /// Whether zig chooses this type or the user specifies it, it is stored here.1081 /// Whether zig chooses this type or the user specifies it, it is stored here.
1090 tag_ty: Type,1082 tag_ty: Type,
...@@ -1103,7 +1095,7 @@ pub const EnumNumbered = struct {...@@ -1103,7 +1095,7 @@ pub const EnumNumbered = struct {
1103 return .{1095 return .{
1104 .file_scope = owner_decl.getFileScope(),1096 .file_scope = owner_decl.getFileScope(),
1105 .parent_decl_node = owner_decl.src_node,1097 .parent_decl_node = owner_decl.src_node,
1106 .lazy = LazySrcLoc.nodeOffset(self.node_offset),1098 .lazy = LazySrcLoc.nodeOffset(0),
1107 };1099 };
1108 }1100 }
1109};1101};
...@@ -1113,8 +1105,6 @@ pub const EnumNumbered = struct {...@@ -1113,8 +1105,6 @@ pub const EnumNumbered = struct {
1113pub const EnumFull = struct {1105pub const EnumFull = struct {
1114 /// The Decl that corresponds to the enum itself.1106 /// The Decl that corresponds to the enum itself.
1115 owner_decl: Decl.Index,1107 owner_decl: Decl.Index,
1116 /// Offset from `owner_decl`, points to the enum decl AST node.
1117 node_offset: i32,
1118 /// An integer type which is used for the numerical value of the enum.1108 /// An integer type which is used for the numerical value of the enum.
1119 /// Whether zig chooses this type or the user specifies it, it is stored here.1109 /// Whether zig chooses this type or the user specifies it, it is stored here.
1120 tag_ty: Type,1110 tag_ty: Type,
...@@ -1137,7 +1127,7 @@ pub const EnumFull = struct {...@@ -1137,7 +1127,7 @@ pub const EnumFull = struct {
1137 return .{1127 return .{
1138 .file_scope = owner_decl.getFileScope(),1128 .file_scope = owner_decl.getFileScope(),
1139 .parent_decl_node = owner_decl.src_node,1129 .parent_decl_node = owner_decl.src_node,
1140 .lazy = LazySrcLoc.nodeOffset(self.node_offset),1130 .lazy = LazySrcLoc.nodeOffset(0),
1141 };1131 };
1142 }1132 }
1143};1133};
...@@ -1155,8 +1145,6 @@ pub const Union = struct {...@@ -1155,8 +1145,6 @@ pub const Union = struct {
1155 namespace: Namespace,1145 namespace: Namespace,
1156 /// The Decl that corresponds to the union itself.1146 /// The Decl that corresponds to the union itself.
1157 owner_decl: Decl.Index,1147 owner_decl: Decl.Index,
1158 /// Offset from `owner_decl`, points to the union decl AST node.
1159 node_offset: i32,
1160 /// Index of the union_decl ZIR instruction.1148 /// Index of the union_decl ZIR instruction.
1161 zir_index: Zir.Inst.Index,1149 zir_index: Zir.Inst.Index,
11621150
...@@ -1203,7 +1191,7 @@ pub const Union = struct {...@@ -1203,7 +1191,7 @@ pub const Union = struct {
1203 return .{1191 return .{
1204 .file_scope = owner_decl.getFileScope(),1192 .file_scope = owner_decl.getFileScope(),
1205 .parent_decl_node = owner_decl.src_node,1193 .parent_decl_node = owner_decl.src_node,
1206 .lazy = LazySrcLoc.nodeOffset(self.node_offset),1194 .lazy = LazySrcLoc.nodeOffset(0),
1207 };1195 };
1208 }1196 }
12091197
...@@ -1218,7 +1206,7 @@ pub const Union = struct {...@@ -1218,7 +1206,7 @@ pub const Union = struct {
1218 });1206 });
1219 return u.srcLoc(mod);1207 return u.srcLoc(mod);
1220 };1208 };
1221 const node = owner_decl.relativeToNodeIndex(u.node_offset);1209 const node = owner_decl.relativeToNodeIndex(0);
1222 const node_tags = tree.nodes.items(.tag);1210 const node_tags = tree.nodes.items(.tag);
1223 var buf: [2]Ast.Node.Index = undefined;1211 var buf: [2]Ast.Node.Index = undefined;
1224 switch (node_tags[node]) {1212 switch (node_tags[node]) {
...@@ -1410,8 +1398,6 @@ pub const Union = struct {...@@ -1410,8 +1398,6 @@ pub const Union = struct {
1410pub const Opaque = struct {1398pub const Opaque = struct {
1411 /// The Decl that corresponds to the opaque itself.1399 /// The Decl that corresponds to the opaque itself.
1412 owner_decl: Decl.Index,1400 owner_decl: Decl.Index,
1413 /// Offset from `owner_decl`, points to the opaque decl AST node.
1414 node_offset: i32,
1415 /// Represents the declarations inside this opaque.1401 /// Represents the declarations inside this opaque.
1416 namespace: Namespace,1402 namespace: Namespace,
14171403
...@@ -1420,7 +1406,7 @@ pub const Opaque = struct {...@@ -1420,7 +1406,7 @@ pub const Opaque = struct {
1420 return .{1406 return .{
1421 .file_scope = owner_decl.getFileScope(),1407 .file_scope = owner_decl.getFileScope(),
1422 .parent_decl_node = owner_decl.src_node,1408 .parent_decl_node = owner_decl.src_node,
1423 .lazy = LazySrcLoc.nodeOffset(self.node_offset),1409 .lazy = LazySrcLoc.nodeOffset(0),
1424 };1410 };
1425 }1411 }
14261412
...@@ -4337,7 +4323,6 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {...@@ -4337,7 +4323,6 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
4337 struct_obj.* = .{4323 struct_obj.* = .{
4338 .owner_decl = undefined, // set below4324 .owner_decl = undefined, // set below
4339 .fields = .{},4325 .fields = .{},
4340 .node_offset = 0, // it's the struct for the root file
4341 .zir_index = undefined, // set below4326 .zir_index = undefined, // set below
4342 .layout = .Auto,4327 .layout = .Auto,
4343 .status = .none,4328 .status = .none,
src/Sema.zig+30-39
...@@ -1818,10 +1818,10 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS...@@ -1818,10 +1818,10 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS
18181818
1819 const tree = try sema.getAstTree(block);1819 const tree = try sema.getAstTree(block);
1820 const decl = sema.mod.declPtr(decl_index);1820 const decl = sema.mod.declPtr(decl_index);
1821 const field_src = enumFieldSrcLoc(decl, tree.*, container_ty.getNodeOffset(), field_index);1821 const field_src = enumFieldSrcLoc(decl, tree.*, 0, field_index);
1822 const default_value_src: LazySrcLoc = .{ .node_offset_field_default = field_src.node_offset.x };1822 const default_value_src: LazySrcLoc = .{ .node_offset_field_default = field_src.node_offset.x };
18231823
1824 try sema.errNote(block, default_value_src, msg, "default value set here", .{});1824 try sema.mod.errNoteNonLazy(default_value_src.toSrcLoc(decl), msg, "default value set here", .{});
1825 break :msg msg;1825 break :msg msg;
1826 };1826 };
1827 return sema.failWithOwnedErrorMsg(msg);1827 return sema.failWithOwnedErrorMsg(msg);
...@@ -1866,7 +1866,7 @@ fn addFieldErrNote(...@@ -1866,7 +1866,7 @@ fn addFieldErrNote(
1866 const decl_index = container_ty.getOwnerDecl();1866 const decl_index = container_ty.getOwnerDecl();
1867 const decl = mod.declPtr(decl_index);1867 const decl = mod.declPtr(decl_index);
1868 const tree = try sema.getAstTree(block);1868 const tree = try sema.getAstTree(block);
1869 const field_src = enumFieldSrcLoc(decl, tree.*, container_ty.getNodeOffset(), field_index);1869 const field_src = enumFieldSrcLoc(decl, tree.*, 0, field_index);
1870 try mod.errNoteNonLazy(field_src.toSrcLoc(decl), parent, format, args);1870 try mod.errNoteNonLazy(field_src.toSrcLoc(decl), parent, format, args);
1871}1871}
18721872
...@@ -2262,7 +2262,7 @@ fn zirStructDecl(...@@ -2262,7 +2262,7 @@ fn zirStructDecl(
2262 const struct_obj = try new_decl_arena_allocator.create(Module.Struct);2262 const struct_obj = try new_decl_arena_allocator.create(Module.Struct);
2263 const struct_ty = try Type.Tag.@"struct".create(new_decl_arena_allocator, struct_obj);2263 const struct_ty = try Type.Tag.@"struct".create(new_decl_arena_allocator, struct_obj);
2264 const struct_val = try Value.Tag.ty.create(new_decl_arena_allocator, struct_ty);2264 const struct_val = try Value.Tag.ty.create(new_decl_arena_allocator, struct_ty);
2265 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{2265 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
2266 .ty = Type.type,2266 .ty = Type.type,
2267 .val = struct_val,2267 .val = struct_val,
2268 }, small.name_strategy, "struct", inst);2268 }, small.name_strategy, "struct", inst);
...@@ -2272,7 +2272,6 @@ fn zirStructDecl(...@@ -2272,7 +2272,6 @@ fn zirStructDecl(
2272 struct_obj.* = .{2272 struct_obj.* = .{
2273 .owner_decl = new_decl_index,2273 .owner_decl = new_decl_index,
2274 .fields = .{},2274 .fields = .{},
2275 .node_offset = src.node_offset.x,
2276 .zir_index = inst,2275 .zir_index = inst,
2277 .layout = small.layout,2276 .layout = small.layout,
2278 .status = .none,2277 .status = .none,
...@@ -2294,6 +2293,7 @@ fn zirStructDecl(...@@ -2294,6 +2293,7 @@ fn zirStructDecl(
2294fn createAnonymousDeclTypeNamed(2293fn createAnonymousDeclTypeNamed(
2295 sema: *Sema,2294 sema: *Sema,
2296 block: *Block,2295 block: *Block,
2296 src: LazySrcLoc,
2297 typed_value: TypedValue,2297 typed_value: TypedValue,
2298 name_strategy: Zir.Inst.NameStrategy,2298 name_strategy: Zir.Inst.NameStrategy,
2299 anon_prefix: []const u8,2299 anon_prefix: []const u8,
...@@ -2303,7 +2303,8 @@ fn createAnonymousDeclTypeNamed(...@@ -2303,7 +2303,8 @@ fn createAnonymousDeclTypeNamed(
2303 const namespace = block.namespace;2303 const namespace = block.namespace;
2304 const src_scope = block.wip_capture_scope;2304 const src_scope = block.wip_capture_scope;
2305 const src_decl = mod.declPtr(block.src_decl);2305 const src_decl = mod.declPtr(block.src_decl);
2306 const new_decl_index = try mod.allocateNewDecl(namespace, src_decl.src_node, src_scope);2306 const src_node = src_decl.relativeToNodeIndex(src.node_offset.x);
2307 const new_decl_index = try mod.allocateNewDecl(namespace, src_node, src_scope);
2307 errdefer mod.destroyDecl(new_decl_index);2308 errdefer mod.destroyDecl(new_decl_index);
23082309
2309 switch (name_strategy) {2310 switch (name_strategy) {
...@@ -2378,7 +2379,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2378,7 +2379,7 @@ fn createAnonymousDeclTypeNamed(
2378 },2379 },
2379 else => {},2380 else => {},
2380 };2381 };
2381 return sema.createAnonymousDeclTypeNamed(block, typed_value, .anon, anon_prefix, null);2382 return sema.createAnonymousDeclTypeNamed(block, src, typed_value, .anon, anon_prefix, null);
2382 },2383 },
2383 }2384 }
2384}2385}
...@@ -2442,7 +2443,7 @@ fn zirEnumDecl(...@@ -2442,7 +2443,7 @@ fn zirEnumDecl(
2442 };2443 };
2443 const enum_ty = Type.initPayload(&enum_ty_payload.base);2444 const enum_ty = Type.initPayload(&enum_ty_payload.base);
2444 const enum_val = try Value.Tag.ty.create(new_decl_arena_allocator, enum_ty);2445 const enum_val = try Value.Tag.ty.create(new_decl_arena_allocator, enum_ty);
2445 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{2446 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
2446 .ty = Type.type,2447 .ty = Type.type,
2447 .val = enum_val,2448 .val = enum_val,
2448 }, small.name_strategy, "enum", inst);2449 }, small.name_strategy, "enum", inst);
...@@ -2456,7 +2457,6 @@ fn zirEnumDecl(...@@ -2456,7 +2457,6 @@ fn zirEnumDecl(
2456 .tag_ty_inferred = true,2457 .tag_ty_inferred = true,
2457 .fields = .{},2458 .fields = .{},
2458 .values = .{},2459 .values = .{},
2459 .node_offset = src.node_offset.x,
2460 .namespace = .{2460 .namespace = .{
2461 .parent = block.namespace,2461 .parent = block.namespace,
2462 .ty = enum_ty,2462 .ty = enum_ty,
...@@ -2684,7 +2684,7 @@ fn zirUnionDecl(...@@ -2684,7 +2684,7 @@ fn zirUnionDecl(
2684 const union_ty = Type.initPayload(&union_payload.base);2684 const union_ty = Type.initPayload(&union_payload.base);
2685 const union_val = try Value.Tag.ty.create(new_decl_arena_allocator, union_ty);2685 const union_val = try Value.Tag.ty.create(new_decl_arena_allocator, union_ty);
2686 const mod = sema.mod;2686 const mod = sema.mod;
2687 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{2687 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
2688 .ty = Type.type,2688 .ty = Type.type,
2689 .val = union_val,2689 .val = union_val,
2690 }, small.name_strategy, "union", inst);2690 }, small.name_strategy, "union", inst);
...@@ -2695,7 +2695,6 @@ fn zirUnionDecl(...@@ -2695,7 +2695,6 @@ fn zirUnionDecl(
2695 .owner_decl = new_decl_index,2695 .owner_decl = new_decl_index,
2696 .tag_ty = Type.initTag(.@"null"),2696 .tag_ty = Type.initTag(.@"null"),
2697 .fields = .{},2697 .fields = .{},
2698 .node_offset = src.node_offset.x,
2699 .zir_index = inst,2698 .zir_index = inst,
2700 .layout = small.layout,2699 .layout = small.layout,
2701 .status = .none,2700 .status = .none,
...@@ -2753,7 +2752,7 @@ fn zirOpaqueDecl(...@@ -2753,7 +2752,7 @@ fn zirOpaqueDecl(
2753 };2752 };
2754 const opaque_ty = Type.initPayload(&opaque_ty_payload.base);2753 const opaque_ty = Type.initPayload(&opaque_ty_payload.base);
2755 const opaque_val = try Value.Tag.ty.create(new_decl_arena_allocator, opaque_ty);2754 const opaque_val = try Value.Tag.ty.create(new_decl_arena_allocator, opaque_ty);
2756 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{2755 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
2757 .ty = Type.type,2756 .ty = Type.type,
2758 .val = opaque_val,2757 .val = opaque_val,
2759 }, small.name_strategy, "opaque", inst);2758 }, small.name_strategy, "opaque", inst);
...@@ -2763,7 +2762,6 @@ fn zirOpaqueDecl(...@@ -2763,7 +2762,6 @@ fn zirOpaqueDecl(
27632762
2764 opaque_obj.* = .{2763 opaque_obj.* = .{
2765 .owner_decl = new_decl_index,2764 .owner_decl = new_decl_index,
2766 .node_offset = src.node_offset.x,
2767 .namespace = .{2765 .namespace = .{
2768 .parent = block.namespace,2766 .parent = block.namespace,
2769 .ty = opaque_ty,2767 .ty = opaque_ty,
...@@ -2802,7 +2800,7 @@ fn zirErrorSetDecl(...@@ -2802,7 +2800,7 @@ fn zirErrorSetDecl(
2802 const error_set_ty = try Type.Tag.error_set.create(new_decl_arena_allocator, error_set);2800 const error_set_ty = try Type.Tag.error_set.create(new_decl_arena_allocator, error_set);
2803 const error_set_val = try Value.Tag.ty.create(new_decl_arena_allocator, error_set_ty);2801 const error_set_val = try Value.Tag.ty.create(new_decl_arena_allocator, error_set_ty);
2804 const mod = sema.mod;2802 const mod = sema.mod;
2805 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{2803 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
2806 .ty = Type.type,2804 .ty = Type.type,
2807 .val = error_set_val,2805 .val = error_set_val,
2808 }, name_strategy, "error", inst);2806 }, name_strategy, "error", inst);
...@@ -2827,7 +2825,6 @@ fn zirErrorSetDecl(...@@ -2827,7 +2825,6 @@ fn zirErrorSetDecl(
28272825
2828 error_set.* = .{2826 error_set.* = .{
2829 .owner_decl = new_decl_index,2827 .owner_decl = new_decl_index,
2830 .node_offset = inst_data.src_node,
2831 .names = names,2828 .names = names,
2832 };2829 };
2833 try new_decl.finalizeNewArena(&new_decl_arena);2830 try new_decl.finalizeNewArena(&new_decl_arena);
...@@ -16336,7 +16333,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in...@@ -16336,7 +16333,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
16336 };16333 };
16337 const enum_ty = Type.initPayload(&enum_ty_payload.base);16334 const enum_ty = Type.initPayload(&enum_ty_payload.base);
16338 const enum_val = try Value.Tag.ty.create(new_decl_arena_allocator, enum_ty);16335 const enum_val = try Value.Tag.ty.create(new_decl_arena_allocator, enum_ty);
16339 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{16336 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
16340 .ty = Type.type,16337 .ty = Type.type,
16341 .val = enum_val,16338 .val = enum_val,
16342 }, name_strategy, "enum", inst);16339 }, name_strategy, "enum", inst);
...@@ -16350,7 +16347,6 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in...@@ -16350,7 +16347,6 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
16350 .tag_ty_inferred = false,16347 .tag_ty_inferred = false,
16351 .fields = .{},16348 .fields = .{},
16352 .values = .{},16349 .values = .{},
16353 .node_offset = src.node_offset.x,
16354 .namespace = .{16350 .namespace = .{
16355 .parent = block.namespace,16351 .parent = block.namespace,
16356 .ty = enum_ty,16352 .ty = enum_ty,
...@@ -16433,7 +16429,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in...@@ -16433,7 +16429,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
16433 };16429 };
16434 const opaque_ty = Type.initPayload(&opaque_ty_payload.base);16430 const opaque_ty = Type.initPayload(&opaque_ty_payload.base);
16435 const opaque_val = try Value.Tag.ty.create(new_decl_arena_allocator, opaque_ty);16431 const opaque_val = try Value.Tag.ty.create(new_decl_arena_allocator, opaque_ty);
16436 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{16432 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
16437 .ty = Type.type,16433 .ty = Type.type,
16438 .val = opaque_val,16434 .val = opaque_val,
16439 }, name_strategy, "opaque", inst);16435 }, name_strategy, "opaque", inst);
...@@ -16443,7 +16439,6 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in...@@ -16443,7 +16439,6 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1644316439
16444 opaque_obj.* = .{16440 opaque_obj.* = .{
16445 .owner_decl = new_decl_index,16441 .owner_decl = new_decl_index,
16446 .node_offset = src.node_offset.x,
16447 .namespace = .{16442 .namespace = .{
16448 .parent = block.namespace,16443 .parent = block.namespace,
16449 .ty = opaque_ty,16444 .ty = opaque_ty,
...@@ -16492,7 +16487,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in...@@ -16492,7 +16487,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
16492 };16487 };
16493 const union_ty = Type.initPayload(&union_payload.base);16488 const union_ty = Type.initPayload(&union_payload.base);
16494 const new_union_val = try Value.Tag.ty.create(new_decl_arena_allocator, union_ty);16489 const new_union_val = try Value.Tag.ty.create(new_decl_arena_allocator, union_ty);
16495 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{16490 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
16496 .ty = Type.type,16491 .ty = Type.type,
16497 .val = new_union_val,16492 .val = new_union_val,
16498 }, name_strategy, "union", inst);16493 }, name_strategy, "union", inst);
...@@ -16503,7 +16498,6 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in...@@ -16503,7 +16498,6 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
16503 .owner_decl = new_decl_index,16498 .owner_decl = new_decl_index,
16504 .tag_ty = Type.initTag(.@"null"),16499 .tag_ty = Type.initTag(.@"null"),
16505 .fields = .{},16500 .fields = .{},
16506 .node_offset = src.node_offset.x,
16507 .zir_index = inst,16501 .zir_index = inst,
16508 .layout = layout,16502 .layout = layout,
16509 .status = .have_field_types,16503 .status = .have_field_types,
...@@ -16798,7 +16792,7 @@ fn reifyStruct(...@@ -16798,7 +16792,7 @@ fn reifyStruct(
16798 const struct_ty = try Type.Tag.@"struct".create(new_decl_arena_allocator, struct_obj);16792 const struct_ty = try Type.Tag.@"struct".create(new_decl_arena_allocator, struct_obj);
16799 const new_struct_val = try Value.Tag.ty.create(new_decl_arena_allocator, struct_ty);16793 const new_struct_val = try Value.Tag.ty.create(new_decl_arena_allocator, struct_ty);
16800 const mod = sema.mod;16794 const mod = sema.mod;
16801 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{16795 const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{
16802 .ty = Type.type,16796 .ty = Type.type,
16803 .val = new_struct_val,16797 .val = new_struct_val,
16804 }, name_strategy, "struct", inst);16798 }, name_strategy, "struct", inst);
...@@ -16808,7 +16802,6 @@ fn reifyStruct(...@@ -16808,7 +16802,6 @@ fn reifyStruct(
16808 struct_obj.* = .{16802 struct_obj.* = .{
16809 .owner_decl = new_decl_index,16803 .owner_decl = new_decl_index,
16810 .fields = .{},16804 .fields = .{},
16811 .node_offset = src.node_offset.x,
16812 .zir_index = inst,16805 .zir_index = inst,
16813 .layout = layout_val.toEnum(std.builtin.Type.ContainerLayout),16806 .layout = layout_val.toEnum(std.builtin.Type.ContainerLayout),
16814 .status = .have_field_types,16807 .status = .have_field_types,
...@@ -27241,7 +27234,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void...@@ -27241,7 +27234,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
27241 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);27234 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
27242 var extra_index: usize = extended.operand;27235 var extra_index: usize = extended.operand;
2724327236
27244 const src = LazySrcLoc.nodeOffset(struct_obj.node_offset);27237 const src = LazySrcLoc.nodeOffset(0);
27245 extra_index += @boolToInt(small.has_src_node);27238 extra_index += @boolToInt(small.has_src_node);
2724627239
27247 const fields_len = if (small.has_fields_len) blk: {27240 const fields_len = if (small.has_fields_len) blk: {
...@@ -27360,12 +27353,12 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void...@@ -27360,12 +27353,12 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
27360 if (gop.found_existing) {27353 if (gop.found_existing) {
27361 const msg = msg: {27354 const msg = msg: {
27362 const tree = try sema.getAstTree(&block_scope);27355 const tree = try sema.getAstTree(&block_scope);
27363 const field_src = enumFieldSrcLoc(decl, tree.*, struct_obj.node_offset, field_i);27356 const field_src = enumFieldSrcLoc(decl, tree.*, 0, field_i);
27364 const msg = try sema.errMsg(&block_scope, field_src, "duplicate struct field: '{s}'", .{field_name});27357 const msg = try sema.errMsg(&block_scope, field_src, "duplicate struct field: '{s}'", .{field_name});
27365 errdefer msg.destroy(gpa);27358 errdefer msg.destroy(gpa);
2736627359
27367 const prev_field_index = struct_obj.fields.getIndex(field_name).?;27360 const prev_field_index = struct_obj.fields.getIndex(field_name).?;
27368 const prev_field_src = enumFieldSrcLoc(decl, tree.*, struct_obj.node_offset, prev_field_index);27361 const prev_field_src = enumFieldSrcLoc(decl, tree.*, 0, prev_field_index);
27369 try sema.mod.errNoteNonLazy(prev_field_src.toSrcLoc(decl), msg, "other field here", .{});27362 try sema.mod.errNoteNonLazy(prev_field_src.toSrcLoc(decl), msg, "other field here", .{});
27370 try sema.errNote(&block_scope, src, msg, "struct declared here", .{});27363 try sema.errNote(&block_scope, src, msg, "struct declared here", .{});
27371 break :msg msg;27364 break :msg msg;
...@@ -27422,7 +27415,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void...@@ -27422,7 +27415,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
27422 if (field_ty.zigTypeTag() == .Opaque) {27415 if (field_ty.zigTypeTag() == .Opaque) {
27423 const msg = msg: {27416 const msg = msg: {
27424 const tree = try sema.getAstTree(&block_scope);27417 const tree = try sema.getAstTree(&block_scope);
27425 const field_src = enumFieldSrcLoc(decl, tree.*, struct_obj.node_offset, i);27418 const field_src = enumFieldSrcLoc(decl, tree.*, 0, i);
27426 const msg = try sema.errMsg(&block_scope, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});27419 const msg = try sema.errMsg(&block_scope, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
27427 errdefer msg.destroy(sema.gpa);27420 errdefer msg.destroy(sema.gpa);
2742827421
...@@ -27434,7 +27427,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void...@@ -27434,7 +27427,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
27434 if (struct_obj.layout == .Extern and !sema.validateExternType(field.ty, .other)) {27427 if (struct_obj.layout == .Extern and !sema.validateExternType(field.ty, .other)) {
27435 const msg = msg: {27428 const msg = msg: {
27436 const tree = try sema.getAstTree(&block_scope);27429 const tree = try sema.getAstTree(&block_scope);
27437 const fields_src = enumFieldSrcLoc(decl, tree.*, struct_obj.node_offset, i);27430 const fields_src = enumFieldSrcLoc(decl, tree.*, 0, i);
27438 const msg = try sema.errMsg(&block_scope, fields_src, "extern structs cannot contain fields of type '{}'", .{field.ty.fmt(sema.mod)});27431 const msg = try sema.errMsg(&block_scope, fields_src, "extern structs cannot contain fields of type '{}'", .{field.ty.fmt(sema.mod)});
27439 errdefer msg.destroy(sema.gpa);27432 errdefer msg.destroy(sema.gpa);
2744027433
...@@ -27447,7 +27440,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void...@@ -27447,7 +27440,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
27447 } else if (struct_obj.layout == .Packed and !(validatePackedType(field.ty))) {27440 } else if (struct_obj.layout == .Packed and !(validatePackedType(field.ty))) {
27448 const msg = msg: {27441 const msg = msg: {
27449 const tree = try sema.getAstTree(&block_scope);27442 const tree = try sema.getAstTree(&block_scope);
27450 const fields_src = enumFieldSrcLoc(decl, tree.*, struct_obj.node_offset, i);27443 const fields_src = enumFieldSrcLoc(decl, tree.*, 0, i);
27451 const msg = try sema.errMsg(&block_scope, fields_src, "packed structs cannot contain fields of type '{}'", .{field.ty.fmt(sema.mod)});27444 const msg = try sema.errMsg(&block_scope, fields_src, "packed structs cannot contain fields of type '{}'", .{field.ty.fmt(sema.mod)});
27452 errdefer msg.destroy(sema.gpa);27445 errdefer msg.destroy(sema.gpa);
2745327446
...@@ -27504,7 +27497,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {...@@ -27504,7 +27497,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
27504 const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small);27497 const small = @bitCast(Zir.Inst.UnionDecl.Small, extended.small);
27505 var extra_index: usize = extended.operand;27498 var extra_index: usize = extended.operand;
2750627499
27507 const src = LazySrcLoc.nodeOffset(union_obj.node_offset);27500 const src = LazySrcLoc.nodeOffset(0);
27508 extra_index += @boolToInt(small.has_src_node);27501 extra_index += @boolToInt(small.has_src_node);
2750927502
27510 const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: {27503 const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: {
...@@ -27728,12 +27721,12 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {...@@ -27728,12 +27721,12 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
27728 if (gop.found_existing) {27721 if (gop.found_existing) {
27729 const msg = msg: {27722 const msg = msg: {
27730 const tree = try sema.getAstTree(&block_scope);27723 const tree = try sema.getAstTree(&block_scope);
27731 const field_src = enumFieldSrcLoc(decl, tree.*, union_obj.node_offset, field_i);27724 const field_src = enumFieldSrcLoc(decl, tree.*, 0, field_i);
27732 const msg = try sema.errMsg(&block_scope, field_src, "duplicate union field: '{s}'", .{field_name});27725 const msg = try sema.errMsg(&block_scope, field_src, "duplicate union field: '{s}'", .{field_name});
27733 errdefer msg.destroy(gpa);27726 errdefer msg.destroy(gpa);
2773427727
27735 const prev_field_index = union_obj.fields.getIndex(field_name).?;27728 const prev_field_index = union_obj.fields.getIndex(field_name).?;
27736 const prev_field_src = enumFieldSrcLoc(decl, tree.*, union_obj.node_offset, prev_field_index);27729 const prev_field_src = enumFieldSrcLoc(decl, tree.*, 0, prev_field_index);
27737 try sema.mod.errNoteNonLazy(prev_field_src.toSrcLoc(decl), msg, "other field here", .{});27730 try sema.mod.errNoteNonLazy(prev_field_src.toSrcLoc(decl), msg, "other field here", .{});
27738 try sema.errNote(&block_scope, src, msg, "union declared here", .{});27731 try sema.errNote(&block_scope, src, msg, "union declared here", .{});
27739 break :msg msg;27732 break :msg msg;
...@@ -27746,7 +27739,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {...@@ -27746,7 +27739,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
27746 if (!enum_has_field) {27739 if (!enum_has_field) {
27747 const msg = msg: {27740 const msg = msg: {
27748 const tree = try sema.getAstTree(&block_scope);27741 const tree = try sema.getAstTree(&block_scope);
27749 const field_src = enumFieldSrcLoc(decl, tree.*, union_obj.node_offset, field_i);27742 const field_src = enumFieldSrcLoc(decl, tree.*, 0, field_i);
27750 const msg = try sema.errMsg(&block_scope, field_src, "no field named '{s}' in enum '{}'", .{ field_name, union_obj.tag_ty.fmt(sema.mod) });27743 const msg = try sema.errMsg(&block_scope, field_src, "no field named '{s}' in enum '{}'", .{ field_name, union_obj.tag_ty.fmt(sema.mod) });
27751 errdefer msg.destroy(sema.gpa);27744 errdefer msg.destroy(sema.gpa);
27752 try sema.addDeclaredHereNote(msg, union_obj.tag_ty);27745 try sema.addDeclaredHereNote(msg, union_obj.tag_ty);
...@@ -27759,7 +27752,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {...@@ -27759,7 +27752,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
27759 if (field_ty.zigTypeTag() == .Opaque) {27752 if (field_ty.zigTypeTag() == .Opaque) {
27760 const msg = msg: {27753 const msg = msg: {
27761 const tree = try sema.getAstTree(&block_scope);27754 const tree = try sema.getAstTree(&block_scope);
27762 const field_src = enumFieldSrcLoc(decl, tree.*, union_obj.node_offset, field_i);27755 const field_src = enumFieldSrcLoc(decl, tree.*, 0, field_i);
27763 const msg = try sema.errMsg(&block_scope, field_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});27756 const msg = try sema.errMsg(&block_scope, field_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
27764 errdefer msg.destroy(sema.gpa);27757 errdefer msg.destroy(sema.gpa);
2776527758
...@@ -27771,7 +27764,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {...@@ -27771,7 +27764,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
27771 if (union_obj.layout == .Extern and !sema.validateExternType(field_ty, .union_field)) {27764 if (union_obj.layout == .Extern and !sema.validateExternType(field_ty, .union_field)) {
27772 const msg = msg: {27765 const msg = msg: {
27773 const tree = try sema.getAstTree(&block_scope);27766 const tree = try sema.getAstTree(&block_scope);
27774 const field_src = enumFieldSrcLoc(decl, tree.*, union_obj.node_offset, field_i);27767 const field_src = enumFieldSrcLoc(decl, tree.*, 0, field_i);
27775 const msg = try sema.errMsg(&block_scope, field_src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});27768 const msg = try sema.errMsg(&block_scope, field_src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
27776 errdefer msg.destroy(sema.gpa);27769 errdefer msg.destroy(sema.gpa);
2777727770
...@@ -27784,7 +27777,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {...@@ -27784,7 +27777,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
27784 } else if (union_obj.layout == .Packed and !(validatePackedType(field_ty))) {27777 } else if (union_obj.layout == .Packed and !(validatePackedType(field_ty))) {
27785 const msg = msg: {27778 const msg = msg: {
27786 const tree = try sema.getAstTree(&block_scope);27779 const tree = try sema.getAstTree(&block_scope);
27787 const fields_src = enumFieldSrcLoc(decl, tree.*, union_obj.node_offset, field_i);27780 const fields_src = enumFieldSrcLoc(decl, tree.*, 0, field_i);
27788 const msg = try sema.errMsg(&block_scope, fields_src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});27781 const msg = try sema.errMsg(&block_scope, fields_src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
27789 errdefer msg.destroy(sema.gpa);27782 errdefer msg.destroy(sema.gpa);
2779027783
...@@ -27876,7 +27869,6 @@ fn generateUnionTagTypeNumbered(...@@ -27876,7 +27869,6 @@ fn generateUnionTagTypeNumbered(
27876 .tag_ty = int_ty,27869 .tag_ty = int_ty,
27877 .fields = .{},27870 .fields = .{},
27878 .values = .{},27871 .values = .{},
27879 .node_offset = 0,
27880 };27872 };
27881 // Here we pre-allocate the maps using the decl arena.27873 // Here we pre-allocate the maps using the decl arena.
27882 try enum_obj.fields.ensureTotalCapacity(new_decl_arena_allocator, fields_len);27874 try enum_obj.fields.ensureTotalCapacity(new_decl_arena_allocator, fields_len);
...@@ -27934,7 +27926,6 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Block, fields_len: usize, may...@@ -27934,7 +27926,6 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Block, fields_len: usize, may
27934 enum_obj.* = .{27926 enum_obj.* = .{
27935 .owner_decl = new_decl_index,27927 .owner_decl = new_decl_index,
27936 .fields = .{},27928 .fields = .{},
27937 .node_offset = 0,
27938 };27929 };
27939 // Here we pre-allocate the maps using the decl arena.27930 // Here we pre-allocate the maps using the decl arena.
27940 try enum_obj.fields.ensureTotalCapacity(new_decl_arena_allocator, fields_len);27931 try enum_obj.fields.ensureTotalCapacity(new_decl_arena_allocator, fields_len);
...@@ -28245,7 +28236,7 @@ fn enumFieldSrcLoc(...@@ -28245,7 +28236,7 @@ fn enumFieldSrcLoc(
28245 => tree.containerDeclArg(enum_node),28236 => tree.containerDeclArg(enum_node),
2824628237
28247 // Container was constructed with `@Type`.28238 // Container was constructed with `@Type`.
28248 else => return LazySrcLoc.nodeOffset(node_offset),28239 else => return LazySrcLoc.nodeOffset(0),
28249 };28240 };
28250 var it_index: usize = 0;28241 var it_index: usize = 0;
28251 for (container_decl.ast.members) |member_node| {28242 for (container_decl.ast.members) |member_node| {
src/print_zir.zig+16
...@@ -1245,6 +1245,10 @@ const Writer = struct {...@@ -1245,6 +1245,10 @@ const Writer = struct {
1245 if (decls_len == 0) {1245 if (decls_len == 0) {
1246 try stream.writeAll("{}, ");1246 try stream.writeAll("{}, ");
1247 } else {1247 } else {
1248 const prev_parent_decl_node = self.parent_decl_node;
1249 if (src_node) |off| self.parent_decl_node = self.relativeToNodeIndex(off);
1250 defer self.parent_decl_node = prev_parent_decl_node;
1251
1248 try stream.writeAll("{\n");1252 try stream.writeAll("{\n");
1249 self.indent += 2;1253 self.indent += 2;
1250 extra_index = try self.writeDecls(stream, decls_len, extra_index);1254 extra_index = try self.writeDecls(stream, decls_len, extra_index);
...@@ -1415,6 +1419,10 @@ const Writer = struct {...@@ -1415,6 +1419,10 @@ const Writer = struct {
1415 if (decls_len == 0) {1419 if (decls_len == 0) {
1416 try stream.writeAll("{}, ");1420 try stream.writeAll("{}, ");
1417 } else {1421 } else {
1422 const prev_parent_decl_node = self.parent_decl_node;
1423 if (src_node) |off| self.parent_decl_node = self.relativeToNodeIndex(off);
1424 defer self.parent_decl_node = prev_parent_decl_node;
1425
1418 try stream.writeAll("{\n");1426 try stream.writeAll("{\n");
1419 self.indent += 2;1427 self.indent += 2;
1420 extra_index = try self.writeDecls(stream, decls_len, extra_index);1428 extra_index = try self.writeDecls(stream, decls_len, extra_index);
...@@ -1662,6 +1670,10 @@ const Writer = struct {...@@ -1662,6 +1670,10 @@ const Writer = struct {
1662 if (decls_len == 0) {1670 if (decls_len == 0) {
1663 try stream.writeAll("{}, ");1671 try stream.writeAll("{}, ");
1664 } else {1672 } else {
1673 const prev_parent_decl_node = self.parent_decl_node;
1674 if (src_node) |off| self.parent_decl_node = self.relativeToNodeIndex(off);
1675 defer self.parent_decl_node = prev_parent_decl_node;
1676
1665 try stream.writeAll("{\n");1677 try stream.writeAll("{\n");
1666 self.indent += 2;1678 self.indent += 2;
1667 extra_index = try self.writeDecls(stream, decls_len, extra_index);1679 extra_index = try self.writeDecls(stream, decls_len, extra_index);
...@@ -1755,6 +1767,10 @@ const Writer = struct {...@@ -1755,6 +1767,10 @@ const Writer = struct {
1755 if (decls_len == 0) {1767 if (decls_len == 0) {
1756 try stream.writeAll("{})");1768 try stream.writeAll("{})");
1757 } else {1769 } else {
1770 const prev_parent_decl_node = self.parent_decl_node;
1771 if (src_node) |off| self.parent_decl_node = self.relativeToNodeIndex(off);
1772 defer self.parent_decl_node = prev_parent_decl_node;
1773
1758 try stream.writeAll("{\n");1774 try stream.writeAll("{\n");
1759 self.indent += 2;1775 self.indent += 2;
1760 _ = try self.writeDecls(stream, decls_len, extra_index);1776 _ = try self.writeDecls(stream, decls_len, extra_index);
src/type.zig-44
...@@ -5771,50 +5771,6 @@ pub const Type = extern union {...@@ -5771,50 +5771,6 @@ pub const Type = extern union {
5771 }5771 }
5772 }5772 }
57735773
5774 pub fn getNodeOffset(ty: Type) i32 {
5775 switch (ty.tag()) {
5776 .enum_full, .enum_nonexhaustive => {
5777 const enum_full = ty.cast(Payload.EnumFull).?.data;
5778 return enum_full.node_offset;
5779 },
5780 .enum_numbered => return ty.castTag(.enum_numbered).?.data.node_offset,
5781 .enum_simple => {
5782 const enum_simple = ty.castTag(.enum_simple).?.data;
5783 return enum_simple.node_offset;
5784 },
5785 .@"struct" => {
5786 const struct_obj = ty.castTag(.@"struct").?.data;
5787 return struct_obj.node_offset;
5788 },
5789 .error_set => {
5790 const error_set = ty.castTag(.error_set).?.data;
5791 return error_set.node_offset;
5792 },
5793 .@"union", .union_safety_tagged, .union_tagged => {
5794 const union_obj = ty.cast(Payload.Union).?.data;
5795 return union_obj.node_offset;
5796 },
5797 .@"opaque" => {
5798 const opaque_obj = ty.cast(Payload.Opaque).?.data;
5799 return opaque_obj.node_offset;
5800 },
5801 .atomic_order,
5802 .atomic_rmw_op,
5803 .calling_convention,
5804 .address_space,
5805 .float_mode,
5806 .reduce_op,
5807 .call_options,
5808 .prefetch_options,
5809 .export_options,
5810 .extern_options,
5811 .type_info,
5812 => unreachable, // These need to be resolved earlier.
5813
5814 else => unreachable,
5815 }
5816 }
5817
5818 /// This enum does not directly correspond to `std.builtin.TypeId` because5774 /// This enum does not directly correspond to `std.builtin.TypeId` because
5819 /// it has extra enum tags in it, as a way of using less memory. For example,5775 /// it has extra enum tags in it, as a way of using less memory. For example,
5820 /// even though Zig recognizes `*align(10) i32` and `*i32` both as Pointer types5776 /// even though Zig recognizes `*align(10) i32` and `*i32` both as Pointer types
test/cases/compile_errors/non_constant_expression_in_array_size.zig+1-1
...@@ -11,4 +11,4 @@ export fn entry() usize { return @offsetOf(Foo, "y"); }...@@ -11,4 +11,4 @@ export fn entry() usize { return @offsetOf(Foo, "y"); }
11// target=native11// target=native
12//12//
13// :5:25: error: cannot load runtime value in comptime block13// :5:25: error: cannot load runtime value in comptime block
14// :2:15: note: called from here14// :2:12: note: called from here
test/cases/compile_errors/not_an_enum_type.zig+1-1
...@@ -17,4 +17,4 @@ const ExpectedVarDeclOrFn = struct {};...@@ -17,4 +17,4 @@ const ExpectedVarDeclOrFn = struct {};
17// target=native17// target=native
18//18//
19// :4:9: error: expected type '@typeInfo(tmp.Error).Union.tag_type.?', found 'type'19// :4:9: error: expected type '@typeInfo(tmp.Error).Union.tag_type.?', found 'type'
20// :8:1: note: enum declared here20// :8:15: note: enum declared here
test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig+1-1
...@@ -9,4 +9,4 @@ test "enum" {...@@ -9,4 +9,4 @@ test "enum" {
9// is_test=19// is_test=1
10//10//
11// :3:9: error: no field with value '5' in enum 'test.enum.E'11// :3:9: error: no field with value '5' in enum 'test.enum.E'
12// :1:1: note: declared here12// :2:15: note: declared here
test/cases/error_in_nested_declaration.zig created+31
...@@ -0,0 +1,31 @@
1const S = struct {
2 b: u32,
3 c: i32,
4 a: struct {
5 pub fn str(_: @This(), extra: []u32) []i32 {
6 return @bitCast([]i32, extra);
7 }
8 },
9};
10
11pub export fn entry() void {
12 var s: S = undefined;
13 _ = s.a.str(undefined);
14}
15
16const S2 = struct {
17 a: [*c]anyopaque,
18};
19
20pub export fn entry2() void {
21 var s: S2 = undefined;
22 _ = s;
23}
24
25// error
26// backend=llvm
27// target=native
28//
29// :17:12: error: C pointers cannot point to opaque types
30// :6:29: error: cannot @bitCast to '[]i32'
31// :6:29: note: use @ptrCast to cast from '[]u32'