| ... | ... | @@ -8212,6 +8212,7 @@ static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, Ast |
| 8212 | 8212 | { |
| 8213 | 8213 | Error err; |
| 8214 | 8214 | assert(ptr_val->type->id == ZigTypeIdPointer); |
| 8215 | assert(ptr_val->special == ConstValSpecialStatic); |
| 8215 | 8216 | ConstExprValue tmp = {}; |
| 8216 | 8217 | tmp.special = ConstValSpecialStatic; |
| 8217 | 8218 | tmp.type = ptr_val->type->data.pointer.child_type; |
| ... | ... | @@ -16150,51 +16151,21 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source |
| 16150 | 16151 | zig_unreachable(); |
| 16151 | 16152 | } |
| 16152 | 16153 | |
| 16153 | | static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { |
| 16154 | | Error err; |
| 16155 | | IrInstruction *value = un_op_instruction->value->child; |
| 16156 | | ZigType *type_entry = ir_resolve_type(ira, value); |
| 16157 | | if (type_is_invalid(type_entry)) |
| 16158 | | return ira->codegen->invalid_instruction; |
| 16159 | | if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown))) |
| 16160 | | return ira->codegen->invalid_instruction; |
| 16154 | static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 16155 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 16156 | result->value.special = ConstValSpecialLazy; |
| 16161 | 16157 | |
| 16162 | | switch (type_entry->id) { |
| 16163 | | case ZigTypeIdInvalid: |
| 16164 | | zig_unreachable(); |
| 16165 | | case ZigTypeIdMetaType: |
| 16166 | | case ZigTypeIdVoid: |
| 16167 | | case ZigTypeIdBool: |
| 16168 | | case ZigTypeIdInt: |
| 16169 | | case ZigTypeIdVector: |
| 16170 | | case ZigTypeIdFloat: |
| 16171 | | case ZigTypeIdPointer: |
| 16172 | | case ZigTypeIdArray: |
| 16173 | | case ZigTypeIdStruct: |
| 16174 | | case ZigTypeIdComptimeFloat: |
| 16175 | | case ZigTypeIdComptimeInt: |
| 16176 | | case ZigTypeIdEnumLiteral: |
| 16177 | | case ZigTypeIdUndefined: |
| 16178 | | case ZigTypeIdNull: |
| 16179 | | case ZigTypeIdOptional: |
| 16180 | | case ZigTypeIdErrorUnion: |
| 16181 | | case ZigTypeIdErrorSet: |
| 16182 | | case ZigTypeIdEnum: |
| 16183 | | case ZigTypeIdUnion: |
| 16184 | | case ZigTypeIdFn: |
| 16185 | | case ZigTypeIdBoundFn: |
| 16186 | | case ZigTypeIdArgTuple: |
| 16187 | | case ZigTypeIdFnFrame: |
| 16188 | | case ZigTypeIdAnyFrame: |
| 16189 | | return ir_const_type(ira, &un_op_instruction->base, get_optional_type(ira->codegen, type_entry)); |
| 16158 | LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1); |
| 16159 | result->value.data.x_lazy = &lazy_opt_type->base; |
| 16160 | lazy_opt_type->base.id = LazyValueIdOptType; |
| 16161 | lazy_opt_type->base.exec = ira->new_irb.exec; |
| 16190 | 16162 | |
| 16191 | | case ZigTypeIdUnreachable: |
| 16192 | | case ZigTypeIdOpaque: |
| 16193 | | ir_add_error_node(ira, un_op_instruction->base.source_node, |
| 16194 | | buf_sprintf("type '%s' not optional", buf_ptr(&type_entry->name))); |
| 16195 | | return ira->codegen->invalid_instruction; |
| 16196 | | } |
| 16197 | | zig_unreachable(); |
| 16163 | lazy_opt_type->payload_type_val = ir_resolve_type_lazy(ira, instruction->value->child); |
| 16164 | if (lazy_opt_type->payload_type_val == nullptr) |
| 16165 | return ira->codegen->invalid_instruction; |
| 16166 | lazy_opt_type->payload_type_src_node = instruction->value->source_node; |
| 16167 | |
| 16168 | return result; |
| 16198 | 16169 | } |
| 16199 | 16170 | |
| 16200 | 16171 | static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *scalar_type, |
| ... | ... | @@ -19658,11 +19629,9 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig |
| 19658 | 19629 | |
| 19659 | 19630 | ZigVar *var = tld->var; |
| 19660 | 19631 | |
| 19661 | | if ((err = type_resolve(ira->codegen, var->const_value->type, ResolveStatusSizeKnown))) |
| 19662 | | return ira->codegen->builtin_types.entry_invalid; |
| 19663 | | |
| 19664 | 19632 | assert(var->const_value->type->id == ZigTypeIdMetaType); |
| 19665 | | return var->const_value->data.x_type; |
| 19633 | |
| 19634 | return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value); |
| 19666 | 19635 | } |
| 19667 | 19636 | |
| 19668 | 19637 | static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *out_val, |
| ... | ... | @@ -25633,6 +25602,28 @@ static Error ir_resolve_lazy_raw(CodeGen *codegen, AstNode *source_node, ConstEx |
| 25633 | 25602 | val->special = ConstValSpecialStatic; |
| 25634 | 25603 | return ErrorNone; |
| 25635 | 25604 | } |
| 25605 | case LazyValueIdOptType: { |
| 25606 | LazyValueOptType *lazy_opt_type = reinterpret_cast<LazyValueOptType *>(val->data.x_lazy); |
| 25607 | |
| 25608 | ZigType *payload_type = ir_resolve_const_type(codegen, exec, lazy_opt_type->payload_type_src_node, |
| 25609 | lazy_opt_type->payload_type_val); |
| 25610 | if (type_is_invalid(payload_type)) |
| 25611 | return ErrorSemanticAnalyzeFail; |
| 25612 | |
| 25613 | if (payload_type->id == ZigTypeIdOpaque || payload_type->id == ZigTypeIdUnreachable) { |
| 25614 | exec_add_error_node(codegen, exec, lazy_opt_type->payload_type_src_node, |
| 25615 | buf_sprintf("type '%s' cannot be optional", buf_ptr(&payload_type->name))); |
| 25616 | return ErrorSemanticAnalyzeFail; |
| 25617 | } |
| 25618 | |
| 25619 | if ((err = type_resolve(codegen, payload_type, ResolveStatusSizeKnown))) |
| 25620 | return err; |
| 25621 | |
| 25622 | assert(val->type->id == ZigTypeIdMetaType); |
| 25623 | val->data.x_type = get_optional_type(codegen, payload_type); |
| 25624 | val->special = ConstValSpecialStatic; |
| 25625 | return ErrorNone; |
| 25626 | } |
| 25636 | 25627 | case LazyValueIdFnType: { |
| 25637 | 25628 | ZigType *fn_type = ir_resolve_lazy_fn_type(codegen, exec, source_node, |
| 25638 | 25629 | reinterpret_cast<LazyValueFnType *>(val->data.x_lazy)); |