| ... | ... | @@ -11624,61 +11624,6 @@ static TypeTableEntry *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructi |
| 11624 | 11624 | zig_unreachable(); |
| 11625 | 11625 | } |
| 11626 | 11626 | |
| 11627 | | enum VarClassRequired { |
| 11628 | | VarClassRequiredAny, |
| 11629 | | VarClassRequiredConst, |
| 11630 | | VarClassRequiredIllegal, |
| 11631 | | }; |
| 11632 | | |
| 11633 | | static VarClassRequired get_var_class_required(TypeTableEntry *type_entry) { |
| 11634 | | switch (type_entry->id) { |
| 11635 | | case TypeTableEntryIdInvalid: |
| 11636 | | zig_unreachable(); |
| 11637 | | case TypeTableEntryIdUnreachable: |
| 11638 | | return VarClassRequiredIllegal; |
| 11639 | | case TypeTableEntryIdBool: |
| 11640 | | case TypeTableEntryIdInt: |
| 11641 | | case TypeTableEntryIdFloat: |
| 11642 | | case TypeTableEntryIdVoid: |
| 11643 | | case TypeTableEntryIdErrorSet: |
| 11644 | | case TypeTableEntryIdFn: |
| 11645 | | case TypeTableEntryIdPromise: |
| 11646 | | return VarClassRequiredAny; |
| 11647 | | case TypeTableEntryIdComptimeFloat: |
| 11648 | | case TypeTableEntryIdComptimeInt: |
| 11649 | | case TypeTableEntryIdUndefined: |
| 11650 | | case TypeTableEntryIdBlock: |
| 11651 | | case TypeTableEntryIdNull: |
| 11652 | | case TypeTableEntryIdOpaque: |
| 11653 | | case TypeTableEntryIdMetaType: |
| 11654 | | case TypeTableEntryIdNamespace: |
| 11655 | | case TypeTableEntryIdBoundFn: |
| 11656 | | case TypeTableEntryIdArgTuple: |
| 11657 | | return VarClassRequiredConst; |
| 11658 | | |
| 11659 | | case TypeTableEntryIdPointer: |
| 11660 | | if (type_entry->data.pointer.child_type->id == TypeTableEntryIdOpaque) { |
| 11661 | | return VarClassRequiredAny; |
| 11662 | | } else { |
| 11663 | | return get_var_class_required(type_entry->data.pointer.child_type); |
| 11664 | | } |
| 11665 | | case TypeTableEntryIdArray: |
| 11666 | | return get_var_class_required(type_entry->data.array.child_type); |
| 11667 | | case TypeTableEntryIdMaybe: |
| 11668 | | return get_var_class_required(type_entry->data.maybe.child_type); |
| 11669 | | case TypeTableEntryIdErrorUnion: |
| 11670 | | return get_var_class_required(type_entry->data.error_union.payload_type); |
| 11671 | | |
| 11672 | | case TypeTableEntryIdStruct: |
| 11673 | | case TypeTableEntryIdEnum: |
| 11674 | | case TypeTableEntryIdUnion: |
| 11675 | | // TODO check the fields of these things and make sure that they don't recursively |
| 11676 | | // contain any of the other variable classes |
| 11677 | | return VarClassRequiredAny; |
| 11678 | | } |
| 11679 | | zig_unreachable(); |
| 11680 | | } |
| 11681 | | |
| 11682 | 11627 | static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDeclVar *decl_var_instruction) { |
| 11683 | 11628 | VariableTableEntry *var = decl_var_instruction->var; |
| 11684 | 11629 | |
| ... | ... | @@ -11713,36 +11658,41 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 11713 | 11658 | if (type_is_invalid(result_type)) { |
| 11714 | 11659 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 11715 | 11660 | } else { |
| 11716 | | switch (get_var_class_required(result_type)) { |
| 11717 | | case VarClassRequiredIllegal: |
| 11661 | type_ensure_zero_bits_known(ira->codegen, result_type); |
| 11662 | if (type_is_invalid(result_type)) { |
| 11663 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 11664 | } |
| 11665 | } |
| 11666 | |
| 11667 | if (!type_is_invalid(result_type)) { |
| 11668 | if (result_type->id == TypeTableEntryIdUnreachable || |
| 11669 | result_type->id == TypeTableEntryIdOpaque) |
| 11670 | { |
| 11671 | ir_add_error_node(ira, source_node, |
| 11672 | buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name))); |
| 11673 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 11674 | } else if (type_requires_comptime(result_type)) { |
| 11675 | var_class_requires_const = true; |
| 11676 | if (!var->src_is_const && !is_comptime_var) { |
| 11718 | 11677 | ir_add_error_node(ira, source_node, |
| 11719 | | buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name))); |
| 11678 | buf_sprintf("variable of type '%s' must be const or comptime", |
| 11679 | buf_ptr(&result_type->name))); |
| 11720 | 11680 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 11721 | | break; |
| 11722 | | case VarClassRequiredConst: |
| 11681 | } |
| 11682 | } else { |
| 11683 | if (casted_init_value->value.special == ConstValSpecialStatic && |
| 11684 | casted_init_value->value.type->id == TypeTableEntryIdFn && |
| 11685 | casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways) |
| 11686 | { |
| 11723 | 11687 | var_class_requires_const = true; |
| 11724 | 11688 | if (!var->src_is_const && !is_comptime_var) { |
| 11725 | | ir_add_error_node(ira, source_node, |
| 11726 | | buf_sprintf("variable of type '%s' must be const or comptime", |
| 11727 | | buf_ptr(&result_type->name))); |
| 11689 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 11690 | buf_sprintf("functions marked inline must be stored in const or comptime var")); |
| 11691 | AstNode *proto_node = casted_init_value->value.data.x_ptr.data.fn.fn_entry->proto_node; |
| 11692 | add_error_note(ira->codegen, msg, proto_node, buf_sprintf("declared here")); |
| 11728 | 11693 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 11729 | 11694 | } |
| 11730 | | break; |
| 11731 | | case VarClassRequiredAny: |
| 11732 | | if (casted_init_value->value.special == ConstValSpecialStatic && |
| 11733 | | casted_init_value->value.type->id == TypeTableEntryIdFn && |
| 11734 | | casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways) |
| 11735 | | { |
| 11736 | | var_class_requires_const = true; |
| 11737 | | if (!var->src_is_const && !is_comptime_var) { |
| 11738 | | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 11739 | | buf_sprintf("functions marked inline must be stored in const or comptime var")); |
| 11740 | | AstNode *proto_node = casted_init_value->value.data.x_ptr.data.fn.fn_entry->proto_node; |
| 11741 | | add_error_note(ira->codegen, msg, proto_node, buf_sprintf("declared here")); |
| 11742 | | result_type = ira->codegen->builtin_types.entry_invalid; |
| 11743 | | } |
| 11744 | | } |
| 11745 | | break; |
| 11695 | } |
| 11746 | 11696 | } |
| 11747 | 11697 | } |
| 11748 | 11698 | |
| ... | ... | @@ -12623,6 +12573,10 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 12623 | 12573 | inst_fn_type_id.return_type = specified_return_type; |
| 12624 | 12574 | } |
| 12625 | 12575 | |
| 12576 | type_ensure_zero_bits_known(ira->codegen, specified_return_type); |
| 12577 | if (type_is_invalid(specified_return_type)) |
| 12578 | return ira->codegen->builtin_types.entry_invalid; |
| 12579 | |
| 12626 | 12580 | if (type_requires_comptime(specified_return_type)) { |
| 12627 | 12581 | // Throw out our work and call the function as if it were comptime. |
| 12628 | 12582 | return ir_analyze_fn_call(ira, call_instruction, fn_entry, fn_type, fn_ref, first_arg_ptr, true, FnInlineAuto); |