authorgravatar for spexguy070@gmail.comMartin Wickham <spexguy070@gmail.com> 2021-10-01 17:45:13-05:00
committergravatar for spexguy070@gmail.comMartin Wickham <spexguy070@gmail.com> 2021-10-02 15:21:49-05:00
log272bad3f12a43e3613498080b6b656de5e28e2cf
tree8257a0a5416d6f70656ad441a12e2cb4a151fd18
parentfd60012c21360202a74b17d87d230a18d56edc88

Delete Module.Scope, move Block into Sema


12 files changed, 943 insertions(+), 1073 deletions(-)

src/Compilation.zig+6-6
...@@ -54,7 +54,7 @@ c_object_work_queue: std.fifo.LinearFifo(*CObject, .Dynamic),...@@ -54,7 +54,7 @@ c_object_work_queue: std.fifo.LinearFifo(*CObject, .Dynamic),
54/// These jobs are to tokenize, parse, and astgen files, which may be outdated54/// These jobs are to tokenize, parse, and astgen files, which may be outdated
55/// since the last compilation, as well as scan for `@import` and queue up55/// since the last compilation, as well as scan for `@import` and queue up
56/// additional jobs corresponding to those new files.56/// additional jobs corresponding to those new files.
57astgen_work_queue: std.fifo.LinearFifo(*Module.Scope.File, .Dynamic),57astgen_work_queue: std.fifo.LinearFifo(*Module.File, .Dynamic),
5858
59/// The ErrorMsg memory is owned by the `CObject`, using Compilation's general purpose allocator.59/// The ErrorMsg memory is owned by the `CObject`, using Compilation's general purpose allocator.
60/// This data is accessed by multiple threads and is protected by `mutex`.60/// This data is accessed by multiple threads and is protected by `mutex`.
...@@ -446,7 +446,7 @@ pub const AllErrors = struct {...@@ -446,7 +446,7 @@ pub const AllErrors = struct {
446 pub fn addZir(446 pub fn addZir(
447 arena: *Allocator,447 arena: *Allocator,
448 errors: *std.ArrayList(Message),448 errors: *std.ArrayList(Message),
449 file: *Module.Scope.File,449 file: *Module.File,
450 ) !void {450 ) !void {
451 assert(file.zir_loaded);451 assert(file.zir_loaded);
452 assert(file.tree_loaded);452 assert(file.tree_loaded);
...@@ -1444,7 +1444,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -1444,7 +1444,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
1444 .emit_docs = options.emit_docs,1444 .emit_docs = options.emit_docs,
1445 .work_queue = std.fifo.LinearFifo(Job, .Dynamic).init(gpa),1445 .work_queue = std.fifo.LinearFifo(Job, .Dynamic).init(gpa),
1446 .c_object_work_queue = std.fifo.LinearFifo(*CObject, .Dynamic).init(gpa),1446 .c_object_work_queue = std.fifo.LinearFifo(*CObject, .Dynamic).init(gpa),
1447 .astgen_work_queue = std.fifo.LinearFifo(*Module.Scope.File, .Dynamic).init(gpa),1447 .astgen_work_queue = std.fifo.LinearFifo(*Module.File, .Dynamic).init(gpa),
1448 .keep_source_files_loaded = options.keep_source_files_loaded,1448 .keep_source_files_loaded = options.keep_source_files_loaded,
1449 .use_clang = use_clang,1449 .use_clang = use_clang,
1450 .clang_argv = options.clang_argv,1450 .clang_argv = options.clang_argv,
...@@ -2465,14 +2465,14 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor...@@ -2465,14 +2465,14 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
2465const AstGenSrc = union(enum) {2465const AstGenSrc = union(enum) {
2466 root,2466 root,
2467 import: struct {2467 import: struct {
2468 importing_file: *Module.Scope.File,2468 importing_file: *Module.File,
2469 import_tok: std.zig.Ast.TokenIndex,2469 import_tok: std.zig.Ast.TokenIndex,
2470 },2470 },
2471};2471};
24722472
2473fn workerAstGenFile(2473fn workerAstGenFile(
2474 comp: *Compilation,2474 comp: *Compilation,
2475 file: *Module.Scope.File,2475 file: *Module.File,
2476 prog_node: *std.Progress.Node,2476 prog_node: *std.Progress.Node,
2477 wg: *WaitGroup,2477 wg: *WaitGroup,
2478 src: AstGenSrc,2478 src: AstGenSrc,
...@@ -2742,7 +2742,7 @@ fn reportRetryableCObjectError(...@@ -2742,7 +2742,7 @@ fn reportRetryableCObjectError(
2742fn reportRetryableAstGenError(2742fn reportRetryableAstGenError(
2743 comp: *Compilation,2743 comp: *Compilation,
2744 src: AstGenSrc,2744 src: AstGenSrc,
2745 file: *Module.Scope.File,2745 file: *Module.File,
2746 err: anyerror,2746 err: anyerror,
2747) error{OutOfMemory}!void {2747) error{OutOfMemory}!void {
2748 const mod = comp.bin_file.options.module.?;2748 const mod = comp.bin_file.options.module.?;
src/Module.zig+276-684
...@@ -59,7 +59,7 @@ export_owners: std.AutoArrayHashMapUnmanaged(*Decl, []*Export) = .{},...@@ -59,7 +59,7 @@ export_owners: std.AutoArrayHashMapUnmanaged(*Decl, []*Export) = .{},
59/// over it and check which source files have been modified on the file system when59/// over it and check which source files have been modified on the file system when
60/// an update is requested, as well as to cache `@import` results.60/// an update is requested, as well as to cache `@import` results.
61/// Keys are fully resolved file paths. This table owns the keys and values.61/// Keys are fully resolved file paths. This table owns the keys and values.
62import_table: std.StringArrayHashMapUnmanaged(*Scope.File) = .{},62import_table: std.StringArrayHashMapUnmanaged(*File) = .{},
6363
64/// The set of all the generic function instantiations. This is used so that when a generic64/// The set of all the generic function instantiations. This is used so that when a generic
65/// function is called twice with the same comptime parameter arguments, both calls dispatch65/// function is called twice with the same comptime parameter arguments, both calls dispatch
...@@ -85,8 +85,8 @@ failed_decls: std.AutoArrayHashMapUnmanaged(*Decl, *ErrorMsg) = .{},...@@ -85,8 +85,8 @@ failed_decls: std.AutoArrayHashMapUnmanaged(*Decl, *ErrorMsg) = .{},
85/// The value is the AST node index offset from the Decl.85/// The value is the AST node index offset from the Decl.
86compile_log_decls: std.AutoArrayHashMapUnmanaged(*Decl, i32) = .{},86compile_log_decls: std.AutoArrayHashMapUnmanaged(*Decl, i32) = .{},
87/// Using a map here for consistency with the other fields here.87/// Using a map here for consistency with the other fields here.
88/// The ErrorMsg memory is owned by the `Scope.File`, using Module's general purpose allocator.88/// The ErrorMsg memory is owned by the `File`, using Module's general purpose allocator.
89failed_files: std.AutoArrayHashMapUnmanaged(*Scope.File, ?*ErrorMsg) = .{},89failed_files: std.AutoArrayHashMapUnmanaged(*File, ?*ErrorMsg) = .{},
90/// Using a map here for consistency with the other fields here.90/// Using a map here for consistency with the other fields here.
91/// The ErrorMsg memory is owned by the `Export`, using Module's general purpose allocator.91/// The ErrorMsg memory is owned by the `Export`, using Module's general purpose allocator.
92failed_exports: std.AutoArrayHashMapUnmanaged(*Export, *ErrorMsg) = .{},92failed_exports: std.AutoArrayHashMapUnmanaged(*Export, *ErrorMsg) = .{},
...@@ -350,7 +350,7 @@ pub const Decl = struct {...@@ -350,7 +350,7 @@ pub const Decl = struct {
350 /// Reference to externally owned memory.350 /// Reference to externally owned memory.
351 /// In the case of the Decl corresponding to a file, this is351 /// In the case of the Decl corresponding to a file, this is
352 /// the namespace of the struct, since there is no parent.352 /// the namespace of the struct, since there is no parent.
353 src_namespace: *Scope.Namespace,353 src_namespace: *Namespace,
354354
355 /// The scope which lexically contains this decl. A decl must depend355 /// The scope which lexically contains this decl. A decl must depend
356 /// on its lexical parent, in order to ensure that this pointer is valid.356 /// on its lexical parent, in order to ensure that this pointer is valid.
...@@ -690,7 +690,7 @@ pub const Decl = struct {...@@ -690,7 +690,7 @@ pub const Decl = struct {
690 /// Gets the namespace that this Decl creates by being a struct, union,690 /// Gets the namespace that this Decl creates by being a struct, union,
691 /// enum, or opaque.691 /// enum, or opaque.
692 /// Only returns it if the Decl is the owner.692 /// Only returns it if the Decl is the owner.
693 pub fn getInnerNamespace(decl: *Decl) ?*Scope.Namespace {693 pub fn getInnerNamespace(decl: *Decl) ?*Namespace {
694 if (!decl.owns_tv) return null;694 if (!decl.owns_tv) return null;
695 const ty = (decl.val.castTag(.ty) orelse return null).data;695 const ty = (decl.val.castTag(.ty) orelse return null).data;
696 switch (ty.tag()) {696 switch (ty.tag()) {
...@@ -735,7 +735,7 @@ pub const Decl = struct {...@@ -735,7 +735,7 @@ pub const Decl = struct {
735 std.debug.print("\n", .{});735 std.debug.print("\n", .{});
736 }736 }
737737
738 pub fn getFileScope(decl: Decl) *Scope.File {738 pub fn getFileScope(decl: Decl) *File {
739 return decl.src_namespace.file_scope;739 return decl.src_namespace.file_scope;
740 }740 }
741741
...@@ -787,7 +787,7 @@ pub const Struct = struct {...@@ -787,7 +787,7 @@ pub const Struct = struct {
787 /// Set of field names in declaration order.787 /// Set of field names in declaration order.
788 fields: std.StringArrayHashMapUnmanaged(Field),788 fields: std.StringArrayHashMapUnmanaged(Field),
789 /// Represents the declarations inside this struct.789 /// Represents the declarations inside this struct.
790 namespace: Scope.Namespace,790 namespace: Namespace,
791 /// Offset from `owner_decl`, points to the struct AST node.791 /// Offset from `owner_decl`, points to the struct AST node.
792 node_offset: i32,792 node_offset: i32,
793 /// Index of the struct_decl ZIR instruction.793 /// Index of the struct_decl ZIR instruction.
...@@ -909,7 +909,7 @@ pub const EnumFull = struct {...@@ -909,7 +909,7 @@ pub const EnumFull = struct {
909 /// If this hash map is empty, it means the enum tags are auto-numbered.909 /// If this hash map is empty, it means the enum tags are auto-numbered.
910 values: ValueMap,910 values: ValueMap,
911 /// Represents the declarations inside this enum.911 /// Represents the declarations inside this enum.
912 namespace: Scope.Namespace,912 namespace: Namespace,
913 /// Offset from `owner_decl`, points to the enum decl AST node.913 /// Offset from `owner_decl`, points to the enum decl AST node.
914 node_offset: i32,914 node_offset: i32,
915915
...@@ -937,7 +937,7 @@ pub const Union = struct {...@@ -937,7 +937,7 @@ pub const Union = struct {
937 /// Set of field names in declaration order.937 /// Set of field names in declaration order.
938 fields: std.StringArrayHashMapUnmanaged(Field),938 fields: std.StringArrayHashMapUnmanaged(Field),
939 /// Represents the declarations inside this union.939 /// Represents the declarations inside this union.
940 namespace: Scope.Namespace,940 namespace: Namespace,
941 /// Offset from `owner_decl`, points to the union decl AST node.941 /// Offset from `owner_decl`, points to the union decl AST node.
942 node_offset: i32,942 node_offset: i32,
943 /// Index of the union_decl ZIR instruction.943 /// Index of the union_decl ZIR instruction.
...@@ -1081,668 +1081,312 @@ pub const Var = struct {...@@ -1081,668 +1081,312 @@ pub const Var = struct {
1081 is_threadlocal: bool,1081 is_threadlocal: bool,
1082};1082};
10831083
1084pub const Scope = struct {1084/// The container that structs, enums, unions, and opaques have.
1085 tag: Tag,1085pub const Namespace = struct {
1086 parent: ?*Namespace,
1087 file_scope: *File,
1088 /// Will be a struct, enum, union, or opaque.
1089 ty: Type,
1090 /// Direct children of the namespace. Used during an update to detect
1091 /// which decls have been added/removed from source.
1092 /// Declaration order is preserved via entry order.
1093 /// Key memory is owned by `decl.name`.
1094 /// TODO save memory with https://github.com/ziglang/zig/issues/8619.
1095 /// Anonymous decls are not stored here; they are kept in `anon_decls` instead.
1096 decls: std.StringArrayHashMapUnmanaged(*Decl) = .{},
10861097
1087 pub fn cast(base: *Scope, comptime T: type) ?*T {1098 anon_decls: std.AutoArrayHashMapUnmanaged(*Decl, void) = .{},
1088 if (base.tag != T.base_tag)
1089 return null;
10901099
1091 return @fieldParentPtr(T, "base", base);1100 /// Key is usingnamespace Decl itself. To find the namespace being included,
1092 }1101 /// the Decl Value has to be resolved as a Type which has a Namespace.
1102 /// Value is whether the usingnamespace decl is marked `pub`.
1103 usingnamespace_set: std.AutoHashMapUnmanaged(*Decl, bool) = .{},
10931104
1094 /// Get the decl which contains this decl, for the purposes of source reporting1105 pub fn deinit(ns: *Namespace, mod: *Module) void {
1095 pub fn srcDecl(scope: *Scope) ?*Decl {1106 ns.destroyDecls(mod);
1096 return switch (scope.tag) {1107 ns.* = undefined;
1097 .block => scope.cast(Block).?.src_decl,
1098 .file => null,
1099 .namespace => scope.cast(Namespace).?.getDecl(),
1100 };
1101 }1108 }
11021109
1103 /// Get the scope which contains this decl, for resolving closure_get instructions.1110 pub fn destroyDecls(ns: *Namespace, mod: *Module) void {
1104 pub fn srcScope(scope: *Scope) ?*CaptureScope {1111 const gpa = mod.gpa;
1105 return switch (scope.tag) {
1106 .block => scope.cast(Block).?.wip_capture_scope,
1107 .file => null,
1108 .namespace => scope.cast(Namespace).?.getDecl().src_scope,
1109 };
1110 }
11111112
1112 /// Asserts the scope has a parent which is a Namespace and returns it.1113 log.debug("destroyDecls {*}", .{ns});
1113 pub fn namespace(scope: *Scope) *Namespace {
1114 switch (scope.tag) {
1115 .block => return scope.cast(Block).?.namespace,
1116 .file => return scope.cast(File).?.root_decl.?.src_namespace,
1117 .namespace => return scope.cast(Namespace).?,
1118 }
1119 }
11201114
1121 /// Asserts the scope has a parent which is a Namespace or File and1115 var decls = ns.decls;
1122 /// returns the sub_file_path field.1116 ns.decls = .{};
1123 pub fn subFilePath(base: *Scope) []const u8 {
1124 switch (base.tag) {
1125 .namespace => return @fieldParentPtr(Namespace, "base", base).file_scope.sub_file_path,
1126 .file => return @fieldParentPtr(File, "base", base).sub_file_path,
1127 .block => unreachable,
1128 }
1129 }
11301117
1131 /// When called from inside a Block Scope, chases the namespace, not the owner_decl.1118 var anon_decls = ns.anon_decls;
1132 pub fn getFileScope(base: *Scope) *Scope.File {1119 ns.anon_decls = .{};
1133 var cur = base;
1134 while (true) {
1135 cur = switch (cur.tag) {
1136 .namespace => return @fieldParentPtr(Namespace, "base", cur).file_scope,
1137 .file => return @fieldParentPtr(File, "base", cur),
1138 .block => return @fieldParentPtr(Block, "base", cur).namespace.file_scope,
1139 };
1140 }
1141 }
11421120
1143 pub const Tag = enum {1121 for (decls.values()) |value| {
1144 /// .zig source code.1122 value.destroy(mod);
1145 file,
1146 /// Namespace owned by structs, enums, unions, and opaques for decls.
1147 namespace,
1148 block,
1149 };
1150
1151 /// The container that structs, enums, unions, and opaques have.
1152 pub const Namespace = struct {
1153 pub const base_tag: Tag = .namespace;
1154 base: Scope = Scope{ .tag = base_tag },
1155
1156 parent: ?*Namespace,
1157 file_scope: *Scope.File,
1158 /// Will be a struct, enum, union, or opaque.
1159 ty: Type,
1160 /// Direct children of the namespace. Used during an update to detect
1161 /// which decls have been added/removed from source.
1162 /// Declaration order is preserved via entry order.
1163 /// Key memory is owned by `decl.name`.
1164 /// TODO save memory with https://github.com/ziglang/zig/issues/8619.
1165 /// Anonymous decls are not stored here; they are kept in `anon_decls` instead.
1166 decls: std.StringArrayHashMapUnmanaged(*Decl) = .{},
1167
1168 anon_decls: std.AutoArrayHashMapUnmanaged(*Decl, void) = .{},
1169
1170 /// Key is usingnamespace Decl itself. To find the namespace being included,
1171 /// the Decl Value has to be resolved as a Type which has a Namespace.
1172 /// Value is whether the usingnamespace decl is marked `pub`.
1173 usingnamespace_set: std.AutoHashMapUnmanaged(*Decl, bool) = .{},
1174
1175 pub fn deinit(ns: *Namespace, mod: *Module) void {
1176 ns.destroyDecls(mod);
1177 ns.* = undefined;
1178 }1123 }
1124 decls.deinit(gpa);
11791125
1180 pub fn destroyDecls(ns: *Namespace, mod: *Module) void {1126 for (anon_decls.keys()) |key| {
1181 const gpa = mod.gpa;1127 key.destroy(mod);
1182
1183 log.debug("destroyDecls {*}", .{ns});
1184
1185 var decls = ns.decls;
1186 ns.decls = .{};
1187
1188 var anon_decls = ns.anon_decls;
1189 ns.anon_decls = .{};
1190
1191 for (decls.values()) |value| {
1192 value.destroy(mod);
1193 }
1194 decls.deinit(gpa);
1195
1196 for (anon_decls.keys()) |key| {
1197 key.destroy(mod);
1198 }
1199 anon_decls.deinit(gpa);
1200 }1128 }
1129 anon_decls.deinit(gpa);
1130 }
12011131
1202 pub fn deleteAllDecls(1132 pub fn deleteAllDecls(
1203 ns: *Namespace,1133 ns: *Namespace,
1204 mod: *Module,1134 mod: *Module,
1205 outdated_decls: ?*std.AutoArrayHashMap(*Decl, void),1135 outdated_decls: ?*std.AutoArrayHashMap(*Decl, void),
1206 ) !void {1136 ) !void {
1207 const gpa = mod.gpa;1137 const gpa = mod.gpa;
1208
1209 log.debug("deleteAllDecls {*}", .{ns});
1210
1211 var decls = ns.decls;
1212 ns.decls = .{};
12131138
1214 var anon_decls = ns.anon_decls;1139 log.debug("deleteAllDecls {*}", .{ns});
1215 ns.anon_decls = .{};
12161140
1217 // TODO rework this code to not panic on OOM.1141 var decls = ns.decls;
1218 // (might want to coordinate with the clearDecl function)1142 ns.decls = .{};
12191143
1220 for (decls.values()) |child_decl| {1144 var anon_decls = ns.anon_decls;
1221 mod.clearDecl(child_decl, outdated_decls) catch @panic("out of memory");1145 ns.anon_decls = .{};
1222 child_decl.destroy(mod);
1223 }
1224 decls.deinit(gpa);
12251146
1226 for (anon_decls.keys()) |child_decl| {1147 // TODO rework this code to not panic on OOM.
1227 mod.clearDecl(child_decl, outdated_decls) catch @panic("out of memory");1148 // (might want to coordinate with the clearDecl function)
1228 child_decl.destroy(mod);
1229 }
1230 anon_decls.deinit(gpa);
1231 }
12321149
1233 // This renders e.g. "std.fs.Dir.OpenOptions"1150 for (decls.values()) |child_decl| {
1234 pub fn renderFullyQualifiedName(1151 mod.clearDecl(child_decl, outdated_decls) catch @panic("out of memory");
1235 ns: Namespace,1152 child_decl.destroy(mod);
1236 name: []const u8,
1237 writer: anytype,
1238 ) @TypeOf(writer).Error!void {
1239 if (ns.parent) |parent| {
1240 const decl = ns.getDecl();
1241 try parent.renderFullyQualifiedName(mem.spanZ(decl.name), writer);
1242 } else {
1243 try ns.file_scope.renderFullyQualifiedName(writer);
1244 }
1245 if (name.len != 0) {
1246 try writer.writeAll(".");
1247 try writer.writeAll(name);
1248 }
1249 }1153 }
1154 decls.deinit(gpa);
12501155
1251 /// This renders e.g. "std/fs.zig:Dir.OpenOptions"1156 for (anon_decls.keys()) |child_decl| {
1252 pub fn renderFullyQualifiedDebugName(1157 mod.clearDecl(child_decl, outdated_decls) catch @panic("out of memory");
1253 ns: Namespace,1158 child_decl.destroy(mod);
1254 name: []const u8,
1255 writer: anytype,
1256 ) @TypeOf(writer).Error!void {
1257 var separator_char: u8 = '.';
1258 if (ns.parent) |parent| {
1259 const decl = ns.getDecl();
1260 try parent.renderFullyQualifiedDebugName(mem.spanZ(decl.name), writer);
1261 } else {
1262 try ns.file_scope.renderFullyQualifiedDebugName(writer);
1263 separator_char = ':';
1264 }
1265 if (name.len != 0) {
1266 try writer.writeByte(separator_char);
1267 try writer.writeAll(name);
1268 }
1269 }1159 }
12701160 anon_decls.deinit(gpa);
1271 pub fn getDecl(ns: Namespace) *Decl {1161 }
1272 return ns.ty.getOwnerDecl();1162
1163 // This renders e.g. "std.fs.Dir.OpenOptions"
1164 pub fn renderFullyQualifiedName(
1165 ns: Namespace,
1166 name: []const u8,
1167 writer: anytype,
1168 ) @TypeOf(writer).Error!void {
1169 if (ns.parent) |parent| {
1170 const decl = ns.getDecl();
1171 try parent.renderFullyQualifiedName(mem.spanZ(decl.name), writer);
1172 } else {
1173 try ns.file_scope.renderFullyQualifiedName(writer);
1273 }1174 }
1274 };1175 if (name.len != 0) {
12751176 try writer.writeAll(".");
1276 pub const File = struct {1177 try writer.writeAll(name);
1277 pub const base_tag: Tag = .file;
1278 base: Scope = Scope{ .tag = base_tag },
1279 status: enum {
1280 never_loaded,
1281 retryable_failure,
1282 parse_failure,
1283 astgen_failure,
1284 success_zir,
1285 },
1286 source_loaded: bool,
1287 tree_loaded: bool,
1288 zir_loaded: bool,
1289 /// Relative to the owning package's root_src_dir.
1290 /// Memory is stored in gpa, owned by File.
1291 sub_file_path: []const u8,
1292 /// Whether this is populated depends on `source_loaded`.
1293 source: [:0]const u8,
1294 /// Whether this is populated depends on `status`.
1295 stat_size: u64,
1296 /// Whether this is populated depends on `status`.
1297 stat_inode: std.fs.File.INode,
1298 /// Whether this is populated depends on `status`.
1299 stat_mtime: i128,
1300 /// Whether this is populated or not depends on `tree_loaded`.
1301 tree: Ast,
1302 /// Whether this is populated or not depends on `zir_loaded`.
1303 zir: Zir,
1304 /// Package that this file is a part of, managed externally.
1305 pkg: *Package,
1306 /// The Decl of the struct that represents this File.
1307 root_decl: ?*Decl,
1308
1309 /// Used by change detection algorithm, after astgen, contains the
1310 /// set of decls that existed in the previous ZIR but not in the new one.
1311 deleted_decls: std.ArrayListUnmanaged(*Decl) = .{},
1312 /// Used by change detection algorithm, after astgen, contains the
1313 /// set of decls that existed both in the previous ZIR and in the new one,
1314 /// but their source code has been modified.
1315 outdated_decls: std.ArrayListUnmanaged(*Decl) = .{},
1316
1317 /// The most recent successful ZIR for this file, with no errors.
1318 /// This is only populated when a previously successful ZIR
1319 /// newly introduces compile errors during an update. When ZIR is
1320 /// successful, this field is unloaded.
1321 prev_zir: ?*Zir = null,
1322
1323 pub fn unload(file: *File, gpa: *Allocator) void {
1324 file.unloadTree(gpa);
1325 file.unloadSource(gpa);
1326 file.unloadZir(gpa);
1327 }1178 }
1179 }
13281180
1329 pub fn unloadTree(file: *File, gpa: *Allocator) void {1181 /// This renders e.g. "std/fs.zig:Dir.OpenOptions"
1330 if (file.tree_loaded) {1182 pub fn renderFullyQualifiedDebugName(
1331 file.tree_loaded = false;1183 ns: Namespace,
1332 file.tree.deinit(gpa);1184 name: []const u8,
1333 }1185 writer: anytype,
1186 ) @TypeOf(writer).Error!void {
1187 var separator_char: u8 = '.';
1188 if (ns.parent) |parent| {
1189 const decl = ns.getDecl();
1190 try parent.renderFullyQualifiedDebugName(mem.spanZ(decl.name), writer);
1191 } else {
1192 try ns.file_scope.renderFullyQualifiedDebugName(writer);
1193 separator_char = ':';
1334 }1194 }
13351195 if (name.len != 0) {
1336 pub fn unloadSource(file: *File, gpa: *Allocator) void {1196 try writer.writeByte(separator_char);
1337 if (file.source_loaded) {1197 try writer.writeAll(name);
1338 file.source_loaded = false;
1339 gpa.free(file.source);
1340 }
1341 }1198 }
1199 }
13421200
1343 pub fn unloadZir(file: *File, gpa: *Allocator) void {1201 pub fn getDecl(ns: Namespace) *Decl {
1344 if (file.zir_loaded) {1202 return ns.ty.getOwnerDecl();
1345 file.zir_loaded = false;1203 }
1346 file.zir.deinit(gpa);1204};
1347 }
1348 }
13491205
1350 pub fn deinit(file: *File, mod: *Module) void {1206pub const File = struct {
1351 const gpa = mod.gpa;1207 status: enum {
1352 log.debug("deinit File {s}", .{file.sub_file_path});1208 never_loaded,
1353 file.deleted_decls.deinit(gpa);1209 retryable_failure,
1354 file.outdated_decls.deinit(gpa);1210 parse_failure,
1355 if (file.root_decl) |root_decl| {1211 astgen_failure,
1356 root_decl.destroy(mod);1212 success_zir,
1357 }1213 },
1358 gpa.free(file.sub_file_path);1214 source_loaded: bool,
1359 file.unload(gpa);1215 tree_loaded: bool,
1360 if (file.prev_zir) |prev_zir| {1216 zir_loaded: bool,
1361 prev_zir.deinit(gpa);1217 /// Relative to the owning package's root_src_dir.
1362 gpa.destroy(prev_zir);1218 /// Memory is stored in gpa, owned by File.
1363 }1219 sub_file_path: []const u8,
1364 file.* = undefined;1220 /// Whether this is populated depends on `source_loaded`.
1221 source: [:0]const u8,
1222 /// Whether this is populated depends on `status`.
1223 stat_size: u64,
1224 /// Whether this is populated depends on `status`.
1225 stat_inode: std.fs.File.INode,
1226 /// Whether this is populated depends on `status`.
1227 stat_mtime: i128,
1228 /// Whether this is populated or not depends on `tree_loaded`.
1229 tree: Ast,
1230 /// Whether this is populated or not depends on `zir_loaded`.
1231 zir: Zir,
1232 /// Package that this file is a part of, managed externally.
1233 pkg: *Package,
1234 /// The Decl of the struct that represents this File.
1235 root_decl: ?*Decl,
1236
1237 /// Used by change detection algorithm, after astgen, contains the
1238 /// set of decls that existed in the previous ZIR but not in the new one.
1239 deleted_decls: std.ArrayListUnmanaged(*Decl) = .{},
1240 /// Used by change detection algorithm, after astgen, contains the
1241 /// set of decls that existed both in the previous ZIR and in the new one,
1242 /// but their source code has been modified.
1243 outdated_decls: std.ArrayListUnmanaged(*Decl) = .{},
1244
1245 /// The most recent successful ZIR for this file, with no errors.
1246 /// This is only populated when a previously successful ZIR
1247 /// newly introduces compile errors during an update. When ZIR is
1248 /// successful, this field is unloaded.
1249 prev_zir: ?*Zir = null,
1250
1251 pub fn unload(file: *File, gpa: *Allocator) void {
1252 file.unloadTree(gpa);
1253 file.unloadSource(gpa);
1254 file.unloadZir(gpa);
1255 }
1256
1257 pub fn unloadTree(file: *File, gpa: *Allocator) void {
1258 if (file.tree_loaded) {
1259 file.tree_loaded = false;
1260 file.tree.deinit(gpa);
1365 }1261 }
1262 }
13661263
1367 pub fn getSource(file: *File, gpa: *Allocator) ![:0]const u8 {1264 pub fn unloadSource(file: *File, gpa: *Allocator) void {
1368 if (file.source_loaded) return file.source;1265 if (file.source_loaded) {
13691266 file.source_loaded = false;
1370 const root_dir_path = file.pkg.root_src_directory.path orelse ".";1267 gpa.free(file.source);
1371 log.debug("File.getSource, not cached. pkgdir={s} sub_file_path={s}", .{
1372 root_dir_path, file.sub_file_path,
1373 });
1374
1375 // Keep track of inode, file size, mtime, hash so we can detect which files
1376 // have been modified when an incremental update is requested.
1377 var f = try file.pkg.root_src_directory.handle.openFile(file.sub_file_path, .{});
1378 defer f.close();
1379
1380 const stat = try f.stat();
1381
1382 if (stat.size > std.math.maxInt(u32))
1383 return error.FileTooBig;
1384
1385 const source = try gpa.allocSentinel(u8, @intCast(usize, stat.size), 0);
1386 defer if (!file.source_loaded) gpa.free(source);
1387 const amt = try f.readAll(source);
1388 if (amt != stat.size)
1389 return error.UnexpectedEndOfFile;
1390
1391 // Here we do not modify stat fields because this function is the one
1392 // used for error reporting. We need to keep the stat fields stale so that
1393 // astGenFile can know to regenerate ZIR.
1394
1395 file.source = source;
1396 file.source_loaded = true;
1397 return source;
1398 }1268 }
1269 }
13991270
1400 pub fn getTree(file: *File, gpa: *Allocator) !*const Ast {1271 pub fn unloadZir(file: *File, gpa: *Allocator) void {
1401 if (file.tree_loaded) return &file.tree;1272 if (file.zir_loaded) {
14021273 file.zir_loaded = false;
1403 const source = try file.getSource(gpa);1274 file.zir.deinit(gpa);
1404 file.tree = try std.zig.parse(gpa, source);
1405 file.tree_loaded = true;
1406 return &file.tree;
1407 }1275 }
1276 }
14081277
1409 pub fn destroy(file: *File, mod: *Module) void {1278 pub fn deinit(file: *File, mod: *Module) void {
1410 const gpa = mod.gpa;1279 const gpa = mod.gpa;
1411 file.deinit(mod);1280 log.debug("deinit File {s}", .{file.sub_file_path});
1412 gpa.destroy(file);1281 file.deleted_decls.deinit(gpa);
1282 file.outdated_decls.deinit(gpa);
1283 if (file.root_decl) |root_decl| {
1284 root_decl.destroy(mod);
1413 }1285 }
14141286 gpa.free(file.sub_file_path);
1415 pub fn renderFullyQualifiedName(file: File, writer: anytype) !void {1287 file.unload(gpa);
1416 // Convert all the slashes into dots and truncate the extension.1288 if (file.prev_zir) |prev_zir| {
1417 const ext = std.fs.path.extension(file.sub_file_path);1289 prev_zir.deinit(gpa);
1418 const noext = file.sub_file_path[0 .. file.sub_file_path.len - ext.len];1290 gpa.destroy(prev_zir);
1419 for (noext) |byte| switch (byte) {
1420 '/', '\\' => try writer.writeByte('.'),
1421 else => try writer.writeByte(byte),
1422 };
1423 }1291 }
1292 file.* = undefined;
1293 }
14241294
1425 pub fn renderFullyQualifiedDebugName(file: File, writer: anytype) !void {1295 pub fn getSource(file: *File, gpa: *Allocator) ![:0]const u8 {
1426 for (file.sub_file_path) |byte| switch (byte) {1296 if (file.source_loaded) return file.source;
1427 '/', '\\' => try writer.writeByte('/'),
1428 else => try writer.writeByte(byte),
1429 };
1430 }
14311297
1432 pub fn fullyQualifiedNameZ(file: File, gpa: *Allocator) ![:0]u8 {1298 const root_dir_path = file.pkg.root_src_directory.path orelse ".";
1433 var buf = std.ArrayList(u8).init(gpa);1299 log.debug("File.getSource, not cached. pkgdir={s} sub_file_path={s}", .{
1434 defer buf.deinit();1300 root_dir_path, file.sub_file_path,
1435 try file.renderFullyQualifiedName(buf.writer());1301 });
1436 return buf.toOwnedSliceSentinel(0);
1437 }
14381302
1439 /// Returns the full path to this file relative to its package.1303 // Keep track of inode, file size, mtime, hash so we can detect which files
1440 pub fn fullPath(file: File, ally: *Allocator) ![]u8 {1304 // have been modified when an incremental update is requested.
1441 return file.pkg.root_src_directory.join(ally, &[_][]const u8{file.sub_file_path});1305 var f = try file.pkg.root_src_directory.handle.openFile(file.sub_file_path, .{});
1442 }1306 defer f.close();
14431307
1444 pub fn dumpSrc(file: *File, src: LazySrcLoc) void {1308 const stat = try f.stat();
1445 const loc = std.zig.findLineColumn(file.source.bytes, src);
1446 std.debug.print("{s}:{d}:{d}\n", .{ file.sub_file_path, loc.line + 1, loc.column + 1 });
1447 }
14481309
1449 pub fn okToReportErrors(file: File) bool {1310 if (stat.size > std.math.maxInt(u32))
1450 return switch (file.status) {1311 return error.FileTooBig;
1451 .parse_failure, .astgen_failure => false,
1452 else => true,
1453 };
1454 }
1455 };
14561312
1457 /// This is the context needed to semantically analyze ZIR instructions and1313 const source = try gpa.allocSentinel(u8, @intCast(usize, stat.size), 0);
1458 /// produce AIR instructions.1314 defer if (!file.source_loaded) gpa.free(source);
1459 /// This is a temporary structure stored on the stack; references to it are valid only1315 const amt = try f.readAll(source);
1460 /// during semantic analysis of the block.1316 if (amt != stat.size)
1461 pub const Block = struct {1317 return error.UnexpectedEndOfFile;
1462 pub const base_tag: Tag = .block;
1463
1464 base: Scope = Scope{ .tag = base_tag },
1465 parent: ?*Block,
1466 /// Shared among all child blocks.
1467 sema: *Sema,
1468 /// This Decl is the Decl according to the Zig source code corresponding to this Block.
1469 /// This can vary during inline or comptime function calls. See `Sema.owner_decl`
1470 /// for the one that will be the same for all Block instances.
1471 src_decl: *Decl,
1472 /// The namespace to use for lookups from this source block
1473 /// When analyzing fields, this is different from src_decl.src_namepsace.
1474 namespace: *Namespace,
1475 /// The AIR instructions generated for this block.
1476 instructions: ArrayListUnmanaged(Air.Inst.Index),
1477 // `param` instructions are collected here to be used by the `func` instruction.
1478 params: std.ArrayListUnmanaged(Param) = .{},
1479
1480 wip_capture_scope: *CaptureScope,
1481
1482 label: ?*Label = null,
1483 inlining: ?*Inlining,
1484 /// If runtime_index is not 0 then one of these is guaranteed to be non null.
1485 runtime_cond: ?LazySrcLoc = null,
1486 runtime_loop: ?LazySrcLoc = null,
1487 /// Non zero if a non-inline loop or a runtime conditional have been encountered.
1488 /// Stores to to comptime variables are only allowed when var.runtime_index <= runtime_index.
1489 runtime_index: u32 = 0,
14901318
1491 is_comptime: bool,1319 // Here we do not modify stat fields because this function is the one
1320 // used for error reporting. We need to keep the stat fields stale so that
1321 // astGenFile can know to regenerate ZIR.
14921322
1493 /// when null, it is determined by build mode, changed by @setRuntimeSafety1323 file.source = source;
1494 want_safety: ?bool = null,1324 file.source_loaded = true;
1325 return source;
1326 }
14951327
1496 c_import_buf: ?*std.ArrayList(u8) = null,1328 pub fn getTree(file: *File, gpa: *Allocator) !*const Ast {
1329 if (file.tree_loaded) return &file.tree;
14971330
1498 const Param = struct {1331 const source = try file.getSource(gpa);
1499 /// `noreturn` means `anytype`.1332 file.tree = try std.zig.parse(gpa, source);
1500 ty: Type,1333 file.tree_loaded = true;
1501 is_comptime: bool,1334 return &file.tree;
1502 };1335 }
15031336
1504 /// This `Block` maps a block ZIR instruction to the corresponding1337 pub fn destroy(file: *File, mod: *Module) void {
1505 /// AIR instruction for break instruction analysis.1338 const gpa = mod.gpa;
1506 pub const Label = struct {1339 file.deinit(mod);
1507 zir_block: Zir.Inst.Index,1340 gpa.destroy(file);
1508 merges: Merges,1341 }
1509 };
15101342
1511 /// This `Block` indicates that an inline function call is happening1343 pub fn renderFullyQualifiedName(file: File, writer: anytype) !void {
1512 /// and return instructions should be analyzed as a break instruction1344 // Convert all the slashes into dots and truncate the extension.
1513 /// to this AIR block instruction.1345 const ext = std.fs.path.extension(file.sub_file_path);
1514 /// It is shared among all the blocks in an inline or comptime called1346 const noext = file.sub_file_path[0 .. file.sub_file_path.len - ext.len];
1515 /// function.1347 for (noext) |byte| switch (byte) {
1516 pub const Inlining = struct {1348 '/', '\\' => try writer.writeByte('.'),
1517 comptime_result: Air.Inst.Ref,1349 else => try writer.writeByte(byte),
1518 merges: Merges,
1519 };1350 };
1351 }
15201352
1521 pub const Merges = struct {1353 pub fn renderFullyQualifiedDebugName(file: File, writer: anytype) !void {
1522 block_inst: Air.Inst.Index,1354 for (file.sub_file_path) |byte| switch (byte) {
1523 /// Separate array list from break_inst_list so that it can be passed directly1355 '/', '\\' => try writer.writeByte('/'),
1524 /// to resolvePeerTypes.1356 else => try writer.writeByte(byte),
1525 results: ArrayListUnmanaged(Air.Inst.Ref),
1526 /// Keeps track of the break instructions so that the operand can be replaced
1527 /// if we need to add type coercion at the end of block analysis.
1528 /// Same indexes, capacity, length as `results`.
1529 br_list: ArrayListUnmanaged(Air.Inst.Index),
1530 };1357 };
1358 }
15311359
1532 /// For debugging purposes.1360 pub fn fullyQualifiedNameZ(file: File, gpa: *Allocator) ![:0]u8 {
1533 pub fn dump(block: *Block, mod: Module) void {1361 var buf = std.ArrayList(u8).init(gpa);
1534 Zir.dumpBlock(mod, block);1362 defer buf.deinit();
1535 }1363 try file.renderFullyQualifiedName(buf.writer());
15361364 return buf.toOwnedSliceSentinel(0);
1537 pub fn makeSubBlock(parent: *Block) Block {1365 }
1538 return .{
1539 .parent = parent,
1540 .sema = parent.sema,
1541 .src_decl = parent.src_decl,
1542 .namespace = parent.namespace,
1543 .instructions = .{},
1544 .wip_capture_scope = parent.wip_capture_scope,
1545 .label = null,
1546 .inlining = parent.inlining,
1547 .is_comptime = parent.is_comptime,
1548 .runtime_cond = parent.runtime_cond,
1549 .runtime_loop = parent.runtime_loop,
1550 .runtime_index = parent.runtime_index,
1551 .want_safety = parent.want_safety,
1552 .c_import_buf = parent.c_import_buf,
1553 };
1554 }
1555
1556 pub fn wantSafety(block: *const Block) bool {
1557 return block.want_safety orelse switch (block.sema.mod.optimizeMode()) {
1558 .Debug => true,
1559 .ReleaseSafe => true,
1560 .ReleaseFast => false,
1561 .ReleaseSmall => false,
1562 };
1563 }
1564
1565 pub fn getFileScope(block: *Block) *Scope.File {
1566 return block.namespace.file_scope;
1567 }
1568
1569 pub fn addTy(
1570 block: *Block,
1571 tag: Air.Inst.Tag,
1572 ty: Type,
1573 ) error{OutOfMemory}!Air.Inst.Ref {
1574 return block.addInst(.{
1575 .tag = tag,
1576 .data = .{ .ty = ty },
1577 });
1578 }
1579
1580 pub fn addTyOp(
1581 block: *Block,
1582 tag: Air.Inst.Tag,
1583 ty: Type,
1584 operand: Air.Inst.Ref,
1585 ) error{OutOfMemory}!Air.Inst.Ref {
1586 return block.addInst(.{
1587 .tag = tag,
1588 .data = .{ .ty_op = .{
1589 .ty = try block.sema.addType(ty),
1590 .operand = operand,
1591 } },
1592 });
1593 }
1594
1595 pub fn addNoOp(block: *Block, tag: Air.Inst.Tag) error{OutOfMemory}!Air.Inst.Ref {
1596 return block.addInst(.{
1597 .tag = tag,
1598 .data = .{ .no_op = {} },
1599 });
1600 }
1601
1602 pub fn addUnOp(
1603 block: *Block,
1604 tag: Air.Inst.Tag,
1605 operand: Air.Inst.Ref,
1606 ) error{OutOfMemory}!Air.Inst.Ref {
1607 return block.addInst(.{
1608 .tag = tag,
1609 .data = .{ .un_op = operand },
1610 });
1611 }
1612
1613 pub fn addBr(
1614 block: *Block,
1615 target_block: Air.Inst.Index,
1616 operand: Air.Inst.Ref,
1617 ) error{OutOfMemory}!Air.Inst.Ref {
1618 return block.addInst(.{
1619 .tag = .br,
1620 .data = .{ .br = .{
1621 .block_inst = target_block,
1622 .operand = operand,
1623 } },
1624 });
1625 }
1626
1627 pub fn addBinOp(
1628 block: *Block,
1629 tag: Air.Inst.Tag,
1630 lhs: Air.Inst.Ref,
1631 rhs: Air.Inst.Ref,
1632 ) error{OutOfMemory}!Air.Inst.Ref {
1633 return block.addInst(.{
1634 .tag = tag,
1635 .data = .{ .bin_op = .{
1636 .lhs = lhs,
1637 .rhs = rhs,
1638 } },
1639 });
1640 }
1641
1642 pub fn addArg(block: *Block, ty: Type, name: u32) error{OutOfMemory}!Air.Inst.Ref {
1643 return block.addInst(.{
1644 .tag = .arg,
1645 .data = .{ .ty_str = .{
1646 .ty = try block.sema.addType(ty),
1647 .str = name,
1648 } },
1649 });
1650 }
1651
1652 pub fn addStructFieldPtr(
1653 block: *Block,
1654 struct_ptr: Air.Inst.Ref,
1655 field_index: u32,
1656 ptr_field_ty: Type,
1657 ) !Air.Inst.Ref {
1658 const ty = try block.sema.addType(ptr_field_ty);
1659 const tag: Air.Inst.Tag = switch (field_index) {
1660 0 => .struct_field_ptr_index_0,
1661 1 => .struct_field_ptr_index_1,
1662 2 => .struct_field_ptr_index_2,
1663 3 => .struct_field_ptr_index_3,
1664 else => {
1665 return block.addInst(.{
1666 .tag = .struct_field_ptr,
1667 .data = .{ .ty_pl = .{
1668 .ty = ty,
1669 .payload = try block.sema.addExtra(Air.StructField{
1670 .struct_operand = struct_ptr,
1671 .field_index = @intCast(u32, field_index),
1672 }),
1673 } },
1674 });
1675 },
1676 };
1677 return block.addInst(.{
1678 .tag = tag,
1679 .data = .{ .ty_op = .{
1680 .ty = ty,
1681 .operand = struct_ptr,
1682 } },
1683 });
1684 }
1685
1686 pub fn addInst(block: *Block, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Ref {
1687 return Air.indexToRef(try block.addInstAsIndex(inst));
1688 }
1689
1690 pub fn addInstAsIndex(block: *Block, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Index {
1691 const sema = block.sema;
1692 const gpa = sema.gpa;
1693
1694 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
1695 try block.instructions.ensureUnusedCapacity(gpa, 1);
1696
1697 const result_index = @intCast(Air.Inst.Index, sema.air_instructions.len);
1698 sema.air_instructions.appendAssumeCapacity(inst);
1699 block.instructions.appendAssumeCapacity(result_index);
1700 return result_index;
1701 }
1702
1703 pub fn startAnonDecl(block: *Block) !WipAnonDecl {
1704 return WipAnonDecl{
1705 .block = block,
1706 .new_decl_arena = std.heap.ArenaAllocator.init(block.sema.gpa),
1707 .finished = false,
1708 };
1709 }
1710
1711 pub const WipAnonDecl = struct {
1712 block: *Scope.Block,
1713 new_decl_arena: std.heap.ArenaAllocator,
1714 finished: bool,
17151366
1716 pub fn arena(wad: *WipAnonDecl) *Allocator {1367 /// Returns the full path to this file relative to its package.
1717 return &wad.new_decl_arena.allocator;1368 pub fn fullPath(file: File, ally: *Allocator) ![]u8 {
1718 }1369 return file.pkg.root_src_directory.join(ally, &[_][]const u8{file.sub_file_path});
1370 }
17191371
1720 pub fn deinit(wad: *WipAnonDecl) void {1372 pub fn dumpSrc(file: *File, src: LazySrcLoc) void {
1721 if (!wad.finished) {1373 const loc = std.zig.findLineColumn(file.source.bytes, src);
1722 wad.new_decl_arena.deinit();1374 std.debug.print("{s}:{d}:{d}\n", .{ file.sub_file_path, loc.line + 1, loc.column + 1 });
1723 }1375 }
1724 wad.* = undefined;
1725 }
17261376
1727 pub fn finish(wad: *WipAnonDecl, ty: Type, val: Value) !*Decl {1377 pub fn okToReportErrors(file: File) bool {
1728 const new_decl = try wad.block.sema.mod.createAnonymousDecl(&wad.block.base, .{1378 return switch (file.status) {
1729 .ty = ty,1379 .parse_failure, .astgen_failure => false,
1730 .val = val,1380 else => true,
1731 });
1732 errdefer wad.block.sema.mod.abortAnonDecl(new_decl);
1733 try new_decl.finalizeNewArena(&wad.new_decl_arena);
1734 wad.finished = true;
1735 return new_decl;
1736 }
1737 };1381 };
1738 };1382 }
1739};1383};
17401384
1741/// This struct holds data necessary to construct API-facing `AllErrors.Message`.1385/// This struct holds data necessary to construct API-facing `AllErrors.Message`.
1742/// Its memory is managed with the general purpose allocator so that they1386/// Its memory is managed with the general purpose allocator so that they
1743/// can be created and destroyed in response to incremental updates.1387/// can be created and destroyed in response to incremental updates.
1744/// In some cases, the Scope.File could have been inferred from where the ErrorMsg1388/// In some cases, the File could have been inferred from where the ErrorMsg
1745/// is stored. For example, if it is stored in Module.failed_decls, then the Scope.File1389/// is stored. For example, if it is stored in Module.failed_decls, then the File
1746/// would be determined by the Decl Scope. However, the data structure contains the field1390/// would be determined by the Decl Scope. However, the data structure contains the field
1747/// anyway so that `ErrorMsg` can be reused for error notes, which may be in a different1391/// anyway so that `ErrorMsg` can be reused for error notes, which may be in a different
1748/// file than the parent error message. It also simplifies processing of error messages.1392/// file than the parent error message. It also simplifies processing of error messages.
...@@ -1794,7 +1438,7 @@ pub const ErrorMsg = struct {...@@ -1794,7 +1438,7 @@ pub const ErrorMsg = struct {
17941438
1795/// Canonical reference to a position within a source file.1439/// Canonical reference to a position within a source file.
1796pub const SrcLoc = struct {1440pub const SrcLoc = struct {
1797 file_scope: *Scope.File,1441 file_scope: *File,
1798 /// Might be 0 depending on tag of `lazy`.1442 /// Might be 0 depending on tag of `lazy`.
1799 parent_decl_node: Ast.Node.Index,1443 parent_decl_node: Ast.Node.Index,
1800 /// Relative to `parent_decl_node`.1444 /// Relative to `parent_decl_node`.
...@@ -2371,60 +2015,8 @@ pub const LazySrcLoc = union(enum) {...@@ -2371,60 +2015,8 @@ pub const LazySrcLoc = union(enum) {
2371 /// The Decl is determined contextually.2015 /// The Decl is determined contextually.
2372 node_offset_lib_name: i32,2016 node_offset_lib_name: i32,
23732017
2374 /// Upgrade to a `SrcLoc` based on the `Decl` or file in the provided scope.
2375 pub fn toSrcLoc(lazy: LazySrcLoc, block: *Scope.Block) SrcLoc {
2376 return switch (lazy) {
2377 .unneeded,
2378 .entire_file,
2379 .byte_abs,
2380 .token_abs,
2381 .node_abs,
2382 => .{
2383 .file_scope = block.getFileScope(),
2384 .parent_decl_node = 0,
2385 .lazy = lazy,
2386 },
2387
2388 .byte_offset,
2389 .token_offset,
2390 .node_offset,
2391 .node_offset_back2tok,
2392 .node_offset_var_decl_ty,
2393 .node_offset_for_cond,
2394 .node_offset_builtin_call_arg0,
2395 .node_offset_builtin_call_arg1,
2396 .node_offset_builtin_call_arg2,
2397 .node_offset_builtin_call_arg3,
2398 .node_offset_builtin_call_arg4,
2399 .node_offset_builtin_call_arg5,
2400 .node_offset_array_access_index,
2401 .node_offset_slice_sentinel,
2402 .node_offset_call_func,
2403 .node_offset_field_name,
2404 .node_offset_deref_ptr,
2405 .node_offset_asm_source,
2406 .node_offset_asm_ret_ty,
2407 .node_offset_if_cond,
2408 .node_offset_bin_op,
2409 .node_offset_bin_lhs,
2410 .node_offset_bin_rhs,
2411 .node_offset_switch_operand,
2412 .node_offset_switch_special_prong,
2413 .node_offset_switch_range,
2414 .node_offset_fn_type_cc,
2415 .node_offset_fn_type_ret_ty,
2416 .node_offset_anyframe_type,
2417 .node_offset_lib_name,
2418 => .{
2419 .file_scope = block.getFileScope(),
2420 .parent_decl_node = block.src_decl.src_node,
2421 .lazy = lazy,
2422 },
2423 };
2424 }
2425
2426 /// Upgrade to a `SrcLoc` based on the `Decl` provided.2018 /// Upgrade to a `SrcLoc` based on the `Decl` provided.
2427 pub fn toSrcLocWithDecl(lazy: LazySrcLoc, decl: *Decl) SrcLoc {2019 pub fn toSrcLoc(lazy: LazySrcLoc, decl: *Decl) SrcLoc {
2428 return switch (lazy) {2020 return switch (lazy) {
2429 .unneeded,2021 .unneeded,
2430 .entire_file,2022 .entire_file,
...@@ -2613,7 +2205,7 @@ comptime {...@@ -2613,7 +2205,7 @@ comptime {
2613 }2205 }
2614}2206}
26152207
2616pub fn astGenFile(mod: *Module, file: *Scope.File) !void {2208pub fn astGenFile(mod: *Module, file: *File) !void {
2617 const tracy = trace(@src());2209 const tracy = trace(@src());
2618 defer tracy.end();2210 defer tracy.end();
26192211
...@@ -2997,7 +2589,7 @@ pub fn astGenFile(mod: *Module, file: *Scope.File) !void {...@@ -2997,7 +2589,7 @@ pub fn astGenFile(mod: *Module, file: *Scope.File) !void {
2997/// * Decl.zir_index2589/// * Decl.zir_index
2998/// * Fn.zir_body_inst2590/// * Fn.zir_body_inst
2999/// * Decl.zir_decl_index2591/// * Decl.zir_decl_index
3000fn updateZirRefs(gpa: *Allocator, file: *Scope.File, old_zir: Zir) !void {2592fn updateZirRefs(gpa: *Allocator, file: *File, old_zir: Zir) !void {
3001 const new_zir = file.zir;2593 const new_zir = file.zir;
30022594
3003 // Maps from old ZIR to new ZIR, struct_decl, enum_decl, etc. Any instruction which2595 // Maps from old ZIR to new ZIR, struct_decl, enum_decl, etc. Any instruction which
...@@ -3253,7 +2845,7 @@ pub fn semaPkg(mod: *Module, pkg: *Package) !void {...@@ -3253,7 +2845,7 @@ pub fn semaPkg(mod: *Module, pkg: *Package) !void {
32532845
3254/// Regardless of the file status, will create a `Decl` so that we2846/// Regardless of the file status, will create a `Decl` so that we
3255/// can track dependencies and re-analyze when the file becomes outdated.2847/// can track dependencies and re-analyze when the file becomes outdated.
3256pub fn semaFile(mod: *Module, file: *Scope.File) SemaError!void {2848pub fn semaFile(mod: *Module, file: *File) SemaError!void {
3257 const tracy = trace(@src());2849 const tracy = trace(@src());
3258 defer tracy.end();2850 defer tracy.end();
32592851
...@@ -3322,7 +2914,7 @@ pub fn semaFile(mod: *Module, file: *Scope.File) SemaError!void {...@@ -3322,7 +2914,7 @@ pub fn semaFile(mod: *Module, file: *Scope.File) SemaError!void {
3322 var wip_captures = try WipCaptureScope.init(gpa, &new_decl_arena.allocator, null);2914 var wip_captures = try WipCaptureScope.init(gpa, &new_decl_arena.allocator, null);
3323 defer wip_captures.deinit();2915 defer wip_captures.deinit();
33242916
3325 var block_scope: Scope.Block = .{2917 var block_scope: Sema.Block = .{
3326 .parent = null,2918 .parent = null,
3327 .sema = &sema,2919 .sema = &sema,
3328 .src_decl = new_decl,2920 .src_decl = new_decl,
...@@ -3402,7 +2994,7 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {...@@ -3402,7 +2994,7 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {
3402 var wip_captures = try WipCaptureScope.init(gpa, &decl_arena.allocator, decl.src_scope);2994 var wip_captures = try WipCaptureScope.init(gpa, &decl_arena.allocator, decl.src_scope);
3403 defer wip_captures.deinit();2995 defer wip_captures.deinit();
34042996
3405 var block_scope: Scope.Block = .{2997 var block_scope: Sema.Block = .{
3406 .parent = null,2998 .parent = null,
3407 .sema = &sema,2999 .sema = &sema,
3408 .src_decl = decl,3000 .src_decl = decl,
...@@ -3617,7 +3209,7 @@ pub fn declareDeclDependency(mod: *Module, depender: *Decl, dependee: *Decl) !vo...@@ -3617,7 +3209,7 @@ pub fn declareDeclDependency(mod: *Module, depender: *Decl, dependee: *Decl) !vo
3617}3209}
36183210
3619pub const ImportFileResult = struct {3211pub const ImportFileResult = struct {
3620 file: *Scope.File,3212 file: *File,
3621 is_new: bool,3213 is_new: bool,
3622};3214};
36233215
...@@ -3643,7 +3235,7 @@ pub fn importPkg(mod: *Module, pkg: *Package) !ImportFileResult {...@@ -3643,7 +3235,7 @@ pub fn importPkg(mod: *Module, pkg: *Package) !ImportFileResult {
3643 const sub_file_path = try gpa.dupe(u8, pkg.root_src_path);3235 const sub_file_path = try gpa.dupe(u8, pkg.root_src_path);
3644 errdefer gpa.free(sub_file_path);3236 errdefer gpa.free(sub_file_path);
36453237
3646 const new_file = try gpa.create(Scope.File);3238 const new_file = try gpa.create(File);
3647 errdefer gpa.destroy(new_file);3239 errdefer gpa.destroy(new_file);
36483240
3649 gop.value_ptr.* = new_file;3241 gop.value_ptr.* = new_file;
...@@ -3670,7 +3262,7 @@ pub fn importPkg(mod: *Module, pkg: *Package) !ImportFileResult {...@@ -3670,7 +3262,7 @@ pub fn importPkg(mod: *Module, pkg: *Package) !ImportFileResult {
36703262
3671pub fn importFile(3263pub fn importFile(
3672 mod: *Module,3264 mod: *Module,
3673 cur_file: *Scope.File,3265 cur_file: *File,
3674 import_string: []const u8,3266 import_string: []const u8,
3675) !ImportFileResult {3267) !ImportFileResult {
3676 if (cur_file.pkg.table.get(import_string)) |pkg| {3268 if (cur_file.pkg.table.get(import_string)) |pkg| {
...@@ -3698,7 +3290,7 @@ pub fn importFile(...@@ -3698,7 +3290,7 @@ pub fn importFile(
3698 };3290 };
3699 keep_resolved_path = true; // It's now owned by import_table.3291 keep_resolved_path = true; // It's now owned by import_table.
37003292
3701 const new_file = try gpa.create(Scope.File);3293 const new_file = try gpa.create(File);
3702 errdefer gpa.destroy(new_file);3294 errdefer gpa.destroy(new_file);
37033295
3704 const resolved_root_path = try std.fs.path.resolve(gpa, &[_][]const u8{cur_pkg_dir_path});3296 const resolved_root_path = try std.fs.path.resolve(gpa, &[_][]const u8{cur_pkg_dir_path});
...@@ -3739,7 +3331,7 @@ pub fn importFile(...@@ -3739,7 +3331,7 @@ pub fn importFile(
37393331
3740pub fn scanNamespace(3332pub fn scanNamespace(
3741 mod: *Module,3333 mod: *Module,
3742 namespace: *Scope.Namespace,3334 namespace: *Namespace,
3743 extra_start: usize,3335 extra_start: usize,
3744 decls_len: u32,3336 decls_len: u32,
3745 parent_decl: *Decl,3337 parent_decl: *Decl,
...@@ -3783,7 +3375,7 @@ pub fn scanNamespace(...@@ -3783,7 +3375,7 @@ pub fn scanNamespace(
37833375
3784const ScanDeclIter = struct {3376const ScanDeclIter = struct {
3785 module: *Module,3377 module: *Module,
3786 namespace: *Scope.Namespace,3378 namespace: *Namespace,
3787 parent_decl: *Decl,3379 parent_decl: *Decl,
3788 usingnamespace_index: usize = 0,3380 usingnamespace_index: usize = 0,
3789 comptime_index: usize = 0,3381 comptime_index: usize = 0,
...@@ -4146,7 +3738,7 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn, arena: *Allocator) Se...@@ -4146,7 +3738,7 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn, arena: *Allocator) Se
4146 var wip_captures = try WipCaptureScope.init(gpa, &decl_arena.allocator, decl.src_scope);3738 var wip_captures = try WipCaptureScope.init(gpa, &decl_arena.allocator, decl.src_scope);
4147 defer wip_captures.deinit();3739 defer wip_captures.deinit();
41483740
4149 var inner_block: Scope.Block = .{3741 var inner_block: Sema.Block = .{
4150 .parent = null,3742 .parent = null,
4151 .sema = &sema,3743 .sema = &sema,
4152 .src_decl = decl,3744 .src_decl = decl,
...@@ -4269,7 +3861,7 @@ fn markOutdatedDecl(mod: *Module, decl: *Decl) !void {...@@ -4269,7 +3861,7 @@ fn markOutdatedDecl(mod: *Module, decl: *Decl) !void {
4269 decl.analysis = .outdated;3861 decl.analysis = .outdated;
4270}3862}
42713863
4272pub fn allocateNewDecl(mod: *Module, name: [:0]const u8, namespace: *Scope.Namespace, src_node: Ast.Node.Index, src_scope: ?*CaptureScope) !*Decl {3864pub fn allocateNewDecl(mod: *Module, name: [:0]const u8, namespace: *Namespace, src_node: Ast.Node.Index, src_scope: ?*CaptureScope) !*Decl {
4273 // If we have emit-h then we must allocate a bigger structure to store the emit-h state.3865 // If we have emit-h then we must allocate a bigger structure to store the emit-h state.
4274 const new_decl: *Decl = if (mod.emit_h != null) blk: {3866 const new_decl: *Decl = if (mod.emit_h != null) blk: {
4275 const parent_struct = try mod.gpa.create(DeclPlusEmitH);3867 const parent_struct = try mod.gpa.create(DeclPlusEmitH);
...@@ -4350,21 +3942,21 @@ pub fn getErrorValue(mod: *Module, name: []const u8) !std.StringHashMapUnmanaged...@@ -4350,21 +3942,21 @@ pub fn getErrorValue(mod: *Module, name: []const u8) !std.StringHashMapUnmanaged
4350/// Takes ownership of `name` even if it returns an error.3942/// Takes ownership of `name` even if it returns an error.
4351pub fn createAnonymousDeclNamed(3943pub fn createAnonymousDeclNamed(
4352 mod: *Module,3944 mod: *Module,
4353 scope: *Scope,3945 block: *Sema.Block,
4354 typed_value: TypedValue,3946 typed_value: TypedValue,
4355 name: [:0]u8,3947 name: [:0]u8,
4356) !*Decl {3948) !*Decl {
4357 return mod.createAnonymousDeclFromDeclNamed(scope.srcDecl().?, scope.namespace(), scope.srcScope(), typed_value, name);3949 return mod.createAnonymousDeclFromDeclNamed(block.src_decl, block.namespace, block.wip_capture_scope, typed_value, name);
4358}3950}
43593951
4360pub fn createAnonymousDecl(mod: *Module, scope: *Scope, typed_value: TypedValue) !*Decl {3952pub fn createAnonymousDecl(mod: *Module, block: *Sema.Block, typed_value: TypedValue) !*Decl {
4361 return mod.createAnonymousDeclFromDecl(scope.srcDecl().?, scope.namespace(), scope.srcScope(), typed_value);3953 return mod.createAnonymousDeclFromDecl(block.src_decl, block.namespace, block.wip_capture_scope, typed_value);
4362}3954}
43633955
4364pub fn createAnonymousDeclFromDecl(3956pub fn createAnonymousDeclFromDecl(
4365 mod: *Module,3957 mod: *Module,
4366 src_decl: *Decl,3958 src_decl: *Decl,
4367 namespace: *Scope.Namespace,3959 namespace: *Namespace,
4368 src_scope: ?*CaptureScope,3960 src_scope: ?*CaptureScope,
4369 tv: TypedValue,3961 tv: TypedValue,
4370) !*Decl {3962) !*Decl {
...@@ -4379,7 +3971,7 @@ pub fn createAnonymousDeclFromDecl(...@@ -4379,7 +3971,7 @@ pub fn createAnonymousDeclFromDecl(
4379pub fn createAnonymousDeclFromDeclNamed(3971pub fn createAnonymousDeclFromDeclNamed(
4380 mod: *Module,3972 mod: *Module,
4381 src_decl: *Decl,3973 src_decl: *Decl,
4382 namespace: *Scope.Namespace,3974 namespace: *Namespace,
4383 src_scope: ?*CaptureScope,3975 src_scope: ?*CaptureScope,
4384 typed_value: TypedValue,3976 typed_value: TypedValue,
4385 name: [:0]u8,3977 name: [:0]u8,
...@@ -4516,7 +4108,7 @@ pub fn optimizeMode(mod: Module) std.builtin.Mode {...@@ -4516,7 +4108,7 @@ pub fn optimizeMode(mod: Module) std.builtin.Mode {
4516 return mod.comp.bin_file.options.optimize_mode;4108 return mod.comp.bin_file.options.optimize_mode;
4517}4109}
45184110
4519fn lockAndClearFileCompileError(mod: *Module, file: *Scope.File) void {4111fn lockAndClearFileCompileError(mod: *Module, file: *File) void {
4520 switch (file.status) {4112 switch (file.status) {
4521 .success_zir, .retryable_failure => {},4113 .success_zir, .retryable_failure => {},
4522 .never_loaded, .parse_failure, .astgen_failure => {4114 .never_loaded, .parse_failure, .astgen_failure => {
src/Sema.zig+640-360
...@@ -21,7 +21,7 @@ air_values: std.ArrayListUnmanaged(Value) = .{},...@@ -21,7 +21,7 @@ air_values: std.ArrayListUnmanaged(Value) = .{},
21/// Maps ZIR to AIR.21/// Maps ZIR to AIR.
22inst_map: InstMap = .{},22inst_map: InstMap = .{},
23/// When analyzing an inline function call, owner_decl is the Decl of the caller23/// When analyzing an inline function call, owner_decl is the Decl of the caller
24/// and `src_decl` of `Scope.Block` is the `Decl` of the callee.24/// and `src_decl` of `Block` is the `Decl` of the callee.
25/// This `Decl` owns the arena memory of this `Sema`.25/// This `Decl` owns the arena memory of this `Sema`.
26owner_decl: *Decl,26owner_decl: *Decl,
27/// For an inline or comptime function call, this will be the root parent function27/// For an inline or comptime function call, this will be the root parent function
...@@ -75,7 +75,7 @@ const Air = @import("Air.zig");...@@ -75,7 +75,7 @@ const Air = @import("Air.zig");
75const Zir = @import("Zir.zig");75const Zir = @import("Zir.zig");
76const Module = @import("Module.zig");76const Module = @import("Module.zig");
77const trace = @import("tracy.zig").trace;77const trace = @import("tracy.zig").trace;
78const Scope = Module.Scope;78const Namespace = Module.Namespace;
79const CompileError = Module.CompileError;79const CompileError = Module.CompileError;
80const SemaError = Module.SemaError;80const SemaError = Module.SemaError;
81const Decl = Module.Decl;81const Decl = Module.Decl;
...@@ -89,6 +89,286 @@ const crash_report = @import("crash_report.zig");...@@ -89,6 +89,286 @@ const crash_report = @import("crash_report.zig");
8989
90pub const InstMap = std.AutoHashMapUnmanaged(Zir.Inst.Index, Air.Inst.Ref);90pub const InstMap = std.AutoHashMapUnmanaged(Zir.Inst.Index, Air.Inst.Ref);
9191
92/// This is the context needed to semantically analyze ZIR instructions and
93/// produce AIR instructions.
94/// This is a temporary structure stored on the stack; references to it are valid only
95/// during semantic analysis of the block.
96pub const Block = struct {
97 parent: ?*Block,
98 /// Shared among all child blocks.
99 sema: *Sema,
100 /// This Decl is the Decl according to the Zig source code corresponding to this Block.
101 /// This can vary during inline or comptime function calls. See `Sema.owner_decl`
102 /// for the one that will be the same for all Block instances.
103 src_decl: *Decl,
104 /// The namespace to use for lookups from this source block
105 /// When analyzing fields, this is different from src_decl.src_namepsace.
106 namespace: *Namespace,
107 /// The AIR instructions generated for this block.
108 instructions: std.ArrayListUnmanaged(Air.Inst.Index),
109 // `param` instructions are collected here to be used by the `func` instruction.
110 params: std.ArrayListUnmanaged(Param) = .{},
111
112 wip_capture_scope: *CaptureScope,
113
114 label: ?*Label = null,
115 inlining: ?*Inlining,
116 /// If runtime_index is not 0 then one of these is guaranteed to be non null.
117 runtime_cond: ?LazySrcLoc = null,
118 runtime_loop: ?LazySrcLoc = null,
119 /// Non zero if a non-inline loop or a runtime conditional have been encountered.
120 /// Stores to to comptime variables are only allowed when var.runtime_index <= runtime_index.
121 runtime_index: u32 = 0,
122
123 is_comptime: bool,
124
125 /// when null, it is determined by build mode, changed by @setRuntimeSafety
126 want_safety: ?bool = null,
127
128 c_import_buf: ?*std.ArrayList(u8) = null,
129
130 const Param = struct {
131 /// `noreturn` means `anytype`.
132 ty: Type,
133 is_comptime: bool,
134 };
135
136 /// This `Block` maps a block ZIR instruction to the corresponding
137 /// AIR instruction for break instruction analysis.
138 pub const Label = struct {
139 zir_block: Zir.Inst.Index,
140 merges: Merges,
141 };
142
143 /// This `Block` indicates that an inline function call is happening
144 /// and return instructions should be analyzed as a break instruction
145 /// to this AIR block instruction.
146 /// It is shared among all the blocks in an inline or comptime called
147 /// function.
148 pub const Inlining = struct {
149 comptime_result: Air.Inst.Ref,
150 merges: Merges,
151 };
152
153 pub const Merges = struct {
154 block_inst: Air.Inst.Index,
155 /// Separate array list from break_inst_list so that it can be passed directly
156 /// to resolvePeerTypes.
157 results: std.ArrayListUnmanaged(Air.Inst.Ref),
158 /// Keeps track of the break instructions so that the operand can be replaced
159 /// if we need to add type coercion at the end of block analysis.
160 /// Same indexes, capacity, length as `results`.
161 br_list: std.ArrayListUnmanaged(Air.Inst.Index),
162 };
163
164 /// For debugging purposes.
165 pub fn dump(block: *Block, mod: Module) void {
166 Zir.dumpBlock(mod, block);
167 }
168
169 pub fn makeSubBlock(parent: *Block) Block {
170 return .{
171 .parent = parent,
172 .sema = parent.sema,
173 .src_decl = parent.src_decl,
174 .namespace = parent.namespace,
175 .instructions = .{},
176 .wip_capture_scope = parent.wip_capture_scope,
177 .label = null,
178 .inlining = parent.inlining,
179 .is_comptime = parent.is_comptime,
180 .runtime_cond = parent.runtime_cond,
181 .runtime_loop = parent.runtime_loop,
182 .runtime_index = parent.runtime_index,
183 .want_safety = parent.want_safety,
184 .c_import_buf = parent.c_import_buf,
185 };
186 }
187
188 pub fn wantSafety(block: *const Block) bool {
189 return block.want_safety orelse switch (block.sema.mod.optimizeMode()) {
190 .Debug => true,
191 .ReleaseSafe => true,
192 .ReleaseFast => false,
193 .ReleaseSmall => false,
194 };
195 }
196
197 pub fn getFileScope(block: *Block) *Module.File {
198 return block.namespace.file_scope;
199 }
200
201 pub fn addTy(
202 block: *Block,
203 tag: Air.Inst.Tag,
204 ty: Type,
205 ) error{OutOfMemory}!Air.Inst.Ref {
206 return block.addInst(.{
207 .tag = tag,
208 .data = .{ .ty = ty },
209 });
210 }
211
212 pub fn addTyOp(
213 block: *Block,
214 tag: Air.Inst.Tag,
215 ty: Type,
216 operand: Air.Inst.Ref,
217 ) error{OutOfMemory}!Air.Inst.Ref {
218 return block.addInst(.{
219 .tag = tag,
220 .data = .{ .ty_op = .{
221 .ty = try block.sema.addType(ty),
222 .operand = operand,
223 } },
224 });
225 }
226
227 pub fn addNoOp(block: *Block, tag: Air.Inst.Tag) error{OutOfMemory}!Air.Inst.Ref {
228 return block.addInst(.{
229 .tag = tag,
230 .data = .{ .no_op = {} },
231 });
232 }
233
234 pub fn addUnOp(
235 block: *Block,
236 tag: Air.Inst.Tag,
237 operand: Air.Inst.Ref,
238 ) error{OutOfMemory}!Air.Inst.Ref {
239 return block.addInst(.{
240 .tag = tag,
241 .data = .{ .un_op = operand },
242 });
243 }
244
245 pub fn addBr(
246 block: *Block,
247 target_block: Air.Inst.Index,
248 operand: Air.Inst.Ref,
249 ) error{OutOfMemory}!Air.Inst.Ref {
250 return block.addInst(.{
251 .tag = .br,
252 .data = .{ .br = .{
253 .block_inst = target_block,
254 .operand = operand,
255 } },
256 });
257 }
258
259 pub fn addBinOp(
260 block: *Block,
261 tag: Air.Inst.Tag,
262 lhs: Air.Inst.Ref,
263 rhs: Air.Inst.Ref,
264 ) error{OutOfMemory}!Air.Inst.Ref {
265 return block.addInst(.{
266 .tag = tag,
267 .data = .{ .bin_op = .{
268 .lhs = lhs,
269 .rhs = rhs,
270 } },
271 });
272 }
273
274 pub fn addArg(block: *Block, ty: Type, name: u32) error{OutOfMemory}!Air.Inst.Ref {
275 return block.addInst(.{
276 .tag = .arg,
277 .data = .{ .ty_str = .{
278 .ty = try block.sema.addType(ty),
279 .str = name,
280 } },
281 });
282 }
283
284 pub fn addStructFieldPtr(
285 block: *Block,
286 struct_ptr: Air.Inst.Ref,
287 field_index: u32,
288 ptr_field_ty: Type,
289 ) !Air.Inst.Ref {
290 const ty = try block.sema.addType(ptr_field_ty);
291 const tag: Air.Inst.Tag = switch (field_index) {
292 0 => .struct_field_ptr_index_0,
293 1 => .struct_field_ptr_index_1,
294 2 => .struct_field_ptr_index_2,
295 3 => .struct_field_ptr_index_3,
296 else => {
297 return block.addInst(.{
298 .tag = .struct_field_ptr,
299 .data = .{ .ty_pl = .{
300 .ty = ty,
301 .payload = try block.sema.addExtra(Air.StructField{
302 .struct_operand = struct_ptr,
303 .field_index = @intCast(u32, field_index),
304 }),
305 } },
306 });
307 },
308 };
309 return block.addInst(.{
310 .tag = tag,
311 .data = .{ .ty_op = .{
312 .ty = ty,
313 .operand = struct_ptr,
314 } },
315 });
316 }
317
318 pub fn addInst(block: *Block, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Ref {
319 return Air.indexToRef(try block.addInstAsIndex(inst));
320 }
321
322 pub fn addInstAsIndex(block: *Block, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Index {
323 const sema = block.sema;
324 const gpa = sema.gpa;
325
326 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
327 try block.instructions.ensureUnusedCapacity(gpa, 1);
328
329 const result_index = @intCast(Air.Inst.Index, sema.air_instructions.len);
330 sema.air_instructions.appendAssumeCapacity(inst);
331 block.instructions.appendAssumeCapacity(result_index);
332 return result_index;
333 }
334
335 pub fn startAnonDecl(block: *Block) !WipAnonDecl {
336 return WipAnonDecl{
337 .block = block,
338 .new_decl_arena = std.heap.ArenaAllocator.init(block.sema.gpa),
339 .finished = false,
340 };
341 }
342
343 pub const WipAnonDecl = struct {
344 block: *Block,
345 new_decl_arena: std.heap.ArenaAllocator,
346 finished: bool,
347
348 pub fn arena(wad: *WipAnonDecl) *Allocator {
349 return &wad.new_decl_arena.allocator;
350 }
351
352 pub fn deinit(wad: *WipAnonDecl) void {
353 if (!wad.finished) {
354 wad.new_decl_arena.deinit();
355 }
356 wad.* = undefined;
357 }
358
359 pub fn finish(wad: *WipAnonDecl, ty: Type, val: Value) !*Decl {
360 const new_decl = try wad.block.sema.mod.createAnonymousDecl(wad.block, .{
361 .ty = ty,
362 .val = val,
363 });
364 errdefer wad.block.sema.mod.abortAnonDecl(new_decl);
365 try new_decl.finalizeNewArena(&wad.new_decl_arena);
366 wad.finished = true;
367 return new_decl;
368 }
369 };
370};
371
92pub fn deinit(sema: *Sema) void {372pub fn deinit(sema: *Sema) void {
93 const gpa = sema.gpa;373 const gpa = sema.gpa;
94 sema.air_instructions.deinit(gpa);374 sema.air_instructions.deinit(gpa);
...@@ -102,7 +382,7 @@ pub fn deinit(sema: *Sema) void {...@@ -102,7 +382,7 @@ pub fn deinit(sema: *Sema) void {
102/// Returns only the result from the body that is specified.382/// Returns only the result from the body that is specified.
103/// Only appropriate to call when it is determined at comptime that this body383/// Only appropriate to call when it is determined at comptime that this body
104/// has no peers.384/// has no peers.
105fn resolveBody(sema: *Sema, block: *Scope.Block, body: []const Zir.Inst.Index) CompileError!Air.Inst.Ref {385fn resolveBody(sema: *Sema, block: *Block, body: []const Zir.Inst.Index) CompileError!Air.Inst.Ref {
106 const break_inst = try sema.analyzeBody(block, body);386 const break_inst = try sema.analyzeBody(block, body);
107 const operand_ref = sema.code.instructions.items(.data)[break_inst].@"break".operand;387 const operand_ref = sema.code.instructions.items(.data)[break_inst].@"break".operand;
108 return sema.resolveInst(operand_ref);388 return sema.resolveInst(operand_ref);
...@@ -125,7 +405,7 @@ const always_noreturn: CompileError!Zir.Inst.Index = @as(Zir.Inst.Index, undefin...@@ -125,7 +405,7 @@ const always_noreturn: CompileError!Zir.Inst.Index = @as(Zir.Inst.Index, undefin
125/// well as the operand. No block scope needs to be created for this strategy.405/// well as the operand. No block scope needs to be created for this strategy.
126pub fn analyzeBody(406pub fn analyzeBody(
127 sema: *Sema,407 sema: *Sema,
128 block: *Scope.Block,408 block: *Block,
129 body: []const Zir.Inst.Index,409 body: []const Zir.Inst.Index,
130) CompileError!Zir.Inst.Index {410) CompileError!Zir.Inst.Index {
131 // No tracy calls here, to avoid interfering with the tail call mechanism.411 // No tracy calls here, to avoid interfering with the tail call mechanism.
...@@ -142,9 +422,9 @@ pub fn analyzeBody(...@@ -142,9 +422,9 @@ pub fn analyzeBody(
142 wip_captures.deinit();422 wip_captures.deinit();
143 };423 };
144424
145 const map = &block.sema.inst_map;425 const map = &sema.inst_map;
146 const tags = block.sema.code.instructions.items(.tag);426 const tags = sema.code.instructions.items(.tag);
147 const datas = block.sema.code.instructions.items(.data);427 const datas = sema.code.instructions.items(.data);
148428
149 var orig_captures: usize = parent_capture_scope.captures.count();429 var orig_captures: usize = parent_capture_scope.captures.count();
150430
...@@ -667,7 +947,7 @@ pub fn analyzeBody(...@@ -667,7 +947,7 @@ pub fn analyzeBody(
667 return result;947 return result;
668}948}
669949
670fn zirExtended(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {950fn zirExtended(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
671 const extended = sema.code.instructions.items(.data)[inst].extended;951 const extended = sema.code.instructions.items(.data)[inst].extended;
672 switch (extended.opcode) {952 switch (extended.opcode) {
673 // zig fmt: off953 // zig fmt: off
...@@ -719,7 +999,7 @@ pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) Air.Inst.Ref {...@@ -719,7 +999,7 @@ pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) Air.Inst.Ref {
719999
720fn resolveConstBool(1000fn resolveConstBool(
721 sema: *Sema,1001 sema: *Sema,
722 block: *Scope.Block,1002 block: *Block,
723 src: LazySrcLoc,1003 src: LazySrcLoc,
724 zir_ref: Zir.Inst.Ref,1004 zir_ref: Zir.Inst.Ref,
725) !bool {1005) !bool {
...@@ -732,7 +1012,7 @@ fn resolveConstBool(...@@ -732,7 +1012,7 @@ fn resolveConstBool(
7321012
733fn resolveConstString(1013fn resolveConstString(
734 sema: *Sema,1014 sema: *Sema,
735 block: *Scope.Block,1015 block: *Block,
736 src: LazySrcLoc,1016 src: LazySrcLoc,
737 zir_ref: Zir.Inst.Ref,1017 zir_ref: Zir.Inst.Ref,
738) ![]u8 {1018) ![]u8 {
...@@ -743,14 +1023,14 @@ fn resolveConstString(...@@ -743,14 +1023,14 @@ fn resolveConstString(
743 return val.toAllocatedBytes(sema.arena);1023 return val.toAllocatedBytes(sema.arena);
744}1024}
7451025
746pub fn resolveType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type {1026pub fn resolveType(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type {
747 const air_inst = sema.resolveInst(zir_ref);1027 const air_inst = sema.resolveInst(zir_ref);
748 return sema.analyzeAsType(block, src, air_inst);1028 return sema.analyzeAsType(block, src, air_inst);
749}1029}
7501030
751fn analyzeAsType(1031fn analyzeAsType(
752 sema: *Sema,1032 sema: *Sema,
753 block: *Scope.Block,1033 block: *Block,
754 src: LazySrcLoc,1034 src: LazySrcLoc,
755 air_inst: Air.Inst.Ref,1035 air_inst: Air.Inst.Ref,
756) !Type {1036) !Type {
...@@ -767,7 +1047,7 @@ fn analyzeAsType(...@@ -767,7 +1047,7 @@ fn analyzeAsType(
767/// Value Tag `generic_poison` causes `error.GenericPoison` to be returned.1047/// Value Tag `generic_poison` causes `error.GenericPoison` to be returned.
768fn resolveValue(1048fn resolveValue(
769 sema: *Sema,1049 sema: *Sema,
770 block: *Scope.Block,1050 block: *Block,
771 src: LazySrcLoc,1051 src: LazySrcLoc,
772 air_ref: Air.Inst.Ref,1052 air_ref: Air.Inst.Ref,
773) CompileError!Value {1053) CompileError!Value {
...@@ -782,7 +1062,7 @@ fn resolveValue(...@@ -782,7 +1062,7 @@ fn resolveValue(
782/// Value Tag `undef` may be returned.1062/// Value Tag `undef` may be returned.
783fn resolveConstMaybeUndefVal(1063fn resolveConstMaybeUndefVal(
784 sema: *Sema,1064 sema: *Sema,
785 block: *Scope.Block,1065 block: *Block,
786 src: LazySrcLoc,1066 src: LazySrcLoc,
787 inst: Air.Inst.Ref,1067 inst: Air.Inst.Ref,
788) CompileError!Value {1068) CompileError!Value {
...@@ -800,7 +1080,7 @@ fn resolveConstMaybeUndefVal(...@@ -800,7 +1080,7 @@ fn resolveConstMaybeUndefVal(
800/// See `resolveValue` for an alternative.1080/// See `resolveValue` for an alternative.
801fn resolveConstValue(1081fn resolveConstValue(
802 sema: *Sema,1082 sema: *Sema,
803 block: *Scope.Block,1083 block: *Block,
804 src: LazySrcLoc,1084 src: LazySrcLoc,
805 air_ref: Air.Inst.Ref,1085 air_ref: Air.Inst.Ref,
806) CompileError!Value {1086) CompileError!Value {
...@@ -819,7 +1099,7 @@ fn resolveConstValue(...@@ -819,7 +1099,7 @@ fn resolveConstValue(
819/// Value Tag `undef` causes this function to return a compile error.1099/// Value Tag `undef` causes this function to return a compile error.
820fn resolveDefinedValue(1100fn resolveDefinedValue(
821 sema: *Sema,1101 sema: *Sema,
822 block: *Scope.Block,1102 block: *Block,
823 src: LazySrcLoc,1103 src: LazySrcLoc,
824 air_ref: Air.Inst.Ref,1104 air_ref: Air.Inst.Ref,
825) CompileError!?Value {1105) CompileError!?Value {
...@@ -837,7 +1117,7 @@ fn resolveDefinedValue(...@@ -837,7 +1117,7 @@ fn resolveDefinedValue(
837/// Value Tag `generic_poison` causes `error.GenericPoison` to be returned.1117/// Value Tag `generic_poison` causes `error.GenericPoison` to be returned.
838fn resolveMaybeUndefVal(1118fn resolveMaybeUndefVal(
839 sema: *Sema,1119 sema: *Sema,
840 block: *Scope.Block,1120 block: *Block,
841 src: LazySrcLoc,1121 src: LazySrcLoc,
842 inst: Air.Inst.Ref,1122 inst: Air.Inst.Ref,
843) CompileError!?Value {1123) CompileError!?Value {
...@@ -852,7 +1132,7 @@ fn resolveMaybeUndefVal(...@@ -852,7 +1132,7 @@ fn resolveMaybeUndefVal(
852/// Returns all Value tags including `variable` and `undef`.1132/// Returns all Value tags including `variable` and `undef`.
853fn resolveMaybeUndefValAllowVariables(1133fn resolveMaybeUndefValAllowVariables(
854 sema: *Sema,1134 sema: *Sema,
855 block: *Scope.Block,1135 block: *Block,
856 src: LazySrcLoc,1136 src: LazySrcLoc,
857 inst: Air.Inst.Ref,1137 inst: Air.Inst.Ref,
858) CompileError!?Value {1138) CompileError!?Value {
...@@ -879,19 +1159,19 @@ fn resolveMaybeUndefValAllowVariables(...@@ -879,19 +1159,19 @@ fn resolveMaybeUndefValAllowVariables(
879 }1159 }
880}1160}
8811161
882fn failWithNeededComptime(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) CompileError {1162fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError {
883 return sema.fail(block, src, "unable to resolve comptime value", .{});1163 return sema.fail(block, src, "unable to resolve comptime value", .{});
884}1164}
8851165
886fn failWithUseOfUndef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) CompileError {1166fn failWithUseOfUndef(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError {
887 return sema.fail(block, src, "use of undefined value here causes undefined behavior", .{});1167 return sema.fail(block, src, "use of undefined value here causes undefined behavior", .{});
888}1168}
8891169
890fn failWithDivideByZero(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) CompileError {1170fn failWithDivideByZero(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError {
891 return sema.fail(block, src, "division by zero here causes undefined behavior", .{});1171 return sema.fail(block, src, "division by zero here causes undefined behavior", .{});
892}1172}
8931173
894fn failWithModRemNegative(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, lhs_ty: Type, rhs_ty: Type) CompileError {1174fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: Type, rhs_ty: Type) CompileError {
895 return sema.fail(block, src, "remainder division with '{}' and '{}': signed integers and floats must use @rem or @mod", .{ lhs_ty, rhs_ty });1175 return sema.fail(block, src, "remainder division with '{}' and '{}': signed integers and floats must use @rem or @mod", .{ lhs_ty, rhs_ty });
896}1176}
8971177
...@@ -899,28 +1179,28 @@ fn failWithModRemNegative(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, lhs...@@ -899,28 +1179,28 @@ fn failWithModRemNegative(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, lhs
899/// becomes invalid when you add another one.1179/// becomes invalid when you add another one.
900fn errNote(1180fn errNote(
901 sema: *Sema,1181 sema: *Sema,
902 block: *Scope.Block,1182 block: *Block,
903 src: LazySrcLoc,1183 src: LazySrcLoc,
904 parent: *Module.ErrorMsg,1184 parent: *Module.ErrorMsg,
905 comptime format: []const u8,1185 comptime format: []const u8,
906 args: anytype,1186 args: anytype,
907) error{OutOfMemory}!void {1187) error{OutOfMemory}!void {
908 return sema.mod.errNoteNonLazy(src.toSrcLoc(block), parent, format, args);1188 return sema.mod.errNoteNonLazy(src.toSrcLoc(block.src_decl), parent, format, args);
909}1189}
9101190
911fn errMsg(1191fn errMsg(
912 sema: *Sema,1192 sema: *Sema,
913 block: *Scope.Block,1193 block: *Block,
914 src: LazySrcLoc,1194 src: LazySrcLoc,
915 comptime format: []const u8,1195 comptime format: []const u8,
916 args: anytype,1196 args: anytype,
917) error{OutOfMemory}!*Module.ErrorMsg {1197) error{OutOfMemory}!*Module.ErrorMsg {
918 return Module.ErrorMsg.create(sema.gpa, src.toSrcLoc(block), format, args);1198 return Module.ErrorMsg.create(sema.gpa, src.toSrcLoc(block.src_decl), format, args);
919}1199}
9201200
921pub fn fail(1201pub fn fail(
922 sema: *Sema,1202 sema: *Sema,
923 block: *Scope.Block,1203 block: *Block,
924 src: LazySrcLoc,1204 src: LazySrcLoc,
925 comptime format: []const u8,1205 comptime format: []const u8,
926 args: anytype,1206 args: anytype,
...@@ -958,7 +1238,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError {...@@ -958,7 +1238,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError {
958/// TODO don't ever call this since we're migrating towards ResultLoc.coerced_ty.1238/// TODO don't ever call this since we're migrating towards ResultLoc.coerced_ty.
959fn resolveAlreadyCoercedInt(1239fn resolveAlreadyCoercedInt(
960 sema: *Sema,1240 sema: *Sema,
961 block: *Scope.Block,1241 block: *Block,
962 src: LazySrcLoc,1242 src: LazySrcLoc,
963 zir_ref: Zir.Inst.Ref,1243 zir_ref: Zir.Inst.Ref,
964 comptime Int: type,1244 comptime Int: type,
...@@ -974,7 +1254,7 @@ fn resolveAlreadyCoercedInt(...@@ -974,7 +1254,7 @@ fn resolveAlreadyCoercedInt(
9741254
975fn resolveAlign(1255fn resolveAlign(
976 sema: *Sema,1256 sema: *Sema,
977 block: *Scope.Block,1257 block: *Block,
978 src: LazySrcLoc,1258 src: LazySrcLoc,
979 zir_ref: Zir.Inst.Ref,1259 zir_ref: Zir.Inst.Ref,
980) !u16 {1260) !u16 {
...@@ -991,7 +1271,7 @@ fn resolveAlign(...@@ -991,7 +1271,7 @@ fn resolveAlign(
9911271
992fn resolveInt(1272fn resolveInt(
993 sema: *Sema,1273 sema: *Sema,
994 block: *Scope.Block,1274 block: *Block,
995 src: LazySrcLoc,1275 src: LazySrcLoc,
996 zir_ref: Zir.Inst.Ref,1276 zir_ref: Zir.Inst.Ref,
997 dest_type: Type,1277 dest_type: Type,
...@@ -1007,7 +1287,7 @@ fn resolveInt(...@@ -1007,7 +1287,7 @@ fn resolveInt(
1007// a function that does not.1287// a function that does not.
1008pub fn resolveInstConst(1288pub fn resolveInstConst(
1009 sema: *Sema,1289 sema: *Sema,
1010 block: *Scope.Block,1290 block: *Block,
1011 src: LazySrcLoc,1291 src: LazySrcLoc,
1012 zir_ref: Zir.Inst.Ref,1292 zir_ref: Zir.Inst.Ref,
1013) CompileError!TypedValue {1293) CompileError!TypedValue {
...@@ -1023,7 +1303,7 @@ pub fn resolveInstConst(...@@ -1023,7 +1303,7 @@ pub fn resolveInstConst(
1023// See `resolveInstConst` for an alternative.1303// See `resolveInstConst` for an alternative.
1024pub fn resolveInstValue(1304pub fn resolveInstValue(
1025 sema: *Sema,1305 sema: *Sema,
1026 block: *Scope.Block,1306 block: *Block,
1027 src: LazySrcLoc,1307 src: LazySrcLoc,
1028 zir_ref: Zir.Inst.Ref,1308 zir_ref: Zir.Inst.Ref,
1029) CompileError!TypedValue {1309) CompileError!TypedValue {
...@@ -1035,13 +1315,13 @@ pub fn resolveInstValue(...@@ -1035,13 +1315,13 @@ pub fn resolveInstValue(
1035 };1315 };
1036}1316}
10371317
1038fn zirBitcastResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {1318fn zirBitcastResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1039 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1319 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1040 const src = inst_data.src();1320 const src = inst_data.src();
1041 return sema.fail(block, src, "TODO implement zir_sema.zirBitcastResultPtr", .{});1321 return sema.fail(block, src, "TODO implement zir_sema.zirBitcastResultPtr", .{});
1042}1322}
10431323
1044fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {1324fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1045 const tracy = trace(@src());1325 const tracy = trace(@src());
1046 defer tracy.end();1326 defer tracy.end();
10471327
...@@ -1103,7 +1383,7 @@ pub fn analyzeStructDecl(...@@ -1103,7 +1383,7 @@ pub fn analyzeStructDecl(
11031383
1104fn zirStructDecl(1384fn zirStructDecl(
1105 sema: *Sema,1385 sema: *Sema,
1106 block: *Scope.Block,1386 block: *Block,
1107 extended: Zir.Inst.Extended.InstData,1387 extended: Zir.Inst.Extended.InstData,
1108 inst: Zir.Inst.Index,1388 inst: Zir.Inst.Index,
1109) CompileError!Air.Inst.Ref {1389) CompileError!Air.Inst.Ref {
...@@ -1120,7 +1400,7 @@ fn zirStructDecl(...@@ -1120,7 +1400,7 @@ fn zirStructDecl(
1120 const struct_ty = try Type.Tag.@"struct".create(&new_decl_arena.allocator, struct_obj);1400 const struct_ty = try Type.Tag.@"struct".create(&new_decl_arena.allocator, struct_obj);
1121 const struct_val = try Value.Tag.ty.create(&new_decl_arena.allocator, struct_ty);1401 const struct_val = try Value.Tag.ty.create(&new_decl_arena.allocator, struct_ty);
1122 const type_name = try sema.createTypeName(block, small.name_strategy);1402 const type_name = try sema.createTypeName(block, small.name_strategy);
1123 const new_decl = try sema.mod.createAnonymousDeclNamed(&block.base, .{1403 const new_decl = try sema.mod.createAnonymousDeclNamed(block, .{
1124 .ty = Type.initTag(.type),1404 .ty = Type.initTag(.type),
1125 .val = struct_val,1405 .val = struct_val,
1126 }, type_name);1406 }, type_name);
...@@ -1148,7 +1428,7 @@ fn zirStructDecl(...@@ -1148,7 +1428,7 @@ fn zirStructDecl(
1148 return sema.analyzeDeclVal(block, src, new_decl);1428 return sema.analyzeDeclVal(block, src, new_decl);
1149}1429}
11501430
1151fn createTypeName(sema: *Sema, block: *Scope.Block, name_strategy: Zir.Inst.NameStrategy) ![:0]u8 {1431fn createTypeName(sema: *Sema, block: *Block, name_strategy: Zir.Inst.NameStrategy) ![:0]u8 {
1152 switch (name_strategy) {1432 switch (name_strategy) {
1153 .anon => {1433 .anon => {
1154 // It would be neat to have "struct:line:column" but this name has1434 // It would be neat to have "struct:line:column" but this name has
...@@ -1176,7 +1456,7 @@ fn createTypeName(sema: *Sema, block: *Scope.Block, name_strategy: Zir.Inst.Name...@@ -1176,7 +1456,7 @@ fn createTypeName(sema: *Sema, block: *Scope.Block, name_strategy: Zir.Inst.Name
11761456
1177fn zirEnumDecl(1457fn zirEnumDecl(
1178 sema: *Sema,1458 sema: *Sema,
1179 block: *Scope.Block,1459 block: *Block,
1180 extended: Zir.Inst.Extended.InstData,1460 extended: Zir.Inst.Extended.InstData,
1181) CompileError!Air.Inst.Ref {1461) CompileError!Air.Inst.Ref {
1182 const tracy = trace(@src());1462 const tracy = trace(@src());
...@@ -1229,7 +1509,7 @@ fn zirEnumDecl(...@@ -1229,7 +1509,7 @@ fn zirEnumDecl(
1229 const enum_ty = Type.initPayload(&enum_ty_payload.base);1509 const enum_ty = Type.initPayload(&enum_ty_payload.base);
1230 const enum_val = try Value.Tag.ty.create(&new_decl_arena.allocator, enum_ty);1510 const enum_val = try Value.Tag.ty.create(&new_decl_arena.allocator, enum_ty);
1231 const type_name = try sema.createTypeName(block, small.name_strategy);1511 const type_name = try sema.createTypeName(block, small.name_strategy);
1232 const new_decl = try mod.createAnonymousDeclNamed(&block.base, .{1512 const new_decl = try mod.createAnonymousDeclNamed(block, .{
1233 .ty = Type.initTag(.type),1513 .ty = Type.initTag(.type),
1234 .val = enum_val,1514 .val = enum_val,
1235 }, type_name);1515 }, type_name);
...@@ -1287,7 +1567,7 @@ fn zirEnumDecl(...@@ -1287,7 +1567,7 @@ fn zirEnumDecl(
1287 var wip_captures = try WipCaptureScope.init(gpa, sema.perm_arena, new_decl.src_scope);1567 var wip_captures = try WipCaptureScope.init(gpa, sema.perm_arena, new_decl.src_scope);
1288 defer wip_captures.deinit();1568 defer wip_captures.deinit();
12891569
1290 var enum_block: Scope.Block = .{1570 var enum_block: Block = .{
1291 .parent = null,1571 .parent = null,
1292 .sema = sema,1572 .sema = sema,
1293 .src_decl = new_decl,1573 .src_decl = new_decl,
...@@ -1377,7 +1657,7 @@ fn zirEnumDecl(...@@ -1377,7 +1657,7 @@ fn zirEnumDecl(
13771657
1378fn zirUnionDecl(1658fn zirUnionDecl(
1379 sema: *Sema,1659 sema: *Sema,
1380 block: *Scope.Block,1660 block: *Block,
1381 extended: Zir.Inst.Extended.InstData,1661 extended: Zir.Inst.Extended.InstData,
1382 inst: Zir.Inst.Index,1662 inst: Zir.Inst.Index,
1383) CompileError!Air.Inst.Ref {1663) CompileError!Air.Inst.Ref {
...@@ -1416,7 +1696,7 @@ fn zirUnionDecl(...@@ -1416,7 +1696,7 @@ fn zirUnionDecl(
1416 const union_ty = Type.initPayload(&union_payload.base);1696 const union_ty = Type.initPayload(&union_payload.base);
1417 const union_val = try Value.Tag.ty.create(&new_decl_arena.allocator, union_ty);1697 const union_val = try Value.Tag.ty.create(&new_decl_arena.allocator, union_ty);
1418 const type_name = try sema.createTypeName(block, small.name_strategy);1698 const type_name = try sema.createTypeName(block, small.name_strategy);
1419 const new_decl = try sema.mod.createAnonymousDeclNamed(&block.base, .{1699 const new_decl = try sema.mod.createAnonymousDeclNamed(block, .{
1420 .ty = Type.initTag(.type),1700 .ty = Type.initTag(.type),
1421 .val = union_val,1701 .val = union_val,
1422 }, type_name);1702 }, type_name);
...@@ -1448,7 +1728,7 @@ fn zirUnionDecl(...@@ -1448,7 +1728,7 @@ fn zirUnionDecl(
14481728
1449fn zirOpaqueDecl(1729fn zirOpaqueDecl(
1450 sema: *Sema,1730 sema: *Sema,
1451 block: *Scope.Block,1731 block: *Block,
1452 extended: Zir.Inst.Extended.InstData,1732 extended: Zir.Inst.Extended.InstData,
1453 inst: Zir.Inst.Index,1733 inst: Zir.Inst.Index,
1454) CompileError!Air.Inst.Ref {1734) CompileError!Air.Inst.Ref {
...@@ -1462,7 +1742,7 @@ fn zirOpaqueDecl(...@@ -1462,7 +1742,7 @@ fn zirOpaqueDecl(
14621742
1463fn zirErrorSetDecl(1743fn zirErrorSetDecl(
1464 sema: *Sema,1744 sema: *Sema,
1465 block: *Scope.Block,1745 block: *Block,
1466 inst: Zir.Inst.Index,1746 inst: Zir.Inst.Index,
1467 name_strategy: Zir.Inst.NameStrategy,1747 name_strategy: Zir.Inst.NameStrategy,
1468) CompileError!Air.Inst.Ref {1748) CompileError!Air.Inst.Ref {
...@@ -1482,7 +1762,7 @@ fn zirErrorSetDecl(...@@ -1482,7 +1762,7 @@ fn zirErrorSetDecl(
1482 const error_set_ty = try Type.Tag.error_set.create(&new_decl_arena.allocator, error_set);1762 const error_set_ty = try Type.Tag.error_set.create(&new_decl_arena.allocator, error_set);
1483 const error_set_val = try Value.Tag.ty.create(&new_decl_arena.allocator, error_set_ty);1763 const error_set_val = try Value.Tag.ty.create(&new_decl_arena.allocator, error_set_ty);
1484 const type_name = try sema.createTypeName(block, name_strategy);1764 const type_name = try sema.createTypeName(block, name_strategy);
1485 const new_decl = try sema.mod.createAnonymousDeclNamed(&block.base, .{1765 const new_decl = try sema.mod.createAnonymousDeclNamed(block, .{
1486 .ty = Type.initTag(.type),1766 .ty = Type.initTag(.type),
1487 .val = error_set_val,1767 .val = error_set_val,
1488 }, type_name);1768 }, type_name);
...@@ -1504,7 +1784,7 @@ fn zirErrorSetDecl(...@@ -1504,7 +1784,7 @@ fn zirErrorSetDecl(
15041784
1505fn zirRetPtr(1785fn zirRetPtr(
1506 sema: *Sema,1786 sema: *Sema,
1507 block: *Scope.Block,1787 block: *Block,
1508 extended: Zir.Inst.Extended.InstData,1788 extended: Zir.Inst.Extended.InstData,
1509) CompileError!Air.Inst.Ref {1789) CompileError!Air.Inst.Ref {
1510 const tracy = trace(@src());1790 const tracy = trace(@src());
...@@ -1524,7 +1804,7 @@ fn zirRetPtr(...@@ -1524,7 +1804,7 @@ fn zirRetPtr(
1524 return block.addTy(.alloc, ptr_type);1804 return block.addTy(.alloc, ptr_type);
1525}1805}
15261806
1527fn zirRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {1807fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1528 const tracy = trace(@src());1808 const tracy = trace(@src());
1529 defer tracy.end();1809 defer tracy.end();
15301810
...@@ -1535,7 +1815,7 @@ fn zirRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A...@@ -1535,7 +1815,7 @@ fn zirRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A
15351815
1536fn zirRetType(1816fn zirRetType(
1537 sema: *Sema,1817 sema: *Sema,
1538 block: *Scope.Block,1818 block: *Block,
1539 extended: Zir.Inst.Extended.InstData,1819 extended: Zir.Inst.Extended.InstData,
1540) CompileError!Air.Inst.Ref {1820) CompileError!Air.Inst.Ref {
1541 const tracy = trace(@src());1821 const tracy = trace(@src());
...@@ -1546,7 +1826,7 @@ fn zirRetType(...@@ -1546,7 +1826,7 @@ fn zirRetType(
1546 return sema.addType(sema.fn_ret_ty);1826 return sema.addType(sema.fn_ret_ty);
1547}1827}
15481828
1549fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {1829fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
1550 const tracy = trace(@src());1830 const tracy = trace(@src());
1551 defer tracy.end();1831 defer tracy.end();
15521832
...@@ -1559,7 +1839,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) C...@@ -1559,7 +1839,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) C
15591839
1560fn ensureResultUsed(1840fn ensureResultUsed(
1561 sema: *Sema,1841 sema: *Sema,
1562 block: *Scope.Block,1842 block: *Block,
1563 operand: Air.Inst.Ref,1843 operand: Air.Inst.Ref,
1564 src: LazySrcLoc,1844 src: LazySrcLoc,
1565) CompileError!void {1845) CompileError!void {
...@@ -1570,7 +1850,7 @@ fn ensureResultUsed(...@@ -1570,7 +1850,7 @@ fn ensureResultUsed(
1570 }1850 }
1571}1851}
15721852
1573fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {1853fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
1574 const tracy = trace(@src());1854 const tracy = trace(@src());
1575 defer tracy.end();1855 defer tracy.end();
15761856
...@@ -1584,7 +1864,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde...@@ -1584,7 +1864,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
1584 }1864 }
1585}1865}
15861866
1587fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {1867fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1588 const tracy = trace(@src());1868 const tracy = trace(@src());
1589 defer tracy.end();1869 defer tracy.end();
15901870
...@@ -1632,7 +1912,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co...@@ -1632,7 +1912,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co
16321912
1633fn zirAllocExtended(1913fn zirAllocExtended(
1634 sema: *Sema,1914 sema: *Sema,
1635 block: *Scope.Block,1915 block: *Block,
1636 extended: Zir.Inst.Extended.InstData,1916 extended: Zir.Inst.Extended.InstData,
1637) CompileError!Air.Inst.Ref {1917) CompileError!Air.Inst.Ref {
1638 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);1918 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);
...@@ -1675,7 +1955,7 @@ fn zirAllocExtended(...@@ -1675,7 +1955,7 @@ fn zirAllocExtended(
1675 return block.addTy(.alloc, ptr_type);1955 return block.addTy(.alloc, ptr_type);
1676}1956}
16771957
1678fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {1958fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1679 const tracy = trace(@src());1959 const tracy = trace(@src());
1680 defer tracy.end();1960 defer tracy.end();
16811961
...@@ -1695,7 +1975,7 @@ fn zirAllocInferredComptime(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air....@@ -1695,7 +1975,7 @@ fn zirAllocInferredComptime(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.
1695 );1975 );
1696}1976}
16971977
1698fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {1978fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1699 const tracy = trace(@src());1979 const tracy = trace(@src());
1700 defer tracy.end();1980 defer tracy.end();
17011981
...@@ -1711,7 +1991,7 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError...@@ -1711,7 +1991,7 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError
1711 return block.addTy(.alloc, ptr_type);1991 return block.addTy(.alloc, ptr_type);
1712}1992}
17131993
1714fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {1994fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1715 const tracy = trace(@src());1995 const tracy = trace(@src());
1716 defer tracy.end();1996 defer tracy.end();
17171997
...@@ -1733,7 +2013,7 @@ fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -1733,7 +2013,7 @@ fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
17332013
1734fn zirAllocInferred(2014fn zirAllocInferred(
1735 sema: *Sema,2015 sema: *Sema,
1736 block: *Scope.Block,2016 block: *Block,
1737 inst: Zir.Inst.Index,2017 inst: Zir.Inst.Index,
1738 inferred_alloc_ty: Type,2018 inferred_alloc_ty: Type,
1739) CompileError!Air.Inst.Ref {2019) CompileError!Air.Inst.Ref {
...@@ -1764,7 +2044,7 @@ fn zirAllocInferred(...@@ -1764,7 +2044,7 @@ fn zirAllocInferred(
1764 return result;2044 return result;
1765}2045}
17662046
1767fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {2047fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
1768 const tracy = trace(@src());2048 const tracy = trace(@src());
1769 defer tracy.end();2049 defer tracy.end();
17702050
...@@ -1823,7 +2103,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde...@@ -1823,7 +2103,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
1823 }2103 }
1824}2104}
18252105
1826fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {2106fn zirValidateStructInitPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
1827 const tracy = trace(@src());2107 const tracy = trace(@src());
1828 defer tracy.end();2108 defer tracy.end();
18292109
...@@ -1855,7 +2135,7 @@ fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Ind...@@ -1855,7 +2135,7 @@ fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Ind
18552135
1856fn validateUnionInitPtr(2136fn validateUnionInitPtr(
1857 sema: *Sema,2137 sema: *Sema,
1858 block: *Scope.Block,2138 block: *Block,
1859 union_obj: *Module.Union,2139 union_obj: *Module.Union,
1860 init_src: LazySrcLoc,2140 init_src: LazySrcLoc,
1861 instrs: []const Zir.Inst.Index,2141 instrs: []const Zir.Inst.Index,
...@@ -1894,7 +2174,7 @@ fn validateUnionInitPtr(...@@ -1894,7 +2174,7 @@ fn validateUnionInitPtr(
18942174
1895fn validateStructInitPtr(2175fn validateStructInitPtr(
1896 sema: *Sema,2176 sema: *Sema,
1897 block: *Scope.Block,2177 block: *Block,
1898 struct_obj: *Module.Struct,2178 struct_obj: *Module.Struct,
1899 init_src: LazySrcLoc,2179 init_src: LazySrcLoc,
1900 instrs: []const Zir.Inst.Index,2180 instrs: []const Zir.Inst.Index,
...@@ -1956,7 +2236,7 @@ fn validateStructInitPtr(...@@ -1956,7 +2236,7 @@ fn validateStructInitPtr(
1956 }2236 }
1957}2237}
19582238
1959fn zirValidateArrayInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {2239fn zirValidateArrayInitPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
1960 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2240 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1961 const src = inst_data.src();2241 const src = inst_data.src();
1962 return sema.fail(block, src, "TODO implement Sema.zirValidateArrayInitPtr", .{});2242 return sema.fail(block, src, "TODO implement Sema.zirValidateArrayInitPtr", .{});
...@@ -1964,7 +2244,7 @@ fn zirValidateArrayInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde...@@ -1964,7 +2244,7 @@ fn zirValidateArrayInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
19642244
1965fn failWithBadFieldAccess(2245fn failWithBadFieldAccess(
1966 sema: *Sema,2246 sema: *Sema,
1967 block: *Scope.Block,2247 block: *Block,
1968 struct_obj: *Module.Struct,2248 struct_obj: *Module.Struct,
1969 field_src: LazySrcLoc,2249 field_src: LazySrcLoc,
1970 field_name: []const u8,2250 field_name: []const u8,
...@@ -1990,7 +2270,7 @@ fn failWithBadFieldAccess(...@@ -1990,7 +2270,7 @@ fn failWithBadFieldAccess(
19902270
1991fn failWithBadUnionFieldAccess(2271fn failWithBadUnionFieldAccess(
1992 sema: *Sema,2272 sema: *Sema,
1993 block: *Scope.Block,2273 block: *Block,
1994 union_obj: *Module.Union,2274 union_obj: *Module.Union,
1995 field_src: LazySrcLoc,2275 field_src: LazySrcLoc,
1996 field_name: []const u8,2276 field_name: []const u8,
...@@ -2014,7 +2294,7 @@ fn failWithBadUnionFieldAccess(...@@ -2014,7 +2294,7 @@ fn failWithBadUnionFieldAccess(
2014 return sema.failWithOwnedErrorMsg(msg);2294 return sema.failWithOwnedErrorMsg(msg);
2015}2295}
20162296
2017fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {2297fn zirStoreToBlockPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2018 const tracy = trace(@src());2298 const tracy = trace(@src());
2019 defer tracy.end();2299 defer tracy.end();
20202300
...@@ -2039,7 +2319,7 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co...@@ -2039,7 +2319,7 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co
2039 return sema.storePtr(block, src, bitcasted_ptr, value);2319 return sema.storePtr(block, src, bitcasted_ptr, value);
2040}2320}
20412321
2042fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {2322fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2043 const tracy = trace(@src());2323 const tracy = trace(@src());
2044 defer tracy.end();2324 defer tracy.end();
20452325
...@@ -2087,7 +2367,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)...@@ -2087,7 +2367,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)
2087 unreachable;2367 unreachable;
2088}2368}
20892369
2090fn zirSetEvalBranchQuota(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {2370fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2091 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2371 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2092 const src = inst_data.src();2372 const src = inst_data.src();
2093 const quota = try sema.resolveAlreadyCoercedInt(block, src, inst_data.operand, u32);2373 const quota = try sema.resolveAlreadyCoercedInt(block, src, inst_data.operand, u32);
...@@ -2095,7 +2375,7 @@ fn zirSetEvalBranchQuota(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)...@@ -2095,7 +2375,7 @@ fn zirSetEvalBranchQuota(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)
2095 sema.branch_quota = quota;2375 sema.branch_quota = quota;
2096}2376}
20972377
2098fn zirStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {2378fn zirStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2099 const tracy = trace(@src());2379 const tracy = trace(@src());
2100 defer tracy.end();2380 defer tracy.end();
21012381
...@@ -2105,7 +2385,7 @@ fn zirStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError...@@ -2105,7 +2385,7 @@ fn zirStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError
2105 return sema.storePtr(block, sema.src, ptr, value);2385 return sema.storePtr(block, sema.src, ptr, value);
2106}2386}
21072387
2108fn zirStoreNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {2388fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2109 const tracy = trace(@src());2389 const tracy = trace(@src());
2110 defer tracy.end();2390 defer tracy.end();
21112391
...@@ -2117,7 +2397,7 @@ fn zirStoreNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE...@@ -2117,7 +2397,7 @@ fn zirStoreNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
2117 return sema.storePtr(block, src, ptr, value);2397 return sema.storePtr(block, src, ptr, value);
2118}2398}
21192399
2120fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {2400fn zirStr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2121 const tracy = trace(@src());2401 const tracy = trace(@src());
2122 defer tracy.end();2402 defer tracy.end();
21232403
...@@ -2136,7 +2416,7 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A...@@ -2136,7 +2416,7 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A
2136 const decl_ty = try Type.Tag.array_u8_sentinel_0.create(&new_decl_arena.allocator, bytes.len);2416 const decl_ty = try Type.Tag.array_u8_sentinel_0.create(&new_decl_arena.allocator, bytes.len);
2137 const decl_val = try Value.Tag.bytes.create(&new_decl_arena.allocator, bytes);2417 const decl_val = try Value.Tag.bytes.create(&new_decl_arena.allocator, bytes);
21382418
2139 const new_decl = try sema.mod.createAnonymousDecl(&block.base, .{2419 const new_decl = try sema.mod.createAnonymousDecl(block, .{
2140 .ty = decl_ty,2420 .ty = decl_ty,
2141 .val = decl_val,2421 .val = decl_val,
2142 });2422 });
...@@ -2145,7 +2425,7 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A...@@ -2145,7 +2425,7 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A
2145 return sema.analyzeDeclRef(new_decl);2425 return sema.analyzeDeclRef(new_decl);
2146}2426}
21472427
2148fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {2428fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2149 _ = block;2429 _ = block;
2150 const tracy = trace(@src());2430 const tracy = trace(@src());
2151 defer tracy.end();2431 defer tracy.end();
...@@ -2154,7 +2434,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A...@@ -2154,7 +2434,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A
2154 return sema.addIntUnsigned(Type.initTag(.comptime_int), int);2434 return sema.addIntUnsigned(Type.initTag(.comptime_int), int);
2155}2435}
21562436
2157fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {2437fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2158 _ = block;2438 _ = block;
2159 const tracy = trace(@src());2439 const tracy = trace(@src());
2160 defer tracy.end();2440 defer tracy.end();
...@@ -2172,7 +2452,7 @@ fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro...@@ -2172,7 +2452,7 @@ fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
2172 );2452 );
2173}2453}
21742454
2175fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {2455fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2176 _ = block;2456 _ = block;
2177 const arena = sema.arena;2457 const arena = sema.arena;
2178 const number = sema.code.instructions.items(.data)[inst].float;2458 const number = sema.code.instructions.items(.data)[inst].float;
...@@ -2182,7 +2462,7 @@ fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError...@@ -2182,7 +2462,7 @@ fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError
2182 );2462 );
2183}2463}
21842464
2185fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {2465fn zirFloat128(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2186 _ = block;2466 _ = block;
2187 const arena = sema.arena;2467 const arena = sema.arena;
2188 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2468 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
...@@ -2194,7 +2474,7 @@ fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -2194,7 +2474,7 @@ fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
2194 );2474 );
2195}2475}
21962476
2197fn zirCompileError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {2477fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {
2198 const tracy = trace(@src());2478 const tracy = trace(@src());
2199 defer tracy.end();2479 defer tracy.end();
22002480
...@@ -2207,7 +2487,7 @@ fn zirCompileError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi...@@ -2207,7 +2487,7 @@ fn zirCompileError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi
22072487
2208fn zirCompileLog(2488fn zirCompileLog(
2209 sema: *Sema,2489 sema: *Sema,
2210 block: *Scope.Block,2490 block: *Block,
2211 extended: Zir.Inst.Extended.InstData,2491 extended: Zir.Inst.Extended.InstData,
2212) CompileError!Air.Inst.Ref {2492) CompileError!Air.Inst.Ref {
2213 var managed = sema.mod.compile_log_text.toManaged(sema.gpa);2493 var managed = sema.mod.compile_log_text.toManaged(sema.gpa);
...@@ -2239,7 +2519,7 @@ fn zirCompileLog(...@@ -2239,7 +2519,7 @@ fn zirCompileLog(
2239 return Air.Inst.Ref.void_value;2519 return Air.Inst.Ref.void_value;
2240}2520}
22412521
2242fn zirPanic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {2522fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {
2243 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2523 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2244 const src: LazySrcLoc = inst_data.src();2524 const src: LazySrcLoc = inst_data.src();
2245 const msg_inst = sema.resolveInst(inst_data.operand);2525 const msg_inst = sema.resolveInst(inst_data.operand);
...@@ -2247,7 +2527,7 @@ fn zirPanic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError...@@ -2247,7 +2527,7 @@ fn zirPanic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError
2247 return sema.panicWithMsg(block, src, msg_inst);2527 return sema.panicWithMsg(block, src, msg_inst);
2248}2528}
22492529
2250fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {2530fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2251 const tracy = trace(@src());2531 const tracy = trace(@src());
2252 defer tracy.end();2532 defer tracy.end();
22532533
...@@ -2275,7 +2555,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Compil...@@ -2275,7 +2555,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Compil
2275 .payload = undefined,2555 .payload = undefined,
2276 } },2556 } },
2277 });2557 });
2278 var label: Scope.Block.Label = .{2558 var label: Block.Label = .{
2279 .zir_block = inst,2559 .zir_block = inst,
2280 .merges = .{2560 .merges = .{
2281 .results = .{},2561 .results = .{},
...@@ -2310,7 +2590,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Compil...@@ -2310,7 +2590,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Compil
2310 return sema.analyzeBlockBody(parent_block, src, &child_block, merges);2590 return sema.analyzeBlockBody(parent_block, src, &child_block, merges);
2311}2591}
23122592
2313fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {2593fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2314 const tracy = trace(@src());2594 const tracy = trace(@src());
2315 defer tracy.end();2595 defer tracy.end();
23162596
...@@ -2326,7 +2606,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com...@@ -2326,7 +2606,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com
2326 var c_import_buf = std.ArrayList(u8).init(sema.gpa);2606 var c_import_buf = std.ArrayList(u8).init(sema.gpa);
2327 defer c_import_buf.deinit();2607 defer c_import_buf.deinit();
23282608
2329 var child_block: Scope.Block = .{2609 var child_block: Block = .{
2330 .parent = parent_block,2610 .parent = parent_block,
2331 .sema = sema,2611 .sema = sema,
2332 .src_decl = parent_block.src_decl,2612 .src_decl = parent_block.src_decl,
...@@ -2389,7 +2669,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com...@@ -2389,7 +2669,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com
2389 return sema.addConstant(file_root_decl.ty, file_root_decl.val);2669 return sema.addConstant(file_root_decl.ty, file_root_decl.val);
2390}2670}
23912671
2392fn zirSuspendBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {2672fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2393 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;2673 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2394 const src = inst_data.src();2674 const src = inst_data.src();
2395 return sema.fail(parent_block, src, "TODO: implement Sema.zirSuspendBlock", .{});2675 return sema.fail(parent_block, src, "TODO: implement Sema.zirSuspendBlock", .{});
...@@ -2397,7 +2677,7 @@ fn zirSuspendBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index...@@ -2397,7 +2677,7 @@ fn zirSuspendBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index
23972677
2398fn zirBlock(2678fn zirBlock(
2399 sema: *Sema,2679 sema: *Sema,
2400 parent_block: *Scope.Block,2680 parent_block: *Block,
2401 inst: Zir.Inst.Index,2681 inst: Zir.Inst.Index,
2402) CompileError!Air.Inst.Ref {2682) CompileError!Air.Inst.Ref {
2403 const tracy = trace(@src());2683 const tracy = trace(@src());
...@@ -2418,7 +2698,7 @@ fn zirBlock(...@@ -2418,7 +2698,7 @@ fn zirBlock(
2418 .data = undefined,2698 .data = undefined,
2419 });2699 });
24202700
2421 var label: Scope.Block.Label = .{2701 var label: Block.Label = .{
2422 .zir_block = inst,2702 .zir_block = inst,
2423 .merges = .{2703 .merges = .{
2424 .results = .{},2704 .results = .{},
...@@ -2427,7 +2707,7 @@ fn zirBlock(...@@ -2427,7 +2707,7 @@ fn zirBlock(
2427 },2707 },
2428 };2708 };
24292709
2430 var child_block: Scope.Block = .{2710 var child_block: Block = .{
2431 .parent = parent_block,2711 .parent = parent_block,
2432 .sema = sema,2712 .sema = sema,
2433 .src_decl = parent_block.src_decl,2713 .src_decl = parent_block.src_decl,
...@@ -2451,11 +2731,11 @@ fn zirBlock(...@@ -2451,11 +2731,11 @@ fn zirBlock(
24512731
2452fn resolveBlockBody(2732fn resolveBlockBody(
2453 sema: *Sema,2733 sema: *Sema,
2454 parent_block: *Scope.Block,2734 parent_block: *Block,
2455 src: LazySrcLoc,2735 src: LazySrcLoc,
2456 child_block: *Scope.Block,2736 child_block: *Block,
2457 body: []const Zir.Inst.Index,2737 body: []const Zir.Inst.Index,
2458 merges: *Scope.Block.Merges,2738 merges: *Block.Merges,
2459) CompileError!Air.Inst.Ref {2739) CompileError!Air.Inst.Ref {
2460 if (child_block.is_comptime) {2740 if (child_block.is_comptime) {
2461 return sema.resolveBody(child_block, body);2741 return sema.resolveBody(child_block, body);
...@@ -2467,10 +2747,10 @@ fn resolveBlockBody(...@@ -2467,10 +2747,10 @@ fn resolveBlockBody(
24672747
2468fn analyzeBlockBody(2748fn analyzeBlockBody(
2469 sema: *Sema,2749 sema: *Sema,
2470 parent_block: *Scope.Block,2750 parent_block: *Block,
2471 src: LazySrcLoc,2751 src: LazySrcLoc,
2472 child_block: *Scope.Block,2752 child_block: *Block,
2473 merges: *Scope.Block.Merges,2753 merges: *Block.Merges,
2474) CompileError!Air.Inst.Ref {2754) CompileError!Air.Inst.Ref {
2475 const tracy = trace(@src());2755 const tracy = trace(@src());
2476 defer tracy.end();2756 defer tracy.end();
...@@ -2568,7 +2848,7 @@ fn analyzeBlockBody(...@@ -2568,7 +2848,7 @@ fn analyzeBlockBody(
2568 return Air.indexToRef(merges.block_inst);2848 return Air.indexToRef(merges.block_inst);
2569}2849}
25702850
2571fn zirExport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {2851fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2572 const tracy = trace(@src());2852 const tracy = trace(@src());
2573 defer tracy.end();2853 defer tracy.end();
25742854
...@@ -2586,7 +2866,7 @@ fn zirExport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro...@@ -2586,7 +2866,7 @@ fn zirExport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
2586 try sema.analyzeExport(block, src, options, decl);2866 try sema.analyzeExport(block, src, options, decl);
2587}2867}
25882868
2589fn zirExportValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {2869fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2590 const tracy = trace(@src());2870 const tracy = trace(@src());
2591 defer tracy.end();2871 defer tracy.end();
25922872
...@@ -2606,7 +2886,7 @@ fn zirExportValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil...@@ -2606,7 +2886,7 @@ fn zirExportValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil
26062886
2607pub fn analyzeExport(2887pub fn analyzeExport(
2608 sema: *Sema,2888 sema: *Sema,
2609 block: *Scope.Block,2889 block: *Block,
2610 src: LazySrcLoc,2890 src: LazySrcLoc,
2611 borrowed_options: std.builtin.ExportOptions,2891 borrowed_options: std.builtin.ExportOptions,
2612 exported_decl: *Decl,2892 exported_decl: *Decl,
...@@ -2682,7 +2962,7 @@ pub fn analyzeExport(...@@ -2682,7 +2962,7 @@ pub fn analyzeExport(
2682 errdefer de_gop.value_ptr.* = gpa.shrink(de_gop.value_ptr.*, de_gop.value_ptr.len - 1);2962 errdefer de_gop.value_ptr.* = gpa.shrink(de_gop.value_ptr.*, de_gop.value_ptr.len - 1);
2683}2963}
26842964
2685fn zirSetAlignStack(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {2965fn zirSetAlignStack(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2686 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2966 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2687 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };2967 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2688 const src: LazySrcLoc = inst_data.src();2968 const src: LazySrcLoc = inst_data.src();
...@@ -2714,7 +2994,7 @@ fn zirSetAlignStack(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp...@@ -2714,7 +2994,7 @@ fn zirSetAlignStack(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp
2714 gop.value_ptr.* = .{ .alignment = alignment, .src = src };2994 gop.value_ptr.* = .{ .alignment = alignment, .src = src };
2715}2995}
27162996
2717fn zirSetCold(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {2997fn zirSetCold(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2718 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2998 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2719 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };2999 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2720 const is_cold = try sema.resolveConstBool(block, operand_src, inst_data.operand);3000 const is_cold = try sema.resolveConstBool(block, operand_src, inst_data.operand);
...@@ -2722,19 +3002,19 @@ fn zirSetCold(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -2722,19 +3002,19 @@ fn zirSetCold(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
2722 func.is_cold = is_cold;3002 func.is_cold = is_cold;
2723}3003}
27243004
2725fn zirSetFloatMode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {3005fn zirSetFloatMode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2726 const inst_data = sema.code.instructions.items(.data)[inst].un_node;3006 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2727 const src: LazySrcLoc = inst_data.src();3007 const src: LazySrcLoc = inst_data.src();
2728 return sema.fail(block, src, "TODO: implement Sema.zirSetFloatMode", .{});3008 return sema.fail(block, src, "TODO: implement Sema.zirSetFloatMode", .{});
2729}3009}
27303010
2731fn zirSetRuntimeSafety(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {3011fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2732 const inst_data = sema.code.instructions.items(.data)[inst].un_node;3012 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2733 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };3013 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2734 block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand);3014 block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand);
2735}3015}
27363016
2737fn zirFence(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {3017fn zirFence(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2738 if (block.is_comptime) return;3018 if (block.is_comptime) return;
27393019
2740 const inst_data = sema.code.instructions.items(.data)[inst].un_node;3020 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
...@@ -2751,7 +3031,7 @@ fn zirFence(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError...@@ -2751,7 +3031,7 @@ fn zirFence(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError
2751 });3031 });
2752}3032}
27533033
2754fn zirBreak(sema: *Sema, start_block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {3034fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {
2755 const tracy = trace(@src());3035 const tracy = trace(@src());
2756 defer tracy.end();3036 defer tracy.end();
27573037
...@@ -2773,7 +3053,7 @@ fn zirBreak(sema: *Sema, start_block: *Scope.Block, inst: Zir.Inst.Index) Compil...@@ -2773,7 +3053,7 @@ fn zirBreak(sema: *Sema, start_block: *Scope.Block, inst: Zir.Inst.Index) Compil
2773 }3053 }
2774}3054}
27753055
2776fn zirDbgStmt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {3056fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2777 const tracy = trace(@src());3057 const tracy = trace(@src());
2778 defer tracy.end();3058 defer tracy.end();
27793059
...@@ -2793,7 +3073,7 @@ fn zirDbgStmt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -2793,7 +3073,7 @@ fn zirDbgStmt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
2793 });3073 });
2794}3074}
27953075
2796fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {3076fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2797 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;3077 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
2798 const src = inst_data.src();3078 const src = inst_data.src();
2799 const decl_name = inst_data.get(sema.code);3079 const decl_name = inst_data.get(sema.code);
...@@ -2801,7 +3081,7 @@ fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -2801,7 +3081,7 @@ fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
2801 return sema.analyzeDeclRef(decl);3081 return sema.analyzeDeclRef(decl);
2802}3082}
28033083
2804fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {3084fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2805 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;3085 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
2806 const src = inst_data.src();3086 const src = inst_data.src();
2807 const decl_name = inst_data.get(sema.code);3087 const decl_name = inst_data.get(sema.code);
...@@ -2809,7 +3089,7 @@ fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -2809,7 +3089,7 @@ fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
2809 return sema.analyzeDeclVal(block, src, decl);3089 return sema.analyzeDeclVal(block, src, decl);
2810}3090}
28113091
2812fn lookupIdentifier(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, name: []const u8) !*Decl {3092fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: []const u8) !*Decl {
2813 var namespace = block.namespace;3093 var namespace = block.namespace;
2814 while (true) {3094 while (true) {
2815 if (try sema.lookupInNamespace(block, src, namespace, name, false)) |decl| {3095 if (try sema.lookupInNamespace(block, src, namespace, name, false)) |decl| {
...@@ -2824,9 +3104,9 @@ fn lookupIdentifier(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, name: []c...@@ -2824,9 +3104,9 @@ fn lookupIdentifier(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, name: []c
2824/// only for ones in the specified namespace.3104/// only for ones in the specified namespace.
2825fn lookupInNamespace(3105fn lookupInNamespace(
2826 sema: *Sema,3106 sema: *Sema,
2827 block: *Scope.Block,3107 block: *Block,
2828 src: LazySrcLoc,3108 src: LazySrcLoc,
2829 namespace: *Scope.Namespace,3109 namespace: *Namespace,
2830 ident_name: []const u8,3110 ident_name: []const u8,
2831 observe_usingnamespace: bool,3111 observe_usingnamespace: bool,
2832) CompileError!?*Decl {3112) CompileError!?*Decl {
...@@ -2842,7 +3122,7 @@ fn lookupInNamespace(...@@ -2842,7 +3122,7 @@ fn lookupInNamespace(
2842 const src_file = block.namespace.file_scope;3122 const src_file = block.namespace.file_scope;
28433123
2844 const gpa = sema.gpa;3124 const gpa = sema.gpa;
2845 var checked_namespaces: std.AutoArrayHashMapUnmanaged(*Scope.Namespace, void) = .{};3125 var checked_namespaces: std.AutoArrayHashMapUnmanaged(*Namespace, void) = .{};
2846 defer checked_namespaces.deinit(gpa);3126 defer checked_namespaces.deinit(gpa);
28473127
2848 // Keep track of name conflicts for error notes.3128 // Keep track of name conflicts for error notes.
...@@ -2914,7 +3194,7 @@ fn lookupInNamespace(...@@ -2914,7 +3194,7 @@ fn lookupInNamespace(
29143194
2915fn zirCall(3195fn zirCall(
2916 sema: *Sema,3196 sema: *Sema,
2917 block: *Scope.Block,3197 block: *Block,
2918 inst: Zir.Inst.Index,3198 inst: Zir.Inst.Index,
2919) CompileError!Air.Inst.Ref {3199) CompileError!Air.Inst.Ref {
2920 const tracy = trace(@src());3200 const tracy = trace(@src());
...@@ -3016,7 +3296,7 @@ const GenericRemoveAdapter = struct {...@@ -3016,7 +3296,7 @@ const GenericRemoveAdapter = struct {
30163296
3017fn analyzeCall(3297fn analyzeCall(
3018 sema: *Sema,3298 sema: *Sema,
3019 block: *Scope.Block,3299 block: *Block,
3020 func: Air.Inst.Ref,3300 func: Air.Inst.Ref,
3021 func_src: LazySrcLoc,3301 func_src: LazySrcLoc,
3022 call_src: LazySrcLoc,3302 call_src: LazySrcLoc,
...@@ -3097,7 +3377,7 @@ fn analyzeCall(...@@ -3097,7 +3377,7 @@ fn analyzeCall(
30973377
3098 // Analyze the ZIR. The same ZIR gets analyzed into a runtime function3378 // Analyze the ZIR. The same ZIR gets analyzed into a runtime function
3099 // or an inlined call depending on what union tag the `label` field is3379 // or an inlined call depending on what union tag the `label` field is
3100 // set to in the `Scope.Block`.3380 // set to in the `Block`.
3101 // This block instruction will be used to capture the return value from the3381 // This block instruction will be used to capture the return value from the
3102 // inlined function.3382 // inlined function.
3103 const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);3383 const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);
...@@ -3107,7 +3387,7 @@ fn analyzeCall(...@@ -3107,7 +3387,7 @@ fn analyzeCall(
3107 });3387 });
3108 // This one is shared among sub-blocks within the same callee, but not3388 // This one is shared among sub-blocks within the same callee, but not
3109 // shared among the entire inline/comptime call stack.3389 // shared among the entire inline/comptime call stack.
3110 var inlining: Scope.Block.Inlining = .{3390 var inlining: Block.Inlining = .{
3111 .comptime_result = undefined,3391 .comptime_result = undefined,
3112 .merges = .{3392 .merges = .{
3113 .results = .{},3393 .results = .{},
...@@ -3135,7 +3415,7 @@ fn analyzeCall(...@@ -3135,7 +3415,7 @@ fn analyzeCall(
3135 var wip_captures = try WipCaptureScope.init(gpa, sema.perm_arena, module_fn.owner_decl.src_scope);3415 var wip_captures = try WipCaptureScope.init(gpa, sema.perm_arena, module_fn.owner_decl.src_scope);
3136 defer wip_captures.deinit();3416 defer wip_captures.deinit();
31373417
3138 var child_block: Scope.Block = .{3418 var child_block: Block = .{
3139 .parent = null,3419 .parent = null,
3140 .sema = sema,3420 .sema = sema,
3141 .src_decl = module_fn.owner_decl,3421 .src_decl = module_fn.owner_decl,
...@@ -3437,7 +3717,7 @@ fn analyzeCall(...@@ -3437,7 +3717,7 @@ fn analyzeCall(
3437 var wip_captures = try WipCaptureScope.init(gpa, sema.perm_arena, new_decl.src_scope);3717 var wip_captures = try WipCaptureScope.init(gpa, sema.perm_arena, new_decl.src_scope);
3438 defer wip_captures.deinit();3718 defer wip_captures.deinit();
34393719
3440 var child_block: Scope.Block = .{3720 var child_block: Block = .{
3441 .parent = null,3721 .parent = null,
3442 .sema = &child_sema,3722 .sema = &child_sema,
3443 .src_decl = new_decl,3723 .src_decl = new_decl,
...@@ -3598,7 +3878,7 @@ fn analyzeCall(...@@ -3598,7 +3878,7 @@ fn analyzeCall(
35983878
3599fn finishGenericCall(3879fn finishGenericCall(
3600 sema: *Sema,3880 sema: *Sema,
3601 block: *Scope.Block,3881 block: *Block,
3602 call_src: LazySrcLoc,3882 call_src: LazySrcLoc,
3603 callee: *Module.Fn,3883 callee: *Module.Fn,
3604 func_src: LazySrcLoc,3884 func_src: LazySrcLoc,
...@@ -3665,7 +3945,7 @@ fn finishGenericCall(...@@ -3665,7 +3945,7 @@ fn finishGenericCall(
3665 return func_inst;3945 return func_inst;
3666}3946}
36673947
3668fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {3948fn zirIntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3669 _ = block;3949 _ = block;
3670 const tracy = trace(@src());3950 const tracy = trace(@src());
3671 defer tracy.end();3951 defer tracy.end();
...@@ -3676,7 +3956,7 @@ fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -3676,7 +3956,7 @@ fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
3676 return sema.addType(ty);3956 return sema.addType(ty);
3677}3957}
36783958
3679fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {3959fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3680 const tracy = trace(@src());3960 const tracy = trace(@src());
3681 defer tracy.end();3961 defer tracy.end();
36823962
...@@ -3688,7 +3968,7 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi...@@ -3688,7 +3968,7 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi
3688 return sema.addType(opt_type);3968 return sema.addType(opt_type);
3689}3969}
36903970
3691fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {3971fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3692 const inst_data = sema.code.instructions.items(.data)[inst].un_node;3972 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3693 const src = inst_data.src();3973 const src = inst_data.src();
3694 const array_type = try sema.resolveType(block, src, inst_data.operand);3974 const array_type = try sema.resolveType(block, src, inst_data.operand);
...@@ -3696,7 +3976,7 @@ fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -3696,7 +3976,7 @@ fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
3696 return sema.addType(elem_type);3976 return sema.addType(elem_type);
3697}3977}
36983978
3699fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {3979fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3700 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;3980 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
3701 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };3981 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
3702 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };3982 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
...@@ -3710,7 +3990,7 @@ fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile...@@ -3710,7 +3990,7 @@ fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile
3710 return sema.addType(vector_type);3990 return sema.addType(vector_type);
3711}3991}
37123992
3713fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {3993fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3714 const tracy = trace(@src());3994 const tracy = trace(@src());
3715 defer tracy.end();3995 defer tracy.end();
37163996
...@@ -3722,7 +4002,7 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE...@@ -3722,7 +4002,7 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
3722 return sema.addType(array_ty);4002 return sema.addType(array_ty);
3723}4003}
37244004
3725fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4005fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3726 const tracy = trace(@src());4006 const tracy = trace(@src());
3727 defer tracy.end();4007 defer tracy.end();
37284008
...@@ -3738,7 +4018,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)...@@ -3738,7 +4018,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)
3738 return sema.addType(array_ty);4018 return sema.addType(array_ty);
3739}4019}
37404020
3741fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4021fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3742 const tracy = trace(@src());4022 const tracy = trace(@src());
3743 defer tracy.end();4023 defer tracy.end();
37444024
...@@ -3750,7 +4030,7 @@ fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi...@@ -3750,7 +4030,7 @@ fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi
3750 return sema.addType(anyframe_type);4030 return sema.addType(anyframe_type);
3751}4031}
37524032
3753fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4033fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3754 const tracy = trace(@src());4034 const tracy = trace(@src());
3755 defer tracy.end();4035 defer tracy.end();
37564036
...@@ -3770,7 +4050,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com...@@ -3770,7 +4050,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com
3770 return sema.addType(err_union_ty);4050 return sema.addType(err_union_ty);
3771}4051}
37724052
3773fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4053fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3774 _ = block;4054 _ = block;
3775 const tracy = trace(@src());4055 const tracy = trace(@src());
3776 defer tracy.end();4056 defer tracy.end();
...@@ -3788,7 +4068,7 @@ fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile...@@ -3788,7 +4068,7 @@ fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile
3788 );4068 );
3789}4069}
37904070
3791fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4071fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3792 const tracy = trace(@src());4072 const tracy = trace(@src());
3793 defer tracy.end();4073 defer tracy.end();
37944074
...@@ -3815,7 +4095,7 @@ fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile...@@ -3815,7 +4095,7 @@ fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile
3815 return block.addTyOp(.bitcast, result_ty, op_coerced);4095 return block.addTyOp(.bitcast, result_ty, op_coerced);
3816}4096}
38174097
3818fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4098fn zirIntToError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3819 const tracy = trace(@src());4099 const tracy = trace(@src());
3820 defer tracy.end();4100 defer tracy.end();
38214101
...@@ -3845,7 +4125,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile...@@ -3845,7 +4125,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile
3845 return block.addTyOp(.bitcast, Type.initTag(.anyerror), op);4125 return block.addTyOp(.bitcast, Type.initTag(.anyerror), op);
3846}4126}
38474127
3848fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4128fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3849 const tracy = trace(@src());4129 const tracy = trace(@src());
3850 defer tracy.end();4130 defer tracy.end();
38514131
...@@ -3929,7 +4209,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com...@@ -3929,7 +4209,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com
3929 return sema.addConstant(Type.initTag(.type), try Value.Tag.ty.create(sema.arena, error_set_ty));4209 return sema.addConstant(Type.initTag(.type), try Value.Tag.ty.create(sema.arena, error_set_ty));
3930}4210}
39314211
3932fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4212fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3933 _ = block;4213 _ = block;
3934 const tracy = trace(@src());4214 const tracy = trace(@src());
3935 defer tracy.end();4215 defer tracy.end();
...@@ -3942,7 +4222,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil...@@ -3942,7 +4222,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil
3942 );4222 );
3943}4223}
39444224
3945fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4225fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3946 const arena = sema.arena;4226 const arena = sema.arena;
3947 const inst_data = sema.code.instructions.items(.data)[inst].un_node;4227 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3948 const src = inst_data.src();4228 const src = inst_data.src();
...@@ -3988,7 +4268,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE...@@ -3988,7 +4268,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
3988 return block.addTyOp(.bitcast, int_tag_ty, enum_tag);4268 return block.addTyOp(.bitcast, int_tag_ty, enum_tag);
3989}4269}
39904270
3991fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4271fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3992 const target = sema.mod.getTarget();4272 const target = sema.mod.getTarget();
3993 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;4273 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
3994 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;4274 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
...@@ -4038,7 +4318,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE...@@ -4038,7 +4318,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
4038/// Pointer in, pointer out.4318/// Pointer in, pointer out.
4039fn zirOptionalPayloadPtr(4319fn zirOptionalPayloadPtr(
4040 sema: *Sema,4320 sema: *Sema,
4041 block: *Scope.Block,4321 block: *Block,
4042 inst: Zir.Inst.Index,4322 inst: Zir.Inst.Index,
4043 safety_check: bool,4323 safety_check: bool,
4044) CompileError!Air.Inst.Ref {4324) CompileError!Air.Inst.Ref {
...@@ -4087,7 +4367,7 @@ fn zirOptionalPayloadPtr(...@@ -4087,7 +4367,7 @@ fn zirOptionalPayloadPtr(
4087/// Value in, value out.4367/// Value in, value out.
4088fn zirOptionalPayload(4368fn zirOptionalPayload(
4089 sema: *Sema,4369 sema: *Sema,
4090 block: *Scope.Block,4370 block: *Block,
4091 inst: Zir.Inst.Index,4371 inst: Zir.Inst.Index,
4092 safety_check: bool,4372 safety_check: bool,
4093) CompileError!Air.Inst.Ref {4373) CompileError!Air.Inst.Ref {
...@@ -4124,7 +4404,7 @@ fn zirOptionalPayload(...@@ -4124,7 +4404,7 @@ fn zirOptionalPayload(
4124/// Value in, value out4404/// Value in, value out
4125fn zirErrUnionPayload(4405fn zirErrUnionPayload(
4126 sema: *Sema,4406 sema: *Sema,
4127 block: *Scope.Block,4407 block: *Block,
4128 inst: Zir.Inst.Index,4408 inst: Zir.Inst.Index,
4129 safety_check: bool,4409 safety_check: bool,
4130) CompileError!Air.Inst.Ref {4410) CompileError!Air.Inst.Ref {
...@@ -4159,7 +4439,7 @@ fn zirErrUnionPayload(...@@ -4159,7 +4439,7 @@ fn zirErrUnionPayload(
4159/// Pointer in, pointer out.4439/// Pointer in, pointer out.
4160fn zirErrUnionPayloadPtr(4440fn zirErrUnionPayloadPtr(
4161 sema: *Sema,4441 sema: *Sema,
4162 block: *Scope.Block,4442 block: *Block,
4163 inst: Zir.Inst.Index,4443 inst: Zir.Inst.Index,
4164 safety_check: bool,4444 safety_check: bool,
4165) CompileError!Air.Inst.Ref {4445) CompileError!Air.Inst.Ref {
...@@ -4203,7 +4483,7 @@ fn zirErrUnionPayloadPtr(...@@ -4203,7 +4483,7 @@ fn zirErrUnionPayloadPtr(
4203}4483}
42044484
4205/// Value in, value out4485/// Value in, value out
4206fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4486fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4207 const tracy = trace(@src());4487 const tracy = trace(@src());
4208 defer tracy.end();4488 defer tracy.end();
42094489
...@@ -4226,7 +4506,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi...@@ -4226,7 +4506,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi
4226}4506}
42274507
4228/// Pointer in, value out4508/// Pointer in, value out
4229fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4509fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4230 const tracy = trace(@src());4510 const tracy = trace(@src());
4231 defer tracy.end();4511 defer tracy.end();
42324512
...@@ -4252,7 +4532,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co...@@ -4252,7 +4532,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co
4252 return block.addTyOp(.unwrap_errunion_err_ptr, result_ty, operand);4532 return block.addTyOp(.unwrap_errunion_err_ptr, result_ty, operand);
4253}4533}
42544534
4255fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {4535fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
4256 const tracy = trace(@src());4536 const tracy = trace(@src());
4257 defer tracy.end();4537 defer tracy.end();
42584538
...@@ -4269,7 +4549,7 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde...@@ -4269,7 +4549,7 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
42694549
4270fn zirFunc(4550fn zirFunc(
4271 sema: *Sema,4551 sema: *Sema,
4272 block: *Scope.Block,4552 block: *Block,
4273 inst: Zir.Inst.Index,4553 inst: Zir.Inst.Index,
4274 inferred_error_set: bool,4554 inferred_error_set: bool,
4275) CompileError!Air.Inst.Ref {4555) CompileError!Air.Inst.Ref {
...@@ -4312,7 +4592,7 @@ fn zirFunc(...@@ -4312,7 +4592,7 @@ fn zirFunc(
43124592
4313fn funcCommon(4593fn funcCommon(
4314 sema: *Sema,4594 sema: *Sema,
4315 block: *Scope.Block,4595 block: *Block,
4316 src_node_offset: i32,4596 src_node_offset: i32,
4317 body_inst: Zir.Inst.Index,4597 body_inst: Zir.Inst.Index,
4318 ret_ty_body: []const Zir.Inst.Index,4598 ret_ty_body: []const Zir.Inst.Index,
...@@ -4511,7 +4791,7 @@ fn funcCommon(...@@ -4511,7 +4791,7 @@ fn funcCommon(
45114791
4512fn zirParam(4792fn zirParam(
4513 sema: *Sema,4793 sema: *Sema,
4514 block: *Scope.Block,4794 block: *Block,
4515 inst: Zir.Inst.Index,4795 inst: Zir.Inst.Index,
4516 is_comptime: bool,4796 is_comptime: bool,
4517) CompileError!void {4797) CompileError!void {
...@@ -4581,7 +4861,7 @@ fn zirParam(...@@ -4581,7 +4861,7 @@ fn zirParam(
45814861
4582fn zirParamAnytype(4862fn zirParamAnytype(
4583 sema: *Sema,4863 sema: *Sema,
4584 block: *Scope.Block,4864 block: *Block,
4585 inst: Zir.Inst.Index,4865 inst: Zir.Inst.Index,
4586 is_comptime: bool,4866 is_comptime: bool,
4587) CompileError!void {4867) CompileError!void {
...@@ -4616,7 +4896,7 @@ fn zirParamAnytype(...@@ -4616,7 +4896,7 @@ fn zirParamAnytype(
4616 try sema.inst_map.put(sema.gpa, inst, .generic_poison);4896 try sema.inst_map.put(sema.gpa, inst, .generic_poison);
4617}4897}
46184898
4619fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4899fn zirAs(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4620 const tracy = trace(@src());4900 const tracy = trace(@src());
4621 defer tracy.end();4901 defer tracy.end();
46224902
...@@ -4624,7 +4904,7 @@ fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -4624,7 +4904,7 @@ fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Ai
4624 return sema.analyzeAs(block, .unneeded, bin_inst.lhs, bin_inst.rhs);4904 return sema.analyzeAs(block, .unneeded, bin_inst.lhs, bin_inst.rhs);
4625}4905}
46264906
4627fn zirAsNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4907fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4628 const tracy = trace(@src());4908 const tracy = trace(@src());
4629 defer tracy.end();4909 defer tracy.end();
46304910
...@@ -4636,7 +4916,7 @@ fn zirAsNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro...@@ -4636,7 +4916,7 @@ fn zirAsNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
46364916
4637fn analyzeAs(4917fn analyzeAs(
4638 sema: *Sema,4918 sema: *Sema,
4639 block: *Scope.Block,4919 block: *Block,
4640 src: LazySrcLoc,4920 src: LazySrcLoc,
4641 zir_dest_type: Zir.Inst.Ref,4921 zir_dest_type: Zir.Inst.Ref,
4642 zir_operand: Zir.Inst.Ref,4922 zir_operand: Zir.Inst.Ref,
...@@ -4646,7 +4926,7 @@ fn analyzeAs(...@@ -4646,7 +4926,7 @@ fn analyzeAs(
4646 return sema.coerce(block, dest_type, operand, src);4926 return sema.coerce(block, dest_type, operand, src);
4647}4927}
46484928
4649fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4929fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4650 const tracy = trace(@src());4930 const tracy = trace(@src());
4651 defer tracy.end();4931 defer tracy.end();
46524932
...@@ -4663,7 +4943,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -4663,7 +4943,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
4663 return block.addUnOp(.ptrtoint, ptr);4943 return block.addUnOp(.ptrtoint, ptr);
4664}4944}
46654945
4666fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4946fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4667 const tracy = trace(@src());4947 const tracy = trace(@src());
4668 defer tracy.end();4948 defer tracy.end();
46694949
...@@ -4682,7 +4962,7 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -4682,7 +4962,7 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
4682 }4962 }
4683}4963}
46844964
4685fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4965fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4686 const tracy = trace(@src());4966 const tracy = trace(@src());
4687 defer tracy.end();4967 defer tracy.end();
46884968
...@@ -4695,7 +4975,7 @@ fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -4695,7 +4975,7 @@ fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
4695 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src);4975 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src);
4696}4976}
46974977
4698fn zirFieldCallBind(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4978fn zirFieldCallBind(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4699 const tracy = trace(@src());4979 const tracy = trace(@src());
4700 defer tracy.end();4980 defer tracy.end();
47014981
...@@ -4708,7 +4988,7 @@ fn zirFieldCallBind(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp...@@ -4708,7 +4988,7 @@ fn zirFieldCallBind(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp
4708 return sema.fieldCallBind(block, src, object_ptr, field_name, field_name_src);4988 return sema.fieldCallBind(block, src, object_ptr, field_name, field_name_src);
4709}4989}
47104990
4711fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4991fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4712 const tracy = trace(@src());4992 const tracy = trace(@src());
4713 defer tracy.end();4993 defer tracy.end();
47144994
...@@ -4721,7 +5001,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp...@@ -4721,7 +5001,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp
4721 return sema.fieldVal(block, src, object, field_name, field_name_src);5001 return sema.fieldVal(block, src, object, field_name, field_name_src);
4722}5002}
47235003
4724fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5004fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4725 const tracy = trace(@src());5005 const tracy = trace(@src());
4726 defer tracy.end();5006 defer tracy.end();
47275007
...@@ -4734,7 +5014,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp...@@ -4734,7 +5014,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp
4734 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src);5014 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src);
4735}5015}
47365016
4737fn zirFieldCallBindNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5017fn zirFieldCallBindNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4738 const tracy = trace(@src());5018 const tracy = trace(@src());
4739 defer tracy.end();5019 defer tracy.end();
47405020
...@@ -4747,7 +5027,7 @@ fn zirFieldCallBindNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)...@@ -4747,7 +5027,7 @@ fn zirFieldCallBindNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)
4747 return sema.fieldCallBind(block, src, object_ptr, field_name, field_name_src);5027 return sema.fieldCallBind(block, src, object_ptr, field_name, field_name_src);
4748}5028}
47495029
4750fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5030fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4751 const tracy = trace(@src());5031 const tracy = trace(@src());
4752 defer tracy.end();5032 defer tracy.end();
47535033
...@@ -4773,7 +5053,7 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -4773,7 +5053,7 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
4773 return block.addTyOp(.intcast, dest_type, operand);5053 return block.addTyOp(.intcast, dest_type, operand);
4774}5054}
47755055
4776fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5056fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4777 const tracy = trace(@src());5057 const tracy = trace(@src());
4778 defer tracy.end();5058 defer tracy.end();
47795059
...@@ -4787,7 +5067,7 @@ fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -4787,7 +5067,7 @@ fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
4787 return sema.bitcast(block, dest_type, operand, operand_src);5067 return sema.bitcast(block, dest_type, operand, operand_src);
4788}5068}
47895069
4790fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5070fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4791 const tracy = trace(@src());5071 const tracy = trace(@src());
4792 defer tracy.end();5072 defer tracy.end();
47935073
...@@ -4838,7 +5118,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE...@@ -4838,7 +5118,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
4838 return block.addTyOp(.fptrunc, dest_type, operand);5118 return block.addTyOp(.fptrunc, dest_type, operand);
4839}5119}
48405120
4841fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5121fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4842 const tracy = trace(@src());5122 const tracy = trace(@src());
4843 defer tracy.end();5123 defer tracy.end();
48445124
...@@ -4848,7 +5128,7 @@ fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -4848,7 +5128,7 @@ fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
4848 return sema.elemVal(block, sema.src, array, elem_index, sema.src);5128 return sema.elemVal(block, sema.src, array, elem_index, sema.src);
4849}5129}
48505130
4851fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5131fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4852 const tracy = trace(@src());5132 const tracy = trace(@src());
4853 defer tracy.end();5133 defer tracy.end();
48545134
...@@ -4861,7 +5141,7 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil...@@ -4861,7 +5141,7 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil
4861 return sema.elemVal(block, src, array, elem_index, elem_index_src);5141 return sema.elemVal(block, src, array, elem_index, elem_index_src);
4862}5142}
48635143
4864fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5144fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4865 const tracy = trace(@src());5145 const tracy = trace(@src());
4866 defer tracy.end();5146 defer tracy.end();
48675147
...@@ -4871,7 +5151,7 @@ fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -4871,7 +5151,7 @@ fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
4871 return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);5151 return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);
4872}5152}
48735153
4874fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5154fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4875 const tracy = trace(@src());5155 const tracy = trace(@src());
4876 defer tracy.end();5156 defer tracy.end();
48775157
...@@ -4884,7 +5164,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil...@@ -4884,7 +5164,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil
4884 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);5164 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);
4885}5165}
48865166
4887fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5167fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4888 const tracy = trace(@src());5168 const tracy = trace(@src());
4889 defer tracy.end();5169 defer tracy.end();
48905170
...@@ -4897,7 +5177,7 @@ fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile...@@ -4897,7 +5177,7 @@ fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile
4897 return sema.analyzeSlice(block, src, array_ptr, start, .none, .none, .unneeded);5177 return sema.analyzeSlice(block, src, array_ptr, start, .none, .none, .unneeded);
4898}5178}
48995179
4900fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5180fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4901 const tracy = trace(@src());5181 const tracy = trace(@src());
4902 defer tracy.end();5182 defer tracy.end();
49035183
...@@ -4911,7 +5191,7 @@ fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -4911,7 +5191,7 @@ fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
4911 return sema.analyzeSlice(block, src, array_ptr, start, end, .none, .unneeded);5191 return sema.analyzeSlice(block, src, array_ptr, start, end, .none, .unneeded);
4912}5192}
49135193
4914fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5194fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4915 const tracy = trace(@src());5195 const tracy = trace(@src());
4916 defer tracy.end();5196 defer tracy.end();
49175197
...@@ -4929,7 +5209,7 @@ fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp...@@ -4929,7 +5209,7 @@ fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp
49295209
4930fn zirSwitchCapture(5210fn zirSwitchCapture(
4931 sema: *Sema,5211 sema: *Sema,
4932 block: *Scope.Block,5212 block: *Block,
4933 inst: Zir.Inst.Index,5213 inst: Zir.Inst.Index,
4934 is_multi: bool,5214 is_multi: bool,
4935 is_ref: bool,5215 is_ref: bool,
...@@ -4949,7 +5229,7 @@ fn zirSwitchCapture(...@@ -4949,7 +5229,7 @@ fn zirSwitchCapture(
49495229
4950fn zirSwitchCaptureElse(5230fn zirSwitchCaptureElse(
4951 sema: *Sema,5231 sema: *Sema,
4952 block: *Scope.Block,5232 block: *Block,
4953 inst: Zir.Inst.Index,5233 inst: Zir.Inst.Index,
4954 is_ref: bool,5234 is_ref: bool,
4955) CompileError!Air.Inst.Ref {5235) CompileError!Air.Inst.Ref {
...@@ -4967,7 +5247,7 @@ fn zirSwitchCaptureElse(...@@ -4967,7 +5247,7 @@ fn zirSwitchCaptureElse(
49675247
4968fn zirSwitchBlock(5248fn zirSwitchBlock(
4969 sema: *Sema,5249 sema: *Sema,
4970 block: *Scope.Block,5250 block: *Block,
4971 inst: Zir.Inst.Index,5251 inst: Zir.Inst.Index,
4972 is_ref: bool,5252 is_ref: bool,
4973 special_prong: Zir.SpecialProng,5253 special_prong: Zir.SpecialProng,
...@@ -5000,7 +5280,7 @@ fn zirSwitchBlock(...@@ -5000,7 +5280,7 @@ fn zirSwitchBlock(
50005280
5001fn zirSwitchBlockMulti(5281fn zirSwitchBlockMulti(
5002 sema: *Sema,5282 sema: *Sema,
5003 block: *Scope.Block,5283 block: *Block,
5004 inst: Zir.Inst.Index,5284 inst: Zir.Inst.Index,
5005 is_ref: bool,5285 is_ref: bool,
5006 special_prong: Zir.SpecialProng,5286 special_prong: Zir.SpecialProng,
...@@ -5033,7 +5313,7 @@ fn zirSwitchBlockMulti(...@@ -5033,7 +5313,7 @@ fn zirSwitchBlockMulti(
50335313
5034fn analyzeSwitch(5314fn analyzeSwitch(
5035 sema: *Sema,5315 sema: *Sema,
5036 block: *Scope.Block,5316 block: *Block,
5037 operand: Air.Inst.Ref,5317 operand: Air.Inst.Ref,
5038 extra_end: usize,5318 extra_end: usize,
5039 special_prong: Zir.SpecialProng,5319 special_prong: Zir.SpecialProng,
...@@ -5451,7 +5731,7 @@ fn analyzeSwitch(...@@ -5451,7 +5731,7 @@ fn analyzeSwitch(
5451 .tag = .block,5731 .tag = .block,
5452 .data = undefined,5732 .data = undefined,
5453 });5733 });
5454 var label: Scope.Block.Label = .{5734 var label: Block.Label = .{
5455 .zir_block = switch_inst,5735 .zir_block = switch_inst,
5456 .merges = .{5736 .merges = .{
5457 .results = .{},5737 .results = .{},
...@@ -5460,7 +5740,7 @@ fn analyzeSwitch(...@@ -5460,7 +5740,7 @@ fn analyzeSwitch(
5460 },5740 },
5461 };5741 };
54625742
5463 var child_block: Scope.Block = .{5743 var child_block: Block = .{
5464 .parent = block,5744 .parent = block,
5465 .sema = sema,5745 .sema = sema,
5466 .src_decl = block.src_decl,5746 .src_decl = block.src_decl,
...@@ -5771,7 +6051,7 @@ fn analyzeSwitch(...@@ -5771,7 +6051,7 @@ fn analyzeSwitch(
57716051
5772fn resolveSwitchItemVal(6052fn resolveSwitchItemVal(
5773 sema: *Sema,6053 sema: *Sema,
5774 block: *Scope.Block,6054 block: *Block,
5775 item_ref: Zir.Inst.Ref,6055 item_ref: Zir.Inst.Ref,
5776 switch_node_offset: i32,6056 switch_node_offset: i32,
5777 switch_prong_src: Module.SwitchProngSrc,6057 switch_prong_src: Module.SwitchProngSrc,
...@@ -5798,7 +6078,7 @@ fn resolveSwitchItemVal(...@@ -5798,7 +6078,7 @@ fn resolveSwitchItemVal(
57986078
5799fn validateSwitchRange(6079fn validateSwitchRange(
5800 sema: *Sema,6080 sema: *Sema,
5801 block: *Scope.Block,6081 block: *Block,
5802 range_set: *RangeSet,6082 range_set: *RangeSet,
5803 first_ref: Zir.Inst.Ref,6083 first_ref: Zir.Inst.Ref,
5804 last_ref: Zir.Inst.Ref,6084 last_ref: Zir.Inst.Ref,
...@@ -5814,7 +6094,7 @@ fn validateSwitchRange(...@@ -5814,7 +6094,7 @@ fn validateSwitchRange(
58146094
5815fn validateSwitchItem(6095fn validateSwitchItem(
5816 sema: *Sema,6096 sema: *Sema,
5817 block: *Scope.Block,6097 block: *Block,
5818 range_set: *RangeSet,6098 range_set: *RangeSet,
5819 item_ref: Zir.Inst.Ref,6099 item_ref: Zir.Inst.Ref,
5820 operand_ty: Type,6100 operand_ty: Type,
...@@ -5828,7 +6108,7 @@ fn validateSwitchItem(...@@ -5828,7 +6108,7 @@ fn validateSwitchItem(
58286108
5829fn validateSwitchItemEnum(6109fn validateSwitchItemEnum(
5830 sema: *Sema,6110 sema: *Sema,
5831 block: *Scope.Block,6111 block: *Block,
5832 seen_fields: []?Module.SwitchProngSrc,6112 seen_fields: []?Module.SwitchProngSrc,
5833 item_ref: Zir.Inst.Ref,6113 item_ref: Zir.Inst.Ref,
5834 src_node_offset: i32,6114 src_node_offset: i32,
...@@ -5862,7 +6142,7 @@ fn validateSwitchItemEnum(...@@ -5862,7 +6142,7 @@ fn validateSwitchItemEnum(
58626142
5863fn validateSwitchDupe(6143fn validateSwitchDupe(
5864 sema: *Sema,6144 sema: *Sema,
5865 block: *Scope.Block,6145 block: *Block,
5866 maybe_prev_src: ?Module.SwitchProngSrc,6146 maybe_prev_src: ?Module.SwitchProngSrc,
5867 switch_prong_src: Module.SwitchProngSrc,6147 switch_prong_src: Module.SwitchProngSrc,
5868 src_node_offset: i32,6148 src_node_offset: i32,
...@@ -5893,7 +6173,7 @@ fn validateSwitchDupe(...@@ -5893,7 +6173,7 @@ fn validateSwitchDupe(
58936173
5894fn validateSwitchItemBool(6174fn validateSwitchItemBool(
5895 sema: *Sema,6175 sema: *Sema,
5896 block: *Scope.Block,6176 block: *Block,
5897 true_count: *u8,6177 true_count: *u8,
5898 false_count: *u8,6178 false_count: *u8,
5899 item_ref: Zir.Inst.Ref,6179 item_ref: Zir.Inst.Ref,
...@@ -5916,7 +6196,7 @@ const ValueSrcMap = std.HashMap(Value, Module.SwitchProngSrc, Value.HashContext,...@@ -5916,7 +6196,7 @@ const ValueSrcMap = std.HashMap(Value, Module.SwitchProngSrc, Value.HashContext,
59166196
5917fn validateSwitchItemSparse(6197fn validateSwitchItemSparse(
5918 sema: *Sema,6198 sema: *Sema,
5919 block: *Scope.Block,6199 block: *Block,
5920 seen_values: *ValueSrcMap,6200 seen_values: *ValueSrcMap,
5921 item_ref: Zir.Inst.Ref,6201 item_ref: Zir.Inst.Ref,
5922 src_node_offset: i32,6202 src_node_offset: i32,
...@@ -5929,7 +6209,7 @@ fn validateSwitchItemSparse(...@@ -5929,7 +6209,7 @@ fn validateSwitchItemSparse(
59296209
5930fn validateSwitchNoRange(6210fn validateSwitchNoRange(
5931 sema: *Sema,6211 sema: *Sema,
5932 block: *Scope.Block,6212 block: *Block,
5933 ranges_len: u32,6213 ranges_len: u32,
5934 operand_ty: Type,6214 operand_ty: Type,
5935 src_node_offset: i32,6215 src_node_offset: i32,
...@@ -5960,7 +6240,7 @@ fn validateSwitchNoRange(...@@ -5960,7 +6240,7 @@ fn validateSwitchNoRange(
5960 return sema.failWithOwnedErrorMsg(msg);6240 return sema.failWithOwnedErrorMsg(msg);
5961}6241}
59626242
5963fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {6243fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
5964 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6244 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5965 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;6245 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
5966 _ = extra;6246 _ = extra;
...@@ -5969,7 +6249,7 @@ fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -5969,7 +6249,7 @@ fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
5969 return sema.fail(block, src, "TODO implement zirHasField", .{});6249 return sema.fail(block, src, "TODO implement zirHasField", .{});
5970}6250}
59716251
5972fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {6252fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
5973 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;6253 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5974 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;6254 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
5975 const src = inst_data.src();6255 const src = inst_data.src();
...@@ -5985,14 +6265,14 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -5985,14 +6265,14 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
5985 .{container_type},6265 .{container_type},
5986 );6266 );
5987 if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl| {6267 if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl| {
5988 if (decl.is_pub or decl.getFileScope() == block.base.namespace().file_scope) {6268 if (decl.is_pub or decl.getFileScope() == block.getFileScope()) {
5989 return Air.Inst.Ref.bool_true;6269 return Air.Inst.Ref.bool_true;
5990 }6270 }
5991 }6271 }
5992 return Air.Inst.Ref.bool_false;6272 return Air.Inst.Ref.bool_false;
5993}6273}
59946274
5995fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {6275fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
5996 const tracy = trace(@src());6276 const tracy = trace(@src());
5997 defer tracy.end();6277 defer tracy.end();
59986278
...@@ -6017,7 +6297,7 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro...@@ -6017,7 +6297,7 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
6017 return sema.addConstant(file_root_decl.ty, file_root_decl.val);6297 return sema.addConstant(file_root_decl.ty, file_root_decl.val);
6018}6298}
60196299
6020fn zirRetErrValueCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {6300fn zirRetErrValueCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
6021 _ = block;6301 _ = block;
6022 _ = inst;6302 _ = inst;
6023 return sema.fail(block, sema.src, "TODO implement zirRetErrValueCode", .{});6303 return sema.fail(block, sema.src, "TODO implement zirRetErrValueCode", .{});
...@@ -6025,7 +6305,7 @@ fn zirRetErrValueCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co...@@ -6025,7 +6305,7 @@ fn zirRetErrValueCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co
60256305
6026fn zirShl(6306fn zirShl(
6027 sema: *Sema,6307 sema: *Sema,
6028 block: *Scope.Block,6308 block: *Block,
6029 inst: Zir.Inst.Index,6309 inst: Zir.Inst.Index,
6030 air_tag: Air.Inst.Tag,6310 air_tag: Air.Inst.Tag,
6031) CompileError!Air.Inst.Ref {6311) CompileError!Air.Inst.Ref {
...@@ -6076,7 +6356,7 @@ fn zirShl(...@@ -6076,7 +6356,7 @@ fn zirShl(
6076 return block.addBinOp(air_tag, lhs, rhs);6356 return block.addBinOp(air_tag, lhs, rhs);
6077}6357}
60786358
6079fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {6359fn zirShr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
6080 const tracy = trace(@src());6360 const tracy = trace(@src());
6081 defer tracy.end();6361 defer tracy.end();
60826362
...@@ -6109,7 +6389,7 @@ fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A...@@ -6109,7 +6389,7 @@ fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A
61096389
6110fn zirBitwise(6390fn zirBitwise(
6111 sema: *Sema,6391 sema: *Sema,
6112 block: *Scope.Block,6392 block: *Block,
6113 inst: Zir.Inst.Index,6393 inst: Zir.Inst.Index,
6114 air_tag: Air.Inst.Tag,6394 air_tag: Air.Inst.Tag,
6115) CompileError!Air.Inst.Ref {6395) CompileError!Air.Inst.Ref {
...@@ -6175,7 +6455,7 @@ fn zirBitwise(...@@ -6175,7 +6455,7 @@ fn zirBitwise(
6175 return block.addBinOp(air_tag, casted_lhs, casted_rhs);6455 return block.addBinOp(air_tag, casted_lhs, casted_rhs);
6176}6456}
61776457
6178fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {6458fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
6179 const tracy = trace(@src());6459 const tracy = trace(@src());
6180 defer tracy.end();6460 defer tracy.end();
61816461
...@@ -6183,7 +6463,7 @@ fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro...@@ -6183,7 +6463,7 @@ fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
6183 return sema.fail(block, sema.src, "TODO implement zirBitNot", .{});6463 return sema.fail(block, sema.src, "TODO implement zirBitNot", .{});
6184}6464}
61856465
6186fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {6466fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
6187 const tracy = trace(@src());6467 const tracy = trace(@src());
6188 defer tracy.end();6468 defer tracy.end();
61896469
...@@ -6267,7 +6547,7 @@ fn getArrayCatInfo(t: Type) ?Type.ArrayInfo {...@@ -6267,7 +6547,7 @@ fn getArrayCatInfo(t: Type) ?Type.ArrayInfo {
6267 };6547 };
6268}6548}
62696549
6270fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {6550fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
6271 const tracy = trace(@src());6551 const tracy = trace(@src());
6272 defer tracy.end();6552 defer tracy.end();
62736553
...@@ -6321,7 +6601,7 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -6321,7 +6601,7 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
63216601
6322fn zirNegate(6602fn zirNegate(
6323 sema: *Sema,6603 sema: *Sema,
6324 block: *Scope.Block,6604 block: *Block,
6325 inst: Zir.Inst.Index,6605 inst: Zir.Inst.Index,
6326 tag_override: Zir.Inst.Tag,6606 tag_override: Zir.Inst.Tag,
6327) CompileError!Air.Inst.Ref {6607) CompileError!Air.Inst.Ref {
...@@ -6340,7 +6620,7 @@ fn zirNegate(...@@ -6340,7 +6620,7 @@ fn zirNegate(
63406620
6341fn zirArithmetic(6621fn zirArithmetic(
6342 sema: *Sema,6622 sema: *Sema,
6343 block: *Scope.Block,6623 block: *Block,
6344 inst: Zir.Inst.Index,6624 inst: Zir.Inst.Index,
6345 zir_tag: Zir.Inst.Tag,6625 zir_tag: Zir.Inst.Tag,
6346) CompileError!Air.Inst.Ref {6626) CompileError!Air.Inst.Ref {
...@@ -6360,7 +6640,7 @@ fn zirArithmetic(...@@ -6360,7 +6640,7 @@ fn zirArithmetic(
63606640
6361fn zirOverflowArithmetic(6641fn zirOverflowArithmetic(
6362 sema: *Sema,6642 sema: *Sema,
6363 block: *Scope.Block,6643 block: *Block,
6364 extended: Zir.Inst.Extended.InstData,6644 extended: Zir.Inst.Extended.InstData,
6365) CompileError!Air.Inst.Ref {6645) CompileError!Air.Inst.Ref {
6366 const tracy = trace(@src());6646 const tracy = trace(@src());
...@@ -6374,7 +6654,7 @@ fn zirOverflowArithmetic(...@@ -6374,7 +6654,7 @@ fn zirOverflowArithmetic(
63746654
6375fn analyzeArithmetic(6655fn analyzeArithmetic(
6376 sema: *Sema,6656 sema: *Sema,
6377 block: *Scope.Block,6657 block: *Block,
6378 /// TODO performance investigation: make this comptime?6658 /// TODO performance investigation: make this comptime?
6379 zir_tag: Zir.Inst.Tag,6659 zir_tag: Zir.Inst.Tag,
6380 lhs: Air.Inst.Ref,6660 lhs: Air.Inst.Ref,
...@@ -7035,7 +7315,7 @@ fn analyzeArithmetic(...@@ -7035,7 +7315,7 @@ fn analyzeArithmetic(
7035 return block.addBinOp(rs.air_tag, casted_lhs, casted_rhs);7315 return block.addBinOp(rs.air_tag, casted_lhs, casted_rhs);
7036}7316}
70377317
7038fn zirLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {7318fn zirLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7039 const tracy = trace(@src());7319 const tracy = trace(@src());
7040 defer tracy.end();7320 defer tracy.end();
70417321
...@@ -7048,7 +7328,7 @@ fn zirLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!...@@ -7048,7 +7328,7 @@ fn zirLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!
70487328
7049fn zirAsm(7329fn zirAsm(
7050 sema: *Sema,7330 sema: *Sema,
7051 block: *Scope.Block,7331 block: *Block,
7052 extended: Zir.Inst.Extended.InstData,7332 extended: Zir.Inst.Extended.InstData,
7053 inst: Zir.Inst.Index,7333 inst: Zir.Inst.Index,
7054) CompileError!Air.Inst.Ref {7334) CompileError!Air.Inst.Ref {
...@@ -7127,7 +7407,7 @@ fn zirAsm(...@@ -7127,7 +7407,7 @@ fn zirAsm(
7127/// Only called for equality operators. See also `zirCmp`.7407/// Only called for equality operators. See also `zirCmp`.
7128fn zirCmpEq(7408fn zirCmpEq(
7129 sema: *Sema,7409 sema: *Sema,
7130 block: *Scope.Block,7410 block: *Block,
7131 inst: Zir.Inst.Index,7411 inst: Zir.Inst.Index,
7132 op: std.math.CompareOperator,7412 op: std.math.CompareOperator,
7133 air_tag: Air.Inst.Tag,7413 air_tag: Air.Inst.Tag,
...@@ -7216,7 +7496,7 @@ fn zirCmpEq(...@@ -7216,7 +7496,7 @@ fn zirCmpEq(
72167496
7217fn analyzeCmpUnionTag(7497fn analyzeCmpUnionTag(
7218 sema: *Sema,7498 sema: *Sema,
7219 block: *Scope.Block,7499 block: *Block,
7220 un: Air.Inst.Ref,7500 un: Air.Inst.Ref,
7221 un_src: LazySrcLoc,7501 un_src: LazySrcLoc,
7222 tag: Air.Inst.Ref,7502 tag: Air.Inst.Ref,
...@@ -7239,7 +7519,7 @@ fn analyzeCmpUnionTag(...@@ -7239,7 +7519,7 @@ fn analyzeCmpUnionTag(
7239/// Only called for non-equality operators. See also `zirCmpEq`.7519/// Only called for non-equality operators. See also `zirCmpEq`.
7240fn zirCmp(7520fn zirCmp(
7241 sema: *Sema,7521 sema: *Sema,
7242 block: *Scope.Block,7522 block: *Block,
7243 inst: Zir.Inst.Index,7523 inst: Zir.Inst.Index,
7244 op: std.math.CompareOperator,7524 op: std.math.CompareOperator,
7245) CompileError!Air.Inst.Ref {7525) CompileError!Air.Inst.Ref {
...@@ -7258,7 +7538,7 @@ fn zirCmp(...@@ -7258,7 +7538,7 @@ fn zirCmp(
72587538
7259fn analyzeCmp(7539fn analyzeCmp(
7260 sema: *Sema,7540 sema: *Sema,
7261 block: *Scope.Block,7541 block: *Block,
7262 src: LazySrcLoc,7542 src: LazySrcLoc,
7263 lhs: Air.Inst.Ref,7543 lhs: Air.Inst.Ref,
7264 rhs: Air.Inst.Ref,7544 rhs: Air.Inst.Ref,
...@@ -7289,7 +7569,7 @@ fn analyzeCmp(...@@ -7289,7 +7569,7 @@ fn analyzeCmp(
72897569
7290fn cmpSelf(7570fn cmpSelf(
7291 sema: *Sema,7571 sema: *Sema,
7292 block: *Scope.Block,7572 block: *Block,
7293 casted_lhs: Air.Inst.Ref,7573 casted_lhs: Air.Inst.Ref,
7294 casted_rhs: Air.Inst.Ref,7574 casted_rhs: Air.Inst.Ref,
7295 op: std.math.CompareOperator,7575 op: std.math.CompareOperator,
...@@ -7347,7 +7627,7 @@ fn cmpSelf(...@@ -7347,7 +7627,7 @@ fn cmpSelf(
7347/// cmp_neq(x, true ) => not(x)7627/// cmp_neq(x, true ) => not(x)
7348fn runtimeBoolCmp(7628fn runtimeBoolCmp(
7349 sema: *Sema,7629 sema: *Sema,
7350 block: *Scope.Block,7630 block: *Block,
7351 op: std.math.CompareOperator,7631 op: std.math.CompareOperator,
7352 lhs: Air.Inst.Ref,7632 lhs: Air.Inst.Ref,
7353 rhs: bool,7633 rhs: bool,
...@@ -7361,7 +7641,7 @@ fn runtimeBoolCmp(...@@ -7361,7 +7641,7 @@ fn runtimeBoolCmp(
7361 }7641 }
7362}7642}
73637643
7364fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {7644fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7365 const inst_data = sema.code.instructions.items(.data)[inst].un_node;7645 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
7366 const src = inst_data.src();7646 const src = inst_data.src();
7367 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };7647 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
...@@ -7402,7 +7682,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro...@@ -7402,7 +7682,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
7402 return sema.addIntUnsigned(Type.initTag(.comptime_int), abi_size);7682 return sema.addIntUnsigned(Type.initTag(.comptime_int), abi_size);
7403}7683}
74047684
7405fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {7685fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7406 const inst_data = sema.code.instructions.items(.data)[inst].un_node;7686 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
7407 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };7687 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
7408 const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand);7688 const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand);
...@@ -7413,17 +7693,17 @@ fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE...@@ -7413,17 +7693,17 @@ fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
74137693
7414fn zirThis(7694fn zirThis(
7415 sema: *Sema,7695 sema: *Sema,
7416 block: *Scope.Block,7696 block: *Block,
7417 extended: Zir.Inst.Extended.InstData,7697 extended: Zir.Inst.Extended.InstData,
7418) CompileError!Air.Inst.Ref {7698) CompileError!Air.Inst.Ref {
7419 const this_decl = block.base.namespace().getDecl();7699 const this_decl = block.namespace.getDecl();
7420 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };7700 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
7421 return sema.analyzeDeclVal(block, src, this_decl);7701 return sema.analyzeDeclVal(block, src, this_decl);
7422}7702}
74237703
7424fn zirClosureCapture(7704fn zirClosureCapture(
7425 sema: *Sema,7705 sema: *Sema,
7426 block: *Scope.Block,7706 block: *Block,
7427 inst: Zir.Inst.Index,7707 inst: Zir.Inst.Index,
7428) CompileError!void {7708) CompileError!void {
7429 // TODO: Compile error when closed over values are modified7709 // TODO: Compile error when closed over values are modified
...@@ -7437,7 +7717,7 @@ fn zirClosureCapture(...@@ -7437,7 +7717,7 @@ fn zirClosureCapture(
74377717
7438fn zirClosureGet(7718fn zirClosureGet(
7439 sema: *Sema,7719 sema: *Sema,
7440 block: *Scope.Block,7720 block: *Block,
7441 inst: Zir.Inst.Index,7721 inst: Zir.Inst.Index,
7442) CompileError!Air.Inst.Ref {7722) CompileError!Air.Inst.Ref {
7443 // TODO CLOSURE: Test this with inline functions7723 // TODO CLOSURE: Test this with inline functions
...@@ -7459,7 +7739,7 @@ fn zirClosureGet(...@@ -7459,7 +7739,7 @@ fn zirClosureGet(
74597739
7460fn zirRetAddr(7740fn zirRetAddr(
7461 sema: *Sema,7741 sema: *Sema,
7462 block: *Scope.Block,7742 block: *Block,
7463 extended: Zir.Inst.Extended.InstData,7743 extended: Zir.Inst.Extended.InstData,
7464) CompileError!Air.Inst.Ref {7744) CompileError!Air.Inst.Ref {
7465 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };7745 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
...@@ -7468,14 +7748,14 @@ fn zirRetAddr(...@@ -7468,14 +7748,14 @@ fn zirRetAddr(
74687748
7469fn zirBuiltinSrc(7749fn zirBuiltinSrc(
7470 sema: *Sema,7750 sema: *Sema,
7471 block: *Scope.Block,7751 block: *Block,
7472 extended: Zir.Inst.Extended.InstData,7752 extended: Zir.Inst.Extended.InstData,
7473) CompileError!Air.Inst.Ref {7753) CompileError!Air.Inst.Ref {
7474 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };7754 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
7475 return sema.fail(block, src, "TODO: implement Sema.zirBuiltinSrc", .{});7755 return sema.fail(block, src, "TODO: implement Sema.zirBuiltinSrc", .{});
7476}7756}
74777757
7478fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {7758fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7479 const inst_data = sema.code.instructions.items(.data)[inst].un_node;7759 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
7480 const src = inst_data.src();7760 const src = inst_data.src();
7481 const ty = try sema.resolveType(block, src, inst_data.operand);7761 const ty = try sema.resolveType(block, src, inst_data.operand);
...@@ -7680,7 +7960,7 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -7680,7 +7960,7 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
7680 }7960 }
7681}7961}
76827962
7683fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {7963fn zirTypeof(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7684 _ = block;7964 _ = block;
7685 const zir_datas = sema.code.instructions.items(.data);7965 const zir_datas = sema.code.instructions.items(.data);
7686 const inst_data = zir_datas[inst].un_node;7966 const inst_data = zir_datas[inst].un_node;
...@@ -7689,7 +7969,7 @@ fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro...@@ -7689,7 +7969,7 @@ fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
7689 return sema.addType(operand_ty);7969 return sema.addType(operand_ty);
7690}7970}
76917971
7692fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {7972fn zirTypeofElem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7693 _ = block;7973 _ = block;
7694 const inst_data = sema.code.instructions.items(.data)[inst].un_node;7974 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
7695 const operand_ptr = sema.resolveInst(inst_data.operand);7975 const operand_ptr = sema.resolveInst(inst_data.operand);
...@@ -7697,7 +7977,7 @@ fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile...@@ -7697,7 +7977,7 @@ fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile
7697 return sema.addType(elem_ty);7977 return sema.addType(elem_ty);
7698}7978}
76997979
7700fn zirTypeofLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {7980fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7701 const inst_data = sema.code.instructions.items(.data)[inst].un_node;7981 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
7702 const src = inst_data.src();7982 const src = inst_data.src();
7703 const operand = sema.resolveInst(inst_data.operand);7983 const operand = sema.resolveInst(inst_data.operand);
...@@ -7705,14 +7985,14 @@ fn zirTypeofLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)...@@ -7705,14 +7985,14 @@ fn zirTypeofLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)
7705 return sema.log2IntType(block, operand_ty, src);7985 return sema.log2IntType(block, operand_ty, src);
7706}7986}
77077987
7708fn zirLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {7988fn zirLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7709 const inst_data = sema.code.instructions.items(.data)[inst].un_node;7989 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
7710 const src = inst_data.src();7990 const src = inst_data.src();
7711 const operand = try sema.resolveType(block, src, inst_data.operand);7991 const operand = try sema.resolveType(block, src, inst_data.operand);
7712 return sema.log2IntType(block, operand, src);7992 return sema.log2IntType(block, operand, src);
7713}7993}
77147994
7715fn log2IntType(sema: *Sema, block: *Scope.Block, operand: Type, src: LazySrcLoc) CompileError!Air.Inst.Ref {7995fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) CompileError!Air.Inst.Ref {
7716 switch (operand.zigTypeTag()) {7996 switch (operand.zigTypeTag()) {
7717 .ComptimeInt => return Air.Inst.Ref.comptime_int_type,7997 .ComptimeInt => return Air.Inst.Ref.comptime_int_type,
7718 .Int => {7998 .Int => {
...@@ -7735,7 +8015,7 @@ fn log2IntType(sema: *Sema, block: *Scope.Block, operand: Type, src: LazySrcLoc)...@@ -7735,7 +8015,7 @@ fn log2IntType(sema: *Sema, block: *Scope.Block, operand: Type, src: LazySrcLoc)
77358015
7736fn zirTypeofPeer(8016fn zirTypeofPeer(
7737 sema: *Sema,8017 sema: *Sema,
7738 block: *Scope.Block,8018 block: *Block,
7739 extended: Zir.Inst.Extended.InstData,8019 extended: Zir.Inst.Extended.InstData,
7740) CompileError!Air.Inst.Ref {8020) CompileError!Air.Inst.Ref {
7741 const tracy = trace(@src());8021 const tracy = trace(@src());
...@@ -7756,7 +8036,7 @@ fn zirTypeofPeer(...@@ -7756,7 +8036,7 @@ fn zirTypeofPeer(
7756 return sema.addType(result_type);8036 return sema.addType(result_type);
7757}8037}
77588038
7759fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8039fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7760 const tracy = trace(@src());8040 const tracy = trace(@src());
7761 defer tracy.end();8041 defer tracy.end();
77628042
...@@ -7780,7 +8060,7 @@ fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -7780,7 +8060,7 @@ fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
77808060
7781fn zirBoolBr(8061fn zirBoolBr(
7782 sema: *Sema,8062 sema: *Sema,
7783 parent_block: *Scope.Block,8063 parent_block: *Block,
7784 inst: Zir.Inst.Index,8064 inst: Zir.Inst.Index,
7785 is_bool_or: bool,8065 is_bool_or: bool,
7786) CompileError!Air.Inst.Ref {8066) CompileError!Air.Inst.Ref {
...@@ -7866,7 +8146,7 @@ fn zirBoolBr(...@@ -7866,7 +8146,7 @@ fn zirBoolBr(
78668146
7867fn zirIsNonNull(8147fn zirIsNonNull(
7868 sema: *Sema,8148 sema: *Sema,
7869 block: *Scope.Block,8149 block: *Block,
7870 inst: Zir.Inst.Index,8150 inst: Zir.Inst.Index,
7871) CompileError!Air.Inst.Ref {8151) CompileError!Air.Inst.Ref {
7872 const tracy = trace(@src());8152 const tracy = trace(@src());
...@@ -7880,7 +8160,7 @@ fn zirIsNonNull(...@@ -7880,7 +8160,7 @@ fn zirIsNonNull(
78808160
7881fn zirIsNonNullPtr(8161fn zirIsNonNullPtr(
7882 sema: *Sema,8162 sema: *Sema,
7883 block: *Scope.Block,8163 block: *Block,
7884 inst: Zir.Inst.Index,8164 inst: Zir.Inst.Index,
7885) CompileError!Air.Inst.Ref {8165) CompileError!Air.Inst.Ref {
7886 const tracy = trace(@src());8166 const tracy = trace(@src());
...@@ -7893,7 +8173,7 @@ fn zirIsNonNullPtr(...@@ -7893,7 +8173,7 @@ fn zirIsNonNullPtr(
7893 return sema.analyzeIsNull(block, src, loaded, true);8173 return sema.analyzeIsNull(block, src, loaded, true);
7894}8174}
78958175
7896fn zirIsNonErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8176fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7897 const tracy = trace(@src());8177 const tracy = trace(@src());
7898 defer tracy.end();8178 defer tracy.end();
78998179
...@@ -7902,7 +8182,7 @@ fn zirIsNonErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -7902,7 +8182,7 @@ fn zirIsNonErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
7902 return sema.analyzeIsNonErr(block, inst_data.src(), operand);8182 return sema.analyzeIsNonErr(block, inst_data.src(), operand);
7903}8183}
79048184
7905fn zirIsNonErrPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8185fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7906 const tracy = trace(@src());8186 const tracy = trace(@src());
7907 defer tracy.end();8187 defer tracy.end();
79088188
...@@ -7915,7 +8195,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil...@@ -7915,7 +8195,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil
79158195
7916fn zirCondbr(8196fn zirCondbr(
7917 sema: *Sema,8197 sema: *Sema,
7918 parent_block: *Scope.Block,8198 parent_block: *Block,
7919 inst: Zir.Inst.Index,8199 inst: Zir.Inst.Index,
7920) CompileError!Zir.Inst.Index {8200) CompileError!Zir.Inst.Index {
7921 const tracy = trace(@src());8201 const tracy = trace(@src());
...@@ -7970,7 +8250,7 @@ fn zirCondbr(...@@ -7970,7 +8250,7 @@ fn zirCondbr(
7970 return always_noreturn;8250 return always_noreturn;
7971}8251}
79728252
7973fn zirUnreachable(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {8253fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {
7974 const tracy = trace(@src());8254 const tracy = trace(@src());
7975 defer tracy.end();8255 defer tracy.end();
79768256
...@@ -7989,7 +8269,7 @@ fn zirUnreachable(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil...@@ -7989,7 +8269,7 @@ fn zirUnreachable(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil
79898269
7990fn zirRetErrValue(8270fn zirRetErrValue(
7991 sema: *Sema,8271 sema: *Sema,
7992 block: *Scope.Block,8272 block: *Block,
7993 inst: Zir.Inst.Index,8273 inst: Zir.Inst.Index,
7994) CompileError!Zir.Inst.Index {8274) CompileError!Zir.Inst.Index {
7995 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;8275 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
...@@ -8013,7 +8293,7 @@ fn zirRetErrValue(...@@ -8013,7 +8293,7 @@ fn zirRetErrValue(
80138293
8014fn zirRetCoerce(8294fn zirRetCoerce(
8015 sema: *Sema,8295 sema: *Sema,
8016 block: *Scope.Block,8296 block: *Block,
8017 inst: Zir.Inst.Index,8297 inst: Zir.Inst.Index,
8018) CompileError!Zir.Inst.Index {8298) CompileError!Zir.Inst.Index {
8019 const tracy = trace(@src());8299 const tracy = trace(@src());
...@@ -8026,7 +8306,7 @@ fn zirRetCoerce(...@@ -8026,7 +8306,7 @@ fn zirRetCoerce(
8026 return sema.analyzeRet(block, operand, src, true);8306 return sema.analyzeRet(block, operand, src, true);
8027}8307}
80288308
8029fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {8309fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {
8030 const tracy = trace(@src());8310 const tracy = trace(@src());
8031 defer tracy.end();8311 defer tracy.end();
80328312
...@@ -8041,7 +8321,7 @@ fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -8041,7 +8321,7 @@ fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
8041 return sema.analyzeRet(block, operand, src, false);8321 return sema.analyzeRet(block, operand, src, false);
8042}8322}
80438323
8044fn zirRetLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {8324fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {
8045 const tracy = trace(@src());8325 const tracy = trace(@src());
8046 defer tracy.end();8326 defer tracy.end();
80478327
...@@ -8058,7 +8338,7 @@ fn zirRetLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -8058,7 +8338,7 @@ fn zirRetLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
80588338
8059fn analyzeRet(8339fn analyzeRet(
8060 sema: *Sema,8340 sema: *Sema,
8061 block: *Scope.Block,8341 block: *Block,
8062 uncasted_operand: Air.Inst.Ref,8342 uncasted_operand: Air.Inst.Ref,
8063 src: LazySrcLoc,8343 src: LazySrcLoc,
8064 need_coercion: bool,8344 need_coercion: bool,
...@@ -8091,7 +8371,7 @@ fn floatOpAllowed(tag: Zir.Inst.Tag) bool {...@@ -8091,7 +8371,7 @@ fn floatOpAllowed(tag: Zir.Inst.Tag) bool {
8091 };8371 };
8092}8372}
80938373
8094fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8374fn zirPtrTypeSimple(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8095 const tracy = trace(@src());8375 const tracy = trace(@src());
8096 defer tracy.end();8376 defer tracy.end();
80978377
...@@ -8108,7 +8388,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp...@@ -8108,7 +8388,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Comp
8108 return sema.addType(ty);8388 return sema.addType(ty);
8109}8389}
81108390
8111fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8391fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8112 const tracy = trace(@src());8392 const tracy = trace(@src());
8113 defer tracy.end();8393 defer tracy.end();
81148394
...@@ -8168,7 +8448,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -8168,7 +8448,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
8168 return sema.addType(ty);8448 return sema.addType(ty);
8169}8449}
81708450
8171fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8451fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8172 const tracy = trace(@src());8452 const tracy = trace(@src());
8173 defer tracy.end();8453 defer tracy.end();
81748454
...@@ -8179,13 +8459,13 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co...@@ -8179,13 +8459,13 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co
8179 return sema.addConstant(struct_type, Value.initTag(.empty_struct_value));8459 return sema.addConstant(struct_type, Value.initTag(.empty_struct_value));
8180}8460}
81818461
8182fn zirUnionInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8462fn zirUnionInitPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8183 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;8463 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8184 const src = inst_data.src();8464 const src = inst_data.src();
8185 return sema.fail(block, src, "TODO: Sema.zirUnionInitPtr", .{});8465 return sema.fail(block, src, "TODO: Sema.zirUnionInitPtr", .{});
8186}8466}
81878467
8188fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref {8468fn zirStructInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref {
8189 const gpa = sema.gpa;8469 const gpa = sema.gpa;
8190 const zir_datas = sema.code.instructions.items(.data);8470 const zir_datas = sema.code.instructions.items(.data);
8191 const inst_data = zir_datas[inst].pl_node;8471 const inst_data = zir_datas[inst].pl_node;
...@@ -8326,7 +8606,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:...@@ -8326,7 +8606,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
8326 unreachable;8606 unreachable;
8327}8607}
83288608
8329fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref {8609fn zirStructInitAnon(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref {
8330 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;8610 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8331 const src = inst_data.src();8611 const src = inst_data.src();
83328612
...@@ -8334,7 +8614,7 @@ fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_...@@ -8334,7 +8614,7 @@ fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_
8334 return sema.fail(block, src, "TODO: Sema.zirStructInitAnon", .{});8614 return sema.fail(block, src, "TODO: Sema.zirStructInitAnon", .{});
8335}8615}
83368616
8337fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref {8617fn zirArrayInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref {
8338 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;8618 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8339 const src = inst_data.src();8619 const src = inst_data.src();
83408620
...@@ -8386,7 +8666,7 @@ fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:...@@ -8386,7 +8666,7 @@ fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
8386 try sema.analyzeLoad(block, .unneeded, alloc, .unneeded);8666 try sema.analyzeLoad(block, .unneeded, alloc, .unneeded);
8387}8667}
83888668
8389fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref {8669fn zirArrayInitAnon(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref {
8390 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;8670 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8391 const src = inst_data.src();8671 const src = inst_data.src();
83928672
...@@ -8394,13 +8674,13 @@ fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_r...@@ -8394,13 +8674,13 @@ fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_r
8394 return sema.fail(block, src, "TODO: Sema.zirArrayInitAnon", .{});8674 return sema.fail(block, src, "TODO: Sema.zirArrayInitAnon", .{});
8395}8675}
83968676
8397fn zirFieldTypeRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8677fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8398 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;8678 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8399 const src = inst_data.src();8679 const src = inst_data.src();
8400 return sema.fail(block, src, "TODO: Sema.zirFieldTypeRef", .{});8680 return sema.fail(block, src, "TODO: Sema.zirFieldTypeRef", .{});
8401}8681}
84028682
8403fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8683fn zirFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8404 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;8684 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8405 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;8685 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
8406 const src = inst_data.src();8686 const src = inst_data.src();
...@@ -8428,7 +8708,7 @@ fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE...@@ -8428,7 +8708,7 @@ fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
84288708
8429fn zirErrorReturnTrace(8709fn zirErrorReturnTrace(
8430 sema: *Sema,8710 sema: *Sema,
8431 block: *Scope.Block,8711 block: *Block,
8432 extended: Zir.Inst.Extended.InstData,8712 extended: Zir.Inst.Extended.InstData,
8433) CompileError!Air.Inst.Ref {8713) CompileError!Air.Inst.Ref {
8434 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };8714 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
...@@ -8437,7 +8717,7 @@ fn zirErrorReturnTrace(...@@ -8437,7 +8717,7 @@ fn zirErrorReturnTrace(
84378717
8438fn zirFrame(8718fn zirFrame(
8439 sema: *Sema,8719 sema: *Sema,
8440 block: *Scope.Block,8720 block: *Block,
8441 extended: Zir.Inst.Extended.InstData,8721 extended: Zir.Inst.Extended.InstData,
8442) CompileError!Air.Inst.Ref {8722) CompileError!Air.Inst.Ref {
8443 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };8723 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
...@@ -8446,14 +8726,14 @@ fn zirFrame(...@@ -8446,14 +8726,14 @@ fn zirFrame(
84468726
8447fn zirFrameAddress(8727fn zirFrameAddress(
8448 sema: *Sema,8728 sema: *Sema,
8449 block: *Scope.Block,8729 block: *Block,
8450 extended: Zir.Inst.Extended.InstData,8730 extended: Zir.Inst.Extended.InstData,
8451) CompileError!Air.Inst.Ref {8731) CompileError!Air.Inst.Ref {
8452 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };8732 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
8453 return sema.fail(block, src, "TODO: Sema.zirFrameAddress", .{});8733 return sema.fail(block, src, "TODO: Sema.zirFrameAddress", .{});
8454}8734}
84558735
8456fn zirAlignOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8736fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8457 const inst_data = sema.code.instructions.items(.data)[inst].un_node;8737 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8458 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };8738 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
8459 const ty = try sema.resolveType(block, operand_src, inst_data.operand);8739 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
...@@ -8462,7 +8742,7 @@ fn zirAlignOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -8462,7 +8742,7 @@ fn zirAlignOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
8462 return sema.addIntUnsigned(Type.comptime_int, abi_align);8742 return sema.addIntUnsigned(Type.comptime_int, abi_align);
8463}8743}
84648744
8465fn zirBoolToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8745fn zirBoolToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8466 const inst_data = sema.code.instructions.items(.data)[inst].un_node;8746 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8467 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };8747 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
8468 const operand = sema.resolveInst(inst_data.operand);8748 const operand = sema.resolveInst(inst_data.operand);
...@@ -8474,31 +8754,31 @@ fn zirBoolToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE...@@ -8474,31 +8754,31 @@ fn zirBoolToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
8474 return block.addUnOp(.bool_to_int, operand);8754 return block.addUnOp(.bool_to_int, operand);
8475}8755}
84768756
8477fn zirEmbedFile(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8757fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8478 const inst_data = sema.code.instructions.items(.data)[inst].un_node;8758 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8479 const src = inst_data.src();8759 const src = inst_data.src();
8480 return sema.fail(block, src, "TODO: Sema.zirEmbedFile", .{});8760 return sema.fail(block, src, "TODO: Sema.zirEmbedFile", .{});
8481}8761}
84828762
8483fn zirErrorName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8763fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8484 const inst_data = sema.code.instructions.items(.data)[inst].un_node;8764 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8485 const src = inst_data.src();8765 const src = inst_data.src();
8486 return sema.fail(block, src, "TODO: Sema.zirErrorName", .{});8766 return sema.fail(block, src, "TODO: Sema.zirErrorName", .{});
8487}8767}
84888768
8489fn zirUnaryMath(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8769fn zirUnaryMath(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8490 const inst_data = sema.code.instructions.items(.data)[inst].un_node;8770 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8491 const src = inst_data.src();8771 const src = inst_data.src();
8492 return sema.fail(block, src, "TODO: Sema.zirUnaryMath", .{});8772 return sema.fail(block, src, "TODO: Sema.zirUnaryMath", .{});
8493}8773}
84948774
8495fn zirTagName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8775fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8496 const inst_data = sema.code.instructions.items(.data)[inst].un_node;8776 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8497 const src = inst_data.src();8777 const src = inst_data.src();
8498 return sema.fail(block, src, "TODO: Sema.zirTagName", .{});8778 return sema.fail(block, src, "TODO: Sema.zirTagName", .{});
8499}8779}
85008780
8501fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8781fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8502 const inst_data = sema.code.instructions.items(.data)[inst].un_node;8782 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8503 const src = inst_data.src();8783 const src = inst_data.src();
8504 const type_info_ty = try sema.getBuiltinType(block, src, "TypeInfo");8784 const type_info_ty = try sema.getBuiltinType(block, src, "TypeInfo");
...@@ -8551,32 +8831,32 @@ fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError...@@ -8551,32 +8831,32 @@ fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError
8551 }8831 }
8552}8832}
85538833
8554fn zirTypeName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8834fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8555 const inst_data = sema.code.instructions.items(.data)[inst].un_node;8835 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8556 const src = inst_data.src();8836 const src = inst_data.src();
8557 return sema.fail(block, src, "TODO: Sema.zirTypeName", .{});8837 return sema.fail(block, src, "TODO: Sema.zirTypeName", .{});
8558}8838}
85598839
8560fn zirFrameType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8840fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8561 const inst_data = sema.code.instructions.items(.data)[inst].un_node;8841 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8562 const src = inst_data.src();8842 const src = inst_data.src();
8563 return sema.fail(block, src, "TODO: Sema.zirFrameType", .{});8843 return sema.fail(block, src, "TODO: Sema.zirFrameType", .{});
8564}8844}
85658845
8566fn zirFrameSize(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8846fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8567 const inst_data = sema.code.instructions.items(.data)[inst].un_node;8847 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8568 const src = inst_data.src();8848 const src = inst_data.src();
8569 return sema.fail(block, src, "TODO: Sema.zirFrameSize", .{});8849 return sema.fail(block, src, "TODO: Sema.zirFrameSize", .{});
8570}8850}
85718851
8572fn zirFloatToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8852fn zirFloatToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8573 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;8853 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8574 const src = inst_data.src();8854 const src = inst_data.src();
8575 // TODO don't forget the safety check!8855 // TODO don't forget the safety check!
8576 return sema.fail(block, src, "TODO: Sema.zirFloatToInt", .{});8856 return sema.fail(block, src, "TODO: Sema.zirFloatToInt", .{});
8577}8857}
85788858
8579fn zirIntToFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8859fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8580 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;8860 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8581 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8861 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8582 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };8862 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
...@@ -8598,7 +8878,7 @@ fn zirIntToFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile...@@ -8598,7 +8878,7 @@ fn zirIntToFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile
8598 return block.addTyOp(.int_to_float, dest_ty, operand);8878 return block.addTyOp(.int_to_float, dest_ty, operand);
8599}8879}
86008880
8601fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8881fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8602 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;8882 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8603 const src = inst_data.src();8883 const src = inst_data.src();
86048884
...@@ -8654,13 +8934,13 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -8654,13 +8934,13 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
8654 return block.addTyOp(.bitcast, type_res, operand_coerced);8934 return block.addTyOp(.bitcast, type_res, operand_coerced);
8655}8935}
86568936
8657fn zirErrSetCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8937fn zirErrSetCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8658 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;8938 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8659 const src = inst_data.src();8939 const src = inst_data.src();
8660 return sema.fail(block, src, "TODO: Sema.zirErrSetCast", .{});8940 return sema.fail(block, src, "TODO: Sema.zirErrSetCast", .{});
8661}8941}
86628942
8663fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8943fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8664 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;8944 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8665 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };8945 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
8666 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };8946 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
...@@ -8684,7 +8964,7 @@ fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -8684,7 +8964,7 @@ fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
8684 return block.addTyOp(.bitcast, dest_ty, operand);8964 return block.addTyOp(.bitcast, dest_ty, operand);
8685}8965}
86868966
8687fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8967fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8688 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;8968 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8689 const src = inst_data.src();8969 const src = inst_data.src();
8690 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };8970 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
...@@ -8744,13 +9024,13 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -8744,13 +9024,13 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
8744 return block.addTyOp(.trunc, dest_ty, operand);9024 return block.addTyOp(.trunc, dest_ty, operand);
8745}9025}
87469026
8747fn zirAlignCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9027fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8748 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9028 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8749 const src = inst_data.src();9029 const src = inst_data.src();
8750 return sema.fail(block, src, "TODO: Sema.zirAlignCast", .{});9030 return sema.fail(block, src, "TODO: Sema.zirAlignCast", .{});
8751}9031}
87529032
8753fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9033fn zirClz(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8754 const inst_data = sema.code.instructions.items(.data)[inst].un_node;9034 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8755 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };9035 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
8756 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };9036 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
...@@ -8777,7 +9057,7 @@ fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A...@@ -8777,7 +9057,7 @@ fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A
8777 return block.addTyOp(.clz, result_ty, operand);9057 return block.addTyOp(.clz, result_ty, operand);
8778}9058}
87799059
8780fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9060fn zirCtz(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8781 const inst_data = sema.code.instructions.items(.data)[inst].un_node;9061 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8782 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };9062 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
8783 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };9063 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
...@@ -8804,62 +9084,62 @@ fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A...@@ -8804,62 +9084,62 @@ fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A
8804 return block.addTyOp(.ctz, result_ty, operand);9084 return block.addTyOp(.ctz, result_ty, operand);
8805}9085}
88069086
8807fn zirPopCount(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9087fn zirPopCount(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8808 const inst_data = sema.code.instructions.items(.data)[inst].un_node;9088 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8809 const src = inst_data.src();9089 const src = inst_data.src();
8810 return sema.fail(block, src, "TODO: Sema.zirPopCount", .{});9090 return sema.fail(block, src, "TODO: Sema.zirPopCount", .{});
8811}9091}
88129092
8813fn zirByteSwap(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9093fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8814 const inst_data = sema.code.instructions.items(.data)[inst].un_node;9094 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8815 const src = inst_data.src();9095 const src = inst_data.src();
8816 return sema.fail(block, src, "TODO: Sema.zirByteSwap", .{});9096 return sema.fail(block, src, "TODO: Sema.zirByteSwap", .{});
8817}9097}
88189098
8819fn zirBitReverse(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9099fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8820 const inst_data = sema.code.instructions.items(.data)[inst].un_node;9100 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8821 const src = inst_data.src();9101 const src = inst_data.src();
8822 return sema.fail(block, src, "TODO: Sema.zirBitReverse", .{});9102 return sema.fail(block, src, "TODO: Sema.zirBitReverse", .{});
8823}9103}
88249104
8825fn zirDivExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9105fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8826 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9106 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8827 const src = inst_data.src();9107 const src = inst_data.src();
8828 return sema.fail(block, src, "TODO: Sema.zirDivExact", .{});9108 return sema.fail(block, src, "TODO: Sema.zirDivExact", .{});
8829}9109}
88309110
8831fn zirDivFloor(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9111fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8832 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9112 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8833 const src = inst_data.src();9113 const src = inst_data.src();
8834 return sema.fail(block, src, "TODO: Sema.zirDivFloor", .{});9114 return sema.fail(block, src, "TODO: Sema.zirDivFloor", .{});
8835}9115}
88369116
8837fn zirDivTrunc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9117fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8838 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9118 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8839 const src = inst_data.src();9119 const src = inst_data.src();
8840 return sema.fail(block, src, "TODO: Sema.zirDivTrunc", .{});9120 return sema.fail(block, src, "TODO: Sema.zirDivTrunc", .{});
8841}9121}
88429122
8843fn zirShrExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9123fn zirShrExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8844 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9124 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8845 const src = inst_data.src();9125 const src = inst_data.src();
8846 return sema.fail(block, src, "TODO: Sema.zirShrExact", .{});9126 return sema.fail(block, src, "TODO: Sema.zirShrExact", .{});
8847}9127}
88489128
8849fn zirBitOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9129fn zirBitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8850 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9130 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8851 const src = inst_data.src();9131 const src = inst_data.src();
8852 return sema.fail(block, src, "TODO: Sema.zirBitOffsetOf", .{});9132 return sema.fail(block, src, "TODO: Sema.zirBitOffsetOf", .{});
8853}9133}
88549134
8855fn zirOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9135fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8856 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9136 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8857 const src = inst_data.src();9137 const src = inst_data.src();
8858 return sema.fail(block, src, "TODO: Sema.zirOffsetOf", .{});9138 return sema.fail(block, src, "TODO: Sema.zirOffsetOf", .{});
8859}9139}
88609140
8861/// Returns `true` if the type was a comptime_int.9141/// Returns `true` if the type was a comptime_int.
8862fn checkIntType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) CompileError!bool {9142fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {
8863 switch (ty.zigTypeTag()) {9143 switch (ty.zigTypeTag()) {
8864 .ComptimeInt => return true,9144 .ComptimeInt => return true,
8865 .Int => return false,9145 .Int => return false,
...@@ -8869,7 +9149,7 @@ fn checkIntType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) Com...@@ -8869,7 +9149,7 @@ fn checkIntType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) Com
88699149
8870fn checkFloatType(9150fn checkFloatType(
8871 sema: *Sema,9151 sema: *Sema,
8872 block: *Scope.Block,9152 block: *Block,
8873 ty_src: LazySrcLoc,9153 ty_src: LazySrcLoc,
8874 ty: Type,9154 ty: Type,
8875) CompileError!void {9155) CompileError!void {
...@@ -8883,7 +9163,7 @@ fn checkFloatType(...@@ -8883,7 +9163,7 @@ fn checkFloatType(
88839163
8884fn checkAtomicOperandType(9164fn checkAtomicOperandType(
8885 sema: *Sema,9165 sema: *Sema,
8886 block: *Scope.Block,9166 block: *Block,
8887 ty_src: LazySrcLoc,9167 ty_src: LazySrcLoc,
8888 ty: Type,9168 ty: Type,
8889) CompileError!void {9169) CompileError!void {
...@@ -8930,7 +9210,7 @@ fn checkAtomicOperandType(...@@ -8930,7 +9210,7 @@ fn checkAtomicOperandType(
89309210
8931fn resolveExportOptions(9211fn resolveExportOptions(
8932 sema: *Sema,9212 sema: *Sema,
8933 block: *Scope.Block,9213 block: *Block,
8934 src: LazySrcLoc,9214 src: LazySrcLoc,
8935 zir_ref: Zir.Inst.Ref,9215 zir_ref: Zir.Inst.Ref,
8936) CompileError!std.builtin.ExportOptions {9216) CompileError!std.builtin.ExportOptions {
...@@ -8955,7 +9235,7 @@ fn resolveExportOptions(...@@ -8955,7 +9235,7 @@ fn resolveExportOptions(
89559235
8956fn resolveAtomicOrder(9236fn resolveAtomicOrder(
8957 sema: *Sema,9237 sema: *Sema,
8958 block: *Scope.Block,9238 block: *Block,
8959 src: LazySrcLoc,9239 src: LazySrcLoc,
8960 zir_ref: Zir.Inst.Ref,9240 zir_ref: Zir.Inst.Ref,
8961) CompileError!std.builtin.AtomicOrder {9241) CompileError!std.builtin.AtomicOrder {
...@@ -8968,7 +9248,7 @@ fn resolveAtomicOrder(...@@ -8968,7 +9248,7 @@ fn resolveAtomicOrder(
89689248
8969fn resolveAtomicRmwOp(9249fn resolveAtomicRmwOp(
8970 sema: *Sema,9250 sema: *Sema,
8971 block: *Scope.Block,9251 block: *Block,
8972 src: LazySrcLoc,9252 src: LazySrcLoc,
8973 zir_ref: Zir.Inst.Ref,9253 zir_ref: Zir.Inst.Ref,
8974) CompileError!std.builtin.AtomicRmwOp {9254) CompileError!std.builtin.AtomicRmwOp {
...@@ -8981,7 +9261,7 @@ fn resolveAtomicRmwOp(...@@ -8981,7 +9261,7 @@ fn resolveAtomicRmwOp(
89819261
8982fn zirCmpxchg(9262fn zirCmpxchg(
8983 sema: *Sema,9263 sema: *Sema,
8984 block: *Scope.Block,9264 block: *Block,
8985 inst: Zir.Inst.Index,9265 inst: Zir.Inst.Index,
8986 air_tag: Air.Inst.Tag,9266 air_tag: Air.Inst.Tag,
8987) CompileError!Air.Inst.Ref {9267) CompileError!Air.Inst.Ref {
...@@ -9069,31 +9349,31 @@ fn zirCmpxchg(...@@ -9069,31 +9349,31 @@ fn zirCmpxchg(
9069 });9349 });
9070}9350}
90719351
9072fn zirSplat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9352fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9073 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9353 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9074 const src = inst_data.src();9354 const src = inst_data.src();
9075 return sema.fail(block, src, "TODO: Sema.zirSplat", .{});9355 return sema.fail(block, src, "TODO: Sema.zirSplat", .{});
9076}9356}
90779357
9078fn zirReduce(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9358fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9079 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9359 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9080 const src = inst_data.src();9360 const src = inst_data.src();
9081 return sema.fail(block, src, "TODO: Sema.zirReduce", .{});9361 return sema.fail(block, src, "TODO: Sema.zirReduce", .{});
9082}9362}
90839363
9084fn zirShuffle(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9364fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9085 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9365 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9086 const src = inst_data.src();9366 const src = inst_data.src();
9087 return sema.fail(block, src, "TODO: Sema.zirShuffle", .{});9367 return sema.fail(block, src, "TODO: Sema.zirShuffle", .{});
9088}9368}
90899369
9090fn zirSelect(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9370fn zirSelect(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9091 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9371 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9092 const src = inst_data.src();9372 const src = inst_data.src();
9093 return sema.fail(block, src, "TODO: Sema.zirSelect", .{});9373 return sema.fail(block, src, "TODO: Sema.zirSelect", .{});
9094}9374}
90959375
9096fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9376fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9097 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9377 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9098 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;9378 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
9099 // zig fmt: off9379 // zig fmt: off
...@@ -9138,7 +9418,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile...@@ -9138,7 +9418,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile
9138 });9418 });
9139}9419}
91409420
9141fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9421fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9142 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9422 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9143 const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;9423 const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;
9144 const src = inst_data.src();9424 const src = inst_data.src();
...@@ -9216,7 +9496,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE...@@ -9216,7 +9496,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
9216 });9496 });
9217}9497}
92189498
9219fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {9499fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
9220 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9500 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9221 const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data;9501 const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data;
9222 const src = inst_data.src();9502 const src = inst_data.src();
...@@ -9250,37 +9530,37 @@ fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil...@@ -9250,37 +9530,37 @@ fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil
9250 return sema.storePtr2(block, src, ptr, ptr_src, operand, operand_src, air_tag);9530 return sema.storePtr2(block, src, ptr, ptr_src, operand, operand_src, air_tag);
9251}9531}
92529532
9253fn zirMulAdd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9533fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9254 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9534 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9255 const src = inst_data.src();9535 const src = inst_data.src();
9256 return sema.fail(block, src, "TODO: Sema.zirMulAdd", .{});9536 return sema.fail(block, src, "TODO: Sema.zirMulAdd", .{});
9257}9537}
92589538
9259fn zirBuiltinCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9539fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9260 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9540 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9261 const src = inst_data.src();9541 const src = inst_data.src();
9262 return sema.fail(block, src, "TODO: Sema.zirBuiltinCall", .{});9542 return sema.fail(block, src, "TODO: Sema.zirBuiltinCall", .{});
9263}9543}
92649544
9265fn zirFieldPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9545fn zirFieldPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9266 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9546 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9267 const src = inst_data.src();9547 const src = inst_data.src();
9268 return sema.fail(block, src, "TODO: Sema.zirFieldPtrType", .{});9548 return sema.fail(block, src, "TODO: Sema.zirFieldPtrType", .{});
9269}9549}
92709550
9271fn zirFieldParentPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9551fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9272 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9552 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9273 const src = inst_data.src();9553 const src = inst_data.src();
9274 return sema.fail(block, src, "TODO: Sema.zirFieldParentPtr", .{});9554 return sema.fail(block, src, "TODO: Sema.zirFieldParentPtr", .{});
9275}9555}
92769556
9277fn zirMaximum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9557fn zirMaximum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9278 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9558 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9279 const src = inst_data.src();9559 const src = inst_data.src();
9280 return sema.fail(block, src, "TODO: Sema.zirMaximum", .{});9560 return sema.fail(block, src, "TODO: Sema.zirMaximum", .{});
9281}9561}
92829562
9283fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {9563fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
9284 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9564 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9285 const extra = sema.code.extraData(Zir.Inst.Memcpy, inst_data.payload_index).data;9565 const extra = sema.code.extraData(Zir.Inst.Memcpy, inst_data.payload_index).data;
9286 const src = inst_data.src();9566 const src = inst_data.src();
...@@ -9345,7 +9625,7 @@ fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro...@@ -9345,7 +9625,7 @@ fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
9345 });9625 });
9346}9626}
93479627
9348fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {9628fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
9349 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9629 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9350 const extra = sema.code.extraData(Zir.Inst.Memset, inst_data.payload_index).data;9630 const extra = sema.code.extraData(Zir.Inst.Memset, inst_data.payload_index).data;
9351 const src = inst_data.src();9631 const src = inst_data.src();
...@@ -9391,19 +9671,19 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro...@@ -9391,19 +9671,19 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
9391 });9671 });
9392}9672}
93939673
9394fn zirMinimum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9674fn zirMinimum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9395 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9675 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9396 const src = inst_data.src();9676 const src = inst_data.src();
9397 return sema.fail(block, src, "TODO: Sema.zirMinimum", .{});9677 return sema.fail(block, src, "TODO: Sema.zirMinimum", .{});
9398}9678}
93999679
9400fn zirBuiltinAsyncCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9680fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9401 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;9681 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9402 const src = inst_data.src();9682 const src = inst_data.src();
9403 return sema.fail(block, src, "TODO: Sema.zirBuiltinAsyncCall", .{});9683 return sema.fail(block, src, "TODO: Sema.zirBuiltinAsyncCall", .{});
9404}9684}
94059685
9406fn zirResume(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9686fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9407 const inst_data = sema.code.instructions.items(.data)[inst].un_node;9687 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
9408 const src = inst_data.src();9688 const src = inst_data.src();
9409 return sema.fail(block, src, "TODO: Sema.zirResume", .{});9689 return sema.fail(block, src, "TODO: Sema.zirResume", .{});
...@@ -9411,7 +9691,7 @@ fn zirResume(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro...@@ -9411,7 +9691,7 @@ fn zirResume(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
94119691
9412fn zirAwait(9692fn zirAwait(
9413 sema: *Sema,9693 sema: *Sema,
9414 block: *Scope.Block,9694 block: *Block,
9415 inst: Zir.Inst.Index,9695 inst: Zir.Inst.Index,
9416 is_nosuspend: bool,9696 is_nosuspend: bool,
9417) CompileError!Air.Inst.Ref {9697) CompileError!Air.Inst.Ref {
...@@ -9424,7 +9704,7 @@ fn zirAwait(...@@ -9424,7 +9704,7 @@ fn zirAwait(
94249704
9425fn zirVarExtended(9705fn zirVarExtended(
9426 sema: *Sema,9706 sema: *Sema,
9427 block: *Scope.Block,9707 block: *Block,
9428 extended: Zir.Inst.Extended.InstData,9708 extended: Zir.Inst.Extended.InstData,
9429) CompileError!Air.Inst.Ref {9709) CompileError!Air.Inst.Ref {
9430 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);9710 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
...@@ -9499,7 +9779,7 @@ fn zirVarExtended(...@@ -9499,7 +9779,7 @@ fn zirVarExtended(
94999779
9500fn zirFuncExtended(9780fn zirFuncExtended(
9501 sema: *Sema,9781 sema: *Sema,
9502 block: *Scope.Block,9782 block: *Block,
9503 extended: Zir.Inst.Extended.InstData,9783 extended: Zir.Inst.Extended.InstData,
9504 inst: Zir.Inst.Index,9784 inst: Zir.Inst.Index,
9505) CompileError!Air.Inst.Ref {9785) CompileError!Air.Inst.Ref {
...@@ -9566,7 +9846,7 @@ fn zirFuncExtended(...@@ -9566,7 +9846,7 @@ fn zirFuncExtended(
95669846
9567fn zirCUndef(9847fn zirCUndef(
9568 sema: *Sema,9848 sema: *Sema,
9569 block: *Scope.Block,9849 block: *Block,
9570 extended: Zir.Inst.Extended.InstData,9850 extended: Zir.Inst.Extended.InstData,
9571) CompileError!Air.Inst.Ref {9851) CompileError!Air.Inst.Ref {
9572 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;9852 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
...@@ -9579,7 +9859,7 @@ fn zirCUndef(...@@ -9579,7 +9859,7 @@ fn zirCUndef(
95799859
9580fn zirCInclude(9860fn zirCInclude(
9581 sema: *Sema,9861 sema: *Sema,
9582 block: *Scope.Block,9862 block: *Block,
9583 extended: Zir.Inst.Extended.InstData,9863 extended: Zir.Inst.Extended.InstData,
9584) CompileError!Air.Inst.Ref {9864) CompileError!Air.Inst.Ref {
9585 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;9865 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
...@@ -9592,7 +9872,7 @@ fn zirCInclude(...@@ -9592,7 +9872,7 @@ fn zirCInclude(
95929872
9593fn zirCDefine(9873fn zirCDefine(
9594 sema: *Sema,9874 sema: *Sema,
9595 block: *Scope.Block,9875 block: *Block,
9596 extended: Zir.Inst.Extended.InstData,9876 extended: Zir.Inst.Extended.InstData,
9597) CompileError!Air.Inst.Ref {9877) CompileError!Air.Inst.Ref {
9598 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;9878 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
...@@ -9610,7 +9890,7 @@ fn zirCDefine(...@@ -9610,7 +9890,7 @@ fn zirCDefine(
96109890
9611fn zirWasmMemorySize(9891fn zirWasmMemorySize(
9612 sema: *Sema,9892 sema: *Sema,
9613 block: *Scope.Block,9893 block: *Block,
9614 extended: Zir.Inst.Extended.InstData,9894 extended: Zir.Inst.Extended.InstData,
9615) CompileError!Air.Inst.Ref {9895) CompileError!Air.Inst.Ref {
9616 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;9896 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
...@@ -9620,7 +9900,7 @@ fn zirWasmMemorySize(...@@ -9620,7 +9900,7 @@ fn zirWasmMemorySize(
96209900
9621fn zirWasmMemoryGrow(9901fn zirWasmMemoryGrow(
9622 sema: *Sema,9902 sema: *Sema,
9623 block: *Scope.Block,9903 block: *Block,
9624 extended: Zir.Inst.Extended.InstData,9904 extended: Zir.Inst.Extended.InstData,
9625) CompileError!Air.Inst.Ref {9905) CompileError!Air.Inst.Ref {
9626 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;9906 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
...@@ -9630,7 +9910,7 @@ fn zirWasmMemoryGrow(...@@ -9630,7 +9910,7 @@ fn zirWasmMemoryGrow(
96309910
9631fn zirBuiltinExtern(9911fn zirBuiltinExtern(
9632 sema: *Sema,9912 sema: *Sema,
9633 block: *Scope.Block,9913 block: *Block,
9634 extended: Zir.Inst.Extended.InstData,9914 extended: Zir.Inst.Extended.InstData,
9635) CompileError!Air.Inst.Ref {9915) CompileError!Air.Inst.Ref {
9636 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;9916 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
...@@ -9638,13 +9918,13 @@ fn zirBuiltinExtern(...@@ -9638,13 +9918,13 @@ fn zirBuiltinExtern(
9638 return sema.fail(block, src, "TODO: implement Sema.zirBuiltinExtern", .{});9918 return sema.fail(block, src, "TODO: implement Sema.zirBuiltinExtern", .{});
9639}9919}
96409920
9641fn requireFunctionBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void {9921fn requireFunctionBlock(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
9642 if (sema.func == null) {9922 if (sema.func == null) {
9643 return sema.fail(block, src, "instruction illegal outside function body", .{});9923 return sema.fail(block, src, "instruction illegal outside function body", .{});
9644 }9924 }
9645}9925}
96469926
9647fn requireRuntimeBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void {9927fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
9648 if (block.is_comptime) {9928 if (block.is_comptime) {
9649 return sema.failWithNeededComptime(block, src);9929 return sema.failWithNeededComptime(block, src);
9650 }9930 }
...@@ -9654,7 +9934,7 @@ fn requireRuntimeBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void...@@ -9654,7 +9934,7 @@ fn requireRuntimeBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void
9654/// Emit a compile error if type cannot be used for a runtime variable.9934/// Emit a compile error if type cannot be used for a runtime variable.
9655fn validateVarType(9935fn validateVarType(
9656 sema: *Sema,9936 sema: *Sema,
9657 block: *Scope.Block,9937 block: *Block,
9658 src: LazySrcLoc,9938 src: LazySrcLoc,
9659 var_ty: Type,9939 var_ty: Type,
9660 is_extern: bool,9940 is_extern: bool,
...@@ -9713,13 +9993,13 @@ pub const PanicId = enum {...@@ -9713,13 +9993,13 @@ pub const PanicId = enum {
97139993
9714fn addSafetyCheck(9994fn addSafetyCheck(
9715 sema: *Sema,9995 sema: *Sema,
9716 parent_block: *Scope.Block,9996 parent_block: *Block,
9717 ok: Air.Inst.Ref,9997 ok: Air.Inst.Ref,
9718 panic_id: PanicId,9998 panic_id: PanicId,
9719) !void {9999) !void {
9720 const gpa = sema.gpa;10000 const gpa = sema.gpa;
972110001
9722 var fail_block: Scope.Block = .{10002 var fail_block: Block = .{
9723 .parent = parent_block,10003 .parent = parent_block,
9724 .sema = sema,10004 .sema = sema,
9725 .src_decl = parent_block.src_decl,10005 .src_decl = parent_block.src_decl,
...@@ -9783,7 +10063,7 @@ fn addSafetyCheck(...@@ -9783,7 +10063,7 @@ fn addSafetyCheck(
978310063
9784fn panicWithMsg(10064fn panicWithMsg(
9785 sema: *Sema,10065 sema: *Sema,
9786 block: *Scope.Block,10066 block: *Block,
9787 src: LazySrcLoc,10067 src: LazySrcLoc,
9788 msg_inst: Air.Inst.Ref,10068 msg_inst: Air.Inst.Ref,
9789) !Zir.Inst.Index {10069) !Zir.Inst.Index {
...@@ -9817,7 +10097,7 @@ fn panicWithMsg(...@@ -9817,7 +10097,7 @@ fn panicWithMsg(
981710097
9818fn safetyPanic(10098fn safetyPanic(
9819 sema: *Sema,10099 sema: *Sema,
9820 block: *Scope.Block,10100 block: *Block,
9821 src: LazySrcLoc,10101 src: LazySrcLoc,
9822 panic_id: PanicId,10102 panic_id: PanicId,
9823) CompileError!Zir.Inst.Index {10103) CompileError!Zir.Inst.Index {
...@@ -9845,7 +10125,7 @@ fn safetyPanic(...@@ -9845,7 +10125,7 @@ fn safetyPanic(
9845 return sema.panicWithMsg(block, src, casted_msg_inst);10125 return sema.panicWithMsg(block, src, casted_msg_inst);
9846}10126}
984710127
9848fn emitBackwardBranch(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void {10128fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
9849 sema.branch_count += 1;10129 sema.branch_count += 1;
9850 if (sema.branch_count > sema.branch_quota) {10130 if (sema.branch_count > sema.branch_quota) {
9851 // TODO show the "called from here" stack10131 // TODO show the "called from here" stack
...@@ -9855,7 +10135,7 @@ fn emitBackwardBranch(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void {...@@ -9855,7 +10135,7 @@ fn emitBackwardBranch(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void {
985510135
9856fn fieldVal(10136fn fieldVal(
9857 sema: *Sema,10137 sema: *Sema,
9858 block: *Scope.Block,10138 block: *Block,
9859 src: LazySrcLoc,10139 src: LazySrcLoc,
9860 object: Air.Inst.Ref,10140 object: Air.Inst.Ref,
9861 field_name: []const u8,10141 field_name: []const u8,
...@@ -10036,7 +10316,7 @@ fn fieldVal(...@@ -10036,7 +10316,7 @@ fn fieldVal(
1003610316
10037fn fieldPtr(10317fn fieldPtr(
10038 sema: *Sema,10318 sema: *Sema,
10039 block: *Scope.Block,10319 block: *Block,
10040 src: LazySrcLoc,10320 src: LazySrcLoc,
10041 object_ptr: Air.Inst.Ref,10321 object_ptr: Air.Inst.Ref,
10042 field_name: []const u8,10322 field_name: []const u8,
...@@ -10227,7 +10507,7 @@ fn fieldPtr(...@@ -10227,7 +10507,7 @@ fn fieldPtr(
1022710507
10228fn fieldCallBind(10508fn fieldCallBind(
10229 sema: *Sema,10509 sema: *Sema,
10230 block: *Scope.Block,10510 block: *Block,
10231 src: LazySrcLoc,10511 src: LazySrcLoc,
10232 raw_ptr: Air.Inst.Ref,10512 raw_ptr: Air.Inst.Ref,
10233 field_name: []const u8,10513 field_name: []const u8,
...@@ -10368,9 +10648,9 @@ fn fieldCallBind(...@@ -10368,9 +10648,9 @@ fn fieldCallBind(
1036810648
10369fn namespaceLookup(10649fn namespaceLookup(
10370 sema: *Sema,10650 sema: *Sema,
10371 block: *Scope.Block,10651 block: *Block,
10372 src: LazySrcLoc,10652 src: LazySrcLoc,
10373 namespace: *Scope.Namespace,10653 namespace: *Namespace,
10374 decl_name: []const u8,10654 decl_name: []const u8,
10375) CompileError!?*Decl {10655) CompileError!?*Decl {
10376 const gpa = sema.gpa;10656 const gpa = sema.gpa;
...@@ -10393,9 +10673,9 @@ fn namespaceLookup(...@@ -10393,9 +10673,9 @@ fn namespaceLookup(
1039310673
10394fn namespaceLookupRef(10674fn namespaceLookupRef(
10395 sema: *Sema,10675 sema: *Sema,
10396 block: *Scope.Block,10676 block: *Block,
10397 src: LazySrcLoc,10677 src: LazySrcLoc,
10398 namespace: *Scope.Namespace,10678 namespace: *Namespace,
10399 decl_name: []const u8,10679 decl_name: []const u8,
10400) CompileError!?Air.Inst.Ref {10680) CompileError!?Air.Inst.Ref {
10401 const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null;10681 const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null;
...@@ -10404,7 +10684,7 @@ fn namespaceLookupRef(...@@ -10404,7 +10684,7 @@ fn namespaceLookupRef(
1040410684
10405fn structFieldPtr(10685fn structFieldPtr(
10406 sema: *Sema,10686 sema: *Sema,
10407 block: *Scope.Block,10687 block: *Block,
10408 src: LazySrcLoc,10688 src: LazySrcLoc,
10409 struct_ptr: Air.Inst.Ref,10689 struct_ptr: Air.Inst.Ref,
10410 field_name: []const u8,10690 field_name: []const u8,
...@@ -10444,7 +10724,7 @@ fn structFieldPtr(...@@ -10444,7 +10724,7 @@ fn structFieldPtr(
1044410724
10445fn structFieldVal(10725fn structFieldVal(
10446 sema: *Sema,10726 sema: *Sema,
10447 block: *Scope.Block,10727 block: *Block,
10448 src: LazySrcLoc,10728 src: LazySrcLoc,
10449 struct_byval: Air.Inst.Ref,10729 struct_byval: Air.Inst.Ref,
10450 field_name: []const u8,10730 field_name: []const u8,
...@@ -10482,7 +10762,7 @@ fn structFieldVal(...@@ -10482,7 +10762,7 @@ fn structFieldVal(
1048210762
10483fn unionFieldPtr(10763fn unionFieldPtr(
10484 sema: *Sema,10764 sema: *Sema,
10485 block: *Scope.Block,10765 block: *Block,
10486 src: LazySrcLoc,10766 src: LazySrcLoc,
10487 union_ptr: Air.Inst.Ref,10767 union_ptr: Air.Inst.Ref,
10488 field_name: []const u8,10768 field_name: []const u8,
...@@ -10524,7 +10804,7 @@ fn unionFieldPtr(...@@ -10524,7 +10804,7 @@ fn unionFieldPtr(
1052410804
10525fn unionFieldVal(10805fn unionFieldVal(
10526 sema: *Sema,10806 sema: *Sema,
10527 block: *Scope.Block,10807 block: *Block,
10528 src: LazySrcLoc,10808 src: LazySrcLoc,
10529 union_byval: Air.Inst.Ref,10809 union_byval: Air.Inst.Ref,
10530 field_name: []const u8,10810 field_name: []const u8,
...@@ -10555,7 +10835,7 @@ fn unionFieldVal(...@@ -10555,7 +10835,7 @@ fn unionFieldVal(
1055510835
10556fn elemPtr(10836fn elemPtr(
10557 sema: *Sema,10837 sema: *Sema,
10558 block: *Scope.Block,10838 block: *Block,
10559 src: LazySrcLoc,10839 src: LazySrcLoc,
10560 array_ptr: Air.Inst.Ref,10840 array_ptr: Air.Inst.Ref,
10561 elem_index: Air.Inst.Ref,10841 elem_index: Air.Inst.Ref,
...@@ -10584,7 +10864,7 @@ fn elemPtr(...@@ -10584,7 +10864,7 @@ fn elemPtr(
1058410864
10585fn elemVal(10865fn elemVal(
10586 sema: *Sema,10866 sema: *Sema,
10587 block: *Scope.Block,10867 block: *Block,
10588 src: LazySrcLoc,10868 src: LazySrcLoc,
10589 array_maybe_ptr: Air.Inst.Ref,10869 array_maybe_ptr: Air.Inst.Ref,
10590 elem_index: Air.Inst.Ref,10870 elem_index: Air.Inst.Ref,
...@@ -10673,7 +10953,7 @@ fn elemVal(...@@ -10673,7 +10953,7 @@ fn elemVal(
1067310953
10674fn elemPtrArray(10954fn elemPtrArray(
10675 sema: *Sema,10955 sema: *Sema,
10676 block: *Scope.Block,10956 block: *Block,
10677 src: LazySrcLoc,10957 src: LazySrcLoc,
10678 array_ptr: Air.Inst.Ref,10958 array_ptr: Air.Inst.Ref,
10679 elem_index: Air.Inst.Ref,10959 elem_index: Air.Inst.Ref,
...@@ -10713,7 +10993,7 @@ fn elemPtrArray(...@@ -10713,7 +10993,7 @@ fn elemPtrArray(
1071310993
10714fn coerce(10994fn coerce(
10715 sema: *Sema,10995 sema: *Sema,
10716 block: *Scope.Block,10996 block: *Block,
10717 dest_type_unresolved: Type,10997 dest_type_unresolved: Type,
10718 inst: Air.Inst.Ref,10998 inst: Air.Inst.Ref,
10719 inst_src: LazySrcLoc,10999 inst_src: LazySrcLoc,
...@@ -10985,7 +11265,7 @@ fn coerceInMemoryAllowed(dest_type: Type, src_type: Type, dest_is_mut: bool, tar...@@ -10985,7 +11265,7 @@ fn coerceInMemoryAllowed(dest_type: Type, src_type: Type, dest_is_mut: bool, tar
1098511265
10986fn coerceNum(11266fn coerceNum(
10987 sema: *Sema,11267 sema: *Sema,
10988 block: *Scope.Block,11268 block: *Block,
10989 dest_type: Type,11269 dest_type: Type,
10990 inst: Air.Inst.Ref,11270 inst: Air.Inst.Ref,
10991 inst_src: LazySrcLoc,11271 inst_src: LazySrcLoc,
...@@ -11053,7 +11333,7 @@ fn coerceNum(...@@ -11053,7 +11333,7 @@ fn coerceNum(
1105311333
11054fn coerceVarArgParam(11334fn coerceVarArgParam(
11055 sema: *Sema,11335 sema: *Sema,
11056 block: *Scope.Block,11336 block: *Block,
11057 inst: Air.Inst.Ref,11337 inst: Air.Inst.Ref,
11058 inst_src: LazySrcLoc,11338 inst_src: LazySrcLoc,
11059) !Air.Inst.Ref {11339) !Air.Inst.Ref {
...@@ -11069,7 +11349,7 @@ fn coerceVarArgParam(...@@ -11069,7 +11349,7 @@ fn coerceVarArgParam(
11069// TODO migrate callsites to use storePtr2 instead.11349// TODO migrate callsites to use storePtr2 instead.
11070fn storePtr(11350fn storePtr(
11071 sema: *Sema,11351 sema: *Sema,
11072 block: *Scope.Block,11352 block: *Block,
11073 src: LazySrcLoc,11353 src: LazySrcLoc,
11074 ptr: Air.Inst.Ref,11354 ptr: Air.Inst.Ref,
11075 uncasted_operand: Air.Inst.Ref,11355 uncasted_operand: Air.Inst.Ref,
...@@ -11079,7 +11359,7 @@ fn storePtr(...@@ -11079,7 +11359,7 @@ fn storePtr(
1107911359
11080fn storePtr2(11360fn storePtr2(
11081 sema: *Sema,11361 sema: *Sema,
11082 block: *Scope.Block,11362 block: *Block,
11083 src: LazySrcLoc,11363 src: LazySrcLoc,
11084 ptr: Air.Inst.Ref,11364 ptr: Air.Inst.Ref,
11085 ptr_src: LazySrcLoc,11365 ptr_src: LazySrcLoc,
...@@ -11116,7 +11396,7 @@ fn storePtr2(...@@ -11116,7 +11396,7 @@ fn storePtr2(
11116/// assert the store must be done at comptime.11396/// assert the store must be done at comptime.
11117fn storePtrVal(11397fn storePtrVal(
11118 sema: *Sema,11398 sema: *Sema,
11119 block: *Scope.Block,11399 block: *Block,
11120 src: LazySrcLoc,11400 src: LazySrcLoc,
11121 ptr_val: Value,11401 ptr_val: Value,
11122 operand_val: Value,11402 operand_val: Value,
...@@ -11161,7 +11441,7 @@ fn storePtrVal(...@@ -11161,7 +11441,7 @@ fn storePtrVal(
1116111441
11162fn bitcast(11442fn bitcast(
11163 sema: *Sema,11443 sema: *Sema,
11164 block: *Scope.Block,11444 block: *Block,
11165 dest_type: Type,11445 dest_type: Type,
11166 inst: Air.Inst.Ref,11446 inst: Air.Inst.Ref,
11167 inst_src: LazySrcLoc,11447 inst_src: LazySrcLoc,
...@@ -11177,7 +11457,7 @@ fn bitcast(...@@ -11177,7 +11457,7 @@ fn bitcast(
1117711457
11178fn coerceArrayPtrToSlice(11458fn coerceArrayPtrToSlice(
11179 sema: *Sema,11459 sema: *Sema,
11180 block: *Scope.Block,11460 block: *Block,
11181 dest_type: Type,11461 dest_type: Type,
11182 inst: Air.Inst.Ref,11462 inst: Air.Inst.Ref,
11183 inst_src: LazySrcLoc,11463 inst_src: LazySrcLoc,
...@@ -11192,7 +11472,7 @@ fn coerceArrayPtrToSlice(...@@ -11192,7 +11472,7 @@ fn coerceArrayPtrToSlice(
1119211472
11193fn coerceArrayPtrToMany(11473fn coerceArrayPtrToMany(
11194 sema: *Sema,11474 sema: *Sema,
11195 block: *Scope.Block,11475 block: *Block,
11196 dest_type: Type,11476 dest_type: Type,
11197 inst: Air.Inst.Ref,11477 inst: Air.Inst.Ref,
11198 inst_src: LazySrcLoc,11478 inst_src: LazySrcLoc,
...@@ -11207,7 +11487,7 @@ fn coerceArrayPtrToMany(...@@ -11207,7 +11487,7 @@ fn coerceArrayPtrToMany(
1120711487
11208fn analyzeDeclVal(11488fn analyzeDeclVal(
11209 sema: *Sema,11489 sema: *Sema,
11210 block: *Scope.Block,11490 block: *Block,
11211 src: LazySrcLoc,11491 src: LazySrcLoc,
11212 decl: *Decl,11492 decl: *Decl,
11213) CompileError!Air.Inst.Ref {11493) CompileError!Air.Inst.Ref {
...@@ -11261,7 +11541,7 @@ fn analyzeDeclRef(sema: *Sema, decl: *Decl) CompileError!Air.Inst.Ref {...@@ -11261,7 +11541,7 @@ fn analyzeDeclRef(sema: *Sema, decl: *Decl) CompileError!Air.Inst.Ref {
1126111541
11262fn analyzeRef(11542fn analyzeRef(
11263 sema: *Sema,11543 sema: *Sema,
11264 block: *Scope.Block,11544 block: *Block,
11265 src: LazySrcLoc,11545 src: LazySrcLoc,
11266 operand: Air.Inst.Ref,11546 operand: Air.Inst.Ref,
11267) CompileError!Air.Inst.Ref {11547) CompileError!Air.Inst.Ref {
...@@ -11296,7 +11576,7 @@ fn analyzeRef(...@@ -11296,7 +11576,7 @@ fn analyzeRef(
1129611576
11297fn analyzeLoad(11577fn analyzeLoad(
11298 sema: *Sema,11578 sema: *Sema,
11299 block: *Scope.Block,11579 block: *Block,
11300 src: LazySrcLoc,11580 src: LazySrcLoc,
11301 ptr: Air.Inst.Ref,11581 ptr: Air.Inst.Ref,
11302 ptr_src: LazySrcLoc,11582 ptr_src: LazySrcLoc,
...@@ -11318,7 +11598,7 @@ fn analyzeLoad(...@@ -11318,7 +11598,7 @@ fn analyzeLoad(
1131811598
11319fn analyzeSliceLen(11599fn analyzeSliceLen(
11320 sema: *Sema,11600 sema: *Sema,
11321 block: *Scope.Block,11601 block: *Block,
11322 src: LazySrcLoc,11602 src: LazySrcLoc,
11323 slice_inst: Air.Inst.Ref,11603 slice_inst: Air.Inst.Ref,
11324) CompileError!Air.Inst.Ref {11604) CompileError!Air.Inst.Ref {
...@@ -11334,7 +11614,7 @@ fn analyzeSliceLen(...@@ -11334,7 +11614,7 @@ fn analyzeSliceLen(
1133411614
11335fn analyzeIsNull(11615fn analyzeIsNull(
11336 sema: *Sema,11616 sema: *Sema,
11337 block: *Scope.Block,11617 block: *Block,
11338 src: LazySrcLoc,11618 src: LazySrcLoc,
11339 operand: Air.Inst.Ref,11619 operand: Air.Inst.Ref,
11340 invert_logic: bool,11620 invert_logic: bool,
...@@ -11359,7 +11639,7 @@ fn analyzeIsNull(...@@ -11359,7 +11639,7 @@ fn analyzeIsNull(
1135911639
11360fn analyzeIsNonErr(11640fn analyzeIsNonErr(
11361 sema: *Sema,11641 sema: *Sema,
11362 block: *Scope.Block,11642 block: *Block,
11363 src: LazySrcLoc,11643 src: LazySrcLoc,
11364 operand: Air.Inst.Ref,11644 operand: Air.Inst.Ref,
11365) CompileError!Air.Inst.Ref {11645) CompileError!Air.Inst.Ref {
...@@ -11385,7 +11665,7 @@ fn analyzeIsNonErr(...@@ -11385,7 +11665,7 @@ fn analyzeIsNonErr(
1138511665
11386fn analyzeSlice(11666fn analyzeSlice(
11387 sema: *Sema,11667 sema: *Sema,
11388 block: *Scope.Block,11668 block: *Block,
11389 src: LazySrcLoc,11669 src: LazySrcLoc,
11390 array_ptr: Air.Inst.Ref,11670 array_ptr: Air.Inst.Ref,
11391 start: Air.Inst.Ref,11671 start: Air.Inst.Ref,
...@@ -11460,7 +11740,7 @@ fn analyzeSlice(...@@ -11460,7 +11740,7 @@ fn analyzeSlice(
11460/// Asserts that lhs and rhs types are both numeric.11740/// Asserts that lhs and rhs types are both numeric.
11461fn cmpNumeric(11741fn cmpNumeric(
11462 sema: *Sema,11742 sema: *Sema,
11463 block: *Scope.Block,11743 block: *Block,
11464 src: LazySrcLoc,11744 src: LazySrcLoc,
11465 lhs: Air.Inst.Ref,11745 lhs: Air.Inst.Ref,
11466 rhs: Air.Inst.Ref,11746 rhs: Air.Inst.Ref,
...@@ -11648,7 +11928,7 @@ fn cmpNumeric(...@@ -11648,7 +11928,7 @@ fn cmpNumeric(
1164811928
11649fn wrapOptional(11929fn wrapOptional(
11650 sema: *Sema,11930 sema: *Sema,
11651 block: *Scope.Block,11931 block: *Block,
11652 dest_type: Type,11932 dest_type: Type,
11653 inst: Air.Inst.Ref,11933 inst: Air.Inst.Ref,
11654 inst_src: LazySrcLoc,11934 inst_src: LazySrcLoc,
...@@ -11663,7 +11943,7 @@ fn wrapOptional(...@@ -11663,7 +11943,7 @@ fn wrapOptional(
1166311943
11664fn wrapErrorUnion(11944fn wrapErrorUnion(
11665 sema: *Sema,11945 sema: *Sema,
11666 block: *Scope.Block,11946 block: *Block,
11667 dest_type: Type,11947 dest_type: Type,
11668 inst: Air.Inst.Ref,11948 inst: Air.Inst.Ref,
11669 inst_src: LazySrcLoc,11949 inst_src: LazySrcLoc,
...@@ -11739,7 +12019,7 @@ fn wrapErrorUnion(...@@ -11739,7 +12019,7 @@ fn wrapErrorUnion(
1173912019
11740fn unionToTag(12020fn unionToTag(
11741 sema: *Sema,12021 sema: *Sema,
11742 block: *Scope.Block,12022 block: *Block,
11743 dest_type: Type,12023 dest_type: Type,
11744 un: Air.Inst.Ref,12024 un: Air.Inst.Ref,
11745 un_src: LazySrcLoc,12025 un_src: LazySrcLoc,
...@@ -11753,7 +12033,7 @@ fn unionToTag(...@@ -11753,7 +12033,7 @@ fn unionToTag(
1175312033
11754fn resolvePeerTypes(12034fn resolvePeerTypes(
11755 sema: *Sema,12035 sema: *Sema,
11756 block: *Scope.Block,12036 block: *Block,
11757 src: LazySrcLoc,12037 src: LazySrcLoc,
11758 instructions: []Air.Inst.Ref,12038 instructions: []Air.Inst.Ref,
11759 candidate_srcs: Module.PeerTypeCandidateSrc,12039 candidate_srcs: Module.PeerTypeCandidateSrc,
...@@ -11867,7 +12147,7 @@ fn resolvePeerTypes(...@@ -11867,7 +12147,7 @@ fn resolvePeerTypes(
1186712147
11868pub fn resolveTypeLayout(12148pub fn resolveTypeLayout(
11869 sema: *Sema,12149 sema: *Sema,
11870 block: *Scope.Block,12150 block: *Block,
11871 src: LazySrcLoc,12151 src: LazySrcLoc,
11872 ty: Type,12152 ty: Type,
11873) CompileError!void {12153) CompileError!void {
...@@ -11892,7 +12172,7 @@ pub fn resolveTypeLayout(...@@ -11892,7 +12172,7 @@ pub fn resolveTypeLayout(
11892 }12172 }
11893}12173}
1189412174
11895fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) CompileError!Type {12175fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!Type {
11896 switch (ty.tag()) {12176 switch (ty.tag()) {
11897 .@"struct" => {12177 .@"struct" => {
11898 const struct_obj = ty.castTag(.@"struct").?.data;12178 const struct_obj = ty.castTag(.@"struct").?.data;
...@@ -11943,7 +12223,7 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type...@@ -11943,7 +12223,7 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type
1194312223
11944fn resolveBuiltinTypeFields(12224fn resolveBuiltinTypeFields(
11945 sema: *Sema,12225 sema: *Sema,
11946 block: *Scope.Block,12226 block: *Block,
11947 src: LazySrcLoc,12227 src: LazySrcLoc,
11948 name: []const u8,12228 name: []const u8,
11949) CompileError!Type {12229) CompileError!Type {
...@@ -12021,7 +12301,7 @@ fn semaStructFields(...@@ -12021,7 +12301,7 @@ fn semaStructFields(
12021 var wip_captures = try WipCaptureScope.init(gpa, &decl_arena.allocator, decl.src_scope);12301 var wip_captures = try WipCaptureScope.init(gpa, &decl_arena.allocator, decl.src_scope);
12022 defer wip_captures.deinit();12302 defer wip_captures.deinit();
1202312303
12024 var block_scope: Scope.Block = .{12304 var block_scope: Block = .{
12025 .parent = null,12305 .parent = null,
12026 .sema = &sema,12306 .sema = &sema,
12027 .src_decl = decl,12307 .src_decl = decl,
...@@ -12191,7 +12471,7 @@ fn semaUnionFields(...@@ -12191,7 +12471,7 @@ fn semaUnionFields(
12191 var wip_captures = try WipCaptureScope.init(gpa, &decl_arena.allocator, decl.src_scope);12471 var wip_captures = try WipCaptureScope.init(gpa, &decl_arena.allocator, decl.src_scope);
12192 defer wip_captures.deinit();12472 defer wip_captures.deinit();
1219312473
12194 var block_scope: Scope.Block = .{12474 var block_scope: Block = .{
12195 .parent = null,12475 .parent = null,
12196 .sema = &sema,12476 .sema = &sema,
12197 .src_decl = decl,12477 .src_decl = decl,
...@@ -12322,7 +12602,7 @@ fn semaUnionFields(...@@ -12322,7 +12602,7 @@ fn semaUnionFields(
1232212602
12323fn generateUnionTagTypeNumbered(12603fn generateUnionTagTypeNumbered(
12324 sema: *Sema,12604 sema: *Sema,
12325 block: *Scope.Block,12605 block: *Block,
12326 fields_len: u32,12606 fields_len: u32,
12327 int_ty: Type,12607 int_ty: Type,
12328) !Type {12608) !Type {
...@@ -12340,7 +12620,7 @@ fn generateUnionTagTypeNumbered(...@@ -12340,7 +12620,7 @@ fn generateUnionTagTypeNumbered(
12340 const enum_ty = Type.initPayload(&enum_ty_payload.base);12620 const enum_ty = Type.initPayload(&enum_ty_payload.base);
12341 const enum_val = try Value.Tag.ty.create(&new_decl_arena.allocator, enum_ty);12621 const enum_val = try Value.Tag.ty.create(&new_decl_arena.allocator, enum_ty);
12342 // TODO better type name12622 // TODO better type name
12343 const new_decl = try mod.createAnonymousDecl(&block.base, .{12623 const new_decl = try mod.createAnonymousDecl(block, .{
12344 .ty = Type.initTag(.type),12624 .ty = Type.initTag(.type),
12345 .val = enum_val,12625 .val = enum_val,
12346 });12626 });
...@@ -12361,7 +12641,7 @@ fn generateUnionTagTypeNumbered(...@@ -12361,7 +12641,7 @@ fn generateUnionTagTypeNumbered(
12361 return enum_ty;12641 return enum_ty;
12362}12642}
1236312643
12364fn generateUnionTagTypeSimple(sema: *Sema, block: *Scope.Block, fields_len: u32) !Type {12644fn generateUnionTagTypeSimple(sema: *Sema, block: *Block, fields_len: u32) !Type {
12365 const mod = sema.mod;12645 const mod = sema.mod;
1236612646
12367 var new_decl_arena = std.heap.ArenaAllocator.init(sema.gpa);12647 var new_decl_arena = std.heap.ArenaAllocator.init(sema.gpa);
...@@ -12376,7 +12656,7 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Scope.Block, fields_len: u32)...@@ -12376,7 +12656,7 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Scope.Block, fields_len: u32)
12376 const enum_ty = Type.initPayload(&enum_ty_payload.base);12656 const enum_ty = Type.initPayload(&enum_ty_payload.base);
12377 const enum_val = try Value.Tag.ty.create(&new_decl_arena.allocator, enum_ty);12657 const enum_val = try Value.Tag.ty.create(&new_decl_arena.allocator, enum_ty);
12378 // TODO better type name12658 // TODO better type name
12379 const new_decl = try mod.createAnonymousDecl(&block.base, .{12659 const new_decl = try mod.createAnonymousDecl(block, .{
12380 .ty = Type.initTag(.type),12660 .ty = Type.initTag(.type),
12381 .val = enum_val,12661 .val = enum_val,
12382 });12662 });
...@@ -12396,7 +12676,7 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Scope.Block, fields_len: u32)...@@ -12396,7 +12676,7 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Scope.Block, fields_len: u32)
1239612676
12397fn getBuiltin(12677fn getBuiltin(
12398 sema: *Sema,12678 sema: *Sema,
12399 block: *Scope.Block,12679 block: *Block,
12400 src: LazySrcLoc,12680 src: LazySrcLoc,
12401 name: []const u8,12681 name: []const u8,
12402) CompileError!Air.Inst.Ref {12682) CompileError!Air.Inst.Ref {
...@@ -12422,7 +12702,7 @@ fn getBuiltin(...@@ -12422,7 +12702,7 @@ fn getBuiltin(
1242212702
12423fn getBuiltinType(12703fn getBuiltinType(
12424 sema: *Sema,12704 sema: *Sema,
12425 block: *Scope.Block,12705 block: *Block,
12426 src: LazySrcLoc,12706 src: LazySrcLoc,
12427 name: []const u8,12707 name: []const u8,
12428) CompileError!Type {12708) CompileError!Type {
...@@ -12436,7 +12716,7 @@ fn getBuiltinType(...@@ -12436,7 +12716,7 @@ fn getBuiltinType(
12436/// that the types are already resolved.12716/// that the types are already resolved.
12437fn typeHasOnePossibleValue(12717fn typeHasOnePossibleValue(
12438 sema: *Sema,12718 sema: *Sema,
12439 block: *Scope.Block,12719 block: *Block,
12440 src: LazySrcLoc,12720 src: LazySrcLoc,
12441 starting_type: Type,12721 starting_type: Type,
12442) CompileError!?Value {12722) CompileError!?Value {
...@@ -12599,7 +12879,7 @@ fn typeHasOnePossibleValue(...@@ -12599,7 +12879,7 @@ fn typeHasOnePossibleValue(
12599 };12879 };
12600}12880}
1260112881
12602fn getAstTree(sema: *Sema, block: *Scope.Block) CompileError!*const std.zig.Ast {12882fn getAstTree(sema: *Sema, block: *Block) CompileError!*const std.zig.Ast {
12603 return block.namespace.file_scope.getTree(sema.gpa) catch |err| {12883 return block.namespace.file_scope.getTree(sema.gpa) catch |err| {
12604 log.err("unable to load AST to report compile error: {s}", .{@errorName(err)});12884 log.err("unable to load AST to report compile error: {s}", .{@errorName(err)});
12605 return error.AnalysisFail;12885 return error.AnalysisFail;
...@@ -12789,7 +13069,7 @@ fn getBreakBlock(sema: *Sema, inst_index: Air.Inst.Index) ?Air.Inst.Index {...@@ -12789,7 +13069,7 @@ fn getBreakBlock(sema: *Sema, inst_index: Air.Inst.Index) ?Air.Inst.Index {
1278913069
12790fn isComptimeKnown(13070fn isComptimeKnown(
12791 sema: *Sema,13071 sema: *Sema,
12792 block: *Scope.Block,13072 block: *Block,
12793 src: LazySrcLoc,13073 src: LazySrcLoc,
12794 inst: Air.Inst.Ref,13074 inst: Air.Inst.Ref,
12795) !bool {13075) !bool {
...@@ -12798,7 +13078,7 @@ fn isComptimeKnown(...@@ -12798,7 +13078,7 @@ fn isComptimeKnown(
1279813078
12799fn analyzeComptimeAlloc(13079fn analyzeComptimeAlloc(
12800 sema: *Sema,13080 sema: *Sema,
12801 block: *Scope.Block,13081 block: *Block,
12802 var_type: Type,13082 var_type: Type,
12803) CompileError!Air.Inst.Ref {13083) CompileError!Air.Inst.Ref {
12804 const ptr_type = try Type.ptr(sema.arena, .{13084 const ptr_type = try Type.ptr(sema.arena, .{
...@@ -12841,7 +13121,7 @@ pub const AddressSpaceContext = enum {...@@ -12841,7 +13121,7 @@ pub const AddressSpaceContext = enum {
1284113121
12842pub fn analyzeAddrspace(13122pub fn analyzeAddrspace(
12843 sema: *Sema,13123 sema: *Sema,
12844 block: *Scope.Block,13124 block: *Block,
12845 src: LazySrcLoc,13125 src: LazySrcLoc,
12846 zir_ref: Zir.Inst.Ref,13126 zir_ref: Zir.Inst.Ref,
12847 ctx: AddressSpaceContext,13127 ctx: AddressSpaceContext,
src/codegen/c.zig+1-1
...@@ -246,7 +246,7 @@ pub const DeclGen = struct {...@@ -246,7 +246,7 @@ pub const DeclGen = struct {
246 fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } {246 fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } {
247 @setCold(true);247 @setCold(true);
248 const src: LazySrcLoc = .{ .node_offset = 0 };248 const src: LazySrcLoc = .{ .node_offset = 0 };
249 const src_loc = src.toSrcLocWithDecl(dg.decl);249 const src_loc = src.toSrcLoc(dg.decl);
250 dg.error_msg = try Module.ErrorMsg.create(dg.module.gpa, src_loc, format, args);250 dg.error_msg = try Module.ErrorMsg.create(dg.module.gpa, src_loc, format, args);
251 return error.AnalysisFail;251 return error.AnalysisFail;
252 }252 }
src/codegen/llvm.zig+1-1
...@@ -557,7 +557,7 @@ pub const DeclGen = struct {...@@ -557,7 +557,7 @@ pub const DeclGen = struct {
557 fn todo(self: *DeclGen, comptime format: []const u8, args: anytype) error{ OutOfMemory, CodegenFail } {557 fn todo(self: *DeclGen, comptime format: []const u8, args: anytype) error{ OutOfMemory, CodegenFail } {
558 @setCold(true);558 @setCold(true);
559 assert(self.err_msg == null);559 assert(self.err_msg == null);
560 const src_loc = @as(LazySrcLoc, .{ .node_offset = 0 }).toSrcLocWithDecl(self.decl);560 const src_loc = @as(LazySrcLoc, .{ .node_offset = 0 }).toSrcLoc(self.decl);
561 self.err_msg = try Module.ErrorMsg.create(self.gpa, src_loc, "TODO (LLVM): " ++ format, args);561 self.err_msg = try Module.ErrorMsg.create(self.gpa, src_loc, "TODO (LLVM): " ++ format, args);
562 return error.CodegenFail;562 return error.CodegenFail;
563 }563 }
src/codegen/spirv.zig+1-1
...@@ -295,7 +295,7 @@ pub const DeclGen = struct {...@@ -295,7 +295,7 @@ pub const DeclGen = struct {
295 fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error {295 fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error {
296 @setCold(true);296 @setCold(true);
297 const src: LazySrcLoc = .{ .node_offset = 0 };297 const src: LazySrcLoc = .{ .node_offset = 0 };
298 const src_loc = src.toSrcLocWithDecl(self.decl);298 const src_loc = src.toSrcLoc(self.decl);
299 self.error_msg = try Module.ErrorMsg.create(self.spv.module.gpa, src_loc, format, args);299 self.error_msg = try Module.ErrorMsg.create(self.spv.module.gpa, src_loc, format, args);
300 return error.AnalysisFail;300 return error.AnalysisFail;
301 }301 }
src/codegen/wasm.zig+1-1
...@@ -540,7 +540,7 @@ pub const Context = struct {...@@ -540,7 +540,7 @@ pub const Context = struct {
540 /// Sets `err_msg` on `Context` and returns `error.CodegemFail` which is caught in link/Wasm.zig540 /// Sets `err_msg` on `Context` and returns `error.CodegemFail` which is caught in link/Wasm.zig
541 fn fail(self: *Context, comptime fmt: []const u8, args: anytype) InnerError {541 fn fail(self: *Context, comptime fmt: []const u8, args: anytype) InnerError {
542 const src: LazySrcLoc = .{ .node_offset = 0 };542 const src: LazySrcLoc = .{ .node_offset = 0 };
543 const src_loc = src.toSrcLocWithDecl(self.decl);543 const src_loc = src.toSrcLoc(self.decl);
544 self.err_msg = try Module.ErrorMsg.create(self.gpa, src_loc, fmt, args);544 self.err_msg = try Module.ErrorMsg.create(self.gpa, src_loc, fmt, args);
545 return error.CodegenFail;545 return error.CodegenFail;
546 }546 }
src/crash_report.zig+5-7
...@@ -8,6 +8,7 @@ const print_zir = @import("print_zir.zig");...@@ -8,6 +8,7 @@ const print_zir = @import("print_zir.zig");
8const Module = @import("Module.zig");8const Module = @import("Module.zig");
9const Sema = @import("Sema.zig");9const Sema = @import("Sema.zig");
10const Zir = @import("Zir.zig");10const Zir = @import("Zir.zig");
11const Decl = Module.Decl;
1112
12pub const is_enabled = builtin.mode == .Debug;13pub const is_enabled = builtin.mode == .Debug;
1314
...@@ -36,7 +37,7 @@ fn en(val: anytype) En(@TypeOf(val)) {...@@ -36,7 +37,7 @@ fn en(val: anytype) En(@TypeOf(val)) {
36pub const AnalyzeBody = struct {37pub const AnalyzeBody = struct {
37 parent: if (is_enabled) ?*AnalyzeBody else void,38 parent: if (is_enabled) ?*AnalyzeBody else void,
38 sema: En(*Sema),39 sema: En(*Sema),
39 block: En(*Module.Scope.Block),40 block: En(*Sema.Block),
40 body: En([]const Zir.Inst.Index),41 body: En([]const Zir.Inst.Index),
41 body_index: En(usize),42 body_index: En(usize),
4243
...@@ -64,7 +65,7 @@ pub const AnalyzeBody = struct {...@@ -64,7 +65,7 @@ pub const AnalyzeBody = struct {
6465
65threadlocal var zir_state: ?*AnalyzeBody = if (is_enabled) null else @compileError("Cannot use zir_state if crash_report is disabled.");66threadlocal var zir_state: ?*AnalyzeBody = if (is_enabled) null else @compileError("Cannot use zir_state if crash_report is disabled.");
6667
67pub fn prepAnalyzeBody(sema: *Sema, block: *Module.Scope.Block, body: []const Zir.Inst.Index) AnalyzeBody {68pub fn prepAnalyzeBody(sema: *Sema, block: *Sema.Block, body: []const Zir.Inst.Index) AnalyzeBody {
68 if (is_enabled) {69 if (is_enabled) {
69 return .{70 return .{
70 .parent = null,71 .parent = null,
...@@ -87,7 +88,7 @@ fn dumpStatusReport() !void {...@@ -87,7 +88,7 @@ fn dumpStatusReport() !void {
87 const allocator = &fba.allocator;88 const allocator = &fba.allocator;
8889
89 const stderr = io.getStdErr().writer();90 const stderr = io.getStdErr().writer();
90 const block: *Scope.Block = anal.block;91 const block: *Sema.Block = anal.block;
9192
92 try stderr.writeAll("Analyzing ");93 try stderr.writeAll("Analyzing ");
93 try writeFullyQualifiedDeclWithFile(block.src_decl, stderr);94 try writeFullyQualifiedDeclWithFile(block.src_decl, stderr);
...@@ -134,12 +135,9 @@ fn dumpStatusReport() !void {...@@ -134,12 +135,9 @@ fn dumpStatusReport() !void {
134 try stderr.writeAll("\n");135 try stderr.writeAll("\n");
135}136}
136137
137const Scope = Module.Scope;
138const Decl = Module.Decl;
139
140var crash_heap: [16 * 4096]u8 = undefined;138var crash_heap: [16 * 4096]u8 = undefined;
141139
142fn writeFilePath(file: *Scope.File, stream: anytype) !void {140fn writeFilePath(file: *Module.File, stream: anytype) !void {
143 if (file.pkg.root_src_directory.path) |path| {141 if (file.pkg.root_src_directory.path) |path| {
144 try stream.writeAll(path);142 try stream.writeAll(path);
145 try stream.writeAll(std.fs.path.sep_str);143 try stream.writeAll(std.fs.path.sep_str);
src/link/Plan9.zig+1-1
...@@ -57,7 +57,7 @@ path_arena: std.heap.ArenaAllocator,...@@ -57,7 +57,7 @@ path_arena: std.heap.ArenaAllocator,
57/// of the function to know what file it came from.57/// of the function to know what file it came from.
58/// If we group the decls by file, it makes it really easy to do this (put the symbol in the correct place)58/// If we group the decls by file, it makes it really easy to do this (put the symbol in the correct place)
59fn_decl_table: std.AutoArrayHashMapUnmanaged(59fn_decl_table: std.AutoArrayHashMapUnmanaged(
60 *Module.Scope.File,60 *Module.File,
61 struct { sym_index: u32, functions: std.AutoArrayHashMapUnmanaged(*Module.Decl, FnDeclOutput) = .{} },61 struct { sym_index: u32, functions: std.AutoArrayHashMapUnmanaged(*Module.Decl, FnDeclOutput) = .{} },
62) = .{},62) = .{},
63data_decl_table: std.AutoArrayHashMapUnmanaged(*Module.Decl, []const u8) = .{},63data_decl_table: std.AutoArrayHashMapUnmanaged(*Module.Decl, []const u8) = .{},
src/main.zig+4-4
...@@ -3233,7 +3233,7 @@ pub fn cmdFmt(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !voi...@@ -3233,7 +3233,7 @@ pub fn cmdFmt(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !voi
3233 const Module = @import("Module.zig");3233 const Module = @import("Module.zig");
3234 const AstGen = @import("AstGen.zig");3234 const AstGen = @import("AstGen.zig");
32353235
3236 var file: Module.Scope.File = .{3236 var file: Module.File = .{
3237 .status = .never_loaded,3237 .status = .never_loaded,
3238 .source_loaded = true,3238 .source_loaded = true,
3239 .zir_loaded = false,3239 .zir_loaded = false,
...@@ -3429,7 +3429,7 @@ fn fmtPathFile(...@@ -3429,7 +3429,7 @@ fn fmtPathFile(
3429 const Module = @import("Module.zig");3429 const Module = @import("Module.zig");
3430 const AstGen = @import("AstGen.zig");3430 const AstGen = @import("AstGen.zig");
34313431
3432 var file: Module.Scope.File = .{3432 var file: Module.File = .{
3433 .status = .never_loaded,3433 .status = .never_loaded,
3434 .source_loaded = true,3434 .source_loaded = true,
3435 .zir_loaded = false,3435 .zir_loaded = false,
...@@ -4019,7 +4019,7 @@ pub fn cmdAstCheck(...@@ -4019,7 +4019,7 @@ pub fn cmdAstCheck(
4019 }4019 }
4020 }4020 }
40214021
4022 var file: Module.Scope.File = .{4022 var file: Module.File = .{
4023 .status = .never_loaded,4023 .status = .never_loaded,
4024 .source_loaded = false,4024 .source_loaded = false,
4025 .tree_loaded = false,4025 .tree_loaded = false,
...@@ -4170,7 +4170,7 @@ pub fn cmdChangelist(...@@ -4170,7 +4170,7 @@ pub fn cmdChangelist(
4170 if (stat.size > max_src_size)4170 if (stat.size > max_src_size)
4171 return error.FileTooBig;4171 return error.FileTooBig;
41724172
4173 var file: Module.Scope.File = .{4173 var file: Module.File = .{
4174 .status = .never_loaded,4174 .status = .never_loaded,
4175 .source_loaded = false,4175 .source_loaded = false,
4176 .tree_loaded = false,4176 .tree_loaded = false,
src/print_zir.zig+4-4
...@@ -11,7 +11,7 @@ const LazySrcLoc = Module.LazySrcLoc;...@@ -11,7 +11,7 @@ const LazySrcLoc = Module.LazySrcLoc;
11/// Write human-readable, debug formatted ZIR code to a file.11/// Write human-readable, debug formatted ZIR code to a file.
12pub fn renderAsTextToFile(12pub fn renderAsTextToFile(
13 gpa: *Allocator,13 gpa: *Allocator,
14 scope_file: *Module.Scope.File,14 scope_file: *Module.File,
15 fs_file: std.fs.File,15 fs_file: std.fs.File,
16) !void {16) !void {
17 var arena = std.heap.ArenaAllocator.init(gpa);17 var arena = std.heap.ArenaAllocator.init(gpa);
...@@ -64,7 +64,7 @@ pub fn renderInstructionContext(...@@ -64,7 +64,7 @@ pub fn renderInstructionContext(
64 gpa: *Allocator,64 gpa: *Allocator,
65 block: []const Zir.Inst.Index,65 block: []const Zir.Inst.Index,
66 block_index: usize,66 block_index: usize,
67 scope_file: *Module.Scope.File,67 scope_file: *Module.File,
68 parent_decl_node: Ast.Node.Index,68 parent_decl_node: Ast.Node.Index,
69 indent: u32,69 indent: u32,
70 stream: anytype,70 stream: anytype,
...@@ -96,7 +96,7 @@ pub fn renderInstructionContext(...@@ -96,7 +96,7 @@ pub fn renderInstructionContext(
96pub fn renderSingleInstruction(96pub fn renderSingleInstruction(
97 gpa: *Allocator,97 gpa: *Allocator,
98 inst: Zir.Inst.Index,98 inst: Zir.Inst.Index,
99 scope_file: *Module.Scope.File,99 scope_file: *Module.File,
100 parent_decl_node: Ast.Node.Index,100 parent_decl_node: Ast.Node.Index,
101 indent: u32,101 indent: u32,
102 stream: anytype,102 stream: anytype,
...@@ -122,7 +122,7 @@ pub fn renderSingleInstruction(...@@ -122,7 +122,7 @@ pub fn renderSingleInstruction(
122const Writer = struct {122const Writer = struct {
123 gpa: *Allocator,123 gpa: *Allocator,
124 arena: *Allocator,124 arena: *Allocator,
125 file: *Module.Scope.File,125 file: *Module.File,
126 code: Zir,126 code: Zir,
127 indent: u32,127 indent: u32,
128 parent_decl_node: Ast.Node.Index,128 parent_decl_node: Ast.Node.Index,
src/type.zig+3-3
...@@ -3067,7 +3067,7 @@ pub const Type = extern union {...@@ -3067,7 +3067,7 @@ pub const Type = extern union {
3067 }3067 }
30683068
3069 /// Returns null if the type has no namespace.3069 /// Returns null if the type has no namespace.
3070 pub fn getNamespace(self: Type) ?*Module.Scope.Namespace {3070 pub fn getNamespace(self: Type) ?*Module.Namespace {
3071 return switch (self.tag()) {3071 return switch (self.tag()) {
3072 .@"struct" => &self.castTag(.@"struct").?.data.namespace,3072 .@"struct" => &self.castTag(.@"struct").?.data.namespace,
3073 .enum_full => &self.castTag(.enum_full).?.data.namespace,3073 .enum_full => &self.castTag(.enum_full).?.data.namespace,
...@@ -3833,12 +3833,12 @@ pub const Type = extern union {...@@ -3833,12 +3833,12 @@ pub const Type = extern union {
3833 /// Most commonly used for files.3833 /// Most commonly used for files.
3834 pub const ContainerScope = struct {3834 pub const ContainerScope = struct {
3835 base: Payload,3835 base: Payload,
3836 data: *Module.Scope.Namespace,3836 data: *Module.Namespace,
3837 };3837 };
38383838
3839 pub const Opaque = struct {3839 pub const Opaque = struct {
3840 base: Payload = .{ .tag = .@"opaque" },3840 base: Payload = .{ .tag = .@"opaque" },
3841 data: Module.Scope.Namespace,3841 data: Module.Namespace,
3842 };3842 };
38433843
3844 pub const Struct = struct {3844 pub const Struct = struct {