authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-02-23 19:03:55+01:00
committergravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-02-23 19:03:55+01:00
log9c35f680f73538b8c36121ff938cc0b19eadbb42
tree077169ab7941c9feaaa793a3ea1f3f14f4fcf584
parent7664c3bc11988fd1ee2b3f26d1f08ac80d873c64

nuke @bytesToSlice, @sliceToBytes in stage1


4 files changed, 0 insertions(+), 394 deletions(-)

src/all_types.hpp-28
...@@ -1750,8 +1750,6 @@ enum BuiltinFnId {...@@ -1750,8 +1750,6 @@ enum BuiltinFnId {
1750 BuiltinFnIdIntCast,1750 BuiltinFnIdIntCast,
1751 BuiltinFnIdFloatCast,1751 BuiltinFnIdFloatCast,
1752 BuiltinFnIdErrSetCast,1752 BuiltinFnIdErrSetCast,
1753 BuiltinFnIdToBytes,
1754 BuiltinFnIdFromBytes,
1755 BuiltinFnIdIntToFloat,1753 BuiltinFnIdIntToFloat,
1756 BuiltinFnIdFloatToInt,1754 BuiltinFnIdFloatToInt,
1757 BuiltinFnIdBoolToInt,1755 BuiltinFnIdBoolToInt,
...@@ -1821,7 +1819,6 @@ enum PanicMsgId {...@@ -1821,7 +1819,6 @@ enum PanicMsgId {
1821 PanicMsgIdDivisionByZero,1819 PanicMsgIdDivisionByZero,
1822 PanicMsgIdRemainderDivisionByZero,1820 PanicMsgIdRemainderDivisionByZero,
1823 PanicMsgIdExactDivisionRemainder,1821 PanicMsgIdExactDivisionRemainder,
1824 PanicMsgIdSliceWidenRemainder,
1825 PanicMsgIdUnwrapOptionalFail,1822 PanicMsgIdUnwrapOptionalFail,
1826 PanicMsgIdInvalidErrorCode,1823 PanicMsgIdInvalidErrorCode,
1827 PanicMsgIdIncorrectAlignment,1824 PanicMsgIdIncorrectAlignment,
...@@ -2699,8 +2696,6 @@ enum IrInstSrcId {...@@ -2699,8 +2696,6 @@ enum IrInstSrcId {
2699 IrInstSrcIdSaveErrRetAddr,2696 IrInstSrcIdSaveErrRetAddr,
2700 IrInstSrcIdAddImplicitReturnType,2697 IrInstSrcIdAddImplicitReturnType,
2701 IrInstSrcIdErrSetCast,2698 IrInstSrcIdErrSetCast,
2702 IrInstSrcIdToBytes,
2703 IrInstSrcIdFromBytes,
2704 IrInstSrcIdCheckRuntimeScope,2699 IrInstSrcIdCheckRuntimeScope,
2705 IrInstSrcIdHasDecl,2700 IrInstSrcIdHasDecl,
2706 IrInstSrcIdUndeclaredIdent,2701 IrInstSrcIdUndeclaredIdent,
...@@ -2739,7 +2734,6 @@ enum IrInstGenId {...@@ -2739,7 +2734,6 @@ enum IrInstGenId {
2739 IrInstGenIdCall,2734 IrInstGenIdCall,
2740 IrInstGenIdReturn,2735 IrInstGenIdReturn,
2741 IrInstGenIdCast,2736 IrInstGenIdCast,
2742 IrInstGenIdResizeSlice,
2743 IrInstGenIdUnreachable,2737 IrInstGenIdUnreachable,
2744 IrInstGenIdAsm,2738 IrInstGenIdAsm,
2745 IrInstGenIdTestNonNull,2739 IrInstGenIdTestNonNull,
...@@ -3271,13 +3265,6 @@ struct IrInstGenCast {...@@ -3271,13 +3265,6 @@ struct IrInstGenCast {
3271 CastOp cast_op;3265 CastOp cast_op;
3272};3266};
32733267
3274struct IrInstGenResizeSlice {
3275 IrInstGen base;
3276
3277 IrInstGen *operand;
3278 IrInstGen *result_loc;
3279};
3280
3281struct IrInstSrcContainerInitList {3268struct IrInstSrcContainerInitList {
3282 IrInstSrc base;3269 IrInstSrc base;
32833270
...@@ -3629,21 +3616,6 @@ struct IrInstSrcErrSetCast {...@@ -3629,21 +3616,6 @@ struct IrInstSrcErrSetCast {
3629 IrInstSrc *target;3616 IrInstSrc *target;
3630};3617};
36313618
3632struct IrInstSrcToBytes {
3633 IrInstSrc base;
3634
3635 IrInstSrc *target;
3636 ResultLoc *result_loc;
3637};
3638
3639struct IrInstSrcFromBytes {
3640 IrInstSrc base;
3641
3642 IrInstSrc *dest_child_type;
3643 IrInstSrc *target;
3644 ResultLoc *result_loc;
3645};
3646
3647struct IrInstSrcIntToFloat {3619struct IrInstSrcIntToFloat {
3648 IrInstSrc base;3620 IrInstSrc base;
36493621
src/codegen.cpp-74
...@@ -972,8 +972,6 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {...@@ -972,8 +972,6 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {
972 return buf_create_from_str("remainder division by zero or negative value");972 return buf_create_from_str("remainder division by zero or negative value");
973 case PanicMsgIdExactDivisionRemainder:973 case PanicMsgIdExactDivisionRemainder:
974 return buf_create_from_str("exact division produced remainder");974 return buf_create_from_str("exact division produced remainder");
975 case PanicMsgIdSliceWidenRemainder:
976 return buf_create_from_str("slice widening size mismatch");
977 case PanicMsgIdUnwrapOptionalFail:975 case PanicMsgIdUnwrapOptionalFail:
978 return buf_create_from_str("attempt to unwrap null");976 return buf_create_from_str("attempt to unwrap null");
979 case PanicMsgIdUnreachable:977 case PanicMsgIdUnreachable:
...@@ -3085,74 +3083,6 @@ static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *in...@@ -3085,74 +3083,6 @@ static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *in
3085 }3083 }
3086}3084}
30873085
3088static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutableGen *executable,
3089 IrInstGenResizeSlice *instruction)
3090{
3091 ZigType *actual_type = instruction->operand->value->type;
3092 ZigType *wanted_type = instruction->base.value->type;
3093 LLVMValueRef expr_val = ir_llvm_value(g, instruction->operand);
3094 assert(expr_val);
3095
3096 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
3097 assert(wanted_type->id == ZigTypeIdStruct);
3098 assert(wanted_type->data.structure.special == StructSpecialSlice);
3099 assert(actual_type->id == ZigTypeIdStruct);
3100 assert(actual_type->data.structure.special == StructSpecialSlice);
3101
3102 ZigType *actual_pointer_type = actual_type->data.structure.fields[0]->type_entry;
3103 ZigType *actual_child_type = actual_pointer_type->data.pointer.child_type;
3104 ZigType *wanted_pointer_type = wanted_type->data.structure.fields[0]->type_entry;
3105 ZigType *wanted_child_type = wanted_pointer_type->data.pointer.child_type;
3106
3107
3108 size_t actual_ptr_index = actual_type->data.structure.fields[slice_ptr_index]->gen_index;
3109 size_t actual_len_index = actual_type->data.structure.fields[slice_len_index]->gen_index;
3110 size_t wanted_ptr_index = wanted_type->data.structure.fields[slice_ptr_index]->gen_index;
3111 size_t wanted_len_index = wanted_type->data.structure.fields[slice_len_index]->gen_index;
3112
3113 LLVMValueRef src_ptr_ptr = LLVMBuildStructGEP(g->builder, expr_val, (unsigned)actual_ptr_index, "");
3114 LLVMValueRef src_ptr = gen_load_untyped(g, src_ptr_ptr, 0, false, "");
3115 LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr,
3116 get_llvm_type(g, wanted_type->data.structure.fields[0]->type_entry), "");
3117 LLVMValueRef dest_ptr_ptr = LLVMBuildStructGEP(g->builder, result_loc,
3118 (unsigned)wanted_ptr_index, "");
3119 gen_store_untyped(g, src_ptr_casted, dest_ptr_ptr, 0, false);
3120
3121 LLVMValueRef src_len_ptr = LLVMBuildStructGEP(g->builder, expr_val, (unsigned)actual_len_index, "");
3122 LLVMValueRef src_len = gen_load_untyped(g, src_len_ptr, 0, false, "");
3123 uint64_t src_size = type_size(g, actual_child_type);
3124 uint64_t dest_size = type_size(g, wanted_child_type);
3125
3126 LLVMValueRef new_len;
3127 if (dest_size == 1) {
3128 LLVMValueRef src_size_val = LLVMConstInt(g->builtin_types.entry_usize->llvm_type, src_size, false);
3129 new_len = LLVMBuildMul(g->builder, src_len, src_size_val, "");
3130 } else if (src_size == 1) {
3131 LLVMValueRef dest_size_val = LLVMConstInt(g->builtin_types.entry_usize->llvm_type, dest_size, false);
3132 if (ir_want_runtime_safety(g, &instruction->base)) {
3133 LLVMValueRef remainder_val = LLVMBuildURem(g->builder, src_len, dest_size_val, "");
3134 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_usize->llvm_type);
3135 LLVMValueRef ok_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, remainder_val, zero, "");
3136 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "SliceWidenOk");
3137 LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn_val, "SliceWidenFail");
3138 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
3139
3140 LLVMPositionBuilderAtEnd(g->builder, fail_block);
3141 gen_safety_crash(g, PanicMsgIdSliceWidenRemainder);
3142
3143 LLVMPositionBuilderAtEnd(g->builder, ok_block);
3144 }
3145 new_len = LLVMBuildExactUDiv(g->builder, src_len, dest_size_val, "");
3146 } else {
3147 zig_unreachable();
3148 }
3149
3150 LLVMValueRef dest_len_ptr = LLVMBuildStructGEP(g->builder, result_loc, (unsigned)wanted_len_index, "");
3151 gen_store_untyped(g, new_len, dest_len_ptr, 0, false);
3152
3153 return result_loc;
3154}
3155
3156static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutableGen *executable,3086static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutableGen *executable,
3157 IrInstGenCast *cast_instruction)3087 IrInstGenCast *cast_instruction)
3158{3088{
...@@ -6485,8 +6415,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutableGen *executabl...@@ -6485,8 +6415,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutableGen *executabl
6485 return ir_render_assert_zero(g, executable, (IrInstGenAssertZero *)instruction);6415 return ir_render_assert_zero(g, executable, (IrInstGenAssertZero *)instruction);
6486 case IrInstGenIdAssertNonNull:6416 case IrInstGenIdAssertNonNull:
6487 return ir_render_assert_non_null(g, executable, (IrInstGenAssertNonNull *)instruction);6417 return ir_render_assert_non_null(g, executable, (IrInstGenAssertNonNull *)instruction);
6488 case IrInstGenIdResizeSlice:
6489 return ir_render_resize_slice(g, executable, (IrInstGenResizeSlice *)instruction);
6490 case IrInstGenIdPtrOfArrayToSlice:6418 case IrInstGenIdPtrOfArrayToSlice:
6491 return ir_render_ptr_of_array_to_slice(g, executable, (IrInstGenPtrOfArrayToSlice *)instruction);6419 return ir_render_ptr_of_array_to_slice(g, executable, (IrInstGenPtrOfArrayToSlice *)instruction);
6492 case IrInstGenIdSuspendBegin:6420 case IrInstGenIdSuspendBegin:
...@@ -8317,8 +8245,6 @@ static void define_builtin_fns(CodeGen *g) {...@@ -8317,8 +8245,6 @@ static void define_builtin_fns(CodeGen *g) {
8317 create_builtin_fn(g, BuiltinFnIdAtomicLoad, "atomicLoad", 3);8245 create_builtin_fn(g, BuiltinFnIdAtomicLoad, "atomicLoad", 3);
8318 create_builtin_fn(g, BuiltinFnIdAtomicStore, "atomicStore", 4);8246 create_builtin_fn(g, BuiltinFnIdAtomicStore, "atomicStore", 4);
8319 create_builtin_fn(g, BuiltinFnIdErrSetCast, "errSetCast", 2);8247 create_builtin_fn(g, BuiltinFnIdErrSetCast, "errSetCast", 2);
8320 create_builtin_fn(g, BuiltinFnIdToBytes, "sliceToBytes", 1);
8321 create_builtin_fn(g, BuiltinFnIdFromBytes, "bytesToSlice", 2);
8322 create_builtin_fn(g, BuiltinFnIdThis, "This", 0);8248 create_builtin_fn(g, BuiltinFnIdThis, "This", 0);
8323 create_builtin_fn(g, BuiltinFnIdHasDecl, "hasDecl", 2);8249 create_builtin_fn(g, BuiltinFnIdHasDecl, "hasDecl", 2);
8324 create_builtin_fn(g, BuiltinFnIdUnionInit, "unionInit", 3);8250 create_builtin_fn(g, BuiltinFnIdUnionInit, "unionInit", 3);
src/ir.cpp-256
...@@ -383,10 +383,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {...@@ -383,10 +383,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
383 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatCast *>(inst));383 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatCast *>(inst));
384 case IrInstSrcIdErrSetCast:384 case IrInstSrcIdErrSetCast:
385 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrSetCast *>(inst));385 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrSetCast *>(inst));
386 case IrInstSrcIdFromBytes:
387 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFromBytes *>(inst));
388 case IrInstSrcIdToBytes:
389 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcToBytes *>(inst));
390 case IrInstSrcIdIntToFloat:386 case IrInstSrcIdIntToFloat:
391 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntToFloat *>(inst));387 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntToFloat *>(inst));
392 case IrInstSrcIdFloatToInt:388 case IrInstSrcIdFloatToInt:
...@@ -707,8 +703,6 @@ void destroy_instruction_gen(IrInstGen *inst) {...@@ -707,8 +703,6 @@ void destroy_instruction_gen(IrInstGen *inst) {
707 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAssertZero *>(inst));703 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAssertZero *>(inst));
708 case IrInstGenIdAssertNonNull:704 case IrInstGenIdAssertNonNull:
709 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAssertNonNull *>(inst));705 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAssertNonNull *>(inst));
710 case IrInstGenIdResizeSlice:
711 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenResizeSlice *>(inst));
712 case IrInstGenIdAlloca:706 case IrInstGenIdAlloca:
713 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAlloca *>(inst));707 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAlloca *>(inst));
714 case IrInstGenIdSuspendBegin:708 case IrInstGenIdSuspendBegin:
...@@ -1563,14 +1557,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrSetCast *) {...@@ -1563,14 +1557,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrSetCast *) {
1563 return IrInstSrcIdErrSetCast;1557 return IrInstSrcIdErrSetCast;
1564}1558}
15651559
1566static constexpr IrInstSrcId ir_inst_id(IrInstSrcToBytes *) {
1567 return IrInstSrcIdToBytes;
1568}
1569
1570static constexpr IrInstSrcId ir_inst_id(IrInstSrcFromBytes *) {
1571 return IrInstSrcIdFromBytes;
1572}
1573
1574static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckRuntimeScope *) {1560static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckRuntimeScope *) {
1575 return IrInstSrcIdCheckRuntimeScope;1561 return IrInstSrcIdCheckRuntimeScope;
1576}1562}
...@@ -1700,10 +1686,6 @@ static constexpr IrInstGenId ir_inst_id(IrInstGenCast *) {...@@ -1700,10 +1686,6 @@ static constexpr IrInstGenId ir_inst_id(IrInstGenCast *) {
1700 return IrInstGenIdCast;1686 return IrInstGenIdCast;
1701}1687}
17021688
1703static constexpr IrInstGenId ir_inst_id(IrInstGenResizeSlice *) {
1704 return IrInstGenIdResizeSlice;
1705}
1706
1707static constexpr IrInstGenId ir_inst_id(IrInstGenUnreachable *) {1689static constexpr IrInstGenId ir_inst_id(IrInstGenUnreachable *) {
1708 return IrInstGenIdUnreachable;1690 return IrInstGenIdUnreachable;
1709}1691}
...@@ -2759,21 +2741,6 @@ static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instructi...@@ -2759,21 +2741,6 @@ static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instructi
2759 return &inst->base;2741 return &inst->base;
2760}2742}
27612743
2762static IrInstGen *ir_build_resize_slice(IrAnalyze *ira, IrInst *source_instruction,
2763 IrInstGen *operand, ZigType *ty, IrInstGen *result_loc)
2764{
2765 IrInstGenResizeSlice *instruction = ir_build_inst_gen<IrInstGenResizeSlice>(&ira->new_irb,
2766 source_instruction->scope, source_instruction->source_node);
2767 instruction->base.value->type = ty;
2768 instruction->operand = operand;
2769 instruction->result_loc = result_loc;
2770
2771 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2772 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
2773
2774 return &instruction->base;
2775}
2776
2777static IrInstSrc *ir_build_export(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,2744static IrInstSrc *ir_build_export(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2778 IrInstSrc *target, IrInstSrc *options)2745 IrInstSrc *target, IrInstSrc *options)
2779{2746{
...@@ -3540,32 +3507,6 @@ static IrInstSrc *ir_build_err_set_cast(IrBuilderSrc *irb, Scope *scope, AstNode...@@ -3540,32 +3507,6 @@ static IrInstSrc *ir_build_err_set_cast(IrBuilderSrc *irb, Scope *scope, AstNode
3540 return &instruction->base;3507 return &instruction->base;
3541}3508}
35423509
3543static IrInstSrc *ir_build_to_bytes(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target,
3544 ResultLoc *result_loc)
3545{
3546 IrInstSrcToBytes *instruction = ir_build_instruction<IrInstSrcToBytes>(irb, scope, source_node);
3547 instruction->target = target;
3548 instruction->result_loc = result_loc;
3549
3550 ir_ref_instruction(target, irb->current_basic_block);
3551
3552 return &instruction->base;
3553}
3554
3555static IrInstSrc *ir_build_from_bytes(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3556 IrInstSrc *dest_child_type, IrInstSrc *target, ResultLoc *result_loc)
3557{
3558 IrInstSrcFromBytes *instruction = ir_build_instruction<IrInstSrcFromBytes>(irb, scope, source_node);
3559 instruction->dest_child_type = dest_child_type;
3560 instruction->target = target;
3561 instruction->result_loc = result_loc;
3562
3563 ir_ref_instruction(dest_child_type, irb->current_basic_block);
3564 ir_ref_instruction(target, irb->current_basic_block);
3565
3566 return &instruction->base;
3567}
3568
3569static IrInstSrc *ir_build_int_to_float(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,3510static IrInstSrc *ir_build_int_to_float(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3570 IrInstSrc *dest_type, IrInstSrc *target)3511 IrInstSrc *dest_type, IrInstSrc *target)
3571{3512{
...@@ -6597,31 +6538,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod...@@ -6597,31 +6538,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
6597 IrInstSrc *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value);6538 IrInstSrc *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value);
6598 return ir_lval_wrap(irb, scope, result, lval, result_loc);6539 return ir_lval_wrap(irb, scope, result, lval, result_loc);
6599 }6540 }
6600 case BuiltinFnIdFromBytes:
6601 {
6602 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6603 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6604 if (arg0_value == irb->codegen->invalid_inst_src)
6605 return arg0_value;
6606
6607 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6608 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6609 if (arg1_value == irb->codegen->invalid_inst_src)
6610 return arg1_value;
6611
6612 IrInstSrc *result = ir_build_from_bytes(irb, scope, node, arg0_value, arg1_value, result_loc);
6613 return ir_lval_wrap(irb, scope, result, lval, result_loc);
6614 }
6615 case BuiltinFnIdToBytes:
6616 {
6617 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6618 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6619 if (arg0_value == irb->codegen->invalid_inst_src)
6620 return arg0_value;
6621
6622 IrInstSrc *result = ir_build_to_bytes(irb, scope, node, arg0_value, result_loc);
6623 return ir_lval_wrap(irb, scope, result, lval, result_loc);
6624 }
6625 case BuiltinFnIdIntToFloat:6541 case BuiltinFnIdIntToFloat:
6626 {6542 {
6627 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6543 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
...@@ -25489,171 +25405,6 @@ static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcE...@@ -25489,171 +25405,6 @@ static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcE
25489 return ir_analyze_err_set_cast(ira, &instruction->base.base, target, dest_type);25405 return ir_analyze_err_set_cast(ira, &instruction->base.base, target, dest_type);
25490}25406}
2549125407
25492static IrInstGen *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstSrcFromBytes *instruction) {
25493 Error err;
25494
25495 ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->child);
25496 if (type_is_invalid(dest_child_type))
25497 return ira->codegen->invalid_inst_gen;
25498
25499 IrInstGen *target = instruction->target->child;
25500 if (type_is_invalid(target->value->type))
25501 return ira->codegen->invalid_inst_gen;
25502
25503 bool src_ptr_const;
25504 bool src_ptr_volatile;
25505 uint32_t src_ptr_align;
25506 if (target->value->type->id == ZigTypeIdPointer) {
25507 src_ptr_const = target->value->type->data.pointer.is_const;
25508 src_ptr_volatile = target->value->type->data.pointer.is_volatile;
25509
25510 if ((err = resolve_ptr_align(ira, target->value->type, &src_ptr_align)))
25511 return ira->codegen->invalid_inst_gen;
25512 } else if (is_slice(target->value->type)) {
25513 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;
25514 src_ptr_const = src_ptr_type->data.pointer.is_const;
25515 src_ptr_volatile = src_ptr_type->data.pointer.is_volatile;
25516
25517 if ((err = resolve_ptr_align(ira, src_ptr_type, &src_ptr_align)))
25518 return ira->codegen->invalid_inst_gen;
25519 } else {
25520 src_ptr_const = true;
25521 src_ptr_volatile = false;
25522
25523 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusAlignmentKnown)))
25524 return ira->codegen->invalid_inst_gen;
25525
25526 src_ptr_align = get_abi_alignment(ira->codegen, target->value->type);
25527 }
25528
25529 if (src_ptr_align != 0) {
25530 if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusAlignmentKnown)))
25531 return ira->codegen->invalid_inst_gen;
25532 }
25533
25534 ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type,
25535 src_ptr_const, src_ptr_volatile, PtrLenUnknown,
25536 src_ptr_align, 0, 0, false);
25537 ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);
25538
25539 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
25540 src_ptr_const, src_ptr_volatile, PtrLenUnknown,
25541 src_ptr_align, 0, 0, false);
25542 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
25543
25544 IrInstGen *casted_value = ir_implicit_cast2(ira, &instruction->target->base, target, u8_slice);
25545 if (type_is_invalid(casted_value->value->type))
25546 return ira->codegen->invalid_inst_gen;
25547
25548 bool have_known_len = false;
25549 uint64_t known_len;
25550
25551 if (instr_is_comptime(casted_value)) {
25552 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
25553 if (!val)
25554 return ira->codegen->invalid_inst_gen;
25555
25556 ZigValue *len_val = val->data.x_struct.fields[slice_len_index];
25557 if (value_is_comptime(len_val)) {
25558 known_len = bigint_as_u64(&len_val->data.x_bigint);
25559 have_known_len = true;
25560 }
25561 }
25562
25563 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
25564 dest_slice_type, nullptr, true, true);
25565 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) {
25566 return result_loc;
25567 }
25568
25569 if (target->value->type->id == ZigTypeIdPointer &&
25570 target->value->type->data.pointer.ptr_len == PtrLenSingle &&
25571 target->value->type->data.pointer.child_type->id == ZigTypeIdArray)
25572 {
25573 known_len = target->value->type->data.pointer.child_type->data.array.len;
25574 have_known_len = true;
25575 } else if (casted_value->value->data.rh_slice.id == RuntimeHintSliceIdLen) {
25576 known_len = casted_value->value->data.rh_slice.len;
25577 have_known_len = true;
25578 }
25579
25580 if (have_known_len) {
25581 if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusSizeKnown)))
25582 return ira->codegen->invalid_inst_gen;
25583 uint64_t child_type_size = type_size(ira->codegen, dest_child_type);
25584 uint64_t remainder = known_len % child_type_size;
25585 if (remainder != 0) {
25586 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
25587 buf_sprintf("unable to convert [%" ZIG_PRI_u64 "]u8 to %s: size mismatch",
25588 known_len, buf_ptr(&dest_slice_type->name)));
25589 add_error_note(ira->codegen, msg, instruction->dest_child_type->base.source_node,
25590 buf_sprintf("%s has size %" ZIG_PRI_u64 "; remaining bytes: %" ZIG_PRI_u64,
25591 buf_ptr(&dest_child_type->name), child_type_size, remainder));
25592 return ira->codegen->invalid_inst_gen;
25593 }
25594 }
25595
25596 return ir_build_resize_slice(ira, &instruction->base.base, casted_value, dest_slice_type, result_loc);
25597}
25598
25599static IrInstGen *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstSrcToBytes *instruction) {
25600 Error err;
25601
25602 IrInstGen *target = instruction->target->child;
25603 if (type_is_invalid(target->value->type))
25604 return ira->codegen->invalid_inst_gen;
25605
25606 if (!is_slice(target->value->type)) {
25607 ir_add_error(ira, &instruction->target->base,
25608 buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value->type->name)));
25609 return ira->codegen->invalid_inst_gen;
25610 }
25611
25612 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;
25613
25614 uint32_t alignment;
25615 if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment)))
25616 return ira->codegen->invalid_inst_gen;
25617
25618 ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
25619 src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown,
25620 alignment, 0, 0, false);
25621 ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);
25622
25623 if (instr_is_comptime(target)) {
25624 ZigValue *target_val = ir_resolve_const(ira, target, UndefBad);
25625 if (target_val == nullptr)
25626 return ira->codegen->invalid_inst_gen;
25627
25628 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_slice_type);
25629 result->value->data.x_struct.fields = alloc_const_vals_ptrs(ira->codegen, 2);
25630
25631 ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];
25632 ZigValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index];
25633 copy_const_val(ira->codegen, ptr_val, target_ptr_val);
25634 ptr_val->type = dest_ptr_type;
25635
25636 ZigValue *len_val = result->value->data.x_struct.fields[slice_len_index];
25637 len_val->special = ConstValSpecialStatic;
25638 len_val->type = ira->codegen->builtin_types.entry_usize;
25639 ZigValue *target_len_val = target_val->data.x_struct.fields[slice_len_index];
25640 ZigType *elem_type = src_ptr_type->data.pointer.child_type;
25641 BigInt elem_size_bigint;
25642 bigint_init_unsigned(&elem_size_bigint, type_size(ira->codegen, elem_type));
25643 bigint_mul(&len_val->data.x_bigint, &target_len_val->data.x_bigint, &elem_size_bigint);
25644
25645 return result;
25646 }
25647
25648 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
25649 dest_slice_type, nullptr, true, true);
25650 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
25651 return result_loc;
25652 }
25653
25654 return ir_build_resize_slice(ira, &instruction->base.base, target, dest_slice_type, result_loc);
25655}
25656
25657static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) {25408static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) {
25658 Error err;25409 Error err;
2565925410
...@@ -29783,10 +29534,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc...@@ -29783,10 +29534,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
29783 return ir_analyze_instruction_float_cast(ira, (IrInstSrcFloatCast *)instruction);29534 return ir_analyze_instruction_float_cast(ira, (IrInstSrcFloatCast *)instruction);
29784 case IrInstSrcIdErrSetCast:29535 case IrInstSrcIdErrSetCast:
29785 return ir_analyze_instruction_err_set_cast(ira, (IrInstSrcErrSetCast *)instruction);29536 return ir_analyze_instruction_err_set_cast(ira, (IrInstSrcErrSetCast *)instruction);
29786 case IrInstSrcIdFromBytes:
29787 return ir_analyze_instruction_from_bytes(ira, (IrInstSrcFromBytes *)instruction);
29788 case IrInstSrcIdToBytes:
29789 return ir_analyze_instruction_to_bytes(ira, (IrInstSrcToBytes *)instruction);
29790 case IrInstSrcIdIntToFloat:29537 case IrInstSrcIdIntToFloat:
29791 return ir_analyze_instruction_int_to_float(ira, (IrInstSrcIntToFloat *)instruction);29538 return ir_analyze_instruction_int_to_float(ira, (IrInstSrcIntToFloat *)instruction);
29792 case IrInstSrcIdFloatToInt:29539 case IrInstSrcIdFloatToInt:
...@@ -30113,7 +29860,6 @@ bool ir_inst_gen_has_side_effects(IrInstGen *instruction) {...@@ -30113,7 +29860,6 @@ bool ir_inst_gen_has_side_effects(IrInstGen *instruction) {
30113 case IrInstGenIdCmpxchg:29860 case IrInstGenIdCmpxchg:
30114 case IrInstGenIdAssertZero:29861 case IrInstGenIdAssertZero:
30115 case IrInstGenIdAssertNonNull:29862 case IrInstGenIdAssertNonNull:
30116 case IrInstGenIdResizeSlice:
30117 case IrInstGenIdPtrOfArrayToSlice:29863 case IrInstGenIdPtrOfArrayToSlice:
30118 case IrInstGenIdSlice:29864 case IrInstGenIdSlice:
30119 case IrInstGenIdOptionalWrap:29865 case IrInstGenIdOptionalWrap:
...@@ -30339,8 +30085,6 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {...@@ -30339,8 +30085,6 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
30339 case IrInstSrcIdIntToFloat:30085 case IrInstSrcIdIntToFloat:
30340 case IrInstSrcIdFloatToInt:30086 case IrInstSrcIdFloatToInt:
30341 case IrInstSrcIdBoolToInt:30087 case IrInstSrcIdBoolToInt:
30342 case IrInstSrcIdFromBytes:
30343 case IrInstSrcIdToBytes:
30344 case IrInstSrcIdEnumToInt:30088 case IrInstSrcIdEnumToInt:
30345 case IrInstSrcIdHasDecl:30089 case IrInstSrcIdHasDecl:
30346 case IrInstSrcIdAlloca:30090 case IrInstSrcIdAlloca:
src/ir_print.cpp-36
...@@ -307,10 +307,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {...@@ -307,10 +307,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
307 return "SrcAddImplicitReturnType";307 return "SrcAddImplicitReturnType";
308 case IrInstSrcIdErrSetCast:308 case IrInstSrcIdErrSetCast:
309 return "SrcErrSetCast";309 return "SrcErrSetCast";
310 case IrInstSrcIdToBytes:
311 return "SrcToBytes";
312 case IrInstSrcIdFromBytes:
313 return "SrcFromBytes";
314 case IrInstSrcIdCheckRuntimeScope:310 case IrInstSrcIdCheckRuntimeScope:
315 return "SrcCheckRuntimeScope";311 return "SrcCheckRuntimeScope";
316 case IrInstSrcIdHasDecl:312 case IrInstSrcIdHasDecl:
...@@ -383,8 +379,6 @@ const char* ir_inst_gen_type_str(IrInstGenId id) {...@@ -383,8 +379,6 @@ const char* ir_inst_gen_type_str(IrInstGenId id) {
383 return "GenReturn";379 return "GenReturn";
384 case IrInstGenIdCast:380 case IrInstGenIdCast:
385 return "GenCast";381 return "GenCast";
386 case IrInstGenIdResizeSlice:
387 return "GenResizeSlice";
388 case IrInstGenIdUnreachable:382 case IrInstGenIdUnreachable:
389 return "GenUnreachable";383 return "GenUnreachable";
390 case IrInstGenIdAsm:384 case IrInstGenIdAsm:
...@@ -1644,20 +1638,6 @@ static void ir_print_err_set_cast(IrPrintSrc *irp, IrInstSrcErrSetCast *instruct...@@ -1644,20 +1638,6 @@ static void ir_print_err_set_cast(IrPrintSrc *irp, IrInstSrcErrSetCast *instruct
1644 fprintf(irp->f, ")");1638 fprintf(irp->f, ")");
1645}1639}
16461640
1647static void ir_print_from_bytes(IrPrintSrc *irp, IrInstSrcFromBytes *instruction) {
1648 fprintf(irp->f, "@bytesToSlice(");
1649 ir_print_other_inst_src(irp, instruction->dest_child_type);
1650 fprintf(irp->f, ", ");
1651 ir_print_other_inst_src(irp, instruction->target);
1652 fprintf(irp->f, ")");
1653}
1654
1655static void ir_print_to_bytes(IrPrintSrc *irp, IrInstSrcToBytes *instruction) {
1656 fprintf(irp->f, "@sliceToBytes(");
1657 ir_print_other_inst_src(irp, instruction->target);
1658 fprintf(irp->f, ")");
1659}
1660
1661static void ir_print_int_to_float(IrPrintSrc *irp, IrInstSrcIntToFloat *instruction) {1641static void ir_print_int_to_float(IrPrintSrc *irp, IrInstSrcIntToFloat *instruction) {
1662 fprintf(irp->f, "@intToFloat(");1642 fprintf(irp->f, "@intToFloat(");
1663 ir_print_other_inst_src(irp, instruction->dest_type);1643 ir_print_other_inst_src(irp, instruction->dest_type);
...@@ -2142,13 +2122,6 @@ static void ir_print_assert_non_null(IrPrintGen *irp, IrInstGenAssertNonNull *in...@@ -2142,13 +2122,6 @@ static void ir_print_assert_non_null(IrPrintGen *irp, IrInstGenAssertNonNull *in
2142 fprintf(irp->f, ")");2122 fprintf(irp->f, ")");
2143}2123}
21442124
2145static void ir_print_resize_slice(IrPrintGen *irp, IrInstGenResizeSlice *instruction) {
2146 fprintf(irp->f, "@resizeSlice(");
2147 ir_print_other_inst_gen(irp, instruction->operand);
2148 fprintf(irp->f, ")result=");
2149 ir_print_other_inst_gen(irp, instruction->result_loc);
2150}
2151
2152static void ir_print_alloca_src(IrPrintSrc *irp, IrInstSrcAlloca *instruction) {2125static void ir_print_alloca_src(IrPrintSrc *irp, IrInstSrcAlloca *instruction) {
2153 fprintf(irp->f, "Alloca(align=");2126 fprintf(irp->f, "Alloca(align=");
2154 ir_print_other_inst_src(irp, instruction->align);2127 ir_print_other_inst_src(irp, instruction->align);
...@@ -2793,12 +2766,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai...@@ -2793,12 +2766,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai
2793 case IrInstSrcIdErrSetCast:2766 case IrInstSrcIdErrSetCast:
2794 ir_print_err_set_cast(irp, (IrInstSrcErrSetCast *)instruction);2767 ir_print_err_set_cast(irp, (IrInstSrcErrSetCast *)instruction);
2795 break;2768 break;
2796 case IrInstSrcIdFromBytes:
2797 ir_print_from_bytes(irp, (IrInstSrcFromBytes *)instruction);
2798 break;
2799 case IrInstSrcIdToBytes:
2800 ir_print_to_bytes(irp, (IrInstSrcToBytes *)instruction);
2801 break;
2802 case IrInstSrcIdIntToFloat:2769 case IrInstSrcIdIntToFloat:
2803 ir_print_int_to_float(irp, (IrInstSrcIntToFloat *)instruction);2770 ir_print_int_to_float(irp, (IrInstSrcIntToFloat *)instruction);
2804 break;2771 break;
...@@ -3273,9 +3240,6 @@ static void ir_print_inst_gen(IrPrintGen *irp, IrInstGen *instruction, bool trai...@@ -3273,9 +3240,6 @@ static void ir_print_inst_gen(IrPrintGen *irp, IrInstGen *instruction, bool trai
3273 case IrInstGenIdAssertNonNull:3240 case IrInstGenIdAssertNonNull:
3274 ir_print_assert_non_null(irp, (IrInstGenAssertNonNull *)instruction);3241 ir_print_assert_non_null(irp, (IrInstGenAssertNonNull *)instruction);
3275 break;3242 break;
3276 case IrInstGenIdResizeSlice:
3277 ir_print_resize_slice(irp, (IrInstGenResizeSlice *)instruction);
3278 break;
3279 case IrInstGenIdAlloca:3243 case IrInstGenIdAlloca:
3280 ir_print_alloca_gen(irp, (IrInstGenAlloca *)instruction);3244 ir_print_alloca_gen(irp, (IrInstGenAlloca *)instruction);
3281 break;3245 break;