| ... | ... | @@ -252,7 +252,6 @@ pub const Block = struct { |
| 252 | 252 | // TODO is_comptime and comptime_reason should probably be merged together. |
| 253 | 253 | is_comptime: bool, |
| 254 | 254 | is_typeof: bool = false, |
| 255 | | is_coerce_result_ptr: bool = false, |
| 256 | 255 | |
| 257 | 256 | /// Keep track of the active error return trace index around blocks so that we can correctly |
| 258 | 257 | /// pop the error trace upon block exit. |
| ... | ... | @@ -2469,7 +2468,6 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 2469 | 2468 | // kind of transformations to make on the result pointer. |
| 2470 | 2469 | var trash_block = block.makeSubBlock(); |
| 2471 | 2470 | trash_block.is_comptime = false; |
| 2472 | | trash_block.is_coerce_result_ptr = true; |
| 2473 | 2471 | defer trash_block.instructions.deinit(sema.gpa); |
| 2474 | 2472 | |
| 2475 | 2473 | const dummy_ptr = try trash_block.addTy(.alloc, sema.typeOf(ptr)); |
| ... | ... | @@ -2579,6 +2577,9 @@ fn coerceResultPtr( |
| 2579 | 2577 | .array_to_slice => { |
| 2580 | 2578 | return sema.fail(block, src, "TODO coerce_result_ptr array_to_slice", .{}); |
| 2581 | 2579 | }, |
| 2580 | .get_union_tag => { |
| 2581 | return sema.fail(block, src, "TODO coerce_result_ptr get_union_tag", .{}); |
| 2582 | }, |
| 2582 | 2583 | else => { |
| 2583 | 2584 | if (std.debug.runtime_safety) { |
| 2584 | 2585 | std.debug.panic("unexpected AIR tag for coerce_result_ptr: {}", .{ |
| ... | ... | @@ -3563,6 +3564,13 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 3563 | 3564 | )); |
| 3564 | 3565 | } |
| 3565 | 3566 | |
| 3567 | return sema.makePtrConst(block, alloc); |
| 3568 | } |
| 3569 | |
| 3570 | fn makePtrConst(sema: *Sema, block: *Block, alloc: Air.Inst.Ref) CompileError!Air.Inst.Ref { |
| 3571 | const alloc_ty = sema.typeOf(alloc); |
| 3572 | |
| 3573 | var ptr_info = alloc_ty.ptrInfo().data; |
| 3566 | 3574 | ptr_info.mutable = false; |
| 3567 | 3575 | const const_ptr_ty = try Type.ptr(sema.arena, sema.mod, ptr_info); |
| 3568 | 3576 | |
| ... | ... | @@ -3831,7 +3839,6 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3831 | 3839 | |
| 3832 | 3840 | var trash_block = block.makeSubBlock(); |
| 3833 | 3841 | trash_block.is_comptime = false; |
| 3834 | | trash_block.is_coerce_result_ptr = true; |
| 3835 | 3842 | defer trash_block.instructions.deinit(gpa); |
| 3836 | 3843 | |
| 3837 | 3844 | const mut_final_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{ |
| ... | ... | @@ -17773,7 +17780,7 @@ fn zirStructInit( |
| 17773 | 17780 | try sema.storePtr(block, src, field_ptr, init_inst); |
| 17774 | 17781 | const new_tag = try sema.addConstant(resolved_ty.unionTagTypeHypothetical(), tag_val); |
| 17775 | 17782 | _ = try block.addBinOp(.set_union_tag, alloc, new_tag); |
| 17776 | | return alloc; |
| 17783 | return sema.makePtrConst(block, alloc); |
| 17777 | 17784 | } |
| 17778 | 17785 | |
| 17779 | 17786 | try sema.requireRuntimeBlock(block, src, null); |
| ... | ... | @@ -17900,7 +17907,7 @@ fn finishStructInit( |
| 17900 | 17907 | try sema.storePtr(block, dest_src, field_ptr, field_init); |
| 17901 | 17908 | } |
| 17902 | 17909 | |
| 17903 | | return alloc; |
| 17910 | return sema.makePtrConst(block, alloc); |
| 17904 | 17911 | } |
| 17905 | 17912 | |
| 17906 | 17913 | try sema.requireRuntimeBlock(block, dest_src, null); |
| ... | ... | @@ -18017,7 +18024,7 @@ fn zirStructInitAnon( |
| 18017 | 18024 | } |
| 18018 | 18025 | } |
| 18019 | 18026 | |
| 18020 | | return alloc; |
| 18027 | return sema.makePtrConst(block, alloc); |
| 18021 | 18028 | } |
| 18022 | 18029 | |
| 18023 | 18030 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, types.len); |
| ... | ... | @@ -18120,7 +18127,7 @@ fn zirArrayInit( |
| 18120 | 18127 | const elem_ptr = try block.addPtrElemPtrTypeRef(alloc, index, elem_ptr_ty_ref); |
| 18121 | 18128 | _ = try block.addBinOp(.store, elem_ptr, arg); |
| 18122 | 18129 | } |
| 18123 | | return alloc; |
| 18130 | return sema.makePtrConst(block, alloc); |
| 18124 | 18131 | } |
| 18125 | 18132 | |
| 18126 | 18133 | const elem_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{ |
| ... | ... | @@ -18135,7 +18142,7 @@ fn zirArrayInit( |
| 18135 | 18142 | const elem_ptr = try block.addPtrElemPtrTypeRef(alloc, index, elem_ptr_ty_ref); |
| 18136 | 18143 | _ = try block.addBinOp(.store, elem_ptr, arg); |
| 18137 | 18144 | } |
| 18138 | | return alloc; |
| 18145 | return sema.makePtrConst(block, alloc); |
| 18139 | 18146 | } |
| 18140 | 18147 | |
| 18141 | 18148 | return block.addAggregateInit(array_ty, resolved_args); |
| ... | ... | @@ -18213,7 +18220,7 @@ fn zirArrayInitAnon( |
| 18213 | 18220 | } |
| 18214 | 18221 | } |
| 18215 | 18222 | |
| 18216 | | return alloc; |
| 18223 | return sema.makePtrConst(block, alloc); |
| 18217 | 18224 | } |
| 18218 | 18225 | |
| 18219 | 18226 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len); |