| ... | ... | @@ -3026,9 +3026,9 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3026 | 3026 | defer tracy.end(); |
| 3027 | 3027 | |
| 3028 | 3028 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; |
| 3029 | | const len = try sema.resolveInstConst(block, .unneeded, bin_inst.lhs); |
| 3029 | const len = try sema.resolveInt(block, .unneeded, bin_inst.lhs, Type.initTag(.usize)); |
| 3030 | 3030 | const elem_type = try sema.resolveType(block, .unneeded, bin_inst.rhs); |
| 3031 | | const array_ty = try Module.arrayType(sema.arena, len.val.toUnsignedInt(), null, elem_type); |
| 3031 | const array_ty = try Module.arrayType(sema.arena, len, null, elem_type); |
| 3032 | 3032 | |
| 3033 | 3033 | return sema.addType(array_ty); |
| 3034 | 3034 | } |
| ... | ... | @@ -3038,11 +3038,13 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) |
| 3038 | 3038 | defer tracy.end(); |
| 3039 | 3039 | |
| 3040 | 3040 | const inst_data = sema.code.instructions.items(.data)[inst].array_type_sentinel; |
| 3041 | | const len = try sema.resolveInstConst(block, .unneeded, inst_data.len); |
| 3041 | const len = try sema.resolveInt(block, .unneeded, inst_data.len, Type.initTag(.usize)); |
| 3042 | 3042 | const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data; |
| 3043 | | const sentinel = try sema.resolveInstConst(block, .unneeded, extra.sentinel); |
| 3044 | 3043 | const elem_type = try sema.resolveType(block, .unneeded, extra.elem_type); |
| 3045 | | const array_ty = try Module.arrayType(sema.arena, len.val.toUnsignedInt(), sentinel.val, elem_type); |
| 3044 | const uncasted_sentinel = sema.resolveInst(extra.sentinel); |
| 3045 | const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, .unneeded); |
| 3046 | const sentinel_val = try sema.resolveConstValue(block, .unneeded, sentinel); |
| 3047 | const array_ty = try Module.arrayType(sema.arena, len, sentinel_val, elem_type); |
| 3046 | 3048 | |
| 3047 | 3049 | return sema.addType(array_ty); |
| 3048 | 3050 | } |
| ... | ... | @@ -6774,8 +6776,26 @@ fn zirErrSetCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 6774 | 6776 | |
| 6775 | 6777 | fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6776 | 6778 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6777 | | const src = inst_data.src(); |
| 6778 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirPtrCast", .{}); |
| 6779 | const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 6780 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 6781 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 6782 | const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs); |
| 6783 | const operand = sema.resolveInst(extra.rhs); |
| 6784 | const operand_ty = sema.typeOf(operand); |
| 6785 | if (operand_ty.zigTypeTag() != .Pointer) { |
| 6786 | return sema.mod.fail(&block.base, operand_src, "expected pointer, found {s} type '{}'", .{ |
| 6787 | @tagName(operand_ty.zigTypeTag()), operand_ty, |
| 6788 | }); |
| 6789 | } |
| 6790 | if (dest_ty.zigTypeTag() != .Pointer) { |
| 6791 | return sema.mod.fail(&block.base, dest_ty_src, "expected pointer, found {s} type '{}'", .{ |
| 6792 | @tagName(dest_ty.zigTypeTag()), dest_ty, |
| 6793 | }); |
| 6794 | } |
| 6795 | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 6796 | return sema.addConstant(dest_ty, val); |
| 6797 | } |
| 6798 | return block.addTyOp(.bitcast, dest_ty, operand); |
| 6779 | 6799 | } |
| 6780 | 6800 | |
| 6781 | 6801 | fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -8151,11 +8171,8 @@ fn coerce( |
| 8151 | 8171 | // T to ?T |
| 8152 | 8172 | var buf: Type.Payload.ElemType = undefined; |
| 8153 | 8173 | const child_type = dest_type.optionalChild(&buf); |
| 8154 | | if (child_type.eql(inst_ty)) { |
| 8155 | | return sema.wrapOptional(block, dest_type, inst, inst_src); |
| 8156 | | } else if (try sema.coerceNum(block, child_type, inst, inst_src)) |some| { |
| 8157 | | return sema.wrapOptional(block, dest_type, some, inst_src); |
| 8158 | | } |
| 8174 | const intermediate = try sema.coerce(block, child_type, inst, inst_src); |
| 8175 | return sema.wrapOptional(block, dest_type, intermediate, inst_src); |
| 8159 | 8176 | }, |
| 8160 | 8177 | .Pointer => { |
| 8161 | 8178 | // Coercions where the source is a single pointer to an array. |