| ... | @@ -224,6 +224,16 @@ pub const Block = struct { | ... | @@ -224,6 +224,16 @@ pub const Block = struct { |
| 224 | }); | 224 | }); |
| 225 | } | 225 | } |
| 226 | | 226 | |
| | 227 | pub fn addBitCast(block: *Block, ty: Type, operand: Air.Inst.Ref) Allocator.Error!Air.Inst.Ref { |
| | 228 | return block.addInst(.{ |
| | 229 | .tag = .bitcast, |
| | 230 | .data = .{ .ty_op = .{ |
| | 231 | .ty = try block.sema.addType(ty), |
| | 232 | .operand = operand, |
| | 233 | } }, |
| | 234 | }); |
| | 235 | } |
| | 236 | |
| 227 | pub fn addNoOp(block: *Block, tag: Air.Inst.Tag) error{OutOfMemory}!Air.Inst.Ref { | 237 | pub fn addNoOp(block: *Block, tag: Air.Inst.Tag) error{OutOfMemory}!Air.Inst.Ref { |
| 228 | return block.addInst(.{ | 238 | return block.addInst(.{ |
| 229 | .tag = tag, | 239 | .tag = tag, |
| ... | @@ -1409,7 +1419,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -1409,7 +1419,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 1409 | // for the inferred allocation. | 1419 | // for the inferred allocation. |
| 1410 | // This instruction will not make it to codegen; it is only to participate | 1420 | // This instruction will not make it to codegen; it is only to participate |
| 1411 | // in the `stored_inst_list` of the `inferred_alloc`. | 1421 | // in the `stored_inst_list` of the `inferred_alloc`. |
| 1412 | const operand = try block.addTyOp(.bitcast, pointee_ty, .void_value); | 1422 | const operand = try block.addBitCast(pointee_ty, .void_value); |
| 1413 | try inferred_alloc.stored_inst_list.append(sema.arena, operand); | 1423 | try inferred_alloc.stored_inst_list.append(sema.arena, operand); |
| 1414 | }, | 1424 | }, |
| 1415 | .inferred_alloc_comptime => { | 1425 | .inferred_alloc_comptime => { |
| ... | @@ -1436,7 +1446,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -1436,7 +1446,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 1436 | } | 1446 | } |
| 1437 | } | 1447 | } |
| 1438 | try sema.requireRuntimeBlock(block, src); | 1448 | try sema.requireRuntimeBlock(block, src); |
| 1439 | const bitcasted_ptr = try block.addTyOp(.bitcast, ptr_ty, ptr); | 1449 | const bitcasted_ptr = try block.addBitCast(ptr_ty, ptr); |
| 1440 | return bitcasted_ptr; | 1450 | return bitcasted_ptr; |
| 1441 | } | 1451 | } |
| 1442 | | 1452 | |
| ... | @@ -2509,7 +2519,7 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -2509,7 +2519,7 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 2509 | // if expressions should force it when the condition is compile-time known. | 2519 | // if expressions should force it when the condition is compile-time known. |
| 2510 | const src: LazySrcLoc = .unneeded; | 2520 | const src: LazySrcLoc = .unneeded; |
| 2511 | try sema.requireRuntimeBlock(block, src); | 2521 | try sema.requireRuntimeBlock(block, src); |
| 2512 | const bitcasted_ptr = try block.addTyOp(.bitcast, ptr_ty, ptr); | 2522 | const bitcasted_ptr = try block.addBitCast(ptr_ty, ptr); |
| 2513 | return sema.storePtr(block, src, bitcasted_ptr, value); | 2523 | return sema.storePtr(block, src, bitcasted_ptr, value); |
| 2514 | } | 2524 | } |
| 2515 | | 2525 | |
| ... | @@ -2555,7 +2565,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi | ... | @@ -2555,7 +2565,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi |
| 2555 | .pointee_type = operand_ty, | 2565 | .pointee_type = operand_ty, |
| 2556 | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .local), | 2566 | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .local), |
| 2557 | }); | 2567 | }); |
| 2558 | const bitcasted_ptr = try block.addTyOp(.bitcast, ptr_ty, ptr); | 2568 | const bitcasted_ptr = try block.addBitCast(ptr_ty, ptr); |
| 2559 | return sema.storePtr(block, src, bitcasted_ptr, operand); | 2569 | return sema.storePtr(block, src, bitcasted_ptr, operand); |
| 2560 | } | 2570 | } |
| 2561 | unreachable; | 2571 | unreachable; |
| ... | @@ -4310,7 +4320,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -4310,7 +4320,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 4310 | } | 4320 | } |
| 4311 | | 4321 | |
| 4312 | try sema.requireRuntimeBlock(block, src); | 4322 | try sema.requireRuntimeBlock(block, src); |
| 4313 | return block.addTyOp(.bitcast, result_ty, op_coerced); | 4323 | return block.addBitCast(result_ty, op_coerced); |
| 4314 | } | 4324 | } |
| 4315 | | 4325 | |
| 4316 | fn zirIntToError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 4326 | fn zirIntToError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -4340,7 +4350,13 @@ fn zirIntToError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -4340,7 +4350,13 @@ fn zirIntToError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 4340 | // const is_gt_max = @panic("TODO get max errors in compilation"); | 4350 | // const is_gt_max = @panic("TODO get max errors in compilation"); |
| 4341 | // try sema.addSafetyCheck(block, is_gt_max, .invalid_error_code); | 4351 | // try sema.addSafetyCheck(block, is_gt_max, .invalid_error_code); |
| 4342 | } | 4352 | } |
| 4343 | return block.addTyOp(.bitcast, Type.anyerror, op); | 4353 | return block.addInst(.{ |
| | 4354 | .tag = .bitcast, |
| | 4355 | .data = .{ .ty_op = .{ |
| | 4356 | .ty = Air.Inst.Ref.anyerror_type, |
| | 4357 | .operand = op, |
| | 4358 | } }, |
| | 4359 | }); |
| 4344 | } | 4360 | } |
| 4345 | | 4361 | |
| 4346 | fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 4362 | fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -4483,7 +4499,7 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -4483,7 +4499,7 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 4483 | } | 4499 | } |
| 4484 | | 4500 | |
| 4485 | try sema.requireRuntimeBlock(block, src); | 4501 | try sema.requireRuntimeBlock(block, src); |
| 4486 | return block.addTyOp(.bitcast, int_tag_ty, enum_tag); | 4502 | return block.addBitCast(int_tag_ty, enum_tag); |
| 4487 | } | 4503 | } |
| 4488 | | 4504 | |
| 4489 | fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 4505 | fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -9620,7 +9636,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -9620,7 +9636,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 9620 | try sema.addSafetyCheck(block, is_aligned, .incorrect_alignment); | 9636 | try sema.addSafetyCheck(block, is_aligned, .incorrect_alignment); |
| 9621 | } | 9637 | } |
| 9622 | } | 9638 | } |
| 9623 | return block.addTyOp(.bitcast, type_res, operand_coerced); | 9639 | return block.addBitCast(type_res, operand_coerced); |
| 9624 | } | 9640 | } |
| 9625 | | 9641 | |
| 9626 | fn zirErrSetCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9642 | fn zirErrSetCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -9650,7 +9666,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -9650,7 +9666,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9650 | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { | 9666 | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 9651 | return sema.addConstant(dest_ty, val); | 9667 | return sema.addConstant(dest_ty, val); |
| 9652 | } | 9668 | } |
| 9653 | return block.addTyOp(.bitcast, dest_ty, operand); | 9669 | return block.addBitCast(dest_ty, operand); |
| 9654 | } | 9670 | } |
| 9655 | | 9671 | |
| 9656 | fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9672 | fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -11871,7 +11887,7 @@ fn coerce( | ... | @@ -11871,7 +11887,7 @@ fn coerce( |
| 11871 | return sema.addConstant(dest_ty, val); | 11887 | return sema.addConstant(dest_ty, val); |
| 11872 | } | 11888 | } |
| 11873 | try sema.requireRuntimeBlock(block, inst_src); | 11889 | try sema.requireRuntimeBlock(block, inst_src); |
| 11874 | return block.addTyOp(.bitcast, dest_ty, inst); | 11890 | return block.addBitCast(dest_ty, inst); |
| 11875 | } | 11891 | } |
| 11876 | | 11892 | |
| 11877 | // undefined to anything | 11893 | // undefined to anything |
| ... | @@ -11896,8 +11912,7 @@ fn coerce( | ... | @@ -11896,8 +11912,7 @@ fn coerce( |
| 11896 | } | 11912 | } |
| 11897 | | 11913 | |
| 11898 | // T to ?T | 11914 | // T to ?T |
| 11899 | var buf: Type.Payload.ElemType = undefined; | 11915 | const child_type = try dest_ty.optionalChildAlloc(sema.arena); |
| 11900 | const child_type = dest_ty.optionalChild(&buf); | | |
| 11901 | const intermediate = try sema.coerce(block, child_type, inst, inst_src); | 11916 | const intermediate = try sema.coerce(block, child_type, inst, inst_src); |
| 11902 | return sema.wrapOptional(block, dest_ty, intermediate, inst_src); | 11917 | return sema.wrapOptional(block, dest_ty, intermediate, inst_src); |
| 11903 | }, | 11918 | }, |
| ... | @@ -12603,11 +12618,10 @@ fn beginComptimePtrLoad( | ... | @@ -12603,11 +12618,10 @@ fn beginComptimePtrLoad( |
| 12603 | .opt_payload_ptr => { | 12618 | .opt_payload_ptr => { |
| 12604 | const opt_ptr = ptr_val.castTag(.opt_payload_ptr).?.data; | 12619 | const opt_ptr = ptr_val.castTag(.opt_payload_ptr).?.data; |
| 12605 | const parent = try beginComptimePtrLoad(sema, block, src, opt_ptr); | 12620 | const parent = try beginComptimePtrLoad(sema, block, src, opt_ptr); |
| 12606 | var buf: Type.Payload.ElemType = undefined; | | |
| 12607 | return ComptimePtrLoadKit{ | 12621 | return ComptimePtrLoadKit{ |
| 12608 | .root_val = parent.root_val, | 12622 | .root_val = parent.root_val, |
| 12609 | .val = parent.val.castTag(.opt_payload).?.data, | 12623 | .val = parent.val.castTag(.opt_payload).?.data, |
| 12610 | .ty = parent.ty.optionalChild(&buf), | 12624 | .ty = try parent.ty.optionalChildAlloc(sema.arena), |
| 12611 | .byte_offset = undefined, | 12625 | .byte_offset = undefined, |
| 12612 | .is_mutable = parent.is_mutable, | 12626 | .is_mutable = parent.is_mutable, |
| 12613 | }; | 12627 | }; |
| ... | @@ -12643,7 +12657,7 @@ fn bitCast( | ... | @@ -12643,7 +12657,7 @@ fn bitCast( |
| 12643 | return sema.addConstant(dest_ty, result_val); | 12657 | return sema.addConstant(dest_ty, result_val); |
| 12644 | } | 12658 | } |
| 12645 | try sema.requireRuntimeBlock(block, inst_src); | 12659 | try sema.requireRuntimeBlock(block, inst_src); |
| 12646 | return block.addTyOp(.bitcast, dest_ty, inst); | 12660 | return block.addBitCast(dest_ty, inst); |
| 12647 | } | 12661 | } |
| 12648 | | 12662 | |
| 12649 | fn coerceArrayPtrToSlice( | 12663 | fn coerceArrayPtrToSlice( |
| ... | @@ -12756,7 +12770,7 @@ fn coerceEnumToUnion( | ... | @@ -12756,7 +12770,7 @@ fn coerceEnumToUnion( |
| 12756 | | 12770 | |
| 12757 | // If the union has all fields 0 bits, the union value is just the enum value. | 12771 | // If the union has all fields 0 bits, the union value is just the enum value. |
| 12758 | if (union_ty.unionHasAllZeroBitFieldTypes()) { | 12772 | if (union_ty.unionHasAllZeroBitFieldTypes()) { |
| 12759 | return block.addTyOp(.bitcast, union_ty, enum_tag); | 12773 | return block.addBitCast(union_ty, enum_tag); |
| 12760 | } | 12774 | } |
| 12761 | | 12775 | |
| 12762 | // TODO resolve the field names and add a hint that says "field 'foo' has type 'bar'" | 12776 | // TODO resolve the field names and add a hint that says "field 'foo' has type 'bar'" |
| ... | @@ -12814,7 +12828,7 @@ fn coerceVectorInMemory( | ... | @@ -12814,7 +12828,7 @@ fn coerceVectorInMemory( |
| 12814 | } | 12828 | } |
| 12815 | | 12829 | |
| 12816 | try sema.requireRuntimeBlock(block, inst_src); | 12830 | try sema.requireRuntimeBlock(block, inst_src); |
| 12817 | return block.addTyOp(.bitcast, dest_ty, inst); | 12831 | return block.addBitCast(dest_ty, inst); |
| 12818 | } | 12832 | } |
| 12819 | | 12833 | |
| 12820 | fn coerceCompatibleErrorSets( | 12834 | fn coerceCompatibleErrorSets( |
| ... | @@ -12828,7 +12842,13 @@ fn coerceCompatibleErrorSets( | ... | @@ -12828,7 +12842,13 @@ fn coerceCompatibleErrorSets( |
| 12828 | return sema.addConstant(Type.anyerror, err_set_val); | 12842 | return sema.addConstant(Type.anyerror, err_set_val); |
| 12829 | } | 12843 | } |
| 12830 | try sema.requireRuntimeBlock(block, err_set_src); | 12844 | try sema.requireRuntimeBlock(block, err_set_src); |
| 12831 | return block.addTyOp(.bitcast, Type.anyerror, err_set); | 12845 | return block.addInst(.{ |
| | 12846 | .tag = .bitcast, |
| | 12847 | .data = .{ .ty_op = .{ |
| | 12848 | .ty = Air.Inst.Ref.anyerror_type, |
| | 12849 | .operand = err_set, |
| | 12850 | } }, |
| | 12851 | }); |
| 12832 | } | 12852 | } |
| 12833 | | 12853 | |
| 12834 | fn analyzeDeclVal( | 12854 | fn analyzeDeclVal( |
| ... | @@ -13128,7 +13148,7 @@ fn analyzeSlice( | ... | @@ -13128,7 +13148,7 @@ fn analyzeSlice( |
| 13128 | if (opt_new_ptr_val) |new_ptr_val| { | 13148 | if (opt_new_ptr_val) |new_ptr_val| { |
| 13129 | return sema.addConstant(return_ty, new_ptr_val); | 13149 | return sema.addConstant(return_ty, new_ptr_val); |
| 13130 | } else { | 13150 | } else { |
| 13131 | return block.addTyOp(.bitcast, return_ty, new_ptr); | 13151 | return block.addBitCast(return_ty, new_ptr); |
| 13132 | } | 13152 | } |
| 13133 | } | 13153 | } |
| 13134 | | 13154 | |