authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-13 15:45:08-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-20 12:19:16-07:00
logc09b973ec25f328f5e15e9e6eed4da7f5e4634af
tree3e6d262995f7c4b1760d154078875681082b4110
parent0f38f686964664f68e013ec3c63cfe655001f165

stage2: compile error fixes for AIR memory layout branch

Now the branch is compiling again, provided that one uses `-Dskip-non-native`, but many code paths are disabled. The code paths can now be re-enabled one at a time and updated to conform to the new AIR memory layout.

9 files changed, 851 insertions(+), 640 deletions(-)

src/Air.zig+24-6
...@@ -332,12 +332,12 @@ pub const Block = struct {...@@ -332,12 +332,12 @@ pub const Block = struct {
332 body_len: u32,332 body_len: u32,
333};333};
334334
335/// Trailing is a list of `Ref` for every `args_len`.335/// Trailing is a list of `Inst.Ref` for every `args_len`.
336pub const Call = struct {336pub const Call = struct {
337 args_len: u32,337 args_len: u32,
338};338};
339339
340/// This data is stored inside extra, with two sets of trailing `Ref`:340/// This data is stored inside extra, with two sets of trailing `Inst.Ref`:
341/// * 0. the then body, according to `then_body_len`.341/// * 0. the then body, according to `then_body_len`.
342/// * 1. the else body, according to `else_body_len`.342/// * 1. the else body, according to `else_body_len`.
343pub const CondBr = struct {343pub const CondBr = struct {
...@@ -355,19 +355,19 @@ pub const SwitchBr = struct {...@@ -355,19 +355,19 @@ pub const SwitchBr = struct {
355 /// Trailing:355 /// Trailing:
356 /// * instruction index for each `body_len`.356 /// * instruction index for each `body_len`.
357 pub const Case = struct {357 pub const Case = struct {
358 item: Ref,358 item: Inst.Ref,
359 body_len: u32,359 body_len: u32,
360 };360 };
361};361};
362362
363pub const StructField = struct {363pub const StructField = struct {
364 struct_ptr: Ref,364 struct_ptr: Inst.Ref,
365 field_index: u32,365 field_index: u32,
366};366};
367367
368/// Trailing:368/// Trailing:
369/// 0. `Ref` for every outputs_len369/// 0. `Inst.Ref` for every outputs_len
370/// 1. `Ref` for every inputs_len370/// 1. `Inst.Ref` for every inputs_len
371pub const Asm = struct {371pub const Asm = struct {
372 /// Index to the corresponding ZIR instruction.372 /// Index to the corresponding ZIR instruction.
373 /// `asm_source`, `outputs_len`, `inputs_len`, `clobbers_len`, `is_volatile`, and373 /// `asm_source`, `outputs_len`, `inputs_len`, `clobbers_len`, `is_volatile`, and
...@@ -381,6 +381,24 @@ pub fn getMainBody(air: Air) []const Air.Inst.Index {...@@ -381,6 +381,24 @@ pub fn getMainBody(air: Air) []const Air.Inst.Index {
381 return air.extra[body_index..][0..body_len];381 return air.extra[body_index..][0..body_len];
382}382}
383383
384pub fn getType(air: Air, inst: Air.Inst.Index) Type {
385 _ = air;
386 _ = inst;
387 @panic("TODO Air getType");
388}
389
390pub fn getRefType(air: Air, ref: Air.Inst.Ref) Type {
391 var i: usize = @enumToInt(ref);
392 if (i < Air.Inst.Ref.typed_value_map.len) {
393 return Air.Inst.Ref.typed_value_map[i].val.toType(undefined) catch unreachable;
394 }
395 i -= Air.Inst.Ref.typed_value_map.len;
396 const air_tags = air.instructions.items(.tag);
397 const air_datas = air.instructions.items(.data);
398 assert(air_tags[i] == .const_ty);
399 return air_datas[i].ty;
400}
401
384/// Returns the requested data, as well as the new index which is at the start of the402/// Returns the requested data, as well as the new index which is at the start of the
385/// trailers for the object.403/// trailers for the object.
386pub fn extraData(air: Air, comptime T: type, index: usize) struct { data: T, end: usize } {404pub fn extraData(air: Air, comptime T: type, index: usize) struct { data: T, end: usize } {
src/Compilation.zig+1-1
...@@ -2023,7 +2023,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor...@@ -2023,7 +2023,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
2023 defer air.deinit(gpa);2023 defer air.deinit(gpa);
20242024
2025 log.debug("analyze liveness of {s}", .{decl.name});2025 log.debug("analyze liveness of {s}", .{decl.name});
2026 var liveness = try Liveness.analyze(gpa, air);2026 var liveness = try Liveness.analyze(gpa, air, decl.namespace.file_scope.zir);
2027 defer liveness.deinit(gpa);2027 defer liveness.deinit(gpa);
20282028
2029 if (std.builtin.mode == .Debug and self.verbose_air) {2029 if (std.builtin.mode == .Debug and self.verbose_air) {
src/Liveness.zig+51-20
...@@ -7,11 +7,13 @@...@@ -7,11 +7,13 @@
7//! * Switch Branches7//! * Switch Branches
8const Liveness = @This();8const Liveness = @This();
9const std = @import("std");9const std = @import("std");
10const Air = @import("Air.zig");
11const trace = @import("tracy.zig").trace;10const trace = @import("tracy.zig").trace;
12const log = std.log.scoped(.liveness);11const log = std.log.scoped(.liveness);
13const assert = std.debug.assert;12const assert = std.debug.assert;
14const Allocator = std.mem.Allocator;13const Allocator = std.mem.Allocator;
14const Air = @import("Air.zig");
15const Zir = @import("Zir.zig");
16const Log2Int = std.math.Log2Int;
1517
16/// This array is split into sets of 4 bits per AIR instruction.18/// This array is split into sets of 4 bits per AIR instruction.
17/// The MSB (0bX000) is whether the instruction is unreferenced.19/// The MSB (0bX000) is whether the instruction is unreferenced.
...@@ -44,7 +46,7 @@ pub const SwitchBr = struct {...@@ -44,7 +46,7 @@ pub const SwitchBr = struct {
44 else_death_count: u32,46 else_death_count: u32,
45};47};
4648
47pub fn analyze(gpa: *Allocator, air: Air) Allocator.Error!Liveness {49pub fn analyze(gpa: *Allocator, air: Air, zir: Zir) Allocator.Error!Liveness {
48 const tracy = trace(@src());50 const tracy = trace(@src());
49 defer tracy.end();51 defer tracy.end();
5052
...@@ -58,6 +60,7 @@ pub fn analyze(gpa: *Allocator, air: Air) Allocator.Error!Liveness {...@@ -58,6 +60,7 @@ pub fn analyze(gpa: *Allocator, air: Air) Allocator.Error!Liveness {
58 ),60 ),
59 .extra = .{},61 .extra = .{},
60 .special = .{},62 .special = .{},
63 .zir = &zir,
61 };64 };
62 errdefer gpa.free(a.tomb_bits);65 errdefer gpa.free(a.tomb_bits);
63 errdefer a.special.deinit(gpa);66 errdefer a.special.deinit(gpa);
...@@ -74,23 +77,32 @@ pub fn analyze(gpa: *Allocator, air: Air) Allocator.Error!Liveness {...@@ -74,23 +77,32 @@ pub fn analyze(gpa: *Allocator, air: Air) Allocator.Error!Liveness {
74 };77 };
75}78}
7679
80pub fn getTombBits(l: Liveness, inst: Air.Inst.Index) Bpi {
81 const usize_index = (inst * bpi) / @bitSizeOf(usize);
82 return @truncate(Bpi, l.tomb_bits[usize_index] >>
83 @intCast(Log2Int(usize), (inst % (@bitSizeOf(usize) / bpi)) * bpi));
84}
85
77pub fn isUnused(l: Liveness, inst: Air.Inst.Index) bool {86pub fn isUnused(l: Liveness, inst: Air.Inst.Index) bool {
78 const usize_index = (inst * bpi) / @bitSizeOf(usize);87 const usize_index = (inst * bpi) / @bitSizeOf(usize);
79 const mask = @as(usize, 1) << ((inst % (@bitSizeOf(usize) / bpi)) * bpi + (bpi - 1));88 const mask = @as(usize, 1) <<
89 @intCast(Log2Int(usize), (inst % (@bitSizeOf(usize) / bpi)) * bpi + (bpi - 1));
80 return (l.tomb_bits[usize_index] & mask) != 0;90 return (l.tomb_bits[usize_index] & mask) != 0;
81}91}
8292
83pub fn operandDies(l: Liveness, inst: Air.Inst.Index, operand: OperandInt) bool {93pub fn operandDies(l: Liveness, inst: Air.Inst.Index, operand: OperandInt) bool {
84 assert(operand < bpi - 1);94 assert(operand < bpi - 1);
85 const usize_index = (inst * bpi) / @bitSizeOf(usize);95 const usize_index = (inst * bpi) / @bitSizeOf(usize);
86 const mask = @as(usize, 1) << ((inst % (@bitSizeOf(usize) / bpi)) * bpi + operand);96 const mask = @as(usize, 1) <<
97 @intCast(Log2Int(usize), (inst % (@bitSizeOf(usize) / bpi)) * bpi + operand);
87 return (l.tomb_bits[usize_index] & mask) != 0;98 return (l.tomb_bits[usize_index] & mask) != 0;
88}99}
89100
90pub fn clearOperandDeath(l: *Liveness, inst: Air.Inst.Index, operand: OperandInt) void {101pub fn clearOperandDeath(l: *Liveness, inst: Air.Inst.Index, operand: OperandInt) void {
91 assert(operand < bpi - 1);102 assert(operand < bpi - 1);
92 const usize_index = (inst * bpi) / @bitSizeOf(usize);103 const usize_index = (inst * bpi) / @bitSizeOf(usize);
93 const mask = @as(usize, 1) << ((inst % (@bitSizeOf(usize) / bpi)) * bpi + operand);104 const mask = @as(usize, 1) <<
105 @intCast(Log2Int(usize), (inst % (@bitSizeOf(usize) / bpi)) * bpi + operand);
94 l.tomb_bits[usize_index] |= mask;106 l.tomb_bits[usize_index] |= mask;
95}107}
96108
...@@ -113,10 +125,12 @@ const Analysis = struct {...@@ -113,10 +125,12 @@ const Analysis = struct {
113 tomb_bits: []usize,125 tomb_bits: []usize,
114 special: std.AutoHashMapUnmanaged(Air.Inst.Index, u32),126 special: std.AutoHashMapUnmanaged(Air.Inst.Index, u32),
115 extra: std.ArrayListUnmanaged(u32),127 extra: std.ArrayListUnmanaged(u32),
128 zir: *const Zir,
116129
117 fn storeTombBits(a: *Analysis, inst: Air.Inst.Index, tomb_bits: Bpi) void {130 fn storeTombBits(a: *Analysis, inst: Air.Inst.Index, tomb_bits: Bpi) void {
118 const usize_index = (inst * bpi) / @bitSizeOf(usize);131 const usize_index = (inst * bpi) / @bitSizeOf(usize);
119 a.tomb_bits[usize_index] |= tomb_bits << (inst % (@bitSizeOf(usize) / bpi)) * bpi;132 a.tomb_bits[usize_index] |= @as(usize, tomb_bits) <<
133 @intCast(Log2Int(usize), (inst % (@bitSizeOf(usize) / bpi)) * bpi);
120 }134 }
121135
122 fn addExtra(a: *Analysis, extra: anytype) Allocator.Error!u32 {136 fn addExtra(a: *Analysis, extra: anytype) Allocator.Error!u32 {
...@@ -203,9 +217,11 @@ fn analyzeInst(...@@ -203,9 +217,11 @@ fn analyzeInst(
203 return trackOperands(a, new_set, inst, main_tomb, .{ o.lhs, o.rhs, .none });217 return trackOperands(a, new_set, inst, main_tomb, .{ o.lhs, o.rhs, .none });
204 },218 },
205219
220 .arg,
206 .alloc,221 .alloc,
207 .br,222 .br,
208 .constant,223 .constant,
224 .const_ty,
209 .breakpoint,225 .breakpoint,
210 .dbg_stmt,226 .dbg_stmt,
211 .varptr,227 .varptr,
...@@ -255,15 +271,30 @@ fn analyzeInst(...@@ -255,15 +271,30 @@ fn analyzeInst(
255 if (args.len <= bpi - 2) {271 if (args.len <= bpi - 2) {
256 var buf: [bpi - 1]Air.Inst.Ref = undefined;272 var buf: [bpi - 1]Air.Inst.Ref = undefined;
257 buf[0] = callee;273 buf[0] = callee;
258 std.mem.copy(&buf, buf[1..], args);274 std.mem.copy(Air.Inst.Ref, buf[1..], @bitCast([]const Air.Inst.Ref, args));
259 return trackOperands(a, new_set, inst, main_tomb, buf);275 return trackOperands(a, new_set, inst, main_tomb, buf);
260 }276 }
261 @panic("TODO: liveness analysis for function with many args");277 @panic("TODO: liveness analysis for function with greater than 2 args");
262 },278 },
263 .struct_field_ptr => {279 .struct_field_ptr => {
264 const extra = a.air.extraData(Air.StructField, inst_datas[inst].ty_pl.payload).data;280 const extra = a.air.extraData(Air.StructField, inst_datas[inst].ty_pl.payload).data;
265 return trackOperands(a, new_set, inst, main_tomb, .{ extra.struct_ptr, .none, .none });281 return trackOperands(a, new_set, inst, main_tomb, .{ extra.struct_ptr, .none, .none });
266 },282 },
283 .assembly => {
284 const extra = a.air.extraData(Air.Asm, inst_datas[inst].ty_pl.payload);
285 const extended = a.zir.instructions.items(.data)[extra.data.zir_index].extended;
286 const outputs_len = @truncate(u5, extended.small);
287 const inputs_len = @truncate(u5, extended.small >> 5);
288 const outputs = a.air.extra[extra.end..][0..outputs_len];
289 const inputs = a.air.extra[extra.end + outputs.len ..][0..inputs_len];
290 if (outputs.len + inputs.len <= bpi - 1) {
291 var buf: [bpi - 1]Air.Inst.Ref = undefined;
292 std.mem.copy(Air.Inst.Ref, &buf, @bitCast([]const Air.Inst.Ref, outputs));
293 std.mem.copy(Air.Inst.Ref, buf[outputs.len..], @bitCast([]const Air.Inst.Ref, inputs));
294 return trackOperands(a, new_set, inst, main_tomb, buf);
295 }
296 @panic("TODO: liveness analysis for asm with greater than 3 args");
297 },
267 .block => {298 .block => {
268 const extra = a.air.extraData(Air.Block, inst_datas[inst].ty_pl.payload);299 const extra = a.air.extraData(Air.Block, inst_datas[inst].ty_pl.payload);
269 const body = a.air.extra[extra.end..][0..extra.data.body_len];300 const body = a.air.extra[extra.end..][0..extra.data.body_len];
...@@ -287,8 +318,8 @@ fn analyzeInst(...@@ -287,8 +318,8 @@ fn analyzeInst(
287 const then_body = a.air.extra[extra.end..][0..extra.data.then_body_len];318 const then_body = a.air.extra[extra.end..][0..extra.data.then_body_len];
288 const else_body = a.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];319 const else_body = a.air.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
289320
290 var then_table = std.AutoHashMap(Air.Inst.Index, void).init(gpa);321 var then_table: std.AutoHashMapUnmanaged(Air.Inst.Index, void) = .{};
291 defer then_table.deinit();322 defer then_table.deinit(gpa);
292 try analyzeWithContext(a, &then_table, then_body);323 try analyzeWithContext(a, &then_table, then_body);
293324
294 // Reset the table back to its state from before the branch.325 // Reset the table back to its state from before the branch.
...@@ -299,8 +330,8 @@ fn analyzeInst(...@@ -299,8 +330,8 @@ fn analyzeInst(
299 }330 }
300 }331 }
301332
302 var else_table = std.AutoHashMap(Air.Inst.Index, void).init(gpa);333 var else_table: std.AutoHashMapUnmanaged(Air.Inst.Index, void) = .{};
303 defer else_table.deinit();334 defer else_table.deinit(gpa);
304 try analyzeWithContext(a, &else_table, else_body);335 try analyzeWithContext(a, &else_table, else_body);
305336
306 var then_entry_deaths = std.ArrayList(Air.Inst.Index).init(gpa);337 var then_entry_deaths = std.ArrayList(Air.Inst.Index).init(gpa);
...@@ -331,7 +362,7 @@ fn analyzeInst(...@@ -331,7 +362,7 @@ fn analyzeInst(
331 }362 }
332 // Now we have to correctly populate new_set.363 // Now we have to correctly populate new_set.
333 if (new_set) |ns| {364 if (new_set) |ns| {
334 try ns.ensureCapacity(@intCast(u32, ns.count() + then_table.count() + else_table.count()));365 try ns.ensureCapacity(gpa, @intCast(u32, ns.count() + then_table.count() + else_table.count()));
335 var it = then_table.keyIterator();366 var it = then_table.keyIterator();
336 while (it.next()) |key| {367 while (it.next()) |key| {
337 _ = ns.putAssumeCapacity(key.*, {});368 _ = ns.putAssumeCapacity(key.*, {});
...@@ -344,7 +375,7 @@ fn analyzeInst(...@@ -344,7 +375,7 @@ fn analyzeInst(
344 const then_death_count = @intCast(u32, then_entry_deaths.items.len);375 const then_death_count = @intCast(u32, then_entry_deaths.items.len);
345 const else_death_count = @intCast(u32, else_entry_deaths.items.len);376 const else_death_count = @intCast(u32, else_entry_deaths.items.len);
346377
347 try a.extra.ensureUnusedCapacity(std.meta.fields(@TypeOf(CondBr)).len +378 try a.extra.ensureUnusedCapacity(gpa, std.meta.fields(Air.CondBr).len +
348 then_death_count + else_death_count);379 then_death_count + else_death_count);
349 const extra_index = a.addExtraAssumeCapacity(CondBr{380 const extra_index = a.addExtraAssumeCapacity(CondBr{
350 .then_death_count = then_death_count,381 .then_death_count = then_death_count,
...@@ -352,7 +383,7 @@ fn analyzeInst(...@@ -352,7 +383,7 @@ fn analyzeInst(
352 });383 });
353 a.extra.appendSliceAssumeCapacity(then_entry_deaths.items);384 a.extra.appendSliceAssumeCapacity(then_entry_deaths.items);
354 a.extra.appendSliceAssumeCapacity(else_entry_deaths.items);385 a.extra.appendSliceAssumeCapacity(else_entry_deaths.items);
355 try a.special.put(inst, extra_index);386 try a.special.put(gpa, inst, extra_index);
356387
357 // Continue on with the instruction analysis. The following code will find the condition388 // Continue on with the instruction analysis. The following code will find the condition
358 // instruction, and the deaths flag for the CondBr instruction will indicate whether the389 // instruction, and the deaths flag for the CondBr instruction will indicate whether the
...@@ -438,12 +469,12 @@ fn analyzeInst(...@@ -438,12 +469,12 @@ fn analyzeInst(
438 });469 });
439 for (case_deaths[0 .. case_deaths.len - 1]) |*cd| {470 for (case_deaths[0 .. case_deaths.len - 1]) |*cd| {
440 const case_death_count = @intCast(u32, cd.items.len);471 const case_death_count = @intCast(u32, cd.items.len);
441 try a.extra.ensureUnusedCapacity(1 + case_death_count + else_death_count);472 try a.extra.ensureUnusedCapacity(gpa, 1 + case_death_count + else_death_count);
442 a.extra.appendAssumeCapacity(case_death_count);473 a.extra.appendAssumeCapacity(case_death_count);
443 a.extra.appendSliceAssumeCapacity(cd.items);474 a.extra.appendSliceAssumeCapacity(cd.items);
444 }475 }
445 a.extra.appendSliceAssumeCapacity(case_deaths[case_deaths.len - 1].items);476 a.extra.appendSliceAssumeCapacity(case_deaths[case_deaths.len - 1].items);
446 try a.special.put(inst, extra_index);477 try a.special.put(gpa, inst, extra_index);
447478
448 return trackOperands(a, new_set, inst, main_tomb, .{ condition, .none, .none });479 return trackOperands(a, new_set, inst, main_tomb, .{ condition, .none, .none });
449 },480 },
...@@ -452,7 +483,7 @@ fn analyzeInst(...@@ -452,7 +483,7 @@ fn analyzeInst(
452483
453fn trackOperands(484fn trackOperands(
454 a: *Analysis,485 a: *Analysis,
455 new_set: ?*std.AutoHashMap(Air.Inst.Index, void),486 new_set: ?*std.AutoHashMapUnmanaged(Air.Inst.Index, void),
456 inst: Air.Inst.Index,487 inst: Air.Inst.Index,
457 main_tomb: bool,488 main_tomb: bool,
458 operands: [bpi - 1]Air.Inst.Ref,489 operands: [bpi - 1]Air.Inst.Ref,
...@@ -468,12 +499,12 @@ fn trackOperands(...@@ -468,12 +499,12 @@ fn trackOperands(
468 tomb_bits <<= 1;499 tomb_bits <<= 1;
469 const op_int = @enumToInt(operands[i]);500 const op_int = @enumToInt(operands[i]);
470 if (op_int < Air.Inst.Ref.typed_value_map.len) continue;501 if (op_int < Air.Inst.Ref.typed_value_map.len) continue;
471 const operand: Air.Inst.Index = op_int - Air.Inst.Ref.typed_value_map.len;502 const operand: Air.Inst.Index = op_int - @intCast(u32, Air.Inst.Ref.typed_value_map.len);
472 const prev = try table.fetchPut(gpa, operand, {});503 const prev = try table.fetchPut(gpa, operand, {});
473 if (prev == null) {504 if (prev == null) {
474 // Death.505 // Death.
475 tomb_bits |= 1;506 tomb_bits |= 1;
476 if (new_set) |ns| try ns.putNoClobber(operand, {});507 if (new_set) |ns| try ns.putNoClobber(gpa, operand, {});
477 }508 }
478 }509 }
479 a.storeTombBits(inst, tomb_bits);510 a.storeTombBits(inst, tomb_bits);
src/Module.zig+29-5
...@@ -1225,6 +1225,30 @@ pub const Scope = struct {...@@ -1225,6 +1225,30 @@ pub const Scope = struct {
1225 pub fn getFileScope(block: *Block) *Scope.File {1225 pub fn getFileScope(block: *Block) *Scope.File {
1226 return block.src_decl.namespace.file_scope;1226 return block.src_decl.namespace.file_scope;
1227 }1227 }
1228
1229 pub fn addTyOp(
1230 block: *Block,
1231 tag: Air.Inst.Tag,
1232 ty: Type,
1233 operand: Air.Inst.Ref,
1234 ) error{OutOfMemory}!Air.Inst.Ref {
1235 const sema = block.sema;
1236 const gpa = sema.gpa;
1237
1238 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
1239 try block.instructions.ensureUnusedCapacity(gpa, 1);
1240
1241 const inst = @intCast(Air.Inst.Index, sema.air_instructions.len);
1242 sema.air_instructions.appendAssumeCapacity(.{
1243 .tag = tag,
1244 .data = .{ .ty_op = .{
1245 .ty = try sema.addType(ty),
1246 .operand = operand,
1247 } },
1248 });
1249 block.instructions.appendAssumeCapacity(inst);
1250 return Sema.indexToRef(inst);
1251 }
1228 };1252 };
1229};1253};
12301254
...@@ -3408,7 +3432,7 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !Air {...@@ -3408,7 +3432,7 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !Air {
3408 defer decl.value_arena.?.* = arena.state;3432 defer decl.value_arena.?.* = arena.state;
34093433
3410 const fn_ty = decl.ty;3434 const fn_ty = decl.ty;
3411 const param_inst_list = try gpa.alloc(Air.Inst.Index, fn_ty.fnParamLen());3435 const param_inst_list = try gpa.alloc(Air.Inst.Ref, fn_ty.fnParamLen());
3412 defer gpa.free(param_inst_list);3436 defer gpa.free(param_inst_list);
34133437
3414 var sema: Sema = .{3438 var sema: Sema = .{
...@@ -3440,10 +3464,13 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !Air {...@@ -3440,10 +3464,13 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !Air {
3440 defer inner_block.instructions.deinit(gpa);3464 defer inner_block.instructions.deinit(gpa);
34413465
3442 // AIR requires the arg parameters to be the first N instructions.3466 // AIR requires the arg parameters to be the first N instructions.
3467 try inner_block.instructions.ensureTotalCapacity(gpa, param_inst_list.len);
3443 for (param_inst_list) |*param_inst, param_index| {3468 for (param_inst_list) |*param_inst, param_index| {
3444 const param_type = fn_ty.fnParamType(param_index);3469 const param_type = fn_ty.fnParamType(param_index);
3445 const ty_ref = try sema.addType(param_type);3470 const ty_ref = try sema.addType(param_type);
3446 param_inst.* = @intCast(u32, sema.air_instructions.len);3471 const arg_index = @intCast(u32, sema.air_instructions.len);
3472 inner_block.instructions.appendAssumeCapacity(arg_index);
3473 param_inst.* = Sema.indexToRef(arg_index);
3447 try sema.air_instructions.append(gpa, .{3474 try sema.air_instructions.append(gpa, .{
3448 .tag = .arg,3475 .tag = .arg,
3449 .data = .{3476 .data = .{
...@@ -3454,7 +3481,6 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !Air {...@@ -3454,7 +3481,6 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !Air {
3454 },3481 },
3455 });3482 });
3456 }3483 }
3457 try inner_block.instructions.appendSlice(gpa, param_inst_list);
34583484
3459 func.state = .in_progress;3485 func.state = .in_progress;
3460 log.debug("set {s} to in_progress", .{decl.name});3486 log.debug("set {s} to in_progress", .{decl.name});
...@@ -4043,13 +4069,11 @@ pub fn floatMul(...@@ -4043,13 +4069,11 @@ pub fn floatMul(
4043}4069}
40444070
4045pub fn simplePtrType(4071pub fn simplePtrType(
4046 mod: *Module,
4047 arena: *Allocator,4072 arena: *Allocator,
4048 elem_ty: Type,4073 elem_ty: Type,
4049 mutable: bool,4074 mutable: bool,
4050 size: std.builtin.TypeInfo.Pointer.Size,4075 size: std.builtin.TypeInfo.Pointer.Size,
4051) Allocator.Error!Type {4076) Allocator.Error!Type {
4052 _ = mod;
4053 if (!mutable and size == .Slice and elem_ty.eql(Type.initTag(.u8))) {4077 if (!mutable and size == .Slice and elem_ty.eql(Type.initTag(.u8))) {
4054 return Type.initTag(.const_slice_u8);4078 return Type.initTag(.const_slice_u8);
4055 }4079 }
src/Sema.zig+556-430
...@@ -36,7 +36,7 @@ func: ?*Module.Fn,...@@ -36,7 +36,7 @@ func: ?*Module.Fn,
36/// > Denormalized data to make `resolveInst` faster. This is 0 if not inside a function,36/// > Denormalized data to make `resolveInst` faster. This is 0 if not inside a function,
37/// > otherwise it is the number of parameters of the function.37/// > otherwise it is the number of parameters of the function.
38/// > param_count: u3238/// > param_count: u32
39param_inst_list: []const Air.Inst.Index,39param_inst_list: []const Air.Inst.Ref,
40branch_quota: u32 = 1000,40branch_quota: u32 = 1000,
41branch_count: u32 = 0,41branch_count: u32 = 0,
42/// This field is updated when a new source location becomes active, so that42/// This field is updated when a new source location becomes active, so that
...@@ -59,8 +59,6 @@ const TypedValue = @import("TypedValue.zig");...@@ -59,8 +59,6 @@ const TypedValue = @import("TypedValue.zig");
59const Air = @import("Air.zig");59const Air = @import("Air.zig");
60const Zir = @import("Zir.zig");60const Zir = @import("Zir.zig");
61const Module = @import("Module.zig");61const Module = @import("Module.zig");
62const Inst = ir.Inst;
63const Body = ir.Body;
64const trace = @import("tracy.zig").trace;62const trace = @import("tracy.zig").trace;
65const Scope = Module.Scope;63const Scope = Module.Scope;
66const InnerError = Module.InnerError;64const InnerError = Module.InnerError;
...@@ -117,7 +115,7 @@ pub fn analyzeFnBody(...@@ -117,7 +115,7 @@ pub fn analyzeFnBody(
117/// Returns only the result from the body that is specified.115/// Returns only the result from the body that is specified.
118/// Only appropriate to call when it is determined at comptime that this body116/// Only appropriate to call when it is determined at comptime that this body
119/// has no peers.117/// has no peers.
120fn resolveBody(sema: *Sema, block: *Scope.Block, body: []const Zir.Inst.Index) InnerError!Air.Inst.Index {118fn resolveBody(sema: *Sema, block: *Scope.Block, body: []const Zir.Inst.Index) InnerError!Air.Inst.Ref {
121 const break_inst = try sema.analyzeBody(block, body);119 const break_inst = try sema.analyzeBody(block, body);
122 const operand_ref = sema.code.instructions.items(.data)[break_inst].@"break".operand;120 const operand_ref = sema.code.instructions.items(.data)[break_inst].@"break".operand;
123 return sema.resolveInst(operand_ref);121 return sema.resolveInst(operand_ref);
...@@ -513,7 +511,7 @@ pub fn analyzeBody(...@@ -513,7 +511,7 @@ pub fn analyzeBody(
513 // const break_inst = try sema.analyzeBody(block, inline_body);511 // const break_inst = try sema.analyzeBody(block, inline_body);
514 // const break_data = datas[break_inst].@"break";512 // const break_data = datas[break_inst].@"break";
515 // if (inst == break_data.block_inst) {513 // if (inst == break_data.block_inst) {
516 // break :blk try sema.resolveInst(break_data.operand);514 // break :blk sema.resolveInst(break_data.operand);
517 // } else {515 // } else {
518 // return break_inst;516 // return break_inst;
519 // }517 // }
...@@ -529,12 +527,12 @@ pub fn analyzeBody(...@@ -529,12 +527,12 @@ pub fn analyzeBody(
529 // const break_inst = try sema.analyzeBody(block, inline_body);527 // const break_inst = try sema.analyzeBody(block, inline_body);
530 // const break_data = datas[break_inst].@"break";528 // const break_data = datas[break_inst].@"break";
531 // if (inst == break_data.block_inst) {529 // if (inst == break_data.block_inst) {
532 // break :blk try sema.resolveInst(break_data.operand);530 // break :blk sema.resolveInst(break_data.operand);
533 // } else {531 // } else {
534 // return break_inst;532 // return break_inst;
535 // }533 // }
536 //},534 //},
537 else => @panic("TODO remove else prong"),535 else => @panic("TODO finish updating Sema for AIR memory layout changes and then remove this else prong"),
538 };536 };
539 if (sema.getAirType(air_inst).isNoReturn())537 if (sema.getAirType(air_inst).isNoReturn())
540 return always_noreturn;538 return always_noreturn;
...@@ -543,7 +541,7 @@ pub fn analyzeBody(...@@ -543,7 +541,7 @@ pub fn analyzeBody(
543 }541 }
544}542}
545543
546fn zirExtended(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {544fn zirExtended(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
547 const extended = sema.code.instructions.items(.data)[inst].extended;545 const extended = sema.code.instructions.items(.data)[inst].extended;
548 switch (extended.opcode) {546 switch (extended.opcode) {
549 // zig fmt: off547 // zig fmt: off
...@@ -598,7 +596,7 @@ fn resolveConstBool(...@@ -598,7 +596,7 @@ fn resolveConstBool(
598 src: LazySrcLoc,596 src: LazySrcLoc,
599 zir_ref: Zir.Inst.Ref,597 zir_ref: Zir.Inst.Ref,
600) !bool {598) !bool {
601 const air_inst = try sema.resolveInst(zir_ref);599 const air_inst = sema.resolveInst(zir_ref);
602 const wanted_type = Type.initTag(.bool);600 const wanted_type = Type.initTag(.bool);
603 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);601 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
604 const val = try sema.resolveConstValue(block, src, coerced_inst);602 const val = try sema.resolveConstValue(block, src, coerced_inst);
...@@ -611,7 +609,7 @@ fn resolveConstString(...@@ -611,7 +609,7 @@ fn resolveConstString(
611 src: LazySrcLoc,609 src: LazySrcLoc,
612 zir_ref: Zir.Inst.Ref,610 zir_ref: Zir.Inst.Ref,
613) ![]u8 {611) ![]u8 {
614 const air_inst = try sema.resolveInst(zir_ref);612 const air_inst = sema.resolveInst(zir_ref);
615 const wanted_type = Type.initTag(.const_slice_u8);613 const wanted_type = Type.initTag(.const_slice_u8);
616 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);614 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
617 const val = try sema.resolveConstValue(block, src, coerced_inst);615 const val = try sema.resolveConstValue(block, src, coerced_inst);
...@@ -619,24 +617,39 @@ fn resolveConstString(...@@ -619,24 +617,39 @@ fn resolveConstString(
619}617}
620618
621pub fn resolveType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type {619pub fn resolveType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type {
622 const air_inst = try sema.resolveInst(zir_ref);620 const air_inst = sema.resolveInst(zir_ref);
623 return sema.resolveAirAsType(block, src, air_inst);621 return sema.resolveAirAsType(block, src, air_inst);
624}622}
625623
626fn resolveAirAsType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, air_inst: Air.Inst.Index) !Type {624fn resolveAirAsType(
625 sema: *Sema,
626 block: *Scope.Block,
627 src: LazySrcLoc,
628 air_inst: Air.Inst.Ref,
629) !Type {
627 const wanted_type = Type.initTag(.@"type");630 const wanted_type = Type.initTag(.@"type");
628 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);631 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
629 const val = try sema.resolveConstValue(block, src, coerced_inst);632 const val = try sema.resolveConstValue(block, src, coerced_inst);
630 return val.toType(sema.arena);633 return val.toType(sema.arena);
631}634}
632635
633fn resolveConstValue(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, base: Air.Inst.Index) !Value {636fn resolveConstValue(
634 return (try sema.resolveDefinedValue(block, src, base)) orelse637 sema: *Sema,
638 block: *Scope.Block,
639 src: LazySrcLoc,
640 air_ref: Air.Inst.Ref,
641) !Value {
642 return (try sema.resolveDefinedValue(block, src, air_ref)) orelse
635 return sema.failWithNeededComptime(block, src);643 return sema.failWithNeededComptime(block, src);
636}644}
637645
638fn resolveDefinedValue(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, base: Air.Inst.Index) !?Value {646fn resolveDefinedValue(
639 if (try sema.resolvePossiblyUndefinedValue(block, src, base)) |val| {647 sema: *Sema,
648 block: *Scope.Block,
649 src: LazySrcLoc,
650 air_ref: Air.Inst.Ref,
651) !?Value {
652 if (try sema.resolvePossiblyUndefinedValue(block, src, air_ref)) |val| {
640 if (val.isUndef()) {653 if (val.isUndef()) {
641 return sema.failWithUseOfUndef(block, src);654 return sema.failWithUseOfUndef(block, src);
642 }655 }
...@@ -649,13 +662,29 @@ fn resolvePossiblyUndefinedValue(...@@ -649,13 +662,29 @@ fn resolvePossiblyUndefinedValue(
649 sema: *Sema,662 sema: *Sema,
650 block: *Scope.Block,663 block: *Scope.Block,
651 src: LazySrcLoc,664 src: LazySrcLoc,
652 base: Air.Inst.Index,665 air_ref: Air.Inst.Ref,
653) !?Value {666) !?Value {
654 if (try sema.typeHasOnePossibleValue(block, src, base.ty)) |opv| {667 const ty = sema.getTypeOfAirRef(air_ref);
668 if (try sema.typeHasOnePossibleValue(block, src, ty)) |opv| {
655 return opv;669 return opv;
656 }670 }
657 const inst = base.castTag(.constant) orelse return null;671 // First section of indexes correspond to a set number of constant values.
658 return inst.val;672 var i: usize = @enumToInt(air_ref);
673 if (i < Air.Inst.Ref.typed_value_map.len) {
674 return Air.Inst.Ref.typed_value_map[i].val;
675 }
676 i -= Air.Inst.Ref.typed_value_map.len;
677
678 switch (sema.air_instructions.items(.tag)[i]) {
679 .constant => {
680 const ty_pl = sema.air_instructions.items(.data)[i].ty_pl;
681 return sema.air_values.items[ty_pl.payload];
682 },
683 .const_ty => {
684 return sema.air_instructions.items(.data)[i].ty.toValue(undefined) catch unreachable;
685 },
686 else => return null,
687 }
659}688}
660689
661fn failWithNeededComptime(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) InnerError {690fn failWithNeededComptime(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) InnerError {
...@@ -677,7 +706,7 @@ fn resolveAlreadyCoercedInt(...@@ -677,7 +706,7 @@ fn resolveAlreadyCoercedInt(
677 comptime Int: type,706 comptime Int: type,
678) !Int {707) !Int {
679 comptime assert(@typeInfo(Int).Int.bits <= 64);708 comptime assert(@typeInfo(Int).Int.bits <= 64);
680 const air_inst = try sema.resolveInst(zir_ref);709 const air_inst = sema.resolveInst(zir_ref);
681 const val = try sema.resolveConstValue(block, src, air_inst);710 const val = try sema.resolveConstValue(block, src, air_inst);
682 switch (@typeInfo(Int).Int.signedness) {711 switch (@typeInfo(Int).Int.signedness) {
683 .signed => return @intCast(Int, val.toSignedInt()),712 .signed => return @intCast(Int, val.toSignedInt()),
...@@ -692,7 +721,7 @@ fn resolveInt(...@@ -692,7 +721,7 @@ fn resolveInt(
692 zir_ref: Zir.Inst.Ref,721 zir_ref: Zir.Inst.Ref,
693 dest_type: Type,722 dest_type: Type,
694) !u64 {723) !u64 {
695 const air_inst = try sema.resolveInst(zir_ref);724 const air_inst = sema.resolveInst(zir_ref);
696 const coerced = try sema.coerce(block, dest_type, air_inst, src);725 const coerced = try sema.coerce(block, dest_type, air_inst, src);
697 const val = try sema.resolveConstValue(block, src, coerced);726 const val = try sema.resolveConstValue(block, src, coerced);
698727
...@@ -705,21 +734,21 @@ pub fn resolveInstConst(...@@ -705,21 +734,21 @@ pub fn resolveInstConst(
705 src: LazySrcLoc,734 src: LazySrcLoc,
706 zir_ref: Zir.Inst.Ref,735 zir_ref: Zir.Inst.Ref,
707) InnerError!TypedValue {736) InnerError!TypedValue {
708 const air_inst = try sema.resolveInst(zir_ref);737 const air_ref = sema.resolveInst(zir_ref);
709 const val = try sema.resolveConstValue(block, src, air_inst);738 const val = try sema.resolveConstValue(block, src, air_ref);
710 return TypedValue{739 return TypedValue{
711 .ty = air_inst.ty,740 .ty = sema.getTypeOfAirRef(air_ref),
712 .val = val,741 .val = val,
713 };742 };
714}743}
715744
716fn zirBitcastResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {745fn zirBitcastResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
717 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;746 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
718 const src = inst_data.src();747 const src = inst_data.src();
719 return sema.mod.fail(&block.base, src, "TODO implement zir_sema.zirBitcastResultPtr", .{});748 return sema.mod.fail(&block.base, src, "TODO implement zir_sema.zirBitcastResultPtr", .{});
720}749}
721750
722fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {751fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
723 _ = inst;752 _ = inst;
724 const tracy = trace(@src());753 const tracy = trace(@src());
725 defer tracy.end();754 defer tracy.end();
...@@ -754,7 +783,7 @@ fn zirStructDecl(...@@ -754,7 +783,7 @@ fn zirStructDecl(
754 block: *Scope.Block,783 block: *Scope.Block,
755 extended: Zir.Inst.Extended.InstData,784 extended: Zir.Inst.Extended.InstData,
756 inst: Zir.Inst.Index,785 inst: Zir.Inst.Index,
757) InnerError!Air.Inst.Index {786) InnerError!Air.Inst.Ref {
758 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);787 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
759 const src: LazySrcLoc = if (small.has_src_node) blk: {788 const src: LazySrcLoc = if (small.has_src_node) blk: {
760 const node_offset = @bitCast(i32, sema.code.extra[extended.operand]);789 const node_offset = @bitCast(i32, sema.code.extra[extended.operand]);
...@@ -825,7 +854,7 @@ fn zirEnumDecl(...@@ -825,7 +854,7 @@ fn zirEnumDecl(
825 sema: *Sema,854 sema: *Sema,
826 block: *Scope.Block,855 block: *Scope.Block,
827 extended: Zir.Inst.Extended.InstData,856 extended: Zir.Inst.Extended.InstData,
828) InnerError!Air.Inst.Index {857) InnerError!Air.Inst.Ref {
829 const tracy = trace(@src());858 const tracy = trace(@src());
830 defer tracy.end();859 defer tracy.end();
831860
...@@ -1022,7 +1051,7 @@ fn zirUnionDecl(...@@ -1022,7 +1051,7 @@ fn zirUnionDecl(
1022 block: *Scope.Block,1051 block: *Scope.Block,
1023 extended: Zir.Inst.Extended.InstData,1052 extended: Zir.Inst.Extended.InstData,
1024 inst: Zir.Inst.Index,1053 inst: Zir.Inst.Index,
1025) InnerError!Air.Inst.Index {1054) InnerError!Air.Inst.Ref {
1026 const tracy = trace(@src());1055 const tracy = trace(@src());
1027 defer tracy.end();1056 defer tracy.end();
10281057
...@@ -1086,7 +1115,7 @@ fn zirOpaqueDecl(...@@ -1086,7 +1115,7 @@ fn zirOpaqueDecl(
1086 block: *Scope.Block,1115 block: *Scope.Block,
1087 inst: Zir.Inst.Index,1116 inst: Zir.Inst.Index,
1088 name_strategy: Zir.Inst.NameStrategy,1117 name_strategy: Zir.Inst.NameStrategy,
1089) InnerError!Air.Inst.Index {1118) InnerError!Air.Inst.Ref {
1090 const tracy = trace(@src());1119 const tracy = trace(@src());
1091 defer tracy.end();1120 defer tracy.end();
10921121
...@@ -1106,7 +1135,7 @@ fn zirErrorSetDecl(...@@ -1106,7 +1135,7 @@ fn zirErrorSetDecl(
1106 block: *Scope.Block,1135 block: *Scope.Block,
1107 inst: Zir.Inst.Index,1136 inst: Zir.Inst.Index,
1108 name_strategy: Zir.Inst.NameStrategy,1137 name_strategy: Zir.Inst.NameStrategy,
1109) InnerError!Air.Inst.Index {1138) InnerError!Air.Inst.Ref {
1110 const tracy = trace(@src());1139 const tracy = trace(@src());
1111 defer tracy.end();1140 defer tracy.end();
11121141
...@@ -1146,7 +1175,7 @@ fn zirRetPtr(...@@ -1146,7 +1175,7 @@ fn zirRetPtr(
1146 sema: *Sema,1175 sema: *Sema,
1147 block: *Scope.Block,1176 block: *Scope.Block,
1148 extended: Zir.Inst.Extended.InstData,1177 extended: Zir.Inst.Extended.InstData,
1149) InnerError!Air.Inst.Index {1178) InnerError!Air.Inst.Ref {
1150 const tracy = trace(@src());1179 const tracy = trace(@src());
1151 defer tracy.end();1180 defer tracy.end();
11521181
...@@ -1154,16 +1183,16 @@ fn zirRetPtr(...@@ -1154,16 +1183,16 @@ fn zirRetPtr(
1154 try sema.requireFunctionBlock(block, src);1183 try sema.requireFunctionBlock(block, src);
1155 const fn_ty = sema.func.?.owner_decl.ty;1184 const fn_ty = sema.func.?.owner_decl.ty;
1156 const ret_type = fn_ty.fnReturnType();1185 const ret_type = fn_ty.fnReturnType();
1157 const ptr_type = try sema.mod.simplePtrType(sema.arena, ret_type, true, .One);1186 const ptr_type = try Module.simplePtrType(sema.arena, ret_type, true, .One);
1158 return block.addNoOp(src, ptr_type, .alloc);1187 return block.addNoOp(src, ptr_type, .alloc);
1159}1188}
11601189
1161fn zirRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {1190fn zirRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
1162 const tracy = trace(@src());1191 const tracy = trace(@src());
1163 defer tracy.end();1192 defer tracy.end();
11641193
1165 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;1194 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
1166 const operand = try sema.resolveInst(inst_data.operand);1195 const operand = sema.resolveInst(inst_data.operand);
1167 return sema.analyzeRef(block, inst_data.src(), operand);1196 return sema.analyzeRef(block, inst_data.src(), operand);
1168}1197}
11691198
...@@ -1171,7 +1200,7 @@ fn zirRetType(...@@ -1171,7 +1200,7 @@ fn zirRetType(
1171 sema: *Sema,1200 sema: *Sema,
1172 block: *Scope.Block,1201 block: *Scope.Block,
1173 extended: Zir.Inst.Extended.InstData,1202 extended: Zir.Inst.Extended.InstData,
1174) InnerError!Air.Inst.Index {1203) InnerError!Air.Inst.Ref {
1175 const tracy = trace(@src());1204 const tracy = trace(@src());
1176 defer tracy.end();1205 defer tracy.end();
11771206
...@@ -1187,7 +1216,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) I...@@ -1187,7 +1216,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) I
1187 defer tracy.end();1216 defer tracy.end();
11881217
1189 const inst_data = sema.code.instructions.items(.data)[inst].un_node;1218 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1190 const operand = try sema.resolveInst(inst_data.operand);1219 const operand = sema.resolveInst(inst_data.operand);
1191 const src = inst_data.src();1220 const src = inst_data.src();
11921221
1193 return sema.ensureResultUsed(block, operand, src);1222 return sema.ensureResultUsed(block, operand, src);
...@@ -1196,7 +1225,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) I...@@ -1196,7 +1225,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) I
1196fn ensureResultUsed(1225fn ensureResultUsed(
1197 sema: *Sema,1226 sema: *Sema,
1198 block: *Scope.Block,1227 block: *Scope.Block,
1199 operand: Air.Inst.Index,1228 operand: Air.Inst.Ref,
1200 src: LazySrcLoc,1229 src: LazySrcLoc,
1201) InnerError!void {1230) InnerError!void {
1202 switch (operand.ty.zigTypeTag()) {1231 switch (operand.ty.zigTypeTag()) {
...@@ -1210,7 +1239,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde...@@ -1210,7 +1239,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
1210 defer tracy.end();1239 defer tracy.end();
12111240
1212 const inst_data = sema.code.instructions.items(.data)[inst].un_node;1241 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1213 const operand = try sema.resolveInst(inst_data.operand);1242 const operand = sema.resolveInst(inst_data.operand);
1214 const src = inst_data.src();1243 const src = inst_data.src();
1215 switch (operand.ty.zigTypeTag()) {1244 switch (operand.ty.zigTypeTag()) {
1216 .ErrorSet, .ErrorUnion => return sema.mod.fail(&block.base, src, "error is discarded", .{}),1245 .ErrorSet, .ErrorUnion => return sema.mod.fail(&block.base, src, "error is discarded", .{}),
...@@ -1218,13 +1247,13 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde...@@ -1218,13 +1247,13 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
1218 }1247 }
1219}1248}
12201249
1221fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {1250fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
1222 const tracy = trace(@src());1251 const tracy = trace(@src());
1223 defer tracy.end();1252 defer tracy.end();
12241253
1225 const inst_data = sema.code.instructions.items(.data)[inst].un_node;1254 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1226 const src = inst_data.src();1255 const src = inst_data.src();
1227 const array_ptr = try sema.resolveInst(inst_data.operand);1256 const array_ptr = sema.resolveInst(inst_data.operand);
12281257
1229 const elem_ty = array_ptr.ty.elemType();1258 const elem_ty = array_ptr.ty.elemType();
1230 if (!elem_ty.isIndexable()) {1259 if (!elem_ty.isIndexable()) {
...@@ -1267,7 +1296,7 @@ fn zirArg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air...@@ -1267,7 +1296,7 @@ fn zirArg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air
12671296
1268 // Set the name of the Air.Arg instruction for use by codegen debug info.1297 // Set the name of the Air.Arg instruction for use by codegen debug info.
1269 const air_arg = sema.param_inst_list[arg_index];1298 const air_arg = sema.param_inst_list[arg_index];
1270 sema.air_instructions.items(.data)[air_arg].ty_str.str = inst_data.start;1299 sema.air_instructions.items(.data)[refToIndex(air_arg).?].ty_str.str = inst_data.start;
1271 return air_arg;1300 return air_arg;
1272}1301}
12731302
...@@ -1275,13 +1304,13 @@ fn zirAllocExtended(...@@ -1275,13 +1304,13 @@ fn zirAllocExtended(
1275 sema: *Sema,1304 sema: *Sema,
1276 block: *Scope.Block,1305 block: *Scope.Block,
1277 extended: Zir.Inst.Extended.InstData,1306 extended: Zir.Inst.Extended.InstData,
1278) InnerError!Air.Inst.Index {1307) InnerError!Air.Inst.Ref {
1279 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);1308 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);
1280 const src: LazySrcLoc = .{ .node_offset = extra.data.src_node };1309 const src: LazySrcLoc = .{ .node_offset = extra.data.src_node };
1281 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocExtended", .{});1310 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocExtended", .{});
1282}1311}
12831312
1284fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {1313fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
1285 const tracy = trace(@src());1314 const tracy = trace(@src());
1286 defer tracy.end();1315 defer tracy.end();
12871316
...@@ -1289,7 +1318,7 @@ fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne...@@ -1289,7 +1318,7 @@ fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
1289 const src = inst_data.src();1318 const src = inst_data.src();
1290 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };1319 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
1291 const var_type = try sema.resolveType(block, ty_src, inst_data.operand);1320 const var_type = try sema.resolveType(block, ty_src, inst_data.operand);
1292 const ptr_type = try sema.mod.simplePtrType(sema.arena, var_type, true, .One);1321 const ptr_type = try Module.simplePtrType(sema.arena, var_type, true, .One);
12931322
1294 const val_payload = try sema.arena.create(Value.Payload.ComptimeAlloc);1323 const val_payload = try sema.arena.create(Value.Payload.ComptimeAlloc);
1295 val_payload.* = .{1324 val_payload.* = .{
...@@ -1304,13 +1333,13 @@ fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne...@@ -1304,13 +1333,13 @@ fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
1304 });1333 });
1305}1334}
13061335
1307fn zirAllocInferredComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {1336fn zirAllocInferredComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
1308 const src_node = sema.code.instructions.items(.data)[inst].node;1337 const src_node = sema.code.instructions.items(.data)[inst].node;
1309 const src: LazySrcLoc = .{ .node_offset = src_node };1338 const src: LazySrcLoc = .{ .node_offset = src_node };
1310 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocInferredComptime", .{});1339 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocInferredComptime", .{});
1311}1340}
13121341
1313fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {1342fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
1314 const tracy = trace(@src());1343 const tracy = trace(@src());
1315 defer tracy.end();1344 defer tracy.end();
13161345
...@@ -1318,12 +1347,12 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!A...@@ -1318,12 +1347,12 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!A
1318 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };1347 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
1319 const var_decl_src = inst_data.src();1348 const var_decl_src = inst_data.src();
1320 const var_type = try sema.resolveType(block, ty_src, inst_data.operand);1349 const var_type = try sema.resolveType(block, ty_src, inst_data.operand);
1321 const ptr_type = try sema.mod.simplePtrType(sema.arena, var_type, true, .One);1350 const ptr_type = try Module.simplePtrType(sema.arena, var_type, true, .One);
1322 try sema.requireRuntimeBlock(block, var_decl_src);1351 try sema.requireRuntimeBlock(block, var_decl_src);
1323 return block.addNoOp(var_decl_src, ptr_type, .alloc);1352 return block.addNoOp(var_decl_src, ptr_type, .alloc);
1324}1353}
13251354
1326fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {1355fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
1327 const tracy = trace(@src());1356 const tracy = trace(@src());
1328 defer tracy.end();1357 defer tracy.end();
13291358
...@@ -1332,7 +1361,7 @@ fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -1332,7 +1361,7 @@ fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
1332 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };1361 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
1333 const var_type = try sema.resolveType(block, ty_src, inst_data.operand);1362 const var_type = try sema.resolveType(block, ty_src, inst_data.operand);
1334 try sema.validateVarType(block, ty_src, var_type);1363 try sema.validateVarType(block, ty_src, var_type);
1335 const ptr_type = try sema.mod.simplePtrType(sema.arena, var_type, true, .One);1364 const ptr_type = try Module.simplePtrType(sema.arena, var_type, true, .One);
1336 try sema.requireRuntimeBlock(block, var_decl_src);1365 try sema.requireRuntimeBlock(block, var_decl_src);
1337 return block.addNoOp(var_decl_src, ptr_type, .alloc);1366 return block.addNoOp(var_decl_src, ptr_type, .alloc);
1338}1367}
...@@ -1342,7 +1371,7 @@ fn zirAllocInferred(...@@ -1342,7 +1371,7 @@ fn zirAllocInferred(
1342 block: *Scope.Block,1371 block: *Scope.Block,
1343 inst: Zir.Inst.Index,1372 inst: Zir.Inst.Index,
1344 inferred_alloc_ty: Type,1373 inferred_alloc_ty: Type,
1345) InnerError!Air.Inst.Index {1374) InnerError!Air.Inst.Ref {
1346 const tracy = trace(@src());1375 const tracy = trace(@src());
1347 defer tracy.end();1376 defer tracy.end();
13481377
...@@ -1372,7 +1401,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde...@@ -1372,7 +1401,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
13721401
1373 const inst_data = sema.code.instructions.items(.data)[inst].un_node;1402 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1374 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };1403 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
1375 const ptr = try sema.resolveInst(inst_data.operand);1404 const ptr = sema.resolveInst(inst_data.operand);
1376 const ptr_val = ptr.castTag(.constant).?.val;1405 const ptr_val = ptr.castTag(.constant).?.val;
1377 const inferred_alloc = ptr_val.castTag(.inferred_alloc).?;1406 const inferred_alloc = ptr_val.castTag(.inferred_alloc).?;
1378 const peer_inst_list = inferred_alloc.data.stored_inst_list.items;1407 const peer_inst_list = inferred_alloc.data.stored_inst_list.items;
...@@ -1385,7 +1414,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde...@@ -1385,7 +1414,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
1385 if (var_is_mut) {1414 if (var_is_mut) {
1386 try sema.validateVarType(block, ty_src, final_elem_ty);1415 try sema.validateVarType(block, ty_src, final_elem_ty);
1387 }1416 }
1388 const final_ptr_ty = try sema.mod.simplePtrType(sema.arena, final_elem_ty, true, .One);1417 const final_ptr_ty = try Module.simplePtrType(sema.arena, final_elem_ty, true, .One);
13891418
1390 // Change it to a normal alloc.1419 // Change it to a normal alloc.
1391 ptr.ty = final_ptr_ty;1420 ptr.ty = final_ptr_ty;
...@@ -1406,7 +1435,7 @@ fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Ind...@@ -1406,7 +1435,7 @@ fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Ind
1406 const struct_obj: *Module.Struct = s: {1435 const struct_obj: *Module.Struct = s: {
1407 const field_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node;1436 const field_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node;
1408 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;1437 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
1409 const object_ptr = try sema.resolveInst(field_ptr_extra.lhs);1438 const object_ptr = sema.resolveInst(field_ptr_extra.lhs);
1410 break :s object_ptr.ty.elemType().castTag(.@"struct").?.data;1439 break :s object_ptr.ty.elemType().castTag(.@"struct").?.data;
1411 };1440 };
14121441
...@@ -1535,9 +1564,9 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In...@@ -1535,9 +1564,9 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In
1535 // to omit it.1564 // to omit it.
1536 return;1565 return;
1537 }1566 }
1538 const ptr = try sema.resolveInst(bin_inst.lhs);1567 const ptr = sema.resolveInst(bin_inst.lhs);
1539 const value = try sema.resolveInst(bin_inst.rhs);1568 const value = sema.resolveInst(bin_inst.rhs);
1540 const ptr_ty = try sema.mod.simplePtrType(sema.arena, value.ty, true, .One);1569 const ptr_ty = try Module.simplePtrType(sema.arena, value.ty, true, .One);
1541 // TODO detect when this store should be done at compile-time. For example,1570 // TODO detect when this store should be done at compile-time. For example,
1542 // if expressions should force it when the condition is compile-time known.1571 // if expressions should force it when the condition is compile-time known.
1543 const src: LazySrcLoc = .unneeded;1572 const src: LazySrcLoc = .unneeded;
...@@ -1552,14 +1581,14 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)...@@ -1552,14 +1581,14 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)
15521581
1553 const src: LazySrcLoc = .unneeded;1582 const src: LazySrcLoc = .unneeded;
1554 const bin_inst = sema.code.instructions.items(.data)[inst].bin;1583 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
1555 const ptr = try sema.resolveInst(bin_inst.lhs);1584 const ptr = sema.resolveInst(bin_inst.lhs);
1556 const value = try sema.resolveInst(bin_inst.rhs);1585 const value = sema.resolveInst(bin_inst.rhs);
1557 const inferred_alloc = ptr.castTag(.constant).?.val.castTag(.inferred_alloc).?;1586 const inferred_alloc = ptr.castTag(.constant).?.val.castTag(.inferred_alloc).?;
1558 // Add the stored instruction to the set we will use to resolve peer types1587 // Add the stored instruction to the set we will use to resolve peer types
1559 // for the inferred allocation.1588 // for the inferred allocation.
1560 try inferred_alloc.data.stored_inst_list.append(sema.arena, value);1589 try inferred_alloc.data.stored_inst_list.append(sema.arena, value);
1561 // Create a runtime bitcast instruction with exactly the type the pointer wants.1590 // Create a runtime bitcast instruction with exactly the type the pointer wants.
1562 const ptr_ty = try sema.mod.simplePtrType(sema.arena, value.ty, true, .One);1591 const ptr_ty = try Module.simplePtrType(sema.arena, value.ty, true, .One);
1563 try sema.requireRuntimeBlock(block, src);1592 try sema.requireRuntimeBlock(block, src);
1564 const bitcasted_ptr = try block.addUnOp(src, ptr_ty, .bitcast, ptr);1593 const bitcasted_ptr = try block.addUnOp(src, ptr_ty, .bitcast, ptr);
1565 return sema.storePtr(block, src, bitcasted_ptr, value);1594 return sema.storePtr(block, src, bitcasted_ptr, value);
...@@ -1578,8 +1607,8 @@ fn zirStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!v...@@ -1578,8 +1607,8 @@ fn zirStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!v
1578 defer tracy.end();1607 defer tracy.end();
15791608
1580 const bin_inst = sema.code.instructions.items(.data)[inst].bin;1609 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
1581 const ptr = try sema.resolveInst(bin_inst.lhs);1610 const ptr = sema.resolveInst(bin_inst.lhs);
1582 const value = try sema.resolveInst(bin_inst.rhs);1611 const value = sema.resolveInst(bin_inst.rhs);
1583 return sema.storePtr(block, sema.src, ptr, value);1612 return sema.storePtr(block, sema.src, ptr, value);
1584}1613}
15851614
...@@ -1590,18 +1619,18 @@ fn zirStoreNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr...@@ -1590,18 +1619,18 @@ fn zirStoreNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
1590 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1619 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1591 const src = inst_data.src();1620 const src = inst_data.src();
1592 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;1621 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1593 const ptr = try sema.resolveInst(extra.lhs);1622 const ptr = sema.resolveInst(extra.lhs);
1594 const value = try sema.resolveInst(extra.rhs);1623 const value = sema.resolveInst(extra.rhs);
1595 return sema.storePtr(block, src, ptr, value);1624 return sema.storePtr(block, src, ptr, value);
1596}1625}
15971626
1598fn zirParamType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {1627fn zirParamType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
1599 const tracy = trace(@src());1628 const tracy = trace(@src());
1600 defer tracy.end();1629 defer tracy.end();
16011630
1602 const src: LazySrcLoc = .unneeded;1631 const src: LazySrcLoc = .unneeded;
1603 const inst_data = sema.code.instructions.items(.data)[inst].param_type;1632 const inst_data = sema.code.instructions.items(.data)[inst].param_type;
1604 const fn_inst = try sema.resolveInst(inst_data.callee);1633 const fn_inst = sema.resolveInst(inst_data.callee);
1605 const param_index = inst_data.param_index;1634 const param_index = inst_data.param_index;
16061635
1607 const fn_ty: Type = switch (fn_inst.ty.zigTypeTag()) {1636 const fn_ty: Type = switch (fn_inst.ty.zigTypeTag()) {
...@@ -1631,7 +1660,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr...@@ -1631,7 +1660,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
1631 return sema.mod.constType(sema.arena, src, param_type);1660 return sema.mod.constType(sema.arena, src, param_type);
1632}1661}
16331662
1634fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {1663fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
1635 const tracy = trace(@src());1664 const tracy = trace(@src());
1636 defer tracy.end();1665 defer tracy.end();
16371666
...@@ -1659,7 +1688,7 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air...@@ -1659,7 +1688,7 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air
1659 return sema.analyzeDeclRef(block, .unneeded, new_decl);1688 return sema.analyzeDeclRef(block, .unneeded, new_decl);
1660}1689}
16611690
1662fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {1691fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
1663 _ = block;1692 _ = block;
1664 const tracy = trace(@src());1693 const tracy = trace(@src());
1665 defer tracy.end();1694 defer tracy.end();
...@@ -1668,7 +1697,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air...@@ -1668,7 +1697,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air
1668 return sema.mod.constIntUnsigned(sema.arena, .unneeded, Type.initTag(.comptime_int), int);1697 return sema.mod.constIntUnsigned(sema.arena, .unneeded, Type.initTag(.comptime_int), int);
1669}1698}
16701699
1671fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {1700fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
1672 _ = block;1701 _ = block;
1673 const tracy = trace(@src());1702 const tracy = trace(@src());
1674 defer tracy.end();1703 defer tracy.end();
...@@ -1686,7 +1715,7 @@ fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!...@@ -1686,7 +1715,7 @@ fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
1686 });1715 });
1687}1716}
16881717
1689fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {1718fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
1690 _ = block;1719 _ = block;
1691 const arena = sema.arena;1720 const arena = sema.arena;
1692 const inst_data = sema.code.instructions.items(.data)[inst].float;1721 const inst_data = sema.code.instructions.items(.data)[inst].float;
...@@ -1699,7 +1728,7 @@ fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!A...@@ -1699,7 +1728,7 @@ fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!A
1699 });1728 });
1700}1729}
17011730
1702fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {1731fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
1703 _ = block;1732 _ = block;
1704 const arena = sema.arena;1733 const arena = sema.arena;
1705 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1734 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
...@@ -1728,7 +1757,7 @@ fn zirCompileLog(...@@ -1728,7 +1757,7 @@ fn zirCompileLog(
1728 sema: *Sema,1757 sema: *Sema,
1729 block: *Scope.Block,1758 block: *Scope.Block,
1730 extended: Zir.Inst.Extended.InstData,1759 extended: Zir.Inst.Extended.InstData,
1731) InnerError!Air.Inst.Index {1760) InnerError!Air.Inst.Ref {
1732 var managed = sema.mod.compile_log_text.toManaged(sema.gpa);1761 var managed = sema.mod.compile_log_text.toManaged(sema.gpa);
1733 defer sema.mod.compile_log_text = managed.moveToUnmanaged();1762 defer sema.mod.compile_log_text = managed.moveToUnmanaged();
1734 const writer = managed.writer();1763 const writer = managed.writer();
...@@ -1741,7 +1770,7 @@ fn zirCompileLog(...@@ -1741,7 +1770,7 @@ fn zirCompileLog(
1741 for (args) |arg_ref, i| {1770 for (args) |arg_ref, i| {
1742 if (i != 0) try writer.print(", ", .{});1771 if (i != 0) try writer.print(", ", .{});
17431772
1744 const arg = try sema.resolveInst(arg_ref);1773 const arg = sema.resolveInst(arg_ref);
1745 if (try sema.resolvePossiblyUndefinedValue(block, src, arg)) |val| {1774 if (try sema.resolvePossiblyUndefinedValue(block, src, arg)) |val| {
1746 try writer.print("@as({}, {})", .{ arg.ty, val });1775 try writer.print("@as({}, {})", .{ arg.ty, val });
1747 } else {1776 } else {
...@@ -1773,12 +1802,12 @@ fn zirRepeat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!...@@ -1773,12 +1802,12 @@ fn zirRepeat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
1773fn zirPanic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Zir.Inst.Index {1802fn zirPanic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Zir.Inst.Index {
1774 const inst_data = sema.code.instructions.items(.data)[inst].un_node;1803 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1775 const src: LazySrcLoc = inst_data.src();1804 const src: LazySrcLoc = inst_data.src();
1776 const msg_inst = try sema.resolveInst(inst_data.operand);1805 const msg_inst = sema.resolveInst(inst_data.operand);
17771806
1778 return sema.panicWithMsg(block, src, msg_inst);1807 return sema.panicWithMsg(block, src, msg_inst);
1779}1808}
17801809
1781fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {1810fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
1782 const tracy = trace(@src());1811 const tracy = trace(@src());
1783 defer tracy.end();1812 defer tracy.end();
17841813
...@@ -1843,7 +1872,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerE...@@ -1843,7 +1872,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerE
1843 return sema.analyzeBlockBody(parent_block, src, &child_block, merges);1872 return sema.analyzeBlockBody(parent_block, src, &child_block, merges);
1844}1873}
18451874
1846fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {1875fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
1847 const tracy = trace(@src());1876 const tracy = trace(@src());
1848 defer tracy.end();1877 defer tracy.end();
18491878
...@@ -1853,13 +1882,13 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Inn...@@ -1853,13 +1882,13 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Inn
1853 return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirCImport", .{});1882 return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirCImport", .{});
1854}1883}
18551884
1856fn zirSuspendBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {1885fn zirSuspendBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
1857 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1886 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1858 const src = inst_data.src();1887 const src = inst_data.src();
1859 return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirSuspendBlock", .{});1888 return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirSuspendBlock", .{});
1860}1889}
18611890
1862fn zirBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {1891fn zirBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
1863 const tracy = trace(@src());1892 const tracy = trace(@src());
1864 defer tracy.end();1893 defer tracy.end();
18651894
...@@ -1917,7 +1946,7 @@ fn resolveBlockBody(...@@ -1917,7 +1946,7 @@ fn resolveBlockBody(
1917 child_block: *Scope.Block,1946 child_block: *Scope.Block,
1918 body: []const Zir.Inst.Index,1947 body: []const Zir.Inst.Index,
1919 merges: *Scope.Block.Merges,1948 merges: *Scope.Block.Merges,
1920) InnerError!Air.Inst.Index {1949) InnerError!Air.Inst.Ref {
1921 _ = try sema.analyzeBody(child_block, body);1950 _ = try sema.analyzeBody(child_block, body);
1922 return sema.analyzeBlockBody(parent_block, src, child_block, merges);1951 return sema.analyzeBlockBody(parent_block, src, child_block, merges);
1923}1952}
...@@ -1928,7 +1957,7 @@ fn analyzeBlockBody(...@@ -1928,7 +1957,7 @@ fn analyzeBlockBody(
1928 src: LazySrcLoc,1957 src: LazySrcLoc,
1929 child_block: *Scope.Block,1958 child_block: *Scope.Block,
1930 merges: *Scope.Block.Merges,1959 merges: *Scope.Block.Merges,
1931) InnerError!Air.Inst.Index {1960) InnerError!Air.Inst.Ref {
1932 const tracy = trace(@src());1961 const tracy = trace(@src());
1933 defer tracy.end();1962 defer tracy.end();
19341963
...@@ -2088,7 +2117,7 @@ fn zirBreak(sema: *Sema, start_block: *Scope.Block, inst: Zir.Inst.Index) InnerE...@@ -2088,7 +2117,7 @@ fn zirBreak(sema: *Sema, start_block: *Scope.Block, inst: Zir.Inst.Index) InnerE
20882117
2089 const inst_data = sema.code.instructions.items(.data)[inst].@"break";2118 const inst_data = sema.code.instructions.items(.data)[inst].@"break";
2090 const src = sema.src;2119 const src = sema.src;
2091 const operand = try sema.resolveInst(inst_data.operand);2120 const operand = sema.resolveInst(inst_data.operand);
2092 const zir_block = inst_data.block_inst;2121 const zir_block = inst_data.block_inst;
20932122
2094 var block = start_block;2123 var block = start_block;
...@@ -2136,7 +2165,7 @@ fn zirDbgStmt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -2136,7 +2165,7 @@ fn zirDbgStmt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
2136 _ = try block.addDbgStmt(.unneeded, inst_data.line, inst_data.column);2165 _ = try block.addDbgStmt(.unneeded, inst_data.line, inst_data.column);
2137}2166}
21382167
2139fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2168fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2140 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;2169 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
2141 const src = inst_data.src();2170 const src = inst_data.src();
2142 const decl_name = inst_data.get(sema.code);2171 const decl_name = inst_data.get(sema.code);
...@@ -2144,7 +2173,7 @@ fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -2144,7 +2173,7 @@ fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
2144 return sema.analyzeDeclRef(block, src, decl);2173 return sema.analyzeDeclRef(block, src, decl);
2145}2174}
21462175
2147fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2176fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2148 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;2177 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
2149 const src = inst_data.src();2178 const src = inst_data.src();
2150 const decl_name = inst_data.get(sema.code);2179 const decl_name = inst_data.get(sema.code);
...@@ -2198,7 +2227,7 @@ fn zirCall(...@@ -2198,7 +2227,7 @@ fn zirCall(
2198 inst: Zir.Inst.Index,2227 inst: Zir.Inst.Index,
2199 modifier: std.builtin.CallOptions.Modifier,2228 modifier: std.builtin.CallOptions.Modifier,
2200 ensure_result_used: bool,2229 ensure_result_used: bool,
2201) InnerError!Air.Inst.Index {2230) InnerError!Air.Inst.Ref {
2202 const tracy = trace(@src());2231 const tracy = trace(@src());
2203 defer tracy.end();2232 defer tracy.end();
22042233
...@@ -2208,12 +2237,12 @@ fn zirCall(...@@ -2208,12 +2237,12 @@ fn zirCall(
2208 const extra = sema.code.extraData(Zir.Inst.Call, inst_data.payload_index);2237 const extra = sema.code.extraData(Zir.Inst.Call, inst_data.payload_index);
2209 const args = sema.code.refSlice(extra.end, extra.data.args_len);2238 const args = sema.code.refSlice(extra.end, extra.data.args_len);
22102239
2211 const func = try sema.resolveInst(extra.data.callee);2240 const func = sema.resolveInst(extra.data.callee);
2212 // TODO handle function calls of generic functions2241 // TODO handle function calls of generic functions
2213 const resolved_args = try sema.arena.alloc(Air.Inst.Index, args.len);2242 const resolved_args = try sema.arena.alloc(Air.Inst.Ref, args.len);
2214 for (args) |zir_arg, i| {2243 for (args) |zir_arg, i| {
2215 // the args are already casted to the result of a param type instruction.2244 // the args are already casted to the result of a param type instruction.
2216 resolved_args[i] = try sema.resolveInst(zir_arg);2245 resolved_args[i] = sema.resolveInst(zir_arg);
2217 }2246 }
22182247
2219 return sema.analyzeCall(block, func, func_src, call_src, modifier, ensure_result_used, resolved_args);2248 return sema.analyzeCall(block, func, func_src, call_src, modifier, ensure_result_used, resolved_args);
...@@ -2222,13 +2251,13 @@ fn zirCall(...@@ -2222,13 +2251,13 @@ fn zirCall(
2222fn analyzeCall(2251fn analyzeCall(
2223 sema: *Sema,2252 sema: *Sema,
2224 block: *Scope.Block,2253 block: *Scope.Block,
2225 func: Air.Inst.Index,2254 func: Air.Inst.Ref,
2226 func_src: LazySrcLoc,2255 func_src: LazySrcLoc,
2227 call_src: LazySrcLoc,2256 call_src: LazySrcLoc,
2228 modifier: std.builtin.CallOptions.Modifier,2257 modifier: std.builtin.CallOptions.Modifier,
2229 ensure_result_used: bool,2258 ensure_result_used: bool,
2230 args: []const Air.Inst.Index,2259 args: []const Air.Inst.Ref,
2231) InnerError!Air.Inst.Index {2260) InnerError!Air.Inst.Ref {
2232 if (func.ty.zigTypeTag() != .Fn)2261 if (func.ty.zigTypeTag() != .Fn)
2233 return sema.mod.fail(&block.base, func_src, "type '{}' not a function", .{func.ty});2262 return sema.mod.fail(&block.base, func_src, "type '{}' not a function", .{func.ty});
22342263
...@@ -2285,7 +2314,7 @@ fn analyzeCall(...@@ -2285,7 +2314,7 @@ fn analyzeCall(
2285 const is_comptime_call = block.is_comptime or modifier == .compile_time;2314 const is_comptime_call = block.is_comptime or modifier == .compile_time;
2286 const is_inline_call = is_comptime_call or modifier == .always_inline or2315 const is_inline_call = is_comptime_call or modifier == .always_inline or
2287 func.ty.fnCallingConvention() == .Inline;2316 func.ty.fnCallingConvention() == .Inline;
2288 const result: Air.Inst.Index = if (is_inline_call) res: {2317 const result: Air.Inst.Ref = if (is_inline_call) res: {
2289 const func_val = try sema.resolveConstValue(block, func_src, func);2318 const func_val = try sema.resolveConstValue(block, func_src, func);
2290 const module_fn = switch (func_val.tag()) {2319 const module_fn = switch (func_val.tag()) {
2291 .function => func_val.castTag(.function).?.data,2320 .function => func_val.castTag(.function).?.data,
...@@ -2383,7 +2412,7 @@ fn analyzeCall(...@@ -2383,7 +2412,7 @@ fn analyzeCall(
2383 return result;2412 return result;
2384}2413}
23852414
2386fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2415fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2387 _ = block;2416 _ = block;
2388 const tracy = trace(@src());2417 const tracy = trace(@src());
2389 defer tracy.end();2418 defer tracy.end();
...@@ -2395,7 +2424,7 @@ fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -2395,7 +2424,7 @@ fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
2395 return sema.mod.constType(sema.arena, src, ty);2424 return sema.mod.constType(sema.arena, src, ty);
2396}2425}
23972426
2398fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2427fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2399 const tracy = trace(@src());2428 const tracy = trace(@src());
2400 defer tracy.end();2429 defer tracy.end();
24012430
...@@ -2407,7 +2436,7 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner...@@ -2407,7 +2436,7 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner
2407 return sema.mod.constType(sema.arena, src, opt_type);2436 return sema.mod.constType(sema.arena, src, opt_type);
2408}2437}
24092438
2410fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2439fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2411 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2440 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2412 const src = inst_data.src();2441 const src = inst_data.src();
2413 const array_type = try sema.resolveType(block, src, inst_data.operand);2442 const array_type = try sema.resolveType(block, src, inst_data.operand);
...@@ -2415,7 +2444,7 @@ fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -2415,7 +2444,7 @@ fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
2415 return sema.mod.constType(sema.arena, src, elem_type);2444 return sema.mod.constType(sema.arena, src, elem_type);
2416}2445}
24172446
2418fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2447fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2419 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2448 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2420 const src = inst_data.src();2449 const src = inst_data.src();
2421 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };2450 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
...@@ -2430,7 +2459,7 @@ fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr...@@ -2430,7 +2459,7 @@ fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
2430 return sema.mod.constType(sema.arena, src, vector_type);2459 return sema.mod.constType(sema.arena, src, vector_type);
2431}2460}
24322461
2433fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2462fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2434 const tracy = trace(@src());2463 const tracy = trace(@src());
2435 defer tracy.end();2464 defer tracy.end();
24362465
...@@ -2443,7 +2472,7 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr...@@ -2443,7 +2472,7 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
2443 return sema.mod.constType(sema.arena, .unneeded, array_ty);2472 return sema.mod.constType(sema.arena, .unneeded, array_ty);
2444}2473}
24452474
2446fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2475fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2447 const tracy = trace(@src());2476 const tracy = trace(@src());
2448 defer tracy.end();2477 defer tracy.end();
24492478
...@@ -2458,7 +2487,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)...@@ -2458,7 +2487,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)
2458 return sema.mod.constType(sema.arena, .unneeded, array_ty);2487 return sema.mod.constType(sema.arena, .unneeded, array_ty);
2459}2488}
24602489
2461fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2490fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2462 const tracy = trace(@src());2491 const tracy = trace(@src());
2463 defer tracy.end();2492 defer tracy.end();
24642493
...@@ -2471,7 +2500,7 @@ fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner...@@ -2471,7 +2500,7 @@ fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner
2471 return sema.mod.constType(sema.arena, src, anyframe_type);2500 return sema.mod.constType(sema.arena, src, anyframe_type);
2472}2501}
24732502
2474fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2503fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2475 const tracy = trace(@src());2504 const tracy = trace(@src());
2476 defer tracy.end();2505 defer tracy.end();
24772506
...@@ -2492,7 +2521,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn...@@ -2492,7 +2521,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn
2492 return sema.mod.constType(sema.arena, src, err_union_ty);2521 return sema.mod.constType(sema.arena, src, err_union_ty);
2493}2522}
24942523
2495fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2524fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2496 _ = block;2525 _ = block;
2497 const tracy = trace(@src());2526 const tracy = trace(@src());
2498 defer tracy.end();2527 defer tracy.end();
...@@ -2511,14 +2540,14 @@ fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr...@@ -2511,14 +2540,14 @@ fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
2511 });2540 });
2512}2541}
25132542
2514fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2543fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2515 const tracy = trace(@src());2544 const tracy = trace(@src());
2516 defer tracy.end();2545 defer tracy.end();
25172546
2518 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2547 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2519 const src = inst_data.src();2548 const src = inst_data.src();
2520 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };2549 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2521 const op = try sema.resolveInst(inst_data.operand);2550 const op = sema.resolveInst(inst_data.operand);
2522 const op_coerced = try sema.coerce(block, Type.initTag(.anyerror), op, operand_src);2551 const op_coerced = try sema.coerce(block, Type.initTag(.anyerror), op, operand_src);
2523 const result_ty = Type.initTag(.u16);2552 const result_ty = Type.initTag(.u16);
25242553
...@@ -2541,7 +2570,7 @@ fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr...@@ -2541,7 +2570,7 @@ fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
2541 return block.addUnOp(src, result_ty, .bitcast, op_coerced);2570 return block.addUnOp(src, result_ty, .bitcast, op_coerced);
2542}2571}
25432572
2544fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2573fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2545 const tracy = trace(@src());2574 const tracy = trace(@src());
2546 defer tracy.end();2575 defer tracy.end();
25472576
...@@ -2549,7 +2578,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr...@@ -2549,7 +2578,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
2549 const src = inst_data.src();2578 const src = inst_data.src();
2550 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };2579 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
25512580
2552 const op = try sema.resolveInst(inst_data.operand);2581 const op = sema.resolveInst(inst_data.operand);
25532582
2554 if (try sema.resolveDefinedValue(block, operand_src, op)) |value| {2583 if (try sema.resolveDefinedValue(block, operand_src, op)) |value| {
2555 const int = value.toUnsignedInt();2584 const int = value.toUnsignedInt();
...@@ -2574,7 +2603,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr...@@ -2574,7 +2603,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
2574 return block.addUnOp(src, Type.initTag(.anyerror), .bitcast, op);2603 return block.addUnOp(src, Type.initTag(.anyerror), .bitcast, op);
2575}2604}
25762605
2577fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2606fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2578 const tracy = trace(@src());2607 const tracy = trace(@src());
2579 defer tracy.end();2608 defer tracy.end();
25802609
...@@ -2583,8 +2612,8 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn...@@ -2583,8 +2612,8 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn
2583 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };2612 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
2584 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };2613 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
2585 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };2614 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
2586 const lhs = try sema.resolveInst(extra.lhs);2615 const lhs = sema.resolveInst(extra.lhs);
2587 const rhs = try sema.resolveInst(extra.rhs);2616 const rhs = sema.resolveInst(extra.rhs);
2588 if (rhs.ty.zigTypeTag() == .Bool and lhs.ty.zigTypeTag() == .Bool) {2617 if (rhs.ty.zigTypeTag() == .Bool and lhs.ty.zigTypeTag() == .Bool) {
2589 const msg = msg: {2618 const msg = msg: {
2590 const msg = try sema.mod.errMsg(&block.base, lhs_src, "expected error set type, found 'bool'", .{});2619 const msg = try sema.mod.errMsg(&block.base, lhs_src, "expected error set type, found 'bool'", .{});
...@@ -2664,7 +2693,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn...@@ -2664,7 +2693,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn
2664 });2693 });
2665}2694}
26662695
2667fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2696fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2668 _ = block;2697 _ = block;
2669 const tracy = trace(@src());2698 const tracy = trace(@src());
2670 defer tracy.end();2699 defer tracy.end();
...@@ -2678,15 +2707,15 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE...@@ -2678,15 +2707,15 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE
2678 });2707 });
2679}2708}
26802709
2681fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2710fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2682 const mod = sema.mod;2711 const mod = sema.mod;
2683 const arena = sema.arena;2712 const arena = sema.arena;
2684 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2713 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2685 const src = inst_data.src();2714 const src = inst_data.src();
2686 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };2715 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2687 const operand = try sema.resolveInst(inst_data.operand);2716 const operand = sema.resolveInst(inst_data.operand);
26882717
2689 const enum_tag: Air.Inst.Index = switch (operand.ty.zigTypeTag()) {2718 const enum_tag: Air.Inst.Ref = switch (operand.ty.zigTypeTag()) {
2690 .Enum => operand,2719 .Enum => operand,
2691 .Union => {2720 .Union => {
2692 //if (!operand.ty.unionHasTag()) {2721 //if (!operand.ty.unionHasTag()) {
...@@ -2760,7 +2789,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr...@@ -2760,7 +2789,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
2760 return block.addUnOp(src, int_tag_ty, .bitcast, enum_tag);2789 return block.addUnOp(src, int_tag_ty, .bitcast, enum_tag);
2761}2790}
27622791
2763fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {2792fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2764 const mod = sema.mod;2793 const mod = sema.mod;
2765 const target = mod.getTarget();2794 const target = mod.getTarget();
2766 const arena = sema.arena;2795 const arena = sema.arena;
...@@ -2770,7 +2799,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr...@@ -2770,7 +2799,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
2770 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };2799 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2771 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };2800 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
2772 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);2801 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
2773 const operand = try sema.resolveInst(extra.rhs);2802 const operand = sema.resolveInst(extra.rhs);
27742803
2775 if (dest_ty.zigTypeTag() != .Enum) {2804 if (dest_ty.zigTypeTag() != .Enum) {
2776 return mod.fail(&block.base, dest_ty_src, "expected enum, found {}", .{dest_ty});2805 return mod.fail(&block.base, dest_ty_src, "expected enum, found {}", .{dest_ty});
...@@ -2821,12 +2850,12 @@ fn zirOptionalPayloadPtr(...@@ -2821,12 +2850,12 @@ fn zirOptionalPayloadPtr(
2821 block: *Scope.Block,2850 block: *Scope.Block,
2822 inst: Zir.Inst.Index,2851 inst: Zir.Inst.Index,
2823 safety_check: bool,2852 safety_check: bool,
2824) InnerError!Air.Inst.Index {2853) InnerError!Air.Inst.Ref {
2825 const tracy = trace(@src());2854 const tracy = trace(@src());
2826 defer tracy.end();2855 defer tracy.end();
28272856
2828 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2857 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2829 const optional_ptr = try sema.resolveInst(inst_data.operand);2858 const optional_ptr = sema.resolveInst(inst_data.operand);
2830 assert(optional_ptr.ty.zigTypeTag() == .Pointer);2859 assert(optional_ptr.ty.zigTypeTag() == .Pointer);
2831 const src = inst_data.src();2860 const src = inst_data.src();
28322861
...@@ -2836,7 +2865,7 @@ fn zirOptionalPayloadPtr(...@@ -2836,7 +2865,7 @@ fn zirOptionalPayloadPtr(
2836 }2865 }
28372866
2838 const child_type = try opt_type.optionalChildAlloc(sema.arena);2867 const child_type = try opt_type.optionalChildAlloc(sema.arena);
2839 const child_pointer = try sema.mod.simplePtrType(sema.arena, child_type, !optional_ptr.ty.isConstPtr(), .One);2868 const child_pointer = try Module.simplePtrType(sema.arena, child_type, !optional_ptr.ty.isConstPtr(), .One);
28402869
2841 if (optional_ptr.value()) |pointer_val| {2870 if (optional_ptr.value()) |pointer_val| {
2842 const val = try pointer_val.pointerDeref(sema.arena);2871 const val = try pointer_val.pointerDeref(sema.arena);
...@@ -2864,13 +2893,13 @@ fn zirOptionalPayload(...@@ -2864,13 +2893,13 @@ fn zirOptionalPayload(
2864 block: *Scope.Block,2893 block: *Scope.Block,
2865 inst: Zir.Inst.Index,2894 inst: Zir.Inst.Index,
2866 safety_check: bool,2895 safety_check: bool,
2867) InnerError!Air.Inst.Index {2896) InnerError!Air.Inst.Ref {
2868 const tracy = trace(@src());2897 const tracy = trace(@src());
2869 defer tracy.end();2898 defer tracy.end();
28702899
2871 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2900 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2872 const src = inst_data.src();2901 const src = inst_data.src();
2873 const operand = try sema.resolveInst(inst_data.operand);2902 const operand = sema.resolveInst(inst_data.operand);
2874 const opt_type = operand.ty;2903 const opt_type = operand.ty;
2875 if (opt_type.zigTypeTag() != .Optional) {2904 if (opt_type.zigTypeTag() != .Optional) {
2876 return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type});2905 return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type});
...@@ -2902,13 +2931,13 @@ fn zirErrUnionPayload(...@@ -2902,13 +2931,13 @@ fn zirErrUnionPayload(
2902 block: *Scope.Block,2931 block: *Scope.Block,
2903 inst: Zir.Inst.Index,2932 inst: Zir.Inst.Index,
2904 safety_check: bool,2933 safety_check: bool,
2905) InnerError!Air.Inst.Index {2934) InnerError!Air.Inst.Ref {
2906 const tracy = trace(@src());2935 const tracy = trace(@src());
2907 defer tracy.end();2936 defer tracy.end();
29082937
2909 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2938 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2910 const src = inst_data.src();2939 const src = inst_data.src();
2911 const operand = try sema.resolveInst(inst_data.operand);2940 const operand = sema.resolveInst(inst_data.operand);
2912 if (operand.ty.zigTypeTag() != .ErrorUnion)2941 if (operand.ty.zigTypeTag() != .ErrorUnion)
2913 return sema.mod.fail(&block.base, operand.src, "expected error union type, found '{}'", .{operand.ty});2942 return sema.mod.fail(&block.base, operand.src, "expected error union type, found '{}'", .{operand.ty});
29142943
...@@ -2936,19 +2965,19 @@ fn zirErrUnionPayloadPtr(...@@ -2936,19 +2965,19 @@ fn zirErrUnionPayloadPtr(
2936 block: *Scope.Block,2965 block: *Scope.Block,
2937 inst: Zir.Inst.Index,2966 inst: Zir.Inst.Index,
2938 safety_check: bool,2967 safety_check: bool,
2939) InnerError!Air.Inst.Index {2968) InnerError!Air.Inst.Ref {
2940 const tracy = trace(@src());2969 const tracy = trace(@src());
2941 defer tracy.end();2970 defer tracy.end();
29422971
2943 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2972 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2944 const src = inst_data.src();2973 const src = inst_data.src();
2945 const operand = try sema.resolveInst(inst_data.operand);2974 const operand = sema.resolveInst(inst_data.operand);
2946 assert(operand.ty.zigTypeTag() == .Pointer);2975 assert(operand.ty.zigTypeTag() == .Pointer);
29472976
2948 if (operand.ty.elemType().zigTypeTag() != .ErrorUnion)2977 if (operand.ty.elemType().zigTypeTag() != .ErrorUnion)
2949 return sema.mod.fail(&block.base, src, "expected error union type, found {}", .{operand.ty.elemType()});2978 return sema.mod.fail(&block.base, src, "expected error union type, found {}", .{operand.ty.elemType()});
29502979
2951 const operand_pointer_ty = try sema.mod.simplePtrType(sema.arena, operand.ty.elemType().castTag(.error_union).?.data.payload, !operand.ty.isConstPtr(), .One);2980 const operand_pointer_ty = try Module.simplePtrType(sema.arena, operand.ty.elemType().castTag(.error_union).?.data.payload, !operand.ty.isConstPtr(), .One);
29522981
2953 if (operand.value()) |pointer_val| {2982 if (operand.value()) |pointer_val| {
2954 const val = try pointer_val.pointerDeref(sema.arena);2983 const val = try pointer_val.pointerDeref(sema.arena);
...@@ -2975,13 +3004,13 @@ fn zirErrUnionPayloadPtr(...@@ -2975,13 +3004,13 @@ fn zirErrUnionPayloadPtr(
2975}3004}
29763005
2977/// Value in, value out3006/// Value in, value out
2978fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3007fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
2979 const tracy = trace(@src());3008 const tracy = trace(@src());
2980 defer tracy.end();3009 defer tracy.end();
29813010
2982 const inst_data = sema.code.instructions.items(.data)[inst].un_node;3011 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2983 const src = inst_data.src();3012 const src = inst_data.src();
2984 const operand = try sema.resolveInst(inst_data.operand);3013 const operand = sema.resolveInst(inst_data.operand);
2985 if (operand.ty.zigTypeTag() != .ErrorUnion)3014 if (operand.ty.zigTypeTag() != .ErrorUnion)
2986 return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand.ty});3015 return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand.ty});
29873016
...@@ -3001,13 +3030,13 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner...@@ -3001,13 +3030,13 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner
3001}3030}
30023031
3003/// Pointer in, value out3032/// Pointer in, value out
3004fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3033fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3005 const tracy = trace(@src());3034 const tracy = trace(@src());
3006 defer tracy.end();3035 defer tracy.end();
30073036
3008 const inst_data = sema.code.instructions.items(.data)[inst].un_node;3037 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3009 const src = inst_data.src();3038 const src = inst_data.src();
3010 const operand = try sema.resolveInst(inst_data.operand);3039 const operand = sema.resolveInst(inst_data.operand);
3011 assert(operand.ty.zigTypeTag() == .Pointer);3040 assert(operand.ty.zigTypeTag() == .Pointer);
30123041
3013 if (operand.ty.elemType().zigTypeTag() != .ErrorUnion)3042 if (operand.ty.elemType().zigTypeTag() != .ErrorUnion)
...@@ -3035,7 +3064,7 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde...@@ -3035,7 +3064,7 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
30353064
3036 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;3065 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
3037 const src = inst_data.src();3066 const src = inst_data.src();
3038 const operand = try sema.resolveInst(inst_data.operand);3067 const operand = sema.resolveInst(inst_data.operand);
3039 if (operand.ty.zigTypeTag() != .ErrorUnion)3068 if (operand.ty.zigTypeTag() != .ErrorUnion)
3040 return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand.ty});3069 return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand.ty});
3041 if (operand.ty.castTag(.error_union).?.data.payload.zigTypeTag() != .Void) {3070 if (operand.ty.castTag(.error_union).?.data.payload.zigTypeTag() != .Void) {
...@@ -3048,7 +3077,7 @@ fn zirFunc(...@@ -3048,7 +3077,7 @@ fn zirFunc(
3048 block: *Scope.Block,3077 block: *Scope.Block,
3049 inst: Zir.Inst.Index,3078 inst: Zir.Inst.Index,
3050 inferred_error_set: bool,3079 inferred_error_set: bool,
3051) InnerError!Air.Inst.Index {3080) InnerError!Air.Inst.Ref {
3052 const tracy = trace(@src());3081 const tracy = trace(@src());
3053 defer tracy.end();3082 defer tracy.end();
30543083
...@@ -3099,7 +3128,7 @@ fn funcCommon(...@@ -3099,7 +3128,7 @@ fn funcCommon(
3099 is_extern: bool,3128 is_extern: bool,
3100 src_locs: Zir.Inst.Func.SrcLocs,3129 src_locs: Zir.Inst.Func.SrcLocs,
3101 opt_lib_name: ?[]const u8,3130 opt_lib_name: ?[]const u8,
3102) InnerError!Air.Inst.Index {3131) InnerError!Air.Inst.Ref {
3103 const src: LazySrcLoc = .{ .node_offset = src_node_offset };3132 const src: LazySrcLoc = .{ .node_offset = src_node_offset };
3104 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset };3133 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset };
3105 const bare_return_type = try sema.resolveType(block, ret_ty_src, zir_return_type);3134 const bare_return_type = try sema.resolveType(block, ret_ty_src, zir_return_type);
...@@ -3240,7 +3269,7 @@ fn funcCommon(...@@ -3240,7 +3269,7 @@ fn funcCommon(
3240 return result;3269 return result;
3241}3270}
32423271
3243fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3272fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3244 const tracy = trace(@src());3273 const tracy = trace(@src());
3245 defer tracy.end();3274 defer tracy.end();
32463275
...@@ -3248,7 +3277,7 @@ fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air....@@ -3248,7 +3277,7 @@ fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.
3248 return sema.analyzeAs(block, .unneeded, bin_inst.lhs, bin_inst.rhs);3277 return sema.analyzeAs(block, .unneeded, bin_inst.lhs, bin_inst.rhs);
3249}3278}
32503279
3251fn zirAsNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3280fn zirAsNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3252 const tracy = trace(@src());3281 const tracy = trace(@src());
3253 defer tracy.end();3282 defer tracy.end();
32543283
...@@ -3264,18 +3293,18 @@ fn analyzeAs(...@@ -3264,18 +3293,18 @@ fn analyzeAs(
3264 src: LazySrcLoc,3293 src: LazySrcLoc,
3265 zir_dest_type: Zir.Inst.Ref,3294 zir_dest_type: Zir.Inst.Ref,
3266 zir_operand: Zir.Inst.Ref,3295 zir_operand: Zir.Inst.Ref,
3267) InnerError!Air.Inst.Index {3296) InnerError!Air.Inst.Ref {
3268 const dest_type = try sema.resolveType(block, src, zir_dest_type);3297 const dest_type = try sema.resolveType(block, src, zir_dest_type);
3269 const operand = try sema.resolveInst(zir_operand);3298 const operand = sema.resolveInst(zir_operand);
3270 return sema.coerce(block, dest_type, operand, src);3299 return sema.coerce(block, dest_type, operand, src);
3271}3300}
32723301
3273fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3302fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3274 const tracy = trace(@src());3303 const tracy = trace(@src());
3275 defer tracy.end();3304 defer tracy.end();
32763305
3277 const inst_data = sema.code.instructions.items(.data)[inst].un_node;3306 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3278 const ptr = try sema.resolveInst(inst_data.operand);3307 const ptr = sema.resolveInst(inst_data.operand);
3279 if (ptr.ty.zigTypeTag() != .Pointer) {3308 if (ptr.ty.zigTypeTag() != .Pointer) {
3280 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };3309 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
3281 return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr.ty});3310 return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr.ty});
...@@ -3287,7 +3316,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -3287,7 +3316,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
3287 return block.addUnOp(src, ty, .ptrtoint, ptr);3316 return block.addUnOp(src, ty, .ptrtoint, ptr);
3288}3317}
32893318
3290fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3319fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3291 const tracy = trace(@src());3320 const tracy = trace(@src());
3292 defer tracy.end();3321 defer tracy.end();
32933322
...@@ -3296,7 +3325,7 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -3296,7 +3325,7 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
3296 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };3325 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
3297 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;3326 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
3298 const field_name = sema.code.nullTerminatedString(extra.field_name_start);3327 const field_name = sema.code.nullTerminatedString(extra.field_name_start);
3299 const object = try sema.resolveInst(extra.lhs);3328 const object = sema.resolveInst(extra.lhs);
3300 const object_ptr = if (object.ty.zigTypeTag() == .Pointer)3329 const object_ptr = if (object.ty.zigTypeTag() == .Pointer)
3301 object3330 object
3302 else3331 else
...@@ -3305,7 +3334,7 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -3305,7 +3334,7 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
3305 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);3334 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);
3306}3335}
33073336
3308fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3337fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3309 const tracy = trace(@src());3338 const tracy = trace(@src());
3310 defer tracy.end();3339 defer tracy.end();
33113340
...@@ -3314,11 +3343,11 @@ fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -3314,11 +3343,11 @@ fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
3314 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };3343 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
3315 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;3344 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
3316 const field_name = sema.code.nullTerminatedString(extra.field_name_start);3345 const field_name = sema.code.nullTerminatedString(extra.field_name_start);
3317 const object_ptr = try sema.resolveInst(extra.lhs);3346 const object_ptr = sema.resolveInst(extra.lhs);
3318 return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);3347 return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);
3319}3348}
33203349
3321fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3350fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3322 const tracy = trace(@src());3351 const tracy = trace(@src());
3323 defer tracy.end();3352 defer tracy.end();
33243353
...@@ -3326,14 +3355,14 @@ fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne...@@ -3326,14 +3355,14 @@ fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
3326 const src = inst_data.src();3355 const src = inst_data.src();
3327 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };3356 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
3328 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;3357 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
3329 const object = try sema.resolveInst(extra.lhs);3358 const object = sema.resolveInst(extra.lhs);
3330 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);3359 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);
3331 const object_ptr = try sema.analyzeRef(block, src, object);3360 const object_ptr = try sema.analyzeRef(block, src, object);
3332 const result_ptr = try sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);3361 const result_ptr = try sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);
3333 return sema.analyzeLoad(block, src, result_ptr, src);3362 return sema.analyzeLoad(block, src, result_ptr, src);
3334}3363}
33353364
3336fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3365fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3337 const tracy = trace(@src());3366 const tracy = trace(@src());
3338 defer tracy.end();3367 defer tracy.end();
33393368
...@@ -3341,12 +3370,12 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne...@@ -3341,12 +3370,12 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
3341 const src = inst_data.src();3370 const src = inst_data.src();
3342 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };3371 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
3343 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;3372 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
3344 const object_ptr = try sema.resolveInst(extra.lhs);3373 const object_ptr = sema.resolveInst(extra.lhs);
3345 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);3374 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);
3346 return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);3375 return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);
3347}3376}
33483377
3349fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3378fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3350 const tracy = trace(@src());3379 const tracy = trace(@src());
3351 defer tracy.end();3380 defer tracy.end();
33523381
...@@ -3357,7 +3386,7 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -3357,7 +3386,7 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
3357 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;3386 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
33583387
3359 const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs);3388 const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs);
3360 const operand = try sema.resolveInst(extra.rhs);3389 const operand = sema.resolveInst(extra.rhs);
33613390
3362 const dest_is_comptime_int = switch (dest_type.zigTypeTag()) {3391 const dest_is_comptime_int = switch (dest_type.zigTypeTag()) {
3363 .ComptimeInt => true,3392 .ComptimeInt => true,
...@@ -3389,20 +3418,21 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -3389,20 +3418,21 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
3389 return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten int", .{});3418 return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten int", .{});
3390}3419}
33913420
3392fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3421fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3393 const tracy = trace(@src());3422 const tracy = trace(@src());
3394 defer tracy.end();3423 defer tracy.end();
33953424
3396 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;3425 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
3397 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };3426 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
3427 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
3398 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;3428 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
33993429
3400 const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs);3430 const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs);
3401 const operand = try sema.resolveInst(extra.rhs);3431 const operand = sema.resolveInst(extra.rhs);
3402 return sema.bitcast(block, dest_type, operand);3432 return sema.bitcast(block, dest_type, operand, operand_src);
3403}3433}
34043434
3405fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3435fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3406 const tracy = trace(@src());3436 const tracy = trace(@src());
3407 defer tracy.end();3437 defer tracy.end();
34083438
...@@ -3413,7 +3443,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr...@@ -3413,7 +3443,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
3413 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;3443 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
34143444
3415 const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs);3445 const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs);
3416 const operand = try sema.resolveInst(extra.rhs);3446 const operand = sema.resolveInst(extra.rhs);
34173447
3418 const dest_is_comptime_float = switch (dest_type.zigTypeTag()) {3448 const dest_is_comptime_float = switch (dest_type.zigTypeTag()) {
3419 .ComptimeFloat => true,3449 .ComptimeFloat => true,
...@@ -3445,22 +3475,22 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr...@@ -3445,22 +3475,22 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
3445 return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten float", .{});3475 return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten float", .{});
3446}3476}
34473477
3448fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3478fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3449 const tracy = trace(@src());3479 const tracy = trace(@src());
3450 defer tracy.end();3480 defer tracy.end();
34513481
3452 const bin_inst = sema.code.instructions.items(.data)[inst].bin;3482 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
3453 const array = try sema.resolveInst(bin_inst.lhs);3483 const array = sema.resolveInst(bin_inst.lhs);
3454 const array_ptr = if (array.ty.zigTypeTag() == .Pointer)3484 const array_ptr = if (array.ty.zigTypeTag() == .Pointer)
3455 array3485 array
3456 else3486 else
3457 try sema.analyzeRef(block, sema.src, array);3487 try sema.analyzeRef(block, sema.src, array);
3458 const elem_index = try sema.resolveInst(bin_inst.rhs);3488 const elem_index = sema.resolveInst(bin_inst.rhs);
3459 const result_ptr = try sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);3489 const result_ptr = try sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);
3460 return sema.analyzeLoad(block, sema.src, result_ptr, sema.src);3490 return sema.analyzeLoad(block, sema.src, result_ptr, sema.src);
3461}3491}
34623492
3463fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3493fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3464 const tracy = trace(@src());3494 const tracy = trace(@src());
3465 defer tracy.end();3495 defer tracy.end();
34663496
...@@ -3468,27 +3498,27 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE...@@ -3468,27 +3498,27 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE
3468 const src = inst_data.src();3498 const src = inst_data.src();
3469 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };3499 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
3470 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;3500 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
3471 const array = try sema.resolveInst(extra.lhs);3501 const array = sema.resolveInst(extra.lhs);
3472 const array_ptr = if (array.ty.zigTypeTag() == .Pointer)3502 const array_ptr = if (array.ty.zigTypeTag() == .Pointer)
3473 array3503 array
3474 else3504 else
3475 try sema.analyzeRef(block, src, array);3505 try sema.analyzeRef(block, src, array);
3476 const elem_index = try sema.resolveInst(extra.rhs);3506 const elem_index = sema.resolveInst(extra.rhs);
3477 const result_ptr = try sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);3507 const result_ptr = try sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);
3478 return sema.analyzeLoad(block, src, result_ptr, src);3508 return sema.analyzeLoad(block, src, result_ptr, src);
3479}3509}
34803510
3481fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3511fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3482 const tracy = trace(@src());3512 const tracy = trace(@src());
3483 defer tracy.end();3513 defer tracy.end();
34843514
3485 const bin_inst = sema.code.instructions.items(.data)[inst].bin;3515 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
3486 const array_ptr = try sema.resolveInst(bin_inst.lhs);3516 const array_ptr = sema.resolveInst(bin_inst.lhs);
3487 const elem_index = try sema.resolveInst(bin_inst.rhs);3517 const elem_index = sema.resolveInst(bin_inst.rhs);
3488 return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);3518 return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);
3489}3519}
34903520
3491fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3521fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3492 const tracy = trace(@src());3522 const tracy = trace(@src());
3493 defer tracy.end();3523 defer tracy.end();
34943524
...@@ -3496,39 +3526,39 @@ fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE...@@ -3496,39 +3526,39 @@ fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE
3496 const src = inst_data.src();3526 const src = inst_data.src();
3497 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };3527 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
3498 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;3528 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
3499 const array_ptr = try sema.resolveInst(extra.lhs);3529 const array_ptr = sema.resolveInst(extra.lhs);
3500 const elem_index = try sema.resolveInst(extra.rhs);3530 const elem_index = sema.resolveInst(extra.rhs);
3501 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);3531 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);
3502}3532}
35033533
3504fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3534fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3505 const tracy = trace(@src());3535 const tracy = trace(@src());
3506 defer tracy.end();3536 defer tracy.end();
35073537
3508 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;3538 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
3509 const src = inst_data.src();3539 const src = inst_data.src();
3510 const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;3540 const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;
3511 const array_ptr = try sema.resolveInst(extra.lhs);3541 const array_ptr = sema.resolveInst(extra.lhs);
3512 const start = try sema.resolveInst(extra.start);3542 const start = sema.resolveInst(extra.start);
35133543
3514 return sema.analyzeSlice(block, src, array_ptr, start, null, null, .unneeded);3544 return sema.analyzeSlice(block, src, array_ptr, start, null, null, .unneeded);
3515}3545}
35163546
3517fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3547fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3518 const tracy = trace(@src());3548 const tracy = trace(@src());
3519 defer tracy.end();3549 defer tracy.end();
35203550
3521 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;3551 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
3522 const src = inst_data.src();3552 const src = inst_data.src();
3523 const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;3553 const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;
3524 const array_ptr = try sema.resolveInst(extra.lhs);3554 const array_ptr = sema.resolveInst(extra.lhs);
3525 const start = try sema.resolveInst(extra.start);3555 const start = sema.resolveInst(extra.start);
3526 const end = try sema.resolveInst(extra.end);3556 const end = sema.resolveInst(extra.end);
35273557
3528 return sema.analyzeSlice(block, src, array_ptr, start, end, null, .unneeded);3558 return sema.analyzeSlice(block, src, array_ptr, start, end, null, .unneeded);
3529}3559}
35303560
3531fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {3561fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
3532 const tracy = trace(@src());3562 const tracy = trace(@src());
3533 defer tracy.end();3563 defer tracy.end();
35343564
...@@ -3536,10 +3566,10 @@ fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne...@@ -3536,10 +3566,10 @@ fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
3536 const src = inst_data.src();3566 const src = inst_data.src();
3537 const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node };3567 const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node };
3538 const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;3568 const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;
3539 const array_ptr = try sema.resolveInst(extra.lhs);3569 const array_ptr = sema.resolveInst(extra.lhs);
3540 const start = try sema.resolveInst(extra.start);3570 const start = sema.resolveInst(extra.start);
3541 const end = try sema.resolveInst(extra.end);3571 const end = sema.resolveInst(extra.end);
3542 const sentinel = try sema.resolveInst(extra.sentinel);3572 const sentinel = sema.resolveInst(extra.sentinel);
35433573
3544 return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src);3574 return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src);
3545}3575}
...@@ -3550,7 +3580,7 @@ fn zirSwitchCapture(...@@ -3550,7 +3580,7 @@ fn zirSwitchCapture(
3550 inst: Zir.Inst.Index,3580 inst: Zir.Inst.Index,
3551 is_multi: bool,3581 is_multi: bool,
3552 is_ref: bool,3582 is_ref: bool,
3553) InnerError!Air.Inst.Index {3583) InnerError!Air.Inst.Ref {
3554 const tracy = trace(@src());3584 const tracy = trace(@src());
3555 defer tracy.end();3585 defer tracy.end();
35563586
...@@ -3569,7 +3599,7 @@ fn zirSwitchCaptureElse(...@@ -3569,7 +3599,7 @@ fn zirSwitchCaptureElse(
3569 block: *Scope.Block,3599 block: *Scope.Block,
3570 inst: Zir.Inst.Index,3600 inst: Zir.Inst.Index,
3571 is_ref: bool,3601 is_ref: bool,
3572) InnerError!Air.Inst.Index {3602) InnerError!Air.Inst.Ref {
3573 const tracy = trace(@src());3603 const tracy = trace(@src());
3574 defer tracy.end();3604 defer tracy.end();
35753605
...@@ -3588,7 +3618,7 @@ fn zirSwitchBlock(...@@ -3588,7 +3618,7 @@ fn zirSwitchBlock(
3588 inst: Zir.Inst.Index,3618 inst: Zir.Inst.Index,
3589 is_ref: bool,3619 is_ref: bool,
3590 special_prong: Zir.SpecialProng,3620 special_prong: Zir.SpecialProng,
3591) InnerError!Air.Inst.Index {3621) InnerError!Air.Inst.Ref {
3592 const tracy = trace(@src());3622 const tracy = trace(@src());
3593 defer tracy.end();3623 defer tracy.end();
35943624
...@@ -3597,7 +3627,7 @@ fn zirSwitchBlock(...@@ -3597,7 +3627,7 @@ fn zirSwitchBlock(
3597 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = inst_data.src_node };3627 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = inst_data.src_node };
3598 const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);3628 const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);
35993629
3600 const operand_ptr = try sema.resolveInst(extra.data.operand);3630 const operand_ptr = sema.resolveInst(extra.data.operand);
3601 const operand = if (is_ref)3631 const operand = if (is_ref)
3602 try sema.analyzeLoad(block, src, operand_ptr, operand_src)3632 try sema.analyzeLoad(block, src, operand_ptr, operand_src)
3603 else3633 else
...@@ -3621,7 +3651,7 @@ fn zirSwitchBlockMulti(...@@ -3621,7 +3651,7 @@ fn zirSwitchBlockMulti(
3621 inst: Zir.Inst.Index,3651 inst: Zir.Inst.Index,
3622 is_ref: bool,3652 is_ref: bool,
3623 special_prong: Zir.SpecialProng,3653 special_prong: Zir.SpecialProng,
3624) InnerError!Air.Inst.Index {3654) InnerError!Air.Inst.Ref {
3625 const tracy = trace(@src());3655 const tracy = trace(@src());
3626 defer tracy.end();3656 defer tracy.end();
36273657
...@@ -3630,7 +3660,7 @@ fn zirSwitchBlockMulti(...@@ -3630,7 +3660,7 @@ fn zirSwitchBlockMulti(
3630 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = inst_data.src_node };3660 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = inst_data.src_node };
3631 const extra = sema.code.extraData(Zir.Inst.SwitchBlockMulti, inst_data.payload_index);3661 const extra = sema.code.extraData(Zir.Inst.SwitchBlockMulti, inst_data.payload_index);
36323662
3633 const operand_ptr = try sema.resolveInst(extra.data.operand);3663 const operand_ptr = sema.resolveInst(extra.data.operand);
3634 const operand = if (is_ref)3664 const operand = if (is_ref)
3635 try sema.analyzeLoad(block, src, operand_ptr, operand_src)3665 try sema.analyzeLoad(block, src, operand_ptr, operand_src)
3636 else3666 else
...@@ -3651,14 +3681,14 @@ fn zirSwitchBlockMulti(...@@ -3651,14 +3681,14 @@ fn zirSwitchBlockMulti(
3651fn analyzeSwitch(3681fn analyzeSwitch(
3652 sema: *Sema,3682 sema: *Sema,
3653 block: *Scope.Block,3683 block: *Scope.Block,
3654 operand: Air.Inst.Index,3684 operand: Air.Inst.Ref,
3655 extra_end: usize,3685 extra_end: usize,
3656 special_prong: Zir.SpecialProng,3686 special_prong: Zir.SpecialProng,
3657 scalar_cases_len: usize,3687 scalar_cases_len: usize,
3658 multi_cases_len: usize,3688 multi_cases_len: usize,
3659 switch_inst: Zir.Inst.Index,3689 switch_inst: Zir.Inst.Index,
3660 src_node_offset: i32,3690 src_node_offset: i32,
3661) InnerError!Air.Inst.Index {3691) InnerError!Air.Inst.Ref {
3662 const gpa = sema.gpa;3692 const gpa = sema.gpa;
3663 const mod = sema.mod;3693 const mod = sema.mod;
36643694
...@@ -4217,7 +4247,7 @@ fn analyzeSwitch(...@@ -4217,7 +4247,7 @@ fn analyzeSwitch(
4217 const bool_ty = comptime Type.initTag(.bool);4247 const bool_ty = comptime Type.initTag(.bool);
42184248
4219 for (items) |item_ref| {4249 for (items) |item_ref| {
4220 const item = try sema.resolveInst(item_ref);4250 const item = sema.resolveInst(item_ref);
4221 _ = try sema.resolveConstValue(&child_block, item.src, item);4251 _ = try sema.resolveConstValue(&child_block, item.src, item);
42224252
4223 const cmp_ok = try case_block.addBinOp(item.src, bool_ty, .cmp_eq, operand, item);4253 const cmp_ok = try case_block.addBinOp(item.src, bool_ty, .cmp_eq, operand, item);
...@@ -4235,8 +4265,8 @@ fn analyzeSwitch(...@@ -4235,8 +4265,8 @@ fn analyzeSwitch(
4235 const last_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);4265 const last_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
4236 extra_index += 1;4266 extra_index += 1;
42374267
4238 const item_first = try sema.resolveInst(first_ref);4268 const item_first = sema.resolveInst(first_ref);
4239 const item_last = try sema.resolveInst(last_ref);4269 const item_last = sema.resolveInst(last_ref);
42404270
4241 _ = try sema.resolveConstValue(&child_block, item_first.src, item_first);4271 _ = try sema.resolveConstValue(&child_block, item_first.src, item_first);
4242 _ = try sema.resolveConstValue(&child_block, item_last.src, item_last);4272 _ = try sema.resolveConstValue(&child_block, item_last.src, item_last);
...@@ -4334,7 +4364,7 @@ fn resolveSwitchItemVal(...@@ -4334,7 +4364,7 @@ fn resolveSwitchItemVal(
4334 switch_prong_src: Module.SwitchProngSrc,4364 switch_prong_src: Module.SwitchProngSrc,
4335 range_expand: Module.SwitchProngSrc.RangeExpand,4365 range_expand: Module.SwitchProngSrc.RangeExpand,
4336) InnerError!TypedValue {4366) InnerError!TypedValue {
4337 const item = try sema.resolveInst(item_ref);4367 const item = sema.resolveInst(item_ref);
4338 // We have to avoid the other helper functions here because we cannot construct a LazySrcLoc4368 // We have to avoid the other helper functions here because we cannot construct a LazySrcLoc
4339 // because we only have the switch AST node. Only if we know for sure we need to report4369 // because we only have the switch AST node. Only if we know for sure we need to report
4340 // a compile error do we resolve the full source locations.4370 // a compile error do we resolve the full source locations.
...@@ -4513,7 +4543,7 @@ fn validateSwitchNoRange(...@@ -4513,7 +4543,7 @@ fn validateSwitchNoRange(
4513 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);4543 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);
4514}4544}
45154545
4516fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {4546fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
4517 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;4547 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
4518 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;4548 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
4519 _ = extra;4549 _ = extra;
...@@ -4522,7 +4552,7 @@ fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -4522,7 +4552,7 @@ fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
4522 return sema.mod.fail(&block.base, src, "TODO implement zirHasField", .{});4552 return sema.mod.fail(&block.base, src, "TODO implement zirHasField", .{});
4523}4553}
45244554
4525fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {4555fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
4526 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;4556 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
4527 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;4557 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
4528 const src = inst_data.src();4558 const src = inst_data.src();
...@@ -4547,7 +4577,7 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -4547,7 +4577,7 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
4547 return mod.constBool(arena, src, false);4577 return mod.constBool(arena, src, false);
4548}4578}
45494579
4550fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {4580fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
4551 const tracy = trace(@src());4581 const tracy = trace(@src());
4552 defer tracy.end();4582 defer tracy.end();
45534583
...@@ -4572,13 +4602,13 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!...@@ -4572,13 +4602,13 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
4572 return mod.constType(sema.arena, src, file_root_decl.ty);4602 return mod.constType(sema.arena, src, file_root_decl.ty);
4573}4603}
45744604
4575fn zirRetErrValueCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {4605fn zirRetErrValueCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
4576 _ = block;4606 _ = block;
4577 _ = inst;4607 _ = inst;
4578 return sema.mod.fail(&block.base, sema.src, "TODO implement zirRetErrValueCode", .{});4608 return sema.mod.fail(&block.base, sema.src, "TODO implement zirRetErrValueCode", .{});
4579}4609}
45804610
4581fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {4611fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
4582 const tracy = trace(@src());4612 const tracy = trace(@src());
4583 defer tracy.end();4613 defer tracy.end();
45844614
...@@ -4587,7 +4617,7 @@ fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air...@@ -4587,7 +4617,7 @@ fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air
4587 return sema.mod.fail(&block.base, sema.src, "TODO implement zirShl", .{});4617 return sema.mod.fail(&block.base, sema.src, "TODO implement zirShl", .{});
4588}4618}
45894619
4590fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {4620fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
4591 const tracy = trace(@src());4621 const tracy = trace(@src());
4592 defer tracy.end();4622 defer tracy.end();
45934623
...@@ -4599,8 +4629,8 @@ fn zirBitwise(...@@ -4599,8 +4629,8 @@ fn zirBitwise(
4599 sema: *Sema,4629 sema: *Sema,
4600 block: *Scope.Block,4630 block: *Scope.Block,
4601 inst: Zir.Inst.Index,4631 inst: Zir.Inst.Index,
4602 ir_tag: ir.Inst.Tag,4632 air_tag: Air.Inst.Tag,
4603) InnerError!Air.Inst.Index {4633) InnerError!Air.Inst.Ref {
4604 const tracy = trace(@src());4634 const tracy = trace(@src());
4605 defer tracy.end();4635 defer tracy.end();
46064636
...@@ -4609,8 +4639,8 @@ fn zirBitwise(...@@ -4609,8 +4639,8 @@ fn zirBitwise(
4609 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };4639 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
4610 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };4640 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
4611 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;4641 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
4612 const lhs = try sema.resolveInst(extra.lhs);4642 const lhs = sema.resolveInst(extra.lhs);
4613 const rhs = try sema.resolveInst(extra.rhs);4643 const rhs = sema.resolveInst(extra.rhs);
46144644
4615 const instructions = &[_]Air.Inst.Index{ lhs, rhs };4645 const instructions = &[_]Air.Inst.Index{ lhs, rhs };
4616 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);4646 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);
...@@ -4655,10 +4685,10 @@ fn zirBitwise(...@@ -4655,10 +4685,10 @@ fn zirBitwise(
4655 }4685 }
46564686
4657 try sema.requireRuntimeBlock(block, src);4687 try sema.requireRuntimeBlock(block, src);
4658 return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs);4688 return block.addBinOp(src, scalar_type, air_tag, casted_lhs, casted_rhs);
4659}4689}
46604690
4661fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {4691fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
4662 const tracy = trace(@src());4692 const tracy = trace(@src());
4663 defer tracy.end();4693 defer tracy.end();
46644694
...@@ -4666,7 +4696,7 @@ fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!...@@ -4666,7 +4696,7 @@ fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
4666 return sema.mod.fail(&block.base, sema.src, "TODO implement zirBitNot", .{});4696 return sema.mod.fail(&block.base, sema.src, "TODO implement zirBitNot", .{});
4667}4697}
46684698
4669fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {4699fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
4670 const tracy = trace(@src());4700 const tracy = trace(@src());
4671 defer tracy.end();4701 defer tracy.end();
46724702
...@@ -4674,7 +4704,7 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -4674,7 +4704,7 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
4674 return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayCat", .{});4704 return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayCat", .{});
4675}4705}
46764706
4677fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {4707fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
4678 const tracy = trace(@src());4708 const tracy = trace(@src());
4679 defer tracy.end();4709 defer tracy.end();
46804710
...@@ -4687,7 +4717,7 @@ fn zirNegate(...@@ -4687,7 +4717,7 @@ fn zirNegate(
4687 block: *Scope.Block,4717 block: *Scope.Block,
4688 inst: Zir.Inst.Index,4718 inst: Zir.Inst.Index,
4689 tag_override: Zir.Inst.Tag,4719 tag_override: Zir.Inst.Tag,
4690) InnerError!Air.Inst.Index {4720) InnerError!Air.Inst.Ref {
4691 const tracy = trace(@src());4721 const tracy = trace(@src());
4692 defer tracy.end();4722 defer tracy.end();
46934723
...@@ -4695,13 +4725,13 @@ fn zirNegate(...@@ -4695,13 +4725,13 @@ fn zirNegate(
4695 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };4725 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
4696 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };4726 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
4697 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };4727 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
4698 const lhs = try sema.resolveInst(.zero);4728 const lhs = sema.resolveInst(.zero);
4699 const rhs = try sema.resolveInst(inst_data.operand);4729 const rhs = sema.resolveInst(inst_data.operand);
47004730
4701 return sema.analyzeArithmetic(block, tag_override, lhs, rhs, src, lhs_src, rhs_src);4731 return sema.analyzeArithmetic(block, tag_override, lhs, rhs, src, lhs_src, rhs_src);
4702}4732}
47034733
4704fn zirArithmetic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {4734fn zirArithmetic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
4705 const tracy = trace(@src());4735 const tracy = trace(@src());
4706 defer tracy.end();4736 defer tracy.end();
47074737
...@@ -4711,8 +4741,8 @@ fn zirArithmetic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr...@@ -4711,8 +4741,8 @@ fn zirArithmetic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
4711 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };4741 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
4712 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };4742 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
4713 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;4743 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
4714 const lhs = try sema.resolveInst(extra.lhs);4744 const lhs = sema.resolveInst(extra.lhs);
4715 const rhs = try sema.resolveInst(extra.rhs);4745 const rhs = sema.resolveInst(extra.rhs);
47164746
4717 return sema.analyzeArithmetic(block, tag_override, lhs, rhs, sema.src, lhs_src, rhs_src);4747 return sema.analyzeArithmetic(block, tag_override, lhs, rhs, sema.src, lhs_src, rhs_src);
4718}4748}
...@@ -4721,7 +4751,7 @@ fn zirOverflowArithmetic(...@@ -4721,7 +4751,7 @@ fn zirOverflowArithmetic(
4721 sema: *Sema,4751 sema: *Sema,
4722 block: *Scope.Block,4752 block: *Scope.Block,
4723 extended: Zir.Inst.Extended.InstData,4753 extended: Zir.Inst.Extended.InstData,
4724) InnerError!Air.Inst.Index {4754) InnerError!Air.Inst.Ref {
4725 const tracy = trace(@src());4755 const tracy = trace(@src());
4726 defer tracy.end();4756 defer tracy.end();
47274757
...@@ -4735,12 +4765,12 @@ fn analyzeArithmetic(...@@ -4735,12 +4765,12 @@ fn analyzeArithmetic(
4735 sema: *Sema,4765 sema: *Sema,
4736 block: *Scope.Block,4766 block: *Scope.Block,
4737 zir_tag: Zir.Inst.Tag,4767 zir_tag: Zir.Inst.Tag,
4738 lhs: Air.Inst.Index,4768 lhs: Air.Inst.Ref,
4739 rhs: Air.Inst.Index,4769 rhs: Air.Inst.Ref,
4740 src: LazySrcLoc,4770 src: LazySrcLoc,
4741 lhs_src: LazySrcLoc,4771 lhs_src: LazySrcLoc,
4742 rhs_src: LazySrcLoc,4772 rhs_src: LazySrcLoc,
4743) InnerError!Air.Inst.Index {4773) InnerError!Air.Inst.Ref {
4744 const instructions = &[_]Air.Inst.Index{ lhs, rhs };4774 const instructions = &[_]Air.Inst.Index{ lhs, rhs };
4745 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);4775 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);
4746 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);4776 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
...@@ -4850,14 +4880,14 @@ fn analyzeArithmetic(...@@ -4850,14 +4880,14 @@ fn analyzeArithmetic(
4850 return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs);4880 return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs);
4851}4881}
48524882
4853fn zirLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {4883fn zirLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
4854 const tracy = trace(@src());4884 const tracy = trace(@src());
4855 defer tracy.end();4885 defer tracy.end();
48564886
4857 const inst_data = sema.code.instructions.items(.data)[inst].un_node;4887 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
4858 const src = inst_data.src();4888 const src = inst_data.src();
4859 const ptr_src: LazySrcLoc = .{ .node_offset_deref_ptr = inst_data.src_node };4889 const ptr_src: LazySrcLoc = .{ .node_offset_deref_ptr = inst_data.src_node };
4860 const ptr = try sema.resolveInst(inst_data.operand);4890 const ptr = sema.resolveInst(inst_data.operand);
4861 return sema.analyzeLoad(block, src, ptr, ptr_src);4891 return sema.analyzeLoad(block, src, ptr, ptr_src);
4862}4892}
48634893
...@@ -4865,7 +4895,7 @@ fn zirAsm(...@@ -4865,7 +4895,7 @@ fn zirAsm(
4865 sema: *Sema,4895 sema: *Sema,
4866 block: *Scope.Block,4896 block: *Scope.Block,
4867 extended: Zir.Inst.Extended.InstData,4897 extended: Zir.Inst.Extended.InstData,
4868) InnerError!Air.Inst.Index {4898) InnerError!Air.Inst.Ref {
4869 const tracy = trace(@src());4899 const tracy = trace(@src());
4870 defer tracy.end();4900 defer tracy.end();
48714901
...@@ -4915,7 +4945,7 @@ fn zirAsm(...@@ -4915,7 +4945,7 @@ fn zirAsm(
4915 const name = sema.code.nullTerminatedString(input.data.name);4945 const name = sema.code.nullTerminatedString(input.data.name);
4916 _ = name; // TODO: use the name4946 _ = name; // TODO: use the name
49174947
4918 arg.* = try sema.resolveInst(input.data.operand);4948 arg.* = sema.resolveInst(input.data.operand);
4919 inputs[arg_i] = sema.code.nullTerminatedString(input.data.constraint);4949 inputs[arg_i] = sema.code.nullTerminatedString(input.data.constraint);
4920 }4950 }
49214951
...@@ -4949,7 +4979,7 @@ fn zirCmp(...@@ -4949,7 +4979,7 @@ fn zirCmp(
4949 block: *Scope.Block,4979 block: *Scope.Block,
4950 inst: Zir.Inst.Index,4980 inst: Zir.Inst.Index,
4951 op: std.math.CompareOperator,4981 op: std.math.CompareOperator,
4952) InnerError!Air.Inst.Index {4982) InnerError!Air.Inst.Ref {
4953 const tracy = trace(@src());4983 const tracy = trace(@src());
4954 defer tracy.end();4984 defer tracy.end();
49554985
...@@ -4960,8 +4990,8 @@ fn zirCmp(...@@ -4960,8 +4990,8 @@ fn zirCmp(
4960 const src: LazySrcLoc = inst_data.src();4990 const src: LazySrcLoc = inst_data.src();
4961 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };4991 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
4962 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };4992 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
4963 const lhs = try sema.resolveInst(extra.lhs);4993 const lhs = sema.resolveInst(extra.lhs);
4964 const rhs = try sema.resolveInst(extra.rhs);4994 const rhs = sema.resolveInst(extra.rhs);
49654995
4966 const is_equality_cmp = switch (op) {4996 const is_equality_cmp = switch (op) {
4967 .eq, .neq => true,4997 .eq, .neq => true,
...@@ -5047,7 +5077,7 @@ fn zirCmp(...@@ -5047,7 +5077,7 @@ fn zirCmp(
5047 return block.addBinOp(src, bool_type, tag, casted_lhs, casted_rhs);5077 return block.addBinOp(src, bool_type, tag, casted_lhs, casted_rhs);
5048}5078}
50495079
5050fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5080fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5051 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5081 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5052 const src = inst_data.src();5082 const src = inst_data.src();
5053 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };5083 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
...@@ -5057,7 +5087,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!...@@ -5057,7 +5087,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
5057 return sema.mod.constIntUnsigned(sema.arena, src, Type.initTag(.comptime_int), abi_size);5087 return sema.mod.constIntUnsigned(sema.arena, src, Type.initTag(.comptime_int), abi_size);
5058}5088}
50595089
5060fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5090fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5061 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5091 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5062 const src = inst_data.src();5092 const src = inst_data.src();
5063 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };5093 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
...@@ -5071,7 +5101,7 @@ fn zirThis(...@@ -5071,7 +5101,7 @@ fn zirThis(
5071 sema: *Sema,5101 sema: *Sema,
5072 block: *Scope.Block,5102 block: *Scope.Block,
5073 extended: Zir.Inst.Extended.InstData,5103 extended: Zir.Inst.Extended.InstData,
5074) InnerError!Air.Inst.Index {5104) InnerError!Air.Inst.Ref {
5075 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };5105 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
5076 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirThis", .{});5106 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirThis", .{});
5077}5107}
...@@ -5080,7 +5110,7 @@ fn zirRetAddr(...@@ -5080,7 +5110,7 @@ fn zirRetAddr(
5080 sema: *Sema,5110 sema: *Sema,
5081 block: *Scope.Block,5111 block: *Scope.Block,
5082 extended: Zir.Inst.Extended.InstData,5112 extended: Zir.Inst.Extended.InstData,
5083) InnerError!Air.Inst.Index {5113) InnerError!Air.Inst.Ref {
5084 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };5114 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
5085 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirRetAddr", .{});5115 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirRetAddr", .{});
5086}5116}
...@@ -5089,12 +5119,12 @@ fn zirBuiltinSrc(...@@ -5089,12 +5119,12 @@ fn zirBuiltinSrc(
5089 sema: *Sema,5119 sema: *Sema,
5090 block: *Scope.Block,5120 block: *Scope.Block,
5091 extended: Zir.Inst.Extended.InstData,5121 extended: Zir.Inst.Extended.InstData,
5092) InnerError!Air.Inst.Index {5122) InnerError!Air.Inst.Ref {
5093 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };5123 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
5094 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinSrc", .{});5124 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinSrc", .{});
5095}5125}
50965126
5097fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5127fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5098 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5128 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5099 const src = inst_data.src();5129 const src = inst_data.src();
5100 const ty = try sema.resolveType(block, src, inst_data.operand);5130 const ty = try sema.resolveType(block, src, inst_data.operand);
...@@ -5137,31 +5167,31 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -5137,31 +5167,31 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
5137 }5167 }
5138}5168}
51395169
5140fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5170fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5141 _ = block;5171 _ = block;
5142 const zir_datas = sema.code.instructions.items(.data);5172 const zir_datas = sema.code.instructions.items(.data);
5143 const inst_data = zir_datas[inst].un_node;5173 const inst_data = zir_datas[inst].un_node;
5144 const src = inst_data.src();5174 const src = inst_data.src();
5145 const operand = try sema.resolveInst(inst_data.operand);5175 const operand = sema.resolveInst(inst_data.operand);
5146 return sema.mod.constType(sema.arena, src, operand.ty);5176 return sema.mod.constType(sema.arena, src, operand.ty);
5147}5177}
51485178
5149fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5179fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5150 _ = block;5180 _ = block;
5151 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5181 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5152 const src = inst_data.src();5182 const src = inst_data.src();
5153 const operand_ptr = try sema.resolveInst(inst_data.operand);5183 const operand_ptr = sema.resolveInst(inst_data.operand);
5154 const elem_ty = operand_ptr.ty.elemType();5184 const elem_ty = operand_ptr.ty.elemType();
5155 return sema.mod.constType(sema.arena, src, elem_ty);5185 return sema.mod.constType(sema.arena, src, elem_ty);
5156}5186}
51575187
5158fn zirTypeofLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5188fn zirTypeofLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5159 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5189 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5160 const src = inst_data.src();5190 const src = inst_data.src();
5161 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirTypeofLog2IntType", .{});5191 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirTypeofLog2IntType", .{});
5162}5192}
51635193
5164fn zirLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5194fn zirLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5165 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5195 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5166 const src = inst_data.src();5196 const src = inst_data.src();
5167 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirLog2IntType", .{});5197 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirLog2IntType", .{});
...@@ -5171,7 +5201,7 @@ fn zirTypeofPeer(...@@ -5171,7 +5201,7 @@ fn zirTypeofPeer(
5171 sema: *Sema,5201 sema: *Sema,
5172 block: *Scope.Block,5202 block: *Scope.Block,
5173 extended: Zir.Inst.Extended.InstData,5203 extended: Zir.Inst.Extended.InstData,
5174) InnerError!Air.Inst.Index {5204) InnerError!Air.Inst.Ref {
5175 const tracy = trace(@src());5205 const tracy = trace(@src());
5176 defer tracy.end();5206 defer tracy.end();
51775207
...@@ -5183,20 +5213,20 @@ fn zirTypeofPeer(...@@ -5183,20 +5213,20 @@ fn zirTypeofPeer(
5183 defer sema.gpa.free(inst_list);5213 defer sema.gpa.free(inst_list);
51845214
5185 for (args) |arg_ref, i| {5215 for (args) |arg_ref, i| {
5186 inst_list[i] = try sema.resolveInst(arg_ref);5216 inst_list[i] = sema.resolveInst(arg_ref);
5187 }5217 }
51885218
5189 const result_type = try sema.resolvePeerTypes(block, src, inst_list);5219 const result_type = try sema.resolvePeerTypes(block, src, inst_list);
5190 return sema.mod.constType(sema.arena, src, result_type);5220 return sema.mod.constType(sema.arena, src, result_type);
5191}5221}
51925222
5193fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5223fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5194 const tracy = trace(@src());5224 const tracy = trace(@src());
5195 defer tracy.end();5225 defer tracy.end();
51965226
5197 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5227 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5198 const src = inst_data.src();5228 const src = inst_data.src();
5199 const uncasted_operand = try sema.resolveInst(inst_data.operand);5229 const uncasted_operand = sema.resolveInst(inst_data.operand);
52005230
5201 const bool_type = Type.initTag(.bool);5231 const bool_type = Type.initTag(.bool);
5202 const operand = try sema.coerce(block, bool_type, uncasted_operand, uncasted_operand.src);5232 const operand = try sema.coerce(block, bool_type, uncasted_operand, uncasted_operand.src);
...@@ -5212,16 +5242,16 @@ fn zirBoolOp(...@@ -5212,16 +5242,16 @@ fn zirBoolOp(
5212 block: *Scope.Block,5242 block: *Scope.Block,
5213 inst: Zir.Inst.Index,5243 inst: Zir.Inst.Index,
5214 comptime is_bool_or: bool,5244 comptime is_bool_or: bool,
5215) InnerError!Air.Inst.Index {5245) InnerError!Air.Inst.Ref {
5216 const tracy = trace(@src());5246 const tracy = trace(@src());
5217 defer tracy.end();5247 defer tracy.end();
52185248
5219 const src: LazySrcLoc = .unneeded;5249 const src: LazySrcLoc = .unneeded;
5220 const bool_type = Type.initTag(.bool);5250 const bool_type = Type.initTag(.bool);
5221 const bin_inst = sema.code.instructions.items(.data)[inst].bin;5251 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
5222 const uncasted_lhs = try sema.resolveInst(bin_inst.lhs);5252 const uncasted_lhs = sema.resolveInst(bin_inst.lhs);
5223 const lhs = try sema.coerce(block, bool_type, uncasted_lhs, uncasted_lhs.src);5253 const lhs = try sema.coerce(block, bool_type, uncasted_lhs, uncasted_lhs.src);
5224 const uncasted_rhs = try sema.resolveInst(bin_inst.rhs);5254 const uncasted_rhs = sema.resolveInst(bin_inst.rhs);
5225 const rhs = try sema.coerce(block, bool_type, uncasted_rhs, uncasted_rhs.src);5255 const rhs = try sema.coerce(block, bool_type, uncasted_rhs, uncasted_rhs.src);
52265256
5227 if (lhs.value()) |lhs_val| {5257 if (lhs.value()) |lhs_val| {
...@@ -5234,7 +5264,7 @@ fn zirBoolOp(...@@ -5234,7 +5264,7 @@ fn zirBoolOp(
5234 }5264 }
5235 }5265 }
5236 try sema.requireRuntimeBlock(block, src);5266 try sema.requireRuntimeBlock(block, src);
5237 const tag: ir.Inst.Tag = if (is_bool_or) .bool_or else .bool_and;5267 const tag: Air.Inst.Tag = if (is_bool_or) .bool_or else .bool_and;
5238 return block.addBinOp(src, bool_type, tag, lhs, rhs);5268 return block.addBinOp(src, bool_type, tag, lhs, rhs);
5239}5269}
52405270
...@@ -5243,14 +5273,14 @@ fn zirBoolBr(...@@ -5243,14 +5273,14 @@ fn zirBoolBr(
5243 parent_block: *Scope.Block,5273 parent_block: *Scope.Block,
5244 inst: Zir.Inst.Index,5274 inst: Zir.Inst.Index,
5245 is_bool_or: bool,5275 is_bool_or: bool,
5246) InnerError!Air.Inst.Index {5276) InnerError!Air.Inst.Ref {
5247 const tracy = trace(@src());5277 const tracy = trace(@src());
5248 defer tracy.end();5278 defer tracy.end();
52495279
5250 const datas = sema.code.instructions.items(.data);5280 const datas = sema.code.instructions.items(.data);
5251 const inst_data = datas[inst].bool_br;5281 const inst_data = datas[inst].bool_br;
5252 const src: LazySrcLoc = .unneeded;5282 const src: LazySrcLoc = .unneeded;
5253 const lhs = try sema.resolveInst(inst_data.lhs);5283 const lhs = sema.resolveInst(inst_data.lhs);
5254 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);5284 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
5255 const body = sema.code.extra[extra.end..][0..extra.data.body_len];5285 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
52565286
...@@ -5313,13 +5343,13 @@ fn zirIsNonNull(...@@ -5313,13 +5343,13 @@ fn zirIsNonNull(
5313 sema: *Sema,5343 sema: *Sema,
5314 block: *Scope.Block,5344 block: *Scope.Block,
5315 inst: Zir.Inst.Index,5345 inst: Zir.Inst.Index,
5316) InnerError!Air.Inst.Index {5346) InnerError!Air.Inst.Ref {
5317 const tracy = trace(@src());5347 const tracy = trace(@src());
5318 defer tracy.end();5348 defer tracy.end();
53195349
5320 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5350 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5321 const src = inst_data.src();5351 const src = inst_data.src();
5322 const operand = try sema.resolveInst(inst_data.operand);5352 const operand = sema.resolveInst(inst_data.operand);
5323 return sema.analyzeIsNull(block, src, operand, true);5353 return sema.analyzeIsNull(block, src, operand, true);
5324}5354}
53255355
...@@ -5327,33 +5357,33 @@ fn zirIsNonNullPtr(...@@ -5327,33 +5357,33 @@ fn zirIsNonNullPtr(
5327 sema: *Sema,5357 sema: *Sema,
5328 block: *Scope.Block,5358 block: *Scope.Block,
5329 inst: Zir.Inst.Index,5359 inst: Zir.Inst.Index,
5330) InnerError!Air.Inst.Index {5360) InnerError!Air.Inst.Ref {
5331 const tracy = trace(@src());5361 const tracy = trace(@src());
5332 defer tracy.end();5362 defer tracy.end();
53335363
5334 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5364 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5335 const src = inst_data.src();5365 const src = inst_data.src();
5336 const ptr = try sema.resolveInst(inst_data.operand);5366 const ptr = sema.resolveInst(inst_data.operand);
5337 const loaded = try sema.analyzeLoad(block, src, ptr, src);5367 const loaded = try sema.analyzeLoad(block, src, ptr, src);
5338 return sema.analyzeIsNull(block, src, loaded, true);5368 return sema.analyzeIsNull(block, src, loaded, true);
5339}5369}
53405370
5341fn zirIsNonErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5371fn zirIsNonErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5342 const tracy = trace(@src());5372 const tracy = trace(@src());
5343 defer tracy.end();5373 defer tracy.end();
53445374
5345 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5375 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5346 const operand = try sema.resolveInst(inst_data.operand);5376 const operand = sema.resolveInst(inst_data.operand);
5347 return sema.analyzeIsNonErr(block, inst_data.src(), operand);5377 return sema.analyzeIsNonErr(block, inst_data.src(), operand);
5348}5378}
53495379
5350fn zirIsNonErrPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5380fn zirIsNonErrPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5351 const tracy = trace(@src());5381 const tracy = trace(@src());
5352 defer tracy.end();5382 defer tracy.end();
53535383
5354 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5384 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5355 const src = inst_data.src();5385 const src = inst_data.src();
5356 const ptr = try sema.resolveInst(inst_data.operand);5386 const ptr = sema.resolveInst(inst_data.operand);
5357 const loaded = try sema.analyzeLoad(block, src, ptr, src);5387 const loaded = try sema.analyzeLoad(block, src, ptr, src);
5358 return sema.analyzeIsNonErr(block, src, loaded);5388 return sema.analyzeIsNonErr(block, src, loaded);
5359}5389}
...@@ -5374,7 +5404,7 @@ fn zirCondbr(...@@ -5374,7 +5404,7 @@ fn zirCondbr(
5374 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];5404 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];
5375 const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];5405 const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
53765406
5377 const uncasted_cond = try sema.resolveInst(extra.data.condition);5407 const uncasted_cond = sema.resolveInst(extra.data.condition);
5378 const cond = try sema.coerce(parent_block, Type.initTag(.bool), uncasted_cond, cond_src);5408 const cond = try sema.coerce(parent_block, Type.initTag(.bool), uncasted_cond, cond_src);
53795409
5380 if (try sema.resolveDefinedValue(parent_block, src, cond)) |cond_val| {5410 if (try sema.resolveDefinedValue(parent_block, src, cond)) |cond_val| {
...@@ -5456,7 +5486,7 @@ fn zirRetCoerce(...@@ -5456,7 +5486,7 @@ fn zirRetCoerce(
5456 defer tracy.end();5486 defer tracy.end();
54575487
5458 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;5488 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
5459 const operand = try sema.resolveInst(inst_data.operand);5489 const operand = sema.resolveInst(inst_data.operand);
5460 const src = inst_data.src();5490 const src = inst_data.src();
54615491
5462 return sema.analyzeRet(block, operand, src, need_coercion);5492 return sema.analyzeRet(block, operand, src, need_coercion);
...@@ -5467,7 +5497,7 @@ fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -5467,7 +5497,7 @@ fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
5467 defer tracy.end();5497 defer tracy.end();
54685498
5469 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5499 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5470 const operand = try sema.resolveInst(inst_data.operand);5500 const operand = sema.resolveInst(inst_data.operand);
5471 const src = inst_data.src();5501 const src = inst_data.src();
54725502
5473 return sema.analyzeRet(block, operand, src, false);5503 return sema.analyzeRet(block, operand, src, false);
...@@ -5476,7 +5506,7 @@ fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -5476,7 +5506,7 @@ fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
5476fn analyzeRet(5506fn analyzeRet(
5477 sema: *Sema,5507 sema: *Sema,
5478 block: *Scope.Block,5508 block: *Scope.Block,
5479 operand: Air.Inst.Index,5509 operand: Air.Inst.Ref,
5480 src: LazySrcLoc,5510 src: LazySrcLoc,
5481 need_coercion: bool,5511 need_coercion: bool,
5482) InnerError!Zir.Inst.Index {5512) InnerError!Zir.Inst.Index {
...@@ -5511,7 +5541,7 @@ fn floatOpAllowed(tag: Zir.Inst.Tag) bool {...@@ -5511,7 +5541,7 @@ fn floatOpAllowed(tag: Zir.Inst.Tag) bool {
5511 };5541 };
5512}5542}
55135543
5514fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5544fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5515 const tracy = trace(@src());5545 const tracy = trace(@src());
5516 defer tracy.end();5546 defer tracy.end();
55175547
...@@ -5532,7 +5562,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne...@@ -5532,7 +5562,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
5532 return sema.mod.constType(sema.arena, .unneeded, ty);5562 return sema.mod.constType(sema.arena, .unneeded, ty);
5533}5563}
55345564
5535fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5565fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5536 const tracy = trace(@src());5566 const tracy = trace(@src());
5537 defer tracy.end();5567 defer tracy.end();
55385568
...@@ -5586,7 +5616,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -5586,7 +5616,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
5586 return sema.mod.constType(sema.arena, src, ty);5616 return sema.mod.constType(sema.arena, src, ty);
5587}5617}
55885618
5589fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5619fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5590 const tracy = trace(@src());5620 const tracy = trace(@src());
5591 defer tracy.end();5621 defer tracy.end();
55925622
...@@ -5600,13 +5630,13 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In...@@ -5600,13 +5630,13 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In
5600 });5630 });
5601}5631}
56025632
5603fn zirUnionInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5633fn zirUnionInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5604 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5634 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5605 const src = inst_data.src();5635 const src = inst_data.src();
5606 return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnionInitPtr", .{});5636 return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnionInitPtr", .{});
5607}5637}
56085638
5609fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Index {5639fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Ref {
5610 const mod = sema.mod;5640 const mod = sema.mod;
5611 const gpa = sema.gpa;5641 const gpa = sema.gpa;
5612 const zir_datas = sema.code.instructions.items(.data);5642 const zir_datas = sema.code.instructions.items(.data);
...@@ -5657,7 +5687,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:...@@ -5657,7 +5687,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
5657 return mod.failWithOwnedErrorMsg(&block.base, msg);5687 return mod.failWithOwnedErrorMsg(&block.base, msg);
5658 }5688 }
5659 found_fields[field_index] = item.data.field_type;5689 found_fields[field_index] = item.data.field_type;
5660 field_inits[field_index] = try sema.resolveInst(item.data.init);5690 field_inits[field_index] = sema.resolveInst(item.data.init);
5661 }5691 }
56625692
5663 var root_msg: ?*Module.ErrorMsg = null;5693 var root_msg: ?*Module.ErrorMsg = null;
...@@ -5719,7 +5749,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:...@@ -5719,7 +5749,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
5719 return mod.fail(&block.base, src, "TODO: Sema.zirStructInit for runtime-known struct values", .{});5749 return mod.fail(&block.base, src, "TODO: Sema.zirStructInit for runtime-known struct values", .{});
5720}5750}
57215751
5722fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Index {5752fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Ref {
5723 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5753 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5724 const src = inst_data.src();5754 const src = inst_data.src();
57255755
...@@ -5727,7 +5757,7 @@ fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_...@@ -5727,7 +5757,7 @@ fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_
5727 return sema.mod.fail(&block.base, src, "TODO: Sema.zirStructInitAnon", .{});5757 return sema.mod.fail(&block.base, src, "TODO: Sema.zirStructInitAnon", .{});
5728}5758}
57295759
5730fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Index {5760fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Ref {
5731 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5761 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5732 const src = inst_data.src();5762 const src = inst_data.src();
57335763
...@@ -5735,7 +5765,7 @@ fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:...@@ -5735,7 +5765,7 @@ fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
5735 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInit", .{});5765 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInit", .{});
5736}5766}
57375767
5738fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Index {5768fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Ref {
5739 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5769 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5740 const src = inst_data.src();5770 const src = inst_data.src();
57415771
...@@ -5743,13 +5773,13 @@ fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_r...@@ -5743,13 +5773,13 @@ fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_r
5743 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInitAnon", .{});5773 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInitAnon", .{});
5744}5774}
57455775
5746fn zirFieldTypeRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5776fn zirFieldTypeRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5747 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5777 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5748 const src = inst_data.src();5778 const src = inst_data.src();
5749 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldTypeRef", .{});5779 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldTypeRef", .{});
5750}5780}
57515781
5752fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5782fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5753 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5783 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5754 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;5784 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
5755 const src = inst_data.src();5785 const src = inst_data.src();
...@@ -5771,7 +5801,7 @@ fn zirErrorReturnTrace(...@@ -5771,7 +5801,7 @@ fn zirErrorReturnTrace(
5771 sema: *Sema,5801 sema: *Sema,
5772 block: *Scope.Block,5802 block: *Scope.Block,
5773 extended: Zir.Inst.Extended.InstData,5803 extended: Zir.Inst.Extended.InstData,
5774) InnerError!Air.Inst.Index {5804) InnerError!Air.Inst.Ref {
5775 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };5805 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
5776 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorReturnTrace", .{});5806 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorReturnTrace", .{});
5777}5807}
...@@ -5780,7 +5810,7 @@ fn zirFrame(...@@ -5780,7 +5810,7 @@ fn zirFrame(
5780 sema: *Sema,5810 sema: *Sema,
5781 block: *Scope.Block,5811 block: *Scope.Block,
5782 extended: Zir.Inst.Extended.InstData,5812 extended: Zir.Inst.Extended.InstData,
5783) InnerError!Air.Inst.Index {5813) InnerError!Air.Inst.Ref {
5784 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };5814 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
5785 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrame", .{});5815 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrame", .{});
5786}5816}
...@@ -5789,91 +5819,91 @@ fn zirFrameAddress(...@@ -5789,91 +5819,91 @@ fn zirFrameAddress(
5789 sema: *Sema,5819 sema: *Sema,
5790 block: *Scope.Block,5820 block: *Scope.Block,
5791 extended: Zir.Inst.Extended.InstData,5821 extended: Zir.Inst.Extended.InstData,
5792) InnerError!Air.Inst.Index {5822) InnerError!Air.Inst.Ref {
5793 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };5823 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
5794 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameAddress", .{});5824 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameAddress", .{});
5795}5825}
57965826
5797fn zirAlignOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5827fn zirAlignOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5798 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5828 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5799 const src = inst_data.src();5829 const src = inst_data.src();
5800 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignOf", .{});5830 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignOf", .{});
5801}5831}
58025832
5803fn zirBoolToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5833fn zirBoolToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5804 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5834 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5805 const src = inst_data.src();5835 const src = inst_data.src();
5806 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBoolToInt", .{});5836 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBoolToInt", .{});
5807}5837}
58085838
5809fn zirEmbedFile(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5839fn zirEmbedFile(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5810 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5840 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5811 const src = inst_data.src();5841 const src = inst_data.src();
5812 return sema.mod.fail(&block.base, src, "TODO: Sema.zirEmbedFile", .{});5842 return sema.mod.fail(&block.base, src, "TODO: Sema.zirEmbedFile", .{});
5813}5843}
58145844
5815fn zirErrorName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5845fn zirErrorName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5816 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5846 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5817 const src = inst_data.src();5847 const src = inst_data.src();
5818 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorName", .{});5848 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorName", .{});
5819}5849}
58205850
5821fn zirUnaryMath(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5851fn zirUnaryMath(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5822 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5852 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5823 const src = inst_data.src();5853 const src = inst_data.src();
5824 return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnaryMath", .{});5854 return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnaryMath", .{});
5825}5855}
58265856
5827fn zirTagName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5857fn zirTagName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5828 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5858 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5829 const src = inst_data.src();5859 const src = inst_data.src();
5830 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTagName", .{});5860 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTagName", .{});
5831}5861}
58325862
5833fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5863fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5834 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5864 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5835 const src = inst_data.src();5865 const src = inst_data.src();
5836 return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify", .{});5866 return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify", .{});
5837}5867}
58385868
5839fn zirTypeName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5869fn zirTypeName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5840 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5870 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5841 const src = inst_data.src();5871 const src = inst_data.src();
5842 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTypeName", .{});5872 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTypeName", .{});
5843}5873}
58445874
5845fn zirFrameType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5875fn zirFrameType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5846 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5876 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5847 const src = inst_data.src();5877 const src = inst_data.src();
5848 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameType", .{});5878 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameType", .{});
5849}5879}
58505880
5851fn zirFrameSize(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5881fn zirFrameSize(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5852 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5882 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5853 const src = inst_data.src();5883 const src = inst_data.src();
5854 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameSize", .{});5884 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameSize", .{});
5855}5885}
58565886
5857fn zirFloatToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5887fn zirFloatToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5858 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5888 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5859 const src = inst_data.src();5889 const src = inst_data.src();
5860 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFloatToInt", .{});5890 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFloatToInt", .{});
5861}5891}
58625892
5863fn zirIntToFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5893fn zirIntToFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5864 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5894 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5865 const src = inst_data.src();5895 const src = inst_data.src();
5866 return sema.mod.fail(&block.base, src, "TODO: Sema.zirIntToFloat", .{});5896 return sema.mod.fail(&block.base, src, "TODO: Sema.zirIntToFloat", .{});
5867}5897}
58685898
5869fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5899fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5870 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5900 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5871 const src = inst_data.src();5901 const src = inst_data.src();
58725902
5873 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;5903 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
58745904
5875 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };5905 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
5876 const operand_res = try sema.resolveInst(extra.rhs);5906 const operand_res = sema.resolveInst(extra.rhs);
5877 const operand_coerced = try sema.coerce(block, Type.initTag(.usize), operand_res, operand_src);5907 const operand_coerced = try sema.coerce(block, Type.initTag(.usize), operand_res, operand_src);
58785908
5879 const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };5909 const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
...@@ -5929,199 +5959,199 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -5929,199 +5959,199 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
5929 return block.addUnOp(src, type_res, .bitcast, operand_coerced);5959 return block.addUnOp(src, type_res, .bitcast, operand_coerced);
5930}5960}
59315961
5932fn zirErrSetCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5962fn zirErrSetCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5933 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5963 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5934 const src = inst_data.src();5964 const src = inst_data.src();
5935 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrSetCast", .{});5965 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrSetCast", .{});
5936}5966}
59375967
5938fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5968fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5939 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5969 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5940 const src = inst_data.src();5970 const src = inst_data.src();
5941 return sema.mod.fail(&block.base, src, "TODO: Sema.zirPtrCast", .{});5971 return sema.mod.fail(&block.base, src, "TODO: Sema.zirPtrCast", .{});
5942}5972}
59435973
5944fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5974fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5945 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5975 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5946 const src = inst_data.src();5976 const src = inst_data.src();
5947 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTruncate", .{});5977 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTruncate", .{});
5948}5978}
59495979
5950fn zirAlignCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5980fn zirAlignCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5951 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5981 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5952 const src = inst_data.src();5982 const src = inst_data.src();
5953 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignCast", .{});5983 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignCast", .{});
5954}5984}
59555985
5956fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5986fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5957 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5987 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5958 const src = inst_data.src();5988 const src = inst_data.src();
5959 return sema.mod.fail(&block.base, src, "TODO: Sema.zirClz", .{});5989 return sema.mod.fail(&block.base, src, "TODO: Sema.zirClz", .{});
5960}5990}
59615991
5962fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5992fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5963 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5993 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5964 const src = inst_data.src();5994 const src = inst_data.src();
5965 return sema.mod.fail(&block.base, src, "TODO: Sema.zirCtz", .{});5995 return sema.mod.fail(&block.base, src, "TODO: Sema.zirCtz", .{});
5966}5996}
59675997
5968fn zirPopCount(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {5998fn zirPopCount(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5969 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5999 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5970 const src = inst_data.src();6000 const src = inst_data.src();
5971 return sema.mod.fail(&block.base, src, "TODO: Sema.zirPopCount", .{});6001 return sema.mod.fail(&block.base, src, "TODO: Sema.zirPopCount", .{});
5972}6002}
59736003
5974fn zirByteSwap(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6004fn zirByteSwap(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5975 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6005 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5976 const src = inst_data.src();6006 const src = inst_data.src();
5977 return sema.mod.fail(&block.base, src, "TODO: Sema.zirByteSwap", .{});6007 return sema.mod.fail(&block.base, src, "TODO: Sema.zirByteSwap", .{});
5978}6008}
59796009
5980fn zirBitReverse(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6010fn zirBitReverse(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5981 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6011 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5982 const src = inst_data.src();6012 const src = inst_data.src();
5983 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitReverse", .{});6013 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitReverse", .{});
5984}6014}
59856015
5986fn zirDivExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6016fn zirDivExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5987 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6017 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5988 const src = inst_data.src();6018 const src = inst_data.src();
5989 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivExact", .{});6019 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivExact", .{});
5990}6020}
59916021
5992fn zirDivFloor(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6022fn zirDivFloor(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5993 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6023 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5994 const src = inst_data.src();6024 const src = inst_data.src();
5995 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivFloor", .{});6025 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivFloor", .{});
5996}6026}
59976027
5998fn zirDivTrunc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6028fn zirDivTrunc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
5999 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6029 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6000 const src = inst_data.src();6030 const src = inst_data.src();
6001 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivTrunc", .{});6031 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivTrunc", .{});
6002}6032}
60036033
6004fn zirMod(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6034fn zirMod(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6005 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6035 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6006 const src = inst_data.src();6036 const src = inst_data.src();
6007 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMod", .{});6037 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMod", .{});
6008}6038}
60096039
6010fn zirRem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6040fn zirRem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6011 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6041 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6012 const src = inst_data.src();6042 const src = inst_data.src();
6013 return sema.mod.fail(&block.base, src, "TODO: Sema.zirRem", .{});6043 return sema.mod.fail(&block.base, src, "TODO: Sema.zirRem", .{});
6014}6044}
60156045
6016fn zirShlExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6046fn zirShlExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6017 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6047 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6018 const src = inst_data.src();6048 const src = inst_data.src();
6019 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShlExact", .{});6049 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShlExact", .{});
6020}6050}
60216051
6022fn zirShrExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6052fn zirShrExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6023 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6053 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6024 const src = inst_data.src();6054 const src = inst_data.src();
6025 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShrExact", .{});6055 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShrExact", .{});
6026}6056}
60276057
6028fn zirBitOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6058fn zirBitOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6029 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6059 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6030 const src = inst_data.src();6060 const src = inst_data.src();
6031 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitOffsetOf", .{});6061 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitOffsetOf", .{});
6032}6062}
60336063
6034fn zirOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6064fn zirOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6035 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6065 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6036 const src = inst_data.src();6066 const src = inst_data.src();
6037 return sema.mod.fail(&block.base, src, "TODO: Sema.zirOffsetOf", .{});6067 return sema.mod.fail(&block.base, src, "TODO: Sema.zirOffsetOf", .{});
6038}6068}
60396069
6040fn zirCmpxchg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6070fn zirCmpxchg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6041 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6071 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6042 const src = inst_data.src();6072 const src = inst_data.src();
6043 return sema.mod.fail(&block.base, src, "TODO: Sema.zirCmpxchg", .{});6073 return sema.mod.fail(&block.base, src, "TODO: Sema.zirCmpxchg", .{});
6044}6074}
60456075
6046fn zirSplat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6076fn zirSplat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6047 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6077 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6048 const src = inst_data.src();6078 const src = inst_data.src();
6049 return sema.mod.fail(&block.base, src, "TODO: Sema.zirSplat", .{});6079 return sema.mod.fail(&block.base, src, "TODO: Sema.zirSplat", .{});
6050}6080}
60516081
6052fn zirReduce(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6082fn zirReduce(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6053 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6083 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6054 const src = inst_data.src();6084 const src = inst_data.src();
6055 return sema.mod.fail(&block.base, src, "TODO: Sema.zirReduce", .{});6085 return sema.mod.fail(&block.base, src, "TODO: Sema.zirReduce", .{});
6056}6086}
60576087
6058fn zirShuffle(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6088fn zirShuffle(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6059 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6089 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6060 const src = inst_data.src();6090 const src = inst_data.src();
6061 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShuffle", .{});6091 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShuffle", .{});
6062}6092}
60636093
6064fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6094fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6065 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6095 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6066 const src = inst_data.src();6096 const src = inst_data.src();
6067 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicLoad", .{});6097 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicLoad", .{});
6068}6098}
60696099
6070fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6100fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6071 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6101 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6072 const src = inst_data.src();6102 const src = inst_data.src();
6073 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicRmw", .{});6103 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicRmw", .{});
6074}6104}
60756105
6076fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6106fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6077 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6107 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6078 const src = inst_data.src();6108 const src = inst_data.src();
6079 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicStore", .{});6109 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicStore", .{});
6080}6110}
60816111
6082fn zirMulAdd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6112fn zirMulAdd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6083 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6113 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6084 const src = inst_data.src();6114 const src = inst_data.src();
6085 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMulAdd", .{});6115 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMulAdd", .{});
6086}6116}
60876117
6088fn zirBuiltinCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6118fn zirBuiltinCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6089 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6119 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6090 const src = inst_data.src();6120 const src = inst_data.src();
6091 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinCall", .{});6121 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinCall", .{});
6092}6122}
60936123
6094fn zirFieldPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6124fn zirFieldPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6095 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6125 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6096 const src = inst_data.src();6126 const src = inst_data.src();
6097 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldPtrType", .{});6127 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldPtrType", .{});
6098}6128}
60996129
6100fn zirFieldParentPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6130fn zirFieldParentPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6101 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6131 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6102 const src = inst_data.src();6132 const src = inst_data.src();
6103 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldParentPtr", .{});6133 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldParentPtr", .{});
6104}6134}
61056135
6106fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6136fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6107 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6137 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6108 const src = inst_data.src();6138 const src = inst_data.src();
6109 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemcpy", .{});6139 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemcpy", .{});
6110}6140}
61116141
6112fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6142fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6113 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6143 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6114 const src = inst_data.src();6144 const src = inst_data.src();
6115 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemset", .{});6145 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemset", .{});
6116}6146}
61176147
6118fn zirBuiltinAsyncCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6148fn zirBuiltinAsyncCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6119 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6149 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6120 const src = inst_data.src();6150 const src = inst_data.src();
6121 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinAsyncCall", .{});6151 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinAsyncCall", .{});
6122}6152}
61236153
6124fn zirResume(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {6154fn zirResume(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref {
6125 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6155 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6126 const src = inst_data.src();6156 const src = inst_data.src();
6127 return sema.mod.fail(&block.base, src, "TODO: Sema.zirResume", .{});6157 return sema.mod.fail(&block.base, src, "TODO: Sema.zirResume", .{});
...@@ -6132,7 +6162,7 @@ fn zirAwait(...@@ -6132,7 +6162,7 @@ fn zirAwait(
6132 block: *Scope.Block,6162 block: *Scope.Block,
6133 inst: Zir.Inst.Index,6163 inst: Zir.Inst.Index,
6134 is_nosuspend: bool,6164 is_nosuspend: bool,
6135) InnerError!Air.Inst.Index {6165) InnerError!Air.Inst.Ref {
6136 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6166 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6137 const src = inst_data.src();6167 const src = inst_data.src();
61386168
...@@ -6144,7 +6174,7 @@ fn zirVarExtended(...@@ -6144,7 +6174,7 @@ fn zirVarExtended(
6144 sema: *Sema,6174 sema: *Sema,
6145 block: *Scope.Block,6175 block: *Scope.Block,
6146 extended: Zir.Inst.Extended.InstData,6176 extended: Zir.Inst.Extended.InstData,
6147) InnerError!Air.Inst.Index {6177) InnerError!Air.Inst.Ref {
6148 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);6178 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
6149 const src = sema.src;6179 const src = sema.src;
6150 const ty_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at type6180 const ty_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at type
...@@ -6210,7 +6240,7 @@ fn zirFuncExtended(...@@ -6210,7 +6240,7 @@ fn zirFuncExtended(
6210 block: *Scope.Block,6240 block: *Scope.Block,
6211 extended: Zir.Inst.Extended.InstData,6241 extended: Zir.Inst.Extended.InstData,
6212 inst: Zir.Inst.Index,6242 inst: Zir.Inst.Index,
6213) InnerError!Air.Inst.Index {6243) InnerError!Air.Inst.Ref {
6214 const tracy = trace(@src());6244 const tracy = trace(@src());
6215 defer tracy.end();6245 defer tracy.end();
62166246
...@@ -6277,7 +6307,7 @@ fn zirCUndef(...@@ -6277,7 +6307,7 @@ fn zirCUndef(
6277 sema: *Sema,6307 sema: *Sema,
6278 block: *Scope.Block,6308 block: *Scope.Block,
6279 extended: Zir.Inst.Extended.InstData,6309 extended: Zir.Inst.Extended.InstData,
6280) InnerError!Air.Inst.Index {6310) InnerError!Air.Inst.Ref {
6281 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;6311 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6282 const src: LazySrcLoc = .{ .node_offset = extra.node };6312 const src: LazySrcLoc = .{ .node_offset = extra.node };
6283 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCUndef", .{});6313 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCUndef", .{});
...@@ -6287,7 +6317,7 @@ fn zirCInclude(...@@ -6287,7 +6317,7 @@ fn zirCInclude(
6287 sema: *Sema,6317 sema: *Sema,
6288 block: *Scope.Block,6318 block: *Scope.Block,
6289 extended: Zir.Inst.Extended.InstData,6319 extended: Zir.Inst.Extended.InstData,
6290) InnerError!Air.Inst.Index {6320) InnerError!Air.Inst.Ref {
6291 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;6321 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6292 const src: LazySrcLoc = .{ .node_offset = extra.node };6322 const src: LazySrcLoc = .{ .node_offset = extra.node };
6293 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCInclude", .{});6323 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCInclude", .{});
...@@ -6297,7 +6327,7 @@ fn zirCDefine(...@@ -6297,7 +6327,7 @@ fn zirCDefine(
6297 sema: *Sema,6327 sema: *Sema,
6298 block: *Scope.Block,6328 block: *Scope.Block,
6299 extended: Zir.Inst.Extended.InstData,6329 extended: Zir.Inst.Extended.InstData,
6300) InnerError!Air.Inst.Index {6330) InnerError!Air.Inst.Ref {
6301 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;6331 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
6302 const src: LazySrcLoc = .{ .node_offset = extra.node };6332 const src: LazySrcLoc = .{ .node_offset = extra.node };
6303 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCDefine", .{});6333 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCDefine", .{});
...@@ -6307,7 +6337,7 @@ fn zirWasmMemorySize(...@@ -6307,7 +6337,7 @@ fn zirWasmMemorySize(
6307 sema: *Sema,6337 sema: *Sema,
6308 block: *Scope.Block,6338 block: *Scope.Block,
6309 extended: Zir.Inst.Extended.InstData,6339 extended: Zir.Inst.Extended.InstData,
6310) InnerError!Air.Inst.Index {6340) InnerError!Air.Inst.Ref {
6311 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;6341 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6312 const src: LazySrcLoc = .{ .node_offset = extra.node };6342 const src: LazySrcLoc = .{ .node_offset = extra.node };
6313 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemorySize", .{});6343 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemorySize", .{});
...@@ -6317,7 +6347,7 @@ fn zirWasmMemoryGrow(...@@ -6317,7 +6347,7 @@ fn zirWasmMemoryGrow(
6317 sema: *Sema,6347 sema: *Sema,
6318 block: *Scope.Block,6348 block: *Scope.Block,
6319 extended: Zir.Inst.Extended.InstData,6349 extended: Zir.Inst.Extended.InstData,
6320) InnerError!Air.Inst.Index {6350) InnerError!Air.Inst.Ref {
6321 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;6351 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
6322 const src: LazySrcLoc = .{ .node_offset = extra.node };6352 const src: LazySrcLoc = .{ .node_offset = extra.node };
6323 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemoryGrow", .{});6353 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemoryGrow", .{});
...@@ -6327,7 +6357,7 @@ fn zirBuiltinExtern(...@@ -6327,7 +6357,7 @@ fn zirBuiltinExtern(
6327 sema: *Sema,6357 sema: *Sema,
6328 block: *Scope.Block,6358 block: *Scope.Block,
6329 extended: Zir.Inst.Extended.InstData,6359 extended: Zir.Inst.Extended.InstData,
6330) InnerError!Air.Inst.Index {6360) InnerError!Air.Inst.Ref {
6331 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;6361 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
6332 const src: LazySrcLoc = .{ .node_offset = extra.node };6362 const src: LazySrcLoc = .{ .node_offset = extra.node };
6333 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinExtern", .{});6363 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinExtern", .{});
...@@ -6361,7 +6391,7 @@ pub const PanicId = enum {...@@ -6361,7 +6391,7 @@ pub const PanicId = enum {
6361 invalid_error_code,6391 invalid_error_code,
6362};6392};
63636393
6364fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: Air.Inst.Index, panic_id: PanicId) !void {6394fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: Air.Inst.Ref, panic_id: PanicId) !void {
6365 const block_inst = try sema.arena.create(Inst.Block);6395 const block_inst = try sema.arena.create(Inst.Block);
6366 block_inst.* = .{6396 block_inst.* = .{
6367 .base = .{6397 .base = .{
...@@ -6423,7 +6453,7 @@ fn panicWithMsg(...@@ -6423,7 +6453,7 @@ fn panicWithMsg(
6423 sema: *Sema,6453 sema: *Sema,
6424 block: *Scope.Block,6454 block: *Scope.Block,
6425 src: LazySrcLoc,6455 src: LazySrcLoc,
6426 msg_inst: Air.Inst.Index,6456 msg_inst: Air.Inst.Ref,
6427) !Zir.Inst.Index {6457) !Zir.Inst.Index {
6428 const mod = sema.mod;6458 const mod = sema.mod;
6429 const arena = sema.arena;6459 const arena = sema.arena;
...@@ -6439,7 +6469,7 @@ fn panicWithMsg(...@@ -6439,7 +6469,7 @@ fn panicWithMsg(
6439 const panic_fn = try sema.getBuiltin(block, src, "panic");6469 const panic_fn = try sema.getBuiltin(block, src, "panic");
6440 const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace");6470 const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace");
6441 const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty);6471 const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty);
6442 const ptr_stack_trace_ty = try mod.simplePtrType(arena, stack_trace_ty, true, .One);6472 const ptr_stack_trace_ty = try Module.simplePtrType(arena, stack_trace_ty, true, .One);
6443 const null_stack_trace = try mod.constInst(arena, src, .{6473 const null_stack_trace = try mod.constInst(arena, src, .{
6444 .ty = try mod.optionalType(arena, ptr_stack_trace_ty),6474 .ty = try mod.optionalType(arena, ptr_stack_trace_ty),
6445 .val = Value.initTag(.null_value),6475 .val = Value.initTag(.null_value),
...@@ -6500,10 +6530,10 @@ fn namedFieldPtr(...@@ -6500,10 +6530,10 @@ fn namedFieldPtr(
6500 sema: *Sema,6530 sema: *Sema,
6501 block: *Scope.Block,6531 block: *Scope.Block,
6502 src: LazySrcLoc,6532 src: LazySrcLoc,
6503 object_ptr: Air.Inst.Index,6533 object_ptr: Air.Inst.Ref,
6504 field_name: []const u8,6534 field_name: []const u8,
6505 field_name_src: LazySrcLoc,6535 field_name_src: LazySrcLoc,
6506) InnerError!Air.Inst.Index {6536) InnerError!Air.Inst.Ref {
6507 const mod = sema.mod;6537 const mod = sema.mod;
6508 const arena = sema.arena;6538 const arena = sema.arena;
65096539
...@@ -6579,7 +6609,7 @@ fn namedFieldPtr(...@@ -6579,7 +6609,7 @@ fn namedFieldPtr(
6579 } else (try mod.getErrorValue(field_name)).key;6609 } else (try mod.getErrorValue(field_name)).key;
65806610
6581 return mod.constInst(arena, src, .{6611 return mod.constInst(arena, src, .{
6582 .ty = try mod.simplePtrType(arena, child_type, false, .One),6612 .ty = try Module.simplePtrType(arena, child_type, false, .One),
6583 .val = try Value.Tag.ref_val.create(6613 .val = try Value.Tag.ref_val.create(
6584 arena,6614 arena,
6585 try Value.Tag.@"error".create(arena, .{6615 try Value.Tag.@"error".create(arena, .{
...@@ -6633,7 +6663,7 @@ fn namedFieldPtr(...@@ -6633,7 +6663,7 @@ fn namedFieldPtr(
6633 const field_index_u32 = @intCast(u32, field_index);6663 const field_index_u32 = @intCast(u32, field_index);
6634 const enum_val = try Value.Tag.enum_field_index.create(arena, field_index_u32);6664 const enum_val = try Value.Tag.enum_field_index.create(arena, field_index_u32);
6635 return mod.constInst(arena, src, .{6665 return mod.constInst(arena, src, .{
6636 .ty = try mod.simplePtrType(arena, child_type, false, .One),6666 .ty = try Module.simplePtrType(arena, child_type, false, .One),
6637 .val = try Value.Tag.ref_val.create(arena, enum_val),6667 .val = try Value.Tag.ref_val.create(arena, enum_val),
6638 });6668 });
6639 },6669 },
...@@ -6653,7 +6683,7 @@ fn analyzeNamespaceLookup(...@@ -6653,7 +6683,7 @@ fn analyzeNamespaceLookup(
6653 src: LazySrcLoc,6683 src: LazySrcLoc,
6654 namespace: *Scope.Namespace,6684 namespace: *Scope.Namespace,
6655 decl_name: []const u8,6685 decl_name: []const u8,
6656) InnerError!?Air.Inst.Index {6686) InnerError!?Air.Inst.Ref {
6657 const mod = sema.mod;6687 const mod = sema.mod;
6658 const gpa = sema.gpa;6688 const gpa = sema.gpa;
6659 if (try sema.lookupInNamespace(namespace, decl_name)) |decl| {6689 if (try sema.lookupInNamespace(namespace, decl_name)) |decl| {
...@@ -6677,11 +6707,11 @@ fn analyzeStructFieldPtr(...@@ -6677,11 +6707,11 @@ fn analyzeStructFieldPtr(
6677 sema: *Sema,6707 sema: *Sema,
6678 block: *Scope.Block,6708 block: *Scope.Block,
6679 src: LazySrcLoc,6709 src: LazySrcLoc,
6680 struct_ptr: Air.Inst.Index,6710 struct_ptr: Air.Inst.Ref,
6681 field_name: []const u8,6711 field_name: []const u8,
6682 field_name_src: LazySrcLoc,6712 field_name_src: LazySrcLoc,
6683 unresolved_struct_ty: Type,6713 unresolved_struct_ty: Type,
6684) InnerError!Air.Inst.Index {6714) InnerError!Air.Inst.Ref {
6685 const mod = sema.mod;6715 const mod = sema.mod;
6686 const arena = sema.arena;6716 const arena = sema.arena;
6687 assert(unresolved_struct_ty.zigTypeTag() == .Struct);6717 assert(unresolved_struct_ty.zigTypeTag() == .Struct);
...@@ -6692,7 +6722,7 @@ fn analyzeStructFieldPtr(...@@ -6692,7 +6722,7 @@ fn analyzeStructFieldPtr(
6692 const field_index = struct_obj.fields.getIndex(field_name) orelse6722 const field_index = struct_obj.fields.getIndex(field_name) orelse
6693 return sema.failWithBadFieldAccess(block, struct_obj, field_name_src, field_name);6723 return sema.failWithBadFieldAccess(block, struct_obj, field_name_src, field_name);
6694 const field = struct_obj.fields.values()[field_index];6724 const field = struct_obj.fields.values()[field_index];
6695 const ptr_field_ty = try mod.simplePtrType(arena, field.ty, true, .One);6725 const ptr_field_ty = try Module.simplePtrType(arena, field.ty, true, .One);
66966726
6697 if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| {6727 if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| {
6698 return mod.constInst(arena, src, .{6728 return mod.constInst(arena, src, .{
...@@ -6712,11 +6742,11 @@ fn analyzeUnionFieldPtr(...@@ -6712,11 +6742,11 @@ fn analyzeUnionFieldPtr(
6712 sema: *Sema,6742 sema: *Sema,
6713 block: *Scope.Block,6743 block: *Scope.Block,
6714 src: LazySrcLoc,6744 src: LazySrcLoc,
6715 union_ptr: Air.Inst.Index,6745 union_ptr: Air.Inst.Ref,
6716 field_name: []const u8,6746 field_name: []const u8,
6717 field_name_src: LazySrcLoc,6747 field_name_src: LazySrcLoc,
6718 unresolved_union_ty: Type,6748 unresolved_union_ty: Type,
6719) InnerError!Air.Inst.Index {6749) InnerError!Air.Inst.Ref {
6720 const mod = sema.mod;6750 const mod = sema.mod;
6721 const arena = sema.arena;6751 const arena = sema.arena;
6722 assert(unresolved_union_ty.zigTypeTag() == .Union);6752 assert(unresolved_union_ty.zigTypeTag() == .Union);
...@@ -6728,7 +6758,7 @@ fn analyzeUnionFieldPtr(...@@ -6728,7 +6758,7 @@ fn analyzeUnionFieldPtr(
6728 return sema.failWithBadUnionFieldAccess(block, union_obj, field_name_src, field_name);6758 return sema.failWithBadUnionFieldAccess(block, union_obj, field_name_src, field_name);
67296759
6730 const field = union_obj.fields.values()[field_index];6760 const field = union_obj.fields.values()[field_index];
6731 const ptr_field_ty = try mod.simplePtrType(arena, field.ty, true, .One);6761 const ptr_field_ty = try Module.simplePtrType(arena, field.ty, true, .One);
67326762
6733 if (try sema.resolveDefinedValue(block, src, union_ptr)) |union_ptr_val| {6763 if (try sema.resolveDefinedValue(block, src, union_ptr)) |union_ptr_val| {
6734 // TODO detect inactive union field and emit compile error6764 // TODO detect inactive union field and emit compile error
...@@ -6749,10 +6779,10 @@ fn elemPtr(...@@ -6749,10 +6779,10 @@ fn elemPtr(
6749 sema: *Sema,6779 sema: *Sema,
6750 block: *Scope.Block,6780 block: *Scope.Block,
6751 src: LazySrcLoc,6781 src: LazySrcLoc,
6752 array_ptr: Air.Inst.Index,6782 array_ptr: Air.Inst.Ref,
6753 elem_index: Air.Inst.Index,6783 elem_index: Air.Inst.Ref,
6754 elem_index_src: LazySrcLoc,6784 elem_index_src: LazySrcLoc,
6755) InnerError!Air.Inst.Index {6785) InnerError!Air.Inst.Ref {
6756 const array_ty = switch (array_ptr.ty.zigTypeTag()) {6786 const array_ty = switch (array_ptr.ty.zigTypeTag()) {
6757 .Pointer => array_ptr.ty.elemType(),6787 .Pointer => array_ptr.ty.elemType(),
6758 else => return sema.mod.fail(&block.base, array_ptr.src, "expected pointer, found '{}'", .{array_ptr.ty}),6788 else => return sema.mod.fail(&block.base, array_ptr.src, "expected pointer, found '{}'", .{array_ptr.ty}),
...@@ -6776,10 +6806,10 @@ fn elemPtrArray(...@@ -6776,10 +6806,10 @@ fn elemPtrArray(
6776 sema: *Sema,6806 sema: *Sema,
6777 block: *Scope.Block,6807 block: *Scope.Block,
6778 src: LazySrcLoc,6808 src: LazySrcLoc,
6779 array_ptr: Air.Inst.Index,6809 array_ptr: Air.Inst.Ref,
6780 elem_index: Air.Inst.Index,6810 elem_index: Air.Inst.Ref,
6781 elem_index_src: LazySrcLoc,6811 elem_index_src: LazySrcLoc,
6782) InnerError!Air.Inst.Index {6812) InnerError!Air.Inst.Ref {
6783 if (array_ptr.value()) |array_ptr_val| {6813 if (array_ptr.value()) |array_ptr_val| {
6784 if (elem_index.value()) |index_val| {6814 if (elem_index.value()) |index_val| {
6785 // Both array pointer and index are compile-time known.6815 // Both array pointer and index are compile-time known.
...@@ -6804,35 +6834,41 @@ fn coerce(...@@ -6804,35 +6834,41 @@ fn coerce(
6804 sema: *Sema,6834 sema: *Sema,
6805 block: *Scope.Block,6835 block: *Scope.Block,
6806 dest_type: Type,6836 dest_type: Type,
6807 inst: Air.Inst.Index,6837 inst: Air.Inst.Ref,
6808 inst_src: LazySrcLoc,6838 inst_src: LazySrcLoc,
6809) InnerError!Air.Inst.Index {6839) InnerError!Air.Inst.Ref {
6810 if (dest_type.tag() == .var_args_param) {6840 if (dest_type.tag() == .var_args_param) {
6811 return sema.coerceVarArgParam(block, inst);6841 return sema.coerceVarArgParam(block, inst, inst_src);
6812 }6842 }
6843
6844 const inst_ty = sema.getTypeOfAirRef(inst);
6813 // If the types are the same, we can return the operand.6845 // If the types are the same, we can return the operand.
6814 if (dest_type.eql(inst.ty))6846 if (dest_type.eql(inst_ty))
6815 return inst;6847 return inst;
68166848
6817 const in_memory_result = coerceInMemoryAllowed(dest_type, inst.ty);6849 const in_memory_result = coerceInMemoryAllowed(dest_type, inst_ty);
6818 if (in_memory_result == .ok) {6850 if (in_memory_result == .ok) {
6819 return sema.bitcast(block, dest_type, inst);6851 return sema.bitcast(block, dest_type, inst, inst_src);
6820 }6852 }
68216853
6822 const mod = sema.mod;6854 const mod = sema.mod;
6823 const arena = sema.arena;6855 const arena = sema.arena;
68246856
6825 // undefined to anything6857 // undefined to anything
6826 if (inst.value()) |val| {6858 if (try sema.resolvePossiblyUndefinedValue(block, inst_src, inst)) |val| {
6827 if (val.isUndef() or inst.ty.zigTypeTag() == .Undefined) {6859 if (val.isUndef() or inst_ty.zigTypeTag() == .Undefined) {
6828 return mod.constInst(arena, inst_src, .{ .ty = dest_type, .val = val });6860 return sema.addConstant(dest_type, val);
6829 }6861 }
6830 }6862 }
6831 assert(inst.ty.zigTypeTag() != .Undefined);6863 assert(inst_ty.zigTypeTag() != .Undefined);
6864
6865 if (true) {
6866 @panic("TODO finish AIR memory layout rework");
6867 }
68326868
6833 // T to E!T or E to E!T6869 // T to E!T or E to E!T
6834 if (dest_type.tag() == .error_union) {6870 if (dest_type.tag() == .error_union) {
6835 return try sema.wrapErrorUnion(block, dest_type, inst);6871 return try sema.wrapErrorUnion(block, dest_type, inst, inst_src);
6836 }6872 }
68376873
6838 // comptime known number to other number6874 // comptime known number to other number
...@@ -6844,14 +6880,14 @@ fn coerce(...@@ -6844,14 +6880,14 @@ fn coerce(
6844 switch (dest_type.zigTypeTag()) {6880 switch (dest_type.zigTypeTag()) {
6845 .Optional => {6881 .Optional => {
6846 // null to ?T6882 // null to ?T
6847 if (inst.ty.zigTypeTag() == .Null) {6883 if (inst_ty.zigTypeTag() == .Null) {
6848 return mod.constInst(arena, inst_src, .{ .ty = dest_type, .val = Value.initTag(.null_value) });6884 return mod.constInst(arena, inst_src, .{ .ty = dest_type, .val = Value.initTag(.null_value) });
6849 }6885 }
68506886
6851 // T to ?T6887 // T to ?T
6852 var buf: Type.Payload.ElemType = undefined;6888 var buf: Type.Payload.ElemType = undefined;
6853 const child_type = dest_type.optionalChild(&buf);6889 const child_type = dest_type.optionalChild(&buf);
6854 if (child_type.eql(inst.ty)) {6890 if (child_type.eql(inst_ty)) {
6855 return sema.wrapOptional(block, dest_type, inst);6891 return sema.wrapOptional(block, dest_type, inst);
6856 } else if (try sema.coerceNum(block, child_type, inst)) |some| {6892 } else if (try sema.coerceNum(block, child_type, inst)) |some| {
6857 return sema.wrapOptional(block, dest_type, some);6893 return sema.wrapOptional(block, dest_type, some);
...@@ -6860,12 +6896,12 @@ fn coerce(...@@ -6860,12 +6896,12 @@ fn coerce(
6860 .Pointer => {6896 .Pointer => {
6861 // Coercions where the source is a single pointer to an array.6897 // Coercions where the source is a single pointer to an array.
6862 src_array_ptr: {6898 src_array_ptr: {
6863 if (!inst.ty.isSinglePointer()) break :src_array_ptr;6899 if (!inst_ty.isSinglePointer()) break :src_array_ptr;
6864 const array_type = inst.ty.elemType();6900 const array_type = inst_ty.elemType();
6865 if (array_type.zigTypeTag() != .Array) break :src_array_ptr;6901 if (array_type.zigTypeTag() != .Array) break :src_array_ptr;
6866 const array_elem_type = array_type.elemType();6902 const array_elem_type = array_type.elemType();
6867 if (inst.ty.isConstPtr() and !dest_type.isConstPtr()) break :src_array_ptr;6903 if (inst_ty.isConstPtr() and !dest_type.isConstPtr()) break :src_array_ptr;
6868 if (inst.ty.isVolatilePtr() and !dest_type.isVolatilePtr()) break :src_array_ptr;6904 if (inst_ty.isVolatilePtr() and !dest_type.isVolatilePtr()) break :src_array_ptr;
68696905
6870 const dst_elem_type = dest_type.elemType();6906 const dst_elem_type = dest_type.elemType();
6871 switch (coerceInMemoryAllowed(dst_elem_type, array_elem_type)) {6907 switch (coerceInMemoryAllowed(dst_elem_type, array_elem_type)) {
...@@ -6904,11 +6940,11 @@ fn coerce(...@@ -6904,11 +6940,11 @@ fn coerce(
6904 },6940 },
6905 .Int => {6941 .Int => {
6906 // integer widening6942 // integer widening
6907 if (inst.ty.zigTypeTag() == .Int) {6943 if (inst_ty.zigTypeTag() == .Int) {
6908 assert(inst.value() == null); // handled above6944 assert(inst.value() == null); // handled above
69096945
6910 const dst_info = dest_type.intInfo(target);6946 const dst_info = dest_type.intInfo(target);
6911 const src_info = inst.ty.intInfo(target);6947 const src_info = inst_ty.intInfo(target);
6912 if ((src_info.signedness == dst_info.signedness and dst_info.bits >= src_info.bits) or6948 if ((src_info.signedness == dst_info.signedness and dst_info.bits >= src_info.bits) or
6913 // small enough unsigned ints can get casted to large enough signed ints6949 // small enough unsigned ints can get casted to large enough signed ints
6914 (src_info.signedness == .signed and dst_info.signedness == .unsigned and dst_info.bits > src_info.bits))6950 (src_info.signedness == .signed and dst_info.signedness == .unsigned and dst_info.bits > src_info.bits))
...@@ -6920,10 +6956,10 @@ fn coerce(...@@ -6920,10 +6956,10 @@ fn coerce(
6920 },6956 },
6921 .Float => {6957 .Float => {
6922 // float widening6958 // float widening
6923 if (inst.ty.zigTypeTag() == .Float) {6959 if (inst_ty.zigTypeTag() == .Float) {
6924 assert(inst.value() == null); // handled above6960 assert(inst.value() == null); // handled above
69256961
6926 const src_bits = inst.ty.floatBits(target);6962 const src_bits = inst_ty.floatBits(target);
6927 const dst_bits = dest_type.floatBits(target);6963 const dst_bits = dest_type.floatBits(target);
6928 if (dst_bits >= src_bits) {6964 if (dst_bits >= src_bits) {
6929 try sema.requireRuntimeBlock(block, inst_src);6965 try sema.requireRuntimeBlock(block, inst_src);
...@@ -6933,7 +6969,7 @@ fn coerce(...@@ -6933,7 +6969,7 @@ fn coerce(
6933 },6969 },
6934 .Enum => {6970 .Enum => {
6935 // enum literal to enum6971 // enum literal to enum
6936 if (inst.ty.zigTypeTag() == .EnumLiteral) {6972 if (inst_ty.zigTypeTag() == .EnumLiteral) {
6937 const val = try sema.resolveConstValue(block, inst_src, inst);6973 const val = try sema.resolveConstValue(block, inst_src, inst);
6938 const bytes = val.castTag(.enum_literal).?.data;6974 const bytes = val.castTag(.enum_literal).?.data;
6939 const resolved_dest_type = try sema.resolveTypeFields(block, inst_src, dest_type);6975 const resolved_dest_type = try sema.resolveTypeFields(block, inst_src, dest_type);
...@@ -6965,7 +7001,7 @@ fn coerce(...@@ -6965,7 +7001,7 @@ fn coerce(
6965 else => {},7001 else => {},
6966 }7002 }
69677003
6968 return mod.fail(&block.base, inst_src, "expected {}, found {}", .{ dest_type, inst.ty });7004 return mod.fail(&block.base, inst_src, "expected {}, found {}", .{ dest_type, inst_ty });
6969}7005}
69707006
6971const InMemoryCoercionResult = enum {7007const InMemoryCoercionResult = enum {
...@@ -6982,7 +7018,7 @@ fn coerceInMemoryAllowed(dest_type: Type, src_type: Type) InMemoryCoercionResult...@@ -6982,7 +7018,7 @@ fn coerceInMemoryAllowed(dest_type: Type, src_type: Type) InMemoryCoercionResult
6982 return .no_match;7018 return .no_match;
6983}7019}
69847020
6985fn coerceNum(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) InnerError!?Air.Inst.Index {7021fn coerceNum(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Ref) InnerError!?Air.Inst.Index {
6986 const val = inst.value() orelse return null;7022 const val = inst.value() orelse return null;
6987 const src_zig_tag = inst.ty.zigTypeTag();7023 const src_zig_tag = inst.ty.zigTypeTag();
6988 const dst_zig_tag = dest_type.zigTypeTag();7024 const dst_zig_tag = dest_type.zigTypeTag();
...@@ -7020,9 +7056,15 @@ fn coerceNum(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.I...@@ -7020,9 +7056,15 @@ fn coerceNum(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.I
7020 return null;7056 return null;
7021}7057}
70227058
7023fn coerceVarArgParam(sema: *Sema, block: *Scope.Block, inst: Air.Inst.Index) !Air.Inst.Index {7059fn coerceVarArgParam(
7024 switch (inst.ty.zigTypeTag()) {7060 sema: *Sema,
7025 .ComptimeInt, .ComptimeFloat => return sema.mod.fail(&block.base, inst.src, "integer and float literals in var args function must be casted", .{}),7061 block: *Scope.Block,
7062 inst: Air.Inst.Ref,
7063 inst_src: LazySrcLoc,
7064) !Air.Inst.Ref {
7065 const inst_ty = sema.getTypeOfAirRef(inst);
7066 switch (inst_ty.zigTypeTag()) {
7067 .ComptimeInt, .ComptimeFloat => return sema.mod.fail(&block.base, inst_src, "integer and float literals in var args function must be casted", .{}),
7026 else => {},7068 else => {},
7027 }7069 }
7028 // TODO implement more of this function.7070 // TODO implement more of this function.
...@@ -7033,8 +7075,8 @@ fn storePtr(...@@ -7033,8 +7075,8 @@ fn storePtr(
7033 sema: *Sema,7075 sema: *Sema,
7034 block: *Scope.Block,7076 block: *Scope.Block,
7035 src: LazySrcLoc,7077 src: LazySrcLoc,
7036 ptr: Air.Inst.Index,7078 ptr: Air.Inst.Ref,
7037 uncasted_value: Air.Inst.Index,7079 uncasted_value: Air.Inst.Ref,
7038) !void {7080) !void {
7039 if (ptr.ty.isConstPtr())7081 if (ptr.ty.isConstPtr())
7040 return sema.mod.fail(&block.base, src, "cannot assign to constant", .{});7082 return sema.mod.fail(&block.base, src, "cannot assign to constant", .{});
...@@ -7082,17 +7124,23 @@ fn storePtr(...@@ -7082,17 +7124,23 @@ fn storePtr(
7082 _ = try block.addBinOp(src, Type.initTag(.void), .store, ptr, value);7124 _ = try block.addBinOp(src, Type.initTag(.void), .store, ptr, value);
7083}7125}
70847126
7085fn bitcast(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) !Air.Inst.Index {7127fn bitcast(
7086 if (inst.value()) |val| {7128 sema: *Sema,
7129 block: *Scope.Block,
7130 dest_type: Type,
7131 inst: Air.Inst.Ref,
7132 inst_src: LazySrcLoc,
7133) InnerError!Air.Inst.Ref {
7134 if (try sema.resolvePossiblyUndefinedValue(block, inst_src, inst)) |val| {
7087 // Keep the comptime Value representation; take the new type.7135 // Keep the comptime Value representation; take the new type.
7088 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });7136 return sema.addConstant(dest_type, val);
7089 }7137 }
7090 // TODO validate the type size and other compile errors7138 // TODO validate the type size and other compile errors
7091 try sema.requireRuntimeBlock(block, inst.src);7139 try sema.requireRuntimeBlock(block, inst_src);
7092 return block.addUnOp(inst.src, dest_type, .bitcast, inst);7140 return block.addTyOp(.bitcast, dest_type, inst);
7093}7141}
70947142
7095fn coerceArrayPtrToSlice(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) !Air.Inst.Index {7143fn coerceArrayPtrToSlice(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Ref) InnerError!Air.Inst.Ref {
7096 if (inst.value()) |val| {7144 if (inst.value()) |val| {
7097 // The comptime Value representation is compatible with both types.7145 // The comptime Value representation is compatible with both types.
7098 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });7146 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });
...@@ -7100,7 +7148,7 @@ fn coerceArrayPtrToSlice(sema: *Sema, block: *Scope.Block, dest_type: Type, inst...@@ -7100,7 +7148,7 @@ fn coerceArrayPtrToSlice(sema: *Sema, block: *Scope.Block, dest_type: Type, inst
7100 return sema.mod.fail(&block.base, inst.src, "TODO implement coerceArrayPtrToSlice runtime instruction", .{});7148 return sema.mod.fail(&block.base, inst.src, "TODO implement coerceArrayPtrToSlice runtime instruction", .{});
7101}7149}
71027150
7103fn coerceArrayPtrToMany(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) !Air.Inst.Index {7151fn coerceArrayPtrToMany(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Ref) !Air.Inst.Ref {
7104 if (inst.value()) |val| {7152 if (inst.value()) |val| {
7105 // The comptime Value representation is compatible with both types.7153 // The comptime Value representation is compatible with both types.
7106 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });7154 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });
...@@ -7108,12 +7156,12 @@ fn coerceArrayPtrToMany(sema: *Sema, block: *Scope.Block, dest_type: Type, inst:...@@ -7108,12 +7156,12 @@ fn coerceArrayPtrToMany(sema: *Sema, block: *Scope.Block, dest_type: Type, inst:
7108 return sema.mod.fail(&block.base, inst.src, "TODO implement coerceArrayPtrToMany runtime instruction", .{});7156 return sema.mod.fail(&block.base, inst.src, "TODO implement coerceArrayPtrToMany runtime instruction", .{});
7109}7157}
71107158
7111fn analyzeDeclVal(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) InnerError!Air.Inst.Index {7159fn analyzeDeclVal(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) InnerError!Air.Inst.Ref {
7112 const decl_ref = try sema.analyzeDeclRef(block, src, decl);7160 const decl_ref = try sema.analyzeDeclRef(block, src, decl);
7113 return sema.analyzeLoad(block, src, decl_ref, src);7161 return sema.analyzeLoad(block, src, decl_ref, src);
7114}7162}
71157163
7116fn analyzeDeclRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) InnerError!Air.Inst.Index {7164fn analyzeDeclRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) InnerError!Air.Inst.Ref {
7117 try sema.mod.declareDeclDependency(sema.owner_decl, decl);7165 try sema.mod.declareDeclDependency(sema.owner_decl, decl);
7118 sema.mod.ensureDeclAnalyzed(decl) catch |err| {7166 sema.mod.ensureDeclAnalyzed(decl) catch |err| {
7119 if (sema.func) |func| {7167 if (sema.func) |func| {
...@@ -7128,43 +7176,41 @@ fn analyzeDeclRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl...@@ -7128,43 +7176,41 @@ fn analyzeDeclRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl
7128 if (decl_tv.val.tag() == .variable) {7176 if (decl_tv.val.tag() == .variable) {
7129 return sema.analyzeVarRef(block, src, decl_tv);7177 return sema.analyzeVarRef(block, src, decl_tv);
7130 }7178 }
7131 return sema.mod.constInst(sema.arena, src, .{7179 return sema.addConstant(
7132 .ty = try sema.mod.simplePtrType(sema.arena, decl_tv.ty, false, .One),7180 try Module.simplePtrType(sema.arena, decl_tv.ty, false, .One),
7133 .val = try Value.Tag.decl_ref.create(sema.arena, decl),7181 try Value.Tag.decl_ref.create(sema.arena, decl),
7134 });7182 );
7135}7183}
71367184
7137fn analyzeVarRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, tv: TypedValue) InnerError!Air.Inst.Index {7185fn analyzeVarRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, tv: TypedValue) InnerError!Air.Inst.Ref {
7138 const variable = tv.val.castTag(.variable).?.data;7186 const variable = tv.val.castTag(.variable).?.data;
71397187
7140 const ty = try sema.mod.simplePtrType(sema.arena, tv.ty, variable.is_mutable, .One);7188 const ty = try Module.simplePtrType(sema.arena, tv.ty, variable.is_mutable, .One);
7141 if (!variable.is_mutable and !variable.is_extern) {7189 if (!variable.is_mutable and !variable.is_extern) {
7142 return sema.mod.constInst(sema.arena, src, .{7190 return sema.addConstant(ty, try Value.Tag.ref_val.create(sema.arena, variable.init));
7143 .ty = ty,
7144 .val = try Value.Tag.ref_val.create(sema.arena, variable.init),
7145 });
7146 }7191 }
71477192
7193 const gpa = sema.gpa;
7148 try sema.requireRuntimeBlock(block, src);7194 try sema.requireRuntimeBlock(block, src);
7149 const inst = try sema.arena.create(Inst.VarPtr);7195 try sema.air_variables.append(gpa, variable);
7150 inst.* = .{7196 const result_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);
7151 .base = .{7197 try sema.air_instructions.append(gpa, .{
7152 .tag = .varptr,7198 .tag = .varptr,
7153 .ty = ty,7199 .data = .{ .ty_pl = .{
7154 .src = src,7200 .ty = try sema.addType(ty),
7155 },7201 .payload = @intCast(u32, sema.air_variables.items.len - 1),
7156 .variable = variable,7202 } },
7157 };7203 });
7158 try block.instructions.append(sema.gpa, &inst.base);7204 try block.instructions.append(gpa, result_inst);
7159 return &inst.base;7205 return indexToRef(result_inst);
7160}7206}
71617207
7162fn analyzeRef(7208fn analyzeRef(
7163 sema: *Sema,7209 sema: *Sema,
7164 block: *Scope.Block,7210 block: *Scope.Block,
7165 src: LazySrcLoc,7211 src: LazySrcLoc,
7166 operand: Air.Inst.Index,7212 operand: Air.Inst.Ref,
7167) InnerError!Air.Inst.Index {7213) InnerError!Air.Inst.Ref {
7168 const ptr_type = try sema.mod.simplePtrType(sema.arena, operand.ty, false, .One);7214 const ptr_type = try sema.mod.simplePtrType(sema.arena, operand.ty, false, .One);
71697215
7170 if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |val| {7216 if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |val| {
...@@ -7182,34 +7228,32 @@ fn analyzeLoad(...@@ -7182,34 +7228,32 @@ fn analyzeLoad(
7182 sema: *Sema,7228 sema: *Sema,
7183 block: *Scope.Block,7229 block: *Scope.Block,
7184 src: LazySrcLoc,7230 src: LazySrcLoc,
7185 ptr: Air.Inst.Index,7231 ptr: Air.Inst.Ref,
7186 ptr_src: LazySrcLoc,7232 ptr_src: LazySrcLoc,
7187) InnerError!Air.Inst.Index {7233) InnerError!Air.Inst.Ref {
7188 const elem_ty = switch (ptr.ty.zigTypeTag()) {7234 const ptr_ty = sema.getTypeOfAirRef(ptr);
7189 .Pointer => ptr.ty.elemType(),7235 const elem_ty = switch (ptr_ty.zigTypeTag()) {
7190 else => return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr.ty}),7236 .Pointer => ptr_ty.elemType(),
7237 else => return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr_ty}),
7191 };7238 };
7192 if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| blk: {7239 if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| blk: {
7193 if (ptr_val.tag() == .int_u64)7240 if (ptr_val.tag() == .int_u64)
7194 break :blk; // do it at runtime7241 break :blk; // do it at runtime
71957242
7196 return sema.mod.constInst(sema.arena, src, .{7243 return sema.addConstant(elem_ty, try ptr_val.pointerDeref(sema.arena));
7197 .ty = elem_ty,
7198 .val = try ptr_val.pointerDeref(sema.arena),
7199 });
7200 }7244 }
72017245
7202 try sema.requireRuntimeBlock(block, src);7246 try sema.requireRuntimeBlock(block, src);
7203 return block.addUnOp(src, elem_ty, .load, ptr);7247 return block.addTyOp(.load, elem_ty, ptr);
7204}7248}
72057249
7206fn analyzeIsNull(7250fn analyzeIsNull(
7207 sema: *Sema,7251 sema: *Sema,
7208 block: *Scope.Block,7252 block: *Scope.Block,
7209 src: LazySrcLoc,7253 src: LazySrcLoc,
7210 operand: Air.Inst.Index,7254 operand: Air.Inst.Ref,
7211 invert_logic: bool,7255 invert_logic: bool,
7212) InnerError!Air.Inst.Index {7256) InnerError!Air.Inst.Ref {
7213 const result_ty = Type.initTag(.bool);7257 const result_ty = Type.initTag(.bool);
7214 if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |opt_val| {7258 if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |opt_val| {
7215 if (opt_val.isUndef()) {7259 if (opt_val.isUndef()) {
...@@ -7228,8 +7272,8 @@ fn analyzeIsNonErr(...@@ -7228,8 +7272,8 @@ fn analyzeIsNonErr(
7228 sema: *Sema,7272 sema: *Sema,
7229 block: *Scope.Block,7273 block: *Scope.Block,
7230 src: LazySrcLoc,7274 src: LazySrcLoc,
7231 operand: Air.Inst.Index,7275 operand: Air.Inst.Ref,
7232) InnerError!Air.Inst.Index {7276) InnerError!Air.Inst.Ref {
7233 const ot = operand.ty.zigTypeTag();7277 const ot = operand.ty.zigTypeTag();
7234 if (ot != .ErrorSet and ot != .ErrorUnion) return sema.mod.constBool(sema.arena, src, true);7278 if (ot != .ErrorSet and ot != .ErrorUnion) return sema.mod.constBool(sema.arena, src, true);
7235 if (ot == .ErrorSet) return sema.mod.constBool(sema.arena, src, false);7279 if (ot == .ErrorSet) return sema.mod.constBool(sema.arena, src, false);
...@@ -7249,12 +7293,12 @@ fn analyzeSlice(...@@ -7249,12 +7293,12 @@ fn analyzeSlice(
7249 sema: *Sema,7293 sema: *Sema,
7250 block: *Scope.Block,7294 block: *Scope.Block,
7251 src: LazySrcLoc,7295 src: LazySrcLoc,
7252 array_ptr: Air.Inst.Index,7296 array_ptr: Air.Inst.Ref,
7253 start: Air.Inst.Index,7297 start: Air.Inst.Ref,
7254 end_opt: ?Air.Inst.Index,7298 end_opt: ?Air.Inst.Index,
7255 sentinel_opt: ?Air.Inst.Index,7299 sentinel_opt: ?Air.Inst.Index,
7256 sentinel_src: LazySrcLoc,7300 sentinel_src: LazySrcLoc,
7257) InnerError!Air.Inst.Index {7301) InnerError!Air.Inst.Ref {
7258 const ptr_child = switch (array_ptr.ty.zigTypeTag()) {7302 const ptr_child = switch (array_ptr.ty.zigTypeTag()) {
7259 .Pointer => array_ptr.ty.elemType(),7303 .Pointer => array_ptr.ty.elemType(),
7260 else => return sema.mod.fail(&block.base, src, "expected pointer, found '{}'", .{array_ptr.ty}),7304 else => return sema.mod.fail(&block.base, src, "expected pointer, found '{}'", .{array_ptr.ty}),
...@@ -7325,10 +7369,10 @@ fn cmpNumeric(...@@ -7325,10 +7369,10 @@ fn cmpNumeric(
7325 sema: *Sema,7369 sema: *Sema,
7326 block: *Scope.Block,7370 block: *Scope.Block,
7327 src: LazySrcLoc,7371 src: LazySrcLoc,
7328 lhs: Air.Inst.Index,7372 lhs: Air.Inst.Ref,
7329 rhs: Air.Inst.Index,7373 rhs: Air.Inst.Ref,
7330 op: std.math.CompareOperator,7374 op: std.math.CompareOperator,
7331) InnerError!Air.Inst.Index {7375) InnerError!Air.Inst.Ref {
7332 assert(lhs.ty.isNumeric());7376 assert(lhs.ty.isNumeric());
7333 assert(rhs.ty.isNumeric());7377 assert(rhs.ty.isNumeric());
73347378
...@@ -7494,7 +7538,7 @@ fn cmpNumeric(...@@ -7494,7 +7538,7 @@ fn cmpNumeric(
7494 return block.addBinOp(src, Type.initTag(.bool), Inst.Tag.fromCmpOp(op), casted_lhs, casted_rhs);7538 return block.addBinOp(src, Type.initTag(.bool), Inst.Tag.fromCmpOp(op), casted_lhs, casted_rhs);
7495}7539}
74967540
7497fn wrapOptional(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) !Air.Inst.Index {7541fn wrapOptional(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Ref) !Air.Inst.Index {
7498 if (inst.value()) |val| {7542 if (inst.value()) |val| {
7499 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });7543 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });
7500 }7544 }
...@@ -7503,9 +7547,15 @@ fn wrapOptional(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Ins...@@ -7503,9 +7547,15 @@ fn wrapOptional(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Ins
7503 return block.addUnOp(inst.src, dest_type, .wrap_optional, inst);7547 return block.addUnOp(inst.src, dest_type, .wrap_optional, inst);
7504}7548}
75057549
7506fn wrapErrorUnion(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) !Air.Inst.Index {7550fn wrapErrorUnion(
7551 sema: *Sema,
7552 block: *Scope.Block,
7553 dest_type: Type,
7554 inst: Air.Inst.Ref,
7555 inst_src: LazySrcLoc,
7556) !Air.Inst.Index {
7507 const err_union = dest_type.castTag(.error_union).?;7557 const err_union = dest_type.castTag(.error_union).?;
7508 if (inst.value()) |val| {7558 if (try sema.resolvePossiblyUndefinedValue(block, inst_src, inst)) |val| {
7509 if (inst.ty.zigTypeTag() != .ErrorSet) {7559 if (inst.ty.zigTypeTag() != .ErrorSet) {
7510 _ = try sema.coerce(block, err_union.data.payload, inst, inst.src);7560 _ = try sema.coerce(block, err_union.data.payload, inst, inst.src);
7511 } else switch (err_union.data.error_set.tag()) {7561 } else switch (err_union.data.error_set.tag()) {
...@@ -7710,7 +7760,7 @@ fn getBuiltin(...@@ -7710,7 +7760,7 @@ fn getBuiltin(
7710 block: *Scope.Block,7760 block: *Scope.Block,
7711 src: LazySrcLoc,7761 src: LazySrcLoc,
7712 name: []const u8,7762 name: []const u8,
7713) InnerError!Air.Inst.Index {7763) InnerError!Air.Inst.Ref {
7714 const mod = sema.mod;7764 const mod = sema.mod;
7715 const std_pkg = mod.root_pkg.table.get("std").?;7765 const std_pkg = mod.root_pkg.table.get("std").?;
7716 const std_file = (mod.importPkg(std_pkg) catch unreachable).file;7766 const std_file = (mod.importPkg(std_pkg) catch unreachable).file;
...@@ -7938,6 +7988,68 @@ fn enumFieldSrcLoc(...@@ -7938,6 +7988,68 @@ fn enumFieldSrcLoc(
7938 } else unreachable;7988 } else unreachable;
7939}7989}
79407990
7991/// Returns the type of the AIR instruction.
7992fn getTypeOfAirRef(sema: *Sema, air_ref: Air.Inst.Ref) Type {
7993 switch (air_ref) {
7994 .none => unreachable,
7995 .u8_type => return Type.initTag(.u8),
7996 .i8_type => return Type.initTag(.i8),
7997 .u16_type => return Type.initTag(.u16),
7998 .i16_type => return Type.initTag(.i16),
7999 .u32_type => return Type.initTag(.u32),
8000 .i32_type => return Type.initTag(.i32),
8001 .u64_type => return Type.initTag(.u64),
8002 .i64_type => return Type.initTag(.i64),
8003 .u128_type => return Type.initTag(.u128),
8004 .i128_type => return Type.initTag(.i128),
8005 .usize_type => return Type.initTag(.usize),
8006 .isize_type => return Type.initTag(.isize),
8007 .c_short_type => return Type.initTag(.c_short),
8008 .c_ushort_type => return Type.initTag(.c_ushort),
8009 .c_int_type => return Type.initTag(.c_int),
8010 .c_uint_type => return Type.initTag(.c_uint),
8011 .c_long_type => return Type.initTag(.c_long),
8012 .c_ulong_type => return Type.initTag(.c_ulong),
8013 .c_longlong_type => return Type.initTag(.c_longlong),
8014 .c_ulonglong_type => return Type.initTag(.c_ulonglong),
8015 .c_longdouble_type => return Type.initTag(.c_longdouble),
8016 .f16_type => return Type.initTag(.f16),
8017 .f32_type => return Type.initTag(.f32),
8018 .f64_type => return Type.initTag(.f64),
8019 .f128_type => return Type.initTag(.f128),
8020 .c_void_type => return Type.initTag(.c_void),
8021 .bool_type => return Type.initTag(.bool),
8022 .void_type => return Type.initTag(.void),
8023 .type_type => return Type.initTag(.type),
8024 .anyerror_type => return Type.initTag(.anyerror),
8025 .comptime_int_type => return Type.initTag(.comptime_int),
8026 .comptime_float_type => return Type.initTag(.comptime_float),
8027 .noreturn_type => return Type.initTag(.noreturn),
8028 .anyframe_type => return Type.initTag(.@"anyframe"),
8029 .null_type => return Type.initTag(.@"null"),
8030 .undefined_type => return Type.initTag(.@"undefined"),
8031 .enum_literal_type => return Type.initTag(.enum_literal),
8032 .atomic_ordering_type => return Type.initTag(.atomic_ordering),
8033 .atomic_rmw_op_type => return Type.initTag(.atomic_rmw_op),
8034 .calling_convention_type => return Type.initTag(.calling_convention),
8035 .float_mode_type => return Type.initTag(.float_mode),
8036 .reduce_op_type => return Type.initTag(.reduce_op),
8037 .call_options_type => return Type.initTag(.call_options),
8038 .export_options_type => return Type.initTag(.export_options),
8039 .extern_options_type => return Type.initTag(.extern_options),
8040 .manyptr_u8_type => return Type.initTag(.manyptr_u8),
8041 .manyptr_const_u8_type => return Type.initTag(.manyptr_const_u8),
8042 .fn_noreturn_no_args_type => return Type.initTag(.fn_noreturn_no_args),
8043 .fn_void_no_args_type => return Type.initTag(.fn_void_no_args),
8044 .fn_naked_noreturn_no_args_type => return Type.initTag(.fn_naked_noreturn_no_args),
8045 .fn_ccc_void_no_args_type => return Type.initTag(.fn_ccc_void_no_args),
8046 .single_const_pointer_to_comptime_int_type => return Type.initTag(.single_const_pointer_to_comptime_int),
8047 .const_slice_u8_type => return Type.initTag(.const_slice_u8),
8048 else => return sema.getAirType(air_ref),
8049 }
8050}
8051
8052/// Asserts the AIR instruction is a `const_ty` and returns the type.
7941fn getAirType(sema: *Sema, air_ref: Air.Inst.Ref) Type {8053fn getAirType(sema: *Sema, air_ref: Air.Inst.Ref) Type {
7942 var i: usize = @enumToInt(air_ref);8054 var i: usize = @enumToInt(air_ref);
7943 if (i < Air.Inst.Ref.typed_value_map.len) {8055 if (i < Air.Inst.Ref.typed_value_map.len) {
...@@ -8014,13 +8126,27 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {...@@ -8014,13 +8126,27 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
8014 return indexToRef(@intCast(u32, sema.air_instructions.len - 1));8126 return indexToRef(@intCast(u32, sema.air_instructions.len - 1));
8015}8127}
80168128
8129pub fn addConstant(sema: *Sema, ty: Type, val: Value) InnerError!Air.Inst.Ref {
8130 const gpa = sema.gpa;
8131 const ty_inst = try sema.addType(ty);
8132 try sema.air_values.append(gpa, val);
8133 try sema.air_instructions.append(gpa, .{
8134 .tag = .constant,
8135 .data = .{ .ty_pl = .{
8136 .ty = ty_inst,
8137 .payload = @intCast(u32, sema.air_values.items.len - 1),
8138 } },
8139 });
8140 return indexToRef(@intCast(u32, sema.air_instructions.len - 1));
8141}
8142
8017const ref_start_index: u32 = Air.Inst.Ref.typed_value_map.len;8143const ref_start_index: u32 = Air.Inst.Ref.typed_value_map.len;
80188144
8019fn indexToRef(inst: Air.Inst.Index) Air.Inst.Ref {8145pub fn indexToRef(inst: Air.Inst.Index) Air.Inst.Ref {
8020 return @intToEnum(Air.Inst.Ref, ref_start_index + inst);8146 return @intToEnum(Air.Inst.Ref, ref_start_index + inst);
8021}8147}
80228148
8023fn refToIndex(inst: Air.Inst.Ref) ?Air.Inst.Index {8149pub fn refToIndex(inst: Air.Inst.Ref) ?Air.Inst.Index {
8024 const ref_int = @enumToInt(inst);8150 const ref_int = @enumToInt(inst);
8025 if (ref_int >= ref_start_index) {8151 if (ref_int >= ref_start_index) {
8026 return ref_int - ref_start_index;8152 return ref_int - ref_start_index;
src/codegen.zig+79-80
...@@ -494,7 +494,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -494,7 +494,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
494 defer function.blocks.deinit(bin_file.allocator);494 defer function.blocks.deinit(bin_file.allocator);
495 defer function.exitlude_jump_relocs.deinit(bin_file.allocator);495 defer function.exitlude_jump_relocs.deinit(bin_file.allocator);
496496
497 var call_info = function.resolveCallingConventionValues(src_loc.lazy, fn_type) catch |err| switch (err) {497 var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) {
498 error.CodegenFail => return Result{ .fail = function.err_msg.? },498 error.CodegenFail => return Result{ .fail = function.err_msg.? },
499 else => |e| return e,499 else => |e| return e,
500 };500 };
...@@ -537,7 +537,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -537,7 +537,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
537 self.code.items.len += 4;537 self.code.items.len += 4;
538538
539 try self.dbgSetPrologueEnd();539 try self.dbgSetPrologueEnd();
540 try self.genBody(self.mod_fn.body);540 try self.genBody(self.air.getMainBody());
541541
542 const stack_end = self.max_end_stack;542 const stack_end = self.max_end_stack;
543 if (stack_end > math.maxInt(i32))543 if (stack_end > math.maxInt(i32))
...@@ -578,7 +578,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -578,7 +578,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
578 });578 });
579 } else {579 } else {
580 try self.dbgSetPrologueEnd();580 try self.dbgSetPrologueEnd();
581 try self.genBody(self.mod_fn.body);581 try self.genBody(self.air.getMainBody());
582 try self.dbgSetEpilogueBegin();582 try self.dbgSetEpilogueBegin();
583 }583 }
584 },584 },
...@@ -758,11 +758,12 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -758,11 +758,12 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
758 }758 }
759759
760 // TODO inline this logic into every instruction760 // TODO inline this logic into every instruction
761 var i: ir.Inst.DeathsBitIndex = 0;761 @panic("TODO rework AIR memory layout codegen for processing deaths");
762 while (inst.getOperand(i)) |operand| : (i += 1) {762 //var i: ir.Inst.DeathsBitIndex = 0;
763 if (inst.operandDies(i))763 //while (inst.getOperand(i)) |operand| : (i += 1) {
764 self.processDeath(operand);764 // if (inst.operandDies(i))
765 }765 // self.processDeath(operand);
766 //}
766 }767 }
767 }768 }
768769
...@@ -858,74 +859,76 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -858,74 +859,76 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
858 const air_tags = self.air.instructions.items(.tag);859 const air_tags = self.air.instructions.items(.tag);
859 switch (air_tags[inst]) {860 switch (air_tags[inst]) {
860 // zig fmt: off861 // zig fmt: off
861 .add => return self.genAdd(inst.castTag(.add).?),862 //.add => return self.genAdd(inst.castTag(.add).?),
862 .addwrap => return self.genAddWrap(inst.castTag(.addwrap).?),863 //.addwrap => return self.genAddWrap(inst.castTag(.addwrap).?),
863 .sub => return self.genSub(inst.castTag(.sub).?),864 //.sub => return self.genSub(inst.castTag(.sub).?),
864 .subwrap => return self.genSubWrap(inst.castTag(.subwrap).?),865 //.subwrap => return self.genSubWrap(inst.castTag(.subwrap).?),
865 .mul => return self.genMul(inst.castTag(.mul).?),866 //.mul => return self.genMul(inst.castTag(.mul).?),
866 .mulwrap => return self.genMulWrap(inst.castTag(.mulwrap).?),867 //.mulwrap => return self.genMulWrap(inst.castTag(.mulwrap).?),
867 .div => return self.genDiv(inst.castTag(.div).?),868 //.div => return self.genDiv(inst.castTag(.div).?),
868869
869 .cmp_lt => return self.genCmp(inst.castTag(.cmp_lt).?, .lt),870 //.cmp_lt => return self.genCmp(inst.castTag(.cmp_lt).?, .lt),
870 .cmp_lte => return self.genCmp(inst.castTag(.cmp_lte).?, .lte),871 //.cmp_lte => return self.genCmp(inst.castTag(.cmp_lte).?, .lte),
871 .cmp_eq => return self.genCmp(inst.castTag(.cmp_eq).?, .eq),872 //.cmp_eq => return self.genCmp(inst.castTag(.cmp_eq).?, .eq),
872 .cmp_gte => return self.genCmp(inst.castTag(.cmp_gte).?, .gte),873 //.cmp_gte => return self.genCmp(inst.castTag(.cmp_gte).?, .gte),
873 .cmp_gt => return self.genCmp(inst.castTag(.cmp_gt).?, .gt),874 //.cmp_gt => return self.genCmp(inst.castTag(.cmp_gt).?, .gt),
874 .cmp_neq => return self.genCmp(inst.castTag(.cmp_neq).?, .neq),875 //.cmp_neq => return self.genCmp(inst.castTag(.cmp_neq).?, .neq),
875876
876 .bool_and => return self.genBoolOp(inst.castTag(.bool_and).?),877 //.bool_and => return self.genBoolOp(inst.castTag(.bool_and).?),
877 .bool_or => return self.genBoolOp(inst.castTag(.bool_or).?),878 //.bool_or => return self.genBoolOp(inst.castTag(.bool_or).?),
878 .bit_and => return self.genBitAnd(inst.castTag(.bit_and).?),879 //.bit_and => return self.genBitAnd(inst.castTag(.bit_and).?),
879 .bit_or => return self.genBitOr(inst.castTag(.bit_or).?),880 //.bit_or => return self.genBitOr(inst.castTag(.bit_or).?),
880 .xor => return self.genXor(inst.castTag(.xor).?),881 //.xor => return self.genXor(inst.castTag(.xor).?),
881882
882 .alloc => return self.genAlloc(inst.castTag(.alloc).?),883 //.alloc => return self.genAlloc(inst.castTag(.alloc).?),
883 .arg => return self.genArg(inst.castTag(.arg).?),884 //.arg => return self.genArg(inst.castTag(.arg).?),
884 .assembly => return self.genAsm(inst.castTag(.assembly).?),885 //.assembly => return self.genAsm(inst.castTag(.assembly).?),
885 .bitcast => return self.genBitCast(inst.castTag(.bitcast).?),886 //.bitcast => return self.genBitCast(inst.castTag(.bitcast).?),
886 .block => return self.genBlock(inst.castTag(.block).?),887 //.block => return self.genBlock(inst.castTag(.block).?),
887 .br => return self.genBr(inst.castTag(.br).?),888 //.br => return self.genBr(inst.castTag(.br).?),
888 .br_block_flat => return self.genBrBlockFlat(inst.castTag(.br_block_flat).?),889 //.br_block_flat => return self.genBrBlockFlat(inst.castTag(.br_block_flat).?),
889 .breakpoint => return self.genBreakpoint(inst.src),890 //.breakpoint => return self.genBreakpoint(inst.src),
890 .call => return self.genCall(inst.castTag(.call).?),891 //.call => return self.genCall(inst.castTag(.call).?),
891 .cond_br => return self.genCondBr(inst.castTag(.condbr).?),892 //.cond_br => return self.genCondBr(inst.castTag(.condbr).?),
892 .dbg_stmt => return self.genDbgStmt(inst.castTag(.dbg_stmt).?),893 //.dbg_stmt => return self.genDbgStmt(inst.castTag(.dbg_stmt).?),
893 .floatcast => return self.genFloatCast(inst.castTag(.floatcast).?),894 //.floatcast => return self.genFloatCast(inst.castTag(.floatcast).?),
894 .intcast => return self.genIntCast(inst.castTag(.intcast).?),895 //.intcast => return self.genIntCast(inst.castTag(.intcast).?),
895 .is_non_null => return self.genIsNonNull(inst.castTag(.is_non_null).?),896 //.is_non_null => return self.genIsNonNull(inst.castTag(.is_non_null).?),
896 .is_non_null_ptr => return self.genIsNonNullPtr(inst.castTag(.is_non_null_ptr).?),897 //.is_non_null_ptr => return self.genIsNonNullPtr(inst.castTag(.is_non_null_ptr).?),
897 .is_null => return self.genIsNull(inst.castTag(.is_null).?),898 //.is_null => return self.genIsNull(inst.castTag(.is_null).?),
898 .is_null_ptr => return self.genIsNullPtr(inst.castTag(.is_null_ptr).?),899 //.is_null_ptr => return self.genIsNullPtr(inst.castTag(.is_null_ptr).?),
899 .is_non_err => return self.genIsNonErr(inst.castTag(.is_non_err).?),900 //.is_non_err => return self.genIsNonErr(inst.castTag(.is_non_err).?),
900 .is_non_err_ptr => return self.genIsNonErrPtr(inst.castTag(.is_non_err_ptr).?),901 //.is_non_err_ptr => return self.genIsNonErrPtr(inst.castTag(.is_non_err_ptr).?),
901 .is_err => return self.genIsErr(inst.castTag(.is_err).?),902 //.is_err => return self.genIsErr(inst.castTag(.is_err).?),
902 .is_err_ptr => return self.genIsErrPtr(inst.castTag(.is_err_ptr).?),903 //.is_err_ptr => return self.genIsErrPtr(inst.castTag(.is_err_ptr).?),
903 .load => return self.genLoad(inst.castTag(.load).?),904 //.load => return self.genLoad(inst.castTag(.load).?),
904 .loop => return self.genLoop(inst.castTag(.loop).?),905 //.loop => return self.genLoop(inst.castTag(.loop).?),
905 .not => return self.genNot(inst.castTag(.not).?),906 //.not => return self.genNot(inst.castTag(.not).?),
906 .ptrtoint => return self.genPtrToInt(inst.castTag(.ptrtoint).?),907 //.ptrtoint => return self.genPtrToInt(inst.castTag(.ptrtoint).?),
907 .ref => return self.genRef(inst.castTag(.ref).?),908 //.ref => return self.genRef(inst.castTag(.ref).?),
908 .ret => return self.genRet(inst.castTag(.ret).?),909 //.ret => return self.genRet(inst.castTag(.ret).?),
909 .store => return self.genStore(inst.castTag(.store).?),910 //.store => return self.genStore(inst.castTag(.store).?),
910 .struct_field_ptr=> return self.genStructFieldPtr(inst.castTag(.struct_field_ptr).?),911 //.struct_field_ptr=> return self.genStructFieldPtr(inst.castTag(.struct_field_ptr).?),
911 .switchbr => return self.genSwitch(inst.castTag(.switchbr).?),912 //.switch_br => return self.genSwitch(inst.castTag(.switchbr).?),
912 .varptr => return self.genVarPtr(inst.castTag(.varptr).?),913 //.varptr => return self.genVarPtr(inst.castTag(.varptr).?),
913914
914 .constant => unreachable, // excluded from function bodies915 //.constant => unreachable, // excluded from function bodies
915 .unreach => return MCValue{ .unreach = {} },916 //.unreach => return MCValue{ .unreach = {} },
916917
917 .optional_payload => return self.genOptionalPayload(inst.castTag(.optional_payload).?),918 //.optional_payload => return self.genOptionalPayload(inst.castTag(.optional_payload).?),
918 .optional_payload_ptr => return self.genOptionalPayloadPtr(inst.castTag(.optional_payload_ptr).?),919 //.optional_payload_ptr => return self.genOptionalPayloadPtr(inst.castTag(.optional_payload_ptr).?),
919 .unwrap_errunion_err => return self.genUnwrapErrErr(inst.castTag(.unwrap_errunion_err).?),920 //.unwrap_errunion_err => return self.genUnwrapErrErr(inst.castTag(.unwrap_errunion_err).?),
920 .unwrap_errunion_payload => return self.genUnwrapErrPayload(inst.castTag(.unwrap_errunion_payload).?),921 //.unwrap_errunion_payload => return self.genUnwrapErrPayload(inst.castTag(.unwrap_errunion_payload).?),
921 .unwrap_errunion_err_ptr => return self.genUnwrapErrErrPtr(inst.castTag(.unwrap_errunion_err_ptr).?),922 //.unwrap_errunion_err_ptr => return self.genUnwrapErrErrPtr(inst.castTag(.unwrap_errunion_err_ptr).?),
922 .unwrap_errunion_payload_ptr=> return self.genUnwrapErrPayloadPtr(inst.castTag(.unwrap_errunion_payload_ptr).?),923 //.unwrap_errunion_payload_ptr=> return self.genUnwrapErrPayloadPtr(inst.castTag(.unwrap_errunion_payload_ptr).?),
923924
924 .wrap_optional => return self.genWrapOptional(inst.castTag(.wrap_optional).?),925 //.wrap_optional => return self.genWrapOptional(inst.castTag(.wrap_optional).?),
925 .wrap_errunion_payload => return self.genWrapErrUnionPayload(inst.castTag(.wrap_errunion_payload).?),926 //.wrap_errunion_payload => return self.genWrapErrUnionPayload(inst.castTag(.wrap_errunion_payload).?),
926 .wrap_errunion_err => return self.genWrapErrUnionErr(inst.castTag(.wrap_errunion_err).?),927 //.wrap_errunion_err => return self.genWrapErrUnionErr(inst.castTag(.wrap_errunion_err).?),
927928
928 // zig fmt: on929 // zig fmt: on
930
931 else => @panic("TODO finish air memory layout branch, more codegen.zig instructions"),
929 }932 }
930 }933 }
931934
...@@ -4785,14 +4788,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -4785,14 +4788,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
4785 };4788 };
4786 }4789 }
47874790
4788 fn fail(self: *Self, src: LazySrcLoc, comptime format: []const u8, args: anytype) InnerError {4791 fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
4789 @setCold(true);4792 @setCold(true);
4790 assert(self.err_msg == null);4793 assert(self.err_msg == null);
4791 const src_loc = if (src != .unneeded)4794 self.err_msg = try ErrorMsg.create(self.bin_file.allocator, self.src_loc, format, args);
4792 src.toSrcLocWithDecl(self.mod_fn.owner_decl)
4793 else
4794 self.src_loc;
4795 self.err_msg = try ErrorMsg.create(self.bin_file.allocator, src_loc, format, args);
4796 return error.CodegenFail;4795 return error.CodegenFail;
4797 }4796 }
47984797
src/codegen/c.zig+107-97
...@@ -25,7 +25,7 @@ pub const CValue = union(enum) {...@@ -25,7 +25,7 @@ pub const CValue = union(enum) {
25 /// Index into local_names, but take the address.25 /// Index into local_names, but take the address.
26 local_ref: usize,26 local_ref: usize,
27 /// A constant instruction, to be rendered inline.27 /// A constant instruction, to be rendered inline.
28 constant: *Inst,28 constant: Air.Inst.Index,
29 /// Index into the parameters29 /// Index into the parameters
30 arg: usize,30 arg: usize,
31 /// By-value31 /// By-value
...@@ -99,7 +99,7 @@ pub const Object = struct {...@@ -99,7 +99,7 @@ pub const Object = struct {
99 gpa: *mem.Allocator,99 gpa: *mem.Allocator,
100 code: std.ArrayList(u8),100 code: std.ArrayList(u8),
101 value_map: CValueMap,101 value_map: CValueMap,
102 blocks: std.AutoHashMapUnmanaged(*ir.Inst.Block, BlockData) = .{},102 blocks: std.AutoHashMapUnmanaged(Air.Inst.Index, BlockData) = .{},
103 next_arg_index: usize = 0,103 next_arg_index: usize = 0,
104 next_local_index: usize = 0,104 next_local_index: usize = 0,
105 next_block_index: usize = 0,105 next_block_index: usize = 0,
...@@ -133,7 +133,12 @@ pub const Object = struct {...@@ -133,7 +133,12 @@ pub const Object = struct {
133 .none => unreachable,133 .none => unreachable,
134 .local => |i| return w.print("t{d}", .{i}),134 .local => |i| return w.print("t{d}", .{i}),
135 .local_ref => |i| return w.print("&t{d}", .{i}),135 .local_ref => |i| return w.print("&t{d}", .{i}),
136 .constant => |inst| return o.dg.renderValue(w, inst.ty, inst.value().?),136 .constant => |inst| {
137 const ty_pl = o.air.instructions.items(.data)[inst].ty_pl;
138 const ty = o.air.getRefType(ty_pl.ty);
139 const val = o.air.values[ty_pl.payload];
140 return o.dg.renderValue(w, ty, val);
141 },
137 .arg => |i| return w.print("a{d}", .{i}),142 .arg => |i| return w.print("a{d}", .{i}),
138 .decl => |decl| return w.writeAll(mem.span(decl.name)),143 .decl => |decl| return w.writeAll(mem.span(decl.name)),
139 .decl_ref => |decl| return w.print("&{s}", .{decl.name}),144 .decl_ref => |decl| return w.print("&{s}", .{decl.name}),
...@@ -213,8 +218,9 @@ pub const DeclGen = struct {...@@ -213,8 +218,9 @@ pub const DeclGen = struct {
213 error_msg: ?*Module.ErrorMsg,218 error_msg: ?*Module.ErrorMsg,
214 typedefs: TypedefMap,219 typedefs: TypedefMap,
215220
216 fn fail(dg: *DeclGen, src: LazySrcLoc, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } {221 fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } {
217 @setCold(true);222 @setCold(true);
223 const src: LazySrcLoc = .{ .node_offset = 0 };
218 const src_loc = src.toSrcLocWithDecl(dg.decl);224 const src_loc = src.toSrcLocWithDecl(dg.decl);
219 dg.error_msg = try Module.ErrorMsg.create(dg.module.gpa, src_loc, format, args);225 dg.error_msg = try Module.ErrorMsg.create(dg.module.gpa, src_loc, format, args);
220 return error.AnalysisFail;226 return error.AnalysisFail;
...@@ -230,7 +236,7 @@ pub const DeclGen = struct {...@@ -230,7 +236,7 @@ pub const DeclGen = struct {
230 // This should lower to 0xaa bytes in safe modes, and for unsafe modes should236 // This should lower to 0xaa bytes in safe modes, and for unsafe modes should
231 // lower to leaving variables uninitialized (that might need to be implemented237 // lower to leaving variables uninitialized (that might need to be implemented
232 // outside of this function).238 // outside of this function).
233 return dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement renderValue undef", .{});239 return dg.fail("TODO: C backend: implement renderValue undef", .{});
234 }240 }
235 switch (t.zigTypeTag()) {241 switch (t.zigTypeTag()) {
236 .Int => {242 .Int => {
...@@ -440,7 +446,7 @@ pub const DeclGen = struct {...@@ -440,7 +446,7 @@ pub const DeclGen = struct {
440 },446 },
441 else => unreachable,447 else => unreachable,
442 },448 },
443 else => |e| return dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement value {s}", .{449 else => |e| return dg.fail("TODO: C backend: implement value {s}", .{
444 @tagName(e),450 @tagName(e),
445 }),451 }),
446 }452 }
...@@ -519,14 +525,14 @@ pub const DeclGen = struct {...@@ -519,14 +525,14 @@ pub const DeclGen = struct {
519 break;525 break;
520 }526 }
521 } else {527 } else {
522 return dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement integer types larger than 128 bits", .{});528 return dg.fail("TODO: C backend: implement integer types larger than 128 bits", .{});
523 }529 }
524 },530 },
525 else => unreachable,531 else => unreachable,
526 }532 }
527 },533 },
528534
529 .Float => return dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement type Float", .{}),535 .Float => return dg.fail("TODO: C backend: implement type Float", .{}),
530536
531 .Pointer => {537 .Pointer => {
532 if (t.isSlice()) {538 if (t.isSlice()) {
...@@ -681,7 +687,7 @@ pub const DeclGen = struct {...@@ -681,7 +687,7 @@ pub const DeclGen = struct {
681687
682 try dg.renderType(w, int_tag_ty);688 try dg.renderType(w, int_tag_ty);
683 },689 },
684 .Union => return dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement type Union", .{}),690 .Union => return dg.fail("TODO: C backend: implement type Union", .{}),
685 .Fn => {691 .Fn => {
686 try dg.renderType(w, t.fnReturnType());692 try dg.renderType(w, t.fnReturnType());
687 try w.writeAll(" (*)(");693 try w.writeAll(" (*)(");
...@@ -704,10 +710,10 @@ pub const DeclGen = struct {...@@ -704,10 +710,10 @@ pub const DeclGen = struct {
704 }710 }
705 try w.writeByte(')');711 try w.writeByte(')');
706 },712 },
707 .Opaque => return dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement type Opaque", .{}),713 .Opaque => return dg.fail("TODO: C backend: implement type Opaque", .{}),
708 .Frame => return dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement type Frame", .{}),714 .Frame => return dg.fail("TODO: C backend: implement type Frame", .{}),
709 .AnyFrame => return dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement type AnyFrame", .{}),715 .AnyFrame => return dg.fail("TODO: C backend: implement type AnyFrame", .{}),
710 .Vector => return dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement type Vector", .{}),716 .Vector => return dg.fail("TODO: C backend: implement type Vector", .{}),
711717
712 .Null,718 .Null,
713 .Undefined,719 .Undefined,
...@@ -760,7 +766,8 @@ pub fn genDecl(o: *Object) !void {...@@ -760,7 +766,8 @@ pub fn genDecl(o: *Object) !void {
760 try o.dg.renderFunctionSignature(o.writer(), is_global);766 try o.dg.renderFunctionSignature(o.writer(), is_global);
761767
762 try o.writer().writeByte(' ');768 try o.writer().writeByte(' ');
763 try genBody(o, func.body);769 const main_body = o.air.getMainBody();
770 try genBody(o, main_body);
764771
765 try o.indent_writer.insertNewline();772 try o.indent_writer.insertNewline();
766 return;773 return;
...@@ -833,9 +840,9 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void {...@@ -833,9 +840,9 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void {
833 }840 }
834}841}
835842
836pub fn genBody(o: *Object, body: ir.Body) error{ AnalysisFail, OutOfMemory }!void {843fn genBody(o: *Object, body: []const Air.Inst.Index) error{ AnalysisFail, OutOfMemory }!void {
837 const writer = o.writer();844 const writer = o.writer();
838 if (body.instructions.len == 0) {845 if (body.len == 0) {
839 try writer.writeAll("{}");846 try writer.writeAll("{}");
840 return;847 return;
841 }848 }
...@@ -843,82 +850,85 @@ pub fn genBody(o: *Object, body: ir.Body) error{ AnalysisFail, OutOfMemory }!voi...@@ -843,82 +850,85 @@ pub fn genBody(o: *Object, body: ir.Body) error{ AnalysisFail, OutOfMemory }!voi
843 try writer.writeAll("{\n");850 try writer.writeAll("{\n");
844 o.indent_writer.pushIndent();851 o.indent_writer.pushIndent();
845852
846 for (body.instructions) |inst| {853 const air_tags = o.air.instructions.items(.tag);
847 const result_value = switch (inst.tag) {854
848 // TODO use a different strategy for add that communicates to the optimizer855 for (body) |inst| {
849 // that wrapping is UB.856 const result_value = switch (air_tags[inst]) {
850 .add => try genBinOp(o, inst.castTag(.add).?, " + "),857 //// TODO use a different strategy for add that communicates to the optimizer
851 .addwrap => try genWrapOp(o, inst.castTag(.addwrap).?, " + ", "addw_"),858 //// that wrapping is UB.
852 // TODO use a different strategy for sub that communicates to the optimizer859 //.add => try genBinOp(o, inst.castTag(.add).?, " + "),
853 // that wrapping is UB.860 //.addwrap => try genWrapOp(o, inst.castTag(.addwrap).?, " + ", "addw_"),
854 .sub => try genBinOp(o, inst.castTag(.sub).?, " - "),861 //// TODO use a different strategy for sub that communicates to the optimizer
855 .subwrap => try genWrapOp(o, inst.castTag(.subwrap).?, " - ", "subw_"),862 //// that wrapping is UB.
856 // TODO use a different strategy for mul that communicates to the optimizer863 //.sub => try genBinOp(o, inst.castTag(.sub).?, " - "),
857 // that wrapping is UB.864 //.subwrap => try genWrapOp(o, inst.castTag(.subwrap).?, " - ", "subw_"),
858 .mul => try genBinOp(o, inst.castTag(.sub).?, " * "),865 //// TODO use a different strategy for mul that communicates to the optimizer
859 .mulwrap => try genWrapOp(o, inst.castTag(.mulwrap).?, " * ", "mulw_"),866 //// that wrapping is UB.
860 // TODO use a different strategy for div that communicates to the optimizer867 //.mul => try genBinOp(o, inst.castTag(.sub).?, " * "),
861 // that wrapping is UB.868 //.mulwrap => try genWrapOp(o, inst.castTag(.mulwrap).?, " * ", "mulw_"),
862 .div => try genBinOp(o, inst.castTag(.div).?, " / "),869 //// TODO use a different strategy for div that communicates to the optimizer
863870 //// that wrapping is UB.
864 .constant => unreachable, // excluded from function bodies871 //.div => try genBinOp(o, inst.castTag(.div).?, " / "),
865 .alloc => try genAlloc(o, inst.castTag(.alloc).?),872
866 .arg => genArg(o),873 //.constant => unreachable, // excluded from function bodies
867 .assembly => try genAsm(o, inst.castTag(.assembly).?),874 //.alloc => try genAlloc(o, inst.castTag(.alloc).?),
868 .block => try genBlock(o, inst.castTag(.block).?),875 //.arg => genArg(o),
869 .bitcast => try genBitcast(o, inst.castTag(.bitcast).?),876 //.assembly => try genAsm(o, inst.castTag(.assembly).?),
870 .breakpoint => try genBreakpoint(o, inst.castTag(.breakpoint).?),877 //.block => try genBlock(o, inst.castTag(.block).?),
871 .call => try genCall(o, inst.castTag(.call).?),878 //.bitcast => try genBitcast(o, inst.castTag(.bitcast).?),
872 .cmp_eq => try genBinOp(o, inst.castTag(.cmp_eq).?, " == "),879 //.breakpoint => try genBreakpoint(o, inst.castTag(.breakpoint).?),
873 .cmp_gt => try genBinOp(o, inst.castTag(.cmp_gt).?, " > "),880 //.call => try genCall(o, inst.castTag(.call).?),
874 .cmp_gte => try genBinOp(o, inst.castTag(.cmp_gte).?, " >= "),881 //.cmp_eq => try genBinOp(o, inst.castTag(.cmp_eq).?, " == "),
875 .cmp_lt => try genBinOp(o, inst.castTag(.cmp_lt).?, " < "),882 //.cmp_gt => try genBinOp(o, inst.castTag(.cmp_gt).?, " > "),
876 .cmp_lte => try genBinOp(o, inst.castTag(.cmp_lte).?, " <= "),883 //.cmp_gte => try genBinOp(o, inst.castTag(.cmp_gte).?, " >= "),
877 .cmp_neq => try genBinOp(o, inst.castTag(.cmp_neq).?, " != "),884 //.cmp_lt => try genBinOp(o, inst.castTag(.cmp_lt).?, " < "),
878 .dbg_stmt => try genDbgStmt(o, inst.castTag(.dbg_stmt).?),885 //.cmp_lte => try genBinOp(o, inst.castTag(.cmp_lte).?, " <= "),
879 .intcast => try genIntCast(o, inst.castTag(.intcast).?),886 //.cmp_neq => try genBinOp(o, inst.castTag(.cmp_neq).?, " != "),
880 .load => try genLoad(o, inst.castTag(.load).?),887 //.dbg_stmt => try genDbgStmt(o, inst.castTag(.dbg_stmt).?),
881 .ret => try genRet(o, inst.castTag(.ret).?),888 //.intcast => try genIntCast(o, inst.castTag(.intcast).?),
882 .retvoid => try genRetVoid(o),889 //.load => try genLoad(o, inst.castTag(.load).?),
883 .store => try genStore(o, inst.castTag(.store).?),890 //.ret => try genRet(o, inst.castTag(.ret).?),
884 .unreach => try genUnreach(o, inst.castTag(.unreach).?),891 //.retvoid => try genRetVoid(o),
885 .loop => try genLoop(o, inst.castTag(.loop).?),892 //.store => try genStore(o, inst.castTag(.store).?),
886 .condbr => try genCondBr(o, inst.castTag(.condbr).?),893 //.unreach => try genUnreach(o, inst.castTag(.unreach).?),
887 .br => try genBr(o, inst.castTag(.br).?),894 //.loop => try genLoop(o, inst.castTag(.loop).?),
888 .br_void => try genBrVoid(o, inst.castTag(.br_void).?.block),895 //.condbr => try genCondBr(o, inst.castTag(.condbr).?),
889 .switchbr => try genSwitchBr(o, inst.castTag(.switchbr).?),896 //.br => try genBr(o, inst.castTag(.br).?),
890 // bool_and and bool_or are non-short-circuit operations897 //.br_void => try genBrVoid(o, inst.castTag(.br_void).?.block),
891 .bool_and => try genBinOp(o, inst.castTag(.bool_and).?, " & "),898 //.switchbr => try genSwitchBr(o, inst.castTag(.switchbr).?),
892 .bool_or => try genBinOp(o, inst.castTag(.bool_or).?, " | "),899 //// bool_and and bool_or are non-short-circuit operations
893 .bit_and => try genBinOp(o, inst.castTag(.bit_and).?, " & "),900 //.bool_and => try genBinOp(o, inst.castTag(.bool_and).?, " & "),
894 .bit_or => try genBinOp(o, inst.castTag(.bit_or).?, " | "),901 //.bool_or => try genBinOp(o, inst.castTag(.bool_or).?, " | "),
895 .xor => try genBinOp(o, inst.castTag(.xor).?, " ^ "),902 //.bit_and => try genBinOp(o, inst.castTag(.bit_and).?, " & "),
896 .not => try genUnOp(o, inst.castTag(.not).?, "!"),903 //.bit_or => try genBinOp(o, inst.castTag(.bit_or).?, " | "),
897 .is_null => try genIsNull(o, inst.castTag(.is_null).?),904 //.xor => try genBinOp(o, inst.castTag(.xor).?, " ^ "),
898 .is_non_null => try genIsNull(o, inst.castTag(.is_non_null).?),905 //.not => try genUnOp(o, inst.castTag(.not).?, "!"),
899 .is_null_ptr => try genIsNull(o, inst.castTag(.is_null_ptr).?),906 //.is_null => try genIsNull(o, inst.castTag(.is_null).?),
900 .is_non_null_ptr => try genIsNull(o, inst.castTag(.is_non_null_ptr).?),907 //.is_non_null => try genIsNull(o, inst.castTag(.is_non_null).?),
901 .wrap_optional => try genWrapOptional(o, inst.castTag(.wrap_optional).?),908 //.is_null_ptr => try genIsNull(o, inst.castTag(.is_null_ptr).?),
902 .optional_payload => try genOptionalPayload(o, inst.castTag(.optional_payload).?),909 //.is_non_null_ptr => try genIsNull(o, inst.castTag(.is_non_null_ptr).?),
903 .optional_payload_ptr => try genOptionalPayload(o, inst.castTag(.optional_payload_ptr).?),910 //.wrap_optional => try genWrapOptional(o, inst.castTag(.wrap_optional).?),
904 .ref => try genRef(o, inst.castTag(.ref).?),911 //.optional_payload => try genOptionalPayload(o, inst.castTag(.optional_payload).?),
905 .struct_field_ptr => try genStructFieldPtr(o, inst.castTag(.struct_field_ptr).?),912 //.optional_payload_ptr => try genOptionalPayload(o, inst.castTag(.optional_payload_ptr).?),
906913 //.ref => try genRef(o, inst.castTag(.ref).?),
907 .is_err => try genIsErr(o, inst.castTag(.is_err).?, "", ".", "!="),914 //.struct_field_ptr => try genStructFieldPtr(o, inst.castTag(.struct_field_ptr).?),
908 .is_non_err => try genIsErr(o, inst.castTag(.is_non_err).?, "", ".", "=="),915
909 .is_err_ptr => try genIsErr(o, inst.castTag(.is_err_ptr).?, "*", "->", "!="),916 //.is_err => try genIsErr(o, inst.castTag(.is_err).?, "", ".", "!="),
910 .is_non_err_ptr => try genIsErr(o, inst.castTag(.is_non_err_ptr).?, "*", "->", "=="),917 //.is_non_err => try genIsErr(o, inst.castTag(.is_non_err).?, "", ".", "=="),
911918 //.is_err_ptr => try genIsErr(o, inst.castTag(.is_err_ptr).?, "*", "->", "!="),
912 .unwrap_errunion_payload => try genUnwrapErrUnionPay(o, inst.castTag(.unwrap_errunion_payload).?),919 //.is_non_err_ptr => try genIsErr(o, inst.castTag(.is_non_err_ptr).?, "*", "->", "=="),
913 .unwrap_errunion_err => try genUnwrapErrUnionErr(o, inst.castTag(.unwrap_errunion_err).?),920
914 .unwrap_errunion_payload_ptr => try genUnwrapErrUnionPay(o, inst.castTag(.unwrap_errunion_payload_ptr).?),921 //.unwrap_errunion_payload => try genUnwrapErrUnionPay(o, inst.castTag(.unwrap_errunion_payload).?),
915 .unwrap_errunion_err_ptr => try genUnwrapErrUnionErr(o, inst.castTag(.unwrap_errunion_err_ptr).?),922 //.unwrap_errunion_err => try genUnwrapErrUnionErr(o, inst.castTag(.unwrap_errunion_err).?),
916 .wrap_errunion_payload => try genWrapErrUnionPay(o, inst.castTag(.wrap_errunion_payload).?),923 //.unwrap_errunion_payload_ptr => try genUnwrapErrUnionPay(o, inst.castTag(.unwrap_errunion_payload_ptr).?),
917 .wrap_errunion_err => try genWrapErrUnionErr(o, inst.castTag(.wrap_errunion_err).?),924 //.unwrap_errunion_err_ptr => try genUnwrapErrUnionErr(o, inst.castTag(.unwrap_errunion_err_ptr).?),
918 .br_block_flat => return o.dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement codegen for br_block_flat", .{}),925 //.wrap_errunion_payload => try genWrapErrUnionPay(o, inst.castTag(.wrap_errunion_payload).?),
919 .ptrtoint => return o.dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement codegen for ptrtoint", .{}),926 //.wrap_errunion_err => try genWrapErrUnionErr(o, inst.castTag(.wrap_errunion_err).?),
920 .varptr => try genVarPtr(o, inst.castTag(.varptr).?),927 //.br_block_flat => return o.dg.fail("TODO: C backend: implement codegen for br_block_flat", .{}),
921 .floatcast => return o.dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement codegen for floatcast", .{}),928 //.ptrtoint => return o.dg.fail("TODO: C backend: implement codegen for ptrtoint", .{}),
929 //.varptr => try genVarPtr(o, inst.castTag(.varptr).?),
930 //.floatcast => return o.dg.fail("TODO: C backend: implement codegen for floatcast", .{}),
931 else => return o.dg.fail("TODO: C backend: rework AIR memory layout", .{}),
922 };932 };
923 switch (result_value) {933 switch (result_value) {
924 .none => {},934 .none => {},
...@@ -1060,7 +1070,7 @@ fn genWrapOp(o: *Object, inst: *Inst.BinOp, str_op: [*:0]const u8, fn_op: [*:0]c...@@ -1060,7 +1070,7 @@ fn genWrapOp(o: *Object, inst: *Inst.BinOp, str_op: [*:0]const u8, fn_op: [*:0]c
1060 }1070 }
10611071
1062 if (bits > 64) {1072 if (bits > 64) {
1063 return o.dg.fail(.{ .node_offset = 0 }, "TODO: C backend: genWrapOp for large integers", .{});1073 return o.dg.fail("TODO: C backend: genWrapOp for large integers", .{});
1064 }1074 }
10651075
1066 var min_buf: [80]u8 = undefined;1076 var min_buf: [80]u8 = undefined;
...@@ -1227,7 +1237,7 @@ fn genCall(o: *Object, inst: *Inst.Call) !CValue {...@@ -1227,7 +1237,7 @@ fn genCall(o: *Object, inst: *Inst.Call) !CValue {
1227 try writer.writeAll(");\n");1237 try writer.writeAll(");\n");
1228 return result_local;1238 return result_local;
1229 } else {1239 } else {
1230 return o.dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement function pointers", .{});1240 return o.dg.fail("TODO: C backend: implement function pointers", .{});
1231 }1241 }
1232}1242}
12331243
...@@ -1390,13 +1400,13 @@ fn genAsm(o: *Object, as: *Inst.Assembly) !CValue {...@@ -1390,13 +1400,13 @@ fn genAsm(o: *Object, as: *Inst.Assembly) !CValue {
1390 try o.writeCValue(writer, arg_c_value);1400 try o.writeCValue(writer, arg_c_value);
1391 try writer.writeAll(";\n");1401 try writer.writeAll(";\n");
1392 } else {1402 } else {
1393 return o.dg.fail(.{ .node_offset = 0 }, "TODO non-explicit inline asm regs", .{});1403 return o.dg.fail("TODO non-explicit inline asm regs", .{});
1394 }1404 }
1395 }1405 }
1396 const volatile_string: []const u8 = if (as.is_volatile) "volatile " else "";1406 const volatile_string: []const u8 = if (as.is_volatile) "volatile " else "";
1397 try writer.print("__asm {s}(\"{s}\"", .{ volatile_string, as.asm_source });1407 try writer.print("__asm {s}(\"{s}\"", .{ volatile_string, as.asm_source });
1398 if (as.output_constraint) |_| {1408 if (as.output_constraint) |_| {
1399 return o.dg.fail(.{ .node_offset = 0 }, "TODO: CBE inline asm output", .{});1409 return o.dg.fail("TODO: CBE inline asm output", .{});
1400 }1410 }
1401 if (as.inputs.len > 0) {1411 if (as.inputs.len > 0) {
1402 if (as.output_constraint == null) {1412 if (as.output_constraint == null) {
...@@ -1421,7 +1431,7 @@ fn genAsm(o: *Object, as: *Inst.Assembly) !CValue {...@@ -1421,7 +1431,7 @@ fn genAsm(o: *Object, as: *Inst.Assembly) !CValue {
1421 if (as.base.isUnused())1431 if (as.base.isUnused())
1422 return CValue.none;1432 return CValue.none;
14231433
1424 return o.dg.fail(.{ .node_offset = 0 }, "TODO: C backend: inline asm expression result used", .{});1434 return o.dg.fail("TODO: C backend: inline asm expression result used", .{});
1425}1435}
14261436
1427fn genIsNull(o: *Object, inst: *Inst.UnOp) !CValue {1437fn genIsNull(o: *Object, inst: *Inst.UnOp) !CValue {
src/link/Elf.zig+3
...@@ -2519,6 +2519,9 @@ pub fn updateDecl(self: *Elf, module: *Module, decl: *Module.Decl) !void {...@@ -2519,6 +2519,9 @@ pub fn updateDecl(self: *Elf, module: *Module, decl: *Module.Decl) !void {
2519 var code_buffer = std.ArrayList(u8).init(self.base.allocator);2519 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
2520 defer code_buffer.deinit();2520 defer code_buffer.deinit();
25212521
2522 var dbg_line_buffer = std.ArrayList(u8).init(self.base.allocator);
2523 defer dbg_line_buffer.deinit();
2524
2522 var dbg_info_buffer = std.ArrayList(u8).init(self.base.allocator);2525 var dbg_info_buffer = std.ArrayList(u8).init(self.base.allocator);
2523 defer dbg_info_buffer.deinit();2526 defer dbg_info_buffer.deinit();
25242527
src/value.zig+1-1
...@@ -1700,7 +1700,7 @@ pub const Value = extern union {...@@ -1700,7 +1700,7 @@ pub const Value = extern union {
1700 /// peer type resolution. This is stored in a separate list so that1700 /// peer type resolution. This is stored in a separate list so that
1701 /// the items are contiguous in memory and thus can be passed to1701 /// the items are contiguous in memory and thus can be passed to
1702 /// `Module.resolvePeerTypes`.1702 /// `Module.resolvePeerTypes`.
1703 stored_inst_list: std.ArrayListUnmanaged(*ir.Inst) = .{},1703 stored_inst_list: std.ArrayListUnmanaged(Air.Inst.Index) = .{},
1704 },1704 },
1705 };1705 };
17061706