| ... | @@ -479,10 +479,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionCUndef *) { | ... | @@ -479,10 +479,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionCUndef *) { |
| 479 | return IrInstructionIdCUndef; | 479 | return IrInstructionIdCUndef; |
| 480 | } | 480 | } |
| 481 | | 481 | |
| 482 | static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayLen *) { | | |
| 483 | return IrInstructionIdArrayLen; | | |
| 484 | } | | |
| 485 | | | |
| 486 | static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) { | 482 | static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) { |
| 487 | return IrInstructionIdRef; | 483 | return IrInstructionIdRef; |
| 488 | } | 484 | } |
| ... | @@ -1663,15 +1659,6 @@ static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *sou | ... | @@ -1663,15 +1659,6 @@ static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *sou |
| 1663 | return &instruction->base; | 1659 | return &instruction->base; |
| 1664 | } | 1660 | } |
| 1665 | | 1661 | |
| 1666 | static IrInstruction *ir_build_array_len(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *array_value) { | | |
| 1667 | IrInstructionArrayLen *instruction = ir_build_instruction<IrInstructionArrayLen>(irb, scope, source_node); | | |
| 1668 | instruction->array_value = array_value; | | |
| 1669 | | | |
| 1670 | ir_ref_instruction(array_value, irb->current_basic_block); | | |
| 1671 | | | |
| 1672 | return &instruction->base; | | |
| 1673 | } | | |
| 1674 | | | |
| 1675 | static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value, | 1662 | static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value, |
| 1676 | bool is_const, bool is_volatile) | 1663 | bool is_const, bool is_volatile) |
| 1677 | { | 1664 | { |
| ... | @@ -5351,7 +5338,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo | ... | @@ -5351,7 +5338,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5351 | IrBasicBlock *else_block = else_node ? ir_create_basic_block(irb, child_scope, "ForElse") : end_block; | 5338 | IrBasicBlock *else_block = else_node ? ir_create_basic_block(irb, child_scope, "ForElse") : end_block; |
| 5352 | IrBasicBlock *continue_block = ir_create_basic_block(irb, child_scope, "ForContinue"); | 5339 | IrBasicBlock *continue_block = ir_create_basic_block(irb, child_scope, "ForContinue"); |
| 5353 | | 5340 | |
| 5354 | IrInstruction *len_val = ir_build_array_len(irb, child_scope, node, array_val); | 5341 | Buf *len_field_name = buf_create_from_str("len"); |
| | 5342 | IrInstruction *len_ref = ir_build_field_ptr(irb, child_scope, node, array_val_ptr, len_field_name); |
| | 5343 | IrInstruction *len_val = ir_build_load_ptr(irb, child_scope, node, len_ref); |
| 5355 | ir_build_br(irb, child_scope, node, cond_block, is_comptime); | 5344 | ir_build_br(irb, child_scope, node, cond_block, is_comptime); |
| 5356 | | 5345 | |
| 5357 | ir_set_cursor_at_end_and_append_block(irb, cond_block); | 5346 | ir_set_cursor_at_end_and_append_block(irb, cond_block); |
| ... | @@ -9450,12 +9439,6 @@ static IrInstruction *ir_const_unsigned(IrAnalyze *ira, IrInstruction *source_in | ... | @@ -9450,12 +9439,6 @@ static IrInstruction *ir_const_unsigned(IrAnalyze *ira, IrInstruction *source_in |
| 9450 | return result; | 9439 | return result; |
| 9451 | } | 9440 | } |
| 9452 | | 9441 | |
| 9453 | static IrInstruction *ir_const_usize(IrAnalyze *ira, IrInstruction *source_instruction, uint64_t value) { | | |
| 9454 | IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_usize); | | |
| 9455 | bigint_init_unsigned(&result->value.data.x_bigint, value); | | |
| 9456 | return result; | | |
| 9457 | } | | |
| 9458 | | | |
| 9459 | static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction, | 9442 | static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 9460 | ConstExprValue *pointee, ZigType *pointee_type, | 9443 | ConstExprValue *pointee, ZigType *pointee_type, |
| 9461 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align) | 9444 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align) |
| ... | @@ -14971,8 +14954,14 @@ static IrInstruction *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, | ... | @@ -14971,8 +14954,14 @@ static IrInstruction *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, |
| 14971 | | 14954 | |
| 14972 | ZigType *ptr_type; | 14955 | ZigType *ptr_type; |
| 14973 | if (type_entry->id == ZigTypeIdArray) { | 14956 | if (type_entry->id == ZigTypeIdArray) { |
| | 14957 | // TODO: Allow capturing pointer to const array. |
| | 14958 | // const a = "123"; for (a) |*c| continue; |
| | 14959 | // error: expected type '*u8', found '*const u8' |
| 14974 | ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false); | 14960 | ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false); |
| 14975 | } else if (is_slice(type_entry)) { | 14961 | } else if (is_array_ref(type_entry)) { |
| | 14962 | ptr_type = get_pointer_to_type(ira->codegen, |
| | 14963 | type_entry->data.pointer.child_type->data.array.child_type, type_entry->data.pointer.is_const); |
| | 14964 | } else if (is_slice(type_entry)) { |
| 14976 | ptr_type = adjust_ptr_len(ira->codegen, type_entry->data.structure.fields[0].type_entry, PtrLenSingle); | 14965 | ptr_type = adjust_ptr_len(ira->codegen, type_entry->data.structure.fields[0].type_entry, PtrLenSingle); |
| 14977 | } else if (type_entry->id == ZigTypeIdArgTuple) { | 14966 | } else if (type_entry->id == ZigTypeIdArgTuple) { |
| 14978 | ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad); | 14967 | ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad); |
| ... | @@ -15959,39 +15948,6 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio | ... | @@ -15959,39 +15948,6 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio |
| 15959 | return result; | 15948 | return result; |
| 15960 | } | 15949 | } |
| 15961 | | 15950 | |
| 15962 | static IrInstruction *ir_analyze_instruction_array_len(IrAnalyze *ira, | | |
| 15963 | IrInstructionArrayLen *array_len_instruction) | | |
| 15964 | { | | |
| 15965 | IrInstruction *array_value = array_len_instruction->array_value->child; | | |
| 15966 | ZigType *type_entry = array_value->value.type; | | |
| 15967 | if (type_is_invalid(type_entry)) { | | |
| 15968 | return ira->codegen->invalid_instruction; | | |
| 15969 | } else if (type_entry->id == ZigTypeIdArray) { | | |
| 15970 | return ir_const_usize(ira, &array_len_instruction->base, | | |
| 15971 | type_entry->data.array.len); | | |
| 15972 | } else if (is_slice(type_entry)) { | | |
| 15973 | if (array_value->value.special != ConstValSpecialRuntime) { | | |
| 15974 | ConstExprValue *len_val = &array_value->value.data.x_struct.fields[slice_len_index]; | | |
| 15975 | if (len_val->special != ConstValSpecialRuntime) { | | |
| 15976 | return ir_const_usize(ira, &array_len_instruction->base, | | |
| 15977 | bigint_as_unsigned(&len_val->data.x_bigint)); | | |
| 15978 | } | | |
| 15979 | } | | |
| 15980 | TypeStructField *field = &type_entry->data.structure.fields[slice_len_index]; | | |
| 15981 | IrInstruction *len_ptr = ir_build_struct_field_ptr(&ira->new_irb, array_len_instruction->base.scope, | | |
| 15982 | array_len_instruction->base.source_node, array_value, field); | | |
| 15983 | len_ptr->value.type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_usize, true); | | |
| 15984 | IrInstruction *result = ir_build_load_ptr(&ira->new_irb, | | |
| 15985 | array_len_instruction->base.scope, array_len_instruction->base.source_node, len_ptr); | | |
| 15986 | result->value.type = ira->codegen->builtin_types.entry_usize; | | |
| 15987 | return result; | | |
| 15988 | } else { | | |
| 15989 | ir_add_error_node(ira, array_len_instruction->base.source_node, | | |
| 15990 | buf_sprintf("type '%s' has no field 'len'", buf_ptr(&array_value->value.type->name))); | | |
| 15991 | return ira->codegen->invalid_instruction; | | |
| 15992 | } | | |
| 15993 | } | | |
| 15994 | | | |
| 15995 | static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) { | 15951 | static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) { |
| 15996 | IrInstruction *value = ref_instruction->value->child; | 15952 | IrInstruction *value = ref_instruction->value->child; |
| 15997 | if (type_is_invalid(value->value.type)) | 15953 | if (type_is_invalid(value->value.type)) |
| ... | @@ -20893,8 +20849,6 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio | ... | @@ -20893,8 +20849,6 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio |
| 20893 | return ir_analyze_instruction_union_tag(ira, (IrInstructionUnionTag *)instruction); | 20849 | return ir_analyze_instruction_union_tag(ira, (IrInstructionUnionTag *)instruction); |
| 20894 | case IrInstructionIdImport: | 20850 | case IrInstructionIdImport: |
| 20895 | return ir_analyze_instruction_import(ira, (IrInstructionImport *)instruction); | 20851 | return ir_analyze_instruction_import(ira, (IrInstructionImport *)instruction); |
| 20896 | case IrInstructionIdArrayLen: | | |
| 20897 | return ir_analyze_instruction_array_len(ira, (IrInstructionArrayLen *)instruction); | | |
| 20898 | case IrInstructionIdRef: | 20852 | case IrInstructionIdRef: |
| 20899 | return ir_analyze_instruction_ref(ira, (IrInstructionRef *)instruction); | 20853 | return ir_analyze_instruction_ref(ira, (IrInstructionRef *)instruction); |
| 20900 | case IrInstructionIdContainerInitList: | 20854 | case IrInstructionIdContainerInitList: |
| ... | @@ -21228,7 +21182,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -21228,7 +21182,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 21228 | case IrInstructionIdTypeOf: | 21182 | case IrInstructionIdTypeOf: |
| 21229 | case IrInstructionIdToPtrType: | 21183 | case IrInstructionIdToPtrType: |
| 21230 | case IrInstructionIdPtrTypeChild: | 21184 | case IrInstructionIdPtrTypeChild: |
| 21231 | case IrInstructionIdArrayLen: | | |
| 21232 | case IrInstructionIdStructFieldPtr: | 21185 | case IrInstructionIdStructFieldPtr: |
| 21233 | case IrInstructionIdUnionFieldPtr: | 21186 | case IrInstructionIdUnionFieldPtr: |
| 21234 | case IrInstructionIdArrayType: | 21187 | case IrInstructionIdArrayType: |