authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-20 20:37:44-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-31 21:09:22-07:00
logb7452fe35f514d4c04aae4582bc8071bc9e70f1b
treeb125fa735b9d2f9ea3791687f8ef22d75aca590a
parentfdc875ed0080cd2542a854a8cd6c627b25e9b7a4

stage2: rework astgen result locations

Motivating test case: ```zig export fn _start() noreturn { var x: u64 = 1; var y: u32 = 2; var thing: u32 = 1; const result = if (thing == 1) x else y; exit(); } ``` The main idea here is for astgen to output ideal ZIR depending on whether or not the sub-expressions of a block consume the result location. Here, neither `x` nor `y` consume the result location of the conditional expression block, and so the ZIR should communicate the result of the condbr using break instructions, not with the result location pointer. With this commit, this is accomplished: ``` %22 = alloc_inferred() %23 = block({ %24 = const(TypedValue{ .ty = type, .val = bool}) %25 = deref(%18) %26 = const(TypedValue{ .ty = comptime_int, .val = 1}) %27 = cmp_eq(%25, %26) %28 = as(%24, %27) %29 = condbr(%28, { %30 = deref(%4) < there is no longer a store instruction here > %31 = break("label_23", %30) }, { %32 = deref(%11) < there is no longer a store instruction here > %33 = break("label_23", %32) }) }) %34 = store_to_inferred_ptr(%22, %23) <-- the store is only here %35 = resolve_inferred_alloc(%22) ``` However if the result location gets consumed, the break instructions change to break_void, and the result value is communicated only by the stores, not by the break instructions. Implementation: * The GenZIR scope that conditional branches uses now has an optional result location pointer field and a count of how many times the result location ended up being an rvalue (not consumed). * When rvalue() is called on a result location for a block, it increments this counter. After generating the branches of a block, astgen for the conditional branch checks this count and if it is 2 then the store_to_block_ptr instructions are elided and it calls rvalue() using the block result (which will account for peer type resolution on the break operands). astgen has many functions disabled until they can be reworked with these new semantics. That will be done before merging the branch. There are some new rules for astgen to follow regarding result locations and what you are allowed/required to do depending on which one is passed to expr(). See the updated doc comments of ResultLoc for details. I also changed naming conventions of stuff in this commit, sorry about that.

6 files changed, 649 insertions(+), 529 deletions(-)

