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 {
17501750 BuiltinFnIdIntCast,
17511751 BuiltinFnIdFloatCast,
17521752 BuiltinFnIdErrSetCast,
1753 BuiltinFnIdToBytes,
1754 BuiltinFnIdFromBytes,
17551753 BuiltinFnIdIntToFloat,
17561754 BuiltinFnIdFloatToInt,
17571755 BuiltinFnIdBoolToInt,
......@@ -1821,7 +1819,6 @@ enum PanicMsgId {
18211819 PanicMsgIdDivisionByZero,
18221820 PanicMsgIdRemainderDivisionByZero,
18231821 PanicMsgIdExactDivisionRemainder,
1824 PanicMsgIdSliceWidenRemainder,
18251822 PanicMsgIdUnwrapOptionalFail,
18261823 PanicMsgIdInvalidErrorCode,
18271824 PanicMsgIdIncorrectAlignment,
......@@ -2699,8 +2696,6 @@ enum IrInstSrcId {
26992696 IrInstSrcIdSaveErrRetAddr,
27002697 IrInstSrcIdAddImplicitReturnType,
27012698 IrInstSrcIdErrSetCast,
2702 IrInstSrcIdToBytes,
2703 IrInstSrcIdFromBytes,
27042699 IrInstSrcIdCheckRuntimeScope,
27052700 IrInstSrcIdHasDecl,
27062701 IrInstSrcIdUndeclaredIdent,
......@@ -2739,7 +2734,6 @@ enum IrInstGenId {
27392734 IrInstGenIdCall,
27402735 IrInstGenIdReturn,
27412736 IrInstGenIdCast,
2742 IrInstGenIdResizeSlice,
27432737 IrInstGenIdUnreachable,
27442738 IrInstGenIdAsm,
27452739 IrInstGenIdTestNonNull,
......@@ -3271,13 +3265,6 @@ struct IrInstGenCast {
32713265 CastOp cast_op;
32723266};
32733267
3274struct IrInstGenResizeSlice {
3275 IrInstGen base;
3276
3277 IrInstGen *operand;
3278 IrInstGen *result_loc;
3279};
3280
32813268struct IrInstSrcContainerInitList {
32823269 IrInstSrc base;
32833270
......@@ -3629,21 +3616,6 @@ struct IrInstSrcErrSetCast {
36293616 IrInstSrc *target;
36303617};
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
36473619struct IrInstSrcIntToFloat {
36483620 IrInstSrc base;
36493621
src/codegen.cpp-74
......@@ -972,8 +972,6 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {
972972 return buf_create_from_str("remainder division by zero or negative value");
973973 case PanicMsgIdExactDivisionRemainder:
974974 return buf_create_from_str("exact division produced remainder");
975 case PanicMsgIdSliceWidenRemainder:
976 return buf_create_from_str("slice widening size mismatch");
977975 case PanicMsgIdUnwrapOptionalFail:
978976 return buf_create_from_str("attempt to unwrap null");
979977 case PanicMsgIdUnreachable:
......@@ -3085,74 +3083,6 @@ static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *in
30853083 }
30863084}
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
31563086static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutableGen *executable,
31573087 IrInstGenCast *cast_instruction)
31583088{
......@@ -6485,8 +6415,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutableGen *executabl
64856415 return ir_render_assert_zero(g, executable, (IrInstGenAssertZero *)instruction);
64866416 case IrInstGenIdAssertNonNull:
64876417 return ir_render_assert_non_null(g, executable, (IrInstGenAssertNonNull *)instruction);
6488 case IrInstGenIdResizeSlice:
6489 return ir_render_resize_slice(g, executable, (IrInstGenResizeSlice *)instruction);
64906418 case IrInstGenIdPtrOfArrayToSlice:
64916419 return ir_render_ptr_of_array_to_slice(g, executable, (IrInstGenPtrOfArrayToSlice *)instruction);
64926420 case IrInstGenIdSuspendBegin:
......@@ -8317,8 +8245,6 @@ static void define_builtin_fns(CodeGen *g) {
83178245 create_builtin_fn(g, BuiltinFnIdAtomicLoad, "atomicLoad", 3);
83188246 create_builtin_fn(g, BuiltinFnIdAtomicStore, "atomicStore", 4);
83198247 create_builtin_fn(g, BuiltinFnIdErrSetCast, "errSetCast", 2);
8320 create_builtin_fn(g, BuiltinFnIdToBytes, "sliceToBytes", 1);
8321 create_builtin_fn(g, BuiltinFnIdFromBytes, "bytesToSlice", 2);
83228248 create_builtin_fn(g, BuiltinFnIdThis, "This", 0);
83238249 create_builtin_fn(g, BuiltinFnIdHasDecl, "hasDecl", 2);
83248250 create_builtin_fn(g, BuiltinFnIdUnionInit, "unionInit", 3);
src/ir.cpp-256
......@@ -383,10 +383,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
383383 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatCast *>(inst));
384384 case IrInstSrcIdErrSetCast:
385385 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));
390386 case IrInstSrcIdIntToFloat:
391387 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntToFloat *>(inst));
392388 case IrInstSrcIdFloatToInt:
......@@ -707,8 +703,6 @@ void destroy_instruction_gen(IrInstGen *inst) {
707703 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAssertZero *>(inst));
708704 case IrInstGenIdAssertNonNull:
709705 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAssertNonNull *>(inst));
710 case IrInstGenIdResizeSlice:
711 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenResizeSlice *>(inst));
712706 case IrInstGenIdAlloca:
713707 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAlloca *>(inst));
714708 case IrInstGenIdSuspendBegin:
......@@ -1563,14 +1557,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrSetCast *) {
15631557 return IrInstSrcIdErrSetCast;
15641558}
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
15741560static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckRuntimeScope *) {
15751561 return IrInstSrcIdCheckRuntimeScope;
15761562}
......@@ -1700,10 +1686,6 @@ static constexpr IrInstGenId ir_inst_id(IrInstGenCast *) {
17001686 return IrInstGenIdCast;
17011687}
17021688
1703static constexpr IrInstGenId ir_inst_id(IrInstGenResizeSlice *) {
1704 return IrInstGenIdResizeSlice;
1705}
1706
17071689static constexpr IrInstGenId ir_inst_id(IrInstGenUnreachable *) {
17081690 return IrInstGenIdUnreachable;
17091691}
......@@ -2759,21 +2741,6 @@ static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instructi
27592741 return &inst->base;
27602742}
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
27772744static IrInstSrc *ir_build_export(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
27782745 IrInstSrc *target, IrInstSrc *options)
27792746{
......@@ -3540,32 +3507,6 @@ static IrInstSrc *ir_build_err_set_cast(IrBuilderSrc *irb, Scope *scope, AstNode
35403507 return &instruction->base;
35413508}
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
35693510static IrInstSrc *ir_build_int_to_float(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
35703511 IrInstSrc *dest_type, IrInstSrc *target)
35713512{
......@@ -6597,31 +6538,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
65976538 IrInstSrc *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value);
65986539 return ir_lval_wrap(irb, scope, result, lval, result_loc);
65996540 }
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 }
66256541 case BuiltinFnIdIntToFloat:
66266542 {
66276543 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
2548925405 return ir_analyze_err_set_cast(ira, &instruction->base.base, target, dest_type);
2549025406}
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
2565725408static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) {
2565825409 Error err;
2565925410
......@@ -29783,10 +29534,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
2978329534 return ir_analyze_instruction_float_cast(ira, (IrInstSrcFloatCast *)instruction);
2978429535 case IrInstSrcIdErrSetCast:
2978529536 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);
2979029537 case IrInstSrcIdIntToFloat:
2979129538 return ir_analyze_instruction_int_to_float(ira, (IrInstSrcIntToFloat *)instruction);
2979229539 case IrInstSrcIdFloatToInt:
......@@ -30113,7 +29860,6 @@ bool ir_inst_gen_has_side_effects(IrInstGen *instruction) {
3011329860 case IrInstGenIdCmpxchg:
3011429861 case IrInstGenIdAssertZero:
3011529862 case IrInstGenIdAssertNonNull:
30116 case IrInstGenIdResizeSlice:
3011729863 case IrInstGenIdPtrOfArrayToSlice:
3011829864 case IrInstGenIdSlice:
3011929865 case IrInstGenIdOptionalWrap:
......@@ -30339,8 +30085,6 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
3033930085 case IrInstSrcIdIntToFloat:
3034030086 case IrInstSrcIdFloatToInt:
3034130087 case IrInstSrcIdBoolToInt:
30342 case IrInstSrcIdFromBytes:
30343 case IrInstSrcIdToBytes:
3034430088 case IrInstSrcIdEnumToInt:
3034530089 case IrInstSrcIdHasDecl:
3034630090 case IrInstSrcIdAlloca:
src/ir_print.cpp-36
......@@ -307,10 +307,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
307307 return "SrcAddImplicitReturnType";
308308 case IrInstSrcIdErrSetCast:
309309 return "SrcErrSetCast";
310 case IrInstSrcIdToBytes:
311 return "SrcToBytes";
312 case IrInstSrcIdFromBytes:
313 return "SrcFromBytes";
314310 case IrInstSrcIdCheckRuntimeScope:
315311 return "SrcCheckRuntimeScope";
316312 case IrInstSrcIdHasDecl:
......@@ -383,8 +379,6 @@ const char* ir_inst_gen_type_str(IrInstGenId id) {
383379 return "GenReturn";
384380 case IrInstGenIdCast:
385381 return "GenCast";
386 case IrInstGenIdResizeSlice:
387 return "GenResizeSlice";
388382 case IrInstGenIdUnreachable:
389383 return "GenUnreachable";
390384 case IrInstGenIdAsm:
......@@ -1644,20 +1638,6 @@ static void ir_print_err_set_cast(IrPrintSrc *irp, IrInstSrcErrSetCast *instruct
16441638 fprintf(irp->f, ")");
16451639}
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
16611641static void ir_print_int_to_float(IrPrintSrc *irp, IrInstSrcIntToFloat *instruction) {
16621642 fprintf(irp->f, "@intToFloat(");
16631643 ir_print_other_inst_src(irp, instruction->dest_type);
......@@ -2142,13 +2122,6 @@ static void ir_print_assert_non_null(IrPrintGen *irp, IrInstGenAssertNonNull *in
21422122 fprintf(irp->f, ")");
21432123}
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
21522125static void ir_print_alloca_src(IrPrintSrc *irp, IrInstSrcAlloca *instruction) {
21532126 fprintf(irp->f, "Alloca(align=");
21542127 ir_print_other_inst_src(irp, instruction->align);
......@@ -2793,12 +2766,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai
27932766 case IrInstSrcIdErrSetCast:
27942767 ir_print_err_set_cast(irp, (IrInstSrcErrSetCast *)instruction);
27952768 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;
28022769 case IrInstSrcIdIntToFloat:
28032770 ir_print_int_to_float(irp, (IrInstSrcIntToFloat *)instruction);
28042771 break;
......@@ -3273,9 +3240,6 @@ static void ir_print_inst_gen(IrPrintGen *irp, IrInstGen *instruction, bool trai
32733240 case IrInstGenIdAssertNonNull:
32743241 ir_print_assert_non_null(irp, (IrInstGenAssertNonNull *)instruction);
32753242 break;
3276 case IrInstGenIdResizeSlice:
3277 ir_print_resize_slice(irp, (IrInstGenResizeSlice *)instruction);
3278 break;
32793243 case IrInstGenIdAlloca:
32803244 ir_print_alloca_gen(irp, (IrInstGenAlloca *)instruction);
32813245 break;