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 {
332332 body_len: u32,
333333};
334334
335/// Trailing is a list of `Ref` for every `args_len`.
335/// Trailing is a list of `Inst.Ref` for every `args_len`.
336336pub const Call = struct {
337337 args_len: u32,
338338};
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`:
341341/// * 0. the then body, according to `then_body_len`.
342342/// * 1. the else body, according to `else_body_len`.
343343pub const CondBr = struct {
......@@ -355,19 +355,19 @@ pub const SwitchBr = struct {
355355 /// Trailing:
356356 /// * instruction index for each `body_len`.
357357 pub const Case = struct {
358 item: Ref,
358 item: Inst.Ref,
359359 body_len: u32,
360360 };
361361};
362362
363363pub const StructField = struct {
364 struct_ptr: Ref,
364 struct_ptr: Inst.Ref,
365365 field_index: u32,
366366};
367367
368368/// Trailing:
369/// 0. `Ref` for every outputs_len
370/// 1. `Ref` for every inputs_len
369/// 0. `Inst.Ref` for every outputs_len
370/// 1. `Inst.Ref` for every inputs_len
371371pub const Asm = struct {
372372 /// Index to the corresponding ZIR instruction.
373373 /// `asm_source`, `outputs_len`, `inputs_len`, `clobbers_len`, `is_volatile`, and
......@@ -381,6 +381,24 @@ pub fn getMainBody(air: Air) []const Air.Inst.Index {
381381 return air.extra[body_index..][0..body_len];
382382}
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
384402/// Returns the requested data, as well as the new index which is at the start of the
385403/// trailers for the object.
386404pub 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
20232023 defer air.deinit(gpa);
20242024
20252025 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);
20272027 defer liveness.deinit(gpa);
20282028
20292029 if (std.builtin.mode == .Debug and self.verbose_air) {
src/Liveness.zig+51-20
......@@ -7,11 +7,13 @@
77//! * Switch Branches
88const Liveness = @This();
99const std = @import("std");
10const Air = @import("Air.zig");
1110const trace = @import("tracy.zig").trace;
1211const log = std.log.scoped(.liveness);
1312const assert = std.debug.assert;
1413const Allocator = std.mem.Allocator;
14const Air = @import("Air.zig");
15const Zir = @import("Zir.zig");
16const Log2Int = std.math.Log2Int;
1517
1618/// This array is split into sets of 4 bits per AIR instruction.
1719/// The MSB (0bX000) is whether the instruction is unreferenced.
......@@ -44,7 +46,7 @@ pub const SwitchBr = struct {
4446 else_death_count: u32,
4547};
4648
47pub fn analyze(gpa: *Allocator, air: Air) Allocator.Error!Liveness {
49pub fn analyze(gpa: *Allocator, air: Air, zir: Zir) Allocator.Error!Liveness {
4850 const tracy = trace(@src());
4951 defer tracy.end();
5052
......@@ -58,6 +60,7 @@ pub fn analyze(gpa: *Allocator, air: Air) Allocator.Error!Liveness {
5860 ),
5961 .extra = .{},
6062 .special = .{},
63 .zir = &zir,
6164 };
6265 errdefer gpa.free(a.tomb_bits);
6366 errdefer a.special.deinit(gpa);
......@@ -74,23 +77,32 @@ pub fn analyze(gpa: *Allocator, air: Air) Allocator.Error!Liveness {
7477 };
7578}
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
7786pub fn isUnused(l: Liveness, inst: Air.Inst.Index) bool {
7887 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));
8090 return (l.tomb_bits[usize_index] & mask) != 0;
8191}
8292
8393pub fn operandDies(l: Liveness, inst: Air.Inst.Index, operand: OperandInt) bool {
8494 assert(operand < bpi - 1);
8595 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);
8798 return (l.tomb_bits[usize_index] & mask) != 0;
8899}
89100
90101pub fn clearOperandDeath(l: *Liveness, inst: Air.Inst.Index, operand: OperandInt) void {
91102 assert(operand < bpi - 1);
92103 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);
94106 l.tomb_bits[usize_index] |= mask;
95107}
96108
......@@ -113,10 +125,12 @@ const Analysis = struct {
113125 tomb_bits: []usize,
114126 special: std.AutoHashMapUnmanaged(Air.Inst.Index, u32),
115127 extra: std.ArrayListUnmanaged(u32),
128 zir: *const Zir,
116129
117130 fn storeTombBits(a: *Analysis, inst: Air.Inst.Index, tomb_bits: Bpi) void {
118131 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);
120134 }
121135
122136 fn addExtra(a: *Analysis, extra: anytype) Allocator.Error!u32 {
......@@ -203,9 +217,11 @@ fn analyzeInst(
203217 return trackOperands(a, new_set, inst, main_tomb, .{ o.lhs, o.rhs, .none });
204218 },
205219
220 .arg,
206221 .alloc,
207222 .br,
208223 .constant,
224 .const_ty,
209225 .breakpoint,
210226 .dbg_stmt,
211227 .varptr,
......@@ -255,15 +271,30 @@ fn analyzeInst(
255271 if (args.len <= bpi - 2) {
256272 var buf: [bpi - 1]Air.Inst.Ref = undefined;
257273 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));
259275 return trackOperands(a, new_set, inst, main_tomb, buf);
260276 }
261 @panic("TODO: liveness analysis for function with many args");
277 @panic("TODO: liveness analysis for function with greater than 2 args");
262278 },
263279 .struct_field_ptr => {
264280 const extra = a.air.extraData(Air.StructField, inst_datas[inst].ty_pl.payload).data;
265281 return trackOperands(a, new_set, inst, main_tomb, .{ extra.struct_ptr, .none, .none });
266282 },
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 },
267298 .block => {
268299 const extra = a.air.extraData(Air.Block, inst_datas[inst].ty_pl.payload);
269300 const body = a.air.extra[extra.end..][0..extra.data.body_len];
......@@ -287,8 +318,8 @@ fn analyzeInst(
287318 const then_body = a.air.extra[extra.end..][0..extra.data.then_body_len];
288319 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);
291 defer then_table.deinit();
321 var then_table: std.AutoHashMapUnmanaged(Air.Inst.Index, void) = .{};
322 defer then_table.deinit(gpa);
292323 try analyzeWithContext(a, &then_table, then_body);
293324
294325 // Reset the table back to its state from before the branch.
......@@ -299,8 +330,8 @@ fn analyzeInst(
299330 }
300331 }
301332
302 var else_table = std.AutoHashMap(Air.Inst.Index, void).init(gpa);
303 defer else_table.deinit();
333 var else_table: std.AutoHashMapUnmanaged(Air.Inst.Index, void) = .{};
334 defer else_table.deinit(gpa);
304335 try analyzeWithContext(a, &else_table, else_body);
305336
306337 var then_entry_deaths = std.ArrayList(Air.Inst.Index).init(gpa);
......@@ -331,7 +362,7 @@ fn analyzeInst(
331362 }
332363 // Now we have to correctly populate new_set.
333364 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()));
335366 var it = then_table.keyIterator();
336367 while (it.next()) |key| {
337368 _ = ns.putAssumeCapacity(key.*, {});
......@@ -344,7 +375,7 @@ fn analyzeInst(
344375 const then_death_count = @intCast(u32, then_entry_deaths.items.len);
345376 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 +
348379 then_death_count + else_death_count);
349380 const extra_index = a.addExtraAssumeCapacity(CondBr{
350381 .then_death_count = then_death_count,
......@@ -352,7 +383,7 @@ fn analyzeInst(
352383 });
353384 a.extra.appendSliceAssumeCapacity(then_entry_deaths.items);
354385 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
357388 // Continue on with the instruction analysis. The following code will find the condition
358389 // instruction, and the deaths flag for the CondBr instruction will indicate whether the
......@@ -438,12 +469,12 @@ fn analyzeInst(
438469 });
439470 for (case_deaths[0 .. case_deaths.len - 1]) |*cd| {
440471 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);
442473 a.extra.appendAssumeCapacity(case_death_count);
443474 a.extra.appendSliceAssumeCapacity(cd.items);
444475 }
445476 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
448479 return trackOperands(a, new_set, inst, main_tomb, .{ condition, .none, .none });
449480 },
......@@ -452,7 +483,7 @@ fn analyzeInst(
452483
453484fn trackOperands(
454485 a: *Analysis,
455 new_set: ?*std.AutoHashMap(Air.Inst.Index, void),
486 new_set: ?*std.AutoHashMapUnmanaged(Air.Inst.Index, void),
456487 inst: Air.Inst.Index,
457488 main_tomb: bool,
458489 operands: [bpi - 1]Air.Inst.Ref,
......@@ -468,12 +499,12 @@ fn trackOperands(
468499 tomb_bits <<= 1;
469500 const op_int = @enumToInt(operands[i]);
470501 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);
472503 const prev = try table.fetchPut(gpa, operand, {});
473504 if (prev == null) {
474505 // Death.
475506 tomb_bits |= 1;
476 if (new_set) |ns| try ns.putNoClobber(operand, {});
507 if (new_set) |ns| try ns.putNoClobber(gpa, operand, {});
477508 }
478509 }
479510 a.storeTombBits(inst, tomb_bits);
src/Module.zig+29-5
......@@ -1225,6 +1225,30 @@ pub const Scope = struct {
12251225 pub fn getFileScope(block: *Block) *Scope.File {
12261226 return block.src_decl.namespace.file_scope;
12271227 }
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 }
12281252 };
12291253};
12301254
......@@ -3408,7 +3432,7 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !Air {
34083432 defer decl.value_arena.?.* = arena.state;
34093433
34103434 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());
34123436 defer gpa.free(param_inst_list);
34133437
34143438 var sema: Sema = .{
......@@ -3440,10 +3464,13 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !Air {
34403464 defer inner_block.instructions.deinit(gpa);
34413465
34423466 // AIR requires the arg parameters to be the first N instructions.
3467 try inner_block.instructions.ensureTotalCapacity(gpa, param_inst_list.len);
34433468 for (param_inst_list) |*param_inst, param_index| {
34443469 const param_type = fn_ty.fnParamType(param_index);
34453470 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);
34473474 try sema.air_instructions.append(gpa, .{
34483475 .tag = .arg,
34493476 .data = .{
......@@ -3454,7 +3481,6 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !Air {
34543481 },
34553482 });
34563483 }
3457 try inner_block.instructions.appendSlice(gpa, param_inst_list);
34583484
34593485 func.state = .in_progress;
34603486 log.debug("set {s} to in_progress", .{decl.name});
......@@ -4043,13 +4069,11 @@ pub fn floatMul(
40434069}
40444070
40454071pub fn simplePtrType(
4046 mod: *Module,
40474072 arena: *Allocator,
40484073 elem_ty: Type,
40494074 mutable: bool,
40504075 size: std.builtin.TypeInfo.Pointer.Size,
40514076) Allocator.Error!Type {
4052 _ = mod;
40534077 if (!mutable and size == .Slice and elem_ty.eql(Type.initTag(.u8))) {
40544078 return Type.initTag(.const_slice_u8);
40554079 }
src/Sema.zig+556-430
......@@ -36,7 +36,7 @@ func: ?*Module.Fn,
3636/// > Denormalized data to make `resolveInst` faster. This is 0 if not inside a function,
3737/// > otherwise it is the number of parameters of the function.
3838/// > param_count: u32
39param_inst_list: []const Air.Inst.Index,
39param_inst_list: []const Air.Inst.Ref,
4040branch_quota: u32 = 1000,
4141branch_count: u32 = 0,
4242/// This field is updated when a new source location becomes active, so that
......@@ -59,8 +59,6 @@ const TypedValue = @import("TypedValue.zig");
5959const Air = @import("Air.zig");
6060const Zir = @import("Zir.zig");
6161const Module = @import("Module.zig");
62const Inst = ir.Inst;
63const Body = ir.Body;
6462const trace = @import("tracy.zig").trace;
6563const Scope = Module.Scope;
6664const InnerError = Module.InnerError;
......@@ -117,7 +115,7 @@ pub fn analyzeFnBody(
117115/// Returns only the result from the body that is specified.
118116/// Only appropriate to call when it is determined at comptime that this body
119117/// 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 {
121119 const break_inst = try sema.analyzeBody(block, body);
122120 const operand_ref = sema.code.instructions.items(.data)[break_inst].@"break".operand;
123121 return sema.resolveInst(operand_ref);
......@@ -513,7 +511,7 @@ pub fn analyzeBody(
513511 // const break_inst = try sema.analyzeBody(block, inline_body);
514512 // const break_data = datas[break_inst].@"break";
515513 // if (inst == break_data.block_inst) {
516 // break :blk try sema.resolveInst(break_data.operand);
514 // break :blk sema.resolveInst(break_data.operand);
517515 // } else {
518516 // return break_inst;
519517 // }
......@@ -529,12 +527,12 @@ pub fn analyzeBody(
529527 // const break_inst = try sema.analyzeBody(block, inline_body);
530528 // const break_data = datas[break_inst].@"break";
531529 // if (inst == break_data.block_inst) {
532 // break :blk try sema.resolveInst(break_data.operand);
530 // break :blk sema.resolveInst(break_data.operand);
533531 // } else {
534532 // return break_inst;
535533 // }
536534 //},
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"),
538536 };
539537 if (sema.getAirType(air_inst).isNoReturn())
540538 return always_noreturn;
......@@ -543,7 +541,7 @@ pub fn analyzeBody(
543541 }
544542}
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 {
547545 const extended = sema.code.instructions.items(.data)[inst].extended;
548546 switch (extended.opcode) {
549547 // zig fmt: off
......@@ -598,7 +596,7 @@ fn resolveConstBool(
598596 src: LazySrcLoc,
599597 zir_ref: Zir.Inst.Ref,
600598) !bool {
601 const air_inst = try sema.resolveInst(zir_ref);
599 const air_inst = sema.resolveInst(zir_ref);
602600 const wanted_type = Type.initTag(.bool);
603601 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
604602 const val = try sema.resolveConstValue(block, src, coerced_inst);
......@@ -611,7 +609,7 @@ fn resolveConstString(
611609 src: LazySrcLoc,
612610 zir_ref: Zir.Inst.Ref,
613611) ![]u8 {
614 const air_inst = try sema.resolveInst(zir_ref);
612 const air_inst = sema.resolveInst(zir_ref);
615613 const wanted_type = Type.initTag(.const_slice_u8);
616614 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
617615 const val = try sema.resolveConstValue(block, src, coerced_inst);
......@@ -619,24 +617,39 @@ fn resolveConstString(
619617}
620618
621619pub 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);
623621 return sema.resolveAirAsType(block, src, air_inst);
624622}
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 {
627630 const wanted_type = Type.initTag(.@"type");
628631 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
629632 const val = try sema.resolveConstValue(block, src, coerced_inst);
630633 return val.toType(sema.arena);
631634}
632635
633fn resolveConstValue(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, base: Air.Inst.Index) !Value {
634 return (try sema.resolveDefinedValue(block, src, base)) orelse
636fn resolveConstValue(
637 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
635643 return sema.failWithNeededComptime(block, src);
636644}
637645
638fn resolveDefinedValue(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, base: Air.Inst.Index) !?Value {
639 if (try sema.resolvePossiblyUndefinedValue(block, src, base)) |val| {
646fn resolveDefinedValue(
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| {
640653 if (val.isUndef()) {
641654 return sema.failWithUseOfUndef(block, src);
642655 }
......@@ -649,13 +662,29 @@ fn resolvePossiblyUndefinedValue(
649662 sema: *Sema,
650663 block: *Scope.Block,
651664 src: LazySrcLoc,
652 base: Air.Inst.Index,
665 air_ref: Air.Inst.Ref,
653666) !?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| {
655669 return opv;
656670 }
657 const inst = base.castTag(.constant) orelse return null;
658 return inst.val;
671 // First section of indexes correspond to a set number of constant values.
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 }
659688}
660689
661690fn failWithNeededComptime(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) InnerError {
......@@ -677,7 +706,7 @@ fn resolveAlreadyCoercedInt(
677706 comptime Int: type,
678707) !Int {
679708 comptime assert(@typeInfo(Int).Int.bits <= 64);
680 const air_inst = try sema.resolveInst(zir_ref);
709 const air_inst = sema.resolveInst(zir_ref);
681710 const val = try sema.resolveConstValue(block, src, air_inst);
682711 switch (@typeInfo(Int).Int.signedness) {
683712 .signed => return @intCast(Int, val.toSignedInt()),
......@@ -692,7 +721,7 @@ fn resolveInt(
692721 zir_ref: Zir.Inst.Ref,
693722 dest_type: Type,
694723) !u64 {
695 const air_inst = try sema.resolveInst(zir_ref);
724 const air_inst = sema.resolveInst(zir_ref);
696725 const coerced = try sema.coerce(block, dest_type, air_inst, src);
697726 const val = try sema.resolveConstValue(block, src, coerced);
698727
......@@ -705,21 +734,21 @@ pub fn resolveInstConst(
705734 src: LazySrcLoc,
706735 zir_ref: Zir.Inst.Ref,
707736) InnerError!TypedValue {
708 const air_inst = try sema.resolveInst(zir_ref);
709 const val = try sema.resolveConstValue(block, src, air_inst);
737 const air_ref = sema.resolveInst(zir_ref);
738 const val = try sema.resolveConstValue(block, src, air_ref);
710739 return TypedValue{
711 .ty = air_inst.ty,
740 .ty = sema.getTypeOfAirRef(air_ref),
712741 .val = val,
713742 };
714743}
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 {
717746 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
718747 const src = inst_data.src();
719748 return sema.mod.fail(&block.base, src, "TODO implement zir_sema.zirBitcastResultPtr", .{});
720749}
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 {
723752 _ = inst;
724753 const tracy = trace(@src());
725754 defer tracy.end();
......@@ -754,7 +783,7 @@ fn zirStructDecl(
754783 block: *Scope.Block,
755784 extended: Zir.Inst.Extended.InstData,
756785 inst: Zir.Inst.Index,
757) InnerError!Air.Inst.Index {
786) InnerError!Air.Inst.Ref {
758787 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
759788 const src: LazySrcLoc = if (small.has_src_node) blk: {
760789 const node_offset = @bitCast(i32, sema.code.extra[extended.operand]);
......@@ -825,7 +854,7 @@ fn zirEnumDecl(
825854 sema: *Sema,
826855 block: *Scope.Block,
827856 extended: Zir.Inst.Extended.InstData,
828) InnerError!Air.Inst.Index {
857) InnerError!Air.Inst.Ref {
829858 const tracy = trace(@src());
830859 defer tracy.end();
831860
......@@ -1022,7 +1051,7 @@ fn zirUnionDecl(
10221051 block: *Scope.Block,
10231052 extended: Zir.Inst.Extended.InstData,
10241053 inst: Zir.Inst.Index,
1025) InnerError!Air.Inst.Index {
1054) InnerError!Air.Inst.Ref {
10261055 const tracy = trace(@src());
10271056 defer tracy.end();
10281057
......@@ -1086,7 +1115,7 @@ fn zirOpaqueDecl(
10861115 block: *Scope.Block,
10871116 inst: Zir.Inst.Index,
10881117 name_strategy: Zir.Inst.NameStrategy,
1089) InnerError!Air.Inst.Index {
1118) InnerError!Air.Inst.Ref {
10901119 const tracy = trace(@src());
10911120 defer tracy.end();
10921121
......@@ -1106,7 +1135,7 @@ fn zirErrorSetDecl(
11061135 block: *Scope.Block,
11071136 inst: Zir.Inst.Index,
11081137 name_strategy: Zir.Inst.NameStrategy,
1109) InnerError!Air.Inst.Index {
1138) InnerError!Air.Inst.Ref {
11101139 const tracy = trace(@src());
11111140 defer tracy.end();
11121141
......@@ -1146,7 +1175,7 @@ fn zirRetPtr(
11461175 sema: *Sema,
11471176 block: *Scope.Block,
11481177 extended: Zir.Inst.Extended.InstData,
1149) InnerError!Air.Inst.Index {
1178) InnerError!Air.Inst.Ref {
11501179 const tracy = trace(@src());
11511180 defer tracy.end();
11521181
......@@ -1154,16 +1183,16 @@ fn zirRetPtr(
11541183 try sema.requireFunctionBlock(block, src);
11551184 const fn_ty = sema.func.?.owner_decl.ty;
11561185 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);
11581187 return block.addNoOp(src, ptr_type, .alloc);
11591188}
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 {
11621191 const tracy = trace(@src());
11631192 defer tracy.end();
11641193
11651194 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);
11671196 return sema.analyzeRef(block, inst_data.src(), operand);
11681197}
11691198
......@@ -1171,7 +1200,7 @@ fn zirRetType(
11711200 sema: *Sema,
11721201 block: *Scope.Block,
11731202 extended: Zir.Inst.Extended.InstData,
1174) InnerError!Air.Inst.Index {
1203) InnerError!Air.Inst.Ref {
11751204 const tracy = trace(@src());
11761205 defer tracy.end();
11771206
......@@ -1187,7 +1216,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) I
11871216 defer tracy.end();
11881217
11891218 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);
11911220 const src = inst_data.src();
11921221
11931222 return sema.ensureResultUsed(block, operand, src);
......@@ -1196,7 +1225,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) I
11961225fn ensureResultUsed(
11971226 sema: *Sema,
11981227 block: *Scope.Block,
1199 operand: Air.Inst.Index,
1228 operand: Air.Inst.Ref,
12001229 src: LazySrcLoc,
12011230) InnerError!void {
12021231 switch (operand.ty.zigTypeTag()) {
......@@ -1210,7 +1239,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
12101239 defer tracy.end();
12111240
12121241 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);
12141243 const src = inst_data.src();
12151244 switch (operand.ty.zigTypeTag()) {
12161245 .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
12181247 }
12191248}
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 {
12221251 const tracy = trace(@src());
12231252 defer tracy.end();
12241253
12251254 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
12261255 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
12291258 const elem_ty = array_ptr.ty.elemType();
12301259 if (!elem_ty.isIndexable()) {
......@@ -1267,7 +1296,7 @@ fn zirArg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air
12671296
12681297 // Set the name of the Air.Arg instruction for use by codegen debug info.
12691298 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;
12711300 return air_arg;
12721301}
12731302
......@@ -1275,13 +1304,13 @@ fn zirAllocExtended(
12751304 sema: *Sema,
12761305 block: *Scope.Block,
12771306 extended: Zir.Inst.Extended.InstData,
1278) InnerError!Air.Inst.Index {
1307) InnerError!Air.Inst.Ref {
12791308 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);
12801309 const src: LazySrcLoc = .{ .node_offset = extra.data.src_node };
12811310 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocExtended", .{});
12821311}
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 {
12851314 const tracy = trace(@src());
12861315 defer tracy.end();
12871316
......@@ -1289,7 +1318,7 @@ fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
12891318 const src = inst_data.src();
12901319 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
12911320 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
12941323 const val_payload = try sema.arena.create(Value.Payload.ComptimeAlloc);
12951324 val_payload.* = .{
......@@ -1304,13 +1333,13 @@ fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
13041333 });
13051334}
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 {
13081337 const src_node = sema.code.instructions.items(.data)[inst].node;
13091338 const src: LazySrcLoc = .{ .node_offset = src_node };
13101339 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocInferredComptime", .{});
13111340}
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 {
13141343 const tracy = trace(@src());
13151344 defer tracy.end();
13161345
......@@ -1318,12 +1347,12 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!A
13181347 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
13191348 const var_decl_src = inst_data.src();
13201349 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);
13221351 try sema.requireRuntimeBlock(block, var_decl_src);
13231352 return block.addNoOp(var_decl_src, ptr_type, .alloc);
13241353}
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 {
13271356 const tracy = trace(@src());
13281357 defer tracy.end();
13291358
......@@ -1332,7 +1361,7 @@ fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
13321361 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
13331362 const var_type = try sema.resolveType(block, ty_src, inst_data.operand);
13341363 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);
13361365 try sema.requireRuntimeBlock(block, var_decl_src);
13371366 return block.addNoOp(var_decl_src, ptr_type, .alloc);
13381367}
......@@ -1342,7 +1371,7 @@ fn zirAllocInferred(
13421371 block: *Scope.Block,
13431372 inst: Zir.Inst.Index,
13441373 inferred_alloc_ty: Type,
1345) InnerError!Air.Inst.Index {
1374) InnerError!Air.Inst.Ref {
13461375 const tracy = trace(@src());
13471376 defer tracy.end();
13481377
......@@ -1372,7 +1401,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
13721401
13731402 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
13741403 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);
13761405 const ptr_val = ptr.castTag(.constant).?.val;
13771406 const inferred_alloc = ptr_val.castTag(.inferred_alloc).?;
13781407 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
13851414 if (var_is_mut) {
13861415 try sema.validateVarType(block, ty_src, final_elem_ty);
13871416 }
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
13901419 // Change it to a normal alloc.
13911420 ptr.ty = final_ptr_ty;
......@@ -1406,7 +1435,7 @@ fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Ind
14061435 const struct_obj: *Module.Struct = s: {
14071436 const field_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node;
14081437 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);
14101439 break :s object_ptr.ty.elemType().castTag(.@"struct").?.data;
14111440 };
14121441
......@@ -1535,9 +1564,9 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In
15351564 // to omit it.
15361565 return;
15371566 }
1538 const ptr = try sema.resolveInst(bin_inst.lhs);
1539 const value = try sema.resolveInst(bin_inst.rhs);
1540 const ptr_ty = try sema.mod.simplePtrType(sema.arena, value.ty, true, .One);
1567 const ptr = sema.resolveInst(bin_inst.lhs);
1568 const value = sema.resolveInst(bin_inst.rhs);
1569 const ptr_ty = try Module.simplePtrType(sema.arena, value.ty, true, .One);
15411570 // TODO detect when this store should be done at compile-time. For example,
15421571 // if expressions should force it when the condition is compile-time known.
15431572 const src: LazySrcLoc = .unneeded;
......@@ -1552,14 +1581,14 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)
15521581
15531582 const src: LazySrcLoc = .unneeded;
15541583 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
1555 const ptr = try sema.resolveInst(bin_inst.lhs);
1556 const value = try sema.resolveInst(bin_inst.rhs);
1584 const ptr = sema.resolveInst(bin_inst.lhs);
1585 const value = sema.resolveInst(bin_inst.rhs);
15571586 const inferred_alloc = ptr.castTag(.constant).?.val.castTag(.inferred_alloc).?;
15581587 // Add the stored instruction to the set we will use to resolve peer types
15591588 // for the inferred allocation.
15601589 try inferred_alloc.data.stored_inst_list.append(sema.arena, value);
15611590 // 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);
15631592 try sema.requireRuntimeBlock(block, src);
15641593 const bitcasted_ptr = try block.addUnOp(src, ptr_ty, .bitcast, ptr);
15651594 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
15781607 defer tracy.end();
15791608
15801609 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
1581 const ptr = try sema.resolveInst(bin_inst.lhs);
1582 const value = try sema.resolveInst(bin_inst.rhs);
1610 const ptr = sema.resolveInst(bin_inst.lhs);
1611 const value = sema.resolveInst(bin_inst.rhs);
15831612 return sema.storePtr(block, sema.src, ptr, value);
15841613}
15851614
......@@ -1590,18 +1619,18 @@ fn zirStoreNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
15901619 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
15911620 const src = inst_data.src();
15921621 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1593 const ptr = try sema.resolveInst(extra.lhs);
1594 const value = try sema.resolveInst(extra.rhs);
1622 const ptr = sema.resolveInst(extra.lhs);
1623 const value = sema.resolveInst(extra.rhs);
15951624 return sema.storePtr(block, src, ptr, value);
15961625}
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 {
15991628 const tracy = trace(@src());
16001629 defer tracy.end();
16011630
16021631 const src: LazySrcLoc = .unneeded;
16031632 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);
16051634 const param_index = inst_data.param_index;
16061635
16071636 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
16311660 return sema.mod.constType(sema.arena, src, param_type);
16321661}
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 {
16351664 const tracy = trace(@src());
16361665 defer tracy.end();
16371666
......@@ -1659,7 +1688,7 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air
16591688 return sema.analyzeDeclRef(block, .unneeded, new_decl);
16601689}
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 {
16631692 _ = block;
16641693 const tracy = trace(@src());
16651694 defer tracy.end();
......@@ -1668,7 +1697,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air
16681697 return sema.mod.constIntUnsigned(sema.arena, .unneeded, Type.initTag(.comptime_int), int);
16691698}
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 {
16721701 _ = block;
16731702 const tracy = trace(@src());
16741703 defer tracy.end();
......@@ -1686,7 +1715,7 @@ fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
16861715 });
16871716}
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 {
16901719 _ = block;
16911720 const arena = sema.arena;
16921721 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
16991728 });
17001729}
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 {
17031732 _ = block;
17041733 const arena = sema.arena;
17051734 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
......@@ -1728,7 +1757,7 @@ fn zirCompileLog(
17281757 sema: *Sema,
17291758 block: *Scope.Block,
17301759 extended: Zir.Inst.Extended.InstData,
1731) InnerError!Air.Inst.Index {
1760) InnerError!Air.Inst.Ref {
17321761 var managed = sema.mod.compile_log_text.toManaged(sema.gpa);
17331762 defer sema.mod.compile_log_text = managed.moveToUnmanaged();
17341763 const writer = managed.writer();
......@@ -1741,7 +1770,7 @@ fn zirCompileLog(
17411770 for (args) |arg_ref, i| {
17421771 if (i != 0) try writer.print(", ", .{});
17431772
1744 const arg = try sema.resolveInst(arg_ref);
1773 const arg = sema.resolveInst(arg_ref);
17451774 if (try sema.resolvePossiblyUndefinedValue(block, src, arg)) |val| {
17461775 try writer.print("@as({}, {})", .{ arg.ty, val });
17471776 } else {
......@@ -1773,12 +1802,12 @@ fn zirRepeat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
17731802fn zirPanic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Zir.Inst.Index {
17741803 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
17751804 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
17781807 return sema.panicWithMsg(block, src, msg_inst);
17791808}
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 {
17821811 const tracy = trace(@src());
17831812 defer tracy.end();
17841813
......@@ -1843,7 +1872,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerE
18431872 return sema.analyzeBlockBody(parent_block, src, &child_block, merges);
18441873}
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 {
18471876 const tracy = trace(@src());
18481877 defer tracy.end();
18491878
......@@ -1853,13 +1882,13 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Inn
18531882 return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirCImport", .{});
18541883}
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 {
18571886 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
18581887 const src = inst_data.src();
18591888 return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirSuspendBlock", .{});
18601889}
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 {
18631892 const tracy = trace(@src());
18641893 defer tracy.end();
18651894
......@@ -1917,7 +1946,7 @@ fn resolveBlockBody(
19171946 child_block: *Scope.Block,
19181947 body: []const Zir.Inst.Index,
19191948 merges: *Scope.Block.Merges,
1920) InnerError!Air.Inst.Index {
1949) InnerError!Air.Inst.Ref {
19211950 _ = try sema.analyzeBody(child_block, body);
19221951 return sema.analyzeBlockBody(parent_block, src, child_block, merges);
19231952}
......@@ -1928,7 +1957,7 @@ fn analyzeBlockBody(
19281957 src: LazySrcLoc,
19291958 child_block: *Scope.Block,
19301959 merges: *Scope.Block.Merges,
1931) InnerError!Air.Inst.Index {
1960) InnerError!Air.Inst.Ref {
19321961 const tracy = trace(@src());
19331962 defer tracy.end();
19341963
......@@ -2088,7 +2117,7 @@ fn zirBreak(sema: *Sema, start_block: *Scope.Block, inst: Zir.Inst.Index) InnerE
20882117
20892118 const inst_data = sema.code.instructions.items(.data)[inst].@"break";
20902119 const src = sema.src;
2091 const operand = try sema.resolveInst(inst_data.operand);
2120 const operand = sema.resolveInst(inst_data.operand);
20922121 const zir_block = inst_data.block_inst;
20932122
20942123 var block = start_block;
......@@ -2136,7 +2165,7 @@ fn zirDbgStmt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
21362165 _ = try block.addDbgStmt(.unneeded, inst_data.line, inst_data.column);
21372166}
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 {
21402169 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
21412170 const src = inst_data.src();
21422171 const decl_name = inst_data.get(sema.code);
......@@ -2144,7 +2173,7 @@ fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
21442173 return sema.analyzeDeclRef(block, src, decl);
21452174}
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 {
21482177 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
21492178 const src = inst_data.src();
21502179 const decl_name = inst_data.get(sema.code);
......@@ -2198,7 +2227,7 @@ fn zirCall(
21982227 inst: Zir.Inst.Index,
21992228 modifier: std.builtin.CallOptions.Modifier,
22002229 ensure_result_used: bool,
2201) InnerError!Air.Inst.Index {
2230) InnerError!Air.Inst.Ref {
22022231 const tracy = trace(@src());
22032232 defer tracy.end();
22042233
......@@ -2208,12 +2237,12 @@ fn zirCall(
22082237 const extra = sema.code.extraData(Zir.Inst.Call, inst_data.payload_index);
22092238 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);
22122241 // 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);
22142243 for (args) |zir_arg, i| {
22152244 // 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);
22172246 }
22182247
22192248 return sema.analyzeCall(block, func, func_src, call_src, modifier, ensure_result_used, resolved_args);
......@@ -2222,13 +2251,13 @@ fn zirCall(
22222251fn analyzeCall(
22232252 sema: *Sema,
22242253 block: *Scope.Block,
2225 func: Air.Inst.Index,
2254 func: Air.Inst.Ref,
22262255 func_src: LazySrcLoc,
22272256 call_src: LazySrcLoc,
22282257 modifier: std.builtin.CallOptions.Modifier,
22292258 ensure_result_used: bool,
2230 args: []const Air.Inst.Index,
2231) InnerError!Air.Inst.Index {
2259 args: []const Air.Inst.Ref,
2260) InnerError!Air.Inst.Ref {
22322261 if (func.ty.zigTypeTag() != .Fn)
22332262 return sema.mod.fail(&block.base, func_src, "type '{}' not a function", .{func.ty});
22342263
......@@ -2285,7 +2314,7 @@ fn analyzeCall(
22852314 const is_comptime_call = block.is_comptime or modifier == .compile_time;
22862315 const is_inline_call = is_comptime_call or modifier == .always_inline or
22872316 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: {
22892318 const func_val = try sema.resolveConstValue(block, func_src, func);
22902319 const module_fn = switch (func_val.tag()) {
22912320 .function => func_val.castTag(.function).?.data,
......@@ -2383,7 +2412,7 @@ fn analyzeCall(
23832412 return result;
23842413}
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 {
23872416 _ = block;
23882417 const tracy = trace(@src());
23892418 defer tracy.end();
......@@ -2395,7 +2424,7 @@ fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
23952424 return sema.mod.constType(sema.arena, src, ty);
23962425}
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 {
23992428 const tracy = trace(@src());
24002429 defer tracy.end();
24012430
......@@ -2407,7 +2436,7 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner
24072436 return sema.mod.constType(sema.arena, src, opt_type);
24082437}
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 {
24112440 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
24122441 const src = inst_data.src();
24132442 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
24152444 return sema.mod.constType(sema.arena, src, elem_type);
24162445}
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 {
24192448 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
24202449 const src = inst_data.src();
24212450 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
24302459 return sema.mod.constType(sema.arena, src, vector_type);
24312460}
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 {
24342463 const tracy = trace(@src());
24352464 defer tracy.end();
24362465
......@@ -2443,7 +2472,7 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
24432472 return sema.mod.constType(sema.arena, .unneeded, array_ty);
24442473}
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 {
24472476 const tracy = trace(@src());
24482477 defer tracy.end();
24492478
......@@ -2458,7 +2487,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)
24582487 return sema.mod.constType(sema.arena, .unneeded, array_ty);
24592488}
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 {
24622491 const tracy = trace(@src());
24632492 defer tracy.end();
24642493
......@@ -2471,7 +2500,7 @@ fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner
24712500 return sema.mod.constType(sema.arena, src, anyframe_type);
24722501}
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 {
24752504 const tracy = trace(@src());
24762505 defer tracy.end();
24772506
......@@ -2492,7 +2521,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn
24922521 return sema.mod.constType(sema.arena, src, err_union_ty);
24932522}
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 {
24962525 _ = block;
24972526 const tracy = trace(@src());
24982527 defer tracy.end();
......@@ -2511,14 +2540,14 @@ fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
25112540 });
25122541}
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 {
25152544 const tracy = trace(@src());
25162545 defer tracy.end();
25172546
25182547 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
25192548 const src = inst_data.src();
25202549 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);
25222551 const op_coerced = try sema.coerce(block, Type.initTag(.anyerror), op, operand_src);
25232552 const result_ty = Type.initTag(.u16);
25242553
......@@ -2541,7 +2570,7 @@ fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
25412570 return block.addUnOp(src, result_ty, .bitcast, op_coerced);
25422571}
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 {
25452574 const tracy = trace(@src());
25462575 defer tracy.end();
25472576
......@@ -2549,7 +2578,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
25492578 const src = inst_data.src();
25502579 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
25542583 if (try sema.resolveDefinedValue(block, operand_src, op)) |value| {
25552584 const int = value.toUnsignedInt();
......@@ -2574,7 +2603,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
25742603 return block.addUnOp(src, Type.initTag(.anyerror), .bitcast, op);
25752604}
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 {
25782607 const tracy = trace(@src());
25792608 defer tracy.end();
25802609
......@@ -2583,8 +2612,8 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn
25832612 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
25842613 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
25852614 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
2586 const lhs = try sema.resolveInst(extra.lhs);
2587 const rhs = try sema.resolveInst(extra.rhs);
2615 const lhs = sema.resolveInst(extra.lhs);
2616 const rhs = sema.resolveInst(extra.rhs);
25882617 if (rhs.ty.zigTypeTag() == .Bool and lhs.ty.zigTypeTag() == .Bool) {
25892618 const msg = msg: {
25902619 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
26642693 });
26652694}
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 {
26682697 _ = block;
26692698 const tracy = trace(@src());
26702699 defer tracy.end();
......@@ -2678,15 +2707,15 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE
26782707 });
26792708}
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 {
26822711 const mod = sema.mod;
26832712 const arena = sema.arena;
26842713 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
26852714 const src = inst_data.src();
26862715 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()) {
26902719 .Enum => operand,
26912720 .Union => {
26922721 //if (!operand.ty.unionHasTag()) {
......@@ -2760,7 +2789,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
27602789 return block.addUnOp(src, int_tag_ty, .bitcast, enum_tag);
27612790}
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 {
27642793 const mod = sema.mod;
27652794 const target = mod.getTarget();
27662795 const arena = sema.arena;
......@@ -2770,7 +2799,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
27702799 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
27712800 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
27722801 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
27752804 if (dest_ty.zigTypeTag() != .Enum) {
27762805 return mod.fail(&block.base, dest_ty_src, "expected enum, found {}", .{dest_ty});
......@@ -2821,12 +2850,12 @@ fn zirOptionalPayloadPtr(
28212850 block: *Scope.Block,
28222851 inst: Zir.Inst.Index,
28232852 safety_check: bool,
2824) InnerError!Air.Inst.Index {
2853) InnerError!Air.Inst.Ref {
28252854 const tracy = trace(@src());
28262855 defer tracy.end();
28272856
28282857 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);
28302859 assert(optional_ptr.ty.zigTypeTag() == .Pointer);
28312860 const src = inst_data.src();
28322861
......@@ -2836,7 +2865,7 @@ fn zirOptionalPayloadPtr(
28362865 }
28372866
28382867 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
28412870 if (optional_ptr.value()) |pointer_val| {
28422871 const val = try pointer_val.pointerDeref(sema.arena);
......@@ -2864,13 +2893,13 @@ fn zirOptionalPayload(
28642893 block: *Scope.Block,
28652894 inst: Zir.Inst.Index,
28662895 safety_check: bool,
2867) InnerError!Air.Inst.Index {
2896) InnerError!Air.Inst.Ref {
28682897 const tracy = trace(@src());
28692898 defer tracy.end();
28702899
28712900 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
28722901 const src = inst_data.src();
2873 const operand = try sema.resolveInst(inst_data.operand);
2902 const operand = sema.resolveInst(inst_data.operand);
28742903 const opt_type = operand.ty;
28752904 if (opt_type.zigTypeTag() != .Optional) {
28762905 return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type});
......@@ -2902,13 +2931,13 @@ fn zirErrUnionPayload(
29022931 block: *Scope.Block,
29032932 inst: Zir.Inst.Index,
29042933 safety_check: bool,
2905) InnerError!Air.Inst.Index {
2934) InnerError!Air.Inst.Ref {
29062935 const tracy = trace(@src());
29072936 defer tracy.end();
29082937
29092938 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
29102939 const src = inst_data.src();
2911 const operand = try sema.resolveInst(inst_data.operand);
2940 const operand = sema.resolveInst(inst_data.operand);
29122941 if (operand.ty.zigTypeTag() != .ErrorUnion)
29132942 return sema.mod.fail(&block.base, operand.src, "expected error union type, found '{}'", .{operand.ty});
29142943
......@@ -2936,19 +2965,19 @@ fn zirErrUnionPayloadPtr(
29362965 block: *Scope.Block,
29372966 inst: Zir.Inst.Index,
29382967 safety_check: bool,
2939) InnerError!Air.Inst.Index {
2968) InnerError!Air.Inst.Ref {
29402969 const tracy = trace(@src());
29412970 defer tracy.end();
29422971
29432972 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
29442973 const src = inst_data.src();
2945 const operand = try sema.resolveInst(inst_data.operand);
2974 const operand = sema.resolveInst(inst_data.operand);
29462975 assert(operand.ty.zigTypeTag() == .Pointer);
29472976
29482977 if (operand.ty.elemType().zigTypeTag() != .ErrorUnion)
29492978 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
29532982 if (operand.value()) |pointer_val| {
29542983 const val = try pointer_val.pointerDeref(sema.arena);
......@@ -2975,13 +3004,13 @@ fn zirErrUnionPayloadPtr(
29753004}
29763005
29773006/// 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 {
29793008 const tracy = trace(@src());
29803009 defer tracy.end();
29813010
29823011 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
29833012 const src = inst_data.src();
2984 const operand = try sema.resolveInst(inst_data.operand);
3013 const operand = sema.resolveInst(inst_data.operand);
29853014 if (operand.ty.zigTypeTag() != .ErrorUnion)
29863015 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
30013030}
30023031
30033032/// 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 {
30053034 const tracy = trace(@src());
30063035 defer tracy.end();
30073036
30083037 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
30093038 const src = inst_data.src();
3010 const operand = try sema.resolveInst(inst_data.operand);
3039 const operand = sema.resolveInst(inst_data.operand);
30113040 assert(operand.ty.zigTypeTag() == .Pointer);
30123041
30133042 if (operand.ty.elemType().zigTypeTag() != .ErrorUnion)
......@@ -3035,7 +3064,7 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
30353064
30363065 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
30373066 const src = inst_data.src();
3038 const operand = try sema.resolveInst(inst_data.operand);
3067 const operand = sema.resolveInst(inst_data.operand);
30393068 if (operand.ty.zigTypeTag() != .ErrorUnion)
30403069 return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand.ty});
30413070 if (operand.ty.castTag(.error_union).?.data.payload.zigTypeTag() != .Void) {
......@@ -3048,7 +3077,7 @@ fn zirFunc(
30483077 block: *Scope.Block,
30493078 inst: Zir.Inst.Index,
30503079 inferred_error_set: bool,
3051) InnerError!Air.Inst.Index {
3080) InnerError!Air.Inst.Ref {
30523081 const tracy = trace(@src());
30533082 defer tracy.end();
30543083
......@@ -3099,7 +3128,7 @@ fn funcCommon(
30993128 is_extern: bool,
31003129 src_locs: Zir.Inst.Func.SrcLocs,
31013130 opt_lib_name: ?[]const u8,
3102) InnerError!Air.Inst.Index {
3131) InnerError!Air.Inst.Ref {
31033132 const src: LazySrcLoc = .{ .node_offset = src_node_offset };
31043133 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset };
31053134 const bare_return_type = try sema.resolveType(block, ret_ty_src, zir_return_type);
......@@ -3240,7 +3269,7 @@ fn funcCommon(
32403269 return result;
32413270}
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 {
32443273 const tracy = trace(@src());
32453274 defer tracy.end();
32463275
......@@ -3248,7 +3277,7 @@ fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.
32483277 return sema.analyzeAs(block, .unneeded, bin_inst.lhs, bin_inst.rhs);
32493278}
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 {
32523281 const tracy = trace(@src());
32533282 defer tracy.end();
32543283
......@@ -3264,18 +3293,18 @@ fn analyzeAs(
32643293 src: LazySrcLoc,
32653294 zir_dest_type: Zir.Inst.Ref,
32663295 zir_operand: Zir.Inst.Ref,
3267) InnerError!Air.Inst.Index {
3296) InnerError!Air.Inst.Ref {
32683297 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);
32703299 return sema.coerce(block, dest_type, operand, src);
32713300}
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 {
32743303 const tracy = trace(@src());
32753304 defer tracy.end();
32763305
32773306 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);
32793308 if (ptr.ty.zigTypeTag() != .Pointer) {
32803309 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
32813310 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
32873316 return block.addUnOp(src, ty, .ptrtoint, ptr);
32883317}
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 {
32913320 const tracy = trace(@src());
32923321 defer tracy.end();
32933322
......@@ -3296,7 +3325,7 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
32963325 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
32973326 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
32983327 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);
33003329 const object_ptr = if (object.ty.zigTypeTag() == .Pointer)
33013330 object
33023331 else
......@@ -3305,7 +3334,7 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
33053334 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);
33063335}
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 {
33093338 const tracy = trace(@src());
33103339 defer tracy.end();
33113340
......@@ -3314,11 +3343,11 @@ fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
33143343 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
33153344 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
33163345 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);
33183347 return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);
33193348}
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 {
33223351 const tracy = trace(@src());
33233352 defer tracy.end();
33243353
......@@ -3326,14 +3355,14 @@ fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
33263355 const src = inst_data.src();
33273356 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
33283357 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);
33303359 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);
33313360 const object_ptr = try sema.analyzeRef(block, src, object);
33323361 const result_ptr = try sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);
33333362 return sema.analyzeLoad(block, src, result_ptr, src);
33343363}
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 {
33373366 const tracy = trace(@src());
33383367 defer tracy.end();
33393368
......@@ -3341,12 +3370,12 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
33413370 const src = inst_data.src();
33423371 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
33433372 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);
33453374 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);
33463375 return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);
33473376}
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 {
33503379 const tracy = trace(@src());
33513380 defer tracy.end();
33523381
......@@ -3357,7 +3386,7 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
33573386 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
33583387
33593388 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
33623391 const dest_is_comptime_int = switch (dest_type.zigTypeTag()) {
33633392 .ComptimeInt => true,
......@@ -3389,20 +3418,21 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
33893418 return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten int", .{});
33903419}
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 {
33933422 const tracy = trace(@src());
33943423 defer tracy.end();
33953424
33963425 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
33973426 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 };
33983428 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
33993429
34003430 const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs);
3401 const operand = try sema.resolveInst(extra.rhs);
3402 return sema.bitcast(block, dest_type, operand);
3431 const operand = sema.resolveInst(extra.rhs);
3432 return sema.bitcast(block, dest_type, operand, operand_src);
34033433}
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 {
34063436 const tracy = trace(@src());
34073437 defer tracy.end();
34083438
......@@ -3413,7 +3443,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
34133443 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
34143444
34153445 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
34183448 const dest_is_comptime_float = switch (dest_type.zigTypeTag()) {
34193449 .ComptimeFloat => true,
......@@ -3445,22 +3475,22 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
34453475 return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten float", .{});
34463476}
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 {
34493479 const tracy = trace(@src());
34503480 defer tracy.end();
34513481
34523482 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);
34543484 const array_ptr = if (array.ty.zigTypeTag() == .Pointer)
34553485 array
34563486 else
34573487 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);
34593489 const result_ptr = try sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);
34603490 return sema.analyzeLoad(block, sema.src, result_ptr, sema.src);
34613491}
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 {
34643494 const tracy = trace(@src());
34653495 defer tracy.end();
34663496
......@@ -3468,27 +3498,27 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE
34683498 const src = inst_data.src();
34693499 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
34703500 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);
34723502 const array_ptr = if (array.ty.zigTypeTag() == .Pointer)
34733503 array
34743504 else
34753505 try sema.analyzeRef(block, src, array);
3476 const elem_index = try sema.resolveInst(extra.rhs);
3506 const elem_index = sema.resolveInst(extra.rhs);
34773507 const result_ptr = try sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);
34783508 return sema.analyzeLoad(block, src, result_ptr, src);
34793509}
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 {
34823512 const tracy = trace(@src());
34833513 defer tracy.end();
34843514
34853515 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
3486 const array_ptr = try sema.resolveInst(bin_inst.lhs);
3487 const elem_index = try sema.resolveInst(bin_inst.rhs);
3516 const array_ptr = sema.resolveInst(bin_inst.lhs);
3517 const elem_index = sema.resolveInst(bin_inst.rhs);
34883518 return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);
34893519}
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 {
34923522 const tracy = trace(@src());
34933523 defer tracy.end();
34943524
......@@ -3496,39 +3526,39 @@ fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE
34963526 const src = inst_data.src();
34973527 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
34983528 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
3499 const array_ptr = try sema.resolveInst(extra.lhs);
3500 const elem_index = try sema.resolveInst(extra.rhs);
3529 const array_ptr = sema.resolveInst(extra.lhs);
3530 const elem_index = sema.resolveInst(extra.rhs);
35013531 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);
35023532}
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 {
35053535 const tracy = trace(@src());
35063536 defer tracy.end();
35073537
35083538 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
35093539 const src = inst_data.src();
35103540 const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;
3511 const array_ptr = try sema.resolveInst(extra.lhs);
3512 const start = try sema.resolveInst(extra.start);
3541 const array_ptr = sema.resolveInst(extra.lhs);
3542 const start = sema.resolveInst(extra.start);
35133543
35143544 return sema.analyzeSlice(block, src, array_ptr, start, null, null, .unneeded);
35153545}
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 {
35183548 const tracy = trace(@src());
35193549 defer tracy.end();
35203550
35213551 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
35223552 const src = inst_data.src();
35233553 const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;
3524 const array_ptr = try sema.resolveInst(extra.lhs);
3525 const start = try sema.resolveInst(extra.start);
3526 const end = try sema.resolveInst(extra.end);
3554 const array_ptr = sema.resolveInst(extra.lhs);
3555 const start = sema.resolveInst(extra.start);
3556 const end = sema.resolveInst(extra.end);
35273557
35283558 return sema.analyzeSlice(block, src, array_ptr, start, end, null, .unneeded);
35293559}
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 {
35323562 const tracy = trace(@src());
35333563 defer tracy.end();
35343564
......@@ -3536,10 +3566,10 @@ fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
35363566 const src = inst_data.src();
35373567 const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node };
35383568 const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;
3539 const array_ptr = try sema.resolveInst(extra.lhs);
3540 const start = try sema.resolveInst(extra.start);
3541 const end = try sema.resolveInst(extra.end);
3542 const sentinel = try sema.resolveInst(extra.sentinel);
3569 const array_ptr = sema.resolveInst(extra.lhs);
3570 const start = sema.resolveInst(extra.start);
3571 const end = sema.resolveInst(extra.end);
3572 const sentinel = sema.resolveInst(extra.sentinel);
35433573
35443574 return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src);
35453575}
......@@ -3550,7 +3580,7 @@ fn zirSwitchCapture(
35503580 inst: Zir.Inst.Index,
35513581 is_multi: bool,
35523582 is_ref: bool,
3553) InnerError!Air.Inst.Index {
3583) InnerError!Air.Inst.Ref {
35543584 const tracy = trace(@src());
35553585 defer tracy.end();
35563586
......@@ -3569,7 +3599,7 @@ fn zirSwitchCaptureElse(
35693599 block: *Scope.Block,
35703600 inst: Zir.Inst.Index,
35713601 is_ref: bool,
3572) InnerError!Air.Inst.Index {
3602) InnerError!Air.Inst.Ref {
35733603 const tracy = trace(@src());
35743604 defer tracy.end();
35753605
......@@ -3588,7 +3618,7 @@ fn zirSwitchBlock(
35883618 inst: Zir.Inst.Index,
35893619 is_ref: bool,
35903620 special_prong: Zir.SpecialProng,
3591) InnerError!Air.Inst.Index {
3621) InnerError!Air.Inst.Ref {
35923622 const tracy = trace(@src());
35933623 defer tracy.end();
35943624
......@@ -3597,7 +3627,7 @@ fn zirSwitchBlock(
35973627 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = inst_data.src_node };
35983628 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);
36013631 const operand = if (is_ref)
36023632 try sema.analyzeLoad(block, src, operand_ptr, operand_src)
36033633 else
......@@ -3621,7 +3651,7 @@ fn zirSwitchBlockMulti(
36213651 inst: Zir.Inst.Index,
36223652 is_ref: bool,
36233653 special_prong: Zir.SpecialProng,
3624) InnerError!Air.Inst.Index {
3654) InnerError!Air.Inst.Ref {
36253655 const tracy = trace(@src());
36263656 defer tracy.end();
36273657
......@@ -3630,7 +3660,7 @@ fn zirSwitchBlockMulti(
36303660 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = inst_data.src_node };
36313661 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);
36343664 const operand = if (is_ref)
36353665 try sema.analyzeLoad(block, src, operand_ptr, operand_src)
36363666 else
......@@ -3651,14 +3681,14 @@ fn zirSwitchBlockMulti(
36513681fn analyzeSwitch(
36523682 sema: *Sema,
36533683 block: *Scope.Block,
3654 operand: Air.Inst.Index,
3684 operand: Air.Inst.Ref,
36553685 extra_end: usize,
36563686 special_prong: Zir.SpecialProng,
36573687 scalar_cases_len: usize,
36583688 multi_cases_len: usize,
36593689 switch_inst: Zir.Inst.Index,
36603690 src_node_offset: i32,
3661) InnerError!Air.Inst.Index {
3691) InnerError!Air.Inst.Ref {
36623692 const gpa = sema.gpa;
36633693 const mod = sema.mod;
36643694
......@@ -4217,7 +4247,7 @@ fn analyzeSwitch(
42174247 const bool_ty = comptime Type.initTag(.bool);
42184248
42194249 for (items) |item_ref| {
4220 const item = try sema.resolveInst(item_ref);
4250 const item = sema.resolveInst(item_ref);
42214251 _ = try sema.resolveConstValue(&child_block, item.src, item);
42224252
42234253 const cmp_ok = try case_block.addBinOp(item.src, bool_ty, .cmp_eq, operand, item);
......@@ -4235,8 +4265,8 @@ fn analyzeSwitch(
42354265 const last_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
42364266 extra_index += 1;
42374267
4238 const item_first = try sema.resolveInst(first_ref);
4239 const item_last = try sema.resolveInst(last_ref);
4268 const item_first = sema.resolveInst(first_ref);
4269 const item_last = sema.resolveInst(last_ref);
42404270
42414271 _ = try sema.resolveConstValue(&child_block, item_first.src, item_first);
42424272 _ = try sema.resolveConstValue(&child_block, item_last.src, item_last);
......@@ -4334,7 +4364,7 @@ fn resolveSwitchItemVal(
43344364 switch_prong_src: Module.SwitchProngSrc,
43354365 range_expand: Module.SwitchProngSrc.RangeExpand,
43364366) InnerError!TypedValue {
4337 const item = try sema.resolveInst(item_ref);
4367 const item = sema.resolveInst(item_ref);
43384368 // We have to avoid the other helper functions here because we cannot construct a LazySrcLoc
43394369 // because we only have the switch AST node. Only if we know for sure we need to report
43404370 // a compile error do we resolve the full source locations.
......@@ -4513,7 +4543,7 @@ fn validateSwitchNoRange(
45134543 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);
45144544}
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 {
45174547 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
45184548 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
45194549 _ = extra;
......@@ -4522,7 +4552,7 @@ fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
45224552 return sema.mod.fail(&block.base, src, "TODO implement zirHasField", .{});
45234553}
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 {
45264556 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
45274557 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
45284558 const src = inst_data.src();
......@@ -4547,7 +4577,7 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
45474577 return mod.constBool(arena, src, false);
45484578}
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 {
45514581 const tracy = trace(@src());
45524582 defer tracy.end();
45534583
......@@ -4572,13 +4602,13 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
45724602 return mod.constType(sema.arena, src, file_root_decl.ty);
45734603}
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 {
45764606 _ = block;
45774607 _ = inst;
45784608 return sema.mod.fail(&block.base, sema.src, "TODO implement zirRetErrValueCode", .{});
45794609}
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 {
45824612 const tracy = trace(@src());
45834613 defer tracy.end();
45844614
......@@ -4587,7 +4617,7 @@ fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air
45874617 return sema.mod.fail(&block.base, sema.src, "TODO implement zirShl", .{});
45884618}
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 {
45914621 const tracy = trace(@src());
45924622 defer tracy.end();
45934623
......@@ -4599,8 +4629,8 @@ fn zirBitwise(
45994629 sema: *Sema,
46004630 block: *Scope.Block,
46014631 inst: Zir.Inst.Index,
4602 ir_tag: ir.Inst.Tag,
4603) InnerError!Air.Inst.Index {
4632 air_tag: Air.Inst.Tag,
4633) InnerError!Air.Inst.Ref {
46044634 const tracy = trace(@src());
46054635 defer tracy.end();
46064636
......@@ -4609,8 +4639,8 @@ fn zirBitwise(
46094639 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
46104640 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
46114641 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
4612 const lhs = try sema.resolveInst(extra.lhs);
4613 const rhs = try sema.resolveInst(extra.rhs);
4642 const lhs = sema.resolveInst(extra.lhs);
4643 const rhs = sema.resolveInst(extra.rhs);
46144644
46154645 const instructions = &[_]Air.Inst.Index{ lhs, rhs };
46164646 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);
......@@ -4655,10 +4685,10 @@ fn zirBitwise(
46554685 }
46564686
46574687 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);
46594689}
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 {
46624692 const tracy = trace(@src());
46634693 defer tracy.end();
46644694
......@@ -4666,7 +4696,7 @@ fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
46664696 return sema.mod.fail(&block.base, sema.src, "TODO implement zirBitNot", .{});
46674697}
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 {
46704700 const tracy = trace(@src());
46714701 defer tracy.end();
46724702
......@@ -4674,7 +4704,7 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
46744704 return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayCat", .{});
46754705}
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 {
46784708 const tracy = trace(@src());
46794709 defer tracy.end();
46804710
......@@ -4687,7 +4717,7 @@ fn zirNegate(
46874717 block: *Scope.Block,
46884718 inst: Zir.Inst.Index,
46894719 tag_override: Zir.Inst.Tag,
4690) InnerError!Air.Inst.Index {
4720) InnerError!Air.Inst.Ref {
46914721 const tracy = trace(@src());
46924722 defer tracy.end();
46934723
......@@ -4695,13 +4725,13 @@ fn zirNegate(
46954725 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
46964726 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
46974727 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
4698 const lhs = try sema.resolveInst(.zero);
4699 const rhs = try sema.resolveInst(inst_data.operand);
4728 const lhs = sema.resolveInst(.zero);
4729 const rhs = sema.resolveInst(inst_data.operand);
47004730
47014731 return sema.analyzeArithmetic(block, tag_override, lhs, rhs, src, lhs_src, rhs_src);
47024732}
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 {
47054735 const tracy = trace(@src());
47064736 defer tracy.end();
47074737
......@@ -4711,8 +4741,8 @@ fn zirArithmetic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
47114741 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
47124742 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
47134743 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
4714 const lhs = try sema.resolveInst(extra.lhs);
4715 const rhs = try sema.resolveInst(extra.rhs);
4744 const lhs = sema.resolveInst(extra.lhs);
4745 const rhs = sema.resolveInst(extra.rhs);
47164746
47174747 return sema.analyzeArithmetic(block, tag_override, lhs, rhs, sema.src, lhs_src, rhs_src);
47184748}
......@@ -4721,7 +4751,7 @@ fn zirOverflowArithmetic(
47214751 sema: *Sema,
47224752 block: *Scope.Block,
47234753 extended: Zir.Inst.Extended.InstData,
4724) InnerError!Air.Inst.Index {
4754) InnerError!Air.Inst.Ref {
47254755 const tracy = trace(@src());
47264756 defer tracy.end();
47274757
......@@ -4735,12 +4765,12 @@ fn analyzeArithmetic(
47354765 sema: *Sema,
47364766 block: *Scope.Block,
47374767 zir_tag: Zir.Inst.Tag,
4738 lhs: Air.Inst.Index,
4739 rhs: Air.Inst.Index,
4768 lhs: Air.Inst.Ref,
4769 rhs: Air.Inst.Ref,
47404770 src: LazySrcLoc,
47414771 lhs_src: LazySrcLoc,
47424772 rhs_src: LazySrcLoc,
4743) InnerError!Air.Inst.Index {
4773) InnerError!Air.Inst.Ref {
47444774 const instructions = &[_]Air.Inst.Index{ lhs, rhs };
47454775 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);
47464776 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
......@@ -4850,14 +4880,14 @@ fn analyzeArithmetic(
48504880 return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs);
48514881}
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 {
48544884 const tracy = trace(@src());
48554885 defer tracy.end();
48564886
48574887 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
48584888 const src = inst_data.src();
48594889 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);
48614891 return sema.analyzeLoad(block, src, ptr, ptr_src);
48624892}
48634893
......@@ -4865,7 +4895,7 @@ fn zirAsm(
48654895 sema: *Sema,
48664896 block: *Scope.Block,
48674897 extended: Zir.Inst.Extended.InstData,
4868) InnerError!Air.Inst.Index {
4898) InnerError!Air.Inst.Ref {
48694899 const tracy = trace(@src());
48704900 defer tracy.end();
48714901
......@@ -4915,7 +4945,7 @@ fn zirAsm(
49154945 const name = sema.code.nullTerminatedString(input.data.name);
49164946 _ = name; // TODO: use the name
49174947
4918 arg.* = try sema.resolveInst(input.data.operand);
4948 arg.* = sema.resolveInst(input.data.operand);
49194949 inputs[arg_i] = sema.code.nullTerminatedString(input.data.constraint);
49204950 }
49214951
......@@ -4949,7 +4979,7 @@ fn zirCmp(
49494979 block: *Scope.Block,
49504980 inst: Zir.Inst.Index,
49514981 op: std.math.CompareOperator,
4952) InnerError!Air.Inst.Index {
4982) InnerError!Air.Inst.Ref {
49534983 const tracy = trace(@src());
49544984 defer tracy.end();
49554985
......@@ -4960,8 +4990,8 @@ fn zirCmp(
49604990 const src: LazySrcLoc = inst_data.src();
49614991 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
49624992 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
4963 const lhs = try sema.resolveInst(extra.lhs);
4964 const rhs = try sema.resolveInst(extra.rhs);
4993 const lhs = sema.resolveInst(extra.lhs);
4994 const rhs = sema.resolveInst(extra.rhs);
49654995
49664996 const is_equality_cmp = switch (op) {
49674997 .eq, .neq => true,
......@@ -5047,7 +5077,7 @@ fn zirCmp(
50475077 return block.addBinOp(src, bool_type, tag, casted_lhs, casted_rhs);
50485078}
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 {
50515081 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
50525082 const src = inst_data.src();
50535083 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!
50575087 return sema.mod.constIntUnsigned(sema.arena, src, Type.initTag(.comptime_int), abi_size);
50585088}
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 {
50615091 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
50625092 const src = inst_data.src();
50635093 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -5071,7 +5101,7 @@ fn zirThis(
50715101 sema: *Sema,
50725102 block: *Scope.Block,
50735103 extended: Zir.Inst.Extended.InstData,
5074) InnerError!Air.Inst.Index {
5104) InnerError!Air.Inst.Ref {
50755105 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
50765106 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirThis", .{});
50775107}
......@@ -5080,7 +5110,7 @@ fn zirRetAddr(
50805110 sema: *Sema,
50815111 block: *Scope.Block,
50825112 extended: Zir.Inst.Extended.InstData,
5083) InnerError!Air.Inst.Index {
5113) InnerError!Air.Inst.Ref {
50845114 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
50855115 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirRetAddr", .{});
50865116}
......@@ -5089,12 +5119,12 @@ fn zirBuiltinSrc(
50895119 sema: *Sema,
50905120 block: *Scope.Block,
50915121 extended: Zir.Inst.Extended.InstData,
5092) InnerError!Air.Inst.Index {
5122) InnerError!Air.Inst.Ref {
50935123 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
50945124 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinSrc", .{});
50955125}
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 {
50985128 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
50995129 const src = inst_data.src();
51005130 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
51375167 }
51385168}
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 {
51415171 _ = block;
51425172 const zir_datas = sema.code.instructions.items(.data);
51435173 const inst_data = zir_datas[inst].un_node;
51445174 const src = inst_data.src();
5145 const operand = try sema.resolveInst(inst_data.operand);
5175 const operand = sema.resolveInst(inst_data.operand);
51465176 return sema.mod.constType(sema.arena, src, operand.ty);
51475177}
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 {
51505180 _ = block;
51515181 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
51525182 const src = inst_data.src();
5153 const operand_ptr = try sema.resolveInst(inst_data.operand);
5183 const operand_ptr = sema.resolveInst(inst_data.operand);
51545184 const elem_ty = operand_ptr.ty.elemType();
51555185 return sema.mod.constType(sema.arena, src, elem_ty);
51565186}
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 {
51595189 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
51605190 const src = inst_data.src();
51615191 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirTypeofLog2IntType", .{});
51625192}
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 {
51655195 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
51665196 const src = inst_data.src();
51675197 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirLog2IntType", .{});
......@@ -5171,7 +5201,7 @@ fn zirTypeofPeer(
51715201 sema: *Sema,
51725202 block: *Scope.Block,
51735203 extended: Zir.Inst.Extended.InstData,
5174) InnerError!Air.Inst.Index {
5204) InnerError!Air.Inst.Ref {
51755205 const tracy = trace(@src());
51765206 defer tracy.end();
51775207
......@@ -5183,20 +5213,20 @@ fn zirTypeofPeer(
51835213 defer sema.gpa.free(inst_list);
51845214
51855215 for (args) |arg_ref, i| {
5186 inst_list[i] = try sema.resolveInst(arg_ref);
5216 inst_list[i] = sema.resolveInst(arg_ref);
51875217 }
51885218
51895219 const result_type = try sema.resolvePeerTypes(block, src, inst_list);
51905220 return sema.mod.constType(sema.arena, src, result_type);
51915221}
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 {
51945224 const tracy = trace(@src());
51955225 defer tracy.end();
51965226
51975227 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
51985228 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
52015231 const bool_type = Type.initTag(.bool);
52025232 const operand = try sema.coerce(block, bool_type, uncasted_operand, uncasted_operand.src);
......@@ -5212,16 +5242,16 @@ fn zirBoolOp(
52125242 block: *Scope.Block,
52135243 inst: Zir.Inst.Index,
52145244 comptime is_bool_or: bool,
5215) InnerError!Air.Inst.Index {
5245) InnerError!Air.Inst.Ref {
52165246 const tracy = trace(@src());
52175247 defer tracy.end();
52185248
52195249 const src: LazySrcLoc = .unneeded;
52205250 const bool_type = Type.initTag(.bool);
52215251 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);
52235253 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);
52255255 const rhs = try sema.coerce(block, bool_type, uncasted_rhs, uncasted_rhs.src);
52265256
52275257 if (lhs.value()) |lhs_val| {
......@@ -5234,7 +5264,7 @@ fn zirBoolOp(
52345264 }
52355265 }
52365266 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;
52385268 return block.addBinOp(src, bool_type, tag, lhs, rhs);
52395269}
52405270
......@@ -5243,14 +5273,14 @@ fn zirBoolBr(
52435273 parent_block: *Scope.Block,
52445274 inst: Zir.Inst.Index,
52455275 is_bool_or: bool,
5246) InnerError!Air.Inst.Index {
5276) InnerError!Air.Inst.Ref {
52475277 const tracy = trace(@src());
52485278 defer tracy.end();
52495279
52505280 const datas = sema.code.instructions.items(.data);
52515281 const inst_data = datas[inst].bool_br;
52525282 const src: LazySrcLoc = .unneeded;
5253 const lhs = try sema.resolveInst(inst_data.lhs);
5283 const lhs = sema.resolveInst(inst_data.lhs);
52545284 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
52555285 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
52565286
......@@ -5313,13 +5343,13 @@ fn zirIsNonNull(
53135343 sema: *Sema,
53145344 block: *Scope.Block,
53155345 inst: Zir.Inst.Index,
5316) InnerError!Air.Inst.Index {
5346) InnerError!Air.Inst.Ref {
53175347 const tracy = trace(@src());
53185348 defer tracy.end();
53195349
53205350 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
53215351 const src = inst_data.src();
5322 const operand = try sema.resolveInst(inst_data.operand);
5352 const operand = sema.resolveInst(inst_data.operand);
53235353 return sema.analyzeIsNull(block, src, operand, true);
53245354}
53255355
......@@ -5327,33 +5357,33 @@ fn zirIsNonNullPtr(
53275357 sema: *Sema,
53285358 block: *Scope.Block,
53295359 inst: Zir.Inst.Index,
5330) InnerError!Air.Inst.Index {
5360) InnerError!Air.Inst.Ref {
53315361 const tracy = trace(@src());
53325362 defer tracy.end();
53335363
53345364 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
53355365 const src = inst_data.src();
5336 const ptr = try sema.resolveInst(inst_data.operand);
5366 const ptr = sema.resolveInst(inst_data.operand);
53375367 const loaded = try sema.analyzeLoad(block, src, ptr, src);
53385368 return sema.analyzeIsNull(block, src, loaded, true);
53395369}
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 {
53425372 const tracy = trace(@src());
53435373 defer tracy.end();
53445374
53455375 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);
53475377 return sema.analyzeIsNonErr(block, inst_data.src(), operand);
53485378}
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 {
53515381 const tracy = trace(@src());
53525382 defer tracy.end();
53535383
53545384 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
53555385 const src = inst_data.src();
5356 const ptr = try sema.resolveInst(inst_data.operand);
5386 const ptr = sema.resolveInst(inst_data.operand);
53575387 const loaded = try sema.analyzeLoad(block, src, ptr, src);
53585388 return sema.analyzeIsNonErr(block, src, loaded);
53595389}
......@@ -5374,7 +5404,7 @@ fn zirCondbr(
53745404 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];
53755405 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);
53785408 const cond = try sema.coerce(parent_block, Type.initTag(.bool), uncasted_cond, cond_src);
53795409
53805410 if (try sema.resolveDefinedValue(parent_block, src, cond)) |cond_val| {
......@@ -5456,7 +5486,7 @@ fn zirRetCoerce(
54565486 defer tracy.end();
54575487
54585488 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);
54605490 const src = inst_data.src();
54615491
54625492 return sema.analyzeRet(block, operand, src, need_coercion);
......@@ -5467,7 +5497,7 @@ fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
54675497 defer tracy.end();
54685498
54695499 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);
54715501 const src = inst_data.src();
54725502
54735503 return sema.analyzeRet(block, operand, src, false);
......@@ -5476,7 +5506,7 @@ fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
54765506fn analyzeRet(
54775507 sema: *Sema,
54785508 block: *Scope.Block,
5479 operand: Air.Inst.Index,
5509 operand: Air.Inst.Ref,
54805510 src: LazySrcLoc,
54815511 need_coercion: bool,
54825512) InnerError!Zir.Inst.Index {
......@@ -5511,7 +5541,7 @@ fn floatOpAllowed(tag: Zir.Inst.Tag) bool {
55115541 };
55125542}
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 {
55155545 const tracy = trace(@src());
55165546 defer tracy.end();
55175547
......@@ -5532,7 +5562,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
55325562 return sema.mod.constType(sema.arena, .unneeded, ty);
55335563}
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 {
55365566 const tracy = trace(@src());
55375567 defer tracy.end();
55385568
......@@ -5586,7 +5616,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
55865616 return sema.mod.constType(sema.arena, src, ty);
55875617}
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 {
55905620 const tracy = trace(@src());
55915621 defer tracy.end();
55925622
......@@ -5600,13 +5630,13 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In
56005630 });
56015631}
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 {
56045634 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
56055635 const src = inst_data.src();
56065636 return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnionInitPtr", .{});
56075637}
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 {
56105640 const mod = sema.mod;
56115641 const gpa = sema.gpa;
56125642 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:
56575687 return mod.failWithOwnedErrorMsg(&block.base, msg);
56585688 }
56595689 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);
56615691 }
56625692
56635693 var root_msg: ?*Module.ErrorMsg = null;
......@@ -5719,7 +5749,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
57195749 return mod.fail(&block.base, src, "TODO: Sema.zirStructInit for runtime-known struct values", .{});
57205750}
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 {
57235753 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
57245754 const src = inst_data.src();
57255755
......@@ -5727,7 +5757,7 @@ fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_
57275757 return sema.mod.fail(&block.base, src, "TODO: Sema.zirStructInitAnon", .{});
57285758}
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 {
57315761 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
57325762 const src = inst_data.src();
57335763
......@@ -5735,7 +5765,7 @@ fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
57355765 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInit", .{});
57365766}
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 {
57395769 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
57405770 const src = inst_data.src();
57415771
......@@ -5743,13 +5773,13 @@ fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_r
57435773 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInitAnon", .{});
57445774}
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 {
57475777 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
57485778 const src = inst_data.src();
57495779 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldTypeRef", .{});
57505780}
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 {
57535783 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
57545784 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
57555785 const src = inst_data.src();
......@@ -5771,7 +5801,7 @@ fn zirErrorReturnTrace(
57715801 sema: *Sema,
57725802 block: *Scope.Block,
57735803 extended: Zir.Inst.Extended.InstData,
5774) InnerError!Air.Inst.Index {
5804) InnerError!Air.Inst.Ref {
57755805 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
57765806 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorReturnTrace", .{});
57775807}
......@@ -5780,7 +5810,7 @@ fn zirFrame(
57805810 sema: *Sema,
57815811 block: *Scope.Block,
57825812 extended: Zir.Inst.Extended.InstData,
5783) InnerError!Air.Inst.Index {
5813) InnerError!Air.Inst.Ref {
57845814 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
57855815 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrame", .{});
57865816}
......@@ -5789,91 +5819,91 @@ fn zirFrameAddress(
57895819 sema: *Sema,
57905820 block: *Scope.Block,
57915821 extended: Zir.Inst.Extended.InstData,
5792) InnerError!Air.Inst.Index {
5822) InnerError!Air.Inst.Ref {
57935823 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
57945824 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameAddress", .{});
57955825}
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 {
57985828 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
57995829 const src = inst_data.src();
58005830 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignOf", .{});
58015831}
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 {
58045834 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58055835 const src = inst_data.src();
58065836 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBoolToInt", .{});
58075837}
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 {
58105840 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58115841 const src = inst_data.src();
58125842 return sema.mod.fail(&block.base, src, "TODO: Sema.zirEmbedFile", .{});
58135843}
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 {
58165846 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58175847 const src = inst_data.src();
58185848 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorName", .{});
58195849}
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 {
58225852 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58235853 const src = inst_data.src();
58245854 return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnaryMath", .{});
58255855}
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 {
58285858 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58295859 const src = inst_data.src();
58305860 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTagName", .{});
58315861}
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 {
58345864 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58355865 const src = inst_data.src();
58365866 return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify", .{});
58375867}
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 {
58405870 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58415871 const src = inst_data.src();
58425872 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTypeName", .{});
58435873}
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 {
58465876 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58475877 const src = inst_data.src();
58485878 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameType", .{});
58495879}
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 {
58525882 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58535883 const src = inst_data.src();
58545884 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameSize", .{});
58555885}
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 {
58585888 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
58595889 const src = inst_data.src();
58605890 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFloatToInt", .{});
58615891}
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 {
58645894 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
58655895 const src = inst_data.src();
58665896 return sema.mod.fail(&block.base, src, "TODO: Sema.zirIntToFloat", .{});
58675897}
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 {
58705900 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
58715901 const src = inst_data.src();
58725902
58735903 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
58745904
58755905 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);
58775907 const operand_coerced = try sema.coerce(block, Type.initTag(.usize), operand_res, operand_src);
58785908
58795909 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
59295959 return block.addUnOp(src, type_res, .bitcast, operand_coerced);
59305960}
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 {
59335963 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
59345964 const src = inst_data.src();
59355965 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrSetCast", .{});
59365966}
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 {
59395969 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
59405970 const src = inst_data.src();
59415971 return sema.mod.fail(&block.base, src, "TODO: Sema.zirPtrCast", .{});
59425972}
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 {
59455975 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
59465976 const src = inst_data.src();
59475977 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTruncate", .{});
59485978}
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 {
59515981 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
59525982 const src = inst_data.src();
59535983 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignCast", .{});
59545984}
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 {
59575987 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
59585988 const src = inst_data.src();
59595989 return sema.mod.fail(&block.base, src, "TODO: Sema.zirClz", .{});
59605990}
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 {
59635993 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
59645994 const src = inst_data.src();
59655995 return sema.mod.fail(&block.base, src, "TODO: Sema.zirCtz", .{});
59665996}
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 {
59695999 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
59706000 const src = inst_data.src();
59716001 return sema.mod.fail(&block.base, src, "TODO: Sema.zirPopCount", .{});
59726002}
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 {
59756005 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
59766006 const src = inst_data.src();
59776007 return sema.mod.fail(&block.base, src, "TODO: Sema.zirByteSwap", .{});
59786008}
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 {
59816011 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
59826012 const src = inst_data.src();
59836013 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitReverse", .{});
59846014}
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 {
59876017 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
59886018 const src = inst_data.src();
59896019 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivExact", .{});
59906020}
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 {
59936023 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
59946024 const src = inst_data.src();
59956025 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivFloor", .{});
59966026}
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 {
59996029 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60006030 const src = inst_data.src();
60016031 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivTrunc", .{});
60026032}
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 {
60056035 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60066036 const src = inst_data.src();
60076037 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMod", .{});
60086038}
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 {
60116041 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60126042 const src = inst_data.src();
60136043 return sema.mod.fail(&block.base, src, "TODO: Sema.zirRem", .{});
60146044}
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 {
60176047 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60186048 const src = inst_data.src();
60196049 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShlExact", .{});
60206050}
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 {
60236053 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60246054 const src = inst_data.src();
60256055 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShrExact", .{});
60266056}
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 {
60296059 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60306060 const src = inst_data.src();
60316061 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitOffsetOf", .{});
60326062}
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 {
60356065 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60366066 const src = inst_data.src();
60376067 return sema.mod.fail(&block.base, src, "TODO: Sema.zirOffsetOf", .{});
60386068}
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 {
60416071 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60426072 const src = inst_data.src();
60436073 return sema.mod.fail(&block.base, src, "TODO: Sema.zirCmpxchg", .{});
60446074}
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 {
60476077 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60486078 const src = inst_data.src();
60496079 return sema.mod.fail(&block.base, src, "TODO: Sema.zirSplat", .{});
60506080}
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 {
60536083 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60546084 const src = inst_data.src();
60556085 return sema.mod.fail(&block.base, src, "TODO: Sema.zirReduce", .{});
60566086}
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 {
60596089 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60606090 const src = inst_data.src();
60616091 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShuffle", .{});
60626092}
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 {
60656095 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60666096 const src = inst_data.src();
60676097 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicLoad", .{});
60686098}
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 {
60716101 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60726102 const src = inst_data.src();
60736103 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicRmw", .{});
60746104}
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 {
60776107 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60786108 const src = inst_data.src();
60796109 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicStore", .{});
60806110}
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 {
60836113 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60846114 const src = inst_data.src();
60856115 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMulAdd", .{});
60866116}
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 {
60896119 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60906120 const src = inst_data.src();
60916121 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinCall", .{});
60926122}
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 {
60956125 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60966126 const src = inst_data.src();
60976127 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldPtrType", .{});
60986128}
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 {
61016131 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
61026132 const src = inst_data.src();
61036133 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldParentPtr", .{});
61046134}
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 {
61076137 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
61086138 const src = inst_data.src();
61096139 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemcpy", .{});
61106140}
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 {
61136143 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
61146144 const src = inst_data.src();
61156145 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemset", .{});
61166146}
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 {
61196149 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
61206150 const src = inst_data.src();
61216151 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinAsyncCall", .{});
61226152}
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 {
61256155 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
61266156 const src = inst_data.src();
61276157 return sema.mod.fail(&block.base, src, "TODO: Sema.zirResume", .{});
......@@ -6132,7 +6162,7 @@ fn zirAwait(
61326162 block: *Scope.Block,
61336163 inst: Zir.Inst.Index,
61346164 is_nosuspend: bool,
6135) InnerError!Air.Inst.Index {
6165) InnerError!Air.Inst.Ref {
61366166 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
61376167 const src = inst_data.src();
61386168
......@@ -6144,7 +6174,7 @@ fn zirVarExtended(
61446174 sema: *Sema,
61456175 block: *Scope.Block,
61466176 extended: Zir.Inst.Extended.InstData,
6147) InnerError!Air.Inst.Index {
6177) InnerError!Air.Inst.Ref {
61486178 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
61496179 const src = sema.src;
61506180 const ty_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at type
......@@ -6210,7 +6240,7 @@ fn zirFuncExtended(
62106240 block: *Scope.Block,
62116241 extended: Zir.Inst.Extended.InstData,
62126242 inst: Zir.Inst.Index,
6213) InnerError!Air.Inst.Index {
6243) InnerError!Air.Inst.Ref {
62146244 const tracy = trace(@src());
62156245 defer tracy.end();
62166246
......@@ -6277,7 +6307,7 @@ fn zirCUndef(
62776307 sema: *Sema,
62786308 block: *Scope.Block,
62796309 extended: Zir.Inst.Extended.InstData,
6280) InnerError!Air.Inst.Index {
6310) InnerError!Air.Inst.Ref {
62816311 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
62826312 const src: LazySrcLoc = .{ .node_offset = extra.node };
62836313 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCUndef", .{});
......@@ -6287,7 +6317,7 @@ fn zirCInclude(
62876317 sema: *Sema,
62886318 block: *Scope.Block,
62896319 extended: Zir.Inst.Extended.InstData,
6290) InnerError!Air.Inst.Index {
6320) InnerError!Air.Inst.Ref {
62916321 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
62926322 const src: LazySrcLoc = .{ .node_offset = extra.node };
62936323 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCInclude", .{});
......@@ -6297,7 +6327,7 @@ fn zirCDefine(
62976327 sema: *Sema,
62986328 block: *Scope.Block,
62996329 extended: Zir.Inst.Extended.InstData,
6300) InnerError!Air.Inst.Index {
6330) InnerError!Air.Inst.Ref {
63016331 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
63026332 const src: LazySrcLoc = .{ .node_offset = extra.node };
63036333 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCDefine", .{});
......@@ -6307,7 +6337,7 @@ fn zirWasmMemorySize(
63076337 sema: *Sema,
63086338 block: *Scope.Block,
63096339 extended: Zir.Inst.Extended.InstData,
6310) InnerError!Air.Inst.Index {
6340) InnerError!Air.Inst.Ref {
63116341 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
63126342 const src: LazySrcLoc = .{ .node_offset = extra.node };
63136343 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemorySize", .{});
......@@ -6317,7 +6347,7 @@ fn zirWasmMemoryGrow(
63176347 sema: *Sema,
63186348 block: *Scope.Block,
63196349 extended: Zir.Inst.Extended.InstData,
6320) InnerError!Air.Inst.Index {
6350) InnerError!Air.Inst.Ref {
63216351 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
63226352 const src: LazySrcLoc = .{ .node_offset = extra.node };
63236353 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemoryGrow", .{});
......@@ -6327,7 +6357,7 @@ fn zirBuiltinExtern(
63276357 sema: *Sema,
63286358 block: *Scope.Block,
63296359 extended: Zir.Inst.Extended.InstData,
6330) InnerError!Air.Inst.Index {
6360) InnerError!Air.Inst.Ref {
63316361 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
63326362 const src: LazySrcLoc = .{ .node_offset = extra.node };
63336363 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinExtern", .{});
......@@ -6361,7 +6391,7 @@ pub const PanicId = enum {
63616391 invalid_error_code,
63626392};
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 {
63656395 const block_inst = try sema.arena.create(Inst.Block);
63666396 block_inst.* = .{
63676397 .base = .{
......@@ -6423,7 +6453,7 @@ fn panicWithMsg(
64236453 sema: *Sema,
64246454 block: *Scope.Block,
64256455 src: LazySrcLoc,
6426 msg_inst: Air.Inst.Index,
6456 msg_inst: Air.Inst.Ref,
64276457) !Zir.Inst.Index {
64286458 const mod = sema.mod;
64296459 const arena = sema.arena;
......@@ -6439,7 +6469,7 @@ fn panicWithMsg(
64396469 const panic_fn = try sema.getBuiltin(block, src, "panic");
64406470 const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace");
64416471 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);
64436473 const null_stack_trace = try mod.constInst(arena, src, .{
64446474 .ty = try mod.optionalType(arena, ptr_stack_trace_ty),
64456475 .val = Value.initTag(.null_value),
......@@ -6500,10 +6530,10 @@ fn namedFieldPtr(
65006530 sema: *Sema,
65016531 block: *Scope.Block,
65026532 src: LazySrcLoc,
6503 object_ptr: Air.Inst.Index,
6533 object_ptr: Air.Inst.Ref,
65046534 field_name: []const u8,
65056535 field_name_src: LazySrcLoc,
6506) InnerError!Air.Inst.Index {
6536) InnerError!Air.Inst.Ref {
65076537 const mod = sema.mod;
65086538 const arena = sema.arena;
65096539
......@@ -6579,7 +6609,7 @@ fn namedFieldPtr(
65796609 } else (try mod.getErrorValue(field_name)).key;
65806610
65816611 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),
65836613 .val = try Value.Tag.ref_val.create(
65846614 arena,
65856615 try Value.Tag.@"error".create(arena, .{
......@@ -6633,7 +6663,7 @@ fn namedFieldPtr(
66336663 const field_index_u32 = @intCast(u32, field_index);
66346664 const enum_val = try Value.Tag.enum_field_index.create(arena, field_index_u32);
66356665 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),
66376667 .val = try Value.Tag.ref_val.create(arena, enum_val),
66386668 });
66396669 },
......@@ -6653,7 +6683,7 @@ fn analyzeNamespaceLookup(
66536683 src: LazySrcLoc,
66546684 namespace: *Scope.Namespace,
66556685 decl_name: []const u8,
6656) InnerError!?Air.Inst.Index {
6686) InnerError!?Air.Inst.Ref {
66576687 const mod = sema.mod;
66586688 const gpa = sema.gpa;
66596689 if (try sema.lookupInNamespace(namespace, decl_name)) |decl| {
......@@ -6677,11 +6707,11 @@ fn analyzeStructFieldPtr(
66776707 sema: *Sema,
66786708 block: *Scope.Block,
66796709 src: LazySrcLoc,
6680 struct_ptr: Air.Inst.Index,
6710 struct_ptr: Air.Inst.Ref,
66816711 field_name: []const u8,
66826712 field_name_src: LazySrcLoc,
66836713 unresolved_struct_ty: Type,
6684) InnerError!Air.Inst.Index {
6714) InnerError!Air.Inst.Ref {
66856715 const mod = sema.mod;
66866716 const arena = sema.arena;
66876717 assert(unresolved_struct_ty.zigTypeTag() == .Struct);
......@@ -6692,7 +6722,7 @@ fn analyzeStructFieldPtr(
66926722 const field_index = struct_obj.fields.getIndex(field_name) orelse
66936723 return sema.failWithBadFieldAccess(block, struct_obj, field_name_src, field_name);
66946724 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
66976727 if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| {
66986728 return mod.constInst(arena, src, .{
......@@ -6712,11 +6742,11 @@ fn analyzeUnionFieldPtr(
67126742 sema: *Sema,
67136743 block: *Scope.Block,
67146744 src: LazySrcLoc,
6715 union_ptr: Air.Inst.Index,
6745 union_ptr: Air.Inst.Ref,
67166746 field_name: []const u8,
67176747 field_name_src: LazySrcLoc,
67186748 unresolved_union_ty: Type,
6719) InnerError!Air.Inst.Index {
6749) InnerError!Air.Inst.Ref {
67206750 const mod = sema.mod;
67216751 const arena = sema.arena;
67226752 assert(unresolved_union_ty.zigTypeTag() == .Union);
......@@ -6728,7 +6758,7 @@ fn analyzeUnionFieldPtr(
67286758 return sema.failWithBadUnionFieldAccess(block, union_obj, field_name_src, field_name);
67296759
67306760 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
67336763 if (try sema.resolveDefinedValue(block, src, union_ptr)) |union_ptr_val| {
67346764 // TODO detect inactive union field and emit compile error
......@@ -6749,10 +6779,10 @@ fn elemPtr(
67496779 sema: *Sema,
67506780 block: *Scope.Block,
67516781 src: LazySrcLoc,
6752 array_ptr: Air.Inst.Index,
6753 elem_index: Air.Inst.Index,
6782 array_ptr: Air.Inst.Ref,
6783 elem_index: Air.Inst.Ref,
67546784 elem_index_src: LazySrcLoc,
6755) InnerError!Air.Inst.Index {
6785) InnerError!Air.Inst.Ref {
67566786 const array_ty = switch (array_ptr.ty.zigTypeTag()) {
67576787 .Pointer => array_ptr.ty.elemType(),
67586788 else => return sema.mod.fail(&block.base, array_ptr.src, "expected pointer, found '{}'", .{array_ptr.ty}),
......@@ -6776,10 +6806,10 @@ fn elemPtrArray(
67766806 sema: *Sema,
67776807 block: *Scope.Block,
67786808 src: LazySrcLoc,
6779 array_ptr: Air.Inst.Index,
6780 elem_index: Air.Inst.Index,
6809 array_ptr: Air.Inst.Ref,
6810 elem_index: Air.Inst.Ref,
67816811 elem_index_src: LazySrcLoc,
6782) InnerError!Air.Inst.Index {
6812) InnerError!Air.Inst.Ref {
67836813 if (array_ptr.value()) |array_ptr_val| {
67846814 if (elem_index.value()) |index_val| {
67856815 // Both array pointer and index are compile-time known.
......@@ -6804,35 +6834,41 @@ fn coerce(
68046834 sema: *Sema,
68056835 block: *Scope.Block,
68066836 dest_type: Type,
6807 inst: Air.Inst.Index,
6837 inst: Air.Inst.Ref,
68086838 inst_src: LazySrcLoc,
6809) InnerError!Air.Inst.Index {
6839) InnerError!Air.Inst.Ref {
68106840 if (dest_type.tag() == .var_args_param) {
6811 return sema.coerceVarArgParam(block, inst);
6841 return sema.coerceVarArgParam(block, inst, inst_src);
68126842 }
6843
6844 const inst_ty = sema.getTypeOfAirRef(inst);
68136845 // 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))
68156847 return inst;
68166848
6817 const in_memory_result = coerceInMemoryAllowed(dest_type, inst.ty);
6849 const in_memory_result = coerceInMemoryAllowed(dest_type, inst_ty);
68186850 if (in_memory_result == .ok) {
6819 return sema.bitcast(block, dest_type, inst);
6851 return sema.bitcast(block, dest_type, inst, inst_src);
68206852 }
68216853
68226854 const mod = sema.mod;
68236855 const arena = sema.arena;
68246856
68256857 // undefined to anything
6826 if (inst.value()) |val| {
6827 if (val.isUndef() or inst.ty.zigTypeTag() == .Undefined) {
6828 return mod.constInst(arena, inst_src, .{ .ty = dest_type, .val = val });
6858 if (try sema.resolvePossiblyUndefinedValue(block, inst_src, inst)) |val| {
6859 if (val.isUndef() or inst_ty.zigTypeTag() == .Undefined) {
6860 return sema.addConstant(dest_type, val);
68296861 }
68306862 }
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
68336869 // T to E!T or E to E!T
68346870 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);
68366872 }
68376873
68386874 // comptime known number to other number
......@@ -6844,14 +6880,14 @@ fn coerce(
68446880 switch (dest_type.zigTypeTag()) {
68456881 .Optional => {
68466882 // null to ?T
6847 if (inst.ty.zigTypeTag() == .Null) {
6883 if (inst_ty.zigTypeTag() == .Null) {
68486884 return mod.constInst(arena, inst_src, .{ .ty = dest_type, .val = Value.initTag(.null_value) });
68496885 }
68506886
68516887 // T to ?T
68526888 var buf: Type.Payload.ElemType = undefined;
68536889 const child_type = dest_type.optionalChild(&buf);
6854 if (child_type.eql(inst.ty)) {
6890 if (child_type.eql(inst_ty)) {
68556891 return sema.wrapOptional(block, dest_type, inst);
68566892 } else if (try sema.coerceNum(block, child_type, inst)) |some| {
68576893 return sema.wrapOptional(block, dest_type, some);
......@@ -6860,12 +6896,12 @@ fn coerce(
68606896 .Pointer => {
68616897 // Coercions where the source is a single pointer to an array.
68626898 src_array_ptr: {
6863 if (!inst.ty.isSinglePointer()) break :src_array_ptr;
6864 const array_type = inst.ty.elemType();
6899 if (!inst_ty.isSinglePointer()) break :src_array_ptr;
6900 const array_type = inst_ty.elemType();
68656901 if (array_type.zigTypeTag() != .Array) break :src_array_ptr;
68666902 const array_elem_type = array_type.elemType();
6867 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;
6903 if (inst_ty.isConstPtr() and !dest_type.isConstPtr()) break :src_array_ptr;
6904 if (inst_ty.isVolatilePtr() and !dest_type.isVolatilePtr()) break :src_array_ptr;
68696905
68706906 const dst_elem_type = dest_type.elemType();
68716907 switch (coerceInMemoryAllowed(dst_elem_type, array_elem_type)) {
......@@ -6904,11 +6940,11 @@ fn coerce(
69046940 },
69056941 .Int => {
69066942 // integer widening
6907 if (inst.ty.zigTypeTag() == .Int) {
6943 if (inst_ty.zigTypeTag() == .Int) {
69086944 assert(inst.value() == null); // handled above
69096945
69106946 const dst_info = dest_type.intInfo(target);
6911 const src_info = inst.ty.intInfo(target);
6947 const src_info = inst_ty.intInfo(target);
69126948 if ((src_info.signedness == dst_info.signedness and dst_info.bits >= src_info.bits) or
69136949 // small enough unsigned ints can get casted to large enough signed ints
69146950 (src_info.signedness == .signed and dst_info.signedness == .unsigned and dst_info.bits > src_info.bits))
......@@ -6920,10 +6956,10 @@ fn coerce(
69206956 },
69216957 .Float => {
69226958 // float widening
6923 if (inst.ty.zigTypeTag() == .Float) {
6959 if (inst_ty.zigTypeTag() == .Float) {
69246960 assert(inst.value() == null); // handled above
69256961
6926 const src_bits = inst.ty.floatBits(target);
6962 const src_bits = inst_ty.floatBits(target);
69276963 const dst_bits = dest_type.floatBits(target);
69286964 if (dst_bits >= src_bits) {
69296965 try sema.requireRuntimeBlock(block, inst_src);
......@@ -6933,7 +6969,7 @@ fn coerce(
69336969 },
69346970 .Enum => {
69356971 // enum literal to enum
6936 if (inst.ty.zigTypeTag() == .EnumLiteral) {
6972 if (inst_ty.zigTypeTag() == .EnumLiteral) {
69376973 const val = try sema.resolveConstValue(block, inst_src, inst);
69386974 const bytes = val.castTag(.enum_literal).?.data;
69396975 const resolved_dest_type = try sema.resolveTypeFields(block, inst_src, dest_type);
......@@ -6965,7 +7001,7 @@ fn coerce(
69657001 else => {},
69667002 }
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 });
69697005}
69707006
69717007const InMemoryCoercionResult = enum {
......@@ -6982,7 +7018,7 @@ fn coerceInMemoryAllowed(dest_type: Type, src_type: Type) InMemoryCoercionResult
69827018 return .no_match;
69837019}
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 {
69867022 const val = inst.value() orelse return null;
69877023 const src_zig_tag = inst.ty.zigTypeTag();
69887024 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
70207056 return null;
70217057}
70227058
7023fn coerceVarArgParam(sema: *Sema, block: *Scope.Block, inst: Air.Inst.Index) !Air.Inst.Index {
7024 switch (inst.ty.zigTypeTag()) {
7025 .ComptimeInt, .ComptimeFloat => return sema.mod.fail(&block.base, inst.src, "integer and float literals in var args function must be casted", .{}),
7059fn coerceVarArgParam(
7060 sema: *Sema,
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", .{}),
70267068 else => {},
70277069 }
70287070 // TODO implement more of this function.
......@@ -7033,8 +7075,8 @@ fn storePtr(
70337075 sema: *Sema,
70347076 block: *Scope.Block,
70357077 src: LazySrcLoc,
7036 ptr: Air.Inst.Index,
7037 uncasted_value: Air.Inst.Index,
7078 ptr: Air.Inst.Ref,
7079 uncasted_value: Air.Inst.Ref,
70387080) !void {
70397081 if (ptr.ty.isConstPtr())
70407082 return sema.mod.fail(&block.base, src, "cannot assign to constant", .{});
......@@ -7082,17 +7124,23 @@ fn storePtr(
70827124 _ = try block.addBinOp(src, Type.initTag(.void), .store, ptr, value);
70837125}
70847126
7085fn bitcast(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) !Air.Inst.Index {
7086 if (inst.value()) |val| {
7127fn bitcast(
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| {
70877135 // 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);
70897137 }
70907138 // TODO validate the type size and other compile errors
7091 try sema.requireRuntimeBlock(block, inst.src);
7092 return block.addUnOp(inst.src, dest_type, .bitcast, inst);
7139 try sema.requireRuntimeBlock(block, inst_src);
7140 return block.addTyOp(.bitcast, dest_type, inst);
70937141}
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 {
70967144 if (inst.value()) |val| {
70977145 // The comptime Value representation is compatible with both types.
70987146 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
71007148 return sema.mod.fail(&block.base, inst.src, "TODO implement coerceArrayPtrToSlice runtime instruction", .{});
71017149}
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 {
71047152 if (inst.value()) |val| {
71057153 // The comptime Value representation is compatible with both types.
71067154 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:
71087156 return sema.mod.fail(&block.base, inst.src, "TODO implement coerceArrayPtrToMany runtime instruction", .{});
71097157}
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 {
71127160 const decl_ref = try sema.analyzeDeclRef(block, src, decl);
71137161 return sema.analyzeLoad(block, src, decl_ref, src);
71147162}
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 {
71177165 try sema.mod.declareDeclDependency(sema.owner_decl, decl);
71187166 sema.mod.ensureDeclAnalyzed(decl) catch |err| {
71197167 if (sema.func) |func| {
......@@ -7128,43 +7176,41 @@ fn analyzeDeclRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl
71287176 if (decl_tv.val.tag() == .variable) {
71297177 return sema.analyzeVarRef(block, src, decl_tv);
71307178 }
7131 return sema.mod.constInst(sema.arena, src, .{
7132 .ty = try sema.mod.simplePtrType(sema.arena, decl_tv.ty, false, .One),
7133 .val = try Value.Tag.decl_ref.create(sema.arena, decl),
7134 });
7179 return sema.addConstant(
7180 try Module.simplePtrType(sema.arena, decl_tv.ty, false, .One),
7181 try Value.Tag.decl_ref.create(sema.arena, decl),
7182 );
71357183}
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 {
71387186 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);
71417189 if (!variable.is_mutable and !variable.is_extern) {
7142 return sema.mod.constInst(sema.arena, src, .{
7143 .ty = ty,
7144 .val = try Value.Tag.ref_val.create(sema.arena, variable.init),
7145 });
7190 return sema.addConstant(ty, try Value.Tag.ref_val.create(sema.arena, variable.init));
71467191 }
71477192
7193 const gpa = sema.gpa;
71487194 try sema.requireRuntimeBlock(block, src);
7149 const inst = try sema.arena.create(Inst.VarPtr);
7150 inst.* = .{
7151 .base = .{
7152 .tag = .varptr,
7153 .ty = ty,
7154 .src = src,
7155 },
7156 .variable = variable,
7157 };
7158 try block.instructions.append(sema.gpa, &inst.base);
7159 return &inst.base;
7195 try sema.air_variables.append(gpa, variable);
7196 const result_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);
7197 try sema.air_instructions.append(gpa, .{
7198 .tag = .varptr,
7199 .data = .{ .ty_pl = .{
7200 .ty = try sema.addType(ty),
7201 .payload = @intCast(u32, sema.air_variables.items.len - 1),
7202 } },
7203 });
7204 try block.instructions.append(gpa, result_inst);
7205 return indexToRef(result_inst);
71607206}
71617207
71627208fn analyzeRef(
71637209 sema: *Sema,
71647210 block: *Scope.Block,
71657211 src: LazySrcLoc,
7166 operand: Air.Inst.Index,
7167) InnerError!Air.Inst.Index {
7212 operand: Air.Inst.Ref,
7213) InnerError!Air.Inst.Ref {
71687214 const ptr_type = try sema.mod.simplePtrType(sema.arena, operand.ty, false, .One);
71697215
71707216 if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |val| {
......@@ -7182,34 +7228,32 @@ fn analyzeLoad(
71827228 sema: *Sema,
71837229 block: *Scope.Block,
71847230 src: LazySrcLoc,
7185 ptr: Air.Inst.Index,
7231 ptr: Air.Inst.Ref,
71867232 ptr_src: LazySrcLoc,
7187) InnerError!Air.Inst.Index {
7188 const elem_ty = switch (ptr.ty.zigTypeTag()) {
7189 .Pointer => ptr.ty.elemType(),
7190 else => return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr.ty}),
7233) InnerError!Air.Inst.Ref {
7234 const ptr_ty = sema.getTypeOfAirRef(ptr);
7235 const elem_ty = switch (ptr_ty.zigTypeTag()) {
7236 .Pointer => ptr_ty.elemType(),
7237 else => return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr_ty}),
71917238 };
71927239 if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| blk: {
71937240 if (ptr_val.tag() == .int_u64)
71947241 break :blk; // do it at runtime
71957242
7196 return sema.mod.constInst(sema.arena, src, .{
7197 .ty = elem_ty,
7198 .val = try ptr_val.pointerDeref(sema.arena),
7199 });
7243 return sema.addConstant(elem_ty, try ptr_val.pointerDeref(sema.arena));
72007244 }
72017245
72027246 try sema.requireRuntimeBlock(block, src);
7203 return block.addUnOp(src, elem_ty, .load, ptr);
7247 return block.addTyOp(.load, elem_ty, ptr);
72047248}
72057249
72067250fn analyzeIsNull(
72077251 sema: *Sema,
72087252 block: *Scope.Block,
72097253 src: LazySrcLoc,
7210 operand: Air.Inst.Index,
7254 operand: Air.Inst.Ref,
72117255 invert_logic: bool,
7212) InnerError!Air.Inst.Index {
7256) InnerError!Air.Inst.Ref {
72137257 const result_ty = Type.initTag(.bool);
72147258 if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |opt_val| {
72157259 if (opt_val.isUndef()) {
......@@ -7228,8 +7272,8 @@ fn analyzeIsNonErr(
72287272 sema: *Sema,
72297273 block: *Scope.Block,
72307274 src: LazySrcLoc,
7231 operand: Air.Inst.Index,
7232) InnerError!Air.Inst.Index {
7275 operand: Air.Inst.Ref,
7276) InnerError!Air.Inst.Ref {
72337277 const ot = operand.ty.zigTypeTag();
72347278 if (ot != .ErrorSet and ot != .ErrorUnion) return sema.mod.constBool(sema.arena, src, true);
72357279 if (ot == .ErrorSet) return sema.mod.constBool(sema.arena, src, false);
......@@ -7249,12 +7293,12 @@ fn analyzeSlice(
72497293 sema: *Sema,
72507294 block: *Scope.Block,
72517295 src: LazySrcLoc,
7252 array_ptr: Air.Inst.Index,
7253 start: Air.Inst.Index,
7296 array_ptr: Air.Inst.Ref,
7297 start: Air.Inst.Ref,
72547298 end_opt: ?Air.Inst.Index,
72557299 sentinel_opt: ?Air.Inst.Index,
72567300 sentinel_src: LazySrcLoc,
7257) InnerError!Air.Inst.Index {
7301) InnerError!Air.Inst.Ref {
72587302 const ptr_child = switch (array_ptr.ty.zigTypeTag()) {
72597303 .Pointer => array_ptr.ty.elemType(),
72607304 else => return sema.mod.fail(&block.base, src, "expected pointer, found '{}'", .{array_ptr.ty}),
......@@ -7325,10 +7369,10 @@ fn cmpNumeric(
73257369 sema: *Sema,
73267370 block: *Scope.Block,
73277371 src: LazySrcLoc,
7328 lhs: Air.Inst.Index,
7329 rhs: Air.Inst.Index,
7372 lhs: Air.Inst.Ref,
7373 rhs: Air.Inst.Ref,
73307374 op: std.math.CompareOperator,
7331) InnerError!Air.Inst.Index {
7375) InnerError!Air.Inst.Ref {
73327376 assert(lhs.ty.isNumeric());
73337377 assert(rhs.ty.isNumeric());
73347378
......@@ -7494,7 +7538,7 @@ fn cmpNumeric(
74947538 return block.addBinOp(src, Type.initTag(.bool), Inst.Tag.fromCmpOp(op), casted_lhs, casted_rhs);
74957539}
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 {
74987542 if (inst.value()) |val| {
74997543 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });
75007544 }
......@@ -7503,9 +7547,15 @@ fn wrapOptional(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Ins
75037547 return block.addUnOp(inst.src, dest_type, .wrap_optional, inst);
75047548}
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 {
75077557 const err_union = dest_type.castTag(.error_union).?;
7508 if (inst.value()) |val| {
7558 if (try sema.resolvePossiblyUndefinedValue(block, inst_src, inst)) |val| {
75097559 if (inst.ty.zigTypeTag() != .ErrorSet) {
75107560 _ = try sema.coerce(block, err_union.data.payload, inst, inst.src);
75117561 } else switch (err_union.data.error_set.tag()) {
......@@ -7710,7 +7760,7 @@ fn getBuiltin(
77107760 block: *Scope.Block,
77117761 src: LazySrcLoc,
77127762 name: []const u8,
7713) InnerError!Air.Inst.Index {
7763) InnerError!Air.Inst.Ref {
77147764 const mod = sema.mod;
77157765 const std_pkg = mod.root_pkg.table.get("std").?;
77167766 const std_file = (mod.importPkg(std_pkg) catch unreachable).file;
......@@ -7938,6 +7988,68 @@ fn enumFieldSrcLoc(
79387988 } else unreachable;
79397989}
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.
79418053fn getAirType(sema: *Sema, air_ref: Air.Inst.Ref) Type {
79428054 var i: usize = @enumToInt(air_ref);
79438055 if (i < Air.Inst.Ref.typed_value_map.len) {
......@@ -8014,13 +8126,27 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
80148126 return indexToRef(@intCast(u32, sema.air_instructions.len - 1));
80158127}
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
80178143const 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 {
80208146 return @intToEnum(Air.Inst.Ref, ref_start_index + inst);
80218147}
80228148
8023fn refToIndex(inst: Air.Inst.Ref) ?Air.Inst.Index {
8149pub fn refToIndex(inst: Air.Inst.Ref) ?Air.Inst.Index {
80248150 const ref_int = @enumToInt(inst);
80258151 if (ref_int >= ref_start_index) {
80268152 return ref_int - ref_start_index;
src/codegen.zig+79-80
......@@ -494,7 +494,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
494494 defer function.blocks.deinit(bin_file.allocator);
495495 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) {
498498 error.CodegenFail => return Result{ .fail = function.err_msg.? },
499499 else => |e| return e,
500500 };
......@@ -537,7 +537,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
537537 self.code.items.len += 4;
538538
539539 try self.dbgSetPrologueEnd();
540 try self.genBody(self.mod_fn.body);
540 try self.genBody(self.air.getMainBody());
541541
542542 const stack_end = self.max_end_stack;
543543 if (stack_end > math.maxInt(i32))
......@@ -578,7 +578,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
578578 });
579579 } else {
580580 try self.dbgSetPrologueEnd();
581 try self.genBody(self.mod_fn.body);
581 try self.genBody(self.air.getMainBody());
582582 try self.dbgSetEpilogueBegin();
583583 }
584584 },
......@@ -758,11 +758,12 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
758758 }
759759
760760 // TODO inline this logic into every instruction
761 var i: ir.Inst.DeathsBitIndex = 0;
762 while (inst.getOperand(i)) |operand| : (i += 1) {
763 if (inst.operandDies(i))
764 self.processDeath(operand);
765 }
761 @panic("TODO rework AIR memory layout codegen for processing deaths");
762 //var i: ir.Inst.DeathsBitIndex = 0;
763 //while (inst.getOperand(i)) |operand| : (i += 1) {
764 // if (inst.operandDies(i))
765 // self.processDeath(operand);
766 //}
766767 }
767768 }
768769
......@@ -858,74 +859,76 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
858859 const air_tags = self.air.instructions.items(.tag);
859860 switch (air_tags[inst]) {
860861 // zig fmt: off
861 .add => return self.genAdd(inst.castTag(.add).?),
862 .addwrap => return self.genAddWrap(inst.castTag(.addwrap).?),
863 .sub => return self.genSub(inst.castTag(.sub).?),
864 .subwrap => return self.genSubWrap(inst.castTag(.subwrap).?),
865 .mul => return self.genMul(inst.castTag(.mul).?),
866 .mulwrap => return self.genMulWrap(inst.castTag(.mulwrap).?),
867 .div => return self.genDiv(inst.castTag(.div).?),
868
869 .cmp_lt => return self.genCmp(inst.castTag(.cmp_lt).?, .lt),
870 .cmp_lte => return self.genCmp(inst.castTag(.cmp_lte).?, .lte),
871 .cmp_eq => return self.genCmp(inst.castTag(.cmp_eq).?, .eq),
872 .cmp_gte => return self.genCmp(inst.castTag(.cmp_gte).?, .gte),
873 .cmp_gt => return self.genCmp(inst.castTag(.cmp_gt).?, .gt),
874 .cmp_neq => return self.genCmp(inst.castTag(.cmp_neq).?, .neq),
875
876 .bool_and => return self.genBoolOp(inst.castTag(.bool_and).?),
877 .bool_or => return self.genBoolOp(inst.castTag(.bool_or).?),
878 .bit_and => return self.genBitAnd(inst.castTag(.bit_and).?),
879 .bit_or => return self.genBitOr(inst.castTag(.bit_or).?),
880 .xor => return self.genXor(inst.castTag(.xor).?),
881
882 .alloc => return self.genAlloc(inst.castTag(.alloc).?),
883 .arg => return self.genArg(inst.castTag(.arg).?),
884 .assembly => return self.genAsm(inst.castTag(.assembly).?),
885 .bitcast => return self.genBitCast(inst.castTag(.bitcast).?),
886 .block => return self.genBlock(inst.castTag(.block).?),
887 .br => return self.genBr(inst.castTag(.br).?),
888 .br_block_flat => return self.genBrBlockFlat(inst.castTag(.br_block_flat).?),
889 .breakpoint => return self.genBreakpoint(inst.src),
890 .call => return self.genCall(inst.castTag(.call).?),
891 .cond_br => return self.genCondBr(inst.castTag(.condbr).?),
892 .dbg_stmt => return self.genDbgStmt(inst.castTag(.dbg_stmt).?),
893 .floatcast => return self.genFloatCast(inst.castTag(.floatcast).?),
894 .intcast => return self.genIntCast(inst.castTag(.intcast).?),
895 .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_null => return self.genIsNull(inst.castTag(.is_null).?),
898 .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_ptr => return self.genIsNonErrPtr(inst.castTag(.is_non_err_ptr).?),
901 .is_err => return self.genIsErr(inst.castTag(.is_err).?),
902 .is_err_ptr => return self.genIsErrPtr(inst.castTag(.is_err_ptr).?),
903 .load => return self.genLoad(inst.castTag(.load).?),
904 .loop => return self.genLoop(inst.castTag(.loop).?),
905 .not => return self.genNot(inst.castTag(.not).?),
906 .ptrtoint => return self.genPtrToInt(inst.castTag(.ptrtoint).?),
907 .ref => return self.genRef(inst.castTag(.ref).?),
908 .ret => return self.genRet(inst.castTag(.ret).?),
909 .store => return self.genStore(inst.castTag(.store).?),
910 .struct_field_ptr=> return self.genStructFieldPtr(inst.castTag(.struct_field_ptr).?),
911 .switchbr => return self.genSwitch(inst.castTag(.switchbr).?),
912 .varptr => return self.genVarPtr(inst.castTag(.varptr).?),
913
914 .constant => unreachable, // excluded from function bodies
915 .unreach => return MCValue{ .unreach = {} },
916
917 .optional_payload => return self.genOptionalPayload(inst.castTag(.optional_payload).?),
918 .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_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_payload_ptr=> return self.genUnwrapErrPayloadPtr(inst.castTag(.unwrap_errunion_payload_ptr).?),
923
924 .wrap_optional => return self.genWrapOptional(inst.castTag(.wrap_optional).?),
925 .wrap_errunion_payload => return self.genWrapErrUnionPayload(inst.castTag(.wrap_errunion_payload).?),
926 .wrap_errunion_err => return self.genWrapErrUnionErr(inst.castTag(.wrap_errunion_err).?),
862 //.add => return self.genAdd(inst.castTag(.add).?),
863 //.addwrap => return self.genAddWrap(inst.castTag(.addwrap).?),
864 //.sub => return self.genSub(inst.castTag(.sub).?),
865 //.subwrap => return self.genSubWrap(inst.castTag(.subwrap).?),
866 //.mul => return self.genMul(inst.castTag(.mul).?),
867 //.mulwrap => return self.genMulWrap(inst.castTag(.mulwrap).?),
868 //.div => return self.genDiv(inst.castTag(.div).?),
869
870 //.cmp_lt => return self.genCmp(inst.castTag(.cmp_lt).?, .lt),
871 //.cmp_lte => return self.genCmp(inst.castTag(.cmp_lte).?, .lte),
872 //.cmp_eq => return self.genCmp(inst.castTag(.cmp_eq).?, .eq),
873 //.cmp_gte => return self.genCmp(inst.castTag(.cmp_gte).?, .gte),
874 //.cmp_gt => return self.genCmp(inst.castTag(.cmp_gt).?, .gt),
875 //.cmp_neq => return self.genCmp(inst.castTag(.cmp_neq).?, .neq),
876
877 //.bool_and => return self.genBoolOp(inst.castTag(.bool_and).?),
878 //.bool_or => return self.genBoolOp(inst.castTag(.bool_or).?),
879 //.bit_and => return self.genBitAnd(inst.castTag(.bit_and).?),
880 //.bit_or => return self.genBitOr(inst.castTag(.bit_or).?),
881 //.xor => return self.genXor(inst.castTag(.xor).?),
882
883 //.alloc => return self.genAlloc(inst.castTag(.alloc).?),
884 //.arg => return self.genArg(inst.castTag(.arg).?),
885 //.assembly => return self.genAsm(inst.castTag(.assembly).?),
886 //.bitcast => return self.genBitCast(inst.castTag(.bitcast).?),
887 //.block => return self.genBlock(inst.castTag(.block).?),
888 //.br => return self.genBr(inst.castTag(.br).?),
889 //.br_block_flat => return self.genBrBlockFlat(inst.castTag(.br_block_flat).?),
890 //.breakpoint => return self.genBreakpoint(inst.src),
891 //.call => return self.genCall(inst.castTag(.call).?),
892 //.cond_br => return self.genCondBr(inst.castTag(.condbr).?),
893 //.dbg_stmt => return self.genDbgStmt(inst.castTag(.dbg_stmt).?),
894 //.floatcast => return self.genFloatCast(inst.castTag(.floatcast).?),
895 //.intcast => return self.genIntCast(inst.castTag(.intcast).?),
896 //.is_non_null => return self.genIsNonNull(inst.castTag(.is_non_null).?),
897 //.is_non_null_ptr => return self.genIsNonNullPtr(inst.castTag(.is_non_null_ptr).?),
898 //.is_null => return self.genIsNull(inst.castTag(.is_null).?),
899 //.is_null_ptr => return self.genIsNullPtr(inst.castTag(.is_null_ptr).?),
900 //.is_non_err => return self.genIsNonErr(inst.castTag(.is_non_err).?),
901 //.is_non_err_ptr => return self.genIsNonErrPtr(inst.castTag(.is_non_err_ptr).?),
902 //.is_err => return self.genIsErr(inst.castTag(.is_err).?),
903 //.is_err_ptr => return self.genIsErrPtr(inst.castTag(.is_err_ptr).?),
904 //.load => return self.genLoad(inst.castTag(.load).?),
905 //.loop => return self.genLoop(inst.castTag(.loop).?),
906 //.not => return self.genNot(inst.castTag(.not).?),
907 //.ptrtoint => return self.genPtrToInt(inst.castTag(.ptrtoint).?),
908 //.ref => return self.genRef(inst.castTag(.ref).?),
909 //.ret => return self.genRet(inst.castTag(.ret).?),
910 //.store => return self.genStore(inst.castTag(.store).?),
911 //.struct_field_ptr=> return self.genStructFieldPtr(inst.castTag(.struct_field_ptr).?),
912 //.switch_br => return self.genSwitch(inst.castTag(.switchbr).?),
913 //.varptr => return self.genVarPtr(inst.castTag(.varptr).?),
914
915 //.constant => unreachable, // excluded from function bodies
916 //.unreach => return MCValue{ .unreach = {} },
917
918 //.optional_payload => return self.genOptionalPayload(inst.castTag(.optional_payload).?),
919 //.optional_payload_ptr => return self.genOptionalPayloadPtr(inst.castTag(.optional_payload_ptr).?),
920 //.unwrap_errunion_err => return self.genUnwrapErrErr(inst.castTag(.unwrap_errunion_err).?),
921 //.unwrap_errunion_payload => return self.genUnwrapErrPayload(inst.castTag(.unwrap_errunion_payload).?),
922 //.unwrap_errunion_err_ptr => return self.genUnwrapErrErrPtr(inst.castTag(.unwrap_errunion_err_ptr).?),
923 //.unwrap_errunion_payload_ptr=> return self.genUnwrapErrPayloadPtr(inst.castTag(.unwrap_errunion_payload_ptr).?),
924
925 //.wrap_optional => return self.genWrapOptional(inst.castTag(.wrap_optional).?),
926 //.wrap_errunion_payload => return self.genWrapErrUnionPayload(inst.castTag(.wrap_errunion_payload).?),
927 //.wrap_errunion_err => return self.genWrapErrUnionErr(inst.castTag(.wrap_errunion_err).?),
927928
928929 // zig fmt: on
930
931 else => @panic("TODO finish air memory layout branch, more codegen.zig instructions"),
929932 }
930933 }
931934
......@@ -4785,14 +4788,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
47854788 };
47864789 }
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 {
47894792 @setCold(true);
47904793 assert(self.err_msg == null);
4791 const src_loc = if (src != .unneeded)
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);
4794 self.err_msg = try ErrorMsg.create(self.bin_file.allocator, self.src_loc, format, args);
47964795 return error.CodegenFail;
47974796 }
47984797
src/codegen/c.zig+107-97
......@@ -25,7 +25,7 @@ pub const CValue = union(enum) {
2525 /// Index into local_names, but take the address.
2626 local_ref: usize,
2727 /// A constant instruction, to be rendered inline.
28 constant: *Inst,
28 constant: Air.Inst.Index,
2929 /// Index into the parameters
3030 arg: usize,
3131 /// By-value
......@@ -99,7 +99,7 @@ pub const Object = struct {
9999 gpa: *mem.Allocator,
100100 code: std.ArrayList(u8),
101101 value_map: CValueMap,
102 blocks: std.AutoHashMapUnmanaged(*ir.Inst.Block, BlockData) = .{},
102 blocks: std.AutoHashMapUnmanaged(Air.Inst.Index, BlockData) = .{},
103103 next_arg_index: usize = 0,
104104 next_local_index: usize = 0,
105105 next_block_index: usize = 0,
......@@ -133,7 +133,12 @@ pub const Object = struct {
133133 .none => unreachable,
134134 .local => |i| return w.print("t{d}", .{i}),
135135 .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 },
137142 .arg => |i| return w.print("a{d}", .{i}),
138143 .decl => |decl| return w.writeAll(mem.span(decl.name)),
139144 .decl_ref => |decl| return w.print("&{s}", .{decl.name}),
......@@ -213,8 +218,9 @@ pub const DeclGen = struct {
213218 error_msg: ?*Module.ErrorMsg,
214219 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 } {
217222 @setCold(true);
223 const src: LazySrcLoc = .{ .node_offset = 0 };
218224 const src_loc = src.toSrcLocWithDecl(dg.decl);
219225 dg.error_msg = try Module.ErrorMsg.create(dg.module.gpa, src_loc, format, args);
220226 return error.AnalysisFail;
......@@ -230,7 +236,7 @@ pub const DeclGen = struct {
230236 // This should lower to 0xaa bytes in safe modes, and for unsafe modes should
231237 // lower to leaving variables uninitialized (that might need to be implemented
232238 // 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", .{});
234240 }
235241 switch (t.zigTypeTag()) {
236242 .Int => {
......@@ -440,7 +446,7 @@ pub const DeclGen = struct {
440446 },
441447 else => unreachable,
442448 },
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}", .{
444450 @tagName(e),
445451 }),
446452 }
......@@ -519,14 +525,14 @@ pub const DeclGen = struct {
519525 break;
520526 }
521527 } 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", .{});
523529 }
524530 },
525531 else => unreachable,
526532 }
527533 },
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
531537 .Pointer => {
532538 if (t.isSlice()) {
......@@ -681,7 +687,7 @@ pub const DeclGen = struct {
681687
682688 try dg.renderType(w, int_tag_ty);
683689 },
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", .{}),
685691 .Fn => {
686692 try dg.renderType(w, t.fnReturnType());
687693 try w.writeAll(" (*)(");
......@@ -704,10 +710,10 @@ pub const DeclGen = struct {
704710 }
705711 try w.writeByte(')');
706712 },
707 .Opaque => return dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement type Opaque", .{}),
708 .Frame => return dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement type Frame", .{}),
709 .AnyFrame => return dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement type AnyFrame", .{}),
710 .Vector => return dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement type Vector", .{}),
713 .Opaque => return dg.fail("TODO: C backend: implement type Opaque", .{}),
714 .Frame => return dg.fail("TODO: C backend: implement type Frame", .{}),
715 .AnyFrame => return dg.fail("TODO: C backend: implement type AnyFrame", .{}),
716 .Vector => return dg.fail("TODO: C backend: implement type Vector", .{}),
711717
712718 .Null,
713719 .Undefined,
......@@ -760,7 +766,8 @@ pub fn genDecl(o: *Object) !void {
760766 try o.dg.renderFunctionSignature(o.writer(), is_global);
761767
762768 try o.writer().writeByte(' ');
763 try genBody(o, func.body);
769 const main_body = o.air.getMainBody();
770 try genBody(o, main_body);
764771
765772 try o.indent_writer.insertNewline();
766773 return;
......@@ -833,9 +840,9 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void {
833840 }
834841}
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 {
837844 const writer = o.writer();
838 if (body.instructions.len == 0) {
845 if (body.len == 0) {
839846 try writer.writeAll("{}");
840847 return;
841848 }
......@@ -843,82 +850,85 @@ pub fn genBody(o: *Object, body: ir.Body) error{ AnalysisFail, OutOfMemory }!voi
843850 try writer.writeAll("{\n");
844851 o.indent_writer.pushIndent();
845852
846 for (body.instructions) |inst| {
847 const result_value = switch (inst.tag) {
848 // TODO use a different strategy for add that communicates to the optimizer
849 // that wrapping is UB.
850 .add => try genBinOp(o, inst.castTag(.add).?, " + "),
851 .addwrap => try genWrapOp(o, inst.castTag(.addwrap).?, " + ", "addw_"),
852 // TODO use a different strategy for sub that communicates to the optimizer
853 // that wrapping is UB.
854 .sub => try genBinOp(o, inst.castTag(.sub).?, " - "),
855 .subwrap => try genWrapOp(o, inst.castTag(.subwrap).?, " - ", "subw_"),
856 // TODO use a different strategy for mul that communicates to the optimizer
857 // that wrapping is UB.
858 .mul => try genBinOp(o, inst.castTag(.sub).?, " * "),
859 .mulwrap => try genWrapOp(o, inst.castTag(.mulwrap).?, " * ", "mulw_"),
860 // TODO use a different strategy for div that communicates to the optimizer
861 // that wrapping is UB.
862 .div => try genBinOp(o, inst.castTag(.div).?, " / "),
863
864 .constant => unreachable, // excluded from function bodies
865 .alloc => try genAlloc(o, inst.castTag(.alloc).?),
866 .arg => genArg(o),
867 .assembly => try genAsm(o, inst.castTag(.assembly).?),
868 .block => try genBlock(o, inst.castTag(.block).?),
869 .bitcast => try genBitcast(o, inst.castTag(.bitcast).?),
870 .breakpoint => try genBreakpoint(o, inst.castTag(.breakpoint).?),
871 .call => try genCall(o, inst.castTag(.call).?),
872 .cmp_eq => try genBinOp(o, inst.castTag(.cmp_eq).?, " == "),
873 .cmp_gt => try genBinOp(o, inst.castTag(.cmp_gt).?, " > "),
874 .cmp_gte => try genBinOp(o, inst.castTag(.cmp_gte).?, " >= "),
875 .cmp_lt => try genBinOp(o, inst.castTag(.cmp_lt).?, " < "),
876 .cmp_lte => try genBinOp(o, inst.castTag(.cmp_lte).?, " <= "),
877 .cmp_neq => try genBinOp(o, inst.castTag(.cmp_neq).?, " != "),
878 .dbg_stmt => try genDbgStmt(o, inst.castTag(.dbg_stmt).?),
879 .intcast => try genIntCast(o, inst.castTag(.intcast).?),
880 .load => try genLoad(o, inst.castTag(.load).?),
881 .ret => try genRet(o, inst.castTag(.ret).?),
882 .retvoid => try genRetVoid(o),
883 .store => try genStore(o, inst.castTag(.store).?),
884 .unreach => try genUnreach(o, inst.castTag(.unreach).?),
885 .loop => try genLoop(o, inst.castTag(.loop).?),
886 .condbr => try genCondBr(o, inst.castTag(.condbr).?),
887 .br => try genBr(o, inst.castTag(.br).?),
888 .br_void => try genBrVoid(o, inst.castTag(.br_void).?.block),
889 .switchbr => try genSwitchBr(o, inst.castTag(.switchbr).?),
890 // bool_and and bool_or are non-short-circuit operations
891 .bool_and => try genBinOp(o, inst.castTag(.bool_and).?, " & "),
892 .bool_or => try genBinOp(o, inst.castTag(.bool_or).?, " | "),
893 .bit_and => try genBinOp(o, inst.castTag(.bit_and).?, " & "),
894 .bit_or => try genBinOp(o, inst.castTag(.bit_or).?, " | "),
895 .xor => try genBinOp(o, inst.castTag(.xor).?, " ^ "),
896 .not => try genUnOp(o, inst.castTag(.not).?, "!"),
897 .is_null => try genIsNull(o, inst.castTag(.is_null).?),
898 .is_non_null => try genIsNull(o, inst.castTag(.is_non_null).?),
899 .is_null_ptr => try genIsNull(o, inst.castTag(.is_null_ptr).?),
900 .is_non_null_ptr => try genIsNull(o, inst.castTag(.is_non_null_ptr).?),
901 .wrap_optional => try genWrapOptional(o, inst.castTag(.wrap_optional).?),
902 .optional_payload => try genOptionalPayload(o, inst.castTag(.optional_payload).?),
903 .optional_payload_ptr => try genOptionalPayload(o, inst.castTag(.optional_payload_ptr).?),
904 .ref => try genRef(o, inst.castTag(.ref).?),
905 .struct_field_ptr => try genStructFieldPtr(o, inst.castTag(.struct_field_ptr).?),
906
907 .is_err => try genIsErr(o, inst.castTag(.is_err).?, "", ".", "!="),
908 .is_non_err => try genIsErr(o, inst.castTag(.is_non_err).?, "", ".", "=="),
909 .is_err_ptr => try genIsErr(o, inst.castTag(.is_err_ptr).?, "*", "->", "!="),
910 .is_non_err_ptr => try genIsErr(o, inst.castTag(.is_non_err_ptr).?, "*", "->", "=="),
911
912 .unwrap_errunion_payload => try genUnwrapErrUnionPay(o, inst.castTag(.unwrap_errunion_payload).?),
913 .unwrap_errunion_err => try genUnwrapErrUnionErr(o, inst.castTag(.unwrap_errunion_err).?),
914 .unwrap_errunion_payload_ptr => try genUnwrapErrUnionPay(o, inst.castTag(.unwrap_errunion_payload_ptr).?),
915 .unwrap_errunion_err_ptr => try genUnwrapErrUnionErr(o, inst.castTag(.unwrap_errunion_err_ptr).?),
916 .wrap_errunion_payload => try genWrapErrUnionPay(o, inst.castTag(.wrap_errunion_payload).?),
917 .wrap_errunion_err => try genWrapErrUnionErr(o, inst.castTag(.wrap_errunion_err).?),
918 .br_block_flat => return o.dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement codegen for br_block_flat", .{}),
919 .ptrtoint => return o.dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement codegen for ptrtoint", .{}),
920 .varptr => try genVarPtr(o, inst.castTag(.varptr).?),
921 .floatcast => return o.dg.fail(.{ .node_offset = 0 }, "TODO: C backend: implement codegen for floatcast", .{}),
853 const air_tags = o.air.instructions.items(.tag);
854
855 for (body) |inst| {
856 const result_value = switch (air_tags[inst]) {
857 //// TODO use a different strategy for add that communicates to the optimizer
858 //// that wrapping is UB.
859 //.add => try genBinOp(o, inst.castTag(.add).?, " + "),
860 //.addwrap => try genWrapOp(o, inst.castTag(.addwrap).?, " + ", "addw_"),
861 //// TODO use a different strategy for sub that communicates to the optimizer
862 //// that wrapping is UB.
863 //.sub => try genBinOp(o, inst.castTag(.sub).?, " - "),
864 //.subwrap => try genWrapOp(o, inst.castTag(.subwrap).?, " - ", "subw_"),
865 //// TODO use a different strategy for mul that communicates to the optimizer
866 //// that wrapping is UB.
867 //.mul => try genBinOp(o, inst.castTag(.sub).?, " * "),
868 //.mulwrap => try genWrapOp(o, inst.castTag(.mulwrap).?, " * ", "mulw_"),
869 //// TODO use a different strategy for div that communicates to the optimizer
870 //// that wrapping is UB.
871 //.div => try genBinOp(o, inst.castTag(.div).?, " / "),
872
873 //.constant => unreachable, // excluded from function bodies
874 //.alloc => try genAlloc(o, inst.castTag(.alloc).?),
875 //.arg => genArg(o),
876 //.assembly => try genAsm(o, inst.castTag(.assembly).?),
877 //.block => try genBlock(o, inst.castTag(.block).?),
878 //.bitcast => try genBitcast(o, inst.castTag(.bitcast).?),
879 //.breakpoint => try genBreakpoint(o, inst.castTag(.breakpoint).?),
880 //.call => try genCall(o, inst.castTag(.call).?),
881 //.cmp_eq => try genBinOp(o, inst.castTag(.cmp_eq).?, " == "),
882 //.cmp_gt => try genBinOp(o, inst.castTag(.cmp_gt).?, " > "),
883 //.cmp_gte => try genBinOp(o, inst.castTag(.cmp_gte).?, " >= "),
884 //.cmp_lt => try genBinOp(o, inst.castTag(.cmp_lt).?, " < "),
885 //.cmp_lte => try genBinOp(o, inst.castTag(.cmp_lte).?, " <= "),
886 //.cmp_neq => try genBinOp(o, inst.castTag(.cmp_neq).?, " != "),
887 //.dbg_stmt => try genDbgStmt(o, inst.castTag(.dbg_stmt).?),
888 //.intcast => try genIntCast(o, inst.castTag(.intcast).?),
889 //.load => try genLoad(o, inst.castTag(.load).?),
890 //.ret => try genRet(o, inst.castTag(.ret).?),
891 //.retvoid => try genRetVoid(o),
892 //.store => try genStore(o, inst.castTag(.store).?),
893 //.unreach => try genUnreach(o, inst.castTag(.unreach).?),
894 //.loop => try genLoop(o, inst.castTag(.loop).?),
895 //.condbr => try genCondBr(o, inst.castTag(.condbr).?),
896 //.br => try genBr(o, inst.castTag(.br).?),
897 //.br_void => try genBrVoid(o, inst.castTag(.br_void).?.block),
898 //.switchbr => try genSwitchBr(o, inst.castTag(.switchbr).?),
899 //// bool_and and bool_or are non-short-circuit operations
900 //.bool_and => try genBinOp(o, inst.castTag(.bool_and).?, " & "),
901 //.bool_or => try genBinOp(o, inst.castTag(.bool_or).?, " | "),
902 //.bit_and => try genBinOp(o, inst.castTag(.bit_and).?, " & "),
903 //.bit_or => try genBinOp(o, inst.castTag(.bit_or).?, " | "),
904 //.xor => try genBinOp(o, inst.castTag(.xor).?, " ^ "),
905 //.not => try genUnOp(o, inst.castTag(.not).?, "!"),
906 //.is_null => try genIsNull(o, inst.castTag(.is_null).?),
907 //.is_non_null => try genIsNull(o, inst.castTag(.is_non_null).?),
908 //.is_null_ptr => try genIsNull(o, inst.castTag(.is_null_ptr).?),
909 //.is_non_null_ptr => try genIsNull(o, inst.castTag(.is_non_null_ptr).?),
910 //.wrap_optional => try genWrapOptional(o, inst.castTag(.wrap_optional).?),
911 //.optional_payload => try genOptionalPayload(o, inst.castTag(.optional_payload).?),
912 //.optional_payload_ptr => try genOptionalPayload(o, inst.castTag(.optional_payload_ptr).?),
913 //.ref => try genRef(o, inst.castTag(.ref).?),
914 //.struct_field_ptr => try genStructFieldPtr(o, inst.castTag(.struct_field_ptr).?),
915
916 //.is_err => try genIsErr(o, inst.castTag(.is_err).?, "", ".", "!="),
917 //.is_non_err => try genIsErr(o, inst.castTag(.is_non_err).?, "", ".", "=="),
918 //.is_err_ptr => try genIsErr(o, inst.castTag(.is_err_ptr).?, "*", "->", "!="),
919 //.is_non_err_ptr => try genIsErr(o, inst.castTag(.is_non_err_ptr).?, "*", "->", "=="),
920
921 //.unwrap_errunion_payload => try genUnwrapErrUnionPay(o, inst.castTag(.unwrap_errunion_payload).?),
922 //.unwrap_errunion_err => try genUnwrapErrUnionErr(o, inst.castTag(.unwrap_errunion_err).?),
923 //.unwrap_errunion_payload_ptr => try genUnwrapErrUnionPay(o, inst.castTag(.unwrap_errunion_payload_ptr).?),
924 //.unwrap_errunion_err_ptr => try genUnwrapErrUnionErr(o, inst.castTag(.unwrap_errunion_err_ptr).?),
925 //.wrap_errunion_payload => try genWrapErrUnionPay(o, inst.castTag(.wrap_errunion_payload).?),
926 //.wrap_errunion_err => try genWrapErrUnionErr(o, inst.castTag(.wrap_errunion_err).?),
927 //.br_block_flat => return o.dg.fail("TODO: C backend: implement codegen for br_block_flat", .{}),
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", .{}),
922932 };
923933 switch (result_value) {
924934 .none => {},
......@@ -1060,7 +1070,7 @@ fn genWrapOp(o: *Object, inst: *Inst.BinOp, str_op: [*:0]const u8, fn_op: [*:0]c
10601070 }
10611071
10621072 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", .{});
10641074 }
10651075
10661076 var min_buf: [80]u8 = undefined;
......@@ -1227,7 +1237,7 @@ fn genCall(o: *Object, inst: *Inst.Call) !CValue {
12271237 try writer.writeAll(");\n");
12281238 return result_local;
12291239 } 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", .{});
12311241 }
12321242}
12331243
......@@ -1390,13 +1400,13 @@ fn genAsm(o: *Object, as: *Inst.Assembly) !CValue {
13901400 try o.writeCValue(writer, arg_c_value);
13911401 try writer.writeAll(";\n");
13921402 } 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", .{});
13941404 }
13951405 }
13961406 const volatile_string: []const u8 = if (as.is_volatile) "volatile " else "";
13971407 try writer.print("__asm {s}(\"{s}\"", .{ volatile_string, as.asm_source });
13981408 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", .{});
14001410 }
14011411 if (as.inputs.len > 0) {
14021412 if (as.output_constraint == null) {
......@@ -1421,7 +1431,7 @@ fn genAsm(o: *Object, as: *Inst.Assembly) !CValue {
14211431 if (as.base.isUnused())
14221432 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", .{});
14251435}
14261436
14271437fn 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 {
25192519 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
25202520 defer code_buffer.deinit();
25212521
2522 var dbg_line_buffer = std.ArrayList(u8).init(self.base.allocator);
2523 defer dbg_line_buffer.deinit();
2524
25222525 var dbg_info_buffer = std.ArrayList(u8).init(self.base.allocator);
25232526 defer dbg_info_buffer.deinit();
25242527
src/value.zig+1-1
......@@ -1700,7 +1700,7 @@ pub const Value = extern union {
17001700 /// peer type resolution. This is stored in a separate list so that
17011701 /// the items are contiguous in memory and thus can be passed to
17021702 /// `Module.resolvePeerTypes`.
1703 stored_inst_list: std.ArrayListUnmanaged(*ir.Inst) = .{},
1703 stored_inst_list: std.ArrayListUnmanaged(Air.Inst.Index) = .{},
17041704 },
17051705 };
17061706