authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-11 16:32:11-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-20 12:19:16-07:00
logef7080aed1a1a4dc54cb837938e462b4e6720734
tree0055927bdd4f59d94260733fc6d56fc99544b32a
parent9918a5fbe3dc910f90f2c60ad74edb51de53e0cf

stage2: update Liveness, SPIR-V for new AIR memory layout

also do the inline assembly instruction

7 files changed, 595 insertions(+), 577 deletions(-)

BRANCH_TODO-44
......@@ -1,24 +1,6 @@
11 * be sure to test debug info of parameters
22
33
4 /// Each bit represents the index of an `Inst` parameter in the `args` field.
5 /// If a bit is set, it marks the end of the lifetime of the corresponding
6 /// instruction parameter. For example, 0b101 means that the first and
7 /// third `Inst` parameters' lifetimes end after this instruction, and will
8 /// not have any more following references.
9 /// The most significant bit being set means that the instruction itself is
10 /// never referenced, in other words its lifetime ends as soon as it finishes.
11 /// If bit 15 (0b1xxx_xxxx_xxxx_xxxx) is set, it means this instruction itself is unreferenced.
12 /// If bit 14 (0bx1xx_xxxx_xxxx_xxxx) is set, it means this is a special case and the
13 /// lifetimes of operands are encoded elsewhere.
14 deaths: DeathsInt = undefined,
15
16
17 pub const DeathsInt = u16;
18 pub const DeathsBitIndex = std.math.Log2Int(DeathsInt);
19 pub const unreferenced_bit_index = @typeInfo(DeathsInt).Int.bits - 1;
20 pub const deaths_bits = unreferenced_bit_index - 1;
21
224 pub fn isUnused(self: Inst) bool {
235 return (self.deaths & (1 << unreferenced_bit_index)) != 0;
246 }
......@@ -115,32 +97,6 @@
11597
11698
11799
118 pub const Assembly = struct {
119 pub const base_tag = Tag.assembly;
120
121 base: Inst,
122 asm_source: []const u8,
123 is_volatile: bool,
124 output_constraint: ?[]const u8,
125 inputs: []const []const u8,
126 clobbers: []const []const u8,
127 args: []const *Inst,
128
129 pub fn operandCount(self: *const Assembly) usize {
130 return self.args.len;
131 }
132 pub fn getOperand(self: *const Assembly, index: usize) ?*Inst {
133 if (index < self.args.len)
134 return self.args[index];
135 return null;
136 }
137 };
138
139 pub const StructFieldPtr = struct {
140 struct_ptr: *Inst,
141 field_index: usize,
142 };
143
144100
145101/// For debugging purposes, prints a function representation to stderr.
146102pub fn dumpFn(old_module: Module, module_fn: *Module.Fn) void {
src/Air.zig+45-15
......@@ -1,5 +1,7 @@
11//! Analyzed Intermediate Representation.
2//! Sema inputs ZIR and outputs AIR.
2//! This data is produced by Sema and consumed by codegen.
3//! Unlike ZIR where there is one instance for an entire source file, each function
4//! gets its own `Air` instance.
35
46const std = @import("std");
57const Value = @import("value.zig").Value;
......@@ -27,38 +29,48 @@ pub const Inst = struct {
2729 data: Data,
2830
2931 pub const Tag = enum(u8) {
32 /// The first N instructions in Air must be one arg instruction per function parameter.
33 /// Uses the `ty` field.
34 arg,
3035 /// Float or integer addition. For integers, wrapping is undefined behavior.
31 /// Result type is the same as both operands.
36 /// Both operands are guaranteed to be the same type, and the result type
37 /// is the same as both operands.
3238 /// Uses the `bin_op` field.
3339 add,
3440 /// Integer addition. Wrapping is defined to be twos complement wrapping.
35 /// Result type is the same as both operands.
41 /// Both operands are guaranteed to be the same type, and the result type
42 /// is the same as both operands.
3643 /// Uses the `bin_op` field.
3744 addwrap,
3845 /// Float or integer subtraction. For integers, wrapping is undefined behavior.
39 /// Result type is the same as both operands.
46 /// Both operands are guaranteed to be the same type, and the result type
47 /// is the same as both operands.
4048 /// Uses the `bin_op` field.
4149 sub,
4250 /// Integer subtraction. Wrapping is defined to be twos complement wrapping.
43 /// Result type is the same as both operands.
51 /// Both operands are guaranteed to be the same type, and the result type
52 /// is the same as both operands.
4453 /// Uses the `bin_op` field.
4554 subwrap,
4655 /// Float or integer multiplication. For integers, wrapping is undefined behavior.
47 /// Result type is the same as both operands.
56 /// Both operands are guaranteed to be the same type, and the result type
57 /// is the same as both operands.
4858 /// Uses the `bin_op` field.
4959 mul,
5060 /// Integer multiplication. Wrapping is defined to be twos complement wrapping.
51 /// Result type is the same as both operands.
61 /// Both operands are guaranteed to be the same type, and the result type
62 /// is the same as both operands.
5263 /// Uses the `bin_op` field.
5364 mulwrap,
5465 /// Integer or float division. For integers, wrapping is undefined behavior.
55 /// Result type is the same as both operands.
66 /// Both operands are guaranteed to be the same type, and the result type
67 /// is the same as both operands.
5668 /// Uses the `bin_op` field.
5769 div,
5870 /// Allocates stack local memory.
5971 /// Uses the `ty` field.
6072 alloc,
61 /// TODO
73 /// Inline assembly. Uses the `ty_pl` field. Payload is `Asm`.
6274 assembly,
6375 /// Bitwise AND. `&`.
6476 /// Result type is the same as both operands.
......@@ -80,7 +92,7 @@ pub const Inst = struct {
8092 /// Uses the `ty_pl` field with payload `Block`.
8193 block,
8294 /// Return from a block with a result.
83 /// Result type is always noreturn.
95 /// Result type is always noreturn; no instructions in a block follow this one.
8496 /// Uses the `br` field.
8597 br,
8698 /// Lowers to a hardware trap instruction, or the next best thing.
......@@ -109,11 +121,11 @@ pub const Inst = struct {
109121 /// Uses the `bin_op` field.
110122 cmp_neq,
111123 /// Conditional branch.
112 /// Result type is always noreturn.
124 /// Result type is always noreturn; no instructions in a block follow this one.
113125 /// Uses the `pl_op` field. Operand is the condition. Payload is `CondBr`.
114126 cond_br,
115127 /// Switch branch.
116 /// Result type is always noreturn.
128 /// Result type is always noreturn; no instructions in a block follow this one.
117129 /// Uses the `pl_op` field. Operand is the condition. Payload is `SwitchBr`.
118130 switch_br,
119131 /// A comptime-known value. Uses the `ty_pl` field, payload is index of
......@@ -166,7 +178,7 @@ pub const Inst = struct {
166178 load,
167179 /// A labeled block of code that loops forever. At the end of the body it is implied
168180 /// to repeat; no explicit "repeat" instruction terminates loop bodies.
169 /// Result type is always noreturn.
181 /// Result type is always noreturn; no instructions in a block follow this one.
170182 /// Uses the `ty_pl` field. Payload is `Block`.
171183 loop,
172184 /// Converts a pointer to its address. Result type is always `usize`.
......@@ -178,7 +190,7 @@ pub const Inst = struct {
178190 /// Uses the `ty_op` field.
179191 ref,
180192 /// Return a value from a function.
181 /// Result type is always noreturn.
193 /// Result type is always noreturn; no instructions in a block follow this one.
182194 /// Uses the `un_op` field.
183195 ret,
184196 /// Returns a pointer to a global variable.
......@@ -189,7 +201,7 @@ pub const Inst = struct {
189201 /// Uses the `bin_op` field.
190202 store,
191203 /// Indicates the program counter will never get to this instruction.
192 /// Result type is always noreturn.
204 /// Result type is always noreturn; no instructions in a block follow this one.
193205 unreach,
194206 /// Convert from one float type to another.
195207 /// Uses the `ty_op` field.
......@@ -343,6 +355,16 @@ pub const StructField = struct {
343355 field_index: u32,
344356};
345357
358/// Trailing:
359/// 0. `Ref` for every outputs_len
360/// 1. `Ref` for every inputs_len
361pub const Asm = struct {
362 /// Index to the corresponding ZIR instruction.
363 /// `asm_source`, `outputs_len`, `inputs_len`, `clobbers_len`, `is_volatile`, and
364 /// clobbers are found via here.
365 zir_index: u32,
366};
367
346368pub fn getMainBody(air: Air) []const Air.Inst.Index {
347369 const body_index = air.extra[@enumToInt(ExtraIndex.main_block)];
348370 const body_len = air.extra[body_index];
......@@ -369,3 +391,11 @@ pub fn extraData(air: Air, comptime T: type, index: usize) struct { data: T, end
369391 .end = i,
370392 };
371393}
394
395pub fn deinit(air: *Air, gpa: *std.mem.Allocator) void {
396 air.instructions.deinit(gpa);
397 gpa.free(air.extra);
398 gpa.free(air.values);
399 gpa.free(air.variables);
400 air.* = undefined;
401}
src/Compilation.zig+40-17
......@@ -13,7 +13,7 @@ const target_util = @import("target.zig");
1313const Package = @import("Package.zig");
1414const link = @import("link.zig");
1515const trace = @import("tracy.zig").trace;
16const liveness = @import("liveness.zig");
16const Liveness = @import("Liveness.zig");
1717const build_options = @import("build_options");
1818const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
1919const glibc = @import("glibc.zig");
......@@ -1922,6 +1922,7 @@ pub fn getCompileLogOutput(self: *Compilation) []const u8 {
19221922}
19231923
19241924pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemory }!void {
1925 const gpa = self.gpa;
19251926 // If the terminal is dumb, we dont want to show the user all the
19261927 // output.
19271928 var progress: std.Progress = .{ .dont_print_on_dumb = true };
......@@ -2005,7 +2006,8 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
20052006 assert(decl.has_tv);
20062007 if (decl.val.castTag(.function)) |payload| {
20072008 const func = payload.data;
2008 switch (func.state) {
2009
2010 var air = switch (func.state) {
20092011 .queued => module.analyzeFnBody(decl, func) catch |err| switch (err) {
20102012 error.AnalysisFail => {
20112013 assert(func.state != .in_progress);
......@@ -2016,18 +2018,39 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
20162018 .in_progress => unreachable,
20172019 .inline_only => unreachable, // don't queue work for this
20182020 .sema_failure, .dependency_failure => continue,
2019 .success => {},
2020 }
2021 // Here we tack on additional allocations to the Decl's arena. The allocations
2022 // are lifetime annotations in the ZIR.
2023 var decl_arena = decl.value_arena.?.promote(module.gpa);
2024 defer decl.value_arena.?.* = decl_arena.state;
2021 .success => unreachable, // don't queue it twice
2022 };
2023 defer air.deinit(gpa);
2024
20252025 log.debug("analyze liveness of {s}", .{decl.name});
2026 try liveness.analyze(module.gpa, &decl_arena.allocator, func.body);
2026 var liveness = try Liveness.analyze(gpa, air);
2027 defer liveness.deinit(gpa);
20272028
20282029 if (std.builtin.mode == .Debug and self.verbose_air) {
20292030 func.dump(module.*);
20302031 }
2032
2033 assert(decl.ty.hasCodeGenBits());
2034
2035 self.bin_file.updateFunc(module, func, air, liveness) catch |err| switch (err) {
2036 error.OutOfMemory => return error.OutOfMemory,
2037 error.AnalysisFail => {
2038 decl.analysis = .codegen_failure;
2039 continue;
2040 },
2041 else => {
2042 try module.failed_decls.ensureUnusedCapacity(gpa, 1);
2043 module.failed_decls.putAssumeCapacityNoClobber(decl, try Module.ErrorMsg.create(
2044 gpa,
2045 decl.srcLoc(),
2046 "unable to codegen: {s}",
2047 .{@errorName(err)},
2048 ));
2049 decl.analysis = .codegen_failure_retryable;
2050 continue;
2051 },
2052 };
2053 continue;
20312054 }
20322055
20332056 assert(decl.ty.hasCodeGenBits());
......@@ -2039,9 +2062,9 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
20392062 continue;
20402063 },
20412064 else => {
2042 try module.failed_decls.ensureCapacity(module.gpa, module.failed_decls.count() + 1);
2065 try module.failed_decls.ensureCapacity(gpa, module.failed_decls.count() + 1);
20432066 module.failed_decls.putAssumeCapacityNoClobber(decl, try Module.ErrorMsg.create(
2044 module.gpa,
2067 gpa,
20452068 decl.srcLoc(),
20462069 "unable to codegen: {s}",
20472070 .{@errorName(err)},
......@@ -2070,7 +2093,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
20702093 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
20712094 const module = self.bin_file.options.module.?;
20722095 const emit_h = module.emit_h.?;
2073 _ = try emit_h.decl_table.getOrPut(module.gpa, decl);
2096 _ = try emit_h.decl_table.getOrPut(gpa, decl);
20742097 const decl_emit_h = decl.getEmitH(module);
20752098 const fwd_decl = &decl_emit_h.fwd_decl;
20762099 fwd_decl.shrinkRetainingCapacity(0);
......@@ -2079,7 +2102,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
20792102 .module = module,
20802103 .error_msg = null,
20812104 .decl = decl,
2082 .fwd_decl = fwd_decl.toManaged(module.gpa),
2105 .fwd_decl = fwd_decl.toManaged(gpa),
20832106 // we don't want to emit optionals and error unions to headers since they have no ABI
20842107 .typedefs = undefined,
20852108 };
......@@ -2087,14 +2110,14 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
20872110
20882111 c_codegen.genHeader(&dg) catch |err| switch (err) {
20892112 error.AnalysisFail => {
2090 try emit_h.failed_decls.put(module.gpa, decl, dg.error_msg.?);
2113 try emit_h.failed_decls.put(gpa, decl, dg.error_msg.?);
20912114 continue;
20922115 },
20932116 else => |e| return e,
20942117 };
20952118
20962119 fwd_decl.* = dg.fwd_decl.moveToUnmanaged();
2097 fwd_decl.shrinkAndFree(module.gpa, fwd_decl.items.len);
2120 fwd_decl.shrinkAndFree(gpa, fwd_decl.items.len);
20982121 },
20992122 },
21002123 .analyze_decl => |decl| {
......@@ -2111,9 +2134,9 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
21112134 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
21122135 const module = self.bin_file.options.module.?;
21132136 self.bin_file.updateDeclLineNumber(module, decl) catch |err| {
2114 try module.failed_decls.ensureCapacity(module.gpa, module.failed_decls.count() + 1);
2137 try module.failed_decls.ensureCapacity(gpa, module.failed_decls.count() + 1);
21152138 module.failed_decls.putAssumeCapacityNoClobber(decl, try Module.ErrorMsg.create(
2116 module.gpa,
2139 gpa,
21172140 decl.srcLoc(),
21182141 "unable to update line number: {s}",
21192142 .{@errorName(err)},
src/Liveness.zig+1
......@@ -150,6 +150,7 @@ fn analyzeInst(
150150 const gpa = a.gpa;
151151 const table = &a.table;
152152 const inst_tags = a.air.instructions.items(.tag);
153 const inst_datas = a.air.instructions.items(.data);
153154
154155 // No tombstone for this instruction means it is never referenced,
155156 // and its birth marks its own death. Very metal 🤘
src/Module.zig+25-11
......@@ -739,8 +739,6 @@ pub const Union = struct {
739739pub const Fn = struct {
740740 /// The Decl that corresponds to the function itself.
741741 owner_decl: *Decl,
742 /// undefined unless analysis state is `success`.
743 body: ir.Body,
744742 /// The ZIR instruction that is a function instruction. Use this to find
745743 /// the body. We store this rather than the body directly so that when ZIR
746744 /// is regenerated on update(), we can map this to the new corresponding
......@@ -3585,17 +3583,19 @@ fn deleteDeclExports(mod: *Module, decl: *Decl) void {
35853583 mod.gpa.free(kv.value);
35863584}
35873585
3588pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !void {
3586pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !Air {
35893587 const tracy = trace(@src());
35903588 defer tracy.end();
35913589
3590 const gpa = mod.gpa;
3591
35923592 // Use the Decl's arena for function memory.
3593 var arena = decl.value_arena.?.promote(mod.gpa);
3593 var arena = decl.value_arena.?.promote(gpa);
35943594 defer decl.value_arena.?.* = arena.state;
35953595
35963596 const fn_ty = decl.ty;
3597 const param_inst_list = try mod.gpa.alloc(*ir.Inst, fn_ty.fnParamLen());
3598 defer mod.gpa.free(param_inst_list);
3597 const param_inst_list = try gpa.alloc(*ir.Inst, fn_ty.fnParamLen());
3598 defer gpa.free(param_inst_list);
35993599
36003600 for (param_inst_list) |*param_inst, param_index| {
36013601 const param_type = fn_ty.fnParamType(param_index);
......@@ -3615,7 +3615,7 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !void {
36153615
36163616 var sema: Sema = .{
36173617 .mod = mod,
3618 .gpa = mod.gpa,
3618 .gpa = gpa,
36193619 .arena = &arena.allocator,
36203620 .code = zir,
36213621 .owner_decl = decl,
......@@ -3626,6 +3626,11 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !void {
36263626 };
36273627 defer sema.deinit();
36283628
3629 // First few indexes of extra are reserved and set at the end.
3630 const reserved_count = @typeInfo(Air.ExtraIndex).Enum.fields.len;
3631 try sema.air_extra.ensureTotalCapacity(gpa, reserved_count);
3632 sema.air_extra.items.len += reserved_count;
3633
36293634 var inner_block: Scope.Block = .{
36303635 .parent = null,
36313636 .sema = &sema,
......@@ -3634,20 +3639,29 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !void {
36343639 .inlining = null,
36353640 .is_comptime = false,
36363641 };
3637 defer inner_block.instructions.deinit(mod.gpa);
3642 defer inner_block.instructions.deinit(gpa);
36383643
36393644 // AIR currently requires the arg parameters to be the first N instructions
3640 try inner_block.instructions.appendSlice(mod.gpa, param_inst_list);
3645 try inner_block.instructions.appendSlice(gpa, param_inst_list);
36413646
36423647 func.state = .in_progress;
36433648 log.debug("set {s} to in_progress", .{decl.name});
36443649
36453650 try sema.analyzeFnBody(&inner_block, func.zir_body_inst);
36463651
3647 const instructions = try arena.allocator.dupe(*ir.Inst, inner_block.instructions.items);
3652 // Copy the block into place and mark that as the main block.
3653 sema.air_extra.items[@enumToInt(Air.ExtraIndex.main_block)] = sema.air_extra.items.len;
3654 try sema.air_extra.appendSlice(inner_block.instructions.items);
3655
36483656 func.state = .success;
3649 func.body = .{ .instructions = instructions };
36503657 log.debug("set {s} to success", .{decl.name});
3658
3659 return Air{
3660 .instructions = sema.air_instructions.toOwnedSlice(),
3661 .extra = sema.air_extra.toOwnedSlice(),
3662 .values = sema.air_values.toOwnedSlice(),
3663 .variables = sema.air_variables.toOwnedSlice(),
3664 };
36513665}
36523666
36533667fn markOutdatedDecl(mod: *Module, decl: *Decl) !void {
src/Sema.zig+286-277
......@@ -1,6 +1,6 @@
11//! Semantic analysis of ZIR instructions.
22//! Shared to every Block. Stored on the stack.
3//! State used for compiling a `Zir` into AIR.
3//! State used for compiling a ZIR into AIR.
44//! Transforms untyped ZIR instructions into semantically-analyzed AIR instructions.
55//! Does type checking, comptime control flow, and safety-check generation.
66//! This is the the heart of the Zig compiler.
......@@ -11,6 +11,10 @@ gpa: *Allocator,
1111/// Points to the arena allocator of the Decl.
1212arena: *Allocator,
1313code: Zir,
14air_instructions: std.MultiArrayList(Air.Inst) = .{},
15air_extra: ArrayListUnmanaged(u32) = .{},
16air_values: ArrayListUnmanaged(Value) = .{},
17air_variables: ArrayListUnmanaged(Module.Var) = .{},
1418/// Maps ZIR to AIR.
1519inst_map: InstMap = .{},
1620/// When analyzing an inline function call, owner_decl is the Decl of the caller
......@@ -32,7 +36,7 @@ func: ?*Module.Fn,
3236/// > Denormalized data to make `resolveInst` faster. This is 0 if not inside a function,
3337/// > otherwise it is the number of parameters of the function.
3438/// > param_count: u32
35param_inst_list: []const *ir.Inst,
39param_inst_list: []const Air.Inst.Index,
3640branch_quota: u32 = 1000,
3741branch_count: u32 = 0,
3842/// This field is updated when a new source location becomes active, so that
......@@ -65,10 +69,15 @@ const LazySrcLoc = Module.LazySrcLoc;
6569const RangeSet = @import("RangeSet.zig");
6670const target_util = @import("target.zig");
6771
68pub const InstMap = std.AutoHashMapUnmanaged(Zir.Inst.Index, *ir.Inst);
72pub const InstMap = std.AutoHashMapUnmanaged(Zir.Inst.Index, Air.Inst.Index);
6973
7074pub fn deinit(sema: *Sema) void {
71 sema.inst_map.deinit(sema.gpa);
75 const gpa = sema.gpa;
76 sema.air_instructions.deinit(gpa);
77 sema.air_extra.deinit(gpa);
78 sema.air_values.deinit(gpa);
79 sema.air_variables.deinit(gpa);
80 sema.inst_map.deinit(gpa);
7281 sema.* = undefined;
7382}
7483
......@@ -108,7 +117,7 @@ pub fn analyzeFnBody(
108117/// Returns only the result from the body that is specified.
109118/// Only appropriate to call when it is determined at comptime that this body
110119/// has no peers.
111fn resolveBody(sema: *Sema, block: *Scope.Block, body: []const Zir.Inst.Index) InnerError!*Inst {
120fn resolveBody(sema: *Sema, block: *Scope.Block, body: []const Zir.Inst.Index) InnerError!Air.Inst.Index {
112121 const break_inst = try sema.analyzeBody(block, body);
113122 const operand_ref = sema.code.instructions.items(.data)[break_inst].@"break".operand;
114123 return sema.resolveInst(operand_ref);
......@@ -533,7 +542,7 @@ pub fn analyzeBody(
533542 }
534543}
535544
536fn zirExtended(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
545fn zirExtended(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
537546 const extended = sema.code.instructions.items(.data)[inst].extended;
538547 switch (extended.opcode) {
539548 // zig fmt: off
......@@ -569,7 +578,7 @@ fn zirExtended(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
569578}
570579
571580/// TODO when we rework AIR memory layout, this function will no longer have a possible error.
572pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) error{OutOfMemory}!*ir.Inst {
581pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) error{OutOfMemory}!Air.Inst.Index {
573582 var i: usize = @enumToInt(zir_ref);
574583
575584 // First section of indexes correspond to a set number of constant values.
......@@ -618,19 +627,19 @@ pub fn resolveType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, zir_ref: Z
618627 return sema.resolveAirAsType(block, src, air_inst);
619628}
620629
621fn resolveAirAsType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, air_inst: *ir.Inst) !Type {
630fn resolveAirAsType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, air_inst: Air.Inst.Index) !Type {
622631 const wanted_type = Type.initTag(.@"type");
623632 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
624633 const val = try sema.resolveConstValue(block, src, coerced_inst);
625634 return val.toType(sema.arena);
626635}
627636
628fn resolveConstValue(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, base: *ir.Inst) !Value {
637fn resolveConstValue(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, base: Air.Inst.Index) !Value {
629638 return (try sema.resolveDefinedValue(block, src, base)) orelse
630639 return sema.failWithNeededComptime(block, src);
631640}
632641
633fn resolveDefinedValue(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, base: *ir.Inst) !?Value {
642fn resolveDefinedValue(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, base: Air.Inst.Index) !?Value {
634643 if (try sema.resolvePossiblyUndefinedValue(block, src, base)) |val| {
635644 if (val.isUndef()) {
636645 return sema.failWithUseOfUndef(block, src);
......@@ -644,7 +653,7 @@ fn resolvePossiblyUndefinedValue(
644653 sema: *Sema,
645654 block: *Scope.Block,
646655 src: LazySrcLoc,
647 base: *ir.Inst,
656 base: Air.Inst.Index,
648657) !?Value {
649658 if (try sema.typeHasOnePossibleValue(block, src, base.ty)) |opv| {
650659 return opv;
......@@ -708,13 +717,13 @@ pub fn resolveInstConst(
708717 };
709718}
710719
711fn zirBitcastResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
720fn zirBitcastResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
712721 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
713722 const src = inst_data.src();
714723 return sema.mod.fail(&block.base, src, "TODO implement zir_sema.zirBitcastResultPtr", .{});
715724}
716725
717fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
726fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
718727 _ = inst;
719728 const tracy = trace(@src());
720729 defer tracy.end();
......@@ -749,7 +758,7 @@ fn zirStructDecl(
749758 block: *Scope.Block,
750759 extended: Zir.Inst.Extended.InstData,
751760 inst: Zir.Inst.Index,
752) InnerError!*Inst {
761) InnerError!Air.Inst.Index {
753762 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
754763 const src: LazySrcLoc = if (small.has_src_node) blk: {
755764 const node_offset = @bitCast(i32, sema.code.extra[extended.operand]);
......@@ -820,7 +829,7 @@ fn zirEnumDecl(
820829 sema: *Sema,
821830 block: *Scope.Block,
822831 extended: Zir.Inst.Extended.InstData,
823) InnerError!*Inst {
832) InnerError!Air.Inst.Index {
824833 const tracy = trace(@src());
825834 defer tracy.end();
826835
......@@ -1017,7 +1026,7 @@ fn zirUnionDecl(
10171026 block: *Scope.Block,
10181027 extended: Zir.Inst.Extended.InstData,
10191028 inst: Zir.Inst.Index,
1020) InnerError!*Inst {
1029) InnerError!Air.Inst.Index {
10211030 const tracy = trace(@src());
10221031 defer tracy.end();
10231032
......@@ -1081,7 +1090,7 @@ fn zirOpaqueDecl(
10811090 block: *Scope.Block,
10821091 inst: Zir.Inst.Index,
10831092 name_strategy: Zir.Inst.NameStrategy,
1084) InnerError!*Inst {
1093) InnerError!Air.Inst.Index {
10851094 const tracy = trace(@src());
10861095 defer tracy.end();
10871096
......@@ -1101,7 +1110,7 @@ fn zirErrorSetDecl(
11011110 block: *Scope.Block,
11021111 inst: Zir.Inst.Index,
11031112 name_strategy: Zir.Inst.NameStrategy,
1104) InnerError!*Inst {
1113) InnerError!Air.Inst.Index {
11051114 const tracy = trace(@src());
11061115 defer tracy.end();
11071116
......@@ -1141,7 +1150,7 @@ fn zirRetPtr(
11411150 sema: *Sema,
11421151 block: *Scope.Block,
11431152 extended: Zir.Inst.Extended.InstData,
1144) InnerError!*Inst {
1153) InnerError!Air.Inst.Index {
11451154 const tracy = trace(@src());
11461155 defer tracy.end();
11471156
......@@ -1153,7 +1162,7 @@ fn zirRetPtr(
11531162 return block.addNoOp(src, ptr_type, .alloc);
11541163}
11551164
1156fn zirRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1165fn zirRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
11571166 const tracy = trace(@src());
11581167 defer tracy.end();
11591168
......@@ -1166,7 +1175,7 @@ fn zirRetType(
11661175 sema: *Sema,
11671176 block: *Scope.Block,
11681177 extended: Zir.Inst.Extended.InstData,
1169) InnerError!*Inst {
1178) InnerError!Air.Inst.Index {
11701179 const tracy = trace(@src());
11711180 defer tracy.end();
11721181
......@@ -1191,7 +1200,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) I
11911200fn ensureResultUsed(
11921201 sema: *Sema,
11931202 block: *Scope.Block,
1194 operand: *Inst,
1203 operand: Air.Inst.Index,
11951204 src: LazySrcLoc,
11961205) InnerError!void {
11971206 switch (operand.ty.zigTypeTag()) {
......@@ -1213,7 +1222,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
12131222 }
12141223}
12151224
1216fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1225fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
12171226 const tracy = trace(@src());
12181227 defer tracy.end();
12191228
......@@ -1247,7 +1256,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In
12471256 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);
12481257}
12491258
1250fn zirArg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1259fn zirArg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
12511260 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
12521261 const arg_name = inst_data.get(sema.code);
12531262 const arg_index = sema.next_arg_index;
......@@ -1269,13 +1278,13 @@ fn zirAllocExtended(
12691278 sema: *Sema,
12701279 block: *Scope.Block,
12711280 extended: Zir.Inst.Extended.InstData,
1272) InnerError!*Inst {
1281) InnerError!Air.Inst.Index {
12731282 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);
12741283 const src: LazySrcLoc = .{ .node_offset = extra.data.src_node };
12751284 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocExtended", .{});
12761285}
12771286
1278fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1287fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
12791288 const tracy = trace(@src());
12801289 defer tracy.end();
12811290
......@@ -1298,13 +1307,13 @@ fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
12981307 });
12991308}
13001309
1301fn zirAllocInferredComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1310fn zirAllocInferredComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
13021311 const src_node = sema.code.instructions.items(.data)[inst].node;
13031312 const src: LazySrcLoc = .{ .node_offset = src_node };
13041313 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocInferredComptime", .{});
13051314}
13061315
1307fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1316fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
13081317 const tracy = trace(@src());
13091318 defer tracy.end();
13101319
......@@ -1317,7 +1326,7 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*
13171326 return block.addNoOp(var_decl_src, ptr_type, .alloc);
13181327}
13191328
1320fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1329fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
13211330 const tracy = trace(@src());
13221331 defer tracy.end();
13231332
......@@ -1336,7 +1345,7 @@ fn zirAllocInferred(
13361345 block: *Scope.Block,
13371346 inst: Zir.Inst.Index,
13381347 inferred_alloc_ty: Type,
1339) InnerError!*Inst {
1348) InnerError!Air.Inst.Index {
13401349 const tracy = trace(@src());
13411350 defer tracy.end();
13421351
......@@ -1589,7 +1598,7 @@ fn zirStoreNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
15891598 return sema.storePtr(block, src, ptr, value);
15901599}
15911600
1592fn zirParamType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1601fn zirParamType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
15931602 const tracy = trace(@src());
15941603 defer tracy.end();
15951604
......@@ -1625,7 +1634,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
16251634 return sema.mod.constType(sema.arena, src, param_type);
16261635}
16271636
1628fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1637fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
16291638 const tracy = trace(@src());
16301639 defer tracy.end();
16311640
......@@ -1653,7 +1662,7 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In
16531662 return sema.analyzeDeclRef(block, .unneeded, new_decl);
16541663}
16551664
1656fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1665fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
16571666 _ = block;
16581667 const tracy = trace(@src());
16591668 defer tracy.end();
......@@ -1662,7 +1671,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In
16621671 return sema.mod.constIntUnsigned(sema.arena, .unneeded, Type.initTag(.comptime_int), int);
16631672}
16641673
1665fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1674fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
16661675 _ = block;
16671676 const tracy = trace(@src());
16681677 defer tracy.end();
......@@ -1680,7 +1689,7 @@ fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
16801689 });
16811690}
16821691
1683fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1692fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
16841693 _ = block;
16851694 const arena = sema.arena;
16861695 const inst_data = sema.code.instructions.items(.data)[inst].float;
......@@ -1693,7 +1702,7 @@ fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*
16931702 });
16941703}
16951704
1696fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1705fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
16971706 _ = block;
16981707 const arena = sema.arena;
16991708 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
......@@ -1722,7 +1731,7 @@ fn zirCompileLog(
17221731 sema: *Sema,
17231732 block: *Scope.Block,
17241733 extended: Zir.Inst.Extended.InstData,
1725) InnerError!*Inst {
1734) InnerError!Air.Inst.Index {
17261735 var managed = sema.mod.compile_log_text.toManaged(sema.gpa);
17271736 defer sema.mod.compile_log_text = managed.moveToUnmanaged();
17281737 const writer = managed.writer();
......@@ -1772,7 +1781,7 @@ fn zirPanic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Z
17721781 return sema.panicWithMsg(block, src, msg_inst);
17731782}
17741783
1775fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1784fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
17761785 const tracy = trace(@src());
17771786 defer tracy.end();
17781787
......@@ -1832,12 +1841,12 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerE
18321841 // Loop repetition is implied so the last instruction may or may not be a noreturn instruction.
18331842
18341843 try child_block.instructions.append(sema.gpa, &loop_inst.base);
1835 loop_inst.body = .{ .instructions = try sema.arena.dupe(*Inst, loop_block.instructions.items) };
1844 loop_inst.body = .{ .instructions = try sema.arena.dupe(Air.Inst.Index, loop_block.instructions.items) };
18361845
18371846 return sema.analyzeBlockBody(parent_block, src, &child_block, merges);
18381847}
18391848
1840fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1849fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
18411850 const tracy = trace(@src());
18421851 defer tracy.end();
18431852
......@@ -1847,13 +1856,13 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Inn
18471856 return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirCImport", .{});
18481857}
18491858
1850fn zirSuspendBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1859fn zirSuspendBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
18511860 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
18521861 const src = inst_data.src();
18531862 return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirSuspendBlock", .{});
18541863}
18551864
1856fn zirBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1865fn zirBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
18571866 const tracy = trace(@src());
18581867 defer tracy.end();
18591868
......@@ -1911,7 +1920,7 @@ fn resolveBlockBody(
19111920 child_block: *Scope.Block,
19121921 body: []const Zir.Inst.Index,
19131922 merges: *Scope.Block.Merges,
1914) InnerError!*Inst {
1923) InnerError!Air.Inst.Index {
19151924 _ = try sema.analyzeBody(child_block, body);
19161925 return sema.analyzeBlockBody(parent_block, src, child_block, merges);
19171926}
......@@ -1922,7 +1931,7 @@ fn analyzeBlockBody(
19221931 src: LazySrcLoc,
19231932 child_block: *Scope.Block,
19241933 merges: *Scope.Block.Merges,
1925) InnerError!*Inst {
1934) InnerError!Air.Inst.Index {
19261935 const tracy = trace(@src());
19271936 defer tracy.end();
19281937
......@@ -1933,7 +1942,7 @@ fn analyzeBlockBody(
19331942 if (merges.results.items.len == 0) {
19341943 // No need for a block instruction. We can put the new instructions
19351944 // directly into the parent block.
1936 const copied_instructions = try sema.arena.dupe(*Inst, child_block.instructions.items);
1945 const copied_instructions = try sema.arena.dupe(Air.Inst.Index, child_block.instructions.items);
19371946 try parent_block.instructions.appendSlice(sema.gpa, copied_instructions);
19381947 return copied_instructions[copied_instructions.len - 1];
19391948 }
......@@ -1944,7 +1953,7 @@ fn analyzeBlockBody(
19441953 if (br_block == merges.block_inst) {
19451954 // No need for a block instruction. We can put the new instructions directly
19461955 // into the parent block. Here we omit the break instruction.
1947 const copied_instructions = try sema.arena.dupe(*Inst, child_block.instructions.items[0..last_inst_index]);
1956 const copied_instructions = try sema.arena.dupe(Air.Inst.Index, child_block.instructions.items[0..last_inst_index]);
19481957 try parent_block.instructions.appendSlice(sema.gpa, copied_instructions);
19491958 return merges.results.items[0];
19501959 }
......@@ -1959,7 +1968,7 @@ fn analyzeBlockBody(
19591968 const resolved_ty = try sema.resolvePeerTypes(parent_block, src, merges.results.items);
19601969 merges.block_inst.base.ty = resolved_ty;
19611970 merges.block_inst.body = .{
1962 .instructions = try sema.arena.dupe(*Inst, child_block.instructions.items),
1971 .instructions = try sema.arena.dupe(Air.Inst.Index, child_block.instructions.items),
19631972 };
19641973 // Now that the block has its type resolved, we need to go back into all the break
19651974 // instructions, and insert type coercion on the operands.
......@@ -1991,7 +2000,7 @@ fn analyzeBlockBody(
19912000 },
19922001 .block = merges.block_inst,
19932002 .body = .{
1994 .instructions = try sema.arena.dupe(*Inst, coerce_block.instructions.items),
2003 .instructions = try sema.arena.dupe(Air.Inst.Index, coerce_block.instructions.items),
19952004 },
19962005 };
19972006 }
......@@ -2130,7 +2139,7 @@ fn zirDbgStmt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
21302139 _ = try block.addDbgStmt(.unneeded, inst_data.line, inst_data.column);
21312140}
21322141
2133fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2142fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
21342143 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
21352144 const src = inst_data.src();
21362145 const decl_name = inst_data.get(sema.code);
......@@ -2138,7 +2147,7 @@ fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
21382147 return sema.analyzeDeclRef(block, src, decl);
21392148}
21402149
2141fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2150fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
21422151 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
21432152 const src = inst_data.src();
21442153 const decl_name = inst_data.get(sema.code);
......@@ -2192,7 +2201,7 @@ fn zirCall(
21922201 inst: Zir.Inst.Index,
21932202 modifier: std.builtin.CallOptions.Modifier,
21942203 ensure_result_used: bool,
2195) InnerError!*Inst {
2204) InnerError!Air.Inst.Index {
21962205 const tracy = trace(@src());
21972206 defer tracy.end();
21982207
......@@ -2204,7 +2213,7 @@ fn zirCall(
22042213
22052214 const func = try sema.resolveInst(extra.data.callee);
22062215 // TODO handle function calls of generic functions
2207 const resolved_args = try sema.arena.alloc(*Inst, args.len);
2216 const resolved_args = try sema.arena.alloc(Air.Inst.Index, args.len);
22082217 for (args) |zir_arg, i| {
22092218 // the args are already casted to the result of a param type instruction.
22102219 resolved_args[i] = try sema.resolveInst(zir_arg);
......@@ -2216,13 +2225,13 @@ fn zirCall(
22162225fn analyzeCall(
22172226 sema: *Sema,
22182227 block: *Scope.Block,
2219 func: *ir.Inst,
2228 func: Air.Inst.Index,
22202229 func_src: LazySrcLoc,
22212230 call_src: LazySrcLoc,
22222231 modifier: std.builtin.CallOptions.Modifier,
22232232 ensure_result_used: bool,
2224 args: []const *ir.Inst,
2225) InnerError!*ir.Inst {
2233 args: []const Air.Inst.Index,
2234) InnerError!Air.Inst.Index {
22262235 if (func.ty.zigTypeTag() != .Fn)
22272236 return sema.mod.fail(&block.base, func_src, "type '{}' not a function", .{func.ty});
22282237
......@@ -2279,7 +2288,7 @@ fn analyzeCall(
22792288 const is_comptime_call = block.is_comptime or modifier == .compile_time;
22802289 const is_inline_call = is_comptime_call or modifier == .always_inline or
22812290 func.ty.fnCallingConvention() == .Inline;
2282 const result: *Inst = if (is_inline_call) res: {
2291 const result: Air.Inst.Index = if (is_inline_call) res: {
22832292 const func_val = try sema.resolveConstValue(block, func_src, func);
22842293 const module_fn = switch (func_val.tag()) {
22852294 .function => func_val.castTag(.function).?.data,
......@@ -2377,7 +2386,7 @@ fn analyzeCall(
23772386 return result;
23782387}
23792388
2380fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2389fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
23812390 _ = block;
23822391 const tracy = trace(@src());
23832392 defer tracy.end();
......@@ -2389,7 +2398,7 @@ fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
23892398 return sema.mod.constType(sema.arena, src, ty);
23902399}
23912400
2392fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2401fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
23932402 const tracy = trace(@src());
23942403 defer tracy.end();
23952404
......@@ -2401,7 +2410,7 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner
24012410 return sema.mod.constType(sema.arena, src, opt_type);
24022411}
24032412
2404fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2413fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
24052414 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
24062415 const src = inst_data.src();
24072416 const array_type = try sema.resolveType(block, src, inst_data.operand);
......@@ -2409,7 +2418,7 @@ fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
24092418 return sema.mod.constType(sema.arena, src, elem_type);
24102419}
24112420
2412fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2421fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
24132422 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
24142423 const src = inst_data.src();
24152424 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -2424,7 +2433,7 @@ fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
24242433 return sema.mod.constType(sema.arena, src, vector_type);
24252434}
24262435
2427fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2436fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
24282437 const tracy = trace(@src());
24292438 defer tracy.end();
24302439
......@@ -2437,7 +2446,7 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
24372446 return sema.mod.constType(sema.arena, .unneeded, array_ty);
24382447}
24392448
2440fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2449fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
24412450 const tracy = trace(@src());
24422451 defer tracy.end();
24432452
......@@ -2452,7 +2461,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)
24522461 return sema.mod.constType(sema.arena, .unneeded, array_ty);
24532462}
24542463
2455fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2464fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
24562465 const tracy = trace(@src());
24572466 defer tracy.end();
24582467
......@@ -2465,7 +2474,7 @@ fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner
24652474 return sema.mod.constType(sema.arena, src, anyframe_type);
24662475}
24672476
2468fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2477fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
24692478 const tracy = trace(@src());
24702479 defer tracy.end();
24712480
......@@ -2486,7 +2495,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn
24862495 return sema.mod.constType(sema.arena, src, err_union_ty);
24872496}
24882497
2489fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2498fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
24902499 _ = block;
24912500 const tracy = trace(@src());
24922501 defer tracy.end();
......@@ -2505,7 +2514,7 @@ fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
25052514 });
25062515}
25072516
2508fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2517fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
25092518 const tracy = trace(@src());
25102519 defer tracy.end();
25112520
......@@ -2535,7 +2544,7 @@ fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
25352544 return block.addUnOp(src, result_ty, .bitcast, op_coerced);
25362545}
25372546
2538fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2547fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
25392548 const tracy = trace(@src());
25402549 defer tracy.end();
25412550
......@@ -2568,7 +2577,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
25682577 return block.addUnOp(src, Type.initTag(.anyerror), .bitcast, op);
25692578}
25702579
2571fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2580fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
25722581 const tracy = trace(@src());
25732582 defer tracy.end();
25742583
......@@ -2658,7 +2667,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn
26582667 });
26592668}
26602669
2661fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2670fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
26622671 _ = block;
26632672 const tracy = trace(@src());
26642673 defer tracy.end();
......@@ -2672,7 +2681,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE
26722681 });
26732682}
26742683
2675fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2684fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
26762685 const mod = sema.mod;
26772686 const arena = sema.arena;
26782687 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
......@@ -2680,7 +2689,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
26802689 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
26812690 const operand = try sema.resolveInst(inst_data.operand);
26822691
2683 const enum_tag: *Inst = switch (operand.ty.zigTypeTag()) {
2692 const enum_tag: Air.Inst.Index = switch (operand.ty.zigTypeTag()) {
26842693 .Enum => operand,
26852694 .Union => {
26862695 //if (!operand.ty.unionHasTag()) {
......@@ -2754,7 +2763,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
27542763 return block.addUnOp(src, int_tag_ty, .bitcast, enum_tag);
27552764}
27562765
2757fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2766fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
27582767 const mod = sema.mod;
27592768 const target = mod.getTarget();
27602769 const arena = sema.arena;
......@@ -2815,7 +2824,7 @@ fn zirOptionalPayloadPtr(
28152824 block: *Scope.Block,
28162825 inst: Zir.Inst.Index,
28172826 safety_check: bool,
2818) InnerError!*Inst {
2827) InnerError!Air.Inst.Index {
28192828 const tracy = trace(@src());
28202829 defer tracy.end();
28212830
......@@ -2858,7 +2867,7 @@ fn zirOptionalPayload(
28582867 block: *Scope.Block,
28592868 inst: Zir.Inst.Index,
28602869 safety_check: bool,
2861) InnerError!*Inst {
2870) InnerError!Air.Inst.Index {
28622871 const tracy = trace(@src());
28632872 defer tracy.end();
28642873
......@@ -2896,7 +2905,7 @@ fn zirErrUnionPayload(
28962905 block: *Scope.Block,
28972906 inst: Zir.Inst.Index,
28982907 safety_check: bool,
2899) InnerError!*Inst {
2908) InnerError!Air.Inst.Index {
29002909 const tracy = trace(@src());
29012910 defer tracy.end();
29022911
......@@ -2930,7 +2939,7 @@ fn zirErrUnionPayloadPtr(
29302939 block: *Scope.Block,
29312940 inst: Zir.Inst.Index,
29322941 safety_check: bool,
2933) InnerError!*Inst {
2942) InnerError!Air.Inst.Index {
29342943 const tracy = trace(@src());
29352944 defer tracy.end();
29362945
......@@ -2969,7 +2978,7 @@ fn zirErrUnionPayloadPtr(
29692978}
29702979
29712980/// Value in, value out
2972fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2981fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
29732982 const tracy = trace(@src());
29742983 defer tracy.end();
29752984
......@@ -2995,7 +3004,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner
29953004}
29963005
29973006/// Pointer in, value out
2998fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3007fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
29993008 const tracy = trace(@src());
30003009 defer tracy.end();
30013010
......@@ -3042,7 +3051,7 @@ fn zirFunc(
30423051 block: *Scope.Block,
30433052 inst: Zir.Inst.Index,
30443053 inferred_error_set: bool,
3045) InnerError!*Inst {
3054) InnerError!Air.Inst.Index {
30463055 const tracy = trace(@src());
30473056 defer tracy.end();
30483057
......@@ -3093,7 +3102,7 @@ fn funcCommon(
30933102 is_extern: bool,
30943103 src_locs: Zir.Inst.Func.SrcLocs,
30953104 opt_lib_name: ?[]const u8,
3096) InnerError!*Inst {
3105) InnerError!Air.Inst.Index {
30973106 const src: LazySrcLoc = .{ .node_offset = src_node_offset };
30983107 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset };
30993108 const bare_return_type = try sema.resolveType(block, ret_ty_src, zir_return_type);
......@@ -3234,7 +3243,7 @@ fn funcCommon(
32343243 return result;
32353244}
32363245
3237fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3246fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
32383247 const tracy = trace(@src());
32393248 defer tracy.end();
32403249
......@@ -3242,7 +3251,7 @@ fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Ins
32423251 return sema.analyzeAs(block, .unneeded, bin_inst.lhs, bin_inst.rhs);
32433252}
32443253
3245fn zirAsNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3254fn zirAsNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
32463255 const tracy = trace(@src());
32473256 defer tracy.end();
32483257
......@@ -3258,13 +3267,13 @@ fn analyzeAs(
32583267 src: LazySrcLoc,
32593268 zir_dest_type: Zir.Inst.Ref,
32603269 zir_operand: Zir.Inst.Ref,
3261) InnerError!*Inst {
3270) InnerError!Air.Inst.Index {
32623271 const dest_type = try sema.resolveType(block, src, zir_dest_type);
32633272 const operand = try sema.resolveInst(zir_operand);
32643273 return sema.coerce(block, dest_type, operand, src);
32653274}
32663275
3267fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3276fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
32683277 const tracy = trace(@src());
32693278 defer tracy.end();
32703279
......@@ -3281,7 +3290,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
32813290 return block.addUnOp(src, ty, .ptrtoint, ptr);
32823291}
32833292
3284fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3293fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
32853294 const tracy = trace(@src());
32863295 defer tracy.end();
32873296
......@@ -3299,7 +3308,7 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
32993308 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);
33003309}
33013310
3302fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3311fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
33033312 const tracy = trace(@src());
33043313 defer tracy.end();
33053314
......@@ -3312,7 +3321,7 @@ fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
33123321 return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);
33133322}
33143323
3315fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3324fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
33163325 const tracy = trace(@src());
33173326 defer tracy.end();
33183327
......@@ -3327,7 +3336,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
33273336 return sema.analyzeLoad(block, src, result_ptr, src);
33283337}
33293338
3330fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3339fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
33313340 const tracy = trace(@src());
33323341 defer tracy.end();
33333342
......@@ -3340,7 +3349,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
33403349 return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);
33413350}
33423351
3343fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3352fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
33443353 const tracy = trace(@src());
33453354 defer tracy.end();
33463355
......@@ -3383,7 +3392,7 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
33833392 return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten int", .{});
33843393}
33853394
3386fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3395fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
33873396 const tracy = trace(@src());
33883397 defer tracy.end();
33893398
......@@ -3396,7 +3405,7 @@ fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
33963405 return sema.bitcast(block, dest_type, operand);
33973406}
33983407
3399fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3408fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
34003409 const tracy = trace(@src());
34013410 defer tracy.end();
34023411
......@@ -3439,7 +3448,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
34393448 return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten float", .{});
34403449}
34413450
3442fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3451fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
34433452 const tracy = trace(@src());
34443453 defer tracy.end();
34453454
......@@ -3454,7 +3463,7 @@ fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
34543463 return sema.analyzeLoad(block, sema.src, result_ptr, sema.src);
34553464}
34563465
3457fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3466fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
34583467 const tracy = trace(@src());
34593468 defer tracy.end();
34603469
......@@ -3472,7 +3481,7 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE
34723481 return sema.analyzeLoad(block, src, result_ptr, src);
34733482}
34743483
3475fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3484fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
34763485 const tracy = trace(@src());
34773486 defer tracy.end();
34783487
......@@ -3482,7 +3491,7 @@ fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
34823491 return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);
34833492}
34843493
3485fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3494fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
34863495 const tracy = trace(@src());
34873496 defer tracy.end();
34883497
......@@ -3495,7 +3504,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE
34953504 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);
34963505}
34973506
3498fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3507fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
34993508 const tracy = trace(@src());
35003509 defer tracy.end();
35013510
......@@ -3508,7 +3517,7 @@ fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
35083517 return sema.analyzeSlice(block, src, array_ptr, start, null, null, .unneeded);
35093518}
35103519
3511fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3520fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
35123521 const tracy = trace(@src());
35133522 defer tracy.end();
35143523
......@@ -3522,7 +3531,7 @@ fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
35223531 return sema.analyzeSlice(block, src, array_ptr, start, end, null, .unneeded);
35233532}
35243533
3525fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
3534fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
35263535 const tracy = trace(@src());
35273536 defer tracy.end();
35283537
......@@ -3544,7 +3553,7 @@ fn zirSwitchCapture(
35443553 inst: Zir.Inst.Index,
35453554 is_multi: bool,
35463555 is_ref: bool,
3547) InnerError!*Inst {
3556) InnerError!Air.Inst.Index {
35483557 const tracy = trace(@src());
35493558 defer tracy.end();
35503559
......@@ -3563,7 +3572,7 @@ fn zirSwitchCaptureElse(
35633572 block: *Scope.Block,
35643573 inst: Zir.Inst.Index,
35653574 is_ref: bool,
3566) InnerError!*Inst {
3575) InnerError!Air.Inst.Index {
35673576 const tracy = trace(@src());
35683577 defer tracy.end();
35693578
......@@ -3582,7 +3591,7 @@ fn zirSwitchBlock(
35823591 inst: Zir.Inst.Index,
35833592 is_ref: bool,
35843593 special_prong: Zir.SpecialProng,
3585) InnerError!*Inst {
3594) InnerError!Air.Inst.Index {
35863595 const tracy = trace(@src());
35873596 defer tracy.end();
35883597
......@@ -3615,7 +3624,7 @@ fn zirSwitchBlockMulti(
36153624 inst: Zir.Inst.Index,
36163625 is_ref: bool,
36173626 special_prong: Zir.SpecialProng,
3618) InnerError!*Inst {
3627) InnerError!Air.Inst.Index {
36193628 const tracy = trace(@src());
36203629 defer tracy.end();
36213630
......@@ -3645,14 +3654,14 @@ fn zirSwitchBlockMulti(
36453654fn analyzeSwitch(
36463655 sema: *Sema,
36473656 block: *Scope.Block,
3648 operand: *Inst,
3657 operand: Air.Inst.Index,
36493658 extra_end: usize,
36503659 special_prong: Zir.SpecialProng,
36513660 scalar_cases_len: usize,
36523661 multi_cases_len: usize,
36533662 switch_inst: Zir.Inst.Index,
36543663 src_node_offset: i32,
3655) InnerError!*Inst {
3664) InnerError!Air.Inst.Index {
36563665 const gpa = sema.gpa;
36573666 const mod = sema.mod;
36583667
......@@ -4187,7 +4196,7 @@ fn analyzeSwitch(
41874196
41884197 cases[scalar_i] = .{
41894198 .item = item_val,
4190 .body = .{ .instructions = try sema.arena.dupe(*Inst, case_block.instructions.items) },
4199 .body = .{ .instructions = try sema.arena.dupe(Air.Inst.Index, case_block.instructions.items) },
41914200 };
41924201 }
41934202
......@@ -4207,7 +4216,7 @@ fn analyzeSwitch(
42074216
42084217 case_block.instructions.shrinkRetainingCapacity(0);
42094218
4210 var any_ok: ?*Inst = null;
4219 var any_ok: ?Air.Inst.Index = null;
42114220 const bool_ty = comptime Type.initTag(.bool);
42124221
42134222 for (items) |item_ref| {
......@@ -4280,7 +4289,7 @@ fn analyzeSwitch(
42804289 try case_block.instructions.append(gpa, &new_condbr.base);
42814290
42824291 const cond_body: Body = .{
4283 .instructions = try sema.arena.dupe(*Inst, case_block.instructions.items),
4292 .instructions = try sema.arena.dupe(Air.Inst.Index, case_block.instructions.items),
42844293 };
42854294
42864295 case_block.instructions.shrinkRetainingCapacity(0);
......@@ -4288,7 +4297,7 @@ fn analyzeSwitch(
42884297 extra_index += body_len;
42894298 _ = try sema.analyzeBody(&case_block, body);
42904299 new_condbr.then_body = .{
4291 .instructions = try sema.arena.dupe(*Inst, case_block.instructions.items),
4300 .instructions = try sema.arena.dupe(Air.Inst.Index, case_block.instructions.items),
42924301 };
42934302 if (prev_condbr) |condbr| {
42944303 condbr.else_body = cond_body;
......@@ -4303,7 +4312,7 @@ fn analyzeSwitch(
43034312 case_block.instructions.shrinkRetainingCapacity(0);
43044313 _ = try sema.analyzeBody(&case_block, special.body);
43054314 const else_body: Body = .{
4306 .instructions = try sema.arena.dupe(*Inst, case_block.instructions.items),
4315 .instructions = try sema.arena.dupe(Air.Inst.Index, case_block.instructions.items),
43074316 };
43084317 if (prev_condbr) |condbr| {
43094318 condbr.else_body = else_body;
......@@ -4507,7 +4516,7 @@ fn validateSwitchNoRange(
45074516 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);
45084517}
45094518
4510fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4519fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
45114520 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
45124521 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
45134522 _ = extra;
......@@ -4516,7 +4525,7 @@ fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
45164525 return sema.mod.fail(&block.base, src, "TODO implement zirHasField", .{});
45174526}
45184527
4519fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4528fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
45204529 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
45214530 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
45224531 const src = inst_data.src();
......@@ -4541,7 +4550,7 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
45414550 return mod.constBool(arena, src, false);
45424551}
45434552
4544fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4553fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
45454554 const tracy = trace(@src());
45464555 defer tracy.end();
45474556
......@@ -4566,13 +4575,13 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
45664575 return mod.constType(sema.arena, src, file_root_decl.ty);
45674576}
45684577
4569fn zirRetErrValueCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4578fn zirRetErrValueCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
45704579 _ = block;
45714580 _ = inst;
45724581 return sema.mod.fail(&block.base, sema.src, "TODO implement zirRetErrValueCode", .{});
45734582}
45744583
4575fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4584fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
45764585 const tracy = trace(@src());
45774586 defer tracy.end();
45784587
......@@ -4581,7 +4590,7 @@ fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In
45814590 return sema.mod.fail(&block.base, sema.src, "TODO implement zirShl", .{});
45824591}
45834592
4584fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4593fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
45854594 const tracy = trace(@src());
45864595 defer tracy.end();
45874596
......@@ -4594,7 +4603,7 @@ fn zirBitwise(
45944603 block: *Scope.Block,
45954604 inst: Zir.Inst.Index,
45964605 ir_tag: ir.Inst.Tag,
4597) InnerError!*Inst {
4606) InnerError!Air.Inst.Index {
45984607 const tracy = trace(@src());
45994608 defer tracy.end();
46004609
......@@ -4606,7 +4615,7 @@ fn zirBitwise(
46064615 const lhs = try sema.resolveInst(extra.lhs);
46074616 const rhs = try sema.resolveInst(extra.rhs);
46084617
4609 const instructions = &[_]*Inst{ lhs, rhs };
4618 const instructions = &[_]Air.Inst.Index{ lhs, rhs };
46104619 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);
46114620 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
46124621 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
......@@ -4652,7 +4661,7 @@ fn zirBitwise(
46524661 return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs);
46534662}
46544663
4655fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4664fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
46564665 const tracy = trace(@src());
46574666 defer tracy.end();
46584667
......@@ -4660,7 +4669,7 @@ fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
46604669 return sema.mod.fail(&block.base, sema.src, "TODO implement zirBitNot", .{});
46614670}
46624671
4663fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4672fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
46644673 const tracy = trace(@src());
46654674 defer tracy.end();
46664675
......@@ -4668,7 +4677,7 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
46684677 return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayCat", .{});
46694678}
46704679
4671fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4680fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
46724681 const tracy = trace(@src());
46734682 defer tracy.end();
46744683
......@@ -4681,7 +4690,7 @@ fn zirNegate(
46814690 block: *Scope.Block,
46824691 inst: Zir.Inst.Index,
46834692 tag_override: Zir.Inst.Tag,
4684) InnerError!*Inst {
4693) InnerError!Air.Inst.Index {
46854694 const tracy = trace(@src());
46864695 defer tracy.end();
46874696
......@@ -4695,7 +4704,7 @@ fn zirNegate(
46954704 return sema.analyzeArithmetic(block, tag_override, lhs, rhs, src, lhs_src, rhs_src);
46964705}
46974706
4698fn zirArithmetic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4707fn zirArithmetic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
46994708 const tracy = trace(@src());
47004709 defer tracy.end();
47014710
......@@ -4715,7 +4724,7 @@ fn zirOverflowArithmetic(
47154724 sema: *Sema,
47164725 block: *Scope.Block,
47174726 extended: Zir.Inst.Extended.InstData,
4718) InnerError!*Inst {
4727) InnerError!Air.Inst.Index {
47194728 const tracy = trace(@src());
47204729 defer tracy.end();
47214730
......@@ -4729,13 +4738,13 @@ fn analyzeArithmetic(
47294738 sema: *Sema,
47304739 block: *Scope.Block,
47314740 zir_tag: Zir.Inst.Tag,
4732 lhs: *Inst,
4733 rhs: *Inst,
4741 lhs: Air.Inst.Index,
4742 rhs: Air.Inst.Index,
47344743 src: LazySrcLoc,
47354744 lhs_src: LazySrcLoc,
47364745 rhs_src: LazySrcLoc,
4737) InnerError!*Inst {
4738 const instructions = &[_]*Inst{ lhs, rhs };
4746) InnerError!Air.Inst.Index {
4747 const instructions = &[_]Air.Inst.Index{ lhs, rhs };
47394748 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);
47404749 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
47414750 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
......@@ -4844,7 +4853,7 @@ fn analyzeArithmetic(
48444853 return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs);
48454854}
48464855
4847fn zirLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4856fn zirLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
48484857 const tracy = trace(@src());
48494858 defer tracy.end();
48504859
......@@ -4859,7 +4868,7 @@ fn zirAsm(
48594868 sema: *Sema,
48604869 block: *Scope.Block,
48614870 extended: Zir.Inst.Extended.InstData,
4862) InnerError!*Inst {
4871) InnerError!Air.Inst.Index {
48634872 const tracy = trace(@src());
48644873 defer tracy.end();
48654874
......@@ -4899,7 +4908,7 @@ fn zirAsm(
48994908 };
49004909 };
49014910
4902 const args = try sema.arena.alloc(*Inst, inputs_len);
4911 const args = try sema.arena.alloc(Air.Inst.Index, inputs_len);
49034912 const inputs = try sema.arena.alloc([]const u8, inputs_len);
49044913
49054914 for (args) |*arg, arg_i| {
......@@ -4943,7 +4952,7 @@ fn zirCmp(
49434952 block: *Scope.Block,
49444953 inst: Zir.Inst.Index,
49454954 op: std.math.CompareOperator,
4946) InnerError!*Inst {
4955) InnerError!Air.Inst.Index {
49474956 const tracy = trace(@src());
49484957 defer tracy.end();
49494958
......@@ -5009,7 +5018,7 @@ fn zirCmp(
50095018 return mod.constBool(sema.arena, src, lhs.value().?.eql(rhs.value().?) == (op == .eq));
50105019 }
50115020
5012 const instructions = &[_]*Inst{ lhs, rhs };
5021 const instructions = &[_]Air.Inst.Index{ lhs, rhs };
50135022 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);
50145023 if (!resolved_type.isSelfComparable(is_equality_cmp)) {
50155024 return mod.fail(&block.base, src, "operator not allowed for type '{}'", .{resolved_type});
......@@ -5041,7 +5050,7 @@ fn zirCmp(
50415050 return block.addBinOp(src, bool_type, tag, casted_lhs, casted_rhs);
50425051}
50435052
5044fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5053fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
50455054 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
50465055 const src = inst_data.src();
50475056 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -5051,7 +5060,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
50515060 return sema.mod.constIntUnsigned(sema.arena, src, Type.initTag(.comptime_int), abi_size);
50525061}
50535062
5054fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5063fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
50555064 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
50565065 const src = inst_data.src();
50575066 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -5065,7 +5074,7 @@ fn zirThis(
50655074 sema: *Sema,
50665075 block: *Scope.Block,
50675076 extended: Zir.Inst.Extended.InstData,
5068) InnerError!*Inst {
5077) InnerError!Air.Inst.Index {
50695078 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
50705079 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirThis", .{});
50715080}
......@@ -5074,7 +5083,7 @@ fn zirRetAddr(
50745083 sema: *Sema,
50755084 block: *Scope.Block,
50765085 extended: Zir.Inst.Extended.InstData,
5077) InnerError!*Inst {
5086) InnerError!Air.Inst.Index {
50785087 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
50795088 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirRetAddr", .{});
50805089}
......@@ -5083,12 +5092,12 @@ fn zirBuiltinSrc(
50835092 sema: *Sema,
50845093 block: *Scope.Block,
50855094 extended: Zir.Inst.Extended.InstData,
5086) InnerError!*Inst {
5095) InnerError!Air.Inst.Index {
50875096 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
50885097 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinSrc", .{});
50895098}
50905099
5091fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5100fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
50925101 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
50935102 const src = inst_data.src();
50945103 const ty = try sema.resolveType(block, src, inst_data.operand);
......@@ -5131,7 +5140,7 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
51315140 }
51325141}
51335142
5134fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5143fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
51355144 _ = block;
51365145 const zir_datas = sema.code.instructions.items(.data);
51375146 const inst_data = zir_datas[inst].un_node;
......@@ -5140,7 +5149,7 @@ fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
51405149 return sema.mod.constType(sema.arena, src, operand.ty);
51415150}
51425151
5143fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5152fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
51445153 _ = block;
51455154 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
51465155 const src = inst_data.src();
......@@ -5149,13 +5158,13 @@ fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
51495158 return sema.mod.constType(sema.arena, src, elem_ty);
51505159}
51515160
5152fn zirTypeofLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5161fn zirTypeofLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
51535162 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
51545163 const src = inst_data.src();
51555164 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirTypeofLog2IntType", .{});
51565165}
51575166
5158fn zirLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5167fn zirLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
51595168 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
51605169 const src = inst_data.src();
51615170 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirLog2IntType", .{});
......@@ -5165,7 +5174,7 @@ fn zirTypeofPeer(
51655174 sema: *Sema,
51665175 block: *Scope.Block,
51675176 extended: Zir.Inst.Extended.InstData,
5168) InnerError!*Inst {
5177) InnerError!Air.Inst.Index {
51695178 const tracy = trace(@src());
51705179 defer tracy.end();
51715180
......@@ -5173,7 +5182,7 @@ fn zirTypeofPeer(
51735182 const src: LazySrcLoc = .{ .node_offset = extra.data.src_node };
51745183 const args = sema.code.refSlice(extra.end, extended.small);
51755184
5176 const inst_list = try sema.gpa.alloc(*ir.Inst, args.len);
5185 const inst_list = try sema.gpa.alloc(Air.Inst.Index, args.len);
51775186 defer sema.gpa.free(inst_list);
51785187
51795188 for (args) |arg_ref, i| {
......@@ -5184,7 +5193,7 @@ fn zirTypeofPeer(
51845193 return sema.mod.constType(sema.arena, src, result_type);
51855194}
51865195
5187fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5196fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
51885197 const tracy = trace(@src());
51895198 defer tracy.end();
51905199
......@@ -5206,7 +5215,7 @@ fn zirBoolOp(
52065215 block: *Scope.Block,
52075216 inst: Zir.Inst.Index,
52085217 comptime is_bool_or: bool,
5209) InnerError!*Inst {
5218) InnerError!Air.Inst.Index {
52105219 const tracy = trace(@src());
52115220 defer tracy.end();
52125221
......@@ -5237,7 +5246,7 @@ fn zirBoolBr(
52375246 parent_block: *Scope.Block,
52385247 inst: Zir.Inst.Index,
52395248 is_bool_or: bool,
5240) InnerError!*Inst {
5249) InnerError!Air.Inst.Index {
52415250 const tracy = trace(@src());
52425251 defer tracy.end();
52435252
......@@ -5292,12 +5301,12 @@ fn zirBoolBr(
52925301 const rhs_result = try sema.resolveBody(rhs_block, body);
52935302 _ = try rhs_block.addBr(src, block_inst, rhs_result);
52945303
5295 const air_then_body: ir.Body = .{ .instructions = try sema.arena.dupe(*Inst, then_block.instructions.items) };
5296 const air_else_body: ir.Body = .{ .instructions = try sema.arena.dupe(*Inst, else_block.instructions.items) };
5304 const air_then_body: ir.Body = .{ .instructions = try sema.arena.dupe(Air.Inst.Index, then_block.instructions.items) };
5305 const air_else_body: ir.Body = .{ .instructions = try sema.arena.dupe(Air.Inst.Index, else_block.instructions.items) };
52975306 _ = try child_block.addCondBr(src, lhs, air_then_body, air_else_body);
52985307
52995308 block_inst.body = .{
5300 .instructions = try sema.arena.dupe(*Inst, child_block.instructions.items),
5309 .instructions = try sema.arena.dupe(Air.Inst.Index, child_block.instructions.items),
53015310 };
53025311 try parent_block.instructions.append(sema.gpa, &block_inst.base);
53035312 return &block_inst.base;
......@@ -5307,7 +5316,7 @@ fn zirIsNonNull(
53075316 sema: *Sema,
53085317 block: *Scope.Block,
53095318 inst: Zir.Inst.Index,
5310) InnerError!*Inst {
5319) InnerError!Air.Inst.Index {
53115320 const tracy = trace(@src());
53125321 defer tracy.end();
53135322
......@@ -5321,7 +5330,7 @@ fn zirIsNonNullPtr(
53215330 sema: *Sema,
53225331 block: *Scope.Block,
53235332 inst: Zir.Inst.Index,
5324) InnerError!*Inst {
5333) InnerError!Air.Inst.Index {
53255334 const tracy = trace(@src());
53265335 defer tracy.end();
53275336
......@@ -5332,7 +5341,7 @@ fn zirIsNonNullPtr(
53325341 return sema.analyzeIsNull(block, src, loaded, true);
53335342}
53345343
5335fn zirIsNonErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5344fn zirIsNonErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
53365345 const tracy = trace(@src());
53375346 defer tracy.end();
53385347
......@@ -5341,7 +5350,7 @@ fn zirIsNonErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
53415350 return sema.analyzeIsNonErr(block, inst_data.src(), operand);
53425351}
53435352
5344fn zirIsNonErrPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5353fn zirIsNonErrPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
53455354 const tracy = trace(@src());
53465355 defer tracy.end();
53475356
......@@ -5385,14 +5394,14 @@ fn zirCondbr(
53855394
53865395 _ = try sema.analyzeBody(&sub_block, then_body);
53875396 const air_then_body: ir.Body = .{
5388 .instructions = try sema.arena.dupe(*Inst, sub_block.instructions.items),
5397 .instructions = try sema.arena.dupe(Air.Inst.Index, sub_block.instructions.items),
53895398 };
53905399
53915400 sub_block.instructions.shrinkRetainingCapacity(0);
53925401
53935402 _ = try sema.analyzeBody(&sub_block, else_body);
53945403 const air_else_body: ir.Body = .{
5395 .instructions = try sema.arena.dupe(*Inst, sub_block.instructions.items),
5404 .instructions = try sema.arena.dupe(Air.Inst.Index, sub_block.instructions.items),
53965405 };
53975406
53985407 _ = try parent_block.addCondBr(src, cond, air_then_body, air_else_body);
......@@ -5470,7 +5479,7 @@ fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
54705479fn analyzeRet(
54715480 sema: *Sema,
54725481 block: *Scope.Block,
5473 operand: *Inst,
5482 operand: Air.Inst.Index,
54745483 src: LazySrcLoc,
54755484 need_coercion: bool,
54765485) InnerError!Zir.Inst.Index {
......@@ -5505,7 +5514,7 @@ fn floatOpAllowed(tag: Zir.Inst.Tag) bool {
55055514 };
55065515}
55075516
5508fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5517fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
55095518 const tracy = trace(@src());
55105519 defer tracy.end();
55115520
......@@ -5526,7 +5535,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
55265535 return sema.mod.constType(sema.arena, .unneeded, ty);
55275536}
55285537
5529fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5538fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
55305539 const tracy = trace(@src());
55315540 defer tracy.end();
55325541
......@@ -5580,7 +5589,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
55805589 return sema.mod.constType(sema.arena, src, ty);
55815590}
55825591
5583fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5592fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
55845593 const tracy = trace(@src());
55855594 defer tracy.end();
55865595
......@@ -5594,13 +5603,13 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In
55945603 });
55955604}
55965605
5597fn zirUnionInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5606fn zirUnionInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
55985607 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
55995608 const src = inst_data.src();
56005609 return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnionInitPtr", .{});
56015610}
56025611
5603fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!*Inst {
5612fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Index {
56045613 const mod = sema.mod;
56055614 const gpa = sema.gpa;
56065615 const zir_datas = sema.code.instructions.items(.data);
......@@ -5622,7 +5631,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
56225631 mem.set(Zir.Inst.Index, found_fields, 0);
56235632
56245633 // The init values to use for the struct instance.
5625 const field_inits = try gpa.alloc(*ir.Inst, struct_obj.fields.count());
5634 const field_inits = try gpa.alloc(Air.Inst.Index, struct_obj.fields.count());
56265635 defer gpa.free(field_inits);
56275636
56285637 var field_i: u32 = 0;
......@@ -5713,7 +5722,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
57135722 return mod.fail(&block.base, src, "TODO: Sema.zirStructInit for runtime-known struct values", .{});
57145723}
57155724
5716fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!*Inst {
5725fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Index {
57175726 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
57185727 const src = inst_data.src();
57195728
......@@ -5721,7 +5730,7 @@ fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_
57215730 return sema.mod.fail(&block.base, src, "TODO: Sema.zirStructInitAnon", .{});
57225731}
57235732
5724fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!*Inst {
5733fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Index {
57255734 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
57265735 const src = inst_data.src();
57275736
......@@ -5729,7 +5738,7 @@ fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
57295738 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInit", .{});
57305739}
57315740
5732fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!*Inst {
5741fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Index {
57335742 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
57345743 const src = inst_data.src();
57355744
......@@ -5737,13 +5746,13 @@ fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_r
57375746 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInitAnon", .{});
57385747}
57395748
5740fn zirFieldTypeRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5749fn zirFieldTypeRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
57415750 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
57425751 const src = inst_data.src();
57435752 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldTypeRef", .{});
57445753}
57455754
5746fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5755fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
57475756 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
57485757 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
57495758 const src = inst_data.src();
......@@ -5765,7 +5774,7 @@ fn zirErrorReturnTrace(
57655774 sema: *Sema,
57665775 block: *Scope.Block,
57675776 extended: Zir.Inst.Extended.InstData,
5768) InnerError!*Inst {
5777) InnerError!Air.Inst.Index {
57695778 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
57705779 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorReturnTrace", .{});
57715780}
......@@ -5774,7 +5783,7 @@ fn zirFrame(
57745783 sema: *Sema,
57755784 block: *Scope.Block,
57765785 extended: Zir.Inst.Extended.InstData,
5777) InnerError!*Inst {
5786) InnerError!Air.Inst.Index {
57785787 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
57795788 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrame", .{});
57805789}
......@@ -5783,84 +5792,84 @@ fn zirFrameAddress(
57835792 sema: *Sema,
57845793 block: *Scope.Block,
57855794 extended: Zir.Inst.Extended.InstData,
5786) InnerError!*Inst {
5795) InnerError!Air.Inst.Index {
57875796 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
57885797 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameAddress", .{});
57895798}
57905799
5791fn zirAlignOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5800fn zirAlignOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
57925801 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
57935802 const src = inst_data.src();
57945803 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignOf", .{});
57955804}
57965805
5797fn zirBoolToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5806fn zirBoolToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
57985807 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
57995808 const src = inst_data.src();
58005809 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBoolToInt", .{});
58015810}
58025811
5803fn zirEmbedFile(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5812fn zirEmbedFile(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
58045813 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58055814 const src = inst_data.src();
58065815 return sema.mod.fail(&block.base, src, "TODO: Sema.zirEmbedFile", .{});
58075816}
58085817
5809fn zirErrorName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5818fn zirErrorName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
58105819 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58115820 const src = inst_data.src();
58125821 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorName", .{});
58135822}
58145823
5815fn zirUnaryMath(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5824fn zirUnaryMath(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
58165825 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58175826 const src = inst_data.src();
58185827 return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnaryMath", .{});
58195828}
58205829
5821fn zirTagName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5830fn zirTagName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
58225831 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58235832 const src = inst_data.src();
58245833 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTagName", .{});
58255834}
58265835
5827fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5836fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
58285837 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58295838 const src = inst_data.src();
58305839 return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify", .{});
58315840}
58325841
5833fn zirTypeName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5842fn zirTypeName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
58345843 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58355844 const src = inst_data.src();
58365845 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTypeName", .{});
58375846}
58385847
5839fn zirFrameType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5848fn zirFrameType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
58405849 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58415850 const src = inst_data.src();
58425851 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameType", .{});
58435852}
58445853
5845fn zirFrameSize(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5854fn zirFrameSize(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
58465855 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
58475856 const src = inst_data.src();
58485857 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameSize", .{});
58495858}
58505859
5851fn zirFloatToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5860fn zirFloatToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
58525861 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
58535862 const src = inst_data.src();
58545863 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFloatToInt", .{});
58555864}
58565865
5857fn zirIntToFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5866fn zirIntToFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
58585867 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
58595868 const src = inst_data.src();
58605869 return sema.mod.fail(&block.base, src, "TODO: Sema.zirIntToFloat", .{});
58615870}
58625871
5863fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5872fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
58645873 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
58655874 const src = inst_data.src();
58665875
......@@ -5923,199 +5932,199 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
59235932 return block.addUnOp(src, type_res, .bitcast, operand_coerced);
59245933}
59255934
5926fn zirErrSetCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5935fn zirErrSetCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
59275936 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
59285937 const src = inst_data.src();
59295938 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrSetCast", .{});
59305939}
59315940
5932fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5941fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
59335942 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
59345943 const src = inst_data.src();
59355944 return sema.mod.fail(&block.base, src, "TODO: Sema.zirPtrCast", .{});
59365945}
59375946
5938fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5947fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
59395948 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
59405949 const src = inst_data.src();
59415950 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTruncate", .{});
59425951}
59435952
5944fn zirAlignCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5953fn zirAlignCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
59455954 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
59465955 const src = inst_data.src();
59475956 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignCast", .{});
59485957}
59495958
5950fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5959fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
59515960 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
59525961 const src = inst_data.src();
59535962 return sema.mod.fail(&block.base, src, "TODO: Sema.zirClz", .{});
59545963}
59555964
5956fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5965fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
59575966 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
59585967 const src = inst_data.src();
59595968 return sema.mod.fail(&block.base, src, "TODO: Sema.zirCtz", .{});
59605969}
59615970
5962fn zirPopCount(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5971fn zirPopCount(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
59635972 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
59645973 const src = inst_data.src();
59655974 return sema.mod.fail(&block.base, src, "TODO: Sema.zirPopCount", .{});
59665975}
59675976
5968fn zirByteSwap(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5977fn zirByteSwap(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
59695978 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
59705979 const src = inst_data.src();
59715980 return sema.mod.fail(&block.base, src, "TODO: Sema.zirByteSwap", .{});
59725981}
59735982
5974fn zirBitReverse(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5983fn zirBitReverse(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
59755984 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
59765985 const src = inst_data.src();
59775986 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitReverse", .{});
59785987}
59795988
5980fn zirDivExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5989fn zirDivExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
59815990 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
59825991 const src = inst_data.src();
59835992 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivExact", .{});
59845993}
59855994
5986fn zirDivFloor(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5995fn zirDivFloor(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
59875996 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
59885997 const src = inst_data.src();
59895998 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivFloor", .{});
59905999}
59916000
5992fn zirDivTrunc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6001fn zirDivTrunc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
59936002 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
59946003 const src = inst_data.src();
59956004 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivTrunc", .{});
59966005}
59976006
5998fn zirMod(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6007fn zirMod(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
59996008 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60006009 const src = inst_data.src();
60016010 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMod", .{});
60026011}
60036012
6004fn zirRem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6013fn zirRem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
60056014 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60066015 const src = inst_data.src();
60076016 return sema.mod.fail(&block.base, src, "TODO: Sema.zirRem", .{});
60086017}
60096018
6010fn zirShlExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6019fn zirShlExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
60116020 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60126021 const src = inst_data.src();
60136022 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShlExact", .{});
60146023}
60156024
6016fn zirShrExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6025fn zirShrExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
60176026 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60186027 const src = inst_data.src();
60196028 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShrExact", .{});
60206029}
60216030
6022fn zirBitOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6031fn zirBitOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
60236032 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60246033 const src = inst_data.src();
60256034 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitOffsetOf", .{});
60266035}
60276036
6028fn zirOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6037fn zirOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
60296038 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60306039 const src = inst_data.src();
60316040 return sema.mod.fail(&block.base, src, "TODO: Sema.zirOffsetOf", .{});
60326041}
60336042
6034fn zirCmpxchg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6043fn zirCmpxchg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
60356044 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60366045 const src = inst_data.src();
60376046 return sema.mod.fail(&block.base, src, "TODO: Sema.zirCmpxchg", .{});
60386047}
60396048
6040fn zirSplat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6049fn zirSplat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
60416050 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60426051 const src = inst_data.src();
60436052 return sema.mod.fail(&block.base, src, "TODO: Sema.zirSplat", .{});
60446053}
60456054
6046fn zirReduce(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6055fn zirReduce(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
60476056 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60486057 const src = inst_data.src();
60496058 return sema.mod.fail(&block.base, src, "TODO: Sema.zirReduce", .{});
60506059}
60516060
6052fn zirShuffle(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6061fn zirShuffle(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
60536062 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60546063 const src = inst_data.src();
60556064 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShuffle", .{});
60566065}
60576066
6058fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6067fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
60596068 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60606069 const src = inst_data.src();
60616070 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicLoad", .{});
60626071}
60636072
6064fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6073fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
60656074 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60666075 const src = inst_data.src();
60676076 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicRmw", .{});
60686077}
60696078
6070fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6079fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
60716080 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60726081 const src = inst_data.src();
60736082 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicStore", .{});
60746083}
60756084
6076fn zirMulAdd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6085fn zirMulAdd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
60776086 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60786087 const src = inst_data.src();
60796088 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMulAdd", .{});
60806089}
60816090
6082fn zirBuiltinCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6091fn zirBuiltinCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
60836092 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60846093 const src = inst_data.src();
60856094 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinCall", .{});
60866095}
60876096
6088fn zirFieldPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6097fn zirFieldPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
60896098 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60906099 const src = inst_data.src();
60916100 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldPtrType", .{});
60926101}
60936102
6094fn zirFieldParentPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6103fn zirFieldParentPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
60956104 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
60966105 const src = inst_data.src();
60976106 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldParentPtr", .{});
60986107}
60996108
6100fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6109fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
61016110 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
61026111 const src = inst_data.src();
61036112 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemcpy", .{});
61046113}
61056114
6106fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6115fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
61076116 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
61086117 const src = inst_data.src();
61096118 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemset", .{});
61106119}
61116120
6112fn zirBuiltinAsyncCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6121fn zirBuiltinAsyncCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
61136122 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
61146123 const src = inst_data.src();
61156124 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinAsyncCall", .{});
61166125}
61176126
6118fn zirResume(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
6127fn zirResume(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index {
61196128 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
61206129 const src = inst_data.src();
61216130 return sema.mod.fail(&block.base, src, "TODO: Sema.zirResume", .{});
......@@ -6126,7 +6135,7 @@ fn zirAwait(
61266135 block: *Scope.Block,
61276136 inst: Zir.Inst.Index,
61286137 is_nosuspend: bool,
6129) InnerError!*Inst {
6138) InnerError!Air.Inst.Index {
61306139 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
61316140 const src = inst_data.src();
61326141
......@@ -6138,7 +6147,7 @@ fn zirVarExtended(
61386147 sema: *Sema,
61396148 block: *Scope.Block,
61406149 extended: Zir.Inst.Extended.InstData,
6141) InnerError!*Inst {
6150) InnerError!Air.Inst.Index {
61426151 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
61436152 const src = sema.src;
61446153 const ty_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at type
......@@ -6204,7 +6213,7 @@ fn zirFuncExtended(
62046213 block: *Scope.Block,
62056214 extended: Zir.Inst.Extended.InstData,
62066215 inst: Zir.Inst.Index,
6207) InnerError!*Inst {
6216) InnerError!Air.Inst.Index {
62086217 const tracy = trace(@src());
62096218 defer tracy.end();
62106219
......@@ -6271,7 +6280,7 @@ fn zirCUndef(
62716280 sema: *Sema,
62726281 block: *Scope.Block,
62736282 extended: Zir.Inst.Extended.InstData,
6274) InnerError!*Inst {
6283) InnerError!Air.Inst.Index {
62756284 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
62766285 const src: LazySrcLoc = .{ .node_offset = extra.node };
62776286 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCUndef", .{});
......@@ -6281,7 +6290,7 @@ fn zirCInclude(
62816290 sema: *Sema,
62826291 block: *Scope.Block,
62836292 extended: Zir.Inst.Extended.InstData,
6284) InnerError!*Inst {
6293) InnerError!Air.Inst.Index {
62856294 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
62866295 const src: LazySrcLoc = .{ .node_offset = extra.node };
62876296 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCInclude", .{});
......@@ -6291,7 +6300,7 @@ fn zirCDefine(
62916300 sema: *Sema,
62926301 block: *Scope.Block,
62936302 extended: Zir.Inst.Extended.InstData,
6294) InnerError!*Inst {
6303) InnerError!Air.Inst.Index {
62956304 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
62966305 const src: LazySrcLoc = .{ .node_offset = extra.node };
62976306 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCDefine", .{});
......@@ -6301,7 +6310,7 @@ fn zirWasmMemorySize(
63016310 sema: *Sema,
63026311 block: *Scope.Block,
63036312 extended: Zir.Inst.Extended.InstData,
6304) InnerError!*Inst {
6313) InnerError!Air.Inst.Index {
63056314 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
63066315 const src: LazySrcLoc = .{ .node_offset = extra.node };
63076316 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemorySize", .{});
......@@ -6311,7 +6320,7 @@ fn zirWasmMemoryGrow(
63116320 sema: *Sema,
63126321 block: *Scope.Block,
63136322 extended: Zir.Inst.Extended.InstData,
6314) InnerError!*Inst {
6323) InnerError!Air.Inst.Index {
63156324 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
63166325 const src: LazySrcLoc = .{ .node_offset = extra.node };
63176326 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemoryGrow", .{});
......@@ -6321,7 +6330,7 @@ fn zirBuiltinExtern(
63216330 sema: *Sema,
63226331 block: *Scope.Block,
63236332 extended: Zir.Inst.Extended.InstData,
6324) InnerError!*Inst {
6333) InnerError!Air.Inst.Index {
63256334 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
63266335 const src: LazySrcLoc = .{ .node_offset = extra.node };
63276336 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinExtern", .{});
......@@ -6355,7 +6364,7 @@ pub const PanicId = enum {
63556364 invalid_error_code,
63566365};
63576366
6358fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id: PanicId) !void {
6367fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: Air.Inst.Index, panic_id: PanicId) !void {
63596368 const block_inst = try sema.arena.create(Inst.Block);
63606369 block_inst.* = .{
63616370 .base = .{
......@@ -6364,12 +6373,12 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id:
63646373 .src = ok.src,
63656374 },
63666375 .body = .{
6367 .instructions = try sema.arena.alloc(*Inst, 1), // Only need space for the condbr.
6376 .instructions = try sema.arena.alloc(Air.Inst.Index, 1), // Only need space for the condbr.
63686377 },
63696378 };
63706379
63716380 const ok_body: ir.Body = .{
6372 .instructions = try sema.arena.alloc(*Inst, 1), // Only need space for the br_void.
6381 .instructions = try sema.arena.alloc(Air.Inst.Index, 1), // Only need space for the br_void.
63736382 };
63746383 const br_void = try sema.arena.create(Inst.BrVoid);
63756384 br_void.* = .{
......@@ -6395,7 +6404,7 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id:
63956404
63966405 _ = try sema.safetyPanic(&fail_block, ok.src, panic_id);
63976406
6398 const fail_body: ir.Body = .{ .instructions = try sema.arena.dupe(*Inst, fail_block.instructions.items) };
6407 const fail_body: ir.Body = .{ .instructions = try sema.arena.dupe(Air.Inst.Index, fail_block.instructions.items) };
63996408
64006409 const condbr = try sema.arena.create(Inst.CondBr);
64016410 condbr.* = .{
......@@ -6417,7 +6426,7 @@ fn panicWithMsg(
64176426 sema: *Sema,
64186427 block: *Scope.Block,
64196428 src: LazySrcLoc,
6420 msg_inst: *ir.Inst,
6429 msg_inst: Air.Inst.Index,
64216430) !Zir.Inst.Index {
64226431 const mod = sema.mod;
64236432 const arena = sema.arena;
......@@ -6438,7 +6447,7 @@ fn panicWithMsg(
64386447 .ty = try mod.optionalType(arena, ptr_stack_trace_ty),
64396448 .val = Value.initTag(.null_value),
64406449 });
6441 const args = try arena.create([2]*ir.Inst);
6450 const args = try arena.create([2]Air.Inst.Index);
64426451 args.* = .{ msg_inst, null_stack_trace };
64436452 _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, args);
64446453 return always_noreturn;
......@@ -6494,10 +6503,10 @@ fn namedFieldPtr(
64946503 sema: *Sema,
64956504 block: *Scope.Block,
64966505 src: LazySrcLoc,
6497 object_ptr: *Inst,
6506 object_ptr: Air.Inst.Index,
64986507 field_name: []const u8,
64996508 field_name_src: LazySrcLoc,
6500) InnerError!*Inst {
6509) InnerError!Air.Inst.Index {
65016510 const mod = sema.mod;
65026511 const arena = sema.arena;
65036512
......@@ -6647,7 +6656,7 @@ fn analyzeNamespaceLookup(
66476656 src: LazySrcLoc,
66486657 namespace: *Scope.Namespace,
66496658 decl_name: []const u8,
6650) InnerError!?*Inst {
6659) InnerError!?Air.Inst.Index {
66516660 const mod = sema.mod;
66526661 const gpa = sema.gpa;
66536662 if (try sema.lookupInNamespace(namespace, decl_name)) |decl| {
......@@ -6671,11 +6680,11 @@ fn analyzeStructFieldPtr(
66716680 sema: *Sema,
66726681 block: *Scope.Block,
66736682 src: LazySrcLoc,
6674 struct_ptr: *Inst,
6683 struct_ptr: Air.Inst.Index,
66756684 field_name: []const u8,
66766685 field_name_src: LazySrcLoc,
66776686 unresolved_struct_ty: Type,
6678) InnerError!*Inst {
6687) InnerError!Air.Inst.Index {
66796688 const mod = sema.mod;
66806689 const arena = sema.arena;
66816690 assert(unresolved_struct_ty.zigTypeTag() == .Struct);
......@@ -6706,11 +6715,11 @@ fn analyzeUnionFieldPtr(
67066715 sema: *Sema,
67076716 block: *Scope.Block,
67086717 src: LazySrcLoc,
6709 union_ptr: *Inst,
6718 union_ptr: Air.Inst.Index,
67106719 field_name: []const u8,
67116720 field_name_src: LazySrcLoc,
67126721 unresolved_union_ty: Type,
6713) InnerError!*Inst {
6722) InnerError!Air.Inst.Index {
67146723 const mod = sema.mod;
67156724 const arena = sema.arena;
67166725 assert(unresolved_union_ty.zigTypeTag() == .Union);
......@@ -6743,10 +6752,10 @@ fn elemPtr(
67436752 sema: *Sema,
67446753 block: *Scope.Block,
67456754 src: LazySrcLoc,
6746 array_ptr: *Inst,
6747 elem_index: *Inst,
6755 array_ptr: Air.Inst.Index,
6756 elem_index: Air.Inst.Index,
67486757 elem_index_src: LazySrcLoc,
6749) InnerError!*Inst {
6758) InnerError!Air.Inst.Index {
67506759 const array_ty = switch (array_ptr.ty.zigTypeTag()) {
67516760 .Pointer => array_ptr.ty.elemType(),
67526761 else => return sema.mod.fail(&block.base, array_ptr.src, "expected pointer, found '{}'", .{array_ptr.ty}),
......@@ -6770,10 +6779,10 @@ fn elemPtrArray(
67706779 sema: *Sema,
67716780 block: *Scope.Block,
67726781 src: LazySrcLoc,
6773 array_ptr: *Inst,
6774 elem_index: *Inst,
6782 array_ptr: Air.Inst.Index,
6783 elem_index: Air.Inst.Index,
67756784 elem_index_src: LazySrcLoc,
6776) InnerError!*Inst {
6785) InnerError!Air.Inst.Index {
67776786 if (array_ptr.value()) |array_ptr_val| {
67786787 if (elem_index.value()) |index_val| {
67796788 // Both array pointer and index are compile-time known.
......@@ -6798,9 +6807,9 @@ fn coerce(
67986807 sema: *Sema,
67996808 block: *Scope.Block,
68006809 dest_type: Type,
6801 inst: *Inst,
6810 inst: Air.Inst.Index,
68026811 inst_src: LazySrcLoc,
6803) InnerError!*Inst {
6812) InnerError!Air.Inst.Index {
68046813 if (dest_type.tag() == .var_args_param) {
68056814 return sema.coerceVarArgParam(block, inst);
68066815 }
......@@ -6976,7 +6985,7 @@ fn coerceInMemoryAllowed(dest_type: Type, src_type: Type) InMemoryCoercionResult
69766985 return .no_match;
69776986}
69786987
6979fn coerceNum(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst) InnerError!?*Inst {
6988fn coerceNum(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) InnerError!?Air.Inst.Index {
69806989 const val = inst.value() orelse return null;
69816990 const src_zig_tag = inst.ty.zigTypeTag();
69826991 const dst_zig_tag = dest_type.zigTypeTag();
......@@ -7014,7 +7023,7 @@ fn coerceNum(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst) Inn
70147023 return null;
70157024}
70167025
7017fn coerceVarArgParam(sema: *Sema, block: *Scope.Block, inst: *Inst) !*Inst {
7026fn coerceVarArgParam(sema: *Sema, block: *Scope.Block, inst: Air.Inst.Index) !Air.Inst.Index {
70187027 switch (inst.ty.zigTypeTag()) {
70197028 .ComptimeInt, .ComptimeFloat => return sema.mod.fail(&block.base, inst.src, "integer and float literals in var args function must be casted", .{}),
70207029 else => {},
......@@ -7027,8 +7036,8 @@ fn storePtr(
70277036 sema: *Sema,
70287037 block: *Scope.Block,
70297038 src: LazySrcLoc,
7030 ptr: *Inst,
7031 uncasted_value: *Inst,
7039 ptr: Air.Inst.Index,
7040 uncasted_value: Air.Inst.Index,
70327041) !void {
70337042 if (ptr.ty.isConstPtr())
70347043 return sema.mod.fail(&block.base, src, "cannot assign to constant", .{});
......@@ -7076,7 +7085,7 @@ fn storePtr(
70767085 _ = try block.addBinOp(src, Type.initTag(.void), .store, ptr, value);
70777086}
70787087
7079fn bitcast(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst) !*Inst {
7088fn bitcast(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) !Air.Inst.Index {
70807089 if (inst.value()) |val| {
70817090 // Keep the comptime Value representation; take the new type.
70827091 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });
......@@ -7086,7 +7095,7 @@ fn bitcast(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst) !*Ins
70867095 return block.addUnOp(inst.src, dest_type, .bitcast, inst);
70877096}
70887097
7089fn coerceArrayPtrToSlice(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst) !*Inst {
7098fn coerceArrayPtrToSlice(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) !Air.Inst.Index {
70907099 if (inst.value()) |val| {
70917100 // The comptime Value representation is compatible with both types.
70927101 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });
......@@ -7094,7 +7103,7 @@ fn coerceArrayPtrToSlice(sema: *Sema, block: *Scope.Block, dest_type: Type, inst
70947103 return sema.mod.fail(&block.base, inst.src, "TODO implement coerceArrayPtrToSlice runtime instruction", .{});
70957104}
70967105
7097fn coerceArrayPtrToMany(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst) !*Inst {
7106fn coerceArrayPtrToMany(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) !Air.Inst.Index {
70987107 if (inst.value()) |val| {
70997108 // The comptime Value representation is compatible with both types.
71007109 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });
......@@ -7102,12 +7111,12 @@ fn coerceArrayPtrToMany(sema: *Sema, block: *Scope.Block, dest_type: Type, inst:
71027111 return sema.mod.fail(&block.base, inst.src, "TODO implement coerceArrayPtrToMany runtime instruction", .{});
71037112}
71047113
7105fn analyzeDeclVal(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) InnerError!*Inst {
7114fn analyzeDeclVal(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) InnerError!Air.Inst.Index {
71067115 const decl_ref = try sema.analyzeDeclRef(block, src, decl);
71077116 return sema.analyzeLoad(block, src, decl_ref, src);
71087117}
71097118
7110fn analyzeDeclRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) InnerError!*Inst {
7119fn analyzeDeclRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) InnerError!Air.Inst.Index {
71117120 try sema.mod.declareDeclDependency(sema.owner_decl, decl);
71127121 sema.mod.ensureDeclAnalyzed(decl) catch |err| {
71137122 if (sema.func) |func| {
......@@ -7128,7 +7137,7 @@ fn analyzeDeclRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl
71287137 });
71297138}
71307139
7131fn analyzeVarRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, tv: TypedValue) InnerError!*Inst {
7140fn analyzeVarRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, tv: TypedValue) InnerError!Air.Inst.Index {
71327141 const variable = tv.val.castTag(.variable).?.data;
71337142
71347143 const ty = try sema.mod.simplePtrType(sema.arena, tv.ty, variable.is_mutable, .One);
......@@ -7157,8 +7166,8 @@ fn analyzeRef(
71577166 sema: *Sema,
71587167 block: *Scope.Block,
71597168 src: LazySrcLoc,
7160 operand: *Inst,
7161) InnerError!*Inst {
7169 operand: Air.Inst.Index,
7170) InnerError!Air.Inst.Index {
71627171 const ptr_type = try sema.mod.simplePtrType(sema.arena, operand.ty, false, .One);
71637172
71647173 if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |val| {
......@@ -7176,9 +7185,9 @@ fn analyzeLoad(
71767185 sema: *Sema,
71777186 block: *Scope.Block,
71787187 src: LazySrcLoc,
7179 ptr: *Inst,
7188 ptr: Air.Inst.Index,
71807189 ptr_src: LazySrcLoc,
7181) InnerError!*Inst {
7190) InnerError!Air.Inst.Index {
71827191 const elem_ty = switch (ptr.ty.zigTypeTag()) {
71837192 .Pointer => ptr.ty.elemType(),
71847193 else => return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr.ty}),
......@@ -7201,9 +7210,9 @@ fn analyzeIsNull(
72017210 sema: *Sema,
72027211 block: *Scope.Block,
72037212 src: LazySrcLoc,
7204 operand: *Inst,
7213 operand: Air.Inst.Index,
72057214 invert_logic: bool,
7206) InnerError!*Inst {
7215) InnerError!Air.Inst.Index {
72077216 const result_ty = Type.initTag(.bool);
72087217 if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |opt_val| {
72097218 if (opt_val.isUndef()) {
......@@ -7222,8 +7231,8 @@ fn analyzeIsNonErr(
72227231 sema: *Sema,
72237232 block: *Scope.Block,
72247233 src: LazySrcLoc,
7225 operand: *Inst,
7226) InnerError!*Inst {
7234 operand: Air.Inst.Index,
7235) InnerError!Air.Inst.Index {
72277236 const ot = operand.ty.zigTypeTag();
72287237 if (ot != .ErrorSet and ot != .ErrorUnion) return sema.mod.constBool(sema.arena, src, true);
72297238 if (ot == .ErrorSet) return sema.mod.constBool(sema.arena, src, false);
......@@ -7243,12 +7252,12 @@ fn analyzeSlice(
72437252 sema: *Sema,
72447253 block: *Scope.Block,
72457254 src: LazySrcLoc,
7246 array_ptr: *Inst,
7247 start: *Inst,
7248 end_opt: ?*Inst,
7249 sentinel_opt: ?*Inst,
7255 array_ptr: Air.Inst.Index,
7256 start: Air.Inst.Index,
7257 end_opt: ?Air.Inst.Index,
7258 sentinel_opt: ?Air.Inst.Index,
72507259 sentinel_src: LazySrcLoc,
7251) InnerError!*Inst {
7260) InnerError!Air.Inst.Index {
72527261 const ptr_child = switch (array_ptr.ty.zigTypeTag()) {
72537262 .Pointer => array_ptr.ty.elemType(),
72547263 else => return sema.mod.fail(&block.base, src, "expected pointer, found '{}'", .{array_ptr.ty}),
......@@ -7319,10 +7328,10 @@ fn cmpNumeric(
73197328 sema: *Sema,
73207329 block: *Scope.Block,
73217330 src: LazySrcLoc,
7322 lhs: *Inst,
7323 rhs: *Inst,
7331 lhs: Air.Inst.Index,
7332 rhs: Air.Inst.Index,
73247333 op: std.math.CompareOperator,
7325) InnerError!*Inst {
7334) InnerError!Air.Inst.Index {
73267335 assert(lhs.ty.isNumeric());
73277336 assert(rhs.ty.isNumeric());
73287337
......@@ -7488,7 +7497,7 @@ fn cmpNumeric(
74887497 return block.addBinOp(src, Type.initTag(.bool), Inst.Tag.fromCmpOp(op), casted_lhs, casted_rhs);
74897498}
74907499
7491fn wrapOptional(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst) !*Inst {
7500fn wrapOptional(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) !Air.Inst.Index {
74927501 if (inst.value()) |val| {
74937502 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });
74947503 }
......@@ -7497,7 +7506,7 @@ fn wrapOptional(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst)
74977506 return block.addUnOp(inst.src, dest_type, .wrap_optional, inst);
74987507}
74997508
7500fn wrapErrorUnion(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst) !*Inst {
7509fn wrapErrorUnion(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) !Air.Inst.Index {
75017510 const err_union = dest_type.castTag(.error_union).?;
75027511 if (inst.value()) |val| {
75037512 if (inst.ty.zigTypeTag() != .ErrorSet) {
......@@ -7568,7 +7577,7 @@ fn wrapErrorUnion(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst
75687577 }
75697578}
75707579
7571fn resolvePeerTypes(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, instructions: []*Inst) !Type {
7580fn resolvePeerTypes(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, instructions: []Air.Inst.Index) !Type {
75727581 if (instructions.len == 0)
75737582 return Type.initTag(.noreturn);
75747583
......@@ -7704,7 +7713,7 @@ fn getBuiltin(
77047713 block: *Scope.Block,
77057714 src: LazySrcLoc,
77067715 name: []const u8,
7707) InnerError!*ir.Inst {
7716) InnerError!Air.Inst.Index {
77087717 const mod = sema.mod;
77097718 const std_pkg = mod.root_pkg.table.get("std").?;
77107719 const std_file = (mod.importPkg(std_pkg) catch unreachable).file;
src/codegen/spirv.zig+198-213
......@@ -18,14 +18,14 @@ pub const Word = u32;
1818pub const ResultId = u32;
1919
2020pub const TypeMap = std.HashMap(Type, u32, Type.HashContext64, std.hash_map.default_max_load_percentage);
21pub const InstMap = std.AutoHashMap(*Inst, ResultId);
21pub const InstMap = std.AutoHashMap(Air.Inst.Index, ResultId);
2222
2323const IncomingBlock = struct {
2424 src_label_id: ResultId,
2525 break_value_id: ResultId,
2626};
2727
28pub const BlockMap = std.AutoHashMap(*Inst.Block, struct {
28pub const BlockMap = std.AutoHashMap(Air.Inst.Index, struct {
2929 label_id: ResultId,
3030 incoming_blocks: *std.ArrayListUnmanaged(IncomingBlock),
3131});
......@@ -279,16 +279,17 @@ pub const DeclGen = struct {
279279 return self.spv.module.getTarget();
280280 }
281281
282 fn fail(self: *DeclGen, src: LazySrcLoc, comptime format: []const u8, args: anytype) Error {
282 fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error {
283283 @setCold(true);
284 const src: LazySrcLoc = .{ .node_offset = 0 };
284285 const src_loc = src.toSrcLocWithDecl(self.decl);
285286 self.error_msg = try Module.ErrorMsg.create(self.spv.module.gpa, src_loc, format, args);
286287 return error.AnalysisFail;
287288 }
288289
289 fn resolve(self: *DeclGen, inst: *Inst) !ResultId {
290 fn resolve(self: *DeclGen, inst: Air.Inst.Index) !ResultId {
290291 if (inst.value()) |val| {
291 return self.genConstant(inst.src, inst.ty, val);
292 return self.genConstant(inst.ty, val);
292293 }
293294
294295 return self.inst_results.get(inst).?; // Instruction does not dominate all uses!
......@@ -313,7 +314,7 @@ pub const DeclGen = struct {
313314 const target = self.getTarget();
314315
315316 // The backend will never be asked to compiler a 0-bit integer, so we won't have to handle those in this function.
316 std.debug.assert(bits != 0);
317 assert(bits != 0);
317318
318319 // 8, 16 and 64-bit integers require the Int8, Int16 and Inr64 capabilities respectively.
319320 // 32-bit integers are always supported (see spec, 2.16.1, Data rules).
......@@ -387,19 +388,19 @@ pub const DeclGen = struct {
387388 .composite_integer };
388389 },
389390 // As of yet, there is no vector support in the self-hosted compiler.
390 .Vector => self.fail(.{ .node_offset = 0 }, "TODO: SPIR-V backend: implement arithmeticTypeInfo for Vector", .{}),
391 .Vector => self.fail("TODO: SPIR-V backend: implement arithmeticTypeInfo for Vector", .{}),
391392 // TODO: For which types is this the case?
392 else => self.fail(.{ .node_offset = 0 }, "TODO: SPIR-V backend: implement arithmeticTypeInfo for {}", .{ty}),
393 else => self.fail("TODO: SPIR-V backend: implement arithmeticTypeInfo for {}", .{ty}),
393394 };
394395 }
395396
396397 /// Generate a constant representing `val`.
397398 /// TODO: Deduplication?
398 fn genConstant(self: *DeclGen, src: LazySrcLoc, ty: Type, val: Value) Error!ResultId {
399 fn genConstant(self: *DeclGen, ty: Type, val: Value) Error!ResultId {
399400 const target = self.getTarget();
400401 const code = &self.spv.binary.types_globals_constants;
401402 const result_id = self.spv.allocResultId();
402 const result_type_id = try self.genType(src, ty);
403 const result_type_id = try self.genType(ty);
403404
404405 if (val.isUndef()) {
405406 try writeInstruction(code, .OpUndef, &[_]Word{ result_type_id, result_id });
......@@ -411,13 +412,13 @@ pub const DeclGen = struct {
411412 const int_info = ty.intInfo(target);
412413 const backing_bits = self.backingIntBits(int_info.bits) orelse {
413414 // Integers too big for any native type are represented as "composite integers": An array of largestSupportedIntBits.
414 return self.fail(src, "TODO: SPIR-V backend: implement composite int constants for {}", .{ty});
415 return self.fail("TODO: SPIR-V backend: implement composite int constants for {}", .{ty});
415416 };
416417
417418 // We can just use toSignedInt/toUnsignedInt here as it returns u64 - a type large enough to hold any
418419 // SPIR-V native type (up to i/u64 with Int64). If SPIR-V ever supports native ints of a larger size, this
419420 // might need to be updated.
420 std.debug.assert(self.largestSupportedIntBits() <= std.meta.bitCount(u64));
421 assert(self.largestSupportedIntBits() <= std.meta.bitCount(u64));
421422 var int_bits = if (ty.isSignedInt()) @bitCast(u64, val.toSignedInt()) else val.toUnsignedInt();
422423
423424 // Mask the low bits which make up the actual integer. This is to make sure that negative values
......@@ -469,13 +470,13 @@ pub const DeclGen = struct {
469470 }
470471 },
471472 .Void => unreachable,
472 else => return self.fail(src, "TODO: SPIR-V backend: constant generation of type {}", .{ty}),
473 else => return self.fail("TODO: SPIR-V backend: constant generation of type {}", .{ty}),
473474 }
474475
475476 return result_id;
476477 }
477478
478 fn genType(self: *DeclGen, src: LazySrcLoc, ty: Type) Error!ResultId {
479 fn genType(self: *DeclGen, ty: Type) Error!ResultId {
479480 // We can't use getOrPut here so we can recursively generate types.
480481 if (self.spv.types.get(ty)) |already_generated| {
481482 return already_generated;
......@@ -492,7 +493,7 @@ pub const DeclGen = struct {
492493 const int_info = ty.intInfo(target);
493494 const backing_bits = self.backingIntBits(int_info.bits) orelse {
494495 // Integers too big for any native type are represented as "composite integers": An array of largestSupportedIntBits.
495 return self.fail(src, "TODO: SPIR-V backend: implement composite int {}", .{ty});
496 return self.fail("TODO: SPIR-V backend: implement composite int {}", .{ty});
496497 };
497498
498499 // TODO: If backing_bits != int_info.bits, a duplicate type might be generated here.
......@@ -518,7 +519,7 @@ pub const DeclGen = struct {
518519 };
519520
520521 if (!supported) {
521 return self.fail(src, "Floating point width of {} bits is not supported for the current SPIR-V feature set", .{bits});
522 return self.fail("Floating point width of {} bits is not supported for the current SPIR-V feature set", .{bits});
522523 }
523524
524525 try writeInstruction(code, .OpTypeFloat, &[_]Word{ result_id, bits });
......@@ -526,19 +527,19 @@ pub const DeclGen = struct {
526527 .Fn => {
527528 // We only support zig-calling-convention functions, no varargs.
528529 if (ty.fnCallingConvention() != .Unspecified)
529 return self.fail(src, "Unsupported calling convention for SPIR-V", .{});
530 return self.fail("Unsupported calling convention for SPIR-V", .{});
530531 if (ty.fnIsVarArgs())
531 return self.fail(src, "VarArgs unsupported for SPIR-V", .{});
532 return self.fail("VarArgs unsupported for SPIR-V", .{});
532533
533534 // In order to avoid a temporary here, first generate all the required types and then simply look them up
534535 // when generating the function type.
535536 const params = ty.fnParamLen();
536537 var i: usize = 0;
537538 while (i < params) : (i += 1) {
538 _ = try self.genType(src, ty.fnParamType(i));
539 _ = try self.genType(ty.fnParamType(i));
539540 }
540541
541 const return_type_id = try self.genType(src, ty.fnReturnType());
542 const return_type_id = try self.genType(ty.fnReturnType());
542543
543544 // result id + result type id + parameter type ids.
544545 try writeOpcode(code, .OpTypeFunction, 2 + @intCast(u16, ty.fnParamLen()));
......@@ -551,7 +552,7 @@ pub const DeclGen = struct {
551552 }
552553 },
553554 // When recursively generating a type, we cannot infer the pointer's storage class. See genPointerType.
554 .Pointer => return self.fail(src, "Cannot create pointer with unkown storage class", .{}),
555 .Pointer => return self.fail("Cannot create pointer with unkown storage class", .{}),
555556 .Vector => {
556557 // Although not 100% the same, Zig vectors map quite neatly to SPIR-V vectors (including many integer and float operations
557558 // which work on them), so simply use those.
......@@ -561,7 +562,7 @@ pub const DeclGen = struct {
561562 // is adequate at all for this.
562563
563564 // TODO: Vectors are not yet supported by the self-hosted compiler itself it seems.
564 return self.fail(src, "TODO: SPIR-V backend: implement type Vector", .{});
565 return self.fail("TODO: SPIR-V backend: implement type Vector", .{});
565566 },
566567 .Null,
567568 .Undefined,
......@@ -573,7 +574,7 @@ pub const DeclGen = struct {
573574
574575 .BoundFn => unreachable, // this type will be deleted from the language.
575576
576 else => |tag| return self.fail(src, "TODO: SPIR-V backend: implement type {}s", .{tag}),
577 else => |tag| return self.fail("TODO: SPIR-V backend: implement type {}s", .{tag}),
577578 }
578579
579580 try self.spv.types.putNoClobber(ty, result_id);
......@@ -582,8 +583,8 @@ pub const DeclGen = struct {
582583
583584 /// SPIR-V requires pointers to have a storage class (address space), and so we have a special function for that.
584585 /// TODO: The result of this needs to be cached.
585 fn genPointerType(self: *DeclGen, src: LazySrcLoc, ty: Type, storage_class: spec.StorageClass) !ResultId {
586 std.debug.assert(ty.zigTypeTag() == .Pointer);
586 fn genPointerType(self: *DeclGen, ty: Type, storage_class: spec.StorageClass) !ResultId {
587 assert(ty.zigTypeTag() == .Pointer);
587588
588589 const code = &self.spv.binary.types_globals_constants;
589590 const result_id = self.spv.allocResultId();
......@@ -591,7 +592,7 @@ pub const DeclGen = struct {
591592 // TODO: There are many constraints which are ignored for now: We may only create pointers to certain types, and to other types
592593 // if more capabilities are enabled. For example, we may only create pointers to f16 if Float16Buffer is enabled.
593594 // These also relates to the pointer's address space.
594 const child_id = try self.genType(src, ty.elemType());
595 const child_id = try self.genType(ty.elemType());
595596
596597 try writeInstruction(code, .OpTypePointer, &[_]Word{ result_id, @enumToInt(storage_class), child_id });
597598
......@@ -602,9 +603,9 @@ pub const DeclGen = struct {
602603 const decl = self.decl;
603604 const result_id = decl.fn_link.spirv.id;
604605
605 if (decl.val.castTag(.function)) |func_payload| {
606 std.debug.assert(decl.ty.zigTypeTag() == .Fn);
607 const prototype_id = try self.genType(.{ .node_offset = 0 }, decl.ty);
606 if (decl.val.castTag(.function)) |_| {
607 assert(decl.ty.zigTypeTag() == .Fn);
608 const prototype_id = try self.genType(decl.ty);
608609 try writeInstruction(&self.spv.binary.fn_decls, .OpFunction, &[_]Word{
609610 self.spv.types.get(decl.ty.fnReturnType()).?, // This type should be generated along with the prototype.
610611 result_id,
......@@ -631,189 +632,167 @@ pub const DeclGen = struct {
631632 try writeInstruction(&self.spv.binary.fn_decls, .OpLabel, &[_]Word{root_block_id});
632633 self.current_block_label_id = root_block_id;
633634
634 try self.genBody(func_payload.data.body);
635 const main_body = self.air.getMainBody();
636 try self.genBody(main_body);
635637
636638 // Append the actual code into the fn_decls section.
637639 try self.spv.binary.fn_decls.appendSlice(self.code.items);
638640 try writeInstruction(&self.spv.binary.fn_decls, .OpFunctionEnd, &[_]Word{});
639641 } else {
640 return self.fail(.{ .node_offset = 0 }, "TODO: SPIR-V backend: generate decl type {}", .{decl.ty.zigTypeTag()});
642 return self.fail("TODO: SPIR-V backend: generate decl type {}", .{decl.ty.zigTypeTag()});
641643 }
642644 }
643645
644 fn genBody(self: *DeclGen, body: ir.Body) Error!void {
645 for (body.instructions) |inst| {
646 fn genBody(self: *DeclGen, body: []const Air.Inst.Index) Error!void {
647 for (body) |inst| {
646648 try self.genInst(inst);
647649 }
648650 }
649651
650 fn genInst(self: *DeclGen, inst: *Inst) !void {
651 const result_id = switch (inst.tag) {
652 .add, .addwrap => try self.genBinOp(inst.castTag(.add).?),
653 .sub, .subwrap => try self.genBinOp(inst.castTag(.sub).?),
654 .mul, .mulwrap => try self.genBinOp(inst.castTag(.mul).?),
655 .div => try self.genBinOp(inst.castTag(.div).?),
656 .bit_and => try self.genBinOp(inst.castTag(.bit_and).?),
657 .bit_or => try self.genBinOp(inst.castTag(.bit_or).?),
658 .xor => try self.genBinOp(inst.castTag(.xor).?),
659 .cmp_eq => try self.genCmp(inst.castTag(.cmp_eq).?),
660 .cmp_neq => try self.genCmp(inst.castTag(.cmp_neq).?),
661 .cmp_gt => try self.genCmp(inst.castTag(.cmp_gt).?),
662 .cmp_gte => try self.genCmp(inst.castTag(.cmp_gte).?),
663 .cmp_lt => try self.genCmp(inst.castTag(.cmp_lt).?),
664 .cmp_lte => try self.genCmp(inst.castTag(.cmp_lte).?),
665 .bool_and => try self.genBinOp(inst.castTag(.bool_and).?),
666 .bool_or => try self.genBinOp(inst.castTag(.bool_or).?),
667 .not => try self.genUnOp(inst.castTag(.not).?),
668 .alloc => try self.genAlloc(inst.castTag(.alloc).?),
669 .arg => self.genArg(),
670 .block => (try self.genBlock(inst.castTag(.block).?)) orelse return,
671 .br => return try self.genBr(inst.castTag(.br).?),
672 .br_void => return try self.genBrVoid(inst.castTag(.br_void).?),
673 // TODO: Breakpoints won't be supported in SPIR-V, but the compiler seems to insert them
674 // throughout the IR.
652 fn genInst(self: *DeclGen, inst: Air.Inst.Index) !void {
653 const air_tags = self.air.instructions.items(.tag);
654 const result_id = switch (air_tags[inst]) {
655 // zig fmt: off
656 .add, .addwrap => try self.genArithOp(inst, .{.OpFAdd, .OpIAdd, .OpIAdd}),
657 .sub, .subwrap => try self.genArithOp(inst, .{.OpFSub, .OpISub, .OpISub}),
658 .mul, .mulwrap => try self.genArithOp(inst, .{.OpFMul, .OpIMul, .OpIMul}),
659 .div => try self.genArithOp(inst, .{.OpFDiv, .OpSDiv, .OpUDiv}),
660
661 .bit_and => try self.genBinOpSimple(inst, .OpBitwiseAnd),
662 .bit_or => try self.genBinOpSimple(inst, .OpBitwiseOr),
663 .xor => try self.genBinOpSimple(inst, .OpBitwiseXor),
664 .bool_and => try self.genBinOpSimple(inst, .OpLogicalAnd),
665 .bool_or => try self.genBinOpSimple(inst, .OpLogicalOr),
666
667 .not => try self.genNot(inst),
668
669 .cmp_eq => try self.genCmp(inst, .{.OpFOrdEqual, .OpLogicalEqual, .OpIEqual}),
670 .cmp_neq => try self.genCmp(inst, .{.OpFOrdNotEqual, .OpLogicalNotEqual, .OpINotEqual}),
671 .cmp_gt => try self.genCmp(inst, .{.OpFOrdGreaterThan, .OpSGreaterThan, .OpUGreaterThan}),
672 .cmp_gte => try self.genCmp(inst, .{.OpFOrdGreaterThanEqual, .OpSGreaterThanEqual, .OpUGreaterThanEqual}),
673 .cmp_lt => try self.genCmp(inst, .{.OpFOrdLessThan, .OpSLessThan, .OpULessThan}),
674 .cmp_lte => try self.genCmp(inst, .{.OpFOrdLessThanEqual, .OpSLessThanEqual, .OpULessThanEqual}),
675
676 .arg => self.genArg(),
677 .alloc => try self.genAlloc(inst),
678 .block => (try self.genBlock(inst)) orelse return,
679 .load => try self.genLoad(inst),
680
681 .br => return self.genBr(inst),
675682 .breakpoint => return,
676 .condbr => return try self.genCondBr(inst.castTag(.condbr).?),
677 .constant => unreachable,
678 .dbg_stmt => return try self.genDbgStmt(inst.castTag(.dbg_stmt).?),
679 .load => try self.genLoad(inst.castTag(.load).?),
680 .loop => return try self.genLoop(inst.castTag(.loop).?),
681 .ret => return try self.genRet(inst.castTag(.ret).?),
682 .retvoid => return try self.genRetVoid(),
683 .store => return try self.genStore(inst.castTag(.store).?),
684 .unreach => return try self.genUnreach(),
685 else => return self.fail(inst.src, "TODO: SPIR-V backend: implement inst {s}", .{@tagName(inst.tag)}),
683 .condbr => return self.genCondBr(inst),
684 .constant => unreachable,
685 .dbg_stmt => return self.genDbgStmt(inst),
686 .loop => return self.genLoop(inst),
687 .ret => return self.genRet(inst),
688 .store => return self.genStore(inst),
689 .unreach => return self.genUnreach(),
690 // zig fmt: on
686691 };
687692
688693 try self.inst_results.putNoClobber(inst, result_id);
689694 }
690695
691 fn genBinOp(self: *DeclGen, inst: *Inst.BinOp) !ResultId {
692 // TODO: Will lhs and rhs have the same type?
693 const lhs_id = try self.resolve(inst.lhs);
694 const rhs_id = try self.resolve(inst.rhs);
696 fn genBinOpSimple(self: *DeclGen, inst: Air.Inst.Index, opcode: Opcode) !ResultId {
697 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
698 const lhs_id = try self.resolve(bin_op.lhs);
699 const rhs_id = try self.resolve(bin_op.rhs);
700 const result_id = self.spv.allocResultId();
701 try writeInstruction(&self.code, opcode, &[_]Word{
702 result_type_id, result_id, lhs_id, rhs_id,
703 });
704 return result_id;
705 }
706
707 fn genArithOp(self: *DeclGen, inst: Air.Inst.Index, ops: [3]Opcode) !ResultId {
708 // LHS and RHS are guaranteed to have the same type, and AIR guarantees
709 // the result to be the same as the LHS and RHS, which matches SPIR-V.
710 const ty = self.air.getType(inst);
711 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
712 const lhs_id = try self.resolve(bin_op.lhs);
713 const rhs_id = try self.resolve(bin_op.rhs);
695714
696715 const result_id = self.spv.allocResultId();
697 const result_type_id = try self.genType(inst.base.src, inst.base.ty);
698
699 // TODO: Is the result the same as the argument types?
700 // This is supposed to be the case for SPIR-V.
701 std.debug.assert(inst.rhs.ty.eql(inst.lhs.ty));
702 std.debug.assert(inst.base.ty.tag() == .bool or inst.base.ty.eql(inst.lhs.ty));
703
704 // Binary operations are generally applicable to both scalar and vector operations in SPIR-V, but int and float
705 // versions of operations require different opcodes.
706 // For operations which produce bools, the information of inst.base.ty is not useful, so just pick either operand
707 // instead.
708 const info = try self.arithmeticTypeInfo(inst.lhs.ty);
709
710 if (info.class == .composite_integer) {
711 return self.fail(inst.base.src, "TODO: SPIR-V backend: binary operations for composite integers", .{});
712 } else if (info.class == .strange_integer) {
713 return self.fail(inst.base.src, "TODO: SPIR-V backend: binary operations for strange integers", .{});
714 }
716 const result_type_id = try self.genType(ty);
717
718 assert(self.air.getType(bin_op.lhs).eql(ty));
719 assert(self.air.getType(bin_op.rhs).eql(ty));
715720
716 const is_float = info.class == .float;
717 const is_signed = info.signedness == .signed;
718 // **Note**: All these operations must be valid for vectors as well!
719 const opcode = switch (inst.base.tag) {
720 // The regular integer operations are all defined for wrapping. Since theyre only relevant for integers,
721 // we can just switch on both cases here.
722 .add, .addwrap => if (is_float) Opcode.OpFAdd else Opcode.OpIAdd,
723 .sub, .subwrap => if (is_float) Opcode.OpFSub else Opcode.OpISub,
724 .mul, .mulwrap => if (is_float) Opcode.OpFMul else Opcode.OpIMul,
725 // TODO: Trap if divisor is 0?
726 // TODO: Figure out of OpSDiv for unsigned/OpUDiv for signed does anything useful.
727 // => Those are probably for divTrunc and divFloor, though the compiler does not yet generate those.
728 // => TODO: Figure out how those work on the SPIR-V side.
729 // => TODO: Test these.
730 .div => if (is_float) Opcode.OpFDiv else if (is_signed) Opcode.OpSDiv else Opcode.OpUDiv,
731 // Only integer versions for these.
732 .bit_and => Opcode.OpBitwiseAnd,
733 .bit_or => Opcode.OpBitwiseOr,
734 .xor => Opcode.OpBitwiseXor,
735 // Bool -> bool operations.
736 .bool_and => Opcode.OpLogicalAnd,
737 .bool_or => Opcode.OpLogicalOr,
721 // Binary operations are generally applicable to both scalar and vector operations
722 // in SPIR-V, but int and float versions of operations require different opcodes.
723 const info = try self.arithmeticTypeInfo(ty);
724
725 const opcode_index: usize = switch (info.class) {
726 .composite_integer => {
727 return self.fail("TODO: SPIR-V backend: binary operations for composite integers", .{});
728 },
729 .strange_integer => {
730 return self.fail("TODO: SPIR-V backend: binary operations for strange integers", .{});
731 },
732 .integer => switch (info.signedness) {
733 .signed => 1,
734 .unsigned => 2,
735 },
736 .float => 0,
738737 else => unreachable,
739738 };
740
739 const opcode = ops[opcode_index];
741740 try writeInstruction(&self.code, opcode, &[_]Word{ result_type_id, result_id, lhs_id, rhs_id });
742741
743742 // TODO: Trap on overflow? Probably going to be annoying.
744743 // TODO: Look into SPV_KHR_no_integer_wrap_decoration which provides NoSignedWrap/NoUnsignedWrap.
745744
746 if (info.class != .strange_integer)
747 return result_id;
748
749 return self.fail(inst.base.src, "TODO: SPIR-V backend: strange integer operation mask", .{});
745 return result_id;
750746 }
751747
752 fn genCmp(self: *DeclGen, inst: *Inst.BinOp) !ResultId {
753 const lhs_id = try self.resolve(inst.lhs);
754 const rhs_id = try self.resolve(inst.rhs);
755
748 fn genCmp(self: *DeclGen, inst: Air.Inst.Index, ops: [3]Opcode) !ResultId {
749 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
750 const lhs_id = try self.resolve(bin_op.lhs);
751 const rhs_id = try self.resolve(bin_op.rhs);
756752 const result_id = self.spv.allocResultId();
757 const result_type_id = try self.genType(inst.base.src, inst.base.ty);
758
759 // All of these operations should be 2 equal types -> bool
760 std.debug.assert(inst.rhs.ty.eql(inst.lhs.ty));
761 std.debug.assert(inst.base.ty.tag() == .bool);
762
763 // Comparisons are generally applicable to both scalar and vector operations in SPIR-V, but int and float
764 // versions of operations require different opcodes.
765 // Since inst.base.ty is always bool and so not very useful, and because both arguments must be the same, just get the info
766 // from either of the operands.
767 const info = try self.arithmeticTypeInfo(inst.lhs.ty);
768
769 if (info.class == .composite_integer) {
770 return self.fail(inst.base.src, "TODO: SPIR-V backend: binary operations for composite integers", .{});
771 } else if (info.class == .strange_integer) {
772 return self.fail(inst.base.src, "TODO: SPIR-V backend: comparison for strange integers", .{});
773 }
753 const result_type_id = try self.genType(Type.initTag(.bool));
754 const op_ty = self.air.getType(bin_op.lhs);
755 assert(op_ty.eql(self.air.getType(bin_op.rhs)));
774756
775 const is_bool = info.class == .bool;
776 const is_float = info.class == .float;
777 const is_signed = info.signedness == .signed;
778
779 // **Note**: All these operations must be valid for vectors as well!
780 // For floating points, we generally want ordered operations (which return false if either operand is nan).
781 const opcode = switch (inst.base.tag) {
782 .cmp_eq => if (is_float) Opcode.OpFOrdEqual else if (is_bool) Opcode.OpLogicalEqual else Opcode.OpIEqual,
783 .cmp_neq => if (is_float) Opcode.OpFOrdNotEqual else if (is_bool) Opcode.OpLogicalNotEqual else Opcode.OpINotEqual,
784 // TODO: Verify that these OpFOrd type operations produce the right value.
785 // TODO: Is there a more fundamental difference between OpU and OpS operations here than just the type?
786 .cmp_gt => if (is_float) Opcode.OpFOrdGreaterThan else if (is_signed) Opcode.OpSGreaterThan else Opcode.OpUGreaterThan,
787 .cmp_gte => if (is_float) Opcode.OpFOrdGreaterThanEqual else if (is_signed) Opcode.OpSGreaterThanEqual else Opcode.OpUGreaterThanEqual,
788 .cmp_lt => if (is_float) Opcode.OpFOrdLessThan else if (is_signed) Opcode.OpSLessThan else Opcode.OpULessThan,
789 .cmp_lte => if (is_float) Opcode.OpFOrdLessThanEqual else if (is_signed) Opcode.OpSLessThanEqual else Opcode.OpULessThanEqual,
757 // Comparisons are generally applicable to both scalar and vector operations in SPIR-V,
758 // but int and float versions of operations require different opcodes.
759 const info = try self.arithmeticTypeInfo(op_ty);
760
761 const opcode_index: usize = switch (info.class) {
762 .composite_integer => {
763 return self.fail("TODO: SPIR-V backend: binary operations for composite integers", .{});
764 },
765 .strange_integer => {
766 return self.fail("TODO: SPIR-V backend: comparison for strange integers", .{});
767 },
768 .float => 0,
769 .bool => 1,
770 .integer => switch (info.signedness) {
771 .signed => 1,
772 .unsigned => 2,
773 },
790774 else => unreachable,
791775 };
776 const opcode = ops[opcode_index];
792777
793778 try writeInstruction(&self.code, opcode, &[_]Word{ result_type_id, result_id, lhs_id, rhs_id });
794779 return result_id;
795780 }
796781
797 fn genUnOp(self: *DeclGen, inst: *Inst.UnOp) !ResultId {
798 const operand_id = try self.resolve(inst.operand);
799
782 fn genNot(self: *DeclGen, inst: Air.Inst.Index) !ResultId {
783 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
784 const operand_id = try self.resolve(ty_op.operand);
800785 const result_id = self.spv.allocResultId();
801 const result_type_id = try self.genType(inst.base.src, inst.base.ty);
802
803 const opcode = switch (inst.base.tag) {
804 // Bool -> bool
805 .not => Opcode.OpLogicalNot,
806 else => unreachable,
807 };
808
786 const result_type_id = try self.genType(Type.initTag(.bool));
787 const opcode: Opcode = .OpLogicalNot;
809788 try writeInstruction(&self.code, opcode, &[_]Word{ result_type_id, result_id, operand_id });
810
811789 return result_id;
812790 }
813791
814 fn genAlloc(self: *DeclGen, inst: *Inst.NoOp) !ResultId {
792 fn genAlloc(self: *DeclGen, inst: Air.Inst.Index) !ResultId {
793 const ty = self.air.getType(inst);
815794 const storage_class = spec.StorageClass.Function;
816 const result_type_id = try self.genPointerType(inst.base.src, inst.base.ty, storage_class);
795 const result_type_id = try self.genPointerType(ty, storage_class);
817796 const result_id = self.spv.allocResultId();
818797
819798 // Rather than generating into code here, we're just going to generate directly into the fn_decls section so that
......@@ -828,7 +807,7 @@ pub const DeclGen = struct {
828807 return self.args.items[self.next_arg_index];
829808 }
830809
831 fn genBlock(self: *DeclGen, inst: *Inst.Block) !?ResultId {
810 fn genBlock(self: *DeclGen, inst: Air.Inst.Index) !?ResultId {
832811 // In IR, a block doesn't really define an entry point like a block, but more like a scope that breaks can jump out of and
833812 // "return" a value from. This cannot be directly modelled in SPIR-V, so in a block instruction, we're going to split up
834813 // the current block by first generating the code of the block, then a label, and then generate the rest of the current
......@@ -848,11 +827,16 @@ pub const DeclGen = struct {
848827 incoming_blocks.deinit(self.spv.gpa);
849828 }
850829
851 try self.genBody(inst.body);
830 const ty = self.air.getType(inst);
831 const inst_datas = self.air.instructions.items(.data);
832 const extra = self.air.extraData(Air.Block, inst_datas[inst].ty_pl.payload);
833 const body = self.air.extra[extra.end..][0..extra.data.body_len];
834
835 try self.genBody(body);
852836 try self.beginSPIRVBlock(label_id);
853837
854838 // If this block didn't produce a value, simply return here.
855 if (!inst.base.ty.hasCodeGenBits())
839 if (!ty.hasCodeGenBits())
856840 return null;
857841
858842 // Combine the result from the blocks using the Phi instruction.
......@@ -862,7 +846,7 @@ pub const DeclGen = struct {
862846 // TODO: OpPhi is limited in the types that it may produce, such as pointers. Figure out which other types
863847 // are not allowed to be created from a phi node, and throw an error for those. For now, genType already throws
864848 // an error for pointers.
865 const result_type_id = try self.genType(inst.base.src, inst.base.ty);
849 const result_type_id = try self.genType(ty);
866850 _ = result_type_id;
867851
868852 try writeOpcode(&self.code, .OpPhi, 2 + @intCast(u16, incoming_blocks.items.len * 2)); // result type + result + variable/parent...
......@@ -874,30 +858,26 @@ pub const DeclGen = struct {
874858 return result_id;
875859 }
876860
877 fn genBr(self: *DeclGen, inst: *Inst.Br) !void {
878 // TODO: This instruction needs to be the last in a block. Is that guaranteed?
879 const target = self.blocks.get(inst.block).?;
861 fn genBr(self: *DeclGen, inst: Air.Inst.Index) !void {
862 const br = self.air.instructions.items(.data)[inst].br;
863 const block = self.blocks.get(br.block_inst).?;
864 const operand_ty = self.air.getType(br.operand);
880865
881 // TODO: For some reason, br is emitted with void parameters.
882 if (inst.operand.ty.hasCodeGenBits()) {
883 const operand_id = try self.resolve(inst.operand);
866 if (operand_ty.hasCodeGenBits()) {
867 const operand_id = try self.resolve(br.operand);
884868 // current_block_label_id should not be undefined here, lest there is a br or br_void in the function's body.
885 try target.incoming_blocks.append(self.spv.gpa, .{ .src_label_id = self.current_block_label_id, .break_value_id = operand_id });
869 try block.incoming_blocks.append(self.spv.gpa, .{ .src_label_id = self.current_block_label_id, .break_value_id = operand_id });
886870 }
887871
888 try writeInstruction(&self.code, .OpBranch, &[_]Word{target.label_id});
889 }
890
891 fn genBrVoid(self: *DeclGen, inst: *Inst.BrVoid) !void {
892 // TODO: This instruction needs to be the last in a block. Is that guaranteed?
893 const target = self.blocks.get(inst.block).?;
894 // Don't need to add this to the incoming block list, as there is no value to insert in the phi node anyway.
895 try writeInstruction(&self.code, .OpBranch, &[_]Word{target.label_id});
872 try writeInstruction(&self.code, .OpBranch, &[_]Word{block.label_id});
896873 }
897874
898875 fn genCondBr(self: *DeclGen, inst: *Inst.CondBr) !void {
899 // TODO: This instruction needs to be the last in a block. Is that guaranteed?
900 const condition_id = try self.resolve(inst.condition);
876 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
877 const cond_br = self.air.extraData(Air.CondBr, pl_op.payload);
878 const then_body = self.air.extra[cond_br.end..][0..cond_br.data.then_body_len];
879 const else_body = self.air.extra[cond_br.end + then_body.len ..][0..cond_br.data.else_body_len];
880 const condition_id = try self.resolve(pl_op.operand);
901881
902882 // These will always generate a new SPIR-V block, since they are ir.Body and not ir.Block.
903883 const then_label_id = self.spv.allocResultId();
......@@ -913,23 +893,26 @@ pub const DeclGen = struct {
913893 });
914894
915895 try self.beginSPIRVBlock(then_label_id);
916 try self.genBody(inst.then_body);
896 try self.genBody(then_body);
917897 try self.beginSPIRVBlock(else_label_id);
918 try self.genBody(inst.else_body);
898 try self.genBody(else_body);
919899 }
920900
921 fn genDbgStmt(self: *DeclGen, inst: *Inst.DbgStmt) !void {
901 fn genDbgStmt(self: *DeclGen, inst: Air.Inst.Index) !void {
902 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;
922903 const src_fname_id = try self.spv.resolveSourceFileName(self.decl);
923 try writeInstruction(&self.code, .OpLine, &[_]Word{ src_fname_id, inst.line, inst.column });
904 try writeInstruction(&self.code, .OpLine, &[_]Word{ src_fname_id, dbg_stmt.line, dbg_stmt.column });
924905 }
925906
926 fn genLoad(self: *DeclGen, inst: *Inst.UnOp) !ResultId {
927 const operand_id = try self.resolve(inst.operand);
907 fn genLoad(self: *DeclGen, inst: Air.Inst.Index) !ResultId {
908 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
909 const operand_id = try self.resolve(ty_op.operand);
910 const ty = self.air.getType(inst);
928911
929 const result_type_id = try self.genType(inst.base.src, inst.base.ty);
912 const result_type_id = try self.genType(ty);
930913 const result_id = self.spv.allocResultId();
931914
932 const operands = if (inst.base.ty.isVolatilePtr())
915 const operands = if (ty.isVolatilePtr())
933916 &[_]Word{ result_type_id, result_id, operand_id, @bitCast(u32, spec.MemoryAccess{ .Volatile = true }) }
934917 else
935918 &[_]Word{ result_type_id, result_id, operand_id };
......@@ -939,8 +922,9 @@ pub const DeclGen = struct {
939922 return result_id;
940923 }
941924
942 fn genLoop(self: *DeclGen, inst: *Inst.Loop) !void {
943 // TODO: This instruction needs to be the last in a block. Is that guaranteed?
925 fn genLoop(self: *DeclGen, inst: Air.Inst.Index) !void {
926 const loop = self.air.extraData(Air.Block, inst_datas[inst].ty_pl.payload);
927 const body = self.air.extra[loop.end..][0..loop.data.body_len];
944928 const loop_label_id = self.spv.allocResultId();
945929
946930 // Jump to the loop entry point
......@@ -949,27 +933,29 @@ pub const DeclGen = struct {
949933 // TODO: Look into OpLoopMerge.
950934
951935 try self.beginSPIRVBlock(loop_label_id);
952 try self.genBody(inst.body);
936 try self.genBody(body);
953937
954938 try writeInstruction(&self.code, .OpBranch, &[_]Word{loop_label_id});
955939 }
956940
957 fn genRet(self: *DeclGen, inst: *Inst.UnOp) !void {
958 const operand_id = try self.resolve(inst.operand);
959 // TODO: This instruction needs to be the last in a block. Is that guaranteed?
960 try writeInstruction(&self.code, .OpReturnValue, &[_]Word{operand_id});
961 }
962
963 fn genRetVoid(self: *DeclGen) !void {
964 // TODO: This instruction needs to be the last in a block. Is that guaranteed?
965 try writeInstruction(&self.code, .OpReturn, &[_]Word{});
941 fn genRet(self: *DeclGen, inst: Air.Inst.Index) !void {
942 const operand = inst_datas[inst].un_op;
943 const operand_ty = self.air.getType(operand);
944 if (operand_ty.hasCodeGenBits()) {
945 const operand_id = try self.resolve(operand);
946 try writeInstruction(&self.code, .OpReturnValue, &[_]Word{operand_id});
947 } else {
948 try writeInstruction(&self.code, .OpReturn, &[_]Word{});
949 }
966950 }
967951
968 fn genStore(self: *DeclGen, inst: *Inst.BinOp) !void {
969 const dst_ptr_id = try self.resolve(inst.lhs);
970 const src_val_id = try self.resolve(inst.rhs);
952 fn genStore(self: *DeclGen, inst: Air.Inst.Index) !void {
953 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
954 const dst_ptr_id = try self.resolve(bin_op.lhs);
955 const src_val_id = try self.resolve(bin_op.rhs);
956 const lhs_ty = self.air.getType(bin_op.lhs);
971957
972 const operands = if (inst.lhs.ty.isVolatilePtr())
958 const operands = if (lhs_ty.isVolatilePtr())
973959 &[_]Word{ dst_ptr_id, src_val_id, @bitCast(u32, spec.MemoryAccess{ .Volatile = true }) }
974960 else
975961 &[_]Word{ dst_ptr_id, src_val_id };
......@@ -978,7 +964,6 @@ pub const DeclGen = struct {
978964 }
979965
980966 fn genUnreach(self: *DeclGen) !void {
981 // TODO: This instruction needs to be the last in a block. Is that guaranteed?
982967 try writeInstruction(&self.code, .OpUnreachable, &[_]Word{});
983968 }
984969};