authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-13 12:34:27-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-15 19:06:39-07:00
log0170a242bb99e96fcb127e26e1b2fcbe5a19c4ee
treeab5dd10064527ff8fcd7d3f676466de9c30d1c2b
parent798ad631f3f9836de663bc6c728b415e0a13528f

stage2: move zir.Code to become root level fields of zir.zig

next commit will do the rename

4 files changed, 431 insertions(+), 432 deletions(-)

src/AstGen.zig+3-3
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1//! A Work-In-Progress `zir.Code`. This is a shared parent of all1//! A Work-In-Progress `Zir`. This is a shared parent of all
2//! `GenZir` scopes. Once the `zir.Code` is produced, this struct2//! `GenZir` scopes. Once the `Zir` is produced, this struct
3//! is deinitialized.3//! is deinitialized.
4//! The `GenZir.finish` function converts this to a `zir.Code`.4//! The `GenZir.finish` function converts this to a `Zir`.
55
6const AstGen = @This();6const AstGen = @This();
77
src/Module.zig+103-103
...@@ -21,7 +21,7 @@ const TypedValue = @import("TypedValue.zig");...@@ -21,7 +21,7 @@ const TypedValue = @import("TypedValue.zig");
21const Package = @import("Package.zig");21const Package = @import("Package.zig");
22const link = @import("link.zig");22const link = @import("link.zig");
23const ir = @import("ir.zig");23const ir = @import("ir.zig");
24const zir = @import("zir.zig");24const Zir = @import("zir.zig"); // TODO rename this to Zir
25const trace = @import("tracy.zig").trace;25const trace = @import("tracy.zig").trace;
26const AstGen = @import("AstGen.zig");26const AstGen = @import("AstGen.zig");
27const Sema = @import("Sema.zig");27const Sema = @import("Sema.zig");
...@@ -464,7 +464,7 @@ pub const Fn = struct {...@@ -464,7 +464,7 @@ pub const Fn = struct {
464 /// The first N elements of `extra` are indexes into `string_bytes` to464 /// The first N elements of `extra` are indexes into `string_bytes` to
465 /// a null-terminated string.465 /// a null-terminated string.
466 /// This memory is managed with gpa, must be freed when the function is freed.466 /// This memory is managed with gpa, must be freed when the function is freed.
467 zir: zir.Code,467 zir: Zir,
468 /// undefined unless analysis state is `success`.468 /// undefined unless analysis state is `success`.
469 body: ir.Body,469 body: ir.Body,
470 state: Analysis,470 state: Analysis,
...@@ -808,7 +808,7 @@ pub const Scope = struct {...@@ -808,7 +808,7 @@ pub const Scope = struct {
808 /// This `Block` maps a block ZIR instruction to the corresponding808 /// This `Block` maps a block ZIR instruction to the corresponding
809 /// TZIR instruction for break instruction analysis.809 /// TZIR instruction for break instruction analysis.
810 pub const Label = struct {810 pub const Label = struct {
811 zir_block: zir.Inst.Index,811 zir_block: Zir.Inst.Index,
812 merges: Merges,812 merges: Merges,
813 };813 };
814814
...@@ -834,7 +834,7 @@ pub const Scope = struct {...@@ -834,7 +834,7 @@ pub const Scope = struct {
834834
835 /// For debugging purposes.835 /// For debugging purposes.
836 pub fn dump(block: *Block, mod: Module) void {836 pub fn dump(block: *Block, mod: Module) void {
837 zir.dumpBlock(mod, block);837 Zir.dumpBlock(mod, block);
838 }838 }
839839
840 pub fn makeSubBlock(parent: *Block) Block {840 pub fn makeSubBlock(parent: *Block) Block {
...@@ -1045,7 +1045,7 @@ pub const Scope = struct {...@@ -1045,7 +1045,7 @@ pub const Scope = struct {
1045 };1045 };
10461046
1047 /// This is a temporary structure; references to it are valid only1047 /// This is a temporary structure; references to it are valid only
1048 /// while constructing a `zir.Code`.1048 /// while constructing a `Zir`.
1049 pub const GenZir = struct {1049 pub const GenZir = struct {
1050 pub const base_tag: Tag = .gen_zir;1050 pub const base_tag: Tag = .gen_zir;
1051 base: Scope = Scope{ .tag = base_tag },1051 base: Scope = Scope{ .tag = base_tag },
...@@ -1056,16 +1056,16 @@ pub const Scope = struct {...@@ -1056,16 +1056,16 @@ pub const Scope = struct {
1056 astgen: *AstGen,1056 astgen: *AstGen,
1057 /// Keeps track of the list of instructions in this scope only. Indexes1057 /// Keeps track of the list of instructions in this scope only. Indexes
1058 /// to instructions in `astgen`.1058 /// to instructions in `astgen`.
1059 instructions: ArrayListUnmanaged(zir.Inst.Index) = .{},1059 instructions: ArrayListUnmanaged(Zir.Inst.Index) = .{},
1060 label: ?Label = null,1060 label: ?Label = null,
1061 break_block: zir.Inst.Index = 0,1061 break_block: Zir.Inst.Index = 0,
1062 continue_block: zir.Inst.Index = 0,1062 continue_block: Zir.Inst.Index = 0,
1063 /// Only valid when setBreakResultLoc is called.1063 /// Only valid when setBreakResultLoc is called.
1064 break_result_loc: AstGen.ResultLoc = undefined,1064 break_result_loc: AstGen.ResultLoc = undefined,
1065 /// When a block has a pointer result location, here it is.1065 /// When a block has a pointer result location, here it is.
1066 rl_ptr: zir.Inst.Ref = .none,1066 rl_ptr: Zir.Inst.Ref = .none,
1067 /// When a block has a type result location, here it is.1067 /// When a block has a type result location, here it is.
1068 rl_ty_inst: zir.Inst.Ref = .none,1068 rl_ty_inst: Zir.Inst.Ref = .none,
1069 /// Keeps track of how many branches of a block did not actually1069 /// Keeps track of how many branches of a block did not actually
1070 /// consume the result location. astgen uses this to figure out1070 /// consume the result location. astgen uses this to figure out
1071 /// whether to rely on break instructions or writing to the result1071 /// whether to rely on break instructions or writing to the result
...@@ -1077,25 +1077,25 @@ pub const Scope = struct {...@@ -1077,25 +1077,25 @@ pub const Scope = struct {
1077 break_count: usize = 0,1077 break_count: usize = 0,
1078 /// Tracks `break :foo bar` instructions so they can possibly be elided later if1078 /// Tracks `break :foo bar` instructions so they can possibly be elided later if
1079 /// the labeled block ends up not needing a result location pointer.1079 /// the labeled block ends up not needing a result location pointer.
1080 labeled_breaks: ArrayListUnmanaged(zir.Inst.Index) = .{},1080 labeled_breaks: ArrayListUnmanaged(Zir.Inst.Index) = .{},
1081 /// Tracks `store_to_block_ptr` instructions that correspond to break instructions1081 /// Tracks `store_to_block_ptr` instructions that correspond to break instructions
1082 /// so they can possibly be elided later if the labeled block ends up not needing1082 /// so they can possibly be elided later if the labeled block ends up not needing
1083 /// a result location pointer.1083 /// a result location pointer.
1084 labeled_store_to_block_ptr_list: ArrayListUnmanaged(zir.Inst.Index) = .{},1084 labeled_store_to_block_ptr_list: ArrayListUnmanaged(Zir.Inst.Index) = .{},
10851085
1086 pub const Label = struct {1086 pub const Label = struct {
1087 token: ast.TokenIndex,1087 token: ast.TokenIndex,
1088 block_inst: zir.Inst.Index,1088 block_inst: Zir.Inst.Index,
1089 used: bool = false,1089 used: bool = false,
1090 };1090 };
10911091
1092 /// Only valid to call on the top of the `GenZir` stack. Completes the1092 /// Only valid to call on the top of the `GenZir` stack. Completes the
1093 /// `AstGen` into a `zir.Code`. Leaves the `AstGen` in an1093 /// `AstGen` into a `Zir`. Leaves the `AstGen` in an
1094 /// initialized, but empty, state.1094 /// initialized, but empty, state.
1095 pub fn finish(gz: *GenZir) !zir.Code {1095 pub fn finish(gz: *GenZir) !Zir {
1096 const gpa = gz.astgen.mod.gpa;1096 const gpa = gz.astgen.mod.gpa;
1097 try gz.setBlockBody(0);1097 try gz.setBlockBody(0);
1098 return zir.Code{1098 return Zir{
1099 .instructions = gz.astgen.instructions.toOwnedSlice(),1099 .instructions = gz.astgen.instructions.toOwnedSlice(),
1100 .string_bytes = gz.astgen.string_bytes.toOwnedSlice(gpa),1100 .string_bytes = gz.astgen.string_bytes.toOwnedSlice(gpa),
1101 .extra = gz.astgen.extra.toOwnedSlice(gpa),1101 .extra = gz.astgen.extra.toOwnedSlice(gpa),
...@@ -1148,24 +1148,24 @@ pub const Scope = struct {...@@ -1148,24 +1148,24 @@ pub const Scope = struct {
1148 }1148 }
1149 }1149 }
11501150
1151 pub fn setBoolBrBody(gz: GenZir, inst: zir.Inst.Index) !void {1151 pub fn setBoolBrBody(gz: GenZir, inst: Zir.Inst.Index) !void {
1152 const gpa = gz.astgen.mod.gpa;1152 const gpa = gz.astgen.mod.gpa;
1153 try gz.astgen.extra.ensureCapacity(gpa, gz.astgen.extra.items.len +1153 try gz.astgen.extra.ensureCapacity(gpa, gz.astgen.extra.items.len +
1154 @typeInfo(zir.Inst.Block).Struct.fields.len + gz.instructions.items.len);1154 @typeInfo(Zir.Inst.Block).Struct.fields.len + gz.instructions.items.len);
1155 const zir_datas = gz.astgen.instructions.items(.data);1155 const zir_datas = gz.astgen.instructions.items(.data);
1156 zir_datas[inst].bool_br.payload_index = gz.astgen.addExtraAssumeCapacity(1156 zir_datas[inst].bool_br.payload_index = gz.astgen.addExtraAssumeCapacity(
1157 zir.Inst.Block{ .body_len = @intCast(u32, gz.instructions.items.len) },1157 Zir.Inst.Block{ .body_len = @intCast(u32, gz.instructions.items.len) },
1158 );1158 );
1159 gz.astgen.extra.appendSliceAssumeCapacity(gz.instructions.items);1159 gz.astgen.extra.appendSliceAssumeCapacity(gz.instructions.items);
1160 }1160 }
11611161
1162 pub fn setBlockBody(gz: GenZir, inst: zir.Inst.Index) !void {1162 pub fn setBlockBody(gz: GenZir, inst: Zir.Inst.Index) !void {
1163 const gpa = gz.astgen.mod.gpa;1163 const gpa = gz.astgen.mod.gpa;
1164 try gz.astgen.extra.ensureCapacity(gpa, gz.astgen.extra.items.len +1164 try gz.astgen.extra.ensureCapacity(gpa, gz.astgen.extra.items.len +
1165 @typeInfo(zir.Inst.Block).Struct.fields.len + gz.instructions.items.len);1165 @typeInfo(Zir.Inst.Block).Struct.fields.len + gz.instructions.items.len);
1166 const zir_datas = gz.astgen.instructions.items(.data);1166 const zir_datas = gz.astgen.instructions.items(.data);
1167 zir_datas[inst].pl_node.payload_index = gz.astgen.addExtraAssumeCapacity(1167 zir_datas[inst].pl_node.payload_index = gz.astgen.addExtraAssumeCapacity(
1168 zir.Inst.Block{ .body_len = @intCast(u32, gz.instructions.items.len) },1168 Zir.Inst.Block{ .body_len = @intCast(u32, gz.instructions.items.len) },
1169 );1169 );
1170 gz.astgen.extra.appendSliceAssumeCapacity(gz.instructions.items);1170 gz.astgen.extra.appendSliceAssumeCapacity(gz.instructions.items);
1171 }1171 }
...@@ -1180,12 +1180,12 @@ pub const Scope = struct {...@@ -1180,12 +1180,12 @@ pub const Scope = struct {
1180 return str_index;1180 return str_index;
1181 }1181 }
11821182
1183 pub fn addFnTypeCc(gz: *GenZir, tag: zir.Inst.Tag, args: struct {1183 pub fn addFnTypeCc(gz: *GenZir, tag: Zir.Inst.Tag, args: struct {
1184 src_node: ast.Node.Index,1184 src_node: ast.Node.Index,
1185 param_types: []const zir.Inst.Ref,1185 param_types: []const Zir.Inst.Ref,
1186 ret_ty: zir.Inst.Ref,1186 ret_ty: Zir.Inst.Ref,
1187 cc: zir.Inst.Ref,1187 cc: Zir.Inst.Ref,
1188 }) !zir.Inst.Ref {1188 }) !Zir.Inst.Ref {
1189 assert(args.src_node != 0);1189 assert(args.src_node != 0);
1190 assert(args.ret_ty != .none);1190 assert(args.ret_ty != .none);
1191 assert(args.cc != .none);1191 assert(args.cc != .none);
...@@ -1193,16 +1193,16 @@ pub const Scope = struct {...@@ -1193,16 +1193,16 @@ pub const Scope = struct {
1193 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);1193 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);
1194 try gz.astgen.instructions.ensureCapacity(gpa, gz.astgen.instructions.len + 1);1194 try gz.astgen.instructions.ensureCapacity(gpa, gz.astgen.instructions.len + 1);
1195 try gz.astgen.extra.ensureCapacity(gpa, gz.astgen.extra.items.len +1195 try gz.astgen.extra.ensureCapacity(gpa, gz.astgen.extra.items.len +
1196 @typeInfo(zir.Inst.FnTypeCc).Struct.fields.len + args.param_types.len);1196 @typeInfo(Zir.Inst.FnTypeCc).Struct.fields.len + args.param_types.len);
11971197
1198 const payload_index = gz.astgen.addExtraAssumeCapacity(zir.Inst.FnTypeCc{1198 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.FnTypeCc{
1199 .return_type = args.ret_ty,1199 .return_type = args.ret_ty,
1200 .cc = args.cc,1200 .cc = args.cc,
1201 .param_types_len = @intCast(u32, args.param_types.len),1201 .param_types_len = @intCast(u32, args.param_types.len),
1202 });1202 });
1203 gz.astgen.appendRefsAssumeCapacity(args.param_types);1203 gz.astgen.appendRefsAssumeCapacity(args.param_types);
12041204
1205 const new_index = @intCast(zir.Inst.Index, gz.astgen.instructions.len);1205 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
1206 gz.astgen.instructions.appendAssumeCapacity(.{1206 gz.astgen.instructions.appendAssumeCapacity(.{
1207 .tag = tag,1207 .tag = tag,
1208 .data = .{ .pl_node = .{1208 .data = .{ .pl_node = .{
...@@ -1214,26 +1214,26 @@ pub const Scope = struct {...@@ -1214,26 +1214,26 @@ pub const Scope = struct {
1214 return gz.astgen.indexToRef(new_index);1214 return gz.astgen.indexToRef(new_index);
1215 }1215 }
12161216
1217 pub fn addFnType(gz: *GenZir, tag: zir.Inst.Tag, args: struct {1217 pub fn addFnType(gz: *GenZir, tag: Zir.Inst.Tag, args: struct {
1218 src_node: ast.Node.Index,1218 src_node: ast.Node.Index,
1219 ret_ty: zir.Inst.Ref,1219 ret_ty: Zir.Inst.Ref,
1220 param_types: []const zir.Inst.Ref,1220 param_types: []const Zir.Inst.Ref,
1221 }) !zir.Inst.Ref {1221 }) !Zir.Inst.Ref {
1222 assert(args.src_node != 0);1222 assert(args.src_node != 0);
1223 assert(args.ret_ty != .none);1223 assert(args.ret_ty != .none);
1224 const gpa = gz.astgen.mod.gpa;1224 const gpa = gz.astgen.mod.gpa;
1225 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);1225 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);
1226 try gz.astgen.instructions.ensureCapacity(gpa, gz.astgen.instructions.len + 1);1226 try gz.astgen.instructions.ensureCapacity(gpa, gz.astgen.instructions.len + 1);
1227 try gz.astgen.extra.ensureCapacity(gpa, gz.astgen.extra.items.len +1227 try gz.astgen.extra.ensureCapacity(gpa, gz.astgen.extra.items.len +
1228 @typeInfo(zir.Inst.FnType).Struct.fields.len + args.param_types.len);1228 @typeInfo(Zir.Inst.FnType).Struct.fields.len + args.param_types.len);
12291229
1230 const payload_index = gz.astgen.addExtraAssumeCapacity(zir.Inst.FnType{1230 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.FnType{
1231 .return_type = args.ret_ty,1231 .return_type = args.ret_ty,
1232 .param_types_len = @intCast(u32, args.param_types.len),1232 .param_types_len = @intCast(u32, args.param_types.len),
1233 });1233 });
1234 gz.astgen.appendRefsAssumeCapacity(args.param_types);1234 gz.astgen.appendRefsAssumeCapacity(args.param_types);
12351235
1236 const new_index = @intCast(zir.Inst.Index, gz.astgen.instructions.len);1236 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
1237 gz.astgen.instructions.appendAssumeCapacity(.{1237 gz.astgen.instructions.appendAssumeCapacity(.{
1238 .tag = tag,1238 .tag = tag,
1239 .data = .{ .pl_node = .{1239 .data = .{ .pl_node = .{
...@@ -1247,27 +1247,27 @@ pub const Scope = struct {...@@ -1247,27 +1247,27 @@ pub const Scope = struct {
12471247
1248 pub fn addCall(1248 pub fn addCall(
1249 gz: *GenZir,1249 gz: *GenZir,
1250 tag: zir.Inst.Tag,1250 tag: Zir.Inst.Tag,
1251 callee: zir.Inst.Ref,1251 callee: Zir.Inst.Ref,
1252 args: []const zir.Inst.Ref,1252 args: []const Zir.Inst.Ref,
1253 /// Absolute node index. This function does the conversion to offset from Decl.1253 /// Absolute node index. This function does the conversion to offset from Decl.
1254 src_node: ast.Node.Index,1254 src_node: ast.Node.Index,
1255 ) !zir.Inst.Ref {1255 ) !Zir.Inst.Ref {
1256 assert(callee != .none);1256 assert(callee != .none);
1257 assert(src_node != 0);1257 assert(src_node != 0);
1258 const gpa = gz.astgen.mod.gpa;1258 const gpa = gz.astgen.mod.gpa;
1259 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);1259 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);
1260 try gz.astgen.instructions.ensureCapacity(gpa, gz.astgen.instructions.len + 1);1260 try gz.astgen.instructions.ensureCapacity(gpa, gz.astgen.instructions.len + 1);
1261 try gz.astgen.extra.ensureCapacity(gpa, gz.astgen.extra.items.len +1261 try gz.astgen.extra.ensureCapacity(gpa, gz.astgen.extra.items.len +
1262 @typeInfo(zir.Inst.Call).Struct.fields.len + args.len);1262 @typeInfo(Zir.Inst.Call).Struct.fields.len + args.len);
12631263
1264 const payload_index = gz.astgen.addExtraAssumeCapacity(zir.Inst.Call{1264 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Call{
1265 .callee = callee,1265 .callee = callee,
1266 .args_len = @intCast(u32, args.len),1266 .args_len = @intCast(u32, args.len),
1267 });1267 });
1268 gz.astgen.appendRefsAssumeCapacity(args);1268 gz.astgen.appendRefsAssumeCapacity(args);
12691269
1270 const new_index = @intCast(zir.Inst.Index, gz.astgen.instructions.len);1270 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
1271 gz.astgen.instructions.appendAssumeCapacity(.{1271 gz.astgen.instructions.appendAssumeCapacity(.{
1272 .tag = tag,1272 .tag = tag,
1273 .data = .{ .pl_node = .{1273 .data = .{ .pl_node = .{
...@@ -1279,19 +1279,19 @@ pub const Scope = struct {...@@ -1279,19 +1279,19 @@ pub const Scope = struct {
1279 return gz.astgen.indexToRef(new_index);1279 return gz.astgen.indexToRef(new_index);
1280 }1280 }
12811281
1282 /// Note that this returns a `zir.Inst.Index` not a ref.1282 /// Note that this returns a `Zir.Inst.Index` not a ref.
1283 /// Leaves the `payload_index` field undefined.1283 /// Leaves the `payload_index` field undefined.
1284 pub fn addBoolBr(1284 pub fn addBoolBr(
1285 gz: *GenZir,1285 gz: *GenZir,
1286 tag: zir.Inst.Tag,1286 tag: Zir.Inst.Tag,
1287 lhs: zir.Inst.Ref,1287 lhs: Zir.Inst.Ref,
1288 ) !zir.Inst.Index {1288 ) !Zir.Inst.Index {
1289 assert(lhs != .none);1289 assert(lhs != .none);
1290 const gpa = gz.astgen.mod.gpa;1290 const gpa = gz.astgen.mod.gpa;
1291 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);1291 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);
1292 try gz.astgen.instructions.ensureCapacity(gpa, gz.astgen.instructions.len + 1);1292 try gz.astgen.instructions.ensureCapacity(gpa, gz.astgen.instructions.len + 1);
12931293
1294 const new_index = @intCast(zir.Inst.Index, gz.astgen.instructions.len);1294 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
1295 gz.astgen.instructions.appendAssumeCapacity(.{1295 gz.astgen.instructions.appendAssumeCapacity(.{
1296 .tag = tag,1296 .tag = tag,
1297 .data = .{ .bool_br = .{1297 .data = .{ .bool_br = .{
...@@ -1303,14 +1303,14 @@ pub const Scope = struct {...@@ -1303,14 +1303,14 @@ pub const Scope = struct {
1303 return new_index;1303 return new_index;
1304 }1304 }
13051305
1306 pub fn addInt(gz: *GenZir, integer: u64) !zir.Inst.Ref {1306 pub fn addInt(gz: *GenZir, integer: u64) !Zir.Inst.Ref {
1307 return gz.add(.{1307 return gz.add(.{
1308 .tag = .int,1308 .tag = .int,
1309 .data = .{ .int = integer },1309 .data = .{ .int = integer },
1310 });1310 });
1311 }1311 }
13121312
1313 pub fn addFloat(gz: *GenZir, number: f32, src_node: ast.Node.Index) !zir.Inst.Ref {1313 pub fn addFloat(gz: *GenZir, number: f32, src_node: ast.Node.Index) !Zir.Inst.Ref {
1314 return gz.add(.{1314 return gz.add(.{
1315 .tag = .float,1315 .tag = .float,
1316 .data = .{ .float = .{1316 .data = .{ .float = .{
...@@ -1322,11 +1322,11 @@ pub const Scope = struct {...@@ -1322,11 +1322,11 @@ pub const Scope = struct {
13221322
1323 pub fn addUnNode(1323 pub fn addUnNode(
1324 gz: *GenZir,1324 gz: *GenZir,
1325 tag: zir.Inst.Tag,1325 tag: Zir.Inst.Tag,
1326 operand: zir.Inst.Ref,1326 operand: Zir.Inst.Ref,
1327 /// Absolute node index. This function does the conversion to offset from Decl.1327 /// Absolute node index. This function does the conversion to offset from Decl.
1328 src_node: ast.Node.Index,1328 src_node: ast.Node.Index,
1329 ) !zir.Inst.Ref {1329 ) !Zir.Inst.Ref {
1330 assert(operand != .none);1330 assert(operand != .none);
1331 return gz.add(.{1331 return gz.add(.{
1332 .tag = tag,1332 .tag = tag,
...@@ -1339,17 +1339,17 @@ pub const Scope = struct {...@@ -1339,17 +1339,17 @@ pub const Scope = struct {
13391339
1340 pub fn addPlNode(1340 pub fn addPlNode(
1341 gz: *GenZir,1341 gz: *GenZir,
1342 tag: zir.Inst.Tag,1342 tag: Zir.Inst.Tag,
1343 /// Absolute node index. This function does the conversion to offset from Decl.1343 /// Absolute node index. This function does the conversion to offset from Decl.
1344 src_node: ast.Node.Index,1344 src_node: ast.Node.Index,
1345 extra: anytype,1345 extra: anytype,
1346 ) !zir.Inst.Ref {1346 ) !Zir.Inst.Ref {
1347 const gpa = gz.astgen.mod.gpa;1347 const gpa = gz.astgen.mod.gpa;
1348 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);1348 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);
1349 try gz.astgen.instructions.ensureCapacity(gpa, gz.astgen.instructions.len + 1);1349 try gz.astgen.instructions.ensureCapacity(gpa, gz.astgen.instructions.len + 1);
13501350
1351 const payload_index = try gz.astgen.addExtra(extra);1351 const payload_index = try gz.astgen.addExtra(extra);
1352 const new_index = @intCast(zir.Inst.Index, gz.astgen.instructions.len);1352 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
1353 gz.astgen.instructions.appendAssumeCapacity(.{1353 gz.astgen.instructions.appendAssumeCapacity(.{
1354 .tag = tag,1354 .tag = tag,
1355 .data = .{ .pl_node = .{1355 .data = .{ .pl_node = .{
...@@ -1363,19 +1363,19 @@ pub const Scope = struct {...@@ -1363,19 +1363,19 @@ pub const Scope = struct {
13631363
1364 pub fn addArrayTypeSentinel(1364 pub fn addArrayTypeSentinel(
1365 gz: *GenZir,1365 gz: *GenZir,
1366 len: zir.Inst.Ref,1366 len: Zir.Inst.Ref,
1367 sentinel: zir.Inst.Ref,1367 sentinel: Zir.Inst.Ref,
1368 elem_type: zir.Inst.Ref,1368 elem_type: Zir.Inst.Ref,
1369 ) !zir.Inst.Ref {1369 ) !Zir.Inst.Ref {
1370 const gpa = gz.astgen.mod.gpa;1370 const gpa = gz.astgen.mod.gpa;
1371 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);1371 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);
1372 try gz.astgen.instructions.ensureCapacity(gpa, gz.astgen.instructions.len + 1);1372 try gz.astgen.instructions.ensureCapacity(gpa, gz.astgen.instructions.len + 1);
13731373
1374 const payload_index = try gz.astgen.addExtra(zir.Inst.ArrayTypeSentinel{1374 const payload_index = try gz.astgen.addExtra(Zir.Inst.ArrayTypeSentinel{
1375 .sentinel = sentinel,1375 .sentinel = sentinel,
1376 .elem_type = elem_type,1376 .elem_type = elem_type,
1377 });1377 });
1378 const new_index = @intCast(zir.Inst.Index, gz.astgen.instructions.len);1378 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
1379 gz.astgen.instructions.appendAssumeCapacity(.{1379 gz.astgen.instructions.appendAssumeCapacity(.{
1380 .tag = .array_type_sentinel,1380 .tag = .array_type_sentinel,
1381 .data = .{ .array_type_sentinel = .{1381 .data = .{ .array_type_sentinel = .{
...@@ -1389,11 +1389,11 @@ pub const Scope = struct {...@@ -1389,11 +1389,11 @@ pub const Scope = struct {
13891389
1390 pub fn addUnTok(1390 pub fn addUnTok(
1391 gz: *GenZir,1391 gz: *GenZir,
1392 tag: zir.Inst.Tag,1392 tag: Zir.Inst.Tag,
1393 operand: zir.Inst.Ref,1393 operand: Zir.Inst.Ref,
1394 /// Absolute token index. This function does the conversion to Decl offset.1394 /// Absolute token index. This function does the conversion to Decl offset.
1395 abs_tok_index: ast.TokenIndex,1395 abs_tok_index: ast.TokenIndex,
1396 ) !zir.Inst.Ref {1396 ) !Zir.Inst.Ref {
1397 assert(operand != .none);1397 assert(operand != .none);
1398 return gz.add(.{1398 return gz.add(.{
1399 .tag = tag,1399 .tag = tag,
...@@ -1406,11 +1406,11 @@ pub const Scope = struct {...@@ -1406,11 +1406,11 @@ pub const Scope = struct {
14061406
1407 pub fn addStrTok(1407 pub fn addStrTok(
1408 gz: *GenZir,1408 gz: *GenZir,
1409 tag: zir.Inst.Tag,1409 tag: Zir.Inst.Tag,
1410 str_index: u32,1410 str_index: u32,
1411 /// Absolute token index. This function does the conversion to Decl offset.1411 /// Absolute token index. This function does the conversion to Decl offset.
1412 abs_tok_index: ast.TokenIndex,1412 abs_tok_index: ast.TokenIndex,
1413 ) !zir.Inst.Ref {1413 ) !Zir.Inst.Ref {
1414 return gz.add(.{1414 return gz.add(.{
1415 .tag = tag,1415 .tag = tag,
1416 .data = .{ .str_tok = .{1416 .data = .{ .str_tok = .{
...@@ -1422,10 +1422,10 @@ pub const Scope = struct {...@@ -1422,10 +1422,10 @@ pub const Scope = struct {
14221422
1423 pub fn addBreak(1423 pub fn addBreak(
1424 gz: *GenZir,1424 gz: *GenZir,
1425 tag: zir.Inst.Tag,1425 tag: Zir.Inst.Tag,
1426 break_block: zir.Inst.Index,1426 break_block: Zir.Inst.Index,
1427 operand: zir.Inst.Ref,1427 operand: Zir.Inst.Ref,
1428 ) !zir.Inst.Index {1428 ) !Zir.Inst.Index {
1429 return gz.addAsIndex(.{1429 return gz.addAsIndex(.{
1430 .tag = tag,1430 .tag = tag,
1431 .data = .{ .@"break" = .{1431 .data = .{ .@"break" = .{
...@@ -1437,10 +1437,10 @@ pub const Scope = struct {...@@ -1437,10 +1437,10 @@ pub const Scope = struct {
14371437
1438 pub fn addBin(1438 pub fn addBin(
1439 gz: *GenZir,1439 gz: *GenZir,
1440 tag: zir.Inst.Tag,1440 tag: Zir.Inst.Tag,
1441 lhs: zir.Inst.Ref,1441 lhs: Zir.Inst.Ref,
1442 rhs: zir.Inst.Ref,1442 rhs: Zir.Inst.Ref,
1443 ) !zir.Inst.Ref {1443 ) !Zir.Inst.Ref {
1444 assert(lhs != .none);1444 assert(lhs != .none);
1445 assert(rhs != .none);1445 assert(rhs != .none);
1446 return gz.add(.{1446 return gz.add(.{
...@@ -1454,10 +1454,10 @@ pub const Scope = struct {...@@ -1454,10 +1454,10 @@ pub const Scope = struct {
14541454
1455 pub fn addDecl(1455 pub fn addDecl(
1456 gz: *GenZir,1456 gz: *GenZir,
1457 tag: zir.Inst.Tag,1457 tag: Zir.Inst.Tag,
1458 decl_index: u32,1458 decl_index: u32,
1459 src_node: ast.Node.Index,1459 src_node: ast.Node.Index,
1460 ) !zir.Inst.Ref {1460 ) !Zir.Inst.Ref {
1461 return gz.add(.{1461 return gz.add(.{
1462 .tag = tag,1462 .tag = tag,
1463 .data = .{ .pl_node = .{1463 .data = .{ .pl_node = .{
...@@ -1469,10 +1469,10 @@ pub const Scope = struct {...@@ -1469,10 +1469,10 @@ pub const Scope = struct {
14691469
1470 pub fn addNode(1470 pub fn addNode(
1471 gz: *GenZir,1471 gz: *GenZir,
1472 tag: zir.Inst.Tag,1472 tag: Zir.Inst.Tag,
1473 /// Absolute node index. This function does the conversion to offset from Decl.1473 /// Absolute node index. This function does the conversion to offset from Decl.
1474 src_node: ast.Node.Index,1474 src_node: ast.Node.Index,
1475 ) !zir.Inst.Ref {1475 ) !Zir.Inst.Ref {
1476 return gz.add(.{1476 return gz.add(.{
1477 .tag = tag,1477 .tag = tag,
1478 .data = .{ .node = gz.astgen.decl.nodeIndexToRelative(src_node) },1478 .data = .{ .node = gz.astgen.decl.nodeIndexToRelative(src_node) },
...@@ -1482,9 +1482,9 @@ pub const Scope = struct {...@@ -1482,9 +1482,9 @@ pub const Scope = struct {
1482 /// Asserts that `str` is 8 or fewer bytes.1482 /// Asserts that `str` is 8 or fewer bytes.
1483 pub fn addSmallStr(1483 pub fn addSmallStr(
1484 gz: *GenZir,1484 gz: *GenZir,
1485 tag: zir.Inst.Tag,1485 tag: Zir.Inst.Tag,
1486 str: []const u8,1486 str: []const u8,
1487 ) !zir.Inst.Ref {1487 ) !Zir.Inst.Ref {
1488 var buf: [9]u8 = undefined;1488 var buf: [9]u8 = undefined;
1489 mem.copy(u8, &buf, str);1489 mem.copy(u8, &buf, str);
1490 buf[str.len] = 0;1490 buf[str.len] = 0;
...@@ -1495,11 +1495,11 @@ pub const Scope = struct {...@@ -1495,11 +1495,11 @@ pub const Scope = struct {
1495 });1495 });
1496 }1496 }
14971497
1498 /// Note that this returns a `zir.Inst.Index` not a ref.1498 /// Note that this returns a `Zir.Inst.Index` not a ref.
1499 /// Does *not* append the block instruction to the scope.1499 /// Does *not* append the block instruction to the scope.
1500 /// Leaves the `payload_index` field undefined.1500 /// Leaves the `payload_index` field undefined.
1501 pub fn addBlock(gz: *GenZir, tag: zir.Inst.Tag, node: ast.Node.Index) !zir.Inst.Index {1501 pub fn addBlock(gz: *GenZir, tag: Zir.Inst.Tag, node: ast.Node.Index) !Zir.Inst.Index {
1502 const new_index = @intCast(zir.Inst.Index, gz.astgen.instructions.len);1502 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
1503 const gpa = gz.astgen.mod.gpa;1503 const gpa = gz.astgen.mod.gpa;
1504 try gz.astgen.instructions.append(gpa, .{1504 try gz.astgen.instructions.append(gpa, .{
1505 .tag = tag,1505 .tag = tag,
...@@ -1511,12 +1511,12 @@ pub const Scope = struct {...@@ -1511,12 +1511,12 @@ pub const Scope = struct {
1511 return new_index;1511 return new_index;
1512 }1512 }
15131513
1514 /// Note that this returns a `zir.Inst.Index` not a ref.1514 /// Note that this returns a `Zir.Inst.Index` not a ref.
1515 /// Leaves the `payload_index` field undefined.1515 /// Leaves the `payload_index` field undefined.
1516 pub fn addCondBr(gz: *GenZir, tag: zir.Inst.Tag, node: ast.Node.Index) !zir.Inst.Index {1516 pub fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: ast.Node.Index) !Zir.Inst.Index {
1517 const gpa = gz.astgen.mod.gpa;1517 const gpa = gz.astgen.mod.gpa;
1518 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);1518 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);
1519 const new_index = @intCast(zir.Inst.Index, gz.astgen.instructions.len);1519 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
1520 try gz.astgen.instructions.append(gpa, .{1520 try gz.astgen.instructions.append(gpa, .{
1521 .tag = tag,1521 .tag = tag,
1522 .data = .{ .pl_node = .{1522 .data = .{ .pl_node = .{
...@@ -1528,16 +1528,16 @@ pub const Scope = struct {...@@ -1528,16 +1528,16 @@ pub const Scope = struct {
1528 return new_index;1528 return new_index;
1529 }1529 }
15301530
1531 pub fn add(gz: *GenZir, inst: zir.Inst) !zir.Inst.Ref {1531 pub fn add(gz: *GenZir, inst: Zir.Inst) !Zir.Inst.Ref {
1532 return gz.astgen.indexToRef(try gz.addAsIndex(inst));1532 return gz.astgen.indexToRef(try gz.addAsIndex(inst));
1533 }1533 }
15341534
1535 pub fn addAsIndex(gz: *GenZir, inst: zir.Inst) !zir.Inst.Index {1535 pub fn addAsIndex(gz: *GenZir, inst: Zir.Inst) !Zir.Inst.Index {
1536 const gpa = gz.astgen.mod.gpa;1536 const gpa = gz.astgen.mod.gpa;
1537 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);1537 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);
1538 try gz.astgen.instructions.ensureCapacity(gpa, gz.astgen.instructions.len + 1);1538 try gz.astgen.instructions.ensureCapacity(gpa, gz.astgen.instructions.len + 1);
15391539
1540 const new_index = @intCast(zir.Inst.Index, gz.astgen.instructions.len);1540 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
1541 gz.astgen.instructions.appendAssumeCapacity(inst);1541 gz.astgen.instructions.appendAssumeCapacity(inst);
1542 gz.instructions.appendAssumeCapacity(new_index);1542 gz.instructions.appendAssumeCapacity(new_index);
1543 return new_index;1543 return new_index;
...@@ -1554,7 +1554,7 @@ pub const Scope = struct {...@@ -1554,7 +1554,7 @@ pub const Scope = struct {
1554 parent: *Scope,1554 parent: *Scope,
1555 gen_zir: *GenZir,1555 gen_zir: *GenZir,
1556 name: []const u8,1556 name: []const u8,
1557 inst: zir.Inst.Ref,1557 inst: Zir.Inst.Ref,
1558 /// Source location of the corresponding variable declaration.1558 /// Source location of the corresponding variable declaration.
1559 src: LazySrcLoc,1559 src: LazySrcLoc,
1560 };1560 };
...@@ -1569,7 +1569,7 @@ pub const Scope = struct {...@@ -1569,7 +1569,7 @@ pub const Scope = struct {
1569 parent: *Scope,1569 parent: *Scope,
1570 gen_zir: *GenZir,1570 gen_zir: *GenZir,
1571 name: []const u8,1571 name: []const u8,
1572 ptr: zir.Inst.Ref,1572 ptr: Zir.Inst.Ref,
1573 /// Source location of the corresponding variable declaration.1573 /// Source location of the corresponding variable declaration.
1574 src: LazySrcLoc,1574 src: LazySrcLoc,
1575 };1575 };
...@@ -2511,7 +2511,7 @@ fn astgenAndSemaDecl(mod: *Module, decl: *Decl) !bool {...@@ -2511,7 +2511,7 @@ fn astgenAndSemaDecl(mod: *Module, decl: *Decl) !bool {
2511 var analysis_arena = std.heap.ArenaAllocator.init(mod.gpa);2511 var analysis_arena = std.heap.ArenaAllocator.init(mod.gpa);
2512 defer analysis_arena.deinit();2512 defer analysis_arena.deinit();
25132513
2514 var code: zir.Code = blk: {2514 var code: Zir = blk: {
2515 var astgen = try AstGen.init(mod, decl, &analysis_arena.allocator);2515 var astgen = try AstGen.init(mod, decl, &analysis_arena.allocator);
2516 defer astgen.deinit();2516 defer astgen.deinit();
25172517
...@@ -2578,7 +2578,7 @@ fn astgenAndSemaDecl(mod: *Module, decl: *Decl) !bool {...@@ -2578,7 +2578,7 @@ fn astgenAndSemaDecl(mod: *Module, decl: *Decl) !bool {
2578 var analysis_arena = std.heap.ArenaAllocator.init(mod.gpa);2578 var analysis_arena = std.heap.ArenaAllocator.init(mod.gpa);
2579 defer analysis_arena.deinit();2579 defer analysis_arena.deinit();
25802580
2581 var code: zir.Code = blk: {2581 var code: Zir = blk: {
2582 var astgen = try AstGen.init(mod, decl, &analysis_arena.allocator);2582 var astgen = try AstGen.init(mod, decl, &analysis_arena.allocator);
2583 defer astgen.deinit();2583 defer astgen.deinit();
25842584
...@@ -2676,7 +2676,7 @@ fn astgenAndSemaFn(...@@ -2676,7 +2676,7 @@ fn astgenAndSemaFn(
2676 }2676 }
2677 break :blk count;2677 break :blk count;
2678 };2678 };
2679 const param_types = try fn_type_scope_arena.allocator.alloc(zir.Inst.Ref, param_count);2679 const param_types = try fn_type_scope_arena.allocator.alloc(Zir.Inst.Ref, param_count);
26802680
2681 var is_var_args = false;2681 var is_var_args = false;
2682 {2682 {
...@@ -2782,7 +2782,7 @@ fn astgenAndSemaFn(...@@ -2782,7 +2782,7 @@ fn astgenAndSemaFn(
2782 else2782 else
2783 false;2783 false;
27842784
2785 const cc: zir.Inst.Ref = if (fn_proto.ast.callconv_expr != 0)2785 const cc: Zir.Inst.Ref = if (fn_proto.ast.callconv_expr != 0)
2786 // TODO instead of enum literal type, this needs to be the2786 // TODO instead of enum literal type, this needs to be the
2787 // std.builtin.CallingConvention enum. We need to implement importing other files2787 // std.builtin.CallingConvention enum. We need to implement importing other files
2788 // and enums in order to fix this.2788 // and enums in order to fix this.
...@@ -2797,8 +2797,8 @@ fn astgenAndSemaFn(...@@ -2797,8 +2797,8 @@ fn astgenAndSemaFn(
2797 else2797 else
2798 .none;2798 .none;
27992799
2800 const fn_type_inst: zir.Inst.Ref = if (cc != .none) fn_type: {2800 const fn_type_inst: Zir.Inst.Ref = if (cc != .none) fn_type: {
2801 const tag: zir.Inst.Tag = if (is_var_args) .fn_type_cc_var_args else .fn_type_cc;2801 const tag: Zir.Inst.Tag = if (is_var_args) .fn_type_cc_var_args else .fn_type_cc;
2802 break :fn_type try fn_type_scope.addFnTypeCc(tag, .{2802 break :fn_type try fn_type_scope.addFnTypeCc(tag, .{
2803 .src_node = fn_proto.ast.proto_node,2803 .src_node = fn_proto.ast.proto_node,
2804 .ret_ty = return_type_inst,2804 .ret_ty = return_type_inst,
...@@ -2806,7 +2806,7 @@ fn astgenAndSemaFn(...@@ -2806,7 +2806,7 @@ fn astgenAndSemaFn(
2806 .cc = cc,2806 .cc = cc,
2807 });2807 });
2808 } else fn_type: {2808 } else fn_type: {
2809 const tag: zir.Inst.Tag = if (is_var_args) .fn_type_var_args else .fn_type;2809 const tag: Zir.Inst.Tag = if (is_var_args) .fn_type_var_args else .fn_type;
2810 break :fn_type try fn_type_scope.addFnType(tag, .{2810 break :fn_type try fn_type_scope.addFnType(tag, .{
2811 .src_node = fn_proto.ast.proto_node,2811 .src_node = fn_proto.ast.proto_node,
2812 .ret_ty = return_type_inst,2812 .ret_ty = return_type_inst,
...@@ -2890,10 +2890,10 @@ fn astgenAndSemaFn(...@@ -2890,10 +2890,10 @@ fn astgenAndSemaFn(
2890 const new_func = try decl_arena.allocator.create(Fn);2890 const new_func = try decl_arena.allocator.create(Fn);
2891 const fn_payload = try decl_arena.allocator.create(Value.Payload.Function);2891 const fn_payload = try decl_arena.allocator.create(Value.Payload.Function);
28922892
2893 const fn_zir: zir.Code = blk: {2893 const fn_zir: Zir = blk: {
2894 // We put the ZIR inside the Decl arena.2894 // We put the ZIR inside the Decl arena.
2895 var astgen = try AstGen.init(mod, decl, &decl_arena.allocator);2895 var astgen = try AstGen.init(mod, decl, &decl_arena.allocator);
2896 astgen.ref_start_index = @intCast(u32, zir.Inst.Ref.typed_value_map.len + param_count);2896 astgen.ref_start_index = @intCast(u32, Zir.Inst.Ref.typed_value_map.len + param_count);
2897 defer astgen.deinit();2897 defer astgen.deinit();
28982898
2899 var gen_scope: Scope.GenZir = .{2899 var gen_scope: Scope.GenZir = .{
...@@ -2920,7 +2920,7 @@ fn astgenAndSemaFn(...@@ -2920,7 +2920,7 @@ fn astgenAndSemaFn(
2920 .gen_zir = &gen_scope,2920 .gen_zir = &gen_scope,
2921 .name = param_name,2921 .name = param_name,
2922 // Implicit const list first, then implicit arg list.2922 // Implicit const list first, then implicit arg list.
2923 .inst = @intToEnum(zir.Inst.Ref, @intCast(u32, zir.Inst.Ref.typed_value_map.len + i)),2923 .inst = @intToEnum(Zir.Inst.Ref, @intCast(u32, Zir.Inst.Ref.typed_value_map.len + i)),
2924 .src = decl.tokSrcLoc(name_token),2924 .src = decl.tokSrcLoc(name_token),
2925 };2925 };
2926 params_scope = &sub_scope.base;2926 params_scope = &sub_scope.base;
src/Sema.zig+237-237
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1//! Semantic analysis of ZIR instructions.1//! Semantic analysis of ZIR instructions.
2//! Shared to every Block. Stored on the stack.2//! Shared to every Block. Stored on the stack.
3//! State used for compiling a `zir.Code` into TZIR.3//! State used for compiling a `Zir` into TZIR.
4//! Transforms untyped ZIR instructions into semantically-analyzed TZIR instructions.4//! Transforms untyped ZIR instructions into semantically-analyzed TZIR instructions.
5//! Does type checking, comptime control flow, and safety-check generation.5//! Does type checking, comptime control flow, and safety-check generation.
6//! This is the the heart of the Zig compiler.6//! This is the the heart of the Zig compiler.
...@@ -10,7 +10,7 @@ mod: *Module,...@@ -10,7 +10,7 @@ mod: *Module,
10gpa: *Allocator,10gpa: *Allocator,
11/// Points to the arena allocator of the Decl.11/// Points to the arena allocator of the Decl.
12arena: *Allocator,12arena: *Allocator,
13code: zir.Code,13code: Zir,
14/// Maps ZIR to TZIR.14/// Maps ZIR to TZIR.
15inst_map: []*Inst,15inst_map: []*Inst,
16/// When analyzing an inline function call, owner_decl is the Decl of the caller16/// When analyzing an inline function call, owner_decl is the Decl of the caller
...@@ -52,7 +52,7 @@ const Value = @import("value.zig").Value;...@@ -52,7 +52,7 @@ const Value = @import("value.zig").Value;
52const Type = @import("type.zig").Type;52const Type = @import("type.zig").Type;
53const TypedValue = @import("TypedValue.zig");53const TypedValue = @import("TypedValue.zig");
54const ir = @import("ir.zig");54const ir = @import("ir.zig");
55const zir = @import("zir.zig");55const Zir = @import("zir.zig"); // TODO rename to Zir.zig
56const Module = @import("Module.zig");56const Module = @import("Module.zig");
57const Inst = ir.Inst;57const Inst = ir.Inst;
58const Body = ir.Body;58const Body = ir.Body;
...@@ -64,14 +64,14 @@ const LazySrcLoc = Module.LazySrcLoc;...@@ -64,14 +64,14 @@ const LazySrcLoc = Module.LazySrcLoc;
64const RangeSet = @import("RangeSet.zig");64const RangeSet = @import("RangeSet.zig");
65const AstGen = @import("AstGen.zig");65const AstGen = @import("AstGen.zig");
6666
67pub fn root(sema: *Sema, root_block: *Scope.Block) !zir.Inst.Index {67pub fn root(sema: *Sema, root_block: *Scope.Block) !Zir.Inst.Index {
68 const inst_data = sema.code.instructions.items(.data)[0].pl_node;68 const inst_data = sema.code.instructions.items(.data)[0].pl_node;
69 const extra = sema.code.extraData(zir.Inst.Block, inst_data.payload_index);69 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
70 const root_body = sema.code.extra[extra.end..][0..extra.data.body_len];70 const root_body = sema.code.extra[extra.end..][0..extra.data.body_len];
71 return sema.analyzeBody(root_block, root_body);71 return sema.analyzeBody(root_block, root_body);
72}72}
7373
74pub fn rootAsRef(sema: *Sema, root_block: *Scope.Block) !zir.Inst.Ref {74pub fn rootAsRef(sema: *Sema, root_block: *Scope.Block) !Zir.Inst.Ref {
75 const break_inst = try sema.root(root_block);75 const break_inst = try sema.root(root_block);
76 return sema.code.instructions.items(.data)[break_inst].@"break".operand;76 return sema.code.instructions.items(.data)[break_inst].@"break".operand;
77}77}
...@@ -89,7 +89,7 @@ pub fn rootAsType(sema: *Sema, root_block: *Scope.Block) !Type {...@@ -89,7 +89,7 @@ pub fn rootAsType(sema: *Sema, root_block: *Scope.Block) !Type {
89/// Returns only the result from the body that is specified.89/// Returns only the result from the body that is specified.
90/// Only appropriate to call when it is determined at comptime that this body90/// Only appropriate to call when it is determined at comptime that this body
91/// has no peers.91/// has no peers.
92fn resolveBody(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) InnerError!*Inst {92fn resolveBody(sema: *Sema, block: *Scope.Block, body: []const Zir.Inst.Index) InnerError!*Inst {
93 const break_inst = try sema.analyzeBody(block, body);93 const break_inst = try sema.analyzeBody(block, body);
94 const operand_ref = sema.code.instructions.items(.data)[break_inst].@"break".operand;94 const operand_ref = sema.code.instructions.items(.data)[break_inst].@"break".operand;
95 return sema.resolveInst(operand_ref);95 return sema.resolveInst(operand_ref);
...@@ -99,22 +99,22 @@ fn resolveBody(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) I...@@ -99,22 +99,22 @@ fn resolveBody(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) I
99/// return type of `analyzeBody` so that we can tail call them.99/// return type of `analyzeBody` so that we can tail call them.
100/// Only appropriate to return when the instruction is known to be NoReturn100/// Only appropriate to return when the instruction is known to be NoReturn
101/// solely based on the ZIR tag.101/// solely based on the ZIR tag.
102const always_noreturn: InnerError!zir.Inst.Index = @as(zir.Inst.Index, undefined);102const always_noreturn: InnerError!Zir.Inst.Index = @as(Zir.Inst.Index, undefined);
103103
104/// This function is the main loop of `Sema` and it can be used in two different ways:104/// This function is the main loop of `Sema` and it can be used in two different ways:
105/// * The traditional way where there are N breaks out of the block and peer type105/// * The traditional way where there are N breaks out of the block and peer type
106/// resolution is done on the break operands. In this case, the `zir.Inst.Index`106/// resolution is done on the break operands. In this case, the `Zir.Inst.Index`
107/// part of the return value will be `undefined`, and callsites should ignore it,107/// part of the return value will be `undefined`, and callsites should ignore it,
108/// finding the block result value via the block scope.108/// finding the block result value via the block scope.
109/// * The "flat" way. There is only 1 break out of the block, and it is with a `break_inline`109/// * The "flat" way. There is only 1 break out of the block, and it is with a `break_inline`
110/// instruction. In this case, the `zir.Inst.Index` part of the return value will be110/// instruction. In this case, the `Zir.Inst.Index` part of the return value will be
111/// the break instruction. This communicates both which block the break applies to, as111/// the break instruction. This communicates both which block the break applies to, as
112/// well as the operand. No block scope needs to be created for this strategy.112/// well as the operand. No block scope needs to be created for this strategy.
113pub fn analyzeBody(113pub fn analyzeBody(
114 sema: *Sema,114 sema: *Sema,
115 block: *Scope.Block,115 block: *Scope.Block,
116 body: []const zir.Inst.Index,116 body: []const Zir.Inst.Index,
117) InnerError!zir.Inst.Index {117) InnerError!Zir.Inst.Index {
118 // No tracy calls here, to avoid interfering with the tail call mechanism.118 // No tracy calls here, to avoid interfering with the tail call mechanism.
119119
120 const map = block.sema.inst_map;120 const map = block.sema.inst_map;
...@@ -368,7 +368,7 @@ pub fn analyzeBody(...@@ -368,7 +368,7 @@ pub fn analyzeBody(
368 .block_inline => blk: {368 .block_inline => blk: {
369 // Directly analyze the block body without introducing a new block.369 // Directly analyze the block body without introducing a new block.
370 const inst_data = datas[inst].pl_node;370 const inst_data = datas[inst].pl_node;
371 const extra = sema.code.extraData(zir.Inst.Block, inst_data.payload_index);371 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
372 const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len];372 const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len];
373 const break_inst = try sema.analyzeBody(block, inline_body);373 const break_inst = try sema.analyzeBody(block, inline_body);
374 const break_data = datas[break_inst].@"break";374 const break_data = datas[break_inst].@"break";
...@@ -381,7 +381,7 @@ pub fn analyzeBody(...@@ -381,7 +381,7 @@ pub fn analyzeBody(
381 .condbr_inline => blk: {381 .condbr_inline => blk: {
382 const inst_data = datas[inst].pl_node;382 const inst_data = datas[inst].pl_node;
383 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };383 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };
384 const extra = sema.code.extraData(zir.Inst.CondBr, inst_data.payload_index);384 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
385 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];385 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];
386 const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];386 const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
387 const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition);387 const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition);
...@@ -401,19 +401,19 @@ pub fn analyzeBody(...@@ -401,19 +401,19 @@ pub fn analyzeBody(
401}401}
402402
403/// TODO when we rework TZIR memory layout, this function will no longer have a possible error.403/// TODO when we rework TZIR memory layout, this function will no longer have a possible error.
404pub fn resolveInst(sema: *Sema, zir_ref: zir.Inst.Ref) error{OutOfMemory}!*ir.Inst {404pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) error{OutOfMemory}!*ir.Inst {
405 var i: usize = @enumToInt(zir_ref);405 var i: usize = @enumToInt(zir_ref);
406406
407 // First section of indexes correspond to a set number of constant values.407 // First section of indexes correspond to a set number of constant values.
408 if (i < zir.Inst.Ref.typed_value_map.len) {408 if (i < Zir.Inst.Ref.typed_value_map.len) {
409 // TODO when we rework TZIR memory layout, this function can be as simple as:409 // TODO when we rework TZIR memory layout, this function can be as simple as:
410 // if (zir_ref < zir.const_inst_list.len + sema.param_count)410 // if (zir_ref < Zir.const_inst_list.len + sema.param_count)
411 // return zir_ref;411 // return zir_ref;
412 // Until then we allocate memory for a new, mutable `ir.Inst` to match what412 // Until then we allocate memory for a new, mutable `ir.Inst` to match what
413 // TZIR expects.413 // TZIR expects.
414 return sema.mod.constInst(sema.arena, .unneeded, zir.Inst.Ref.typed_value_map[i]);414 return sema.mod.constInst(sema.arena, .unneeded, Zir.Inst.Ref.typed_value_map[i]);
415 }415 }
416 i -= zir.Inst.Ref.typed_value_map.len;416 i -= Zir.Inst.Ref.typed_value_map.len;
417417
418 // Next section of indexes correspond to function parameters, if any.418 // Next section of indexes correspond to function parameters, if any.
419 if (i < sema.param_inst_list.len) {419 if (i < sema.param_inst_list.len) {
...@@ -429,7 +429,7 @@ fn resolveConstString(...@@ -429,7 +429,7 @@ fn resolveConstString(
429 sema: *Sema,429 sema: *Sema,
430 block: *Scope.Block,430 block: *Scope.Block,
431 src: LazySrcLoc,431 src: LazySrcLoc,
432 zir_ref: zir.Inst.Ref,432 zir_ref: Zir.Inst.Ref,
433) ![]u8 {433) ![]u8 {
434 const tzir_inst = try sema.resolveInst(zir_ref);434 const tzir_inst = try sema.resolveInst(zir_ref);
435 const wanted_type = Type.initTag(.const_slice_u8);435 const wanted_type = Type.initTag(.const_slice_u8);
...@@ -438,7 +438,7 @@ fn resolveConstString(...@@ -438,7 +438,7 @@ fn resolveConstString(
438 return val.toAllocatedBytes(sema.arena);438 return val.toAllocatedBytes(sema.arena);
439}439}
440440
441fn resolveType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, zir_ref: zir.Inst.Ref) !Type {441fn resolveType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type {
442 const tzir_inst = try sema.resolveInst(zir_ref);442 const tzir_inst = try sema.resolveInst(zir_ref);
443 const wanted_type = Type.initTag(.@"type");443 const wanted_type = Type.initTag(.@"type");
444 const coerced_inst = try sema.coerce(block, wanted_type, tzir_inst, src);444 const coerced_inst = try sema.coerce(block, wanted_type, tzir_inst, src);
...@@ -476,7 +476,7 @@ fn resolveAlreadyCoercedInt(...@@ -476,7 +476,7 @@ fn resolveAlreadyCoercedInt(
476 sema: *Sema,476 sema: *Sema,
477 block: *Scope.Block,477 block: *Scope.Block,
478 src: LazySrcLoc,478 src: LazySrcLoc,
479 zir_ref: zir.Inst.Ref,479 zir_ref: Zir.Inst.Ref,
480 comptime Int: type,480 comptime Int: type,
481) !Int {481) !Int {
482 comptime assert(@typeInfo(Int).Int.bits <= 64);482 comptime assert(@typeInfo(Int).Int.bits <= 64);
...@@ -492,7 +492,7 @@ fn resolveInt(...@@ -492,7 +492,7 @@ fn resolveInt(
492 sema: *Sema,492 sema: *Sema,
493 block: *Scope.Block,493 block: *Scope.Block,
494 src: LazySrcLoc,494 src: LazySrcLoc,
495 zir_ref: zir.Inst.Ref,495 zir_ref: Zir.Inst.Ref,
496 dest_type: Type,496 dest_type: Type,
497) !u64 {497) !u64 {
498 const tzir_inst = try sema.resolveInst(zir_ref);498 const tzir_inst = try sema.resolveInst(zir_ref);
...@@ -506,7 +506,7 @@ fn resolveInstConst(...@@ -506,7 +506,7 @@ fn resolveInstConst(
506 sema: *Sema,506 sema: *Sema,
507 block: *Scope.Block,507 block: *Scope.Block,
508 src: LazySrcLoc,508 src: LazySrcLoc,
509 zir_ref: zir.Inst.Ref,509 zir_ref: Zir.Inst.Ref,
510) InnerError!TypedValue {510) InnerError!TypedValue {
511 const tzir_inst = try sema.resolveInst(zir_ref);511 const tzir_inst = try sema.resolveInst(zir_ref);
512 const val = try sema.resolveConstValue(block, src, tzir_inst);512 const val = try sema.resolveConstValue(block, src, tzir_inst);
...@@ -516,13 +516,13 @@ fn resolveInstConst(...@@ -516,13 +516,13 @@ fn resolveInstConst(
516 };516 };
517}517}
518518
519fn zirBitcastResultPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {519fn zirBitcastResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
520 const tracy = trace(@src());520 const tracy = trace(@src());
521 defer tracy.end();521 defer tracy.end();
522 return sema.mod.fail(&block.base, sema.src, "TODO implement zir_sema.zirBitcastResultPtr", .{});522 return sema.mod.fail(&block.base, sema.src, "TODO implement zir_sema.zirBitcastResultPtr", .{});
523}523}
524524
525fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {525fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
526 const tracy = trace(@src());526 const tracy = trace(@src());
527 defer tracy.end();527 defer tracy.end();
528 return sema.mod.fail(&block.base, sema.src, "TODO implement zirCoerceResultPtr", .{});528 return sema.mod.fail(&block.base, sema.src, "TODO implement zirCoerceResultPtr", .{});
...@@ -531,7 +531,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In...@@ -531,7 +531,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In
531fn zirStructDecl(531fn zirStructDecl(
532 sema: *Sema,532 sema: *Sema,
533 block: *Scope.Block,533 block: *Scope.Block,
534 inst: zir.Inst.Index,534 inst: Zir.Inst.Index,
535 layout: std.builtin.TypeInfo.ContainerLayout,535 layout: std.builtin.TypeInfo.ContainerLayout,
536) InnerError!*Inst {536) InnerError!*Inst {
537 const tracy = trace(@src());537 const tracy = trace(@src());
...@@ -540,7 +540,7 @@ fn zirStructDecl(...@@ -540,7 +540,7 @@ fn zirStructDecl(
540 const gpa = sema.gpa;540 const gpa = sema.gpa;
541 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;541 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
542 const src = inst_data.src();542 const src = inst_data.src();
543 const extra = sema.code.extraData(zir.Inst.StructDecl, inst_data.payload_index);543 const extra = sema.code.extraData(Zir.Inst.StructDecl, inst_data.payload_index);
544 const body = sema.code.extra[extra.end..][0..extra.data.body_len];544 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
545 const fields_len = extra.data.fields_len;545 const fields_len = extra.data.fields_len;
546546
...@@ -650,7 +650,7 @@ fn zirStructDecl(...@@ -650,7 +650,7 @@ fn zirStructDecl(
650650
651 const field_name_zir = sema.code.nullTerminatedString(sema.code.extra[extra_index]);651 const field_name_zir = sema.code.nullTerminatedString(sema.code.extra[extra_index]);
652 extra_index += 1;652 extra_index += 1;
653 const field_type_ref = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_index]);653 const field_type_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
654 extra_index += 1;654 extra_index += 1;
655655
656 // This string needs to outlive the ZIR code.656 // This string needs to outlive the ZIR code.
...@@ -669,7 +669,7 @@ fn zirStructDecl(...@@ -669,7 +669,7 @@ fn zirStructDecl(
669 };669 };
670670
671 if (has_align) {671 if (has_align) {
672 const align_ref = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_index]);672 const align_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
673 extra_index += 1;673 extra_index += 1;
674 // TODO: if we need to report an error here, use a source location674 // TODO: if we need to report an error here, use a source location
675 // that points to this alignment expression rather than the struct.675 // that points to this alignment expression rather than the struct.
...@@ -677,7 +677,7 @@ fn zirStructDecl(...@@ -677,7 +677,7 @@ fn zirStructDecl(
677 gop.entry.value.abi_align = (try sema.resolveInstConst(block, src, align_ref)).val;677 gop.entry.value.abi_align = (try sema.resolveInstConst(block, src, align_ref)).val;
678 }678 }
679 if (has_default) {679 if (has_default) {
680 const default_ref = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_index]);680 const default_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
681 extra_index += 1;681 extra_index += 1;
682 // TODO: if we need to report an error here, use a source location682 // TODO: if we need to report an error here, use a source location
683 // that points to this default value expression rather than the struct.683 // that points to this default value expression rather than the struct.
...@@ -692,7 +692,7 @@ fn zirStructDecl(...@@ -692,7 +692,7 @@ fn zirStructDecl(
692fn zirEnumDecl(692fn zirEnumDecl(
693 sema: *Sema,693 sema: *Sema,
694 block: *Scope.Block,694 block: *Scope.Block,
695 inst: zir.Inst.Index,695 inst: Zir.Inst.Index,
696 nonexhaustive: bool,696 nonexhaustive: bool,
697) InnerError!*Inst {697) InnerError!*Inst {
698 const tracy = trace(@src());698 const tracy = trace(@src());
...@@ -701,7 +701,7 @@ fn zirEnumDecl(...@@ -701,7 +701,7 @@ fn zirEnumDecl(
701 const gpa = sema.gpa;701 const gpa = sema.gpa;
702 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;702 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
703 const src = inst_data.src();703 const src = inst_data.src();
704 const extra = sema.code.extraData(zir.Inst.EnumDecl, inst_data.payload_index);704 const extra = sema.code.extraData(Zir.Inst.EnumDecl, inst_data.payload_index);
705 const body = sema.code.extra[extra.end..][0..extra.data.body_len];705 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
706 const fields_len = extra.data.fields_len;706 const fields_len = extra.data.fields_len;
707707
...@@ -842,7 +842,7 @@ fn zirEnumDecl(...@@ -842,7 +842,7 @@ fn zirEnumDecl(
842 assert(!gop.found_existing);842 assert(!gop.found_existing);
843843
844 if (has_tag_value) {844 if (has_tag_value) {
845 const tag_val_ref = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_index]);845 const tag_val_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
846 extra_index += 1;846 extra_index += 1;
847 // TODO: if we need to report an error here, use a source location847 // TODO: if we need to report an error here, use a source location
848 // that points to this default value expression rather than the struct.848 // that points to this default value expression rather than the struct.
...@@ -858,29 +858,29 @@ fn zirEnumDecl(...@@ -858,29 +858,29 @@ fn zirEnumDecl(
858 return sema.analyzeDeclVal(block, src, new_decl);858 return sema.analyzeDeclVal(block, src, new_decl);
859}859}
860860
861fn zirUnionDecl(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {861fn zirUnionDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
862 const tracy = trace(@src());862 const tracy = trace(@src());
863 defer tracy.end();863 defer tracy.end();
864864
865 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;865 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
866 const src = inst_data.src();866 const src = inst_data.src();
867 const extra = sema.code.extraData(zir.Inst.Block, inst_data.payload_index);867 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
868868
869 return sema.mod.fail(&block.base, sema.src, "TODO implement zirUnionDecl", .{});869 return sema.mod.fail(&block.base, sema.src, "TODO implement zirUnionDecl", .{});
870}870}
871871
872fn zirOpaqueDecl(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {872fn zirOpaqueDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
873 const tracy = trace(@src());873 const tracy = trace(@src());
874 defer tracy.end();874 defer tracy.end();
875875
876 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;876 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
877 const src = inst_data.src();877 const src = inst_data.src();
878 const extra = sema.code.extraData(zir.Inst.Block, inst_data.payload_index);878 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
879879
880 return sema.mod.fail(&block.base, sema.src, "TODO implement zirOpaqueDecl", .{});880 return sema.mod.fail(&block.base, sema.src, "TODO implement zirOpaqueDecl", .{});
881}881}
882882
883fn zirRetPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {883fn zirRetPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
884 const tracy = trace(@src());884 const tracy = trace(@src());
885 defer tracy.end();885 defer tracy.end();
886886
...@@ -892,7 +892,7 @@ fn zirRetPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!...@@ -892,7 +892,7 @@ fn zirRetPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!
892 return block.addNoOp(src, ptr_type, .alloc);892 return block.addNoOp(src, ptr_type, .alloc);
893}893}
894894
895fn zirRef(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {895fn zirRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
896 const tracy = trace(@src());896 const tracy = trace(@src());
897 defer tracy.end();897 defer tracy.end();
898898
...@@ -901,7 +901,7 @@ fn zirRef(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*In...@@ -901,7 +901,7 @@ fn zirRef(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*In
901 return sema.analyzeRef(block, inst_data.src(), operand);901 return sema.analyzeRef(block, inst_data.src(), operand);
902}902}
903903
904fn zirRetType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {904fn zirRetType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
905 const tracy = trace(@src());905 const tracy = trace(@src());
906 defer tracy.end();906 defer tracy.end();
907907
...@@ -912,7 +912,7 @@ fn zirRetType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError...@@ -912,7 +912,7 @@ fn zirRetType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError
912 return sema.mod.constType(sema.arena, src, ret_type);912 return sema.mod.constType(sema.arena, src, ret_type);
913}913}
914914
915fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!void {915fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
916 const tracy = trace(@src());916 const tracy = trace(@src());
917 defer tracy.end();917 defer tracy.end();
918918
...@@ -935,7 +935,7 @@ fn ensureResultUsed(...@@ -935,7 +935,7 @@ fn ensureResultUsed(
935 }935 }
936}936}
937937
938fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!void {938fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
939 const tracy = trace(@src());939 const tracy = trace(@src());
940 defer tracy.end();940 defer tracy.end();
941941
...@@ -948,7 +948,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Inde...@@ -948,7 +948,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Inde
948 }948 }
949}949}
950950
951fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {951fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
952 const tracy = trace(@src());952 const tracy = trace(@src());
953 defer tracy.end();953 defer tracy.end();
954954
...@@ -982,7 +982,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In...@@ -982,7 +982,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In
982 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);982 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);
983}983}
984984
985fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {985fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
986 const tracy = trace(@src());986 const tracy = trace(@src());
987 defer tracy.end();987 defer tracy.end();
988988
...@@ -995,7 +995,7 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*...@@ -995,7 +995,7 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*
995 return block.addNoOp(var_decl_src, ptr_type, .alloc);995 return block.addNoOp(var_decl_src, ptr_type, .alloc);
996}996}
997997
998fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {998fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
999 const tracy = trace(@src());999 const tracy = trace(@src());
1000 defer tracy.end();1000 defer tracy.end();
10011001
...@@ -1012,7 +1012,7 @@ fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro...@@ -1012,7 +1012,7 @@ fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro
1012fn zirAllocInferred(1012fn zirAllocInferred(
1013 sema: *Sema,1013 sema: *Sema,
1014 block: *Scope.Block,1014 block: *Scope.Block,
1015 inst: zir.Inst.Index,1015 inst: Zir.Inst.Index,
1016 inferred_alloc_ty: Type,1016 inferred_alloc_ty: Type,
1017) InnerError!*Inst {1017) InnerError!*Inst {
1018 const tracy = trace(@src());1018 const tracy = trace(@src());
...@@ -1038,7 +1038,7 @@ fn zirAllocInferred(...@@ -1038,7 +1038,7 @@ fn zirAllocInferred(
1038 return result;1038 return result;
1039}1039}
10401040
1041fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!void {1041fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
1042 const tracy = trace(@src());1042 const tracy = trace(@src());
1043 defer tracy.end();1043 defer tracy.end();
10441044
...@@ -1064,7 +1064,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Inde...@@ -1064,7 +1064,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Inde
1064 ptr.tag = .alloc;1064 ptr.tag = .alloc;
1065}1065}
10661066
1067fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!void {1067fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
1068 const tracy = trace(@src());1068 const tracy = trace(@src());
1069 defer tracy.end();1069 defer tracy.end();
10701070
...@@ -1072,26 +1072,26 @@ fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Ind...@@ -1072,26 +1072,26 @@ fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Ind
1072 const mod = sema.mod;1072 const mod = sema.mod;
1073 const validate_inst = sema.code.instructions.items(.data)[inst].pl_node;1073 const validate_inst = sema.code.instructions.items(.data)[inst].pl_node;
1074 const struct_init_src = validate_inst.src();1074 const struct_init_src = validate_inst.src();
1075 const validate_extra = sema.code.extraData(zir.Inst.Block, validate_inst.payload_index);1075 const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index);
1076 const instrs = sema.code.extra[validate_extra.end..][0..validate_extra.data.body_len];1076 const instrs = sema.code.extra[validate_extra.end..][0..validate_extra.data.body_len];
10771077
1078 const struct_obj: *Module.Struct = s: {1078 const struct_obj: *Module.Struct = s: {
1079 const field_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node;1079 const field_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node;
1080 const field_ptr_extra = sema.code.extraData(zir.Inst.Field, field_ptr_data.payload_index).data;1080 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
1081 const object_ptr = try sema.resolveInst(field_ptr_extra.lhs);1081 const object_ptr = try sema.resolveInst(field_ptr_extra.lhs);
1082 break :s object_ptr.ty.elemType().castTag(.@"struct").?.data;1082 break :s object_ptr.ty.elemType().castTag(.@"struct").?.data;
1083 };1083 };
10841084
1085 // Maps field index to field_ptr index of where it was already initialized.1085 // Maps field index to field_ptr index of where it was already initialized.
1086 const found_fields = try gpa.alloc(zir.Inst.Index, struct_obj.fields.entries.items.len);1086 const found_fields = try gpa.alloc(Zir.Inst.Index, struct_obj.fields.entries.items.len);
1087 defer gpa.free(found_fields);1087 defer gpa.free(found_fields);
10881088
1089 mem.set(zir.Inst.Index, found_fields, 0);1089 mem.set(Zir.Inst.Index, found_fields, 0);
10901090
1091 for (instrs) |field_ptr| {1091 for (instrs) |field_ptr| {
1092 const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;1092 const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;
1093 const field_src: LazySrcLoc = .{ .node_offset_back2tok = field_ptr_data.src_node };1093 const field_src: LazySrcLoc = .{ .node_offset_back2tok = field_ptr_data.src_node };
1094 const field_ptr_extra = sema.code.extraData(zir.Inst.Field, field_ptr_data.payload_index).data;1094 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
1095 const field_name = sema.code.nullTerminatedString(field_ptr_extra.field_name_start);1095 const field_name = sema.code.nullTerminatedString(field_ptr_extra.field_name_start);
1096 const field_index = struct_obj.fields.getIndex(field_name) orelse1096 const field_index = struct_obj.fields.getIndex(field_name) orelse
1097 return sema.failWithBadFieldAccess(block, struct_obj, field_src, field_name);1097 return sema.failWithBadFieldAccess(block, struct_obj, field_src, field_name);
...@@ -1164,7 +1164,7 @@ fn failWithBadFieldAccess(...@@ -1164,7 +1164,7 @@ fn failWithBadFieldAccess(
1164 return mod.failWithOwnedErrorMsg(&block.base, msg);1164 return mod.failWithOwnedErrorMsg(&block.base, msg);
1165}1165}
11661166
1167fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!void {1167fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
1168 const tracy = trace(@src());1168 const tracy = trace(@src());
1169 defer tracy.end();1169 defer tracy.end();
11701170
...@@ -1180,7 +1180,7 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In...@@ -1180,7 +1180,7 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In
1180 return sema.storePtr(block, src, bitcasted_ptr, value);1180 return sema.storePtr(block, src, bitcasted_ptr, value);
1181}1181}
11821182
1183fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!void {1183fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
1184 const tracy = trace(@src());1184 const tracy = trace(@src());
1185 defer tracy.end();1185 defer tracy.end();
11861186
...@@ -1199,7 +1199,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index)...@@ -1199,7 +1199,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index)
1199 return sema.storePtr(block, src, bitcasted_ptr, value);1199 return sema.storePtr(block, src, bitcasted_ptr, value);
1200}1200}
12011201
1202fn zirSetEvalBranchQuota(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!void {1202fn zirSetEvalBranchQuota(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
1203 const inst_data = sema.code.instructions.items(.data)[inst].un_node;1203 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1204 const src = inst_data.src();1204 const src = inst_data.src();
1205 try sema.requireFunctionBlock(block, src);1205 try sema.requireFunctionBlock(block, src);
...@@ -1208,7 +1208,7 @@ fn zirSetEvalBranchQuota(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index)...@@ -1208,7 +1208,7 @@ fn zirSetEvalBranchQuota(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index)
1208 sema.branch_quota = quota;1208 sema.branch_quota = quota;
1209}1209}
12101210
1211fn zirStore(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!void {1211fn zirStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
1212 const tracy = trace(@src());1212 const tracy = trace(@src());
1213 defer tracy.end();1213 defer tracy.end();
12141214
...@@ -1218,19 +1218,19 @@ fn zirStore(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!v...@@ -1218,19 +1218,19 @@ fn zirStore(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!v
1218 return sema.storePtr(block, sema.src, ptr, value);1218 return sema.storePtr(block, sema.src, ptr, value);
1219}1219}
12201220
1221fn zirStoreNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!void {1221fn zirStoreNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
1222 const tracy = trace(@src());1222 const tracy = trace(@src());
1223 defer tracy.end();1223 defer tracy.end();
12241224
1225 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1225 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1226 const src = inst_data.src();1226 const src = inst_data.src();
1227 const extra = sema.code.extraData(zir.Inst.Bin, inst_data.payload_index).data;1227 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1228 const ptr = try sema.resolveInst(extra.lhs);1228 const ptr = try sema.resolveInst(extra.lhs);
1229 const value = try sema.resolveInst(extra.rhs);1229 const value = try sema.resolveInst(extra.rhs);
1230 return sema.storePtr(block, src, ptr, value);1230 return sema.storePtr(block, src, ptr, value);
1231}1231}
12321232
1233fn zirParamType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1233fn zirParamType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1234 const tracy = trace(@src());1234 const tracy = trace(@src());
1235 defer tracy.end();1235 defer tracy.end();
12361236
...@@ -1266,7 +1266,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr...@@ -1266,7 +1266,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr
1266 return sema.mod.constType(sema.arena, src, param_type);1266 return sema.mod.constType(sema.arena, src, param_type);
1267}1267}
12681268
1269fn zirStr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1269fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1270 const tracy = trace(@src());1270 const tracy = trace(@src());
1271 defer tracy.end();1271 defer tracy.end();
12721272
...@@ -1292,7 +1292,7 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*In...@@ -1292,7 +1292,7 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*In
1292 return sema.analyzeDeclRef(block, .unneeded, new_decl);1292 return sema.analyzeDeclRef(block, .unneeded, new_decl);
1293}1293}
12941294
1295fn zirInt(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1295fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1296 const tracy = trace(@src());1296 const tracy = trace(@src());
1297 defer tracy.end();1297 defer tracy.end();
12981298
...@@ -1300,7 +1300,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*In...@@ -1300,7 +1300,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*In
1300 return sema.mod.constIntUnsigned(sema.arena, .unneeded, Type.initTag(.comptime_int), int);1300 return sema.mod.constIntUnsigned(sema.arena, .unneeded, Type.initTag(.comptime_int), int);
1301}1301}
13021302
1303fn zirFloat(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1303fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1304 const arena = sema.arena;1304 const arena = sema.arena;
1305 const inst_data = sema.code.instructions.items(.data)[inst].float;1305 const inst_data = sema.code.instructions.items(.data)[inst].float;
1306 const src = inst_data.src();1306 const src = inst_data.src();
...@@ -1312,10 +1312,10 @@ fn zirFloat(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*...@@ -1312,10 +1312,10 @@ fn zirFloat(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*
1312 });1312 });
1313}1313}
13141314
1315fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1315fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1316 const arena = sema.arena;1316 const arena = sema.arena;
1317 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1317 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1318 const extra = sema.code.extraData(zir.Inst.Float128, inst_data.payload_index).data;1318 const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;
1319 const src = inst_data.src();1319 const src = inst_data.src();
1320 const number = extra.get();1320 const number = extra.get();
13211321
...@@ -1325,7 +1325,7 @@ fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro...@@ -1325,7 +1325,7 @@ fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro
1325 });1325 });
1326}1326}
13271327
1328fn zirCompileError(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!zir.Inst.Index {1328fn zirCompileError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Zir.Inst.Index {
1329 const tracy = trace(@src());1329 const tracy = trace(@src());
1330 defer tracy.end();1330 defer tracy.end();
13311331
...@@ -1336,13 +1336,13 @@ fn zirCompileError(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inner...@@ -1336,13 +1336,13 @@ fn zirCompileError(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inner
1336 return sema.mod.fail(&block.base, src, "{s}", .{msg});1336 return sema.mod.fail(&block.base, src, "{s}", .{msg});
1337}1337}
13381338
1339fn zirCompileLog(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!void {1339fn zirCompileLog(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
1340 var managed = sema.mod.compile_log_text.toManaged(sema.gpa);1340 var managed = sema.mod.compile_log_text.toManaged(sema.gpa);
1341 defer sema.mod.compile_log_text = managed.moveToUnmanaged();1341 defer sema.mod.compile_log_text = managed.moveToUnmanaged();
1342 const writer = managed.writer();1342 const writer = managed.writer();
13431343
1344 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1344 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1345 const extra = sema.code.extraData(zir.Inst.MultiOp, inst_data.payload_index);1345 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
1346 const args = sema.code.refSlice(extra.end, extra.data.operands_len);1346 const args = sema.code.refSlice(extra.end, extra.data.operands_len);
13471347
1348 for (args) |arg_ref, i| {1348 for (args) |arg_ref, i| {
...@@ -1363,7 +1363,7 @@ fn zirCompileLog(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr...@@ -1363,7 +1363,7 @@ fn zirCompileLog(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr
1363 }1363 }
1364}1364}
13651365
1366fn zirRepeat(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!zir.Inst.Index {1366fn zirRepeat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Zir.Inst.Index {
1367 const tracy = trace(@src());1367 const tracy = trace(@src());
1368 defer tracy.end();1368 defer tracy.end();
13691369
...@@ -1373,13 +1373,13 @@ fn zirRepeat(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!...@@ -1373,13 +1373,13 @@ fn zirRepeat(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!
1373 return always_noreturn;1373 return always_noreturn;
1374}1374}
13751375
1376fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1376fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1377 const tracy = trace(@src());1377 const tracy = trace(@src());
1378 defer tracy.end();1378 defer tracy.end();
13791379
1380 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1380 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1381 const src = inst_data.src();1381 const src = inst_data.src();
1382 const extra = sema.code.extraData(zir.Inst.Block, inst_data.payload_index);1382 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
1383 const body = sema.code.extra[extra.end..][0..extra.data.body_len];1383 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
13841384
1385 // TZIR expects a block outside the loop block too.1385 // TZIR expects a block outside the loop block too.
...@@ -1434,13 +1434,13 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) InnerE...@@ -1434,13 +1434,13 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) InnerE
1434 return sema.analyzeBlockBody(parent_block, src, &child_block, merges);1434 return sema.analyzeBlockBody(parent_block, src, &child_block, merges);
1435}1435}
14361436
1437fn zirBlock(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1437fn zirBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1438 const tracy = trace(@src());1438 const tracy = trace(@src());
1439 defer tracy.end();1439 defer tracy.end();
14401440
1441 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1441 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1442 const src = inst_data.src();1442 const src = inst_data.src();
1443 const extra = sema.code.extraData(zir.Inst.Block, inst_data.payload_index);1443 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
1444 const body = sema.code.extra[extra.end..][0..extra.data.body_len];1444 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
14451445
1446 // Reserve space for a Block instruction so that generated Break instructions can1446 // Reserve space for a Block instruction so that generated Break instructions can
...@@ -1566,12 +1566,12 @@ fn analyzeBlockBody(...@@ -1566,12 +1566,12 @@ fn analyzeBlockBody(
1566 return &merges.block_inst.base;1566 return &merges.block_inst.base;
1567}1567}
15681568
1569fn zirExport(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!void {1569fn zirExport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
1570 const tracy = trace(@src());1570 const tracy = trace(@src());
1571 defer tracy.end();1571 defer tracy.end();
15721572
1573 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1573 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1574 const extra = sema.code.extraData(zir.Inst.Bin, inst_data.payload_index).data;1574 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1575 const src = inst_data.src();1575 const src = inst_data.src();
1576 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };1576 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1577 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };1577 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
...@@ -1588,7 +1588,7 @@ fn zirExport(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!...@@ -1588,7 +1588,7 @@ fn zirExport(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!
1588 try sema.mod.analyzeExport(&block.base, src, export_name, actual_fn.owner_decl);1588 try sema.mod.analyzeExport(&block.base, src, export_name, actual_fn.owner_decl);
1589}1589}
15901590
1591fn zirBreakpoint(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!void {1591fn zirBreakpoint(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
1592 const tracy = trace(@src());1592 const tracy = trace(@src());
1593 defer tracy.end();1593 defer tracy.end();
15941594
...@@ -1598,7 +1598,7 @@ fn zirBreakpoint(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr...@@ -1598,7 +1598,7 @@ fn zirBreakpoint(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr
1598 _ = try block.addNoOp(src, Type.initTag(.void), .breakpoint);1598 _ = try block.addNoOp(src, Type.initTag(.void), .breakpoint);
1599}1599}
16001600
1601fn zirBreak(sema: *Sema, start_block: *Scope.Block, inst: zir.Inst.Index) InnerError!zir.Inst.Index {1601fn zirBreak(sema: *Sema, start_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Zir.Inst.Index {
1602 const tracy = trace(@src());1602 const tracy = trace(@src());
1603 defer tracy.end();1603 defer tracy.end();
16041604
...@@ -1638,7 +1638,7 @@ fn zirBreak(sema: *Sema, start_block: *Scope.Block, inst: zir.Inst.Index) InnerE...@@ -1638,7 +1638,7 @@ fn zirBreak(sema: *Sema, start_block: *Scope.Block, inst: zir.Inst.Index) InnerE
1638 }1638 }
1639}1639}
16401640
1641fn zirDbgStmtNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!void {1641fn zirDbgStmtNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
1642 const tracy = trace(@src());1642 const tracy = trace(@src());
1643 defer tracy.end();1643 defer tracy.end();
16441644
...@@ -1656,21 +1656,21 @@ fn zirDbgStmtNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE...@@ -1656,21 +1656,21 @@ fn zirDbgStmtNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE
1656 _ = try block.addDbgStmt(src, abs_byte_off);1656 _ = try block.addDbgStmt(src, abs_byte_off);
1657}1657}
16581658
1659fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1659fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1660 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1660 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1661 const src = inst_data.src();1661 const src = inst_data.src();
1662 const decl = sema.owner_decl.dependencies.entries.items[inst_data.payload_index].key;1662 const decl = sema.owner_decl.dependencies.entries.items[inst_data.payload_index].key;
1663 return sema.analyzeDeclRef(block, src, decl);1663 return sema.analyzeDeclRef(block, src, decl);
1664}1664}
16651665
1666fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1666fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1667 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1667 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1668 const src = inst_data.src();1668 const src = inst_data.src();
1669 const decl = sema.owner_decl.dependencies.entries.items[inst_data.payload_index].key;1669 const decl = sema.owner_decl.dependencies.entries.items[inst_data.payload_index].key;
1670 return sema.analyzeDeclVal(block, src, decl);1670 return sema.analyzeDeclVal(block, src, decl);
1671}1671}
16721672
1673fn zirDeclRefNamed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1673fn zirDeclRefNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1674 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;1674 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
1675 const src = inst_data.src();1675 const src = inst_data.src();
1676 const decl_name = inst_data.get(sema.code);1676 const decl_name = inst_data.get(sema.code);
...@@ -1678,7 +1678,7 @@ fn zirDeclRefNamed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inner...@@ -1678,7 +1678,7 @@ fn zirDeclRefNamed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inner
1678 return sema.analyzeDeclRef(block, src, decl);1678 return sema.analyzeDeclRef(block, src, decl);
1679}1679}
16801680
1681fn zirDeclValNamed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1681fn zirDeclValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1682 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;1682 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
1683 const src = inst_data.src();1683 const src = inst_data.src();
1684 const decl_name = inst_data.get(sema.code);1684 const decl_name = inst_data.get(sema.code);
...@@ -1701,7 +1701,7 @@ fn lookupIdentifier(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, name: []c...@@ -1701,7 +1701,7 @@ fn lookupIdentifier(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, name: []c
1701fn zirCallNone(1701fn zirCallNone(
1702 sema: *Sema,1702 sema: *Sema,
1703 block: *Scope.Block,1703 block: *Scope.Block,
1704 inst: zir.Inst.Index,1704 inst: Zir.Inst.Index,
1705 ensure_result_used: bool,1705 ensure_result_used: bool,
1706) InnerError!*Inst {1706) InnerError!*Inst {
1707 const tracy = trace(@src());1707 const tracy = trace(@src());
...@@ -1716,7 +1716,7 @@ fn zirCallNone(...@@ -1716,7 +1716,7 @@ fn zirCallNone(
1716fn zirCall(1716fn zirCall(
1717 sema: *Sema,1717 sema: *Sema,
1718 block: *Scope.Block,1718 block: *Scope.Block,
1719 inst: zir.Inst.Index,1719 inst: Zir.Inst.Index,
1720 modifier: std.builtin.CallOptions.Modifier,1720 modifier: std.builtin.CallOptions.Modifier,
1721 ensure_result_used: bool,1721 ensure_result_used: bool,
1722) InnerError!*Inst {1722) InnerError!*Inst {
...@@ -1726,7 +1726,7 @@ fn zirCall(...@@ -1726,7 +1726,7 @@ fn zirCall(
1726 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1726 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1727 const func_src: LazySrcLoc = .{ .node_offset_call_func = inst_data.src_node };1727 const func_src: LazySrcLoc = .{ .node_offset_call_func = inst_data.src_node };
1728 const call_src = inst_data.src();1728 const call_src = inst_data.src();
1729 const extra = sema.code.extraData(zir.Inst.Call, inst_data.payload_index);1729 const extra = sema.code.extraData(Zir.Inst.Call, inst_data.payload_index);
1730 const args = sema.code.refSlice(extra.end, extra.data.args_len);1730 const args = sema.code.refSlice(extra.end, extra.data.args_len);
17311731
1732 return sema.analyzeCall(block, extra.data.callee, func_src, call_src, modifier, ensure_result_used, args);1732 return sema.analyzeCall(block, extra.data.callee, func_src, call_src, modifier, ensure_result_used, args);
...@@ -1735,12 +1735,12 @@ fn zirCall(...@@ -1735,12 +1735,12 @@ fn zirCall(
1735fn analyzeCall(1735fn analyzeCall(
1736 sema: *Sema,1736 sema: *Sema,
1737 block: *Scope.Block,1737 block: *Scope.Block,
1738 zir_func: zir.Inst.Ref,1738 zir_func: Zir.Inst.Ref,
1739 func_src: LazySrcLoc,1739 func_src: LazySrcLoc,
1740 call_src: LazySrcLoc,1740 call_src: LazySrcLoc,
1741 modifier: std.builtin.CallOptions.Modifier,1741 modifier: std.builtin.CallOptions.Modifier,
1742 ensure_result_used: bool,1742 ensure_result_used: bool,
1743 zir_args: []const zir.Inst.Ref,1743 zir_args: []const Zir.Inst.Ref,
1744) InnerError!*ir.Inst {1744) InnerError!*ir.Inst {
1745 const func = try sema.resolveInst(zir_func);1745 const func = try sema.resolveInst(zir_func);
17461746
...@@ -1886,7 +1886,7 @@ fn analyzeCall(...@@ -1886,7 +1886,7 @@ fn analyzeCall(
1886 return result;1886 return result;
1887}1887}
18881888
1889fn zirIntType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1889fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1890 const tracy = trace(@src());1890 const tracy = trace(@src());
1891 defer tracy.end();1891 defer tracy.end();
18921892
...@@ -1897,7 +1897,7 @@ fn zirIntType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError...@@ -1897,7 +1897,7 @@ fn zirIntType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError
1897 return sema.mod.constType(sema.arena, src, ty);1897 return sema.mod.constType(sema.arena, src, ty);
1898}1898}
18991899
1900fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1900fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1901 const tracy = trace(@src());1901 const tracy = trace(@src());
1902 defer tracy.end();1902 defer tracy.end();
19031903
...@@ -1909,7 +1909,7 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inner...@@ -1909,7 +1909,7 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inner
1909 return sema.mod.constType(sema.arena, src, opt_type);1909 return sema.mod.constType(sema.arena, src, opt_type);
1910}1910}
19111911
1912fn zirOptionalTypeFromPtrElem(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1912fn zirOptionalTypeFromPtrElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1913 const tracy = trace(@src());1913 const tracy = trace(@src());
1914 defer tracy.end();1914 defer tracy.end();
19151915
...@@ -1921,7 +1921,7 @@ fn zirOptionalTypeFromPtrElem(sema: *Sema, block: *Scope.Block, inst: zir.Inst.I...@@ -1921,7 +1921,7 @@ fn zirOptionalTypeFromPtrElem(sema: *Sema, block: *Scope.Block, inst: zir.Inst.I
1921 return sema.mod.constType(sema.arena, inst_data.src(), opt_ty);1921 return sema.mod.constType(sema.arena, inst_data.src(), opt_ty);
1922}1922}
19231923
1924fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1924fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1925 const tracy = trace(@src());1925 const tracy = trace(@src());
1926 defer tracy.end();1926 defer tracy.end();
19271927
...@@ -1934,14 +1934,14 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr...@@ -1934,14 +1934,14 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr
1934 return sema.mod.constType(sema.arena, .unneeded, array_ty);1934 return sema.mod.constType(sema.arena, .unneeded, array_ty);
1935}1935}
19361936
1937fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1937fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1938 const tracy = trace(@src());1938 const tracy = trace(@src());
1939 defer tracy.end();1939 defer tracy.end();
19401940
1941 // TODO these should be lazily evaluated1941 // TODO these should be lazily evaluated
1942 const inst_data = sema.code.instructions.items(.data)[inst].array_type_sentinel;1942 const inst_data = sema.code.instructions.items(.data)[inst].array_type_sentinel;
1943 const len = try sema.resolveInstConst(block, .unneeded, inst_data.len);1943 const len = try sema.resolveInstConst(block, .unneeded, inst_data.len);
1944 const extra = sema.code.extraData(zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data;1944 const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data;
1945 const sentinel = try sema.resolveInstConst(block, .unneeded, extra.sentinel);1945 const sentinel = try sema.resolveInstConst(block, .unneeded, extra.sentinel);
1946 const elem_type = try sema.resolveType(block, .unneeded, extra.elem_type);1946 const elem_type = try sema.resolveType(block, .unneeded, extra.elem_type);
1947 const array_ty = try sema.mod.arrayType(sema.arena, len.val.toUnsignedInt(), sentinel.val, elem_type);1947 const array_ty = try sema.mod.arrayType(sema.arena, len.val.toUnsignedInt(), sentinel.val, elem_type);
...@@ -1949,12 +1949,12 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index)...@@ -1949,12 +1949,12 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index)
1949 return sema.mod.constType(sema.arena, .unneeded, array_ty);1949 return sema.mod.constType(sema.arena, .unneeded, array_ty);
1950}1950}
19511951
1952fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1952fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1953 const tracy = trace(@src());1953 const tracy = trace(@src());
1954 defer tracy.end();1954 defer tracy.end();
19551955
1956 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1956 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1957 const extra = sema.code.extraData(zir.Inst.Bin, inst_data.payload_index).data;1957 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1958 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };1958 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
1959 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };1959 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
1960 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };1960 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
...@@ -1970,7 +1970,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inn...@@ -1970,7 +1970,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inn
1970 return sema.mod.constType(sema.arena, src, err_union_ty);1970 return sema.mod.constType(sema.arena, src, err_union_ty);
1971}1971}
19721972
1973fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1973fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1974 const tracy = trace(@src());1974 const tracy = trace(@src());
1975 defer tracy.end();1975 defer tracy.end();
19761976
...@@ -1988,7 +1988,7 @@ fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr...@@ -1988,7 +1988,7 @@ fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr
1988 });1988 });
1989}1989}
19901990
1991fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {1991fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1992 const tracy = trace(@src());1992 const tracy = trace(@src());
1993 defer tracy.end();1993 defer tracy.end();
19941994
...@@ -2014,7 +2014,7 @@ fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr...@@ -2014,7 +2014,7 @@ fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr
2014 return block.addUnOp(src, Type.initTag(.u16), .error_to_int, op_coerced);2014 return block.addUnOp(src, Type.initTag(.u16), .error_to_int, op_coerced);
2015}2015}
20162016
2017fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2017fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2018 const tracy = trace(@src());2018 const tracy = trace(@src());
2019 defer tracy.end();2019 defer tracy.end();
20202020
...@@ -2047,12 +2047,12 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr...@@ -2047,12 +2047,12 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr
2047 return block.addUnOp(src, Type.initTag(.anyerror), .int_to_error, op);2047 return block.addUnOp(src, Type.initTag(.anyerror), .int_to_error, op);
2048}2048}
20492049
2050fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2050fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2051 const tracy = trace(@src());2051 const tracy = trace(@src());
2052 defer tracy.end();2052 defer tracy.end();
20532053
2054 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2054 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2055 const extra = sema.code.extraData(zir.Inst.Bin, inst_data.payload_index).data;2055 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2056 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };2056 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
2057 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };2057 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
2058 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };2058 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
...@@ -2126,7 +2126,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inn...@@ -2126,7 +2126,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inn
2126 });2126 });
2127}2127}
21282128
2129fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2129fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2130 const tracy = trace(@src());2130 const tracy = trace(@src());
2131 defer tracy.end();2131 defer tracy.end();
21322132
...@@ -2139,7 +2139,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE...@@ -2139,7 +2139,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE
2139 });2139 });
2140}2140}
21412141
2142fn zirEnumLiteralSmall(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2142fn zirEnumLiteralSmall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2143 const tracy = trace(@src());2143 const tracy = trace(@src());
2144 defer tracy.end();2144 defer tracy.end();
21452145
...@@ -2152,7 +2152,7 @@ fn zirEnumLiteralSmall(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) I...@@ -2152,7 +2152,7 @@ fn zirEnumLiteralSmall(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) I
2152 });2152 });
2153}2153}
21542154
2155fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2155fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2156 const mod = sema.mod;2156 const mod = sema.mod;
2157 const arena = sema.arena;2157 const arena = sema.arena;
2158 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2158 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
...@@ -2234,12 +2234,12 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr...@@ -2234,12 +2234,12 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr
2234 return block.addUnOp(src, int_tag_ty, .bitcast, enum_tag);2234 return block.addUnOp(src, int_tag_ty, .bitcast, enum_tag);
2235}2235}
22362236
2237fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2237fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2238 const mod = sema.mod;2238 const mod = sema.mod;
2239 const target = mod.getTarget();2239 const target = mod.getTarget();
2240 const arena = sema.arena;2240 const arena = sema.arena;
2241 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2241 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2242 const extra = sema.code.extraData(zir.Inst.Bin, inst_data.payload_index).data;2242 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2243 const src = inst_data.src();2243 const src = inst_data.src();
2244 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };2244 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2245 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };2245 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
...@@ -2293,7 +2293,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr...@@ -2293,7 +2293,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr
2293fn zirOptionalPayloadPtr(2293fn zirOptionalPayloadPtr(
2294 sema: *Sema,2294 sema: *Sema,
2295 block: *Scope.Block,2295 block: *Scope.Block,
2296 inst: zir.Inst.Index,2296 inst: Zir.Inst.Index,
2297 safety_check: bool,2297 safety_check: bool,
2298) InnerError!*Inst {2298) InnerError!*Inst {
2299 const tracy = trace(@src());2299 const tracy = trace(@src());
...@@ -2336,7 +2336,7 @@ fn zirOptionalPayloadPtr(...@@ -2336,7 +2336,7 @@ fn zirOptionalPayloadPtr(
2336fn zirOptionalPayload(2336fn zirOptionalPayload(
2337 sema: *Sema,2337 sema: *Sema,
2338 block: *Scope.Block,2338 block: *Scope.Block,
2339 inst: zir.Inst.Index,2339 inst: Zir.Inst.Index,
2340 safety_check: bool,2340 safety_check: bool,
2341) InnerError!*Inst {2341) InnerError!*Inst {
2342 const tracy = trace(@src());2342 const tracy = trace(@src());
...@@ -2374,7 +2374,7 @@ fn zirOptionalPayload(...@@ -2374,7 +2374,7 @@ fn zirOptionalPayload(
2374fn zirErrUnionPayload(2374fn zirErrUnionPayload(
2375 sema: *Sema,2375 sema: *Sema,
2376 block: *Scope.Block,2376 block: *Scope.Block,
2377 inst: zir.Inst.Index,2377 inst: Zir.Inst.Index,
2378 safety_check: bool,2378 safety_check: bool,
2379) InnerError!*Inst {2379) InnerError!*Inst {
2380 const tracy = trace(@src());2380 const tracy = trace(@src());
...@@ -2408,7 +2408,7 @@ fn zirErrUnionPayload(...@@ -2408,7 +2408,7 @@ fn zirErrUnionPayload(
2408fn zirErrUnionPayloadPtr(2408fn zirErrUnionPayloadPtr(
2409 sema: *Sema,2409 sema: *Sema,
2410 block: *Scope.Block,2410 block: *Scope.Block,
2411 inst: zir.Inst.Index,2411 inst: Zir.Inst.Index,
2412 safety_check: bool,2412 safety_check: bool,
2413) InnerError!*Inst {2413) InnerError!*Inst {
2414 const tracy = trace(@src());2414 const tracy = trace(@src());
...@@ -2449,7 +2449,7 @@ fn zirErrUnionPayloadPtr(...@@ -2449,7 +2449,7 @@ fn zirErrUnionPayloadPtr(
2449}2449}
24502450
2451/// Value in, value out2451/// Value in, value out
2452fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2452fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2453 const tracy = trace(@src());2453 const tracy = trace(@src());
2454 defer tracy.end();2454 defer tracy.end();
24552455
...@@ -2473,7 +2473,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inner...@@ -2473,7 +2473,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inner
2473}2473}
24742474
2475/// Pointer in, value out2475/// Pointer in, value out
2476fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2476fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2477 const tracy = trace(@src());2477 const tracy = trace(@src());
2478 defer tracy.end();2478 defer tracy.end();
24792479
...@@ -2499,7 +2499,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In...@@ -2499,7 +2499,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In
2499 return block.addUnOp(src, operand.ty.castTag(.error_union).?.data.payload, .unwrap_errunion_err_ptr, operand);2499 return block.addUnOp(src, operand.ty.castTag(.error_union).?.data.payload, .unwrap_errunion_err_ptr, operand);
2500}2500}
25012501
2502fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!void {2502fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
2503 const tracy = trace(@src());2503 const tracy = trace(@src());
2504 defer tracy.end();2504 defer tracy.end();
25052505
...@@ -2513,13 +2513,13 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Inde...@@ -2513,13 +2513,13 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Inde
2513 }2513 }
2514}2514}
25152515
2516fn zirFnType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index, var_args: bool) InnerError!*Inst {2516fn zirFnType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, var_args: bool) InnerError!*Inst {
2517 const tracy = trace(@src());2517 const tracy = trace(@src());
2518 defer tracy.end();2518 defer tracy.end();
25192519
2520 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2520 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2521 const src = inst_data.src();2521 const src = inst_data.src();
2522 const extra = sema.code.extraData(zir.Inst.FnType, inst_data.payload_index);2522 const extra = sema.code.extraData(Zir.Inst.FnType, inst_data.payload_index);
2523 const param_types = sema.code.refSlice(extra.end, extra.data.param_types_len);2523 const param_types = sema.code.refSlice(extra.end, extra.data.param_types_len);
25242524
2525 return sema.fnTypeCommon(2525 return sema.fnTypeCommon(
...@@ -2532,14 +2532,14 @@ fn zirFnType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index, var_args: b...@@ -2532,14 +2532,14 @@ fn zirFnType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index, var_args: b
2532 );2532 );
2533}2533}
25342534
2535fn zirFnTypeCc(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index, var_args: bool) InnerError!*Inst {2535fn zirFnTypeCc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, var_args: bool) InnerError!*Inst {
2536 const tracy = trace(@src());2536 const tracy = trace(@src());
2537 defer tracy.end();2537 defer tracy.end();
25382538
2539 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2539 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2540 const src = inst_data.src();2540 const src = inst_data.src();
2541 const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = inst_data.src_node };2541 const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = inst_data.src_node };
2542 const extra = sema.code.extraData(zir.Inst.FnTypeCc, inst_data.payload_index);2542 const extra = sema.code.extraData(Zir.Inst.FnTypeCc, inst_data.payload_index);
2543 const param_types = sema.code.refSlice(extra.end, extra.data.param_types_len);2543 const param_types = sema.code.refSlice(extra.end, extra.data.param_types_len);
25442544
2545 const cc_tv = try sema.resolveInstConst(block, cc_src, extra.data.cc);2545 const cc_tv = try sema.resolveInstConst(block, cc_src, extra.data.cc);
...@@ -2562,8 +2562,8 @@ fn fnTypeCommon(...@@ -2562,8 +2562,8 @@ fn fnTypeCommon(
2562 sema: *Sema,2562 sema: *Sema,
2563 block: *Scope.Block,2563 block: *Scope.Block,
2564 src_node_offset: i32,2564 src_node_offset: i32,
2565 zir_param_types: []const zir.Inst.Ref,2565 zir_param_types: []const Zir.Inst.Ref,
2566 zir_return_type: zir.Inst.Ref,2566 zir_return_type: Zir.Inst.Ref,
2567 cc: std.builtin.CallingConvention,2567 cc: std.builtin.CallingConvention,
2568 var_args: bool,2568 var_args: bool,
2569) InnerError!*Inst {2569) InnerError!*Inst {
...@@ -2608,7 +2608,7 @@ fn fnTypeCommon(...@@ -2608,7 +2608,7 @@ fn fnTypeCommon(
2608 return sema.mod.constType(sema.arena, src, fn_ty);2608 return sema.mod.constType(sema.arena, src, fn_ty);
2609}2609}
26102610
2611fn zirAs(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2611fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2612 const tracy = trace(@src());2612 const tracy = trace(@src());
2613 defer tracy.end();2613 defer tracy.end();
26142614
...@@ -2616,13 +2616,13 @@ fn zirAs(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Ins...@@ -2616,13 +2616,13 @@ fn zirAs(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Ins
2616 return sema.analyzeAs(block, .unneeded, bin_inst.lhs, bin_inst.rhs);2616 return sema.analyzeAs(block, .unneeded, bin_inst.lhs, bin_inst.rhs);
2617}2617}
26182618
2619fn zirAsNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2619fn zirAsNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2620 const tracy = trace(@src());2620 const tracy = trace(@src());
2621 defer tracy.end();2621 defer tracy.end();
26222622
2623 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2623 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2624 const src = inst_data.src();2624 const src = inst_data.src();
2625 const extra = sema.code.extraData(zir.Inst.As, inst_data.payload_index).data;2625 const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data;
2626 return sema.analyzeAs(block, src, extra.dest_type, extra.operand);2626 return sema.analyzeAs(block, src, extra.dest_type, extra.operand);
2627}2627}
26282628
...@@ -2630,15 +2630,15 @@ fn analyzeAs(...@@ -2630,15 +2630,15 @@ fn analyzeAs(
2630 sema: *Sema,2630 sema: *Sema,
2631 block: *Scope.Block,2631 block: *Scope.Block,
2632 src: LazySrcLoc,2632 src: LazySrcLoc,
2633 zir_dest_type: zir.Inst.Ref,2633 zir_dest_type: Zir.Inst.Ref,
2634 zir_operand: zir.Inst.Ref,2634 zir_operand: Zir.Inst.Ref,
2635) InnerError!*Inst {2635) InnerError!*Inst {
2636 const dest_type = try sema.resolveType(block, src, zir_dest_type);2636 const dest_type = try sema.resolveType(block, src, zir_dest_type);
2637 const operand = try sema.resolveInst(zir_operand);2637 const operand = try sema.resolveInst(zir_operand);
2638 return sema.coerce(block, dest_type, operand, src);2638 return sema.coerce(block, dest_type, operand, src);
2639}2639}
26402640
2641fn zirPtrtoint(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2641fn zirPtrtoint(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2642 const tracy = trace(@src());2642 const tracy = trace(@src());
2643 defer tracy.end();2643 defer tracy.end();
26442644
...@@ -2655,14 +2655,14 @@ fn zirPtrtoint(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro...@@ -2655,14 +2655,14 @@ fn zirPtrtoint(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro
2655 return block.addUnOp(src, ty, .ptrtoint, ptr);2655 return block.addUnOp(src, ty, .ptrtoint, ptr);
2656}2656}
26572657
2658fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2658fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2659 const tracy = trace(@src());2659 const tracy = trace(@src());
2660 defer tracy.end();2660 defer tracy.end();
26612661
2662 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2662 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2663 const src = inst_data.src();2663 const src = inst_data.src();
2664 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };2664 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
2665 const extra = sema.code.extraData(zir.Inst.Field, inst_data.payload_index).data;2665 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
2666 const field_name = sema.code.nullTerminatedString(extra.field_name_start);2666 const field_name = sema.code.nullTerminatedString(extra.field_name_start);
2667 const object = try sema.resolveInst(extra.lhs);2667 const object = try sema.resolveInst(extra.lhs);
2668 const object_ptr = if (object.ty.zigTypeTag() == .Pointer)2668 const object_ptr = if (object.ty.zigTypeTag() == .Pointer)
...@@ -2673,27 +2673,27 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro...@@ -2673,27 +2673,27 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro
2673 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);2673 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);
2674}2674}
26752675
2676fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2676fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2677 const tracy = trace(@src());2677 const tracy = trace(@src());
2678 defer tracy.end();2678 defer tracy.end();
26792679
2680 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2680 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2681 const src = inst_data.src();2681 const src = inst_data.src();
2682 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };2682 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
2683 const extra = sema.code.extraData(zir.Inst.Field, inst_data.payload_index).data;2683 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
2684 const field_name = sema.code.nullTerminatedString(extra.field_name_start);2684 const field_name = sema.code.nullTerminatedString(extra.field_name_start);
2685 const object_ptr = try sema.resolveInst(extra.lhs);2685 const object_ptr = try sema.resolveInst(extra.lhs);
2686 return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);2686 return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);
2687}2687}
26882688
2689fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2689fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2690 const tracy = trace(@src());2690 const tracy = trace(@src());
2691 defer tracy.end();2691 defer tracy.end();
26922692
2693 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2693 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2694 const src = inst_data.src();2694 const src = inst_data.src();
2695 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };2695 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
2696 const extra = sema.code.extraData(zir.Inst.FieldNamed, inst_data.payload_index).data;2696 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
2697 const object = try sema.resolveInst(extra.lhs);2697 const object = try sema.resolveInst(extra.lhs);
2698 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);2698 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);
2699 const object_ptr = try sema.analyzeRef(block, src, object);2699 const object_ptr = try sema.analyzeRef(block, src, object);
...@@ -2701,20 +2701,20 @@ fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inne...@@ -2701,20 +2701,20 @@ fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inne
2701 return sema.analyzeLoad(block, src, result_ptr, src);2701 return sema.analyzeLoad(block, src, result_ptr, src);
2702}2702}
27032703
2704fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2704fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2705 const tracy = trace(@src());2705 const tracy = trace(@src());
2706 defer tracy.end();2706 defer tracy.end();
27072707
2708 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2708 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2709 const src = inst_data.src();2709 const src = inst_data.src();
2710 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };2710 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
2711 const extra = sema.code.extraData(zir.Inst.FieldNamed, inst_data.payload_index).data;2711 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
2712 const object_ptr = try sema.resolveInst(extra.lhs);2712 const object_ptr = try sema.resolveInst(extra.lhs);
2713 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);2713 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);
2714 return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);2714 return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);
2715}2715}
27162716
2717fn zirIntcast(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2717fn zirIntcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2718 const tracy = trace(@src());2718 const tracy = trace(@src());
2719 defer tracy.end();2719 defer tracy.end();
27202720
...@@ -2722,7 +2722,7 @@ fn zirIntcast(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError...@@ -2722,7 +2722,7 @@ fn zirIntcast(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError
2722 const src = inst_data.src();2722 const src = inst_data.src();
2723 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };2723 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2724 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };2724 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
2725 const extra = sema.code.extraData(zir.Inst.Bin, inst_data.payload_index).data;2725 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
27262726
2727 const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs);2727 const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs);
2728 const operand = try sema.resolveInst(extra.rhs);2728 const operand = try sema.resolveInst(extra.rhs);
...@@ -2757,7 +2757,7 @@ fn zirIntcast(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError...@@ -2757,7 +2757,7 @@ fn zirIntcast(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError
2757 return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten int", .{});2757 return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten int", .{});
2758}2758}
27592759
2760fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2760fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2761 const tracy = trace(@src());2761 const tracy = trace(@src());
2762 defer tracy.end();2762 defer tracy.end();
27632763
...@@ -2765,14 +2765,14 @@ fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError...@@ -2765,14 +2765,14 @@ fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError
2765 const src = inst_data.src();2765 const src = inst_data.src();
2766 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };2766 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2767 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };2767 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
2768 const extra = sema.code.extraData(zir.Inst.Bin, inst_data.payload_index).data;2768 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
27692769
2770 const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs);2770 const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs);
2771 const operand = try sema.resolveInst(extra.rhs);2771 const operand = try sema.resolveInst(extra.rhs);
2772 return sema.bitcast(block, dest_type, operand);2772 return sema.bitcast(block, dest_type, operand);
2773}2773}
27742774
2775fn zirFloatcast(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2775fn zirFloatcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2776 const tracy = trace(@src());2776 const tracy = trace(@src());
2777 defer tracy.end();2777 defer tracy.end();
27782778
...@@ -2780,7 +2780,7 @@ fn zirFloatcast(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr...@@ -2780,7 +2780,7 @@ fn zirFloatcast(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr
2780 const src = inst_data.src();2780 const src = inst_data.src();
2781 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };2781 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2782 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };2782 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
2783 const extra = sema.code.extraData(zir.Inst.Bin, inst_data.payload_index).data;2783 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
27842784
2785 const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs);2785 const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs);
2786 const operand = try sema.resolveInst(extra.rhs);2786 const operand = try sema.resolveInst(extra.rhs);
...@@ -2815,7 +2815,7 @@ fn zirFloatcast(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr...@@ -2815,7 +2815,7 @@ fn zirFloatcast(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr
2815 return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten float", .{});2815 return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten float", .{});
2816}2816}
28172817
2818fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2818fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2819 const tracy = trace(@src());2819 const tracy = trace(@src());
2820 defer tracy.end();2820 defer tracy.end();
28212821
...@@ -2830,14 +2830,14 @@ fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError...@@ -2830,14 +2830,14 @@ fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError
2830 return sema.analyzeLoad(block, sema.src, result_ptr, sema.src);2830 return sema.analyzeLoad(block, sema.src, result_ptr, sema.src);
2831}2831}
28322832
2833fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2833fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2834 const tracy = trace(@src());2834 const tracy = trace(@src());
2835 defer tracy.end();2835 defer tracy.end();
28362836
2837 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2837 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2838 const src = inst_data.src();2838 const src = inst_data.src();
2839 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };2839 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
2840 const extra = sema.code.extraData(zir.Inst.Bin, inst_data.payload_index).data;2840 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2841 const array = try sema.resolveInst(extra.lhs);2841 const array = try sema.resolveInst(extra.lhs);
2842 const array_ptr = if (array.ty.zigTypeTag() == .Pointer)2842 const array_ptr = if (array.ty.zigTypeTag() == .Pointer)
2843 array2843 array
...@@ -2848,7 +2848,7 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE...@@ -2848,7 +2848,7 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE
2848 return sema.analyzeLoad(block, src, result_ptr, src);2848 return sema.analyzeLoad(block, src, result_ptr, src);
2849}2849}
28502850
2851fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2851fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2852 const tracy = trace(@src());2852 const tracy = trace(@src());
2853 defer tracy.end();2853 defer tracy.end();
28542854
...@@ -2858,39 +2858,39 @@ fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError...@@ -2858,39 +2858,39 @@ fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError
2858 return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);2858 return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);
2859}2859}
28602860
2861fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2861fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2862 const tracy = trace(@src());2862 const tracy = trace(@src());
2863 defer tracy.end();2863 defer tracy.end();
28642864
2865 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2865 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2866 const src = inst_data.src();2866 const src = inst_data.src();
2867 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };2867 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
2868 const extra = sema.code.extraData(zir.Inst.Bin, inst_data.payload_index).data;2868 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2869 const array_ptr = try sema.resolveInst(extra.lhs);2869 const array_ptr = try sema.resolveInst(extra.lhs);
2870 const elem_index = try sema.resolveInst(extra.rhs);2870 const elem_index = try sema.resolveInst(extra.rhs);
2871 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);2871 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);
2872}2872}
28732873
2874fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2874fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2875 const tracy = trace(@src());2875 const tracy = trace(@src());
2876 defer tracy.end();2876 defer tracy.end();
28772877
2878 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2878 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2879 const src = inst_data.src();2879 const src = inst_data.src();
2880 const extra = sema.code.extraData(zir.Inst.SliceStart, inst_data.payload_index).data;2880 const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;
2881 const array_ptr = try sema.resolveInst(extra.lhs);2881 const array_ptr = try sema.resolveInst(extra.lhs);
2882 const start = try sema.resolveInst(extra.start);2882 const start = try sema.resolveInst(extra.start);
28832883
2884 return sema.analyzeSlice(block, src, array_ptr, start, null, null, .unneeded);2884 return sema.analyzeSlice(block, src, array_ptr, start, null, null, .unneeded);
2885}2885}
28862886
2887fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2887fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2888 const tracy = trace(@src());2888 const tracy = trace(@src());
2889 defer tracy.end();2889 defer tracy.end();
28902890
2891 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2891 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2892 const src = inst_data.src();2892 const src = inst_data.src();
2893 const extra = sema.code.extraData(zir.Inst.SliceEnd, inst_data.payload_index).data;2893 const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;
2894 const array_ptr = try sema.resolveInst(extra.lhs);2894 const array_ptr = try sema.resolveInst(extra.lhs);
2895 const start = try sema.resolveInst(extra.start);2895 const start = try sema.resolveInst(extra.start);
2896 const end = try sema.resolveInst(extra.end);2896 const end = try sema.resolveInst(extra.end);
...@@ -2898,14 +2898,14 @@ fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro...@@ -2898,14 +2898,14 @@ fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro
2898 return sema.analyzeSlice(block, src, array_ptr, start, end, null, .unneeded);2898 return sema.analyzeSlice(block, src, array_ptr, start, end, null, .unneeded);
2899}2899}
29002900
2901fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {2901fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2902 const tracy = trace(@src());2902 const tracy = trace(@src());
2903 defer tracy.end();2903 defer tracy.end();
29042904
2905 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2905 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2906 const src = inst_data.src();2906 const src = inst_data.src();
2907 const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node };2907 const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node };
2908 const extra = sema.code.extraData(zir.Inst.SliceSentinel, inst_data.payload_index).data;2908 const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;
2909 const array_ptr = try sema.resolveInst(extra.lhs);2909 const array_ptr = try sema.resolveInst(extra.lhs);
2910 const start = try sema.resolveInst(extra.start);2910 const start = try sema.resolveInst(extra.start);
2911 const end = try sema.resolveInst(extra.end);2911 const end = try sema.resolveInst(extra.end);
...@@ -2917,7 +2917,7 @@ fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inne...@@ -2917,7 +2917,7 @@ fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inne
2917fn zirSwitchCapture(2917fn zirSwitchCapture(
2918 sema: *Sema,2918 sema: *Sema,
2919 block: *Scope.Block,2919 block: *Scope.Block,
2920 inst: zir.Inst.Index,2920 inst: Zir.Inst.Index,
2921 is_multi: bool,2921 is_multi: bool,
2922 is_ref: bool,2922 is_ref: bool,
2923) InnerError!*Inst {2923) InnerError!*Inst {
...@@ -2935,7 +2935,7 @@ fn zirSwitchCapture(...@@ -2935,7 +2935,7 @@ fn zirSwitchCapture(
2935fn zirSwitchCaptureElse(2935fn zirSwitchCaptureElse(
2936 sema: *Sema,2936 sema: *Sema,
2937 block: *Scope.Block,2937 block: *Scope.Block,
2938 inst: zir.Inst.Index,2938 inst: Zir.Inst.Index,
2939 is_ref: bool,2939 is_ref: bool,
2940) InnerError!*Inst {2940) InnerError!*Inst {
2941 const tracy = trace(@src());2941 const tracy = trace(@src());
...@@ -2952,9 +2952,9 @@ fn zirSwitchCaptureElse(...@@ -2952,9 +2952,9 @@ fn zirSwitchCaptureElse(
2952fn zirSwitchBlock(2952fn zirSwitchBlock(
2953 sema: *Sema,2953 sema: *Sema,
2954 block: *Scope.Block,2954 block: *Scope.Block,
2955 inst: zir.Inst.Index,2955 inst: Zir.Inst.Index,
2956 is_ref: bool,2956 is_ref: bool,
2957 special_prong: zir.SpecialProng,2957 special_prong: Zir.SpecialProng,
2958) InnerError!*Inst {2958) InnerError!*Inst {
2959 const tracy = trace(@src());2959 const tracy = trace(@src());
2960 defer tracy.end();2960 defer tracy.end();
...@@ -2962,7 +2962,7 @@ fn zirSwitchBlock(...@@ -2962,7 +2962,7 @@ fn zirSwitchBlock(
2962 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2962 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2963 const src = inst_data.src();2963 const src = inst_data.src();
2964 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = inst_data.src_node };2964 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = inst_data.src_node };
2965 const extra = sema.code.extraData(zir.Inst.SwitchBlock, inst_data.payload_index);2965 const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);
29662966
2967 const operand_ptr = try sema.resolveInst(extra.data.operand);2967 const operand_ptr = try sema.resolveInst(extra.data.operand);
2968 const operand = if (is_ref)2968 const operand = if (is_ref)
...@@ -2985,9 +2985,9 @@ fn zirSwitchBlock(...@@ -2985,9 +2985,9 @@ fn zirSwitchBlock(
2985fn zirSwitchBlockMulti(2985fn zirSwitchBlockMulti(
2986 sema: *Sema,2986 sema: *Sema,
2987 block: *Scope.Block,2987 block: *Scope.Block,
2988 inst: zir.Inst.Index,2988 inst: Zir.Inst.Index,
2989 is_ref: bool,2989 is_ref: bool,
2990 special_prong: zir.SpecialProng,2990 special_prong: Zir.SpecialProng,
2991) InnerError!*Inst {2991) InnerError!*Inst {
2992 const tracy = trace(@src());2992 const tracy = trace(@src());
2993 defer tracy.end();2993 defer tracy.end();
...@@ -2995,7 +2995,7 @@ fn zirSwitchBlockMulti(...@@ -2995,7 +2995,7 @@ fn zirSwitchBlockMulti(
2995 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2995 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2996 const src = inst_data.src();2996 const src = inst_data.src();
2997 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = inst_data.src_node };2997 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = inst_data.src_node };
2998 const extra = sema.code.extraData(zir.Inst.SwitchBlockMulti, inst_data.payload_index);2998 const extra = sema.code.extraData(Zir.Inst.SwitchBlockMulti, inst_data.payload_index);
29992999
3000 const operand_ptr = try sema.resolveInst(extra.data.operand);3000 const operand_ptr = try sema.resolveInst(extra.data.operand);
3001 const operand = if (is_ref)3001 const operand = if (is_ref)
...@@ -3020,16 +3020,16 @@ fn analyzeSwitch(...@@ -3020,16 +3020,16 @@ fn analyzeSwitch(
3020 block: *Scope.Block,3020 block: *Scope.Block,
3021 operand: *Inst,3021 operand: *Inst,
3022 extra_end: usize,3022 extra_end: usize,
3023 special_prong: zir.SpecialProng,3023 special_prong: Zir.SpecialProng,
3024 scalar_cases_len: usize,3024 scalar_cases_len: usize,
3025 multi_cases_len: usize,3025 multi_cases_len: usize,
3026 switch_inst: zir.Inst.Index,3026 switch_inst: Zir.Inst.Index,
3027 src_node_offset: i32,3027 src_node_offset: i32,
3028) InnerError!*Inst {3028) InnerError!*Inst {
3029 const gpa = sema.gpa;3029 const gpa = sema.gpa;
3030 const mod = sema.mod;3030 const mod = sema.mod;
30313031
3032 const special: struct { body: []const zir.Inst.Index, end: usize } = switch (special_prong) {3032 const special: struct { body: []const Zir.Inst.Index, end: usize } = switch (special_prong) {
3033 .none => .{ .body = &.{}, .end = extra_end },3033 .none => .{ .body = &.{}, .end = extra_end },
3034 .under, .@"else" => blk: {3034 .under, .@"else" => blk: {
3035 const body_len = sema.code.extra[extra_end];3035 const body_len = sema.code.extra[extra_end];
...@@ -3079,7 +3079,7 @@ fn analyzeSwitch(...@@ -3079,7 +3079,7 @@ fn analyzeSwitch(
3079 {3079 {
3080 var scalar_i: u32 = 0;3080 var scalar_i: u32 = 0;
3081 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {3081 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
3082 const item_ref = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_index]);3082 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
3083 extra_index += 1;3083 extra_index += 1;
3084 const body_len = sema.code.extra[extra_index];3084 const body_len = sema.code.extra[extra_index];
3085 extra_index += 1;3085 extra_index += 1;
...@@ -3189,7 +3189,7 @@ fn analyzeSwitch(...@@ -3189,7 +3189,7 @@ fn analyzeSwitch(
3189 {3189 {
3190 var scalar_i: u32 = 0;3190 var scalar_i: u32 = 0;
3191 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {3191 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
3192 const item_ref = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_index]);3192 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
3193 extra_index += 1;3193 extra_index += 1;
3194 const body_len = sema.code.extra[extra_index];3194 const body_len = sema.code.extra[extra_index];
3195 extra_index += 1;3195 extra_index += 1;
...@@ -3229,9 +3229,9 @@ fn analyzeSwitch(...@@ -3229,9 +3229,9 @@ fn analyzeSwitch(
32293229
3230 var range_i: u32 = 0;3230 var range_i: u32 = 0;
3231 while (range_i < ranges_len) : (range_i += 1) {3231 while (range_i < ranges_len) : (range_i += 1) {
3232 const item_first = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_index]);3232 const item_first = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
3233 extra_index += 1;3233 extra_index += 1;
3234 const item_last = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_index]);3234 const item_last = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
3235 extra_index += 1;3235 extra_index += 1;
32363236
3237 try sema.validateSwitchRange(3237 try sema.validateSwitchRange(
...@@ -3285,7 +3285,7 @@ fn analyzeSwitch(...@@ -3285,7 +3285,7 @@ fn analyzeSwitch(
3285 {3285 {
3286 var scalar_i: u32 = 0;3286 var scalar_i: u32 = 0;
3287 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {3287 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
3288 const item_ref = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_index]);3288 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
3289 extra_index += 1;3289 extra_index += 1;
3290 const body_len = sema.code.extra[extra_index];3290 const body_len = sema.code.extra[extra_index];
3291 extra_index += 1;3291 extra_index += 1;
...@@ -3368,7 +3368,7 @@ fn analyzeSwitch(...@@ -3368,7 +3368,7 @@ fn analyzeSwitch(
3368 {3368 {
3369 var scalar_i: u32 = 0;3369 var scalar_i: u32 = 0;
3370 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {3370 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
3371 const item_ref = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_index]);3371 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
3372 extra_index += 1;3372 extra_index += 1;
3373 const body_len = sema.code.extra[extra_index];3373 const body_len = sema.code.extra[extra_index];
3374 extra_index += 1;3374 extra_index += 1;
...@@ -3435,7 +3435,7 @@ fn analyzeSwitch(...@@ -3435,7 +3435,7 @@ fn analyzeSwitch(
3435 {3435 {
3436 var scalar_i: usize = 0;3436 var scalar_i: usize = 0;
3437 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {3437 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
3438 const item_ref = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_index]);3438 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
3439 extra_index += 1;3439 extra_index += 1;
3440 const body_len = sema.code.extra[extra_index];3440 const body_len = sema.code.extra[extra_index];
3441 extra_index += 1;3441 extra_index += 1;
...@@ -3474,9 +3474,9 @@ fn analyzeSwitch(...@@ -3474,9 +3474,9 @@ fn analyzeSwitch(
34743474
3475 var range_i: usize = 0;3475 var range_i: usize = 0;
3476 while (range_i < ranges_len) : (range_i += 1) {3476 while (range_i < ranges_len) : (range_i += 1) {
3477 const item_first = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_index]);3477 const item_first = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
3478 extra_index += 1;3478 extra_index += 1;
3479 const item_last = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_index]);3479 const item_last = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
3480 extra_index += 1;3480 extra_index += 1;
34813481
3482 // Validation above ensured these will succeed.3482 // Validation above ensured these will succeed.
...@@ -3544,7 +3544,7 @@ fn analyzeSwitch(...@@ -3544,7 +3544,7 @@ fn analyzeSwitch(
35443544
3545 var scalar_i: usize = 0;3545 var scalar_i: usize = 0;
3546 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {3546 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
3547 const item_ref = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_index]);3547 const item_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
3548 extra_index += 1;3548 extra_index += 1;
3549 const body_len = sema.code.extra[extra_index];3549 const body_len = sema.code.extra[extra_index];
3550 extra_index += 1;3550 extra_index += 1;
...@@ -3597,9 +3597,9 @@ fn analyzeSwitch(...@@ -3597,9 +3597,9 @@ fn analyzeSwitch(
35973597
3598 var range_i: usize = 0;3598 var range_i: usize = 0;
3599 while (range_i < ranges_len) : (range_i += 1) {3599 while (range_i < ranges_len) : (range_i += 1) {
3600 const first_ref = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_index]);3600 const first_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
3601 extra_index += 1;3601 extra_index += 1;
3602 const last_ref = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_index]);3602 const last_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
3603 extra_index += 1;3603 extra_index += 1;
36043604
3605 const item_first = try sema.resolveInst(first_ref);3605 const item_first = try sema.resolveInst(first_ref);
...@@ -3696,7 +3696,7 @@ fn analyzeSwitch(...@@ -3696,7 +3696,7 @@ fn analyzeSwitch(
3696fn resolveSwitchItemVal(3696fn resolveSwitchItemVal(
3697 sema: *Sema,3697 sema: *Sema,
3698 block: *Scope.Block,3698 block: *Scope.Block,
3699 item_ref: zir.Inst.Ref,3699 item_ref: Zir.Inst.Ref,
3700 switch_node_offset: i32,3700 switch_node_offset: i32,
3701 switch_prong_src: AstGen.SwitchProngSrc,3701 switch_prong_src: AstGen.SwitchProngSrc,
3702 range_expand: AstGen.SwitchProngSrc.RangeExpand,3702 range_expand: AstGen.SwitchProngSrc.RangeExpand,
...@@ -3720,8 +3720,8 @@ fn validateSwitchRange(...@@ -3720,8 +3720,8 @@ fn validateSwitchRange(
3720 sema: *Sema,3720 sema: *Sema,
3721 block: *Scope.Block,3721 block: *Scope.Block,
3722 range_set: *RangeSet,3722 range_set: *RangeSet,
3723 first_ref: zir.Inst.Ref,3723 first_ref: Zir.Inst.Ref,
3724 last_ref: zir.Inst.Ref,3724 last_ref: Zir.Inst.Ref,
3725 src_node_offset: i32,3725 src_node_offset: i32,
3726 switch_prong_src: AstGen.SwitchProngSrc,3726 switch_prong_src: AstGen.SwitchProngSrc,
3727) InnerError!void {3727) InnerError!void {
...@@ -3735,7 +3735,7 @@ fn validateSwitchItem(...@@ -3735,7 +3735,7 @@ fn validateSwitchItem(
3735 sema: *Sema,3735 sema: *Sema,
3736 block: *Scope.Block,3736 block: *Scope.Block,
3737 range_set: *RangeSet,3737 range_set: *RangeSet,
3738 item_ref: zir.Inst.Ref,3738 item_ref: Zir.Inst.Ref,
3739 src_node_offset: i32,3739 src_node_offset: i32,
3740 switch_prong_src: AstGen.SwitchProngSrc,3740 switch_prong_src: AstGen.SwitchProngSrc,
3741) InnerError!void {3741) InnerError!void {
...@@ -3748,7 +3748,7 @@ fn validateSwitchItemEnum(...@@ -3748,7 +3748,7 @@ fn validateSwitchItemEnum(
3748 sema: *Sema,3748 sema: *Sema,
3749 block: *Scope.Block,3749 block: *Scope.Block,
3750 seen_fields: []?AstGen.SwitchProngSrc,3750 seen_fields: []?AstGen.SwitchProngSrc,
3751 item_ref: zir.Inst.Ref,3751 item_ref: Zir.Inst.Ref,
3752 src_node_offset: i32,3752 src_node_offset: i32,
3753 switch_prong_src: AstGen.SwitchProngSrc,3753 switch_prong_src: AstGen.SwitchProngSrc,
3754) InnerError!void {3754) InnerError!void {
...@@ -3815,7 +3815,7 @@ fn validateSwitchItemBool(...@@ -3815,7 +3815,7 @@ fn validateSwitchItemBool(
3815 block: *Scope.Block,3815 block: *Scope.Block,
3816 true_count: *u8,3816 true_count: *u8,
3817 false_count: *u8,3817 false_count: *u8,
3818 item_ref: zir.Inst.Ref,3818 item_ref: Zir.Inst.Ref,
3819 src_node_offset: i32,3819 src_node_offset: i32,
3820 switch_prong_src: AstGen.SwitchProngSrc,3820 switch_prong_src: AstGen.SwitchProngSrc,
3821) InnerError!void {3821) InnerError!void {
...@@ -3837,7 +3837,7 @@ fn validateSwitchItemSparse(...@@ -3837,7 +3837,7 @@ fn validateSwitchItemSparse(
3837 sema: *Sema,3837 sema: *Sema,
3838 block: *Scope.Block,3838 block: *Scope.Block,
3839 seen_values: *ValueSrcMap,3839 seen_values: *ValueSrcMap,
3840 item_ref: zir.Inst.Ref,3840 item_ref: Zir.Inst.Ref,
3841 src_node_offset: i32,3841 src_node_offset: i32,
3842 switch_prong_src: AstGen.SwitchProngSrc,3842 switch_prong_src: AstGen.SwitchProngSrc,
3843) InnerError!void {3843) InnerError!void {
...@@ -3879,12 +3879,12 @@ fn validateSwitchNoRange(...@@ -3879,12 +3879,12 @@ fn validateSwitchNoRange(
3879 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);3879 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);
3880}3880}
38813881
3882fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {3882fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3883 const tracy = trace(@src());3883 const tracy = trace(@src());
3884 defer tracy.end();3884 defer tracy.end();
38853885
3886 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;3886 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
3887 const extra = sema.code.extraData(zir.Inst.Bin, inst_data.payload_index).data;3887 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
3888 const src = inst_data.src();3888 const src = inst_data.src();
3889 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };3889 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
3890 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };3890 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
...@@ -3907,7 +3907,7 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError...@@ -3907,7 +3907,7 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError
3907 return mod.constBool(arena, src, false);3907 return mod.constBool(arena, src, false);
3908}3908}
39093909
3910fn zirImport(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {3910fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3911 const tracy = trace(@src());3911 const tracy = trace(@src());
3912 defer tracy.end();3912 defer tracy.end();
39133913
...@@ -3933,13 +3933,13 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!...@@ -3933,13 +3933,13 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!
3933 return mod.constType(sema.arena, src, file.namespace.ty);3933 return mod.constType(sema.arena, src, file.namespace.ty);
3934}3934}
39353935
3936fn zirShl(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {3936fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3937 const tracy = trace(@src());3937 const tracy = trace(@src());
3938 defer tracy.end();3938 defer tracy.end();
3939 return sema.mod.fail(&block.base, sema.src, "TODO implement zirShl", .{});3939 return sema.mod.fail(&block.base, sema.src, "TODO implement zirShl", .{});
3940}3940}
39413941
3942fn zirShr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {3942fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3943 const tracy = trace(@src());3943 const tracy = trace(@src());
3944 defer tracy.end();3944 defer tracy.end();
3945 return sema.mod.fail(&block.base, sema.src, "TODO implement zirShr", .{});3945 return sema.mod.fail(&block.base, sema.src, "TODO implement zirShr", .{});
...@@ -3948,7 +3948,7 @@ fn zirShr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*In...@@ -3948,7 +3948,7 @@ fn zirShr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*In
3948fn zirBitwise(3948fn zirBitwise(
3949 sema: *Sema,3949 sema: *Sema,
3950 block: *Scope.Block,3950 block: *Scope.Block,
3951 inst: zir.Inst.Index,3951 inst: Zir.Inst.Index,
3952 ir_tag: ir.Inst.Tag,3952 ir_tag: ir.Inst.Tag,
3953) InnerError!*Inst {3953) InnerError!*Inst {
3954 const tracy = trace(@src());3954 const tracy = trace(@src());
...@@ -3958,7 +3958,7 @@ fn zirBitwise(...@@ -3958,7 +3958,7 @@ fn zirBitwise(
3958 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };3958 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
3959 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };3959 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
3960 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };3960 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
3961 const extra = sema.code.extraData(zir.Inst.Bin, inst_data.payload_index).data;3961 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
3962 const lhs = try sema.resolveInst(extra.lhs);3962 const lhs = try sema.resolveInst(extra.lhs);
3963 const rhs = try sema.resolveInst(extra.rhs);3963 const rhs = try sema.resolveInst(extra.rhs);
39643964
...@@ -4011,19 +4011,19 @@ fn zirBitwise(...@@ -4011,19 +4011,19 @@ fn zirBitwise(
4011 return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs);4011 return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs);
4012}4012}
40134013
4014fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4014fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4015 const tracy = trace(@src());4015 const tracy = trace(@src());
4016 defer tracy.end();4016 defer tracy.end();
4017 return sema.mod.fail(&block.base, sema.src, "TODO implement zirBitNot", .{});4017 return sema.mod.fail(&block.base, sema.src, "TODO implement zirBitNot", .{});
4018}4018}
40194019
4020fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4020fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4021 const tracy = trace(@src());4021 const tracy = trace(@src());
4022 defer tracy.end();4022 defer tracy.end();
4023 return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayCat", .{});4023 return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayCat", .{});
4024}4024}
40254025
4026fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4026fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4027 const tracy = trace(@src());4027 const tracy = trace(@src());
4028 defer tracy.end();4028 defer tracy.end();
4029 return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayMul", .{});4029 return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayMul", .{});
...@@ -4032,8 +4032,8 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro...@@ -4032,8 +4032,8 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro
4032fn zirNegate(4032fn zirNegate(
4033 sema: *Sema,4033 sema: *Sema,
4034 block: *Scope.Block,4034 block: *Scope.Block,
4035 inst: zir.Inst.Index,4035 inst: Zir.Inst.Index,
4036 tag_override: zir.Inst.Tag,4036 tag_override: Zir.Inst.Tag,
4037) InnerError!*Inst {4037) InnerError!*Inst {
4038 const tracy = trace(@src());4038 const tracy = trace(@src());
4039 defer tracy.end();4039 defer tracy.end();
...@@ -4048,7 +4048,7 @@ fn zirNegate(...@@ -4048,7 +4048,7 @@ fn zirNegate(
4048 return sema.analyzeArithmetic(block, tag_override, lhs, rhs, src, lhs_src, rhs_src);4048 return sema.analyzeArithmetic(block, tag_override, lhs, rhs, src, lhs_src, rhs_src);
4049}4049}
40504050
4051fn zirArithmetic(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4051fn zirArithmetic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4052 const tracy = trace(@src());4052 const tracy = trace(@src());
4053 defer tracy.end();4053 defer tracy.end();
40544054
...@@ -4057,7 +4057,7 @@ fn zirArithmetic(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr...@@ -4057,7 +4057,7 @@ fn zirArithmetic(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr
4057 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };4057 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
4058 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };4058 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
4059 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };4059 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
4060 const extra = sema.code.extraData(zir.Inst.Bin, inst_data.payload_index).data;4060 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
4061 const lhs = try sema.resolveInst(extra.lhs);4061 const lhs = try sema.resolveInst(extra.lhs);
4062 const rhs = try sema.resolveInst(extra.rhs);4062 const rhs = try sema.resolveInst(extra.rhs);
40634063
...@@ -4067,7 +4067,7 @@ fn zirArithmetic(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr...@@ -4067,7 +4067,7 @@ fn zirArithmetic(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr
4067fn analyzeArithmetic(4067fn analyzeArithmetic(
4068 sema: *Sema,4068 sema: *Sema,
4069 block: *Scope.Block,4069 block: *Scope.Block,
4070 zir_tag: zir.Inst.Tag,4070 zir_tag: Zir.Inst.Tag,
4071 lhs: *Inst,4071 lhs: *Inst,
4072 rhs: *Inst,4072 rhs: *Inst,
4073 src: LazySrcLoc,4073 src: LazySrcLoc,
...@@ -4174,7 +4174,7 @@ fn analyzeArithmetic(...@@ -4174,7 +4174,7 @@ fn analyzeArithmetic(
4174 return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs);4174 return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs);
4175}4175}
41764176
4177fn zirLoad(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4177fn zirLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4178 const tracy = trace(@src());4178 const tracy = trace(@src());
4179 defer tracy.end();4179 defer tracy.end();
41804180
...@@ -4188,7 +4188,7 @@ fn zirLoad(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*I...@@ -4188,7 +4188,7 @@ fn zirLoad(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*I
4188fn zirAsm(4188fn zirAsm(
4189 sema: *Sema,4189 sema: *Sema,
4190 block: *Scope.Block,4190 block: *Scope.Block,
4191 inst: zir.Inst.Index,4191 inst: Zir.Inst.Index,
4192 is_volatile: bool,4192 is_volatile: bool,
4193) InnerError!*Inst {4193) InnerError!*Inst {
4194 const tracy = trace(@src());4194 const tracy = trace(@src());
...@@ -4198,7 +4198,7 @@ fn zirAsm(...@@ -4198,7 +4198,7 @@ fn zirAsm(
4198 const src = inst_data.src();4198 const src = inst_data.src();
4199 const asm_source_src: LazySrcLoc = .{ .node_offset_asm_source = inst_data.src_node };4199 const asm_source_src: LazySrcLoc = .{ .node_offset_asm_source = inst_data.src_node };
4200 const ret_ty_src: LazySrcLoc = .{ .node_offset_asm_ret_ty = inst_data.src_node };4200 const ret_ty_src: LazySrcLoc = .{ .node_offset_asm_ret_ty = inst_data.src_node };
4201 const extra = sema.code.extraData(zir.Inst.Asm, inst_data.payload_index);4201 const extra = sema.code.extraData(Zir.Inst.Asm, inst_data.payload_index);
4202 const return_type = try sema.resolveType(block, ret_ty_src, extra.data.return_type);4202 const return_type = try sema.resolveType(block, ret_ty_src, extra.data.return_type);
4203 const asm_source = try sema.resolveConstString(block, asm_source_src, extra.data.asm_source);4203 const asm_source = try sema.resolveConstString(block, asm_source_src, extra.data.asm_source);
42044204
...@@ -4218,7 +4218,7 @@ fn zirAsm(...@@ -4218,7 +4218,7 @@ fn zirAsm(
4218 const clobbers = try sema.arena.alloc([]const u8, extra.data.clobbers_len);4218 const clobbers = try sema.arena.alloc([]const u8, extra.data.clobbers_len);
42194219
4220 for (args) |*arg| {4220 for (args) |*arg| {
4221 arg.* = try sema.resolveInst(@intToEnum(zir.Inst.Ref, sema.code.extra[extra_i]));4221 arg.* = try sema.resolveInst(@intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]));
4222 extra_i += 1;4222 extra_i += 1;
4223 }4223 }
4224 for (inputs) |*name| {4224 for (inputs) |*name| {
...@@ -4253,7 +4253,7 @@ fn zirAsm(...@@ -4253,7 +4253,7 @@ fn zirAsm(
4253fn zirCmp(4253fn zirCmp(
4254 sema: *Sema,4254 sema: *Sema,
4255 block: *Scope.Block,4255 block: *Scope.Block,
4256 inst: zir.Inst.Index,4256 inst: Zir.Inst.Index,
4257 op: std.math.CompareOperator,4257 op: std.math.CompareOperator,
4258) InnerError!*Inst {4258) InnerError!*Inst {
4259 const tracy = trace(@src());4259 const tracy = trace(@src());
...@@ -4262,7 +4262,7 @@ fn zirCmp(...@@ -4262,7 +4262,7 @@ fn zirCmp(
4262 const mod = sema.mod;4262 const mod = sema.mod;
42634263
4264 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;4264 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
4265 const extra = sema.code.extraData(zir.Inst.Bin, inst_data.payload_index).data;4265 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
4266 const src: LazySrcLoc = inst_data.src();4266 const src: LazySrcLoc = inst_data.src();
4267 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };4267 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
4268 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };4268 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
...@@ -4356,7 +4356,7 @@ fn zirCmp(...@@ -4356,7 +4356,7 @@ fn zirCmp(
4356 return block.addBinOp(src, bool_type, tag, casted_lhs, casted_rhs);4356 return block.addBinOp(src, bool_type, tag, casted_lhs, casted_rhs);
4357}4357}
43584358
4359fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4359fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4360 const inst_data = sema.code.instructions.items(.data)[inst].un_node;4360 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
4361 const src = inst_data.src();4361 const src = inst_data.src();
4362 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };4362 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
...@@ -4366,7 +4366,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!...@@ -4366,7 +4366,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!
4366 return sema.mod.constIntUnsigned(sema.arena, src, Type.initTag(.comptime_int), abi_size);4366 return sema.mod.constIntUnsigned(sema.arena, src, Type.initTag(.comptime_int), abi_size);
4367}4367}
43684368
4369fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4369fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4370 const inst_data = sema.code.instructions.items(.data)[inst].un_node;4370 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
4371 const src = inst_data.src();4371 const src = inst_data.src();
4372 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };4372 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
...@@ -4376,20 +4376,20 @@ fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr...@@ -4376,20 +4376,20 @@ fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr
4376 return sema.mod.constIntUnsigned(sema.arena, src, Type.initTag(.comptime_int), bit_size);4376 return sema.mod.constIntUnsigned(sema.arena, src, Type.initTag(.comptime_int), bit_size);
4377}4377}
43784378
4379fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4379fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4380 const inst_data = sema.code.instructions.items(.data)[inst].un_node;4380 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
4381 const src = inst_data.src();4381 const src = inst_data.src();
4382 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirTypeInfo", .{});4382 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirTypeInfo", .{});
4383}4383}
43844384
4385fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4385fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4386 const inst_data = sema.code.instructions.items(.data)[inst].un_node;4386 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
4387 const src = inst_data.src();4387 const src = inst_data.src();
4388 const operand = try sema.resolveInst(inst_data.operand);4388 const operand = try sema.resolveInst(inst_data.operand);
4389 return sema.mod.constType(sema.arena, src, operand.ty);4389 return sema.mod.constType(sema.arena, src, operand.ty);
4390}4390}
43914391
4392fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4392fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4393 const inst_data = sema.code.instructions.items(.data)[inst].un_node;4393 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
4394 const src = inst_data.src();4394 const src = inst_data.src();
4395 const operand_ptr = try sema.resolveInst(inst_data.operand);4395 const operand_ptr = try sema.resolveInst(inst_data.operand);
...@@ -4397,13 +4397,13 @@ fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr...@@ -4397,13 +4397,13 @@ fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr
4397 return sema.mod.constType(sema.arena, src, elem_ty);4397 return sema.mod.constType(sema.arena, src, elem_ty);
4398}4398}
43994399
4400fn zirTypeofPeer(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4400fn zirTypeofPeer(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4401 const tracy = trace(@src());4401 const tracy = trace(@src());
4402 defer tracy.end();4402 defer tracy.end();
44034403
4404 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;4404 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
4405 const src = inst_data.src();4405 const src = inst_data.src();
4406 const extra = sema.code.extraData(zir.Inst.MultiOp, inst_data.payload_index);4406 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
4407 const args = sema.code.refSlice(extra.end, extra.data.operands_len);4407 const args = sema.code.refSlice(extra.end, extra.data.operands_len);
44084408
4409 const inst_list = try sema.gpa.alloc(*ir.Inst, extra.data.operands_len);4409 const inst_list = try sema.gpa.alloc(*ir.Inst, extra.data.operands_len);
...@@ -4417,7 +4417,7 @@ fn zirTypeofPeer(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr...@@ -4417,7 +4417,7 @@ fn zirTypeofPeer(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr
4417 return sema.mod.constType(sema.arena, src, result_type);4417 return sema.mod.constType(sema.arena, src, result_type);
4418}4418}
44194419
4420fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4420fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4421 const tracy = trace(@src());4421 const tracy = trace(@src());
4422 defer tracy.end();4422 defer tracy.end();
44234423
...@@ -4437,7 +4437,7 @@ fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError...@@ -4437,7 +4437,7 @@ fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError
4437fn zirBoolOp(4437fn zirBoolOp(
4438 sema: *Sema,4438 sema: *Sema,
4439 block: *Scope.Block,4439 block: *Scope.Block,
4440 inst: zir.Inst.Index,4440 inst: Zir.Inst.Index,
4441 comptime is_bool_or: bool,4441 comptime is_bool_or: bool,
4442) InnerError!*Inst {4442) InnerError!*Inst {
4443 const tracy = trace(@src());4443 const tracy = trace(@src());
...@@ -4468,7 +4468,7 @@ fn zirBoolOp(...@@ -4468,7 +4468,7 @@ fn zirBoolOp(
4468fn zirBoolBr(4468fn zirBoolBr(
4469 sema: *Sema,4469 sema: *Sema,
4470 parent_block: *Scope.Block,4470 parent_block: *Scope.Block,
4471 inst: zir.Inst.Index,4471 inst: Zir.Inst.Index,
4472 is_bool_or: bool,4472 is_bool_or: bool,
4473) InnerError!*Inst {4473) InnerError!*Inst {
4474 const tracy = trace(@src());4474 const tracy = trace(@src());
...@@ -4478,7 +4478,7 @@ fn zirBoolBr(...@@ -4478,7 +4478,7 @@ fn zirBoolBr(
4478 const inst_data = datas[inst].bool_br;4478 const inst_data = datas[inst].bool_br;
4479 const src: LazySrcLoc = .unneeded;4479 const src: LazySrcLoc = .unneeded;
4480 const lhs = try sema.resolveInst(inst_data.lhs);4480 const lhs = try sema.resolveInst(inst_data.lhs);
4481 const extra = sema.code.extraData(zir.Inst.Block, inst_data.payload_index);4481 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
4482 const body = sema.code.extra[extra.end..][0..extra.data.body_len];4482 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
44834483
4484 if (try sema.resolveDefinedValue(parent_block, src, lhs)) |lhs_val| {4484 if (try sema.resolveDefinedValue(parent_block, src, lhs)) |lhs_val| {
...@@ -4536,7 +4536,7 @@ fn zirBoolBr(...@@ -4536,7 +4536,7 @@ fn zirBoolBr(
4536fn zirIsNull(4536fn zirIsNull(
4537 sema: *Sema,4537 sema: *Sema,
4538 block: *Scope.Block,4538 block: *Scope.Block,
4539 inst: zir.Inst.Index,4539 inst: Zir.Inst.Index,
4540 invert_logic: bool,4540 invert_logic: bool,
4541) InnerError!*Inst {4541) InnerError!*Inst {
4542 const tracy = trace(@src());4542 const tracy = trace(@src());
...@@ -4551,7 +4551,7 @@ fn zirIsNull(...@@ -4551,7 +4551,7 @@ fn zirIsNull(
4551fn zirIsNullPtr(4551fn zirIsNullPtr(
4552 sema: *Sema,4552 sema: *Sema,
4553 block: *Scope.Block,4553 block: *Scope.Block,
4554 inst: zir.Inst.Index,4554 inst: Zir.Inst.Index,
4555 invert_logic: bool,4555 invert_logic: bool,
4556) InnerError!*Inst {4556) InnerError!*Inst {
4557 const tracy = trace(@src());4557 const tracy = trace(@src());
...@@ -4564,7 +4564,7 @@ fn zirIsNullPtr(...@@ -4564,7 +4564,7 @@ fn zirIsNullPtr(
4564 return sema.analyzeIsNull(block, src, loaded, invert_logic);4564 return sema.analyzeIsNull(block, src, loaded, invert_logic);
4565}4565}
45664566
4567fn zirIsErr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4567fn zirIsErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4568 const tracy = trace(@src());4568 const tracy = trace(@src());
4569 defer tracy.end();4569 defer tracy.end();
45704570
...@@ -4573,7 +4573,7 @@ fn zirIsErr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*...@@ -4573,7 +4573,7 @@ fn zirIsErr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*
4573 return sema.analyzeIsErr(block, inst_data.src(), operand);4573 return sema.analyzeIsErr(block, inst_data.src(), operand);
4574}4574}
45754575
4576fn zirIsErrPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4576fn zirIsErrPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4577 const tracy = trace(@src());4577 const tracy = trace(@src());
4578 defer tracy.end();4578 defer tracy.end();
45794579
...@@ -4587,15 +4587,15 @@ fn zirIsErrPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro...@@ -4587,15 +4587,15 @@ fn zirIsErrPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro
4587fn zirCondbr(4587fn zirCondbr(
4588 sema: *Sema,4588 sema: *Sema,
4589 parent_block: *Scope.Block,4589 parent_block: *Scope.Block,
4590 inst: zir.Inst.Index,4590 inst: Zir.Inst.Index,
4591) InnerError!zir.Inst.Index {4591) InnerError!Zir.Inst.Index {
4592 const tracy = trace(@src());4592 const tracy = trace(@src());
4593 defer tracy.end();4593 defer tracy.end();
45944594
4595 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;4595 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
4596 const src = inst_data.src();4596 const src = inst_data.src();
4597 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };4597 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };
4598 const extra = sema.code.extraData(zir.Inst.CondBr, inst_data.payload_index);4598 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
45994599
4600 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];4600 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];
4601 const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];4601 const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
...@@ -4628,7 +4628,7 @@ fn zirCondbr(...@@ -4628,7 +4628,7 @@ fn zirCondbr(
4628 return always_noreturn;4628 return always_noreturn;
4629}4629}
46304630
4631fn zirUnreachable(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!zir.Inst.Index {4631fn zirUnreachable(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Zir.Inst.Index {
4632 const tracy = trace(@src());4632 const tracy = trace(@src());
4633 defer tracy.end();4633 defer tracy.end();
46344634
...@@ -4648,9 +4648,9 @@ fn zirUnreachable(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE...@@ -4648,9 +4648,9 @@ fn zirUnreachable(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE
4648fn zirRetTok(4648fn zirRetTok(
4649 sema: *Sema,4649 sema: *Sema,
4650 block: *Scope.Block,4650 block: *Scope.Block,
4651 inst: zir.Inst.Index,4651 inst: Zir.Inst.Index,
4652 need_coercion: bool,4652 need_coercion: bool,
4653) InnerError!zir.Inst.Index {4653) InnerError!Zir.Inst.Index {
4654 const tracy = trace(@src());4654 const tracy = trace(@src());
4655 defer tracy.end();4655 defer tracy.end();
46564656
...@@ -4661,7 +4661,7 @@ fn zirRetTok(...@@ -4661,7 +4661,7 @@ fn zirRetTok(
4661 return sema.analyzeRet(block, operand, src, need_coercion);4661 return sema.analyzeRet(block, operand, src, need_coercion);
4662}4662}
46634663
4664fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!zir.Inst.Index {4664fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Zir.Inst.Index {
4665 const tracy = trace(@src());4665 const tracy = trace(@src());
4666 defer tracy.end();4666 defer tracy.end();
46674667
...@@ -4678,7 +4678,7 @@ fn analyzeRet(...@@ -4678,7 +4678,7 @@ fn analyzeRet(
4678 operand: *Inst,4678 operand: *Inst,
4679 src: LazySrcLoc,4679 src: LazySrcLoc,
4680 need_coercion: bool,4680 need_coercion: bool,
4681) InnerError!zir.Inst.Index {4681) InnerError!Zir.Inst.Index {
4682 if (block.inlining) |inlining| {4682 if (block.inlining) |inlining| {
4683 // We are inlining a function call; rewrite the `ret` as a `break`.4683 // We are inlining a function call; rewrite the `ret` as a `break`.
4684 try inlining.merges.results.append(sema.gpa, operand);4684 try inlining.merges.results.append(sema.gpa, operand);
...@@ -4702,7 +4702,7 @@ fn analyzeRet(...@@ -4702,7 +4702,7 @@ fn analyzeRet(
4702 return always_noreturn;4702 return always_noreturn;
4703}4703}
47044704
4705fn floatOpAllowed(tag: zir.Inst.Tag) bool {4705fn floatOpAllowed(tag: Zir.Inst.Tag) bool {
4706 // extend this swich as additional operators are implemented4706 // extend this swich as additional operators are implemented
4707 return switch (tag) {4707 return switch (tag) {
4708 .add, .sub => true,4708 .add, .sub => true,
...@@ -4710,7 +4710,7 @@ fn floatOpAllowed(tag: zir.Inst.Tag) bool {...@@ -4710,7 +4710,7 @@ fn floatOpAllowed(tag: zir.Inst.Tag) bool {
4710 };4710 };
4711}4711}
47124712
4713fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4713fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4714 const tracy = trace(@src());4714 const tracy = trace(@src());
4715 defer tracy.end();4715 defer tracy.end();
47164716
...@@ -4731,36 +4731,36 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inne...@@ -4731,36 +4731,36 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inne
4731 return sema.mod.constType(sema.arena, .unneeded, ty);4731 return sema.mod.constType(sema.arena, .unneeded, ty);
4732}4732}
47334733
4734fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4734fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4735 const tracy = trace(@src());4735 const tracy = trace(@src());
4736 defer tracy.end();4736 defer tracy.end();
47374737
4738 const src: LazySrcLoc = .unneeded;4738 const src: LazySrcLoc = .unneeded;
4739 const inst_data = sema.code.instructions.items(.data)[inst].ptr_type;4739 const inst_data = sema.code.instructions.items(.data)[inst].ptr_type;
4740 const extra = sema.code.extraData(zir.Inst.PtrType, inst_data.payload_index);4740 const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index);
47414741
4742 var extra_i = extra.end;4742 var extra_i = extra.end;
47434743
4744 const sentinel = if (inst_data.flags.has_sentinel) blk: {4744 const sentinel = if (inst_data.flags.has_sentinel) blk: {
4745 const ref = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_i]);4745 const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);
4746 extra_i += 1;4746 extra_i += 1;
4747 break :blk (try sema.resolveInstConst(block, .unneeded, ref)).val;4747 break :blk (try sema.resolveInstConst(block, .unneeded, ref)).val;
4748 } else null;4748 } else null;
47494749
4750 const abi_align = if (inst_data.flags.has_align) blk: {4750 const abi_align = if (inst_data.flags.has_align) blk: {
4751 const ref = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_i]);4751 const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);
4752 extra_i += 1;4752 extra_i += 1;
4753 break :blk try sema.resolveAlreadyCoercedInt(block, .unneeded, ref, u32);4753 break :blk try sema.resolveAlreadyCoercedInt(block, .unneeded, ref, u32);
4754 } else 0;4754 } else 0;
47554755
4756 const bit_start = if (inst_data.flags.has_bit_range) blk: {4756 const bit_start = if (inst_data.flags.has_bit_range) blk: {
4757 const ref = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_i]);4757 const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);
4758 extra_i += 1;4758 extra_i += 1;
4759 break :blk try sema.resolveAlreadyCoercedInt(block, .unneeded, ref, u16);4759 break :blk try sema.resolveAlreadyCoercedInt(block, .unneeded, ref, u16);
4760 } else 0;4760 } else 0;
47614761
4762 const bit_end = if (inst_data.flags.has_bit_range) blk: {4762 const bit_end = if (inst_data.flags.has_bit_range) blk: {
4763 const ref = @intToEnum(zir.Inst.Ref, sema.code.extra[extra_i]);4763 const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);
4764 extra_i += 1;4764 extra_i += 1;
4765 break :blk try sema.resolveAlreadyCoercedInt(block, .unneeded, ref, u16);4765 break :blk try sema.resolveAlreadyCoercedInt(block, .unneeded, ref, u16);
4766 } else 0;4766 } else 0;
...@@ -4785,7 +4785,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError...@@ -4785,7 +4785,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError
4785 return sema.mod.constType(sema.arena, src, ty);4785 return sema.mod.constType(sema.arena, src, ty);
4786}4786}
47874787
4788fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4788fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4789 const tracy = trace(@src());4789 const tracy = trace(@src());
4790 defer tracy.end();4790 defer tracy.end();
47914791
...@@ -4799,13 +4799,13 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In...@@ -4799,13 +4799,13 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In
4799 });4799 });
4800}4800}
48014801
4802fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4802fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4803 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;4803 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
4804 const src = inst_data.src();4804 const src = inst_data.src();
4805 return sema.mod.fail(&block.base, src, "TODO: Sema.zirStructInit", .{});4805 return sema.mod.fail(&block.base, src, "TODO: Sema.zirStructInit", .{});
4806}4806}
48074807
4808fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {4808fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4809 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;4809 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
4810 const src = inst_data.src();4810 const src = inst_data.src();
4811 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldType", .{});4811 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldType", .{});
...@@ -4895,7 +4895,7 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id:...@@ -4895,7 +4895,7 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id:
4895 try parent_block.instructions.append(sema.gpa, &block_inst.base);4895 try parent_block.instructions.append(sema.gpa, &block_inst.base);
4896}4896}
48974897
4898fn safetyPanic(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, panic_id: PanicId) !zir.Inst.Index {4898fn safetyPanic(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, panic_id: PanicId) !Zir.Inst.Index {
4899 // TODO Once we have a panic function to call, call it here instead of breakpoint.4899 // TODO Once we have a panic function to call, call it here instead of breakpoint.
4900 _ = try block.addNoOp(src, Type.initTag(.void), .breakpoint);4900 _ = try block.addNoOp(src, Type.initTag(.void), .breakpoint);
4901 _ = try block.addNoOp(src, Type.initTag(.noreturn), .unreach);4901 _ = try block.addNoOp(src, Type.initTag(.noreturn), .unreach);
src/zir.zig+88-89
...@@ -1,5 +1,14 @@...@@ -1,5 +1,14 @@
1//! Zig Intermediate Representation. Astgen.zig converts AST nodes to these1//! Zig Intermediate Representation. Astgen.zig converts AST nodes to these
2//! untyped IR instructions. Next, Sema.zig processes these into TZIR.2//! untyped IR instructions. Next, Sema.zig processes these into TZIR.
3//! The minimum amount of information needed to represent a list of ZIR instructions.
4//! Once this structure is completed, it can be used to generate TZIR, followed by
5//! machine code, without any memory access into the AST tree token list, node list,
6//! or source bytes. Exceptions include:
7//! * Compile errors, which may need to reach into these data structures to
8//! create a useful report.
9//! * In the future, possibly inline assembly, which needs to get parsed and
10//! handled by the codegen backend, and errors reported there. However for now,
11//! inline assembly is not an exception.
312
4const std = @import("std");13const std = @import("std");
5const mem = std.mem;14const mem = std.mem;
...@@ -9,6 +18,7 @@ const BigIntConst = std.math.big.int.Const;...@@ -9,6 +18,7 @@ const BigIntConst = std.math.big.int.Const;
9const BigIntMutable = std.math.big.int.Mutable;18const BigIntMutable = std.math.big.int.Mutable;
10const ast = std.zig.ast;19const ast = std.zig.ast;
1120
21const Zir = @This();
12const Type = @import("type.zig").Type;22const Type = @import("type.zig").Type;
13const Value = @import("value.zig").Value;23const Value = @import("value.zig").Value;
14const TypedValue = @import("TypedValue.zig");24const TypedValue = @import("TypedValue.zig");
...@@ -16,96 +26,85 @@ const ir = @import("ir.zig");...@@ -16,96 +26,85 @@ const ir = @import("ir.zig");
16const Module = @import("Module.zig");26const Module = @import("Module.zig");
17const LazySrcLoc = Module.LazySrcLoc;27const LazySrcLoc = Module.LazySrcLoc;
1828
19/// The minimum amount of information needed to represent a list of ZIR instructions.29/// There is always implicitly a `block` instruction at index 0.
20/// Once this structure is completed, it can be used to generate TZIR, followed by30/// This is so that `break_inline` can break from the root block.
21/// machine code, without any memory access into the AST tree token list, node list,31instructions: std.MultiArrayList(Inst).Slice,
22/// or source bytes. Exceptions include:32/// In order to store references to strings in fewer bytes, we copy all
23/// * Compile errors, which may need to reach into these data structures to33/// string bytes into here. String bytes can be null. It is up to whomever
24/// create a useful report.34/// is referencing the data here whether they want to store both index and length,
25/// * In the future, possibly inline assembly, which needs to get parsed and35/// thus allowing null bytes, or store only index, and use null-termination. The
26/// handled by the codegen backend, and errors reported there. However for now,36/// `string_bytes` array is agnostic to either usage.
27/// inline assembly is not an exception.37string_bytes: []u8,
28pub const Code = struct {38/// The meaning of this data is determined by `Inst.Tag` value.
29 /// There is always implicitly a `block` instruction at index 0.39extra: []u32,
30 /// This is so that `break_inline` can break from the root block.40
31 instructions: std.MultiArrayList(Inst).Slice,41/// Returns the requested data, as well as the new index which is at the start of the
32 /// In order to store references to strings in fewer bytes, we copy all42/// trailers for the object.
33 /// string bytes into here. String bytes can be null. It is up to whomever43pub fn extraData(code: Zir, comptime T: type, index: usize) struct { data: T, end: usize } {
34 /// is referencing the data here whether they want to store both index and length,44 const fields = std.meta.fields(T);
35 /// thus allowing null bytes, or store only index, and use null-termination. The45 var i: usize = index;
36 /// `string_bytes` array is agnostic to either usage.46 var result: T = undefined;
37 string_bytes: []u8,47 inline for (fields) |field| {
38 /// The meaning of this data is determined by `Inst.Tag` value.48 @field(result, field.name) = switch (field.field_type) {
39 extra: []u32,49 u32 => code.extra[i],
4050 Inst.Ref => @intToEnum(Inst.Ref, code.extra[i]),
41 /// Returns the requested data, as well as the new index which is at the start of the51 else => unreachable,
42 /// trailers for the object.
43 pub fn extraData(code: Code, comptime T: type, index: usize) struct { data: T, end: usize } {
44 const fields = std.meta.fields(T);
45 var i: usize = index;
46 var result: T = undefined;
47 inline for (fields) |field| {
48 @field(result, field.name) = switch (field.field_type) {
49 u32 => code.extra[i],
50 Inst.Ref => @intToEnum(Inst.Ref, code.extra[i]),
51 else => unreachable,
52 };
53 i += 1;
54 }
55 return .{
56 .data = result,
57 .end = i,
58 };52 };
53 i += 1;
59 }54 }
55 return .{
56 .data = result,
57 .end = i,
58 };
59}
6060
61 /// Given an index into `string_bytes` returns the null-terminated string found there.61/// Given an index into `string_bytes` returns the null-terminated string found there.
62 pub fn nullTerminatedString(code: Code, index: usize) [:0]const u8 {62pub fn nullTerminatedString(code: Zir, index: usize) [:0]const u8 {
63 var end: usize = index;63 var end: usize = index;
64 while (code.string_bytes[end] != 0) {64 while (code.string_bytes[end] != 0) {
65 end += 1;65 end += 1;
66 }
67 return code.string_bytes[index..end :0];
68 }
69
70 pub fn refSlice(code: Code, start: usize, len: usize) []Inst.Ref {
71 const raw_slice = code.extra[start..][0..len];
72 return @bitCast([]Inst.Ref, raw_slice);
73 }
74
75 pub fn deinit(code: *Code, gpa: *Allocator) void {
76 code.instructions.deinit(gpa);
77 gpa.free(code.string_bytes);
78 gpa.free(code.extra);
79 code.* = undefined;
80 }66 }
67 return code.string_bytes[index..end :0];
68}
69
70pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {
71 const raw_slice = code.extra[start..][0..len];
72 return @bitCast([]Inst.Ref, raw_slice);
73}
74
75pub fn deinit(code: *Zir, gpa: *Allocator) void {
76 code.instructions.deinit(gpa);
77 gpa.free(code.string_bytes);
78 gpa.free(code.extra);
79 code.* = undefined;
80}
81
82/// For debugging purposes, like dumpFn but for unanalyzed zir blocks
83pub fn dump(
84 code: Zir,
85 gpa: *Allocator,
86 kind: []const u8,
87 scope: *Module.Scope,
88 param_count: usize,
89) !void {
90 var arena = std.heap.ArenaAllocator.init(gpa);
91 defer arena.deinit();
92
93 var writer: Writer = .{
94 .gpa = gpa,
95 .arena = &arena.allocator,
96 .scope = scope,
97 .code = code,
98 .indent = 0,
99 .param_count = param_count,
100 };
81101
82 /// For debugging purposes, like dumpFn but for unanalyzed zir blocks102 const decl_name = scope.srcDecl().?.name;
83 pub fn dump(103 const stderr = std.io.getStdErr().writer();
84 code: Code,104 try stderr.print("ZIR {s} {s} %0 ", .{ kind, decl_name });
85 gpa: *Allocator,105 try writer.writeInstToStream(stderr, 0);
86 kind: []const u8,106 try stderr.print(" // end ZIR {s} {s}\n\n", .{ kind, decl_name });
87 scope: *Module.Scope,107}
88 param_count: usize,
89 ) !void {
90 var arena = std.heap.ArenaAllocator.init(gpa);
91 defer arena.deinit();
92
93 var writer: Writer = .{
94 .gpa = gpa,
95 .arena = &arena.allocator,
96 .scope = scope,
97 .code = code,
98 .indent = 0,
99 .param_count = param_count,
100 };
101
102 const decl_name = scope.srcDecl().?.name;
103 const stderr = std.io.getStdErr().writer();
104 try stderr.print("ZIR {s} {s} %0 ", .{ kind, decl_name });
105 try writer.writeInstToStream(stderr, 0);
106 try stderr.print(" // end ZIR {s} {s}\n\n", .{ kind, decl_name });
107 }
108};
109108
110/// These are untyped instructions generated from an Abstract Syntax Tree.109/// These are untyped instructions generated from an Abstract Syntax Tree.
111/// The data here is immutable because it is possible to have multiple110/// The data here is immutable because it is possible to have multiple
...@@ -885,7 +884,7 @@ pub const Inst = struct {...@@ -885,7 +884,7 @@ pub const Inst = struct {
885 }884 }
886 };885 };
887886
888 /// The position of a ZIR instruction within the `Code` instructions array.887 /// The position of a ZIR instruction within the `Zir` instructions array.
889 pub const Index = u32;888 pub const Index = u32;
890889
891 /// A reference to a TypedValue, parameter of the current function,890 /// A reference to a TypedValue, parameter of the current function,
...@@ -1236,7 +1235,7 @@ pub const Inst = struct {...@@ -1236,7 +1235,7 @@ pub const Inst = struct {
1236 /// Number of bytes in the string.1235 /// Number of bytes in the string.
1237 len: u32,1236 len: u32,
12381237
1239 pub fn get(self: @This(), code: Code) []const u8 {1238 pub fn get(self: @This(), code: Zir) []const u8 {
1240 return code.string_bytes[self.start..][0..self.len];1239 return code.string_bytes[self.start..][0..self.len];
1241 }1240 }
1242 },1241 },
...@@ -1257,7 +1256,7 @@ pub const Inst = struct {...@@ -1257,7 +1256,7 @@ pub const Inst = struct {
1257 /// Offset from Decl AST token index.1256 /// Offset from Decl AST token index.
1258 src_tok: u32,1257 src_tok: u32,
12591258
1260 pub fn get(self: @This(), code: Code) [:0]const u8 {1259 pub fn get(self: @This(), code: Zir) [:0]const u8 {
1261 return code.nullTerminatedString(self.start);1260 return code.nullTerminatedString(self.start);
1262 }1261 }
12631262
...@@ -1609,7 +1608,7 @@ const Writer = struct {...@@ -1609,7 +1608,7 @@ const Writer = struct {
1609 gpa: *Allocator,1608 gpa: *Allocator,
1610 arena: *Allocator,1609 arena: *Allocator,
1611 scope: *Module.Scope,1610 scope: *Module.Scope,
1612 code: Code,1611 code: Zir,
1613 indent: usize,1612 indent: usize,
1614 param_count: usize,1613 param_count: usize,
16151614