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 @@...@@ -1,24 +1,6 @@
1 * be sure to test debug info of parameters1 * 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
22 pub fn isUnused(self: Inst) bool {4 pub fn isUnused(self: Inst) bool {
23 return (self.deaths & (1 << unreferenced_bit_index)) != 0;5 return (self.deaths & (1 << unreferenced_bit_index)) != 0;
24 }6 }
...@@ -115,32 +97,6 @@...@@ -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
145/// For debugging purposes, prints a function representation to stderr.101/// For debugging purposes, prints a function representation to stderr.
146pub fn dumpFn(old_module: Module, module_fn: *Module.Fn) void {102pub fn dumpFn(old_module: Module, module_fn: *Module.Fn) void {
src/Air.zig+45-15
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1//! Analyzed Intermediate Representation.1//! 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
4const std = @import("std");6const std = @import("std");
5const Value = @import("value.zig").Value;7const Value = @import("value.zig").Value;
...@@ -27,38 +29,48 @@ pub const Inst = struct {...@@ -27,38 +29,48 @@ pub const Inst = struct {
27 data: Data,29 data: Data,
2830
29 pub const Tag = enum(u8) {31 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,
30 /// Float or integer addition. For integers, wrapping is undefined behavior.35 /// 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.
32 /// Uses the `bin_op` field.38 /// Uses the `bin_op` field.
33 add,39 add,
34 /// Integer addition. Wrapping is defined to be twos complement wrapping.40 /// 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.
36 /// Uses the `bin_op` field.43 /// Uses the `bin_op` field.
37 addwrap,44 addwrap,
38 /// Float or integer subtraction. For integers, wrapping is undefined behavior.45 /// 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.
40 /// Uses the `bin_op` field.48 /// Uses the `bin_op` field.
41 sub,49 sub,
42 /// Integer subtraction. Wrapping is defined to be twos complement wrapping.50 /// 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.
44 /// Uses the `bin_op` field.53 /// Uses the `bin_op` field.
45 subwrap,54 subwrap,
46 /// Float or integer multiplication. For integers, wrapping is undefined behavior.55 /// 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.
48 /// Uses the `bin_op` field.58 /// Uses the `bin_op` field.
49 mul,59 mul,
50 /// Integer multiplication. Wrapping is defined to be twos complement wrapping.60 /// 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.
52 /// Uses the `bin_op` field.63 /// Uses the `bin_op` field.
53 mulwrap,64 mulwrap,
54 /// Integer or float division. For integers, wrapping is undefined behavior.65 /// 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.
56 /// Uses the `bin_op` field.68 /// Uses the `bin_op` field.
57 div,69 div,
58 /// Allocates stack local memory.70 /// Allocates stack local memory.
59 /// Uses the `ty` field.71 /// Uses the `ty` field.
60 alloc,72 alloc,
61 /// TODO73 /// Inline assembly. Uses the `ty_pl` field. Payload is `Asm`.
62 assembly,74 assembly,
63 /// Bitwise AND. `&`.75 /// Bitwise AND. `&`.
64 /// Result type is the same as both operands.76 /// Result type is the same as both operands.
...@@ -80,7 +92,7 @@ pub const Inst = struct {...@@ -80,7 +92,7 @@ pub const Inst = struct {
80 /// Uses the `ty_pl` field with payload `Block`.92 /// Uses the `ty_pl` field with payload `Block`.
81 block,93 block,
82 /// Return from a block with a result.94 /// 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.
84 /// Uses the `br` field.96 /// Uses the `br` field.
85 br,97 br,
86 /// Lowers to a hardware trap instruction, or the next best thing.98 /// Lowers to a hardware trap instruction, or the next best thing.
...@@ -109,11 +121,11 @@ pub const Inst = struct {...@@ -109,11 +121,11 @@ pub const Inst = struct {
109 /// Uses the `bin_op` field.121 /// Uses the `bin_op` field.
110 cmp_neq,122 cmp_neq,
111 /// Conditional branch.123 /// Conditional branch.
112 /// Result type is always noreturn.124 /// Result type is always noreturn; no instructions in a block follow this one.
113 /// Uses the `pl_op` field. Operand is the condition. Payload is `CondBr`.125 /// Uses the `pl_op` field. Operand is the condition. Payload is `CondBr`.
114 cond_br,126 cond_br,
115 /// Switch branch.127 /// Switch branch.
116 /// Result type is always noreturn.128 /// Result type is always noreturn; no instructions in a block follow this one.
117 /// Uses the `pl_op` field. Operand is the condition. Payload is `SwitchBr`.129 /// Uses the `pl_op` field. Operand is the condition. Payload is `SwitchBr`.
118 switch_br,130 switch_br,
119 /// A comptime-known value. Uses the `ty_pl` field, payload is index of131 /// A comptime-known value. Uses the `ty_pl` field, payload is index of
...@@ -166,7 +178,7 @@ pub const Inst = struct {...@@ -166,7 +178,7 @@ pub const Inst = struct {
166 load,178 load,
167 /// A labeled block of code that loops forever. At the end of the body it is implied179 /// A labeled block of code that loops forever. At the end of the body it is implied
168 /// to repeat; no explicit "repeat" instruction terminates loop bodies.180 /// 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.
170 /// Uses the `ty_pl` field. Payload is `Block`.182 /// Uses the `ty_pl` field. Payload is `Block`.
171 loop,183 loop,
172 /// Converts a pointer to its address. Result type is always `usize`.184 /// Converts a pointer to its address. Result type is always `usize`.
...@@ -178,7 +190,7 @@ pub const Inst = struct {...@@ -178,7 +190,7 @@ pub const Inst = struct {
178 /// Uses the `ty_op` field.190 /// Uses the `ty_op` field.
179 ref,191 ref,
180 /// Return a value from a function.192 /// 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.
182 /// Uses the `un_op` field.194 /// Uses the `un_op` field.
183 ret,195 ret,
184 /// Returns a pointer to a global variable.196 /// Returns a pointer to a global variable.
...@@ -189,7 +201,7 @@ pub const Inst = struct {...@@ -189,7 +201,7 @@ pub const Inst = struct {
189 /// Uses the `bin_op` field.201 /// Uses the `bin_op` field.
190 store,202 store,
191 /// Indicates the program counter will never get to this instruction.203 /// 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.
193 unreach,205 unreach,
194 /// Convert from one float type to another.206 /// Convert from one float type to another.
195 /// Uses the `ty_op` field.207 /// Uses the `ty_op` field.
...@@ -343,6 +355,16 @@ pub const StructField = struct {...@@ -343,6 +355,16 @@ pub const StructField = struct {
343 field_index: u32,355 field_index: u32,
344};356};
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
346pub fn getMainBody(air: Air) []const Air.Inst.Index {368pub fn getMainBody(air: Air) []const Air.Inst.Index {
347 const body_index = air.extra[@enumToInt(ExtraIndex.main_block)];369 const body_index = air.extra[@enumToInt(ExtraIndex.main_block)];
348 const body_len = air.extra[body_index];370 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...@@ -369,3 +391,11 @@ pub fn extraData(air: Air, comptime T: type, index: usize) struct { data: T, end
369 .end = i,391 .end = i,
370 };392 };
371}393}
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");...@@ -13,7 +13,7 @@ const target_util = @import("target.zig");
13const Package = @import("Package.zig");13const Package = @import("Package.zig");
14const link = @import("link.zig");14const link = @import("link.zig");
15const trace = @import("tracy.zig").trace;15const trace = @import("tracy.zig").trace;
16const liveness = @import("liveness.zig");16const Liveness = @import("Liveness.zig");
17const build_options = @import("build_options");17const build_options = @import("build_options");
18const LibCInstallation = @import("libc_installation.zig").LibCInstallation;18const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
19const glibc = @import("glibc.zig");19const glibc = @import("glibc.zig");
...@@ -1922,6 +1922,7 @@ pub fn getCompileLogOutput(self: *Compilation) []const u8 {...@@ -1922,6 +1922,7 @@ pub fn getCompileLogOutput(self: *Compilation) []const u8 {
1922}1922}
19231923
1924pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemory }!void {1924pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemory }!void {
1925 const gpa = self.gpa;
1925 // If the terminal is dumb, we dont want to show the user all the1926 // If the terminal is dumb, we dont want to show the user all the
1926 // output.1927 // output.
1927 var progress: std.Progress = .{ .dont_print_on_dumb = true };1928 var progress: std.Progress = .{ .dont_print_on_dumb = true };
...@@ -2005,7 +2006,8 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor...@@ -2005,7 +2006,8 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
2005 assert(decl.has_tv);2006 assert(decl.has_tv);
2006 if (decl.val.castTag(.function)) |payload| {2007 if (decl.val.castTag(.function)) |payload| {
2007 const func = payload.data;2008 const func = payload.data;
2008 switch (func.state) {2009
2010 var air = switch (func.state) {
2009 .queued => module.analyzeFnBody(decl, func) catch |err| switch (err) {2011 .queued => module.analyzeFnBody(decl, func) catch |err| switch (err) {
2010 error.AnalysisFail => {2012 error.AnalysisFail => {
2011 assert(func.state != .in_progress);2013 assert(func.state != .in_progress);
...@@ -2016,18 +2018,39 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor...@@ -2016,18 +2018,39 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
2016 .in_progress => unreachable,2018 .in_progress => unreachable,
2017 .inline_only => unreachable, // don't queue work for this2019 .inline_only => unreachable, // don't queue work for this
2018 .sema_failure, .dependency_failure => continue,2020 .sema_failure, .dependency_failure => continue,
2019 .success => {},2021 .success => unreachable, // don't queue it twice
2020 }2022 };
2021 // Here we tack on additional allocations to the Decl's arena. The allocations2023 defer air.deinit(gpa);
2022 // are lifetime annotations in the ZIR.2024
2023 var decl_arena = decl.value_arena.?.promote(module.gpa);
2024 defer decl.value_arena.?.* = decl_arena.state;
2025 log.debug("analyze liveness of {s}", .{decl.name});2025 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
2028 if (std.builtin.mode == .Debug and self.verbose_air) {2029 if (std.builtin.mode == .Debug and self.verbose_air) {
2029 func.dump(module.*);2030 func.dump(module.*);
2030 }2031 }
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;
2031 }2054 }
20322055
2033 assert(decl.ty.hasCodeGenBits());2056 assert(decl.ty.hasCodeGenBits());
...@@ -2039,9 +2062,9 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor...@@ -2039,9 +2062,9 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
2039 continue;2062 continue;
2040 },2063 },
2041 else => {2064 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);
2043 module.failed_decls.putAssumeCapacityNoClobber(decl, try Module.ErrorMsg.create(2066 module.failed_decls.putAssumeCapacityNoClobber(decl, try Module.ErrorMsg.create(
2044 module.gpa,2067 gpa,
2045 decl.srcLoc(),2068 decl.srcLoc(),
2046 "unable to codegen: {s}",2069 "unable to codegen: {s}",
2047 .{@errorName(err)},2070 .{@errorName(err)},
...@@ -2070,7 +2093,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor...@@ -2070,7 +2093,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
2070 @panic("sadly stage2 is omitted from this build to save memory on the CI server");2093 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
2071 const module = self.bin_file.options.module.?;2094 const module = self.bin_file.options.module.?;
2072 const emit_h = module.emit_h.?;2095 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);
2074 const decl_emit_h = decl.getEmitH(module);2097 const decl_emit_h = decl.getEmitH(module);
2075 const fwd_decl = &decl_emit_h.fwd_decl;2098 const fwd_decl = &decl_emit_h.fwd_decl;
2076 fwd_decl.shrinkRetainingCapacity(0);2099 fwd_decl.shrinkRetainingCapacity(0);
...@@ -2079,7 +2102,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor...@@ -2079,7 +2102,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
2079 .module = module,2102 .module = module,
2080 .error_msg = null,2103 .error_msg = null,
2081 .decl = decl,2104 .decl = decl,
2082 .fwd_decl = fwd_decl.toManaged(module.gpa),2105 .fwd_decl = fwd_decl.toManaged(gpa),
2083 // we don't want to emit optionals and error unions to headers since they have no ABI2106 // we don't want to emit optionals and error unions to headers since they have no ABI
2084 .typedefs = undefined,2107 .typedefs = undefined,
2085 };2108 };
...@@ -2087,14 +2110,14 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor...@@ -2087,14 +2110,14 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
20872110
2088 c_codegen.genHeader(&dg) catch |err| switch (err) {2111 c_codegen.genHeader(&dg) catch |err| switch (err) {
2089 error.AnalysisFail => {2112 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.?);
2091 continue;2114 continue;
2092 },2115 },
2093 else => |e| return e,2116 else => |e| return e,
2094 };2117 };
20952118
2096 fwd_decl.* = dg.fwd_decl.moveToUnmanaged();2119 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);
2098 },2121 },
2099 },2122 },
2100 .analyze_decl => |decl| {2123 .analyze_decl => |decl| {
...@@ -2111,9 +2134,9 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor...@@ -2111,9 +2134,9 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
2111 @panic("sadly stage2 is omitted from this build to save memory on the CI server");2134 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
2112 const module = self.bin_file.options.module.?;2135 const module = self.bin_file.options.module.?;
2113 self.bin_file.updateDeclLineNumber(module, decl) catch |err| {2136 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);
2115 module.failed_decls.putAssumeCapacityNoClobber(decl, try Module.ErrorMsg.create(2138 module.failed_decls.putAssumeCapacityNoClobber(decl, try Module.ErrorMsg.create(
2116 module.gpa,2139 gpa,
2117 decl.srcLoc(),2140 decl.srcLoc(),
2118 "unable to update line number: {s}",2141 "unable to update line number: {s}",
2119 .{@errorName(err)},2142 .{@errorName(err)},
src/Liveness.zig+1
...@@ -150,6 +150,7 @@ fn analyzeInst(...@@ -150,6 +150,7 @@ fn analyzeInst(
150 const gpa = a.gpa;150 const gpa = a.gpa;
151 const table = &a.table;151 const table = &a.table;
152 const inst_tags = a.air.instructions.items(.tag);152 const inst_tags = a.air.instructions.items(.tag);
153 const inst_datas = a.air.instructions.items(.data);
153154
154 // No tombstone for this instruction means it is never referenced,155 // No tombstone for this instruction means it is never referenced,
155 // and its birth marks its own death. Very metal 🤘156 // and its birth marks its own death. Very metal 🤘
src/Module.zig+25-11
...@@ -739,8 +739,6 @@ pub const Union = struct {...@@ -739,8 +739,6 @@ pub const Union = struct {
739pub const Fn = struct {739pub const Fn = struct {
740 /// The Decl that corresponds to the function itself.740 /// The Decl that corresponds to the function itself.
741 owner_decl: *Decl,741 owner_decl: *Decl,
742 /// undefined unless analysis state is `success`.
743 body: ir.Body,
744 /// The ZIR instruction that is a function instruction. Use this to find742 /// The ZIR instruction that is a function instruction. Use this to find
745 /// the body. We store this rather than the body directly so that when ZIR743 /// the body. We store this rather than the body directly so that when ZIR
746 /// is regenerated on update(), we can map this to the new corresponding744 /// is regenerated on update(), we can map this to the new corresponding
...@@ -3585,17 +3583,19 @@ fn deleteDeclExports(mod: *Module, decl: *Decl) void {...@@ -3585,17 +3583,19 @@ fn deleteDeclExports(mod: *Module, decl: *Decl) void {
3585 mod.gpa.free(kv.value);3583 mod.gpa.free(kv.value);
3586}3584}
35873585
3588pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !void {3586pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !Air {
3589 const tracy = trace(@src());3587 const tracy = trace(@src());
3590 defer tracy.end();3588 defer tracy.end();
35913589
3590 const gpa = mod.gpa;
3591
3592 // Use the Decl's arena for function memory.3592 // 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);
3594 defer decl.value_arena.?.* = arena.state;3594 defer decl.value_arena.?.* = arena.state;
35953595
3596 const fn_ty = decl.ty;3596 const fn_ty = decl.ty;
3597 const param_inst_list = try mod.gpa.alloc(*ir.Inst, fn_ty.fnParamLen());3597 const param_inst_list = try gpa.alloc(*ir.Inst, fn_ty.fnParamLen());
3598 defer mod.gpa.free(param_inst_list);3598 defer gpa.free(param_inst_list);
35993599
3600 for (param_inst_list) |*param_inst, param_index| {3600 for (param_inst_list) |*param_inst, param_index| {
3601 const param_type = fn_ty.fnParamType(param_index);3601 const param_type = fn_ty.fnParamType(param_index);
...@@ -3615,7 +3615,7 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !void {...@@ -3615,7 +3615,7 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !void {
36153615
3616 var sema: Sema = .{3616 var sema: Sema = .{
3617 .mod = mod,3617 .mod = mod,
3618 .gpa = mod.gpa,3618 .gpa = gpa,
3619 .arena = &arena.allocator,3619 .arena = &arena.allocator,
3620 .code = zir,3620 .code = zir,
3621 .owner_decl = decl,3621 .owner_decl = decl,
...@@ -3626,6 +3626,11 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !void {...@@ -3626,6 +3626,11 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !void {
3626 };3626 };
3627 defer sema.deinit();3627 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
3629 var inner_block: Scope.Block = .{3634 var inner_block: Scope.Block = .{
3630 .parent = null,3635 .parent = null,
3631 .sema = &sema,3636 .sema = &sema,
...@@ -3634,20 +3639,29 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !void {...@@ -3634,20 +3639,29 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !void {
3634 .inlining = null,3639 .inlining = null,
3635 .is_comptime = false,3640 .is_comptime = false,
3636 };3641 };
3637 defer inner_block.instructions.deinit(mod.gpa);3642 defer inner_block.instructions.deinit(gpa);
36383643
3639 // AIR currently requires the arg parameters to be the first N instructions3644 // 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
3642 func.state = .in_progress;3647 func.state = .in_progress;
3643 log.debug("set {s} to in_progress", .{decl.name});3648 log.debug("set {s} to in_progress", .{decl.name});
36443649
3645 try sema.analyzeFnBody(&inner_block, func.zir_body_inst);3650 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
3648 func.state = .success;3656 func.state = .success;
3649 func.body = .{ .instructions = instructions };
3650 log.debug("set {s} to success", .{decl.name});3657 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 };
3651}3665}
36523666
3653fn markOutdatedDecl(mod: *Module, decl: *Decl) !void {3667fn markOutdatedDecl(mod: *Module, decl: *Decl) !void {
src/Sema.zig+286-277
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1//! Semantic analysis of ZIR instructions.1//! Semantic analysis of ZIR instructions.
2//! Shared to every Block. Stored on the stack.2//! Shared to every Block. Stored on the stack.
3//! State used for compiling a `Zir` into AIR.3//! State used for compiling a ZIR into AIR.
4//! Transforms untyped ZIR instructions into semantically-analyzed AIR instructions.4//! Transforms untyped ZIR instructions into semantically-analyzed AIR instructions.
5//! Does type checking, comptime control flow, and safety-check generation.5//! Does type checking, comptime control flow, and safety-check generation.
6//! This is the the heart of the Zig compiler.6//! This is the the heart of the Zig compiler.
...@@ -11,6 +11,10 @@ gpa: *Allocator,...@@ -11,6 +11,10 @@ gpa: *Allocator,
11/// Points to the arena allocator of the Decl.11/// Points to the arena allocator of the Decl.
12arena: *Allocator,12arena: *Allocator,
13code: Zir,13code: Zir,
14air_instructions: std.MultiArrayList(Air.Inst) = .{},
15air_extra: ArrayListUnmanaged(u32) = .{},
16air_values: ArrayListUnmanaged(Value) = .{},
17air_variables: ArrayListUnmanaged(Module.Var) = .{},
14/// Maps ZIR to AIR.18/// Maps ZIR to AIR.
15inst_map: InstMap = .{},19inst_map: InstMap = .{},
16/// When analyzing an inline function call, owner_decl is the Decl of the caller20/// When analyzing an inline function call, owner_decl is the Decl of the caller
...@@ -32,7 +36,7 @@ func: ?*Module.Fn,...@@ -32,7 +36,7 @@ func: ?*Module.Fn,
32/// > Denormalized data to make `resolveInst` faster. This is 0 if not inside a function,36/// > Denormalized data to make `resolveInst` faster. This is 0 if not inside a function,
33/// > otherwise it is the number of parameters of the function.37/// > otherwise it is the number of parameters of the function.
34/// > param_count: u3238/// > param_count: u32
35param_inst_list: []const *ir.Inst,39param_inst_list: []const Air.Inst.Index,
36branch_quota: u32 = 1000,40branch_quota: u32 = 1000,
37branch_count: u32 = 0,41branch_count: u32 = 0,
38/// This field is updated when a new source location becomes active, so that42/// This field is updated when a new source location becomes active, so that
...@@ -65,10 +69,15 @@ const LazySrcLoc = Module.LazySrcLoc;...@@ -65,10 +69,15 @@ const LazySrcLoc = Module.LazySrcLoc;
65const RangeSet = @import("RangeSet.zig");69const RangeSet = @import("RangeSet.zig");
66const target_util = @import("target.zig");70const 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
70pub fn deinit(sema: *Sema) void {74pub 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);
72 sema.* = undefined;81 sema.* = undefined;
73}82}
7483
...@@ -108,7 +117,7 @@ pub fn analyzeFnBody(...@@ -108,7 +117,7 @@ pub fn analyzeFnBody(
108/// Returns only the result from the body that is specified.117/// Returns only the result from the body that is specified.
109/// Only appropriate to call when it is determined at comptime that this body118/// Only appropriate to call when it is determined at comptime that this body
110/// has no peers.119/// 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 {
112 const break_inst = try sema.analyzeBody(block, body);121 const break_inst = try sema.analyzeBody(block, body);
113 const operand_ref = sema.code.instructions.items(.data)[break_inst].@"break".operand;122 const operand_ref = sema.code.instructions.items(.data)[break_inst].@"break".operand;
114 return sema.resolveInst(operand_ref);123 return sema.resolveInst(operand_ref);
...@@ -533,7 +542,7 @@ pub fn analyzeBody(...@@ -533,7 +542,7 @@ pub fn analyzeBody(
533 }542 }
534}543}
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 {
537 const extended = sema.code.instructions.items(.data)[inst].extended;546 const extended = sema.code.instructions.items(.data)[inst].extended;
538 switch (extended.opcode) {547 switch (extended.opcode) {
539 // zig fmt: off548 // zig fmt: off
...@@ -569,7 +578,7 @@ fn zirExtended(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -569,7 +578,7 @@ fn zirExtended(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
569}578}
570579
571/// TODO when we rework AIR memory layout, this function will no longer have a possible error.580/// 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 {
573 var i: usize = @enumToInt(zir_ref);582 var i: usize = @enumToInt(zir_ref);
574583
575 // First section of indexes correspond to a set number of constant values.584 // 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...@@ -618,19 +627,19 @@ pub fn resolveType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, zir_ref: Z
618 return sema.resolveAirAsType(block, src, air_inst);627 return sema.resolveAirAsType(block, src, air_inst);
619}628}
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 {
622 const wanted_type = Type.initTag(.@"type");631 const wanted_type = Type.initTag(.@"type");
623 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);632 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
624 const val = try sema.resolveConstValue(block, src, coerced_inst);633 const val = try sema.resolveConstValue(block, src, coerced_inst);
625 return val.toType(sema.arena);634 return val.toType(sema.arena);
626}635}
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 {
629 return (try sema.resolveDefinedValue(block, src, base)) orelse638 return (try sema.resolveDefinedValue(block, src, base)) orelse
630 return sema.failWithNeededComptime(block, src);639 return sema.failWithNeededComptime(block, src);
631}640}
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 {
634 if (try sema.resolvePossiblyUndefinedValue(block, src, base)) |val| {643 if (try sema.resolvePossiblyUndefinedValue(block, src, base)) |val| {
635 if (val.isUndef()) {644 if (val.isUndef()) {
636 return sema.failWithUseOfUndef(block, src);645 return sema.failWithUseOfUndef(block, src);
...@@ -644,7 +653,7 @@ fn resolvePossiblyUndefinedValue(...@@ -644,7 +653,7 @@ fn resolvePossiblyUndefinedValue(
644 sema: *Sema,653 sema: *Sema,
645 block: *Scope.Block,654 block: *Scope.Block,
646 src: LazySrcLoc,655 src: LazySrcLoc,
647 base: *ir.Inst,656 base: Air.Inst.Index,
648) !?Value {657) !?Value {
649 if (try sema.typeHasOnePossibleValue(block, src, base.ty)) |opv| {658 if (try sema.typeHasOnePossibleValue(block, src, base.ty)) |opv| {
650 return opv;659 return opv;
...@@ -708,13 +717,13 @@ pub fn resolveInstConst(...@@ -708,13 +717,13 @@ pub fn resolveInstConst(
708 };717 };
709}718}
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 {
712 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;721 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
713 const src = inst_data.src();722 const src = inst_data.src();
714 return sema.mod.fail(&block.base, src, "TODO implement zir_sema.zirBitcastResultPtr", .{});723 return sema.mod.fail(&block.base, src, "TODO implement zir_sema.zirBitcastResultPtr", .{});
715}724}
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 {
718 _ = inst;727 _ = inst;
719 const tracy = trace(@src());728 const tracy = trace(@src());
720 defer tracy.end();729 defer tracy.end();
...@@ -749,7 +758,7 @@ fn zirStructDecl(...@@ -749,7 +758,7 @@ fn zirStructDecl(
749 block: *Scope.Block,758 block: *Scope.Block,
750 extended: Zir.Inst.Extended.InstData,759 extended: Zir.Inst.Extended.InstData,
751 inst: Zir.Inst.Index,760 inst: Zir.Inst.Index,
752) InnerError!*Inst {761) InnerError!Air.Inst.Index {
753 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);762 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);
754 const src: LazySrcLoc = if (small.has_src_node) blk: {763 const src: LazySrcLoc = if (small.has_src_node) blk: {
755 const node_offset = @bitCast(i32, sema.code.extra[extended.operand]);764 const node_offset = @bitCast(i32, sema.code.extra[extended.operand]);
...@@ -820,7 +829,7 @@ fn zirEnumDecl(...@@ -820,7 +829,7 @@ fn zirEnumDecl(
820 sema: *Sema,829 sema: *Sema,
821 block: *Scope.Block,830 block: *Scope.Block,
822 extended: Zir.Inst.Extended.InstData,831 extended: Zir.Inst.Extended.InstData,
823) InnerError!*Inst {832) InnerError!Air.Inst.Index {
824 const tracy = trace(@src());833 const tracy = trace(@src());
825 defer tracy.end();834 defer tracy.end();
826835
...@@ -1017,7 +1026,7 @@ fn zirUnionDecl(...@@ -1017,7 +1026,7 @@ fn zirUnionDecl(
1017 block: *Scope.Block,1026 block: *Scope.Block,
1018 extended: Zir.Inst.Extended.InstData,1027 extended: Zir.Inst.Extended.InstData,
1019 inst: Zir.Inst.Index,1028 inst: Zir.Inst.Index,
1020) InnerError!*Inst {1029) InnerError!Air.Inst.Index {
1021 const tracy = trace(@src());1030 const tracy = trace(@src());
1022 defer tracy.end();1031 defer tracy.end();
10231032
...@@ -1081,7 +1090,7 @@ fn zirOpaqueDecl(...@@ -1081,7 +1090,7 @@ fn zirOpaqueDecl(
1081 block: *Scope.Block,1090 block: *Scope.Block,
1082 inst: Zir.Inst.Index,1091 inst: Zir.Inst.Index,
1083 name_strategy: Zir.Inst.NameStrategy,1092 name_strategy: Zir.Inst.NameStrategy,
1084) InnerError!*Inst {1093) InnerError!Air.Inst.Index {
1085 const tracy = trace(@src());1094 const tracy = trace(@src());
1086 defer tracy.end();1095 defer tracy.end();
10871096
...@@ -1101,7 +1110,7 @@ fn zirErrorSetDecl(...@@ -1101,7 +1110,7 @@ fn zirErrorSetDecl(
1101 block: *Scope.Block,1110 block: *Scope.Block,
1102 inst: Zir.Inst.Index,1111 inst: Zir.Inst.Index,
1103 name_strategy: Zir.Inst.NameStrategy,1112 name_strategy: Zir.Inst.NameStrategy,
1104) InnerError!*Inst {1113) InnerError!Air.Inst.Index {
1105 const tracy = trace(@src());1114 const tracy = trace(@src());
1106 defer tracy.end();1115 defer tracy.end();
11071116
...@@ -1141,7 +1150,7 @@ fn zirRetPtr(...@@ -1141,7 +1150,7 @@ fn zirRetPtr(
1141 sema: *Sema,1150 sema: *Sema,
1142 block: *Scope.Block,1151 block: *Scope.Block,
1143 extended: Zir.Inst.Extended.InstData,1152 extended: Zir.Inst.Extended.InstData,
1144) InnerError!*Inst {1153) InnerError!Air.Inst.Index {
1145 const tracy = trace(@src());1154 const tracy = trace(@src());
1146 defer tracy.end();1155 defer tracy.end();
11471156
...@@ -1153,7 +1162,7 @@ fn zirRetPtr(...@@ -1153,7 +1162,7 @@ fn zirRetPtr(
1153 return block.addNoOp(src, ptr_type, .alloc);1162 return block.addNoOp(src, ptr_type, .alloc);
1154}1163}
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 {
1157 const tracy = trace(@src());1166 const tracy = trace(@src());
1158 defer tracy.end();1167 defer tracy.end();
11591168
...@@ -1166,7 +1175,7 @@ fn zirRetType(...@@ -1166,7 +1175,7 @@ fn zirRetType(
1166 sema: *Sema,1175 sema: *Sema,
1167 block: *Scope.Block,1176 block: *Scope.Block,
1168 extended: Zir.Inst.Extended.InstData,1177 extended: Zir.Inst.Extended.InstData,
1169) InnerError!*Inst {1178) InnerError!Air.Inst.Index {
1170 const tracy = trace(@src());1179 const tracy = trace(@src());
1171 defer tracy.end();1180 defer tracy.end();
11721181
...@@ -1191,7 +1200,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) I...@@ -1191,7 +1200,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) I
1191fn ensureResultUsed(1200fn ensureResultUsed(
1192 sema: *Sema,1201 sema: *Sema,
1193 block: *Scope.Block,1202 block: *Scope.Block,
1194 operand: *Inst,1203 operand: Air.Inst.Index,
1195 src: LazySrcLoc,1204 src: LazySrcLoc,
1196) InnerError!void {1205) InnerError!void {
1197 switch (operand.ty.zigTypeTag()) {1206 switch (operand.ty.zigTypeTag()) {
...@@ -1213,7 +1222,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde...@@ -1213,7 +1222,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
1213 }1222 }
1214}1223}
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 {
1217 const tracy = trace(@src());1226 const tracy = trace(@src());
1218 defer tracy.end();1227 defer tracy.end();
12191228
...@@ -1247,7 +1256,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In...@@ -1247,7 +1256,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In
1247 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);1256 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);
1248}1257}
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 {
1251 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;1260 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
1252 const arg_name = inst_data.get(sema.code);1261 const arg_name = inst_data.get(sema.code);
1253 const arg_index = sema.next_arg_index;1262 const arg_index = sema.next_arg_index;
...@@ -1269,13 +1278,13 @@ fn zirAllocExtended(...@@ -1269,13 +1278,13 @@ fn zirAllocExtended(
1269 sema: *Sema,1278 sema: *Sema,
1270 block: *Scope.Block,1279 block: *Scope.Block,
1271 extended: Zir.Inst.Extended.InstData,1280 extended: Zir.Inst.Extended.InstData,
1272) InnerError!*Inst {1281) InnerError!Air.Inst.Index {
1273 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);1282 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);
1274 const src: LazySrcLoc = .{ .node_offset = extra.data.src_node };1283 const src: LazySrcLoc = .{ .node_offset = extra.data.src_node };
1275 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocExtended", .{});1284 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocExtended", .{});
1276}1285}
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 {
1279 const tracy = trace(@src());1288 const tracy = trace(@src());
1280 defer tracy.end();1289 defer tracy.end();
12811290
...@@ -1298,13 +1307,13 @@ fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne...@@ -1298,13 +1307,13 @@ fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
1298 });1307 });
1299}1308}
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 {
1302 const src_node = sema.code.instructions.items(.data)[inst].node;1311 const src_node = sema.code.instructions.items(.data)[inst].node;
1303 const src: LazySrcLoc = .{ .node_offset = src_node };1312 const src: LazySrcLoc = .{ .node_offset = src_node };
1304 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocInferredComptime", .{});1313 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocInferredComptime", .{});
1305}1314}
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 {
1308 const tracy = trace(@src());1317 const tracy = trace(@src());
1309 defer tracy.end();1318 defer tracy.end();
13101319
...@@ -1317,7 +1326,7 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*...@@ -1317,7 +1326,7 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*
1317 return block.addNoOp(var_decl_src, ptr_type, .alloc);1326 return block.addNoOp(var_decl_src, ptr_type, .alloc);
1318}1327}
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 {
1321 const tracy = trace(@src());1330 const tracy = trace(@src());
1322 defer tracy.end();1331 defer tracy.end();
13231332
...@@ -1336,7 +1345,7 @@ fn zirAllocInferred(...@@ -1336,7 +1345,7 @@ fn zirAllocInferred(
1336 block: *Scope.Block,1345 block: *Scope.Block,
1337 inst: Zir.Inst.Index,1346 inst: Zir.Inst.Index,
1338 inferred_alloc_ty: Type,1347 inferred_alloc_ty: Type,
1339) InnerError!*Inst {1348) InnerError!Air.Inst.Index {
1340 const tracy = trace(@src());1349 const tracy = trace(@src());
1341 defer tracy.end();1350 defer tracy.end();
13421351
...@@ -1589,7 +1598,7 @@ fn zirStoreNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr...@@ -1589,7 +1598,7 @@ fn zirStoreNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
1589 return sema.storePtr(block, src, ptr, value);1598 return sema.storePtr(block, src, ptr, value);
1590}1599}
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 {
1593 const tracy = trace(@src());1602 const tracy = trace(@src());
1594 defer tracy.end();1603 defer tracy.end();
15951604
...@@ -1625,7 +1634,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr...@@ -1625,7 +1634,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
1625 return sema.mod.constType(sema.arena, src, param_type);1634 return sema.mod.constType(sema.arena, src, param_type);
1626}1635}
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 {
1629 const tracy = trace(@src());1638 const tracy = trace(@src());
1630 defer tracy.end();1639 defer tracy.end();
16311640
...@@ -1653,7 +1662,7 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In...@@ -1653,7 +1662,7 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In
1653 return sema.analyzeDeclRef(block, .unneeded, new_decl);1662 return sema.analyzeDeclRef(block, .unneeded, new_decl);
1654}1663}
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 {
1657 _ = block;1666 _ = block;
1658 const tracy = trace(@src());1667 const tracy = trace(@src());
1659 defer tracy.end();1668 defer tracy.end();
...@@ -1662,7 +1671,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In...@@ -1662,7 +1671,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In
1662 return sema.mod.constIntUnsigned(sema.arena, .unneeded, Type.initTag(.comptime_int), int);1671 return sema.mod.constIntUnsigned(sema.arena, .unneeded, Type.initTag(.comptime_int), int);
1663}1672}
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 {
1666 _ = block;1675 _ = block;
1667 const tracy = trace(@src());1676 const tracy = trace(@src());
1668 defer tracy.end();1677 defer tracy.end();
...@@ -1680,7 +1689,7 @@ fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!...@@ -1680,7 +1689,7 @@ fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
1680 });1689 });
1681}1690}
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 {
1684 _ = block;1693 _ = block;
1685 const arena = sema.arena;1694 const arena = sema.arena;
1686 const inst_data = sema.code.instructions.items(.data)[inst].float;1695 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!*...@@ -1693,7 +1702,7 @@ fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*
1693 });1702 });
1694}1703}
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 {
1697 _ = block;1706 _ = block;
1698 const arena = sema.arena;1707 const arena = sema.arena;
1699 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1708 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
...@@ -1722,7 +1731,7 @@ fn zirCompileLog(...@@ -1722,7 +1731,7 @@ fn zirCompileLog(
1722 sema: *Sema,1731 sema: *Sema,
1723 block: *Scope.Block,1732 block: *Scope.Block,
1724 extended: Zir.Inst.Extended.InstData,1733 extended: Zir.Inst.Extended.InstData,
1725) InnerError!*Inst {1734) InnerError!Air.Inst.Index {
1726 var managed = sema.mod.compile_log_text.toManaged(sema.gpa);1735 var managed = sema.mod.compile_log_text.toManaged(sema.gpa);
1727 defer sema.mod.compile_log_text = managed.moveToUnmanaged();1736 defer sema.mod.compile_log_text = managed.moveToUnmanaged();
1728 const writer = managed.writer();1737 const writer = managed.writer();
...@@ -1772,7 +1781,7 @@ fn zirPanic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Z...@@ -1772,7 +1781,7 @@ fn zirPanic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Z
1772 return sema.panicWithMsg(block, src, msg_inst);1781 return sema.panicWithMsg(block, src, msg_inst);
1773}1782}
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 {
1776 const tracy = trace(@src());1785 const tracy = trace(@src());
1777 defer tracy.end();1786 defer tracy.end();
17781787
...@@ -1832,12 +1841,12 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerE...@@ -1832,12 +1841,12 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerE
1832 // Loop repetition is implied so the last instruction may or may not be a noreturn instruction.1841 // Loop repetition is implied so the last instruction may or may not be a noreturn instruction.
18331842
1834 try child_block.instructions.append(sema.gpa, &loop_inst.base);1843 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
1837 return sema.analyzeBlockBody(parent_block, src, &child_block, merges);1846 return sema.analyzeBlockBody(parent_block, src, &child_block, merges);
1838}1847}
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 {
1841 const tracy = trace(@src());1850 const tracy = trace(@src());
1842 defer tracy.end();1851 defer tracy.end();
18431852
...@@ -1847,13 +1856,13 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Inn...@@ -1847,13 +1856,13 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Inn
1847 return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirCImport", .{});1856 return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirCImport", .{});
1848}1857}
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 {
1851 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1860 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1852 const src = inst_data.src();1861 const src = inst_data.src();
1853 return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirSuspendBlock", .{});1862 return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirSuspendBlock", .{});
1854}1863}
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 {
1857 const tracy = trace(@src());1866 const tracy = trace(@src());
1858 defer tracy.end();1867 defer tracy.end();
18591868
...@@ -1911,7 +1920,7 @@ fn resolveBlockBody(...@@ -1911,7 +1920,7 @@ fn resolveBlockBody(
1911 child_block: *Scope.Block,1920 child_block: *Scope.Block,
1912 body: []const Zir.Inst.Index,1921 body: []const Zir.Inst.Index,
1913 merges: *Scope.Block.Merges,1922 merges: *Scope.Block.Merges,
1914) InnerError!*Inst {1923) InnerError!Air.Inst.Index {
1915 _ = try sema.analyzeBody(child_block, body);1924 _ = try sema.analyzeBody(child_block, body);
1916 return sema.analyzeBlockBody(parent_block, src, child_block, merges);1925 return sema.analyzeBlockBody(parent_block, src, child_block, merges);
1917}1926}
...@@ -1922,7 +1931,7 @@ fn analyzeBlockBody(...@@ -1922,7 +1931,7 @@ fn analyzeBlockBody(
1922 src: LazySrcLoc,1931 src: LazySrcLoc,
1923 child_block: *Scope.Block,1932 child_block: *Scope.Block,
1924 merges: *Scope.Block.Merges,1933 merges: *Scope.Block.Merges,
1925) InnerError!*Inst {1934) InnerError!Air.Inst.Index {
1926 const tracy = trace(@src());1935 const tracy = trace(@src());
1927 defer tracy.end();1936 defer tracy.end();
19281937
...@@ -1933,7 +1942,7 @@ fn analyzeBlockBody(...@@ -1933,7 +1942,7 @@ fn analyzeBlockBody(
1933 if (merges.results.items.len == 0) {1942 if (merges.results.items.len == 0) {
1934 // No need for a block instruction. We can put the new instructions1943 // No need for a block instruction. We can put the new instructions
1935 // directly into the parent block.1944 // 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);
1937 try parent_block.instructions.appendSlice(sema.gpa, copied_instructions);1946 try parent_block.instructions.appendSlice(sema.gpa, copied_instructions);
1938 return copied_instructions[copied_instructions.len - 1];1947 return copied_instructions[copied_instructions.len - 1];
1939 }1948 }
...@@ -1944,7 +1953,7 @@ fn analyzeBlockBody(...@@ -1944,7 +1953,7 @@ fn analyzeBlockBody(
1944 if (br_block == merges.block_inst) {1953 if (br_block == merges.block_inst) {
1945 // No need for a block instruction. We can put the new instructions directly1954 // No need for a block instruction. We can put the new instructions directly
1946 // into the parent block. Here we omit the break instruction.1955 // 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]);
1948 try parent_block.instructions.appendSlice(sema.gpa, copied_instructions);1957 try parent_block.instructions.appendSlice(sema.gpa, copied_instructions);
1949 return merges.results.items[0];1958 return merges.results.items[0];
1950 }1959 }
...@@ -1959,7 +1968,7 @@ fn analyzeBlockBody(...@@ -1959,7 +1968,7 @@ fn analyzeBlockBody(
1959 const resolved_ty = try sema.resolvePeerTypes(parent_block, src, merges.results.items);1968 const resolved_ty = try sema.resolvePeerTypes(parent_block, src, merges.results.items);
1960 merges.block_inst.base.ty = resolved_ty;1969 merges.block_inst.base.ty = resolved_ty;
1961 merges.block_inst.body = .{1970 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),
1963 };1972 };
1964 // Now that the block has its type resolved, we need to go back into all the break1973 // Now that the block has its type resolved, we need to go back into all the break
1965 // instructions, and insert type coercion on the operands.1974 // instructions, and insert type coercion on the operands.
...@@ -1991,7 +2000,7 @@ fn analyzeBlockBody(...@@ -1991,7 +2000,7 @@ fn analyzeBlockBody(
1991 },2000 },
1992 .block = merges.block_inst,2001 .block = merges.block_inst,
1993 .body = .{2002 .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),
1995 },2004 },
1996 };2005 };
1997 }2006 }
...@@ -2130,7 +2139,7 @@ fn zirDbgStmt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -2130,7 +2139,7 @@ fn zirDbgStmt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
2130 _ = try block.addDbgStmt(.unneeded, inst_data.line, inst_data.column);2139 _ = try block.addDbgStmt(.unneeded, inst_data.line, inst_data.column);
2131}2140}
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 {
2134 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;2143 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
2135 const src = inst_data.src();2144 const src = inst_data.src();
2136 const decl_name = inst_data.get(sema.code);2145 const decl_name = inst_data.get(sema.code);
...@@ -2138,7 +2147,7 @@ fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -2138,7 +2147,7 @@ fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
2138 return sema.analyzeDeclRef(block, src, decl);2147 return sema.analyzeDeclRef(block, src, decl);
2139}2148}
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 {
2142 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;2151 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
2143 const src = inst_data.src();2152 const src = inst_data.src();
2144 const decl_name = inst_data.get(sema.code);2153 const decl_name = inst_data.get(sema.code);
...@@ -2192,7 +2201,7 @@ fn zirCall(...@@ -2192,7 +2201,7 @@ fn zirCall(
2192 inst: Zir.Inst.Index,2201 inst: Zir.Inst.Index,
2193 modifier: std.builtin.CallOptions.Modifier,2202 modifier: std.builtin.CallOptions.Modifier,
2194 ensure_result_used: bool,2203 ensure_result_used: bool,
2195) InnerError!*Inst {2204) InnerError!Air.Inst.Index {
2196 const tracy = trace(@src());2205 const tracy = trace(@src());
2197 defer tracy.end();2206 defer tracy.end();
21982207
...@@ -2204,7 +2213,7 @@ fn zirCall(...@@ -2204,7 +2213,7 @@ fn zirCall(
22042213
2205 const func = try sema.resolveInst(extra.data.callee);2214 const func = try sema.resolveInst(extra.data.callee);
2206 // TODO handle function calls of generic functions2215 // 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);
2208 for (args) |zir_arg, i| {2217 for (args) |zir_arg, i| {
2209 // the args are already casted to the result of a param type instruction.2218 // the args are already casted to the result of a param type instruction.
2210 resolved_args[i] = try sema.resolveInst(zir_arg);2219 resolved_args[i] = try sema.resolveInst(zir_arg);
...@@ -2216,13 +2225,13 @@ fn zirCall(...@@ -2216,13 +2225,13 @@ fn zirCall(
2216fn analyzeCall(2225fn analyzeCall(
2217 sema: *Sema,2226 sema: *Sema,
2218 block: *Scope.Block,2227 block: *Scope.Block,
2219 func: *ir.Inst,2228 func: Air.Inst.Index,
2220 func_src: LazySrcLoc,2229 func_src: LazySrcLoc,
2221 call_src: LazySrcLoc,2230 call_src: LazySrcLoc,
2222 modifier: std.builtin.CallOptions.Modifier,2231 modifier: std.builtin.CallOptions.Modifier,
2223 ensure_result_used: bool,2232 ensure_result_used: bool,
2224 args: []const *ir.Inst,2233 args: []const Air.Inst.Index,
2225) InnerError!*ir.Inst {2234) InnerError!Air.Inst.Index {
2226 if (func.ty.zigTypeTag() != .Fn)2235 if (func.ty.zigTypeTag() != .Fn)
2227 return sema.mod.fail(&block.base, func_src, "type '{}' not a function", .{func.ty});2236 return sema.mod.fail(&block.base, func_src, "type '{}' not a function", .{func.ty});
22282237
...@@ -2279,7 +2288,7 @@ fn analyzeCall(...@@ -2279,7 +2288,7 @@ fn analyzeCall(
2279 const is_comptime_call = block.is_comptime or modifier == .compile_time;2288 const is_comptime_call = block.is_comptime or modifier == .compile_time;
2280 const is_inline_call = is_comptime_call or modifier == .always_inline or2289 const is_inline_call = is_comptime_call or modifier == .always_inline or
2281 func.ty.fnCallingConvention() == .Inline;2290 func.ty.fnCallingConvention() == .Inline;
2282 const result: *Inst = if (is_inline_call) res: {2291 const result: Air.Inst.Index = if (is_inline_call) res: {
2283 const func_val = try sema.resolveConstValue(block, func_src, func);2292 const func_val = try sema.resolveConstValue(block, func_src, func);
2284 const module_fn = switch (func_val.tag()) {2293 const module_fn = switch (func_val.tag()) {
2285 .function => func_val.castTag(.function).?.data,2294 .function => func_val.castTag(.function).?.data,
...@@ -2377,7 +2386,7 @@ fn analyzeCall(...@@ -2377,7 +2386,7 @@ fn analyzeCall(
2377 return result;2386 return result;
2378}2387}
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 {
2381 _ = block;2390 _ = block;
2382 const tracy = trace(@src());2391 const tracy = trace(@src());
2383 defer tracy.end();2392 defer tracy.end();
...@@ -2389,7 +2398,7 @@ fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -2389,7 +2398,7 @@ fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
2389 return sema.mod.constType(sema.arena, src, ty);2398 return sema.mod.constType(sema.arena, src, ty);
2390}2399}
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 {
2393 const tracy = trace(@src());2402 const tracy = trace(@src());
2394 defer tracy.end();2403 defer tracy.end();
23952404
...@@ -2401,7 +2410,7 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner...@@ -2401,7 +2410,7 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner
2401 return sema.mod.constType(sema.arena, src, opt_type);2410 return sema.mod.constType(sema.arena, src, opt_type);
2402}2411}
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 {
2405 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2414 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2406 const src = inst_data.src();2415 const src = inst_data.src();
2407 const array_type = try sema.resolveType(block, src, inst_data.operand);2416 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...@@ -2409,7 +2418,7 @@ fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
2409 return sema.mod.constType(sema.arena, src, elem_type);2418 return sema.mod.constType(sema.arena, src, elem_type);
2410}2419}
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 {
2413 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2422 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2414 const src = inst_data.src();2423 const src = inst_data.src();
2415 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };2424 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...@@ -2424,7 +2433,7 @@ fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
2424 return sema.mod.constType(sema.arena, src, vector_type);2433 return sema.mod.constType(sema.arena, src, vector_type);
2425}2434}
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 {
2428 const tracy = trace(@src());2437 const tracy = trace(@src());
2429 defer tracy.end();2438 defer tracy.end();
24302439
...@@ -2437,7 +2446,7 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr...@@ -2437,7 +2446,7 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
2437 return sema.mod.constType(sema.arena, .unneeded, array_ty);2446 return sema.mod.constType(sema.arena, .unneeded, array_ty);
2438}2447}
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 {
2441 const tracy = trace(@src());2450 const tracy = trace(@src());
2442 defer tracy.end();2451 defer tracy.end();
24432452
...@@ -2452,7 +2461,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)...@@ -2452,7 +2461,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)
2452 return sema.mod.constType(sema.arena, .unneeded, array_ty);2461 return sema.mod.constType(sema.arena, .unneeded, array_ty);
2453}2462}
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 {
2456 const tracy = trace(@src());2465 const tracy = trace(@src());
2457 defer tracy.end();2466 defer tracy.end();
24582467
...@@ -2465,7 +2474,7 @@ fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner...@@ -2465,7 +2474,7 @@ fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner
2465 return sema.mod.constType(sema.arena, src, anyframe_type);2474 return sema.mod.constType(sema.arena, src, anyframe_type);
2466}2475}
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 {
2469 const tracy = trace(@src());2478 const tracy = trace(@src());
2470 defer tracy.end();2479 defer tracy.end();
24712480
...@@ -2486,7 +2495,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn...@@ -2486,7 +2495,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn
2486 return sema.mod.constType(sema.arena, src, err_union_ty);2495 return sema.mod.constType(sema.arena, src, err_union_ty);
2487}2496}
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 {
2490 _ = block;2499 _ = block;
2491 const tracy = trace(@src());2500 const tracy = trace(@src());
2492 defer tracy.end();2501 defer tracy.end();
...@@ -2505,7 +2514,7 @@ fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr...@@ -2505,7 +2514,7 @@ fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
2505 });2514 });
2506}2515}
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 {
2509 const tracy = trace(@src());2518 const tracy = trace(@src());
2510 defer tracy.end();2519 defer tracy.end();
25112520
...@@ -2535,7 +2544,7 @@ fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr...@@ -2535,7 +2544,7 @@ fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
2535 return block.addUnOp(src, result_ty, .bitcast, op_coerced);2544 return block.addUnOp(src, result_ty, .bitcast, op_coerced);
2536}2545}
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 {
2539 const tracy = trace(@src());2548 const tracy = trace(@src());
2540 defer tracy.end();2549 defer tracy.end();
25412550
...@@ -2568,7 +2577,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr...@@ -2568,7 +2577,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
2568 return block.addUnOp(src, Type.initTag(.anyerror), .bitcast, op);2577 return block.addUnOp(src, Type.initTag(.anyerror), .bitcast, op);
2569}2578}
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 {
2572 const tracy = trace(@src());2581 const tracy = trace(@src());
2573 defer tracy.end();2582 defer tracy.end();
25742583
...@@ -2658,7 +2667,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn...@@ -2658,7 +2667,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn
2658 });2667 });
2659}2668}
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 {
2662 _ = block;2671 _ = block;
2663 const tracy = trace(@src());2672 const tracy = trace(@src());
2664 defer tracy.end();2673 defer tracy.end();
...@@ -2672,7 +2681,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE...@@ -2672,7 +2681,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE
2672 });2681 });
2673}2682}
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 {
2676 const mod = sema.mod;2685 const mod = sema.mod;
2677 const arena = sema.arena;2686 const arena = sema.arena;
2678 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2687 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...@@ -2680,7 +2689,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
2680 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };2689 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2681 const operand = try sema.resolveInst(inst_data.operand);2690 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()) {
2684 .Enum => operand,2693 .Enum => operand,
2685 .Union => {2694 .Union => {
2686 //if (!operand.ty.unionHasTag()) {2695 //if (!operand.ty.unionHasTag()) {
...@@ -2754,7 +2763,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr...@@ -2754,7 +2763,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
2754 return block.addUnOp(src, int_tag_ty, .bitcast, enum_tag);2763 return block.addUnOp(src, int_tag_ty, .bitcast, enum_tag);
2755}2764}
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 {
2758 const mod = sema.mod;2767 const mod = sema.mod;
2759 const target = mod.getTarget();2768 const target = mod.getTarget();
2760 const arena = sema.arena;2769 const arena = sema.arena;
...@@ -2815,7 +2824,7 @@ fn zirOptionalPayloadPtr(...@@ -2815,7 +2824,7 @@ fn zirOptionalPayloadPtr(
2815 block: *Scope.Block,2824 block: *Scope.Block,
2816 inst: Zir.Inst.Index,2825 inst: Zir.Inst.Index,
2817 safety_check: bool,2826 safety_check: bool,
2818) InnerError!*Inst {2827) InnerError!Air.Inst.Index {
2819 const tracy = trace(@src());2828 const tracy = trace(@src());
2820 defer tracy.end();2829 defer tracy.end();
28212830
...@@ -2858,7 +2867,7 @@ fn zirOptionalPayload(...@@ -2858,7 +2867,7 @@ fn zirOptionalPayload(
2858 block: *Scope.Block,2867 block: *Scope.Block,
2859 inst: Zir.Inst.Index,2868 inst: Zir.Inst.Index,
2860 safety_check: bool,2869 safety_check: bool,
2861) InnerError!*Inst {2870) InnerError!Air.Inst.Index {
2862 const tracy = trace(@src());2871 const tracy = trace(@src());
2863 defer tracy.end();2872 defer tracy.end();
28642873
...@@ -2896,7 +2905,7 @@ fn zirErrUnionPayload(...@@ -2896,7 +2905,7 @@ fn zirErrUnionPayload(
2896 block: *Scope.Block,2905 block: *Scope.Block,
2897 inst: Zir.Inst.Index,2906 inst: Zir.Inst.Index,
2898 safety_check: bool,2907 safety_check: bool,
2899) InnerError!*Inst {2908) InnerError!Air.Inst.Index {
2900 const tracy = trace(@src());2909 const tracy = trace(@src());
2901 defer tracy.end();2910 defer tracy.end();
29022911
...@@ -2930,7 +2939,7 @@ fn zirErrUnionPayloadPtr(...@@ -2930,7 +2939,7 @@ fn zirErrUnionPayloadPtr(
2930 block: *Scope.Block,2939 block: *Scope.Block,
2931 inst: Zir.Inst.Index,2940 inst: Zir.Inst.Index,
2932 safety_check: bool,2941 safety_check: bool,
2933) InnerError!*Inst {2942) InnerError!Air.Inst.Index {
2934 const tracy = trace(@src());2943 const tracy = trace(@src());
2935 defer tracy.end();2944 defer tracy.end();
29362945
...@@ -2969,7 +2978,7 @@ fn zirErrUnionPayloadPtr(...@@ -2969,7 +2978,7 @@ fn zirErrUnionPayloadPtr(
2969}2978}
29702979
2971/// Value in, value out2980/// 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 {
2973 const tracy = trace(@src());2982 const tracy = trace(@src());
2974 defer tracy.end();2983 defer tracy.end();
29752984
...@@ -2995,7 +3004,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner...@@ -2995,7 +3004,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner
2995}3004}
29963005
2997/// Pointer in, value out3006/// 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 {
2999 const tracy = trace(@src());3008 const tracy = trace(@src());
3000 defer tracy.end();3009 defer tracy.end();
30013010
...@@ -3042,7 +3051,7 @@ fn zirFunc(...@@ -3042,7 +3051,7 @@ fn zirFunc(
3042 block: *Scope.Block,3051 block: *Scope.Block,
3043 inst: Zir.Inst.Index,3052 inst: Zir.Inst.Index,
3044 inferred_error_set: bool,3053 inferred_error_set: bool,
3045) InnerError!*Inst {3054) InnerError!Air.Inst.Index {
3046 const tracy = trace(@src());3055 const tracy = trace(@src());
3047 defer tracy.end();3056 defer tracy.end();
30483057
...@@ -3093,7 +3102,7 @@ fn funcCommon(...@@ -3093,7 +3102,7 @@ fn funcCommon(
3093 is_extern: bool,3102 is_extern: bool,
3094 src_locs: Zir.Inst.Func.SrcLocs,3103 src_locs: Zir.Inst.Func.SrcLocs,
3095 opt_lib_name: ?[]const u8,3104 opt_lib_name: ?[]const u8,
3096) InnerError!*Inst {3105) InnerError!Air.Inst.Index {
3097 const src: LazySrcLoc = .{ .node_offset = src_node_offset };3106 const src: LazySrcLoc = .{ .node_offset = src_node_offset };
3098 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset };3107 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset };
3099 const bare_return_type = try sema.resolveType(block, ret_ty_src, zir_return_type);3108 const bare_return_type = try sema.resolveType(block, ret_ty_src, zir_return_type);
...@@ -3234,7 +3243,7 @@ fn funcCommon(...@@ -3234,7 +3243,7 @@ fn funcCommon(
3234 return result;3243 return result;
3235}3244}
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 {
3238 const tracy = trace(@src());3247 const tracy = trace(@src());
3239 defer tracy.end();3248 defer tracy.end();
32403249
...@@ -3242,7 +3251,7 @@ fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Ins...@@ -3242,7 +3251,7 @@ fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Ins
3242 return sema.analyzeAs(block, .unneeded, bin_inst.lhs, bin_inst.rhs);3251 return sema.analyzeAs(block, .unneeded, bin_inst.lhs, bin_inst.rhs);
3243}3252}
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 {
3246 const tracy = trace(@src());3255 const tracy = trace(@src());
3247 defer tracy.end();3256 defer tracy.end();
32483257
...@@ -3258,13 +3267,13 @@ fn analyzeAs(...@@ -3258,13 +3267,13 @@ fn analyzeAs(
3258 src: LazySrcLoc,3267 src: LazySrcLoc,
3259 zir_dest_type: Zir.Inst.Ref,3268 zir_dest_type: Zir.Inst.Ref,
3260 zir_operand: Zir.Inst.Ref,3269 zir_operand: Zir.Inst.Ref,
3261) InnerError!*Inst {3270) InnerError!Air.Inst.Index {
3262 const dest_type = try sema.resolveType(block, src, zir_dest_type);3271 const dest_type = try sema.resolveType(block, src, zir_dest_type);
3263 const operand = try sema.resolveInst(zir_operand);3272 const operand = try sema.resolveInst(zir_operand);
3264 return sema.coerce(block, dest_type, operand, src);3273 return sema.coerce(block, dest_type, operand, src);
3265}3274}
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 {
3268 const tracy = trace(@src());3277 const tracy = trace(@src());
3269 defer tracy.end();3278 defer tracy.end();
32703279
...@@ -3281,7 +3290,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -3281,7 +3290,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
3281 return block.addUnOp(src, ty, .ptrtoint, ptr);3290 return block.addUnOp(src, ty, .ptrtoint, ptr);
3282}3291}
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 {
3285 const tracy = trace(@src());3294 const tracy = trace(@src());
3286 defer tracy.end();3295 defer tracy.end();
32873296
...@@ -3299,7 +3308,7 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -3299,7 +3308,7 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
3299 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);3308 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);
3300}3309}
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 {
3303 const tracy = trace(@src());3312 const tracy = trace(@src());
3304 defer tracy.end();3313 defer tracy.end();
33053314
...@@ -3312,7 +3321,7 @@ fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -3312,7 +3321,7 @@ fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
3312 return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);3321 return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);
3313}3322}
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 {
3316 const tracy = trace(@src());3325 const tracy = trace(@src());
3317 defer tracy.end();3326 defer tracy.end();
33183327
...@@ -3327,7 +3336,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne...@@ -3327,7 +3336,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
3327 return sema.analyzeLoad(block, src, result_ptr, src);3336 return sema.analyzeLoad(block, src, result_ptr, src);
3328}3337}
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 {
3331 const tracy = trace(@src());3340 const tracy = trace(@src());
3332 defer tracy.end();3341 defer tracy.end();
33333342
...@@ -3340,7 +3349,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne...@@ -3340,7 +3349,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
3340 return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);3349 return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);
3341}3350}
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 {
3344 const tracy = trace(@src());3353 const tracy = trace(@src());
3345 defer tracy.end();3354 defer tracy.end();
33463355
...@@ -3383,7 +3392,7 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -3383,7 +3392,7 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
3383 return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten int", .{});3392 return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten int", .{});
3384}3393}
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 {
3387 const tracy = trace(@src());3396 const tracy = trace(@src());
3388 defer tracy.end();3397 defer tracy.end();
33893398
...@@ -3396,7 +3405,7 @@ fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -3396,7 +3405,7 @@ fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
3396 return sema.bitcast(block, dest_type, operand);3405 return sema.bitcast(block, dest_type, operand);
3397}3406}
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 {
3400 const tracy = trace(@src());3409 const tracy = trace(@src());
3401 defer tracy.end();3410 defer tracy.end();
34023411
...@@ -3439,7 +3448,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr...@@ -3439,7 +3448,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
3439 return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten float", .{});3448 return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten float", .{});
3440}3449}
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 {
3443 const tracy = trace(@src());3452 const tracy = trace(@src());
3444 defer tracy.end();3453 defer tracy.end();
34453454
...@@ -3454,7 +3463,7 @@ fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -3454,7 +3463,7 @@ fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
3454 return sema.analyzeLoad(block, sema.src, result_ptr, sema.src);3463 return sema.analyzeLoad(block, sema.src, result_ptr, sema.src);
3455}3464}
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 {
3458 const tracy = trace(@src());3467 const tracy = trace(@src());
3459 defer tracy.end();3468 defer tracy.end();
34603469
...@@ -3472,7 +3481,7 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE...@@ -3472,7 +3481,7 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE
3472 return sema.analyzeLoad(block, src, result_ptr, src);3481 return sema.analyzeLoad(block, src, result_ptr, src);
3473}3482}
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 {
3476 const tracy = trace(@src());3485 const tracy = trace(@src());
3477 defer tracy.end();3486 defer tracy.end();
34783487
...@@ -3482,7 +3491,7 @@ fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -3482,7 +3491,7 @@ fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
3482 return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);3491 return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);
3483}3492}
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 {
3486 const tracy = trace(@src());3495 const tracy = trace(@src());
3487 defer tracy.end();3496 defer tracy.end();
34883497
...@@ -3495,7 +3504,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE...@@ -3495,7 +3504,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE
3495 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);3504 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);
3496}3505}
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 {
3499 const tracy = trace(@src());3508 const tracy = trace(@src());
3500 defer tracy.end();3509 defer tracy.end();
35013510
...@@ -3508,7 +3517,7 @@ fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr...@@ -3508,7 +3517,7 @@ fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
3508 return sema.analyzeSlice(block, src, array_ptr, start, null, null, .unneeded);3517 return sema.analyzeSlice(block, src, array_ptr, start, null, null, .unneeded);
3509}3518}
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 {
3512 const tracy = trace(@src());3521 const tracy = trace(@src());
3513 defer tracy.end();3522 defer tracy.end();
35143523
...@@ -3522,7 +3531,7 @@ fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -3522,7 +3531,7 @@ fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
3522 return sema.analyzeSlice(block, src, array_ptr, start, end, null, .unneeded);3531 return sema.analyzeSlice(block, src, array_ptr, start, end, null, .unneeded);
3523}3532}
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 {
3526 const tracy = trace(@src());3535 const tracy = trace(@src());
3527 defer tracy.end();3536 defer tracy.end();
35283537
...@@ -3544,7 +3553,7 @@ fn zirSwitchCapture(...@@ -3544,7 +3553,7 @@ fn zirSwitchCapture(
3544 inst: Zir.Inst.Index,3553 inst: Zir.Inst.Index,
3545 is_multi: bool,3554 is_multi: bool,
3546 is_ref: bool,3555 is_ref: bool,
3547) InnerError!*Inst {3556) InnerError!Air.Inst.Index {
3548 const tracy = trace(@src());3557 const tracy = trace(@src());
3549 defer tracy.end();3558 defer tracy.end();
35503559
...@@ -3563,7 +3572,7 @@ fn zirSwitchCaptureElse(...@@ -3563,7 +3572,7 @@ fn zirSwitchCaptureElse(
3563 block: *Scope.Block,3572 block: *Scope.Block,
3564 inst: Zir.Inst.Index,3573 inst: Zir.Inst.Index,
3565 is_ref: bool,3574 is_ref: bool,
3566) InnerError!*Inst {3575) InnerError!Air.Inst.Index {
3567 const tracy = trace(@src());3576 const tracy = trace(@src());
3568 defer tracy.end();3577 defer tracy.end();
35693578
...@@ -3582,7 +3591,7 @@ fn zirSwitchBlock(...@@ -3582,7 +3591,7 @@ fn zirSwitchBlock(
3582 inst: Zir.Inst.Index,3591 inst: Zir.Inst.Index,
3583 is_ref: bool,3592 is_ref: bool,
3584 special_prong: Zir.SpecialProng,3593 special_prong: Zir.SpecialProng,
3585) InnerError!*Inst {3594) InnerError!Air.Inst.Index {
3586 const tracy = trace(@src());3595 const tracy = trace(@src());
3587 defer tracy.end();3596 defer tracy.end();
35883597
...@@ -3615,7 +3624,7 @@ fn zirSwitchBlockMulti(...@@ -3615,7 +3624,7 @@ fn zirSwitchBlockMulti(
3615 inst: Zir.Inst.Index,3624 inst: Zir.Inst.Index,
3616 is_ref: bool,3625 is_ref: bool,
3617 special_prong: Zir.SpecialProng,3626 special_prong: Zir.SpecialProng,
3618) InnerError!*Inst {3627) InnerError!Air.Inst.Index {
3619 const tracy = trace(@src());3628 const tracy = trace(@src());
3620 defer tracy.end();3629 defer tracy.end();
36213630
...@@ -3645,14 +3654,14 @@ fn zirSwitchBlockMulti(...@@ -3645,14 +3654,14 @@ fn zirSwitchBlockMulti(
3645fn analyzeSwitch(3654fn analyzeSwitch(
3646 sema: *Sema,3655 sema: *Sema,
3647 block: *Scope.Block,3656 block: *Scope.Block,
3648 operand: *Inst,3657 operand: Air.Inst.Index,
3649 extra_end: usize,3658 extra_end: usize,
3650 special_prong: Zir.SpecialProng,3659 special_prong: Zir.SpecialProng,
3651 scalar_cases_len: usize,3660 scalar_cases_len: usize,
3652 multi_cases_len: usize,3661 multi_cases_len: usize,
3653 switch_inst: Zir.Inst.Index,3662 switch_inst: Zir.Inst.Index,
3654 src_node_offset: i32,3663 src_node_offset: i32,
3655) InnerError!*Inst {3664) InnerError!Air.Inst.Index {
3656 const gpa = sema.gpa;3665 const gpa = sema.gpa;
3657 const mod = sema.mod;3666 const mod = sema.mod;
36583667
...@@ -4187,7 +4196,7 @@ fn analyzeSwitch(...@@ -4187,7 +4196,7 @@ fn analyzeSwitch(
41874196
4188 cases[scalar_i] = .{4197 cases[scalar_i] = .{
4189 .item = item_val,4198 .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) },
4191 };4200 };
4192 }4201 }
41934202
...@@ -4207,7 +4216,7 @@ fn analyzeSwitch(...@@ -4207,7 +4216,7 @@ fn analyzeSwitch(
42074216
4208 case_block.instructions.shrinkRetainingCapacity(0);4217 case_block.instructions.shrinkRetainingCapacity(0);
42094218
4210 var any_ok: ?*Inst = null;4219 var any_ok: ?Air.Inst.Index = null;
4211 const bool_ty = comptime Type.initTag(.bool);4220 const bool_ty = comptime Type.initTag(.bool);
42124221
4213 for (items) |item_ref| {4222 for (items) |item_ref| {
...@@ -4280,7 +4289,7 @@ fn analyzeSwitch(...@@ -4280,7 +4289,7 @@ fn analyzeSwitch(
4280 try case_block.instructions.append(gpa, &new_condbr.base);4289 try case_block.instructions.append(gpa, &new_condbr.base);
42814290
4282 const cond_body: Body = .{4291 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),
4284 };4293 };
42854294
4286 case_block.instructions.shrinkRetainingCapacity(0);4295 case_block.instructions.shrinkRetainingCapacity(0);
...@@ -4288,7 +4297,7 @@ fn analyzeSwitch(...@@ -4288,7 +4297,7 @@ fn analyzeSwitch(
4288 extra_index += body_len;4297 extra_index += body_len;
4289 _ = try sema.analyzeBody(&case_block, body);4298 _ = try sema.analyzeBody(&case_block, body);
4290 new_condbr.then_body = .{4299 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),
4292 };4301 };
4293 if (prev_condbr) |condbr| {4302 if (prev_condbr) |condbr| {
4294 condbr.else_body = cond_body;4303 condbr.else_body = cond_body;
...@@ -4303,7 +4312,7 @@ fn analyzeSwitch(...@@ -4303,7 +4312,7 @@ fn analyzeSwitch(
4303 case_block.instructions.shrinkRetainingCapacity(0);4312 case_block.instructions.shrinkRetainingCapacity(0);
4304 _ = try sema.analyzeBody(&case_block, special.body);4313 _ = try sema.analyzeBody(&case_block, special.body);
4305 const else_body: Body = .{4314 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),
4307 };4316 };
4308 if (prev_condbr) |condbr| {4317 if (prev_condbr) |condbr| {
4309 condbr.else_body = else_body;4318 condbr.else_body = else_body;
...@@ -4507,7 +4516,7 @@ fn validateSwitchNoRange(...@@ -4507,7 +4516,7 @@ fn validateSwitchNoRange(
4507 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);4516 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);
4508}4517}
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 {
4511 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;4520 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
4512 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;4521 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
4513 _ = extra;4522 _ = extra;
...@@ -4516,7 +4525,7 @@ fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -4516,7 +4525,7 @@ fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
4516 return sema.mod.fail(&block.base, src, "TODO implement zirHasField", .{});4525 return sema.mod.fail(&block.base, src, "TODO implement zirHasField", .{});
4517}4526}
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 {
4520 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;4529 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
4521 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;4530 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
4522 const src = inst_data.src();4531 const src = inst_data.src();
...@@ -4541,7 +4550,7 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -4541,7 +4550,7 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
4541 return mod.constBool(arena, src, false);4550 return mod.constBool(arena, src, false);
4542}4551}
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 {
4545 const tracy = trace(@src());4554 const tracy = trace(@src());
4546 defer tracy.end();4555 defer tracy.end();
45474556
...@@ -4566,13 +4575,13 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!...@@ -4566,13 +4575,13 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
4566 return mod.constType(sema.arena, src, file_root_decl.ty);4575 return mod.constType(sema.arena, src, file_root_decl.ty);
4567}4576}
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 {
4570 _ = block;4579 _ = block;
4571 _ = inst;4580 _ = inst;
4572 return sema.mod.fail(&block.base, sema.src, "TODO implement zirRetErrValueCode", .{});4581 return sema.mod.fail(&block.base, sema.src, "TODO implement zirRetErrValueCode", .{});
4573}4582}
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 {
4576 const tracy = trace(@src());4585 const tracy = trace(@src());
4577 defer tracy.end();4586 defer tracy.end();
45784587
...@@ -4581,7 +4590,7 @@ fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In...@@ -4581,7 +4590,7 @@ fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In
4581 return sema.mod.fail(&block.base, sema.src, "TODO implement zirShl", .{});4590 return sema.mod.fail(&block.base, sema.src, "TODO implement zirShl", .{});
4582}4591}
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 {
4585 const tracy = trace(@src());4594 const tracy = trace(@src());
4586 defer tracy.end();4595 defer tracy.end();
45874596
...@@ -4594,7 +4603,7 @@ fn zirBitwise(...@@ -4594,7 +4603,7 @@ fn zirBitwise(
4594 block: *Scope.Block,4603 block: *Scope.Block,
4595 inst: Zir.Inst.Index,4604 inst: Zir.Inst.Index,
4596 ir_tag: ir.Inst.Tag,4605 ir_tag: ir.Inst.Tag,
4597) InnerError!*Inst {4606) InnerError!Air.Inst.Index {
4598 const tracy = trace(@src());4607 const tracy = trace(@src());
4599 defer tracy.end();4608 defer tracy.end();
46004609
...@@ -4606,7 +4615,7 @@ fn zirBitwise(...@@ -4606,7 +4615,7 @@ fn zirBitwise(
4606 const lhs = try sema.resolveInst(extra.lhs);4615 const lhs = try sema.resolveInst(extra.lhs);
4607 const rhs = try sema.resolveInst(extra.rhs);4616 const rhs = try sema.resolveInst(extra.rhs);
46084617
4609 const instructions = &[_]*Inst{ lhs, rhs };4618 const instructions = &[_]Air.Inst.Index{ lhs, rhs };
4610 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);4619 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);
4611 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);4620 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
4612 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);4621 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
...@@ -4652,7 +4661,7 @@ fn zirBitwise(...@@ -4652,7 +4661,7 @@ fn zirBitwise(
4652 return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs);4661 return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs);
4653}4662}
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 {
4656 const tracy = trace(@src());4665 const tracy = trace(@src());
4657 defer tracy.end();4666 defer tracy.end();
46584667
...@@ -4660,7 +4669,7 @@ fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!...@@ -4660,7 +4669,7 @@ fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
4660 return sema.mod.fail(&block.base, sema.src, "TODO implement zirBitNot", .{});4669 return sema.mod.fail(&block.base, sema.src, "TODO implement zirBitNot", .{});
4661}4670}
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 {
4664 const tracy = trace(@src());4673 const tracy = trace(@src());
4665 defer tracy.end();4674 defer tracy.end();
46664675
...@@ -4668,7 +4677,7 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -4668,7 +4677,7 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
4668 return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayCat", .{});4677 return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayCat", .{});
4669}4678}
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 {
4672 const tracy = trace(@src());4681 const tracy = trace(@src());
4673 defer tracy.end();4682 defer tracy.end();
46744683
...@@ -4681,7 +4690,7 @@ fn zirNegate(...@@ -4681,7 +4690,7 @@ fn zirNegate(
4681 block: *Scope.Block,4690 block: *Scope.Block,
4682 inst: Zir.Inst.Index,4691 inst: Zir.Inst.Index,
4683 tag_override: Zir.Inst.Tag,4692 tag_override: Zir.Inst.Tag,
4684) InnerError!*Inst {4693) InnerError!Air.Inst.Index {
4685 const tracy = trace(@src());4694 const tracy = trace(@src());
4686 defer tracy.end();4695 defer tracy.end();
46874696
...@@ -4695,7 +4704,7 @@ fn zirNegate(...@@ -4695,7 +4704,7 @@ fn zirNegate(
4695 return sema.analyzeArithmetic(block, tag_override, lhs, rhs, src, lhs_src, rhs_src);4704 return sema.analyzeArithmetic(block, tag_override, lhs, rhs, src, lhs_src, rhs_src);
4696}4705}
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 {
4699 const tracy = trace(@src());4708 const tracy = trace(@src());
4700 defer tracy.end();4709 defer tracy.end();
47014710
...@@ -4715,7 +4724,7 @@ fn zirOverflowArithmetic(...@@ -4715,7 +4724,7 @@ fn zirOverflowArithmetic(
4715 sema: *Sema,4724 sema: *Sema,
4716 block: *Scope.Block,4725 block: *Scope.Block,
4717 extended: Zir.Inst.Extended.InstData,4726 extended: Zir.Inst.Extended.InstData,
4718) InnerError!*Inst {4727) InnerError!Air.Inst.Index {
4719 const tracy = trace(@src());4728 const tracy = trace(@src());
4720 defer tracy.end();4729 defer tracy.end();
47214730
...@@ -4729,13 +4738,13 @@ fn analyzeArithmetic(...@@ -4729,13 +4738,13 @@ fn analyzeArithmetic(
4729 sema: *Sema,4738 sema: *Sema,
4730 block: *Scope.Block,4739 block: *Scope.Block,
4731 zir_tag: Zir.Inst.Tag,4740 zir_tag: Zir.Inst.Tag,
4732 lhs: *Inst,4741 lhs: Air.Inst.Index,
4733 rhs: *Inst,4742 rhs: Air.Inst.Index,
4734 src: LazySrcLoc,4743 src: LazySrcLoc,
4735 lhs_src: LazySrcLoc,4744 lhs_src: LazySrcLoc,
4736 rhs_src: LazySrcLoc,4745 rhs_src: LazySrcLoc,
4737) InnerError!*Inst {4746) InnerError!Air.Inst.Index {
4738 const instructions = &[_]*Inst{ lhs, rhs };4747 const instructions = &[_]Air.Inst.Index{ lhs, rhs };
4739 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);4748 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);
4740 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);4749 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
4741 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);4750 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
...@@ -4844,7 +4853,7 @@ fn analyzeArithmetic(...@@ -4844,7 +4853,7 @@ fn analyzeArithmetic(
4844 return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs);4853 return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs);
4845}4854}
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 {
4848 const tracy = trace(@src());4857 const tracy = trace(@src());
4849 defer tracy.end();4858 defer tracy.end();
48504859
...@@ -4859,7 +4868,7 @@ fn zirAsm(...@@ -4859,7 +4868,7 @@ fn zirAsm(
4859 sema: *Sema,4868 sema: *Sema,
4860 block: *Scope.Block,4869 block: *Scope.Block,
4861 extended: Zir.Inst.Extended.InstData,4870 extended: Zir.Inst.Extended.InstData,
4862) InnerError!*Inst {4871) InnerError!Air.Inst.Index {
4863 const tracy = trace(@src());4872 const tracy = trace(@src());
4864 defer tracy.end();4873 defer tracy.end();
48654874
...@@ -4899,7 +4908,7 @@ fn zirAsm(...@@ -4899,7 +4908,7 @@ fn zirAsm(
4899 };4908 };
4900 };4909 };
49014910
4902 const args = try sema.arena.alloc(*Inst, inputs_len);4911 const args = try sema.arena.alloc(Air.Inst.Index, inputs_len);
4903 const inputs = try sema.arena.alloc([]const u8, inputs_len);4912 const inputs = try sema.arena.alloc([]const u8, inputs_len);
49044913
4905 for (args) |*arg, arg_i| {4914 for (args) |*arg, arg_i| {
...@@ -4943,7 +4952,7 @@ fn zirCmp(...@@ -4943,7 +4952,7 @@ fn zirCmp(
4943 block: *Scope.Block,4952 block: *Scope.Block,
4944 inst: Zir.Inst.Index,4953 inst: Zir.Inst.Index,
4945 op: std.math.CompareOperator,4954 op: std.math.CompareOperator,
4946) InnerError!*Inst {4955) InnerError!Air.Inst.Index {
4947 const tracy = trace(@src());4956 const tracy = trace(@src());
4948 defer tracy.end();4957 defer tracy.end();
49494958
...@@ -5009,7 +5018,7 @@ fn zirCmp(...@@ -5009,7 +5018,7 @@ fn zirCmp(
5009 return mod.constBool(sema.arena, src, lhs.value().?.eql(rhs.value().?) == (op == .eq));5018 return mod.constBool(sema.arena, src, lhs.value().?.eql(rhs.value().?) == (op == .eq));
5010 }5019 }
50115020
5012 const instructions = &[_]*Inst{ lhs, rhs };5021 const instructions = &[_]Air.Inst.Index{ lhs, rhs };
5013 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);5022 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);
5014 if (!resolved_type.isSelfComparable(is_equality_cmp)) {5023 if (!resolved_type.isSelfComparable(is_equality_cmp)) {
5015 return mod.fail(&block.base, src, "operator not allowed for type '{}'", .{resolved_type});5024 return mod.fail(&block.base, src, "operator not allowed for type '{}'", .{resolved_type});
...@@ -5041,7 +5050,7 @@ fn zirCmp(...@@ -5041,7 +5050,7 @@ fn zirCmp(
5041 return block.addBinOp(src, bool_type, tag, casted_lhs, casted_rhs);5050 return block.addBinOp(src, bool_type, tag, casted_lhs, casted_rhs);
5042}5051}
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 {
5045 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5054 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5046 const src = inst_data.src();5055 const src = inst_data.src();
5047 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };5056 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!...@@ -5051,7 +5060,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
5051 return sema.mod.constIntUnsigned(sema.arena, src, Type.initTag(.comptime_int), abi_size);5060 return sema.mod.constIntUnsigned(sema.arena, src, Type.initTag(.comptime_int), abi_size);
5052}5061}
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 {
5055 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5064 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5056 const src = inst_data.src();5065 const src = inst_data.src();
5057 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };5066 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
...@@ -5065,7 +5074,7 @@ fn zirThis(...@@ -5065,7 +5074,7 @@ fn zirThis(
5065 sema: *Sema,5074 sema: *Sema,
5066 block: *Scope.Block,5075 block: *Scope.Block,
5067 extended: Zir.Inst.Extended.InstData,5076 extended: Zir.Inst.Extended.InstData,
5068) InnerError!*Inst {5077) InnerError!Air.Inst.Index {
5069 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };5078 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
5070 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirThis", .{});5079 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirThis", .{});
5071}5080}
...@@ -5074,7 +5083,7 @@ fn zirRetAddr(...@@ -5074,7 +5083,7 @@ fn zirRetAddr(
5074 sema: *Sema,5083 sema: *Sema,
5075 block: *Scope.Block,5084 block: *Scope.Block,
5076 extended: Zir.Inst.Extended.InstData,5085 extended: Zir.Inst.Extended.InstData,
5077) InnerError!*Inst {5086) InnerError!Air.Inst.Index {
5078 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };5087 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
5079 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirRetAddr", .{});5088 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirRetAddr", .{});
5080}5089}
...@@ -5083,12 +5092,12 @@ fn zirBuiltinSrc(...@@ -5083,12 +5092,12 @@ fn zirBuiltinSrc(
5083 sema: *Sema,5092 sema: *Sema,
5084 block: *Scope.Block,5093 block: *Scope.Block,
5085 extended: Zir.Inst.Extended.InstData,5094 extended: Zir.Inst.Extended.InstData,
5086) InnerError!*Inst {5095) InnerError!Air.Inst.Index {
5087 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };5096 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
5088 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinSrc", .{});5097 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinSrc", .{});
5089}5098}
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 {
5092 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5101 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5093 const src = inst_data.src();5102 const src = inst_data.src();
5094 const ty = try sema.resolveType(block, src, inst_data.operand);5103 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...@@ -5131,7 +5140,7 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
5131 }5140 }
5132}5141}
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 {
5135 _ = block;5144 _ = block;
5136 const zir_datas = sema.code.instructions.items(.data);5145 const zir_datas = sema.code.instructions.items(.data);
5137 const inst_data = zir_datas[inst].un_node;5146 const inst_data = zir_datas[inst].un_node;
...@@ -5140,7 +5149,7 @@ fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!...@@ -5140,7 +5149,7 @@ fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
5140 return sema.mod.constType(sema.arena, src, operand.ty);5149 return sema.mod.constType(sema.arena, src, operand.ty);
5141}5150}
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 {
5144 _ = block;5153 _ = block;
5145 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5154 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5146 const src = inst_data.src();5155 const src = inst_data.src();
...@@ -5149,13 +5158,13 @@ fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr...@@ -5149,13 +5158,13 @@ fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
5149 return sema.mod.constType(sema.arena, src, elem_ty);5158 return sema.mod.constType(sema.arena, src, elem_ty);
5150}5159}
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 {
5153 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5162 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5154 const src = inst_data.src();5163 const src = inst_data.src();
5155 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirTypeofLog2IntType", .{});5164 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirTypeofLog2IntType", .{});
5156}5165}
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 {
5159 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5168 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5160 const src = inst_data.src();5169 const src = inst_data.src();
5161 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirLog2IntType", .{});5170 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirLog2IntType", .{});
...@@ -5165,7 +5174,7 @@ fn zirTypeofPeer(...@@ -5165,7 +5174,7 @@ fn zirTypeofPeer(
5165 sema: *Sema,5174 sema: *Sema,
5166 block: *Scope.Block,5175 block: *Scope.Block,
5167 extended: Zir.Inst.Extended.InstData,5176 extended: Zir.Inst.Extended.InstData,
5168) InnerError!*Inst {5177) InnerError!Air.Inst.Index {
5169 const tracy = trace(@src());5178 const tracy = trace(@src());
5170 defer tracy.end();5179 defer tracy.end();
51715180
...@@ -5173,7 +5182,7 @@ fn zirTypeofPeer(...@@ -5173,7 +5182,7 @@ fn zirTypeofPeer(
5173 const src: LazySrcLoc = .{ .node_offset = extra.data.src_node };5182 const src: LazySrcLoc = .{ .node_offset = extra.data.src_node };
5174 const args = sema.code.refSlice(extra.end, extended.small);5183 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);
5177 defer sema.gpa.free(inst_list);5186 defer sema.gpa.free(inst_list);
51785187
5179 for (args) |arg_ref, i| {5188 for (args) |arg_ref, i| {
...@@ -5184,7 +5193,7 @@ fn zirTypeofPeer(...@@ -5184,7 +5193,7 @@ fn zirTypeofPeer(
5184 return sema.mod.constType(sema.arena, src, result_type);5193 return sema.mod.constType(sema.arena, src, result_type);
5185}5194}
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 {
5188 const tracy = trace(@src());5197 const tracy = trace(@src());
5189 defer tracy.end();5198 defer tracy.end();
51905199
...@@ -5206,7 +5215,7 @@ fn zirBoolOp(...@@ -5206,7 +5215,7 @@ fn zirBoolOp(
5206 block: *Scope.Block,5215 block: *Scope.Block,
5207 inst: Zir.Inst.Index,5216 inst: Zir.Inst.Index,
5208 comptime is_bool_or: bool,5217 comptime is_bool_or: bool,
5209) InnerError!*Inst {5218) InnerError!Air.Inst.Index {
5210 const tracy = trace(@src());5219 const tracy = trace(@src());
5211 defer tracy.end();5220 defer tracy.end();
52125221
...@@ -5237,7 +5246,7 @@ fn zirBoolBr(...@@ -5237,7 +5246,7 @@ fn zirBoolBr(
5237 parent_block: *Scope.Block,5246 parent_block: *Scope.Block,
5238 inst: Zir.Inst.Index,5247 inst: Zir.Inst.Index,
5239 is_bool_or: bool,5248 is_bool_or: bool,
5240) InnerError!*Inst {5249) InnerError!Air.Inst.Index {
5241 const tracy = trace(@src());5250 const tracy = trace(@src());
5242 defer tracy.end();5251 defer tracy.end();
52435252
...@@ -5292,12 +5301,12 @@ fn zirBoolBr(...@@ -5292,12 +5301,12 @@ fn zirBoolBr(
5292 const rhs_result = try sema.resolveBody(rhs_block, body);5301 const rhs_result = try sema.resolveBody(rhs_block, body);
5293 _ = try rhs_block.addBr(src, block_inst, rhs_result);5302 _ = 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) };5304 const air_then_body: ir.Body = .{ .instructions = try sema.arena.dupe(Air.Inst.Index, then_block.instructions.items) };
5296 const air_else_body: ir.Body = .{ .instructions = try sema.arena.dupe(*Inst, else_block.instructions.items) };5305 const air_else_body: ir.Body = .{ .instructions = try sema.arena.dupe(Air.Inst.Index, else_block.instructions.items) };
5297 _ = try child_block.addCondBr(src, lhs, air_then_body, air_else_body);5306 _ = try child_block.addCondBr(src, lhs, air_then_body, air_else_body);
52985307
5299 block_inst.body = .{5308 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),
5301 };5310 };
5302 try parent_block.instructions.append(sema.gpa, &block_inst.base);5311 try parent_block.instructions.append(sema.gpa, &block_inst.base);
5303 return &block_inst.base;5312 return &block_inst.base;
...@@ -5307,7 +5316,7 @@ fn zirIsNonNull(...@@ -5307,7 +5316,7 @@ fn zirIsNonNull(
5307 sema: *Sema,5316 sema: *Sema,
5308 block: *Scope.Block,5317 block: *Scope.Block,
5309 inst: Zir.Inst.Index,5318 inst: Zir.Inst.Index,
5310) InnerError!*Inst {5319) InnerError!Air.Inst.Index {
5311 const tracy = trace(@src());5320 const tracy = trace(@src());
5312 defer tracy.end();5321 defer tracy.end();
53135322
...@@ -5321,7 +5330,7 @@ fn zirIsNonNullPtr(...@@ -5321,7 +5330,7 @@ fn zirIsNonNullPtr(
5321 sema: *Sema,5330 sema: *Sema,
5322 block: *Scope.Block,5331 block: *Scope.Block,
5323 inst: Zir.Inst.Index,5332 inst: Zir.Inst.Index,
5324) InnerError!*Inst {5333) InnerError!Air.Inst.Index {
5325 const tracy = trace(@src());5334 const tracy = trace(@src());
5326 defer tracy.end();5335 defer tracy.end();
53275336
...@@ -5332,7 +5341,7 @@ fn zirIsNonNullPtr(...@@ -5332,7 +5341,7 @@ fn zirIsNonNullPtr(
5332 return sema.analyzeIsNull(block, src, loaded, true);5341 return sema.analyzeIsNull(block, src, loaded, true);
5333}5342}
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 {
5336 const tracy = trace(@src());5345 const tracy = trace(@src());
5337 defer tracy.end();5346 defer tracy.end();
53385347
...@@ -5341,7 +5350,7 @@ fn zirIsNonErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -5341,7 +5350,7 @@ fn zirIsNonErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
5341 return sema.analyzeIsNonErr(block, inst_data.src(), operand);5350 return sema.analyzeIsNonErr(block, inst_data.src(), operand);
5342}5351}
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 {
5345 const tracy = trace(@src());5354 const tracy = trace(@src());
5346 defer tracy.end();5355 defer tracy.end();
53475356
...@@ -5385,14 +5394,14 @@ fn zirCondbr(...@@ -5385,14 +5394,14 @@ fn zirCondbr(
53855394
5386 _ = try sema.analyzeBody(&sub_block, then_body);5395 _ = try sema.analyzeBody(&sub_block, then_body);
5387 const air_then_body: ir.Body = .{5396 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),
5389 };5398 };
53905399
5391 sub_block.instructions.shrinkRetainingCapacity(0);5400 sub_block.instructions.shrinkRetainingCapacity(0);
53925401
5393 _ = try sema.analyzeBody(&sub_block, else_body);5402 _ = try sema.analyzeBody(&sub_block, else_body);
5394 const air_else_body: ir.Body = .{5403 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),
5396 };5405 };
53975406
5398 _ = try parent_block.addCondBr(src, cond, air_then_body, air_else_body);5407 _ = 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...@@ -5470,7 +5479,7 @@ fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
5470fn analyzeRet(5479fn analyzeRet(
5471 sema: *Sema,5480 sema: *Sema,
5472 block: *Scope.Block,5481 block: *Scope.Block,
5473 operand: *Inst,5482 operand: Air.Inst.Index,
5474 src: LazySrcLoc,5483 src: LazySrcLoc,
5475 need_coercion: bool,5484 need_coercion: bool,
5476) InnerError!Zir.Inst.Index {5485) InnerError!Zir.Inst.Index {
...@@ -5505,7 +5514,7 @@ fn floatOpAllowed(tag: Zir.Inst.Tag) bool {...@@ -5505,7 +5514,7 @@ fn floatOpAllowed(tag: Zir.Inst.Tag) bool {
5505 };5514 };
5506}5515}
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 {
5509 const tracy = trace(@src());5518 const tracy = trace(@src());
5510 defer tracy.end();5519 defer tracy.end();
55115520
...@@ -5526,7 +5535,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne...@@ -5526,7 +5535,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne
5526 return sema.mod.constType(sema.arena, .unneeded, ty);5535 return sema.mod.constType(sema.arena, .unneeded, ty);
5527}5536}
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 {
5530 const tracy = trace(@src());5539 const tracy = trace(@src());
5531 defer tracy.end();5540 defer tracy.end();
55325541
...@@ -5580,7 +5589,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -5580,7 +5589,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
5580 return sema.mod.constType(sema.arena, src, ty);5589 return sema.mod.constType(sema.arena, src, ty);
5581}5590}
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 {
5584 const tracy = trace(@src());5593 const tracy = trace(@src());
5585 defer tracy.end();5594 defer tracy.end();
55865595
...@@ -5594,13 +5603,13 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In...@@ -5594,13 +5603,13 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In
5594 });5603 });
5595}5604}
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 {
5598 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5607 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5599 const src = inst_data.src();5608 const src = inst_data.src();
5600 return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnionInitPtr", .{});5609 return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnionInitPtr", .{});
5601}5610}
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 {
5604 const mod = sema.mod;5613 const mod = sema.mod;
5605 const gpa = sema.gpa;5614 const gpa = sema.gpa;
5606 const zir_datas = sema.code.instructions.items(.data);5615 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:...@@ -5622,7 +5631,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
5622 mem.set(Zir.Inst.Index, found_fields, 0);5631 mem.set(Zir.Inst.Index, found_fields, 0);
56235632
5624 // The init values to use for the struct instance.5633 // 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());
5626 defer gpa.free(field_inits);5635 defer gpa.free(field_inits);
56275636
5628 var field_i: u32 = 0;5637 var field_i: u32 = 0;
...@@ -5713,7 +5722,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:...@@ -5713,7 +5722,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
5713 return mod.fail(&block.base, src, "TODO: Sema.zirStructInit for runtime-known struct values", .{});5722 return mod.fail(&block.base, src, "TODO: Sema.zirStructInit for runtime-known struct values", .{});
5714}5723}
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 {
5717 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5726 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5718 const src = inst_data.src();5727 const src = inst_data.src();
57195728
...@@ -5721,7 +5730,7 @@ fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_...@@ -5721,7 +5730,7 @@ fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_
5721 return sema.mod.fail(&block.base, src, "TODO: Sema.zirStructInitAnon", .{});5730 return sema.mod.fail(&block.base, src, "TODO: Sema.zirStructInitAnon", .{});
5722}5731}
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 {
5725 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5734 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5726 const src = inst_data.src();5735 const src = inst_data.src();
57275736
...@@ -5729,7 +5738,7 @@ fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:...@@ -5729,7 +5738,7 @@ fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
5729 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInit", .{});5738 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInit", .{});
5730}5739}
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 {
5733 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5742 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5734 const src = inst_data.src();5743 const src = inst_data.src();
57355744
...@@ -5737,13 +5746,13 @@ fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_r...@@ -5737,13 +5746,13 @@ fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_r
5737 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInitAnon", .{});5746 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInitAnon", .{});
5738}5747}
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 {
5741 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5750 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5742 const src = inst_data.src();5751 const src = inst_data.src();
5743 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldTypeRef", .{});5752 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldTypeRef", .{});
5744}5753}
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 {
5747 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5756 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5748 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;5757 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
5749 const src = inst_data.src();5758 const src = inst_data.src();
...@@ -5765,7 +5774,7 @@ fn zirErrorReturnTrace(...@@ -5765,7 +5774,7 @@ fn zirErrorReturnTrace(
5765 sema: *Sema,5774 sema: *Sema,
5766 block: *Scope.Block,5775 block: *Scope.Block,
5767 extended: Zir.Inst.Extended.InstData,5776 extended: Zir.Inst.Extended.InstData,
5768) InnerError!*Inst {5777) InnerError!Air.Inst.Index {
5769 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };5778 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
5770 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorReturnTrace", .{});5779 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorReturnTrace", .{});
5771}5780}
...@@ -5774,7 +5783,7 @@ fn zirFrame(...@@ -5774,7 +5783,7 @@ fn zirFrame(
5774 sema: *Sema,5783 sema: *Sema,
5775 block: *Scope.Block,5784 block: *Scope.Block,
5776 extended: Zir.Inst.Extended.InstData,5785 extended: Zir.Inst.Extended.InstData,
5777) InnerError!*Inst {5786) InnerError!Air.Inst.Index {
5778 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };5787 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
5779 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrame", .{});5788 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrame", .{});
5780}5789}
...@@ -5783,84 +5792,84 @@ fn zirFrameAddress(...@@ -5783,84 +5792,84 @@ fn zirFrameAddress(
5783 sema: *Sema,5792 sema: *Sema,
5784 block: *Scope.Block,5793 block: *Scope.Block,
5785 extended: Zir.Inst.Extended.InstData,5794 extended: Zir.Inst.Extended.InstData,
5786) InnerError!*Inst {5795) InnerError!Air.Inst.Index {
5787 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };5796 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
5788 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameAddress", .{});5797 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameAddress", .{});
5789}5798}
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 {
5792 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5801 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5793 const src = inst_data.src();5802 const src = inst_data.src();
5794 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignOf", .{});5803 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignOf", .{});
5795}5804}
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 {
5798 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5807 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5799 const src = inst_data.src();5808 const src = inst_data.src();
5800 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBoolToInt", .{});5809 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBoolToInt", .{});
5801}5810}
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 {
5804 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5813 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5805 const src = inst_data.src();5814 const src = inst_data.src();
5806 return sema.mod.fail(&block.base, src, "TODO: Sema.zirEmbedFile", .{});5815 return sema.mod.fail(&block.base, src, "TODO: Sema.zirEmbedFile", .{});
5807}5816}
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 {
5810 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5819 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5811 const src = inst_data.src();5820 const src = inst_data.src();
5812 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorName", .{});5821 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorName", .{});
5813}5822}
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 {
5816 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5825 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5817 const src = inst_data.src();5826 const src = inst_data.src();
5818 return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnaryMath", .{});5827 return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnaryMath", .{});
5819}5828}
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 {
5822 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5831 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5823 const src = inst_data.src();5832 const src = inst_data.src();
5824 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTagName", .{});5833 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTagName", .{});
5825}5834}
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 {
5828 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5837 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5829 const src = inst_data.src();5838 const src = inst_data.src();
5830 return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify", .{});5839 return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify", .{});
5831}5840}
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 {
5834 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5843 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5835 const src = inst_data.src();5844 const src = inst_data.src();
5836 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTypeName", .{});5845 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTypeName", .{});
5837}5846}
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 {
5840 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5849 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5841 const src = inst_data.src();5850 const src = inst_data.src();
5842 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameType", .{});5851 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameType", .{});
5843}5852}
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 {
5846 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5855 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5847 const src = inst_data.src();5856 const src = inst_data.src();
5848 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameSize", .{});5857 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameSize", .{});
5849}5858}
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 {
5852 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5861 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5853 const src = inst_data.src();5862 const src = inst_data.src();
5854 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFloatToInt", .{});5863 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFloatToInt", .{});
5855}5864}
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 {
5858 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5867 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5859 const src = inst_data.src();5868 const src = inst_data.src();
5860 return sema.mod.fail(&block.base, src, "TODO: Sema.zirIntToFloat", .{});5869 return sema.mod.fail(&block.base, src, "TODO: Sema.zirIntToFloat", .{});
5861}5870}
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 {
5864 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5873 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5865 const src = inst_data.src();5874 const src = inst_data.src();
58665875
...@@ -5923,199 +5932,199 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -5923,199 +5932,199 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
5923 return block.addUnOp(src, type_res, .bitcast, operand_coerced);5932 return block.addUnOp(src, type_res, .bitcast, operand_coerced);
5924}5933}
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 {
5927 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5936 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5928 const src = inst_data.src();5937 const src = inst_data.src();
5929 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrSetCast", .{});5938 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrSetCast", .{});
5930}5939}
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 {
5933 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5942 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5934 const src = inst_data.src();5943 const src = inst_data.src();
5935 return sema.mod.fail(&block.base, src, "TODO: Sema.zirPtrCast", .{});5944 return sema.mod.fail(&block.base, src, "TODO: Sema.zirPtrCast", .{});
5936}5945}
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 {
5939 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5948 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5940 const src = inst_data.src();5949 const src = inst_data.src();
5941 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTruncate", .{});5950 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTruncate", .{});
5942}5951}
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 {
5945 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5954 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5946 const src = inst_data.src();5955 const src = inst_data.src();
5947 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignCast", .{});5956 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignCast", .{});
5948}5957}
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 {
5951 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5960 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5952 const src = inst_data.src();5961 const src = inst_data.src();
5953 return sema.mod.fail(&block.base, src, "TODO: Sema.zirClz", .{});5962 return sema.mod.fail(&block.base, src, "TODO: Sema.zirClz", .{});
5954}5963}
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 {
5957 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5966 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5958 const src = inst_data.src();5967 const src = inst_data.src();
5959 return sema.mod.fail(&block.base, src, "TODO: Sema.zirCtz", .{});5968 return sema.mod.fail(&block.base, src, "TODO: Sema.zirCtz", .{});
5960}5969}
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 {
5963 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5972 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5964 const src = inst_data.src();5973 const src = inst_data.src();
5965 return sema.mod.fail(&block.base, src, "TODO: Sema.zirPopCount", .{});5974 return sema.mod.fail(&block.base, src, "TODO: Sema.zirPopCount", .{});
5966}5975}
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 {
5969 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5978 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5970 const src = inst_data.src();5979 const src = inst_data.src();
5971 return sema.mod.fail(&block.base, src, "TODO: Sema.zirByteSwap", .{});5980 return sema.mod.fail(&block.base, src, "TODO: Sema.zirByteSwap", .{});
5972}5981}
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 {
5975 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5984 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5976 const src = inst_data.src();5985 const src = inst_data.src();
5977 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitReverse", .{});5986 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitReverse", .{});
5978}5987}
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 {
5981 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5990 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5982 const src = inst_data.src();5991 const src = inst_data.src();
5983 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivExact", .{});5992 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivExact", .{});
5984}5993}
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 {
5987 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5996 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5988 const src = inst_data.src();5997 const src = inst_data.src();
5989 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivFloor", .{});5998 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivFloor", .{});
5990}5999}
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 {
5993 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6002 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5994 const src = inst_data.src();6003 const src = inst_data.src();
5995 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivTrunc", .{});6004 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivTrunc", .{});
5996}6005}
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 {
5999 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6008 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6000 const src = inst_data.src();6009 const src = inst_data.src();
6001 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMod", .{});6010 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMod", .{});
6002}6011}
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 {
6005 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6014 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6006 const src = inst_data.src();6015 const src = inst_data.src();
6007 return sema.mod.fail(&block.base, src, "TODO: Sema.zirRem", .{});6016 return sema.mod.fail(&block.base, src, "TODO: Sema.zirRem", .{});
6008}6017}
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 {
6011 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6020 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6012 const src = inst_data.src();6021 const src = inst_data.src();
6013 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShlExact", .{});6022 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShlExact", .{});
6014}6023}
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 {
6017 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6026 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6018 const src = inst_data.src();6027 const src = inst_data.src();
6019 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShrExact", .{});6028 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShrExact", .{});
6020}6029}
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 {
6023 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6032 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6024 const src = inst_data.src();6033 const src = inst_data.src();
6025 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitOffsetOf", .{});6034 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitOffsetOf", .{});
6026}6035}
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 {
6029 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6038 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6030 const src = inst_data.src();6039 const src = inst_data.src();
6031 return sema.mod.fail(&block.base, src, "TODO: Sema.zirOffsetOf", .{});6040 return sema.mod.fail(&block.base, src, "TODO: Sema.zirOffsetOf", .{});
6032}6041}
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 {
6035 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6044 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6036 const src = inst_data.src();6045 const src = inst_data.src();
6037 return sema.mod.fail(&block.base, src, "TODO: Sema.zirCmpxchg", .{});6046 return sema.mod.fail(&block.base, src, "TODO: Sema.zirCmpxchg", .{});
6038}6047}
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 {
6041 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6050 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6042 const src = inst_data.src();6051 const src = inst_data.src();
6043 return sema.mod.fail(&block.base, src, "TODO: Sema.zirSplat", .{});6052 return sema.mod.fail(&block.base, src, "TODO: Sema.zirSplat", .{});
6044}6053}
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 {
6047 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6056 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6048 const src = inst_data.src();6057 const src = inst_data.src();
6049 return sema.mod.fail(&block.base, src, "TODO: Sema.zirReduce", .{});6058 return sema.mod.fail(&block.base, src, "TODO: Sema.zirReduce", .{});
6050}6059}
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 {
6053 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6062 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6054 const src = inst_data.src();6063 const src = inst_data.src();
6055 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShuffle", .{});6064 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShuffle", .{});
6056}6065}
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 {
6059 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6068 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6060 const src = inst_data.src();6069 const src = inst_data.src();
6061 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicLoad", .{});6070 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicLoad", .{});
6062}6071}
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 {
6065 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6074 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6066 const src = inst_data.src();6075 const src = inst_data.src();
6067 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicRmw", .{});6076 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicRmw", .{});
6068}6077}
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 {
6071 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6080 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6072 const src = inst_data.src();6081 const src = inst_data.src();
6073 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicStore", .{});6082 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicStore", .{});
6074}6083}
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 {
6077 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6086 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6078 const src = inst_data.src();6087 const src = inst_data.src();
6079 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMulAdd", .{});6088 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMulAdd", .{});
6080}6089}
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 {
6083 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6092 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6084 const src = inst_data.src();6093 const src = inst_data.src();
6085 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinCall", .{});6094 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinCall", .{});
6086}6095}
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 {
6089 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6098 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6090 const src = inst_data.src();6099 const src = inst_data.src();
6091 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldPtrType", .{});6100 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldPtrType", .{});
6092}6101}
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 {
6095 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6104 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6096 const src = inst_data.src();6105 const src = inst_data.src();
6097 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldParentPtr", .{});6106 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldParentPtr", .{});
6098}6107}
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 {
6101 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6110 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6102 const src = inst_data.src();6111 const src = inst_data.src();
6103 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemcpy", .{});6112 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemcpy", .{});
6104}6113}
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 {
6107 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6116 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6108 const src = inst_data.src();6117 const src = inst_data.src();
6109 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemset", .{});6118 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemset", .{});
6110}6119}
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 {
6113 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6122 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6114 const src = inst_data.src();6123 const src = inst_data.src();
6115 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinAsyncCall", .{});6124 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinAsyncCall", .{});
6116}6125}
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 {
6119 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6128 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6120 const src = inst_data.src();6129 const src = inst_data.src();
6121 return sema.mod.fail(&block.base, src, "TODO: Sema.zirResume", .{});6130 return sema.mod.fail(&block.base, src, "TODO: Sema.zirResume", .{});
...@@ -6126,7 +6135,7 @@ fn zirAwait(...@@ -6126,7 +6135,7 @@ fn zirAwait(
6126 block: *Scope.Block,6135 block: *Scope.Block,
6127 inst: Zir.Inst.Index,6136 inst: Zir.Inst.Index,
6128 is_nosuspend: bool,6137 is_nosuspend: bool,
6129) InnerError!*Inst {6138) InnerError!Air.Inst.Index {
6130 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6139 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6131 const src = inst_data.src();6140 const src = inst_data.src();
61326141
...@@ -6138,7 +6147,7 @@ fn zirVarExtended(...@@ -6138,7 +6147,7 @@ fn zirVarExtended(
6138 sema: *Sema,6147 sema: *Sema,
6139 block: *Scope.Block,6148 block: *Scope.Block,
6140 extended: Zir.Inst.Extended.InstData,6149 extended: Zir.Inst.Extended.InstData,
6141) InnerError!*Inst {6150) InnerError!Air.Inst.Index {
6142 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);6151 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
6143 const src = sema.src;6152 const src = sema.src;
6144 const ty_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at type6153 const ty_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at type
...@@ -6204,7 +6213,7 @@ fn zirFuncExtended(...@@ -6204,7 +6213,7 @@ fn zirFuncExtended(
6204 block: *Scope.Block,6213 block: *Scope.Block,
6205 extended: Zir.Inst.Extended.InstData,6214 extended: Zir.Inst.Extended.InstData,
6206 inst: Zir.Inst.Index,6215 inst: Zir.Inst.Index,
6207) InnerError!*Inst {6216) InnerError!Air.Inst.Index {
6208 const tracy = trace(@src());6217 const tracy = trace(@src());
6209 defer tracy.end();6218 defer tracy.end();
62106219
...@@ -6271,7 +6280,7 @@ fn zirCUndef(...@@ -6271,7 +6280,7 @@ fn zirCUndef(
6271 sema: *Sema,6280 sema: *Sema,
6272 block: *Scope.Block,6281 block: *Scope.Block,
6273 extended: Zir.Inst.Extended.InstData,6282 extended: Zir.Inst.Extended.InstData,
6274) InnerError!*Inst {6283) InnerError!Air.Inst.Index {
6275 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;6284 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6276 const src: LazySrcLoc = .{ .node_offset = extra.node };6285 const src: LazySrcLoc = .{ .node_offset = extra.node };
6277 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCUndef", .{});6286 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCUndef", .{});
...@@ -6281,7 +6290,7 @@ fn zirCInclude(...@@ -6281,7 +6290,7 @@ fn zirCInclude(
6281 sema: *Sema,6290 sema: *Sema,
6282 block: *Scope.Block,6291 block: *Scope.Block,
6283 extended: Zir.Inst.Extended.InstData,6292 extended: Zir.Inst.Extended.InstData,
6284) InnerError!*Inst {6293) InnerError!Air.Inst.Index {
6285 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;6294 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6286 const src: LazySrcLoc = .{ .node_offset = extra.node };6295 const src: LazySrcLoc = .{ .node_offset = extra.node };
6287 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCInclude", .{});6296 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCInclude", .{});
...@@ -6291,7 +6300,7 @@ fn zirCDefine(...@@ -6291,7 +6300,7 @@ fn zirCDefine(
6291 sema: *Sema,6300 sema: *Sema,
6292 block: *Scope.Block,6301 block: *Scope.Block,
6293 extended: Zir.Inst.Extended.InstData,6302 extended: Zir.Inst.Extended.InstData,
6294) InnerError!*Inst {6303) InnerError!Air.Inst.Index {
6295 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;6304 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
6296 const src: LazySrcLoc = .{ .node_offset = extra.node };6305 const src: LazySrcLoc = .{ .node_offset = extra.node };
6297 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCDefine", .{});6306 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCDefine", .{});
...@@ -6301,7 +6310,7 @@ fn zirWasmMemorySize(...@@ -6301,7 +6310,7 @@ fn zirWasmMemorySize(
6301 sema: *Sema,6310 sema: *Sema,
6302 block: *Scope.Block,6311 block: *Scope.Block,
6303 extended: Zir.Inst.Extended.InstData,6312 extended: Zir.Inst.Extended.InstData,
6304) InnerError!*Inst {6313) InnerError!Air.Inst.Index {
6305 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;6314 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6306 const src: LazySrcLoc = .{ .node_offset = extra.node };6315 const src: LazySrcLoc = .{ .node_offset = extra.node };
6307 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemorySize", .{});6316 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemorySize", .{});
...@@ -6311,7 +6320,7 @@ fn zirWasmMemoryGrow(...@@ -6311,7 +6320,7 @@ fn zirWasmMemoryGrow(
6311 sema: *Sema,6320 sema: *Sema,
6312 block: *Scope.Block,6321 block: *Scope.Block,
6313 extended: Zir.Inst.Extended.InstData,6322 extended: Zir.Inst.Extended.InstData,
6314) InnerError!*Inst {6323) InnerError!Air.Inst.Index {
6315 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;6324 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
6316 const src: LazySrcLoc = .{ .node_offset = extra.node };6325 const src: LazySrcLoc = .{ .node_offset = extra.node };
6317 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemoryGrow", .{});6326 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemoryGrow", .{});
...@@ -6321,7 +6330,7 @@ fn zirBuiltinExtern(...@@ -6321,7 +6330,7 @@ fn zirBuiltinExtern(
6321 sema: *Sema,6330 sema: *Sema,
6322 block: *Scope.Block,6331 block: *Scope.Block,
6323 extended: Zir.Inst.Extended.InstData,6332 extended: Zir.Inst.Extended.InstData,
6324) InnerError!*Inst {6333) InnerError!Air.Inst.Index {
6325 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;6334 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
6326 const src: LazySrcLoc = .{ .node_offset = extra.node };6335 const src: LazySrcLoc = .{ .node_offset = extra.node };
6327 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinExtern", .{});6336 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinExtern", .{});
...@@ -6355,7 +6364,7 @@ pub const PanicId = enum {...@@ -6355,7 +6364,7 @@ pub const PanicId = enum {
6355 invalid_error_code,6364 invalid_error_code,
6356};6365};
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 {
6359 const block_inst = try sema.arena.create(Inst.Block);6368 const block_inst = try sema.arena.create(Inst.Block);
6360 block_inst.* = .{6369 block_inst.* = .{
6361 .base = .{6370 .base = .{
...@@ -6364,12 +6373,12 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id:...@@ -6364,12 +6373,12 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id:
6364 .src = ok.src,6373 .src = ok.src,
6365 },6374 },
6366 .body = .{6375 .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.
6368 },6377 },
6369 };6378 };
63706379
6371 const ok_body: ir.Body = .{6380 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.
6373 };6382 };
6374 const br_void = try sema.arena.create(Inst.BrVoid);6383 const br_void = try sema.arena.create(Inst.BrVoid);
6375 br_void.* = .{6384 br_void.* = .{
...@@ -6395,7 +6404,7 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id:...@@ -6395,7 +6404,7 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id:
63956404
6396 _ = try sema.safetyPanic(&fail_block, ok.src, panic_id);6405 _ = 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
6400 const condbr = try sema.arena.create(Inst.CondBr);6409 const condbr = try sema.arena.create(Inst.CondBr);
6401 condbr.* = .{6410 condbr.* = .{
...@@ -6417,7 +6426,7 @@ fn panicWithMsg(...@@ -6417,7 +6426,7 @@ fn panicWithMsg(
6417 sema: *Sema,6426 sema: *Sema,
6418 block: *Scope.Block,6427 block: *Scope.Block,
6419 src: LazySrcLoc,6428 src: LazySrcLoc,
6420 msg_inst: *ir.Inst,6429 msg_inst: Air.Inst.Index,
6421) !Zir.Inst.Index {6430) !Zir.Inst.Index {
6422 const mod = sema.mod;6431 const mod = sema.mod;
6423 const arena = sema.arena;6432 const arena = sema.arena;
...@@ -6438,7 +6447,7 @@ fn panicWithMsg(...@@ -6438,7 +6447,7 @@ fn panicWithMsg(
6438 .ty = try mod.optionalType(arena, ptr_stack_trace_ty),6447 .ty = try mod.optionalType(arena, ptr_stack_trace_ty),
6439 .val = Value.initTag(.null_value),6448 .val = Value.initTag(.null_value),
6440 });6449 });
6441 const args = try arena.create([2]*ir.Inst);6450 const args = try arena.create([2]Air.Inst.Index);
6442 args.* = .{ msg_inst, null_stack_trace };6451 args.* = .{ msg_inst, null_stack_trace };
6443 _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, args);6452 _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, args);
6444 return always_noreturn;6453 return always_noreturn;
...@@ -6494,10 +6503,10 @@ fn namedFieldPtr(...@@ -6494,10 +6503,10 @@ fn namedFieldPtr(
6494 sema: *Sema,6503 sema: *Sema,
6495 block: *Scope.Block,6504 block: *Scope.Block,
6496 src: LazySrcLoc,6505 src: LazySrcLoc,
6497 object_ptr: *Inst,6506 object_ptr: Air.Inst.Index,
6498 field_name: []const u8,6507 field_name: []const u8,
6499 field_name_src: LazySrcLoc,6508 field_name_src: LazySrcLoc,
6500) InnerError!*Inst {6509) InnerError!Air.Inst.Index {
6501 const mod = sema.mod;6510 const mod = sema.mod;
6502 const arena = sema.arena;6511 const arena = sema.arena;
65036512
...@@ -6647,7 +6656,7 @@ fn analyzeNamespaceLookup(...@@ -6647,7 +6656,7 @@ fn analyzeNamespaceLookup(
6647 src: LazySrcLoc,6656 src: LazySrcLoc,
6648 namespace: *Scope.Namespace,6657 namespace: *Scope.Namespace,
6649 decl_name: []const u8,6658 decl_name: []const u8,
6650) InnerError!?*Inst {6659) InnerError!?Air.Inst.Index {
6651 const mod = sema.mod;6660 const mod = sema.mod;
6652 const gpa = sema.gpa;6661 const gpa = sema.gpa;
6653 if (try sema.lookupInNamespace(namespace, decl_name)) |decl| {6662 if (try sema.lookupInNamespace(namespace, decl_name)) |decl| {
...@@ -6671,11 +6680,11 @@ fn analyzeStructFieldPtr(...@@ -6671,11 +6680,11 @@ fn analyzeStructFieldPtr(
6671 sema: *Sema,6680 sema: *Sema,
6672 block: *Scope.Block,6681 block: *Scope.Block,
6673 src: LazySrcLoc,6682 src: LazySrcLoc,
6674 struct_ptr: *Inst,6683 struct_ptr: Air.Inst.Index,
6675 field_name: []const u8,6684 field_name: []const u8,
6676 field_name_src: LazySrcLoc,6685 field_name_src: LazySrcLoc,
6677 unresolved_struct_ty: Type,6686 unresolved_struct_ty: Type,
6678) InnerError!*Inst {6687) InnerError!Air.Inst.Index {
6679 const mod = sema.mod;6688 const mod = sema.mod;
6680 const arena = sema.arena;6689 const arena = sema.arena;
6681 assert(unresolved_struct_ty.zigTypeTag() == .Struct);6690 assert(unresolved_struct_ty.zigTypeTag() == .Struct);
...@@ -6706,11 +6715,11 @@ fn analyzeUnionFieldPtr(...@@ -6706,11 +6715,11 @@ fn analyzeUnionFieldPtr(
6706 sema: *Sema,6715 sema: *Sema,
6707 block: *Scope.Block,6716 block: *Scope.Block,
6708 src: LazySrcLoc,6717 src: LazySrcLoc,
6709 union_ptr: *Inst,6718 union_ptr: Air.Inst.Index,
6710 field_name: []const u8,6719 field_name: []const u8,
6711 field_name_src: LazySrcLoc,6720 field_name_src: LazySrcLoc,
6712 unresolved_union_ty: Type,6721 unresolved_union_ty: Type,
6713) InnerError!*Inst {6722) InnerError!Air.Inst.Index {
6714 const mod = sema.mod;6723 const mod = sema.mod;
6715 const arena = sema.arena;6724 const arena = sema.arena;
6716 assert(unresolved_union_ty.zigTypeTag() == .Union);6725 assert(unresolved_union_ty.zigTypeTag() == .Union);
...@@ -6743,10 +6752,10 @@ fn elemPtr(...@@ -6743,10 +6752,10 @@ fn elemPtr(
6743 sema: *Sema,6752 sema: *Sema,
6744 block: *Scope.Block,6753 block: *Scope.Block,
6745 src: LazySrcLoc,6754 src: LazySrcLoc,
6746 array_ptr: *Inst,6755 array_ptr: Air.Inst.Index,
6747 elem_index: *Inst,6756 elem_index: Air.Inst.Index,
6748 elem_index_src: LazySrcLoc,6757 elem_index_src: LazySrcLoc,
6749) InnerError!*Inst {6758) InnerError!Air.Inst.Index {
6750 const array_ty = switch (array_ptr.ty.zigTypeTag()) {6759 const array_ty = switch (array_ptr.ty.zigTypeTag()) {
6751 .Pointer => array_ptr.ty.elemType(),6760 .Pointer => array_ptr.ty.elemType(),
6752 else => return sema.mod.fail(&block.base, array_ptr.src, "expected pointer, found '{}'", .{array_ptr.ty}),6761 else => return sema.mod.fail(&block.base, array_ptr.src, "expected pointer, found '{}'", .{array_ptr.ty}),
...@@ -6770,10 +6779,10 @@ fn elemPtrArray(...@@ -6770,10 +6779,10 @@ fn elemPtrArray(
6770 sema: *Sema,6779 sema: *Sema,
6771 block: *Scope.Block,6780 block: *Scope.Block,
6772 src: LazySrcLoc,6781 src: LazySrcLoc,
6773 array_ptr: *Inst,6782 array_ptr: Air.Inst.Index,
6774 elem_index: *Inst,6783 elem_index: Air.Inst.Index,
6775 elem_index_src: LazySrcLoc,6784 elem_index_src: LazySrcLoc,
6776) InnerError!*Inst {6785) InnerError!Air.Inst.Index {
6777 if (array_ptr.value()) |array_ptr_val| {6786 if (array_ptr.value()) |array_ptr_val| {
6778 if (elem_index.value()) |index_val| {6787 if (elem_index.value()) |index_val| {
6779 // Both array pointer and index are compile-time known.6788 // Both array pointer and index are compile-time known.
...@@ -6798,9 +6807,9 @@ fn coerce(...@@ -6798,9 +6807,9 @@ fn coerce(
6798 sema: *Sema,6807 sema: *Sema,
6799 block: *Scope.Block,6808 block: *Scope.Block,
6800 dest_type: Type,6809 dest_type: Type,
6801 inst: *Inst,6810 inst: Air.Inst.Index,
6802 inst_src: LazySrcLoc,6811 inst_src: LazySrcLoc,
6803) InnerError!*Inst {6812) InnerError!Air.Inst.Index {
6804 if (dest_type.tag() == .var_args_param) {6813 if (dest_type.tag() == .var_args_param) {
6805 return sema.coerceVarArgParam(block, inst);6814 return sema.coerceVarArgParam(block, inst);
6806 }6815 }
...@@ -6976,7 +6985,7 @@ fn coerceInMemoryAllowed(dest_type: Type, src_type: Type) InMemoryCoercionResult...@@ -6976,7 +6985,7 @@ fn coerceInMemoryAllowed(dest_type: Type, src_type: Type) InMemoryCoercionResult
6976 return .no_match;6985 return .no_match;
6977}6986}
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 {
6980 const val = inst.value() orelse return null;6989 const val = inst.value() orelse return null;
6981 const src_zig_tag = inst.ty.zigTypeTag();6990 const src_zig_tag = inst.ty.zigTypeTag();
6982 const dst_zig_tag = dest_type.zigTypeTag();6991 const dst_zig_tag = dest_type.zigTypeTag();
...@@ -7014,7 +7023,7 @@ fn coerceNum(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst) Inn...@@ -7014,7 +7023,7 @@ fn coerceNum(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst) Inn
7014 return null;7023 return null;
7015}7024}
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 {
7018 switch (inst.ty.zigTypeTag()) {7027 switch (inst.ty.zigTypeTag()) {
7019 .ComptimeInt, .ComptimeFloat => return sema.mod.fail(&block.base, inst.src, "integer and float literals in var args function must be casted", .{}),7028 .ComptimeInt, .ComptimeFloat => return sema.mod.fail(&block.base, inst.src, "integer and float literals in var args function must be casted", .{}),
7020 else => {},7029 else => {},
...@@ -7027,8 +7036,8 @@ fn storePtr(...@@ -7027,8 +7036,8 @@ fn storePtr(
7027 sema: *Sema,7036 sema: *Sema,
7028 block: *Scope.Block,7037 block: *Scope.Block,
7029 src: LazySrcLoc,7038 src: LazySrcLoc,
7030 ptr: *Inst,7039 ptr: Air.Inst.Index,
7031 uncasted_value: *Inst,7040 uncasted_value: Air.Inst.Index,
7032) !void {7041) !void {
7033 if (ptr.ty.isConstPtr())7042 if (ptr.ty.isConstPtr())
7034 return sema.mod.fail(&block.base, src, "cannot assign to constant", .{});7043 return sema.mod.fail(&block.base, src, "cannot assign to constant", .{});
...@@ -7076,7 +7085,7 @@ fn storePtr(...@@ -7076,7 +7085,7 @@ fn storePtr(
7076 _ = try block.addBinOp(src, Type.initTag(.void), .store, ptr, value);7085 _ = try block.addBinOp(src, Type.initTag(.void), .store, ptr, value);
7077}7086}
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 {
7080 if (inst.value()) |val| {7089 if (inst.value()) |val| {
7081 // Keep the comptime Value representation; take the new type.7090 // Keep the comptime Value representation; take the new type.
7082 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });7091 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...@@ -7086,7 +7095,7 @@ fn bitcast(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst) !*Ins
7086 return block.addUnOp(inst.src, dest_type, .bitcast, inst);7095 return block.addUnOp(inst.src, dest_type, .bitcast, inst);
7087}7096}
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 {
7090 if (inst.value()) |val| {7099 if (inst.value()) |val| {
7091 // The comptime Value representation is compatible with both types.7100 // The comptime Value representation is compatible with both types.
7092 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });7101 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...@@ -7094,7 +7103,7 @@ fn coerceArrayPtrToSlice(sema: *Sema, block: *Scope.Block, dest_type: Type, inst
7094 return sema.mod.fail(&block.base, inst.src, "TODO implement coerceArrayPtrToSlice runtime instruction", .{});7103 return sema.mod.fail(&block.base, inst.src, "TODO implement coerceArrayPtrToSlice runtime instruction", .{});
7095}7104}
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 {
7098 if (inst.value()) |val| {7107 if (inst.value()) |val| {
7099 // The comptime Value representation is compatible with both types.7108 // The comptime Value representation is compatible with both types.
7100 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });7109 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:...@@ -7102,12 +7111,12 @@ fn coerceArrayPtrToMany(sema: *Sema, block: *Scope.Block, dest_type: Type, inst:
7102 return sema.mod.fail(&block.base, inst.src, "TODO implement coerceArrayPtrToMany runtime instruction", .{});7111 return sema.mod.fail(&block.base, inst.src, "TODO implement coerceArrayPtrToMany runtime instruction", .{});
7103}7112}
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 {
7106 const decl_ref = try sema.analyzeDeclRef(block, src, decl);7115 const decl_ref = try sema.analyzeDeclRef(block, src, decl);
7107 return sema.analyzeLoad(block, src, decl_ref, src);7116 return sema.analyzeLoad(block, src, decl_ref, src);
7108}7117}
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 {
7111 try sema.mod.declareDeclDependency(sema.owner_decl, decl);7120 try sema.mod.declareDeclDependency(sema.owner_decl, decl);
7112 sema.mod.ensureDeclAnalyzed(decl) catch |err| {7121 sema.mod.ensureDeclAnalyzed(decl) catch |err| {
7113 if (sema.func) |func| {7122 if (sema.func) |func| {
...@@ -7128,7 +7137,7 @@ fn analyzeDeclRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl...@@ -7128,7 +7137,7 @@ fn analyzeDeclRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl
7128 });7137 });
7129}7138}
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 {
7132 const variable = tv.val.castTag(.variable).?.data;7141 const variable = tv.val.castTag(.variable).?.data;
71337142
7134 const ty = try sema.mod.simplePtrType(sema.arena, tv.ty, variable.is_mutable, .One);7143 const ty = try sema.mod.simplePtrType(sema.arena, tv.ty, variable.is_mutable, .One);
...@@ -7157,8 +7166,8 @@ fn analyzeRef(...@@ -7157,8 +7166,8 @@ fn analyzeRef(
7157 sema: *Sema,7166 sema: *Sema,
7158 block: *Scope.Block,7167 block: *Scope.Block,
7159 src: LazySrcLoc,7168 src: LazySrcLoc,
7160 operand: *Inst,7169 operand: Air.Inst.Index,
7161) InnerError!*Inst {7170) InnerError!Air.Inst.Index {
7162 const ptr_type = try sema.mod.simplePtrType(sema.arena, operand.ty, false, .One);7171 const ptr_type = try sema.mod.simplePtrType(sema.arena, operand.ty, false, .One);
71637172
7164 if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |val| {7173 if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |val| {
...@@ -7176,9 +7185,9 @@ fn analyzeLoad(...@@ -7176,9 +7185,9 @@ fn analyzeLoad(
7176 sema: *Sema,7185 sema: *Sema,
7177 block: *Scope.Block,7186 block: *Scope.Block,
7178 src: LazySrcLoc,7187 src: LazySrcLoc,
7179 ptr: *Inst,7188 ptr: Air.Inst.Index,
7180 ptr_src: LazySrcLoc,7189 ptr_src: LazySrcLoc,
7181) InnerError!*Inst {7190) InnerError!Air.Inst.Index {
7182 const elem_ty = switch (ptr.ty.zigTypeTag()) {7191 const elem_ty = switch (ptr.ty.zigTypeTag()) {
7183 .Pointer => ptr.ty.elemType(),7192 .Pointer => ptr.ty.elemType(),
7184 else => return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr.ty}),7193 else => return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr.ty}),
...@@ -7201,9 +7210,9 @@ fn analyzeIsNull(...@@ -7201,9 +7210,9 @@ fn analyzeIsNull(
7201 sema: *Sema,7210 sema: *Sema,
7202 block: *Scope.Block,7211 block: *Scope.Block,
7203 src: LazySrcLoc,7212 src: LazySrcLoc,
7204 operand: *Inst,7213 operand: Air.Inst.Index,
7205 invert_logic: bool,7214 invert_logic: bool,
7206) InnerError!*Inst {7215) InnerError!Air.Inst.Index {
7207 const result_ty = Type.initTag(.bool);7216 const result_ty = Type.initTag(.bool);
7208 if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |opt_val| {7217 if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |opt_val| {
7209 if (opt_val.isUndef()) {7218 if (opt_val.isUndef()) {
...@@ -7222,8 +7231,8 @@ fn analyzeIsNonErr(...@@ -7222,8 +7231,8 @@ fn analyzeIsNonErr(
7222 sema: *Sema,7231 sema: *Sema,
7223 block: *Scope.Block,7232 block: *Scope.Block,
7224 src: LazySrcLoc,7233 src: LazySrcLoc,
7225 operand: *Inst,7234 operand: Air.Inst.Index,
7226) InnerError!*Inst {7235) InnerError!Air.Inst.Index {
7227 const ot = operand.ty.zigTypeTag();7236 const ot = operand.ty.zigTypeTag();
7228 if (ot != .ErrorSet and ot != .ErrorUnion) return sema.mod.constBool(sema.arena, src, true);7237 if (ot != .ErrorSet and ot != .ErrorUnion) return sema.mod.constBool(sema.arena, src, true);
7229 if (ot == .ErrorSet) return sema.mod.constBool(sema.arena, src, false);7238 if (ot == .ErrorSet) return sema.mod.constBool(sema.arena, src, false);
...@@ -7243,12 +7252,12 @@ fn analyzeSlice(...@@ -7243,12 +7252,12 @@ fn analyzeSlice(
7243 sema: *Sema,7252 sema: *Sema,
7244 block: *Scope.Block,7253 block: *Scope.Block,
7245 src: LazySrcLoc,7254 src: LazySrcLoc,
7246 array_ptr: *Inst,7255 array_ptr: Air.Inst.Index,
7247 start: *Inst,7256 start: Air.Inst.Index,
7248 end_opt: ?*Inst,7257 end_opt: ?Air.Inst.Index,
7249 sentinel_opt: ?*Inst,7258 sentinel_opt: ?Air.Inst.Index,
7250 sentinel_src: LazySrcLoc,7259 sentinel_src: LazySrcLoc,
7251) InnerError!*Inst {7260) InnerError!Air.Inst.Index {
7252 const ptr_child = switch (array_ptr.ty.zigTypeTag()) {7261 const ptr_child = switch (array_ptr.ty.zigTypeTag()) {
7253 .Pointer => array_ptr.ty.elemType(),7262 .Pointer => array_ptr.ty.elemType(),
7254 else => return sema.mod.fail(&block.base, src, "expected pointer, found '{}'", .{array_ptr.ty}),7263 else => return sema.mod.fail(&block.base, src, "expected pointer, found '{}'", .{array_ptr.ty}),
...@@ -7319,10 +7328,10 @@ fn cmpNumeric(...@@ -7319,10 +7328,10 @@ fn cmpNumeric(
7319 sema: *Sema,7328 sema: *Sema,
7320 block: *Scope.Block,7329 block: *Scope.Block,
7321 src: LazySrcLoc,7330 src: LazySrcLoc,
7322 lhs: *Inst,7331 lhs: Air.Inst.Index,
7323 rhs: *Inst,7332 rhs: Air.Inst.Index,
7324 op: std.math.CompareOperator,7333 op: std.math.CompareOperator,
7325) InnerError!*Inst {7334) InnerError!Air.Inst.Index {
7326 assert(lhs.ty.isNumeric());7335 assert(lhs.ty.isNumeric());
7327 assert(rhs.ty.isNumeric());7336 assert(rhs.ty.isNumeric());
73287337
...@@ -7488,7 +7497,7 @@ fn cmpNumeric(...@@ -7488,7 +7497,7 @@ fn cmpNumeric(
7488 return block.addBinOp(src, Type.initTag(.bool), Inst.Tag.fromCmpOp(op), casted_lhs, casted_rhs);7497 return block.addBinOp(src, Type.initTag(.bool), Inst.Tag.fromCmpOp(op), casted_lhs, casted_rhs);
7489}7498}
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 {
7492 if (inst.value()) |val| {7501 if (inst.value()) |val| {
7493 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });7502 return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val });
7494 }7503 }
...@@ -7497,7 +7506,7 @@ fn wrapOptional(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst)...@@ -7497,7 +7506,7 @@ fn wrapOptional(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst)
7497 return block.addUnOp(inst.src, dest_type, .wrap_optional, inst);7506 return block.addUnOp(inst.src, dest_type, .wrap_optional, inst);
7498}7507}
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 {
7501 const err_union = dest_type.castTag(.error_union).?;7510 const err_union = dest_type.castTag(.error_union).?;
7502 if (inst.value()) |val| {7511 if (inst.value()) |val| {
7503 if (inst.ty.zigTypeTag() != .ErrorSet) {7512 if (inst.ty.zigTypeTag() != .ErrorSet) {
...@@ -7568,7 +7577,7 @@ fn wrapErrorUnion(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst...@@ -7568,7 +7577,7 @@ fn wrapErrorUnion(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: *Inst
7568 }7577 }
7569}7578}
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 {
7572 if (instructions.len == 0)7581 if (instructions.len == 0)
7573 return Type.initTag(.noreturn);7582 return Type.initTag(.noreturn);
75747583
...@@ -7704,7 +7713,7 @@ fn getBuiltin(...@@ -7704,7 +7713,7 @@ fn getBuiltin(
7704 block: *Scope.Block,7713 block: *Scope.Block,
7705 src: LazySrcLoc,7714 src: LazySrcLoc,
7706 name: []const u8,7715 name: []const u8,
7707) InnerError!*ir.Inst {7716) InnerError!Air.Inst.Index {
7708 const mod = sema.mod;7717 const mod = sema.mod;
7709 const std_pkg = mod.root_pkg.table.get("std").?;7718 const std_pkg = mod.root_pkg.table.get("std").?;
7710 const std_file = (mod.importPkg(std_pkg) catch unreachable).file;7719 const std_file = (mod.importPkg(std_pkg) catch unreachable).file;
src/codegen/spirv.zig+198-213
...@@ -18,14 +18,14 @@ pub const Word = u32;...@@ -18,14 +18,14 @@ pub const Word = u32;
18pub const ResultId = u32;18pub const ResultId = u32;
1919
20pub const TypeMap = std.HashMap(Type, u32, Type.HashContext64, std.hash_map.default_max_load_percentage);20pub 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
23const IncomingBlock = struct {23const IncomingBlock = struct {
24 src_label_id: ResultId,24 src_label_id: ResultId,
25 break_value_id: ResultId,25 break_value_id: ResultId,
26};26};
2727
28pub const BlockMap = std.AutoHashMap(*Inst.Block, struct {28pub const BlockMap = std.AutoHashMap(Air.Inst.Index, struct {
29 label_id: ResultId,29 label_id: ResultId,
30 incoming_blocks: *std.ArrayListUnmanaged(IncomingBlock),30 incoming_blocks: *std.ArrayListUnmanaged(IncomingBlock),
31});31});
...@@ -279,16 +279,17 @@ pub const DeclGen = struct {...@@ -279,16 +279,17 @@ pub const DeclGen = struct {
279 return self.spv.module.getTarget();279 return self.spv.module.getTarget();
280 }280 }
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 {
283 @setCold(true);283 @setCold(true);
284 const src: LazySrcLoc = .{ .node_offset = 0 };
284 const src_loc = src.toSrcLocWithDecl(self.decl);285 const src_loc = src.toSrcLocWithDecl(self.decl);
285 self.error_msg = try Module.ErrorMsg.create(self.spv.module.gpa, src_loc, format, args);286 self.error_msg = try Module.ErrorMsg.create(self.spv.module.gpa, src_loc, format, args);
286 return error.AnalysisFail;287 return error.AnalysisFail;
287 }288 }
288289
289 fn resolve(self: *DeclGen, inst: *Inst) !ResultId {290 fn resolve(self: *DeclGen, inst: Air.Inst.Index) !ResultId {
290 if (inst.value()) |val| {291 if (inst.value()) |val| {
291 return self.genConstant(inst.src, inst.ty, val);292 return self.genConstant(inst.ty, val);
292 }293 }
293294
294 return self.inst_results.get(inst).?; // Instruction does not dominate all uses!295 return self.inst_results.get(inst).?; // Instruction does not dominate all uses!
...@@ -313,7 +314,7 @@ pub const DeclGen = struct {...@@ -313,7 +314,7 @@ pub const DeclGen = struct {
313 const target = self.getTarget();314 const target = self.getTarget();
314315
315 // The backend will never be asked to compiler a 0-bit integer, so we won't have to handle those in this function.316 // 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
318 // 8, 16 and 64-bit integers require the Int8, Int16 and Inr64 capabilities respectively.319 // 8, 16 and 64-bit integers require the Int8, Int16 and Inr64 capabilities respectively.
319 // 32-bit integers are always supported (see spec, 2.16.1, Data rules).320 // 32-bit integers are always supported (see spec, 2.16.1, Data rules).
...@@ -387,19 +388,19 @@ pub const DeclGen = struct {...@@ -387,19 +388,19 @@ pub const DeclGen = struct {
387 .composite_integer };388 .composite_integer };
388 },389 },
389 // As of yet, there is no vector support in the self-hosted compiler.390 // 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", .{}),
391 // TODO: For which types is this the case?392 // 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}),
393 };394 };
394 }395 }
395396
396 /// Generate a constant representing `val`.397 /// Generate a constant representing `val`.
397 /// TODO: Deduplication?398 /// 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 {
399 const target = self.getTarget();400 const target = self.getTarget();
400 const code = &self.spv.binary.types_globals_constants;401 const code = &self.spv.binary.types_globals_constants;
401 const result_id = self.spv.allocResultId();402 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
404 if (val.isUndef()) {405 if (val.isUndef()) {
405 try writeInstruction(code, .OpUndef, &[_]Word{ result_type_id, result_id });406 try writeInstruction(code, .OpUndef, &[_]Word{ result_type_id, result_id });
...@@ -411,13 +412,13 @@ pub const DeclGen = struct {...@@ -411,13 +412,13 @@ pub const DeclGen = struct {
411 const int_info = ty.intInfo(target);412 const int_info = ty.intInfo(target);
412 const backing_bits = self.backingIntBits(int_info.bits) orelse {413 const backing_bits = self.backingIntBits(int_info.bits) orelse {
413 // Integers too big for any native type are represented as "composite integers": An array of largestSupportedIntBits.414 // 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});
415 };416 };
416417
417 // We can just use toSignedInt/toUnsignedInt here as it returns u64 - a type large enough to hold any418 // We can just use toSignedInt/toUnsignedInt here as it returns u64 - a type large enough to hold any
418 // SPIR-V native type (up to i/u64 with Int64). If SPIR-V ever supports native ints of a larger size, this419 // SPIR-V native type (up to i/u64 with Int64). If SPIR-V ever supports native ints of a larger size, this
419 // might need to be updated.420 // might need to be updated.
420 std.debug.assert(self.largestSupportedIntBits() <= std.meta.bitCount(u64));421 assert(self.largestSupportedIntBits() <= std.meta.bitCount(u64));
421 var int_bits = if (ty.isSignedInt()) @bitCast(u64, val.toSignedInt()) else val.toUnsignedInt();422 var int_bits = if (ty.isSignedInt()) @bitCast(u64, val.toSignedInt()) else val.toUnsignedInt();
422423
423 // Mask the low bits which make up the actual integer. This is to make sure that negative values424 // 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 {...@@ -469,13 +470,13 @@ pub const DeclGen = struct {
469 }470 }
470 },471 },
471 .Void => unreachable,472 .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}),
473 }474 }
474475
475 return result_id;476 return result_id;
476 }477 }
477478
478 fn genType(self: *DeclGen, src: LazySrcLoc, ty: Type) Error!ResultId {479 fn genType(self: *DeclGen, ty: Type) Error!ResultId {
479 // We can't use getOrPut here so we can recursively generate types.480 // We can't use getOrPut here so we can recursively generate types.
480 if (self.spv.types.get(ty)) |already_generated| {481 if (self.spv.types.get(ty)) |already_generated| {
481 return already_generated;482 return already_generated;
...@@ -492,7 +493,7 @@ pub const DeclGen = struct {...@@ -492,7 +493,7 @@ pub const DeclGen = struct {
492 const int_info = ty.intInfo(target);493 const int_info = ty.intInfo(target);
493 const backing_bits = self.backingIntBits(int_info.bits) orelse {494 const backing_bits = self.backingIntBits(int_info.bits) orelse {
494 // Integers too big for any native type are represented as "composite integers": An array of largestSupportedIntBits.495 // 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});
496 };497 };
497498
498 // TODO: If backing_bits != int_info.bits, a duplicate type might be generated here.499 // TODO: If backing_bits != int_info.bits, a duplicate type might be generated here.
...@@ -518,7 +519,7 @@ pub const DeclGen = struct {...@@ -518,7 +519,7 @@ pub const DeclGen = struct {
518 };519 };
519520
520 if (!supported) {521 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});
522 }523 }
523524
524 try writeInstruction(code, .OpTypeFloat, &[_]Word{ result_id, bits });525 try writeInstruction(code, .OpTypeFloat, &[_]Word{ result_id, bits });
...@@ -526,19 +527,19 @@ pub const DeclGen = struct {...@@ -526,19 +527,19 @@ pub const DeclGen = struct {
526 .Fn => {527 .Fn => {
527 // We only support zig-calling-convention functions, no varargs.528 // We only support zig-calling-convention functions, no varargs.
528 if (ty.fnCallingConvention() != .Unspecified)529 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", .{});
530 if (ty.fnIsVarArgs())531 if (ty.fnIsVarArgs())
531 return self.fail(src, "VarArgs unsupported for SPIR-V", .{});532 return self.fail("VarArgs unsupported for SPIR-V", .{});
532533
533 // In order to avoid a temporary here, first generate all the required types and then simply look them up534 // In order to avoid a temporary here, first generate all the required types and then simply look them up
534 // when generating the function type.535 // when generating the function type.
535 const params = ty.fnParamLen();536 const params = ty.fnParamLen();
536 var i: usize = 0;537 var i: usize = 0;
537 while (i < params) : (i += 1) {538 while (i < params) : (i += 1) {
538 _ = try self.genType(src, ty.fnParamType(i));539 _ = try self.genType(ty.fnParamType(i));
539 }540 }
540541
541 const return_type_id = try self.genType(src, ty.fnReturnType());542 const return_type_id = try self.genType(ty.fnReturnType());
542543
543 // result id + result type id + parameter type ids.544 // result id + result type id + parameter type ids.
544 try writeOpcode(code, .OpTypeFunction, 2 + @intCast(u16, ty.fnParamLen()));545 try writeOpcode(code, .OpTypeFunction, 2 + @intCast(u16, ty.fnParamLen()));
...@@ -551,7 +552,7 @@ pub const DeclGen = struct {...@@ -551,7 +552,7 @@ pub const DeclGen = struct {
551 }552 }
552 },553 },
553 // When recursively generating a type, we cannot infer the pointer's storage class. See genPointerType.554 // 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", .{}),
555 .Vector => {556 .Vector => {
556 // Although not 100% the same, Zig vectors map quite neatly to SPIR-V vectors (including many integer and float operations557 // Although not 100% the same, Zig vectors map quite neatly to SPIR-V vectors (including many integer and float operations
557 // which work on them), so simply use those.558 // which work on them), so simply use those.
...@@ -561,7 +562,7 @@ pub const DeclGen = struct {...@@ -561,7 +562,7 @@ pub const DeclGen = struct {
561 // is adequate at all for this.562 // is adequate at all for this.
562563
563 // TODO: Vectors are not yet supported by the self-hosted compiler itself it seems.564 // 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", .{});
565 },566 },
566 .Null,567 .Null,
567 .Undefined,568 .Undefined,
...@@ -573,7 +574,7 @@ pub const DeclGen = struct {...@@ -573,7 +574,7 @@ pub const DeclGen = struct {
573574
574 .BoundFn => unreachable, // this type will be deleted from the language.575 .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}),
577 }578 }
578579
579 try self.spv.types.putNoClobber(ty, result_id);580 try self.spv.types.putNoClobber(ty, result_id);
...@@ -582,8 +583,8 @@ pub const DeclGen = struct {...@@ -582,8 +583,8 @@ pub const DeclGen = struct {
582583
583 /// SPIR-V requires pointers to have a storage class (address space), and so we have a special function for that.584 /// SPIR-V requires pointers to have a storage class (address space), and so we have a special function for that.
584 /// TODO: The result of this needs to be cached.585 /// TODO: The result of this needs to be cached.
585 fn genPointerType(self: *DeclGen, src: LazySrcLoc, ty: Type, storage_class: spec.StorageClass) !ResultId {586 fn genPointerType(self: *DeclGen, ty: Type, storage_class: spec.StorageClass) !ResultId {
586 std.debug.assert(ty.zigTypeTag() == .Pointer);587 assert(ty.zigTypeTag() == .Pointer);
587588
588 const code = &self.spv.binary.types_globals_constants;589 const code = &self.spv.binary.types_globals_constants;
589 const result_id = self.spv.allocResultId();590 const result_id = self.spv.allocResultId();
...@@ -591,7 +592,7 @@ pub const DeclGen = struct {...@@ -591,7 +592,7 @@ pub const DeclGen = struct {
591 // TODO: There are many constraints which are ignored for now: We may only create pointers to certain types, and to other types592 // TODO: There are many constraints which are ignored for now: We may only create pointers to certain types, and to other types
592 // if more capabilities are enabled. For example, we may only create pointers to f16 if Float16Buffer is enabled.593 // if more capabilities are enabled. For example, we may only create pointers to f16 if Float16Buffer is enabled.
593 // These also relates to the pointer's address space.594 // 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
596 try writeInstruction(code, .OpTypePointer, &[_]Word{ result_id, @enumToInt(storage_class), child_id });597 try writeInstruction(code, .OpTypePointer, &[_]Word{ result_id, @enumToInt(storage_class), child_id });
597598
...@@ -602,9 +603,9 @@ pub const DeclGen = struct {...@@ -602,9 +603,9 @@ pub const DeclGen = struct {
602 const decl = self.decl;603 const decl = self.decl;
603 const result_id = decl.fn_link.spirv.id;604 const result_id = decl.fn_link.spirv.id;
604605
605 if (decl.val.castTag(.function)) |func_payload| {606 if (decl.val.castTag(.function)) |_| {
606 std.debug.assert(decl.ty.zigTypeTag() == .Fn);607 assert(decl.ty.zigTypeTag() == .Fn);
607 const prototype_id = try self.genType(.{ .node_offset = 0 }, decl.ty);608 const prototype_id = try self.genType(decl.ty);
608 try writeInstruction(&self.spv.binary.fn_decls, .OpFunction, &[_]Word{609 try writeInstruction(&self.spv.binary.fn_decls, .OpFunction, &[_]Word{
609 self.spv.types.get(decl.ty.fnReturnType()).?, // This type should be generated along with the prototype.610 self.spv.types.get(decl.ty.fnReturnType()).?, // This type should be generated along with the prototype.
610 result_id,611 result_id,
...@@ -631,189 +632,167 @@ pub const DeclGen = struct {...@@ -631,189 +632,167 @@ pub const DeclGen = struct {
631 try writeInstruction(&self.spv.binary.fn_decls, .OpLabel, &[_]Word{root_block_id});632 try writeInstruction(&self.spv.binary.fn_decls, .OpLabel, &[_]Word{root_block_id});
632 self.current_block_label_id = root_block_id;633 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
636 // Append the actual code into the fn_decls section.638 // Append the actual code into the fn_decls section.
637 try self.spv.binary.fn_decls.appendSlice(self.code.items);639 try self.spv.binary.fn_decls.appendSlice(self.code.items);
638 try writeInstruction(&self.spv.binary.fn_decls, .OpFunctionEnd, &[_]Word{});640 try writeInstruction(&self.spv.binary.fn_decls, .OpFunctionEnd, &[_]Word{});
639 } else {641 } 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()});
641 }643 }
642 }644 }
643645
644 fn genBody(self: *DeclGen, body: ir.Body) Error!void {646 fn genBody(self: *DeclGen, body: []const Air.Inst.Index) Error!void {
645 for (body.instructions) |inst| {647 for (body) |inst| {
646 try self.genInst(inst);648 try self.genInst(inst);
647 }649 }
648 }650 }
649651
650 fn genInst(self: *DeclGen, inst: *Inst) !void {652 fn genInst(self: *DeclGen, inst: Air.Inst.Index) !void {
651 const result_id = switch (inst.tag) {653 const air_tags = self.air.instructions.items(.tag);
652 .add, .addwrap => try self.genBinOp(inst.castTag(.add).?),654 const result_id = switch (air_tags[inst]) {
653 .sub, .subwrap => try self.genBinOp(inst.castTag(.sub).?),655 // zig fmt: off
654 .mul, .mulwrap => try self.genBinOp(inst.castTag(.mul).?),656 .add, .addwrap => try self.genArithOp(inst, .{.OpFAdd, .OpIAdd, .OpIAdd}),
655 .div => try self.genBinOp(inst.castTag(.div).?),657 .sub, .subwrap => try self.genArithOp(inst, .{.OpFSub, .OpISub, .OpISub}),
656 .bit_and => try self.genBinOp(inst.castTag(.bit_and).?),658 .mul, .mulwrap => try self.genArithOp(inst, .{.OpFMul, .OpIMul, .OpIMul}),
657 .bit_or => try self.genBinOp(inst.castTag(.bit_or).?),659 .div => try self.genArithOp(inst, .{.OpFDiv, .OpSDiv, .OpUDiv}),
658 .xor => try self.genBinOp(inst.castTag(.xor).?),660
659 .cmp_eq => try self.genCmp(inst.castTag(.cmp_eq).?),661 .bit_and => try self.genBinOpSimple(inst, .OpBitwiseAnd),
660 .cmp_neq => try self.genCmp(inst.castTag(.cmp_neq).?),662 .bit_or => try self.genBinOpSimple(inst, .OpBitwiseOr),
661 .cmp_gt => try self.genCmp(inst.castTag(.cmp_gt).?),663 .xor => try self.genBinOpSimple(inst, .OpBitwiseXor),
662 .cmp_gte => try self.genCmp(inst.castTag(.cmp_gte).?),664 .bool_and => try self.genBinOpSimple(inst, .OpLogicalAnd),
663 .cmp_lt => try self.genCmp(inst.castTag(.cmp_lt).?),665 .bool_or => try self.genBinOpSimple(inst, .OpLogicalOr),
664 .cmp_lte => try self.genCmp(inst.castTag(.cmp_lte).?),666
665 .bool_and => try self.genBinOp(inst.castTag(.bool_and).?),667 .not => try self.genNot(inst),
666 .bool_or => try self.genBinOp(inst.castTag(.bool_or).?),668
667 .not => try self.genUnOp(inst.castTag(.not).?),669 .cmp_eq => try self.genCmp(inst, .{.OpFOrdEqual, .OpLogicalEqual, .OpIEqual}),
668 .alloc => try self.genAlloc(inst.castTag(.alloc).?),670 .cmp_neq => try self.genCmp(inst, .{.OpFOrdNotEqual, .OpLogicalNotEqual, .OpINotEqual}),
669 .arg => self.genArg(),671 .cmp_gt => try self.genCmp(inst, .{.OpFOrdGreaterThan, .OpSGreaterThan, .OpUGreaterThan}),
670 .block => (try self.genBlock(inst.castTag(.block).?)) orelse return,672 .cmp_gte => try self.genCmp(inst, .{.OpFOrdGreaterThanEqual, .OpSGreaterThanEqual, .OpUGreaterThanEqual}),
671 .br => return try self.genBr(inst.castTag(.br).?),673 .cmp_lt => try self.genCmp(inst, .{.OpFOrdLessThan, .OpSLessThan, .OpULessThan}),
672 .br_void => return try self.genBrVoid(inst.castTag(.br_void).?),674 .cmp_lte => try self.genCmp(inst, .{.OpFOrdLessThanEqual, .OpSLessThanEqual, .OpULessThanEqual}),
673 // TODO: Breakpoints won't be supported in SPIR-V, but the compiler seems to insert them675
674 // throughout the IR.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),
675 .breakpoint => return,682 .breakpoint => return,
676 .condbr => return try self.genCondBr(inst.castTag(.condbr).?),683 .condbr => return self.genCondBr(inst),
677 .constant => unreachable,684 .constant => unreachable,
678 .dbg_stmt => return try self.genDbgStmt(inst.castTag(.dbg_stmt).?),685 .dbg_stmt => return self.genDbgStmt(inst),
679 .load => try self.genLoad(inst.castTag(.load).?),686 .loop => return self.genLoop(inst),
680 .loop => return try self.genLoop(inst.castTag(.loop).?),687 .ret => return self.genRet(inst),
681 .ret => return try self.genRet(inst.castTag(.ret).?),688 .store => return self.genStore(inst),
682 .retvoid => return try self.genRetVoid(),689 .unreach => return self.genUnreach(),
683 .store => return try self.genStore(inst.castTag(.store).?),690 // zig fmt: on
684 .unreach => return try self.genUnreach(),
685 else => return self.fail(inst.src, "TODO: SPIR-V backend: implement inst {s}", .{@tagName(inst.tag)}),
686 };691 };
687692
688 try self.inst_results.putNoClobber(inst, result_id);693 try self.inst_results.putNoClobber(inst, result_id);
689 }694 }
690695
691 fn genBinOp(self: *DeclGen, inst: *Inst.BinOp) !ResultId {696 fn genBinOpSimple(self: *DeclGen, inst: Air.Inst.Index, opcode: Opcode) !ResultId {
692 // TODO: Will lhs and rhs have the same type?697 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
693 const lhs_id = try self.resolve(inst.lhs);698 const lhs_id = try self.resolve(bin_op.lhs);
694 const rhs_id = try self.resolve(inst.rhs);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
696 const result_id = self.spv.allocResultId();715 const result_id = self.spv.allocResultId();
697 const result_type_id = try self.genType(inst.base.src, inst.base.ty);716 const result_type_id = try self.genType(ty);
698717
699 // TODO: Is the result the same as the argument types?718 assert(self.air.getType(bin_op.lhs).eql(ty));
700 // This is supposed to be the case for SPIR-V.719 assert(self.air.getType(bin_op.rhs).eql(ty));
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 }
715720
716 const is_float = info.class == .float;721 // Binary operations are generally applicable to both scalar and vector operations
717 const is_signed = info.signedness == .signed;722 // in SPIR-V, but int and float versions of operations require different opcodes.
718 // **Note**: All these operations must be valid for vectors as well!723 const info = try self.arithmeticTypeInfo(ty);
719 const opcode = switch (inst.base.tag) {724
720 // The regular integer operations are all defined for wrapping. Since theyre only relevant for integers,725 const opcode_index: usize = switch (info.class) {
721 // we can just switch on both cases here.726 .composite_integer => {
722 .add, .addwrap => if (is_float) Opcode.OpFAdd else Opcode.OpIAdd,727 return self.fail("TODO: SPIR-V backend: binary operations for composite integers", .{});
723 .sub, .subwrap => if (is_float) Opcode.OpFSub else Opcode.OpISub,728 },
724 .mul, .mulwrap => if (is_float) Opcode.OpFMul else Opcode.OpIMul,729 .strange_integer => {
725 // TODO: Trap if divisor is 0?730 return self.fail("TODO: SPIR-V backend: binary operations for strange integers", .{});
726 // TODO: Figure out of OpSDiv for unsigned/OpUDiv for signed does anything useful.731 },
727 // => Those are probably for divTrunc and divFloor, though the compiler does not yet generate those.732 .integer => switch (info.signedness) {
728 // => TODO: Figure out how those work on the SPIR-V side.733 .signed => 1,
729 // => TODO: Test these.734 .unsigned => 2,
730 .div => if (is_float) Opcode.OpFDiv else if (is_signed) Opcode.OpSDiv else Opcode.OpUDiv,735 },
731 // Only integer versions for these.736 .float => 0,
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,
738 else => unreachable,737 else => unreachable,
739 };738 };
740739 const opcode = ops[opcode_index];
741 try writeInstruction(&self.code, opcode, &[_]Word{ result_type_id, result_id, lhs_id, rhs_id });740 try writeInstruction(&self.code, opcode, &[_]Word{ result_type_id, result_id, lhs_id, rhs_id });
742741
743 // TODO: Trap on overflow? Probably going to be annoying.742 // TODO: Trap on overflow? Probably going to be annoying.
744 // TODO: Look into SPV_KHR_no_integer_wrap_decoration which provides NoSignedWrap/NoUnsignedWrap.743 // TODO: Look into SPV_KHR_no_integer_wrap_decoration which provides NoSignedWrap/NoUnsignedWrap.
745744
746 if (info.class != .strange_integer)745 return result_id;
747 return result_id;
748
749 return self.fail(inst.base.src, "TODO: SPIR-V backend: strange integer operation mask", .{});
750 }746 }
751747
752 fn genCmp(self: *DeclGen, inst: *Inst.BinOp) !ResultId {748 fn genCmp(self: *DeclGen, inst: Air.Inst.Index, ops: [3]Opcode) !ResultId {
753 const lhs_id = try self.resolve(inst.lhs);749 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
754 const rhs_id = try self.resolve(inst.rhs);750 const lhs_id = try self.resolve(bin_op.lhs);
755751 const rhs_id = try self.resolve(bin_op.rhs);
756 const result_id = self.spv.allocResultId();752 const result_id = self.spv.allocResultId();
757 const result_type_id = try self.genType(inst.base.src, inst.base.ty);753 const result_type_id = try self.genType(Type.initTag(.bool));
758754 const op_ty = self.air.getType(bin_op.lhs);
759 // All of these operations should be 2 equal types -> bool755 assert(op_ty.eql(self.air.getType(bin_op.rhs)));
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 }
774756
775 const is_bool = info.class == .bool;757 // Comparisons are generally applicable to both scalar and vector operations in SPIR-V,
776 const is_float = info.class == .float;758 // but int and float versions of operations require different opcodes.
777 const is_signed = info.signedness == .signed;759 const info = try self.arithmeticTypeInfo(op_ty);
778760
779 // **Note**: All these operations must be valid for vectors as well!761 const opcode_index: usize = switch (info.class) {
780 // For floating points, we generally want ordered operations (which return false if either operand is nan).762 .composite_integer => {
781 const opcode = switch (inst.base.tag) {763 return self.fail("TODO: SPIR-V backend: binary operations for composite integers", .{});
782 .cmp_eq => if (is_float) Opcode.OpFOrdEqual else if (is_bool) Opcode.OpLogicalEqual else Opcode.OpIEqual,764 },
783 .cmp_neq => if (is_float) Opcode.OpFOrdNotEqual else if (is_bool) Opcode.OpLogicalNotEqual else Opcode.OpINotEqual,765 .strange_integer => {
784 // TODO: Verify that these OpFOrd type operations produce the right value.766 return self.fail("TODO: SPIR-V backend: comparison for strange integers", .{});
785 // TODO: Is there a more fundamental difference between OpU and OpS operations here than just the type?767 },
786 .cmp_gt => if (is_float) Opcode.OpFOrdGreaterThan else if (is_signed) Opcode.OpSGreaterThan else Opcode.OpUGreaterThan,768 .float => 0,
787 .cmp_gte => if (is_float) Opcode.OpFOrdGreaterThanEqual else if (is_signed) Opcode.OpSGreaterThanEqual else Opcode.OpUGreaterThanEqual,769 .bool => 1,
788 .cmp_lt => if (is_float) Opcode.OpFOrdLessThan else if (is_signed) Opcode.OpSLessThan else Opcode.OpULessThan,770 .integer => switch (info.signedness) {
789 .cmp_lte => if (is_float) Opcode.OpFOrdLessThanEqual else if (is_signed) Opcode.OpSLessThanEqual else Opcode.OpULessThanEqual,771 .signed => 1,
772 .unsigned => 2,
773 },
790 else => unreachable,774 else => unreachable,
791 };775 };
776 const opcode = ops[opcode_index];
792777
793 try writeInstruction(&self.code, opcode, &[_]Word{ result_type_id, result_id, lhs_id, rhs_id });778 try writeInstruction(&self.code, opcode, &[_]Word{ result_type_id, result_id, lhs_id, rhs_id });
794 return result_id;779 return result_id;
795 }780 }
796781
797 fn genUnOp(self: *DeclGen, inst: *Inst.UnOp) !ResultId {782 fn genNot(self: *DeclGen, inst: Air.Inst.Index) !ResultId {
798 const operand_id = try self.resolve(inst.operand);783 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
799784 const operand_id = try self.resolve(ty_op.operand);
800 const result_id = self.spv.allocResultId();785 const result_id = self.spv.allocResultId();
801 const result_type_id = try self.genType(inst.base.src, inst.base.ty);786 const result_type_id = try self.genType(Type.initTag(.bool));
802787 const opcode: Opcode = .OpLogicalNot;
803 const opcode = switch (inst.base.tag) {
804 // Bool -> bool
805 .not => Opcode.OpLogicalNot,
806 else => unreachable,
807 };
808
809 try writeInstruction(&self.code, opcode, &[_]Word{ result_type_id, result_id, operand_id });788 try writeInstruction(&self.code, opcode, &[_]Word{ result_type_id, result_id, operand_id });
810
811 return result_id;789 return result_id;
812 }790 }
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);
815 const storage_class = spec.StorageClass.Function;794 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);
817 const result_id = self.spv.allocResultId();796 const result_id = self.spv.allocResultId();
818797
819 // Rather than generating into code here, we're just going to generate directly into the fn_decls section so that798 // 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 {...@@ -828,7 +807,7 @@ pub const DeclGen = struct {
828 return self.args.items[self.next_arg_index];807 return self.args.items[self.next_arg_index];
829 }808 }
830809
831 fn genBlock(self: *DeclGen, inst: *Inst.Block) !?ResultId {810 fn genBlock(self: *DeclGen, inst: Air.Inst.Index) !?ResultId {
832 // 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 and811 // 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
833 // "return" a value from. This cannot be directly modelled in SPIR-V, so in a block instruction, we're going to split up812 // "return" a value from. This cannot be directly modelled in SPIR-V, so in a block instruction, we're going to split up
834 // the current block by first generating the code of the block, then a label, and then generate the rest of the current813 // 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 {...@@ -848,11 +827,16 @@ pub const DeclGen = struct {
848 incoming_blocks.deinit(self.spv.gpa);827 incoming_blocks.deinit(self.spv.gpa);
849 }828 }
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);
852 try self.beginSPIRVBlock(label_id);836 try self.beginSPIRVBlock(label_id);
853837
854 // If this block didn't produce a value, simply return here.838 // If this block didn't produce a value, simply return here.
855 if (!inst.base.ty.hasCodeGenBits())839 if (!ty.hasCodeGenBits())
856 return null;840 return null;
857841
858 // Combine the result from the blocks using the Phi instruction.842 // Combine the result from the blocks using the Phi instruction.
...@@ -862,7 +846,7 @@ pub const DeclGen = struct {...@@ -862,7 +846,7 @@ pub const DeclGen = struct {
862 // TODO: OpPhi is limited in the types that it may produce, such as pointers. Figure out which other types846 // TODO: OpPhi is limited in the types that it may produce, such as pointers. Figure out which other types
863 // are not allowed to be created from a phi node, and throw an error for those. For now, genType already throws847 // are not allowed to be created from a phi node, and throw an error for those. For now, genType already throws
864 // an error for pointers.848 // 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);
866 _ = result_type_id;850 _ = result_type_id;
867851
868 try writeOpcode(&self.code, .OpPhi, 2 + @intCast(u16, incoming_blocks.items.len * 2)); // result type + result + variable/parent...852 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 {...@@ -874,30 +858,26 @@ pub const DeclGen = struct {
874 return result_id;858 return result_id;
875 }859 }
876860
877 fn genBr(self: *DeclGen, inst: *Inst.Br) !void {861 fn genBr(self: *DeclGen, inst: Air.Inst.Index) !void {
878 // TODO: This instruction needs to be the last in a block. Is that guaranteed?862 const br = self.air.instructions.items(.data)[inst].br;
879 const target = self.blocks.get(inst.block).?;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.866 if (operand_ty.hasCodeGenBits()) {
882 if (inst.operand.ty.hasCodeGenBits()) {867 const operand_id = try self.resolve(br.operand);
883 const operand_id = try self.resolve(inst.operand);
884 // current_block_label_id should not be undefined here, lest there is a br or br_void in the function's body.868 // 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 });
886 }870 }
887871
888 try writeInstruction(&self.code, .OpBranch, &[_]Word{target.label_id});872 try writeInstruction(&self.code, .OpBranch, &[_]Word{block.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});
896 }873 }
897874
898 fn genCondBr(self: *DeclGen, inst: *Inst.CondBr) !void {875 fn genCondBr(self: *DeclGen, inst: *Inst.CondBr) !void {
899 // TODO: This instruction needs to be the last in a block. Is that guaranteed?876 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
900 const condition_id = try self.resolve(inst.condition);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
902 // These will always generate a new SPIR-V block, since they are ir.Body and not ir.Block.882 // These will always generate a new SPIR-V block, since they are ir.Body and not ir.Block.
903 const then_label_id = self.spv.allocResultId();883 const then_label_id = self.spv.allocResultId();
...@@ -913,23 +893,26 @@ pub const DeclGen = struct {...@@ -913,23 +893,26 @@ pub const DeclGen = struct {
913 });893 });
914894
915 try self.beginSPIRVBlock(then_label_id);895 try self.beginSPIRVBlock(then_label_id);
916 try self.genBody(inst.then_body);896 try self.genBody(then_body);
917 try self.beginSPIRVBlock(else_label_id);897 try self.beginSPIRVBlock(else_label_id);
918 try self.genBody(inst.else_body);898 try self.genBody(else_body);
919 }899 }
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;
922 const src_fname_id = try self.spv.resolveSourceFileName(self.decl);903 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 });
924 }905 }
925906
926 fn genLoad(self: *DeclGen, inst: *Inst.UnOp) !ResultId {907 fn genLoad(self: *DeclGen, inst: Air.Inst.Index) !ResultId {
927 const operand_id = try self.resolve(inst.operand);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);
930 const result_id = self.spv.allocResultId();913 const result_id = self.spv.allocResultId();
931914
932 const operands = if (inst.base.ty.isVolatilePtr())915 const operands = if (ty.isVolatilePtr())
933 &[_]Word{ result_type_id, result_id, operand_id, @bitCast(u32, spec.MemoryAccess{ .Volatile = true }) }916 &[_]Word{ result_type_id, result_id, operand_id, @bitCast(u32, spec.MemoryAccess{ .Volatile = true }) }
934 else917 else
935 &[_]Word{ result_type_id, result_id, operand_id };918 &[_]Word{ result_type_id, result_id, operand_id };
...@@ -939,8 +922,9 @@ pub const DeclGen = struct {...@@ -939,8 +922,9 @@ pub const DeclGen = struct {
939 return result_id;922 return result_id;
940 }923 }
941924
942 fn genLoop(self: *DeclGen, inst: *Inst.Loop) !void {925 fn genLoop(self: *DeclGen, inst: Air.Inst.Index) !void {
943 // TODO: This instruction needs to be the last in a block. Is that guaranteed?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];
944 const loop_label_id = self.spv.allocResultId();928 const loop_label_id = self.spv.allocResultId();
945929
946 // Jump to the loop entry point930 // Jump to the loop entry point
...@@ -949,27 +933,29 @@ pub const DeclGen = struct {...@@ -949,27 +933,29 @@ pub const DeclGen = struct {
949 // TODO: Look into OpLoopMerge.933 // TODO: Look into OpLoopMerge.
950934
951 try self.beginSPIRVBlock(loop_label_id);935 try self.beginSPIRVBlock(loop_label_id);
952 try self.genBody(inst.body);936 try self.genBody(body);
953937
954 try writeInstruction(&self.code, .OpBranch, &[_]Word{loop_label_id});938 try writeInstruction(&self.code, .OpBranch, &[_]Word{loop_label_id});
955 }939 }
956940
957 fn genRet(self: *DeclGen, inst: *Inst.UnOp) !void {941 fn genRet(self: *DeclGen, inst: Air.Inst.Index) !void {
958 const operand_id = try self.resolve(inst.operand);942 const operand = inst_datas[inst].un_op;
959 // TODO: This instruction needs to be the last in a block. Is that guaranteed?943 const operand_ty = self.air.getType(operand);
960 try writeInstruction(&self.code, .OpReturnValue, &[_]Word{operand_id});944 if (operand_ty.hasCodeGenBits()) {
961 }945 const operand_id = try self.resolve(operand);
962946 try writeInstruction(&self.code, .OpReturnValue, &[_]Word{operand_id});
963 fn genRetVoid(self: *DeclGen) !void {947 } else {
964 // TODO: This instruction needs to be the last in a block. Is that guaranteed?948 try writeInstruction(&self.code, .OpReturn, &[_]Word{});
965 try writeInstruction(&self.code, .OpReturn, &[_]Word{});949 }
966 }950 }
967951
968 fn genStore(self: *DeclGen, inst: *Inst.BinOp) !void {952 fn genStore(self: *DeclGen, inst: Air.Inst.Index) !void {
969 const dst_ptr_id = try self.resolve(inst.lhs);953 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
970 const src_val_id = try self.resolve(inst.rhs);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())
973 &[_]Word{ dst_ptr_id, src_val_id, @bitCast(u32, spec.MemoryAccess{ .Volatile = true }) }959 &[_]Word{ dst_ptr_id, src_val_id, @bitCast(u32, spec.MemoryAccess{ .Volatile = true }) }
974 else960 else
975 &[_]Word{ dst_ptr_id, src_val_id };961 &[_]Word{ dst_ptr_id, src_val_id };
...@@ -978,7 +964,6 @@ pub const DeclGen = struct {...@@ -978,7 +964,6 @@ pub const DeclGen = struct {
978 }964 }
979965
980 fn genUnreach(self: *DeclGen) !void {966 fn genUnreach(self: *DeclGen) !void {
981 // TODO: This instruction needs to be the last in a block. Is that guaranteed?
982 try writeInstruction(&self.code, .OpUnreachable, &[_]Word{});967 try writeInstruction(&self.code, .OpUnreachable, &[_]Word{});
983 }968 }
984};969};