src/Module.zig+8-1
...@@ -697,6 +697,13 @@ pub const Scope = struct {...@@ -697,6 +697,13 @@ pub const Scope = struct {
697 continue_block: ?*zir.Inst.Block = null,697 continue_block: ?*zir.Inst.Block = null,
698 /// only valid if label != null or (continue_block and break_block) != null698 /// only valid if label != null or (continue_block and break_block) != null
699 break_result_loc: astgen.ResultLoc = undefined,699 break_result_loc: astgen.ResultLoc = undefined,
700 /// When a block has a pointer result location, here it is.
701 rl_ptr: ?*zir.Inst = null,
702 /// Keeps track of how many branches of a block did not actually
703 /// consume the result location. astgen uses this to figure out
704 /// whether to rely on break instructions or writing to the result
705 /// pointer for the result instruction.
706 rvalue_rl_count: usize = 0,
700707
701 pub const Label = struct {708 pub const Label = struct {
702 token: ast.TokenIndex,709 token: ast.TokenIndex,
...@@ -1171,7 +1178,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool {...@@ -1171,7 +1178,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool {
1171 !gen_scope.instructions.items[gen_scope.instructions.items.len - 1].tag.isNoReturn())1178 !gen_scope.instructions.items[gen_scope.instructions.items.len - 1].tag.isNoReturn())
1172 {1179 {
1173 const src = tree.token_locs[body_block.rbrace].start;1180 const src = tree.token_locs[body_block.rbrace].start;
1174 _ = try astgen.addZIRNoOp(self, &gen_scope.base, src, .returnvoid);1181 _ = try astgen.addZIRNoOp(self, &gen_scope.base, src, .return_void);
1175 }1182 }
11761183
1177 if (std.builtin.mode == .Debug and self.comp.verbose_ir) {1184 if (std.builtin.mode == .Debug and self.comp.verbose_ir) {
src/astgen.zig+259-143
...@@ -14,25 +14,30 @@ const InnerError = Module.InnerError;...@@ -14,25 +14,30 @@ const InnerError = Module.InnerError;
1414
15pub const ResultLoc = union(enum) {15pub const ResultLoc = union(enum) {
16 /// The expression is the right-hand side of assignment to `_`. Only the side-effects of the16 /// The expression is the right-hand side of assignment to `_`. Only the side-effects of the
17 /// expression should be generated.17 /// expression should be generated. The result instruction from the expression must
18 /// be ignored.
18 discard,19 discard,
19 /// The expression has an inferred type, and it will be evaluated as an rvalue.20 /// The expression has an inferred type, and it will be evaluated as an rvalue.
20 none,21 none,
21 /// The expression must generate a pointer rather than a value. For example, the left hand side22 /// The expression must generate a pointer rather than a value. For example, the left hand side
22 /// of an assignment uses this kind of result location.23 /// of an assignment uses this kind of result location.
23 ref,24 ref,
24 /// The expression will be type coerced into this type, but it will be evaluated as an rvalue.25 /// The expression will be coerced into this type, but it will be evaluated as an rvalue.
25 ty: *zir.Inst,26 ty: *zir.Inst,
26 /// The expression must store its result into this typed pointer.27 /// The expression must store its result into this typed pointer. The result instruction
28 /// from the expression must be ignored.
27 ptr: *zir.Inst,29 ptr: *zir.Inst,
28 /// The expression must store its result into this allocation, which has an inferred type.30 /// The expression must store its result into this allocation, which has an inferred type.
31 /// The result instruction from the expression must be ignored.
29 inferred_ptr: *zir.Inst.Tag.alloc_inferred.Type(),32 inferred_ptr: *zir.Inst.Tag.alloc_inferred.Type(),
30 /// The expression must store its result into this pointer, which is a typed pointer that33 /// The expression must store its result into this pointer, which is a typed pointer that
31 /// has been bitcasted to whatever the expression's type is.34 /// has been bitcasted to whatever the expression's type is.
35 /// The result instruction from the expression must be ignored.
32 bitcasted_ptr: *zir.Inst.UnOp,36 bitcasted_ptr: *zir.Inst.UnOp,
33 /// There is a pointer for the expression to store its result into, however, its type37 /// There is a pointer for the expression to store its result into, however, its type
34 /// is inferred based on peer type resolution for a `zir.Inst.Block`.38 /// is inferred based on peer type resolution for a `zir.Inst.Block`.
35 block_ptr: *zir.Inst.Block,39 /// The result instruction from the expression must be ignored.
40 block_ptr: *Module.Scope.GenZIR,
36};41};
3742
38pub fn typeExpr(mod: *Module, scope: *Scope, type_node: *ast.Node) InnerError!*zir.Inst {43pub fn typeExpr(mod: *Module, scope: *Scope, type_node: *ast.Node) InnerError!*zir.Inst {
...@@ -179,6 +184,9 @@ fn lvalExpr(mod: *Module, scope: *Scope, node: *ast.Node) InnerError!*zir.Inst {...@@ -179,6 +184,9 @@ fn lvalExpr(mod: *Module, scope: *Scope, node: *ast.Node) InnerError!*zir.Inst {
179}184}
180185
181/// Turn Zig AST into untyped ZIR istructions.186/// Turn Zig AST into untyped ZIR istructions.
187/// When `rl` is discard, ptr, inferred_ptr, bitcasted_ptr, or inferred_ptr, the
188/// result instruction can be used to inspect whether it is isNoReturn() but that is it,
189/// it must otherwise not be used.
182pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerError!*zir.Inst {190pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerError!*zir.Inst {
183 switch (node.tag) {191 switch (node.tag) {
184 .Root => unreachable, // Top-level declaration.192 .Root => unreachable, // Top-level declaration.
...@@ -197,20 +205,20 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr...@@ -197,20 +205,20 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr
197 .FieldInitializer => unreachable, // Handled explicitly.205 .FieldInitializer => unreachable, // Handled explicitly.
198 .ContainerField => unreachable, // Handled explicitly.206 .ContainerField => unreachable, // Handled explicitly.
199207
200 .Assign => return rlWrapVoid(mod, scope, rl, node, try assign(mod, scope, node.castTag(.Assign).?)),208 .Assign => return rvalueVoid(mod, scope, rl, node, try assign(mod, scope, node.castTag(.Assign).?)),
201 .AssignBitAnd => return rlWrapVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignBitAnd).?, .bitand)),209 .AssignBitAnd => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignBitAnd).?, .bit_and)),
202 .AssignBitOr => return rlWrapVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignBitOr).?, .bitor)),210 .AssignBitOr => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignBitOr).?, .bit_or)),
203 .AssignBitShiftLeft => return rlWrapVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignBitShiftLeft).?, .shl)),211 .AssignBitShiftLeft => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignBitShiftLeft).?, .shl)),
204 .AssignBitShiftRight => return rlWrapVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignBitShiftRight).?, .shr)),212 .AssignBitShiftRight => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignBitShiftRight).?, .shr)),
205 .AssignBitXor => return rlWrapVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignBitXor).?, .xor)),213 .AssignBitXor => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignBitXor).?, .xor)),
206 .AssignDiv => return rlWrapVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignDiv).?, .div)),214 .AssignDiv => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignDiv).?, .div)),
207 .AssignSub => return rlWrapVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignSub).?, .sub)),215 .AssignSub => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignSub).?, .sub)),
208 .AssignSubWrap => return rlWrapVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignSubWrap).?, .subwrap)),216 .AssignSubWrap => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignSubWrap).?, .subwrap)),
209 .AssignMod => return rlWrapVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignMod).?, .mod_rem)),217 .AssignMod => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignMod).?, .mod_rem)),
210 .AssignAdd => return rlWrapVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignAdd).?, .add)),218 .AssignAdd => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignAdd).?, .add)),
211 .AssignAddWrap => return rlWrapVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignAddWrap).?, .addwrap)),219 .AssignAddWrap => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignAddWrap).?, .addwrap)),
212 .AssignMul => return rlWrapVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignMul).?, .mul)),220 .AssignMul => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignMul).?, .mul)),
213 .AssignMulWrap => return rlWrapVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignMulWrap).?, .mulwrap)),221 .AssignMulWrap => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignMulWrap).?, .mulwrap)),
214222
215 .Add => return simpleBinOp(mod, scope, rl, node.castTag(.Add).?, .add),223 .Add => return simpleBinOp(mod, scope, rl, node.castTag(.Add).?, .add),
216 .AddWrap => return simpleBinOp(mod, scope, rl, node.castTag(.AddWrap).?, .addwrap),224 .AddWrap => return simpleBinOp(mod, scope, rl, node.castTag(.AddWrap).?, .addwrap),
...@@ -220,8 +228,8 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr...@@ -220,8 +228,8 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr
220 .MulWrap => return simpleBinOp(mod, scope, rl, node.castTag(.MulWrap).?, .mulwrap),228 .MulWrap => return simpleBinOp(mod, scope, rl, node.castTag(.MulWrap).?, .mulwrap),
221 .Div => return simpleBinOp(mod, scope, rl, node.castTag(.Div).?, .div),229 .Div => return simpleBinOp(mod, scope, rl, node.castTag(.Div).?, .div),
222 .Mod => return simpleBinOp(mod, scope, rl, node.castTag(.Mod).?, .mod_rem),230 .Mod => return simpleBinOp(mod, scope, rl, node.castTag(.Mod).?, .mod_rem),
223 .BitAnd => return simpleBinOp(mod, scope, rl, node.castTag(.BitAnd).?, .bitand),231 .BitAnd => return simpleBinOp(mod, scope, rl, node.castTag(.BitAnd).?, .bit_and),
224 .BitOr => return simpleBinOp(mod, scope, rl, node.castTag(.BitOr).?, .bitor),232 .BitOr => return simpleBinOp(mod, scope, rl, node.castTag(.BitOr).?, .bit_or),
225 .BitShiftLeft => return simpleBinOp(mod, scope, rl, node.castTag(.BitShiftLeft).?, .shl),233 .BitShiftLeft => return simpleBinOp(mod, scope, rl, node.castTag(.BitShiftLeft).?, .shl),
226 .BitShiftRight => return simpleBinOp(mod, scope, rl, node.castTag(.BitShiftRight).?, .shr),234 .BitShiftRight => return simpleBinOp(mod, scope, rl, node.castTag(.BitShiftRight).?, .shr),
227 .BitXor => return simpleBinOp(mod, scope, rl, node.castTag(.BitXor).?, .xor),235 .BitXor => return simpleBinOp(mod, scope, rl, node.castTag(.BitXor).?, .xor),
...@@ -239,15 +247,15 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr...@@ -239,15 +247,15 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr
239 .BoolAnd => return boolBinOp(mod, scope, rl, node.castTag(.BoolAnd).?),247 .BoolAnd => return boolBinOp(mod, scope, rl, node.castTag(.BoolAnd).?),
240 .BoolOr => return boolBinOp(mod, scope, rl, node.castTag(.BoolOr).?),248 .BoolOr => return boolBinOp(mod, scope, rl, node.castTag(.BoolOr).?),
241249
242 .BoolNot => return rlWrap(mod, scope, rl, try boolNot(mod, scope, node.castTag(.BoolNot).?)),250 .BoolNot => return rvalue(mod, scope, rl, try boolNot(mod, scope, node.castTag(.BoolNot).?)),
243 .BitNot => return rlWrap(mod, scope, rl, try bitNot(mod, scope, node.castTag(.BitNot).?)),251 .BitNot => return rvalue(mod, scope, rl, try bitNot(mod, scope, node.castTag(.BitNot).?)),
244 .Negation => return rlWrap(mod, scope, rl, try negation(mod, scope, node.castTag(.Negation).?, .sub)),252 .Negation => return rvalue(mod, scope, rl, try negation(mod, scope, node.castTag(.Negation).?, .sub)),
245 .NegationWrap => return rlWrap(mod, scope, rl, try negation(mod, scope, node.castTag(.NegationWrap).?, .subwrap)),253 .NegationWrap => return rvalue(mod, scope, rl, try negation(mod, scope, node.castTag(.NegationWrap).?, .subwrap)),
246254
247 .Identifier => return try identifier(mod, scope, rl, node.castTag(.Identifier).?),255 .Identifier => return try identifier(mod, scope, rl, node.castTag(.Identifier).?),
248 .Asm => return rlWrap(mod, scope, rl, try assembly(mod, scope, node.castTag(.Asm).?)),256 .Asm => return rvalue(mod, scope, rl, try assembly(mod, scope, node.castTag(.Asm).?)),
249 .StringLiteral => return rlWrap(mod, scope, rl, try stringLiteral(mod, scope, node.castTag(.StringLiteral).?)),257 .StringLiteral => return rvalue(mod, scope, rl, try stringLiteral(mod, scope, node.castTag(.StringLiteral).?)),
250 .IntegerLiteral => return rlWrap(mod, scope, rl, try integerLiteral(mod, scope, node.castTag(.IntegerLiteral).?)),258 .IntegerLiteral => return rvalue(mod, scope, rl, try integerLiteral(mod, scope, node.castTag(.IntegerLiteral).?)),
251 .BuiltinCall => return builtinCall(mod, scope, rl, node.castTag(.BuiltinCall).?),259 .BuiltinCall => return builtinCall(mod, scope, rl, node.castTag(.BuiltinCall).?),
252 .Call => return callExpr(mod, scope, rl, node.castTag(.Call).?),260 .Call => return callExpr(mod, scope, rl, node.castTag(.Call).?),
253 .Unreachable => return unreach(mod, scope, node.castTag(.Unreachable).?),261 .Unreachable => return unreach(mod, scope, node.castTag(.Unreachable).?),
...@@ -255,34 +263,34 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr...@@ -255,34 +263,34 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr
255 .If => return ifExpr(mod, scope, rl, node.castTag(.If).?),263 .If => return ifExpr(mod, scope, rl, node.castTag(.If).?),
256 .While => return whileExpr(mod, scope, rl, node.castTag(.While).?),264 .While => return whileExpr(mod, scope, rl, node.castTag(.While).?),
257 .Period => return field(mod, scope, rl, node.castTag(.Period).?),265 .Period => return field(mod, scope, rl, node.castTag(.Period).?),
258 .Deref => return rlWrap(mod, scope, rl, try deref(mod, scope, node.castTag(.Deref).?)),266 .Deref => return rvalue(mod, scope, rl, try deref(mod, scope, node.castTag(.Deref).?)),
259 .AddressOf => return rlWrap(mod, scope, rl, try addressOf(mod, scope, node.castTag(.AddressOf).?)),267 .AddressOf => return rvalue(mod, scope, rl, try addressOf(mod, scope, node.castTag(.AddressOf).?)),
260 .FloatLiteral => return rlWrap(mod, scope, rl, try floatLiteral(mod, scope, node.castTag(.FloatLiteral).?)),268 .FloatLiteral => return rvalue(mod, scope, rl, try floatLiteral(mod, scope, node.castTag(.FloatLiteral).?)),
261 .UndefinedLiteral => return rlWrap(mod, scope, rl, try undefLiteral(mod, scope, node.castTag(.UndefinedLiteral).?)),269 .UndefinedLiteral => return rvalue(mod, scope, rl, try undefLiteral(mod, scope, node.castTag(.UndefinedLiteral).?)),
262 .BoolLiteral => return rlWrap(mod, scope, rl, try boolLiteral(mod, scope, node.castTag(.BoolLiteral).?)),270 .BoolLiteral => return rvalue(mod, scope, rl, try boolLiteral(mod, scope, node.castTag(.BoolLiteral).?)),
263 .NullLiteral => return rlWrap(mod, scope, rl, try nullLiteral(mod, scope, node.castTag(.NullLiteral).?)),271 .NullLiteral => return rvalue(mod, scope, rl, try nullLiteral(mod, scope, node.castTag(.NullLiteral).?)),
264 .OptionalType => return rlWrap(mod, scope, rl, try optionalType(mod, scope, node.castTag(.OptionalType).?)),272 .OptionalType => return rvalue(mod, scope, rl, try optionalType(mod, scope, node.castTag(.OptionalType).?)),
265 .UnwrapOptional => return unwrapOptional(mod, scope, rl, node.castTag(.UnwrapOptional).?),273 .UnwrapOptional => return unwrapOptional(mod, scope, rl, node.castTag(.UnwrapOptional).?),
266 .Block => return rlWrapVoid(mod, scope, rl, node, try blockExpr(mod, scope, node.castTag(.Block).?)),274 .Block => return rvalueVoid(mod, scope, rl, node, try blockExpr(mod, scope, node.castTag(.Block).?)),
267 .LabeledBlock => return labeledBlockExpr(mod, scope, rl, node.castTag(.LabeledBlock).?, .block),275 .LabeledBlock => return labeledBlockExpr(mod, scope, rl, node.castTag(.LabeledBlock).?, .block),
268 .Break => return rlWrap(mod, scope, rl, try breakExpr(mod, scope, node.castTag(.Break).?)),276 .Break => return rvalue(mod, scope, rl, try breakExpr(mod, scope, node.castTag(.Break).?)),
269 .Continue => return rlWrap(mod, scope, rl, try continueExpr(mod, scope, node.castTag(.Continue).?)),277 .Continue => return rvalue(mod, scope, rl, try continueExpr(mod, scope, node.castTag(.Continue).?)),
270 .PtrType => return rlWrap(mod, scope, rl, try ptrType(mod, scope, node.castTag(.PtrType).?)),278 .PtrType => return rvalue(mod, scope, rl, try ptrType(mod, scope, node.castTag(.PtrType).?)),
271 .GroupedExpression => return expr(mod, scope, rl, node.castTag(.GroupedExpression).?.expr),279 .GroupedExpression => return expr(mod, scope, rl, node.castTag(.GroupedExpression).?.expr),
272 .ArrayType => return rlWrap(mod, scope, rl, try arrayType(mod, scope, node.castTag(.ArrayType).?)),280 .ArrayType => return rvalue(mod, scope, rl, try arrayType(mod, scope, node.castTag(.ArrayType).?)),
273 .ArrayTypeSentinel => return rlWrap(mod, scope, rl, try arrayTypeSentinel(mod, scope, node.castTag(.ArrayTypeSentinel).?)),281 .ArrayTypeSentinel => return rvalue(mod, scope, rl, try arrayTypeSentinel(mod, scope, node.castTag(.ArrayTypeSentinel).?)),
274 .EnumLiteral => return rlWrap(mod, scope, rl, try enumLiteral(mod, scope, node.castTag(.EnumLiteral).?)),282 .EnumLiteral => return rvalue(mod, scope, rl, try enumLiteral(mod, scope, node.castTag(.EnumLiteral).?)),
275 .MultilineStringLiteral => return rlWrap(mod, scope, rl, try multilineStrLiteral(mod, scope, node.castTag(.MultilineStringLiteral).?)),283 .MultilineStringLiteral => return rvalue(mod, scope, rl, try multilineStrLiteral(mod, scope, node.castTag(.MultilineStringLiteral).?)),
276 .CharLiteral => return rlWrap(mod, scope, rl, try charLiteral(mod, scope, node.castTag(.CharLiteral).?)),284 .CharLiteral => return rvalue(mod, scope, rl, try charLiteral(mod, scope, node.castTag(.CharLiteral).?)),
277 .SliceType => return rlWrap(mod, scope, rl, try sliceType(mod, scope, node.castTag(.SliceType).?)),285 .SliceType => return rvalue(mod, scope, rl, try sliceType(mod, scope, node.castTag(.SliceType).?)),
278 .ErrorUnion => return rlWrap(mod, scope, rl, try typeInixOp(mod, scope, node.castTag(.ErrorUnion).?, .error_union_type)),286 .ErrorUnion => return rvalue(mod, scope, rl, try typeInixOp(mod, scope, node.castTag(.ErrorUnion).?, .error_union_type)),
279 .MergeErrorSets => return rlWrap(mod, scope, rl, try typeInixOp(mod, scope, node.castTag(.MergeErrorSets).?, .merge_error_sets)),287 .MergeErrorSets => return rvalue(mod, scope, rl, try typeInixOp(mod, scope, node.castTag(.MergeErrorSets).?, .merge_error_sets)),
280 .AnyFrameType => return rlWrap(mod, scope, rl, try anyFrameType(mod, scope, node.castTag(.AnyFrameType).?)),288 .AnyFrameType => return rvalue(mod, scope, rl, try anyFrameType(mod, scope, node.castTag(.AnyFrameType).?)),
281 .ErrorSetDecl => return rlWrap(mod, scope, rl, try errorSetDecl(mod, scope, node.castTag(.ErrorSetDecl).?)),289 .ErrorSetDecl => return rvalue(mod, scope, rl, try errorSetDecl(mod, scope, node.castTag(.ErrorSetDecl).?)),
282 .ErrorType => return rlWrap(mod, scope, rl, try errorType(mod, scope, node.castTag(.ErrorType).?)),290 .ErrorType => return rvalue(mod, scope, rl, try errorType(mod, scope, node.castTag(.ErrorType).?)),
283 .For => return forExpr(mod, scope, rl, node.castTag(.For).?),291 .For => return forExpr(mod, scope, rl, node.castTag(.For).?),
284 .ArrayAccess => return arrayAccess(mod, scope, rl, node.castTag(.ArrayAccess).?),292 .ArrayAccess => return arrayAccess(mod, scope, rl, node.castTag(.ArrayAccess).?),
285 .Slice => return rlWrap(mod, scope, rl, try sliceExpr(mod, scope, node.castTag(.Slice).?)),293 .Slice => return rvalue(mod, scope, rl, try sliceExpr(mod, scope, node.castTag(.Slice).?)),
286 .Catch => return catchExpr(mod, scope, rl, node.castTag(.Catch).?),294 .Catch => return catchExpr(mod, scope, rl, node.castTag(.Catch).?),
287 .Comptime => return comptimeKeyword(mod, scope, rl, node.castTag(.Comptime).?),295 .Comptime => return comptimeKeyword(mod, scope, rl, node.castTag(.Comptime).?),
288 .OrElse => return orelseExpr(mod, scope, rl, node.castTag(.OrElse).?),296 .OrElse => return orelseExpr(mod, scope, rl, node.castTag(.OrElse).?),
...@@ -341,6 +349,9 @@ pub fn comptimeExpr(mod: *Module, parent_scope: *Scope, rl: ResultLoc, node: *as...@@ -341,6 +349,9 @@ pub fn comptimeExpr(mod: *Module, parent_scope: *Scope, rl: ResultLoc, node: *as
341}349}
342350
343fn breakExpr(mod: *Module, parent_scope: *Scope, node: *ast.Node.ControlFlowExpression) InnerError!*zir.Inst {351fn breakExpr(mod: *Module, parent_scope: *Scope, node: *ast.Node.ControlFlowExpression) InnerError!*zir.Inst {
352 if (true) {
353 @panic("TODO reimplement this");
354 }
344 const tree = parent_scope.tree();355 const tree = parent_scope.tree();
345 const src = tree.token_locs[node.ltoken].start;356 const src = tree.token_locs[node.ltoken].start;
346357
...@@ -563,8 +574,8 @@ fn blockExprStmts(mod: *Module, parent_scope: *Scope, node: *ast.Node, statement...@@ -563,8 +574,8 @@ fn blockExprStmts(mod: *Module, parent_scope: *Scope, node: *ast.Node, statement
563 scope = try varDecl(mod, scope, var_decl_node, &block_arena.allocator);574 scope = try varDecl(mod, scope, var_decl_node, &block_arena.allocator);
564 },575 },
565 .Assign => try assign(mod, scope, statement.castTag(.Assign).?),576 .Assign => try assign(mod, scope, statement.castTag(.Assign).?),
566 .AssignBitAnd => try assignOp(mod, scope, statement.castTag(.AssignBitAnd).?, .bitand),577 .AssignBitAnd => try assignOp(mod, scope, statement.castTag(.AssignBitAnd).?, .bit_and),
567 .AssignBitOr => try assignOp(mod, scope, statement.castTag(.AssignBitOr).?, .bitor),578 .AssignBitOr => try assignOp(mod, scope, statement.castTag(.AssignBitOr).?, .bit_or),
568 .AssignBitShiftLeft => try assignOp(mod, scope, statement.castTag(.AssignBitShiftLeft).?, .shl),579 .AssignBitShiftLeft => try assignOp(mod, scope, statement.castTag(.AssignBitShiftLeft).?, .shl),
569 .AssignBitShiftRight => try assignOp(mod, scope, statement.castTag(.AssignBitShiftRight).?, .shr),580 .AssignBitShiftRight => try assignOp(mod, scope, statement.castTag(.AssignBitShiftRight).?, .shr),
570 .AssignBitXor => try assignOp(mod, scope, statement.castTag(.AssignBitXor).?, .xor),581 .AssignBitXor => try assignOp(mod, scope, statement.castTag(.AssignBitXor).?, .xor),
...@@ -644,6 +655,7 @@ fn varDecl(...@@ -644,6 +655,7 @@ fn varDecl(
644655
645 // Namespace vars shadowing detection656 // Namespace vars shadowing detection
646 if (mod.lookupDeclName(scope, ident_name)) |_| {657 if (mod.lookupDeclName(scope, ident_name)) |_| {
658 // TODO add note for other definition
647 return mod.fail(scope, name_src, "redefinition of '{s}'", .{ident_name});659 return mod.fail(scope, name_src, "redefinition of '{s}'", .{ident_name});
648 }660 }
649 const init_node = node.getInitNode() orelse661 const init_node = node.getInitNode() orelse
...@@ -751,14 +763,14 @@ fn boolNot(mod: *Module, scope: *Scope, node: *ast.Node.SimplePrefixOp) InnerErr...@@ -751,14 +763,14 @@ fn boolNot(mod: *Module, scope: *Scope, node: *ast.Node.SimplePrefixOp) InnerErr
751 .val = Value.initTag(.bool_type),763 .val = Value.initTag(.bool_type),
752 });764 });
753 const operand = try expr(mod, scope, .{ .ty = bool_type }, node.rhs);765 const operand = try expr(mod, scope, .{ .ty = bool_type }, node.rhs);
754 return addZIRUnOp(mod, scope, src, .boolnot, operand);766 return addZIRUnOp(mod, scope, src, .bool_not, operand);
755}767}
756768
757fn bitNot(mod: *Module, scope: *Scope, node: *ast.Node.SimplePrefixOp) InnerError!*zir.Inst {769fn bitNot(mod: *Module, scope: *Scope, node: *ast.Node.SimplePrefixOp) InnerError!*zir.Inst {
758 const tree = scope.tree();770 const tree = scope.tree();
759 const src = tree.token_locs[node.op_token].start;771 const src = tree.token_locs[node.op_token].start;
760 const operand = try expr(mod, scope, .none, node.rhs);772 const operand = try expr(mod, scope, .none, node.rhs);
761 return addZIRUnOp(mod, scope, src, .bitnot, operand);773 return addZIRUnOp(mod, scope, src, .bit_not, operand);
762}774}
763775
764fn negation(mod: *Module, scope: *Scope, node: *ast.Node.SimplePrefixOp, op_inst_tag: zir.Inst.Tag) InnerError!*zir.Inst {776fn negation(mod: *Module, scope: *Scope, node: *ast.Node.SimplePrefixOp, op_inst_tag: zir.Inst.Tag) InnerError!*zir.Inst {
...@@ -1101,7 +1113,7 @@ fn containerDecl(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node.Con...@@ -1101,7 +1113,7 @@ fn containerDecl(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node.Con
1101 if (rl == .ref) {1113 if (rl == .ref) {
1102 return addZIRInst(mod, scope, src, zir.Inst.DeclRef, .{ .decl = decl }, .{});1114 return addZIRInst(mod, scope, src, zir.Inst.DeclRef, .{ .decl = decl }, .{});
1103 } else {1115 } else {
1104 return rlWrap(mod, scope, rl, try addZIRInst(mod, scope, src, zir.Inst.DeclVal, .{1116 return rvalue(mod, scope, rl, try addZIRInst(mod, scope, src, zir.Inst.DeclVal, .{
1105 .decl = decl,1117 .decl = decl,
1106 }, .{}));1118 }, .{}));
1107 }1119 }
...@@ -1200,6 +1212,9 @@ fn orelseCatchExpr(...@@ -1200,6 +1212,9 @@ fn orelseCatchExpr(
1200 rhs: *ast.Node,1212 rhs: *ast.Node,
1201 payload_node: ?*ast.Node,1213 payload_node: ?*ast.Node,
1202) InnerError!*zir.Inst {1214) InnerError!*zir.Inst {
1215 if (true) {
1216 @panic("TODO reimplement this");
1217 }
1203 const tree = scope.tree();1218 const tree = scope.tree();
1204 const src = tree.token_locs[op_token].start;1219 const src = tree.token_locs[op_token].start;
12051220
...@@ -1308,7 +1323,7 @@ pub fn field(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node.SimpleI...@@ -1308,7 +1323,7 @@ pub fn field(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node.SimpleI
1308 .field_name = field_name,1323 .field_name = field_name,
1309 });1324 });
1310 }1325 }
1311 return rlWrap(mod, scope, rl, try addZirInstTag(mod, scope, src, .field_val, .{1326 return rvalue(mod, scope, rl, try addZirInstTag(mod, scope, src, .field_val, .{
1312 .object = try expr(mod, scope, .none, node.lhs),1327 .object = try expr(mod, scope, .none, node.lhs),
1313 .field_name = field_name,1328 .field_name = field_name,
1314 }));1329 }));
...@@ -1338,7 +1353,7 @@ fn namedField(...@@ -1338,7 +1353,7 @@ fn namedField(
1338 .field_name = try comptimeExpr(mod, scope, string_rl, params[1]),1353 .field_name = try comptimeExpr(mod, scope, string_rl, params[1]),
1339 });1354 });
1340 }1355 }
1341 return rlWrap(mod, scope, rl, try addZirInstTag(mod, scope, src, .field_val_named, .{1356 return rvalue(mod, scope, rl, try addZirInstTag(mod, scope, src, .field_val_named, .{
1342 .object = try expr(mod, scope, .none, params[0]),1357 .object = try expr(mod, scope, .none, params[0]),
1343 .field_name = try comptimeExpr(mod, scope, string_rl, params[1]),1358 .field_name = try comptimeExpr(mod, scope, string_rl, params[1]),
1344 }));1359 }));
...@@ -1359,7 +1374,7 @@ fn arrayAccess(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node.Array...@@ -1359,7 +1374,7 @@ fn arrayAccess(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node.Array
1359 .index = try expr(mod, scope, index_rl, node.index_expr),1374 .index = try expr(mod, scope, index_rl, node.index_expr),
1360 });1375 });
1361 }1376 }
1362 return rlWrap(mod, scope, rl, try addZirInstTag(mod, scope, src, .elem_val, .{1377 return rvalue(mod, scope, rl, try addZirInstTag(mod, scope, src, .elem_val, .{
1363 .array = try expr(mod, scope, .none, node.lhs),1378 .array = try expr(mod, scope, .none, node.lhs),
1364 .index = try expr(mod, scope, index_rl, node.index_expr),1379 .index = try expr(mod, scope, index_rl, node.index_expr),
1365 }));1380 }));
...@@ -1416,7 +1431,7 @@ fn simpleBinOp(...@@ -1416,7 +1431,7 @@ fn simpleBinOp(
1416 const rhs = try expr(mod, scope, .none, infix_node.rhs);1431 const rhs = try expr(mod, scope, .none, infix_node.rhs);
14171432
1418 const result = try addZIRBinOp(mod, scope, src, op_inst_tag, lhs, rhs);1433 const result = try addZIRBinOp(mod, scope, src, op_inst_tag, lhs, rhs);
1419 return rlWrap(mod, scope, rl, result);1434 return rvalue(mod, scope, rl, result);
1420}1435}
14211436
1422fn boolBinOp(1437fn boolBinOp(
...@@ -1498,7 +1513,7 @@ fn boolBinOp(...@@ -1498,7 +1513,7 @@ fn boolBinOp(
1498 condbr.positionals.else_body = .{ .instructions = try rhs_scope.arena.dupe(*zir.Inst, rhs_scope.instructions.items) };1513 condbr.positionals.else_body = .{ .instructions = try rhs_scope.arena.dupe(*zir.Inst, rhs_scope.instructions.items) };
1499 }1514 }
15001515
1501 return rlWrap(mod, scope, rl, &block.base);1516 return rvalue(mod, scope, rl, &block.base);
1502}1517}
15031518
1504const CondKind = union(enum) {1519const CondKind = union(enum) {
...@@ -1578,6 +1593,7 @@ fn ifExpr(mod: *Module, scope: *Scope, rl: ResultLoc, if_node: *ast.Node.If) Inn...@@ -1578,6 +1593,7 @@ fn ifExpr(mod: *Module, scope: *Scope, rl: ResultLoc, if_node: *ast.Node.If) Inn
1578 cond_kind = .{ .err_union = null };1593 cond_kind = .{ .err_union = null };
1579 }1594 }
1580 }1595 }
1596 const block_branch_count = 2; // then and else
1581 var block_scope: Scope.GenZIR = .{1597 var block_scope: Scope.GenZIR = .{
1582 .parent = scope,1598 .parent = scope,
1583 .decl = scope.ownerDecl().?,1599 .decl = scope.ownerDecl().?,
...@@ -1600,6 +1616,33 @@ fn ifExpr(mod: *Module, scope: *Scope, rl: ResultLoc, if_node: *ast.Node.If) Inn...@@ -1600,6 +1616,33 @@ fn ifExpr(mod: *Module, scope: *Scope, rl: ResultLoc, if_node: *ast.Node.If) Inn
1600 .instructions = try block_scope.arena.dupe(*zir.Inst, block_scope.instructions.items),1616 .instructions = try block_scope.arena.dupe(*zir.Inst, block_scope.instructions.items),
1601 });1617 });
16021618
1619 // Depending on whether the result location is a pointer or value, different
1620 // ZIR needs to be generated. In the former case we rely on storing to the
1621 // pointer to communicate the result, and use breakvoid; in the latter case
1622 // the block break instructions will have the result values.
1623 // One more complication: when the result location is a pointer, we detect
1624 // the scenario where the result location is not consumed. In this case
1625 // we emit ZIR for the block break instructions to have the result values,
1626 // and then rvalue() on that to pass the value to the result location.
1627 const branch_rl: ResultLoc = switch (rl) {
1628 .discard, .none, .ty, .ptr, .ref => rl,
1629
1630 .inferred_ptr => |ptr| blk: {
1631 block_scope.rl_ptr = &ptr.base;
1632 break :blk .{ .block_ptr = &block_scope };
1633 },
1634
1635 .bitcasted_ptr => |ptr| blk: {
1636 block_scope.rl_ptr = &ptr.base;
1637 break :blk .{ .block_ptr = &block_scope };
1638 },
1639
1640 .block_ptr => |parent_block_scope| blk: {
1641 block_scope.rl_ptr = parent_block_scope.rl_ptr.?;
1642 break :blk .{ .block_ptr = &block_scope };
1643 },
1644 };
1645
1603 const then_src = tree.token_locs[if_node.body.lastToken()].start;1646 const then_src = tree.token_locs[if_node.body.lastToken()].start;
1604 var then_scope: Scope.GenZIR = .{1647 var then_scope: Scope.GenZIR = .{
1605 .parent = scope,1648 .parent = scope,
...@@ -1612,25 +1655,10 @@ fn ifExpr(mod: *Module, scope: *Scope, rl: ResultLoc, if_node: *ast.Node.If) Inn...@@ -1612,25 +1655,10 @@ fn ifExpr(mod: *Module, scope: *Scope, rl: ResultLoc, if_node: *ast.Node.If) Inn
1612 // declare payload to the then_scope1655 // declare payload to the then_scope
1613 const then_sub_scope = try cond_kind.thenSubScope(mod, &then_scope, then_src, if_node.payload);1656 const then_sub_scope = try cond_kind.thenSubScope(mod, &then_scope, then_src, if_node.payload);
16141657
1615 // Most result location types can be forwarded directly; however
1616 // if we need to write to a pointer which has an inferred type,
1617 // proper type inference requires peer type resolution on the if's
1618 // branches.
1619 const branch_rl: ResultLoc = switch (rl) {
1620 .discard, .none, .ty, .ptr, .ref => rl,
1621 .inferred_ptr, .bitcasted_ptr, .block_ptr => .{ .block_ptr = block },
1622 };
1623
1624 const then_result = try expr(mod, then_sub_scope, branch_rl, if_node.body);1658 const then_result = try expr(mod, then_sub_scope, branch_rl, if_node.body);
1625 if (!then_result.tag.isNoReturn()) {1659 // We hold off on the break instructions as well as copying the then/else
1626 _ = try addZIRInst(mod, then_sub_scope, then_src, zir.Inst.Break, .{1660 // instructions into place until we know whether to keep store_to_block_ptr
1627 .block = block,1661 // instructions or not.
1628 .operand = then_result,
1629 }, .{});
1630 }
1631 condbr.positionals.then_body = .{
1632 .instructions = try then_scope.arena.dupe(*zir.Inst, then_scope.instructions.items),
1633 };
16341662
1635 var else_scope: Scope.GenZIR = .{1663 var else_scope: Scope.GenZIR = .{
1636 .parent = scope,1664 .parent = scope,
...@@ -1640,34 +1668,127 @@ fn ifExpr(mod: *Module, scope: *Scope, rl: ResultLoc, if_node: *ast.Node.If) Inn...@@ -1640,34 +1668,127 @@ fn ifExpr(mod: *Module, scope: *Scope, rl: ResultLoc, if_node: *ast.Node.If) Inn
1640 };1668 };
1641 defer else_scope.instructions.deinit(mod.gpa);1669 defer else_scope.instructions.deinit(mod.gpa);
16421670
1643 if (if_node.@"else") |else_node| {1671 var else_src: usize = undefined;
1644 const else_src = tree.token_locs[else_node.body.lastToken()].start;1672 var else_sub_scope: *Module.Scope = undefined;
1673 const else_result: ?*zir.Inst = if (if_node.@"else") |else_node| blk: {
1674 else_src = tree.token_locs[else_node.body.lastToken()].start;
1645 // declare payload to the then_scope1675 // declare payload to the then_scope
1646 const else_sub_scope = try cond_kind.elseSubScope(mod, &else_scope, else_src, else_node.payload);1676 else_sub_scope = try cond_kind.elseSubScope(mod, &else_scope, else_src, else_node.payload);
1677
1678 break :blk try expr(mod, else_sub_scope, branch_rl, else_node.body);
1679 } else blk: {
1680 else_src = tree.token_locs[if_node.lastToken()].start;
1681 else_sub_scope = &else_scope.base;
1682 block_scope.rvalue_rl_count += 1;
1683 break :blk null;
1684 };
16471685
1648 const else_result = try expr(mod, else_sub_scope, branch_rl, else_node.body);1686 // We now have enough information to decide whether the result instruction should
1649 if (!else_result.tag.isNoReturn()) {1687 // be communicated via result location pointer or break instructions.
1650 _ = try addZIRInst(mod, else_sub_scope, else_src, zir.Inst.Break, .{1688 const Strategy = enum {
1651 .block = block,1689 /// Both branches will use break_void; result location is used to communicate the
1652 .operand = else_result,1690 /// result instruction.
1653 }, .{});1691 break_void,
1654 }1692 /// Use break statements to pass the block result value, and call rvalue() at
1655 } else {1693 /// the end depending on rl. Also elide the store_to_block_ptr instructions
1656 // TODO Optimization opportunity: we can avoid an allocation and a memcpy here1694 /// depending on rl.
1657 // by directly allocating the body for this one instruction.1695 break_operand,
1658 const else_src = tree.token_locs[if_node.lastToken()].start;1696 };
1659 _ = try addZIRInst(mod, &else_scope.base, else_src, zir.Inst.BreakVoid, .{1697 var elide_store_to_block_ptr_instructions = false;
1660 .block = block,1698 const strategy: Strategy = switch (rl) {
1661 }, .{});1699 // In this branch there will not be any store_to_block_ptr instructions.
1700 .discard, .none, .ty, .ref => .break_operand,
1701 // The pointer got passed through to the sub-expressions, so we will use
1702 // break_void here.
1703 // In this branch there will not be any store_to_block_ptr instructions.
1704 .ptr => .break_void,
1705 .inferred_ptr, .bitcasted_ptr, .block_ptr => blk: {
1706 if (block_scope.rvalue_rl_count == 2) {
1707 // Neither prong of the if consumed the result location, so we can
1708 // use break instructions to create an rvalue.
1709 elide_store_to_block_ptr_instructions = true;
1710 break :blk Strategy.break_operand;
1711 } else {
1712 // Allow the store_to_block_ptr instructions to remain so that
1713 // semantic analysis can turn them into bitcasts.
1714 break :blk Strategy.break_void;
1715 }
1716 },
1717 };
1718 switch (strategy) {
1719 .break_void => {
1720 if (!then_result.tag.isNoReturn()) {
1721 _ = try addZIRNoOp(mod, then_sub_scope, then_src, .break_void);
1722 }
1723 if (else_result) |inst| {
1724 if (!inst.tag.isNoReturn()) {
1725 _ = try addZIRNoOp(mod, else_sub_scope, else_src, .break_void);
1726 }
1727 } else {
1728 _ = try addZIRNoOp(mod, else_sub_scope, else_src, .break_void);
1729 }
1730 assert(!elide_store_to_block_ptr_instructions);
1731 try copyBodyNoEliding(&condbr.positionals.then_body, then_scope);
1732 try copyBodyNoEliding(&condbr.positionals.else_body, else_scope);
1733 return &block.base;
1734 },
1735 .break_operand => {
1736 if (!then_result.tag.isNoReturn()) {
1737 _ = try addZirInstTag(mod, then_sub_scope, then_src, .@"break", .{
1738 .block = block,
1739 .operand = then_result,
1740 });
1741 }
1742 if (else_result) |inst| {
1743 if (!inst.tag.isNoReturn()) {
1744 _ = try addZirInstTag(mod, else_sub_scope, else_src, .@"break", .{
1745 .block = block,
1746 .operand = inst,
1747 });
1748 }
1749 } else {
1750 _ = try addZIRNoOp(mod, else_sub_scope, else_src, .break_void);
1751 }
1752 if (elide_store_to_block_ptr_instructions) {
1753 try copyBodyWithElidedStoreBlockPtr(&condbr.positionals.then_body, then_scope);
1754 try copyBodyWithElidedStoreBlockPtr(&condbr.positionals.else_body, else_scope);
1755 } else {
1756 try copyBodyNoEliding(&condbr.positionals.then_body, then_scope);
1757 try copyBodyNoEliding(&condbr.positionals.else_body, else_scope);
1758 }
1759 switch (rl) {
1760 .ref => return &block.base,
1761 else => return rvalue(mod, scope, rl, &block.base),
1762 }
1763 },
1662 }1764 }
1663 condbr.positionals.else_body = .{1765}
1664 .instructions = try else_scope.arena.dupe(*zir.Inst, else_scope.instructions.items),1766
1767/// Expects to find exactly 1 .store_to_block_ptr instruction.
1768fn copyBodyWithElidedStoreBlockPtr(body: *zir.Body, scope: Module.Scope.GenZIR) !void {
1769 body.* = .{
1770 .instructions = try scope.arena.alloc(*zir.Inst, scope.instructions.items.len - 1),
1665 };1771 };
1772 var dst_index: usize = 0;
1773 for (scope.instructions.items) |src_inst| {
1774 if (src_inst.tag != .store_to_block_ptr) {
1775 body.instructions[dst_index] = src_inst;
1776 dst_index += 1;
1777 }
1778 }
1779 assert(dst_index == body.instructions.len);
1780}
16661781
1667 return &block.base;1782fn copyBodyNoEliding(body: *zir.Body, scope: Module.Scope.GenZIR) !void {
1783 body.* = .{
1784 .instructions = try scope.arena.dupe(*zir.Inst, scope.instructions.items),
1785 };
1668}1786}
16691787
1670fn whileExpr(mod: *Module, scope: *Scope, rl: ResultLoc, while_node: *ast.Node.While) InnerError!*zir.Inst {1788fn whileExpr(mod: *Module, scope: *Scope, rl: ResultLoc, while_node: *ast.Node.While) InnerError!*zir.Inst {
1789 if (true) {
1790 @panic("TODO reimplement this");
1791 }
1671 var cond_kind: CondKind = .bool;1792 var cond_kind: CondKind = .bool;
1672 if (while_node.payload) |_| cond_kind = .{ .optional = null };1793 if (while_node.payload) |_| cond_kind = .{ .optional = null };
1673 if (while_node.@"else") |else_node| {1794 if (while_node.@"else") |else_node| {
...@@ -1821,6 +1942,9 @@ fn forExpr(...@@ -1821,6 +1942,9 @@ fn forExpr(
1821 rl: ResultLoc,1942 rl: ResultLoc,
1822 for_node: *ast.Node.For,1943 for_node: *ast.Node.For,
1823) InnerError!*zir.Inst {1944) InnerError!*zir.Inst {
1945 if (true) {
1946 @panic("TODO reimplement this");
1947 }
1824 if (for_node.label) |label| {1948 if (for_node.label) |label| {
1825 try checkLabelRedefinition(mod, scope, label);1949 try checkLabelRedefinition(mod, scope, label);
1826 }1950 }
...@@ -2017,6 +2141,9 @@ fn getRangeNode(node: *ast.Node) ?*ast.Node.SimpleInfixOp {...@@ -2017,6 +2141,9 @@ fn getRangeNode(node: *ast.Node) ?*ast.Node.SimpleInfixOp {
2017}2141}
20182142
2019fn switchExpr(mod: *Module, scope: *Scope, rl: ResultLoc, switch_node: *ast.Node.Switch) InnerError!*zir.Inst {2143fn switchExpr(mod: *Module, scope: *Scope, rl: ResultLoc, switch_node: *ast.Node.Switch) InnerError!*zir.Inst {
2144 if (true) {
2145 @panic("TODO reimplement this");
2146 }
2020 var block_scope: Scope.GenZIR = .{2147 var block_scope: Scope.GenZIR = .{
2021 .parent = scope,2148 .parent = scope,
2022 .decl = scope.ownerDecl().?,2149 .decl = scope.ownerDecl().?,
...@@ -2186,10 +2313,10 @@ fn switchExpr(mod: *Module, scope: *Scope, rl: ResultLoc, switch_node: *ast.Node...@@ -2186,10 +2313,10 @@ fn switchExpr(mod: *Module, scope: *Scope, rl: ResultLoc, switch_node: *ast.Node
2186 // target >= start and target <= end2313 // target >= start and target <= end
2187 const range_start_ok = try addZIRBinOp(mod, &else_scope.base, range_src, .cmp_gte, target, start);2314 const range_start_ok = try addZIRBinOp(mod, &else_scope.base, range_src, .cmp_gte, target, start);
2188 const range_end_ok = try addZIRBinOp(mod, &else_scope.base, range_src, .cmp_lte, target, end);2315 const range_end_ok = try addZIRBinOp(mod, &else_scope.base, range_src, .cmp_lte, target, end);
2189 const range_ok = try addZIRBinOp(mod, &else_scope.base, range_src, .booland, range_start_ok, range_end_ok);2316 const range_ok = try addZIRBinOp(mod, &else_scope.base, range_src, .bool_and, range_start_ok, range_end_ok);
21902317
2191 if (any_ok) |some| {2318 if (any_ok) |some| {
2192 any_ok = try addZIRBinOp(mod, &else_scope.base, range_src, .boolor, some, range_ok);2319 any_ok = try addZIRBinOp(mod, &else_scope.base, range_src, .bool_or, some, range_ok);
2193 } else {2320 } else {
2194 any_ok = range_ok;2321 any_ok = range_ok;
2195 }2322 }
...@@ -2201,7 +2328,7 @@ fn switchExpr(mod: *Module, scope: *Scope, rl: ResultLoc, switch_node: *ast.Node...@@ -2201,7 +2328,7 @@ fn switchExpr(mod: *Module, scope: *Scope, rl: ResultLoc, switch_node: *ast.Node
2201 const cpm_ok = try addZIRBinOp(mod, &else_scope.base, item_inst.src, .cmp_eq, target, item_inst);2328 const cpm_ok = try addZIRBinOp(mod, &else_scope.base, item_inst.src, .cmp_eq, target, item_inst);
22022329
2203 if (any_ok) |some| {2330 if (any_ok) |some| {
2204 any_ok = try addZIRBinOp(mod, &else_scope.base, item_inst.src, .boolor, some, cpm_ok);2331 any_ok = try addZIRBinOp(mod, &else_scope.base, item_inst.src, .bool_or, some, cpm_ok);
2205 } else {2332 } else {
2206 any_ok = cpm_ok;2333 any_ok = cpm_ok;
2207 }2334 }
...@@ -2238,7 +2365,7 @@ fn switchExpr(mod: *Module, scope: *Scope, rl: ResultLoc, switch_node: *ast.Node...@@ -2238,7 +2365,7 @@ fn switchExpr(mod: *Module, scope: *Scope, rl: ResultLoc, switch_node: *ast.Node
2238 try switchCaseExpr(mod, &else_scope.base, case_rl, block, case);2365 try switchCaseExpr(mod, &else_scope.base, case_rl, block, case);
2239 } else {2366 } else {
2240 // Not handling all possible cases is a compile error.2367 // Not handling all possible cases is a compile error.
2241 _ = try addZIRNoOp(mod, &else_scope.base, switch_src, .unreach_nocheck);2368 _ = try addZIRNoOp(mod, &else_scope.base, switch_src, .unreachable_unsafe);
2242 }2369 }
22432370
2244 // All items have been generated, add the instructions to the comptime block.2371 // All items have been generated, add the instructions to the comptime block.
...@@ -2288,7 +2415,7 @@ fn ret(mod: *Module, scope: *Scope, cfe: *ast.Node.ControlFlowExpression) InnerE...@@ -2288,7 +2415,7 @@ fn ret(mod: *Module, scope: *Scope, cfe: *ast.Node.ControlFlowExpression) InnerE
2288 return addZIRUnOp(mod, scope, src, .@"return", operand);2415 return addZIRUnOp(mod, scope, src, .@"return", operand);
2289 }2416 }
2290 } else {2417 } else {
2291 return addZIRNoOp(mod, scope, src, .returnvoid);2418 return addZIRNoOp(mod, scope, src, .return_void);
2292 }2419 }
2293}2420}
22942421
...@@ -2305,7 +2432,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo...@@ -2305,7 +2432,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo
23052432
2306 if (getSimplePrimitiveValue(ident_name)) |typed_value| {2433 if (getSimplePrimitiveValue(ident_name)) |typed_value| {
2307 const result = try addZIRInstConst(mod, scope, src, typed_value);2434 const result = try addZIRInstConst(mod, scope, src, typed_value);
2308 return rlWrap(mod, scope, rl, result);2435 return rvalue(mod, scope, rl, result);
2309 }2436 }
23102437
2311 if (ident_name.len >= 2) integer: {2438 if (ident_name.len >= 2) integer: {
...@@ -2327,7 +2454,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo...@@ -2327,7 +2454,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo
2327 32 => if (is_signed) Value.initTag(.i32_type) else Value.initTag(.u32_type),2454 32 => if (is_signed) Value.initTag(.i32_type) else Value.initTag(.u32_type),
2328 64 => if (is_signed) Value.initTag(.i64_type) else Value.initTag(.u64_type),2455 64 => if (is_signed) Value.initTag(.i64_type) else Value.initTag(.u64_type),
2329 else => {2456 else => {
2330 return rlWrap(mod, scope, rl, try addZIRInstConst(mod, scope, src, .{2457 return rvalue(mod, scope, rl, try addZIRInstConst(mod, scope, src, .{
2331 .ty = Type.initTag(.type),2458 .ty = Type.initTag(.type),
2332 .val = try Value.Tag.int_type.create(scope.arena(), .{2459 .val = try Value.Tag.int_type.create(scope.arena(), .{
2333 .signed = is_signed,2460 .signed = is_signed,
...@@ -2340,7 +2467,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo...@@ -2340,7 +2467,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo
2340 .ty = Type.initTag(.type),2467 .ty = Type.initTag(.type),
2341 .val = val,2468 .val = val,
2342 });2469 });
2343 return rlWrap(mod, scope, rl, result);2470 return rvalue(mod, scope, rl, result);
2344 }2471 }
2345 }2472 }
23462473
...@@ -2351,7 +2478,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo...@@ -2351,7 +2478,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo
2351 .local_val => {2478 .local_val => {
2352 const local_val = s.cast(Scope.LocalVal).?;2479 const local_val = s.cast(Scope.LocalVal).?;
2353 if (mem.eql(u8, local_val.name, ident_name)) {2480 if (mem.eql(u8, local_val.name, ident_name)) {
2354 return rlWrap(mod, scope, rl, local_val.inst);2481 return rvalue(mod, scope, rl, local_val.inst);
2355 }2482 }
2356 s = local_val.parent;2483 s = local_val.parent;
2357 },2484 },
...@@ -2360,7 +2487,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo...@@ -2360,7 +2487,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo
2360 if (mem.eql(u8, local_ptr.name, ident_name)) {2487 if (mem.eql(u8, local_ptr.name, ident_name)) {
2361 if (rl == .ref) return local_ptr.ptr;2488 if (rl == .ref) return local_ptr.ptr;
2362 const loaded = try addZIRUnOp(mod, scope, src, .deref, local_ptr.ptr);2489 const loaded = try addZIRUnOp(mod, scope, src, .deref, local_ptr.ptr);
2363 return rlWrap(mod, scope, rl, loaded);2490 return rvalue(mod, scope, rl, loaded);
2364 }2491 }
2365 s = local_ptr.parent;2492 s = local_ptr.parent;
2366 },2493 },
...@@ -2373,7 +2500,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo...@@ -2373,7 +2500,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo
2373 if (rl == .ref) {2500 if (rl == .ref) {
2374 return addZIRInst(mod, scope, src, zir.Inst.DeclRef, .{ .decl = decl }, .{});2501 return addZIRInst(mod, scope, src, zir.Inst.DeclRef, .{ .decl = decl }, .{});
2375 } else {2502 } else {
2376 return rlWrap(mod, scope, rl, try addZIRInst(mod, scope, src, zir.Inst.DeclVal, .{2503 return rvalue(mod, scope, rl, try addZIRInst(mod, scope, src, zir.Inst.DeclVal, .{
2377 .decl = decl,2504 .decl = decl,
2378 }, .{}));2505 }, .{}));
2379 }2506 }
...@@ -2590,7 +2717,7 @@ fn simpleCast(...@@ -2590,7 +2717,7 @@ fn simpleCast(
2590 const dest_type = try typeExpr(mod, scope, params[0]);2717 const dest_type = try typeExpr(mod, scope, params[0]);
2591 const rhs = try expr(mod, scope, .none, params[1]);2718 const rhs = try expr(mod, scope, .none, params[1]);
2592 const result = try addZIRBinOp(mod, scope, src, inst_tag, dest_type, rhs);2719 const result = try addZIRBinOp(mod, scope, src, inst_tag, dest_type, rhs);
2593 return rlWrap(mod, scope, rl, result);2720 return rvalue(mod, scope, rl, result);
2594}2721}
25952722
2596fn ptrToInt(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerError!*zir.Inst {2723fn ptrToInt(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerError!*zir.Inst {
...@@ -2634,11 +2761,11 @@ fn as(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.BuiltinCall) I...@@ -2634,11 +2761,11 @@ fn as(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.BuiltinCall) I
2634 // TODO here we should be able to resolve the inference; we now have a type for the result.2761 // TODO here we should be able to resolve the inference; we now have a type for the result.
2635 return mod.failTok(scope, call.builtin_token, "TODO implement @as with inferred-type result location pointer", .{});2762 return mod.failTok(scope, call.builtin_token, "TODO implement @as with inferred-type result location pointer", .{});
2636 },2763 },
2637 .block_ptr => |block_ptr| {2764 .block_ptr => |block_scope| {
2638 const casted_block_ptr = try addZIRInst(mod, scope, src, zir.Inst.CoerceResultBlockPtr, .{2765 const casted_block_ptr = try addZirInstTag(mod, scope, src, .coerce_result_block_ptr, .{
2639 .dest_type = dest_type,2766 .dest_type = dest_type,
2640 .block = block_ptr,2767 .block_ptr = block_scope.rl_ptr.?,
2641 }, .{});2768 });
2642 return expr(mod, scope, .{ .ptr = casted_block_ptr }, params[1]);2769 return expr(mod, scope, .{ .ptr = casted_block_ptr }, params[1]);
2643 },2770 },
2644 }2771 }
...@@ -2703,7 +2830,7 @@ fn compileError(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerE...@@ -2703,7 +2830,7 @@ fn compileError(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerE
2703 const src = tree.token_locs[call.builtin_token].start;2830 const src = tree.token_locs[call.builtin_token].start;
2704 const params = call.params();2831 const params = call.params();
2705 const target = try expr(mod, scope, .none, params[0]);2832 const target = try expr(mod, scope, .none, params[0]);
2706 return addZIRUnOp(mod, scope, src, .compileerror, target);2833 return addZIRUnOp(mod, scope, src, .compile_error, target);
2707}2834}
27082835
2709fn setEvalBranchQuota(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerError!*zir.Inst {2836fn setEvalBranchQuota(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerError!*zir.Inst {
...@@ -2728,12 +2855,12 @@ fn typeOf(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.BuiltinCal...@@ -2728,12 +2855,12 @@ fn typeOf(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.BuiltinCal
2728 return mod.failTok(scope, call.builtin_token, "expected at least 1 argument, found 0", .{});2855 return mod.failTok(scope, call.builtin_token, "expected at least 1 argument, found 0", .{});
2729 }2856 }
2730 if (params.len == 1) {2857 if (params.len == 1) {
2731 return rlWrap(mod, scope, rl, try addZIRUnOp(mod, scope, src, .typeof, try expr(mod, scope, .none, params[0])));2858 return rvalue(mod, scope, rl, try addZIRUnOp(mod, scope, src, .typeof, try expr(mod, scope, .none, params[0])));
2732 }2859 }
2733 var items = try arena.alloc(*zir.Inst, params.len);2860 var items = try arena.alloc(*zir.Inst, params.len);
2734 for (params) |param, param_i|2861 for (params) |param, param_i|
2735 items[param_i] = try expr(mod, scope, .none, param);2862 items[param_i] = try expr(mod, scope, .none, param);
2736 return rlWrap(mod, scope, rl, try addZIRInst(mod, scope, src, zir.Inst.TypeOfPeer, .{ .items = items }, .{}));2863 return rvalue(mod, scope, rl, try addZIRInst(mod, scope, src, zir.Inst.TypeOfPeer, .{ .items = items }, .{}));
2737}2864}
2738fn compileLog(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerError!*zir.Inst {2865fn compileLog(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerError!*zir.Inst {
2739 const tree = scope.tree();2866 const tree = scope.tree();
...@@ -2756,7 +2883,7 @@ fn builtinCall(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.Built...@@ -2756,7 +2883,7 @@ fn builtinCall(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.Built
2756 // Also, some builtins have a variable number of parameters.2883 // Also, some builtins have a variable number of parameters.
27572884
2758 if (mem.eql(u8, builtin_name, "@ptrToInt")) {2885 if (mem.eql(u8, builtin_name, "@ptrToInt")) {
2759 return rlWrap(mod, scope, rl, try ptrToInt(mod, scope, call));2886 return rvalue(mod, scope, rl, try ptrToInt(mod, scope, call));
2760 } else if (mem.eql(u8, builtin_name, "@as")) {2887 } else if (mem.eql(u8, builtin_name, "@as")) {
2761 return as(mod, scope, rl, call);2888 return as(mod, scope, rl, call);
2762 } else if (mem.eql(u8, builtin_name, "@floatCast")) {2889 } else if (mem.eql(u8, builtin_name, "@floatCast")) {
...@@ -2769,9 +2896,9 @@ fn builtinCall(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.Built...@@ -2769,9 +2896,9 @@ fn builtinCall(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.Built
2769 return typeOf(mod, scope, rl, call);2896 return typeOf(mod, scope, rl, call);
2770 } else if (mem.eql(u8, builtin_name, "@breakpoint")) {2897 } else if (mem.eql(u8, builtin_name, "@breakpoint")) {
2771 const src = tree.token_locs[call.builtin_token].start;2898 const src = tree.token_locs[call.builtin_token].start;
2772 return rlWrap(mod, scope, rl, try addZIRNoOp(mod, scope, src, .breakpoint));2899 return rvalue(mod, scope, rl, try addZIRNoOp(mod, scope, src, .breakpoint));
2773 } else if (mem.eql(u8, builtin_name, "@import")) {2900 } else if (mem.eql(u8, builtin_name, "@import")) {
2774 return rlWrap(mod, scope, rl, try import(mod, scope, call));2901 return rvalue(mod, scope, rl, try import(mod, scope, call));
2775 } else if (mem.eql(u8, builtin_name, "@compileError")) {2902 } else if (mem.eql(u8, builtin_name, "@compileError")) {
2776 return compileError(mod, scope, call);2903 return compileError(mod, scope, call);
2777 } else if (mem.eql(u8, builtin_name, "@setEvalBranchQuota")) {2904 } else if (mem.eql(u8, builtin_name, "@setEvalBranchQuota")) {
...@@ -2806,13 +2933,13 @@ fn callExpr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node.Call) In...@@ -2806,13 +2933,13 @@ fn callExpr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node.Call) In
2806 .args = args,2933 .args = args,
2807 }, .{});2934 }, .{});
2808 // TODO function call with result location2935 // TODO function call with result location
2809 return rlWrap(mod, scope, rl, result);2936 return rvalue(mod, scope, rl, result);
2810}2937}
28112938
2812fn unreach(mod: *Module, scope: *Scope, unreach_node: *ast.Node.OneToken) InnerError!*zir.Inst {2939fn unreach(mod: *Module, scope: *Scope, unreach_node: *ast.Node.OneToken) InnerError!*zir.Inst {
2813 const tree = scope.tree();2940 const tree = scope.tree();
2814 const src = tree.token_locs[unreach_node.token].start;2941 const src = tree.token_locs[unreach_node.token].start;
2815 return addZIRNoOp(mod, scope, src, .@"unreachable");2942 return addZIRNoOp(mod, scope, src, .unreachable_safe);
2816}2943}
28172944
2818fn getSimplePrimitiveValue(name: []const u8) ?TypedValue {2945fn getSimplePrimitiveValue(name: []const u8) ?TypedValue {
...@@ -3099,7 +3226,7 @@ fn nodeMayNeedMemoryLocation(start_node: *ast.Node, scope: *Scope) bool {...@@ -3099,7 +3226,7 @@ fn nodeMayNeedMemoryLocation(start_node: *ast.Node, scope: *Scope) bool {
3099/// result locations must call this function on their result.3226/// result locations must call this function on their result.
3100/// As an example, if the `ResultLoc` is `ptr`, it will write the result to the pointer.3227/// As an example, if the `ResultLoc` is `ptr`, it will write the result to the pointer.
3101/// If the `ResultLoc` is `ty`, it will coerce the result to the type.3228/// If the `ResultLoc` is `ty`, it will coerce the result to the type.
3102fn rlWrap(mod: *Module, scope: *Scope, rl: ResultLoc, result: *zir.Inst) InnerError!*zir.Inst {3229fn rvalue(mod: *Module, scope: *Scope, rl: ResultLoc, result: *zir.Inst) InnerError!*zir.Inst {
3103 switch (rl) {3230 switch (rl) {
3104 .none => return result,3231 .none => return result,
3105 .discard => {3232 .discard => {
...@@ -3113,42 +3240,31 @@ fn rlWrap(mod: *Module, scope: *Scope, rl: ResultLoc, result: *zir.Inst) InnerEr...@@ -3113,42 +3240,31 @@ fn rlWrap(mod: *Module, scope: *Scope, rl: ResultLoc, result: *zir.Inst) InnerEr
3113 },3240 },
3114 .ty => |ty_inst| return addZIRBinOp(mod, scope, result.src, .as, ty_inst, result),3241 .ty => |ty_inst| return addZIRBinOp(mod, scope, result.src, .as, ty_inst, result),
3115 .ptr => |ptr_inst| {3242 .ptr => |ptr_inst| {
3116 const casted_result = try addZIRInst(mod, scope, result.src, zir.Inst.CoerceToPtrElem, .{3243 _ = try addZIRBinOp(mod, scope, result.src, .store, ptr_inst, result);
3117 .ptr = ptr_inst,3244 return result;
3118 .value = result,
3119 }, .{});
3120 _ = try addZIRBinOp(mod, scope, result.src, .store, ptr_inst, casted_result);
3121 return casted_result;
3122 },3245 },
3123 .bitcasted_ptr => |bitcasted_ptr| {3246 .bitcasted_ptr => |bitcasted_ptr| {
3124 return mod.fail(scope, result.src, "TODO implement rlWrap .bitcasted_ptr", .{});3247 return mod.fail(scope, result.src, "TODO implement rvalue .bitcasted_ptr", .{});
3125 },3248 },
3126 .inferred_ptr => |alloc| {3249 .inferred_ptr => |alloc| {
3127 _ = try addZIRBinOp(mod, scope, result.src, .store_to_inferred_ptr, &alloc.base, result);3250 _ = try addZIRBinOp(mod, scope, result.src, .store_to_inferred_ptr, &alloc.base, result);
3128 return result;3251 return result;
3129 },3252 },
3130 .block_ptr => |block_ptr| {3253 .block_ptr => |block_scope| {
3131 return mod.fail(scope, result.src, "TODO implement rlWrap .block_ptr", .{});3254 block_scope.rvalue_rl_count += 1;
3255 _ = try addZIRBinOp(mod, scope, result.src, .store_to_block_ptr, block_scope.rl_ptr.?, result);
3256 return result;
3132 },3257 },
3133 }3258 }
3134}3259}
31353260
3136fn rlWrapVoid(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node, result: void) InnerError!*zir.Inst {3261fn rvalueVoid(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node, result: void) InnerError!*zir.Inst {
3137 const src = scope.tree().token_locs[node.firstToken()].start;3262 const src = scope.tree().token_locs[node.firstToken()].start;
3138 const void_inst = try addZIRInstConst(mod, scope, src, .{3263 const void_inst = try addZIRInstConst(mod, scope, src, .{
3139 .ty = Type.initTag(.void),3264 .ty = Type.initTag(.void),
3140 .val = Value.initTag(.void_value),3265 .val = Value.initTag(.void_value),
3141 });3266 });
3142 return rlWrap(mod, scope, rl, void_inst);3267 return rvalue(mod, scope, rl, void_inst);
3143}
3144
3145/// TODO go over all the callsites and see where we can introduce "by-value" ZIR instructions
3146/// to save ZIR memory. For example, see DeclVal vs DeclRef.
3147/// Do not add additional callsites to this function.
3148fn rlWrapPtr(mod: *Module, scope: *Scope, rl: ResultLoc, ptr: *zir.Inst) InnerError!*zir.Inst {
3149 if (rl == .ref) return ptr;
3150
3151 return rlWrap(mod, scope, rl, try addZIRUnOp(mod, scope, ptr.src, .deref, ptr));
3152}3268}
31533269
3154pub fn addZirInstTag(3270pub fn addZirInstTag(
src/codegen.zig+12-12
...@@ -840,14 +840,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -840,14 +840,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
840 .arg => return self.genArg(inst.castTag(.arg).?),840 .arg => return self.genArg(inst.castTag(.arg).?),
841 .assembly => return self.genAsm(inst.castTag(.assembly).?),841 .assembly => return self.genAsm(inst.castTag(.assembly).?),
842 .bitcast => return self.genBitCast(inst.castTag(.bitcast).?),842 .bitcast => return self.genBitCast(inst.castTag(.bitcast).?),
843 .bitand => return self.genBitAnd(inst.castTag(.bitand).?),843 .bit_and => return self.genBitAnd(inst.castTag(.bit_and).?),
844 .bitor => return self.genBitOr(inst.castTag(.bitor).?),844 .bit_or => return self.genBitOr(inst.castTag(.bit_or).?),
845 .block => return self.genBlock(inst.castTag(.block).?),845 .block => return self.genBlock(inst.castTag(.block).?),
846 .br => return self.genBr(inst.castTag(.br).?),846 .br => return self.genBr(inst.castTag(.br).?),
847 .breakpoint => return self.genBreakpoint(inst.src),847 .breakpoint => return self.genBreakpoint(inst.src),
848 .brvoid => return self.genBrVoid(inst.castTag(.brvoid).?),848 .brvoid => return self.genBrVoid(inst.castTag(.brvoid).?),
849 .booland => return self.genBoolOp(inst.castTag(.booland).?),849 .bool_and => return self.genBoolOp(inst.castTag(.bool_and).?),
850 .boolor => return self.genBoolOp(inst.castTag(.boolor).?),850 .bool_or => return self.genBoolOp(inst.castTag(.bool_or).?),
851 .call => return self.genCall(inst.castTag(.call).?),851 .call => return self.genCall(inst.castTag(.call).?),
852 .cmp_lt => return self.genCmp(inst.castTag(.cmp_lt).?, .lt),852 .cmp_lt => return self.genCmp(inst.castTag(.cmp_lt).?, .lt),
853 .cmp_lte => return self.genCmp(inst.castTag(.cmp_lte).?, .lte),853 .cmp_lte => return self.genCmp(inst.castTag(.cmp_lte).?, .lte),
...@@ -1097,7 +1097,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -1097,7 +1097,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
1097 if (inst.base.isUnused())1097 if (inst.base.isUnused())
1098 return MCValue.dead;1098 return MCValue.dead;
1099 switch (arch) {1099 switch (arch) {
1100 .arm, .armeb => return try self.genArmBinOp(&inst.base, inst.lhs, inst.rhs, .bitand),1100 .arm, .armeb => return try self.genArmBinOp(&inst.base, inst.lhs, inst.rhs, .bit_and),
1101 else => return self.fail(inst.base.src, "TODO implement bitwise and for {}", .{self.target.cpu.arch}),1101 else => return self.fail(inst.base.src, "TODO implement bitwise and for {}", .{self.target.cpu.arch}),
1102 }1102 }
1103 }1103 }
...@@ -1107,7 +1107,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -1107,7 +1107,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
1107 if (inst.base.isUnused())1107 if (inst.base.isUnused())
1108 return MCValue.dead;1108 return MCValue.dead;
1109 switch (arch) {1109 switch (arch) {
1110 .arm, .armeb => return try self.genArmBinOp(&inst.base, inst.lhs, inst.rhs, .bitor),1110 .arm, .armeb => return try self.genArmBinOp(&inst.base, inst.lhs, inst.rhs, .bit_or),
1111 else => return self.fail(inst.base.src, "TODO implement bitwise or for {}", .{self.target.cpu.arch}),1111 else => return self.fail(inst.base.src, "TODO implement bitwise or for {}", .{self.target.cpu.arch}),
1112 }1112 }
1113 }1113 }
...@@ -1371,10 +1371,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -1371,10 +1371,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
1371 writeInt(u32, try self.code.addManyAsArray(4), Instruction.rsb(.al, dst_reg, dst_reg, operand).toU32());1371 writeInt(u32, try self.code.addManyAsArray(4), Instruction.rsb(.al, dst_reg, dst_reg, operand).toU32());
1372 }1372 }
1373 },1373 },
1374 .booland, .bitand => {1374 .bool_and, .bit_and => {
1375 writeInt(u32, try self.code.addManyAsArray(4), Instruction.@"and"(.al, dst_reg, dst_reg, operand).toU32());1375 writeInt(u32, try self.code.addManyAsArray(4), Instruction.@"and"(.al, dst_reg, dst_reg, operand).toU32());
1376 },1376 },
1377 .boolor, .bitor => {1377 .bool_or, .bit_or => {
1378 writeInt(u32, try self.code.addManyAsArray(4), Instruction.orr(.al, dst_reg, dst_reg, operand).toU32());1378 writeInt(u32, try self.code.addManyAsArray(4), Instruction.orr(.al, dst_reg, dst_reg, operand).toU32());
1379 },1379 },
1380 .not, .xor => {1380 .not, .xor => {
...@@ -2464,14 +2464,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2464,14 +2464,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2464 switch (arch) {2464 switch (arch) {
2465 .x86_64 => switch (inst.base.tag) {2465 .x86_64 => switch (inst.base.tag) {
2466 // lhs AND rhs2466 // lhs AND rhs
2467 .booland => return try self.genX8664BinMath(&inst.base, inst.lhs, inst.rhs, 4, 0x20),2467 .bool_and => return try self.genX8664BinMath(&inst.base, inst.lhs, inst.rhs, 4, 0x20),
2468 // lhs OR rhs2468 // lhs OR rhs
2469 .boolor => return try self.genX8664BinMath(&inst.base, inst.lhs, inst.rhs, 1, 0x08),2469 .bool_or => return try self.genX8664BinMath(&inst.base, inst.lhs, inst.rhs, 1, 0x08),
2470 else => unreachable, // Not a boolean operation2470 else => unreachable, // Not a boolean operation
2471 },2471 },
2472 .arm, .armeb => switch (inst.base.tag) {2472 .arm, .armeb => switch (inst.base.tag) {
2473 .booland => return try self.genArmBinOp(&inst.base, inst.lhs, inst.rhs, .booland),2473 .bool_and => return try self.genArmBinOp(&inst.base, inst.lhs, inst.rhs, .bool_and),
2474 .boolor => return try self.genArmBinOp(&inst.base, inst.lhs, inst.rhs, .boolor),2474 .bool_or => return try self.genArmBinOp(&inst.base, inst.lhs, inst.rhs, .bool_or),
2475 else => unreachable, // Not a boolean operation2475 else => unreachable, // Not a boolean operation
2476 },2476 },
2477 else => return self.fail(inst.base.src, "TODO implement boolean operations for {}", .{self.target.cpu.arch}),2477 else => return self.fail(inst.base.src, "TODO implement boolean operations for {}", .{self.target.cpu.arch}),
src/ir.zig+8-8
...@@ -56,9 +56,9 @@ pub const Inst = struct {...@@ -56,9 +56,9 @@ pub const Inst = struct {
56 alloc,56 alloc,
57 arg,57 arg,
58 assembly,58 assembly,
59 bitand,59 bit_and,
60 bitcast,60 bitcast,
61 bitor,61 bit_or,
62 block,62 block,
63 br,63 br,
64 breakpoint,64 breakpoint,
...@@ -85,8 +85,8 @@ pub const Inst = struct {...@@ -85,8 +85,8 @@ pub const Inst = struct {
85 is_err,85 is_err,
86 // *E!T => bool86 // *E!T => bool
87 is_err_ptr,87 is_err_ptr,
88 booland,88 bool_and,
89 boolor,89 bool_or,
90 /// Read a value from a pointer.90 /// Read a value from a pointer.
91 load,91 load,
92 loop,92 loop,
...@@ -147,10 +147,10 @@ pub const Inst = struct {...@@ -147,10 +147,10 @@ pub const Inst = struct {
147 .cmp_gt,147 .cmp_gt,
148 .cmp_neq,148 .cmp_neq,
149 .store,149 .store,
150 .booland,150 .bool_and,
151 .boolor,151 .bool_or,
152 .bitand,152 .bit_and,
153 .bitor,153 .bit_or,
154 .xor,154 .xor,
155 => BinOp,155 => BinOp,
156156
src/zir.zig+73-82
...@@ -59,7 +59,7 @@ pub const Inst = struct {...@@ -59,7 +59,7 @@ pub const Inst = struct {
59 /// Inline assembly.59 /// Inline assembly.
60 @"asm",60 @"asm",
61 /// Bitwise AND. `&`61 /// Bitwise AND. `&`
62 bitand,62 bit_and,
63 /// TODO delete this instruction, it has no purpose.63 /// TODO delete this instruction, it has no purpose.
64 bitcast,64 bitcast,
65 /// An arbitrary typed pointer is pointer-casted to a new Pointer.65 /// An arbitrary typed pointer is pointer-casted to a new Pointer.
...@@ -71,9 +71,9 @@ pub const Inst = struct {...@@ -71,9 +71,9 @@ pub const Inst = struct {
71 /// The new result location pointer has an inferred type.71 /// The new result location pointer has an inferred type.
72 bitcast_result_ptr,72 bitcast_result_ptr,
73 /// Bitwise NOT. `~`73 /// Bitwise NOT. `~`
74 bitnot,74 bit_not,
75 /// Bitwise OR. `|`75 /// Bitwise OR. `|`
76 bitor,76 bit_or,
77 /// A labeled block of code, which can return a value.77 /// A labeled block of code, which can return a value.
78 block,78 block,
79 /// A block of code, which can return a value. There are no instructions that break out of79 /// A block of code, which can return a value. There are no instructions that break out of
...@@ -83,17 +83,17 @@ pub const Inst = struct {...@@ -83,17 +83,17 @@ pub const Inst = struct {
83 block_comptime,83 block_comptime,
84 /// Same as `block_flat` but additionally makes the inner instructions execute at comptime.84 /// Same as `block_flat` but additionally makes the inner instructions execute at comptime.
85 block_comptime_flat,85 block_comptime_flat,
86 /// Boolean AND. See also `bitand`.86 /// Boolean AND. See also `bit_and`.
87 booland,87 bool_and,
88 /// Boolean NOT. See also `bitnot`.88 /// Boolean NOT. See also `bit_not`.
89 boolnot,89 bool_not,
90 /// Boolean OR. See also `bitor`.90 /// Boolean OR. See also `bit_or`.
91 boolor,91 bool_or,
92 /// Return a value from a `Block`.92 /// Return a value from a `Block`.
93 @"break",93 @"break",
94 breakpoint,94 breakpoint,
95 /// Same as `break` but without an operand; the operand is assumed to be the void value.95 /// Same as `break` but without an operand; the operand is assumed to be the void value.
96 breakvoid,96 break_void,
97 /// Function call.97 /// Function call.
98 call,98 call,
99 /// `<`99 /// `<`
...@@ -116,12 +116,10 @@ pub const Inst = struct {...@@ -116,12 +116,10 @@ pub const Inst = struct {
116 /// result location pointer, whose type is inferred by peer type resolution on the116 /// result location pointer, whose type is inferred by peer type resolution on the
117 /// `Block`'s corresponding `break` instructions.117 /// `Block`'s corresponding `break` instructions.
118 coerce_result_block_ptr,118 coerce_result_block_ptr,
119 /// Equivalent to `as(ptr_child_type(typeof(ptr)), value)`.
120 coerce_to_ptr_elem,
121 /// Emit an error message and fail compilation.119 /// Emit an error message and fail compilation.
122 compileerror,120 compile_error,
123 /// Log compile time variables and emit an error message.121 /// Log compile time variables and emit an error message.
124 compilelog,122 compile_log,
125 /// Conditional branch. Splits control flow based on a boolean condition value.123 /// Conditional branch. Splits control flow based on a boolean condition value.
126 condbr,124 condbr,
127 /// Special case, has no textual representation.125 /// Special case, has no textual representation.
...@@ -135,11 +133,11 @@ pub const Inst = struct {...@@ -135,11 +133,11 @@ pub const Inst = struct {
135 /// Declares the beginning of a statement. Used for debug info.133 /// Declares the beginning of a statement. Used for debug info.
136 dbg_stmt,134 dbg_stmt,
137 /// Represents a pointer to a global decl.135 /// Represents a pointer to a global decl.
138 declref,136 decl_ref,
139 /// Represents a pointer to a global decl by string name.137 /// Represents a pointer to a global decl by string name.
140 declref_str,138 decl_ref_str,
141 /// Equivalent to a declref followed by deref.139 /// Equivalent to a decl_ref followed by deref.
142 declval,140 decl_val,
143 /// Load the value from a pointer.141 /// Load the value from a pointer.
144 deref,142 deref,
145 /// Arithmetic division. Asserts no integer overflow.143 /// Arithmetic division. Asserts no integer overflow.
...@@ -185,7 +183,7 @@ pub const Inst = struct {...@@ -185,7 +183,7 @@ pub const Inst = struct {
185 /// can hold the same mathematical value.183 /// can hold the same mathematical value.
186 intcast,184 intcast,
187 /// Make an integer type out of signedness and bit count.185 /// Make an integer type out of signedness and bit count.
188 inttype,186 int_type,
189 /// Return a boolean false if an optional is null. `x != null`187 /// Return a boolean false if an optional is null. `x != null`
190 is_non_null,188 is_non_null,
191 /// Return a boolean true if an optional is null. `x == null`189 /// Return a boolean true if an optional is null. `x == null`
...@@ -232,7 +230,7 @@ pub const Inst = struct {...@@ -232,7 +230,7 @@ pub const Inst = struct {
232 /// Sends control flow back to the function's callee. Takes an operand as the return value.230 /// Sends control flow back to the function's callee. Takes an operand as the return value.
233 @"return",231 @"return",
234 /// Same as `return` but there is no operand; the operand is implicitly the void value.232 /// Same as `return` but there is no operand; the operand is implicitly the void value.
235 returnvoid,233 return_void,
236 /// Changes the maximum number of backwards branches that compile-time234 /// Changes the maximum number of backwards branches that compile-time
237 /// code execution can use before giving up and making a compile error.235 /// code execution can use before giving up and making a compile error.
238 set_eval_branch_quota,236 set_eval_branch_quota,
...@@ -270,6 +268,10 @@ pub const Inst = struct {...@@ -270,6 +268,10 @@ pub const Inst = struct {
270 /// Write a value to a pointer. For loading, see `deref`.268 /// Write a value to a pointer. For loading, see `deref`.
271 store,269 store,
272 /// Same as `store` but the type of the value being stored will be used to infer270 /// Same as `store` but the type of the value being stored will be used to infer
271 /// the block type. The LHS is a block instruction, whose result location is
272 /// being stored to.
273 store_to_block_ptr,
274 /// Same as `store` but the type of the value being stored will be used to infer
273 /// the pointer type.275 /// the pointer type.
274 store_to_inferred_ptr,276 store_to_inferred_ptr,
275 /// String Literal. Makes an anonymous Decl and then takes a pointer to it.277 /// String Literal. Makes an anonymous Decl and then takes a pointer to it.
...@@ -286,11 +288,11 @@ pub const Inst = struct {...@@ -286,11 +288,11 @@ pub const Inst = struct {
286 typeof_peer,288 typeof_peer,
287 /// Asserts control-flow will not reach this instruction. Not safety checked - the compiler289 /// Asserts control-flow will not reach this instruction. Not safety checked - the compiler
288 /// will assume the correctness of this instruction.290 /// will assume the correctness of this instruction.
289 unreach_nocheck,291 unreachable_unsafe,
290 /// Asserts control-flow will not reach this instruction. In safety-checked modes,292 /// Asserts control-flow will not reach this instruction. In safety-checked modes,
291 /// this will generate a call to the panic function unless it can be proven unreachable293 /// this will generate a call to the panic function unless it can be proven unreachable
292 /// by the compiler.294 /// by the compiler.
293 @"unreachable",295 unreachable_safe,
294 /// Bitwise XOR. `^`296 /// Bitwise XOR. `^`
295 xor,297 xor,
296 /// Create an optional type '?T'298 /// Create an optional type '?T'
...@@ -352,17 +354,17 @@ pub const Inst = struct {...@@ -352,17 +354,17 @@ pub const Inst = struct {
352 .alloc_inferred_mut,354 .alloc_inferred_mut,
353 .breakpoint,355 .breakpoint,
354 .dbg_stmt,356 .dbg_stmt,
355 .returnvoid,357 .return_void,
356 .ret_ptr,358 .ret_ptr,
357 .ret_type,359 .ret_type,
358 .unreach_nocheck,360 .unreachable_unsafe,
359 .@"unreachable",361 .unreachable_safe,
360 => NoOp,362 => NoOp,
361363
362 .alloc,364 .alloc,
363 .alloc_mut,365 .alloc_mut,
364 .boolnot,366 .bool_not,
365 .compileerror,367 .compile_error,
366 .deref,368 .deref,
367 .@"return",369 .@"return",
368 .is_null,370 .is_null,
...@@ -400,7 +402,7 @@ pub const Inst = struct {...@@ -400,7 +402,7 @@ pub const Inst = struct {
400 .err_union_code_ptr,402 .err_union_code_ptr,
401 .ensure_err_payload_void,403 .ensure_err_payload_void,
402 .anyframe_type,404 .anyframe_type,
403 .bitnot,405 .bit_not,
404 .import,406 .import,
405 .set_eval_branch_quota,407 .set_eval_branch_quota,
406 .indexable_ptr_len,408 .indexable_ptr_len,
...@@ -411,10 +413,10 @@ pub const Inst = struct {...@@ -411,10 +413,10 @@ pub const Inst = struct {
411 .array_cat,413 .array_cat,
412 .array_mul,414 .array_mul,
413 .array_type,415 .array_type,
414 .bitand,416 .bit_and,
415 .bitor,417 .bit_or,
416 .booland,418 .bool_and,
417 .boolor,419 .bool_or,
418 .div,420 .div,
419 .mod_rem,421 .mod_rem,
420 .mul,422 .mul,
...@@ -422,6 +424,7 @@ pub const Inst = struct {...@@ -422,6 +424,7 @@ pub const Inst = struct {
422 .shl,424 .shl,
423 .shr,425 .shr,
424 .store,426 .store,
427 .store_to_block_ptr,
425 .store_to_inferred_ptr,428 .store_to_inferred_ptr,
426 .sub,429 .sub,
427 .subwrap,430 .subwrap,
...@@ -452,19 +455,18 @@ pub const Inst = struct {...@@ -452,19 +455,18 @@ pub const Inst = struct {
452 .arg => Arg,455 .arg => Arg,
453 .array_type_sentinel => ArrayTypeSentinel,456 .array_type_sentinel => ArrayTypeSentinel,
454 .@"break" => Break,457 .@"break" => Break,
455 .breakvoid => BreakVoid,458 .break_void => BreakVoid,
456 .call => Call,459 .call => Call,
457 .coerce_to_ptr_elem => CoerceToPtrElem,460 .decl_ref => DeclRef,
458 .declref => DeclRef,461 .decl_ref_str => DeclRefStr,
459 .declref_str => DeclRefStr,462 .decl_val => DeclVal,
460 .declval => DeclVal,
461 .coerce_result_block_ptr => CoerceResultBlockPtr,463 .coerce_result_block_ptr => CoerceResultBlockPtr,
462 .compilelog => CompileLog,464 .compile_log => CompileLog,
463 .loop => Loop,465 .loop => Loop,
464 .@"const" => Const,466 .@"const" => Const,
465 .str => Str,467 .str => Str,
466 .int => Int,468 .int => Int,
467 .inttype => IntType,469 .int_type => IntType,
468 .field_ptr, .field_val => Field,470 .field_ptr, .field_val => Field,
469 .field_ptr_named, .field_val_named => FieldNamed,471 .field_ptr_named, .field_val_named => FieldNamed,
470 .@"asm" => Asm,472 .@"asm" => Asm,
...@@ -508,18 +510,18 @@ pub const Inst = struct {...@@ -508,18 +510,18 @@ pub const Inst = struct {
508 .arg,510 .arg,
509 .as,511 .as,
510 .@"asm",512 .@"asm",
511 .bitand,513 .bit_and,
512 .bitcast,514 .bitcast,
513 .bitcast_ref,515 .bitcast_ref,
514 .bitcast_result_ptr,516 .bitcast_result_ptr,
515 .bitor,517 .bit_or,
516 .block,518 .block,
517 .block_flat,519 .block_flat,
518 .block_comptime,520 .block_comptime,
519 .block_comptime_flat,521 .block_comptime_flat,
520 .boolnot,522 .bool_not,
521 .booland,523 .bool_and,
522 .boolor,524 .bool_or,
523 .breakpoint,525 .breakpoint,
524 .call,526 .call,
525 .cmp_lt,527 .cmp_lt,
...@@ -530,12 +532,11 @@ pub const Inst = struct {...@@ -530,12 +532,11 @@ pub const Inst = struct {
530 .cmp_neq,532 .cmp_neq,
531 .coerce_result_ptr,533 .coerce_result_ptr,
532 .coerce_result_block_ptr,534 .coerce_result_block_ptr,
533 .coerce_to_ptr_elem,
534 .@"const",535 .@"const",
535 .dbg_stmt,536 .dbg_stmt,
536 .declref,537 .decl_ref,
537 .declref_str,538 .decl_ref_str,
538 .declval,539 .decl_val,
539 .deref,540 .deref,
540 .div,541 .div,
541 .elem_ptr,542 .elem_ptr,
...@@ -552,7 +553,7 @@ pub const Inst = struct {...@@ -552,7 +553,7 @@ pub const Inst = struct {
552 .fntype,553 .fntype,
553 .int,554 .int,
554 .intcast,555 .intcast,
555 .inttype,556 .int_type,
556 .is_non_null,557 .is_non_null,
557 .is_null,558 .is_null,
558 .is_non_null_ptr,559 .is_non_null_ptr,
...@@ -579,6 +580,7 @@ pub const Inst = struct {...@@ -579,6 +580,7 @@ pub const Inst = struct {
579 .mut_slice_type,580 .mut_slice_type,
580 .const_slice_type,581 .const_slice_type,
581 .store,582 .store,
583 .store_to_block_ptr,
582 .store_to_inferred_ptr,584 .store_to_inferred_ptr,
583 .str,585 .str,
584 .sub,586 .sub,
...@@ -602,7 +604,7 @@ pub const Inst = struct {...@@ -602,7 +604,7 @@ pub const Inst = struct {
602 .merge_error_sets,604 .merge_error_sets,
603 .anyframe_type,605 .anyframe_type,
604 .error_union_type,606 .error_union_type,
605 .bitnot,607 .bit_not,
606 .error_set,608 .error_set,
607 .slice,609 .slice,
608 .slice_start,610 .slice_start,
...@@ -611,20 +613,20 @@ pub const Inst = struct {...@@ -611,20 +613,20 @@ pub const Inst = struct {
611 .typeof_peer,613 .typeof_peer,
612 .resolve_inferred_alloc,614 .resolve_inferred_alloc,
613 .set_eval_branch_quota,615 .set_eval_branch_quota,
614 .compilelog,616 .compile_log,
615 .enum_type,617 .enum_type,
616 .union_type,618 .union_type,
617 .struct_type,619 .struct_type,
618 => false,620 => false,
619621
620 .@"break",622 .@"break",
621 .breakvoid,623 .break_void,
622 .condbr,624 .condbr,
623 .compileerror,625 .compile_error,
624 .@"return",626 .@"return",
625 .returnvoid,627 .return_void,
626 .unreach_nocheck,628 .unreachable_unsafe,
627 .@"unreachable",629 .unreachable_safe,
628 .loop,630 .loop,
629 .switchbr,631 .switchbr,
630 .container_field_named,632 .container_field_named,
...@@ -717,7 +719,7 @@ pub const Inst = struct {...@@ -717,7 +719,7 @@ pub const Inst = struct {
717 };719 };
718720
719 pub const BreakVoid = struct {721 pub const BreakVoid = struct {
720 pub const base_tag = Tag.breakvoid;722 pub const base_tag = Tag.break_void;
721 base: Inst,723 base: Inst,
722724
723 positionals: struct {725 positionals: struct {
...@@ -739,19 +741,8 @@ pub const Inst = struct {...@@ -739,19 +741,8 @@ pub const Inst = struct {
739 },741 },
740 };742 };
741743
742 pub const CoerceToPtrElem = struct {
743 pub const base_tag = Tag.coerce_to_ptr_elem;
744 base: Inst,
745
746 positionals: struct {
747 ptr: *Inst,
748 value: *Inst,
749 },
750 kw_args: struct {},
751 };
752
753 pub const DeclRef = struct {744 pub const DeclRef = struct {
754 pub const base_tag = Tag.declref;745 pub const base_tag = Tag.decl_ref;
755 base: Inst,746 base: Inst,
756747
757 positionals: struct {748 positionals: struct {
...@@ -761,7 +752,7 @@ pub const Inst = struct {...@@ -761,7 +752,7 @@ pub const Inst = struct {
761 };752 };
762753
763 pub const DeclRefStr = struct {754 pub const DeclRefStr = struct {
764 pub const base_tag = Tag.declref_str;755 pub const base_tag = Tag.decl_ref_str;
765 base: Inst,756 base: Inst,
766757
767 positionals: struct {758 positionals: struct {
...@@ -771,7 +762,7 @@ pub const Inst = struct {...@@ -771,7 +762,7 @@ pub const Inst = struct {
771 };762 };
772763
773 pub const DeclVal = struct {764 pub const DeclVal = struct {
774 pub const base_tag = Tag.declval;765 pub const base_tag = Tag.decl_val;
775 base: Inst,766 base: Inst,
776767
777 positionals: struct {768 positionals: struct {
...@@ -786,13 +777,13 @@ pub const Inst = struct {...@@ -786,13 +777,13 @@ pub const Inst = struct {
786777
787 positionals: struct {778 positionals: struct {
788 dest_type: *Inst,779 dest_type: *Inst,
789 block: *Block,780 block_ptr: *Inst,
790 },781 },
791 kw_args: struct {},782 kw_args: struct {},
792 };783 };
793784
794 pub const CompileLog = struct {785 pub const CompileLog = struct {
795 pub const base_tag = Tag.compilelog;786 pub const base_tag = Tag.compile_log;
796 base: Inst,787 base: Inst,
797788
798 positionals: struct {789 positionals: struct {
...@@ -905,7 +896,7 @@ pub const Inst = struct {...@@ -905,7 +896,7 @@ pub const Inst = struct {
905 };896 };
906897
907 pub const IntType = struct {898 pub const IntType = struct {
908 pub const base_tag = Tag.inttype;899 pub const base_tag = Tag.int_type;
909 base: Inst,900 base: Inst,
910901
911 positionals: struct {902 positionals: struct {
...@@ -1641,10 +1632,10 @@ const DumpTzir = struct {...@@ -1641,10 +1632,10 @@ const DumpTzir = struct {
1641 .cmp_gt,1632 .cmp_gt,
1642 .cmp_neq,1633 .cmp_neq,
1643 .store,1634 .store,
1644 .booland,1635 .bool_and,
1645 .boolor,1636 .bool_or,
1646 .bitand,1637 .bit_and,
1647 .bitor,1638 .bit_or,
1648 .xor,1639 .xor,
1649 => {1640 => {
1650 const bin_op = inst.cast(ir.Inst.BinOp).?;1641 const bin_op = inst.cast(ir.Inst.BinOp).?;
...@@ -1753,10 +1744,10 @@ const DumpTzir = struct {...@@ -1753,10 +1744,10 @@ const DumpTzir = struct {
1753 .cmp_gt,1744 .cmp_gt,
1754 .cmp_neq,1745 .cmp_neq,
1755 .store,1746 .store,
1756 .booland,1747 .bool_and,
1757 .boolor,1748 .bool_or,
1758 .bitand,1749 .bit_and,
1759 .bitor,1750 .bit_or,
1760 .xor,1751 .xor,
1761 => {1752 => {
1762 const bin_op = inst.cast(ir.Inst.BinOp).?;1753 const bin_op = inst.cast(ir.Inst.BinOp).?;
src/zir_sema.zig+289-283
...@@ -28,144 +28,134 @@ const Decl = Module.Decl;...@@ -28,144 +28,134 @@ const Decl = Module.Decl;
2828
29pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError!*Inst {29pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError!*Inst {
30 switch (old_inst.tag) {30 switch (old_inst.tag) {
31 .alloc => return analyzeInstAlloc(mod, scope, old_inst.castTag(.alloc).?),31 .alloc => return zirAlloc(mod, scope, old_inst.castTag(.alloc).?),
32 .alloc_mut => return analyzeInstAllocMut(mod, scope, old_inst.castTag(.alloc_mut).?),32 .alloc_mut => return zirAllocMut(mod, scope, old_inst.castTag(.alloc_mut).?),
33 .alloc_inferred => return analyzeInstAllocInferred(33 .alloc_inferred => return zirAllocInferred(mod, scope, old_inst.castTag(.alloc_inferred).?, .inferred_alloc_const),
34 mod,34 .alloc_inferred_mut => return zirAllocInferred(mod, scope, old_inst.castTag(.alloc_inferred_mut).?, .inferred_alloc_mut),
35 scope,35 .arg => return zirArg(mod, scope, old_inst.castTag(.arg).?),
36 old_inst.castTag(.alloc_inferred).?,36 .bitcast_ref => return zirBitcastRef(mod, scope, old_inst.castTag(.bitcast_ref).?),
37 .inferred_alloc_const,37 .bitcast_result_ptr => return zirBitcastResultPtr(mod, scope, old_inst.castTag(.bitcast_result_ptr).?),
38 ),38 .block => return zirBlock(mod, scope, old_inst.castTag(.block).?, false),
39 .alloc_inferred_mut => return analyzeInstAllocInferred(39 .block_comptime => return zirBlock(mod, scope, old_inst.castTag(.block_comptime).?, true),
40 mod,40 .block_flat => return zirBlockFlat(mod, scope, old_inst.castTag(.block_flat).?, false),
41 scope,41 .block_comptime_flat => return zirBlockFlat(mod, scope, old_inst.castTag(.block_comptime_flat).?, true),
42 old_inst.castTag(.alloc_inferred_mut).?,42 .@"break" => return zirBreak(mod, scope, old_inst.castTag(.@"break").?),
43 .inferred_alloc_mut,43 .breakpoint => return zirBreakpoint(mod, scope, old_inst.castTag(.breakpoint).?),
44 ),44 .break_void => return zirBreakVoid(mod, scope, old_inst.castTag(.break_void).?),
45 .arg => return analyzeInstArg(mod, scope, old_inst.castTag(.arg).?),45 .call => return zirCall(mod, scope, old_inst.castTag(.call).?),
46 .bitcast_ref => return bitCastRef(mod, scope, old_inst.castTag(.bitcast_ref).?),46 .coerce_result_block_ptr => return zirCoerceResultBlockPtr(mod, scope, old_inst.castTag(.coerce_result_block_ptr).?),
47 .bitcast_result_ptr => return bitCastResultPtr(mod, scope, old_inst.castTag(.bitcast_result_ptr).?),47 .coerce_result_ptr => return zirCoerceResultPtr(mod, scope, old_inst.castTag(.coerce_result_ptr).?),
48 .block => return analyzeInstBlock(mod, scope, old_inst.castTag(.block).?, false),48 .compile_error => return zirCompileError(mod, scope, old_inst.castTag(.compile_error).?),
49 .block_comptime => return analyzeInstBlock(mod, scope, old_inst.castTag(.block_comptime).?, true),49 .compile_log => return zirCompileLog(mod, scope, old_inst.castTag(.compile_log).?),
50 .block_flat => return analyzeInstBlockFlat(mod, scope, old_inst.castTag(.block_flat).?, false),50 .@"const" => return zirConst(mod, scope, old_inst.castTag(.@"const").?),
51 .block_comptime_flat => return analyzeInstBlockFlat(mod, scope, old_inst.castTag(.block_comptime_flat).?, true),51 .dbg_stmt => return zirDbgStmt(mod, scope, old_inst.castTag(.dbg_stmt).?),
52 .@"break" => return analyzeInstBreak(mod, scope, old_inst.castTag(.@"break").?),52 .decl_ref => return zirDeclRef(mod, scope, old_inst.castTag(.decl_ref).?),
53 .breakpoint => return analyzeInstBreakpoint(mod, scope, old_inst.castTag(.breakpoint).?),53 .decl_ref_str => return zirDeclRefStr(mod, scope, old_inst.castTag(.decl_ref_str).?),
54 .breakvoid => return analyzeInstBreakVoid(mod, scope, old_inst.castTag(.breakvoid).?),54 .decl_val => return zirDeclVal(mod, scope, old_inst.castTag(.decl_val).?),
55 .call => return call(mod, scope, old_inst.castTag(.call).?),55 .ensure_result_used => return zirEnsureResultUsed(mod, scope, old_inst.castTag(.ensure_result_used).?),
56 .coerce_result_block_ptr => return analyzeInstCoerceResultBlockPtr(mod, scope, old_inst.castTag(.coerce_result_block_ptr).?),56 .ensure_result_non_error => return zirEnsureResultNonError(mod, scope, old_inst.castTag(.ensure_result_non_error).?),
57 .coerce_result_ptr => return analyzeInstCoerceResultPtr(mod, scope, old_inst.castTag(.coerce_result_ptr).?),57 .indexable_ptr_len => return zirIndexablePtrLen(mod, scope, old_inst.castTag(.indexable_ptr_len).?),
58 .coerce_to_ptr_elem => return analyzeInstCoerceToPtrElem(mod, scope, old_inst.castTag(.coerce_to_ptr_elem).?),58 .ref => return zirRef(mod, scope, old_inst.castTag(.ref).?),
59 .compileerror => return analyzeInstCompileError(mod, scope, old_inst.castTag(.compileerror).?),59 .resolve_inferred_alloc => return zirResolveInferredAlloc(mod, scope, old_inst.castTag(.resolve_inferred_alloc).?),
60 .compilelog => return analyzeInstCompileLog(mod, scope, old_inst.castTag(.compilelog).?),60 .ret_ptr => return zirRetPtr(mod, scope, old_inst.castTag(.ret_ptr).?),
61 .@"const" => return analyzeInstConst(mod, scope, old_inst.castTag(.@"const").?),61 .ret_type => return zirRetType(mod, scope, old_inst.castTag(.ret_type).?),
62 .dbg_stmt => return analyzeInstDbgStmt(mod, scope, old_inst.castTag(.dbg_stmt).?),62 .store_to_block_ptr => return zirStoreToBlockPtr(mod, scope, old_inst.castTag(.store_to_block_ptr).?),
63 .declref => return declRef(mod, scope, old_inst.castTag(.declref).?),63 .store_to_inferred_ptr => return zirStoreToInferredPtr(mod, scope, old_inst.castTag(.store_to_inferred_ptr).?),
64 .declref_str => return analyzeInstDeclRefStr(mod, scope, old_inst.castTag(.declref_str).?),64 .single_const_ptr_type => return zirSimplePtrType(mod, scope, old_inst.castTag(.single_const_ptr_type).?, false, .One),
65 .declval => return declVal(mod, scope, old_inst.castTag(.declval).?),65 .single_mut_ptr_type => return zirSimplePtrType(mod, scope, old_inst.castTag(.single_mut_ptr_type).?, true, .One),
66 .ensure_result_used => return analyzeInstEnsureResultUsed(mod, scope, old_inst.castTag(.ensure_result_used).?),66 .many_const_ptr_type => return zirSimplePtrType(mod, scope, old_inst.castTag(.many_const_ptr_type).?, false, .Many),
67 .ensure_result_non_error => return analyzeInstEnsureResultNonError(mod, scope, old_inst.castTag(.ensure_result_non_error).?),67 .many_mut_ptr_type => return zirSimplePtrType(mod, scope, old_inst.castTag(.many_mut_ptr_type).?, true, .Many),
68 .indexable_ptr_len => return indexablePtrLen(mod, scope, old_inst.castTag(.indexable_ptr_len).?),68 .c_const_ptr_type => return zirSimplePtrType(mod, scope, old_inst.castTag(.c_const_ptr_type).?, false, .C),
69 .ref => return ref(mod, scope, old_inst.castTag(.ref).?),69 .c_mut_ptr_type => return zirSimplePtrType(mod, scope, old_inst.castTag(.c_mut_ptr_type).?, true, .C),
70 .resolve_inferred_alloc => return analyzeInstResolveInferredAlloc(mod, scope, old_inst.castTag(.resolve_inferred_alloc).?),70 .const_slice_type => return zirSimplePtrType(mod, scope, old_inst.castTag(.const_slice_type).?, false, .Slice),
71 .ret_ptr => return analyzeInstRetPtr(mod, scope, old_inst.castTag(.ret_ptr).?),71 .mut_slice_type => return zirSimplePtrType(mod, scope, old_inst.castTag(.mut_slice_type).?, true, .Slice),
72 .ret_type => return analyzeInstRetType(mod, scope, old_inst.castTag(.ret_type).?),72 .ptr_type => return zirPtrType(mod, scope, old_inst.castTag(.ptr_type).?),
73 .store_to_inferred_ptr => return analyzeInstStoreToInferredPtr(mod, scope, old_inst.castTag(.store_to_inferred_ptr).?),73 .store => return zirStore(mod, scope, old_inst.castTag(.store).?),
74 .single_const_ptr_type => return analyzeInstSimplePtrType(mod, scope, old_inst.castTag(.single_const_ptr_type).?, false, .One),74 .set_eval_branch_quota => return zirSetEvalBranchQuota(mod, scope, old_inst.castTag(.set_eval_branch_quota).?),
75 .single_mut_ptr_type => return analyzeInstSimplePtrType(mod, scope, old_inst.castTag(.single_mut_ptr_type).?, true, .One),75 .str => return zirStr(mod, scope, old_inst.castTag(.str).?),
76 .many_const_ptr_type => return analyzeInstSimplePtrType(mod, scope, old_inst.castTag(.many_const_ptr_type).?, false, .Many),76 .int => return zirInt(mod, scope, old_inst.castTag(.int).?),
77 .many_mut_ptr_type => return analyzeInstSimplePtrType(mod, scope, old_inst.castTag(.many_mut_ptr_type).?, true, .Many),77 .int_type => return zirIntType(mod, scope, old_inst.castTag(.int_type).?),
78 .c_const_ptr_type => return analyzeInstSimplePtrType(mod, scope, old_inst.castTag(.c_const_ptr_type).?, false, .C),78 .loop => return zirLoop(mod, scope, old_inst.castTag(.loop).?),
79 .c_mut_ptr_type => return analyzeInstSimplePtrType(mod, scope, old_inst.castTag(.c_mut_ptr_type).?, true, .C),79 .param_type => return zirParamType(mod, scope, old_inst.castTag(.param_type).?),
80 .const_slice_type => return analyzeInstSimplePtrType(mod, scope, old_inst.castTag(.const_slice_type).?, false, .Slice),80 .ptrtoint => return zirPtrtoint(mod, scope, old_inst.castTag(.ptrtoint).?),
81 .mut_slice_type => return analyzeInstSimplePtrType(mod, scope, old_inst.castTag(.mut_slice_type).?, true, .Slice),81 .field_ptr => return zirFieldPtr(mod, scope, old_inst.castTag(.field_ptr).?),
82 .ptr_type => return analyzeInstPtrType(mod, scope, old_inst.castTag(.ptr_type).?),82 .field_val => return zirFieldVal(mod, scope, old_inst.castTag(.field_val).?),
83 .store => return analyzeInstStore(mod, scope, old_inst.castTag(.store).?),83 .field_ptr_named => return zirFieldPtrNamed(mod, scope, old_inst.castTag(.field_ptr_named).?),
84 .set_eval_branch_quota => return analyzeInstSetEvalBranchQuota(mod, scope, old_inst.castTag(.set_eval_branch_quota).?),84 .field_val_named => return zirFieldValNamed(mod, scope, old_inst.castTag(.field_val_named).?),
85 .str => return analyzeInstStr(mod, scope, old_inst.castTag(.str).?),85 .deref => return zirDeref(mod, scope, old_inst.castTag(.deref).?),
86 .int => return analyzeInstInt(mod, scope, old_inst.castTag(.int).?),86 .as => return zirAs(mod, scope, old_inst.castTag(.as).?),
87 .inttype => return analyzeInstIntType(mod, scope, old_inst.castTag(.inttype).?),87 .@"asm" => return zirAsm(mod, scope, old_inst.castTag(.@"asm").?),
88 .loop => return analyzeInstLoop(mod, scope, old_inst.castTag(.loop).?),88 .unreachable_safe => return zirUnreachable(mod, scope, old_inst.castTag(.unreachable_safe).?, true),
89 .param_type => return analyzeInstParamType(mod, scope, old_inst.castTag(.param_type).?),89 .unreachable_unsafe => return zirUnreachable(mod, scope, old_inst.castTag(.unreachable_unsafe).?, false),
90 .ptrtoint => return analyzeInstPtrToInt(mod, scope, old_inst.castTag(.ptrtoint).?),90 .@"return" => return zirReturn(mod, scope, old_inst.castTag(.@"return").?),
91 .field_ptr => return fieldPtr(mod, scope, old_inst.castTag(.field_ptr).?),91 .return_void => return zirReturnVoid(mod, scope, old_inst.castTag(.return_void).?),
92 .field_val => return fieldVal(mod, scope, old_inst.castTag(.field_val).?),92 .@"fn" => return zirFn(mod, scope, old_inst.castTag(.@"fn").?),
93 .field_ptr_named => return fieldPtrNamed(mod, scope, old_inst.castTag(.field_ptr_named).?),93 .@"export" => return zirExport(mod, scope, old_inst.castTag(.@"export").?),
94 .field_val_named => return fieldValNamed(mod, scope, old_inst.castTag(.field_val_named).?),94 .primitive => return zirPrimitive(mod, scope, old_inst.castTag(.primitive).?),
95 .deref => return analyzeInstDeref(mod, scope, old_inst.castTag(.deref).?),95 .fntype => return zirFnType(mod, scope, old_inst.castTag(.fntype).?),
96 .as => return analyzeInstAs(mod, scope, old_inst.castTag(.as).?),96 .intcast => return zirIntcast(mod, scope, old_inst.castTag(.intcast).?),
97 .@"asm" => return analyzeInstAsm(mod, scope, old_inst.castTag(.@"asm").?),97 .bitcast => return zirBitcast(mod, scope, old_inst.castTag(.bitcast).?),
98 .@"unreachable" => return analyzeInstUnreachable(mod, scope, old_inst.castTag(.@"unreachable").?, true),98 .floatcast => return zirFloatcast(mod, scope, old_inst.castTag(.floatcast).?),
99 .unreach_nocheck => return analyzeInstUnreachable(mod, scope, old_inst.castTag(.unreach_nocheck).?, false),99 .elem_ptr => return zirElemPtr(mod, scope, old_inst.castTag(.elem_ptr).?),
100 .@"return" => return analyzeInstRet(mod, scope, old_inst.castTag(.@"return").?),100 .elem_val => return zirElemVal(mod, scope, old_inst.castTag(.elem_val).?),
101 .returnvoid => return analyzeInstRetVoid(mod, scope, old_inst.castTag(.returnvoid).?),101 .add => return zirArithmetic(mod, scope, old_inst.castTag(.add).?),
102 .@"fn" => return analyzeInstFn(mod, scope, old_inst.castTag(.@"fn").?),102 .addwrap => return zirArithmetic(mod, scope, old_inst.castTag(.addwrap).?),
103 .@"export" => return analyzeInstExport(mod, scope, old_inst.castTag(.@"export").?),103 .sub => return zirArithmetic(mod, scope, old_inst.castTag(.sub).?),
104 .primitive => return analyzeInstPrimitive(mod, scope, old_inst.castTag(.primitive).?),104 .subwrap => return zirArithmetic(mod, scope, old_inst.castTag(.subwrap).?),
105 .fntype => return analyzeInstFnType(mod, scope, old_inst.castTag(.fntype).?),105 .mul => return zirArithmetic(mod, scope, old_inst.castTag(.mul).?),
106 .intcast => return analyzeInstIntCast(mod, scope, old_inst.castTag(.intcast).?),106 .mulwrap => return zirArithmetic(mod, scope, old_inst.castTag(.mulwrap).?),
107 .bitcast => return analyzeInstBitCast(mod, scope, old_inst.castTag(.bitcast).?),107 .div => return zirArithmetic(mod, scope, old_inst.castTag(.div).?),
108 .floatcast => return analyzeInstFloatCast(mod, scope, old_inst.castTag(.floatcast).?),108 .mod_rem => return zirArithmetic(mod, scope, old_inst.castTag(.mod_rem).?),
109 .elem_ptr => return elemPtr(mod, scope, old_inst.castTag(.elem_ptr).?),109 .array_cat => return zirArrayCat(mod, scope, old_inst.castTag(.array_cat).?),
110 .elem_val => return elemVal(mod, scope, old_inst.castTag(.elem_val).?),110 .array_mul => return zirArrayMul(mod, scope, old_inst.castTag(.array_mul).?),
111 .add => return analyzeInstArithmetic(mod, scope, old_inst.castTag(.add).?),111 .bit_and => return zirBitwise(mod, scope, old_inst.castTag(.bit_and).?),
112 .addwrap => return analyzeInstArithmetic(mod, scope, old_inst.castTag(.addwrap).?),112 .bit_not => return zirBitNot(mod, scope, old_inst.castTag(.bit_not).?),
113 .sub => return analyzeInstArithmetic(mod, scope, old_inst.castTag(.sub).?),113 .bit_or => return zirBitwise(mod, scope, old_inst.castTag(.bit_or).?),
114 .subwrap => return analyzeInstArithmetic(mod, scope, old_inst.castTag(.subwrap).?),114 .xor => return zirBitwise(mod, scope, old_inst.castTag(.xor).?),
115 .mul => return analyzeInstArithmetic(mod, scope, old_inst.castTag(.mul).?),115 .shl => return zirShl(mod, scope, old_inst.castTag(.shl).?),
116 .mulwrap => return analyzeInstArithmetic(mod, scope, old_inst.castTag(.mulwrap).?),116 .shr => return zirShr(mod, scope, old_inst.castTag(.shr).?),
117 .div => return analyzeInstArithmetic(mod, scope, old_inst.castTag(.div).?),117 .cmp_lt => return zirCmp(mod, scope, old_inst.castTag(.cmp_lt).?, .lt),
118 .mod_rem => return analyzeInstArithmetic(mod, scope, old_inst.castTag(.mod_rem).?),118 .cmp_lte => return zirCmp(mod, scope, old_inst.castTag(.cmp_lte).?, .lte),
119 .array_cat => return analyzeInstArrayCat(mod, scope, old_inst.castTag(.array_cat).?),119 .cmp_eq => return zirCmp(mod, scope, old_inst.castTag(.cmp_eq).?, .eq),
120 .array_mul => return analyzeInstArrayMul(mod, scope, old_inst.castTag(.array_mul).?),120 .cmp_gte => return zirCmp(mod, scope, old_inst.castTag(.cmp_gte).?, .gte),
121 .bitand => return analyzeInstBitwise(mod, scope, old_inst.castTag(.bitand).?),121 .cmp_gt => return zirCmp(mod, scope, old_inst.castTag(.cmp_gt).?, .gt),
122 .bitnot => return analyzeInstBitNot(mod, scope, old_inst.castTag(.bitnot).?),122 .cmp_neq => return zirCmp(mod, scope, old_inst.castTag(.cmp_neq).?, .neq),
123 .bitor => return analyzeInstBitwise(mod, scope, old_inst.castTag(.bitor).?),123 .condbr => return zirCondbr(mod, scope, old_inst.castTag(.condbr).?),
124 .xor => return analyzeInstBitwise(mod, scope, old_inst.castTag(.xor).?),124 .is_null => return zirIsNull(mod, scope, old_inst.castTag(.is_null).?, false),
125 .shl => return analyzeInstShl(mod, scope, old_inst.castTag(.shl).?),125 .is_non_null => return zirIsNull(mod, scope, old_inst.castTag(.is_non_null).?, true),
126 .shr => return analyzeInstShr(mod, scope, old_inst.castTag(.shr).?),126 .is_null_ptr => return zirIsNullPtr(mod, scope, old_inst.castTag(.is_null_ptr).?, false),
127 .cmp_lt => return analyzeInstCmp(mod, scope, old_inst.castTag(.cmp_lt).?, .lt),127 .is_non_null_ptr => return zirIsNullPtr(mod, scope, old_inst.castTag(.is_non_null_ptr).?, true),
128 .cmp_lte => return analyzeInstCmp(mod, scope, old_inst.castTag(.cmp_lte).?, .lte),128 .is_err => return zirIsErr(mod, scope, old_inst.castTag(.is_err).?),
129 .cmp_eq => return analyzeInstCmp(mod, scope, old_inst.castTag(.cmp_eq).?, .eq),129 .is_err_ptr => return zirIsErrPtr(mod, scope, old_inst.castTag(.is_err_ptr).?),
130 .cmp_gte => return analyzeInstCmp(mod, scope, old_inst.castTag(.cmp_gte).?, .gte),130 .bool_not => return zirBoolNot(mod, scope, old_inst.castTag(.bool_not).?),
131 .cmp_gt => return analyzeInstCmp(mod, scope, old_inst.castTag(.cmp_gt).?, .gt),131 .typeof => return zirTypeof(mod, scope, old_inst.castTag(.typeof).?),
132 .cmp_neq => return analyzeInstCmp(mod, scope, old_inst.castTag(.cmp_neq).?, .neq),132 .typeof_peer => return zirTypeofPeer(mod, scope, old_inst.castTag(.typeof_peer).?),
133 .condbr => return analyzeInstCondBr(mod, scope, old_inst.castTag(.condbr).?),133 .optional_type => return zirOptionalType(mod, scope, old_inst.castTag(.optional_type).?),
134 .is_null => return isNull(mod, scope, old_inst.castTag(.is_null).?, false),134 .optional_payload_safe => return zirOptionalPayload(mod, scope, old_inst.castTag(.optional_payload_safe).?, true),
135 .is_non_null => return isNull(mod, scope, old_inst.castTag(.is_non_null).?, true),135 .optional_payload_unsafe => return zirOptionalPayload(mod, scope, old_inst.castTag(.optional_payload_unsafe).?, false),
136 .is_null_ptr => return isNullPtr(mod, scope, old_inst.castTag(.is_null_ptr).?, false),136 .optional_payload_safe_ptr => return zirOptionalPayloadPtr(mod, scope, old_inst.castTag(.optional_payload_safe_ptr).?, true),
137 .is_non_null_ptr => return isNullPtr(mod, scope, old_inst.castTag(.is_non_null_ptr).?, true),137 .optional_payload_unsafe_ptr => return zirOptionalPayloadPtr(mod, scope, old_inst.castTag(.optional_payload_unsafe_ptr).?, false),
138 .is_err => return isErr(mod, scope, old_inst.castTag(.is_err).?),138 .err_union_payload_safe => return zirErrUnionPayload(mod, scope, old_inst.castTag(.err_union_payload_safe).?, true),
139 .is_err_ptr => return isErrPtr(mod, scope, old_inst.castTag(.is_err_ptr).?),139 .err_union_payload_unsafe => return zirErrUnionPayload(mod, scope, old_inst.castTag(.err_union_payload_unsafe).?, false),
140 .boolnot => return analyzeInstBoolNot(mod, scope, old_inst.castTag(.boolnot).?),140 .err_union_payload_safe_ptr => return zirErrUnionPayloadPtr(mod, scope, old_inst.castTag(.err_union_payload_safe_ptr).?, true),
141 .typeof => return analyzeInstTypeOf(mod, scope, old_inst.castTag(.typeof).?),141 .err_union_payload_unsafe_ptr => return zirErrUnionPayloadPtr(mod, scope, old_inst.castTag(.err_union_payload_unsafe_ptr).?, false),
142 .typeof_peer => return analyzeInstTypeOfPeer(mod, scope, old_inst.castTag(.typeof_peer).?),142 .err_union_code => return zirErrUnionCode(mod, scope, old_inst.castTag(.err_union_code).?),
143 .optional_type => return analyzeInstOptionalType(mod, scope, old_inst.castTag(.optional_type).?),143 .err_union_code_ptr => return zirErrUnionCodePtr(mod, scope, old_inst.castTag(.err_union_code_ptr).?),
144 .optional_payload_safe => return optionalPayload(mod, scope, old_inst.castTag(.optional_payload_safe).?, true),144 .ensure_err_payload_void => return zirEnsureErrPayloadVoid(mod, scope, old_inst.castTag(.ensure_err_payload_void).?),
145 .optional_payload_unsafe => return optionalPayload(mod, scope, old_inst.castTag(.optional_payload_unsafe).?, false),145 .array_type => return zirArrayType(mod, scope, old_inst.castTag(.array_type).?),
146 .optional_payload_safe_ptr => return optionalPayloadPtr(mod, scope, old_inst.castTag(.optional_payload_safe_ptr).?, true),146 .array_type_sentinel => return zirArrayTypeSentinel(mod, scope, old_inst.castTag(.array_type_sentinel).?),
147 .optional_payload_unsafe_ptr => return optionalPayloadPtr(mod, scope, old_inst.castTag(.optional_payload_unsafe_ptr).?, false),147 .enum_literal => return zirEnumLiteral(mod, scope, old_inst.castTag(.enum_literal).?),
148 .err_union_payload_safe => return errorUnionPayload(mod, scope, old_inst.castTag(.err_union_payload_safe).?, true),148 .merge_error_sets => return zirMergeErrorSets(mod, scope, old_inst.castTag(.merge_error_sets).?),
149 .err_union_payload_unsafe => return errorUnionPayload(mod, scope, old_inst.castTag(.err_union_payload_unsafe).?, false),149 .error_union_type => return zirErrorUnionType(mod, scope, old_inst.castTag(.error_union_type).?),
150 .err_union_payload_safe_ptr => return errorUnionPayloadPtr(mod, scope, old_inst.castTag(.err_union_payload_safe_ptr).?, true),150 .anyframe_type => return zirAnyframeType(mod, scope, old_inst.castTag(.anyframe_type).?),
151 .err_union_payload_unsafe_ptr => return errorUnionPayloadPtr(mod, scope, old_inst.castTag(.err_union_payload_unsafe_ptr).?, false),151 .error_set => return zirErrorSet(mod, scope, old_inst.castTag(.error_set).?),
152 .err_union_code => return errorUnionCode(mod, scope, old_inst.castTag(.err_union_code).?),152 .slice => return zirSlice(mod, scope, old_inst.castTag(.slice).?),
153 .err_union_code_ptr => return errorUnionCodePtr(mod, scope, old_inst.castTag(.err_union_code_ptr).?),153 .slice_start => return zirSliceStart(mod, scope, old_inst.castTag(.slice_start).?),
154 .ensure_err_payload_void => return analyzeInstEnsureErrPayloadVoid(mod, scope, old_inst.castTag(.ensure_err_payload_void).?),154 .import => return zirImport(mod, scope, old_inst.castTag(.import).?),
155 .array_type => return analyzeInstArrayType(mod, scope, old_inst.castTag(.array_type).?),155 .switchbr => return zirSwitchbr(mod, scope, old_inst.castTag(.switchbr).?),
156 .array_type_sentinel => return analyzeInstArrayTypeSentinel(mod, scope, old_inst.castTag(.array_type_sentinel).?),156 .switch_range => return zirSwitchRange(mod, scope, old_inst.castTag(.switch_range).?),
157 .enum_literal => return analyzeInstEnumLiteral(mod, scope, old_inst.castTag(.enum_literal).?),157 .bool_and => return zirBoolOp(mod, scope, old_inst.castTag(.bool_and).?),
158 .merge_error_sets => return analyzeInstMergeErrorSets(mod, scope, old_inst.castTag(.merge_error_sets).?),158 .bool_or => return zirBoolOp(mod, scope, old_inst.castTag(.bool_or).?),
159 .error_union_type => return analyzeInstErrorUnionType(mod, scope, old_inst.castTag(.error_union_type).?),
160 .anyframe_type => return analyzeInstAnyframeType(mod, scope, old_inst.castTag(.anyframe_type).?),
161 .error_set => return analyzeInstErrorSet(mod, scope, old_inst.castTag(.error_set).?),
162 .slice => return analyzeInstSlice(mod, scope, old_inst.castTag(.slice).?),
163 .slice_start => return analyzeInstSliceStart(mod, scope, old_inst.castTag(.slice_start).?),
164 .import => return analyzeInstImport(mod, scope, old_inst.castTag(.import).?),
165 .switchbr => return analyzeInstSwitchBr(mod, scope, old_inst.castTag(.switchbr).?),
166 .switch_range => return analyzeInstSwitchRange(mod, scope, old_inst.castTag(.switch_range).?),
167 .booland => return analyzeInstBoolOp(mod, scope, old_inst.castTag(.booland).?),
168 .boolor => return analyzeInstBoolOp(mod, scope, old_inst.castTag(.boolor).?),
169159
170 .container_field_named,160 .container_field_named,
171 .container_field_typed,161 .container_field_typed,
...@@ -258,7 +248,7 @@ pub fn resolveInstConst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerE...@@ -258,7 +248,7 @@ pub fn resolveInstConst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerE
258 };248 };
259}249}
260250
261fn analyzeInstConst(mod: *Module, scope: *Scope, const_inst: *zir.Inst.Const) InnerError!*Inst {251fn zirConst(mod: *Module, scope: *Scope, const_inst: *zir.Inst.Const) InnerError!*Inst {
262 const tracy = trace(@src());252 const tracy = trace(@src());
263 defer tracy.end();253 defer tracy.end();
264 // Move the TypedValue from old memory to new memory. This allows freeing the ZIR instructions254 // Move the TypedValue from old memory to new memory. This allows freeing the ZIR instructions
...@@ -275,44 +265,35 @@ fn analyzeConstInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError...@@ -275,44 +265,35 @@ fn analyzeConstInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError
275 };265 };
276}266}
277267
278fn analyzeInstCoerceResultBlockPtr(268fn zirCoerceResultBlockPtr(
279 mod: *Module,269 mod: *Module,
280 scope: *Scope,270 scope: *Scope,
281 inst: *zir.Inst.CoerceResultBlockPtr,271 inst: *zir.Inst.CoerceResultBlockPtr,
282) InnerError!*Inst {272) InnerError!*Inst {
283 const tracy = trace(@src());273 const tracy = trace(@src());
284 defer tracy.end();274 defer tracy.end();
285 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstCoerceResultBlockPtr", .{});275 return mod.fail(scope, inst.base.src, "TODO implement zirCoerceResultBlockPtr", .{});
286}276}
287277
288fn bitCastRef(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {278fn zirBitcastRef(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
289 const tracy = trace(@src());279 const tracy = trace(@src());
290 defer tracy.end();280 defer tracy.end();
291 return mod.fail(scope, inst.base.src, "TODO implement zir_sema.bitCastRef", .{});281 return mod.fail(scope, inst.base.src, "TODO implement zir_sema.zirBitcastRef", .{});
292}282}
293283
294fn bitCastResultPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {284fn zirBitcastResultPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
295 const tracy = trace(@src());285 const tracy = trace(@src());
296 defer tracy.end();286 defer tracy.end();
297 return mod.fail(scope, inst.base.src, "TODO implement zir_sema.bitCastResultPtr", .{});287 return mod.fail(scope, inst.base.src, "TODO implement zir_sema.zirBitcastResultPtr", .{});
298}288}
299289
300fn analyzeInstCoerceResultPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {290fn zirCoerceResultPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
301 const tracy = trace(@src());291 const tracy = trace(@src());
302 defer tracy.end();292 defer tracy.end();
303 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstCoerceResultPtr", .{});293 return mod.fail(scope, inst.base.src, "TODO implement zirCoerceResultPtr", .{});
304}294}
305295
306/// Equivalent to `as(ptr_child_type(typeof(ptr)), value)`.296fn zirRetPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst {
307fn analyzeInstCoerceToPtrElem(mod: *Module, scope: *Scope, inst: *zir.Inst.CoerceToPtrElem) InnerError!*Inst {
308 const tracy = trace(@src());
309 defer tracy.end();
310 const ptr = try resolveInst(mod, scope, inst.positionals.ptr);
311 const operand = try resolveInst(mod, scope, inst.positionals.value);
312 return mod.coerce(scope, ptr.ty.elemType(), operand);
313}
314
315fn analyzeInstRetPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst {
316 const tracy = trace(@src());297 const tracy = trace(@src());
317 defer tracy.end();298 defer tracy.end();
318 const b = try mod.requireFunctionBlock(scope, inst.base.src);299 const b = try mod.requireFunctionBlock(scope, inst.base.src);
...@@ -322,7 +303,7 @@ fn analyzeInstRetPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerErr...@@ -322,7 +303,7 @@ fn analyzeInstRetPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerErr
322 return mod.addNoOp(b, inst.base.src, ptr_type, .alloc);303 return mod.addNoOp(b, inst.base.src, ptr_type, .alloc);
323}304}
324305
325fn ref(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {306fn zirRef(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
326 const tracy = trace(@src());307 const tracy = trace(@src());
327 defer tracy.end();308 defer tracy.end();
328309
...@@ -330,7 +311,7 @@ fn ref(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {...@@ -330,7 +311,7 @@ fn ref(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
330 return mod.analyzeRef(scope, inst.base.src, operand);311 return mod.analyzeRef(scope, inst.base.src, operand);
331}312}
332313
333fn analyzeInstRetType(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst {314fn zirRetType(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst {
334 const tracy = trace(@src());315 const tracy = trace(@src());
335 defer tracy.end();316 defer tracy.end();
336 const b = try mod.requireFunctionBlock(scope, inst.base.src);317 const b = try mod.requireFunctionBlock(scope, inst.base.src);
...@@ -339,7 +320,7 @@ fn analyzeInstRetType(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerEr...@@ -339,7 +320,7 @@ fn analyzeInstRetType(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerEr
339 return mod.constType(scope, inst.base.src, ret_type);320 return mod.constType(scope, inst.base.src, ret_type);
340}321}
341322
342fn analyzeInstEnsureResultUsed(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {323fn zirEnsureResultUsed(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
343 const tracy = trace(@src());324 const tracy = trace(@src());
344 defer tracy.end();325 defer tracy.end();
345 const operand = try resolveInst(mod, scope, inst.positionals.operand);326 const operand = try resolveInst(mod, scope, inst.positionals.operand);
...@@ -349,7 +330,7 @@ fn analyzeInstEnsureResultUsed(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp...@@ -349,7 +330,7 @@ fn analyzeInstEnsureResultUsed(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp
349 }330 }
350}331}
351332
352fn analyzeInstEnsureResultNonError(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {333fn zirEnsureResultNonError(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
353 const tracy = trace(@src());334 const tracy = trace(@src());
354 defer tracy.end();335 defer tracy.end();
355 const operand = try resolveInst(mod, scope, inst.positionals.operand);336 const operand = try resolveInst(mod, scope, inst.positionals.operand);
...@@ -359,7 +340,7 @@ fn analyzeInstEnsureResultNonError(mod: *Module, scope: *Scope, inst: *zir.Inst....@@ -359,7 +340,7 @@ fn analyzeInstEnsureResultNonError(mod: *Module, scope: *Scope, inst: *zir.Inst.
359 }340 }
360}341}
361342
362fn indexablePtrLen(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {343fn zirIndexablePtrLen(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
363 const tracy = trace(@src());344 const tracy = trace(@src());
364 defer tracy.end();345 defer tracy.end();
365346
...@@ -389,7 +370,7 @@ fn indexablePtrLen(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError...@@ -389,7 +370,7 @@ fn indexablePtrLen(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError
389 return mod.analyzeDeref(scope, inst.base.src, result_ptr, result_ptr.src);370 return mod.analyzeDeref(scope, inst.base.src, result_ptr, result_ptr.src);
390}371}
391372
392fn analyzeInstAlloc(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {373fn zirAlloc(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
393 const tracy = trace(@src());374 const tracy = trace(@src());
394 defer tracy.end();375 defer tracy.end();
395 const var_type = try resolveType(mod, scope, inst.positionals.operand);376 const var_type = try resolveType(mod, scope, inst.positionals.operand);
...@@ -398,7 +379,7 @@ fn analyzeInstAlloc(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerErro...@@ -398,7 +379,7 @@ fn analyzeInstAlloc(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerErro
398 return mod.addNoOp(b, inst.base.src, ptr_type, .alloc);379 return mod.addNoOp(b, inst.base.src, ptr_type, .alloc);
399}380}
400381
401fn analyzeInstAllocMut(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {382fn zirAllocMut(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
402 const tracy = trace(@src());383 const tracy = trace(@src());
403 defer tracy.end();384 defer tracy.end();
404 const var_type = try resolveType(mod, scope, inst.positionals.operand);385 const var_type = try resolveType(mod, scope, inst.positionals.operand);
...@@ -408,7 +389,7 @@ fn analyzeInstAllocMut(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerE...@@ -408,7 +389,7 @@ fn analyzeInstAllocMut(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerE
408 return mod.addNoOp(b, inst.base.src, ptr_type, .alloc);389 return mod.addNoOp(b, inst.base.src, ptr_type, .alloc);
409}390}
410391
411fn analyzeInstAllocInferred(392fn zirAllocInferred(
412 mod: *Module,393 mod: *Module,
413 scope: *Scope,394 scope: *Scope,
414 inst: *zir.Inst.NoOp,395 inst: *zir.Inst.NoOp,
...@@ -437,7 +418,7 @@ fn analyzeInstAllocInferred(...@@ -437,7 +418,7 @@ fn analyzeInstAllocInferred(
437 return result;418 return result;
438}419}
439420
440fn analyzeInstResolveInferredAlloc(421fn zirResolveInferredAlloc(
441 mod: *Module,422 mod: *Module,
442 scope: *Scope,423 scope: *Scope,
443 inst: *zir.Inst.UnOp,424 inst: *zir.Inst.UnOp,
...@@ -466,28 +447,44 @@ fn analyzeInstResolveInferredAlloc(...@@ -466,28 +447,44 @@ fn analyzeInstResolveInferredAlloc(
466 return mod.constVoid(scope, inst.base.src);447 return mod.constVoid(scope, inst.base.src);
467}448}
468449
469fn analyzeInstStoreToInferredPtr(450fn zirStoreToBlockPtr(
451 mod: *Module,
452 scope: *Scope,
453 inst: *zir.Inst.BinOp,
454) InnerError!*Inst {
455 const tracy = trace(@src());
456 defer tracy.end();
457
458 const ptr = try resolveInst(mod, scope, inst.positionals.lhs);
459 const value = try resolveInst(mod, scope, inst.positionals.rhs);
460 const ptr_ty = try mod.simplePtrType(scope, inst.base.src, value.ty, true, .One);
461 const b = try mod.requireRuntimeBlock(scope, inst.base.src);
462 const bitcasted_ptr = try mod.addUnOp(b, inst.base.src, ptr_ty, .bitcast, ptr);
463 return mod.storePtr(scope, inst.base.src, bitcasted_ptr, value);
464}
465
466fn zirStoreToInferredPtr(
470 mod: *Module,467 mod: *Module,
471 scope: *Scope,468 scope: *Scope,
472 inst: *zir.Inst.BinOp,469 inst: *zir.Inst.BinOp,
473) InnerError!*Inst {470) InnerError!*Inst {
474 const tracy = trace(@src());471 const tracy = trace(@src());
475 defer tracy.end();472 defer tracy.end();
473
476 const ptr = try resolveInst(mod, scope, inst.positionals.lhs);474 const ptr = try resolveInst(mod, scope, inst.positionals.lhs);
477 const value = try resolveInst(mod, scope, inst.positionals.rhs);475 const value = try resolveInst(mod, scope, inst.positionals.rhs);
478 const inferred_alloc = ptr.castTag(.constant).?.val.castTag(.inferred_alloc).?;476 const inferred_alloc = ptr.castTag(.constant).?.val.castTag(.inferred_alloc).?;
479 // Add the stored instruction to the set we will use to resolve peer types477 // Add the stored instruction to the set we will use to resolve peer types
480 // for the inferred allocation.478 // for the inferred allocation.
481 try inferred_alloc.data.stored_inst_list.append(scope.arena(), value);479 try inferred_alloc.data.stored_inst_list.append(scope.arena(), value);
482 // Create a new alloc with exactly the type the pointer wants.480 // Create a runtime bitcast instruction with exactly the type the pointer wants.
483 // Later it gets cleaned up by aliasing the alloc we are supposed to be storing to.
484 const ptr_ty = try mod.simplePtrType(scope, inst.base.src, value.ty, true, .One);481 const ptr_ty = try mod.simplePtrType(scope, inst.base.src, value.ty, true, .One);
485 const b = try mod.requireRuntimeBlock(scope, inst.base.src);482 const b = try mod.requireRuntimeBlock(scope, inst.base.src);
486 const bitcasted_ptr = try mod.addUnOp(b, inst.base.src, ptr_ty, .bitcast, ptr);483 const bitcasted_ptr = try mod.addUnOp(b, inst.base.src, ptr_ty, .bitcast, ptr);
487 return mod.storePtr(scope, inst.base.src, bitcasted_ptr, value);484 return mod.storePtr(scope, inst.base.src, bitcasted_ptr, value);
488}485}
489486
490fn analyzeInstSetEvalBranchQuota(487fn zirSetEvalBranchQuota(
491 mod: *Module,488 mod: *Module,
492 scope: *Scope,489 scope: *Scope,
493 inst: *zir.Inst.UnOp,490 inst: *zir.Inst.UnOp,
...@@ -499,15 +496,16 @@ fn analyzeInstSetEvalBranchQuota(...@@ -499,15 +496,16 @@ fn analyzeInstSetEvalBranchQuota(
499 return mod.constVoid(scope, inst.base.src);496 return mod.constVoid(scope, inst.base.src);
500}497}
501498
502fn analyzeInstStore(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {499fn zirStore(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
503 const tracy = trace(@src());500 const tracy = trace(@src());
504 defer tracy.end();501 defer tracy.end();
502
505 const ptr = try resolveInst(mod, scope, inst.positionals.lhs);503 const ptr = try resolveInst(mod, scope, inst.positionals.lhs);
506 const value = try resolveInst(mod, scope, inst.positionals.rhs);504 const value = try resolveInst(mod, scope, inst.positionals.rhs);
507 return mod.storePtr(scope, inst.base.src, ptr, value);505 return mod.storePtr(scope, inst.base.src, ptr, value);
508}506}
509507
510fn analyzeInstParamType(mod: *Module, scope: *Scope, inst: *zir.Inst.ParamType) InnerError!*Inst {508fn zirParamType(mod: *Module, scope: *Scope, inst: *zir.Inst.ParamType) InnerError!*Inst {
511 const tracy = trace(@src());509 const tracy = trace(@src());
512 defer tracy.end();510 defer tracy.end();
513 const fn_inst = try resolveInst(mod, scope, inst.positionals.func);511 const fn_inst = try resolveInst(mod, scope, inst.positionals.func);
...@@ -516,7 +514,7 @@ fn analyzeInstParamType(mod: *Module, scope: *Scope, inst: *zir.Inst.ParamType)...@@ -516,7 +514,7 @@ fn analyzeInstParamType(mod: *Module, scope: *Scope, inst: *zir.Inst.ParamType)
516 const fn_ty: Type = switch (fn_inst.ty.zigTypeTag()) {514 const fn_ty: Type = switch (fn_inst.ty.zigTypeTag()) {
517 .Fn => fn_inst.ty,515 .Fn => fn_inst.ty,
518 .BoundFn => {516 .BoundFn => {
519 return mod.fail(scope, fn_inst.src, "TODO implement analyzeInstParamType for method call syntax", .{});517 return mod.fail(scope, fn_inst.src, "TODO implement zirParamType for method call syntax", .{});
520 },518 },
521 else => {519 else => {
522 return mod.fail(scope, fn_inst.src, "expected function, found '{}'", .{fn_inst.ty});520 return mod.fail(scope, fn_inst.src, "expected function, found '{}'", .{fn_inst.ty});
...@@ -538,7 +536,7 @@ fn analyzeInstParamType(mod: *Module, scope: *Scope, inst: *zir.Inst.ParamType)...@@ -538,7 +536,7 @@ fn analyzeInstParamType(mod: *Module, scope: *Scope, inst: *zir.Inst.ParamType)
538 return mod.constType(scope, inst.base.src, param_type);536 return mod.constType(scope, inst.base.src, param_type);
539}537}
540538
541fn analyzeInstStr(mod: *Module, scope: *Scope, str_inst: *zir.Inst.Str) InnerError!*Inst {539fn zirStr(mod: *Module, scope: *Scope, str_inst: *zir.Inst.Str) InnerError!*Inst {
542 const tracy = trace(@src());540 const tracy = trace(@src());
543 defer tracy.end();541 defer tracy.end();
544 // The bytes references memory inside the ZIR module, which can get deallocated542 // The bytes references memory inside the ZIR module, which can get deallocated
...@@ -557,14 +555,14 @@ fn analyzeInstStr(mod: *Module, scope: *Scope, str_inst: *zir.Inst.Str) InnerErr...@@ -557,14 +555,14 @@ fn analyzeInstStr(mod: *Module, scope: *Scope, str_inst: *zir.Inst.Str) InnerErr
557 return mod.analyzeDeclRef(scope, str_inst.base.src, new_decl);555 return mod.analyzeDeclRef(scope, str_inst.base.src, new_decl);
558}556}
559557
560fn analyzeInstInt(mod: *Module, scope: *Scope, inst: *zir.Inst.Int) InnerError!*Inst {558fn zirInt(mod: *Module, scope: *Scope, inst: *zir.Inst.Int) InnerError!*Inst {
561 const tracy = trace(@src());559 const tracy = trace(@src());
562 defer tracy.end();560 defer tracy.end();
563561
564 return mod.constIntBig(scope, inst.base.src, Type.initTag(.comptime_int), inst.positionals.int);562 return mod.constIntBig(scope, inst.base.src, Type.initTag(.comptime_int), inst.positionals.int);
565}563}
566564
567fn analyzeInstExport(mod: *Module, scope: *Scope, export_inst: *zir.Inst.Export) InnerError!*Inst {565fn zirExport(mod: *Module, scope: *Scope, export_inst: *zir.Inst.Export) InnerError!*Inst {
568 const tracy = trace(@src());566 const tracy = trace(@src());
569 defer tracy.end();567 defer tracy.end();
570 const symbol_name = try resolveConstString(mod, scope, export_inst.positionals.symbol_name);568 const symbol_name = try resolveConstString(mod, scope, export_inst.positionals.symbol_name);
...@@ -574,14 +572,14 @@ fn analyzeInstExport(mod: *Module, scope: *Scope, export_inst: *zir.Inst.Export)...@@ -574,14 +572,14 @@ fn analyzeInstExport(mod: *Module, scope: *Scope, export_inst: *zir.Inst.Export)
574 return mod.constVoid(scope, export_inst.base.src);572 return mod.constVoid(scope, export_inst.base.src);
575}573}
576574
577fn analyzeInstCompileError(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {575fn zirCompileError(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
578 const tracy = trace(@src());576 const tracy = trace(@src());
579 defer tracy.end();577 defer tracy.end();
580 const msg = try resolveConstString(mod, scope, inst.positionals.operand);578 const msg = try resolveConstString(mod, scope, inst.positionals.operand);
581 return mod.fail(scope, inst.base.src, "{s}", .{msg});579 return mod.fail(scope, inst.base.src, "{s}", .{msg});
582}580}
583581
584fn analyzeInstCompileLog(mod: *Module, scope: *Scope, inst: *zir.Inst.CompileLog) InnerError!*Inst {582fn zirCompileLog(mod: *Module, scope: *Scope, inst: *zir.Inst.CompileLog) InnerError!*Inst {
585 var managed = mod.compile_log_text.toManaged(mod.gpa);583 var managed = mod.compile_log_text.toManaged(mod.gpa);
586 defer mod.compile_log_text = managed.moveToUnmanaged();584 defer mod.compile_log_text = managed.moveToUnmanaged();
587 const writer = managed.writer();585 const writer = managed.writer();
...@@ -608,7 +606,7 @@ fn analyzeInstCompileLog(mod: *Module, scope: *Scope, inst: *zir.Inst.CompileLog...@@ -608,7 +606,7 @@ fn analyzeInstCompileLog(mod: *Module, scope: *Scope, inst: *zir.Inst.CompileLog
608 return mod.constVoid(scope, inst.base.src);606 return mod.constVoid(scope, inst.base.src);
609}607}
610608
611fn analyzeInstArg(mod: *Module, scope: *Scope, inst: *zir.Inst.Arg) InnerError!*Inst {609fn zirArg(mod: *Module, scope: *Scope, inst: *zir.Inst.Arg) InnerError!*Inst {
612 const tracy = trace(@src());610 const tracy = trace(@src());
613 defer tracy.end();611 defer tracy.end();
614 const b = try mod.requireFunctionBlock(scope, inst.base.src);612 const b = try mod.requireFunctionBlock(scope, inst.base.src);
...@@ -631,7 +629,7 @@ fn analyzeInstArg(mod: *Module, scope: *Scope, inst: *zir.Inst.Arg) InnerError!*...@@ -631,7 +629,7 @@ fn analyzeInstArg(mod: *Module, scope: *Scope, inst: *zir.Inst.Arg) InnerError!*
631 return mod.addArg(b, inst.base.src, param_type, name);629 return mod.addArg(b, inst.base.src, param_type, name);
632}630}
633631
634fn analyzeInstLoop(mod: *Module, scope: *Scope, inst: *zir.Inst.Loop) InnerError!*Inst {632fn zirLoop(mod: *Module, scope: *Scope, inst: *zir.Inst.Loop) InnerError!*Inst {
635 const tracy = trace(@src());633 const tracy = trace(@src());
636 defer tracy.end();634 defer tracy.end();
637 const parent_block = scope.cast(Scope.Block).?;635 const parent_block = scope.cast(Scope.Block).?;
...@@ -672,7 +670,7 @@ fn analyzeInstLoop(mod: *Module, scope: *Scope, inst: *zir.Inst.Loop) InnerError...@@ -672,7 +670,7 @@ fn analyzeInstLoop(mod: *Module, scope: *Scope, inst: *zir.Inst.Loop) InnerError
672 return &loop_inst.base;670 return &loop_inst.base;
673}671}
674672
675fn analyzeInstBlockFlat(mod: *Module, scope: *Scope, inst: *zir.Inst.Block, is_comptime: bool) InnerError!*Inst {673fn zirBlockFlat(mod: *Module, scope: *Scope, inst: *zir.Inst.Block, is_comptime: bool) InnerError!*Inst {
676 const tracy = trace(@src());674 const tracy = trace(@src());
677 defer tracy.end();675 defer tracy.end();
678 const parent_block = scope.cast(Scope.Block).?;676 const parent_block = scope.cast(Scope.Block).?;
...@@ -704,9 +702,15 @@ fn analyzeInstBlockFlat(mod: *Module, scope: *Scope, inst: *zir.Inst.Block, is_c...@@ -704,9 +702,15 @@ fn analyzeInstBlockFlat(mod: *Module, scope: *Scope, inst: *zir.Inst.Block, is_c
704 return resolveInst(mod, scope, last_zir_inst);702 return resolveInst(mod, scope, last_zir_inst);
705}703}
706704
707fn analyzeInstBlock(mod: *Module, scope: *Scope, inst: *zir.Inst.Block, is_comptime: bool) InnerError!*Inst {705fn zirBlock(
706 mod: *Module,
707 scope: *Scope,
708 inst: *zir.Inst.Block,
709 is_comptime: bool,
710) InnerError!*Inst {
708 const tracy = trace(@src());711 const tracy = trace(@src());
709 defer tracy.end();712 defer tracy.end();
713
710 const parent_block = scope.cast(Scope.Block).?;714 const parent_block = scope.cast(Scope.Block).?;
711715
712 // Reserve space for a Block instruction so that generated Break instructions can716 // Reserve space for a Block instruction so that generated Break instructions can
...@@ -798,30 +802,52 @@ fn analyzeBlockBody(...@@ -798,30 +802,52 @@ fn analyzeBlockBody(
798 return &merges.block_inst.base;802 return &merges.block_inst.base;
799}803}
800804
801fn analyzeInstBreakpoint(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst {805fn zirBreakpoint(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst {
802 const tracy = trace(@src());806 const tracy = trace(@src());
803 defer tracy.end();807 defer tracy.end();
804 const b = try mod.requireRuntimeBlock(scope, inst.base.src);808 const b = try mod.requireRuntimeBlock(scope, inst.base.src);
805 return mod.addNoOp(b, inst.base.src, Type.initTag(.void), .breakpoint);809 return mod.addNoOp(b, inst.base.src, Type.initTag(.void), .breakpoint);
806}810}
807811
808fn analyzeInstBreak(mod: *Module, scope: *Scope, inst: *zir.Inst.Break) InnerError!*Inst {812fn zirBreak(mod: *Module, scope: *Scope, inst: *zir.Inst.Break) InnerError!*Inst {
809 const tracy = trace(@src());813 const tracy = trace(@src());
810 defer tracy.end();814 defer tracy.end();
815
811 const operand = try resolveInst(mod, scope, inst.positionals.operand);816 const operand = try resolveInst(mod, scope, inst.positionals.operand);
812 const block = inst.positionals.block;817 const block = inst.positionals.block;
813 return analyzeBreak(mod, scope, inst.base.src, block, operand);818 return analyzeBreak(mod, scope, inst.base.src, block, operand);
814}819}
815820
816fn analyzeInstBreakVoid(mod: *Module, scope: *Scope, inst: *zir.Inst.BreakVoid) InnerError!*Inst {821fn zirBreakVoid(mod: *Module, scope: *Scope, inst: *zir.Inst.BreakVoid) InnerError!*Inst {
817 const tracy = trace(@src());822 const tracy = trace(@src());
818 defer tracy.end();823 defer tracy.end();
824
819 const block = inst.positionals.block;825 const block = inst.positionals.block;
820 const void_inst = try mod.constVoid(scope, inst.base.src);826 const void_inst = try mod.constVoid(scope, inst.base.src);
821 return analyzeBreak(mod, scope, inst.base.src, block, void_inst);827 return analyzeBreak(mod, scope, inst.base.src, block, void_inst);
822}828}
823829
824fn analyzeInstDbgStmt(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst {830fn analyzeBreak(
831 mod: *Module,
832 scope: *Scope,
833 src: usize,
834 zir_block: *zir.Inst.Block,
835 operand: *Inst,
836) InnerError!*Inst {
837 var opt_block = scope.cast(Scope.Block);
838 while (opt_block) |block| {
839 if (block.label) |*label| {
840 if (label.zir_block == zir_block) {
841 try label.merges.results.append(mod.gpa, operand);
842 const b = try mod.requireFunctionBlock(scope, src);
843 return mod.addBr(b, src, label.merges.block_inst, operand);
844 }
845 }
846 opt_block = block.parent;
847 } else unreachable;
848}
849
850fn zirDbgStmt(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst {
825 const tracy = trace(@src());851 const tracy = trace(@src());
826 defer tracy.end();852 defer tracy.end();
827 if (scope.cast(Scope.Block)) |b| {853 if (scope.cast(Scope.Block)) |b| {
...@@ -832,26 +858,26 @@ fn analyzeInstDbgStmt(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerEr...@@ -832,26 +858,26 @@ fn analyzeInstDbgStmt(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerEr
832 return mod.constVoid(scope, inst.base.src);858 return mod.constVoid(scope, inst.base.src);
833}859}
834860
835fn analyzeInstDeclRefStr(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclRefStr) InnerError!*Inst {861fn zirDeclRefStr(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclRefStr) InnerError!*Inst {
836 const tracy = trace(@src());862 const tracy = trace(@src());
837 defer tracy.end();863 defer tracy.end();
838 const decl_name = try resolveConstString(mod, scope, inst.positionals.name);864 const decl_name = try resolveConstString(mod, scope, inst.positionals.name);
839 return mod.analyzeDeclRefByName(scope, inst.base.src, decl_name);865 return mod.analyzeDeclRefByName(scope, inst.base.src, decl_name);
840}866}
841867
842fn declRef(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclRef) InnerError!*Inst {868fn zirDeclRef(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclRef) InnerError!*Inst {
843 const tracy = trace(@src());869 const tracy = trace(@src());
844 defer tracy.end();870 defer tracy.end();
845 return mod.analyzeDeclRef(scope, inst.base.src, inst.positionals.decl);871 return mod.analyzeDeclRef(scope, inst.base.src, inst.positionals.decl);
846}872}
847873
848fn declVal(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclVal) InnerError!*Inst {874fn zirDeclVal(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclVal) InnerError!*Inst {
849 const tracy = trace(@src());875 const tracy = trace(@src());
850 defer tracy.end();876 defer tracy.end();
851 return mod.analyzeDeclVal(scope, inst.base.src, inst.positionals.decl);877 return mod.analyzeDeclVal(scope, inst.base.src, inst.positionals.decl);
852}878}
853879
854fn call(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError!*Inst {880fn zirCall(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError!*Inst {
855 const tracy = trace(@src());881 const tracy = trace(@src());
856 defer tracy.end();882 defer tracy.end();
857883
...@@ -1002,7 +1028,7 @@ fn call(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError!*Inst {...@@ -1002,7 +1028,7 @@ fn call(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError!*Inst {
1002 return mod.addCall(b, inst.base.src, ret_type, func, casted_args);1028 return mod.addCall(b, inst.base.src, ret_type, func, casted_args);
1003}1029}
10041030
1005fn analyzeInstFn(mod: *Module, scope: *Scope, fn_inst: *zir.Inst.Fn) InnerError!*Inst {1031fn zirFn(mod: *Module, scope: *Scope, fn_inst: *zir.Inst.Fn) InnerError!*Inst {
1006 const tracy = trace(@src());1032 const tracy = trace(@src());
1007 defer tracy.end();1033 defer tracy.end();
1008 const fn_type = try resolveType(mod, scope, fn_inst.positionals.fn_type);1034 const fn_type = try resolveType(mod, scope, fn_inst.positionals.fn_type);
...@@ -1019,13 +1045,13 @@ fn analyzeInstFn(mod: *Module, scope: *Scope, fn_inst: *zir.Inst.Fn) InnerError!...@@ -1019,13 +1045,13 @@ fn analyzeInstFn(mod: *Module, scope: *Scope, fn_inst: *zir.Inst.Fn) InnerError!
1019 });1045 });
1020}1046}
10211047
1022fn analyzeInstIntType(mod: *Module, scope: *Scope, inttype: *zir.Inst.IntType) InnerError!*Inst {1048fn zirIntType(mod: *Module, scope: *Scope, inttype: *zir.Inst.IntType) InnerError!*Inst {
1023 const tracy = trace(@src());1049 const tracy = trace(@src());
1024 defer tracy.end();1050 defer tracy.end();
1025 return mod.fail(scope, inttype.base.src, "TODO implement inttype", .{});1051 return mod.fail(scope, inttype.base.src, "TODO implement inttype", .{});
1026}1052}
10271053
1028fn analyzeInstOptionalType(mod: *Module, scope: *Scope, optional: *zir.Inst.UnOp) InnerError!*Inst {1054fn zirOptionalType(mod: *Module, scope: *Scope, optional: *zir.Inst.UnOp) InnerError!*Inst {
1029 const tracy = trace(@src());1055 const tracy = trace(@src());
1030 defer tracy.end();1056 defer tracy.end();
1031 const child_type = try resolveType(mod, scope, optional.positionals.operand);1057 const child_type = try resolveType(mod, scope, optional.positionals.operand);
...@@ -1033,7 +1059,7 @@ fn analyzeInstOptionalType(mod: *Module, scope: *Scope, optional: *zir.Inst.UnOp...@@ -1033,7 +1059,7 @@ fn analyzeInstOptionalType(mod: *Module, scope: *Scope, optional: *zir.Inst.UnOp
1033 return mod.constType(scope, optional.base.src, try mod.optionalType(scope, child_type));1059 return mod.constType(scope, optional.base.src, try mod.optionalType(scope, child_type));
1034}1060}
10351061
1036fn analyzeInstArrayType(mod: *Module, scope: *Scope, array: *zir.Inst.BinOp) InnerError!*Inst {1062fn zirArrayType(mod: *Module, scope: *Scope, array: *zir.Inst.BinOp) InnerError!*Inst {
1037 const tracy = trace(@src());1063 const tracy = trace(@src());
1038 defer tracy.end();1064 defer tracy.end();
1039 // TODO these should be lazily evaluated1065 // TODO these should be lazily evaluated
...@@ -1043,7 +1069,7 @@ fn analyzeInstArrayType(mod: *Module, scope: *Scope, array: *zir.Inst.BinOp) Inn...@@ -1043,7 +1069,7 @@ fn analyzeInstArrayType(mod: *Module, scope: *Scope, array: *zir.Inst.BinOp) Inn
1043 return mod.constType(scope, array.base.src, try mod.arrayType(scope, len.val.toUnsignedInt(), null, elem_type));1069 return mod.constType(scope, array.base.src, try mod.arrayType(scope, len.val.toUnsignedInt(), null, elem_type));
1044}1070}
10451071
1046fn analyzeInstArrayTypeSentinel(mod: *Module, scope: *Scope, array: *zir.Inst.ArrayTypeSentinel) InnerError!*Inst {1072fn zirArrayTypeSentinel(mod: *Module, scope: *Scope, array: *zir.Inst.ArrayTypeSentinel) InnerError!*Inst {
1047 const tracy = trace(@src());1073 const tracy = trace(@src());
1048 defer tracy.end();1074 defer tracy.end();
1049 // TODO these should be lazily evaluated1075 // TODO these should be lazily evaluated
...@@ -1054,7 +1080,7 @@ fn analyzeInstArrayTypeSentinel(mod: *Module, scope: *Scope, array: *zir.Inst.Ar...@@ -1054,7 +1080,7 @@ fn analyzeInstArrayTypeSentinel(mod: *Module, scope: *Scope, array: *zir.Inst.Ar
1054 return mod.constType(scope, array.base.src, try mod.arrayType(scope, len.val.toUnsignedInt(), sentinel.val, elem_type));1080 return mod.constType(scope, array.base.src, try mod.arrayType(scope, len.val.toUnsignedInt(), sentinel.val, elem_type));
1055}1081}
10561082
1057fn analyzeInstErrorUnionType(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {1083fn zirErrorUnionType(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1058 const tracy = trace(@src());1084 const tracy = trace(@src());
1059 defer tracy.end();1085 defer tracy.end();
1060 const error_union = try resolveType(mod, scope, inst.positionals.lhs);1086 const error_union = try resolveType(mod, scope, inst.positionals.lhs);
...@@ -1067,7 +1093,7 @@ fn analyzeInstErrorUnionType(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp)...@@ -1067,7 +1093,7 @@ fn analyzeInstErrorUnionType(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp)
1067 return mod.constType(scope, inst.base.src, try mod.errorUnionType(scope, error_union, payload));1093 return mod.constType(scope, inst.base.src, try mod.errorUnionType(scope, error_union, payload));
1068}1094}
10691095
1070fn analyzeInstAnyframeType(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {1096fn zirAnyframeType(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
1071 const tracy = trace(@src());1097 const tracy = trace(@src());
1072 defer tracy.end();1098 defer tracy.end();
1073 const return_type = try resolveType(mod, scope, inst.positionals.operand);1099 const return_type = try resolveType(mod, scope, inst.positionals.operand);
...@@ -1075,7 +1101,7 @@ fn analyzeInstAnyframeType(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) In...@@ -1075,7 +1101,7 @@ fn analyzeInstAnyframeType(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) In
1075 return mod.constType(scope, inst.base.src, try mod.anyframeType(scope, return_type));1101 return mod.constType(scope, inst.base.src, try mod.anyframeType(scope, return_type));
1076}1102}
10771103
1078fn analyzeInstErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) InnerError!*Inst {1104fn zirErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) InnerError!*Inst {
1079 const tracy = trace(@src());1105 const tracy = trace(@src());
1080 defer tracy.end();1106 defer tracy.end();
1081 // The declarations arena will store the hashmap.1107 // The declarations arena will store the hashmap.
...@@ -1107,13 +1133,13 @@ fn analyzeInstErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) In...@@ -1107,13 +1133,13 @@ fn analyzeInstErrorSet(mod: *Module, scope: *Scope, inst: *zir.Inst.ErrorSet) In
1107 return mod.analyzeDeclVal(scope, inst.base.src, new_decl);1133 return mod.analyzeDeclVal(scope, inst.base.src, new_decl);
1108}1134}
11091135
1110fn analyzeInstMergeErrorSets(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {1136fn zirMergeErrorSets(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1111 const tracy = trace(@src());1137 const tracy = trace(@src());
1112 defer tracy.end();1138 defer tracy.end();
1113 return mod.fail(scope, inst.base.src, "TODO implement merge_error_sets", .{});1139 return mod.fail(scope, inst.base.src, "TODO implement merge_error_sets", .{});
1114}1140}
11151141
1116fn analyzeInstEnumLiteral(mod: *Module, scope: *Scope, inst: *zir.Inst.EnumLiteral) InnerError!*Inst {1142fn zirEnumLiteral(mod: *Module, scope: *Scope, inst: *zir.Inst.EnumLiteral) InnerError!*Inst {
1117 const tracy = trace(@src());1143 const tracy = trace(@src());
1118 defer tracy.end();1144 defer tracy.end();
1119 const duped_name = try scope.arena().dupe(u8, inst.positionals.name);1145 const duped_name = try scope.arena().dupe(u8, inst.positionals.name);
...@@ -1124,7 +1150,7 @@ fn analyzeInstEnumLiteral(mod: *Module, scope: *Scope, inst: *zir.Inst.EnumLiter...@@ -1124,7 +1150,7 @@ fn analyzeInstEnumLiteral(mod: *Module, scope: *Scope, inst: *zir.Inst.EnumLiter
1124}1150}
11251151
1126/// Pointer in, pointer out.1152/// Pointer in, pointer out.
1127fn optionalPayloadPtr(1153fn zirOptionalPayloadPtr(
1128 mod: *Module,1154 mod: *Module,
1129 scope: *Scope,1155 scope: *Scope,
1130 unwrap: *zir.Inst.UnOp,1156 unwrap: *zir.Inst.UnOp,
...@@ -1165,7 +1191,7 @@ fn optionalPayloadPtr(...@@ -1165,7 +1191,7 @@ fn optionalPayloadPtr(
1165}1191}
11661192
1167/// Value in, value out.1193/// Value in, value out.
1168fn optionalPayload(1194fn zirOptionalPayload(
1169 mod: *Module,1195 mod: *Module,
1170 scope: *Scope,1196 scope: *Scope,
1171 unwrap: *zir.Inst.UnOp,1197 unwrap: *zir.Inst.UnOp,
...@@ -1201,40 +1227,40 @@ fn optionalPayload(...@@ -1201,40 +1227,40 @@ fn optionalPayload(
1201}1227}
12021228
1203/// Value in, value out1229/// Value in, value out
1204fn errorUnionPayload(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp, safety_check: bool) InnerError!*Inst {1230fn zirErrUnionPayload(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp, safety_check: bool) InnerError!*Inst {
1205 const tracy = trace(@src());1231 const tracy = trace(@src());
1206 defer tracy.end();1232 defer tracy.end();
1207 return mod.fail(scope, unwrap.base.src, "TODO implement zir_sema.errorUnionPayload", .{});1233 return mod.fail(scope, unwrap.base.src, "TODO implement zir_sema.zirErrUnionPayload", .{});
1208}1234}
12091235
1210/// Pointer in, pointer out1236/// Pointer in, pointer out
1211fn errorUnionPayloadPtr(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp, safety_check: bool) InnerError!*Inst {1237fn zirErrUnionPayloadPtr(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp, safety_check: bool) InnerError!*Inst {
1212 const tracy = trace(@src());1238 const tracy = trace(@src());
1213 defer tracy.end();1239 defer tracy.end();
1214 return mod.fail(scope, unwrap.base.src, "TODO implement zir_sema.errorUnionPayloadPtr", .{});1240 return mod.fail(scope, unwrap.base.src, "TODO implement zir_sema.zirErrUnionPayloadPtr", .{});
1215}1241}
12161242
1217/// Value in, value out1243/// Value in, value out
1218fn errorUnionCode(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp) InnerError!*Inst {1244fn zirErrUnionCode(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp) InnerError!*Inst {
1219 const tracy = trace(@src());1245 const tracy = trace(@src());
1220 defer tracy.end();1246 defer tracy.end();
1221 return mod.fail(scope, unwrap.base.src, "TODO implement zir_sema.errorUnionCode", .{});1247 return mod.fail(scope, unwrap.base.src, "TODO implement zir_sema.zirErrUnionCode", .{});
1222}1248}
12231249
1224/// Pointer in, value out1250/// Pointer in, value out
1225fn errorUnionCodePtr(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp) InnerError!*Inst {1251fn zirErrUnionCodePtr(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp) InnerError!*Inst {
1226 const tracy = trace(@src());1252 const tracy = trace(@src());
1227 defer tracy.end();1253 defer tracy.end();
1228 return mod.fail(scope, unwrap.base.src, "TODO implement zir_sema.errorUnionCodePtr", .{});1254 return mod.fail(scope, unwrap.base.src, "TODO implement zir_sema.zirErrUnionCodePtr", .{});
1229}1255}
12301256
1231fn analyzeInstEnsureErrPayloadVoid(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp) InnerError!*Inst {1257fn zirEnsureErrPayloadVoid(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp) InnerError!*Inst {
1232 const tracy = trace(@src());1258 const tracy = trace(@src());
1233 defer tracy.end();1259 defer tracy.end();
1234 return mod.fail(scope, unwrap.base.src, "TODO implement analyzeInstEnsureErrPayloadVoid", .{});1260 return mod.fail(scope, unwrap.base.src, "TODO implement zirEnsureErrPayloadVoid", .{});
1235}1261}
12361262
1237fn analyzeInstFnType(mod: *Module, scope: *Scope, fntype: *zir.Inst.FnType) InnerError!*Inst {1263fn zirFnType(mod: *Module, scope: *Scope, fntype: *zir.Inst.FnType) InnerError!*Inst {
1238 const tracy = trace(@src());1264 const tracy = trace(@src());
1239 defer tracy.end();1265 defer tracy.end();
1240 const return_type = try resolveType(mod, scope, fntype.positionals.return_type);1266 const return_type = try resolveType(mod, scope, fntype.positionals.return_type);
...@@ -1277,13 +1303,13 @@ fn analyzeInstFnType(mod: *Module, scope: *Scope, fntype: *zir.Inst.FnType) Inne...@@ -1277,13 +1303,13 @@ fn analyzeInstFnType(mod: *Module, scope: *Scope, fntype: *zir.Inst.FnType) Inne
1277 return mod.constType(scope, fntype.base.src, fn_ty);1303 return mod.constType(scope, fntype.base.src, fn_ty);
1278}1304}
12791305
1280fn analyzeInstPrimitive(mod: *Module, scope: *Scope, primitive: *zir.Inst.Primitive) InnerError!*Inst {1306fn zirPrimitive(mod: *Module, scope: *Scope, primitive: *zir.Inst.Primitive) InnerError!*Inst {
1281 const tracy = trace(@src());1307 const tracy = trace(@src());
1282 defer tracy.end();1308 defer tracy.end();
1283 return mod.constInst(scope, primitive.base.src, primitive.positionals.tag.toTypedValue());1309 return mod.constInst(scope, primitive.base.src, primitive.positionals.tag.toTypedValue());
1284}1310}
12851311
1286fn analyzeInstAs(mod: *Module, scope: *Scope, as: *zir.Inst.BinOp) InnerError!*Inst {1312fn zirAs(mod: *Module, scope: *Scope, as: *zir.Inst.BinOp) InnerError!*Inst {
1287 const tracy = trace(@src());1313 const tracy = trace(@src());
1288 defer tracy.end();1314 defer tracy.end();
1289 const dest_type = try resolveType(mod, scope, as.positionals.lhs);1315 const dest_type = try resolveType(mod, scope, as.positionals.lhs);
...@@ -1291,7 +1317,7 @@ fn analyzeInstAs(mod: *Module, scope: *Scope, as: *zir.Inst.BinOp) InnerError!*I...@@ -1291,7 +1317,7 @@ fn analyzeInstAs(mod: *Module, scope: *Scope, as: *zir.Inst.BinOp) InnerError!*I
1291 return mod.coerce(scope, dest_type, new_inst);1317 return mod.coerce(scope, dest_type, new_inst);
1292}1318}
12931319
1294fn analyzeInstPtrToInt(mod: *Module, scope: *Scope, ptrtoint: *zir.Inst.UnOp) InnerError!*Inst {1320fn zirPtrtoint(mod: *Module, scope: *Scope, ptrtoint: *zir.Inst.UnOp) InnerError!*Inst {
1295 const tracy = trace(@src());1321 const tracy = trace(@src());
1296 defer tracy.end();1322 defer tracy.end();
1297 const ptr = try resolveInst(mod, scope, ptrtoint.positionals.operand);1323 const ptr = try resolveInst(mod, scope, ptrtoint.positionals.operand);
...@@ -1304,7 +1330,7 @@ fn analyzeInstPtrToInt(mod: *Module, scope: *Scope, ptrtoint: *zir.Inst.UnOp) In...@@ -1304,7 +1330,7 @@ fn analyzeInstPtrToInt(mod: *Module, scope: *Scope, ptrtoint: *zir.Inst.UnOp) In
1304 return mod.addUnOp(b, ptrtoint.base.src, ty, .ptrtoint, ptr);1330 return mod.addUnOp(b, ptrtoint.base.src, ty, .ptrtoint, ptr);
1305}1331}
13061332
1307fn fieldVal(mod: *Module, scope: *Scope, inst: *zir.Inst.Field) InnerError!*Inst {1333fn zirFieldVal(mod: *Module, scope: *Scope, inst: *zir.Inst.Field) InnerError!*Inst {
1308 const tracy = trace(@src());1334 const tracy = trace(@src());
1309 defer tracy.end();1335 defer tracy.end();
13101336
...@@ -1315,7 +1341,7 @@ fn fieldVal(mod: *Module, scope: *Scope, inst: *zir.Inst.Field) InnerError!*Inst...@@ -1315,7 +1341,7 @@ fn fieldVal(mod: *Module, scope: *Scope, inst: *zir.Inst.Field) InnerError!*Inst
1315 return mod.analyzeDeref(scope, inst.base.src, result_ptr, result_ptr.src);1341 return mod.analyzeDeref(scope, inst.base.src, result_ptr, result_ptr.src);
1316}1342}
13171343
1318fn fieldPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.Field) InnerError!*Inst {1344fn zirFieldPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.Field) InnerError!*Inst {
1319 const tracy = trace(@src());1345 const tracy = trace(@src());
1320 defer tracy.end();1346 defer tracy.end();
13211347
...@@ -1324,7 +1350,7 @@ fn fieldPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.Field) InnerError!*Inst...@@ -1324,7 +1350,7 @@ fn fieldPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.Field) InnerError!*Inst
1324 return mod.namedFieldPtr(scope, inst.base.src, object_ptr, field_name, inst.base.src);1350 return mod.namedFieldPtr(scope, inst.base.src, object_ptr, field_name, inst.base.src);
1325}1351}
13261352
1327fn fieldValNamed(mod: *Module, scope: *Scope, inst: *zir.Inst.FieldNamed) InnerError!*Inst {1353fn zirFieldValNamed(mod: *Module, scope: *Scope, inst: *zir.Inst.FieldNamed) InnerError!*Inst {
1328 const tracy = trace(@src());1354 const tracy = trace(@src());
1329 defer tracy.end();1355 defer tracy.end();
13301356
...@@ -1336,7 +1362,7 @@ fn fieldValNamed(mod: *Module, scope: *Scope, inst: *zir.Inst.FieldNamed) InnerE...@@ -1336,7 +1362,7 @@ fn fieldValNamed(mod: *Module, scope: *Scope, inst: *zir.Inst.FieldNamed) InnerE
1336 return mod.analyzeDeref(scope, inst.base.src, result_ptr, result_ptr.src);1362 return mod.analyzeDeref(scope, inst.base.src, result_ptr, result_ptr.src);
1337}1363}
13381364
1339fn fieldPtrNamed(mod: *Module, scope: *Scope, inst: *zir.Inst.FieldNamed) InnerError!*Inst {1365fn zirFieldPtrNamed(mod: *Module, scope: *Scope, inst: *zir.Inst.FieldNamed) InnerError!*Inst {
1340 const tracy = trace(@src());1366 const tracy = trace(@src());
1341 defer tracy.end();1367 defer tracy.end();
13421368
...@@ -1346,7 +1372,7 @@ fn fieldPtrNamed(mod: *Module, scope: *Scope, inst: *zir.Inst.FieldNamed) InnerE...@@ -1346,7 +1372,7 @@ fn fieldPtrNamed(mod: *Module, scope: *Scope, inst: *zir.Inst.FieldNamed) InnerE
1346 return mod.namedFieldPtr(scope, inst.base.src, object_ptr, field_name, fsrc);1372 return mod.namedFieldPtr(scope, inst.base.src, object_ptr, field_name, fsrc);
1347}1373}
13481374
1349fn analyzeInstIntCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {1375fn zirIntcast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1350 const tracy = trace(@src());1376 const tracy = trace(@src());
1351 defer tracy.end();1377 defer tracy.end();
1352 const dest_type = try resolveType(mod, scope, inst.positionals.lhs);1378 const dest_type = try resolveType(mod, scope, inst.positionals.lhs);
...@@ -1384,7 +1410,7 @@ fn analyzeInstIntCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerE...@@ -1384,7 +1410,7 @@ fn analyzeInstIntCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerE
1384 return mod.fail(scope, inst.base.src, "TODO implement analyze widen or shorten int", .{});1410 return mod.fail(scope, inst.base.src, "TODO implement analyze widen or shorten int", .{});
1385}1411}
13861412
1387fn analyzeInstBitCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {1413fn zirBitcast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1388 const tracy = trace(@src());1414 const tracy = trace(@src());
1389 defer tracy.end();1415 defer tracy.end();
1390 const dest_type = try resolveType(mod, scope, inst.positionals.lhs);1416 const dest_type = try resolveType(mod, scope, inst.positionals.lhs);
...@@ -1392,7 +1418,7 @@ fn analyzeInstBitCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerE...@@ -1392,7 +1418,7 @@ fn analyzeInstBitCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerE
1392 return mod.bitcast(scope, dest_type, operand);1418 return mod.bitcast(scope, dest_type, operand);
1393}1419}
13941420
1395fn analyzeInstFloatCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {1421fn zirFloatcast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1396 const tracy = trace(@src());1422 const tracy = trace(@src());
1397 defer tracy.end();1423 defer tracy.end();
1398 const dest_type = try resolveType(mod, scope, inst.positionals.lhs);1424 const dest_type = try resolveType(mod, scope, inst.positionals.lhs);
...@@ -1430,7 +1456,7 @@ fn analyzeInstFloatCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) Inne...@@ -1430,7 +1456,7 @@ fn analyzeInstFloatCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) Inne
1430 return mod.fail(scope, inst.base.src, "TODO implement analyze widen or shorten float", .{});1456 return mod.fail(scope, inst.base.src, "TODO implement analyze widen or shorten float", .{});
1431}1457}
14321458
1433fn elemVal(mod: *Module, scope: *Scope, inst: *zir.Inst.Elem) InnerError!*Inst {1459fn zirElemVal(mod: *Module, scope: *Scope, inst: *zir.Inst.Elem) InnerError!*Inst {
1434 const tracy = trace(@src());1460 const tracy = trace(@src());
1435 defer tracy.end();1461 defer tracy.end();
14361462
...@@ -1441,7 +1467,7 @@ fn elemVal(mod: *Module, scope: *Scope, inst: *zir.Inst.Elem) InnerError!*Inst {...@@ -1441,7 +1467,7 @@ fn elemVal(mod: *Module, scope: *Scope, inst: *zir.Inst.Elem) InnerError!*Inst {
1441 return mod.analyzeDeref(scope, inst.base.src, result_ptr, result_ptr.src);1467 return mod.analyzeDeref(scope, inst.base.src, result_ptr, result_ptr.src);
1442}1468}
14431469
1444fn elemPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.Elem) InnerError!*Inst {1470fn zirElemPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.Elem) InnerError!*Inst {
1445 const tracy = trace(@src());1471 const tracy = trace(@src());
1446 defer tracy.end();1472 defer tracy.end();
14471473
...@@ -1450,7 +1476,7 @@ fn elemPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.Elem) InnerError!*Inst {...@@ -1450,7 +1476,7 @@ fn elemPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.Elem) InnerError!*Inst {
1450 return mod.elemPtr(scope, inst.base.src, array_ptr, elem_index);1476 return mod.elemPtr(scope, inst.base.src, array_ptr, elem_index);
1451}1477}
14521478
1453fn analyzeInstSlice(mod: *Module, scope: *Scope, inst: *zir.Inst.Slice) InnerError!*Inst {1479fn zirSlice(mod: *Module, scope: *Scope, inst: *zir.Inst.Slice) InnerError!*Inst {
1454 const tracy = trace(@src());1480 const tracy = trace(@src());
1455 defer tracy.end();1481 defer tracy.end();
1456 const array_ptr = try resolveInst(mod, scope, inst.positionals.array_ptr);1482 const array_ptr = try resolveInst(mod, scope, inst.positionals.array_ptr);
...@@ -1461,7 +1487,7 @@ fn analyzeInstSlice(mod: *Module, scope: *Scope, inst: *zir.Inst.Slice) InnerErr...@@ -1461,7 +1487,7 @@ fn analyzeInstSlice(mod: *Module, scope: *Scope, inst: *zir.Inst.Slice) InnerErr
1461 return mod.analyzeSlice(scope, inst.base.src, array_ptr, start, end, sentinel);1487 return mod.analyzeSlice(scope, inst.base.src, array_ptr, start, end, sentinel);
1462}1488}
14631489
1464fn analyzeInstSliceStart(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {1490fn zirSliceStart(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1465 const tracy = trace(@src());1491 const tracy = trace(@src());
1466 defer tracy.end();1492 defer tracy.end();
1467 const array_ptr = try resolveInst(mod, scope, inst.positionals.lhs);1493 const array_ptr = try resolveInst(mod, scope, inst.positionals.lhs);
...@@ -1470,7 +1496,7 @@ fn analyzeInstSliceStart(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) Inn...@@ -1470,7 +1496,7 @@ fn analyzeInstSliceStart(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) Inn
1470 return mod.analyzeSlice(scope, inst.base.src, array_ptr, start, null, null);1496 return mod.analyzeSlice(scope, inst.base.src, array_ptr, start, null, null);
1471}1497}
14721498
1473fn analyzeInstSwitchRange(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {1499fn zirSwitchRange(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1474 const tracy = trace(@src());1500 const tracy = trace(@src());
1475 defer tracy.end();1501 defer tracy.end();
1476 const start = try resolveInst(mod, scope, inst.positionals.lhs);1502 const start = try resolveInst(mod, scope, inst.positionals.lhs);
...@@ -1494,7 +1520,7 @@ fn analyzeInstSwitchRange(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) In...@@ -1494,7 +1520,7 @@ fn analyzeInstSwitchRange(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) In
1494 return mod.constVoid(scope, inst.base.src);1520 return mod.constVoid(scope, inst.base.src);
1495}1521}
14961522
1497fn analyzeInstSwitchBr(mod: *Module, scope: *Scope, inst: *zir.Inst.SwitchBr) InnerError!*Inst {1523fn zirSwitchbr(mod: *Module, scope: *Scope, inst: *zir.Inst.SwitchBr) InnerError!*Inst {
1498 const tracy = trace(@src());1524 const tracy = trace(@src());
1499 defer tracy.end();1525 defer tracy.end();
1500 const target_ptr = try resolveInst(mod, scope, inst.positionals.target_ptr);1526 const target_ptr = try resolveInst(mod, scope, inst.positionals.target_ptr);
...@@ -1698,7 +1724,7 @@ fn validateSwitch(mod: *Module, scope: *Scope, target: *Inst, inst: *zir.Inst.Sw...@@ -1698,7 +1724,7 @@ fn validateSwitch(mod: *Module, scope: *Scope, target: *Inst, inst: *zir.Inst.Sw
1698 }1724 }
1699}1725}
17001726
1701fn analyzeInstImport(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {1727fn zirImport(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
1702 const tracy = trace(@src());1728 const tracy = trace(@src());
1703 defer tracy.end();1729 defer tracy.end();
1704 const operand = try resolveConstString(mod, scope, inst.positionals.operand);1730 const operand = try resolveConstString(mod, scope, inst.positionals.operand);
...@@ -1718,19 +1744,19 @@ fn analyzeInstImport(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerErr...@@ -1718,19 +1744,19 @@ fn analyzeInstImport(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerErr
1718 return mod.constType(scope, inst.base.src, file_scope.root_container.ty);1744 return mod.constType(scope, inst.base.src, file_scope.root_container.ty);
1719}1745}
17201746
1721fn analyzeInstShl(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {1747fn zirShl(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1722 const tracy = trace(@src());1748 const tracy = trace(@src());
1723 defer tracy.end();1749 defer tracy.end();
1724 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstShl", .{});1750 return mod.fail(scope, inst.base.src, "TODO implement zirShl", .{});
1725}1751}
17261752
1727fn analyzeInstShr(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {1753fn zirShr(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1728 const tracy = trace(@src());1754 const tracy = trace(@src());
1729 defer tracy.end();1755 defer tracy.end();
1730 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstShr", .{});1756 return mod.fail(scope, inst.base.src, "TODO implement zirShr", .{});
1731}1757}
17321758
1733fn analyzeInstBitwise(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {1759fn zirBitwise(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1734 const tracy = trace(@src());1760 const tracy = trace(@src());
1735 defer tracy.end();1761 defer tracy.end();
17361762
...@@ -1784,8 +1810,8 @@ fn analyzeInstBitwise(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerE...@@ -1784,8 +1810,8 @@ fn analyzeInstBitwise(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerE
17841810
1785 const b = try mod.requireRuntimeBlock(scope, inst.base.src);1811 const b = try mod.requireRuntimeBlock(scope, inst.base.src);
1786 const ir_tag = switch (inst.base.tag) {1812 const ir_tag = switch (inst.base.tag) {
1787 .bitand => Inst.Tag.bitand,1813 .bit_and => Inst.Tag.bit_and,
1788 .bitor => Inst.Tag.bitor,1814 .bit_or => Inst.Tag.bit_or,
1789 .xor => Inst.Tag.xor,1815 .xor => Inst.Tag.xor,
1790 else => unreachable,1816 else => unreachable,
1791 };1817 };
...@@ -1793,25 +1819,25 @@ fn analyzeInstBitwise(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerE...@@ -1793,25 +1819,25 @@ fn analyzeInstBitwise(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerE
1793 return mod.addBinOp(b, inst.base.src, scalar_type, ir_tag, casted_lhs, casted_rhs);1819 return mod.addBinOp(b, inst.base.src, scalar_type, ir_tag, casted_lhs, casted_rhs);
1794}1820}
17951821
1796fn analyzeInstBitNot(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {1822fn zirBitNot(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
1797 const tracy = trace(@src());1823 const tracy = trace(@src());
1798 defer tracy.end();1824 defer tracy.end();
1799 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstBitNot", .{});1825 return mod.fail(scope, inst.base.src, "TODO implement zirBitNot", .{});
1800}1826}
18011827
1802fn analyzeInstArrayCat(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {1828fn zirArrayCat(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1803 const tracy = trace(@src());1829 const tracy = trace(@src());
1804 defer tracy.end();1830 defer tracy.end();
1805 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstArrayCat", .{});1831 return mod.fail(scope, inst.base.src, "TODO implement zirArrayCat", .{});
1806}1832}
18071833
1808fn analyzeInstArrayMul(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {1834fn zirArrayMul(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1809 const tracy = trace(@src());1835 const tracy = trace(@src());
1810 defer tracy.end();1836 defer tracy.end();
1811 return mod.fail(scope, inst.base.src, "TODO implement analyzeInstArrayMul", .{});1837 return mod.fail(scope, inst.base.src, "TODO implement zirArrayMul", .{});
1812}1838}
18131839
1814fn analyzeInstArithmetic(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {1840fn zirArithmetic(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
1815 const tracy = trace(@src());1841 const tracy = trace(@src());
1816 defer tracy.end();1842 defer tracy.end();
18171843
...@@ -1912,14 +1938,14 @@ fn analyzeInstComptimeOp(mod: *Module, scope: *Scope, res_type: Type, inst: *zir...@@ -1912,14 +1938,14 @@ fn analyzeInstComptimeOp(mod: *Module, scope: *Scope, res_type: Type, inst: *zir
1912 });1938 });
1913}1939}
19141940
1915fn analyzeInstDeref(mod: *Module, scope: *Scope, deref: *zir.Inst.UnOp) InnerError!*Inst {1941fn zirDeref(mod: *Module, scope: *Scope, deref: *zir.Inst.UnOp) InnerError!*Inst {
1916 const tracy = trace(@src());1942 const tracy = trace(@src());
1917 defer tracy.end();1943 defer tracy.end();
1918 const ptr = try resolveInst(mod, scope, deref.positionals.operand);1944 const ptr = try resolveInst(mod, scope, deref.positionals.operand);
1919 return mod.analyzeDeref(scope, deref.base.src, ptr, deref.positionals.operand.src);1945 return mod.analyzeDeref(scope, deref.base.src, ptr, deref.positionals.operand.src);
1920}1946}
19211947
1922fn analyzeInstAsm(mod: *Module, scope: *Scope, assembly: *zir.Inst.Asm) InnerError!*Inst {1948fn zirAsm(mod: *Module, scope: *Scope, assembly: *zir.Inst.Asm) InnerError!*Inst {
1923 const tracy = trace(@src());1949 const tracy = trace(@src());
1924 defer tracy.end();1950 defer tracy.end();
1925 const return_type = try resolveType(mod, scope, assembly.positionals.return_type);1951 const return_type = try resolveType(mod, scope, assembly.positionals.return_type);
...@@ -1960,7 +1986,7 @@ fn analyzeInstAsm(mod: *Module, scope: *Scope, assembly: *zir.Inst.Asm) InnerErr...@@ -1960,7 +1986,7 @@ fn analyzeInstAsm(mod: *Module, scope: *Scope, assembly: *zir.Inst.Asm) InnerErr
1960 return &inst.base;1986 return &inst.base;
1961}1987}
19621988
1963fn analyzeInstCmp(1989fn zirCmp(
1964 mod: *Module,1990 mod: *Module,
1965 scope: *Scope,1991 scope: *Scope,
1966 inst: *zir.Inst.BinOp,1992 inst: *zir.Inst.BinOp,
...@@ -2018,14 +2044,14 @@ fn analyzeInstCmp(...@@ -2018,14 +2044,14 @@ fn analyzeInstCmp(
2018 return mod.fail(scope, inst.base.src, "TODO implement more cmp analysis", .{});2044 return mod.fail(scope, inst.base.src, "TODO implement more cmp analysis", .{});
2019}2045}
20202046
2021fn analyzeInstTypeOf(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {2047fn zirTypeof(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
2022 const tracy = trace(@src());2048 const tracy = trace(@src());
2023 defer tracy.end();2049 defer tracy.end();
2024 const operand = try resolveInst(mod, scope, inst.positionals.operand);2050 const operand = try resolveInst(mod, scope, inst.positionals.operand);
2025 return mod.constType(scope, inst.base.src, operand.ty);2051 return mod.constType(scope, inst.base.src, operand.ty);
2026}2052}
20272053
2028fn analyzeInstTypeOfPeer(mod: *Module, scope: *Scope, inst: *zir.Inst.TypeOfPeer) InnerError!*Inst {2054fn zirTypeofPeer(mod: *Module, scope: *Scope, inst: *zir.Inst.TypeOfPeer) InnerError!*Inst {
2029 const tracy = trace(@src());2055 const tracy = trace(@src());
2030 defer tracy.end();2056 defer tracy.end();
2031 var insts_to_res = try mod.gpa.alloc(*ir.Inst, inst.positionals.items.len);2057 var insts_to_res = try mod.gpa.alloc(*ir.Inst, inst.positionals.items.len);
...@@ -2037,7 +2063,7 @@ fn analyzeInstTypeOfPeer(mod: *Module, scope: *Scope, inst: *zir.Inst.TypeOfPeer...@@ -2037,7 +2063,7 @@ fn analyzeInstTypeOfPeer(mod: *Module, scope: *Scope, inst: *zir.Inst.TypeOfPeer
2037 return mod.constType(scope, inst.base.src, pt_res);2063 return mod.constType(scope, inst.base.src, pt_res);
2038}2064}
20392065
2040fn analyzeInstBoolNot(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {2066fn zirBoolNot(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
2041 const tracy = trace(@src());2067 const tracy = trace(@src());
2042 defer tracy.end();2068 defer tracy.end();
2043 const uncasted_operand = try resolveInst(mod, scope, inst.positionals.operand);2069 const uncasted_operand = try resolveInst(mod, scope, inst.positionals.operand);
...@@ -2050,7 +2076,7 @@ fn analyzeInstBoolNot(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerEr...@@ -2050,7 +2076,7 @@ fn analyzeInstBoolNot(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerEr
2050 return mod.addUnOp(b, inst.base.src, bool_type, .not, operand);2076 return mod.addUnOp(b, inst.base.src, bool_type, .not, operand);
2051}2077}
20522078
2053fn analyzeInstBoolOp(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {2079fn zirBoolOp(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst {
2054 const tracy = trace(@src());2080 const tracy = trace(@src());
2055 defer tracy.end();2081 defer tracy.end();
2056 const bool_type = Type.initTag(.bool);2082 const bool_type = Type.initTag(.bool);
...@@ -2059,7 +2085,7 @@ fn analyzeInstBoolOp(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerEr...@@ -2059,7 +2085,7 @@ fn analyzeInstBoolOp(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerEr
2059 const uncasted_rhs = try resolveInst(mod, scope, inst.positionals.rhs);2085 const uncasted_rhs = try resolveInst(mod, scope, inst.positionals.rhs);
2060 const rhs = try mod.coerce(scope, bool_type, uncasted_rhs);2086 const rhs = try mod.coerce(scope, bool_type, uncasted_rhs);
20612087
2062 const is_bool_or = inst.base.tag == .boolor;2088 const is_bool_or = inst.base.tag == .bool_or;
20632089
2064 if (lhs.value()) |lhs_val| {2090 if (lhs.value()) |lhs_val| {
2065 if (rhs.value()) |rhs_val| {2091 if (rhs.value()) |rhs_val| {
...@@ -2071,17 +2097,17 @@ fn analyzeInstBoolOp(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerEr...@@ -2071,17 +2097,17 @@ fn analyzeInstBoolOp(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerEr
2071 }2097 }
2072 }2098 }
2073 const b = try mod.requireRuntimeBlock(scope, inst.base.src);2099 const b = try mod.requireRuntimeBlock(scope, inst.base.src);
2074 return mod.addBinOp(b, inst.base.src, bool_type, if (is_bool_or) .boolor else .booland, lhs, rhs);2100 return mod.addBinOp(b, inst.base.src, bool_type, if (is_bool_or) .bool_or else .bool_and, lhs, rhs);
2075}2101}
20762102
2077fn isNull(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp, invert_logic: bool) InnerError!*Inst {2103fn zirIsNull(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp, invert_logic: bool) InnerError!*Inst {
2078 const tracy = trace(@src());2104 const tracy = trace(@src());
2079 defer tracy.end();2105 defer tracy.end();
2080 const operand = try resolveInst(mod, scope, inst.positionals.operand);2106 const operand = try resolveInst(mod, scope, inst.positionals.operand);
2081 return mod.analyzeIsNull(scope, inst.base.src, operand, invert_logic);2107 return mod.analyzeIsNull(scope, inst.base.src, operand, invert_logic);
2082}2108}
20832109
2084fn isNullPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp, invert_logic: bool) InnerError!*Inst {2110fn zirIsNullPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp, invert_logic: bool) InnerError!*Inst {
2085 const tracy = trace(@src());2111 const tracy = trace(@src());
2086 defer tracy.end();2112 defer tracy.end();
2087 const ptr = try resolveInst(mod, scope, inst.positionals.operand);2113 const ptr = try resolveInst(mod, scope, inst.positionals.operand);
...@@ -2089,14 +2115,14 @@ fn isNullPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp, invert_logic: bo...@@ -2089,14 +2115,14 @@ fn isNullPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp, invert_logic: bo
2089 return mod.analyzeIsNull(scope, inst.base.src, loaded, invert_logic);2115 return mod.analyzeIsNull(scope, inst.base.src, loaded, invert_logic);
2090}2116}
20912117
2092fn isErr(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {2118fn zirIsErr(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
2093 const tracy = trace(@src());2119 const tracy = trace(@src());
2094 defer tracy.end();2120 defer tracy.end();
2095 const operand = try resolveInst(mod, scope, inst.positionals.operand);2121 const operand = try resolveInst(mod, scope, inst.positionals.operand);
2096 return mod.analyzeIsErr(scope, inst.base.src, operand);2122 return mod.analyzeIsErr(scope, inst.base.src, operand);
2097}2123}
20982124
2099fn isErrPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {2125fn zirIsErrPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
2100 const tracy = trace(@src());2126 const tracy = trace(@src());
2101 defer tracy.end();2127 defer tracy.end();
2102 const ptr = try resolveInst(mod, scope, inst.positionals.operand);2128 const ptr = try resolveInst(mod, scope, inst.positionals.operand);
...@@ -2104,7 +2130,7 @@ fn isErrPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst...@@ -2104,7 +2130,7 @@ fn isErrPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst
2104 return mod.analyzeIsErr(scope, inst.base.src, loaded);2130 return mod.analyzeIsErr(scope, inst.base.src, loaded);
2105}2131}
21062132
2107fn analyzeInstCondBr(mod: *Module, scope: *Scope, inst: *zir.Inst.CondBr) InnerError!*Inst {2133fn zirCondbr(mod: *Module, scope: *Scope, inst: *zir.Inst.CondBr) InnerError!*Inst {
2108 const tracy = trace(@src());2134 const tracy = trace(@src());
2109 defer tracy.end();2135 defer tracy.end();
2110 const uncasted_cond = try resolveInst(mod, scope, inst.positionals.condition);2136 const uncasted_cond = try resolveInst(mod, scope, inst.positionals.condition);
...@@ -2153,7 +2179,7 @@ fn analyzeInstCondBr(mod: *Module, scope: *Scope, inst: *zir.Inst.CondBr) InnerE...@@ -2153,7 +2179,7 @@ fn analyzeInstCondBr(mod: *Module, scope: *Scope, inst: *zir.Inst.CondBr) InnerE
2153 return mod.addCondBr(parent_block, inst.base.src, cond, then_body, else_body);2179 return mod.addCondBr(parent_block, inst.base.src, cond, then_body, else_body);
2154}2180}
21552181
2156fn analyzeInstUnreachable(2182fn zirUnreachable(
2157 mod: *Module,2183 mod: *Module,
2158 scope: *Scope,2184 scope: *Scope,
2159 unreach: *zir.Inst.NoOp,2185 unreach: *zir.Inst.NoOp,
...@@ -2170,7 +2196,7 @@ fn analyzeInstUnreachable(...@@ -2170,7 +2196,7 @@ fn analyzeInstUnreachable(
2170 }2196 }
2171}2197}
21722198
2173fn analyzeInstRet(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {2199fn zirReturn(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
2174 const tracy = trace(@src());2200 const tracy = trace(@src());
2175 defer tracy.end();2201 defer tracy.end();
2176 const operand = try resolveInst(mod, scope, inst.positionals.operand);2202 const operand = try resolveInst(mod, scope, inst.positionals.operand);
...@@ -2185,7 +2211,7 @@ fn analyzeInstRet(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!...@@ -2185,7 +2211,7 @@ fn analyzeInstRet(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!
2185 return mod.addUnOp(b, inst.base.src, Type.initTag(.noreturn), .ret, operand);2211 return mod.addUnOp(b, inst.base.src, Type.initTag(.noreturn), .ret, operand);
2186}2212}
21872213
2188fn analyzeInstRetVoid(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst {2214fn zirReturnVoid(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerError!*Inst {
2189 const tracy = trace(@src());2215 const tracy = trace(@src());
2190 defer tracy.end();2216 defer tracy.end();
2191 const b = try mod.requireFunctionBlock(scope, inst.base.src);2217 const b = try mod.requireFunctionBlock(scope, inst.base.src);
...@@ -2216,27 +2242,7 @@ fn floatOpAllowed(tag: zir.Inst.Tag) bool {...@@ -2216,27 +2242,7 @@ fn floatOpAllowed(tag: zir.Inst.Tag) bool {
2216 };2242 };
2217}2243}
22182244
2219fn analyzeBreak(2245fn zirSimplePtrType(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp, mutable: bool, size: std.builtin.TypeInfo.Pointer.Size) InnerError!*Inst {
2220 mod: *Module,
2221 scope: *Scope,
2222 src: usize,
2223 zir_block: *zir.Inst.Block,
2224 operand: *Inst,
2225) InnerError!*Inst {
2226 var opt_block = scope.cast(Scope.Block);
2227 while (opt_block) |block| {
2228 if (block.label) |*label| {
2229 if (label.zir_block == zir_block) {
2230 try label.merges.results.append(mod.gpa, operand);
2231 const b = try mod.requireFunctionBlock(scope, src);
2232 return mod.addBr(b, src, label.merges.block_inst, operand);
2233 }
2234 }
2235 opt_block = block.parent;
2236 } else unreachable;
2237}
2238
2239fn analyzeInstSimplePtrType(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp, mutable: bool, size: std.builtin.TypeInfo.Pointer.Size) InnerError!*Inst {
2240 const tracy = trace(@src());2246 const tracy = trace(@src());
2241 defer tracy.end();2247 defer tracy.end();
2242 const elem_type = try resolveType(mod, scope, inst.positionals.operand);2248 const elem_type = try resolveType(mod, scope, inst.positionals.operand);
...@@ -2244,7 +2250,7 @@ fn analyzeInstSimplePtrType(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp, m...@@ -2244,7 +2250,7 @@ fn analyzeInstSimplePtrType(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp, m
2244 return mod.constType(scope, inst.base.src, ty);2250 return mod.constType(scope, inst.base.src, ty);
2245}2251}
22462252
2247fn analyzeInstPtrType(mod: *Module, scope: *Scope, inst: *zir.Inst.PtrType) InnerError!*Inst {2253fn zirPtrType(mod: *Module, scope: *Scope, inst: *zir.Inst.PtrType) InnerError!*Inst {
2248 const tracy = trace(@src());2254 const tracy = trace(@src());
2249 defer tracy.end();2255 defer tracy.end();
2250 // TODO lazy values2256 // TODO lazy values