| ... | ... | @@ -20551,73 +20551,28 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs |
| 20551 | 20551 | static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 20552 | 20552 | IrInstructionArrayType *array_type_instruction) |
| 20553 | 20553 | { |
| 20554 | | Error err; |
| 20554 | IrInstruction *result = ir_const(ira, &array_type_instruction->base, ira->codegen->builtin_types.entry_type); |
| 20555 | result->value->special = ConstValSpecialLazy; |
| 20556 | |
| 20557 | LazyValueArrayType *lazy_array_type = allocate<LazyValueArrayType>(1, "LazyValueArrayType"); |
| 20558 | lazy_array_type->ira = ira; ira_ref(ira); |
| 20559 | result->value->data.x_lazy = &lazy_array_type->base; |
| 20560 | lazy_array_type->base.id = LazyValueIdArrayType; |
| 20555 | 20561 | |
| 20556 | | IrInstruction *size_value = array_type_instruction->size->child; |
| 20557 | | uint64_t size; |
| 20558 | | if (!ir_resolve_usize(ira, size_value, &size)) |
| 20562 | lazy_array_type->elem_type = array_type_instruction->child_type->child; |
| 20563 | if (ir_resolve_type_lazy(ira, lazy_array_type->elem_type) == nullptr) |
| 20559 | 20564 | return ira->codegen->invalid_instruction; |
| 20560 | 20565 | |
| 20561 | | IrInstruction *child_type_value = array_type_instruction->child_type->child; |
| 20562 | | ZigType *child_type = ir_resolve_type(ira, child_type_value); |
| 20563 | | if (type_is_invalid(child_type)) |
| 20566 | if (!ir_resolve_usize(ira, array_type_instruction->size->child, &lazy_array_type->length)) |
| 20564 | 20567 | return ira->codegen->invalid_instruction; |
| 20565 | 20568 | |
| 20566 | | ZigValue *sentinel_val; |
| 20567 | 20569 | if (array_type_instruction->sentinel != nullptr) { |
| 20568 | | IrInstruction *uncasted_sentinel = array_type_instruction->sentinel->child; |
| 20569 | | if (type_is_invalid(uncasted_sentinel->value->type)) |
| 20570 | | return ira->codegen->invalid_instruction; |
| 20571 | | IrInstruction *sentinel = ir_implicit_cast(ira, uncasted_sentinel, child_type); |
| 20572 | | if (type_is_invalid(sentinel->value->type)) |
| 20573 | | return ira->codegen->invalid_instruction; |
| 20574 | | sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); |
| 20575 | | if (sentinel_val == nullptr) |
| 20570 | lazy_array_type->sentinel = array_type_instruction->sentinel->child; |
| 20571 | if (ir_resolve_const(ira, lazy_array_type->sentinel, LazyOk) == nullptr) |
| 20576 | 20572 | return ira->codegen->invalid_instruction; |
| 20577 | | } else { |
| 20578 | | sentinel_val = nullptr; |
| 20579 | 20573 | } |
| 20580 | 20574 | |
| 20581 | | switch (child_type->id) { |
| 20582 | | case ZigTypeIdInvalid: // handled above |
| 20583 | | zig_unreachable(); |
| 20584 | | case ZigTypeIdUnreachable: |
| 20585 | | case ZigTypeIdUndefined: |
| 20586 | | case ZigTypeIdNull: |
| 20587 | | case ZigTypeIdArgTuple: |
| 20588 | | case ZigTypeIdOpaque: |
| 20589 | | ir_add_error_node(ira, array_type_instruction->base.source_node, |
| 20590 | | buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name))); |
| 20591 | | return ira->codegen->invalid_instruction; |
| 20592 | | case ZigTypeIdMetaType: |
| 20593 | | case ZigTypeIdVoid: |
| 20594 | | case ZigTypeIdBool: |
| 20595 | | case ZigTypeIdInt: |
| 20596 | | case ZigTypeIdFloat: |
| 20597 | | case ZigTypeIdPointer: |
| 20598 | | case ZigTypeIdArray: |
| 20599 | | case ZigTypeIdStruct: |
| 20600 | | case ZigTypeIdComptimeFloat: |
| 20601 | | case ZigTypeIdComptimeInt: |
| 20602 | | case ZigTypeIdEnumLiteral: |
| 20603 | | case ZigTypeIdOptional: |
| 20604 | | case ZigTypeIdErrorUnion: |
| 20605 | | case ZigTypeIdErrorSet: |
| 20606 | | case ZigTypeIdEnum: |
| 20607 | | case ZigTypeIdUnion: |
| 20608 | | case ZigTypeIdFn: |
| 20609 | | case ZigTypeIdBoundFn: |
| 20610 | | case ZigTypeIdVector: |
| 20611 | | case ZigTypeIdFnFrame: |
| 20612 | | case ZigTypeIdAnyFrame: |
| 20613 | | { |
| 20614 | | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown))) |
| 20615 | | return ira->codegen->invalid_instruction; |
| 20616 | | ZigType *result_type = get_array_type(ira->codegen, child_type, size, sentinel_val); |
| 20617 | | return ir_const_type(ira, &array_type_instruction->base, result_type); |
| 20618 | | } |
| 20619 | | } |
| 20620 | | zig_unreachable(); |
| 20575 | return result; |
| 20621 | 20576 | } |
| 20622 | 20577 | |
| 20623 | 20578 | static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructionSizeOf *instruction) { |
| ... | ... | @@ -29016,6 +28971,72 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29016 | 28971 | // We can't free the lazy value here, because multiple other ZigValues might be pointing to it. |
| 29017 | 28972 | return ErrorNone; |
| 29018 | 28973 | } |
| 28974 | case LazyValueIdArrayType: { |
| 28975 | LazyValueArrayType *lazy_array_type = reinterpret_cast<LazyValueArrayType *>(val->data.x_lazy); |
| 28976 | IrAnalyze *ira = lazy_array_type->ira; |
| 28977 | |
| 28978 | ZigType *elem_type = ir_resolve_type(ira, lazy_array_type->elem_type); |
| 28979 | if (type_is_invalid(elem_type)) |
| 28980 | return ErrorSemanticAnalyzeFail; |
| 28981 | |
| 28982 | switch (elem_type->id) { |
| 28983 | case ZigTypeIdInvalid: // handled above |
| 28984 | zig_unreachable(); |
| 28985 | case ZigTypeIdUnreachable: |
| 28986 | case ZigTypeIdUndefined: |
| 28987 | case ZigTypeIdNull: |
| 28988 | case ZigTypeIdArgTuple: |
| 28989 | case ZigTypeIdOpaque: |
| 28990 | ir_add_error(ira, lazy_array_type->elem_type, |
| 28991 | buf_sprintf("array of type '%s' not allowed", |
| 28992 | buf_ptr(&elem_type->name))); |
| 28993 | return ErrorSemanticAnalyzeFail; |
| 28994 | case ZigTypeIdMetaType: |
| 28995 | case ZigTypeIdVoid: |
| 28996 | case ZigTypeIdBool: |
| 28997 | case ZigTypeIdInt: |
| 28998 | case ZigTypeIdFloat: |
| 28999 | case ZigTypeIdPointer: |
| 29000 | case ZigTypeIdArray: |
| 29001 | case ZigTypeIdStruct: |
| 29002 | case ZigTypeIdComptimeFloat: |
| 29003 | case ZigTypeIdComptimeInt: |
| 29004 | case ZigTypeIdEnumLiteral: |
| 29005 | case ZigTypeIdOptional: |
| 29006 | case ZigTypeIdErrorUnion: |
| 29007 | case ZigTypeIdErrorSet: |
| 29008 | case ZigTypeIdEnum: |
| 29009 | case ZigTypeIdUnion: |
| 29010 | case ZigTypeIdFn: |
| 29011 | case ZigTypeIdBoundFn: |
| 29012 | case ZigTypeIdVector: |
| 29013 | case ZigTypeIdFnFrame: |
| 29014 | case ZigTypeIdAnyFrame: |
| 29015 | break; |
| 29016 | } |
| 29017 | |
| 29018 | if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusSizeKnown))) |
| 29019 | return err; |
| 29020 | |
| 29021 | ZigValue *sentinel_val = nullptr; |
| 29022 | if (lazy_array_type->sentinel != nullptr) { |
| 29023 | if (type_is_invalid(lazy_array_type->sentinel->value->type)) |
| 29024 | return ErrorSemanticAnalyzeFail; |
| 29025 | IrInstruction *sentinel = ir_implicit_cast(ira, lazy_array_type->sentinel, elem_type); |
| 29026 | if (type_is_invalid(sentinel->value->type)) |
| 29027 | return ErrorSemanticAnalyzeFail; |
| 29028 | sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); |
| 29029 | if (sentinel_val == nullptr) |
| 29030 | return ErrorSemanticAnalyzeFail; |
| 29031 | } |
| 29032 | |
| 29033 | assert(val->type->id == ZigTypeIdMetaType); |
| 29034 | val->data.x_type = get_array_type(ira->codegen, elem_type, lazy_array_type->length, sentinel_val); |
| 29035 | val->special = ConstValSpecialStatic; |
| 29036 | |
| 29037 | // We can't free the lazy value here, because multiple other ZigValues might be pointing to it. |
| 29038 | return ErrorNone; |
| 29039 | } |
| 29019 | 29040 | case LazyValueIdOptType: { |
| 29020 | 29041 | LazyValueOptType *lazy_opt_type = reinterpret_cast<LazyValueOptType *>(val->data.x_lazy); |
| 29021 | 29042 | IrAnalyze *ira = lazy_opt_type->ira; |