| ... | @@ -33,7 +33,7 @@ struct IrAnalyze { | ... | @@ -33,7 +33,7 @@ struct IrAnalyze { |
| 33 | IrExecContext exec_context; | 33 | IrExecContext exec_context; |
| 34 | size_t old_bb_index; | 34 | size_t old_bb_index; |
| 35 | size_t instruction_index; | 35 | size_t instruction_index; |
| 36 | TypeTableEntry *explicit_return_type; | 36 | ZigType *explicit_return_type; |
| 37 | ZigList<IrInstruction *> src_implicit_return_type_list; | 37 | ZigList<IrInstruction *> src_implicit_return_type_list; |
| 38 | IrBasicBlock *const_predecessor_bb; | 38 | IrBasicBlock *const_predecessor_bb; |
| 39 | }; | 39 | }; |
| ... | @@ -99,38 +99,38 @@ struct ConstCastOnly { | ... | @@ -99,38 +99,38 @@ struct ConstCastOnly { |
| 99 | }; | 99 | }; |
| 100 | | 100 | |
| 101 | struct ConstCastTypeMismatch { | 101 | struct ConstCastTypeMismatch { |
| 102 | TypeTableEntry *wanted_type; | 102 | ZigType *wanted_type; |
| 103 | TypeTableEntry *actual_type; | 103 | ZigType *actual_type; |
| 104 | }; | 104 | }; |
| 105 | | 105 | |
| 106 | struct ConstCastOptionalMismatch { | 106 | struct ConstCastOptionalMismatch { |
| 107 | ConstCastOnly child; | 107 | ConstCastOnly child; |
| 108 | TypeTableEntry *wanted_child; | 108 | ZigType *wanted_child; |
| 109 | TypeTableEntry *actual_child; | 109 | ZigType *actual_child; |
| 110 | }; | 110 | }; |
| 111 | | 111 | |
| 112 | struct ConstCastPointerMismatch { | 112 | struct ConstCastPointerMismatch { |
| 113 | ConstCastOnly child; | 113 | ConstCastOnly child; |
| 114 | TypeTableEntry *wanted_child; | 114 | ZigType *wanted_child; |
| 115 | TypeTableEntry *actual_child; | 115 | ZigType *actual_child; |
| 116 | }; | 116 | }; |
| 117 | | 117 | |
| 118 | struct ConstCastSliceMismatch { | 118 | struct ConstCastSliceMismatch { |
| 119 | ConstCastOnly child; | 119 | ConstCastOnly child; |
| 120 | TypeTableEntry *wanted_child; | 120 | ZigType *wanted_child; |
| 121 | TypeTableEntry *actual_child; | 121 | ZigType *actual_child; |
| 122 | }; | 122 | }; |
| 123 | | 123 | |
| 124 | struct ConstCastErrUnionErrSetMismatch { | 124 | struct ConstCastErrUnionErrSetMismatch { |
| 125 | ConstCastOnly child; | 125 | ConstCastOnly child; |
| 126 | TypeTableEntry *wanted_err_set; | 126 | ZigType *wanted_err_set; |
| 127 | TypeTableEntry *actual_err_set; | 127 | ZigType *actual_err_set; |
| 128 | }; | 128 | }; |
| 129 | | 129 | |
| 130 | struct ConstCastErrUnionPayloadMismatch { | 130 | struct ConstCastErrUnionPayloadMismatch { |
| 131 | ConstCastOnly child; | 131 | ConstCastOnly child; |
| 132 | TypeTableEntry *wanted_payload; | 132 | ZigType *wanted_payload; |
| 133 | TypeTableEntry *actual_payload; | 133 | ZigType *actual_payload; |
| 134 | }; | 134 | }; |
| 135 | | 135 | |
| 136 | struct ConstCastErrSetMismatch { | 136 | struct ConstCastErrSetMismatch { |
| ... | @@ -139,19 +139,21 @@ struct ConstCastErrSetMismatch { | ... | @@ -139,19 +139,21 @@ struct ConstCastErrSetMismatch { |
| 139 | | 139 | |
| 140 | static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope); | 140 | static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope); |
| 141 | static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval); | 141 | static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval); |
| 142 | static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction); | 142 | static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction); |
| 143 | static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type); | 143 | static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type); |
| 144 | static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr); | 144 | static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr); |
| 145 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg); | 145 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg); |
| 146 | static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, | 146 | static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 147 | IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type); | 147 | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type); |
| 148 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var); | 148 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var); |
| 149 | static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op); | 149 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op); |
| 150 | static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval); | 150 | static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval); |
| 151 | static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, uint32_t new_align); | 151 | static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align); |
| 152 | static TypeTableEntry *adjust_slice_align(CodeGen *g, TypeTableEntry *slice_type, uint32_t new_align); | 152 | static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align); |
| | 153 | static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val); |
| | 154 | static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val); |
| 153 | | 155 | |
| 154 | ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) { | 156 | static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) { |
| 155 | assert(get_codegen_ptr_type(const_val->type) != nullptr); | 157 | assert(get_codegen_ptr_type(const_val->type) != nullptr); |
| 156 | assert(const_val->special == ConstValSpecialStatic); | 158 | assert(const_val->special == ConstValSpecialStatic); |
| 157 | ConstExprValue *result; | 159 | ConstExprValue *result; |
| ... | @@ -181,6 +183,27 @@ ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) { | ... | @@ -181,6 +183,27 @@ ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) { |
| 181 | return result; | 183 | return result; |
| 182 | } | 184 | } |
| 183 | | 185 | |
| | 186 | static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) { |
| | 187 | if (a == b) |
| | 188 | return true; |
| | 189 | |
| | 190 | if (a->id == b->id) |
| | 191 | return true; |
| | 192 | |
| | 193 | if (get_codegen_ptr_type(a) != nullptr && get_codegen_ptr_type(b) != nullptr) |
| | 194 | return true; |
| | 195 | |
| | 196 | return false; |
| | 197 | } |
| | 198 | |
| | 199 | ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) { |
| | 200 | ConstExprValue *result = const_ptr_pointee_unchecked(g, const_val); |
| | 201 | if (const_val->type->id == ZigTypeIdPointer) { |
| | 202 | assert(types_have_same_zig_comptime_repr(const_val->type->data.pointer.child_type, result->type)); |
| | 203 | } |
| | 204 | return result; |
| | 205 | } |
| | 206 | |
| 184 | static bool ir_should_inline(IrExecutable *exec, Scope *scope) { | 207 | static bool ir_should_inline(IrExecutable *exec, Scope *scope) { |
| 185 | if (exec->is_inline) | 208 | if (exec->is_inline) |
| 186 | return true; | 209 | return true; |
| ... | @@ -213,7 +236,7 @@ static size_t exec_next_mem_slot(IrExecutable *exec) { | ... | @@ -213,7 +236,7 @@ static size_t exec_next_mem_slot(IrExecutable *exec) { |
| 213 | return result; | 236 | return result; |
| 214 | } | 237 | } |
| 215 | | 238 | |
| 216 | static FnTableEntry *exec_fn_entry(IrExecutable *exec) { | 239 | static ZigFn *exec_fn_entry(IrExecutable *exec) { |
| 217 | return exec->fn_entry; | 240 | return exec->fn_entry; |
| 218 | } | 241 | } |
| 219 | | 242 | |
| ... | @@ -230,7 +253,7 @@ static bool instr_is_comptime(IrInstruction *instruction) { | ... | @@ -230,7 +253,7 @@ static bool instr_is_comptime(IrInstruction *instruction) { |
| 230 | } | 253 | } |
| 231 | | 254 | |
| 232 | static bool instr_is_unreachable(IrInstruction *instruction) { | 255 | static bool instr_is_unreachable(IrInstruction *instruction) { |
| 233 | return instruction->value.type && instruction->value.type->id == TypeTableEntryIdUnreachable; | 256 | return instruction->value.type && instruction->value.type->id == ZigTypeIdUnreachable; |
| 234 | } | 257 | } |
| 235 | | 258 | |
| 236 | static void ir_link_new_instruction(IrInstruction *new_instruction, IrInstruction *old_instruction) { | 259 | static void ir_link_new_instruction(IrInstruction *new_instruction, IrInstruction *old_instruction) { |
| ... | @@ -254,7 +277,7 @@ static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb) | ... | @@ -254,7 +277,7 @@ static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb) |
| 254 | ir_ref_bb(instruction->owner_bb); | 277 | ir_ref_bb(instruction->owner_bb); |
| 255 | } | 278 | } |
| 256 | | 279 | |
| 257 | static void ir_ref_var(VariableTableEntry *var) { | 280 | static void ir_ref_var(ZigVar *var) { |
| 258 | var->ref_count += 1; | 281 | var->ref_count += 1; |
| 259 | } | 282 | } |
| 260 | | 283 | |
| ... | @@ -832,6 +855,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionSqrt *) { | ... | @@ -832,6 +855,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionSqrt *) { |
| 832 | return IrInstructionIdSqrt; | 855 | return IrInstructionIdSqrt; |
| 833 | } | 856 | } |
| 834 | | 857 | |
| | 858 | static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckRuntimeScope *) { |
| | 859 | return IrInstructionIdCheckRuntimeScope; |
| | 860 | } |
| | 861 | |
| 835 | template<typename T> | 862 | template<typename T> |
| 836 | static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { | 863 | static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 837 | T *special_instruction = allocate<T>(1); | 864 | T *special_instruction = allocate<T>(1); |
| ... | @@ -851,7 +878,7 @@ static T *ir_build_instruction(IrBuilder *irb, Scope *scope, AstNode *source_nod | ... | @@ -851,7 +878,7 @@ static T *ir_build_instruction(IrBuilder *irb, Scope *scope, AstNode *source_nod |
| 851 | return special_instruction; | 878 | return special_instruction; |
| 852 | } | 879 | } |
| 853 | | 880 | |
| 854 | static IrInstruction *ir_build_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, TypeTableEntry *dest_type, | 881 | static IrInstruction *ir_build_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *dest_type, |
| 855 | IrInstruction *value, CastOp cast_op) | 882 | IrInstruction *value, CastOp cast_op) |
| 856 | { | 883 | { |
| 857 | IrInstructionCast *cast_instruction = ir_build_instruction<IrInstructionCast>(irb, scope, source_node); | 884 | IrInstructionCast *cast_instruction = ir_build_instruction<IrInstructionCast>(irb, scope, source_node); |
| ... | @@ -904,7 +931,7 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou | ... | @@ -904,7 +931,7 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou |
| 904 | } | 931 | } |
| 905 | | 932 | |
| 906 | static IrInstruction *ir_create_const(IrBuilder *irb, Scope *scope, AstNode *source_node, | 933 | static IrInstruction *ir_create_const(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 907 | TypeTableEntry *type_entry) | 934 | ZigType *type_entry) |
| 908 | { | 935 | { |
| 909 | assert(type_entry); | 936 | assert(type_entry); |
| 910 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); | 937 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); |
| ... | @@ -975,7 +1002,7 @@ static IrInstruction *ir_build_const_u8(IrBuilder *irb, Scope *scope, AstNode *s | ... | @@ -975,7 +1002,7 @@ static IrInstruction *ir_build_const_u8(IrBuilder *irb, Scope *scope, AstNode *s |
| 975 | } | 1002 | } |
| 976 | | 1003 | |
| 977 | static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node, | 1004 | static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 978 | TypeTableEntry *type_entry) | 1005 | ZigType *type_entry) |
| 979 | { | 1006 | { |
| 980 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); | 1007 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); |
| 981 | const_instruction->base.value.type = irb->codegen->builtin_types.entry_type; | 1008 | const_instruction->base.value.type = irb->codegen->builtin_types.entry_type; |
| ... | @@ -985,14 +1012,14 @@ static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -985,14 +1012,14 @@ static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode |
| 985 | } | 1012 | } |
| 986 | | 1013 | |
| 987 | static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node, | 1014 | static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 988 | TypeTableEntry *type_entry) | 1015 | ZigType *type_entry) |
| 989 | { | 1016 | { |
| 990 | IrInstruction *instruction = ir_create_const_type(irb, scope, source_node, type_entry); | 1017 | IrInstruction *instruction = ir_create_const_type(irb, scope, source_node, type_entry); |
| 991 | ir_instruction_append(irb->current_basic_block, instruction); | 1018 | ir_instruction_append(irb->current_basic_block, instruction); |
| 992 | return instruction; | 1019 | return instruction; |
| 993 | } | 1020 | } |
| 994 | | 1021 | |
| 995 | static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, FnTableEntry *fn_entry) { | 1022 | static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) { |
| 996 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); | 1023 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); |
| 997 | const_instruction->base.value.type = fn_entry->type_entry; | 1024 | const_instruction->base.value.type = fn_entry->type_entry; |
| 998 | const_instruction->base.value.special = ConstValSpecialStatic; | 1025 | const_instruction->base.value.special = ConstValSpecialStatic; |
| ... | @@ -1002,7 +1029,7 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -1002,7 +1029,7 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode * |
| 1002 | return &const_instruction->base; | 1029 | return &const_instruction->base; |
| 1003 | } | 1030 | } |
| 1004 | | 1031 | |
| 1005 | static IrInstruction *ir_build_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, FnTableEntry *fn_entry) { | 1032 | static IrInstruction *ir_build_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) { |
| 1006 | IrInstruction *instruction = ir_create_const_fn(irb, scope, source_node, fn_entry); | 1033 | IrInstruction *instruction = ir_create_const_fn(irb, scope, source_node, fn_entry); |
| 1007 | ir_instruction_append(irb->current_basic_block, instruction); | 1034 | ir_instruction_append(irb->current_basic_block, instruction); |
| 1008 | return instruction; | 1035 | return instruction; |
| ... | @@ -1035,7 +1062,7 @@ static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -1035,7 +1062,7 @@ static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode |
| 1035 | } | 1062 | } |
| 1036 | | 1063 | |
| 1037 | static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, | 1064 | static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1038 | FnTableEntry *fn_entry, IrInstruction *first_arg) | 1065 | ZigFn *fn_entry, IrInstruction *first_arg) |
| 1039 | { | 1066 | { |
| 1040 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); | 1067 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1041 | const_instruction->base.value.type = get_bound_fn_type(irb->codegen, fn_entry); | 1068 | const_instruction->base.value.type = get_bound_fn_type(irb->codegen, fn_entry); |
| ... | @@ -1087,15 +1114,22 @@ static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_in | ... | @@ -1087,15 +1114,22 @@ static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_in |
| 1087 | return new_instruction; | 1114 | return new_instruction; |
| 1088 | } | 1115 | } |
| 1089 | | 1116 | |
| 1090 | static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, VariableTableEntry *var) { | 1117 | static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var, |
| | 1118 | ScopeFnDef *crossed_fndef_scope) |
| | 1119 | { |
| 1091 | IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node); | 1120 | IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node); |
| 1092 | instruction->var = var; | 1121 | instruction->var = var; |
| | 1122 | instruction->crossed_fndef_scope = crossed_fndef_scope; |
| 1093 | | 1123 | |
| 1094 | ir_ref_var(var); | 1124 | ir_ref_var(var); |
| 1095 | | 1125 | |
| 1096 | return &instruction->base; | 1126 | return &instruction->base; |
| 1097 | } | 1127 | } |
| 1098 | | 1128 | |
| | 1129 | static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var) { |
| | 1130 | return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr); |
| | 1131 | } |
| | 1132 | |
| 1099 | static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *array_ptr, | 1133 | static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *array_ptr, |
| 1100 | IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len) | 1134 | IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len) |
| 1101 | { | 1135 | { |
| ... | @@ -1172,7 +1206,7 @@ static IrInstruction *ir_build_union_field_ptr_from(IrBuilder *irb, IrInstructio | ... | @@ -1172,7 +1206,7 @@ static IrInstruction *ir_build_union_field_ptr_from(IrBuilder *irb, IrInstructio |
| 1172 | } | 1206 | } |
| 1173 | | 1207 | |
| 1174 | static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *source_node, | 1208 | static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1175 | FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, | 1209 | ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, |
| 1176 | bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator, | 1210 | bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator, |
| 1177 | IrInstruction *new_stack) | 1211 | IrInstruction *new_stack) |
| 1178 | { | 1212 | { |
| ... | @@ -1200,7 +1234,7 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc | ... | @@ -1200,7 +1234,7 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc |
| 1200 | } | 1234 | } |
| 1201 | | 1235 | |
| 1202 | static IrInstruction *ir_build_call_from(IrBuilder *irb, IrInstruction *old_instruction, | 1236 | static IrInstruction *ir_build_call_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1203 | FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, | 1237 | ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, |
| 1204 | bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator, | 1238 | bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator, |
| 1205 | IrInstruction *new_stack) | 1239 | IrInstruction *new_stack) |
| 1206 | { | 1240 | { |
| ... | @@ -1349,7 +1383,7 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop | ... | @@ -1349,7 +1383,7 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop |
| 1349 | } | 1383 | } |
| 1350 | | 1384 | |
| 1351 | static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode *source_node, | 1385 | static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1352 | TypeTableEntry *struct_type, size_t field_count, IrInstructionStructInitField *fields) | 1386 | ZigType *struct_type, size_t field_count, IrInstructionStructInitField *fields) |
| 1353 | { | 1387 | { |
| 1354 | IrInstructionStructInit *struct_init_instruction = ir_build_instruction<IrInstructionStructInit>(irb, scope, source_node); | 1388 | IrInstructionStructInit *struct_init_instruction = ir_build_instruction<IrInstructionStructInit>(irb, scope, source_node); |
| 1355 | struct_init_instruction->struct_type = struct_type; | 1389 | struct_init_instruction->struct_type = struct_type; |
| ... | @@ -1363,7 +1397,7 @@ static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -1363,7 +1397,7 @@ static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode |
| 1363 | } | 1397 | } |
| 1364 | | 1398 | |
| 1365 | static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *old_instruction, | 1399 | static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1366 | TypeTableEntry *struct_type, size_t field_count, IrInstructionStructInitField *fields) | 1400 | ZigType *struct_type, size_t field_count, IrInstructionStructInitField *fields) |
| 1367 | { | 1401 | { |
| 1368 | IrInstruction *new_instruction = ir_build_struct_init(irb, old_instruction->scope, | 1402 | IrInstruction *new_instruction = ir_build_struct_init(irb, old_instruction->scope, |
| 1369 | old_instruction->source_node, struct_type, field_count, fields); | 1403 | old_instruction->source_node, struct_type, field_count, fields); |
| ... | @@ -1372,7 +1406,7 @@ static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *o | ... | @@ -1372,7 +1406,7 @@ static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *o |
| 1372 | } | 1406 | } |
| 1373 | | 1407 | |
| 1374 | static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode *source_node, | 1408 | static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1375 | TypeTableEntry *union_type, TypeUnionField *field, IrInstruction *init_value) | 1409 | ZigType *union_type, TypeUnionField *field, IrInstruction *init_value) |
| 1376 | { | 1410 | { |
| 1377 | IrInstructionUnionInit *union_init_instruction = ir_build_instruction<IrInstructionUnionInit>(irb, scope, source_node); | 1411 | IrInstructionUnionInit *union_init_instruction = ir_build_instruction<IrInstructionUnionInit>(irb, scope, source_node); |
| 1378 | union_init_instruction->union_type = union_type; | 1412 | union_init_instruction->union_type = union_type; |
| ... | @@ -1385,7 +1419,7 @@ static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -1385,7 +1419,7 @@ static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode |
| 1385 | } | 1419 | } |
| 1386 | | 1420 | |
| 1387 | static IrInstruction *ir_build_union_init_from(IrBuilder *irb, IrInstruction *old_instruction, | 1421 | static IrInstruction *ir_build_union_init_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1388 | TypeTableEntry *union_type, TypeUnionField *field, IrInstruction *init_value) | 1422 | ZigType *union_type, TypeUnionField *field, IrInstruction *init_value) |
| 1389 | { | 1423 | { |
| 1390 | IrInstruction *new_instruction = ir_build_union_init(irb, old_instruction->scope, | 1424 | IrInstruction *new_instruction = ir_build_union_init(irb, old_instruction->scope, |
| 1391 | old_instruction->source_node, union_type, field, init_value); | 1425 | old_instruction->source_node, union_type, field, init_value); |
| ... | @@ -1432,7 +1466,7 @@ static IrInstruction *ir_build_store_ptr_from(IrBuilder *irb, IrInstruction *old | ... | @@ -1432,7 +1466,7 @@ static IrInstruction *ir_build_store_ptr_from(IrBuilder *irb, IrInstruction *old |
| 1432 | } | 1466 | } |
| 1433 | | 1467 | |
| 1434 | static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *source_node, | 1468 | static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1435 | VariableTableEntry *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value) | 1469 | ZigVar *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value) |
| 1436 | { | 1470 | { |
| 1437 | IrInstructionDeclVar *decl_var_instruction = ir_build_instruction<IrInstructionDeclVar>(irb, scope, source_node); | 1471 | IrInstructionDeclVar *decl_var_instruction = ir_build_instruction<IrInstructionDeclVar>(irb, scope, source_node); |
| 1438 | decl_var_instruction->base.value.special = ConstValSpecialStatic; | 1472 | decl_var_instruction->base.value.special = ConstValSpecialStatic; |
| ... | @@ -1450,7 +1484,7 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *s | ... | @@ -1450,7 +1484,7 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *s |
| 1450 | } | 1484 | } |
| 1451 | | 1485 | |
| 1452 | static IrInstruction *ir_build_var_decl_from(IrBuilder *irb, IrInstruction *old_instruction, | 1486 | static IrInstruction *ir_build_var_decl_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1453 | VariableTableEntry *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value) | 1487 | ZigVar *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value) |
| 1454 | { | 1488 | { |
| 1455 | IrInstruction *new_instruction = ir_build_var_decl(irb, old_instruction->scope, | 1489 | IrInstruction *new_instruction = ir_build_var_decl(irb, old_instruction->scope, |
| 1456 | old_instruction->source_node, var, var_type, align_value, init_value); | 1490 | old_instruction->source_node, var, var_type, align_value, init_value); |
| ... | @@ -1595,7 +1629,7 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -1595,7 +1629,7 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode |
| 1595 | } | 1629 | } |
| 1596 | | 1630 | |
| 1597 | static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction **input_list, | 1631 | static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction **input_list, |
| 1598 | IrInstruction **output_types, VariableTableEntry **output_vars, size_t return_count, bool has_side_effects) | 1632 | IrInstruction **output_types, ZigVar **output_vars, size_t return_count, bool has_side_effects) |
| 1599 | { | 1633 | { |
| 1600 | IrInstructionAsm *instruction = ir_build_instruction<IrInstructionAsm>(irb, scope, source_node); | 1634 | IrInstructionAsm *instruction = ir_build_instruction<IrInstructionAsm>(irb, scope, source_node); |
| 1601 | instruction->input_list = input_list; | 1635 | instruction->input_list = input_list; |
| ... | @@ -1619,7 +1653,7 @@ static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source | ... | @@ -1619,7 +1653,7 @@ static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source |
| 1619 | } | 1653 | } |
| 1620 | | 1654 | |
| 1621 | static IrInstruction *ir_build_asm_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction **input_list, | 1655 | static IrInstruction *ir_build_asm_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction **input_list, |
| 1622 | IrInstruction **output_types, VariableTableEntry **output_vars, size_t return_count, bool has_side_effects) | 1656 | IrInstruction **output_types, ZigVar **output_vars, size_t return_count, bool has_side_effects) |
| 1623 | { | 1657 | { |
| 1624 | IrInstruction *new_instruction = ir_build_asm(irb, old_instruction->scope, | 1658 | IrInstruction *new_instruction = ir_build_asm(irb, old_instruction->scope, |
| 1625 | old_instruction->source_node, input_list, output_types, output_vars, return_count, has_side_effects); | 1659 | old_instruction->source_node, input_list, output_types, output_vars, return_count, has_side_effects); |
| ... | @@ -1946,7 +1980,7 @@ static IrInstruction *ir_build_cmpxchg(IrBuilder *irb, Scope *scope, AstNode *so | ... | @@ -1946,7 +1980,7 @@ static IrInstruction *ir_build_cmpxchg(IrBuilder *irb, Scope *scope, AstNode *so |
| 1946 | IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value, | 1980 | IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value, |
| 1947 | IrInstruction *success_order_value, IrInstruction *failure_order_value, | 1981 | IrInstruction *success_order_value, IrInstruction *failure_order_value, |
| 1948 | bool is_weak, | 1982 | bool is_weak, |
| 1949 | TypeTableEntry *type, AtomicOrder success_order, AtomicOrder failure_order) | 1983 | ZigType *type, AtomicOrder success_order, AtomicOrder failure_order) |
| 1950 | { | 1984 | { |
| 1951 | IrInstructionCmpxchg *instruction = ir_build_instruction<IrInstructionCmpxchg>(irb, scope, source_node); | 1985 | IrInstructionCmpxchg *instruction = ir_build_instruction<IrInstructionCmpxchg>(irb, scope, source_node); |
| 1952 | instruction->type_value = type_value; | 1986 | instruction->type_value = type_value; |
| ... | @@ -2259,7 +2293,7 @@ static IrInstruction *ir_build_handle_from(IrBuilder *irb, IrInstruction *old_in | ... | @@ -2259,7 +2293,7 @@ static IrInstruction *ir_build_handle_from(IrBuilder *irb, IrInstruction *old_in |
| 2259 | | 2293 | |
| 2260 | static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode *source_node, | 2294 | static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2261 | IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2, | 2295 | IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2, |
| 2262 | IrInstruction *result_ptr, TypeTableEntry *result_ptr_type) | 2296 | IrInstruction *result_ptr, ZigType *result_ptr_type) |
| 2263 | { | 2297 | { |
| 2264 | IrInstructionOverflowOp *instruction = ir_build_instruction<IrInstructionOverflowOp>(irb, scope, source_node); | 2298 | IrInstructionOverflowOp *instruction = ir_build_instruction<IrInstructionOverflowOp>(irb, scope, source_node); |
| 2265 | instruction->op = op; | 2299 | instruction->op = op; |
| ... | @@ -2279,7 +2313,7 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -2279,7 +2313,7 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode |
| 2279 | | 2313 | |
| 2280 | static IrInstruction *ir_build_overflow_op_from(IrBuilder *irb, IrInstruction *old_instruction, | 2314 | static IrInstruction *ir_build_overflow_op_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 2281 | IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2, | 2315 | IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2, |
| 2282 | IrInstruction *result_ptr, TypeTableEntry *result_ptr_type) | 2316 | IrInstruction *result_ptr, ZigType *result_ptr_type) |
| 2283 | { | 2317 | { |
| 2284 | IrInstruction *new_instruction = ir_build_overflow_op(irb, old_instruction->scope, old_instruction->source_node, | 2318 | IrInstruction *new_instruction = ir_build_overflow_op(irb, old_instruction->scope, old_instruction->source_node, |
| 2285 | op, type_value, op1, op2, result_ptr, result_ptr_type); | 2319 | op, type_value, op1, op2, result_ptr, result_ptr_type); |
| ... | @@ -2974,6 +3008,17 @@ static IrInstruction *ir_build_sqrt(IrBuilder *irb, Scope *scope, AstNode *sourc | ... | @@ -2974,6 +3008,17 @@ static IrInstruction *ir_build_sqrt(IrBuilder *irb, Scope *scope, AstNode *sourc |
| 2974 | return &instruction->base; | 3008 | return &instruction->base; |
| 2975 | } | 3009 | } |
| 2976 | | 3010 | |
| | 3011 | static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *scope_is_comptime, IrInstruction *is_comptime) { |
| | 3012 | IrInstructionCheckRuntimeScope *instruction = ir_build_instruction<IrInstructionCheckRuntimeScope>(irb, scope, source_node); |
| | 3013 | instruction->scope_is_comptime = scope_is_comptime; |
| | 3014 | instruction->is_comptime = is_comptime; |
| | 3015 | |
| | 3016 | ir_ref_instruction(scope_is_comptime, irb->current_basic_block); |
| | 3017 | ir_ref_instruction(is_comptime, irb->current_basic_block); |
| | 3018 | |
| | 3019 | return &instruction->base; |
| | 3020 | } |
| | 3021 | |
| 2977 | static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) { | 3022 | static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) { |
| 2978 | results[ReturnKindUnconditional] = 0; | 3023 | results[ReturnKindUnconditional] = 0; |
| 2979 | results[ReturnKindError] = 0; | 3024 | results[ReturnKindError] = 0; |
| ... | @@ -2999,6 +3044,7 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco | ... | @@ -2999,6 +3044,7 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco |
| 2999 | case ScopeIdLoop: | 3044 | case ScopeIdLoop: |
| 3000 | case ScopeIdSuspend: | 3045 | case ScopeIdSuspend: |
| 3001 | case ScopeIdCompTime: | 3046 | case ScopeIdCompTime: |
| | 3047 | case ScopeIdRuntime: |
| 3002 | scope = scope->parent; | 3048 | scope = scope->parent; |
| 3003 | continue; | 3049 | continue; |
| 3004 | case ScopeIdDeferExpr: | 3050 | case ScopeIdDeferExpr: |
| ... | @@ -3033,7 +3079,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o | ... | @@ -3033,7 +3079,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o |
| 3033 | Scope *defer_expr_scope = defer_node->data.defer.expr_scope; | 3079 | Scope *defer_expr_scope = defer_node->data.defer.expr_scope; |
| 3034 | IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope); | 3080 | IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope); |
| 3035 | if (defer_expr_value != irb->codegen->invalid_instruction) { | 3081 | if (defer_expr_value != irb->codegen->invalid_instruction) { |
| 3036 | if (defer_expr_value->value.type != nullptr && defer_expr_value->value.type->id == TypeTableEntryIdUnreachable) { | 3082 | if (defer_expr_value->value.type != nullptr && defer_expr_value->value.type->id == ZigTypeIdUnreachable) { |
| 3037 | is_noreturn = true; | 3083 | is_noreturn = true; |
| 3038 | } else { | 3084 | } else { |
| 3039 | ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node, defer_expr_value)); | 3085 | ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node, defer_expr_value)); |
| ... | @@ -3051,6 +3097,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o | ... | @@ -3051,6 +3097,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o |
| 3051 | case ScopeIdLoop: | 3097 | case ScopeIdLoop: |
| 3052 | case ScopeIdSuspend: | 3098 | case ScopeIdSuspend: |
| 3053 | case ScopeIdCompTime: | 3099 | case ScopeIdCompTime: |
| | 3100 | case ScopeIdRuntime: |
| 3054 | scope = scope->parent; | 3101 | scope = scope->parent; |
| 3055 | continue; | 3102 | continue; |
| 3056 | case ScopeIdDeferExpr: | 3103 | case ScopeIdDeferExpr: |
| ... | @@ -3098,7 +3145,7 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) { | ... | @@ -3098,7 +3145,7 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) { |
| 3098 | } | 3145 | } |
| 3099 | | 3146 | |
| 3100 | static bool exec_is_async(IrExecutable *exec) { | 3147 | static bool exec_is_async(IrExecutable *exec) { |
| 3101 | FnTableEntry *fn_entry = exec_fn_entry(exec); | 3148 | ZigFn *fn_entry = exec_fn_entry(exec); |
| 3102 | return fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync; | 3149 | return fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync; |
| 3103 | } | 3150 | } |
| 3104 | | 3151 | |
| ... | @@ -3160,7 +3207,7 @@ static IrInstruction *ir_gen_async_return(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -3160,7 +3207,7 @@ static IrInstruction *ir_gen_async_return(IrBuilder *irb, Scope *scope, AstNode |
| 3160 | static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) { | 3207 | static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) { |
| 3161 | assert(node->type == NodeTypeReturnExpr); | 3208 | assert(node->type == NodeTypeReturnExpr); |
| 3162 | | 3209 | |
| 3163 | FnTableEntry *fn_entry = exec_fn_entry(irb->exec); | 3210 | ZigFn *fn_entry = exec_fn_entry(irb->exec); |
| 3164 | if (!fn_entry) { | 3211 | if (!fn_entry) { |
| 3165 | add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition")); | 3212 | add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition")); |
| 3166 | return irb->codegen->invalid_instruction; | 3213 | return irb->codegen->invalid_instruction; |
| ... | @@ -3184,7 +3231,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, | ... | @@ -3184,7 +3231,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3184 | IrInstruction *return_value; | 3231 | IrInstruction *return_value; |
| 3185 | if (expr_node) { | 3232 | if (expr_node) { |
| 3186 | // Temporarily set this so that if we return a type it gets the name of the function | 3233 | // Temporarily set this so that if we return a type it gets the name of the function |
| 3187 | FnTableEntry *prev_name_fn = irb->exec->name_fn; | 3234 | ZigFn *prev_name_fn = irb->exec->name_fn; |
| 3188 | irb->exec->name_fn = exec_fn_entry(irb->exec); | 3235 | irb->exec->name_fn = exec_fn_entry(irb->exec); |
| 3189 | return_value = ir_gen_node(irb, expr_node, scope); | 3236 | return_value = ir_gen_node(irb, expr_node, scope); |
| 3190 | irb->exec->name_fn = prev_name_fn; | 3237 | irb->exec->name_fn = prev_name_fn; |
| ... | @@ -3280,11 +3327,11 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, | ... | @@ -3280,11 +3327,11 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3280 | zig_unreachable(); | 3327 | zig_unreachable(); |
| 3281 | } | 3328 | } |
| 3282 | | 3329 | |
| 3283 | static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope, | 3330 | static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope, |
| 3284 | Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime, | 3331 | Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime, |
| 3285 | bool skip_name_check) | 3332 | bool skip_name_check) |
| 3286 | { | 3333 | { |
| 3287 | VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1); | 3334 | ZigVar *variable_entry = allocate<ZigVar>(1); |
| 3288 | variable_entry->parent_scope = parent_scope; | 3335 | variable_entry->parent_scope = parent_scope; |
| 3289 | variable_entry->shadowable = is_shadowable; | 3336 | variable_entry->shadowable = is_shadowable; |
| 3290 | variable_entry->mem_slot_index = SIZE_MAX; | 3337 | variable_entry->mem_slot_index = SIZE_MAX; |
| ... | @@ -3296,14 +3343,14 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco | ... | @@ -3296,14 +3343,14 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco |
| 3296 | buf_init_from_buf(&variable_entry->name, name); | 3343 | buf_init_from_buf(&variable_entry->name, name); |
| 3297 | | 3344 | |
| 3298 | if (!skip_name_check) { | 3345 | if (!skip_name_check) { |
| 3299 | VariableTableEntry *existing_var = find_variable(codegen, parent_scope, name); | 3346 | ZigVar *existing_var = find_variable(codegen, parent_scope, name, nullptr); |
| 3300 | if (existing_var && !existing_var->shadowable) { | 3347 | if (existing_var && !existing_var->shadowable) { |
| 3301 | ErrorMsg *msg = add_node_error(codegen, node, | 3348 | ErrorMsg *msg = add_node_error(codegen, node, |
| 3302 | buf_sprintf("redeclaration of variable '%s'", buf_ptr(name))); | 3349 | buf_sprintf("redeclaration of variable '%s'", buf_ptr(name))); |
| 3303 | add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration is here")); | 3350 | add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration is here")); |
| 3304 | variable_entry->value->type = codegen->builtin_types.entry_invalid; | 3351 | variable_entry->value->type = codegen->builtin_types.entry_invalid; |
| 3305 | } else { | 3352 | } else { |
| 3306 | TypeTableEntry *type = get_primitive_type(codegen, name); | 3353 | ZigType *type = get_primitive_type(codegen, name); |
| 3307 | if (type != nullptr) { | 3354 | if (type != nullptr) { |
| 3308 | add_node_error(codegen, node, | 3355 | add_node_error(codegen, node, |
| 3309 | buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name))); | 3356 | buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name))); |
| ... | @@ -3337,11 +3384,11 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco | ... | @@ -3337,11 +3384,11 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco |
| 3337 | | 3384 | |
| 3338 | // Set name to nullptr to make the variable anonymous (not visible to programmer). | 3385 | // Set name to nullptr to make the variable anonymous (not visible to programmer). |
| 3339 | // After you call this function var->child_scope has the variable in scope | 3386 | // After you call this function var->child_scope has the variable in scope |
| 3340 | static VariableTableEntry *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name, | 3387 | static ZigVar *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name, |
| 3341 | bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime) | 3388 | bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime) |
| 3342 | { | 3389 | { |
| 3343 | bool is_underscored = name ? buf_eql_str(name, "_") : false; | 3390 | bool is_underscored = name ? buf_eql_str(name, "_") : false; |
| 3344 | VariableTableEntry *var = create_local_var(irb->codegen, node, scope, | 3391 | ZigVar *var = create_local_var(irb->codegen, node, scope, |
| 3345 | (is_underscored ? nullptr : name), src_is_const, gen_is_const, | 3392 | (is_underscored ? nullptr : name), src_is_const, gen_is_const, |
| 3346 | (is_underscored ? true : is_shadowable), is_comptime, false); | 3393 | (is_underscored ? true : is_shadowable), is_comptime, false); |
| 3347 | if (is_comptime != nullptr || gen_is_const) { | 3394 | if (is_comptime != nullptr || gen_is_const) { |
| ... | @@ -3363,7 +3410,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode | ... | @@ -3363,7 +3410,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 3363 | Scope *outer_block_scope = &scope_block->base; | 3410 | Scope *outer_block_scope = &scope_block->base; |
| 3364 | Scope *child_scope = outer_block_scope; | 3411 | Scope *child_scope = outer_block_scope; |
| 3365 | | 3412 | |
| 3366 | FnTableEntry *fn_entry = scope_fn_entry(parent_scope); | 3413 | ZigFn *fn_entry = scope_fn_entry(parent_scope); |
| 3367 | if (fn_entry && fn_entry->child_scope == parent_scope) { | 3414 | if (fn_entry && fn_entry->child_scope == parent_scope) { |
| 3368 | fn_entry->def_scope = scope_block; | 3415 | fn_entry->def_scope = scope_block; |
| 3369 | } | 3416 | } |
| ... | @@ -3749,7 +3796,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, | ... | @@ -3749,7 +3796,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3749 | return &const_instruction->base; | 3796 | return &const_instruction->base; |
| 3750 | } | 3797 | } |
| 3751 | | 3798 | |
| 3752 | TypeTableEntry *primitive_type = get_primitive_type(irb->codegen, variable_name); | 3799 | ZigType *primitive_type = get_primitive_type(irb->codegen, variable_name); |
| 3753 | if (primitive_type != nullptr) { | 3800 | if (primitive_type != nullptr) { |
| 3754 | IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_type); | 3801 | IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_type); |
| 3755 | if (lval == LValPtr) { | 3802 | if (lval == LValPtr) { |
| ... | @@ -3759,9 +3806,10 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, | ... | @@ -3759,9 +3806,10 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3759 | } | 3806 | } |
| 3760 | } | 3807 | } |
| 3761 | | 3808 | |
| 3762 | VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name); | 3809 | ScopeFnDef *crossed_fndef_scope; |
| | 3810 | ZigVar *var = find_variable(irb->codegen, scope, variable_name, &crossed_fndef_scope); |
| 3763 | if (var) { | 3811 | if (var) { |
| 3764 | IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var); | 3812 | IrInstruction *var_ptr = ir_build_var_ptr_x(irb, scope, node, var, crossed_fndef_scope); |
| 3765 | if (lval == LValPtr) | 3813 | if (lval == LValPtr) |
| 3766 | return var_ptr; | 3814 | return var_ptr; |
| 3767 | else | 3815 | else |
| ... | @@ -4980,7 +5028,8 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -4980,7 +5028,8 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 4980 | | 5028 | |
| 4981 | ir_set_cursor_at_end_and_append_block(irb, then_block); | 5029 | ir_set_cursor_at_end_and_append_block(irb, then_block); |
| 4982 | | 5030 | |
| 4983 | IrInstruction *then_expr_result = ir_gen_node(irb, then_node, scope); | 5031 | Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime); |
| | 5032 | IrInstruction *then_expr_result = ir_gen_node(irb, then_node, subexpr_scope); |
| 4984 | if (then_expr_result == irb->codegen->invalid_instruction) | 5033 | if (then_expr_result == irb->codegen->invalid_instruction) |
| 4985 | return then_expr_result; | 5034 | return then_expr_result; |
| 4986 | IrBasicBlock *after_then_block = irb->current_basic_block; | 5035 | IrBasicBlock *after_then_block = irb->current_basic_block; |
| ... | @@ -4990,7 +5039,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -4990,7 +5039,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 4990 | ir_set_cursor_at_end_and_append_block(irb, else_block); | 5039 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 4991 | IrInstruction *else_expr_result; | 5040 | IrInstruction *else_expr_result; |
| 4992 | if (else_node) { | 5041 | if (else_node) { |
| 4993 | else_expr_result = ir_gen_node(irb, else_node, scope); | 5042 | else_expr_result = ir_gen_node(irb, else_node, subexpr_scope); |
| 4994 | if (else_expr_result == irb->codegen->invalid_instruction) | 5043 | if (else_expr_result == irb->codegen->invalid_instruction) |
| 4995 | return else_expr_result; | 5044 | return else_expr_result; |
| 4996 | } else { | 5045 | } else { |
| ... | @@ -5217,7 +5266,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod | ... | @@ -5217,7 +5266,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 5217 | | 5266 | |
| 5218 | IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, | 5267 | IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, |
| 5219 | ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime); | 5268 | ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime); |
| 5220 | VariableTableEntry *var = ir_create_var(irb, node, scope, variable_declaration->symbol, | 5269 | ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol, |
| 5221 | is_const, is_const, is_shadowable, is_comptime); | 5270 | is_const, is_const, is_shadowable, is_comptime); |
| 5222 | // we detect IrInstructionIdDeclVar in gen_block to make sure the next node | 5271 | // we detect IrInstructionIdDeclVar in gen_block to make sure the next node |
| 5223 | // is inside var->child_scope | 5272 | // is inside var->child_scope |
| ... | @@ -5271,6 +5320,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5271,6 +5320,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5271 | ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline); | 5320 | ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline); |
| 5272 | ir_build_br(irb, scope, node, cond_block, is_comptime); | 5321 | ir_build_br(irb, scope, node, cond_block, is_comptime); |
| 5273 | | 5322 | |
| | 5323 | Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime); |
| 5274 | Buf *var_symbol = node->data.while_expr.var_symbol; | 5324 | Buf *var_symbol = node->data.while_expr.var_symbol; |
| 5275 | Buf *err_symbol = node->data.while_expr.err_symbol; | 5325 | Buf *err_symbol = node->data.while_expr.err_symbol; |
| 5276 | if (err_symbol != nullptr) { | 5326 | if (err_symbol != nullptr) { |
| ... | @@ -5278,16 +5328,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5278,16 +5328,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5278 | | 5328 | |
| 5279 | Scope *payload_scope; | 5329 | Scope *payload_scope; |
| 5280 | AstNode *symbol_node = node; // TODO make more accurate | 5330 | AstNode *symbol_node = node; // TODO make more accurate |
| 5281 | VariableTableEntry *payload_var; | 5331 | ZigVar *payload_var; |
| 5282 | if (var_symbol) { | 5332 | if (var_symbol) { |
| 5283 | // TODO make it an error to write to payload variable | 5333 | // TODO make it an error to write to payload variable |
| 5284 | payload_var = ir_create_var(irb, symbol_node, scope, var_symbol, | 5334 | payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol, |
| 5285 | true, false, false, is_comptime); | 5335 | true, false, false, is_comptime); |
| 5286 | payload_scope = payload_var->child_scope; | 5336 | payload_scope = payload_var->child_scope; |
| 5287 | } else { | 5337 | } else { |
| 5288 | payload_scope = scope; | 5338 | payload_scope = subexpr_scope; |
| 5289 | } | 5339 | } |
| 5290 | IrInstruction *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, scope, LValPtr); | 5340 | IrInstruction *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, LValPtr); |
| 5291 | if (err_val_ptr == irb->codegen->invalid_instruction) | 5341 | if (err_val_ptr == irb->codegen->invalid_instruction) |
| 5292 | return err_val_ptr; | 5342 | return err_val_ptr; |
| 5293 | IrInstruction *err_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, err_val_ptr); | 5343 | IrInstruction *err_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, err_val_ptr); |
| ... | @@ -5342,7 +5392,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5342,7 +5392,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5342 | | 5392 | |
| 5343 | // TODO make it an error to write to error variable | 5393 | // TODO make it an error to write to error variable |
| 5344 | AstNode *err_symbol_node = else_node; // TODO make more accurate | 5394 | AstNode *err_symbol_node = else_node; // TODO make more accurate |
| 5345 | VariableTableEntry *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol, | 5395 | ZigVar *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol, |
| 5346 | true, false, false, is_comptime); | 5396 | true, false, false, is_comptime); |
| 5347 | Scope *err_scope = err_var->child_scope; | 5397 | Scope *err_scope = err_var->child_scope; |
| 5348 | IrInstruction *err_var_value = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr); | 5398 | IrInstruction *err_var_value = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr); |
| ... | @@ -5367,12 +5417,14 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5367,12 +5417,14 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5367 | return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); | 5417 | return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); |
| 5368 | } else if (var_symbol != nullptr) { | 5418 | } else if (var_symbol != nullptr) { |
| 5369 | ir_set_cursor_at_end_and_append_block(irb, cond_block); | 5419 | ir_set_cursor_at_end_and_append_block(irb, cond_block); |
| | 5420 | Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime); |
| 5370 | // TODO make it an error to write to payload variable | 5421 | // TODO make it an error to write to payload variable |
| 5371 | AstNode *symbol_node = node; // TODO make more accurate | 5422 | AstNode *symbol_node = node; // TODO make more accurate |
| 5372 | VariableTableEntry *payload_var = ir_create_var(irb, symbol_node, scope, var_symbol, | 5423 | |
| | 5424 | ZigVar *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol, |
| 5373 | true, false, false, is_comptime); | 5425 | true, false, false, is_comptime); |
| 5374 | Scope *child_scope = payload_var->child_scope; | 5426 | Scope *child_scope = payload_var->child_scope; |
| 5375 | IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, scope, LValPtr); | 5427 | IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, LValPtr); |
| 5376 | if (maybe_val_ptr == irb->codegen->invalid_instruction) | 5428 | if (maybe_val_ptr == irb->codegen->invalid_instruction) |
| 5377 | return maybe_val_ptr; | 5429 | return maybe_val_ptr; |
| 5378 | IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr); | 5430 | IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr); |
| ... | @@ -5456,7 +5508,9 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5456,7 +5508,9 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5456 | ZigList<IrInstruction *> incoming_values = {0}; | 5508 | ZigList<IrInstruction *> incoming_values = {0}; |
| 5457 | ZigList<IrBasicBlock *> incoming_blocks = {0}; | 5509 | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| 5458 | | 5510 | |
| 5459 | ScopeLoop *loop_scope = create_loop_scope(node, scope); | 5511 | Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime); |
| | 5512 | |
| | 5513 | ScopeLoop *loop_scope = create_loop_scope(node, subexpr_scope); |
| 5460 | loop_scope->break_block = end_block; | 5514 | loop_scope->break_block = end_block; |
| 5461 | loop_scope->continue_block = continue_block; | 5515 | loop_scope->continue_block = continue_block; |
| 5462 | loop_scope->is_comptime = is_comptime; | 5516 | loop_scope->is_comptime = is_comptime; |
| ... | @@ -5474,7 +5528,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5474,7 +5528,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5474 | | 5528 | |
| 5475 | if (continue_expr_node) { | 5529 | if (continue_expr_node) { |
| 5476 | ir_set_cursor_at_end_and_append_block(irb, continue_block); | 5530 | ir_set_cursor_at_end_and_append_block(irb, continue_block); |
| 5477 | IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, scope); | 5531 | IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope); |
| 5478 | if (expr_result == irb->codegen->invalid_instruction) | 5532 | if (expr_result == irb->codegen->invalid_instruction) |
| 5479 | return expr_result; | 5533 | return expr_result; |
| 5480 | if (!instr_is_unreachable(expr_result)) | 5534 | if (!instr_is_unreachable(expr_result)) |
| ... | @@ -5485,7 +5539,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5485,7 +5539,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5485 | if (else_node) { | 5539 | if (else_node) { |
| 5486 | ir_set_cursor_at_end_and_append_block(irb, else_block); | 5540 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 5487 | | 5541 | |
| 5488 | else_result = ir_gen_node(irb, else_node, scope); | 5542 | else_result = ir_gen_node(irb, else_node, subexpr_scope); |
| 5489 | if (else_result == irb->codegen->invalid_instruction) | 5543 | if (else_result == irb->codegen->invalid_instruction) |
| 5490 | return else_result; | 5544 | return else_result; |
| 5491 | if (!instr_is_unreachable(else_result)) | 5545 | if (!instr_is_unreachable(else_result)) |
| ... | @@ -5539,7 +5593,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo | ... | @@ -5539,7 +5593,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5539 | | 5593 | |
| 5540 | // TODO make it an error to write to element variable or i variable. | 5594 | // TODO make it an error to write to element variable or i variable. |
| 5541 | Buf *elem_var_name = elem_node->data.symbol_expr.symbol; | 5595 | Buf *elem_var_name = elem_node->data.symbol_expr.symbol; |
| 5542 | VariableTableEntry *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime); | 5596 | ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime); |
| 5543 | Scope *child_scope = elem_var->child_scope; | 5597 | Scope *child_scope = elem_var->child_scope; |
| 5544 | | 5598 | |
| 5545 | IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node); | 5599 | IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node); |
| ... | @@ -5547,7 +5601,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo | ... | @@ -5547,7 +5601,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5547 | IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var); | 5601 | IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var); |
| 5548 | | 5602 | |
| 5549 | AstNode *index_var_source_node; | 5603 | AstNode *index_var_source_node; |
| 5550 | VariableTableEntry *index_var; | 5604 | ZigVar *index_var; |
| 5551 | if (index_node) { | 5605 | if (index_node) { |
| 5552 | index_var_source_node = index_node; | 5606 | index_var_source_node = index_node; |
| 5553 | Buf *index_var_name = index_node->data.symbol_expr.symbol; | 5607 | Buf *index_var_name = index_node->data.symbol_expr.symbol; |
| ... | @@ -5640,7 +5694,7 @@ static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -5640,7 +5694,7 @@ static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode |
| 5640 | if (!scope->parent) | 5694 | if (!scope->parent) |
| 5641 | return ir_build_const_import(irb, scope, node, node->owner); | 5695 | return ir_build_const_import(irb, scope, node, node->owner); |
| 5642 | | 5696 | |
| 5643 | FnTableEntry *fn_entry = scope_get_fn_if_root(scope); | 5697 | ZigFn *fn_entry = scope_get_fn_if_root(scope); |
| 5644 | if (fn_entry) | 5698 | if (fn_entry) |
| 5645 | return ir_build_const_fn(irb, scope, node, fn_entry); | 5699 | return ir_build_const_fn(irb, scope, node, fn_entry); |
| 5646 | | 5700 | |
| ... | @@ -5650,7 +5704,7 @@ static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -5650,7 +5704,7 @@ static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode |
| 5650 | | 5704 | |
| 5651 | if (scope->id == ScopeIdDecls) { | 5705 | if (scope->id == ScopeIdDecls) { |
| 5652 | ScopeDecls *decls_scope = (ScopeDecls *)scope; | 5706 | ScopeDecls *decls_scope = (ScopeDecls *)scope; |
| 5653 | TypeTableEntry *container_type = decls_scope->container_type; | 5707 | ZigType *container_type = decls_scope->container_type; |
| 5654 | assert(container_type); | 5708 | assert(container_type); |
| 5655 | return ir_build_const_type(irb, scope, node, container_type); | 5709 | return ir_build_const_type(irb, scope, node, container_type); |
| 5656 | } | 5710 | } |
| ... | @@ -5752,7 +5806,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod | ... | @@ -5752,7 +5806,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 5752 | | 5806 | |
| 5753 | IrInstruction **input_list = allocate<IrInstruction *>(node->data.asm_expr.input_list.length); | 5807 | IrInstruction **input_list = allocate<IrInstruction *>(node->data.asm_expr.input_list.length); |
| 5754 | IrInstruction **output_types = allocate<IrInstruction *>(node->data.asm_expr.output_list.length); | 5808 | IrInstruction **output_types = allocate<IrInstruction *>(node->data.asm_expr.output_list.length); |
| 5755 | VariableTableEntry **output_vars = allocate<VariableTableEntry *>(node->data.asm_expr.output_list.length); | 5809 | ZigVar **output_vars = allocate<ZigVar *>(node->data.asm_expr.output_list.length); |
| 5756 | size_t return_count = 0; | 5810 | size_t return_count = 0; |
| 5757 | bool is_volatile = node->data.asm_expr.is_volatile; | 5811 | bool is_volatile = node->data.asm_expr.is_volatile; |
| 5758 | if (!is_volatile && node->data.asm_expr.output_list.length == 0) { | 5812 | if (!is_volatile && node->data.asm_expr.output_list.length == 0) { |
| ... | @@ -5776,7 +5830,9 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod | ... | @@ -5776,7 +5830,9 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 5776 | output_types[i] = return_type; | 5830 | output_types[i] = return_type; |
| 5777 | } else { | 5831 | } else { |
| 5778 | Buf *variable_name = asm_output->variable_name; | 5832 | Buf *variable_name = asm_output->variable_name; |
| 5779 | VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name); | 5833 | // TODO there is some duplication here with ir_gen_symbol. I need to do a full audit of how |
| | 5834 | // inline assembly works. https://github.com/ziglang/zig/issues/215 |
| | 5835 | ZigVar *var = find_variable(irb->codegen, scope, variable_name, nullptr); |
| 5780 | if (var) { | 5836 | if (var) { |
| 5781 | output_vars[i] = var; | 5837 | output_vars[i] = var; |
| 5782 | } else { | 5838 | } else { |
| ... | @@ -5828,20 +5884,21 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no | ... | @@ -5828,20 +5884,21 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no |
| 5828 | | 5884 | |
| 5829 | ir_set_cursor_at_end_and_append_block(irb, then_block); | 5885 | ir_set_cursor_at_end_and_append_block(irb, then_block); |
| 5830 | | 5886 | |
| | 5887 | Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime); |
| 5831 | Scope *var_scope; | 5888 | Scope *var_scope; |
| 5832 | if (var_symbol) { | 5889 | if (var_symbol) { |
| 5833 | IrInstruction *var_type = nullptr; | 5890 | IrInstruction *var_type = nullptr; |
| 5834 | bool is_shadowable = false; | 5891 | bool is_shadowable = false; |
| 5835 | bool is_const = true; | 5892 | bool is_const = true; |
| 5836 | VariableTableEntry *var = ir_create_var(irb, node, scope, | 5893 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, |
| 5837 | var_symbol, is_const, is_const, is_shadowable, is_comptime); | 5894 | var_symbol, is_const, is_const, is_shadowable, is_comptime); |
| 5838 | | 5895 | |
| 5839 | IrInstruction *var_ptr_value = ir_build_unwrap_maybe(irb, scope, node, maybe_val_ptr, false); | 5896 | IrInstruction *var_ptr_value = ir_build_unwrap_maybe(irb, subexpr_scope, node, maybe_val_ptr, false); |
| 5840 | IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, scope, node, var_ptr_value); | 5897 | IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, subexpr_scope, node, var_ptr_value); |
| 5841 | ir_build_var_decl(irb, scope, node, var, var_type, nullptr, var_value); | 5898 | ir_build_var_decl(irb, subexpr_scope, node, var, var_type, nullptr, var_value); |
| 5842 | var_scope = var->child_scope; | 5899 | var_scope = var->child_scope; |
| 5843 | } else { | 5900 | } else { |
| 5844 | var_scope = scope; | 5901 | var_scope = subexpr_scope; |
| 5845 | } | 5902 | } |
| 5846 | IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var_scope); | 5903 | IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var_scope); |
| 5847 | if (then_expr_result == irb->codegen->invalid_instruction) | 5904 | if (then_expr_result == irb->codegen->invalid_instruction) |
| ... | @@ -5853,7 +5910,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no | ... | @@ -5853,7 +5910,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no |
| 5853 | ir_set_cursor_at_end_and_append_block(irb, else_block); | 5910 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 5854 | IrInstruction *else_expr_result; | 5911 | IrInstruction *else_expr_result; |
| 5855 | if (else_node) { | 5912 | if (else_node) { |
| 5856 | else_expr_result = ir_gen_node(irb, else_node, scope); | 5913 | else_expr_result = ir_gen_node(irb, else_node, subexpr_scope); |
| 5857 | if (else_expr_result == irb->codegen->invalid_instruction) | 5914 | if (else_expr_result == irb->codegen->invalid_instruction) |
| 5858 | return else_expr_result; | 5915 | return else_expr_result; |
| 5859 | } else { | 5916 | } else { |
| ... | @@ -5902,20 +5959,21 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -5902,20 +5959,21 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 5902 | | 5959 | |
| 5903 | ir_set_cursor_at_end_and_append_block(irb, ok_block); | 5960 | ir_set_cursor_at_end_and_append_block(irb, ok_block); |
| 5904 | | 5961 | |
| | 5962 | Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime); |
| 5905 | Scope *var_scope; | 5963 | Scope *var_scope; |
| 5906 | if (var_symbol) { | 5964 | if (var_symbol) { |
| 5907 | IrInstruction *var_type = nullptr; | 5965 | IrInstruction *var_type = nullptr; |
| 5908 | bool is_shadowable = false; | 5966 | bool is_shadowable = false; |
| 5909 | IrInstruction *var_is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, err_val); | 5967 | IrInstruction *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val); |
| 5910 | VariableTableEntry *var = ir_create_var(irb, node, scope, | 5968 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, |
| 5911 | var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime); | 5969 | var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime); |
| 5912 | | 5970 | |
| 5913 | IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, scope, node, err_val_ptr, false); | 5971 | IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, subexpr_scope, node, err_val_ptr, false); |
| 5914 | IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, scope, node, var_ptr_value); | 5972 | IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, subexpr_scope, node, var_ptr_value); |
| 5915 | ir_build_var_decl(irb, scope, node, var, var_type, nullptr, var_value); | 5973 | ir_build_var_decl(irb, subexpr_scope, node, var, var_type, nullptr, var_value); |
| 5916 | var_scope = var->child_scope; | 5974 | var_scope = var->child_scope; |
| 5917 | } else { | 5975 | } else { |
| 5918 | var_scope = scope; | 5976 | var_scope = subexpr_scope; |
| 5919 | } | 5977 | } |
| 5920 | IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var_scope); | 5978 | IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var_scope); |
| 5921 | if (then_expr_result == irb->codegen->invalid_instruction) | 5979 | if (then_expr_result == irb->codegen->invalid_instruction) |
| ... | @@ -5933,14 +5991,14 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -5933,14 +5991,14 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 5933 | IrInstruction *var_type = nullptr; | 5991 | IrInstruction *var_type = nullptr; |
| 5934 | bool is_shadowable = false; | 5992 | bool is_shadowable = false; |
| 5935 | bool is_const = true; | 5993 | bool is_const = true; |
| 5936 | VariableTableEntry *var = ir_create_var(irb, node, scope, | 5994 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, |
| 5937 | err_symbol, is_const, is_const, is_shadowable, is_comptime); | 5995 | err_symbol, is_const, is_const, is_shadowable, is_comptime); |
| 5938 | | 5996 | |
| 5939 | IrInstruction *var_value = ir_build_unwrap_err_code(irb, scope, node, err_val_ptr); | 5997 | IrInstruction *var_value = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr); |
| 5940 | ir_build_var_decl(irb, scope, node, var, var_type, nullptr, var_value); | 5998 | ir_build_var_decl(irb, subexpr_scope, node, var, var_type, nullptr, var_value); |
| 5941 | err_var_scope = var->child_scope; | 5999 | err_var_scope = var->child_scope; |
| 5942 | } else { | 6000 | } else { |
| 5943 | err_var_scope = scope; | 6001 | err_var_scope = subexpr_scope; |
| 5944 | } | 6002 | } |
| 5945 | else_expr_result = ir_gen_node(irb, else_node, err_var_scope); | 6003 | else_expr_result = ir_gen_node(irb, else_node, err_var_scope); |
| 5946 | if (else_expr_result == irb->codegen->invalid_instruction) | 6004 | if (else_expr_result == irb->codegen->invalid_instruction) |
| ... | @@ -5981,7 +6039,7 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit | ... | @@ -5981,7 +6039,7 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit |
| 5981 | | 6039 | |
| 5982 | bool is_shadowable = false; | 6040 | bool is_shadowable = false; |
| 5983 | bool is_const = true; | 6041 | bool is_const = true; |
| 5984 | VariableTableEntry *var = ir_create_var(irb, var_symbol_node, scope, | 6042 | ZigVar *var = ir_create_var(irb, var_symbol_node, scope, |
| 5985 | var_name, is_const, is_const, is_shadowable, var_is_comptime); | 6043 | var_name, is_const, is_const, is_shadowable, var_is_comptime); |
| 5986 | child_scope = var->child_scope; | 6044 | child_scope = var->child_scope; |
| 5987 | IrInstruction *var_value; | 6045 | IrInstruction *var_value; |
| ... | @@ -6037,6 +6095,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -6037,6 +6095,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 6037 | ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0}; | 6095 | ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0}; |
| 6038 | | 6096 | |
| 6039 | // First do the else and the ranges | 6097 | // First do the else and the ranges |
| | 6098 | Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime); |
| 6040 | Scope *comptime_scope = create_comptime_scope(node, scope); | 6099 | Scope *comptime_scope = create_comptime_scope(node, scope); |
| 6041 | AstNode *else_prong = nullptr; | 6100 | AstNode *else_prong = nullptr; |
| 6042 | for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) { | 6101 | for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) { |
| ... | @@ -6054,7 +6113,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -6054,7 +6113,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 6054 | | 6113 | |
| 6055 | IrBasicBlock *prev_block = irb->current_basic_block; | 6114 | IrBasicBlock *prev_block = irb->current_basic_block; |
| 6056 | ir_set_cursor_at_end_and_append_block(irb, else_block); | 6115 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 6057 | if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block, | 6116 | if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block, |
| 6058 | is_comptime, var_is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values)) | 6117 | is_comptime, var_is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values)) |
| 6059 | { | 6118 | { |
| 6060 | return irb->codegen->invalid_instruction; | 6119 | return irb->codegen->invalid_instruction; |
| ... | @@ -6121,7 +6180,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -6121,7 +6180,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 6121 | range_block_no, is_comptime)); | 6180 | range_block_no, is_comptime)); |
| 6122 | | 6181 | |
| 6123 | ir_set_cursor_at_end_and_append_block(irb, range_block_yes); | 6182 | ir_set_cursor_at_end_and_append_block(irb, range_block_yes); |
| 6124 | if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block, | 6183 | if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block, |
| 6125 | is_comptime, var_is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values)) | 6184 | is_comptime, var_is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values)) |
| 6126 | { | 6185 | { |
| 6127 | return irb->codegen->invalid_instruction; | 6186 | return irb->codegen->invalid_instruction; |
| ... | @@ -6165,7 +6224,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -6165,7 +6224,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 6165 | | 6224 | |
| 6166 | IrBasicBlock *prev_block = irb->current_basic_block; | 6225 | IrBasicBlock *prev_block = irb->current_basic_block; |
| 6167 | ir_set_cursor_at_end_and_append_block(irb, prong_block); | 6226 | ir_set_cursor_at_end_and_append_block(irb, prong_block); |
| 6168 | if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block, | 6227 | if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block, |
| 6169 | is_comptime, var_is_comptime, target_value_ptr, only_item_value, &incoming_blocks, &incoming_values)) | 6228 | is_comptime, var_is_comptime, target_value_ptr, only_item_value, &incoming_blocks, &incoming_values)) |
| 6170 | { | 6229 | { |
| 6171 | return irb->codegen->invalid_instruction; | 6230 | return irb->codegen->invalid_instruction; |
| ... | @@ -6308,6 +6367,8 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast | ... | @@ -6308,6 +6367,8 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast |
| 6308 | // * defer expression scope => error, cannot break out of defer expression | 6367 | // * defer expression scope => error, cannot break out of defer expression |
| 6309 | // * loop scope => OK | 6368 | // * loop scope => OK |
| 6310 | | 6369 | |
| | 6370 | ZigList<ScopeRuntime *> runtime_scopes = {}; |
| | 6371 | |
| 6311 | Scope *search_scope = continue_scope; | 6372 | Scope *search_scope = continue_scope; |
| 6312 | ScopeLoop *loop_scope; | 6373 | ScopeLoop *loop_scope; |
| 6313 | for (;;) { | 6374 | for (;;) { |
| ... | @@ -6330,6 +6391,9 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast | ... | @@ -6330,6 +6391,9 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast |
| 6330 | loop_scope = this_loop_scope; | 6391 | loop_scope = this_loop_scope; |
| 6331 | break; | 6392 | break; |
| 6332 | } | 6393 | } |
| | 6394 | } else if (search_scope->id == ScopeIdRuntime) { |
| | 6395 | ScopeRuntime *scope_runtime = (ScopeRuntime *)search_scope; |
| | 6396 | runtime_scopes.append(scope_runtime); |
| 6333 | } | 6397 | } |
| 6334 | search_scope = search_scope->parent; | 6398 | search_scope = search_scope->parent; |
| 6335 | } | 6399 | } |
| ... | @@ -6341,6 +6405,11 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast | ... | @@ -6341,6 +6405,11 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast |
| 6341 | is_comptime = loop_scope->is_comptime; | 6405 | is_comptime = loop_scope->is_comptime; |
| 6342 | } | 6406 | } |
| 6343 | | 6407 | |
| | 6408 | for (size_t i = 0; i < runtime_scopes.length; i += 1) { |
| | 6409 | ScopeRuntime *scope_runtime = runtime_scopes.at(i); |
| | 6410 | ir_mark_gen(ir_build_check_runtime_scope(irb, continue_scope, node, scope_runtime->is_comptime, is_comptime)); |
| | 6411 | } |
| | 6412 | |
| 6344 | IrBasicBlock *dest_block = loop_scope->continue_block; | 6413 | IrBasicBlock *dest_block = loop_scope->continue_block; |
| 6345 | ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, false); | 6414 | ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, false); |
| 6346 | return ir_mark_gen(ir_build_br(irb, continue_scope, node, dest_block, is_comptime)); | 6415 | return ir_mark_gen(ir_build_br(irb, continue_scope, node, dest_block, is_comptime)); |
| ... | @@ -6435,7 +6504,7 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN | ... | @@ -6435,7 +6504,7 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN |
| 6435 | Buf *var_name = var_node->data.symbol_expr.symbol; | 6504 | Buf *var_name = var_node->data.symbol_expr.symbol; |
| 6436 | bool is_const = true; | 6505 | bool is_const = true; |
| 6437 | bool is_shadowable = false; | 6506 | bool is_shadowable = false; |
| 6438 | VariableTableEntry *var = ir_create_var(irb, node, parent_scope, var_name, | 6507 | ZigVar *var = ir_create_var(irb, node, parent_scope, var_name, |
| 6439 | is_const, is_const, is_shadowable, is_comptime); | 6508 | is_const, is_const, is_shadowable, is_comptime); |
| 6440 | err_scope = var->child_scope; | 6509 | err_scope = var->child_scope; |
| 6441 | IrInstruction *err_val = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr); | 6510 | IrInstruction *err_val = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr); |
| ... | @@ -6507,7 +6576,7 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, | ... | @@ -6507,7 +6576,7 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, |
| 6507 | init_tld(&tld_container->base, TldIdContainer, name, visib_mod, node, parent_scope); | 6576 | init_tld(&tld_container->base, TldIdContainer, name, visib_mod, node, parent_scope); |
| 6508 | | 6577 | |
| 6509 | ContainerLayout layout = node->data.container_decl.layout; | 6578 | ContainerLayout layout = node->data.container_decl.layout; |
| 6510 | TypeTableEntry *container_type = get_partial_container_type(irb->codegen, parent_scope, | 6579 | ZigType *container_type = get_partial_container_type(irb->codegen, parent_scope, |
| 6511 | kind, node, buf_ptr(name), layout); | 6580 | kind, node, buf_ptr(name), layout); |
| 6512 | ScopeDecls *child_scope = get_container_scope(container_type); | 6581 | ScopeDecls *child_scope = get_container_scope(container_type); |
| 6513 | | 6582 | |
| ... | @@ -6527,11 +6596,11 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, | ... | @@ -6527,11 +6596,11 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, |
| 6527 | } | 6596 | } |
| 6528 | | 6597 | |
| 6529 | // errors should be populated with set1's values | 6598 | // errors should be populated with set1's values |
| 6530 | static TypeTableEntry *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, TypeTableEntry *set1, TypeTableEntry *set2) { | 6599 | static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigType *set1, ZigType *set2) { |
| 6531 | assert(set1->id == TypeTableEntryIdErrorSet); | 6600 | assert(set1->id == ZigTypeIdErrorSet); |
| 6532 | assert(set2->id == TypeTableEntryIdErrorSet); | 6601 | assert(set2->id == ZigTypeIdErrorSet); |
| 6533 | | 6602 | |
| 6534 | TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); | 6603 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); |
| 6535 | buf_resize(&err_set_type->name, 0); | 6604 | buf_resize(&err_set_type->name, 0); |
| 6536 | buf_appendf(&err_set_type->name, "error{"); | 6605 | buf_appendf(&err_set_type->name, "error{"); |
| 6537 | | 6606 | |
| ... | @@ -6580,10 +6649,10 @@ static TypeTableEntry *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, | ... | @@ -6580,10 +6649,10 @@ static TypeTableEntry *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, |
| 6580 | | 6649 | |
| 6581 | } | 6650 | } |
| 6582 | | 6651 | |
| 6583 | static TypeTableEntry *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstNode *node, | 6652 | static ZigType *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstNode *node, |
| 6584 | ErrorTableEntry *err_entry) | 6653 | ErrorTableEntry *err_entry) |
| 6585 | { | 6654 | { |
| 6586 | TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); | 6655 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); |
| 6587 | buf_resize(&err_set_type->name, 0); | 6656 | buf_resize(&err_set_type->name, 0); |
| 6588 | buf_appendf(&err_set_type->name, "error{%s}", buf_ptr(&err_entry->name)); | 6657 | buf_appendf(&err_set_type->name, "error{%s}", buf_ptr(&err_entry->name)); |
| 6589 | err_set_type->is_copyable = true; | 6658 | err_set_type->is_copyable = true; |
| ... | @@ -6605,7 +6674,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A | ... | @@ -6605,7 +6674,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A |
| 6605 | uint32_t err_count = node->data.err_set_decl.decls.length; | 6674 | uint32_t err_count = node->data.err_set_decl.decls.length; |
| 6606 | | 6675 | |
| 6607 | Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error set", node); | 6676 | Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error set", node); |
| 6608 | TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); | 6677 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); |
| 6609 | buf_init_from_buf(&err_set_type->name, type_name); | 6678 | buf_init_from_buf(&err_set_type->name, type_name); |
| 6610 | err_set_type->is_copyable = true; | 6679 | err_set_type->is_copyable = true; |
| 6611 | err_set_type->data.error_set.err_count = err_count; | 6680 | err_set_type->data.error_set.err_count = err_count; |
| ... | @@ -6854,7 +6923,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -6854,7 +6923,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 6854 | if (target_inst == irb->codegen->invalid_instruction) | 6923 | if (target_inst == irb->codegen->invalid_instruction) |
| 6855 | return irb->codegen->invalid_instruction; | 6924 | return irb->codegen->invalid_instruction; |
| 6856 | | 6925 | |
| 6857 | FnTableEntry *fn_entry = exec_fn_entry(irb->exec); | 6926 | ZigFn *fn_entry = exec_fn_entry(irb->exec); |
| 6858 | if (!fn_entry) { | 6927 | if (!fn_entry) { |
| 6859 | add_node_error(irb->codegen, node, buf_sprintf("await outside function definition")); | 6928 | add_node_error(irb->codegen, node, buf_sprintf("await outside function definition")); |
| 6860 | return irb->codegen->invalid_instruction; | 6929 | return irb->codegen->invalid_instruction; |
| ... | @@ -6917,7 +6986,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -6917,7 +6986,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 6917 | IrInstruction *is_canceled_mask = ir_build_const_usize(irb, scope, node, 0x1); // 0b001 | 6986 | IrInstruction *is_canceled_mask = ir_build_const_usize(irb, scope, node, 0x1); // 0b001 |
| 6918 | IrInstruction *is_suspended_mask = ir_build_const_usize(irb, scope, node, 0x2); // 0b010 | 6987 | IrInstruction *is_suspended_mask = ir_build_const_usize(irb, scope, node, 0x2); // 0b010 |
| 6919 | | 6988 | |
| 6920 | VariableTableEntry *result_var = ir_create_var(irb, node, scope, nullptr, | 6989 | ZigVar *result_var = ir_create_var(irb, node, scope, nullptr, |
| 6921 | false, false, true, const_bool_false); | 6990 | false, false, true, const_bool_false); |
| 6922 | IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst); | 6991 | IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst); |
| 6923 | IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type); | 6992 | IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type); |
| ... | @@ -7031,7 +7100,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -7031,7 +7100,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7031 | static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNode *node) { | 7100 | static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 7032 | assert(node->type == NodeTypeSuspend); | 7101 | assert(node->type == NodeTypeSuspend); |
| 7033 | | 7102 | |
| 7034 | FnTableEntry *fn_entry = exec_fn_entry(irb->exec); | 7103 | ZigFn *fn_entry = exec_fn_entry(irb->exec); |
| 7035 | if (!fn_entry) { | 7104 | if (!fn_entry) { |
| 7036 | add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition")); | 7105 | add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition")); |
| 7037 | return irb->codegen->invalid_instruction; | 7106 | return irb->codegen->invalid_instruction; |
| ... | @@ -7320,31 +7389,31 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec | ... | @@ -7320,31 +7389,31 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 7320 | // Entry block gets a reference because we enter it to begin. | 7389 | // Entry block gets a reference because we enter it to begin. |
| 7321 | ir_ref_bb(irb->current_basic_block); | 7390 | ir_ref_bb(irb->current_basic_block); |
| 7322 | | 7391 | |
| 7323 | FnTableEntry *fn_entry = exec_fn_entry(irb->exec); | 7392 | ZigFn *fn_entry = exec_fn_entry(irb->exec); |
| 7324 | bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync; | 7393 | bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync; |
| 7325 | IrInstruction *coro_id; | 7394 | IrInstruction *coro_id; |
| 7326 | IrInstruction *u8_ptr_type; | 7395 | IrInstruction *u8_ptr_type; |
| 7327 | IrInstruction *const_bool_false; | 7396 | IrInstruction *const_bool_false; |
| 7328 | IrInstruction *coro_promise_ptr; | 7397 | IrInstruction *coro_promise_ptr; |
| 7329 | IrInstruction *err_ret_trace_ptr; | 7398 | IrInstruction *err_ret_trace_ptr; |
| 7330 | TypeTableEntry *return_type; | 7399 | ZigType *return_type; |
| 7331 | Buf *result_ptr_field_name; | 7400 | Buf *result_ptr_field_name; |
| 7332 | VariableTableEntry *coro_size_var; | 7401 | ZigVar *coro_size_var; |
| 7333 | if (is_async) { | 7402 | if (is_async) { |
| 7334 | // create the coro promise | 7403 | // create the coro promise |
| 7335 | Scope *coro_scope = create_coro_prelude_scope(node, scope); | 7404 | Scope *coro_scope = create_coro_prelude_scope(node, scope); |
| 7336 | const_bool_false = ir_build_const_bool(irb, coro_scope, node, false); | 7405 | const_bool_false = ir_build_const_bool(irb, coro_scope, node, false); |
| 7337 | VariableTableEntry *promise_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false); | 7406 | ZigVar *promise_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false); |
| 7338 | | 7407 | |
| 7339 | return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type; | 7408 | return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type; |
| 7340 | IrInstruction *undef = ir_build_const_undefined(irb, coro_scope, node); | 7409 | IrInstruction *undef = ir_build_const_undefined(irb, coro_scope, node); |
| 7341 | TypeTableEntry *coro_frame_type = get_promise_frame_type(irb->codegen, return_type); | 7410 | ZigType *coro_frame_type = get_promise_frame_type(irb->codegen, return_type); |
| 7342 | IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type); | 7411 | IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type); |
| 7343 | // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa | 7412 | // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa |
| 7344 | ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef); | 7413 | ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef); |
| 7345 | coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var); | 7414 | coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var); |
| 7346 | | 7415 | |
| 7347 | VariableTableEntry *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false); | 7416 | ZigVar *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false); |
| 7348 | IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node); | 7417 | IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node); |
| 7349 | IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node, | 7418 | IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node, |
| 7350 | get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise)); | 7419 | get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise)); |
| ... | @@ -7531,7 +7600,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec | ... | @@ -7531,7 +7600,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 7531 | return true; | 7600 | return true; |
| 7532 | } | 7601 | } |
| 7533 | | 7602 | |
| 7534 | bool ir_gen_fn(CodeGen *codegen, FnTableEntry *fn_entry) { | 7603 | bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) { |
| 7535 | assert(fn_entry); | 7604 | assert(fn_entry); |
| 7536 | | 7605 | |
| 7537 | IrExecutable *ir_executable = &fn_entry->ir_executable; | 7606 | IrExecutable *ir_executable = &fn_entry->ir_executable; |
| ... | @@ -7566,6 +7635,19 @@ static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, | ... | @@ -7566,6 +7635,19 @@ static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, |
| 7566 | return ir_add_error_node(ira, source_instruction->source_node, msg); | 7635 | return ir_add_error_node(ira, source_instruction->source_node, msg); |
| 7567 | } | 7636 | } |
| 7568 | | 7637 | |
| | 7638 | static ConstExprValue *ir_const_ptr_pointee(IrAnalyze *ira, ConstExprValue *const_val, AstNode *source_node) { |
| | 7639 | ConstExprValue *val = const_ptr_pointee_unchecked(ira->codegen, const_val); |
| | 7640 | assert(val != nullptr); |
| | 7641 | assert(const_val->type->id == ZigTypeIdPointer); |
| | 7642 | ZigType *expected_type = const_val->type->data.pointer.child_type; |
| | 7643 | if (!types_have_same_zig_comptime_repr(val->type, expected_type)) { |
| | 7644 | ir_add_error_node(ira, source_node, |
| | 7645 | buf_sprintf("TODO handle comptime reinterpreted pointer. See https://github.com/ziglang/zig/issues/955")); |
| | 7646 | return nullptr; |
| | 7647 | } |
| | 7648 | return val; |
| | 7649 | } |
| | 7650 | |
| 7569 | static IrInstruction *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { | 7651 | static IrInstruction *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { |
| 7570 | IrBasicBlock *bb = exec->basic_block_list.at(0); | 7652 | IrBasicBlock *bb = exec->basic_block_list.at(0); |
| 7571 | for (size_t i = 0; i < bb->instruction_list.length; i += 1) { | 7653 | for (size_t i = 0; i < bb->instruction_list.length; i += 1) { |
| ... | @@ -7596,17 +7678,17 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so | ... | @@ -7596,17 +7678,17 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so |
| 7596 | return true; | 7678 | return true; |
| 7597 | } | 7679 | } |
| 7598 | | 7680 | |
| 7599 | static bool const_val_fits_in_num_lit(ConstExprValue *const_val, TypeTableEntry *num_lit_type) { | 7681 | static bool const_val_fits_in_num_lit(ConstExprValue *const_val, ZigType *num_lit_type) { |
| 7600 | return ((num_lit_type->id == TypeTableEntryIdComptimeFloat && | 7682 | return ((num_lit_type->id == ZigTypeIdComptimeFloat && |
| 7601 | (const_val->type->id == TypeTableEntryIdFloat || const_val->type->id == TypeTableEntryIdComptimeFloat)) || | 7683 | (const_val->type->id == ZigTypeIdFloat || const_val->type->id == ZigTypeIdComptimeFloat)) || |
| 7602 | (num_lit_type->id == TypeTableEntryIdComptimeInt && | 7684 | (num_lit_type->id == ZigTypeIdComptimeInt && |
| 7603 | (const_val->type->id == TypeTableEntryIdInt || const_val->type->id == TypeTableEntryIdComptimeInt))); | 7685 | (const_val->type->id == ZigTypeIdInt || const_val->type->id == ZigTypeIdComptimeInt))); |
| 7604 | } | 7686 | } |
| 7605 | | 7687 | |
| 7606 | static bool float_has_fraction(ConstExprValue *const_val) { | 7688 | static bool float_has_fraction(ConstExprValue *const_val) { |
| 7607 | if (const_val->type->id == TypeTableEntryIdComptimeFloat) { | 7689 | if (const_val->type->id == ZigTypeIdComptimeFloat) { |
| 7608 | return bigfloat_has_fraction(&const_val->data.x_bigfloat); | 7690 | return bigfloat_has_fraction(&const_val->data.x_bigfloat); |
| 7609 | } else if (const_val->type->id == TypeTableEntryIdFloat) { | 7691 | } else if (const_val->type->id == ZigTypeIdFloat) { |
| 7610 | switch (const_val->type->data.floating.bit_count) { | 7692 | switch (const_val->type->data.floating.bit_count) { |
| 7611 | case 16: | 7693 | case 16: |
| 7612 | { | 7694 | { |
| ... | @@ -7632,9 +7714,9 @@ static bool float_has_fraction(ConstExprValue *const_val) { | ... | @@ -7632,9 +7714,9 @@ static bool float_has_fraction(ConstExprValue *const_val) { |
| 7632 | } | 7714 | } |
| 7633 | | 7715 | |
| 7634 | static void float_append_buf(Buf *buf, ConstExprValue *const_val) { | 7716 | static void float_append_buf(Buf *buf, ConstExprValue *const_val) { |
| 7635 | if (const_val->type->id == TypeTableEntryIdComptimeFloat) { | 7717 | if (const_val->type->id == ZigTypeIdComptimeFloat) { |
| 7636 | bigfloat_append_buf(buf, &const_val->data.x_bigfloat); | 7718 | bigfloat_append_buf(buf, &const_val->data.x_bigfloat); |
| 7637 | } else if (const_val->type->id == TypeTableEntryIdFloat) { | 7719 | } else if (const_val->type->id == ZigTypeIdFloat) { |
| 7638 | switch (const_val->type->data.floating.bit_count) { | 7720 | switch (const_val->type->data.floating.bit_count) { |
| 7639 | case 16: | 7721 | case 16: |
| 7640 | buf_appendf(buf, "%f", zig_f16_to_double(const_val->data.x_f16)); | 7722 | buf_appendf(buf, "%f", zig_f16_to_double(const_val->data.x_f16)); |
| ... | @@ -7670,9 +7752,9 @@ static void float_append_buf(Buf *buf, ConstExprValue *const_val) { | ... | @@ -7670,9 +7752,9 @@ static void float_append_buf(Buf *buf, ConstExprValue *const_val) { |
| 7670 | } | 7752 | } |
| 7671 | | 7753 | |
| 7672 | static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) { | 7754 | static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) { |
| 7673 | if (const_val->type->id == TypeTableEntryIdComptimeFloat) { | 7755 | if (const_val->type->id == ZigTypeIdComptimeFloat) { |
| 7674 | bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat); | 7756 | bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat); |
| 7675 | } else if (const_val->type->id == TypeTableEntryIdFloat) { | 7757 | } else if (const_val->type->id == ZigTypeIdFloat) { |
| 7676 | switch (const_val->type->data.floating.bit_count) { | 7758 | switch (const_val->type->data.floating.bit_count) { |
| 7677 | case 16: | 7759 | case 16: |
| 7678 | { | 7760 | { |
| ... | @@ -7717,9 +7799,9 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) { | ... | @@ -7717,9 +7799,9 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) { |
| 7717 | } | 7799 | } |
| 7718 | | 7800 | |
| 7719 | static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) { | 7801 | static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) { |
| 7720 | if (dest_val->type->id == TypeTableEntryIdComptimeFloat) { | 7802 | if (dest_val->type->id == ZigTypeIdComptimeFloat) { |
| 7721 | bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat); | 7803 | bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat); |
| 7722 | } else if (dest_val->type->id == TypeTableEntryIdFloat) { | 7804 | } else if (dest_val->type->id == ZigTypeIdFloat) { |
| 7723 | switch (dest_val->type->data.floating.bit_count) { | 7805 | switch (dest_val->type->data.floating.bit_count) { |
| 7724 | case 16: | 7806 | case 16: |
| 7725 | dest_val->data.x_f16 = bigfloat_to_f16(bigfloat); | 7807 | dest_val->data.x_f16 = bigfloat_to_f16(bigfloat); |
| ... | @@ -7742,9 +7824,9 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) { | ... | @@ -7742,9 +7824,9 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) { |
| 7742 | } | 7824 | } |
| 7743 | | 7825 | |
| 7744 | static void float_init_f16(ConstExprValue *dest_val, float16_t x) { | 7826 | static void float_init_f16(ConstExprValue *dest_val, float16_t x) { |
| 7745 | if (dest_val->type->id == TypeTableEntryIdComptimeFloat) { | 7827 | if (dest_val->type->id == ZigTypeIdComptimeFloat) { |
| 7746 | bigfloat_init_16(&dest_val->data.x_bigfloat, x); | 7828 | bigfloat_init_16(&dest_val->data.x_bigfloat, x); |
| 7747 | } else if (dest_val->type->id == TypeTableEntryIdFloat) { | 7829 | } else if (dest_val->type->id == ZigTypeIdFloat) { |
| 7748 | switch (dest_val->type->data.floating.bit_count) { | 7830 | switch (dest_val->type->data.floating.bit_count) { |
| 7749 | case 16: | 7831 | case 16: |
| 7750 | dest_val->data.x_f16 = x; | 7832 | dest_val->data.x_f16 = x; |
| ... | @@ -7767,9 +7849,9 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) { | ... | @@ -7767,9 +7849,9 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) { |
| 7767 | } | 7849 | } |
| 7768 | | 7850 | |
| 7769 | static void float_init_f32(ConstExprValue *dest_val, float x) { | 7851 | static void float_init_f32(ConstExprValue *dest_val, float x) { |
| 7770 | if (dest_val->type->id == TypeTableEntryIdComptimeFloat) { | 7852 | if (dest_val->type->id == ZigTypeIdComptimeFloat) { |
| 7771 | bigfloat_init_32(&dest_val->data.x_bigfloat, x); | 7853 | bigfloat_init_32(&dest_val->data.x_bigfloat, x); |
| 7772 | } else if (dest_val->type->id == TypeTableEntryIdFloat) { | 7854 | } else if (dest_val->type->id == ZigTypeIdFloat) { |
| 7773 | switch (dest_val->type->data.floating.bit_count) { | 7855 | switch (dest_val->type->data.floating.bit_count) { |
| 7774 | case 16: | 7856 | case 16: |
| 7775 | dest_val->data.x_f16 = zig_double_to_f16(x); | 7857 | dest_val->data.x_f16 = zig_double_to_f16(x); |
| ... | @@ -7796,9 +7878,9 @@ static void float_init_f32(ConstExprValue *dest_val, float x) { | ... | @@ -7796,9 +7878,9 @@ static void float_init_f32(ConstExprValue *dest_val, float x) { |
| 7796 | } | 7878 | } |
| 7797 | | 7879 | |
| 7798 | static void float_init_f64(ConstExprValue *dest_val, double x) { | 7880 | static void float_init_f64(ConstExprValue *dest_val, double x) { |
| 7799 | if (dest_val->type->id == TypeTableEntryIdComptimeFloat) { | 7881 | if (dest_val->type->id == ZigTypeIdComptimeFloat) { |
| 7800 | bigfloat_init_64(&dest_val->data.x_bigfloat, x); | 7882 | bigfloat_init_64(&dest_val->data.x_bigfloat, x); |
| 7801 | } else if (dest_val->type->id == TypeTableEntryIdFloat) { | 7883 | } else if (dest_val->type->id == ZigTypeIdFloat) { |
| 7802 | switch (dest_val->type->data.floating.bit_count) { | 7884 | switch (dest_val->type->data.floating.bit_count) { |
| 7803 | case 16: | 7885 | case 16: |
| 7804 | dest_val->data.x_f16 = zig_double_to_f16(x); | 7886 | dest_val->data.x_f16 = zig_double_to_f16(x); |
| ... | @@ -7825,9 +7907,9 @@ static void float_init_f64(ConstExprValue *dest_val, double x) { | ... | @@ -7825,9 +7907,9 @@ static void float_init_f64(ConstExprValue *dest_val, double x) { |
| 7825 | } | 7907 | } |
| 7826 | | 7908 | |
| 7827 | static void float_init_f128(ConstExprValue *dest_val, float128_t x) { | 7909 | static void float_init_f128(ConstExprValue *dest_val, float128_t x) { |
| 7828 | if (dest_val->type->id == TypeTableEntryIdComptimeFloat) { | 7910 | if (dest_val->type->id == ZigTypeIdComptimeFloat) { |
| 7829 | bigfloat_init_128(&dest_val->data.x_bigfloat, x); | 7911 | bigfloat_init_128(&dest_val->data.x_bigfloat, x); |
| 7830 | } else if (dest_val->type->id == TypeTableEntryIdFloat) { | 7912 | } else if (dest_val->type->id == ZigTypeIdFloat) { |
| 7831 | switch (dest_val->type->data.floating.bit_count) { | 7913 | switch (dest_val->type->data.floating.bit_count) { |
| 7832 | case 16: | 7914 | case 16: |
| 7833 | dest_val->data.x_f16 = f128M_to_f16(&x); | 7915 | dest_val->data.x_f16 = f128M_to_f16(&x); |
| ... | @@ -7858,9 +7940,9 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) { | ... | @@ -7858,9 +7940,9 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) { |
| 7858 | } | 7940 | } |
| 7859 | | 7941 | |
| 7860 | static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) { | 7942 | static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) { |
| 7861 | if (src_val->type->id == TypeTableEntryIdComptimeFloat) { | 7943 | if (src_val->type->id == ZigTypeIdComptimeFloat) { |
| 7862 | float_init_bigfloat(dest_val, &src_val->data.x_bigfloat); | 7944 | float_init_bigfloat(dest_val, &src_val->data.x_bigfloat); |
| 7863 | } else if (src_val->type->id == TypeTableEntryIdFloat) { | 7945 | } else if (src_val->type->id == ZigTypeIdFloat) { |
| 7864 | switch (src_val->type->data.floating.bit_count) { | 7946 | switch (src_val->type->data.floating.bit_count) { |
| 7865 | case 16: | 7947 | case 16: |
| 7866 | float_init_f16(dest_val, src_val->data.x_f16); | 7948 | float_init_f16(dest_val, src_val->data.x_f16); |
| ... | @@ -7884,9 +7966,9 @@ static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) | ... | @@ -7884,9 +7966,9 @@ static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) |
| 7884 | | 7966 | |
| 7885 | static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) { | 7967 | static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) { |
| 7886 | assert(op1->type == op2->type); | 7968 | assert(op1->type == op2->type); |
| 7887 | if (op1->type->id == TypeTableEntryIdComptimeFloat) { | 7969 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 7888 | return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat); | 7970 | return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat); |
| 7889 | } else if (op1->type->id == TypeTableEntryIdFloat) { | 7971 | } else if (op1->type->id == ZigTypeIdFloat) { |
| 7890 | switch (op1->type->data.floating.bit_count) { | 7972 | switch (op1->type->data.floating.bit_count) { |
| 7891 | case 16: | 7973 | case 16: |
| 7892 | if (f16_lt(op1->data.x_f16, op2->data.x_f16)) { | 7974 | if (f16_lt(op1->data.x_f16, op2->data.x_f16)) { |
| ... | @@ -7929,9 +8011,9 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) { | ... | @@ -7929,9 +8011,9 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) { |
| 7929 | } | 8011 | } |
| 7930 | | 8012 | |
| 7931 | static Cmp float_cmp_zero(ConstExprValue *op) { | 8013 | static Cmp float_cmp_zero(ConstExprValue *op) { |
| 7932 | if (op->type->id == TypeTableEntryIdComptimeFloat) { | 8014 | if (op->type->id == ZigTypeIdComptimeFloat) { |
| 7933 | return bigfloat_cmp_zero(&op->data.x_bigfloat); | 8015 | return bigfloat_cmp_zero(&op->data.x_bigfloat); |
| 7934 | } else if (op->type->id == TypeTableEntryIdFloat) { | 8016 | } else if (op->type->id == ZigTypeIdFloat) { |
| 7935 | switch (op->type->data.floating.bit_count) { | 8017 | switch (op->type->data.floating.bit_count) { |
| 7936 | case 16: | 8018 | case 16: |
| 7937 | { | 8019 | { |
| ... | @@ -7981,9 +8063,9 @@ static Cmp float_cmp_zero(ConstExprValue *op) { | ... | @@ -7981,9 +8063,9 @@ static Cmp float_cmp_zero(ConstExprValue *op) { |
| 7981 | static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { | 8063 | static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 7982 | assert(op1->type == op2->type); | 8064 | assert(op1->type == op2->type); |
| 7983 | out_val->type = op1->type; | 8065 | out_val->type = op1->type; |
| 7984 | if (op1->type->id == TypeTableEntryIdComptimeFloat) { | 8066 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 7985 | bigfloat_add(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); | 8067 | bigfloat_add(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); |
| 7986 | } else if (op1->type->id == TypeTableEntryIdFloat) { | 8068 | } else if (op1->type->id == ZigTypeIdFloat) { |
| 7987 | switch (op1->type->data.floating.bit_count) { | 8069 | switch (op1->type->data.floating.bit_count) { |
| 7988 | case 16: | 8070 | case 16: |
| 7989 | out_val->data.x_f16 = f16_add(op1->data.x_f16, op2->data.x_f16); | 8071 | out_val->data.x_f16 = f16_add(op1->data.x_f16, op2->data.x_f16); |
| ... | @@ -8008,9 +8090,9 @@ static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal | ... | @@ -8008,9 +8090,9 @@ static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal |
| 8008 | static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { | 8090 | static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 8009 | assert(op1->type == op2->type); | 8091 | assert(op1->type == op2->type); |
| 8010 | out_val->type = op1->type; | 8092 | out_val->type = op1->type; |
| 8011 | if (op1->type->id == TypeTableEntryIdComptimeFloat) { | 8093 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 8012 | bigfloat_sub(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); | 8094 | bigfloat_sub(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); |
| 8013 | } else if (op1->type->id == TypeTableEntryIdFloat) { | 8095 | } else if (op1->type->id == ZigTypeIdFloat) { |
| 8014 | switch (op1->type->data.floating.bit_count) { | 8096 | switch (op1->type->data.floating.bit_count) { |
| 8015 | case 16: | 8097 | case 16: |
| 8016 | out_val->data.x_f16 = f16_sub(op1->data.x_f16, op2->data.x_f16); | 8098 | out_val->data.x_f16 = f16_sub(op1->data.x_f16, op2->data.x_f16); |
| ... | @@ -8035,9 +8117,9 @@ static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal | ... | @@ -8035,9 +8117,9 @@ static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal |
| 8035 | static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { | 8117 | static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 8036 | assert(op1->type == op2->type); | 8118 | assert(op1->type == op2->type); |
| 8037 | out_val->type = op1->type; | 8119 | out_val->type = op1->type; |
| 8038 | if (op1->type->id == TypeTableEntryIdComptimeFloat) { | 8120 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 8039 | bigfloat_mul(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); | 8121 | bigfloat_mul(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); |
| 8040 | } else if (op1->type->id == TypeTableEntryIdFloat) { | 8122 | } else if (op1->type->id == ZigTypeIdFloat) { |
| 8041 | switch (op1->type->data.floating.bit_count) { | 8123 | switch (op1->type->data.floating.bit_count) { |
| 8042 | case 16: | 8124 | case 16: |
| 8043 | out_val->data.x_f16 = f16_mul(op1->data.x_f16, op2->data.x_f16); | 8125 | out_val->data.x_f16 = f16_mul(op1->data.x_f16, op2->data.x_f16); |
| ... | @@ -8062,9 +8144,9 @@ static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal | ... | @@ -8062,9 +8144,9 @@ static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal |
| 8062 | static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { | 8144 | static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 8063 | assert(op1->type == op2->type); | 8145 | assert(op1->type == op2->type); |
| 8064 | out_val->type = op1->type; | 8146 | out_val->type = op1->type; |
| 8065 | if (op1->type->id == TypeTableEntryIdComptimeFloat) { | 8147 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 8066 | bigfloat_div(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); | 8148 | bigfloat_div(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); |
| 8067 | } else if (op1->type->id == TypeTableEntryIdFloat) { | 8149 | } else if (op1->type->id == ZigTypeIdFloat) { |
| 8068 | switch (op1->type->data.floating.bit_count) { | 8150 | switch (op1->type->data.floating.bit_count) { |
| 8069 | case 16: | 8151 | case 16: |
| 8070 | out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16); | 8152 | out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16); |
| ... | @@ -8089,9 +8171,9 @@ static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal | ... | @@ -8089,9 +8171,9 @@ static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal |
| 8089 | static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { | 8171 | static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 8090 | assert(op1->type == op2->type); | 8172 | assert(op1->type == op2->type); |
| 8091 | out_val->type = op1->type; | 8173 | out_val->type = op1->type; |
| 8092 | if (op1->type->id == TypeTableEntryIdComptimeFloat) { | 8174 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 8093 | bigfloat_div_trunc(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); | 8175 | bigfloat_div_trunc(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); |
| 8094 | } else if (op1->type->id == TypeTableEntryIdFloat) { | 8176 | } else if (op1->type->id == ZigTypeIdFloat) { |
| 8095 | switch (op1->type->data.floating.bit_count) { | 8177 | switch (op1->type->data.floating.bit_count) { |
| 8096 | case 16: | 8178 | case 16: |
| 8097 | out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16); | 8179 | out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16); |
| ... | @@ -8118,9 +8200,9 @@ static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstE | ... | @@ -8118,9 +8200,9 @@ static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstE |
| 8118 | static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { | 8200 | static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 8119 | assert(op1->type == op2->type); | 8201 | assert(op1->type == op2->type); |
| 8120 | out_val->type = op1->type; | 8202 | out_val->type = op1->type; |
| 8121 | if (op1->type->id == TypeTableEntryIdComptimeFloat) { | 8203 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 8122 | bigfloat_div_floor(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); | 8204 | bigfloat_div_floor(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); |
| 8123 | } else if (op1->type->id == TypeTableEntryIdFloat) { | 8205 | } else if (op1->type->id == ZigTypeIdFloat) { |
| 8124 | switch (op1->type->data.floating.bit_count) { | 8206 | switch (op1->type->data.floating.bit_count) { |
| 8125 | case 16: | 8207 | case 16: |
| 8126 | out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16); | 8208 | out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16); |
| ... | @@ -8147,9 +8229,9 @@ static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstE | ... | @@ -8147,9 +8229,9 @@ static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstE |
| 8147 | static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { | 8229 | static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 8148 | assert(op1->type == op2->type); | 8230 | assert(op1->type == op2->type); |
| 8149 | out_val->type = op1->type; | 8231 | out_val->type = op1->type; |
| 8150 | if (op1->type->id == TypeTableEntryIdComptimeFloat) { | 8232 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 8151 | bigfloat_rem(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); | 8233 | bigfloat_rem(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); |
| 8152 | } else if (op1->type->id == TypeTableEntryIdFloat) { | 8234 | } else if (op1->type->id == ZigTypeIdFloat) { |
| 8153 | switch (op1->type->data.floating.bit_count) { | 8235 | switch (op1->type->data.floating.bit_count) { |
| 8154 | case 16: | 8236 | case 16: |
| 8155 | out_val->data.x_f16 = f16_rem(op1->data.x_f16, op2->data.x_f16); | 8237 | out_val->data.x_f16 = f16_rem(op1->data.x_f16, op2->data.x_f16); |
| ... | @@ -8192,9 +8274,9 @@ static void zig_f128M_mod(const float128_t* a, const float128_t* b, float128_t* | ... | @@ -8192,9 +8274,9 @@ static void zig_f128M_mod(const float128_t* a, const float128_t* b, float128_t* |
| 8192 | static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { | 8274 | static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 8193 | assert(op1->type == op2->type); | 8275 | assert(op1->type == op2->type); |
| 8194 | out_val->type = op1->type; | 8276 | out_val->type = op1->type; |
| 8195 | if (op1->type->id == TypeTableEntryIdComptimeFloat) { | 8277 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 8196 | bigfloat_mod(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); | 8278 | bigfloat_mod(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); |
| 8197 | } else if (op1->type->id == TypeTableEntryIdFloat) { | 8279 | } else if (op1->type->id == ZigTypeIdFloat) { |
| 8198 | switch (op1->type->data.floating.bit_count) { | 8280 | switch (op1->type->data.floating.bit_count) { |
| 8199 | case 16: | 8281 | case 16: |
| 8200 | out_val->data.x_f16 = zig_f16_mod(op1->data.x_f16, op2->data.x_f16); | 8282 | out_val->data.x_f16 = zig_f16_mod(op1->data.x_f16, op2->data.x_f16); |
| ... | @@ -8218,9 +8300,9 @@ static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal | ... | @@ -8218,9 +8300,9 @@ static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal |
| 8218 | | 8300 | |
| 8219 | static void float_negate(ConstExprValue *out_val, ConstExprValue *op) { | 8301 | static void float_negate(ConstExprValue *out_val, ConstExprValue *op) { |
| 8220 | out_val->type = op->type; | 8302 | out_val->type = op->type; |
| 8221 | if (op->type->id == TypeTableEntryIdComptimeFloat) { | 8303 | if (op->type->id == ZigTypeIdComptimeFloat) { |
| 8222 | bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat); | 8304 | bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat); |
| 8223 | } else if (op->type->id == TypeTableEntryIdFloat) { | 8305 | } else if (op->type->id == ZigTypeIdFloat) { |
| 8224 | switch (op->type->data.floating.bit_count) { | 8306 | switch (op->type->data.floating.bit_count) { |
| 8225 | case 16: | 8307 | case 16: |
| 8226 | { | 8308 | { |
| ... | @@ -8248,7 +8330,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) { | ... | @@ -8248,7 +8330,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) { |
| 8248 | } | 8330 | } |
| 8249 | | 8331 | |
| 8250 | void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) { | 8332 | void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) { |
| 8251 | if (op->type->id == TypeTableEntryIdFloat) { | 8333 | if (op->type->id == ZigTypeIdFloat) { |
| 8252 | switch (op->type->data.floating.bit_count) { | 8334 | switch (op->type->data.floating.bit_count) { |
| 8253 | case 16: | 8335 | case 16: |
| 8254 | memcpy(buf, &op->data.x_f16, 2); // TODO wrong when compiler is big endian | 8336 | memcpy(buf, &op->data.x_f16, 2); // TODO wrong when compiler is big endian |
| ... | @@ -8271,7 +8353,7 @@ void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) { | ... | @@ -8271,7 +8353,7 @@ void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) { |
| 8271 | } | 8353 | } |
| 8272 | | 8354 | |
| 8273 | void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) { | 8355 | void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) { |
| 8274 | if (val->type->id == TypeTableEntryIdFloat) { | 8356 | if (val->type->id == ZigTypeIdFloat) { |
| 8275 | switch (val->type->data.floating.bit_count) { | 8357 | switch (val->type->data.floating.bit_count) { |
| 8276 | case 16: | 8358 | case 16: |
| 8277 | memcpy(&val->data.x_f16, buf, 2); // TODO wrong when compiler is big endian | 8359 | memcpy(&val->data.x_f16, buf, 2); // TODO wrong when compiler is big endian |
| ... | @@ -8293,7 +8375,7 @@ void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) { | ... | @@ -8293,7 +8375,7 @@ void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) { |
| 8293 | } | 8375 | } |
| 8294 | } | 8376 | } |
| 8295 | | 8377 | |
| 8296 | static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, TypeTableEntry *other_type, | 8378 | static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, ZigType *other_type, |
| 8297 | bool explicit_cast) | 8379 | bool explicit_cast) |
| 8298 | { | 8380 | { |
| 8299 | if (type_is_invalid(other_type)) { | 8381 | if (type_is_invalid(other_type)) { |
| ... | @@ -8303,13 +8385,13 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc | ... | @@ -8303,13 +8385,13 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 8303 | ConstExprValue *const_val = &instruction->value; | 8385 | ConstExprValue *const_val = &instruction->value; |
| 8304 | assert(const_val->special != ConstValSpecialRuntime); | 8386 | assert(const_val->special != ConstValSpecialRuntime); |
| 8305 | | 8387 | |
| 8306 | bool const_val_is_int = (const_val->type->id == TypeTableEntryIdInt || | 8388 | bool const_val_is_int = (const_val->type->id == ZigTypeIdInt || |
| 8307 | const_val->type->id == TypeTableEntryIdComptimeInt); | 8389 | const_val->type->id == ZigTypeIdComptimeInt); |
| 8308 | bool const_val_is_float = (const_val->type->id == TypeTableEntryIdFloat || | 8390 | bool const_val_is_float = (const_val->type->id == ZigTypeIdFloat || |
| 8309 | const_val->type->id == TypeTableEntryIdComptimeFloat); | 8391 | const_val->type->id == ZigTypeIdComptimeFloat); |
| 8310 | if (other_type->id == TypeTableEntryIdFloat) { | 8392 | if (other_type->id == ZigTypeIdFloat) { |
| 8311 | return true; | 8393 | return true; |
| 8312 | } else if (other_type->id == TypeTableEntryIdInt && const_val_is_int) { | 8394 | } else if (other_type->id == ZigTypeIdInt && const_val_is_int) { |
| 8313 | if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { | 8395 | if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { |
| 8314 | Buf *val_buf = buf_alloc(); | 8396 | Buf *val_buf = buf_alloc(); |
| 8315 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); | 8397 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); |
| ... | @@ -8326,11 +8408,11 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc | ... | @@ -8326,11 +8408,11 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 8326 | } | 8408 | } |
| 8327 | } else if (const_val_fits_in_num_lit(const_val, other_type)) { | 8409 | } else if (const_val_fits_in_num_lit(const_val, other_type)) { |
| 8328 | return true; | 8410 | return true; |
| 8329 | } else if (other_type->id == TypeTableEntryIdOptional) { | 8411 | } else if (other_type->id == ZigTypeIdOptional) { |
| 8330 | TypeTableEntry *child_type = other_type->data.maybe.child_type; | 8412 | ZigType *child_type = other_type->data.maybe.child_type; |
| 8331 | if (const_val_fits_in_num_lit(const_val, child_type)) { | 8413 | if (const_val_fits_in_num_lit(const_val, child_type)) { |
| 8332 | return true; | 8414 | return true; |
| 8333 | } else if (child_type->id == TypeTableEntryIdInt && const_val_is_int) { | 8415 | } else if (child_type->id == ZigTypeIdInt && const_val_is_int) { |
| 8334 | if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { | 8416 | if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { |
| 8335 | Buf *val_buf = buf_alloc(); | 8417 | Buf *val_buf = buf_alloc(); |
| 8336 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); | 8418 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); |
| ... | @@ -8346,11 +8428,11 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc | ... | @@ -8346,11 +8428,11 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 8346 | { | 8428 | { |
| 8347 | return true; | 8429 | return true; |
| 8348 | } | 8430 | } |
| 8349 | } else if (child_type->id == TypeTableEntryIdFloat && const_val_is_float) { | 8431 | } else if (child_type->id == ZigTypeIdFloat && const_val_is_float) { |
| 8350 | return true; | 8432 | return true; |
| 8351 | } | 8433 | } |
| 8352 | } | 8434 | } |
| 8353 | if (explicit_cast && (other_type->id == TypeTableEntryIdInt || other_type->id == TypeTableEntryIdComptimeInt) && | 8435 | if (explicit_cast && (other_type->id == ZigTypeIdInt || other_type->id == ZigTypeIdComptimeInt) && |
| 8354 | const_val_is_float) | 8436 | const_val_is_float) |
| 8355 | { | 8437 | { |
| 8356 | if (float_has_fraction(const_val)) { | 8438 | if (float_has_fraction(const_val)) { |
| ... | @@ -8363,7 +8445,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc | ... | @@ -8363,7 +8445,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 8363 | buf_ptr(&other_type->name))); | 8445 | buf_ptr(&other_type->name))); |
| 8364 | return false; | 8446 | return false; |
| 8365 | } else { | 8447 | } else { |
| 8366 | if (other_type->id == TypeTableEntryIdComptimeInt) { | 8448 | if (other_type->id == ZigTypeIdComptimeInt) { |
| 8367 | return true; | 8449 | return true; |
| 8368 | } else { | 8450 | } else { |
| 8369 | BigInt bigint; | 8451 | BigInt bigint; |
| ... | @@ -8395,20 +8477,20 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc | ... | @@ -8395,20 +8477,20 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 8395 | return false; | 8477 | return false; |
| 8396 | } | 8478 | } |
| 8397 | | 8479 | |
| 8398 | static bool is_slice(TypeTableEntry *type) { | 8480 | static bool is_slice(ZigType *type) { |
| 8399 | return type->id == TypeTableEntryIdStruct && type->data.structure.is_slice; | 8481 | return type->id == ZigTypeIdStruct && type->data.structure.is_slice; |
| 8400 | } | 8482 | } |
| 8401 | | 8483 | |
| 8402 | static bool slice_is_const(TypeTableEntry *type) { | 8484 | static bool slice_is_const(ZigType *type) { |
| 8403 | assert(is_slice(type)); | 8485 | assert(is_slice(type)); |
| 8404 | return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const; | 8486 | return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const; |
| 8405 | } | 8487 | } |
| 8406 | | 8488 | |
| 8407 | static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry *set1, TypeTableEntry *set2, | 8489 | static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigType *set2, |
| 8408 | AstNode *source_node) | 8490 | AstNode *source_node) |
| 8409 | { | 8491 | { |
| 8410 | assert(set1->id == TypeTableEntryIdErrorSet); | 8492 | assert(set1->id == ZigTypeIdErrorSet); |
| 8411 | assert(set2->id == TypeTableEntryIdErrorSet); | 8493 | assert(set2->id == ZigTypeIdErrorSet); |
| 8412 | | 8494 | |
| 8413 | if (!resolve_inferred_error_set(ira->codegen, set1, source_node)) { | 8495 | if (!resolve_inferred_error_set(ira->codegen, set1, source_node)) { |
| 8414 | return ira->codegen->builtin_types.entry_invalid; | 8496 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -8430,7 +8512,7 @@ static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry | ... | @@ -8430,7 +8512,7 @@ static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry |
| 8430 | } | 8512 | } |
| 8431 | ZigList<ErrorTableEntry *> intersection_list = {}; | 8513 | ZigList<ErrorTableEntry *> intersection_list = {}; |
| 8432 | | 8514 | |
| 8433 | TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); | 8515 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); |
| 8434 | buf_resize(&err_set_type->name, 0); | 8516 | buf_resize(&err_set_type->name, 0); |
| 8435 | buf_appendf(&err_set_type->name, "error{"); | 8517 | buf_appendf(&err_set_type->name, "error{"); |
| 8436 | | 8518 | |
| ... | @@ -8459,8 +8541,8 @@ static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry | ... | @@ -8459,8 +8541,8 @@ static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry |
| 8459 | } | 8541 | } |
| 8460 | | 8542 | |
| 8461 | | 8543 | |
| 8462 | static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry *wanted_type, | 8544 | static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted_type, |
| 8463 | TypeTableEntry *actual_type, AstNode *source_node, bool wanted_is_mutable) | 8545 | ZigType *actual_type, AstNode *source_node, bool wanted_is_mutable) |
| 8464 | { | 8546 | { |
| 8465 | CodeGen *g = ira->codegen; | 8547 | CodeGen *g = ira->codegen; |
| 8466 | ConstCastOnly result = {}; | 8548 | ConstCastOnly result = {}; |
| ... | @@ -8472,9 +8554,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry | ... | @@ -8472,9 +8554,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8472 | // *T and [*]T may const-cast-only to ?*U and ?[*]U, respectively | 8554 | // *T and [*]T may const-cast-only to ?*U and ?[*]U, respectively |
| 8473 | // but not if we want a mutable pointer | 8555 | // but not if we want a mutable pointer |
| 8474 | // and not if the actual pointer has zero bits | 8556 | // and not if the actual pointer has zero bits |
| 8475 | if (!wanted_is_mutable && wanted_type->id == TypeTableEntryIdOptional && | 8557 | if (!wanted_is_mutable && wanted_type->id == ZigTypeIdOptional && |
| 8476 | wanted_type->data.maybe.child_type->id == TypeTableEntryIdPointer && | 8558 | wanted_type->data.maybe.child_type->id == ZigTypeIdPointer && |
| 8477 | actual_type->id == TypeTableEntryIdPointer && type_has_bits(actual_type)) | 8559 | actual_type->id == ZigTypeIdPointer && type_has_bits(actual_type)) |
| 8478 | { | 8560 | { |
| 8479 | ConstCastOnly child = types_match_const_cast_only(ira, | 8561 | ConstCastOnly child = types_match_const_cast_only(ira, |
| 8480 | wanted_type->data.maybe.child_type, actual_type, source_node, wanted_is_mutable); | 8562 | wanted_type->data.maybe.child_type, actual_type, source_node, wanted_is_mutable); |
| ... | @@ -8487,10 +8569,10 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry | ... | @@ -8487,10 +8569,10 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8487 | } | 8569 | } |
| 8488 | | 8570 | |
| 8489 | // *T and [*]T can always cast to *c_void | 8571 | // *T and [*]T can always cast to *c_void |
| 8490 | if (wanted_type->id == TypeTableEntryIdPointer && | 8572 | if (wanted_type->id == ZigTypeIdPointer && |
| 8491 | wanted_type->data.pointer.ptr_len == PtrLenSingle && | 8573 | wanted_type->data.pointer.ptr_len == PtrLenSingle && |
| 8492 | wanted_type->data.pointer.child_type == g->builtin_types.entry_c_void && | 8574 | wanted_type->data.pointer.child_type == g->builtin_types.entry_c_void && |
| 8493 | actual_type->id == TypeTableEntryIdPointer && | 8575 | actual_type->id == ZigTypeIdPointer && |
| 8494 | (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) && | 8576 | (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) && |
| 8495 | (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile)) | 8577 | (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile)) |
| 8496 | { | 8578 | { |
| ... | @@ -8499,7 +8581,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry | ... | @@ -8499,7 +8581,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8499 | } | 8581 | } |
| 8500 | | 8582 | |
| 8501 | // pointer const | 8583 | // pointer const |
| 8502 | if (wanted_type->id == TypeTableEntryIdPointer && actual_type->id == TypeTableEntryIdPointer) { | 8584 | if (wanted_type->id == ZigTypeIdPointer && actual_type->id == ZigTypeIdPointer) { |
| 8503 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, | 8585 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 8504 | actual_type->data.pointer.child_type, source_node, !wanted_type->data.pointer.is_const); | 8586 | actual_type->data.pointer.child_type, source_node, !wanted_type->data.pointer.is_const); |
| 8505 | if (child.id != ConstCastResultIdOk) { | 8587 | if (child.id != ConstCastResultIdOk) { |
| ... | @@ -8523,8 +8605,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry | ... | @@ -8523,8 +8605,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8523 | | 8605 | |
| 8524 | // slice const | 8606 | // slice const |
| 8525 | if (is_slice(wanted_type) && is_slice(actual_type)) { | 8607 | if (is_slice(wanted_type) && is_slice(actual_type)) { |
| 8526 | TypeTableEntry *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry; | 8608 | ZigType *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8527 | TypeTableEntry *wanted_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; | 8609 | ZigType *wanted_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8528 | if ((!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) && | 8610 | if ((!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) && |
| 8529 | (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile) && | 8611 | (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile) && |
| 8530 | actual_ptr_type->data.pointer.bit_offset == wanted_ptr_type->data.pointer.bit_offset && | 8612 | actual_ptr_type->data.pointer.bit_offset == wanted_ptr_type->data.pointer.bit_offset && |
| ... | @@ -8545,7 +8627,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry | ... | @@ -8545,7 +8627,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8545 | } | 8627 | } |
| 8546 | | 8628 | |
| 8547 | // maybe | 8629 | // maybe |
| 8548 | if (wanted_type->id == TypeTableEntryIdOptional && actual_type->id == TypeTableEntryIdOptional) { | 8630 | if (wanted_type->id == ZigTypeIdOptional && actual_type->id == ZigTypeIdOptional) { |
| 8549 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.maybe.child_type, | 8631 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.maybe.child_type, |
| 8550 | actual_type->data.maybe.child_type, source_node, wanted_is_mutable); | 8632 | actual_type->data.maybe.child_type, source_node, wanted_is_mutable); |
| 8551 | if (child.id != ConstCastResultIdOk) { | 8633 | if (child.id != ConstCastResultIdOk) { |
| ... | @@ -8559,7 +8641,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry | ... | @@ -8559,7 +8641,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8559 | } | 8641 | } |
| 8560 | | 8642 | |
| 8561 | // error union | 8643 | // error union |
| 8562 | if (wanted_type->id == TypeTableEntryIdErrorUnion && actual_type->id == TypeTableEntryIdErrorUnion) { | 8644 | if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id == ZigTypeIdErrorUnion) { |
| 8563 | ConstCastOnly payload_child = types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, | 8645 | ConstCastOnly payload_child = types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, |
| 8564 | actual_type->data.error_union.payload_type, source_node, wanted_is_mutable); | 8646 | actual_type->data.error_union.payload_type, source_node, wanted_is_mutable); |
| 8565 | if (payload_child.id != ConstCastResultIdOk) { | 8647 | if (payload_child.id != ConstCastResultIdOk) { |
| ... | @@ -8584,9 +8666,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry | ... | @@ -8584,9 +8666,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8584 | } | 8666 | } |
| 8585 | | 8667 | |
| 8586 | // error set | 8668 | // error set |
| 8587 | if (wanted_type->id == TypeTableEntryIdErrorSet && actual_type->id == TypeTableEntryIdErrorSet) { | 8669 | if (wanted_type->id == ZigTypeIdErrorSet && actual_type->id == ZigTypeIdErrorSet) { |
| 8588 | TypeTableEntry *contained_set = actual_type; | 8670 | ZigType *contained_set = actual_type; |
| 8589 | TypeTableEntry *container_set = wanted_type; | 8671 | ZigType *container_set = wanted_type; |
| 8590 | | 8672 | |
| 8591 | // if the container set is inferred, then this will always work. | 8673 | // if the container set is inferred, then this will always work. |
| 8592 | if (container_set->data.error_set.infer_fn != nullptr) { | 8674 | if (container_set->data.error_set.infer_fn != nullptr) { |
| ... | @@ -8629,14 +8711,14 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry | ... | @@ -8629,14 +8711,14 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8629 | } | 8711 | } |
| 8630 | | 8712 | |
| 8631 | if (wanted_type == ira->codegen->builtin_types.entry_promise && | 8713 | if (wanted_type == ira->codegen->builtin_types.entry_promise && |
| 8632 | actual_type->id == TypeTableEntryIdPromise) | 8714 | actual_type->id == ZigTypeIdPromise) |
| 8633 | { | 8715 | { |
| 8634 | return result; | 8716 | return result; |
| 8635 | } | 8717 | } |
| 8636 | | 8718 | |
| 8637 | // fn | 8719 | // fn |
| 8638 | if (wanted_type->id == TypeTableEntryIdFn && | 8720 | if (wanted_type->id == ZigTypeIdFn && |
| 8639 | actual_type->id == TypeTableEntryIdFn) | 8721 | actual_type->id == ZigTypeIdFn) |
| 8640 | { | 8722 | { |
| 8641 | if (wanted_type->data.fn.fn_type_id.alignment > actual_type->data.fn.fn_type_id.alignment) { | 8723 | if (wanted_type->data.fn.fn_type_id.alignment > actual_type->data.fn.fn_type_id.alignment) { |
| 8642 | result.id = ConstCastResultIdFnAlign; | 8724 | result.id = ConstCastResultIdFnAlign; |
| ... | @@ -8655,7 +8737,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry | ... | @@ -8655,7 +8737,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8655 | return result; | 8737 | return result; |
| 8656 | } | 8738 | } |
| 8657 | if (!wanted_type->data.fn.is_generic && | 8739 | if (!wanted_type->data.fn.is_generic && |
| 8658 | actual_type->data.fn.fn_type_id.return_type->id != TypeTableEntryIdUnreachable) | 8740 | actual_type->data.fn.fn_type_id.return_type->id != ZigTypeIdUnreachable) |
| 8659 | { | 8741 | { |
| 8660 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.fn.fn_type_id.return_type, | 8742 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.fn.fn_type_id.return_type, |
| 8661 | actual_type->data.fn.fn_type_id.return_type, source_node, false); | 8743 | actual_type->data.fn.fn_type_id.return_type, source_node, false); |
| ... | @@ -8725,7 +8807,7 @@ static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t * | ... | @@ -8725,7 +8807,7 @@ static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t * |
| 8725 | *errors = reallocate(*errors, old_errors_count, *errors_count); | 8807 | *errors = reallocate(*errors, old_errors_count, *errors_count); |
| 8726 | } | 8808 | } |
| 8727 | | 8809 | |
| 8728 | static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, TypeTableEntry *expected_type, IrInstruction **instructions, size_t instruction_count) { | 8810 | static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigType *expected_type, IrInstruction **instructions, size_t instruction_count) { |
| 8729 | Error err; | 8811 | Error err; |
| 8730 | assert(instruction_count >= 1); | 8812 | assert(instruction_count >= 1); |
| 8731 | IrInstruction *prev_inst = instructions[0]; | 8813 | IrInstruction *prev_inst = instructions[0]; |
| ... | @@ -8734,8 +8816,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -8734,8 +8816,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8734 | } | 8816 | } |
| 8735 | ErrorTableEntry **errors = nullptr; | 8817 | ErrorTableEntry **errors = nullptr; |
| 8736 | size_t errors_count = 0; | 8818 | size_t errors_count = 0; |
| 8737 | TypeTableEntry *err_set_type = nullptr; | 8819 | ZigType *err_set_type = nullptr; |
| 8738 | if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) { | 8820 | if (prev_inst->value.type->id == ZigTypeIdErrorSet) { |
| 8739 | if (type_is_global_error_set(prev_inst->value.type)) { | 8821 | if (type_is_global_error_set(prev_inst->value.type)) { |
| 8740 | err_set_type = ira->codegen->builtin_types.entry_global_error_set; | 8822 | err_set_type = ira->codegen->builtin_types.entry_global_error_set; |
| 8741 | } else { | 8823 | } else { |
| ... | @@ -8753,29 +8835,29 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -8753,29 +8835,29 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8753 | } | 8835 | } |
| 8754 | } | 8836 | } |
| 8755 | | 8837 | |
| 8756 | bool any_are_null = (prev_inst->value.type->id == TypeTableEntryIdNull); | 8838 | bool any_are_null = (prev_inst->value.type->id == ZigTypeIdNull); |
| 8757 | bool convert_to_const_slice = false; | 8839 | bool convert_to_const_slice = false; |
| 8758 | for (size_t i = 1; i < instruction_count; i += 1) { | 8840 | for (size_t i = 1; i < instruction_count; i += 1) { |
| 8759 | IrInstruction *cur_inst = instructions[i]; | 8841 | IrInstruction *cur_inst = instructions[i]; |
| 8760 | TypeTableEntry *cur_type = cur_inst->value.type; | 8842 | ZigType *cur_type = cur_inst->value.type; |
| 8761 | TypeTableEntry *prev_type = prev_inst->value.type; | 8843 | ZigType *prev_type = prev_inst->value.type; |
| 8762 | | 8844 | |
| 8763 | if (type_is_invalid(cur_type)) { | 8845 | if (type_is_invalid(cur_type)) { |
| 8764 | return cur_type; | 8846 | return cur_type; |
| 8765 | } | 8847 | } |
| 8766 | | 8848 | |
| 8767 | if (prev_type->id == TypeTableEntryIdUnreachable) { | 8849 | if (prev_type->id == ZigTypeIdUnreachable) { |
| 8768 | prev_inst = cur_inst; | 8850 | prev_inst = cur_inst; |
| 8769 | continue; | 8851 | continue; |
| 8770 | } | 8852 | } |
| 8771 | | 8853 | |
| 8772 | if (cur_type->id == TypeTableEntryIdUnreachable) { | 8854 | if (cur_type->id == ZigTypeIdUnreachable) { |
| 8773 | continue; | 8855 | continue; |
| 8774 | } | 8856 | } |
| 8775 | | 8857 | |
| 8776 | if (prev_type->id == TypeTableEntryIdErrorSet) { | 8858 | if (prev_type->id == ZigTypeIdErrorSet) { |
| 8777 | assert(err_set_type != nullptr); | 8859 | assert(err_set_type != nullptr); |
| 8778 | if (cur_type->id == TypeTableEntryIdErrorSet) { | 8860 | if (cur_type->id == ZigTypeIdErrorSet) { |
| 8779 | if (type_is_global_error_set(err_set_type)) { | 8861 | if (type_is_global_error_set(err_set_type)) { |
| 8780 | continue; | 8862 | continue; |
| 8781 | } | 8863 | } |
| ... | @@ -8839,12 +8921,12 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -8839,12 +8921,12 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8839 | err_set_type = get_error_set_union(ira->codegen, errors, cur_type, err_set_type); | 8921 | err_set_type = get_error_set_union(ira->codegen, errors, cur_type, err_set_type); |
| 8840 | assert(errors != nullptr); | 8922 | assert(errors != nullptr); |
| 8841 | continue; | 8923 | continue; |
| 8842 | } else if (cur_type->id == TypeTableEntryIdErrorUnion) { | 8924 | } else if (cur_type->id == ZigTypeIdErrorUnion) { |
| 8843 | if (type_is_global_error_set(err_set_type)) { | 8925 | if (type_is_global_error_set(err_set_type)) { |
| 8844 | prev_inst = cur_inst; | 8926 | prev_inst = cur_inst; |
| 8845 | continue; | 8927 | continue; |
| 8846 | } | 8928 | } |
| 8847 | TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; | 8929 | ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 8848 | if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { | 8930 | if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { |
| 8849 | return ira->codegen->builtin_types.entry_invalid; | 8931 | return ira->codegen->builtin_types.entry_invalid; |
| 8850 | } | 8932 | } |
| ... | @@ -8897,8 +8979,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -8897,8 +8979,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8897 | } | 8979 | } |
| 8898 | } | 8980 | } |
| 8899 | | 8981 | |
| 8900 | if (cur_type->id == TypeTableEntryIdErrorSet) { | 8982 | if (cur_type->id == ZigTypeIdErrorSet) { |
| 8901 | if (prev_type->id == TypeTableEntryIdArray) { | 8983 | if (prev_type->id == ZigTypeIdArray) { |
| 8902 | convert_to_const_slice = true; | 8984 | convert_to_const_slice = true; |
| 8903 | } | 8985 | } |
| 8904 | if (type_is_global_error_set(cur_type)) { | 8986 | if (type_is_global_error_set(cur_type)) { |
| ... | @@ -8915,7 +8997,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -8915,7 +8997,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8915 | update_errors_helper(ira->codegen, &errors, &errors_count); | 8997 | update_errors_helper(ira->codegen, &errors, &errors_count); |
| 8916 | | 8998 | |
| 8917 | if (err_set_type == nullptr) { | 8999 | if (err_set_type == nullptr) { |
| 8918 | if (prev_type->id == TypeTableEntryIdErrorUnion) { | 9000 | if (prev_type->id == ZigTypeIdErrorUnion) { |
| 8919 | err_set_type = prev_type->data.error_union.err_set_type; | 9001 | err_set_type = prev_type->data.error_union.err_set_type; |
| 8920 | } else { | 9002 | } else { |
| 8921 | err_set_type = cur_type; | 9003 | err_set_type = cur_type; |
| ... | @@ -8948,9 +9030,9 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -8948,9 +9030,9 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8948 | continue; | 9030 | continue; |
| 8949 | } | 9031 | } |
| 8950 | | 9032 | |
| 8951 | if (prev_type->id == TypeTableEntryIdErrorUnion && cur_type->id == TypeTableEntryIdErrorUnion) { | 9033 | if (prev_type->id == ZigTypeIdErrorUnion && cur_type->id == ZigTypeIdErrorUnion) { |
| 8952 | TypeTableEntry *prev_payload_type = prev_type->data.error_union.payload_type; | 9034 | ZigType *prev_payload_type = prev_type->data.error_union.payload_type; |
| 8953 | TypeTableEntry *cur_payload_type = cur_type->data.error_union.payload_type; | 9035 | ZigType *cur_payload_type = cur_type->data.error_union.payload_type; |
| 8954 | | 9036 | |
| 8955 | bool const_cast_prev = types_match_const_cast_only(ira, prev_payload_type, cur_payload_type, | 9037 | bool const_cast_prev = types_match_const_cast_only(ira, prev_payload_type, cur_payload_type, |
| 8956 | source_node, false).id == ConstCastResultIdOk; | 9038 | source_node, false).id == ConstCastResultIdOk; |
| ... | @@ -8962,8 +9044,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -8962,8 +9044,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8962 | prev_inst = cur_inst; | 9044 | prev_inst = cur_inst; |
| 8963 | } | 9045 | } |
| 8964 | | 9046 | |
| 8965 | TypeTableEntry *prev_err_set_type = (err_set_type == nullptr) ? prev_type->data.error_union.err_set_type : err_set_type; | 9047 | ZigType *prev_err_set_type = (err_set_type == nullptr) ? prev_type->data.error_union.err_set_type : err_set_type; |
| 8966 | TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; | 9048 | ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 8967 | | 9049 | |
| 8968 | if (!resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) { | 9050 | if (!resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) { |
| 8969 | return ira->codegen->builtin_types.entry_invalid; | 9051 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -9032,12 +9114,12 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -9032,12 +9114,12 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9032 | } | 9114 | } |
| 9033 | } | 9115 | } |
| 9034 | | 9116 | |
| 9035 | if (prev_type->id == TypeTableEntryIdNull) { | 9117 | if (prev_type->id == ZigTypeIdNull) { |
| 9036 | prev_inst = cur_inst; | 9118 | prev_inst = cur_inst; |
| 9037 | continue; | 9119 | continue; |
| 9038 | } | 9120 | } |
| 9039 | | 9121 | |
| 9040 | if (cur_type->id == TypeTableEntryIdNull) { | 9122 | if (cur_type->id == ZigTypeIdNull) { |
| 9041 | any_are_null = true; | 9123 | any_are_null = true; |
| 9042 | continue; | 9124 | continue; |
| 9043 | } | 9125 | } |
| ... | @@ -9051,8 +9133,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -9051,8 +9133,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9051 | continue; | 9133 | continue; |
| 9052 | } | 9134 | } |
| 9053 | | 9135 | |
| 9054 | if (prev_type->id == TypeTableEntryIdInt && | 9136 | if (prev_type->id == ZigTypeIdInt && |
| 9055 | cur_type->id == TypeTableEntryIdInt && | 9137 | cur_type->id == ZigTypeIdInt && |
| 9056 | prev_type->data.integral.is_signed == cur_type->data.integral.is_signed) | 9138 | prev_type->data.integral.is_signed == cur_type->data.integral.is_signed) |
| 9057 | { | 9139 | { |
| 9058 | if (cur_type->data.integral.bit_count > prev_type->data.integral.bit_count) { | 9140 | if (cur_type->data.integral.bit_count > prev_type->data.integral.bit_count) { |
| ... | @@ -9061,26 +9143,26 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -9061,26 +9143,26 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9061 | continue; | 9143 | continue; |
| 9062 | } | 9144 | } |
| 9063 | | 9145 | |
| 9064 | if (prev_type->id == TypeTableEntryIdFloat && cur_type->id == TypeTableEntryIdFloat) { | 9146 | if (prev_type->id == ZigTypeIdFloat && cur_type->id == ZigTypeIdFloat) { |
| 9065 | if (cur_type->data.floating.bit_count > prev_type->data.floating.bit_count) { | 9147 | if (cur_type->data.floating.bit_count > prev_type->data.floating.bit_count) { |
| 9066 | prev_inst = cur_inst; | 9148 | prev_inst = cur_inst; |
| 9067 | } | 9149 | } |
| 9068 | continue; | 9150 | continue; |
| 9069 | } | 9151 | } |
| 9070 | | 9152 | |
| 9071 | if (prev_type->id == TypeTableEntryIdErrorUnion && | 9153 | if (prev_type->id == ZigTypeIdErrorUnion && |
| 9072 | types_match_const_cast_only(ira, prev_type->data.error_union.payload_type, cur_type, | 9154 | types_match_const_cast_only(ira, prev_type->data.error_union.payload_type, cur_type, |
| 9073 | source_node, false).id == ConstCastResultIdOk) | 9155 | source_node, false).id == ConstCastResultIdOk) |
| 9074 | { | 9156 | { |
| 9075 | continue; | 9157 | continue; |
| 9076 | } | 9158 | } |
| 9077 | | 9159 | |
| 9078 | if (cur_type->id == TypeTableEntryIdErrorUnion && | 9160 | if (cur_type->id == ZigTypeIdErrorUnion && |
| 9079 | types_match_const_cast_only(ira, cur_type->data.error_union.payload_type, prev_type, | 9161 | types_match_const_cast_only(ira, cur_type->data.error_union.payload_type, prev_type, |
| 9080 | source_node, false).id == ConstCastResultIdOk) | 9162 | source_node, false).id == ConstCastResultIdOk) |
| 9081 | { | 9163 | { |
| 9082 | if (err_set_type != nullptr) { | 9164 | if (err_set_type != nullptr) { |
| 9083 | TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; | 9165 | ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 9084 | if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { | 9166 | if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { |
| 9085 | return ira->codegen->builtin_types.entry_invalid; | 9167 | return ira->codegen->builtin_types.entry_invalid; |
| 9086 | } | 9168 | } |
| ... | @@ -9098,14 +9180,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -9098,14 +9180,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9098 | continue; | 9180 | continue; |
| 9099 | } | 9181 | } |
| 9100 | | 9182 | |
| 9101 | if (prev_type->id == TypeTableEntryIdOptional && | 9183 | if (prev_type->id == ZigTypeIdOptional && |
| 9102 | types_match_const_cast_only(ira, prev_type->data.maybe.child_type, cur_type, | 9184 | types_match_const_cast_only(ira, prev_type->data.maybe.child_type, cur_type, |
| 9103 | source_node, false).id == ConstCastResultIdOk) | 9185 | source_node, false).id == ConstCastResultIdOk) |
| 9104 | { | 9186 | { |
| 9105 | continue; | 9187 | continue; |
| 9106 | } | 9188 | } |
| 9107 | | 9189 | |
| 9108 | if (cur_type->id == TypeTableEntryIdOptional && | 9190 | if (cur_type->id == ZigTypeIdOptional && |
| 9109 | types_match_const_cast_only(ira, cur_type->data.maybe.child_type, prev_type, | 9191 | types_match_const_cast_only(ira, cur_type->data.maybe.child_type, prev_type, |
| 9110 | source_node, false).id == ConstCastResultIdOk) | 9192 | source_node, false).id == ConstCastResultIdOk) |
| 9111 | { | 9193 | { |
| ... | @@ -9113,17 +9195,17 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -9113,17 +9195,17 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9113 | continue; | 9195 | continue; |
| 9114 | } | 9196 | } |
| 9115 | | 9197 | |
| 9116 | if (cur_type->id == TypeTableEntryIdUndefined) { | 9198 | if (cur_type->id == ZigTypeIdUndefined) { |
| 9117 | continue; | 9199 | continue; |
| 9118 | } | 9200 | } |
| 9119 | | 9201 | |
| 9120 | if (prev_type->id == TypeTableEntryIdUndefined) { | 9202 | if (prev_type->id == ZigTypeIdUndefined) { |
| 9121 | prev_inst = cur_inst; | 9203 | prev_inst = cur_inst; |
| 9122 | continue; | 9204 | continue; |
| 9123 | } | 9205 | } |
| 9124 | | 9206 | |
| 9125 | if (prev_type->id == TypeTableEntryIdComptimeInt || | 9207 | if (prev_type->id == ZigTypeIdComptimeInt || |
| 9126 | prev_type->id == TypeTableEntryIdComptimeFloat) | 9208 | prev_type->id == ZigTypeIdComptimeFloat) |
| 9127 | { | 9209 | { |
| 9128 | if (ir_num_lit_fits_in_other_type(ira, prev_inst, cur_type, false)) { | 9210 | if (ir_num_lit_fits_in_other_type(ira, prev_inst, cur_type, false)) { |
| 9129 | prev_inst = cur_inst; | 9211 | prev_inst = cur_inst; |
| ... | @@ -9133,8 +9215,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -9133,8 +9215,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9133 | } | 9215 | } |
| 9134 | } | 9216 | } |
| 9135 | | 9217 | |
| 9136 | if (cur_type->id == TypeTableEntryIdComptimeInt || | 9218 | if (cur_type->id == ZigTypeIdComptimeInt || |
| 9137 | cur_type->id == TypeTableEntryIdComptimeFloat) | 9219 | cur_type->id == ZigTypeIdComptimeFloat) |
| 9138 | { | 9220 | { |
| 9139 | if (ir_num_lit_fits_in_other_type(ira, cur_inst, prev_type, false)) { | 9221 | if (ir_num_lit_fits_in_other_type(ira, cur_inst, prev_type, false)) { |
| 9140 | continue; | 9222 | continue; |
| ... | @@ -9143,7 +9225,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -9143,7 +9225,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9143 | } | 9225 | } |
| 9144 | } | 9226 | } |
| 9145 | | 9227 | |
| 9146 | if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && | 9228 | if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray && |
| 9147 | cur_type->data.array.len != prev_type->data.array.len && | 9229 | cur_type->data.array.len != prev_type->data.array.len && |
| 9148 | types_match_const_cast_only(ira, cur_type->data.array.child_type, prev_type->data.array.child_type, | 9230 | types_match_const_cast_only(ira, cur_type->data.array.child_type, prev_type->data.array.child_type, |
| 9149 | source_node, false).id == ConstCastResultIdOk) | 9231 | source_node, false).id == ConstCastResultIdOk) |
| ... | @@ -9153,7 +9235,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -9153,7 +9235,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9153 | continue; | 9235 | continue; |
| 9154 | } | 9236 | } |
| 9155 | | 9237 | |
| 9156 | if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && | 9238 | if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray && |
| 9157 | cur_type->data.array.len != prev_type->data.array.len && | 9239 | cur_type->data.array.len != prev_type->data.array.len && |
| 9158 | types_match_const_cast_only(ira, prev_type->data.array.child_type, cur_type->data.array.child_type, | 9240 | types_match_const_cast_only(ira, prev_type->data.array.child_type, cur_type->data.array.child_type, |
| 9159 | source_node, false).id == ConstCastResultIdOk) | 9241 | source_node, false).id == ConstCastResultIdOk) |
| ... | @@ -9162,7 +9244,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -9162,7 +9244,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9162 | continue; | 9244 | continue; |
| 9163 | } | 9245 | } |
| 9164 | | 9246 | |
| 9165 | if (cur_type->id == TypeTableEntryIdArray && is_slice(prev_type) && | 9247 | if (cur_type->id == ZigTypeIdArray && is_slice(prev_type) && |
| 9166 | (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || | 9248 | (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || |
| 9167 | cur_type->data.array.len == 0) && | 9249 | cur_type->data.array.len == 0) && |
| 9168 | types_match_const_cast_only(ira, | 9250 | types_match_const_cast_only(ira, |
| ... | @@ -9173,7 +9255,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -9173,7 +9255,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9173 | continue; | 9255 | continue; |
| 9174 | } | 9256 | } |
| 9175 | | 9257 | |
| 9176 | if (prev_type->id == TypeTableEntryIdArray && is_slice(cur_type) && | 9258 | if (prev_type->id == ZigTypeIdArray && is_slice(cur_type) && |
| 9177 | (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || | 9259 | (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || |
| 9178 | prev_type->data.array.len == 0) && | 9260 | prev_type->data.array.len == 0) && |
| 9179 | types_match_const_cast_only(ira, | 9261 | types_match_const_cast_only(ira, |
| ... | @@ -9185,7 +9267,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -9185,7 +9267,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9185 | continue; | 9267 | continue; |
| 9186 | } | 9268 | } |
| 9187 | | 9269 | |
| 9188 | if (prev_type->id == TypeTableEntryIdEnum && cur_type->id == TypeTableEntryIdUnion && | 9270 | if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion && |
| 9189 | (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) | 9271 | (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) |
| 9190 | { | 9272 | { |
| 9191 | if ((err = type_ensure_zero_bits_known(ira->codegen, cur_type))) | 9273 | if ((err = type_ensure_zero_bits_known(ira->codegen, cur_type))) |
| ... | @@ -9195,7 +9277,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -9195,7 +9277,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9195 | } | 9277 | } |
| 9196 | } | 9278 | } |
| 9197 | | 9279 | |
| 9198 | if (cur_type->id == TypeTableEntryIdEnum && prev_type->id == TypeTableEntryIdUnion && | 9280 | if (cur_type->id == ZigTypeIdEnum && prev_type->id == ZigTypeIdUnion && |
| 9199 | (prev_type->data.unionation.decl_node->data.container_decl.auto_enum || prev_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) | 9281 | (prev_type->data.unionation.decl_node->data.container_decl.auto_enum || prev_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) |
| 9200 | { | 9282 | { |
| 9201 | if ((err = type_ensure_zero_bits_known(ira->codegen, prev_type))) | 9283 | if ((err = type_ensure_zero_bits_known(ira->codegen, prev_type))) |
| ... | @@ -9220,33 +9302,33 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -9220,33 +9302,33 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9220 | free(errors); | 9302 | free(errors); |
| 9221 | | 9303 | |
| 9222 | if (convert_to_const_slice) { | 9304 | if (convert_to_const_slice) { |
| 9223 | assert(prev_inst->value.type->id == TypeTableEntryIdArray); | 9305 | assert(prev_inst->value.type->id == ZigTypeIdArray); |
| 9224 | TypeTableEntry *ptr_type = get_pointer_to_type_extra( | 9306 | ZigType *ptr_type = get_pointer_to_type_extra( |
| 9225 | ira->codegen, prev_inst->value.type->data.array.child_type, | 9307 | ira->codegen, prev_inst->value.type->data.array.child_type, |
| 9226 | true, false, PtrLenUnknown, | 9308 | true, false, PtrLenUnknown, |
| 9227 | get_abi_alignment(ira->codegen, prev_inst->value.type->data.array.child_type), | 9309 | get_abi_alignment(ira->codegen, prev_inst->value.type->data.array.child_type), |
| 9228 | 0, 0); | 9310 | 0, 0); |
| 9229 | TypeTableEntry *slice_type = get_slice_type(ira->codegen, ptr_type); | 9311 | ZigType *slice_type = get_slice_type(ira->codegen, ptr_type); |
| 9230 | if (err_set_type != nullptr) { | 9312 | if (err_set_type != nullptr) { |
| 9231 | return get_error_union_type(ira->codegen, err_set_type, slice_type); | 9313 | return get_error_union_type(ira->codegen, err_set_type, slice_type); |
| 9232 | } else { | 9314 | } else { |
| 9233 | return slice_type; | 9315 | return slice_type; |
| 9234 | } | 9316 | } |
| 9235 | } else if (err_set_type != nullptr) { | 9317 | } else if (err_set_type != nullptr) { |
| 9236 | if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) { | 9318 | if (prev_inst->value.type->id == ZigTypeIdErrorSet) { |
| 9237 | return err_set_type; | 9319 | return err_set_type; |
| 9238 | } else if (prev_inst->value.type->id == TypeTableEntryIdErrorUnion) { | 9320 | } else if (prev_inst->value.type->id == ZigTypeIdErrorUnion) { |
| 9239 | return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type->data.error_union.payload_type); | 9321 | return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type->data.error_union.payload_type); |
| 9240 | } else if (expected_type != nullptr && expected_type->id == TypeTableEntryIdErrorUnion) { | 9322 | } else if (expected_type != nullptr && expected_type->id == ZigTypeIdErrorUnion) { |
| 9241 | return get_error_union_type(ira->codegen, err_set_type, expected_type->data.error_union.payload_type); | 9323 | return get_error_union_type(ira->codegen, err_set_type, expected_type->data.error_union.payload_type); |
| 9242 | } else { | 9324 | } else { |
| 9243 | if (prev_inst->value.type->id == TypeTableEntryIdComptimeInt || | 9325 | if (prev_inst->value.type->id == ZigTypeIdComptimeInt || |
| 9244 | prev_inst->value.type->id == TypeTableEntryIdComptimeFloat) | 9326 | prev_inst->value.type->id == ZigTypeIdComptimeFloat) |
| 9245 | { | 9327 | { |
| 9246 | ir_add_error_node(ira, source_node, | 9328 | ir_add_error_node(ira, source_node, |
| 9247 | buf_sprintf("unable to make error union out of number literal")); | 9329 | buf_sprintf("unable to make error union out of number literal")); |
| 9248 | return ira->codegen->builtin_types.entry_invalid; | 9330 | return ira->codegen->builtin_types.entry_invalid; |
| 9249 | } else if (prev_inst->value.type->id == TypeTableEntryIdNull) { | 9331 | } else if (prev_inst->value.type->id == ZigTypeIdNull) { |
| 9250 | ir_add_error_node(ira, source_node, | 9332 | ir_add_error_node(ira, source_node, |
| 9251 | buf_sprintf("unable to make error union out of null literal")); | 9333 | buf_sprintf("unable to make error union out of null literal")); |
| 9252 | return ira->codegen->builtin_types.entry_invalid; | 9334 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -9254,14 +9336,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -9254,14 +9336,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9254 | return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type); | 9336 | return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type); |
| 9255 | } | 9337 | } |
| 9256 | } | 9338 | } |
| 9257 | } else if (any_are_null && prev_inst->value.type->id != TypeTableEntryIdNull) { | 9339 | } else if (any_are_null && prev_inst->value.type->id != ZigTypeIdNull) { |
| 9258 | if (prev_inst->value.type->id == TypeTableEntryIdComptimeInt || | 9340 | if (prev_inst->value.type->id == ZigTypeIdComptimeInt || |
| 9259 | prev_inst->value.type->id == TypeTableEntryIdComptimeFloat) | 9341 | prev_inst->value.type->id == ZigTypeIdComptimeFloat) |
| 9260 | { | 9342 | { |
| 9261 | ir_add_error_node(ira, source_node, | 9343 | ir_add_error_node(ira, source_node, |
| 9262 | buf_sprintf("unable to make maybe out of number literal")); | 9344 | buf_sprintf("unable to make maybe out of number literal")); |
| 9263 | return ira->codegen->builtin_types.entry_invalid; | 9345 | return ira->codegen->builtin_types.entry_invalid; |
| 9264 | } else if (prev_inst->value.type->id == TypeTableEntryIdOptional) { | 9346 | } else if (prev_inst->value.type->id == ZigTypeIdOptional) { |
| 9265 | return prev_inst->value.type; | 9347 | return prev_inst->value.type; |
| 9266 | } else { | 9348 | } else { |
| 9267 | return get_optional_type(ira->codegen, prev_inst->value.type); | 9349 | return get_optional_type(ira->codegen, prev_inst->value.type); |
| ... | @@ -9271,9 +9353,9 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod | ... | @@ -9271,9 +9353,9 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9271 | } | 9353 | } |
| 9272 | } | 9354 | } |
| 9273 | | 9355 | |
| 9274 | static void ir_add_alloca(IrAnalyze *ira, IrInstruction *instruction, TypeTableEntry *type_entry) { | 9356 | static void ir_add_alloca(IrAnalyze *ira, IrInstruction *instruction, ZigType *type_entry) { |
| 9275 | if (type_has_bits(type_entry) && handle_is_ptr(type_entry)) { | 9357 | if (type_has_bits(type_entry) && handle_is_ptr(type_entry)) { |
| 9276 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); | 9358 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 9277 | if (fn_entry != nullptr) { | 9359 | if (fn_entry != nullptr) { |
| 9278 | fn_entry->alloca_list.append(instruction); | 9360 | fn_entry->alloca_list.append(instruction); |
| 9279 | } | 9361 | } |
| ... | @@ -9285,7 +9367,7 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_ | ... | @@ -9285,7 +9367,7 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_ |
| 9285 | *dest = *src; | 9367 | *dest = *src; |
| 9286 | if (!same_global_refs) { | 9368 | if (!same_global_refs) { |
| 9287 | dest->global_refs = global_refs; | 9369 | dest->global_refs = global_refs; |
| 9288 | if (dest->type->id == TypeTableEntryIdStruct) { | 9370 | if (dest->type->id == ZigTypeIdStruct) { |
| 9289 | dest->data.x_struct.fields = allocate_nonzero<ConstExprValue>(dest->type->data.structure.src_field_count); | 9371 | dest->data.x_struct.fields = allocate_nonzero<ConstExprValue>(dest->type->data.structure.src_field_count); |
| 9290 | memcpy(dest->data.x_struct.fields, src->data.x_struct.fields, sizeof(ConstExprValue) * dest->type->data.structure.src_field_count); | 9372 | memcpy(dest->data.x_struct.fields, src->data.x_struct.fields, sizeof(ConstExprValue) * dest->type->data.structure.src_field_count); |
| 9291 | } | 9373 | } |
| ... | @@ -9294,8 +9376,8 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_ | ... | @@ -9294,8 +9376,8 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_ |
| 9294 | | 9376 | |
| 9295 | static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr, | 9377 | static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr, |
| 9296 | CastOp cast_op, | 9378 | CastOp cast_op, |
| 9297 | ConstExprValue *other_val, TypeTableEntry *other_type, | 9379 | ConstExprValue *other_val, ZigType *other_type, |
| 9298 | ConstExprValue *const_val, TypeTableEntry *new_type) | 9380 | ConstExprValue *const_val, ZigType *new_type) |
| 9299 | { | 9381 | { |
| 9300 | const_val->special = other_val->special; | 9382 | const_val->special = other_val->special; |
| 9301 | | 9383 | |
| ... | @@ -9315,8 +9397,8 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ | ... | @@ -9315,8 +9397,8 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 9315 | break; | 9397 | break; |
| 9316 | } | 9398 | } |
| 9317 | case CastOpNumLitToConcrete: | 9399 | case CastOpNumLitToConcrete: |
| 9318 | if (other_val->type->id == TypeTableEntryIdComptimeFloat) { | 9400 | if (other_val->type->id == ZigTypeIdComptimeFloat) { |
| 9319 | assert(new_type->id == TypeTableEntryIdFloat); | 9401 | assert(new_type->id == ZigTypeIdFloat); |
| 9320 | switch (new_type->data.floating.bit_count) { | 9402 | switch (new_type->data.floating.bit_count) { |
| 9321 | case 16: | 9403 | case 16: |
| 9322 | const_val->data.x_f16 = bigfloat_to_f16(&other_val->data.x_bigfloat); | 9404 | const_val->data.x_f16 = bigfloat_to_f16(&other_val->data.x_bigfloat); |
| ... | @@ -9333,7 +9415,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ | ... | @@ -9333,7 +9415,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 9333 | default: | 9415 | default: |
| 9334 | zig_unreachable(); | 9416 | zig_unreachable(); |
| 9335 | } | 9417 | } |
| 9336 | } else if (other_val->type->id == TypeTableEntryIdComptimeInt) { | 9418 | } else if (other_val->type->id == ZigTypeIdComptimeInt) { |
| 9337 | bigint_init_bigint(&const_val->data.x_bigint, &other_val->data.x_bigint); | 9419 | bigint_init_bigint(&const_val->data.x_bigint, &other_val->data.x_bigint); |
| 9338 | } else { | 9420 | } else { |
| 9339 | zig_unreachable(); | 9421 | zig_unreachable(); |
| ... | @@ -9346,7 +9428,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ | ... | @@ -9346,7 +9428,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 9346 | zig_unreachable(); | 9428 | zig_unreachable(); |
| 9347 | case CastOpIntToFloat: | 9429 | case CastOpIntToFloat: |
| 9348 | { | 9430 | { |
| 9349 | assert(new_type->id == TypeTableEntryIdFloat); | 9431 | assert(new_type->id == ZigTypeIdFloat); |
| 9350 | | 9432 | |
| 9351 | BigFloat bigfloat; | 9433 | BigFloat bigfloat; |
| 9352 | bigfloat_init_bigint(&bigfloat, &other_val->data.x_bigint); | 9434 | bigfloat_init_bigint(&bigfloat, &other_val->data.x_bigint); |
| ... | @@ -9371,7 +9453,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ | ... | @@ -9371,7 +9453,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 9371 | } | 9453 | } |
| 9372 | case CastOpFloatToInt: | 9454 | case CastOpFloatToInt: |
| 9373 | float_init_bigint(&const_val->data.x_bigint, other_val); | 9455 | float_init_bigint(&const_val->data.x_bigint, other_val); |
| 9374 | if (new_type->id == TypeTableEntryIdInt) { | 9456 | if (new_type->id == ZigTypeIdInt) { |
| 9375 | if (!bigint_fits_in_bits(&const_val->data.x_bigint, new_type->data.integral.bit_count, | 9457 | if (!bigint_fits_in_bits(&const_val->data.x_bigint, new_type->data.integral.bit_count, |
| 9376 | new_type->data.integral.is_signed)) | 9458 | new_type->data.integral.is_signed)) |
| 9377 | { | 9459 | { |
| ... | @@ -9395,7 +9477,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ | ... | @@ -9395,7 +9477,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 9395 | return true; | 9477 | return true; |
| 9396 | } | 9478 | } |
| 9397 | static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, | 9479 | static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 9398 | TypeTableEntry *wanted_type, CastOp cast_op, bool need_alloca) | 9480 | ZigType *wanted_type, CastOp cast_op, bool need_alloca) |
| 9399 | { | 9481 | { |
| 9400 | if ((instr_is_comptime(value) || !type_has_bits(wanted_type)) && | 9482 | if ((instr_is_comptime(value) || !type_has_bits(wanted_type)) && |
| 9401 | cast_op != CastOpResizeSlice && cast_op != CastOpBytesToSlice) | 9483 | cast_op != CastOpResizeSlice && cast_op != CastOpBytesToSlice) |
| ... | @@ -9419,13 +9501,15 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -9419,13 +9501,15 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 9419 | } | 9501 | } |
| 9420 | | 9502 | |
| 9421 | static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr, | 9503 | static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 9422 | IrInstruction *value, TypeTableEntry *wanted_type) | 9504 | IrInstruction *value, ZigType *wanted_type) |
| 9423 | { | 9505 | { |
| 9424 | assert(value->value.type->id == TypeTableEntryIdPointer); | 9506 | assert(value->value.type->id == ZigTypeIdPointer); |
| 9425 | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment); | 9507 | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment); |
| 9426 | | 9508 | |
| 9427 | if (instr_is_comptime(value)) { | 9509 | if (instr_is_comptime(value)) { |
| 9428 | ConstExprValue *pointee = const_ptr_pointee(ira->codegen, &value->value); | 9510 | ConstExprValue *pointee = ir_const_ptr_pointee(ira, &value->value, source_instr->source_node); |
| | 9511 | if (pointee == nullptr) |
| | 9512 | return ira->codegen->invalid_instruction; |
| 9429 | if (pointee->special != ConstValSpecialRuntime) { | 9513 | if (pointee->special != ConstValSpecialRuntime) { |
| 9430 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, | 9514 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, |
| 9431 | source_instr->source_node, wanted_type); | 9515 | source_instr->source_node, wanted_type); |
| ... | @@ -9446,15 +9530,17 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, | ... | @@ -9446,15 +9530,17 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, |
| 9446 | } | 9530 | } |
| 9447 | | 9531 | |
| 9448 | static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr, | 9532 | static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr, |
| 9449 | IrInstruction *value, TypeTableEntry *wanted_type) | 9533 | IrInstruction *value, ZigType *wanted_type) |
| 9450 | { | 9534 | { |
| 9451 | wanted_type = adjust_slice_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment); | 9535 | wanted_type = adjust_slice_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment); |
| 9452 | | 9536 | |
| 9453 | if (instr_is_comptime(value)) { | 9537 | if (instr_is_comptime(value)) { |
| 9454 | ConstExprValue *pointee = const_ptr_pointee(ira->codegen, &value->value); | 9538 | ConstExprValue *pointee = ir_const_ptr_pointee(ira, &value->value, source_instr->source_node); |
| | 9539 | if (pointee == nullptr) |
| | 9540 | return ira->codegen->invalid_instruction; |
| 9455 | if (pointee->special != ConstValSpecialRuntime) { | 9541 | if (pointee->special != ConstValSpecialRuntime) { |
| 9456 | assert(value->value.type->id == TypeTableEntryIdPointer); | 9542 | assert(value->value.type->id == ZigTypeIdPointer); |
| 9457 | TypeTableEntry *array_type = value->value.type->data.pointer.child_type; | 9543 | ZigType *array_type = value->value.type->data.pointer.child_type; |
| 9458 | assert(is_slice(wanted_type)); | 9544 | assert(is_slice(wanted_type)); |
| 9459 | bool is_const = wanted_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const; | 9545 | bool is_const = wanted_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const; |
| 9460 | | 9546 | |
| ... | @@ -9475,10 +9561,10 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc | ... | @@ -9475,10 +9561,10 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc |
| 9475 | return result; | 9561 | return result; |
| 9476 | } | 9562 | } |
| 9477 | | 9563 | |
| 9478 | static bool is_container(TypeTableEntry *type) { | 9564 | static bool is_container(ZigType *type) { |
| 9479 | return type->id == TypeTableEntryIdStruct || | 9565 | return type->id == ZigTypeIdStruct || |
| 9480 | type->id == TypeTableEntryIdEnum || | 9566 | type->id == ZigTypeIdEnum || |
| 9481 | type->id == TypeTableEntryIdUnion; | 9567 | type->id == ZigTypeIdUnion; |
| 9482 | } | 9568 | } |
| 9483 | | 9569 | |
| 9484 | static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) { | 9570 | static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) { |
| ... | @@ -9496,6 +9582,19 @@ static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstr | ... | @@ -9496,6 +9582,19 @@ static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstr |
| 9496 | return new_bb; | 9582 | return new_bb; |
| 9497 | } | 9583 | } |
| 9498 | | 9584 | |
| | 9585 | static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) { |
| | 9586 | assert(ref_old_instruction != nullptr); |
| | 9587 | IrBasicBlock *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction); |
| | 9588 | if (new_bb->must_be_comptime_source_instr) { |
| | 9589 | ErrorMsg *msg = ir_add_error(ira, ref_old_instruction, |
| | 9590 | buf_sprintf("control flow attempts to use compile-time variable at runtime")); |
| | 9591 | add_error_note(ira->codegen, msg, new_bb->must_be_comptime_source_instr->source_node, |
| | 9592 | buf_sprintf("compile-time variable assigned here")); |
| | 9593 | return nullptr; |
| | 9594 | } |
| | 9595 | return new_bb; |
| | 9596 | } |
| | 9597 | |
| 9499 | static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *const_predecessor_bb) { | 9598 | static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *const_predecessor_bb) { |
| 9500 | ira->instruction_index = 0; | 9599 | ira->instruction_index = 0; |
| 9501 | ira->old_irb.current_basic_block = old_bb; | 9600 | ira->old_irb.current_basic_block = old_bb; |
| ... | @@ -9541,7 +9640,7 @@ static void ir_finish_bb(IrAnalyze *ira) { | ... | @@ -9541,7 +9640,7 @@ static void ir_finish_bb(IrAnalyze *ira) { |
| 9541 | } | 9640 | } |
| 9542 | } | 9641 | } |
| 9543 | | 9642 | |
| 9544 | static TypeTableEntry *ir_unreach_error(IrAnalyze *ira) { | 9643 | static ZigType *ir_unreach_error(IrAnalyze *ira) { |
| 9545 | ira->old_bb_index = SIZE_MAX; | 9644 | ira->old_bb_index = SIZE_MAX; |
| 9546 | ira->new_irb.exec->invalid = true; | 9645 | ira->new_irb.exec->invalid = true; |
| 9547 | return ira->codegen->builtin_types.entry_unreachable; | 9646 | return ira->codegen->builtin_types.entry_unreachable; |
| ... | @@ -9564,7 +9663,7 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru | ... | @@ -9564,7 +9663,7 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru |
| 9564 | return true; | 9663 | return true; |
| 9565 | } | 9664 | } |
| 9566 | | 9665 | |
| 9567 | static TypeTableEntry *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, IrBasicBlock *old_bb) { | 9666 | static ZigType *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, IrBasicBlock *old_bb) { |
| 9568 | if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) { | 9667 | if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) { |
| 9569 | if (!ir_emit_backward_branch(ira, source_instruction)) | 9668 | if (!ir_emit_backward_branch(ira, source_instruction)) |
| 9570 | return ir_unreach_error(ira); | 9669 | return ir_unreach_error(ira); |
| ... | @@ -9575,8 +9674,8 @@ static TypeTableEntry *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instru | ... | @@ -9575,8 +9674,8 @@ static TypeTableEntry *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instru |
| 9575 | return ira->codegen->builtin_types.entry_unreachable; | 9674 | return ira->codegen->builtin_types.entry_unreachable; |
| 9576 | } | 9675 | } |
| 9577 | | 9676 | |
| 9578 | static TypeTableEntry *ir_finish_anal(IrAnalyze *ira, TypeTableEntry *result_type) { | 9677 | static ZigType *ir_finish_anal(IrAnalyze *ira, ZigType *result_type) { |
| 9579 | if (result_type->id == TypeTableEntryIdUnreachable) | 9678 | if (result_type->id == ZigTypeIdUnreachable) |
| 9580 | ir_finish_bb(ira); | 9679 | ir_finish_bb(ira); |
| 9581 | return result_type; | 9680 | return result_type; |
| 9582 | } | 9681 | } |
| ... | @@ -9595,16 +9694,16 @@ static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_in | ... | @@ -9595,16 +9694,16 @@ static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_in |
| 9595 | return &new_instruction->value; | 9694 | return &new_instruction->value; |
| 9596 | } | 9695 | } |
| 9597 | | 9696 | |
| 9598 | static TypeTableEntry *ir_analyze_void(IrAnalyze *ira, IrInstruction *instruction) { | 9697 | static ZigType *ir_analyze_void(IrAnalyze *ira, IrInstruction *instruction) { |
| 9599 | ir_build_const_from(ira, instruction); | 9698 | ir_build_const_from(ira, instruction); |
| 9600 | return ira->codegen->builtin_types.entry_void; | 9699 | return ira->codegen->builtin_types.entry_void; |
| 9601 | } | 9700 | } |
| 9602 | | 9701 | |
| 9603 | static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction, | 9702 | static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 9604 | ConstExprValue *pointee, TypeTableEntry *pointee_type, | 9703 | ConstExprValue *pointee, ZigType *pointee_type, |
| 9605 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align) | 9704 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align) |
| 9606 | { | 9705 | { |
| 9607 | TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type, | 9706 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type, |
| 9608 | ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0); | 9707 | ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0); |
| 9609 | IrInstruction *const_instr = ir_get_const(ira, instruction); | 9708 | IrInstruction *const_instr = ir_get_const(ira, instruction); |
| 9610 | ConstExprValue *const_val = &const_instr->value; | 9709 | ConstExprValue *const_val = &const_instr->value; |
| ... | @@ -9615,8 +9714,8 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio | ... | @@ -9615,8 +9714,8 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio |
| 9615 | return const_instr; | 9714 | return const_instr; |
| 9616 | } | 9715 | } |
| 9617 | | 9716 | |
| 9618 | static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction, | 9717 | static ZigType *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 9619 | ConstExprValue *pointee, TypeTableEntry *pointee_type, | 9718 | ConstExprValue *pointee, ZigType *pointee_type, |
| 9620 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile) | 9719 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile) |
| 9621 | { | 9720 | { |
| 9622 | IrInstruction *const_instr = ir_get_const_ptr(ira, instruction, pointee, | 9721 | IrInstruction *const_instr = ir_get_const_ptr(ira, instruction, pointee, |
| ... | @@ -9626,7 +9725,7 @@ static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instr | ... | @@ -9626,7 +9725,7 @@ static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instr |
| 9626 | return const_instr->value.type; | 9725 | return const_instr->value.type; |
| 9627 | } | 9726 | } |
| 9628 | | 9727 | |
| 9629 | static TypeTableEntry *ir_analyze_const_usize(IrAnalyze *ira, IrInstruction *instruction, uint64_t value) { | 9728 | static ZigType *ir_analyze_const_usize(IrAnalyze *ira, IrInstruction *instruction, uint64_t value) { |
| 9630 | ConstExprValue *const_val = ir_build_const_from(ira, instruction); | 9729 | ConstExprValue *const_val = ir_build_const_from(ira, instruction); |
| 9631 | bigint_init_unsigned(&const_val->data.x_bigint, value); | 9730 | bigint_init_unsigned(&const_val->data.x_bigint, value); |
| 9632 | return ira->codegen->builtin_types.entry_usize; | 9731 | return ira->codegen->builtin_types.entry_usize; |
| ... | @@ -9659,8 +9758,8 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un | ... | @@ -9659,8 +9758,8 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un |
| 9659 | } | 9758 | } |
| 9660 | | 9759 | |
| 9661 | IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, | 9760 | IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 9662 | TypeTableEntry *expected_type, size_t *backward_branch_count, size_t backward_branch_quota, | 9761 | ZigType *expected_type, size_t *backward_branch_count, size_t backward_branch_quota, |
| 9663 | FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, | 9762 | ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, |
| 9664 | IrExecutable *parent_exec) | 9763 | IrExecutable *parent_exec) |
| 9665 | { | 9764 | { |
| 9666 | if (expected_type != nullptr && type_is_invalid(expected_type)) | 9765 | if (expected_type != nullptr && type_is_invalid(expected_type)) |
| ... | @@ -9697,7 +9796,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node | ... | @@ -9697,7 +9796,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node |
| 9697 | analyzed_executable->backward_branch_count = backward_branch_count; | 9796 | analyzed_executable->backward_branch_count = backward_branch_count; |
| 9698 | analyzed_executable->backward_branch_quota = backward_branch_quota; | 9797 | analyzed_executable->backward_branch_quota = backward_branch_quota; |
| 9699 | analyzed_executable->begin_scope = scope; | 9798 | analyzed_executable->begin_scope = scope; |
| 9700 | TypeTableEntry *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, node); | 9799 | ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, node); |
| 9701 | if (type_is_invalid(result_type)) | 9800 | if (type_is_invalid(result_type)) |
| 9702 | return codegen->invalid_instruction; | 9801 | return codegen->invalid_instruction; |
| 9703 | | 9802 | |
| ... | @@ -9710,11 +9809,11 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node | ... | @@ -9710,11 +9809,11 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node |
| 9710 | return ir_exec_const_result(codegen, analyzed_executable); | 9809 | return ir_exec_const_result(codegen, analyzed_executable); |
| 9711 | } | 9810 | } |
| 9712 | | 9811 | |
| 9713 | static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) { | 9812 | static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) { |
| 9714 | if (type_is_invalid(type_value->value.type)) | 9813 | if (type_is_invalid(type_value->value.type)) |
| 9715 | return ira->codegen->builtin_types.entry_invalid; | 9814 | return ira->codegen->builtin_types.entry_invalid; |
| 9716 | | 9815 | |
| 9717 | if (type_value->value.type->id != TypeTableEntryIdMetaType) { | 9816 | if (type_value->value.type->id != ZigTypeIdMetaType) { |
| 9718 | ir_add_error(ira, type_value, | 9817 | ir_add_error(ira, type_value, |
| 9719 | buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name))); | 9818 | buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name))); |
| 9720 | return ira->codegen->builtin_types.entry_invalid; | 9819 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -9727,14 +9826,14 @@ static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value | ... | @@ -9727,14 +9826,14 @@ static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value |
| 9727 | return const_val->data.x_type; | 9826 | return const_val->data.x_type; |
| 9728 | } | 9827 | } |
| 9729 | | 9828 | |
| 9730 | static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { | 9829 | static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { |
| 9731 | if (fn_value == ira->codegen->invalid_instruction) | 9830 | if (fn_value == ira->codegen->invalid_instruction) |
| 9732 | return nullptr; | 9831 | return nullptr; |
| 9733 | | 9832 | |
| 9734 | if (type_is_invalid(fn_value->value.type)) | 9833 | if (type_is_invalid(fn_value->value.type)) |
| 9735 | return nullptr; | 9834 | return nullptr; |
| 9736 | | 9835 | |
| 9737 | if (fn_value->value.type->id != TypeTableEntryIdFn) { | 9836 | if (fn_value->value.type->id != ZigTypeIdFn) { |
| 9738 | ir_add_error_node(ira, fn_value->source_node, | 9837 | ir_add_error_node(ira, fn_value->source_node, |
| 9739 | buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value.type->name))); | 9838 | buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value.type->name))); |
| 9740 | return nullptr; | 9839 | return nullptr; |
| ... | @@ -9748,11 +9847,11 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { | ... | @@ -9748,11 +9847,11 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { |
| 9748 | return const_val->data.x_ptr.data.fn.fn_entry; | 9847 | return const_val->data.x_ptr.data.fn.fn_entry; |
| 9749 | } | 9848 | } |
| 9750 | | 9849 | |
| 9751 | static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) { | 9850 | static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { |
| 9752 | assert(wanted_type->id == TypeTableEntryIdOptional); | 9851 | assert(wanted_type->id == ZigTypeIdOptional); |
| 9753 | | 9852 | |
| 9754 | if (instr_is_comptime(value)) { | 9853 | if (instr_is_comptime(value)) { |
| 9755 | TypeTableEntry *payload_type = wanted_type->data.maybe.child_type; | 9854 | ZigType *payload_type = wanted_type->data.maybe.child_type; |
| 9756 | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); | 9855 | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 9757 | if (type_is_invalid(casted_payload->value.type)) | 9856 | if (type_is_invalid(casted_payload->value.type)) |
| 9758 | return ira->codegen->invalid_instruction; | 9857 | return ira->codegen->invalid_instruction; |
| ... | @@ -9781,12 +9880,12 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc | ... | @@ -9781,12 +9880,12 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc |
| 9781 | } | 9880 | } |
| 9782 | | 9881 | |
| 9783 | static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr, | 9882 | static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 9784 | IrInstruction *value, TypeTableEntry *wanted_type) | 9883 | IrInstruction *value, ZigType *wanted_type) |
| 9785 | { | 9884 | { |
| 9786 | assert(wanted_type->id == TypeTableEntryIdErrorUnion); | 9885 | assert(wanted_type->id == ZigTypeIdErrorUnion); |
| 9787 | | 9886 | |
| 9788 | if (instr_is_comptime(value)) { | 9887 | if (instr_is_comptime(value)) { |
| 9789 | TypeTableEntry *payload_type = wanted_type->data.error_union.payload_type; | 9888 | ZigType *payload_type = wanted_type->data.error_union.payload_type; |
| 9790 | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); | 9889 | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 9791 | if (type_is_invalid(casted_payload->value.type)) | 9890 | if (type_is_invalid(casted_payload->value.type)) |
| 9792 | return ira->codegen->invalid_instruction; | 9891 | return ira->codegen->invalid_instruction; |
| ... | @@ -9812,10 +9911,10 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction | ... | @@ -9812,10 +9911,10 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 9812 | } | 9911 | } |
| 9813 | | 9912 | |
| 9814 | static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, | 9913 | static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 9815 | TypeTableEntry *wanted_type) | 9914 | ZigType *wanted_type) |
| 9816 | { | 9915 | { |
| 9817 | assert(value->value.type->id == TypeTableEntryIdErrorSet); | 9916 | assert(value->value.type->id == ZigTypeIdErrorSet); |
| 9818 | assert(wanted_type->id == TypeTableEntryIdErrorSet); | 9917 | assert(wanted_type->id == ZigTypeIdErrorSet); |
| 9819 | | 9918 | |
| 9820 | if (instr_is_comptime(value)) { | 9919 | if (instr_is_comptime(value)) { |
| 9821 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); | 9920 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| ... | @@ -9854,8 +9953,8 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou | ... | @@ -9854,8 +9953,8 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou |
| 9854 | return result; | 9953 | return result; |
| 9855 | } | 9954 | } |
| 9856 | | 9955 | |
| 9857 | static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) { | 9956 | static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { |
| 9858 | assert(wanted_type->id == TypeTableEntryIdErrorUnion); | 9957 | assert(wanted_type->id == ZigTypeIdErrorUnion); |
| 9859 | | 9958 | |
| 9860 | IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type); | 9959 | IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type); |
| 9861 | | 9960 | |
| ... | @@ -9881,7 +9980,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so | ... | @@ -9881,7 +9980,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so |
| 9881 | } | 9980 | } |
| 9882 | | 9981 | |
| 9883 | static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_instr, | 9982 | static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_instr, |
| 9884 | IrInstruction *value, TypeTableEntry *wanted_type) | 9983 | IrInstruction *value, ZigType *wanted_type) |
| 9885 | { | 9984 | { |
| 9886 | if (instr_is_comptime(value)) { | 9985 | if (instr_is_comptime(value)) { |
| 9887 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); | 9986 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| ... | @@ -9905,9 +10004,9 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_ | ... | @@ -9905,9 +10004,9 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_ |
| 9905 | source_instr->source_node, value, true, false); | 10004 | source_instr->source_node, value, true, false); |
| 9906 | new_instruction->value.type = wanted_type; | 10005 | new_instruction->value.type = wanted_type; |
| 9907 | | 10006 | |
| 9908 | TypeTableEntry *child_type = wanted_type->data.pointer.child_type; | 10007 | ZigType *child_type = wanted_type->data.pointer.child_type; |
| 9909 | if (type_has_bits(child_type)) { | 10008 | if (type_has_bits(child_type)) { |
| 9910 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); | 10009 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 9911 | assert(fn_entry); | 10010 | assert(fn_entry); |
| 9912 | fn_entry->alloca_list.append(new_instruction); | 10011 | fn_entry->alloca_list.append(new_instruction); |
| 9913 | } | 10012 | } |
| ... | @@ -9916,8 +10015,8 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_ | ... | @@ -9916,8 +10015,8 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_ |
| 9916 | } | 10015 | } |
| 9917 | } | 10016 | } |
| 9918 | | 10017 | |
| 9919 | static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) { | 10018 | static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { |
| 9920 | assert(wanted_type->id == TypeTableEntryIdOptional); | 10019 | assert(wanted_type->id == ZigTypeIdOptional); |
| 9921 | assert(instr_is_comptime(value)); | 10020 | assert(instr_is_comptime(value)); |
| 9922 | | 10021 | |
| 9923 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); | 10022 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| ... | @@ -9950,14 +10049,14 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi | ... | @@ -9950,14 +10049,14 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi |
| 9950 | get_abi_alignment(ira->codegen, value->value.type)); | 10049 | get_abi_alignment(ira->codegen, value->value.type)); |
| 9951 | } | 10050 | } |
| 9952 | | 10051 | |
| 9953 | TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type, | 10052 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type, |
| 9954 | is_const, is_volatile, PtrLenSingle, get_abi_alignment(ira->codegen, value->value.type), 0, 0); | 10053 | is_const, is_volatile, PtrLenSingle, get_abi_alignment(ira->codegen, value->value.type), 0, 0); |
| 9955 | IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope, | 10054 | IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope, |
| 9956 | source_instruction->source_node, value, is_const, is_volatile); | 10055 | source_instruction->source_node, value, is_const, is_volatile); |
| 9957 | new_instruction->value.type = ptr_type; | 10056 | new_instruction->value.type = ptr_type; |
| 9958 | new_instruction->value.data.rh_ptr = RuntimeHintPtrStack; | 10057 | new_instruction->value.data.rh_ptr = RuntimeHintPtrStack; |
| 9959 | if (type_has_bits(ptr_type)) { | 10058 | if (type_has_bits(ptr_type)) { |
| 9960 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); | 10059 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 9961 | assert(fn_entry); | 10060 | assert(fn_entry); |
| 9962 | fn_entry->alloca_list.append(new_instruction); | 10061 | fn_entry->alloca_list.append(new_instruction); |
| 9963 | } | 10062 | } |
| ... | @@ -9965,7 +10064,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi | ... | @@ -9965,7 +10064,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi |
| 9965 | } | 10064 | } |
| 9966 | | 10065 | |
| 9967 | static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr, | 10066 | static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr, |
| 9968 | IrInstruction *array_arg, TypeTableEntry *wanted_type) | 10067 | IrInstruction *array_arg, ZigType *wanted_type) |
| 9969 | { | 10068 | { |
| 9970 | assert(is_slice(wanted_type)); | 10069 | assert(is_slice(wanted_type)); |
| 9971 | // In this function we honor the const-ness of wanted_type, because | 10070 | // In this function we honor the const-ness of wanted_type, because |
| ... | @@ -9973,14 +10072,14 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s | ... | @@ -9973,14 +10072,14 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s |
| 9973 | | 10072 | |
| 9974 | IrInstruction *array_ptr = nullptr; | 10073 | IrInstruction *array_ptr = nullptr; |
| 9975 | IrInstruction *array; | 10074 | IrInstruction *array; |
| 9976 | if (array_arg->value.type->id == TypeTableEntryIdPointer) { | 10075 | if (array_arg->value.type->id == ZigTypeIdPointer) { |
| 9977 | array = ir_get_deref(ira, source_instr, array_arg); | 10076 | array = ir_get_deref(ira, source_instr, array_arg); |
| 9978 | array_ptr = array_arg; | 10077 | array_ptr = array_arg; |
| 9979 | } else { | 10078 | } else { |
| 9980 | array = array_arg; | 10079 | array = array_arg; |
| 9981 | } | 10080 | } |
| 9982 | TypeTableEntry *array_type = array->value.type; | 10081 | ZigType *array_type = array->value.type; |
| 9983 | assert(array_type->id == TypeTableEntryIdArray); | 10082 | assert(array_type->id == ZigTypeIdArray); |
| 9984 | | 10083 | |
| 9985 | if (instr_is_comptime(array)) { | 10084 | if (instr_is_comptime(array)) { |
| 9986 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, | 10085 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, |
| ... | @@ -10011,12 +10110,12 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s | ... | @@ -10011,12 +10110,12 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s |
| 10011 | } | 10110 | } |
| 10012 | | 10111 | |
| 10013 | static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *source_instr, | 10112 | static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *source_instr, |
| 10014 | IrInstruction *target, TypeTableEntry *wanted_type) | 10113 | IrInstruction *target, ZigType *wanted_type) |
| 10015 | { | 10114 | { |
| 10016 | Error err; | 10115 | Error err; |
| 10017 | assert(wanted_type->id == TypeTableEntryIdInt); | 10116 | assert(wanted_type->id == ZigTypeIdInt); |
| 10018 | | 10117 | |
| 10019 | TypeTableEntry *actual_type = target->value.type; | 10118 | ZigType *actual_type = target->value.type; |
| 10020 | if ((err = ensure_complete_type(ira->codegen, actual_type))) | 10119 | if ((err = ensure_complete_type(ira->codegen, actual_type))) |
| 10021 | return ira->codegen->invalid_instruction; | 10120 | return ira->codegen->invalid_instruction; |
| 10022 | | 10121 | |
| ... | @@ -10028,7 +10127,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour | ... | @@ -10028,7 +10127,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour |
| 10028 | return ira->codegen->invalid_instruction; | 10127 | return ira->codegen->invalid_instruction; |
| 10029 | } | 10128 | } |
| 10030 | | 10129 | |
| 10031 | assert(actual_type->id == TypeTableEntryIdEnum); | 10130 | assert(actual_type->id == ZigTypeIdEnum); |
| 10032 | | 10131 | |
| 10033 | if (instr_is_comptime(target)) { | 10132 | if (instr_is_comptime(target)) { |
| 10034 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); | 10133 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| ... | @@ -10047,10 +10146,10 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour | ... | @@ -10047,10 +10146,10 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour |
| 10047 | } | 10146 | } |
| 10048 | | 10147 | |
| 10049 | static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr, | 10148 | static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr, |
| 10050 | IrInstruction *target, TypeTableEntry *wanted_type) | 10149 | IrInstruction *target, ZigType *wanted_type) |
| 10051 | { | 10150 | { |
| 10052 | assert(target->value.type->id == TypeTableEntryIdUnion); | 10151 | assert(target->value.type->id == ZigTypeIdUnion); |
| 10053 | assert(wanted_type->id == TypeTableEntryIdEnum); | 10152 | assert(wanted_type->id == ZigTypeIdEnum); |
| 10054 | assert(wanted_type == target->value.type->data.unionation.tag_type); | 10153 | assert(wanted_type == target->value.type->data.unionation.tag_type); |
| 10055 | | 10154 | |
| 10056 | if (instr_is_comptime(target)) { | 10155 | if (instr_is_comptime(target)) { |
| ... | @@ -10072,7 +10171,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou | ... | @@ -10072,7 +10171,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou |
| 10072 | } | 10171 | } |
| 10073 | | 10172 | |
| 10074 | static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruction *source_instr, | 10173 | static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruction *source_instr, |
| 10075 | IrInstruction *target, TypeTableEntry *wanted_type) | 10174 | IrInstruction *target, ZigType *wanted_type) |
| 10076 | { | 10175 | { |
| 10077 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, | 10176 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, |
| 10078 | source_instr->source_node, wanted_type); | 10177 | source_instr->source_node, wanted_type); |
| ... | @@ -10081,11 +10180,11 @@ static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruc | ... | @@ -10081,11 +10180,11 @@ static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruc |
| 10081 | } | 10180 | } |
| 10082 | | 10181 | |
| 10083 | static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *source_instr, | 10182 | static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *source_instr, |
| 10084 | IrInstruction *target, TypeTableEntry *wanted_type) | 10183 | IrInstruction *target, ZigType *wanted_type) |
| 10085 | { | 10184 | { |
| 10086 | Error err; | 10185 | Error err; |
| 10087 | assert(wanted_type->id == TypeTableEntryIdUnion); | 10186 | assert(wanted_type->id == ZigTypeIdUnion); |
| 10088 | assert(target->value.type->id == TypeTableEntryIdEnum); | 10187 | assert(target->value.type->id == ZigTypeIdEnum); |
| 10089 | | 10188 | |
| 10090 | if (instr_is_comptime(target)) { | 10189 | if (instr_is_comptime(target)) { |
| 10091 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); | 10190 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| ... | @@ -10140,15 +10239,15 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so | ... | @@ -10140,15 +10239,15 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 10140 | } | 10239 | } |
| 10141 | | 10240 | |
| 10142 | static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction *source_instr, | 10241 | static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction *source_instr, |
| 10143 | IrInstruction *target, TypeTableEntry *wanted_type) | 10242 | IrInstruction *target, ZigType *wanted_type) |
| 10144 | { | 10243 | { |
| 10145 | assert(wanted_type->id == TypeTableEntryIdInt || wanted_type->id == TypeTableEntryIdFloat); | 10244 | assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat); |
| 10146 | | 10245 | |
| 10147 | if (instr_is_comptime(target)) { | 10246 | if (instr_is_comptime(target)) { |
| 10148 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); | 10247 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 10149 | if (!val) | 10248 | if (!val) |
| 10150 | return ira->codegen->invalid_instruction; | 10249 | return ira->codegen->invalid_instruction; |
| 10151 | if (wanted_type->id == TypeTableEntryIdInt) { | 10250 | if (wanted_type->id == ZigTypeIdInt) { |
| 10152 | if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) { | 10251 | if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) { |
| 10153 | ir_add_error(ira, source_instr, | 10252 | ir_add_error(ira, source_instr, |
| 10154 | buf_sprintf("attempt to cast negative value to unsigned integer")); | 10253 | buf_sprintf("attempt to cast negative value to unsigned integer")); |
| ... | @@ -10166,7 +10265,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction | ... | @@ -10166,7 +10265,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction |
| 10166 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, | 10265 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, |
| 10167 | source_instr->source_node, wanted_type); | 10266 | source_instr->source_node, wanted_type); |
| 10168 | result->value.type = wanted_type; | 10267 | result->value.type = wanted_type; |
| 10169 | if (wanted_type->id == TypeTableEntryIdInt) { | 10268 | if (wanted_type->id == ZigTypeIdInt) { |
| 10170 | bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint); | 10269 | bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint); |
| 10171 | } else { | 10270 | } else { |
| 10172 | float_init_float(&result->value, val); | 10271 | float_init_float(&result->value, val); |
| ... | @@ -10181,12 +10280,12 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction | ... | @@ -10181,12 +10280,12 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction |
| 10181 | } | 10280 | } |
| 10182 | | 10281 | |
| 10183 | static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *source_instr, | 10282 | static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *source_instr, |
| 10184 | IrInstruction *target, TypeTableEntry *wanted_type) | 10283 | IrInstruction *target, ZigType *wanted_type) |
| 10185 | { | 10284 | { |
| 10186 | Error err; | 10285 | Error err; |
| 10187 | assert(wanted_type->id == TypeTableEntryIdEnum); | 10286 | assert(wanted_type->id == ZigTypeIdEnum); |
| 10188 | | 10287 | |
| 10189 | TypeTableEntry *actual_type = target->value.type; | 10288 | ZigType *actual_type = target->value.type; |
| 10190 | | 10289 | |
| 10191 | if ((err = ensure_complete_type(ira->codegen, wanted_type))) | 10290 | if ((err = ensure_complete_type(ira->codegen, wanted_type))) |
| 10192 | return ira->codegen->invalid_instruction; | 10291 | return ira->codegen->invalid_instruction; |
| ... | @@ -10199,7 +10298,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour | ... | @@ -10199,7 +10298,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 10199 | return ira->codegen->invalid_instruction; | 10298 | return ira->codegen->invalid_instruction; |
| 10200 | } | 10299 | } |
| 10201 | | 10300 | |
| 10202 | assert(actual_type->id == TypeTableEntryIdInt); | 10301 | assert(actual_type->id == ZigTypeIdInt); |
| 10203 | | 10302 | |
| 10204 | if (instr_is_comptime(target)) { | 10303 | if (instr_is_comptime(target)) { |
| 10205 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); | 10304 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| ... | @@ -10231,7 +10330,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour | ... | @@ -10231,7 +10330,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 10231 | } | 10330 | } |
| 10232 | | 10331 | |
| 10233 | static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr, | 10332 | static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr, |
| 10234 | IrInstruction *target, TypeTableEntry *wanted_type) | 10333 | IrInstruction *target, ZigType *wanted_type) |
| 10235 | { | 10334 | { |
| 10236 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); | 10335 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 10237 | if (!val) | 10336 | if (!val) |
| ... | @@ -10239,9 +10338,9 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction | ... | @@ -10239,9 +10338,9 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction |
| 10239 | | 10338 | |
| 10240 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, | 10339 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, |
| 10241 | source_instr->source_node, wanted_type); | 10340 | source_instr->source_node, wanted_type); |
| 10242 | if (wanted_type->id == TypeTableEntryIdComptimeFloat) { | 10341 | if (wanted_type->id == ZigTypeIdComptimeFloat) { |
| 10243 | float_init_float(&result->value, val); | 10342 | float_init_float(&result->value, val); |
| 10244 | } else if (wanted_type->id == TypeTableEntryIdComptimeInt) { | 10343 | } else if (wanted_type->id == ZigTypeIdComptimeInt) { |
| 10245 | bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint); | 10344 | bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint); |
| 10246 | } else { | 10345 | } else { |
| 10247 | zig_unreachable(); | 10346 | zig_unreachable(); |
| ... | @@ -10250,11 +10349,11 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction | ... | @@ -10250,11 +10349,11 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction |
| 10250 | } | 10349 | } |
| 10251 | | 10350 | |
| 10252 | static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, | 10351 | static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, |
| 10253 | TypeTableEntry *wanted_type) | 10352 | ZigType *wanted_type) |
| 10254 | { | 10353 | { |
| 10255 | assert(target->value.type->id == TypeTableEntryIdInt); | 10354 | assert(target->value.type->id == ZigTypeIdInt); |
| 10256 | assert(!target->value.type->data.integral.is_signed); | 10355 | assert(!target->value.type->data.integral.is_signed); |
| 10257 | assert(wanted_type->id == TypeTableEntryIdErrorSet); | 10356 | assert(wanted_type->id == ZigTypeIdErrorSet); |
| 10258 | | 10357 | |
| 10259 | if (instr_is_comptime(target)) { | 10358 | if (instr_is_comptime(target)) { |
| 10260 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); | 10359 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| ... | @@ -10315,11 +10414,11 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc | ... | @@ -10315,11 +10414,11 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc |
| 10315 | } | 10414 | } |
| 10316 | | 10415 | |
| 10317 | static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, | 10416 | static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, |
| 10318 | TypeTableEntry *wanted_type) | 10417 | ZigType *wanted_type) |
| 10319 | { | 10418 | { |
| 10320 | assert(wanted_type->id == TypeTableEntryIdInt); | 10419 | assert(wanted_type->id == ZigTypeIdInt); |
| 10321 | | 10420 | |
| 10322 | TypeTableEntry *err_type = target->value.type; | 10421 | ZigType *err_type = target->value.type; |
| 10323 | | 10422 | |
| 10324 | if (instr_is_comptime(target)) { | 10423 | if (instr_is_comptime(target)) { |
| 10325 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); | 10424 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| ... | @@ -10330,9 +10429,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc | ... | @@ -10330,9 +10429,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 10330 | source_instr->source_node, wanted_type); | 10429 | source_instr->source_node, wanted_type); |
| 10331 | | 10430 | |
| 10332 | ErrorTableEntry *err; | 10431 | ErrorTableEntry *err; |
| 10333 | if (err_type->id == TypeTableEntryIdErrorUnion) { | 10432 | if (err_type->id == ZigTypeIdErrorUnion) { |
| 10334 | err = val->data.x_err_union.err; | 10433 | err = val->data.x_err_union.err; |
| 10335 | } else if (err_type->id == TypeTableEntryIdErrorSet) { | 10434 | } else if (err_type->id == ZigTypeIdErrorSet) { |
| 10336 | err = val->data.x_err_set; | 10435 | err = val->data.x_err_set; |
| 10337 | } else { | 10436 | } else { |
| 10338 | zig_unreachable(); | 10437 | zig_unreachable(); |
| ... | @@ -10353,10 +10452,10 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc | ... | @@ -10353,10 +10452,10 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 10353 | return result; | 10452 | return result; |
| 10354 | } | 10453 | } |
| 10355 | | 10454 | |
| 10356 | TypeTableEntry *err_set_type; | 10455 | ZigType *err_set_type; |
| 10357 | if (err_type->id == TypeTableEntryIdErrorUnion) { | 10456 | if (err_type->id == ZigTypeIdErrorUnion) { |
| 10358 | err_set_type = err_type->data.error_union.err_set_type; | 10457 | err_set_type = err_type->data.error_union.err_set_type; |
| 10359 | } else if (err_type->id == TypeTableEntryIdErrorSet) { | 10458 | } else if (err_type->id == ZigTypeIdErrorSet) { |
| 10360 | err_set_type = err_type; | 10459 | err_set_type = err_type; |
| 10361 | } else { | 10460 | } else { |
| 10362 | zig_unreachable(); | 10461 | zig_unreachable(); |
| ... | @@ -10395,12 +10494,12 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc | ... | @@ -10395,12 +10494,12 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 10395 | } | 10494 | } |
| 10396 | | 10495 | |
| 10397 | static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, | 10496 | static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, |
| 10398 | TypeTableEntry *wanted_type) | 10497 | ZigType *wanted_type) |
| 10399 | { | 10498 | { |
| 10400 | assert(wanted_type->id == TypeTableEntryIdPointer); | 10499 | assert(wanted_type->id == ZigTypeIdPointer); |
| 10401 | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, target->value.type->data.pointer.alignment); | 10500 | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, target->value.type->data.pointer.alignment); |
| 10402 | TypeTableEntry *array_type = wanted_type->data.pointer.child_type; | 10501 | ZigType *array_type = wanted_type->data.pointer.child_type; |
| 10403 | assert(array_type->id == TypeTableEntryIdArray); | 10502 | assert(array_type->id == ZigTypeIdArray); |
| 10404 | assert(array_type->data.array.len == 1); | 10503 | assert(array_type->data.array.len == 1); |
| 10405 | | 10504 | |
| 10406 | if (instr_is_comptime(target)) { | 10505 | if (instr_is_comptime(target)) { |
| ... | @@ -10408,8 +10507,10 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou | ... | @@ -10408,8 +10507,10 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 10408 | if (!val) | 10507 | if (!val) |
| 10409 | return ira->codegen->invalid_instruction; | 10508 | return ira->codegen->invalid_instruction; |
| 10410 | | 10509 | |
| 10411 | assert(val->type->id == TypeTableEntryIdPointer); | 10510 | assert(val->type->id == ZigTypeIdPointer); |
| 10412 | ConstExprValue *pointee = const_ptr_pointee(ira->codegen, val); | 10511 | ConstExprValue *pointee = ir_const_ptr_pointee(ira, val, source_instr->source_node); |
| | 10512 | if (pointee == nullptr) |
| | 10513 | return ira->codegen->invalid_instruction; |
| 10413 | if (pointee->special != ConstValSpecialRuntime) { | 10514 | if (pointee->special != ConstValSpecialRuntime) { |
| 10414 | ConstExprValue *array_val = create_const_vals(1); | 10515 | ConstExprValue *array_val = create_const_vals(1); |
| 10415 | array_val->special = ConstValSpecialStatic; | 10516 | array_val->special = ConstValSpecialStatic; |
| ... | @@ -10529,10 +10630,10 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa | ... | @@ -10529,10 +10630,10 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa |
| 10529 | } | 10630 | } |
| 10530 | | 10631 | |
| 10531 | static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr, | 10632 | static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr, |
| 10532 | TypeTableEntry *wanted_type, IrInstruction *value) | 10633 | ZigType *wanted_type, IrInstruction *value) |
| 10533 | { | 10634 | { |
| 10534 | Error err; | 10635 | Error err; |
| 10535 | TypeTableEntry *actual_type = value->value.type; | 10636 | ZigType *actual_type = value->value.type; |
| 10536 | AstNode *source_node = source_instr->source_node; | 10637 | AstNode *source_node = source_instr->source_node; |
| 10537 | | 10638 | |
| 10538 | if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) { | 10639 | if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) { |
| ... | @@ -10547,8 +10648,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10547,8 +10648,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10547 | } | 10648 | } |
| 10548 | | 10649 | |
| 10549 | // widening conversion | 10650 | // widening conversion |
| 10550 | if (wanted_type->id == TypeTableEntryIdInt && | 10651 | if (wanted_type->id == ZigTypeIdInt && |
| 10551 | actual_type->id == TypeTableEntryIdInt && | 10652 | actual_type->id == ZigTypeIdInt && |
| 10552 | wanted_type->data.integral.is_signed == actual_type->data.integral.is_signed && | 10653 | wanted_type->data.integral.is_signed == actual_type->data.integral.is_signed && |
| 10553 | wanted_type->data.integral.bit_count >= actual_type->data.integral.bit_count) | 10654 | wanted_type->data.integral.bit_count >= actual_type->data.integral.bit_count) |
| 10554 | { | 10655 | { |
| ... | @@ -10556,16 +10657,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10556,16 +10657,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10556 | } | 10657 | } |
| 10557 | | 10658 | |
| 10558 | // small enough unsigned ints can get casted to large enough signed ints | 10659 | // small enough unsigned ints can get casted to large enough signed ints |
| 10559 | if (wanted_type->id == TypeTableEntryIdInt && wanted_type->data.integral.is_signed && | 10660 | if (wanted_type->id == ZigTypeIdInt && wanted_type->data.integral.is_signed && |
| 10560 | actual_type->id == TypeTableEntryIdInt && !actual_type->data.integral.is_signed && | 10661 | actual_type->id == ZigTypeIdInt && !actual_type->data.integral.is_signed && |
| 10561 | wanted_type->data.integral.bit_count > actual_type->data.integral.bit_count) | 10662 | wanted_type->data.integral.bit_count > actual_type->data.integral.bit_count) |
| 10562 | { | 10663 | { |
| 10563 | return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type); | 10664 | return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type); |
| 10564 | } | 10665 | } |
| 10565 | | 10666 | |
| 10566 | // float widening conversion | 10667 | // float widening conversion |
| 10567 | if (wanted_type->id == TypeTableEntryIdFloat && | 10668 | if (wanted_type->id == ZigTypeIdFloat && |
| 10568 | actual_type->id == TypeTableEntryIdFloat && | 10669 | actual_type->id == ZigTypeIdFloat && |
| 10569 | wanted_type->data.floating.bit_count >= actual_type->data.floating.bit_count) | 10670 | wanted_type->data.floating.bit_count >= actual_type->data.floating.bit_count) |
| 10570 | { | 10671 | { |
| 10571 | return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type); | 10672 | return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type); |
| ... | @@ -10573,9 +10674,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10573,9 +10674,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10573 | | 10674 | |
| 10574 | | 10675 | |
| 10575 | // cast from [N]T to []const T | 10676 | // cast from [N]T to []const T |
| 10576 | if (is_slice(wanted_type) && actual_type->id == TypeTableEntryIdArray) { | 10677 | if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) { |
| 10577 | TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; | 10678 | ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; |
| 10578 | assert(ptr_type->id == TypeTableEntryIdPointer); | 10679 | assert(ptr_type->id == ZigTypeIdPointer); |
| 10579 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 10680 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 10580 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, | 10681 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, |
| 10581 | source_node, false).id == ConstCastResultIdOk) | 10682 | source_node, false).id == ConstCastResultIdOk) |
| ... | @@ -10586,14 +10687,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10586,14 +10687,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10586 | | 10687 | |
| 10587 | // cast from *const [N]T to []const T | 10688 | // cast from *const [N]T to []const T |
| 10588 | if (is_slice(wanted_type) && | 10689 | if (is_slice(wanted_type) && |
| 10589 | actual_type->id == TypeTableEntryIdPointer && | 10690 | actual_type->id == ZigTypeIdPointer && |
| 10590 | actual_type->data.pointer.is_const && | 10691 | actual_type->data.pointer.is_const && |
| 10591 | actual_type->data.pointer.child_type->id == TypeTableEntryIdArray) | 10692 | actual_type->data.pointer.child_type->id == ZigTypeIdArray) |
| 10592 | { | 10693 | { |
| 10593 | TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; | 10694 | ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; |
| 10594 | assert(ptr_type->id == TypeTableEntryIdPointer); | 10695 | assert(ptr_type->id == ZigTypeIdPointer); |
| 10595 | | 10696 | |
| 10596 | TypeTableEntry *array_type = actual_type->data.pointer.child_type; | 10697 | ZigType *array_type = actual_type->data.pointer.child_type; |
| 10597 | | 10698 | |
| 10598 | if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && | 10699 | if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && |
| 10599 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, array_type->data.array.child_type, | 10700 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, array_type->data.array.child_type, |
| ... | @@ -10604,14 +10705,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10604,14 +10705,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10604 | } | 10705 | } |
| 10605 | | 10706 | |
| 10606 | // cast from [N]T to *const []const T | 10707 | // cast from [N]T to *const []const T |
| 10607 | if (wanted_type->id == TypeTableEntryIdPointer && | 10708 | if (wanted_type->id == ZigTypeIdPointer && |
| 10608 | wanted_type->data.pointer.is_const && | 10709 | wanted_type->data.pointer.is_const && |
| 10609 | is_slice(wanted_type->data.pointer.child_type) && | 10710 | is_slice(wanted_type->data.pointer.child_type) && |
| 10610 | actual_type->id == TypeTableEntryIdArray) | 10711 | actual_type->id == ZigTypeIdArray) |
| 10611 | { | 10712 | { |
| 10612 | TypeTableEntry *ptr_type = | 10713 | ZigType *ptr_type = |
| 10613 | wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; | 10714 | wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 10614 | assert(ptr_type->id == TypeTableEntryIdPointer); | 10715 | assert(ptr_type->id == ZigTypeIdPointer); |
| 10615 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 10716 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 10616 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, | 10717 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, |
| 10617 | source_node, false).id == ConstCastResultIdOk) | 10718 | source_node, false).id == ConstCastResultIdOk) |
| ... | @@ -10629,13 +10730,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10629,13 +10730,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10629 | } | 10730 | } |
| 10630 | | 10731 | |
| 10631 | // cast from [N]T to ?[]const T | 10732 | // cast from [N]T to ?[]const T |
| 10632 | if (wanted_type->id == TypeTableEntryIdOptional && | 10733 | if (wanted_type->id == ZigTypeIdOptional && |
| 10633 | is_slice(wanted_type->data.maybe.child_type) && | 10734 | is_slice(wanted_type->data.maybe.child_type) && |
| 10634 | actual_type->id == TypeTableEntryIdArray) | 10735 | actual_type->id == ZigTypeIdArray) |
| 10635 | { | 10736 | { |
| 10636 | TypeTableEntry *ptr_type = | 10737 | ZigType *ptr_type = |
| 10637 | wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; | 10738 | wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 10638 | assert(ptr_type->id == TypeTableEntryIdPointer); | 10739 | assert(ptr_type->id == ZigTypeIdPointer); |
| 10639 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 10740 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 10640 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, | 10741 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, |
| 10641 | source_node, false).id == ConstCastResultIdOk) | 10742 | source_node, false).id == ConstCastResultIdOk) |
| ... | @@ -10653,11 +10754,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10653,11 +10754,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10653 | } | 10754 | } |
| 10654 | | 10755 | |
| 10655 | // *[N]T to [*]T | 10756 | // *[N]T to [*]T |
| 10656 | if (wanted_type->id == TypeTableEntryIdPointer && | 10757 | if (wanted_type->id == ZigTypeIdPointer && |
| 10657 | wanted_type->data.pointer.ptr_len == PtrLenUnknown && | 10758 | wanted_type->data.pointer.ptr_len == PtrLenUnknown && |
| 10658 | actual_type->id == TypeTableEntryIdPointer && | 10759 | actual_type->id == ZigTypeIdPointer && |
| 10659 | actual_type->data.pointer.ptr_len == PtrLenSingle && | 10760 | actual_type->data.pointer.ptr_len == PtrLenSingle && |
| 10660 | actual_type->data.pointer.child_type->id == TypeTableEntryIdArray && | 10761 | actual_type->data.pointer.child_type->id == ZigTypeIdArray && |
| 10661 | actual_type->data.pointer.alignment >= wanted_type->data.pointer.alignment && | 10762 | actual_type->data.pointer.alignment >= wanted_type->data.pointer.alignment && |
| 10662 | types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, | 10763 | types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 10663 | actual_type->data.pointer.child_type->data.array.child_type, source_node, | 10764 | actual_type->data.pointer.child_type->data.array.child_type, source_node, |
| ... | @@ -10668,12 +10769,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10668,12 +10769,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10668 | | 10769 | |
| 10669 | // *[N]T to []T | 10770 | // *[N]T to []T |
| 10670 | if (is_slice(wanted_type) && | 10771 | if (is_slice(wanted_type) && |
| 10671 | actual_type->id == TypeTableEntryIdPointer && | 10772 | actual_type->id == ZigTypeIdPointer && |
| 10672 | actual_type->data.pointer.ptr_len == PtrLenSingle && | 10773 | actual_type->data.pointer.ptr_len == PtrLenSingle && |
| 10673 | actual_type->data.pointer.child_type->id == TypeTableEntryIdArray) | 10774 | actual_type->data.pointer.child_type->id == ZigTypeIdArray) |
| 10674 | { | 10775 | { |
| 10675 | TypeTableEntry *slice_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; | 10776 | ZigType *slice_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; |
| 10676 | assert(slice_ptr_type->id == TypeTableEntryIdPointer); | 10777 | assert(slice_ptr_type->id == ZigTypeIdPointer); |
| 10677 | if (types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type, | 10778 | if (types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type, |
| 10678 | actual_type->data.pointer.child_type->data.array.child_type, source_node, | 10779 | actual_type->data.pointer.child_type->data.array.child_type, source_node, |
| 10679 | !slice_ptr_type->data.pointer.is_const).id == ConstCastResultIdOk) | 10780 | !slice_ptr_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| ... | @@ -10685,23 +10786,23 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10685,23 +10786,23 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10685 | | 10786 | |
| 10686 | // cast from T to ?T | 10787 | // cast from T to ?T |
| 10687 | // note that the *T to ?*T case is handled via the "ConstCastOnly" mechanism | 10788 | // note that the *T to ?*T case is handled via the "ConstCastOnly" mechanism |
| 10688 | if (wanted_type->id == TypeTableEntryIdOptional) { | 10789 | if (wanted_type->id == ZigTypeIdOptional) { |
| 10689 | TypeTableEntry *wanted_child_type = wanted_type->data.maybe.child_type; | 10790 | ZigType *wanted_child_type = wanted_type->data.maybe.child_type; |
| 10690 | if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, | 10791 | if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, |
| 10691 | false).id == ConstCastResultIdOk) | 10792 | false).id == ConstCastResultIdOk) |
| 10692 | { | 10793 | { |
| 10693 | return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); | 10794 | return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); |
| 10694 | } else if (actual_type->id == TypeTableEntryIdComptimeInt || | 10795 | } else if (actual_type->id == ZigTypeIdComptimeInt || |
| 10695 | actual_type->id == TypeTableEntryIdComptimeFloat) | 10796 | actual_type->id == ZigTypeIdComptimeFloat) |
| 10696 | { | 10797 | { |
| 10697 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) { | 10798 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) { |
| 10698 | return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); | 10799 | return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); |
| 10699 | } else { | 10800 | } else { |
| 10700 | return ira->codegen->invalid_instruction; | 10801 | return ira->codegen->invalid_instruction; |
| 10701 | } | 10802 | } |
| 10702 | } else if (wanted_child_type->id == TypeTableEntryIdPointer && | 10803 | } else if (wanted_child_type->id == ZigTypeIdPointer && |
| 10703 | wanted_child_type->data.pointer.is_const && | 10804 | wanted_child_type->data.pointer.is_const && |
| 10704 | (actual_type->id == TypeTableEntryIdPointer || is_container(actual_type))) | 10805 | (actual_type->id == ZigTypeIdPointer || is_container(actual_type))) |
| 10705 | { | 10806 | { |
| 10706 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_child_type, value); | 10807 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_child_type, value); |
| 10707 | if (type_is_invalid(cast1->value.type)) | 10808 | if (type_is_invalid(cast1->value.type)) |
| ... | @@ -10713,36 +10814,38 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10713,36 +10814,38 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10713 | | 10814 | |
| 10714 | return cast2; | 10815 | return cast2; |
| 10715 | } else if ( | 10816 | } else if ( |
| 10716 | wanted_child_type->id == TypeTableEntryIdPointer && | 10817 | wanted_child_type->id == ZigTypeIdPointer && |
| 10717 | wanted_child_type->data.pointer.ptr_len == PtrLenUnknown && | 10818 | wanted_child_type->data.pointer.ptr_len == PtrLenUnknown && |
| 10718 | actual_type->id == TypeTableEntryIdPointer && | 10819 | actual_type->id == ZigTypeIdPointer && |
| 10719 | actual_type->data.pointer.ptr_len == PtrLenSingle && | 10820 | actual_type->data.pointer.ptr_len == PtrLenSingle && |
| 10720 | actual_type->data.pointer.child_type->id == TypeTableEntryIdArray && | 10821 | actual_type->data.pointer.child_type->id == ZigTypeIdArray && |
| 10721 | actual_type->data.pointer.alignment >= wanted_child_type->data.pointer.alignment && | 10822 | actual_type->data.pointer.alignment >= wanted_child_type->data.pointer.alignment && |
| 10722 | types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type, | 10823 | types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type, |
| 10723 | actual_type->data.pointer.child_type->data.array.child_type, source_node, | 10824 | actual_type->data.pointer.child_type->data.array.child_type, source_node, |
| 10724 | !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk) | 10825 | !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 10725 | { | 10826 | { |
| 10726 | IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, wanted_child_type); | 10827 | IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, wanted_child_type); |
| | 10828 | if (type_is_invalid(cast1->value.type)) |
| | 10829 | return ira->codegen->invalid_instruction; |
| 10727 | return ir_analyze_maybe_wrap(ira, source_instr, cast1, wanted_type); | 10830 | return ir_analyze_maybe_wrap(ira, source_instr, cast1, wanted_type); |
| 10728 | } | 10831 | } |
| 10729 | } | 10832 | } |
| 10730 | | 10833 | |
| 10731 | // cast from null literal to maybe type | 10834 | // cast from null literal to maybe type |
| 10732 | if (wanted_type->id == TypeTableEntryIdOptional && | 10835 | if (wanted_type->id == ZigTypeIdOptional && |
| 10733 | actual_type->id == TypeTableEntryIdNull) | 10836 | actual_type->id == ZigTypeIdNull) |
| 10734 | { | 10837 | { |
| 10735 | return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type); | 10838 | return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type); |
| 10736 | } | 10839 | } |
| 10737 | | 10840 | |
| 10738 | // cast from child type of error type to error type | 10841 | // cast from child type of error type to error type |
| 10739 | if (wanted_type->id == TypeTableEntryIdErrorUnion) { | 10842 | if (wanted_type->id == ZigTypeIdErrorUnion) { |
| 10740 | if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type, | 10843 | if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type, |
| 10741 | source_node, false).id == ConstCastResultIdOk) | 10844 | source_node, false).id == ConstCastResultIdOk) |
| 10742 | { | 10845 | { |
| 10743 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); | 10846 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); |
| 10744 | } else if (actual_type->id == TypeTableEntryIdComptimeInt || | 10847 | } else if (actual_type->id == ZigTypeIdComptimeInt || |
| 10745 | actual_type->id == TypeTableEntryIdComptimeFloat) | 10848 | actual_type->id == ZigTypeIdComptimeFloat) |
| 10746 | { | 10849 | { |
| 10747 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) { | 10850 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) { |
| 10748 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); | 10851 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); |
| ... | @@ -10753,13 +10856,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10753,13 +10856,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10753 | } | 10856 | } |
| 10754 | | 10857 | |
| 10755 | // cast from [N]T to E![]const T | 10858 | // cast from [N]T to E![]const T |
| 10756 | if (wanted_type->id == TypeTableEntryIdErrorUnion && | 10859 | if (wanted_type->id == ZigTypeIdErrorUnion && |
| 10757 | is_slice(wanted_type->data.error_union.payload_type) && | 10860 | is_slice(wanted_type->data.error_union.payload_type) && |
| 10758 | actual_type->id == TypeTableEntryIdArray) | 10861 | actual_type->id == ZigTypeIdArray) |
| 10759 | { | 10862 | { |
| 10760 | TypeTableEntry *ptr_type = | 10863 | ZigType *ptr_type = |
| 10761 | wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry; | 10864 | wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry; |
| 10762 | assert(ptr_type->id == TypeTableEntryIdPointer); | 10865 | assert(ptr_type->id == ZigTypeIdPointer); |
| 10763 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 10866 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 10764 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, | 10867 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, |
| 10765 | source_node, false).id == ConstCastResultIdOk) | 10868 | source_node, false).id == ConstCastResultIdOk) |
| ... | @@ -10777,22 +10880,22 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10777,22 +10880,22 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10777 | } | 10880 | } |
| 10778 | | 10881 | |
| 10779 | // cast from error set to error union type | 10882 | // cast from error set to error union type |
| 10780 | if (wanted_type->id == TypeTableEntryIdErrorUnion && | 10883 | if (wanted_type->id == ZigTypeIdErrorUnion && |
| 10781 | actual_type->id == TypeTableEntryIdErrorSet) | 10884 | actual_type->id == ZigTypeIdErrorSet) |
| 10782 | { | 10885 | { |
| 10783 | return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type); | 10886 | return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type); |
| 10784 | } | 10887 | } |
| 10785 | | 10888 | |
| 10786 | // cast from T to E!?T | 10889 | // cast from T to E!?T |
| 10787 | if (wanted_type->id == TypeTableEntryIdErrorUnion && | 10890 | if (wanted_type->id == ZigTypeIdErrorUnion && |
| 10788 | wanted_type->data.error_union.payload_type->id == TypeTableEntryIdOptional && | 10891 | wanted_type->data.error_union.payload_type->id == ZigTypeIdOptional && |
| 10789 | actual_type->id != TypeTableEntryIdOptional) | 10892 | actual_type->id != ZigTypeIdOptional) |
| 10790 | { | 10893 | { |
| 10791 | TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type; | 10894 | ZigType *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type; |
| 10792 | if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, false).id == ConstCastResultIdOk || | 10895 | if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, false).id == ConstCastResultIdOk || |
| 10793 | actual_type->id == TypeTableEntryIdNull || | 10896 | actual_type->id == ZigTypeIdNull || |
| 10794 | actual_type->id == TypeTableEntryIdComptimeInt || | 10897 | actual_type->id == ZigTypeIdComptimeInt || |
| 10795 | actual_type->id == TypeTableEntryIdComptimeFloat) | 10898 | actual_type->id == ZigTypeIdComptimeFloat) |
| 10796 | { | 10899 | { |
| 10797 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); | 10900 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); |
| 10798 | if (type_is_invalid(cast1->value.type)) | 10901 | if (type_is_invalid(cast1->value.type)) |
| ... | @@ -10808,12 +10911,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10808,12 +10911,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10808 | | 10911 | |
| 10809 | // cast from number literal to another type | 10912 | // cast from number literal to another type |
| 10810 | // cast from number literal to *const integer | 10913 | // cast from number literal to *const integer |
| 10811 | if (actual_type->id == TypeTableEntryIdComptimeFloat || | 10914 | if (actual_type->id == ZigTypeIdComptimeFloat || |
| 10812 | actual_type->id == TypeTableEntryIdComptimeInt) | 10915 | actual_type->id == ZigTypeIdComptimeInt) |
| 10813 | { | 10916 | { |
| 10814 | if ((err = ensure_complete_type(ira->codegen, wanted_type))) | 10917 | if ((err = ensure_complete_type(ira->codegen, wanted_type))) |
| 10815 | return ira->codegen->invalid_instruction; | 10918 | return ira->codegen->invalid_instruction; |
| 10816 | if (wanted_type->id == TypeTableEntryIdEnum) { | 10919 | if (wanted_type->id == ZigTypeIdEnum) { |
| 10817 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value); | 10920 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value); |
| 10818 | if (type_is_invalid(cast1->value.type)) | 10921 | if (type_is_invalid(cast1->value.type)) |
| 10819 | return ira->codegen->invalid_instruction; | 10922 | return ira->codegen->invalid_instruction; |
| ... | @@ -10823,7 +10926,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10823,7 +10926,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10823 | return ira->codegen->invalid_instruction; | 10926 | return ira->codegen->invalid_instruction; |
| 10824 | | 10927 | |
| 10825 | return cast2; | 10928 | return cast2; |
| 10826 | } else if (wanted_type->id == TypeTableEntryIdPointer && | 10929 | } else if (wanted_type->id == ZigTypeIdPointer && |
| 10827 | wanted_type->data.pointer.is_const) | 10930 | wanted_type->data.pointer.is_const) |
| 10828 | { | 10931 | { |
| 10829 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value); | 10932 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value); |
| ... | @@ -10837,15 +10940,15 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10837,15 +10940,15 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10837 | return cast2; | 10940 | return cast2; |
| 10838 | } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) { | 10941 | } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) { |
| 10839 | CastOp op; | 10942 | CastOp op; |
| 10840 | if ((actual_type->id == TypeTableEntryIdComptimeFloat && | 10943 | if ((actual_type->id == ZigTypeIdComptimeFloat && |
| 10841 | wanted_type->id == TypeTableEntryIdFloat) || | 10944 | wanted_type->id == ZigTypeIdFloat) || |
| 10842 | (actual_type->id == TypeTableEntryIdComptimeInt && | 10945 | (actual_type->id == ZigTypeIdComptimeInt && |
| 10843 | wanted_type->id == TypeTableEntryIdInt)) | 10946 | wanted_type->id == ZigTypeIdInt)) |
| 10844 | { | 10947 | { |
| 10845 | op = CastOpNumLitToConcrete; | 10948 | op = CastOpNumLitToConcrete; |
| 10846 | } else if (wanted_type->id == TypeTableEntryIdInt) { | 10949 | } else if (wanted_type->id == ZigTypeIdInt) { |
| 10847 | op = CastOpFloatToInt; | 10950 | op = CastOpFloatToInt; |
| 10848 | } else if (wanted_type->id == TypeTableEntryIdFloat) { | 10951 | } else if (wanted_type->id == ZigTypeIdFloat) { |
| 10849 | op = CastOpIntToFloat; | 10952 | op = CastOpIntToFloat; |
| 10850 | } else { | 10953 | } else { |
| 10851 | zig_unreachable(); | 10954 | zig_unreachable(); |
| ... | @@ -10859,14 +10962,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10859,14 +10962,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10859 | // cast from typed number to integer or float literal. | 10962 | // cast from typed number to integer or float literal. |
| 10860 | // works when the number is known at compile time | 10963 | // works when the number is known at compile time |
| 10861 | if (instr_is_comptime(value) && | 10964 | if (instr_is_comptime(value) && |
| 10862 | ((actual_type->id == TypeTableEntryIdInt && wanted_type->id == TypeTableEntryIdComptimeInt) || | 10965 | ((actual_type->id == ZigTypeIdInt && wanted_type->id == ZigTypeIdComptimeInt) || |
| 10863 | (actual_type->id == TypeTableEntryIdFloat && wanted_type->id == TypeTableEntryIdComptimeFloat))) | 10966 | (actual_type->id == ZigTypeIdFloat && wanted_type->id == ZigTypeIdComptimeFloat))) |
| 10864 | { | 10967 | { |
| 10865 | return ir_analyze_number_to_literal(ira, source_instr, value, wanted_type); | 10968 | return ir_analyze_number_to_literal(ira, source_instr, value, wanted_type); |
| 10866 | } | 10969 | } |
| 10867 | | 10970 | |
| 10868 | // cast from union to the enum type of the union | 10971 | // cast from union to the enum type of the union |
| 10869 | if (actual_type->id == TypeTableEntryIdUnion && wanted_type->id == TypeTableEntryIdEnum) { | 10972 | if (actual_type->id == ZigTypeIdUnion && wanted_type->id == ZigTypeIdEnum) { |
| 10870 | if ((err = type_ensure_zero_bits_known(ira->codegen, actual_type))) | 10973 | if ((err = type_ensure_zero_bits_known(ira->codegen, actual_type))) |
| 10871 | return ira->codegen->invalid_instruction; | 10974 | return ira->codegen->invalid_instruction; |
| 10872 | | 10975 | |
| ... | @@ -10876,7 +10979,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10876,7 +10979,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10876 | } | 10979 | } |
| 10877 | | 10980 | |
| 10878 | // enum to union which has the enum as the tag type | 10981 | // enum to union which has the enum as the tag type |
| 10879 | if (wanted_type->id == TypeTableEntryIdUnion && actual_type->id == TypeTableEntryIdEnum && | 10982 | if (wanted_type->id == ZigTypeIdUnion && actual_type->id == ZigTypeIdEnum && |
| 10880 | (wanted_type->data.unionation.decl_node->data.container_decl.auto_enum || | 10983 | (wanted_type->data.unionation.decl_node->data.container_decl.auto_enum || |
| 10881 | wanted_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) | 10984 | wanted_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) |
| 10882 | { | 10985 | { |
| ... | @@ -10889,8 +10992,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10889,8 +10992,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10889 | } | 10992 | } |
| 10890 | | 10993 | |
| 10891 | // enum to &const union which has the enum as the tag type | 10994 | // enum to &const union which has the enum as the tag type |
| 10892 | if (actual_type->id == TypeTableEntryIdEnum && wanted_type->id == TypeTableEntryIdPointer) { | 10995 | if (actual_type->id == ZigTypeIdEnum && wanted_type->id == ZigTypeIdPointer) { |
| 10893 | TypeTableEntry *union_type = wanted_type->data.pointer.child_type; | 10996 | ZigType *union_type = wanted_type->data.pointer.child_type; |
| 10894 | if (union_type->data.unionation.decl_node->data.container_decl.auto_enum || | 10997 | if (union_type->data.unionation.decl_node->data.container_decl.auto_enum || |
| 10895 | union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr) | 10998 | union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr) |
| 10896 | { | 10999 | { |
| ... | @@ -10912,11 +11015,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10912,11 +11015,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10912 | } | 11015 | } |
| 10913 | | 11016 | |
| 10914 | // cast from *T to *[1]T | 11017 | // cast from *T to *[1]T |
| 10915 | if (wanted_type->id == TypeTableEntryIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle && | 11018 | if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle && |
| 10916 | actual_type->id == TypeTableEntryIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle) | 11019 | actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle) |
| 10917 | { | 11020 | { |
| 10918 | TypeTableEntry *array_type = wanted_type->data.pointer.child_type; | 11021 | ZigType *array_type = wanted_type->data.pointer.child_type; |
| 10919 | if (array_type->id == TypeTableEntryIdArray && array_type->data.array.len == 1 && | 11022 | if (array_type->id == ZigTypeIdArray && array_type->data.array.len == 1 && |
| 10920 | types_match_const_cast_only(ira, array_type->data.array.child_type, | 11023 | types_match_const_cast_only(ira, array_type->data.array.child_type, |
| 10921 | actual_type->data.pointer.child_type, source_node, | 11024 | actual_type->data.pointer.child_type, source_node, |
| 10922 | !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) | 11025 | !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| ... | @@ -10936,7 +11039,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10936,7 +11039,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10936 | } | 11039 | } |
| 10937 | | 11040 | |
| 10938 | // cast from T to *T where T is zero bits | 11041 | // cast from T to *T where T is zero bits |
| 10939 | if (wanted_type->id == TypeTableEntryIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle && | 11042 | if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle && |
| 10940 | types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, | 11043 | types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 10941 | actual_type, source_node, !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) | 11044 | actual_type, source_node, !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 10942 | { | 11045 | { |
| ... | @@ -10950,13 +11053,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10950,13 +11053,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10950 | | 11053 | |
| 10951 | | 11054 | |
| 10952 | // cast from undefined to anything | 11055 | // cast from undefined to anything |
| 10953 | if (actual_type->id == TypeTableEntryIdUndefined) { | 11056 | if (actual_type->id == ZigTypeIdUndefined) { |
| 10954 | return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type); | 11057 | return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type); |
| 10955 | } | 11058 | } |
| 10956 | | 11059 | |
| 10957 | // cast from something to const pointer of it | 11060 | // cast from something to const pointer of it |
| 10958 | if (!type_requires_comptime(actual_type)) { | 11061 | if (!type_requires_comptime(actual_type)) { |
| 10959 | TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); | 11062 | ZigType *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); |
| 10960 | if (types_match_const_cast_only(ira, wanted_type, const_ptr_actual, source_node, false).id == ConstCastResultIdOk) { | 11063 | if (types_match_const_cast_only(ira, wanted_type, const_ptr_actual, source_node, false).id == ConstCastResultIdOk) { |
| 10961 | return ir_analyze_cast_ref(ira, source_instr, value, wanted_type); | 11064 | return ir_analyze_cast_ref(ira, source_instr, value, wanted_type); |
| 10962 | } | 11065 | } |
| ... | @@ -10970,7 +11073,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10970,7 +11073,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10970 | return ira->codegen->invalid_instruction; | 11073 | return ira->codegen->invalid_instruction; |
| 10971 | } | 11074 | } |
| 10972 | | 11075 | |
| 10973 | static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type) { | 11076 | static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) { |
| 10974 | assert(value); | 11077 | assert(value); |
| 10975 | assert(value != ira->codegen->invalid_instruction); | 11078 | assert(value != ira->codegen->invalid_instruction); |
| 10976 | assert(!expected_type || !type_is_invalid(expected_type)); | 11079 | assert(!expected_type || !type_is_invalid(expected_type)); |
| ... | @@ -10980,23 +11083,25 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ | ... | @@ -10980,23 +11083,25 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ |
| 10980 | return value; // anything will do | 11083 | return value; // anything will do |
| 10981 | if (expected_type == value->value.type) | 11084 | if (expected_type == value->value.type) |
| 10982 | return value; // match | 11085 | return value; // match |
| 10983 | if (value->value.type->id == TypeTableEntryIdUnreachable) | 11086 | if (value->value.type->id == ZigTypeIdUnreachable) |
| 10984 | return value; | 11087 | return value; |
| 10985 | | 11088 | |
| 10986 | return ir_analyze_cast(ira, value, expected_type, value); | 11089 | return ir_analyze_cast(ira, value, expected_type, value); |
| 10987 | } | 11090 | } |
| 10988 | | 11091 | |
| 10989 | static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr) { | 11092 | static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr) { |
| 10990 | TypeTableEntry *type_entry = ptr->value.type; | 11093 | ZigType *type_entry = ptr->value.type; |
| 10991 | if (type_is_invalid(type_entry)) { | 11094 | if (type_is_invalid(type_entry)) { |
| 10992 | return ira->codegen->invalid_instruction; | 11095 | return ira->codegen->invalid_instruction; |
| 10993 | } else if (type_entry->id == TypeTableEntryIdPointer) { | 11096 | } else if (type_entry->id == ZigTypeIdPointer) { |
| 10994 | TypeTableEntry *child_type = type_entry->data.pointer.child_type; | 11097 | ZigType *child_type = type_entry->data.pointer.child_type; |
| 10995 | if (instr_is_comptime(ptr)) { | 11098 | if (instr_is_comptime(ptr)) { |
| 10996 | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst || | 11099 | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst || |
| 10997 | ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) | 11100 | ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) |
| 10998 | { | 11101 | { |
| 10999 | ConstExprValue *pointee = const_ptr_pointee(ira->codegen, &ptr->value); | 11102 | ConstExprValue *pointee = ir_const_ptr_pointee(ira, &ptr->value, source_instruction->source_node); |
| | 11103 | if (pointee == nullptr) |
| | 11104 | return ira->codegen->invalid_instruction; |
| 11000 | if (pointee->special != ConstValSpecialRuntime) { | 11105 | if (pointee->special != ConstValSpecialRuntime) { |
| 11001 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope, | 11106 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope, |
| 11002 | source_instruction->source_node, child_type); | 11107 | source_instruction->source_node, child_type); |
| ... | @@ -11019,7 +11124,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc | ... | @@ -11019,7 +11124,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 11019 | } | 11124 | } |
| 11020 | } | 11125 | } |
| 11021 | | 11126 | |
| 11022 | static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value, | 11127 | static ZigType *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value, |
| 11023 | bool is_const, bool is_volatile) | 11128 | bool is_const, bool is_volatile) |
| 11024 | { | 11129 | { |
| 11025 | IrInstruction *result = ir_get_ref(ira, source_instruction, value, is_const, is_volatile); | 11130 | IrInstruction *result = ir_get_ref(ira, source_instruction, value, is_const, is_volatile); |
| ... | @@ -11054,7 +11159,7 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, uint32_t *out | ... | @@ -11054,7 +11159,7 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, uint32_t *out |
| 11054 | return true; | 11159 | return true; |
| 11055 | } | 11160 | } |
| 11056 | | 11161 | |
| 11057 | static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *int_type, uint64_t *out) { | 11162 | static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *int_type, uint64_t *out) { |
| 11058 | if (type_is_invalid(value->value.type)) | 11163 | if (type_is_invalid(value->value.type)) |
| 11059 | return false; | 11164 | return false; |
| 11060 | | 11165 | |
| ... | @@ -11103,8 +11208,8 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic | ... | @@ -11103,8 +11208,8 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic |
| 11103 | return false; | 11208 | return false; |
| 11104 | | 11209 | |
| 11105 | ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder"); | 11210 | ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder"); |
| 11106 | assert(atomic_order_val->type->id == TypeTableEntryIdMetaType); | 11211 | assert(atomic_order_val->type->id == ZigTypeIdMetaType); |
| 11107 | TypeTableEntry *atomic_order_type = atomic_order_val->data.x_type; | 11212 | ZigType *atomic_order_type = atomic_order_val->data.x_type; |
| 11108 | | 11213 | |
| 11109 | IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type); | 11214 | IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type); |
| 11110 | if (type_is_invalid(casted_value->value.type)) | 11215 | if (type_is_invalid(casted_value->value.type)) |
| ... | @@ -11123,8 +11228,8 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi | ... | @@ -11123,8 +11228,8 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi |
| 11123 | return false; | 11228 | return false; |
| 11124 | | 11229 | |
| 11125 | ConstExprValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp"); | 11230 | ConstExprValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp"); |
| 11126 | assert(atomic_rmw_op_val->type->id == TypeTableEntryIdMetaType); | 11231 | assert(atomic_rmw_op_val->type->id == ZigTypeIdMetaType); |
| 11127 | TypeTableEntry *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type; | 11232 | ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type; |
| 11128 | | 11233 | |
| 11129 | IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type); | 11234 | IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type); |
| 11130 | if (type_is_invalid(casted_value->value.type)) | 11235 | if (type_is_invalid(casted_value->value.type)) |
| ... | @@ -11143,8 +11248,8 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob | ... | @@ -11143,8 +11248,8 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob |
| 11143 | return false; | 11248 | return false; |
| 11144 | | 11249 | |
| 11145 | ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage"); | 11250 | ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage"); |
| 11146 | assert(global_linkage_val->type->id == TypeTableEntryIdMetaType); | 11251 | assert(global_linkage_val->type->id == ZigTypeIdMetaType); |
| 11147 | TypeTableEntry *global_linkage_type = global_linkage_val->data.x_type; | 11252 | ZigType *global_linkage_type = global_linkage_val->data.x_type; |
| 11148 | | 11253 | |
| 11149 | IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type); | 11254 | IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type); |
| 11150 | if (type_is_invalid(casted_value->value.type)) | 11255 | if (type_is_invalid(casted_value->value.type)) |
| ... | @@ -11163,8 +11268,8 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod | ... | @@ -11163,8 +11268,8 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod |
| 11163 | return false; | 11268 | return false; |
| 11164 | | 11269 | |
| 11165 | ConstExprValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode"); | 11270 | ConstExprValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode"); |
| 11166 | assert(float_mode_val->type->id == TypeTableEntryIdMetaType); | 11271 | assert(float_mode_val->type->id == ZigTypeIdMetaType); |
| 11167 | TypeTableEntry *float_mode_type = float_mode_val->data.x_type; | 11272 | ZigType *float_mode_type = float_mode_val->data.x_type; |
| 11168 | | 11273 | |
| 11169 | IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type); | 11274 | IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type); |
| 11170 | if (type_is_invalid(casted_value->value.type)) | 11275 | if (type_is_invalid(casted_value->value.type)) |
| ... | @@ -11183,10 +11288,10 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { | ... | @@ -11183,10 +11288,10 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 11183 | if (type_is_invalid(value->value.type)) | 11288 | if (type_is_invalid(value->value.type)) |
| 11184 | return nullptr; | 11289 | return nullptr; |
| 11185 | | 11290 | |
| 11186 | TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 11291 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 11187 | true, false, PtrLenUnknown, | 11292 | true, false, PtrLenUnknown, |
| 11188 | get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); | 11293 | get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); |
| 11189 | TypeTableEntry *str_type = get_slice_type(ira->codegen, ptr_type); | 11294 | ZigType *str_type = get_slice_type(ira->codegen, ptr_type); |
| 11190 | IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type); | 11295 | IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type); |
| 11191 | if (type_is_invalid(casted_value->value.type)) | 11296 | if (type_is_invalid(casted_value->value.type)) |
| 11192 | return nullptr; | 11297 | return nullptr; |
| ... | @@ -11219,7 +11324,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { | ... | @@ -11219,7 +11324,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 11219 | return result; | 11324 | return result; |
| 11220 | } | 11325 | } |
| 11221 | | 11326 | |
| 11222 | static TypeTableEntry *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira, | 11327 | static ZigType *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira, |
| 11223 | IrInstructionAddImplicitReturnType *instruction) | 11328 | IrInstructionAddImplicitReturnType *instruction) |
| 11224 | { | 11329 | { |
| 11225 | IrInstruction *value = instruction->value->other; | 11330 | IrInstruction *value = instruction->value->other; |
| ... | @@ -11233,7 +11338,7 @@ static TypeTableEntry *ir_analyze_instruction_add_implicit_return_type(IrAnalyze | ... | @@ -11233,7 +11338,7 @@ static TypeTableEntry *ir_analyze_instruction_add_implicit_return_type(IrAnalyze |
| 11233 | return out_val->type; | 11338 | return out_val->type; |
| 11234 | } | 11339 | } |
| 11235 | | 11340 | |
| 11236 | static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira, | 11341 | static ZigType *ir_analyze_instruction_return(IrAnalyze *ira, |
| 11237 | IrInstructionReturn *return_instruction) | 11342 | IrInstructionReturn *return_instruction) |
| 11238 | { | 11343 | { |
| 11239 | IrInstruction *value = return_instruction->value->other; | 11344 | IrInstruction *value = return_instruction->value->other; |
| ... | @@ -11245,7 +11350,7 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira, | ... | @@ -11245,7 +11350,7 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira, |
| 11245 | return ir_unreach_error(ira); | 11350 | return ir_unreach_error(ira); |
| 11246 | | 11351 | |
| 11247 | if (casted_value->value.special == ConstValSpecialRuntime && | 11352 | if (casted_value->value.special == ConstValSpecialRuntime && |
| 11248 | casted_value->value.type->id == TypeTableEntryIdPointer && | 11353 | casted_value->value.type->id == ZigTypeIdPointer && |
| 11249 | casted_value->value.data.rh_ptr == RuntimeHintPtrStack) | 11354 | casted_value->value.data.rh_ptr == RuntimeHintPtrStack) |
| 11250 | { | 11355 | { |
| 11251 | ir_add_error(ira, casted_value, buf_sprintf("function returns address of local variable")); | 11356 | ir_add_error(ira, casted_value, buf_sprintf("function returns address of local variable")); |
| ... | @@ -11258,13 +11363,13 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira, | ... | @@ -11258,13 +11363,13 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira, |
| 11258 | return ir_finish_anal(ira, result->value.type); | 11363 | return ir_finish_anal(ira, result->value.type); |
| 11259 | } | 11364 | } |
| 11260 | | 11365 | |
| 11261 | static TypeTableEntry *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) { | 11366 | static ZigType *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) { |
| 11262 | ConstExprValue *out_val = ir_build_const_from(ira, &const_instruction->base); | 11367 | ConstExprValue *out_val = ir_build_const_from(ira, &const_instruction->base); |
| 11263 | *out_val = const_instruction->base.value; | 11368 | *out_val = const_instruction->base.value; |
| 11264 | return const_instruction->base.value.type; | 11369 | return const_instruction->base.value.type; |
| 11265 | } | 11370 | } |
| 11266 | | 11371 | |
| 11267 | static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { | 11372 | static ZigType *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 11268 | IrInstruction *op1 = bin_op_instruction->op1->other; | 11373 | IrInstruction *op1 = bin_op_instruction->op1->other; |
| 11269 | if (type_is_invalid(op1->value.type)) | 11374 | if (type_is_invalid(op1->value.type)) |
| 11270 | return ira->codegen->builtin_types.entry_invalid; | 11375 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -11273,7 +11378,7 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -11273,7 +11378,7 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp |
| 11273 | if (type_is_invalid(op2->value.type)) | 11378 | if (type_is_invalid(op2->value.type)) |
| 11274 | return ira->codegen->builtin_types.entry_invalid; | 11379 | return ira->codegen->builtin_types.entry_invalid; |
| 11275 | | 11380 | |
| 11276 | TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool; | 11381 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| 11277 | | 11382 | |
| 11278 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, bool_type); | 11383 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, bool_type); |
| 11279 | if (casted_op1 == ira->codegen->invalid_instruction) | 11384 | if (casted_op1 == ira->codegen->invalid_instruction) |
| ... | @@ -11293,8 +11398,8 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -11293,8 +11398,8 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp |
| 11293 | if (op2_val == nullptr) | 11398 | if (op2_val == nullptr) |
| 11294 | return ira->codegen->builtin_types.entry_invalid; | 11399 | return ira->codegen->builtin_types.entry_invalid; |
| 11295 | | 11400 | |
| 11296 | assert(casted_op1->value.type->id == TypeTableEntryIdBool); | 11401 | assert(casted_op1->value.type->id == ZigTypeIdBool); |
| 11297 | assert(casted_op2->value.type->id == TypeTableEntryIdBool); | 11402 | assert(casted_op2->value.type->id == ZigTypeIdBool); |
| 11298 | if (bin_op_instruction->op_id == IrBinOpBoolOr) { | 11403 | if (bin_op_instruction->op_id == IrBinOpBoolOr) { |
| 11299 | out_val->data.x_bool = op1_val->data.x_bool || op2_val->data.x_bool; | 11404 | out_val->data.x_bool = op1_val->data.x_bool || op2_val->data.x_bool; |
| 11300 | } else if (bin_op_instruction->op_id == IrBinOpBoolAnd) { | 11405 | } else if (bin_op_instruction->op_id == IrBinOpBoolAnd) { |
| ... | @@ -11338,7 +11443,7 @@ static bool optional_value_is_null(ConstExprValue *val) { | ... | @@ -11338,7 +11443,7 @@ static bool optional_value_is_null(ConstExprValue *val) { |
| 11338 | } | 11443 | } |
| 11339 | } | 11444 | } |
| 11340 | | 11445 | |
| 11341 | static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { | 11446 | static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 11342 | Error err; | 11447 | Error err; |
| 11343 | IrInstruction *op1 = bin_op_instruction->op1->other; | 11448 | IrInstruction *op1 = bin_op_instruction->op1->other; |
| 11344 | IrInstruction *op2 = bin_op_instruction->op2->other; | 11449 | IrInstruction *op2 = bin_op_instruction->op2->other; |
| ... | @@ -11347,19 +11452,19 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -11347,19 +11452,19 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 11347 | IrBinOp op_id = bin_op_instruction->op_id; | 11452 | IrBinOp op_id = bin_op_instruction->op_id; |
| 11348 | bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq); | 11453 | bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq); |
| 11349 | if (is_equality_cmp && | 11454 | if (is_equality_cmp && |
| 11350 | ((op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdOptional) || | 11455 | ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdOptional) || |
| 11351 | (op2->value.type->id == TypeTableEntryIdNull && op1->value.type->id == TypeTableEntryIdOptional) || | 11456 | (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdOptional) || |
| 11352 | (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull))) | 11457 | (op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull))) |
| 11353 | { | 11458 | { |
| 11354 | if (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull) { | 11459 | if (op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull) { |
| 11355 | ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base); | 11460 | ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base); |
| 11356 | out_val->data.x_bool = (op_id == IrBinOpCmpEq); | 11461 | out_val->data.x_bool = (op_id == IrBinOpCmpEq); |
| 11357 | return ira->codegen->builtin_types.entry_bool; | 11462 | return ira->codegen->builtin_types.entry_bool; |
| 11358 | } | 11463 | } |
| 11359 | IrInstruction *maybe_op; | 11464 | IrInstruction *maybe_op; |
| 11360 | if (op1->value.type->id == TypeTableEntryIdNull) { | 11465 | if (op1->value.type->id == ZigTypeIdNull) { |
| 11361 | maybe_op = op2; | 11466 | maybe_op = op2; |
| 11362 | } else if (op2->value.type->id == TypeTableEntryIdNull) { | 11467 | } else if (op2->value.type->id == ZigTypeIdNull) { |
| 11363 | maybe_op = op1; | 11468 | maybe_op = op1; |
| 11364 | } else { | 11469 | } else { |
| 11365 | zig_unreachable(); | 11470 | zig_unreachable(); |
| ... | @@ -11386,12 +11491,12 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -11386,12 +11491,12 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 11386 | return ira->codegen->builtin_types.entry_bool; | 11491 | return ira->codegen->builtin_types.entry_bool; |
| 11387 | } | 11492 | } |
| 11388 | | 11493 | |
| 11389 | if (op1->value.type->id == TypeTableEntryIdErrorSet && op2->value.type->id == TypeTableEntryIdErrorSet) { | 11494 | if (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) { |
| 11390 | if (!is_equality_cmp) { | 11495 | if (!is_equality_cmp) { |
| 11391 | ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors")); | 11496 | ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors")); |
| 11392 | return ira->codegen->builtin_types.entry_invalid; | 11497 | return ira->codegen->builtin_types.entry_invalid; |
| 11393 | } | 11498 | } |
| 11394 | TypeTableEntry *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node); | 11499 | ZigType *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node); |
| 11395 | if (type_is_invalid(intersect_type)) { | 11500 | if (type_is_invalid(intersect_type)) { |
| 11396 | return ira->codegen->builtin_types.entry_invalid; | 11501 | return ira->codegen->builtin_types.entry_invalid; |
| 11397 | } | 11502 | } |
| ... | @@ -11472,7 +11577,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -11472,7 +11577,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 11472 | } | 11577 | } |
| 11473 | | 11578 | |
| 11474 | IrInstruction *instructions[] = {op1, op2}; | 11579 | IrInstruction *instructions[] = {op1, op2}; |
| 11475 | TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2); | 11580 | ZigType *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2); |
| 11476 | if (type_is_invalid(resolved_type)) | 11581 | if (type_is_invalid(resolved_type)) |
| 11477 | return resolved_type; | 11582 | return resolved_type; |
| 11478 | if ((err = type_ensure_zero_bits_known(ira->codegen, resolved_type))) | 11583 | if ((err = type_ensure_zero_bits_known(ira->codegen, resolved_type))) |
| ... | @@ -11480,42 +11585,42 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -11480,42 +11585,42 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 11480 | | 11585 | |
| 11481 | bool operator_allowed; | 11586 | bool operator_allowed; |
| 11482 | switch (resolved_type->id) { | 11587 | switch (resolved_type->id) { |
| 11483 | case TypeTableEntryIdInvalid: | 11588 | case ZigTypeIdInvalid: |
| 11484 | zig_unreachable(); // handled above | 11589 | zig_unreachable(); // handled above |
| 11485 | | 11590 | |
| 11486 | case TypeTableEntryIdComptimeFloat: | 11591 | case ZigTypeIdComptimeFloat: |
| 11487 | case TypeTableEntryIdComptimeInt: | 11592 | case ZigTypeIdComptimeInt: |
| 11488 | case TypeTableEntryIdInt: | 11593 | case ZigTypeIdInt: |
| 11489 | case TypeTableEntryIdFloat: | 11594 | case ZigTypeIdFloat: |
| 11490 | operator_allowed = true; | 11595 | operator_allowed = true; |
| 11491 | break; | 11596 | break; |
| 11492 | | 11597 | |
| 11493 | case TypeTableEntryIdBool: | 11598 | case ZigTypeIdBool: |
| 11494 | case TypeTableEntryIdMetaType: | 11599 | case ZigTypeIdMetaType: |
| 11495 | case TypeTableEntryIdVoid: | 11600 | case ZigTypeIdVoid: |
| 11496 | case TypeTableEntryIdPointer: | 11601 | case ZigTypeIdPointer: |
| 11497 | case TypeTableEntryIdErrorSet: | 11602 | case ZigTypeIdErrorSet: |
| 11498 | case TypeTableEntryIdFn: | 11603 | case ZigTypeIdFn: |
| 11499 | case TypeTableEntryIdOpaque: | 11604 | case ZigTypeIdOpaque: |
| 11500 | case TypeTableEntryIdNamespace: | 11605 | case ZigTypeIdNamespace: |
| 11501 | case TypeTableEntryIdBlock: | 11606 | case ZigTypeIdBlock: |
| 11502 | case TypeTableEntryIdBoundFn: | 11607 | case ZigTypeIdBoundFn: |
| 11503 | case TypeTableEntryIdArgTuple: | 11608 | case ZigTypeIdArgTuple: |
| 11504 | case TypeTableEntryIdPromise: | 11609 | case ZigTypeIdPromise: |
| 11505 | case TypeTableEntryIdEnum: | 11610 | case ZigTypeIdEnum: |
| 11506 | operator_allowed = is_equality_cmp; | 11611 | operator_allowed = is_equality_cmp; |
| 11507 | break; | 11612 | break; |
| 11508 | | 11613 | |
| 11509 | case TypeTableEntryIdUnreachable: | 11614 | case ZigTypeIdUnreachable: |
| 11510 | case TypeTableEntryIdArray: | 11615 | case ZigTypeIdArray: |
| 11511 | case TypeTableEntryIdStruct: | 11616 | case ZigTypeIdStruct: |
| 11512 | case TypeTableEntryIdUndefined: | 11617 | case ZigTypeIdUndefined: |
| 11513 | case TypeTableEntryIdNull: | 11618 | case ZigTypeIdNull: |
| 11514 | case TypeTableEntryIdErrorUnion: | 11619 | case ZigTypeIdErrorUnion: |
| 11515 | case TypeTableEntryIdUnion: | 11620 | case ZigTypeIdUnion: |
| 11516 | operator_allowed = false; | 11621 | operator_allowed = false; |
| 11517 | break; | 11622 | break; |
| 11518 | case TypeTableEntryIdOptional: | 11623 | case ZigTypeIdOptional: |
| 11519 | operator_allowed = is_equality_cmp && get_codegen_ptr_type(resolved_type) != nullptr; | 11624 | operator_allowed = is_equality_cmp && get_codegen_ptr_type(resolved_type) != nullptr; |
| 11520 | break; | 11625 | break; |
| 11521 | } | 11626 | } |
| ... | @@ -11543,10 +11648,10 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -11543,10 +11648,10 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 11543 | return ira->codegen->builtin_types.entry_invalid; | 11648 | return ira->codegen->builtin_types.entry_invalid; |
| 11544 | | 11649 | |
| 11545 | bool answer; | 11650 | bool answer; |
| 11546 | if (resolved_type->id == TypeTableEntryIdComptimeFloat || resolved_type->id == TypeTableEntryIdFloat) { | 11651 | if (resolved_type->id == ZigTypeIdComptimeFloat || resolved_type->id == ZigTypeIdFloat) { |
| 11547 | Cmp cmp_result = float_cmp(op1_val, op2_val); | 11652 | Cmp cmp_result = float_cmp(op1_val, op2_val); |
| 11548 | answer = resolve_cmp_op_id(op_id, cmp_result); | 11653 | answer = resolve_cmp_op_id(op_id, cmp_result); |
| 11549 | } else if (resolved_type->id == TypeTableEntryIdComptimeInt || resolved_type->id == TypeTableEntryIdInt) { | 11654 | } else if (resolved_type->id == ZigTypeIdComptimeInt || resolved_type->id == ZigTypeIdInt) { |
| 11550 | Cmp cmp_result = bigint_cmp(&op1_val->data.x_bigint, &op2_val->data.x_bigint); | 11655 | Cmp cmp_result = bigint_cmp(&op1_val->data.x_bigint, &op2_val->data.x_bigint); |
| 11551 | answer = resolve_cmp_op_id(op_id, cmp_result); | 11656 | answer = resolve_cmp_op_id(op_id, cmp_result); |
| 11552 | } else { | 11657 | } else { |
| ... | @@ -11566,7 +11671,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -11566,7 +11671,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 11566 | } | 11671 | } |
| 11567 | | 11672 | |
| 11568 | // some comparisons with unsigned numbers can be evaluated | 11673 | // some comparisons with unsigned numbers can be evaluated |
| 11569 | if (resolved_type->id == TypeTableEntryIdInt && !resolved_type->data.integral.is_signed) { | 11674 | if (resolved_type->id == ZigTypeIdInt && !resolved_type->data.integral.is_signed) { |
| 11570 | ConstExprValue *known_left_val; | 11675 | ConstExprValue *known_left_val; |
| 11571 | IrBinOp flipped_op_id; | 11676 | IrBinOp flipped_op_id; |
| 11572 | if (instr_is_comptime(casted_op1)) { | 11677 | if (instr_is_comptime(casted_op1)) { |
| ... | @@ -11610,18 +11715,18 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -11610,18 +11715,18 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 11610 | return ira->codegen->builtin_types.entry_bool; | 11715 | return ira->codegen->builtin_types.entry_bool; |
| 11611 | } | 11716 | } |
| 11612 | | 11717 | |
| 11613 | static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, | 11718 | static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val, |
| 11614 | IrBinOp op_id, ConstExprValue *op2_val, ConstExprValue *out_val) | 11719 | IrBinOp op_id, ConstExprValue *op2_val, ConstExprValue *out_val) |
| 11615 | { | 11720 | { |
| 11616 | bool is_int; | 11721 | bool is_int; |
| 11617 | bool is_float; | 11722 | bool is_float; |
| 11618 | Cmp op2_zcmp; | 11723 | Cmp op2_zcmp; |
| 11619 | if (type_entry->id == TypeTableEntryIdInt || type_entry->id == TypeTableEntryIdComptimeInt) { | 11724 | if (type_entry->id == ZigTypeIdInt || type_entry->id == ZigTypeIdComptimeInt) { |
| 11620 | is_int = true; | 11725 | is_int = true; |
| 11621 | is_float = false; | 11726 | is_float = false; |
| 11622 | op2_zcmp = bigint_cmp_zero(&op2_val->data.x_bigint); | 11727 | op2_zcmp = bigint_cmp_zero(&op2_val->data.x_bigint); |
| 11623 | } else if (type_entry->id == TypeTableEntryIdFloat || | 11728 | } else if (type_entry->id == ZigTypeIdFloat || |
| 11624 | type_entry->id == TypeTableEntryIdComptimeFloat) | 11729 | type_entry->id == ZigTypeIdComptimeFloat) |
| 11625 | { | 11730 | { |
| 11626 | is_int = false; | 11731 | is_int = false; |
| 11627 | is_float = true; | 11732 | is_float = true; |
| ... | @@ -11671,7 +11776,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, | ... | @@ -11671,7 +11776,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, |
| 11671 | bigint_shl(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint); | 11776 | bigint_shl(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint); |
| 11672 | break; | 11777 | break; |
| 11673 | case IrBinOpBitShiftLeftLossy: | 11778 | case IrBinOpBitShiftLeftLossy: |
| 11674 | assert(type_entry->id == TypeTableEntryIdInt); | 11779 | assert(type_entry->id == ZigTypeIdInt); |
| 11675 | bigint_shl_trunc(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint, | 11780 | bigint_shl_trunc(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint, |
| 11676 | type_entry->data.integral.bit_count, type_entry->data.integral.is_signed); | 11781 | type_entry->data.integral.bit_count, type_entry->data.integral.is_signed); |
| 11677 | break; | 11782 | break; |
| ... | @@ -11698,7 +11803,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, | ... | @@ -11698,7 +11803,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, |
| 11698 | } | 11803 | } |
| 11699 | break; | 11804 | break; |
| 11700 | case IrBinOpAddWrap: | 11805 | case IrBinOpAddWrap: |
| 11701 | assert(type_entry->id == TypeTableEntryIdInt); | 11806 | assert(type_entry->id == ZigTypeIdInt); |
| 11702 | bigint_add_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint, | 11807 | bigint_add_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint, |
| 11703 | type_entry->data.integral.bit_count, type_entry->data.integral.is_signed); | 11808 | type_entry->data.integral.bit_count, type_entry->data.integral.is_signed); |
| 11704 | break; | 11809 | break; |
| ... | @@ -11710,7 +11815,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, | ... | @@ -11710,7 +11815,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, |
| 11710 | } | 11815 | } |
| 11711 | break; | 11816 | break; |
| 11712 | case IrBinOpSubWrap: | 11817 | case IrBinOpSubWrap: |
| 11713 | assert(type_entry->id == TypeTableEntryIdInt); | 11818 | assert(type_entry->id == ZigTypeIdInt); |
| 11714 | bigint_sub_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint, | 11819 | bigint_sub_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint, |
| 11715 | type_entry->data.integral.bit_count, type_entry->data.integral.is_signed); | 11820 | type_entry->data.integral.bit_count, type_entry->data.integral.is_signed); |
| 11716 | break; | 11821 | break; |
| ... | @@ -11722,7 +11827,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, | ... | @@ -11722,7 +11827,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, |
| 11722 | } | 11827 | } |
| 11723 | break; | 11828 | break; |
| 11724 | case IrBinOpMultWrap: | 11829 | case IrBinOpMultWrap: |
| 11725 | assert(type_entry->id == TypeTableEntryIdInt); | 11830 | assert(type_entry->id == ZigTypeIdInt); |
| 11726 | bigint_mul_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint, | 11831 | bigint_mul_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint, |
| 11727 | type_entry->data.integral.bit_count, type_entry->data.integral.is_signed); | 11832 | type_entry->data.integral.bit_count, type_entry->data.integral.is_signed); |
| 11728 | break; | 11833 | break; |
| ... | @@ -11777,7 +11882,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, | ... | @@ -11777,7 +11882,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, |
| 11777 | break; | 11882 | break; |
| 11778 | } | 11883 | } |
| 11779 | | 11884 | |
| 11780 | if (type_entry->id == TypeTableEntryIdInt) { | 11885 | if (type_entry->id == ZigTypeIdInt) { |
| 11781 | if (!bigint_fits_in_bits(&out_val->data.x_bigint, type_entry->data.integral.bit_count, | 11886 | if (!bigint_fits_in_bits(&out_val->data.x_bigint, type_entry->data.integral.bit_count, |
| 11782 | type_entry->data.integral.is_signed)) | 11887 | type_entry->data.integral.is_signed)) |
| 11783 | { | 11888 | { |
| ... | @@ -11790,12 +11895,12 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, | ... | @@ -11790,12 +11895,12 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, |
| 11790 | return 0; | 11895 | return 0; |
| 11791 | } | 11896 | } |
| 11792 | | 11897 | |
| 11793 | static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { | 11898 | static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 11794 | IrInstruction *op1 = bin_op_instruction->op1->other; | 11899 | IrInstruction *op1 = bin_op_instruction->op1->other; |
| 11795 | if (type_is_invalid(op1->value.type)) | 11900 | if (type_is_invalid(op1->value.type)) |
| 11796 | return ira->codegen->builtin_types.entry_invalid; | 11901 | return ira->codegen->builtin_types.entry_invalid; |
| 11797 | | 11902 | |
| 11798 | if (op1->value.type->id != TypeTableEntryIdInt && op1->value.type->id != TypeTableEntryIdComptimeInt) { | 11903 | if (op1->value.type->id != ZigTypeIdInt && op1->value.type->id != ZigTypeIdComptimeInt) { |
| 11799 | ir_add_error(ira, &bin_op_instruction->base, | 11904 | ir_add_error(ira, &bin_op_instruction->base, |
| 11800 | buf_sprintf("bit shifting operation expected integer type, found '%s'", | 11905 | buf_sprintf("bit shifting operation expected integer type, found '%s'", |
| 11801 | buf_ptr(&op1->value.type->name))); | 11906 | buf_ptr(&op1->value.type->name))); |
| ... | @@ -11808,7 +11913,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -11808,7 +11913,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp * |
| 11808 | | 11913 | |
| 11809 | IrInstruction *casted_op2; | 11914 | IrInstruction *casted_op2; |
| 11810 | IrBinOp op_id = bin_op_instruction->op_id; | 11915 | IrBinOp op_id = bin_op_instruction->op_id; |
| 11811 | if (op1->value.type->id == TypeTableEntryIdComptimeInt) { | 11916 | if (op1->value.type->id == ZigTypeIdComptimeInt) { |
| 11812 | casted_op2 = op2; | 11917 | casted_op2 = op2; |
| 11813 | | 11918 | |
| 11814 | if (op_id == IrBinOpBitShiftLeftLossy) { | 11919 | if (op_id == IrBinOpBitShiftLeftLossy) { |
| ... | @@ -11822,10 +11927,10 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -11822,10 +11927,10 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp * |
| 11822 | return ira->codegen->builtin_types.entry_invalid; | 11927 | return ira->codegen->builtin_types.entry_invalid; |
| 11823 | } | 11928 | } |
| 11824 | } else { | 11929 | } else { |
| 11825 | TypeTableEntry *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, | 11930 | ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, |
| 11826 | op1->value.type->data.integral.bit_count - 1); | 11931 | op1->value.type->data.integral.bit_count - 1); |
| 11827 | if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy && | 11932 | if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy && |
| 11828 | op2->value.type->id == TypeTableEntryIdComptimeInt) { | 11933 | op2->value.type->id == ZigTypeIdComptimeInt) { |
| 11829 | if (!bigint_fits_in_bits(&op2->value.data.x_bigint, | 11934 | if (!bigint_fits_in_bits(&op2->value.data.x_bigint, |
| 11830 | shift_amt_type->data.integral.bit_count, | 11935 | shift_amt_type->data.integral.bit_count, |
| 11831 | op2->value.data.x_bigint.is_negative)) { | 11936 | op2->value.data.x_bigint.is_negative)) { |
| ... | @@ -11879,7 +11984,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -11879,7 +11984,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp * |
| 11879 | | 11984 | |
| 11880 | ir_num_lit_fits_in_other_type(ira, result_instruction, op1->value.type, false); | 11985 | ir_num_lit_fits_in_other_type(ira, result_instruction, op1->value.type, false); |
| 11881 | return op1->value.type; | 11986 | return op1->value.type; |
| 11882 | } else if (op1->value.type->id == TypeTableEntryIdComptimeInt) { | 11987 | } else if (op1->value.type->id == ZigTypeIdComptimeInt) { |
| 11883 | ir_add_error(ira, &bin_op_instruction->base, | 11988 | ir_add_error(ira, &bin_op_instruction->base, |
| 11884 | buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known")); | 11989 | buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known")); |
| 11885 | return ira->codegen->builtin_types.entry_invalid; | 11990 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -11890,7 +11995,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -11890,7 +11995,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp * |
| 11890 | return op1->value.type; | 11995 | return op1->value.type; |
| 11891 | } | 11996 | } |
| 11892 | | 11997 | |
| 11893 | static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { | 11998 | static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 11894 | IrInstruction *op1 = bin_op_instruction->op1->other; | 11999 | IrInstruction *op1 = bin_op_instruction->op1->other; |
| 11895 | if (type_is_invalid(op1->value.type)) | 12000 | if (type_is_invalid(op1->value.type)) |
| 11896 | return ira->codegen->builtin_types.entry_invalid; | 12001 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -11902,7 +12007,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -11902,7 +12007,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 11902 | IrBinOp op_id = bin_op_instruction->op_id; | 12007 | IrBinOp op_id = bin_op_instruction->op_id; |
| 11903 | | 12008 | |
| 11904 | // look for pointer math | 12009 | // look for pointer math |
| 11905 | if (op1->value.type->id == TypeTableEntryIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenUnknown && | 12010 | if (op1->value.type->id == ZigTypeIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenUnknown && |
| 11906 | (op_id == IrBinOpAdd || op_id == IrBinOpSub)) | 12011 | (op_id == IrBinOpAdd || op_id == IrBinOpSub)) |
| 11907 | { | 12012 | { |
| 11908 | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize); | 12013 | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize); |
| ... | @@ -11917,19 +12022,19 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -11917,19 +12022,19 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 11917 | } | 12022 | } |
| 11918 | | 12023 | |
| 11919 | IrInstruction *instructions[] = {op1, op2}; | 12024 | IrInstruction *instructions[] = {op1, op2}; |
| 11920 | TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, nullptr, instructions, 2); | 12025 | ZigType *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, nullptr, instructions, 2); |
| 11921 | if (type_is_invalid(resolved_type)) | 12026 | if (type_is_invalid(resolved_type)) |
| 11922 | return resolved_type; | 12027 | return resolved_type; |
| 11923 | | 12028 | |
| 11924 | bool is_int = resolved_type->id == TypeTableEntryIdInt || resolved_type->id == TypeTableEntryIdComptimeInt; | 12029 | bool is_int = resolved_type->id == ZigTypeIdInt || resolved_type->id == ZigTypeIdComptimeInt; |
| 11925 | bool is_float = resolved_type->id == TypeTableEntryIdFloat || resolved_type->id == TypeTableEntryIdComptimeFloat; | 12030 | bool is_float = resolved_type->id == ZigTypeIdFloat || resolved_type->id == ZigTypeIdComptimeFloat; |
| 11926 | bool is_signed_div = ( | 12031 | bool is_signed_div = ( |
| 11927 | (resolved_type->id == TypeTableEntryIdInt && resolved_type->data.integral.is_signed) || | 12032 | (resolved_type->id == ZigTypeIdInt && resolved_type->data.integral.is_signed) || |
| 11928 | resolved_type->id == TypeTableEntryIdFloat || | 12033 | resolved_type->id == ZigTypeIdFloat || |
| 11929 | (resolved_type->id == TypeTableEntryIdComptimeFloat && | 12034 | (resolved_type->id == ZigTypeIdComptimeFloat && |
| 11930 | ((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) != | 12035 | ((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) != |
| 11931 | (bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) || | 12036 | (bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) || |
| 11932 | (resolved_type->id == TypeTableEntryIdComptimeInt && | 12037 | (resolved_type->id == ZigTypeIdComptimeInt && |
| 11933 | ((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) != | 12038 | ((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) != |
| 11934 | (bigint_cmp_zero(&op2->value.data.x_bigint) != CmpGT))) | 12039 | (bigint_cmp_zero(&op2->value.data.x_bigint) != CmpGT))) |
| 11935 | ); | 12040 | ); |
| ... | @@ -12051,7 +12156,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -12051,7 +12156,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 12051 | return ira->codegen->builtin_types.entry_invalid; | 12156 | return ira->codegen->builtin_types.entry_invalid; |
| 12052 | } | 12157 | } |
| 12053 | | 12158 | |
| 12054 | if (resolved_type->id == TypeTableEntryIdComptimeInt) { | 12159 | if (resolved_type->id == ZigTypeIdComptimeInt) { |
| 12055 | if (op_id == IrBinOpAddWrap) { | 12160 | if (op_id == IrBinOpAddWrap) { |
| 12056 | op_id = IrBinOpAdd; | 12161 | op_id = IrBinOpAdd; |
| 12057 | } else if (op_id == IrBinOpSubWrap) { | 12162 | } else if (op_id == IrBinOpSubWrap) { |
| ... | @@ -12111,14 +12216,14 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -12111,14 +12216,14 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 12111 | } | 12216 | } |
| 12112 | | 12217 | |
| 12113 | | 12218 | |
| 12114 | static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) { | 12219 | static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 12115 | IrInstruction *op1 = instruction->op1->other; | 12220 | IrInstruction *op1 = instruction->op1->other; |
| 12116 | TypeTableEntry *op1_type = op1->value.type; | 12221 | ZigType *op1_type = op1->value.type; |
| 12117 | if (type_is_invalid(op1_type)) | 12222 | if (type_is_invalid(op1_type)) |
| 12118 | return ira->codegen->builtin_types.entry_invalid; | 12223 | return ira->codegen->builtin_types.entry_invalid; |
| 12119 | | 12224 | |
| 12120 | IrInstruction *op2 = instruction->op2->other; | 12225 | IrInstruction *op2 = instruction->op2->other; |
| 12121 | TypeTableEntry *op2_type = op2->value.type; | 12226 | ZigType *op2_type = op2->value.type; |
| 12122 | if (type_is_invalid(op2_type)) | 12227 | if (type_is_invalid(op2_type)) |
| 12123 | return ira->codegen->builtin_types.entry_invalid; | 12228 | return ira->codegen->builtin_types.entry_invalid; |
| 12124 | | 12229 | |
| ... | @@ -12133,13 +12238,13 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -12133,13 +12238,13 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 12133 | ConstExprValue *op1_array_val; | 12238 | ConstExprValue *op1_array_val; |
| 12134 | size_t op1_array_index; | 12239 | size_t op1_array_index; |
| 12135 | size_t op1_array_end; | 12240 | size_t op1_array_end; |
| 12136 | TypeTableEntry *child_type; | 12241 | ZigType *child_type; |
| 12137 | if (op1_type->id == TypeTableEntryIdArray) { | 12242 | if (op1_type->id == ZigTypeIdArray) { |
| 12138 | child_type = op1_type->data.array.child_type; | 12243 | child_type = op1_type->data.array.child_type; |
| 12139 | op1_array_val = op1_val; | 12244 | op1_array_val = op1_val; |
| 12140 | op1_array_index = 0; | 12245 | op1_array_index = 0; |
| 12141 | op1_array_end = op1_type->data.array.len; | 12246 | op1_array_end = op1_type->data.array.len; |
| 12142 | } else if (op1_type->id == TypeTableEntryIdPointer && | 12247 | } else if (op1_type->id == ZigTypeIdPointer && |
| 12143 | op1_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 && | 12248 | op1_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 && |
| 12144 | op1_val->data.x_ptr.special == ConstPtrSpecialBaseArray && | 12249 | op1_val->data.x_ptr.special == ConstPtrSpecialBaseArray && |
| 12145 | op1_val->data.x_ptr.data.base_array.is_cstr) | 12250 | op1_val->data.x_ptr.data.base_array.is_cstr) |
| ... | @@ -12149,7 +12254,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -12149,7 +12254,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 12149 | op1_array_index = op1_val->data.x_ptr.data.base_array.elem_index; | 12254 | op1_array_index = op1_val->data.x_ptr.data.base_array.elem_index; |
| 12150 | op1_array_end = op1_array_val->type->data.array.len - 1; | 12255 | op1_array_end = op1_array_val->type->data.array.len - 1; |
| 12151 | } else if (is_slice(op1_type)) { | 12256 | } else if (is_slice(op1_type)) { |
| 12152 | TypeTableEntry *ptr_type = op1_type->data.structure.fields[slice_ptr_index].type_entry; | 12257 | ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index].type_entry; |
| 12153 | child_type = ptr_type->data.pointer.child_type; | 12258 | child_type = ptr_type->data.pointer.child_type; |
| 12154 | ConstExprValue *ptr_val = &op1_val->data.x_struct.fields[slice_ptr_index]; | 12259 | ConstExprValue *ptr_val = &op1_val->data.x_struct.fields[slice_ptr_index]; |
| 12155 | assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray); | 12260 | assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray); |
| ... | @@ -12165,7 +12270,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -12165,7 +12270,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 12165 | ConstExprValue *op2_array_val; | 12270 | ConstExprValue *op2_array_val; |
| 12166 | size_t op2_array_index; | 12271 | size_t op2_array_index; |
| 12167 | size_t op2_array_end; | 12272 | size_t op2_array_end; |
| 12168 | if (op2_type->id == TypeTableEntryIdArray) { | 12273 | if (op2_type->id == ZigTypeIdArray) { |
| 12169 | if (op2_type->data.array.child_type != child_type) { | 12274 | if (op2_type->data.array.child_type != child_type) { |
| 12170 | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", | 12275 | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", |
| 12171 | buf_ptr(&child_type->name), | 12276 | buf_ptr(&child_type->name), |
| ... | @@ -12175,7 +12280,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -12175,7 +12280,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 12175 | op2_array_val = op2_val; | 12280 | op2_array_val = op2_val; |
| 12176 | op2_array_index = 0; | 12281 | op2_array_index = 0; |
| 12177 | op2_array_end = op2_array_val->type->data.array.len; | 12282 | op2_array_end = op2_array_val->type->data.array.len; |
| 12178 | } else if (op2_type->id == TypeTableEntryIdPointer && | 12283 | } else if (op2_type->id == ZigTypeIdPointer && |
| 12179 | op2_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 && | 12284 | op2_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 && |
| 12180 | op2_val->data.x_ptr.special == ConstPtrSpecialBaseArray && | 12285 | op2_val->data.x_ptr.special == ConstPtrSpecialBaseArray && |
| 12181 | op2_val->data.x_ptr.data.base_array.is_cstr) | 12286 | op2_val->data.x_ptr.data.base_array.is_cstr) |
| ... | @@ -12190,7 +12295,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -12190,7 +12295,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 12190 | op2_array_index = op2_val->data.x_ptr.data.base_array.elem_index; | 12295 | op2_array_index = op2_val->data.x_ptr.data.base_array.elem_index; |
| 12191 | op2_array_end = op2_array_val->type->data.array.len - 1; | 12296 | op2_array_end = op2_array_val->type->data.array.len - 1; |
| 12192 | } else if (is_slice(op2_type)) { | 12297 | } else if (is_slice(op2_type)) { |
| 12193 | TypeTableEntry *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry; | 12298 | ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry; |
| 12194 | if (ptr_type->data.pointer.child_type != child_type) { | 12299 | if (ptr_type->data.pointer.child_type != child_type) { |
| 12195 | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", | 12300 | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", |
| 12196 | buf_ptr(&child_type->name), | 12301 | buf_ptr(&child_type->name), |
| ... | @@ -12210,15 +12315,15 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -12210,15 +12315,15 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 12210 | | 12315 | |
| 12211 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 12316 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 12212 | | 12317 | |
| 12213 | TypeTableEntry *result_type; | 12318 | ZigType *result_type; |
| 12214 | ConstExprValue *out_array_val; | 12319 | ConstExprValue *out_array_val; |
| 12215 | size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index); | 12320 | size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index); |
| 12216 | if (op1_type->id == TypeTableEntryIdArray || op2_type->id == TypeTableEntryIdArray) { | 12321 | if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) { |
| 12217 | result_type = get_array_type(ira->codegen, child_type, new_len); | 12322 | result_type = get_array_type(ira->codegen, child_type, new_len); |
| 12218 | | 12323 | |
| 12219 | out_array_val = out_val; | 12324 | out_array_val = out_val; |
| 12220 | } else if (is_slice(op1_type) || is_slice(op2_type)) { | 12325 | } else if (is_slice(op1_type) || is_slice(op2_type)) { |
| 12221 | TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, | 12326 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 12222 | true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, child_type), 0, 0); | 12327 | true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, child_type), 0, 0); |
| 12223 | result_type = get_slice_type(ira->codegen, ptr_type); | 12328 | result_type = get_slice_type(ira->codegen, ptr_type); |
| 12224 | out_array_val = create_const_vals(1); | 12329 | out_array_val = create_const_vals(1); |
| ... | @@ -12279,7 +12384,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -12279,7 +12384,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 12279 | return result_type; | 12384 | return result_type; |
| 12280 | } | 12385 | } |
| 12281 | | 12386 | |
| 12282 | static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) { | 12387 | static ZigType *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 12283 | IrInstruction *op1 = instruction->op1->other; | 12388 | IrInstruction *op1 = instruction->op1->other; |
| 12284 | if (type_is_invalid(op1->value.type)) | 12389 | if (type_is_invalid(op1->value.type)) |
| 12285 | return ira->codegen->builtin_types.entry_invalid; | 12390 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -12296,8 +12401,8 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -12296,8 +12401,8 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp |
| 12296 | if (!ir_resolve_usize(ira, op2, &mult_amt)) | 12401 | if (!ir_resolve_usize(ira, op2, &mult_amt)) |
| 12297 | return ira->codegen->builtin_types.entry_invalid; | 12402 | return ira->codegen->builtin_types.entry_invalid; |
| 12298 | | 12403 | |
| 12299 | TypeTableEntry *array_type = op1->value.type; | 12404 | ZigType *array_type = op1->value.type; |
| 12300 | if (array_type->id != TypeTableEntryIdArray) { | 12405 | if (array_type->id != ZigTypeIdArray) { |
| 12301 | ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name))); | 12406 | ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name))); |
| 12302 | return ira->codegen->builtin_types.entry_invalid; | 12407 | return ira->codegen->builtin_types.entry_invalid; |
| 12303 | } | 12408 | } |
| ... | @@ -12315,7 +12420,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -12315,7 +12420,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp |
| 12315 | if (array_val->data.x_array.special == ConstArraySpecialUndef) { | 12420 | if (array_val->data.x_array.special == ConstArraySpecialUndef) { |
| 12316 | out_val->data.x_array.special = ConstArraySpecialUndef; | 12421 | out_val->data.x_array.special = ConstArraySpecialUndef; |
| 12317 | | 12422 | |
| 12318 | TypeTableEntry *child_type = array_type->data.array.child_type; | 12423 | ZigType *child_type = array_type->data.array.child_type; |
| 12319 | return get_array_type(ira->codegen, child_type, new_array_len); | 12424 | return get_array_type(ira->codegen, child_type, new_array_len); |
| 12320 | } | 12425 | } |
| 12321 | | 12426 | |
| ... | @@ -12330,16 +12435,16 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -12330,16 +12435,16 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp |
| 12330 | } | 12435 | } |
| 12331 | assert(i == new_array_len); | 12436 | assert(i == new_array_len); |
| 12332 | | 12437 | |
| 12333 | TypeTableEntry *child_type = array_type->data.array.child_type; | 12438 | ZigType *child_type = array_type->data.array.child_type; |
| 12334 | return get_array_type(ira->codegen, child_type, new_array_len); | 12439 | return get_array_type(ira->codegen, child_type, new_array_len); |
| 12335 | } | 12440 | } |
| 12336 | | 12441 | |
| 12337 | static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) { | 12442 | static ZigType *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 12338 | TypeTableEntry *op1_type = ir_resolve_type(ira, instruction->op1->other); | 12443 | ZigType *op1_type = ir_resolve_type(ira, instruction->op1->other); |
| 12339 | if (type_is_invalid(op1_type)) | 12444 | if (type_is_invalid(op1_type)) |
| 12340 | return ira->codegen->builtin_types.entry_invalid; | 12445 | return ira->codegen->builtin_types.entry_invalid; |
| 12341 | | 12446 | |
| 12342 | TypeTableEntry *op2_type = ir_resolve_type(ira, instruction->op2->other); | 12447 | ZigType *op2_type = ir_resolve_type(ira, instruction->op2->other); |
| 12343 | if (type_is_invalid(op2_type)) | 12448 | if (type_is_invalid(op2_type)) |
| 12344 | return ira->codegen->builtin_types.entry_invalid; | 12449 | return ira->codegen->builtin_types.entry_invalid; |
| 12345 | | 12450 | |
| ... | @@ -12365,7 +12470,7 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction | ... | @@ -12365,7 +12470,7 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction |
| 12365 | assert(errors[error_entry->value] == nullptr); | 12470 | assert(errors[error_entry->value] == nullptr); |
| 12366 | errors[error_entry->value] = error_entry; | 12471 | errors[error_entry->value] = error_entry; |
| 12367 | } | 12472 | } |
| 12368 | TypeTableEntry *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type); | 12473 | ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type); |
| 12369 | free(errors); | 12474 | free(errors); |
| 12370 | | 12475 | |
| 12371 | | 12476 | |
| ... | @@ -12374,7 +12479,7 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction | ... | @@ -12374,7 +12479,7 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction |
| 12374 | return ira->codegen->builtin_types.entry_type; | 12479 | return ira->codegen->builtin_types.entry_type; |
| 12375 | } | 12480 | } |
| 12376 | | 12481 | |
| 12377 | static TypeTableEntry *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { | 12482 | static ZigType *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 12378 | IrBinOp op_id = bin_op_instruction->op_id; | 12483 | IrBinOp op_id = bin_op_instruction->op_id; |
| 12379 | switch (op_id) { | 12484 | switch (op_id) { |
| 12380 | case IrBinOpInvalid: | 12485 | case IrBinOpInvalid: |
| ... | @@ -12421,9 +12526,9 @@ static TypeTableEntry *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructi | ... | @@ -12421,9 +12526,9 @@ static TypeTableEntry *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructi |
| 12421 | zig_unreachable(); | 12526 | zig_unreachable(); |
| 12422 | } | 12527 | } |
| 12423 | | 12528 | |
| 12424 | static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDeclVar *decl_var_instruction) { | 12529 | static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDeclVar *decl_var_instruction) { |
| 12425 | Error err; | 12530 | Error err; |
| 12426 | VariableTableEntry *var = decl_var_instruction->var; | 12531 | ZigVar *var = decl_var_instruction->var; |
| 12427 | | 12532 | |
| 12428 | IrInstruction *init_value = decl_var_instruction->init_value->other; | 12533 | IrInstruction *init_value = decl_var_instruction->init_value->other; |
| 12429 | if (type_is_invalid(init_value->value.type)) { | 12534 | if (type_is_invalid(init_value->value.type)) { |
| ... | @@ -12431,11 +12536,11 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc | ... | @@ -12431,11 +12536,11 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 12431 | return var->value->type; | 12536 | return var->value->type; |
| 12432 | } | 12537 | } |
| 12433 | | 12538 | |
| 12434 | TypeTableEntry *explicit_type = nullptr; | 12539 | ZigType *explicit_type = nullptr; |
| 12435 | IrInstruction *var_type = nullptr; | 12540 | IrInstruction *var_type = nullptr; |
| 12436 | if (decl_var_instruction->var_type != nullptr) { | 12541 | if (decl_var_instruction->var_type != nullptr) { |
| 12437 | var_type = decl_var_instruction->var_type->other; | 12542 | var_type = decl_var_instruction->var_type->other; |
| 12438 | TypeTableEntry *proposed_type = ir_resolve_type(ira, var_type); | 12543 | ZigType *proposed_type = ir_resolve_type(ira, var_type); |
| 12439 | explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type); | 12544 | explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type); |
| 12440 | if (type_is_invalid(explicit_type)) { | 12545 | if (type_is_invalid(explicit_type)) { |
| 12441 | var->value->type = ira->codegen->builtin_types.entry_invalid; | 12546 | var->value->type = ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -12450,7 +12555,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc | ... | @@ -12450,7 +12555,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 12450 | | 12555 | |
| 12451 | bool var_class_requires_const = false; | 12556 | bool var_class_requires_const = false; |
| 12452 | | 12557 | |
| 12453 | TypeTableEntry *result_type = casted_init_value->value.type; | 12558 | ZigType *result_type = casted_init_value->value.type; |
| 12454 | if (type_is_invalid(result_type)) { | 12559 | if (type_is_invalid(result_type)) { |
| 12455 | result_type = ira->codegen->builtin_types.entry_invalid; | 12560 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 12456 | } else { | 12561 | } else { |
| ... | @@ -12460,8 +12565,8 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc | ... | @@ -12460,8 +12565,8 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 12460 | } | 12565 | } |
| 12461 | | 12566 | |
| 12462 | if (!type_is_invalid(result_type)) { | 12567 | if (!type_is_invalid(result_type)) { |
| 12463 | if (result_type->id == TypeTableEntryIdUnreachable || | 12568 | if (result_type->id == ZigTypeIdUnreachable || |
| 12464 | result_type->id == TypeTableEntryIdOpaque) | 12569 | result_type->id == ZigTypeIdOpaque) |
| 12465 | { | 12570 | { |
| 12466 | ir_add_error_node(ira, source_node, | 12571 | ir_add_error_node(ira, source_node, |
| 12467 | buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name))); | 12572 | buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name))); |
| ... | @@ -12476,7 +12581,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc | ... | @@ -12476,7 +12581,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 12476 | } | 12581 | } |
| 12477 | } else { | 12582 | } else { |
| 12478 | if (casted_init_value->value.special == ConstValSpecialStatic && | 12583 | if (casted_init_value->value.special == ConstValSpecialStatic && |
| 12479 | casted_init_value->value.type->id == TypeTableEntryIdFn && | 12584 | casted_init_value->value.type->id == ZigTypeIdFn && |
| 12480 | casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways) | 12585 | casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways) |
| 12481 | { | 12586 | { |
| 12482 | var_class_requires_const = true; | 12587 | var_class_requires_const = true; |
| ... | @@ -12496,7 +12601,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc | ... | @@ -12496,7 +12601,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 12496 | // This means that this is actually a different variable due to, e.g. an inline while loop. | 12601 | // This means that this is actually a different variable due to, e.g. an inline while loop. |
| 12497 | // We make a new variable so that it can hold a different type, and so the debug info can | 12602 | // We make a new variable so that it can hold a different type, and so the debug info can |
| 12498 | // be distinct. | 12603 | // be distinct. |
| 12499 | VariableTableEntry *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope, | 12604 | ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope, |
| 12500 | &var->name, var->src_is_const, var->gen_is_const, var->shadowable, var->is_comptime, true); | 12605 | &var->name, var->src_is_const, var->gen_is_const, var->shadowable, var->is_comptime, true); |
| 12501 | new_var->owner_exec = var->owner_exec; | 12606 | new_var->owner_exec = var->owner_exec; |
| 12502 | new_var->align_bytes = var->align_bytes; | 12607 | new_var->align_bytes = var->align_bytes; |
| ... | @@ -12549,14 +12654,14 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc | ... | @@ -12549,14 +12654,14 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 12549 | | 12654 | |
| 12550 | ir_build_var_decl_from(&ira->new_irb, &decl_var_instruction->base, var, var_type, nullptr, casted_init_value); | 12655 | ir_build_var_decl_from(&ira->new_irb, &decl_var_instruction->base, var, var_type, nullptr, casted_init_value); |
| 12551 | | 12656 | |
| 12552 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); | 12657 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 12553 | if (fn_entry) | 12658 | if (fn_entry) |
| 12554 | fn_entry->variable_list.append(var); | 12659 | fn_entry->variable_list.append(var); |
| 12555 | | 12660 | |
| 12556 | return ira->codegen->builtin_types.entry_void; | 12661 | return ira->codegen->builtin_types.entry_void; |
| 12557 | } | 12662 | } |
| 12558 | | 12663 | |
| 12559 | static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) { | 12664 | static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) { |
| 12560 | IrInstruction *name = instruction->name->other; | 12665 | IrInstruction *name = instruction->name->other; |
| 12561 | Buf *symbol_name = ir_resolve_str(ira, name); | 12666 | Buf *symbol_name = ir_resolve_str(ira, name); |
| 12562 | if (symbol_name == nullptr) { | 12667 | if (symbol_name == nullptr) { |
| ... | @@ -12585,12 +12690,12 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi | ... | @@ -12585,12 +12690,12 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi |
| 12585 | } | 12690 | } |
| 12586 | | 12691 | |
| 12587 | switch (target->value.type->id) { | 12692 | switch (target->value.type->id) { |
| 12588 | case TypeTableEntryIdInvalid: | 12693 | case ZigTypeIdInvalid: |
| 12589 | case TypeTableEntryIdUnreachable: | 12694 | case ZigTypeIdUnreachable: |
| 12590 | zig_unreachable(); | 12695 | zig_unreachable(); |
| 12591 | case TypeTableEntryIdFn: { | 12696 | case ZigTypeIdFn: { |
| 12592 | assert(target->value.data.x_ptr.special == ConstPtrSpecialFunction); | 12697 | assert(target->value.data.x_ptr.special == ConstPtrSpecialFunction); |
| 12593 | FnTableEntry *fn_entry = target->value.data.x_ptr.data.fn.fn_entry; | 12698 | ZigFn *fn_entry = target->value.data.x_ptr.data.fn.fn_entry; |
| 12594 | CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc; | 12699 | CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc; |
| 12595 | switch (cc) { | 12700 | switch (cc) { |
| 12596 | case CallingConventionUnspecified: { | 12701 | case CallingConventionUnspecified: { |
| ... | @@ -12611,7 +12716,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi | ... | @@ -12611,7 +12716,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi |
| 12611 | break; | 12716 | break; |
| 12612 | } | 12717 | } |
| 12613 | } break; | 12718 | } break; |
| 12614 | case TypeTableEntryIdStruct: | 12719 | case ZigTypeIdStruct: |
| 12615 | if (is_slice(target->value.type)) { | 12720 | if (is_slice(target->value.type)) { |
| 12616 | ir_add_error(ira, target, | 12721 | ir_add_error(ira, target, |
| 12617 | buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value.type->name))); | 12722 | buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value.type->name))); |
| ... | @@ -12621,26 +12726,26 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi | ... | @@ -12621,26 +12726,26 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi |
| 12621 | add_error_note(ira->codegen, msg, target->value.type->data.structure.decl_node, buf_sprintf("declared here")); | 12726 | add_error_note(ira->codegen, msg, target->value.type->data.structure.decl_node, buf_sprintf("declared here")); |
| 12622 | } | 12727 | } |
| 12623 | break; | 12728 | break; |
| 12624 | case TypeTableEntryIdUnion: | 12729 | case ZigTypeIdUnion: |
| 12625 | if (target->value.type->data.unionation.layout != ContainerLayoutExtern) { | 12730 | if (target->value.type->data.unionation.layout != ContainerLayoutExtern) { |
| 12626 | ErrorMsg *msg = ir_add_error(ira, target, | 12731 | ErrorMsg *msg = ir_add_error(ira, target, |
| 12627 | buf_sprintf("exported union value must be declared extern")); | 12732 | buf_sprintf("exported union value must be declared extern")); |
| 12628 | add_error_note(ira->codegen, msg, target->value.type->data.unionation.decl_node, buf_sprintf("declared here")); | 12733 | add_error_note(ira->codegen, msg, target->value.type->data.unionation.decl_node, buf_sprintf("declared here")); |
| 12629 | } | 12734 | } |
| 12630 | break; | 12735 | break; |
| 12631 | case TypeTableEntryIdEnum: | 12736 | case ZigTypeIdEnum: |
| 12632 | if (target->value.type->data.enumeration.layout != ContainerLayoutExtern) { | 12737 | if (target->value.type->data.enumeration.layout != ContainerLayoutExtern) { |
| 12633 | ErrorMsg *msg = ir_add_error(ira, target, | 12738 | ErrorMsg *msg = ir_add_error(ira, target, |
| 12634 | buf_sprintf("exported enum value must be declared extern")); | 12739 | buf_sprintf("exported enum value must be declared extern")); |
| 12635 | add_error_note(ira->codegen, msg, target->value.type->data.enumeration.decl_node, buf_sprintf("declared here")); | 12740 | add_error_note(ira->codegen, msg, target->value.type->data.enumeration.decl_node, buf_sprintf("declared here")); |
| 12636 | } | 12741 | } |
| 12637 | break; | 12742 | break; |
| 12638 | case TypeTableEntryIdMetaType: { | 12743 | case ZigTypeIdMetaType: { |
| 12639 | TypeTableEntry *type_value = target->value.data.x_type; | 12744 | ZigType *type_value = target->value.data.x_type; |
| 12640 | switch (type_value->id) { | 12745 | switch (type_value->id) { |
| 12641 | case TypeTableEntryIdInvalid: | 12746 | case ZigTypeIdInvalid: |
| 12642 | zig_unreachable(); | 12747 | zig_unreachable(); |
| 12643 | case TypeTableEntryIdStruct: | 12748 | case ZigTypeIdStruct: |
| 12644 | if (is_slice(type_value)) { | 12749 | if (is_slice(type_value)) { |
| 12645 | ir_add_error(ira, target, | 12750 | ir_add_error(ira, target, |
| 12646 | buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name))); | 12751 | buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name))); |
| ... | @@ -12650,73 +12755,73 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi | ... | @@ -12650,73 +12755,73 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi |
| 12650 | add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here")); | 12755 | add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here")); |
| 12651 | } | 12756 | } |
| 12652 | break; | 12757 | break; |
| 12653 | case TypeTableEntryIdUnion: | 12758 | case ZigTypeIdUnion: |
| 12654 | if (type_value->data.unionation.layout != ContainerLayoutExtern) { | 12759 | if (type_value->data.unionation.layout != ContainerLayoutExtern) { |
| 12655 | ErrorMsg *msg = ir_add_error(ira, target, | 12760 | ErrorMsg *msg = ir_add_error(ira, target, |
| 12656 | buf_sprintf("exported union must be declared extern")); | 12761 | buf_sprintf("exported union must be declared extern")); |
| 12657 | add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here")); | 12762 | add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here")); |
| 12658 | } | 12763 | } |
| 12659 | break; | 12764 | break; |
| 12660 | case TypeTableEntryIdEnum: | 12765 | case ZigTypeIdEnum: |
| 12661 | if (type_value->data.enumeration.layout != ContainerLayoutExtern) { | 12766 | if (type_value->data.enumeration.layout != ContainerLayoutExtern) { |
| 12662 | ErrorMsg *msg = ir_add_error(ira, target, | 12767 | ErrorMsg *msg = ir_add_error(ira, target, |
| 12663 | buf_sprintf("exported enum must be declared extern")); | 12768 | buf_sprintf("exported enum must be declared extern")); |
| 12664 | add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here")); | 12769 | add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here")); |
| 12665 | } | 12770 | } |
| 12666 | break; | 12771 | break; |
| 12667 | case TypeTableEntryIdFn: { | 12772 | case ZigTypeIdFn: { |
| 12668 | if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) { | 12773 | if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) { |
| 12669 | ir_add_error(ira, target, | 12774 | ir_add_error(ira, target, |
| 12670 | buf_sprintf("exported function type must specify calling convention")); | 12775 | buf_sprintf("exported function type must specify calling convention")); |
| 12671 | } | 12776 | } |
| 12672 | } break; | 12777 | } break; |
| 12673 | case TypeTableEntryIdInt: | 12778 | case ZigTypeIdInt: |
| 12674 | case TypeTableEntryIdFloat: | 12779 | case ZigTypeIdFloat: |
| 12675 | case TypeTableEntryIdPointer: | 12780 | case ZigTypeIdPointer: |
| 12676 | case TypeTableEntryIdArray: | 12781 | case ZigTypeIdArray: |
| 12677 | case TypeTableEntryIdBool: | 12782 | case ZigTypeIdBool: |
| 12678 | break; | 12783 | break; |
| 12679 | case TypeTableEntryIdMetaType: | 12784 | case ZigTypeIdMetaType: |
| 12680 | case TypeTableEntryIdVoid: | 12785 | case ZigTypeIdVoid: |
| 12681 | case TypeTableEntryIdUnreachable: | 12786 | case ZigTypeIdUnreachable: |
| 12682 | case TypeTableEntryIdComptimeFloat: | 12787 | case ZigTypeIdComptimeFloat: |
| 12683 | case TypeTableEntryIdComptimeInt: | 12788 | case ZigTypeIdComptimeInt: |
| 12684 | case TypeTableEntryIdUndefined: | 12789 | case ZigTypeIdUndefined: |
| 12685 | case TypeTableEntryIdNull: | 12790 | case ZigTypeIdNull: |
| 12686 | case TypeTableEntryIdOptional: | 12791 | case ZigTypeIdOptional: |
| 12687 | case TypeTableEntryIdErrorUnion: | 12792 | case ZigTypeIdErrorUnion: |
| 12688 | case TypeTableEntryIdErrorSet: | 12793 | case ZigTypeIdErrorSet: |
| 12689 | case TypeTableEntryIdNamespace: | 12794 | case ZigTypeIdNamespace: |
| 12690 | case TypeTableEntryIdBlock: | 12795 | case ZigTypeIdBlock: |
| 12691 | case TypeTableEntryIdBoundFn: | 12796 | case ZigTypeIdBoundFn: |
| 12692 | case TypeTableEntryIdArgTuple: | 12797 | case ZigTypeIdArgTuple: |
| 12693 | case TypeTableEntryIdOpaque: | 12798 | case ZigTypeIdOpaque: |
| 12694 | case TypeTableEntryIdPromise: | 12799 | case ZigTypeIdPromise: |
| 12695 | ir_add_error(ira, target, | 12800 | ir_add_error(ira, target, |
| 12696 | buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name))); | 12801 | buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name))); |
| 12697 | break; | 12802 | break; |
| 12698 | } | 12803 | } |
| 12699 | } break; | 12804 | } break; |
| 12700 | case TypeTableEntryIdVoid: | 12805 | case ZigTypeIdVoid: |
| 12701 | case TypeTableEntryIdBool: | 12806 | case ZigTypeIdBool: |
| 12702 | case TypeTableEntryIdInt: | 12807 | case ZigTypeIdInt: |
| 12703 | case TypeTableEntryIdFloat: | 12808 | case ZigTypeIdFloat: |
| 12704 | case TypeTableEntryIdPointer: | 12809 | case ZigTypeIdPointer: |
| 12705 | case TypeTableEntryIdArray: | 12810 | case ZigTypeIdArray: |
| 12706 | case TypeTableEntryIdComptimeFloat: | 12811 | case ZigTypeIdComptimeFloat: |
| 12707 | case TypeTableEntryIdComptimeInt: | 12812 | case ZigTypeIdComptimeInt: |
| 12708 | case TypeTableEntryIdUndefined: | 12813 | case ZigTypeIdUndefined: |
| 12709 | case TypeTableEntryIdNull: | 12814 | case ZigTypeIdNull: |
| 12710 | case TypeTableEntryIdOptional: | 12815 | case ZigTypeIdOptional: |
| 12711 | case TypeTableEntryIdErrorUnion: | 12816 | case ZigTypeIdErrorUnion: |
| 12712 | case TypeTableEntryIdErrorSet: | 12817 | case ZigTypeIdErrorSet: |
| 12713 | zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name)); | 12818 | zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name)); |
| 12714 | case TypeTableEntryIdNamespace: | 12819 | case ZigTypeIdNamespace: |
| 12715 | case TypeTableEntryIdBlock: | 12820 | case ZigTypeIdBlock: |
| 12716 | case TypeTableEntryIdBoundFn: | 12821 | case ZigTypeIdBoundFn: |
| 12717 | case TypeTableEntryIdArgTuple: | 12822 | case ZigTypeIdArgTuple: |
| 12718 | case TypeTableEntryIdOpaque: | 12823 | case ZigTypeIdOpaque: |
| 12719 | case TypeTableEntryIdPromise: | 12824 | case ZigTypeIdPromise: |
| 12720 | ir_add_error(ira, target, | 12825 | ir_add_error(ira, target, |
| 12721 | buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name))); | 12826 | buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name))); |
| 12722 | break; | 12827 | break; |
| ... | @@ -12727,16 +12832,16 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi | ... | @@ -12727,16 +12832,16 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi |
| 12727 | } | 12832 | } |
| 12728 | | 12833 | |
| 12729 | static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) { | 12834 | static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) { |
| 12730 | FnTableEntry *fn_entry = exec_fn_entry(exec); | 12835 | ZigFn *fn_entry = exec_fn_entry(exec); |
| 12731 | return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing; | 12836 | return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing; |
| 12732 | } | 12837 | } |
| 12733 | | 12838 | |
| 12734 | static TypeTableEntry *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, | 12839 | static ZigType *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, |
| 12735 | IrInstructionErrorReturnTrace *instruction) | 12840 | IrInstructionErrorReturnTrace *instruction) |
| 12736 | { | 12841 | { |
| 12737 | if (instruction->optional == IrInstructionErrorReturnTrace::Null) { | 12842 | if (instruction->optional == IrInstructionErrorReturnTrace::Null) { |
| 12738 | TypeTableEntry *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(ira->codegen); | 12843 | ZigType *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(ira->codegen); |
| 12739 | TypeTableEntry *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type); | 12844 | ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type); |
| 12740 | if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) { | 12845 | if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) { |
| 12741 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 12846 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 12742 | assert(get_codegen_ptr_type(optional_type) != nullptr); | 12847 | assert(get_codegen_ptr_type(optional_type) != nullptr); |
| ... | @@ -12757,25 +12862,25 @@ static TypeTableEntry *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, | ... | @@ -12757,25 +12862,25 @@ static TypeTableEntry *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, |
| 12757 | } | 12862 | } |
| 12758 | } | 12863 | } |
| 12759 | | 12864 | |
| 12760 | static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira, | 12865 | static ZigType *ir_analyze_instruction_error_union(IrAnalyze *ira, |
| 12761 | IrInstructionErrorUnion *instruction) | 12866 | IrInstructionErrorUnion *instruction) |
| 12762 | { | 12867 | { |
| 12763 | TypeTableEntry *err_set_type = ir_resolve_type(ira, instruction->err_set->other); | 12868 | ZigType *err_set_type = ir_resolve_type(ira, instruction->err_set->other); |
| 12764 | if (type_is_invalid(err_set_type)) | 12869 | if (type_is_invalid(err_set_type)) |
| 12765 | return ira->codegen->builtin_types.entry_invalid; | 12870 | return ira->codegen->builtin_types.entry_invalid; |
| 12766 | | 12871 | |
| 12767 | TypeTableEntry *payload_type = ir_resolve_type(ira, instruction->payload->other); | 12872 | ZigType *payload_type = ir_resolve_type(ira, instruction->payload->other); |
| 12768 | if (type_is_invalid(payload_type)) | 12873 | if (type_is_invalid(payload_type)) |
| 12769 | return ira->codegen->builtin_types.entry_invalid; | 12874 | return ira->codegen->builtin_types.entry_invalid; |
| 12770 | | 12875 | |
| 12771 | if (err_set_type->id != TypeTableEntryIdErrorSet) { | 12876 | if (err_set_type->id != ZigTypeIdErrorSet) { |
| 12772 | ir_add_error(ira, instruction->err_set->other, | 12877 | ir_add_error(ira, instruction->err_set->other, |
| 12773 | buf_sprintf("expected error set type, found type '%s'", | 12878 | buf_sprintf("expected error set type, found type '%s'", |
| 12774 | buf_ptr(&err_set_type->name))); | 12879 | buf_ptr(&err_set_type->name))); |
| 12775 | return ira->codegen->builtin_types.entry_invalid; | 12880 | return ira->codegen->builtin_types.entry_invalid; |
| 12776 | } | 12881 | } |
| 12777 | | 12882 | |
| 12778 | TypeTableEntry *result_type = get_error_union_type(ira->codegen, err_set_type, payload_type); | 12883 | ZigType *result_type = get_error_union_type(ira->codegen, err_set_type, payload_type); |
| 12779 | | 12884 | |
| 12780 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 12885 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 12781 | out_val->data.x_type = result_type; | 12886 | out_val->data.x_type = result_type; |
| ... | @@ -12783,7 +12888,7 @@ static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira, | ... | @@ -12783,7 +12888,7 @@ static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira, |
| 12783 | } | 12888 | } |
| 12784 | | 12889 | |
| 12785 | IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_instr, ImplicitAllocatorId id) { | 12890 | IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_instr, ImplicitAllocatorId id) { |
| 12786 | FnTableEntry *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); | 12891 | ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 12787 | if (parent_fn_entry == nullptr) { | 12892 | if (parent_fn_entry == nullptr) { |
| 12788 | ir_add_error(ira, source_instr, buf_sprintf("no implicit allocator available")); | 12893 | ir_add_error(ira, source_instr, buf_sprintf("no implicit allocator available")); |
| 12789 | return ira->codegen->invalid_instruction; | 12894 | return ira->codegen->invalid_instruction; |
| ... | @@ -12807,7 +12912,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i | ... | @@ -12807,7 +12912,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i |
| 12807 | } | 12912 | } |
| 12808 | case ImplicitAllocatorIdLocalVar: | 12913 | case ImplicitAllocatorIdLocalVar: |
| 12809 | { | 12914 | { |
| 12810 | VariableTableEntry *coro_allocator_var = ira->old_irb.exec->coro_allocator_var; | 12915 | ZigVar *coro_allocator_var = ira->old_irb.exec->coro_allocator_var; |
| 12811 | assert(coro_allocator_var != nullptr); | 12916 | assert(coro_allocator_var != nullptr); |
| 12812 | IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var); | 12917 | IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var); |
| 12813 | IrInstruction *result = ir_get_deref(ira, source_instr, var_ptr_inst); | 12918 | IrInstruction *result = ir_get_deref(ira, source_instr, var_ptr_inst); |
| ... | @@ -12818,38 +12923,38 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i | ... | @@ -12818,38 +12923,38 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i |
| 12818 | zig_unreachable(); | 12923 | zig_unreachable(); |
| 12819 | } | 12924 | } |
| 12820 | | 12925 | |
| 12821 | static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *call_instruction, FnTableEntry *fn_entry, TypeTableEntry *fn_type, | 12926 | static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *call_instruction, ZigFn *fn_entry, ZigType *fn_type, |
| 12822 | IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, IrInstruction *async_allocator_inst) | 12927 | IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, IrInstruction *async_allocator_inst) |
| 12823 | { | 12928 | { |
| 12824 | Buf *alloc_field_name = buf_create_from_str(ASYNC_ALLOC_FIELD_NAME); | 12929 | Buf *alloc_field_name = buf_create_from_str(ASYNC_ALLOC_FIELD_NAME); |
| 12825 | //Buf *free_field_name = buf_create_from_str("freeFn"); | 12930 | //Buf *free_field_name = buf_create_from_str("freeFn"); |
| 12826 | assert(async_allocator_inst->value.type->id == TypeTableEntryIdPointer); | 12931 | assert(async_allocator_inst->value.type->id == ZigTypeIdPointer); |
| 12827 | TypeTableEntry *container_type = async_allocator_inst->value.type->data.pointer.child_type; | 12932 | ZigType *container_type = async_allocator_inst->value.type->data.pointer.child_type; |
| 12828 | IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, alloc_field_name, &call_instruction->base, | 12933 | IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, alloc_field_name, &call_instruction->base, |
| 12829 | async_allocator_inst, container_type); | 12934 | async_allocator_inst, container_type); |
| 12830 | if (type_is_invalid(field_ptr_inst->value.type)) { | 12935 | if (type_is_invalid(field_ptr_inst->value.type)) { |
| 12831 | return ira->codegen->invalid_instruction; | 12936 | return ira->codegen->invalid_instruction; |
| 12832 | } | 12937 | } |
| 12833 | TypeTableEntry *ptr_to_alloc_fn_type = field_ptr_inst->value.type; | 12938 | ZigType *ptr_to_alloc_fn_type = field_ptr_inst->value.type; |
| 12834 | assert(ptr_to_alloc_fn_type->id == TypeTableEntryIdPointer); | 12939 | assert(ptr_to_alloc_fn_type->id == ZigTypeIdPointer); |
| 12835 | | 12940 | |
| 12836 | TypeTableEntry *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type; | 12941 | ZigType *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type; |
| 12837 | if (alloc_fn_type->id != TypeTableEntryIdFn) { | 12942 | if (alloc_fn_type->id != ZigTypeIdFn) { |
| 12838 | ir_add_error(ira, &call_instruction->base, | 12943 | ir_add_error(ira, &call_instruction->base, |
| 12839 | buf_sprintf("expected allocation function, found '%s'", buf_ptr(&alloc_fn_type->name))); | 12944 | buf_sprintf("expected allocation function, found '%s'", buf_ptr(&alloc_fn_type->name))); |
| 12840 | return ira->codegen->invalid_instruction; | 12945 | return ira->codegen->invalid_instruction; |
| 12841 | } | 12946 | } |
| 12842 | | 12947 | |
| 12843 | TypeTableEntry *alloc_fn_return_type = alloc_fn_type->data.fn.fn_type_id.return_type; | 12948 | ZigType *alloc_fn_return_type = alloc_fn_type->data.fn.fn_type_id.return_type; |
| 12844 | if (alloc_fn_return_type->id != TypeTableEntryIdErrorUnion) { | 12949 | if (alloc_fn_return_type->id != ZigTypeIdErrorUnion) { |
| 12845 | ir_add_error(ira, fn_ref, | 12950 | ir_add_error(ira, fn_ref, |
| 12846 | buf_sprintf("expected allocation function to return error union, but it returns '%s'", buf_ptr(&alloc_fn_return_type->name))); | 12951 | buf_sprintf("expected allocation function to return error union, but it returns '%s'", buf_ptr(&alloc_fn_return_type->name))); |
| 12847 | return ira->codegen->invalid_instruction; | 12952 | return ira->codegen->invalid_instruction; |
| 12848 | } | 12953 | } |
| 12849 | TypeTableEntry *alloc_fn_error_set_type = alloc_fn_return_type->data.error_union.err_set_type; | 12954 | ZigType *alloc_fn_error_set_type = alloc_fn_return_type->data.error_union.err_set_type; |
| 12850 | TypeTableEntry *return_type = fn_type->data.fn.fn_type_id.return_type; | 12955 | ZigType *return_type = fn_type->data.fn.fn_type_id.return_type; |
| 12851 | TypeTableEntry *promise_type = get_promise_type(ira->codegen, return_type); | 12956 | ZigType *promise_type = get_promise_type(ira->codegen, return_type); |
| 12852 | TypeTableEntry *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type); | 12957 | ZigType *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type); |
| 12853 | | 12958 | |
| 12854 | IrInstruction *result = ir_build_call(&ira->new_irb, call_instruction->base.scope, call_instruction->base.source_node, | 12959 | IrInstruction *result = ir_build_call(&ira->new_irb, call_instruction->base.scope, call_instruction->base.source_node, |
| 12855 | fn_entry, fn_ref, arg_count, casted_args, false, FnInlineAuto, true, async_allocator_inst, nullptr); | 12960 | fn_entry, fn_ref, arg_count, casted_args, false, FnInlineAuto, true, async_allocator_inst, nullptr); |
| ... | @@ -12866,7 +12971,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node | ... | @@ -12866,7 +12971,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node |
| 12866 | IrInstruction *casted_arg; | 12971 | IrInstruction *casted_arg; |
| 12867 | if (param_decl_node->data.param_decl.var_token == nullptr) { | 12972 | if (param_decl_node->data.param_decl.var_token == nullptr) { |
| 12868 | AstNode *param_type_node = param_decl_node->data.param_decl.type; | 12973 | AstNode *param_type_node = param_decl_node->data.param_decl.type; |
| 12869 | TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node); | 12974 | ZigType *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node); |
| 12870 | if (type_is_invalid(param_type)) | 12975 | if (type_is_invalid(param_type)) |
| 12871 | return false; | 12976 | return false; |
| 12872 | | 12977 | |
| ... | @@ -12882,7 +12987,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node | ... | @@ -12882,7 +12987,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node |
| 12882 | return false; | 12987 | return false; |
| 12883 | | 12988 | |
| 12884 | Buf *param_name = param_decl_node->data.param_decl.name; | 12989 | Buf *param_name = param_decl_node->data.param_decl.name; |
| 12885 | VariableTableEntry *var = add_variable(ira->codegen, param_decl_node, | 12990 | ZigVar *var = add_variable(ira->codegen, param_decl_node, |
| 12886 | *exec_scope, param_name, true, arg_val, nullptr); | 12991 | *exec_scope, param_name, true, arg_val, nullptr); |
| 12887 | *exec_scope = var->child_scope; | 12992 | *exec_scope = var->child_scope; |
| 12888 | *next_proto_i += 1; | 12993 | *next_proto_i += 1; |
| ... | @@ -12893,7 +12998,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node | ... | @@ -12893,7 +12998,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node |
| 12893 | static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node, | 12998 | static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node, |
| 12894 | IrInstruction *arg, Scope **child_scope, size_t *next_proto_i, | 12999 | IrInstruction *arg, Scope **child_scope, size_t *next_proto_i, |
| 12895 | GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstruction **casted_args, | 13000 | GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstruction **casted_args, |
| 12896 | FnTableEntry *impl_fn) | 13001 | ZigFn *impl_fn) |
| 12897 | { | 13002 | { |
| 12898 | AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i); | 13003 | AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i); |
| 12899 | assert(param_decl_node->type == NodeTypeParamDecl); | 13004 | assert(param_decl_node->type == NodeTypeParamDecl); |
| ... | @@ -12906,7 +13011,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod | ... | @@ -12906,7 +13011,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 12906 | } else { | 13011 | } else { |
| 12907 | if (param_decl_node->data.param_decl.var_token == nullptr) { | 13012 | if (param_decl_node->data.param_decl.var_token == nullptr) { |
| 12908 | AstNode *param_type_node = param_decl_node->data.param_decl.type; | 13013 | AstNode *param_type_node = param_decl_node->data.param_decl.type; |
| 12909 | TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node); | 13014 | ZigType *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node); |
| 12910 | if (type_is_invalid(param_type)) | 13015 | if (type_is_invalid(param_type)) |
| 12911 | return false; | 13016 | return false; |
| 12912 | | 13017 | |
| ... | @@ -12920,7 +13025,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod | ... | @@ -12920,7 +13025,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 12920 | } | 13025 | } |
| 12921 | | 13026 | |
| 12922 | bool comptime_arg = param_decl_node->data.param_decl.is_inline || | 13027 | bool comptime_arg = param_decl_node->data.param_decl.is_inline || |
| 12923 | casted_arg->value.type->id == TypeTableEntryIdComptimeInt || casted_arg->value.type->id == TypeTableEntryIdComptimeFloat; | 13028 | casted_arg->value.type->id == ZigTypeIdComptimeInt || casted_arg->value.type->id == ZigTypeIdComptimeFloat; |
| 12924 | | 13029 | |
| 12925 | ConstExprValue *arg_val; | 13030 | ConstExprValue *arg_val; |
| 12926 | | 13031 | |
| ... | @@ -12940,14 +13045,14 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod | ... | @@ -12940,14 +13045,14 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 12940 | Buf *param_name = param_decl_node->data.param_decl.name; | 13045 | Buf *param_name = param_decl_node->data.param_decl.name; |
| 12941 | if (!param_name) return false; | 13046 | if (!param_name) return false; |
| 12942 | if (!is_var_args) { | 13047 | if (!is_var_args) { |
| 12943 | VariableTableEntry *var = add_variable(ira->codegen, param_decl_node, | 13048 | ZigVar *var = add_variable(ira->codegen, param_decl_node, |
| 12944 | *child_scope, param_name, true, arg_val, nullptr); | 13049 | *child_scope, param_name, true, arg_val, nullptr); |
| 12945 | *child_scope = var->child_scope; | 13050 | *child_scope = var->child_scope; |
| 12946 | var->shadowable = !comptime_arg; | 13051 | var->shadowable = !comptime_arg; |
| 12947 | | 13052 | |
| 12948 | *next_proto_i += 1; | 13053 | *next_proto_i += 1; |
| 12949 | } else if (casted_arg->value.type->id == TypeTableEntryIdComptimeInt || | 13054 | } else if (casted_arg->value.type->id == ZigTypeIdComptimeInt || |
| 12950 | casted_arg->value.type->id == TypeTableEntryIdComptimeFloat) | 13055 | casted_arg->value.type->id == ZigTypeIdComptimeFloat) |
| 12951 | { | 13056 | { |
| 12952 | ir_add_error(ira, casted_arg, | 13057 | ir_add_error(ira, casted_arg, |
| 12953 | buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557")); | 13058 | buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557")); |
| ... | @@ -12972,7 +13077,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod | ... | @@ -12972,7 +13077,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 12972 | return true; | 13077 | return true; |
| 12973 | } | 13078 | } |
| 12974 | | 13079 | |
| 12975 | static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t index) { | 13080 | static ZigVar *get_fn_var_by_index(ZigFn *fn_entry, size_t index) { |
| 12976 | size_t next_var_i = 0; | 13081 | size_t next_var_i = 0; |
| 12977 | FnGenParamInfo *gen_param_info = fn_entry->type_entry->data.fn.gen_param_info; | 13082 | FnGenParamInfo *gen_param_info = fn_entry->type_entry->data.fn.gen_param_info; |
| 12978 | assert(gen_param_info != nullptr); | 13083 | assert(gen_param_info != nullptr); |
| ... | @@ -12991,7 +13096,7 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in | ... | @@ -12991,7 +13096,7 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in |
| 12991 | } | 13096 | } |
| 12992 | | 13097 | |
| 12993 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, | 13098 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 12994 | VariableTableEntry *var) | 13099 | ZigVar *var) |
| 12995 | { | 13100 | { |
| 12996 | Error err; | 13101 | Error err; |
| 12997 | while (var->next_var != nullptr) { | 13102 | while (var->next_var != nullptr) { |
| ... | @@ -13002,8 +13107,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, | ... | @@ -13002,8 +13107,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 13002 | assert(ira->codegen->errors.length != 0); | 13107 | assert(ira->codegen->errors.length != 0); |
| 13003 | return ira->codegen->invalid_instruction; | 13108 | return ira->codegen->invalid_instruction; |
| 13004 | } | 13109 | } |
| 13005 | assert(var->value->type); | 13110 | if (var->value->type == nullptr || type_is_invalid(var->value->type)) |
| 13006 | if (type_is_invalid(var->value->type)) | | |
| 13007 | return ira->codegen->invalid_instruction; | 13111 | return ira->codegen->invalid_instruction; |
| 13008 | | 13112 | |
| 13009 | bool comptime_var_mem = ir_get_var_is_comptime(var); | 13113 | bool comptime_var_mem = ir_get_var_is_comptime(var); |
| ... | @@ -13061,8 +13165,8 @@ no_mem_slot: | ... | @@ -13061,8 +13165,8 @@ no_mem_slot: |
| 13061 | return var_ptr_instruction; | 13165 | return var_ptr_instruction; |
| 13062 | } | 13166 | } |
| 13063 | | 13167 | |
| 13064 | static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction, | 13168 | static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction, |
| 13065 | FnTableEntry *fn_entry, TypeTableEntry *fn_type, IrInstruction *fn_ref, | 13169 | ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref, |
| 13066 | IrInstruction *first_arg_ptr, bool comptime_fn_call, FnInline fn_inline) | 13170 | IrInstruction *first_arg_ptr, bool comptime_fn_call, FnInline fn_inline) |
| 13067 | { | 13171 | { |
| 13068 | Error err; | 13172 | Error err; |
| ... | @@ -13082,7 +13186,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13082,7 +13186,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13082 | size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0; | 13186 | size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0; |
| 13083 | for (size_t i = 0; i < call_instruction->arg_count; i += 1) { | 13187 | for (size_t i = 0; i < call_instruction->arg_count; i += 1) { |
| 13084 | ConstExprValue *arg_tuple_value = &call_instruction->args[i]->other->value; | 13188 | ConstExprValue *arg_tuple_value = &call_instruction->args[i]->other->value; |
| 13085 | if (arg_tuple_value->type->id == TypeTableEntryIdArgTuple) { | 13189 | if (arg_tuple_value->type->id == ZigTypeIdArgTuple) { |
| 13086 | call_param_count -= 1; | 13190 | call_param_count -= 1; |
| 13087 | call_param_count += arg_tuple_value->data.x_arg_tuple.end_index - | 13191 | call_param_count += arg_tuple_value->data.x_arg_tuple.end_index - |
| 13088 | arg_tuple_value->data.x_arg_tuple.start_index; | 13192 | arg_tuple_value->data.x_arg_tuple.start_index; |
| ... | @@ -13150,14 +13254,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13150,14 +13254,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13150 | | 13254 | |
| 13151 | size_t next_proto_i = 0; | 13255 | size_t next_proto_i = 0; |
| 13152 | if (first_arg_ptr) { | 13256 | if (first_arg_ptr) { |
| 13153 | assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer); | 13257 | assert(first_arg_ptr->value.type->id == ZigTypeIdPointer); |
| 13154 | | 13258 | |
| 13155 | bool first_arg_known_bare = false; | 13259 | bool first_arg_known_bare = false; |
| 13156 | if (fn_type_id->next_param_index >= 1) { | 13260 | if (fn_type_id->next_param_index >= 1) { |
| 13157 | TypeTableEntry *param_type = fn_type_id->param_info[next_proto_i].type; | 13261 | ZigType *param_type = fn_type_id->param_info[next_proto_i].type; |
| 13158 | if (type_is_invalid(param_type)) | 13262 | if (type_is_invalid(param_type)) |
| 13159 | return ira->codegen->builtin_types.entry_invalid; | 13263 | return ira->codegen->builtin_types.entry_invalid; |
| 13160 | first_arg_known_bare = param_type->id != TypeTableEntryIdPointer; | 13264 | first_arg_known_bare = param_type->id != ZigTypeIdPointer; |
| 13161 | } | 13265 | } |
| 13162 | | 13266 | |
| 13163 | IrInstruction *first_arg; | 13267 | IrInstruction *first_arg; |
| ... | @@ -13190,11 +13294,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13190,11 +13294,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13190 | } | 13294 | } |
| 13191 | | 13295 | |
| 13192 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; | 13296 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; |
| 13193 | TypeTableEntry *specified_return_type = analyze_type_expr(ira->codegen, exec_scope, return_type_node); | 13297 | ZigType *specified_return_type = analyze_type_expr(ira->codegen, exec_scope, return_type_node); |
| 13194 | if (type_is_invalid(specified_return_type)) | 13298 | if (type_is_invalid(specified_return_type)) |
| 13195 | return ira->codegen->builtin_types.entry_invalid; | 13299 | return ira->codegen->builtin_types.entry_invalid; |
| 13196 | TypeTableEntry *return_type; | 13300 | ZigType *return_type; |
| 13197 | TypeTableEntry *inferred_err_set_type = nullptr; | 13301 | ZigType *inferred_err_set_type = nullptr; |
| 13198 | if (fn_proto_node->data.fn_proto.auto_err_set) { | 13302 | if (fn_proto_node->data.fn_proto.auto_err_set) { |
| 13199 | inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry); | 13303 | inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry); |
| 13200 | return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type); | 13304 | return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type); |
| ... | @@ -13219,16 +13323,16 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13219,16 +13323,16 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13219 | | 13323 | |
| 13220 | if (inferred_err_set_type != nullptr) { | 13324 | if (inferred_err_set_type != nullptr) { |
| 13221 | inferred_err_set_type->data.error_set.infer_fn = nullptr; | 13325 | inferred_err_set_type->data.error_set.infer_fn = nullptr; |
| 13222 | if (result->value.type->id == TypeTableEntryIdErrorUnion) { | 13326 | if (result->value.type->id == ZigTypeIdErrorUnion) { |
| 13223 | if (result->value.data.x_err_union.err != nullptr) { | 13327 | if (result->value.data.x_err_union.err != nullptr) { |
| 13224 | inferred_err_set_type->data.error_set.err_count = 1; | 13328 | inferred_err_set_type->data.error_set.err_count = 1; |
| 13225 | inferred_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(1); | 13329 | inferred_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(1); |
| 13226 | inferred_err_set_type->data.error_set.errors[0] = result->value.data.x_err_union.err; | 13330 | inferred_err_set_type->data.error_set.errors[0] = result->value.data.x_err_union.err; |
| 13227 | } | 13331 | } |
| 13228 | TypeTableEntry *fn_inferred_err_set_type = result->value.type->data.error_union.err_set_type; | 13332 | ZigType *fn_inferred_err_set_type = result->value.type->data.error_union.err_set_type; |
| 13229 | inferred_err_set_type->data.error_set.err_count = fn_inferred_err_set_type->data.error_set.err_count; | 13333 | inferred_err_set_type->data.error_set.err_count = fn_inferred_err_set_type->data.error_set.err_count; |
| 13230 | inferred_err_set_type->data.error_set.errors = fn_inferred_err_set_type->data.error_set.errors; | 13334 | inferred_err_set_type->data.error_set.errors = fn_inferred_err_set_type->data.error_set.errors; |
| 13231 | } else if (result->value.type->id == TypeTableEntryIdErrorSet) { | 13335 | } else if (result->value.type->id == ZigTypeIdErrorSet) { |
| 13232 | inferred_err_set_type->data.error_set.err_count = result->value.type->data.error_set.err_count; | 13336 | inferred_err_set_type->data.error_set.err_count = result->value.type->data.error_set.err_count; |
| 13233 | inferred_err_set_type->data.error_set.errors = result->value.type->data.error_set.errors; | 13337 | inferred_err_set_type->data.error_set.errors = result->value.type->data.error_set.errors; |
| 13234 | } | 13338 | } |
| ... | @@ -13249,10 +13353,10 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13249,10 +13353,10 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13249 | | 13353 | |
| 13250 | IrInstruction *casted_new_stack = nullptr; | 13354 | IrInstruction *casted_new_stack = nullptr; |
| 13251 | if (call_instruction->new_stack != nullptr) { | 13355 | if (call_instruction->new_stack != nullptr) { |
| 13252 | TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 13356 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 13253 | false, false, PtrLenUnknown, | 13357 | false, false, PtrLenUnknown, |
| 13254 | get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); | 13358 | get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); |
| 13255 | TypeTableEntry *u8_slice = get_slice_type(ira->codegen, u8_ptr); | 13359 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); |
| 13256 | IrInstruction *new_stack = call_instruction->new_stack->other; | 13360 | IrInstruction *new_stack = call_instruction->new_stack->other; |
| 13257 | if (type_is_invalid(new_stack->value.type)) | 13361 | if (type_is_invalid(new_stack->value.type)) |
| 13258 | return ira->codegen->builtin_types.entry_invalid; | 13362 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -13276,7 +13380,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13276,7 +13380,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13276 | if (type_is_invalid(arg->value.type)) | 13380 | if (type_is_invalid(arg->value.type)) |
| 13277 | return ira->codegen->builtin_types.entry_invalid; | 13381 | return ira->codegen->builtin_types.entry_invalid; |
| 13278 | | 13382 | |
| 13279 | if (arg->value.type->id == TypeTableEntryIdArgTuple) { | 13383 | if (arg->value.type->id == ZigTypeIdArgTuple) { |
| 13280 | new_fn_arg_count += arg->value.data.x_arg_tuple.end_index - arg->value.data.x_arg_tuple.start_index; | 13384 | new_fn_arg_count += arg->value.data.x_arg_tuple.end_index - arg->value.data.x_arg_tuple.start_index; |
| 13281 | } else { | 13385 | } else { |
| 13282 | new_fn_arg_count += 1; | 13386 | new_fn_arg_count += 1; |
| ... | @@ -13287,7 +13391,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13287,7 +13391,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13287 | | 13391 | |
| 13288 | // Fork a scope of the function with known values for the parameters. | 13392 | // Fork a scope of the function with known values for the parameters. |
| 13289 | Scope *parent_scope = fn_entry->fndef_scope->base.parent; | 13393 | Scope *parent_scope = fn_entry->fndef_scope->base.parent; |
| 13290 | FnTableEntry *impl_fn = create_fn(fn_proto_node); | 13394 | ZigFn *impl_fn = create_fn(fn_proto_node); |
| 13291 | impl_fn->param_source_nodes = allocate<AstNode *>(new_fn_arg_count); | 13395 | impl_fn->param_source_nodes = allocate<AstNode *>(new_fn_arg_count); |
| 13292 | buf_init_from_buf(&impl_fn->symbol_name, &fn_entry->symbol_name); | 13396 | buf_init_from_buf(&impl_fn->symbol_name, &fn_entry->symbol_name); |
| 13293 | impl_fn->fndef_scope = create_fndef_scope(impl_fn->body_node, parent_scope, impl_fn); | 13397 | impl_fn->fndef_scope = create_fndef_scope(impl_fn->body_node, parent_scope, impl_fn); |
| ... | @@ -13306,14 +13410,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13306,14 +13410,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13306 | size_t next_proto_i = 0; | 13410 | size_t next_proto_i = 0; |
| 13307 | | 13411 | |
| 13308 | if (first_arg_ptr) { | 13412 | if (first_arg_ptr) { |
| 13309 | assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer); | 13413 | assert(first_arg_ptr->value.type->id == ZigTypeIdPointer); |
| 13310 | | 13414 | |
| 13311 | bool first_arg_known_bare = false; | 13415 | bool first_arg_known_bare = false; |
| 13312 | if (fn_type_id->next_param_index >= 1) { | 13416 | if (fn_type_id->next_param_index >= 1) { |
| 13313 | TypeTableEntry *param_type = fn_type_id->param_info[next_proto_i].type; | 13417 | ZigType *param_type = fn_type_id->param_info[next_proto_i].type; |
| 13314 | if (type_is_invalid(param_type)) | 13418 | if (type_is_invalid(param_type)) |
| 13315 | return ira->codegen->builtin_types.entry_invalid; | 13419 | return ira->codegen->builtin_types.entry_invalid; |
| 13316 | first_arg_known_bare = param_type->id != TypeTableEntryIdPointer; | 13420 | first_arg_known_bare = param_type->id != ZigTypeIdPointer; |
| 13317 | } | 13421 | } |
| 13318 | | 13422 | |
| 13319 | IrInstruction *first_arg; | 13423 | IrInstruction *first_arg; |
| ... | @@ -13335,14 +13439,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13335,14 +13439,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13335 | bool found_first_var_arg = false; | 13439 | bool found_first_var_arg = false; |
| 13336 | size_t first_var_arg; | 13440 | size_t first_var_arg; |
| 13337 | | 13441 | |
| 13338 | FnTableEntry *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); | 13442 | ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 13339 | assert(parent_fn_entry); | 13443 | assert(parent_fn_entry); |
| 13340 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { | 13444 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 13341 | IrInstruction *arg = call_instruction->args[call_i]->other; | 13445 | IrInstruction *arg = call_instruction->args[call_i]->other; |
| 13342 | if (type_is_invalid(arg->value.type)) | 13446 | if (type_is_invalid(arg->value.type)) |
| 13343 | return ira->codegen->builtin_types.entry_invalid; | 13447 | return ira->codegen->builtin_types.entry_invalid; |
| 13344 | | 13448 | |
| 13345 | if (arg->value.type->id == TypeTableEntryIdArgTuple) { | 13449 | if (arg->value.type->id == ZigTypeIdArgTuple) { |
| 13346 | for (size_t arg_tuple_i = arg->value.data.x_arg_tuple.start_index; | 13450 | for (size_t arg_tuple_i = arg->value.data.x_arg_tuple.start_index; |
| 13347 | arg_tuple_i < arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1) | 13451 | arg_tuple_i < arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1) |
| 13348 | { | 13452 | { |
| ... | @@ -13354,7 +13458,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13354,7 +13458,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13354 | found_first_var_arg = true; | 13458 | found_first_var_arg = true; |
| 13355 | } | 13459 | } |
| 13356 | | 13460 | |
| 13357 | VariableTableEntry *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i); | 13461 | ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i); |
| 13358 | if (arg_var == nullptr) { | 13462 | if (arg_var == nullptr) { |
| 13359 | ir_add_error(ira, arg, | 13463 | ir_add_error(ira, arg, |
| 13360 | buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557")); | 13464 | buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557")); |
| ... | @@ -13401,7 +13505,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13401,7 +13505,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13401 | | 13505 | |
| 13402 | ConstExprValue *var_args_val = create_const_arg_tuple(ira->codegen, | 13506 | ConstExprValue *var_args_val = create_const_arg_tuple(ira->codegen, |
| 13403 | first_var_arg, inst_fn_type_id.param_count); | 13507 | first_var_arg, inst_fn_type_id.param_count); |
| 13404 | VariableTableEntry *var = add_variable(ira->codegen, param_decl_node, | 13508 | ZigVar *var = add_variable(ira->codegen, param_decl_node, |
| 13405 | impl_fn->child_scope, param_name, true, var_args_val, nullptr); | 13509 | impl_fn->child_scope, param_name, true, var_args_val, nullptr); |
| 13406 | impl_fn->child_scope = var->child_scope; | 13510 | impl_fn->child_scope = var->child_scope; |
| 13407 | } | 13511 | } |
| ... | @@ -13420,11 +13524,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13420,11 +13524,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13420 | | 13524 | |
| 13421 | if (fn_proto_node->data.fn_proto.return_var_token == nullptr) { | 13525 | if (fn_proto_node->data.fn_proto.return_var_token == nullptr) { |
| 13422 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; | 13526 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; |
| 13423 | TypeTableEntry *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node); | 13527 | ZigType *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node); |
| 13424 | if (type_is_invalid(specified_return_type)) | 13528 | if (type_is_invalid(specified_return_type)) |
| 13425 | return ira->codegen->builtin_types.entry_invalid; | 13529 | return ira->codegen->builtin_types.entry_invalid; |
| 13426 | if (fn_proto_node->data.fn_proto.auto_err_set) { | 13530 | if (fn_proto_node->data.fn_proto.auto_err_set) { |
| 13427 | TypeTableEntry *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn); | 13531 | ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn); |
| 13428 | inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type); | 13532 | inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type); |
| 13429 | } else { | 13533 | } else { |
| 13430 | inst_fn_type_id.return_type = specified_return_type; | 13534 | inst_fn_type_id.return_type = specified_return_type; |
| ... | @@ -13442,7 +13546,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13442,7 +13546,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13442 | if (call_instruction->is_async) { | 13546 | if (call_instruction->is_async) { |
| 13443 | AstNode *async_allocator_type_node = fn_proto_node->data.fn_proto.async_allocator_type; | 13547 | AstNode *async_allocator_type_node = fn_proto_node->data.fn_proto.async_allocator_type; |
| 13444 | if (async_allocator_type_node != nullptr) { | 13548 | if (async_allocator_type_node != nullptr) { |
| 13445 | TypeTableEntry *async_allocator_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, async_allocator_type_node); | 13549 | ZigType *async_allocator_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, async_allocator_type_node); |
| 13446 | if (type_is_invalid(async_allocator_type)) | 13550 | if (type_is_invalid(async_allocator_type)) |
| 13447 | return ira->codegen->builtin_types.entry_invalid; | 13551 | return ira->codegen->builtin_types.entry_invalid; |
| 13448 | inst_fn_type_id.async_allocator_type = async_allocator_type; | 13552 | inst_fn_type_id.async_allocator_type = async_allocator_type; |
| ... | @@ -13486,7 +13590,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13486,7 +13590,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13486 | ira->codegen->fn_defs.append(impl_fn); | 13590 | ira->codegen->fn_defs.append(impl_fn); |
| 13487 | } | 13591 | } |
| 13488 | | 13592 | |
| 13489 | TypeTableEntry *return_type = impl_fn->type_entry->data.fn.fn_type_id.return_type; | 13593 | ZigType *return_type = impl_fn->type_entry->data.fn.fn_type_id.return_type; |
| 13490 | if (fn_type_can_fail(&impl_fn->type_entry->data.fn.fn_type_id)) { | 13594 | if (fn_type_can_fail(&impl_fn->type_entry->data.fn.fn_type_id)) { |
| 13491 | parent_fn_entry->calls_or_awaits_errorable_fn = true; | 13595 | parent_fn_entry->calls_or_awaits_errorable_fn = true; |
| 13492 | } | 13596 | } |
| ... | @@ -13510,7 +13614,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13510,7 +13614,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13510 | return ir_finish_anal(ira, return_type); | 13614 | return ir_finish_anal(ira, return_type); |
| 13511 | } | 13615 | } |
| 13512 | | 13616 | |
| 13513 | FnTableEntry *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); | 13617 | ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 13514 | assert(fn_type_id->return_type != nullptr); | 13618 | assert(fn_type_id->return_type != nullptr); |
| 13515 | assert(parent_fn_entry != nullptr); | 13619 | assert(parent_fn_entry != nullptr); |
| 13516 | if (fn_type_can_fail(fn_type_id)) { | 13620 | if (fn_type_can_fail(fn_type_id)) { |
| ... | @@ -13521,14 +13625,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13521,14 +13625,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13521 | IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count); | 13625 | IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count); |
| 13522 | size_t next_arg_index = 0; | 13626 | size_t next_arg_index = 0; |
| 13523 | if (first_arg_ptr) { | 13627 | if (first_arg_ptr) { |
| 13524 | assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer); | 13628 | assert(first_arg_ptr->value.type->id == ZigTypeIdPointer); |
| 13525 | | 13629 | |
| 13526 | TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type; | 13630 | ZigType *param_type = fn_type_id->param_info[next_arg_index].type; |
| 13527 | if (type_is_invalid(param_type)) | 13631 | if (type_is_invalid(param_type)) |
| 13528 | return ira->codegen->builtin_types.entry_invalid; | 13632 | return ira->codegen->builtin_types.entry_invalid; |
| 13529 | | 13633 | |
| 13530 | IrInstruction *first_arg; | 13634 | IrInstruction *first_arg; |
| 13531 | if (param_type->id == TypeTableEntryIdPointer && | 13635 | if (param_type->id == ZigTypeIdPointer && |
| 13532 | handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) | 13636 | handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) |
| 13533 | { | 13637 | { |
| 13534 | first_arg = first_arg_ptr; | 13638 | first_arg = first_arg_ptr; |
| ... | @@ -13551,7 +13655,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13551,7 +13655,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13551 | return ira->codegen->builtin_types.entry_invalid; | 13655 | return ira->codegen->builtin_types.entry_invalid; |
| 13552 | IrInstruction *casted_arg; | 13656 | IrInstruction *casted_arg; |
| 13553 | if (next_arg_index < src_param_count) { | 13657 | if (next_arg_index < src_param_count) { |
| 13554 | TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type; | 13658 | ZigType *param_type = fn_type_id->param_info[next_arg_index].type; |
| 13555 | if (type_is_invalid(param_type)) | 13659 | if (type_is_invalid(param_type)) |
| 13556 | return ira->codegen->builtin_types.entry_invalid; | 13660 | return ira->codegen->builtin_types.entry_invalid; |
| 13557 | casted_arg = ir_implicit_cast(ira, old_arg, param_type); | 13661 | casted_arg = ir_implicit_cast(ira, old_arg, param_type); |
| ... | @@ -13567,7 +13671,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13567,7 +13671,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13567 | | 13671 | |
| 13568 | assert(next_arg_index == call_param_count); | 13672 | assert(next_arg_index == call_param_count); |
| 13569 | | 13673 | |
| 13570 | TypeTableEntry *return_type = fn_type_id->return_type; | 13674 | ZigType *return_type = fn_type_id->return_type; |
| 13571 | if (type_is_invalid(return_type)) | 13675 | if (type_is_invalid(return_type)) |
| 13572 | return ira->codegen->builtin_types.entry_invalid; | 13676 | return ira->codegen->builtin_types.entry_invalid; |
| 13573 | | 13677 | |
| ... | @@ -13595,6 +13699,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13595,6 +13699,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13595 | return ir_finish_anal(ira, result->value.type); | 13699 | return ir_finish_anal(ira, result->value.type); |
| 13596 | } | 13700 | } |
| 13597 | | 13701 | |
| | 13702 | if (fn_entry != nullptr && fn_entry->fn_inline == FnInlineAlways && fn_inline == FnInlineNever) { |
| | 13703 | ir_add_error(ira, &call_instruction->base, |
| | 13704 | buf_sprintf("no-inline call of inline function")); |
| | 13705 | return ira->codegen->builtin_types.entry_invalid; |
| | 13706 | } |
| 13598 | | 13707 | |
| 13599 | IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base, | 13708 | IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base, |
| 13600 | fn_entry, fn_ref, call_param_count, casted_args, false, fn_inline, false, nullptr, casted_new_stack); | 13709 | fn_entry, fn_ref, call_param_count, casted_args, false, fn_inline, false, nullptr, casted_new_stack); |
| ... | @@ -13603,7 +13712,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -13603,7 +13712,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13603 | return ir_finish_anal(ira, return_type); | 13712 | return ir_finish_anal(ira, return_type); |
| 13604 | } | 13713 | } |
| 13605 | | 13714 | |
| 13606 | static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) { | 13715 | static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) { |
| 13607 | IrInstruction *fn_ref = call_instruction->fn_ref->other; | 13716 | IrInstruction *fn_ref = call_instruction->fn_ref->other; |
| 13608 | if (type_is_invalid(fn_ref->value.type)) | 13717 | if (type_is_invalid(fn_ref->value.type)) |
| 13609 | return ira->codegen->builtin_types.entry_invalid; | 13718 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -13612,8 +13721,8 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction | ... | @@ -13612,8 +13721,8 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction |
| 13612 | ir_should_inline(ira->new_irb.exec, call_instruction->base.scope); | 13721 | ir_should_inline(ira->new_irb.exec, call_instruction->base.scope); |
| 13613 | | 13722 | |
| 13614 | if (is_comptime || instr_is_comptime(fn_ref)) { | 13723 | if (is_comptime || instr_is_comptime(fn_ref)) { |
| 13615 | if (fn_ref->value.type->id == TypeTableEntryIdMetaType) { | 13724 | if (fn_ref->value.type->id == ZigTypeIdMetaType) { |
| 13616 | TypeTableEntry *dest_type = ir_resolve_type(ira, fn_ref); | 13725 | ZigType *dest_type = ir_resolve_type(ira, fn_ref); |
| 13617 | if (type_is_invalid(dest_type)) | 13726 | if (type_is_invalid(dest_type)) |
| 13618 | return ira->codegen->builtin_types.entry_invalid; | 13727 | return ira->codegen->builtin_types.entry_invalid; |
| 13619 | | 13728 | |
| ... | @@ -13633,15 +13742,15 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction | ... | @@ -13633,15 +13742,15 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction |
| 13633 | | 13742 | |
| 13634 | ir_link_new_instruction(cast_instruction, &call_instruction->base); | 13743 | ir_link_new_instruction(cast_instruction, &call_instruction->base); |
| 13635 | return ir_finish_anal(ira, cast_instruction->value.type); | 13744 | return ir_finish_anal(ira, cast_instruction->value.type); |
| 13636 | } else if (fn_ref->value.type->id == TypeTableEntryIdFn) { | 13745 | } else if (fn_ref->value.type->id == ZigTypeIdFn) { |
| 13637 | FnTableEntry *fn_table_entry = ir_resolve_fn(ira, fn_ref); | 13746 | ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref); |
| 13638 | if (fn_table_entry == nullptr) | 13747 | if (fn_table_entry == nullptr) |
| 13639 | return ira->codegen->builtin_types.entry_invalid; | 13748 | return ira->codegen->builtin_types.entry_invalid; |
| 13640 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, | 13749 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, |
| 13641 | fn_ref, nullptr, is_comptime, call_instruction->fn_inline); | 13750 | fn_ref, nullptr, is_comptime, call_instruction->fn_inline); |
| 13642 | } else if (fn_ref->value.type->id == TypeTableEntryIdBoundFn) { | 13751 | } else if (fn_ref->value.type->id == ZigTypeIdBoundFn) { |
| 13643 | assert(fn_ref->value.special == ConstValSpecialStatic); | 13752 | assert(fn_ref->value.special == ConstValSpecialStatic); |
| 13644 | FnTableEntry *fn_table_entry = fn_ref->value.data.x_bound_fn.fn; | 13753 | ZigFn *fn_table_entry = fn_ref->value.data.x_bound_fn.fn; |
| 13645 | IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg; | 13754 | IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg; |
| 13646 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, | 13755 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, |
| 13647 | fn_ref, first_arg_ptr, is_comptime, call_instruction->fn_inline); | 13756 | fn_ref, first_arg_ptr, is_comptime, call_instruction->fn_inline); |
| ... | @@ -13652,7 +13761,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction | ... | @@ -13652,7 +13761,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction |
| 13652 | } | 13761 | } |
| 13653 | } | 13762 | } |
| 13654 | | 13763 | |
| 13655 | if (fn_ref->value.type->id == TypeTableEntryIdFn) { | 13764 | if (fn_ref->value.type->id == ZigTypeIdFn) { |
| 13656 | return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type, | 13765 | return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type, |
| 13657 | fn_ref, nullptr, false, FnInlineAuto); | 13766 | fn_ref, nullptr, false, FnInlineAuto); |
| 13658 | } else { | 13767 | } else { |
| ... | @@ -13662,14 +13771,46 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction | ... | @@ -13662,14 +13771,46 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction |
| 13662 | } | 13771 | } |
| 13663 | } | 13772 | } |
| 13664 | | 13773 | |
| 13665 | static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { | 13774 | // out_val->type must be the type to read the pointer as |
| | 13775 | // if the type is different than the actual type then it does a comptime byte reinterpretation |
| | 13776 | static Error ir_read_const_ptr(IrAnalyze *ira, AstNode *source_node, |
| | 13777 | ConstExprValue *out_val, ConstExprValue *ptr_val) |
| | 13778 | { |
| | 13779 | assert(out_val->type != nullptr); |
| | 13780 | |
| | 13781 | ConstExprValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr_val); |
| | 13782 | |
| | 13783 | size_t src_size = type_size(ira->codegen, pointee->type); |
| | 13784 | size_t dst_size = type_size(ira->codegen, out_val->type); |
| | 13785 | |
| | 13786 | if (src_size == dst_size && types_have_same_zig_comptime_repr(pointee->type, out_val->type)) { |
| | 13787 | copy_const_val(out_val, pointee, ptr_val->data.x_ptr.mut == ConstPtrMutComptimeConst); |
| | 13788 | return ErrorNone; |
| | 13789 | } |
| | 13790 | |
| | 13791 | if (dst_size > src_size) { |
| | 13792 | ir_add_error_node(ira, source_node, |
| | 13793 | buf_sprintf("attempt to read %zu bytes from pointer to %s which is %zu bytes", |
| | 13794 | dst_size, buf_ptr(&pointee->type->name), src_size)); |
| | 13795 | return ErrorSemanticAnalyzeFail; |
| | 13796 | } |
| | 13797 | |
| | 13798 | Buf buf = BUF_INIT; |
| | 13799 | buf_resize(&buf, src_size); |
| | 13800 | buf_write_value_bytes(ira->codegen, (uint8_t*)buf_ptr(&buf), pointee); |
| | 13801 | buf_read_value_bytes(ira->codegen, (uint8_t*)buf_ptr(&buf), out_val); |
| | 13802 | return ErrorNone; |
| | 13803 | } |
| | 13804 | |
| | 13805 | static ZigType *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { |
| | 13806 | Error err; |
| 13666 | IrInstruction *value = un_op_instruction->value->other; | 13807 | IrInstruction *value = un_op_instruction->value->other; |
| 13667 | | 13808 | |
| 13668 | TypeTableEntry *ptr_type = value->value.type; | 13809 | ZigType *ptr_type = value->value.type; |
| 13669 | TypeTableEntry *child_type; | 13810 | ZigType *child_type; |
| 13670 | if (type_is_invalid(ptr_type)) { | 13811 | if (type_is_invalid(ptr_type)) { |
| 13671 | return ira->codegen->builtin_types.entry_invalid; | 13812 | return ira->codegen->builtin_types.entry_invalid; |
| 13672 | } else if (ptr_type->id == TypeTableEntryIdPointer) { | 13813 | } else if (ptr_type->id == ZigTypeIdPointer) { |
| 13673 | if (ptr_type->data.pointer.ptr_len == PtrLenUnknown) { | 13814 | if (ptr_type->data.pointer.ptr_len == PtrLenUnknown) { |
| 13674 | ir_add_error_node(ira, un_op_instruction->base.source_node, | 13815 | ir_add_error_node(ira, un_op_instruction->base.source_node, |
| 13675 | buf_sprintf("index syntax required for unknown-length pointer type '%s'", | 13816 | buf_sprintf("index syntax required for unknown-length pointer type '%s'", |
| ... | @@ -13692,60 +13833,59 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp | ... | @@ -13692,60 +13833,59 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp |
| 13692 | if (comptime_value == nullptr) | 13833 | if (comptime_value == nullptr) |
| 13693 | return ira->codegen->builtin_types.entry_invalid; | 13834 | return ira->codegen->builtin_types.entry_invalid; |
| 13694 | | 13835 | |
| 13695 | ConstExprValue *pointee = const_ptr_pointee(ira->codegen, comptime_value); | 13836 | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base); |
| 13696 | if (pointee->type == child_type) { | 13837 | out_val->type = child_type; |
| 13697 | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base); | 13838 | if ((err = ir_read_const_ptr(ira, un_op_instruction->base.source_node, out_val, comptime_value))) |
| 13698 | copy_const_val(out_val, pointee, value->value.data.x_ptr.mut == ConstPtrMutComptimeConst); | 13839 | return ira->codegen->builtin_types.entry_invalid; |
| 13699 | return child_type; | 13840 | return child_type; |
| 13700 | } | | |
| 13701 | } | 13841 | } |
| 13702 | | 13842 | |
| 13703 | ir_build_load_ptr_from(&ira->new_irb, &un_op_instruction->base, value); | 13843 | ir_build_load_ptr_from(&ira->new_irb, &un_op_instruction->base, value); |
| 13704 | return child_type; | 13844 | return child_type; |
| 13705 | } | 13845 | } |
| 13706 | | 13846 | |
| 13707 | static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { | 13847 | static ZigType *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { |
| 13708 | Error err; | 13848 | Error err; |
| 13709 | IrInstruction *value = un_op_instruction->value->other; | 13849 | IrInstruction *value = un_op_instruction->value->other; |
| 13710 | TypeTableEntry *type_entry = ir_resolve_type(ira, value); | 13850 | ZigType *type_entry = ir_resolve_type(ira, value); |
| 13711 | if (type_is_invalid(type_entry)) | 13851 | if (type_is_invalid(type_entry)) |
| 13712 | return ira->codegen->builtin_types.entry_invalid; | 13852 | return ira->codegen->builtin_types.entry_invalid; |
| 13713 | if ((err = ensure_complete_type(ira->codegen, type_entry))) | 13853 | if ((err = ensure_complete_type(ira->codegen, type_entry))) |
| 13714 | return ira->codegen->builtin_types.entry_invalid; | 13854 | return ira->codegen->builtin_types.entry_invalid; |
| 13715 | | 13855 | |
| 13716 | switch (type_entry->id) { | 13856 | switch (type_entry->id) { |
| 13717 | case TypeTableEntryIdInvalid: | 13857 | case ZigTypeIdInvalid: |
| 13718 | zig_unreachable(); | 13858 | zig_unreachable(); |
| 13719 | case TypeTableEntryIdMetaType: | 13859 | case ZigTypeIdMetaType: |
| 13720 | case TypeTableEntryIdVoid: | 13860 | case ZigTypeIdVoid: |
| 13721 | case TypeTableEntryIdBool: | 13861 | case ZigTypeIdBool: |
| 13722 | case TypeTableEntryIdInt: | 13862 | case ZigTypeIdInt: |
| 13723 | case TypeTableEntryIdFloat: | 13863 | case ZigTypeIdFloat: |
| 13724 | case TypeTableEntryIdPointer: | 13864 | case ZigTypeIdPointer: |
| 13725 | case TypeTableEntryIdArray: | 13865 | case ZigTypeIdArray: |
| 13726 | case TypeTableEntryIdStruct: | 13866 | case ZigTypeIdStruct: |
| 13727 | case TypeTableEntryIdComptimeFloat: | 13867 | case ZigTypeIdComptimeFloat: |
| 13728 | case TypeTableEntryIdComptimeInt: | 13868 | case ZigTypeIdComptimeInt: |
| 13729 | case TypeTableEntryIdUndefined: | 13869 | case ZigTypeIdUndefined: |
| 13730 | case TypeTableEntryIdNull: | 13870 | case ZigTypeIdNull: |
| 13731 | case TypeTableEntryIdOptional: | 13871 | case ZigTypeIdOptional: |
| 13732 | case TypeTableEntryIdErrorUnion: | 13872 | case ZigTypeIdErrorUnion: |
| 13733 | case TypeTableEntryIdErrorSet: | 13873 | case ZigTypeIdErrorSet: |
| 13734 | case TypeTableEntryIdEnum: | 13874 | case ZigTypeIdEnum: |
| 13735 | case TypeTableEntryIdUnion: | 13875 | case ZigTypeIdUnion: |
| 13736 | case TypeTableEntryIdFn: | 13876 | case ZigTypeIdFn: |
| 13737 | case TypeTableEntryIdNamespace: | 13877 | case ZigTypeIdNamespace: |
| 13738 | case TypeTableEntryIdBlock: | 13878 | case ZigTypeIdBlock: |
| 13739 | case TypeTableEntryIdBoundFn: | 13879 | case ZigTypeIdBoundFn: |
| 13740 | case TypeTableEntryIdArgTuple: | 13880 | case ZigTypeIdArgTuple: |
| 13741 | case TypeTableEntryIdPromise: | 13881 | case ZigTypeIdPromise: |
| 13742 | { | 13882 | { |
| 13743 | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base); | 13883 | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base); |
| 13744 | out_val->data.x_type = get_optional_type(ira->codegen, type_entry); | 13884 | out_val->data.x_type = get_optional_type(ira->codegen, type_entry); |
| 13745 | return ira->codegen->builtin_types.entry_type; | 13885 | return ira->codegen->builtin_types.entry_type; |
| 13746 | } | 13886 | } |
| 13747 | case TypeTableEntryIdUnreachable: | 13887 | case ZigTypeIdUnreachable: |
| 13748 | case TypeTableEntryIdOpaque: | 13888 | case ZigTypeIdOpaque: |
| 13749 | ir_add_error_node(ira, un_op_instruction->base.source_node, | 13889 | ir_add_error_node(ira, un_op_instruction->base.source_node, |
| 13750 | buf_sprintf("type '%s' not optional", buf_ptr(&type_entry->name))); | 13890 | buf_sprintf("type '%s' not optional", buf_ptr(&type_entry->name))); |
| 13751 | return ira->codegen->builtin_types.entry_invalid; | 13891 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -13753,18 +13893,18 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op | ... | @@ -13753,18 +13893,18 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op |
| 13753 | zig_unreachable(); | 13893 | zig_unreachable(); |
| 13754 | } | 13894 | } |
| 13755 | | 13895 | |
| 13756 | static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { | 13896 | static ZigType *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { |
| 13757 | IrInstruction *value = un_op_instruction->value->other; | 13897 | IrInstruction *value = un_op_instruction->value->other; |
| 13758 | TypeTableEntry *expr_type = value->value.type; | 13898 | ZigType *expr_type = value->value.type; |
| 13759 | if (type_is_invalid(expr_type)) | 13899 | if (type_is_invalid(expr_type)) |
| 13760 | return ira->codegen->builtin_types.entry_invalid; | 13900 | return ira->codegen->builtin_types.entry_invalid; |
| 13761 | | 13901 | |
| 13762 | bool is_wrap_op = (un_op_instruction->op_id == IrUnOpNegationWrap); | 13902 | bool is_wrap_op = (un_op_instruction->op_id == IrUnOpNegationWrap); |
| 13763 | | 13903 | |
| 13764 | bool is_float = (expr_type->id == TypeTableEntryIdFloat || expr_type->id == TypeTableEntryIdComptimeFloat); | 13904 | bool is_float = (expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat); |
| 13765 | | 13905 | |
| 13766 | if ((expr_type->id == TypeTableEntryIdInt && expr_type->data.integral.is_signed) || | 13906 | if ((expr_type->id == ZigTypeIdInt && expr_type->data.integral.is_signed) || |
| 13767 | expr_type->id == TypeTableEntryIdComptimeInt || (is_float && !is_wrap_op)) | 13907 | expr_type->id == ZigTypeIdComptimeInt || (is_float && !is_wrap_op)) |
| 13768 | { | 13908 | { |
| 13769 | if (instr_is_comptime(value)) { | 13909 | if (instr_is_comptime(value)) { |
| 13770 | ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad); | 13910 | ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad); |
| ... | @@ -13780,7 +13920,7 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un | ... | @@ -13780,7 +13920,7 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un |
| 13780 | } else { | 13920 | } else { |
| 13781 | bigint_negate(&out_val->data.x_bigint, &target_const_val->data.x_bigint); | 13921 | bigint_negate(&out_val->data.x_bigint, &target_const_val->data.x_bigint); |
| 13782 | } | 13922 | } |
| 13783 | if (is_wrap_op || is_float || expr_type->id == TypeTableEntryIdComptimeInt) { | 13923 | if (is_wrap_op || is_float || expr_type->id == ZigTypeIdComptimeInt) { |
| 13784 | return expr_type; | 13924 | return expr_type; |
| 13785 | } | 13925 | } |
| 13786 | | 13926 | |
| ... | @@ -13800,13 +13940,13 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un | ... | @@ -13800,13 +13940,13 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un |
| 13800 | return ira->codegen->builtin_types.entry_invalid; | 13940 | return ira->codegen->builtin_types.entry_invalid; |
| 13801 | } | 13941 | } |
| 13802 | | 13942 | |
| 13803 | static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) { | 13943 | static ZigType *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 13804 | IrInstruction *value = instruction->value->other; | 13944 | IrInstruction *value = instruction->value->other; |
| 13805 | TypeTableEntry *expr_type = value->value.type; | 13945 | ZigType *expr_type = value->value.type; |
| 13806 | if (type_is_invalid(expr_type)) | 13946 | if (type_is_invalid(expr_type)) |
| 13807 | return ira->codegen->builtin_types.entry_invalid; | 13947 | return ira->codegen->builtin_types.entry_invalid; |
| 13808 | | 13948 | |
| 13809 | if (expr_type->id == TypeTableEntryIdInt) { | 13949 | if (expr_type->id == ZigTypeIdInt) { |
| 13810 | if (instr_is_comptime(value)) { | 13950 | if (instr_is_comptime(value)) { |
| 13811 | ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad); | 13951 | ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad); |
| 13812 | if (target_const_val == nullptr) | 13952 | if (target_const_val == nullptr) |
| ... | @@ -13827,7 +13967,7 @@ static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *ins | ... | @@ -13827,7 +13967,7 @@ static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *ins |
| 13827 | return ira->codegen->builtin_types.entry_invalid; | 13967 | return ira->codegen->builtin_types.entry_invalid; |
| 13828 | } | 13968 | } |
| 13829 | | 13969 | |
| 13830 | static TypeTableEntry *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { | 13970 | static ZigType *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { |
| 13831 | IrUnOp op_id = un_op_instruction->op_id; | 13971 | IrUnOp op_id = un_op_instruction->op_id; |
| 13832 | switch (op_id) { | 13972 | switch (op_id) { |
| 13833 | case IrUnOpInvalid: | 13973 | case IrUnOpInvalid: |
| ... | @@ -13845,7 +13985,7 @@ static TypeTableEntry *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructio | ... | @@ -13845,7 +13985,7 @@ static TypeTableEntry *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructio |
| 13845 | zig_unreachable(); | 13985 | zig_unreachable(); |
| 13846 | } | 13986 | } |
| 13847 | | 13987 | |
| 13848 | static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) { | 13988 | static ZigType *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) { |
| 13849 | IrBasicBlock *old_dest_block = br_instruction->dest_block; | 13989 | IrBasicBlock *old_dest_block = br_instruction->dest_block; |
| 13850 | | 13990 | |
| 13851 | bool is_comptime; | 13991 | bool is_comptime; |
| ... | @@ -13855,21 +13995,15 @@ static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr | ... | @@ -13855,21 +13995,15 @@ static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr |
| 13855 | if (is_comptime || old_dest_block->ref_count == 1) | 13995 | if (is_comptime || old_dest_block->ref_count == 1) |
| 13856 | return ir_inline_bb(ira, &br_instruction->base, old_dest_block); | 13996 | return ir_inline_bb(ira, &br_instruction->base, old_dest_block); |
| 13857 | | 13997 | |
| 13858 | IrBasicBlock *new_bb = ir_get_new_bb(ira, old_dest_block, &br_instruction->base); | 13998 | IrBasicBlock *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base); |
| 13859 | | 13999 | if (new_bb == nullptr) |
| 13860 | if (new_bb->must_be_comptime_source_instr) { | | |
| 13861 | ErrorMsg *msg = ir_add_error(ira, &br_instruction->base, | | |
| 13862 | buf_sprintf("control flow attempts to use compile-time variable at runtime")); | | |
| 13863 | add_error_note(ira->codegen, msg, new_bb->must_be_comptime_source_instr->source_node, | | |
| 13864 | buf_sprintf("compile-time variable assigned here")); | | |
| 13865 | return ir_unreach_error(ira); | 14000 | return ir_unreach_error(ira); |
| 13866 | } | | |
| 13867 | | 14001 | |
| 13868 | ir_build_br_from(&ira->new_irb, &br_instruction->base, new_bb); | 14002 | ir_build_br_from(&ira->new_irb, &br_instruction->base, new_bb); |
| 13869 | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); | 14003 | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| 13870 | } | 14004 | } |
| 13871 | | 14005 | |
| 13872 | static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) { | 14006 | static ZigType *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) { |
| 13873 | IrInstruction *condition = cond_br_instruction->condition->other; | 14007 | IrInstruction *condition = cond_br_instruction->condition->other; |
| 13874 | if (type_is_invalid(condition->value.type)) | 14008 | if (type_is_invalid(condition->value.type)) |
| 13875 | return ir_unreach_error(ira); | 14009 | return ir_unreach_error(ira); |
| ... | @@ -13889,32 +14023,41 @@ static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstruct | ... | @@ -13889,32 +14023,41 @@ static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstruct |
| 13889 | if (is_comptime || old_dest_block->ref_count == 1) | 14023 | if (is_comptime || old_dest_block->ref_count == 1) |
| 13890 | return ir_inline_bb(ira, &cond_br_instruction->base, old_dest_block); | 14024 | return ir_inline_bb(ira, &cond_br_instruction->base, old_dest_block); |
| 13891 | | 14025 | |
| 13892 | IrBasicBlock *new_dest_block = ir_get_new_bb(ira, old_dest_block, &cond_br_instruction->base); | 14026 | IrBasicBlock *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base); |
| | 14027 | if (new_dest_block == nullptr) |
| | 14028 | return ir_unreach_error(ira); |
| | 14029 | |
| 13893 | ir_build_br_from(&ira->new_irb, &cond_br_instruction->base, new_dest_block); | 14030 | ir_build_br_from(&ira->new_irb, &cond_br_instruction->base, new_dest_block); |
| 13894 | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); | 14031 | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| 13895 | } | 14032 | } |
| 13896 | | 14033 | |
| 13897 | TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool; | 14034 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| 13898 | IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type); | 14035 | IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type); |
| 13899 | if (casted_condition == ira->codegen->invalid_instruction) | 14036 | if (casted_condition == ira->codegen->invalid_instruction) |
| 13900 | return ir_unreach_error(ira); | 14037 | return ir_unreach_error(ira); |
| 13901 | | 14038 | |
| 13902 | assert(cond_br_instruction->then_block != cond_br_instruction->else_block); | 14039 | assert(cond_br_instruction->then_block != cond_br_instruction->else_block); |
| 13903 | IrBasicBlock *new_then_block = ir_get_new_bb(ira, cond_br_instruction->then_block, &cond_br_instruction->base); | 14040 | IrBasicBlock *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base); |
| 13904 | IrBasicBlock *new_else_block = ir_get_new_bb(ira, cond_br_instruction->else_block, &cond_br_instruction->base); | 14041 | if (new_then_block == nullptr) |
| | 14042 | return ir_unreach_error(ira); |
| | 14043 | |
| | 14044 | IrBasicBlock *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base); |
| | 14045 | if (new_else_block == nullptr) |
| | 14046 | return ir_unreach_error(ira); |
| | 14047 | |
| 13905 | ir_build_cond_br_from(&ira->new_irb, &cond_br_instruction->base, | 14048 | ir_build_cond_br_from(&ira->new_irb, &cond_br_instruction->base, |
| 13906 | casted_condition, new_then_block, new_else_block, nullptr); | 14049 | casted_condition, new_then_block, new_else_block, nullptr); |
| 13907 | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); | 14050 | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| 13908 | } | 14051 | } |
| 13909 | | 14052 | |
| 13910 | static TypeTableEntry *ir_analyze_instruction_unreachable(IrAnalyze *ira, | 14053 | static ZigType *ir_analyze_instruction_unreachable(IrAnalyze *ira, |
| 13911 | IrInstructionUnreachable *unreachable_instruction) | 14054 | IrInstructionUnreachable *unreachable_instruction) |
| 13912 | { | 14055 | { |
| 13913 | ir_build_unreachable_from(&ira->new_irb, &unreachable_instruction->base); | 14056 | ir_build_unreachable_from(&ira->new_irb, &unreachable_instruction->base); |
| 13914 | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); | 14057 | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| 13915 | } | 14058 | } |
| 13916 | | 14059 | |
| 13917 | static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) { | 14060 | static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) { |
| 13918 | if (ira->const_predecessor_bb) { | 14061 | if (ira->const_predecessor_bb) { |
| 13919 | for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) { | 14062 | for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) { |
| 13920 | IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i]; | 14063 | IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i]; |
| ... | @@ -13948,7 +14091,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP | ... | @@ -13948,7 +14091,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP |
| 13948 | IrInstruction *old_value = phi_instruction->incoming_values[i]; | 14091 | IrInstruction *old_value = phi_instruction->incoming_values[i]; |
| 13949 | assert(old_value); | 14092 | assert(old_value); |
| 13950 | IrInstruction *new_value = old_value->other; | 14093 | IrInstruction *new_value = old_value->other; |
| 13951 | if (!new_value || new_value->value.type->id == TypeTableEntryIdUnreachable || predecessor->other == nullptr) | 14094 | if (!new_value || new_value->value.type->id == ZigTypeIdUnreachable || predecessor->other == nullptr) |
| 13952 | continue; | 14095 | continue; |
| 13953 | | 14096 | |
| 13954 | if (type_is_invalid(new_value->value.type)) | 14097 | if (type_is_invalid(new_value->value.type)) |
| ... | @@ -13971,22 +14114,22 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP | ... | @@ -13971,22 +14114,22 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP |
| 13971 | return first_value->value.type; | 14114 | return first_value->value.type; |
| 13972 | } | 14115 | } |
| 13973 | | 14116 | |
| 13974 | TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr, | 14117 | ZigType *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr, |
| 13975 | new_incoming_values.items, new_incoming_values.length); | 14118 | new_incoming_values.items, new_incoming_values.length); |
| 13976 | if (type_is_invalid(resolved_type)) | 14119 | if (type_is_invalid(resolved_type)) |
| 13977 | return resolved_type; | 14120 | return resolved_type; |
| 13978 | | 14121 | |
| 13979 | if (resolved_type->id == TypeTableEntryIdComptimeFloat || | 14122 | if (resolved_type->id == ZigTypeIdComptimeFloat || |
| 13980 | resolved_type->id == TypeTableEntryIdComptimeInt || | 14123 | resolved_type->id == ZigTypeIdComptimeInt || |
| 13981 | resolved_type->id == TypeTableEntryIdNull || | 14124 | resolved_type->id == ZigTypeIdNull || |
| 13982 | resolved_type->id == TypeTableEntryIdUndefined) | 14125 | resolved_type->id == ZigTypeIdUndefined) |
| 13983 | { | 14126 | { |
| 13984 | ir_add_error_node(ira, phi_instruction->base.source_node, | 14127 | ir_add_error_node(ira, phi_instruction->base.source_node, |
| 13985 | buf_sprintf("unable to infer expression type")); | 14128 | buf_sprintf("unable to infer expression type")); |
| 13986 | return ira->codegen->builtin_types.entry_invalid; | 14129 | return ira->codegen->builtin_types.entry_invalid; |
| 13987 | } | 14130 | } |
| 13988 | | 14131 | |
| 13989 | bool all_stack_ptrs = (resolved_type->id == TypeTableEntryIdPointer); | 14132 | bool all_stack_ptrs = (resolved_type->id == ZigTypeIdPointer); |
| 13990 | | 14133 | |
| 13991 | // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction. | 14134 | // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction. |
| 13992 | // so we go back and insert the casts as the last instruction in the corresponding predecessor blocks, and | 14135 | // so we go back and insert the casts as the last instruction in the corresponding predecessor blocks, and |
| ... | @@ -14023,21 +14166,30 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP | ... | @@ -14023,21 +14166,30 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP |
| 14023 | return resolved_type; | 14166 | return resolved_type; |
| 14024 | } | 14167 | } |
| 14025 | | 14168 | |
| 14026 | static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction, | 14169 | static ZigType *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var) { |
| 14027 | VariableTableEntry *var) | | |
| 14028 | { | | |
| 14029 | IrInstruction *result = ir_get_var_ptr(ira, instruction, var); | 14170 | IrInstruction *result = ir_get_var_ptr(ira, instruction, var); |
| 14030 | ir_link_new_instruction(result, instruction); | 14171 | ir_link_new_instruction(result, instruction); |
| 14031 | return result->value.type; | 14172 | return result->value.type; |
| 14032 | } | 14173 | } |
| 14033 | | 14174 | |
| 14034 | static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) { | 14175 | static ZigType *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *instruction) { |
| 14035 | VariableTableEntry *var = var_ptr_instruction->var; | 14176 | ZigVar *var = instruction->var; |
| 14036 | return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var); | 14177 | IrInstruction *result = ir_get_var_ptr(ira, &instruction->base, var); |
| | 14178 | if (instruction->crossed_fndef_scope != nullptr && !instr_is_comptime(result)) { |
| | 14179 | ErrorMsg *msg = ir_add_error(ira, &instruction->base, |
| | 14180 | buf_sprintf("'%s' not accessible from inner function", buf_ptr(&var->name))); |
| | 14181 | add_error_note(ira->codegen, msg, instruction->crossed_fndef_scope->base.source_node, |
| | 14182 | buf_sprintf("crossed function definition here")); |
| | 14183 | add_error_note(ira->codegen, msg, var->decl_node, |
| | 14184 | buf_sprintf("declared here")); |
| | 14185 | return ira->codegen->builtin_types.entry_invalid; |
| | 14186 | } |
| | 14187 | ir_link_new_instruction(result, &instruction->base); |
| | 14188 | return result->value.type; |
| 14037 | } | 14189 | } |
| 14038 | | 14190 | |
| 14039 | static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, uint32_t new_align) { | 14191 | static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align) { |
| 14040 | assert(ptr_type->id == TypeTableEntryIdPointer); | 14192 | assert(ptr_type->id == ZigTypeIdPointer); |
| 14041 | return get_pointer_to_type_extra(g, | 14193 | return get_pointer_to_type_extra(g, |
| 14042 | ptr_type->data.pointer.child_type, | 14194 | ptr_type->data.pointer.child_type, |
| 14043 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, | 14195 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| ... | @@ -14046,15 +14198,15 @@ static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, ui | ... | @@ -14046,15 +14198,15 @@ static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, ui |
| 14046 | ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count); | 14198 | ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count); |
| 14047 | } | 14199 | } |
| 14048 | | 14200 | |
| 14049 | static TypeTableEntry *adjust_slice_align(CodeGen *g, TypeTableEntry *slice_type, uint32_t new_align) { | 14201 | static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align) { |
| 14050 | assert(is_slice(slice_type)); | 14202 | assert(is_slice(slice_type)); |
| 14051 | TypeTableEntry *ptr_type = adjust_ptr_align(g, slice_type->data.structure.fields[slice_ptr_index].type_entry, | 14203 | ZigType *ptr_type = adjust_ptr_align(g, slice_type->data.structure.fields[slice_ptr_index].type_entry, |
| 14052 | new_align); | 14204 | new_align); |
| 14053 | return get_slice_type(g, ptr_type); | 14205 | return get_slice_type(g, ptr_type); |
| 14054 | } | 14206 | } |
| 14055 | | 14207 | |
| 14056 | static TypeTableEntry *adjust_ptr_len(CodeGen *g, TypeTableEntry *ptr_type, PtrLen ptr_len) { | 14208 | static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) { |
| 14057 | assert(ptr_type->id == TypeTableEntryIdPointer); | 14209 | assert(ptr_type->id == ZigTypeIdPointer); |
| 14058 | return get_pointer_to_type_extra(g, | 14210 | return get_pointer_to_type_extra(g, |
| 14059 | ptr_type->data.pointer.child_type, | 14211 | ptr_type->data.pointer.child_type, |
| 14060 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, | 14212 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| ... | @@ -14063,7 +14215,7 @@ static TypeTableEntry *adjust_ptr_len(CodeGen *g, TypeTableEntry *ptr_type, PtrL | ... | @@ -14063,7 +14215,7 @@ static TypeTableEntry *adjust_ptr_len(CodeGen *g, TypeTableEntry *ptr_type, PtrL |
| 14063 | ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count); | 14215 | ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count); |
| 14064 | } | 14216 | } |
| 14065 | | 14217 | |
| 14066 | static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) { | 14218 | static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) { |
| 14067 | Error err; | 14219 | Error err; |
| 14068 | IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->other; | 14220 | IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->other; |
| 14069 | if (type_is_invalid(array_ptr->value.type)) | 14221 | if (type_is_invalid(array_ptr->value.type)) |
| ... | @@ -14075,27 +14227,30 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc | ... | @@ -14075,27 +14227,30 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14075 | if (type_is_invalid(elem_index->value.type)) | 14227 | if (type_is_invalid(elem_index->value.type)) |
| 14076 | return ira->codegen->builtin_types.entry_invalid; | 14228 | return ira->codegen->builtin_types.entry_invalid; |
| 14077 | | 14229 | |
| 14078 | TypeTableEntry *ptr_type = orig_array_ptr_val->type; | 14230 | ZigType *ptr_type = orig_array_ptr_val->type; |
| 14079 | assert(ptr_type->id == TypeTableEntryIdPointer); | 14231 | assert(ptr_type->id == ZigTypeIdPointer); |
| 14080 | | 14232 | |
| 14081 | TypeTableEntry *array_type = ptr_type->data.pointer.child_type; | 14233 | ZigType *array_type = ptr_type->data.pointer.child_type; |
| 14082 | | 14234 | |
| 14083 | // At first return_type will be the pointer type we want to return, except with an optimistic alignment. | 14235 | // At first return_type will be the pointer type we want to return, except with an optimistic alignment. |
| 14084 | // We will adjust return_type's alignment before returning it. | 14236 | // We will adjust return_type's alignment before returning it. |
| 14085 | TypeTableEntry *return_type; | 14237 | ZigType *return_type; |
| 14086 | | 14238 | |
| 14087 | if (type_is_invalid(array_type)) { | 14239 | if (type_is_invalid(array_type)) { |
| 14088 | return array_type; | 14240 | return array_type; |
| 14089 | } else if (array_type->id == TypeTableEntryIdArray || | 14241 | } else if (array_type->id == ZigTypeIdArray || |
| 14090 | (array_type->id == TypeTableEntryIdPointer && | 14242 | (array_type->id == ZigTypeIdPointer && |
| 14091 | array_type->data.pointer.ptr_len == PtrLenSingle && | 14243 | array_type->data.pointer.ptr_len == PtrLenSingle && |
| 14092 | array_type->data.pointer.child_type->id == TypeTableEntryIdArray)) | 14244 | array_type->data.pointer.child_type->id == ZigTypeIdArray)) |
| 14093 | { | 14245 | { |
| 14094 | if (array_type->id == TypeTableEntryIdPointer) { | 14246 | if (array_type->id == ZigTypeIdPointer) { |
| 14095 | array_type = array_type->data.pointer.child_type; | 14247 | array_type = array_type->data.pointer.child_type; |
| 14096 | ptr_type = ptr_type->data.pointer.child_type; | 14248 | ptr_type = ptr_type->data.pointer.child_type; |
| 14097 | if (orig_array_ptr_val->special != ConstValSpecialRuntime) { | 14249 | if (orig_array_ptr_val->special != ConstValSpecialRuntime) { |
| 14098 | orig_array_ptr_val = const_ptr_pointee(ira->codegen, orig_array_ptr_val); | 14250 | orig_array_ptr_val = ir_const_ptr_pointee(ira, orig_array_ptr_val, |
| | 14251 | elem_ptr_instruction->base.source_node); |
| | 14252 | if (orig_array_ptr_val == nullptr) |
| | 14253 | return ira->codegen->builtin_types.entry_invalid; |
| 14099 | } | 14254 | } |
| 14100 | } | 14255 | } |
| 14101 | if (array_type->data.array.len == 0) { | 14256 | if (array_type->data.array.len == 0) { |
| ... | @@ -14103,7 +14258,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc | ... | @@ -14103,7 +14258,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14103 | buf_sprintf("index 0 outside array of size 0")); | 14258 | buf_sprintf("index 0 outside array of size 0")); |
| 14104 | return ira->codegen->builtin_types.entry_invalid; | 14259 | return ira->codegen->builtin_types.entry_invalid; |
| 14105 | } | 14260 | } |
| 14106 | TypeTableEntry *child_type = array_type->data.array.child_type; | 14261 | ZigType *child_type = array_type->data.array.child_type; |
| 14107 | if (ptr_type->data.pointer.unaligned_bit_count == 0) { | 14262 | if (ptr_type->data.pointer.unaligned_bit_count == 0) { |
| 14108 | return_type = get_pointer_to_type_extra(ira->codegen, child_type, | 14263 | return_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 14109 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, | 14264 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| ... | @@ -14122,7 +14277,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc | ... | @@ -14122,7 +14277,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14122 | elem_ptr_instruction->ptr_len, | 14277 | elem_ptr_instruction->ptr_len, |
| 14123 | 1, (uint32_t)bit_offset, (uint32_t)bit_width); | 14278 | 1, (uint32_t)bit_offset, (uint32_t)bit_width); |
| 14124 | } | 14279 | } |
| 14125 | } else if (array_type->id == TypeTableEntryIdPointer) { | 14280 | } else if (array_type->id == ZigTypeIdPointer) { |
| 14126 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { | 14281 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { |
| 14127 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, | 14282 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14128 | buf_sprintf("index of single-item pointer")); | 14283 | buf_sprintf("index of single-item pointer")); |
| ... | @@ -14132,11 +14287,13 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc | ... | @@ -14132,11 +14287,13 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14132 | } else if (is_slice(array_type)) { | 14287 | } else if (is_slice(array_type)) { |
| 14133 | return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index].type_entry, | 14288 | return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index].type_entry, |
| 14134 | elem_ptr_instruction->ptr_len); | 14289 | elem_ptr_instruction->ptr_len); |
| 14135 | } else if (array_type->id == TypeTableEntryIdArgTuple) { | 14290 | } else if (array_type->id == ZigTypeIdArgTuple) { |
| 14136 | ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad); | 14291 | ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad); |
| 14137 | if (!ptr_val) | 14292 | if (!ptr_val) |
| 14138 | return ira->codegen->builtin_types.entry_invalid; | 14293 | return ira->codegen->builtin_types.entry_invalid; |
| 14139 | ConstExprValue *args_val = const_ptr_pointee(ira->codegen, ptr_val); | 14294 | ConstExprValue *args_val = ir_const_ptr_pointee(ira, ptr_val, elem_ptr_instruction->base.source_node); |
| | 14295 | if (args_val == nullptr) |
| | 14296 | return ira->codegen->builtin_types.entry_invalid; |
| 14140 | size_t start = args_val->data.x_arg_tuple.start_index; | 14297 | size_t start = args_val->data.x_arg_tuple.start_index; |
| 14141 | size_t end = args_val->data.x_arg_tuple.end_index; | 14298 | size_t end = args_val->data.x_arg_tuple.end_index; |
| 14142 | uint64_t elem_index_val; | 14299 | uint64_t elem_index_val; |
| ... | @@ -14150,9 +14307,9 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc | ... | @@ -14150,9 +14307,9 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14150 | return ira->codegen->builtin_types.entry_invalid; | 14307 | return ira->codegen->builtin_types.entry_invalid; |
| 14151 | } | 14308 | } |
| 14152 | size_t abs_index = start + index; | 14309 | size_t abs_index = start + index; |
| 14153 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); | 14310 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 14154 | assert(fn_entry); | 14311 | assert(fn_entry); |
| 14155 | VariableTableEntry *var = get_fn_var_by_index(fn_entry, abs_index); | 14312 | ZigVar *var = get_fn_var_by_index(fn_entry, abs_index); |
| 14156 | bool is_const = true; | 14313 | bool is_const = true; |
| 14157 | bool is_volatile = false; | 14314 | bool is_volatile = false; |
| 14158 | if (var) { | 14315 | if (var) { |
| ... | @@ -14167,7 +14324,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc | ... | @@ -14167,7 +14324,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14167 | return ira->codegen->builtin_types.entry_invalid; | 14324 | return ira->codegen->builtin_types.entry_invalid; |
| 14168 | } | 14325 | } |
| 14169 | | 14326 | |
| 14170 | TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; | 14327 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 14171 | IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize); | 14328 | IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize); |
| 14172 | if (casted_elem_index == ira->codegen->invalid_instruction) | 14329 | if (casted_elem_index == ira->codegen->invalid_instruction) |
| 14173 | return ira->codegen->builtin_types.entry_invalid; | 14330 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -14181,7 +14338,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc | ... | @@ -14181,7 +14338,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14181 | uint64_t ptr_align = return_type->data.pointer.alignment; | 14338 | uint64_t ptr_align = return_type->data.pointer.alignment; |
| 14182 | if (instr_is_comptime(casted_elem_index)) { | 14339 | if (instr_is_comptime(casted_elem_index)) { |
| 14183 | uint64_t index = bigint_as_unsigned(&casted_elem_index->value.data.x_bigint); | 14340 | uint64_t index = bigint_as_unsigned(&casted_elem_index->value.data.x_bigint); |
| 14184 | if (array_type->id == TypeTableEntryIdArray) { | 14341 | if (array_type->id == ZigTypeIdArray) { |
| 14185 | uint64_t array_len = array_type->data.array.len; | 14342 | uint64_t array_len = array_type->data.array.len; |
| 14186 | if (index >= array_len) { | 14343 | if (index >= array_len) { |
| 14187 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, | 14344 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| ... | @@ -14212,120 +14369,126 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc | ... | @@ -14212,120 +14369,126 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14212 | return_type = adjust_ptr_align(ira->codegen, return_type, chosen_align); | 14369 | return_type = adjust_ptr_align(ira->codegen, return_type, chosen_align); |
| 14213 | } | 14370 | } |
| 14214 | | 14371 | |
| 14215 | ConstExprValue *array_ptr_val; | | |
| 14216 | if (orig_array_ptr_val->special != ConstValSpecialRuntime && | 14372 | if (orig_array_ptr_val->special != ConstValSpecialRuntime && |
| 14217 | (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == TypeTableEntryIdArray) && | 14373 | (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || |
| 14218 | (array_ptr_val = const_ptr_pointee(ira->codegen, orig_array_ptr_val)) && | 14374 | array_type->id == ZigTypeIdArray)) |
| 14219 | array_ptr_val->special != ConstValSpecialRuntime && | | |
| 14220 | (array_type->id != TypeTableEntryIdPointer || | | |
| 14221 | array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)) | | |
| 14222 | { | 14375 | { |
| 14223 | if (array_type->id == TypeTableEntryIdPointer) { | 14376 | ConstExprValue *array_ptr_val = ir_const_ptr_pointee(ira, orig_array_ptr_val, |
| 14224 | ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base); | 14377 | elem_ptr_instruction->base.source_node); |
| 14225 | out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut; | 14378 | if (array_ptr_val == nullptr) |
| 14226 | size_t new_index; | 14379 | return ira->codegen->builtin_types.entry_invalid; |
| 14227 | size_t mem_size; | | |
| 14228 | size_t old_size; | | |
| 14229 | switch (array_ptr_val->data.x_ptr.special) { | | |
| 14230 | case ConstPtrSpecialInvalid: | | |
| 14231 | case ConstPtrSpecialDiscard: | | |
| 14232 | zig_unreachable(); | | |
| 14233 | case ConstPtrSpecialRef: | | |
| 14234 | mem_size = 1; | | |
| 14235 | old_size = 1; | | |
| 14236 | new_index = index; | | |
| 14237 | | | |
| 14238 | out_val->data.x_ptr.special = ConstPtrSpecialRef; | | |
| 14239 | out_val->data.x_ptr.data.ref.pointee = array_ptr_val->data.x_ptr.data.ref.pointee; | | |
| 14240 | break; | | |
| 14241 | case ConstPtrSpecialBaseArray: | | |
| 14242 | { | | |
| 14243 | size_t offset = array_ptr_val->data.x_ptr.data.base_array.elem_index; | | |
| 14244 | new_index = offset + index; | | |
| 14245 | mem_size = array_ptr_val->data.x_ptr.data.base_array.array_val->type->data.array.len; | | |
| 14246 | old_size = mem_size - offset; | | |
| 14247 | | | |
| 14248 | assert(array_ptr_val->data.x_ptr.data.base_array.array_val); | | |
| 14249 | | | |
| 14250 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; | | |
| 14251 | out_val->data.x_ptr.data.base_array.array_val = | | |
| 14252 | array_ptr_val->data.x_ptr.data.base_array.array_val; | | |
| 14253 | out_val->data.x_ptr.data.base_array.elem_index = new_index; | | |
| 14254 | out_val->data.x_ptr.data.base_array.is_cstr = | | |
| 14255 | array_ptr_val->data.x_ptr.data.base_array.is_cstr; | | |
| 14256 | | 14380 | |
| | 14381 | if (array_ptr_val->special != ConstValSpecialRuntime && |
| | 14382 | (array_type->id != ZigTypeIdPointer || |
| | 14383 | array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)) |
| | 14384 | { |
| | 14385 | if (array_type->id == ZigTypeIdPointer) { |
| | 14386 | ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base); |
| | 14387 | out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut; |
| | 14388 | size_t new_index; |
| | 14389 | size_t mem_size; |
| | 14390 | size_t old_size; |
| | 14391 | switch (array_ptr_val->data.x_ptr.special) { |
| | 14392 | case ConstPtrSpecialInvalid: |
| | 14393 | case ConstPtrSpecialDiscard: |
| | 14394 | zig_unreachable(); |
| | 14395 | case ConstPtrSpecialRef: |
| | 14396 | mem_size = 1; |
| | 14397 | old_size = 1; |
| | 14398 | new_index = index; |
| | 14399 | |
| | 14400 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| | 14401 | out_val->data.x_ptr.data.ref.pointee = array_ptr_val->data.x_ptr.data.ref.pointee; |
| 14257 | break; | 14402 | break; |
| 14258 | } | 14403 | case ConstPtrSpecialBaseArray: |
| 14259 | case ConstPtrSpecialBaseStruct: | 14404 | { |
| 14260 | zig_panic("TODO elem ptr on a const inner struct"); | 14405 | size_t offset = array_ptr_val->data.x_ptr.data.base_array.elem_index; |
| 14261 | case ConstPtrSpecialHardCodedAddr: | 14406 | new_index = offset + index; |
| 14262 | zig_unreachable(); | 14407 | mem_size = array_ptr_val->data.x_ptr.data.base_array.array_val->type->data.array.len; |
| 14263 | case ConstPtrSpecialFunction: | 14408 | old_size = mem_size - offset; |
| 14264 | zig_panic("TODO element ptr of a function casted to a ptr"); | 14409 | |
| 14265 | } | 14410 | assert(array_ptr_val->data.x_ptr.data.base_array.array_val); |
| 14266 | if (new_index >= mem_size) { | 14411 | |
| 14267 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, | 14412 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 14268 | buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size)); | 14413 | out_val->data.x_ptr.data.base_array.array_val = |
| 14269 | return ira->codegen->builtin_types.entry_invalid; | 14414 | array_ptr_val->data.x_ptr.data.base_array.array_val; |
| 14270 | } | 14415 | out_val->data.x_ptr.data.base_array.elem_index = new_index; |
| 14271 | return return_type; | 14416 | out_val->data.x_ptr.data.base_array.is_cstr = |
| 14272 | } else if (is_slice(array_type)) { | 14417 | array_ptr_val->data.x_ptr.data.base_array.is_cstr; |
| 14273 | ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index]; | 14418 | |
| 14274 | if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { | 14419 | break; |
| 14275 | IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, | 14420 | } |
| 14276 | array_ptr, casted_elem_index, false, elem_ptr_instruction->ptr_len); | 14421 | case ConstPtrSpecialBaseStruct: |
| 14277 | result->value.type = return_type; | 14422 | zig_panic("TODO elem ptr on a const inner struct"); |
| 14278 | ir_link_new_instruction(result, &elem_ptr_instruction->base); | 14423 | case ConstPtrSpecialHardCodedAddr: |
| | 14424 | zig_unreachable(); |
| | 14425 | case ConstPtrSpecialFunction: |
| | 14426 | zig_panic("TODO element ptr of a function casted to a ptr"); |
| | 14427 | } |
| | 14428 | if (new_index >= mem_size) { |
| | 14429 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| | 14430 | buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size)); |
| | 14431 | return ira->codegen->builtin_types.entry_invalid; |
| | 14432 | } |
| 14279 | return return_type; | 14433 | return return_type; |
| 14280 | } | 14434 | } else if (is_slice(array_type)) { |
| 14281 | ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index]; | 14435 | ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index]; |
| 14282 | ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base); | 14436 | if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 14283 | uint64_t slice_len = bigint_as_unsigned(&len_field->data.x_bigint); | 14437 | IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, |
| 14284 | if (index >= slice_len) { | 14438 | array_ptr, casted_elem_index, false, elem_ptr_instruction->ptr_len); |
| 14285 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, | 14439 | result->value.type = return_type; |
| 14286 | buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64, | 14440 | ir_link_new_instruction(result, &elem_ptr_instruction->base); |
| 14287 | index, slice_len)); | 14441 | return return_type; |
| 14288 | return ira->codegen->builtin_types.entry_invalid; | 14442 | } |
| 14289 | } | 14443 | ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index]; |
| 14290 | out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut; | 14444 | ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base); |
| 14291 | switch (ptr_field->data.x_ptr.special) { | 14445 | uint64_t slice_len = bigint_as_unsigned(&len_field->data.x_bigint); |
| 14292 | case ConstPtrSpecialInvalid: | 14446 | if (index >= slice_len) { |
| 14293 | case ConstPtrSpecialDiscard: | 14447 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14294 | zig_unreachable(); | 14448 | buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64, |
| 14295 | case ConstPtrSpecialRef: | 14449 | index, slice_len)); |
| 14296 | out_val->data.x_ptr.special = ConstPtrSpecialRef; | 14450 | return ira->codegen->builtin_types.entry_invalid; |
| 14297 | out_val->data.x_ptr.data.ref.pointee = ptr_field->data.x_ptr.data.ref.pointee; | 14451 | } |
| 14298 | break; | 14452 | out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut; |
| 14299 | case ConstPtrSpecialBaseArray: | 14453 | switch (ptr_field->data.x_ptr.special) { |
| 14300 | { | 14454 | case ConstPtrSpecialInvalid: |
| 14301 | size_t offset = ptr_field->data.x_ptr.data.base_array.elem_index; | 14455 | case ConstPtrSpecialDiscard: |
| 14302 | uint64_t new_index = offset + index; | 14456 | zig_unreachable(); |
| 14303 | assert(new_index < ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len); | 14457 | case ConstPtrSpecialRef: |
| 14304 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; | 14458 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 14305 | out_val->data.x_ptr.data.base_array.array_val = | 14459 | out_val->data.x_ptr.data.ref.pointee = ptr_field->data.x_ptr.data.ref.pointee; |
| 14306 | ptr_field->data.x_ptr.data.base_array.array_val; | | |
| 14307 | out_val->data.x_ptr.data.base_array.elem_index = new_index; | | |
| 14308 | out_val->data.x_ptr.data.base_array.is_cstr = | | |
| 14309 | ptr_field->data.x_ptr.data.base_array.is_cstr; | | |
| 14310 | break; | 14460 | break; |
| 14311 | } | 14461 | case ConstPtrSpecialBaseArray: |
| 14312 | case ConstPtrSpecialBaseStruct: | 14462 | { |
| 14313 | zig_panic("TODO elem ptr on a slice backed by const inner struct"); | 14463 | size_t offset = ptr_field->data.x_ptr.data.base_array.elem_index; |
| 14314 | case ConstPtrSpecialHardCodedAddr: | 14464 | uint64_t new_index = offset + index; |
| 14315 | zig_unreachable(); | 14465 | assert(new_index < ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len); |
| 14316 | case ConstPtrSpecialFunction: | 14466 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 14317 | zig_panic("TODO elem ptr on a slice that was ptrcast from a function"); | 14467 | out_val->data.x_ptr.data.base_array.array_val = |
| | 14468 | ptr_field->data.x_ptr.data.base_array.array_val; |
| | 14469 | out_val->data.x_ptr.data.base_array.elem_index = new_index; |
| | 14470 | out_val->data.x_ptr.data.base_array.is_cstr = |
| | 14471 | ptr_field->data.x_ptr.data.base_array.is_cstr; |
| | 14472 | break; |
| | 14473 | } |
| | 14474 | case ConstPtrSpecialBaseStruct: |
| | 14475 | zig_panic("TODO elem ptr on a slice backed by const inner struct"); |
| | 14476 | case ConstPtrSpecialHardCodedAddr: |
| | 14477 | zig_unreachable(); |
| | 14478 | case ConstPtrSpecialFunction: |
| | 14479 | zig_panic("TODO elem ptr on a slice that was ptrcast from a function"); |
| | 14480 | } |
| | 14481 | return return_type; |
| | 14482 | } else if (array_type->id == ZigTypeIdArray) { |
| | 14483 | ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base); |
| | 14484 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| | 14485 | out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut; |
| | 14486 | out_val->data.x_ptr.data.base_array.array_val = array_ptr_val; |
| | 14487 | out_val->data.x_ptr.data.base_array.elem_index = index; |
| | 14488 | return return_type; |
| | 14489 | } else { |
| | 14490 | zig_unreachable(); |
| 14318 | } | 14491 | } |
| 14319 | return return_type; | | |
| 14320 | } else if (array_type->id == TypeTableEntryIdArray) { | | |
| 14321 | ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base); | | |
| 14322 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; | | |
| 14323 | out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut; | | |
| 14324 | out_val->data.x_ptr.data.base_array.array_val = array_ptr_val; | | |
| 14325 | out_val->data.x_ptr.data.base_array.elem_index = index; | | |
| 14326 | return return_type; | | |
| 14327 | } else { | | |
| 14328 | zig_unreachable(); | | |
| 14329 | } | 14492 | } |
| 14330 | } | 14493 | } |
| 14331 | | 14494 | |
| ... | @@ -14351,8 +14514,8 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc | ... | @@ -14351,8 +14514,8 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14351 | } | 14514 | } |
| 14352 | | 14515 | |
| 14353 | static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, | 14516 | static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 14354 | TypeTableEntry *bare_struct_type, Buf *field_name, IrInstruction *source_instr, | 14517 | ZigType *bare_struct_type, Buf *field_name, IrInstruction *source_instr, |
| 14355 | IrInstruction *container_ptr, TypeTableEntry *container_type) | 14518 | IrInstruction *container_ptr, ZigType *container_type) |
| 14356 | { | 14519 | { |
| 14357 | if (!is_slice(bare_struct_type)) { | 14520 | if (!is_slice(bare_struct_type)) { |
| 14358 | ScopeDecls *container_scope = get_container_scope(bare_struct_type); | 14521 | ScopeDecls *container_scope = get_container_scope(bare_struct_type); |
| ... | @@ -14364,7 +14527,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, | ... | @@ -14364,7 +14527,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 14364 | if (tld->resolution == TldResolutionInvalid) | 14527 | if (tld->resolution == TldResolutionInvalid) |
| 14365 | return ira->codegen->invalid_instruction; | 14528 | return ira->codegen->invalid_instruction; |
| 14366 | TldFn *tld_fn = (TldFn *)tld; | 14529 | TldFn *tld_fn = (TldFn *)tld; |
| 14367 | FnTableEntry *fn_entry = tld_fn->fn_entry; | 14530 | ZigFn *fn_entry = tld_fn->fn_entry; |
| 14368 | if (type_is_invalid(fn_entry->type_entry)) | 14531 | if (type_is_invalid(fn_entry->type_entry)) |
| 14369 | return ira->codegen->invalid_instruction; | 14532 | return ira->codegen->invalid_instruction; |
| 14370 | | 14533 | |
| ... | @@ -14376,11 +14539,11 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, | ... | @@ -14376,11 +14539,11 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 14376 | const char *prefix_name; | 14539 | const char *prefix_name; |
| 14377 | if (is_slice(bare_struct_type)) { | 14540 | if (is_slice(bare_struct_type)) { |
| 14378 | prefix_name = ""; | 14541 | prefix_name = ""; |
| 14379 | } else if (bare_struct_type->id == TypeTableEntryIdStruct) { | 14542 | } else if (bare_struct_type->id == ZigTypeIdStruct) { |
| 14380 | prefix_name = "struct "; | 14543 | prefix_name = "struct "; |
| 14381 | } else if (bare_struct_type->id == TypeTableEntryIdEnum) { | 14544 | } else if (bare_struct_type->id == ZigTypeIdEnum) { |
| 14382 | prefix_name = "enum "; | 14545 | prefix_name = "enum "; |
| 14383 | } else if (bare_struct_type->id == TypeTableEntryIdUnion) { | 14546 | } else if (bare_struct_type->id == ZigTypeIdUnion) { |
| 14384 | prefix_name = "union "; | 14547 | prefix_name = "union "; |
| 14385 | } else { | 14548 | } else { |
| 14386 | prefix_name = ""; | 14549 | prefix_name = ""; |
| ... | @@ -14391,18 +14554,18 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, | ... | @@ -14391,18 +14554,18 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 14391 | } | 14554 | } |
| 14392 | | 14555 | |
| 14393 | static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, | 14556 | static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 14394 | IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type) | 14557 | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type) |
| 14395 | { | 14558 | { |
| 14396 | Error err; | 14559 | Error err; |
| 14397 | | 14560 | |
| 14398 | TypeTableEntry *bare_type = container_ref_type(container_type); | 14561 | ZigType *bare_type = container_ref_type(container_type); |
| 14399 | if ((err = ensure_complete_type(ira->codegen, bare_type))) | 14562 | if ((err = ensure_complete_type(ira->codegen, bare_type))) |
| 14400 | return ira->codegen->invalid_instruction; | 14563 | return ira->codegen->invalid_instruction; |
| 14401 | | 14564 | |
| 14402 | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); | 14565 | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 14403 | bool is_const = container_ptr->value.type->data.pointer.is_const; | 14566 | bool is_const = container_ptr->value.type->data.pointer.is_const; |
| 14404 | bool is_volatile = container_ptr->value.type->data.pointer.is_volatile; | 14567 | bool is_volatile = container_ptr->value.type->data.pointer.is_volatile; |
| 14405 | if (bare_type->id == TypeTableEntryIdStruct) { | 14568 | if (bare_type->id == ZigTypeIdStruct) { |
| 14406 | TypeStructField *field = find_struct_type_field(bare_type, field_name); | 14569 | TypeStructField *field = find_struct_type_field(bare_type, field_name); |
| 14407 | if (field) { | 14570 | if (field) { |
| 14408 | bool is_packed = (bare_type->data.structure.layout == ContainerLayoutPacked); | 14571 | bool is_packed = (bare_type->data.structure.layout == ContainerLayoutPacked); |
| ... | @@ -14417,11 +14580,13 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ | ... | @@ -14417,11 +14580,13 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 14417 | return ira->codegen->invalid_instruction; | 14580 | return ira->codegen->invalid_instruction; |
| 14418 | | 14581 | |
| 14419 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { | 14582 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 14420 | ConstExprValue *struct_val = const_ptr_pointee(ira->codegen, ptr_val); | 14583 | ConstExprValue *struct_val = ir_const_ptr_pointee(ira, ptr_val, source_instr->source_node); |
| | 14584 | if (struct_val == nullptr) |
| | 14585 | return ira->codegen->invalid_instruction; |
| 14421 | if (type_is_invalid(struct_val->type)) | 14586 | if (type_is_invalid(struct_val->type)) |
| 14422 | return ira->codegen->invalid_instruction; | 14587 | return ira->codegen->invalid_instruction; |
| 14423 | ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index]; | 14588 | ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index]; |
| 14424 | TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, field_val->type, | 14589 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_val->type, |
| 14425 | is_const, is_volatile, PtrLenSingle, align_bytes, | 14590 | is_const, is_volatile, PtrLenSingle, align_bytes, |
| 14426 | (uint32_t)(ptr_bit_offset + field->packed_bits_offset), | 14591 | (uint32_t)(ptr_bit_offset + field->packed_bits_offset), |
| 14427 | (uint32_t)unaligned_bit_count_for_result_type); | 14592 | (uint32_t)unaligned_bit_count_for_result_type); |
| ... | @@ -14447,10 +14612,10 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ | ... | @@ -14447,10 +14612,10 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 14447 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, | 14612 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, |
| 14448 | source_instr, container_ptr, container_type); | 14613 | source_instr, container_ptr, container_type); |
| 14449 | } | 14614 | } |
| 14450 | } else if (bare_type->id == TypeTableEntryIdEnum) { | 14615 | } else if (bare_type->id == ZigTypeIdEnum) { |
| 14451 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, | 14616 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, |
| 14452 | source_instr, container_ptr, container_type); | 14617 | source_instr, container_ptr, container_type); |
| 14453 | } else if (bare_type->id == TypeTableEntryIdUnion) { | 14618 | } else if (bare_type->id == ZigTypeIdUnion) { |
| 14454 | TypeUnionField *field = find_union_type_field(bare_type, field_name); | 14619 | TypeUnionField *field = find_union_type_field(bare_type, field_name); |
| 14455 | if (field) { | 14620 | if (field) { |
| 14456 | if (instr_is_comptime(container_ptr)) { | 14621 | if (instr_is_comptime(container_ptr)) { |
| ... | @@ -14459,7 +14624,9 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ | ... | @@ -14459,7 +14624,9 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 14459 | return ira->codegen->invalid_instruction; | 14624 | return ira->codegen->invalid_instruction; |
| 14460 | | 14625 | |
| 14461 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { | 14626 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 14462 | ConstExprValue *union_val = const_ptr_pointee(ira->codegen, ptr_val); | 14627 | ConstExprValue *union_val = ir_const_ptr_pointee(ira, ptr_val, source_instr->source_node); |
| | 14628 | if (union_val == nullptr) |
| | 14629 | return ira->codegen->invalid_instruction; |
| 14463 | if (type_is_invalid(union_val->type)) | 14630 | if (type_is_invalid(union_val->type)) |
| 14464 | return ira->codegen->invalid_instruction; | 14631 | return ira->codegen->invalid_instruction; |
| 14465 | | 14632 | |
| ... | @@ -14476,15 +14643,15 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ | ... | @@ -14476,15 +14643,15 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 14476 | | 14643 | |
| 14477 | ConstExprValue *payload_val = union_val->data.x_union.payload; | 14644 | ConstExprValue *payload_val = union_val->data.x_union.payload; |
| 14478 | | 14645 | |
| 14479 | TypeTableEntry *field_type = field->type_entry; | 14646 | ZigType *field_type = field->type_entry; |
| 14480 | if (field_type->id == TypeTableEntryIdVoid) { | 14647 | if (field_type->id == ZigTypeIdVoid) { |
| 14481 | assert(payload_val == nullptr); | 14648 | assert(payload_val == nullptr); |
| 14482 | payload_val = create_const_vals(1); | 14649 | payload_val = create_const_vals(1); |
| 14483 | payload_val->special = ConstValSpecialStatic; | 14650 | payload_val->special = ConstValSpecialStatic; |
| 14484 | payload_val->type = field_type; | 14651 | payload_val->type = field_type; |
| 14485 | } | 14652 | } |
| 14486 | | 14653 | |
| 14487 | TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, | 14654 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, |
| 14488 | is_const, is_volatile, | 14655 | is_const, is_volatile, |
| 14489 | PtrLenSingle, | 14656 | PtrLenSingle, |
| 14490 | get_abi_alignment(ira->codegen, field_type), 0, 0); | 14657 | get_abi_alignment(ira->codegen, field_type), 0, 0); |
| ... | @@ -14531,7 +14698,7 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, | ... | @@ -14531,7 +14698,7 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, |
| 14531 | } | 14698 | } |
| 14532 | | 14699 | |
| 14533 | | 14700 | |
| 14534 | static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) { | 14701 | static ZigType *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) { |
| 14535 | bool pointer_only = false; | 14702 | bool pointer_only = false; |
| 14536 | resolve_top_level_decl(ira->codegen, tld, pointer_only, source_instruction->source_node); | 14703 | resolve_top_level_decl(ira->codegen, tld, pointer_only, source_instruction->source_node); |
| 14537 | if (tld->resolution == TldResolutionInvalid) | 14704 | if (tld->resolution == TldResolutionInvalid) |
| ... | @@ -14544,7 +14711,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source | ... | @@ -14544,7 +14711,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source |
| 14544 | case TldIdVar: | 14711 | case TldIdVar: |
| 14545 | { | 14712 | { |
| 14546 | TldVar *tld_var = (TldVar *)tld; | 14713 | TldVar *tld_var = (TldVar *)tld; |
| 14547 | VariableTableEntry *var = tld_var->var; | 14714 | ZigVar *var = tld_var->var; |
| 14548 | if (tld_var->extern_lib_name != nullptr) { | 14715 | if (tld_var->extern_lib_name != nullptr) { |
| 14549 | add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node); | 14716 | add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node); |
| 14550 | } | 14717 | } |
| ... | @@ -14554,7 +14721,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source | ... | @@ -14554,7 +14721,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source |
| 14554 | case TldIdFn: | 14721 | case TldIdFn: |
| 14555 | { | 14722 | { |
| 14556 | TldFn *tld_fn = (TldFn *)tld; | 14723 | TldFn *tld_fn = (TldFn *)tld; |
| 14557 | FnTableEntry *fn_entry = tld_fn->fn_entry; | 14724 | ZigFn *fn_entry = tld_fn->fn_entry; |
| 14558 | assert(fn_entry->type_entry); | 14725 | assert(fn_entry->type_entry); |
| 14559 | | 14726 | |
| 14560 | if (type_is_invalid(fn_entry->type_entry)) | 14727 | if (type_is_invalid(fn_entry->type_entry)) |
| ... | @@ -14582,8 +14749,8 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source | ... | @@ -14582,8 +14749,8 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source |
| 14582 | zig_unreachable(); | 14749 | zig_unreachable(); |
| 14583 | } | 14750 | } |
| 14584 | | 14751 | |
| 14585 | static ErrorTableEntry *find_err_table_entry(TypeTableEntry *err_set_type, Buf *field_name) { | 14752 | static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_name) { |
| 14586 | assert(err_set_type->id == TypeTableEntryIdErrorSet); | 14753 | assert(err_set_type->id == ZigTypeIdErrorSet); |
| 14587 | for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) { | 14754 | for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) { |
| 14588 | ErrorTableEntry *err_table_entry = err_set_type->data.error_set.errors[i]; | 14755 | ErrorTableEntry *err_table_entry = err_set_type->data.error_set.errors[i]; |
| 14589 | if (buf_eql_buf(&err_table_entry->name, field_name)) { | 14756 | if (buf_eql_buf(&err_table_entry->name, field_name)) { |
| ... | @@ -14593,14 +14760,14 @@ static ErrorTableEntry *find_err_table_entry(TypeTableEntry *err_set_type, Buf * | ... | @@ -14593,14 +14760,14 @@ static ErrorTableEntry *find_err_table_entry(TypeTableEntry *err_set_type, Buf * |
| 14593 | return nullptr; | 14760 | return nullptr; |
| 14594 | } | 14761 | } |
| 14595 | | 14762 | |
| 14596 | static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) { | 14763 | static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) { |
| 14597 | Error err; | 14764 | Error err; |
| 14598 | IrInstruction *container_ptr = field_ptr_instruction->container_ptr->other; | 14765 | IrInstruction *container_ptr = field_ptr_instruction->container_ptr->other; |
| 14599 | if (type_is_invalid(container_ptr->value.type)) | 14766 | if (type_is_invalid(container_ptr->value.type)) |
| 14600 | return ira->codegen->builtin_types.entry_invalid; | 14767 | return ira->codegen->builtin_types.entry_invalid; |
| 14601 | | 14768 | |
| 14602 | TypeTableEntry *container_type = container_ptr->value.type->data.pointer.child_type; | 14769 | ZigType *container_type = container_ptr->value.type->data.pointer.child_type; |
| 14603 | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); | 14770 | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 14604 | | 14771 | |
| 14605 | Buf *field_name = field_ptr_instruction->field_name_buffer; | 14772 | Buf *field_name = field_ptr_instruction->field_name_buffer; |
| 14606 | if (!field_name) { | 14773 | if (!field_name) { |
| ... | @@ -14616,9 +14783,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14616,9 +14783,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14616 | if (type_is_invalid(container_type)) { | 14783 | if (type_is_invalid(container_type)) { |
| 14617 | return container_type; | 14784 | return container_type; |
| 14618 | } else if (is_container_ref(container_type)) { | 14785 | } else if (is_container_ref(container_type)) { |
| 14619 | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); | 14786 | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 14620 | if (container_type->id == TypeTableEntryIdPointer) { | 14787 | if (container_type->id == ZigTypeIdPointer) { |
| 14621 | TypeTableEntry *bare_type = container_ref_type(container_type); | 14788 | ZigType *bare_type = container_ref_type(container_type); |
| 14622 | IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr); | 14789 | IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr); |
| 14623 | IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type); | 14790 | IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type); |
| 14624 | ir_link_new_instruction(result, &field_ptr_instruction->base); | 14791 | ir_link_new_instruction(result, &field_ptr_instruction->base); |
| ... | @@ -14631,13 +14798,13 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14631,13 +14798,13 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14631 | } else if (is_array_ref(container_type)) { | 14798 | } else if (is_array_ref(container_type)) { |
| 14632 | if (buf_eql_str(field_name, "len")) { | 14799 | if (buf_eql_str(field_name, "len")) { |
| 14633 | ConstExprValue *len_val = create_const_vals(1); | 14800 | ConstExprValue *len_val = create_const_vals(1); |
| 14634 | if (container_type->id == TypeTableEntryIdPointer) { | 14801 | if (container_type->id == ZigTypeIdPointer) { |
| 14635 | init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len); | 14802 | init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len); |
| 14636 | } else { | 14803 | } else { |
| 14637 | init_const_usize(ira->codegen, len_val, container_type->data.array.len); | 14804 | init_const_usize(ira->codegen, len_val, container_type->data.array.len); |
| 14638 | } | 14805 | } |
| 14639 | | 14806 | |
| 14640 | TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; | 14807 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 14641 | bool ptr_is_const = true; | 14808 | bool ptr_is_const = true; |
| 14642 | bool ptr_is_volatile = false; | 14809 | bool ptr_is_volatile = false; |
| 14643 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val, | 14810 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val, |
| ... | @@ -14648,20 +14815,22 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14648,20 +14815,22 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14648 | buf_ptr(&container_type->name))); | 14815 | buf_ptr(&container_type->name))); |
| 14649 | return ira->codegen->builtin_types.entry_invalid; | 14816 | return ira->codegen->builtin_types.entry_invalid; |
| 14650 | } | 14817 | } |
| 14651 | } else if (container_type->id == TypeTableEntryIdArgTuple) { | 14818 | } else if (container_type->id == ZigTypeIdArgTuple) { |
| 14652 | ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); | 14819 | ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 14653 | if (!container_ptr_val) | 14820 | if (!container_ptr_val) |
| 14654 | return ira->codegen->builtin_types.entry_invalid; | 14821 | return ira->codegen->builtin_types.entry_invalid; |
| 14655 | | 14822 | |
| 14656 | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); | 14823 | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 14657 | ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val); | 14824 | ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node); |
| | 14825 | if (child_val == nullptr) |
| | 14826 | return ira->codegen->builtin_types.entry_invalid; |
| 14658 | | 14827 | |
| 14659 | if (buf_eql_str(field_name, "len")) { | 14828 | if (buf_eql_str(field_name, "len")) { |
| 14660 | ConstExprValue *len_val = create_const_vals(1); | 14829 | ConstExprValue *len_val = create_const_vals(1); |
| 14661 | size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index; | 14830 | size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index; |
| 14662 | init_const_usize(ira->codegen, len_val, len); | 14831 | init_const_usize(ira->codegen, len_val, len); |
| 14663 | | 14832 | |
| 14664 | TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; | 14833 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 14665 | bool ptr_is_const = true; | 14834 | bool ptr_is_const = true; |
| 14666 | bool ptr_is_volatile = false; | 14835 | bool ptr_is_volatile = false; |
| 14667 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val, | 14836 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val, |
| ... | @@ -14672,14 +14841,16 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14672,14 +14841,16 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14672 | buf_ptr(&container_type->name))); | 14841 | buf_ptr(&container_type->name))); |
| 14673 | return ira->codegen->builtin_types.entry_invalid; | 14842 | return ira->codegen->builtin_types.entry_invalid; |
| 14674 | } | 14843 | } |
| 14675 | } else if (container_type->id == TypeTableEntryIdMetaType) { | 14844 | } else if (container_type->id == ZigTypeIdMetaType) { |
| 14676 | ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); | 14845 | ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 14677 | if (!container_ptr_val) | 14846 | if (!container_ptr_val) |
| 14678 | return ira->codegen->builtin_types.entry_invalid; | 14847 | return ira->codegen->builtin_types.entry_invalid; |
| 14679 | | 14848 | |
| 14680 | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); | 14849 | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 14681 | ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val); | 14850 | ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node); |
| 14682 | TypeTableEntry *child_type = child_val->data.x_type; | 14851 | if (child_val == nullptr) |
| | 14852 | return ira->codegen->builtin_types.entry_invalid; |
| | 14853 | ZigType *child_type = child_val->data.x_type; |
| 14683 | | 14854 | |
| 14684 | if (type_is_invalid(child_type)) { | 14855 | if (type_is_invalid(child_type)) { |
| 14685 | return ira->codegen->builtin_types.entry_invalid; | 14856 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -14688,14 +14859,14 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14688,14 +14859,14 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14688 | bool ptr_is_const = true; | 14859 | bool ptr_is_const = true; |
| 14689 | bool ptr_is_volatile = false; | 14860 | bool ptr_is_volatile = false; |
| 14690 | TypeStructField *ptr_field = &child_type->data.structure.fields[slice_ptr_index]; | 14861 | TypeStructField *ptr_field = &child_type->data.structure.fields[slice_ptr_index]; |
| 14691 | assert(ptr_field->type_entry->id == TypeTableEntryIdPointer); | 14862 | assert(ptr_field->type_entry->id == ZigTypeIdPointer); |
| 14692 | TypeTableEntry *child_type = ptr_field->type_entry->data.pointer.child_type; | 14863 | ZigType *child_type = ptr_field->type_entry->data.pointer.child_type; |
| 14693 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, | 14864 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14694 | create_const_type(ira->codegen, child_type), | 14865 | create_const_type(ira->codegen, child_type), |
| 14695 | ira->codegen->builtin_types.entry_type, | 14866 | ira->codegen->builtin_types.entry_type, |
| 14696 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); | 14867 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14697 | } | 14868 | } |
| 14698 | if (child_type->id == TypeTableEntryIdEnum) { | 14869 | if (child_type->id == ZigTypeIdEnum) { |
| 14699 | if ((err = ensure_complete_type(ira->codegen, child_type))) | 14870 | if ((err = ensure_complete_type(ira->codegen, child_type))) |
| 14700 | return ira->codegen->builtin_types.entry_invalid; | 14871 | return ira->codegen->builtin_types.entry_invalid; |
| 14701 | | 14872 | |
| ... | @@ -14716,7 +14887,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14716,7 +14887,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14716 | return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld); | 14887 | return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld); |
| 14717 | } | 14888 | } |
| 14718 | } | 14889 | } |
| 14719 | if (child_type->id == TypeTableEntryIdUnion && | 14890 | if (child_type->id == ZigTypeIdUnion && |
| 14720 | (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr || | 14891 | (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr || |
| 14721 | child_type->data.unionation.decl_node->data.container_decl.auto_enum)) | 14892 | child_type->data.unionation.decl_node->data.container_decl.auto_enum)) |
| 14722 | { | 14893 | { |
| ... | @@ -14724,7 +14895,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14724,7 +14895,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14724 | return ira->codegen->builtin_types.entry_invalid; | 14895 | return ira->codegen->builtin_types.entry_invalid; |
| 14725 | TypeUnionField *field = find_union_type_field(child_type, field_name); | 14896 | TypeUnionField *field = find_union_type_field(child_type, field_name); |
| 14726 | if (field) { | 14897 | if (field) { |
| 14727 | TypeTableEntry *enum_type = child_type->data.unionation.tag_type; | 14898 | ZigType *enum_type = child_type->data.unionation.tag_type; |
| 14728 | bool ptr_is_const = true; | 14899 | bool ptr_is_const = true; |
| 14729 | bool ptr_is_volatile = false; | 14900 | bool ptr_is_volatile = false; |
| 14730 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, | 14901 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| ... | @@ -14736,9 +14907,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14736,9 +14907,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14736 | buf_sprintf("container '%s' has no member called '%s'", | 14907 | buf_sprintf("container '%s' has no member called '%s'", |
| 14737 | buf_ptr(&child_type->name), buf_ptr(field_name))); | 14908 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 14738 | return ira->codegen->builtin_types.entry_invalid; | 14909 | return ira->codegen->builtin_types.entry_invalid; |
| 14739 | } else if (child_type->id == TypeTableEntryIdErrorSet) { | 14910 | } else if (child_type->id == ZigTypeIdErrorSet) { |
| 14740 | ErrorTableEntry *err_entry; | 14911 | ErrorTableEntry *err_entry; |
| 14741 | TypeTableEntry *err_set_type; | 14912 | ZigType *err_set_type; |
| 14742 | if (type_is_global_error_set(child_type)) { | 14913 | if (type_is_global_error_set(child_type)) { |
| 14743 | auto existing_entry = ira->codegen->error_table.maybe_get(field_name); | 14914 | auto existing_entry = ira->codegen->error_table.maybe_get(field_name); |
| 14744 | if (existing_entry) { | 14915 | if (existing_entry) { |
| ... | @@ -14782,7 +14953,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14782,7 +14953,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14782 | bool ptr_is_volatile = false; | 14953 | bool ptr_is_volatile = false; |
| 14783 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, const_val, | 14954 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, const_val, |
| 14784 | err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); | 14955 | err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14785 | } else if (child_type->id == TypeTableEntryIdInt) { | 14956 | } else if (child_type->id == ZigTypeIdInt) { |
| 14786 | if (buf_eql_str(field_name, "bit_count")) { | 14957 | if (buf_eql_str(field_name, "bit_count")) { |
| 14787 | bool ptr_is_const = true; | 14958 | bool ptr_is_const = true; |
| 14788 | bool ptr_is_volatile = false; | 14959 | bool ptr_is_volatile = false; |
| ... | @@ -14804,7 +14975,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14804,7 +14975,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14804 | buf_ptr(&child_type->name), buf_ptr(field_name))); | 14975 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 14805 | return ira->codegen->builtin_types.entry_invalid; | 14976 | return ira->codegen->builtin_types.entry_invalid; |
| 14806 | } | 14977 | } |
| 14807 | } else if (child_type->id == TypeTableEntryIdFloat) { | 14978 | } else if (child_type->id == ZigTypeIdFloat) { |
| 14808 | if (buf_eql_str(field_name, "bit_count")) { | 14979 | if (buf_eql_str(field_name, "bit_count")) { |
| 14809 | bool ptr_is_const = true; | 14980 | bool ptr_is_const = true; |
| 14810 | bool ptr_is_volatile = false; | 14981 | bool ptr_is_volatile = false; |
| ... | @@ -14819,7 +14990,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14819,7 +14990,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14819 | buf_ptr(&child_type->name), buf_ptr(field_name))); | 14990 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 14820 | return ira->codegen->builtin_types.entry_invalid; | 14991 | return ira->codegen->builtin_types.entry_invalid; |
| 14821 | } | 14992 | } |
| 14822 | } else if (child_type->id == TypeTableEntryIdPointer) { | 14993 | } else if (child_type->id == ZigTypeIdPointer) { |
| 14823 | if (buf_eql_str(field_name, "Child")) { | 14994 | if (buf_eql_str(field_name, "Child")) { |
| 14824 | bool ptr_is_const = true; | 14995 | bool ptr_is_const = true; |
| 14825 | bool ptr_is_volatile = false; | 14996 | bool ptr_is_volatile = false; |
| ... | @@ -14841,7 +15012,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14841,7 +15012,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14841 | buf_ptr(&child_type->name), buf_ptr(field_name))); | 15012 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 14842 | return ira->codegen->builtin_types.entry_invalid; | 15013 | return ira->codegen->builtin_types.entry_invalid; |
| 14843 | } | 15014 | } |
| 14844 | } else if (child_type->id == TypeTableEntryIdArray) { | 15015 | } else if (child_type->id == ZigTypeIdArray) { |
| 14845 | if (buf_eql_str(field_name, "Child")) { | 15016 | if (buf_eql_str(field_name, "Child")) { |
| 14846 | bool ptr_is_const = true; | 15017 | bool ptr_is_const = true; |
| 14847 | bool ptr_is_volatile = false; | 15018 | bool ptr_is_volatile = false; |
| ... | @@ -14863,7 +15034,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14863,7 +15034,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14863 | buf_ptr(&child_type->name), buf_ptr(field_name))); | 15034 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 14864 | return ira->codegen->builtin_types.entry_invalid; | 15035 | return ira->codegen->builtin_types.entry_invalid; |
| 14865 | } | 15036 | } |
| 14866 | } else if (child_type->id == TypeTableEntryIdErrorUnion) { | 15037 | } else if (child_type->id == ZigTypeIdErrorUnion) { |
| 14867 | if (buf_eql_str(field_name, "Payload")) { | 15038 | if (buf_eql_str(field_name, "Payload")) { |
| 14868 | bool ptr_is_const = true; | 15039 | bool ptr_is_const = true; |
| 14869 | bool ptr_is_volatile = false; | 15040 | bool ptr_is_volatile = false; |
| ... | @@ -14884,7 +15055,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14884,7 +15055,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14884 | buf_ptr(&child_type->name), buf_ptr(field_name))); | 15055 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 14885 | return ira->codegen->builtin_types.entry_invalid; | 15056 | return ira->codegen->builtin_types.entry_invalid; |
| 14886 | } | 15057 | } |
| 14887 | } else if (child_type->id == TypeTableEntryIdOptional) { | 15058 | } else if (child_type->id == ZigTypeIdOptional) { |
| 14888 | if (buf_eql_str(field_name, "Child")) { | 15059 | if (buf_eql_str(field_name, "Child")) { |
| 14889 | bool ptr_is_const = true; | 15060 | bool ptr_is_const = true; |
| 14890 | bool ptr_is_volatile = false; | 15061 | bool ptr_is_volatile = false; |
| ... | @@ -14898,7 +15069,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14898,7 +15069,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14898 | buf_ptr(&child_type->name), buf_ptr(field_name))); | 15069 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 14899 | return ira->codegen->builtin_types.entry_invalid; | 15070 | return ira->codegen->builtin_types.entry_invalid; |
| 14900 | } | 15071 | } |
| 14901 | } else if (child_type->id == TypeTableEntryIdFn) { | 15072 | } else if (child_type->id == ZigTypeIdFn) { |
| 14902 | if (buf_eql_str(field_name, "ReturnType")) { | 15073 | if (buf_eql_str(field_name, "ReturnType")) { |
| 14903 | if (child_type->data.fn.fn_type_id.return_type == nullptr) { | 15074 | if (child_type->data.fn.fn_type_id.return_type == nullptr) { |
| 14904 | // Return type can only ever be null, if the function is generic | 15075 | // Return type can only ever be null, if the function is generic |
| ... | @@ -14940,13 +15111,16 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14940,13 +15111,16 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14940 | buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name))); | 15111 | buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name))); |
| 14941 | return ira->codegen->builtin_types.entry_invalid; | 15112 | return ira->codegen->builtin_types.entry_invalid; |
| 14942 | } | 15113 | } |
| 14943 | } else if (container_type->id == TypeTableEntryIdNamespace) { | 15114 | } else if (container_type->id == ZigTypeIdNamespace) { |
| 14944 | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); | 15115 | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 14945 | ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); | 15116 | ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 14946 | if (!container_ptr_val) | 15117 | if (!container_ptr_val) |
| 14947 | return ira->codegen->builtin_types.entry_invalid; | 15118 | return ira->codegen->builtin_types.entry_invalid; |
| 14948 | | 15119 | |
| 14949 | ConstExprValue *namespace_val = const_ptr_pointee(ira->codegen, container_ptr_val); | 15120 | ConstExprValue *namespace_val = ir_const_ptr_pointee(ira, container_ptr_val, |
| | 15121 | field_ptr_instruction->base.source_node); |
| | 15122 | if (namespace_val == nullptr) |
| | 15123 | return ira->codegen->builtin_types.entry_invalid; |
| 14950 | assert(namespace_val->special == ConstValSpecialStatic); | 15124 | assert(namespace_val->special == ConstValSpecialStatic); |
| 14951 | | 15125 | |
| 14952 | ImportTableEntry *namespace_import = namespace_val->data.x_import; | 15126 | ImportTableEntry *namespace_import = namespace_val->data.x_import; |
| ... | @@ -14975,7 +15149,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14975,7 +15149,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14975 | } | 15149 | } |
| 14976 | } | 15150 | } |
| 14977 | | 15151 | |
| 14978 | static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *load_ptr_instruction) { | 15152 | static ZigType *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *load_ptr_instruction) { |
| 14979 | IrInstruction *ptr = load_ptr_instruction->ptr->other; | 15153 | IrInstruction *ptr = load_ptr_instruction->ptr->other; |
| 14980 | if (type_is_invalid(ptr->value.type)) | 15154 | if (type_is_invalid(ptr->value.type)) |
| 14981 | return ira->codegen->builtin_types.entry_invalid; | 15155 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -14986,7 +15160,7 @@ static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstruc | ... | @@ -14986,7 +15160,7 @@ static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstruc |
| 14986 | return result->value.type; | 15160 | return result->value.type; |
| 14987 | } | 15161 | } |
| 14988 | | 15162 | |
| 14989 | static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *store_ptr_instruction) { | 15163 | static ZigType *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *store_ptr_instruction) { |
| 14990 | IrInstruction *ptr = store_ptr_instruction->ptr->other; | 15164 | IrInstruction *ptr = store_ptr_instruction->ptr->other; |
| 14991 | if (type_is_invalid(ptr->value.type)) | 15165 | if (type_is_invalid(ptr->value.type)) |
| 14992 | return ptr->value.type; | 15166 | return ptr->value.type; |
| ... | @@ -14995,7 +15169,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru | ... | @@ -14995,7 +15169,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 14995 | if (type_is_invalid(value->value.type)) | 15169 | if (type_is_invalid(value->value.type)) |
| 14996 | return value->value.type; | 15170 | return value->value.type; |
| 14997 | | 15171 | |
| 14998 | if (ptr->value.type->id != TypeTableEntryIdPointer) { | 15172 | if (ptr->value.type->id != ZigTypeIdPointer) { |
| 14999 | ir_add_error(ira, ptr, | 15173 | ir_add_error(ira, ptr, |
| 15000 | buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr->value.type->name))); | 15174 | buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr->value.type->name))); |
| 15001 | return ira->codegen->builtin_types.entry_invalid; | 15175 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -15010,7 +15184,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru | ... | @@ -15010,7 +15184,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 15010 | return ira->codegen->builtin_types.entry_invalid; | 15184 | return ira->codegen->builtin_types.entry_invalid; |
| 15011 | } | 15185 | } |
| 15012 | | 15186 | |
| 15013 | TypeTableEntry *child_type = ptr->value.type->data.pointer.child_type; | 15187 | ZigType *child_type = ptr->value.type->data.pointer.child_type; |
| 15014 | IrInstruction *casted_value = ir_implicit_cast(ira, value, child_type); | 15188 | IrInstruction *casted_value = ir_implicit_cast(ira, value, child_type); |
| 15015 | if (casted_value == ira->codegen->invalid_instruction) | 15189 | if (casted_value == ira->codegen->invalid_instruction) |
| 15016 | return ira->codegen->builtin_types.entry_invalid; | 15190 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -15022,7 +15196,9 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru | ... | @@ -15022,7 +15196,9 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 15022 | } | 15196 | } |
| 15023 | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) { | 15197 | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) { |
| 15024 | if (instr_is_comptime(casted_value)) { | 15198 | if (instr_is_comptime(casted_value)) { |
| 15025 | ConstExprValue *dest_val = const_ptr_pointee(ira->codegen, &ptr->value); | 15199 | ConstExprValue *dest_val = ir_const_ptr_pointee(ira, &ptr->value, store_ptr_instruction->base.source_node); |
| | 15200 | if (dest_val == nullptr) |
| | 15201 | return ira->codegen->builtin_types.entry_invalid; |
| 15026 | if (dest_val->special != ConstValSpecialRuntime) { | 15202 | if (dest_val->special != ConstValSpecialRuntime) { |
| 15027 | *dest_val = casted_value->value; | 15203 | *dest_val = casted_value->value; |
| 15028 | if (!ira->new_irb.current_basic_block->must_be_comptime_source_instr) { | 15204 | if (!ira->new_irb.current_basic_block->must_be_comptime_source_instr) { |
| ... | @@ -15033,7 +15209,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru | ... | @@ -15033,7 +15209,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 15033 | } | 15209 | } |
| 15034 | ir_add_error(ira, &store_ptr_instruction->base, | 15210 | ir_add_error(ira, &store_ptr_instruction->base, |
| 15035 | buf_sprintf("cannot store runtime value in compile time variable")); | 15211 | buf_sprintf("cannot store runtime value in compile time variable")); |
| 15036 | ConstExprValue *dest_val = const_ptr_pointee(ira->codegen, &ptr->value); | 15212 | ConstExprValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, &ptr->value); |
| 15037 | dest_val->type = ira->codegen->builtin_types.entry_invalid; | 15213 | dest_val->type = ira->codegen->builtin_types.entry_invalid; |
| 15038 | | 15214 | |
| 15039 | return ira->codegen->builtin_types.entry_invalid; | 15215 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -15044,39 +15220,39 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru | ... | @@ -15044,39 +15220,39 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 15044 | return ira->codegen->builtin_types.entry_void; | 15220 | return ira->codegen->builtin_types.entry_void; |
| 15045 | } | 15221 | } |
| 15046 | | 15222 | |
| 15047 | static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) { | 15223 | static ZigType *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) { |
| 15048 | IrInstruction *expr_value = typeof_instruction->value->other; | 15224 | IrInstruction *expr_value = typeof_instruction->value->other; |
| 15049 | TypeTableEntry *type_entry = expr_value->value.type; | 15225 | ZigType *type_entry = expr_value->value.type; |
| 15050 | if (type_is_invalid(type_entry)) | 15226 | if (type_is_invalid(type_entry)) |
| 15051 | return ira->codegen->builtin_types.entry_invalid; | 15227 | return ira->codegen->builtin_types.entry_invalid; |
| 15052 | switch (type_entry->id) { | 15228 | switch (type_entry->id) { |
| 15053 | case TypeTableEntryIdInvalid: | 15229 | case ZigTypeIdInvalid: |
| 15054 | zig_unreachable(); // handled above | 15230 | zig_unreachable(); // handled above |
| 15055 | case TypeTableEntryIdComptimeFloat: | 15231 | case ZigTypeIdComptimeFloat: |
| 15056 | case TypeTableEntryIdComptimeInt: | 15232 | case ZigTypeIdComptimeInt: |
| 15057 | case TypeTableEntryIdUndefined: | 15233 | case ZigTypeIdUndefined: |
| 15058 | case TypeTableEntryIdNull: | 15234 | case ZigTypeIdNull: |
| 15059 | case TypeTableEntryIdNamespace: | 15235 | case ZigTypeIdNamespace: |
| 15060 | case TypeTableEntryIdBlock: | 15236 | case ZigTypeIdBlock: |
| 15061 | case TypeTableEntryIdBoundFn: | 15237 | case ZigTypeIdBoundFn: |
| 15062 | case TypeTableEntryIdMetaType: | 15238 | case ZigTypeIdMetaType: |
| 15063 | case TypeTableEntryIdVoid: | 15239 | case ZigTypeIdVoid: |
| 15064 | case TypeTableEntryIdBool: | 15240 | case ZigTypeIdBool: |
| 15065 | case TypeTableEntryIdUnreachable: | 15241 | case ZigTypeIdUnreachable: |
| 15066 | case TypeTableEntryIdInt: | 15242 | case ZigTypeIdInt: |
| 15067 | case TypeTableEntryIdFloat: | 15243 | case ZigTypeIdFloat: |
| 15068 | case TypeTableEntryIdPointer: | 15244 | case ZigTypeIdPointer: |
| 15069 | case TypeTableEntryIdArray: | 15245 | case ZigTypeIdArray: |
| 15070 | case TypeTableEntryIdStruct: | 15246 | case ZigTypeIdStruct: |
| 15071 | case TypeTableEntryIdOptional: | 15247 | case ZigTypeIdOptional: |
| 15072 | case TypeTableEntryIdErrorUnion: | 15248 | case ZigTypeIdErrorUnion: |
| 15073 | case TypeTableEntryIdErrorSet: | 15249 | case ZigTypeIdErrorSet: |
| 15074 | case TypeTableEntryIdEnum: | 15250 | case ZigTypeIdEnum: |
| 15075 | case TypeTableEntryIdUnion: | 15251 | case ZigTypeIdUnion: |
| 15076 | case TypeTableEntryIdFn: | 15252 | case ZigTypeIdFn: |
| 15077 | case TypeTableEntryIdArgTuple: | 15253 | case ZigTypeIdArgTuple: |
| 15078 | case TypeTableEntryIdOpaque: | 15254 | case ZigTypeIdOpaque: |
| 15079 | case TypeTableEntryIdPromise: | 15255 | case ZigTypeIdPromise: |
| 15080 | { | 15256 | { |
| 15081 | ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base); | 15257 | ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base); |
| 15082 | out_val->data.x_type = type_entry; | 15258 | out_val->data.x_type = type_entry; |
| ... | @@ -15088,20 +15264,20 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi | ... | @@ -15088,20 +15264,20 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi |
| 15088 | zig_unreachable(); | 15264 | zig_unreachable(); |
| 15089 | } | 15265 | } |
| 15090 | | 15266 | |
| 15091 | static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, | 15267 | static ZigType *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, |
| 15092 | IrInstructionToPtrType *to_ptr_type_instruction) | 15268 | IrInstructionToPtrType *to_ptr_type_instruction) |
| 15093 | { | 15269 | { |
| 15094 | IrInstruction *value = to_ptr_type_instruction->value->other; | 15270 | IrInstruction *value = to_ptr_type_instruction->value->other; |
| 15095 | TypeTableEntry *type_entry = value->value.type; | 15271 | ZigType *type_entry = value->value.type; |
| 15096 | if (type_is_invalid(type_entry)) | 15272 | if (type_is_invalid(type_entry)) |
| 15097 | return type_entry; | 15273 | return type_entry; |
| 15098 | | 15274 | |
| 15099 | TypeTableEntry *ptr_type; | 15275 | ZigType *ptr_type; |
| 15100 | if (type_entry->id == TypeTableEntryIdArray) { | 15276 | if (type_entry->id == ZigTypeIdArray) { |
| 15101 | ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false); | 15277 | ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false); |
| 15102 | } else if (is_slice(type_entry)) { | 15278 | } else if (is_slice(type_entry)) { |
| 15103 | ptr_type = adjust_ptr_len(ira->codegen, type_entry->data.structure.fields[0].type_entry, PtrLenSingle); | 15279 | ptr_type = adjust_ptr_len(ira->codegen, type_entry->data.structure.fields[0].type_entry, PtrLenSingle); |
| 15104 | } else if (type_entry->id == TypeTableEntryIdArgTuple) { | 15280 | } else if (type_entry->id == ZigTypeIdArgTuple) { |
| 15105 | ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad); | 15281 | ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad); |
| 15106 | if (!arg_tuple_val) | 15282 | if (!arg_tuple_val) |
| 15107 | return ira->codegen->builtin_types.entry_invalid; | 15283 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -15117,15 +15293,15 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, | ... | @@ -15117,15 +15293,15 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, |
| 15117 | return ira->codegen->builtin_types.entry_type; | 15293 | return ira->codegen->builtin_types.entry_type; |
| 15118 | } | 15294 | } |
| 15119 | | 15295 | |
| 15120 | static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira, | 15296 | static ZigType *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira, |
| 15121 | IrInstructionPtrTypeChild *ptr_type_child_instruction) | 15297 | IrInstructionPtrTypeChild *ptr_type_child_instruction) |
| 15122 | { | 15298 | { |
| 15123 | IrInstruction *type_value = ptr_type_child_instruction->value->other; | 15299 | IrInstruction *type_value = ptr_type_child_instruction->value->other; |
| 15124 | TypeTableEntry *type_entry = ir_resolve_type(ira, type_value); | 15300 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 15125 | if (type_is_invalid(type_entry)) | 15301 | if (type_is_invalid(type_entry)) |
| 15126 | return type_entry; | 15302 | return type_entry; |
| 15127 | | 15303 | |
| 15128 | if (type_entry->id != TypeTableEntryIdPointer) { | 15304 | if (type_entry->id != ZigTypeIdPointer) { |
| 15129 | ir_add_error_node(ira, ptr_type_child_instruction->base.source_node, | 15305 | ir_add_error_node(ira, ptr_type_child_instruction->base.source_node, |
| 15130 | buf_sprintf("expected pointer type, found '%s'", buf_ptr(&type_entry->name))); | 15306 | buf_sprintf("expected pointer type, found '%s'", buf_ptr(&type_entry->name))); |
| 15131 | return ira->codegen->builtin_types.entry_invalid; | 15307 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -15136,7 +15312,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira, | ... | @@ -15136,7 +15312,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira, |
| 15136 | return ira->codegen->builtin_types.entry_type; | 15312 | return ira->codegen->builtin_types.entry_type; |
| 15137 | } | 15313 | } |
| 15138 | | 15314 | |
| 15139 | static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) { | 15315 | static ZigType *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) { |
| 15140 | if (ira->new_irb.exec->is_inline) { | 15316 | if (ira->new_irb.exec->is_inline) { |
| 15141 | // ignore setCold when running functions at compile time | 15317 | // ignore setCold when running functions at compile time |
| 15142 | ir_build_const_from(ira, &instruction->base); | 15318 | ir_build_const_from(ira, &instruction->base); |
| ... | @@ -15148,7 +15324,7 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc | ... | @@ -15148,7 +15324,7 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc |
| 15148 | if (!ir_resolve_bool(ira, is_cold_value, &want_cold)) | 15324 | if (!ir_resolve_bool(ira, is_cold_value, &want_cold)) |
| 15149 | return ira->codegen->builtin_types.entry_invalid; | 15325 | return ira->codegen->builtin_types.entry_invalid; |
| 15150 | | 15326 | |
| 15151 | FnTableEntry *fn_entry = scope_fn_entry(instruction->base.scope); | 15327 | ZigFn *fn_entry = scope_fn_entry(instruction->base.scope); |
| 15152 | if (fn_entry == nullptr) { | 15328 | if (fn_entry == nullptr) { |
| 15153 | ir_add_error(ira, &instruction->base, buf_sprintf("@setCold outside function")); | 15329 | ir_add_error(ira, &instruction->base, buf_sprintf("@setCold outside function")); |
| 15154 | return ira->codegen->builtin_types.entry_invalid; | 15330 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -15166,7 +15342,7 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc | ... | @@ -15166,7 +15342,7 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc |
| 15166 | ir_build_const_from(ira, &instruction->base); | 15342 | ir_build_const_from(ira, &instruction->base); |
| 15167 | return ira->codegen->builtin_types.entry_void; | 15343 | return ira->codegen->builtin_types.entry_void; |
| 15168 | } | 15344 | } |
| 15169 | static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, | 15345 | static ZigType *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 15170 | IrInstructionSetRuntimeSafety *set_runtime_safety_instruction) | 15346 | IrInstructionSetRuntimeSafety *set_runtime_safety_instruction) |
| 15171 | { | 15347 | { |
| 15172 | if (ira->new_irb.exec->is_inline) { | 15348 | if (ira->new_irb.exec->is_inline) { |
| ... | @@ -15187,7 +15363,7 @@ static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, | ... | @@ -15187,7 +15363,7 @@ static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 15187 | break; | 15363 | break; |
| 15188 | } else if (scope->id == ScopeIdFnDef) { | 15364 | } else if (scope->id == ScopeIdFnDef) { |
| 15189 | ScopeFnDef *def_scope = (ScopeFnDef *)scope; | 15365 | ScopeFnDef *def_scope = (ScopeFnDef *)scope; |
| 15190 | FnTableEntry *target_fn = def_scope->fn_entry; | 15366 | ZigFn *target_fn = def_scope->fn_entry; |
| 15191 | assert(target_fn->def_scope != nullptr); | 15367 | assert(target_fn->def_scope != nullptr); |
| 15192 | safety_off_ptr = &target_fn->def_scope->safety_off; | 15368 | safety_off_ptr = &target_fn->def_scope->safety_off; |
| 15193 | safety_set_node_ptr = &target_fn->def_scope->safety_set_node; | 15369 | safety_set_node_ptr = &target_fn->def_scope->safety_set_node; |
| ... | @@ -15223,11 +15399,11 @@ static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, | ... | @@ -15223,11 +15399,11 @@ static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 15223 | return ira->codegen->builtin_types.entry_void; | 15399 | return ira->codegen->builtin_types.entry_void; |
| 15224 | } | 15400 | } |
| 15225 | | 15401 | |
| 15226 | static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, | 15402 | static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 15227 | IrInstructionSetFloatMode *instruction) | 15403 | IrInstructionSetFloatMode *instruction) |
| 15228 | { | 15404 | { |
| 15229 | IrInstruction *target_instruction = instruction->scope_value->other; | 15405 | IrInstruction *target_instruction = instruction->scope_value->other; |
| 15230 | TypeTableEntry *target_type = target_instruction->value.type; | 15406 | ZigType *target_type = target_instruction->value.type; |
| 15231 | if (type_is_invalid(target_type)) | 15407 | if (type_is_invalid(target_type)) |
| 15232 | return ira->codegen->builtin_types.entry_invalid; | 15408 | return ira->codegen->builtin_types.entry_invalid; |
| 15233 | ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad); | 15409 | ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad); |
| ... | @@ -15242,24 +15418,24 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, | ... | @@ -15242,24 +15418,24 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 15242 | | 15418 | |
| 15243 | bool *fast_math_on_ptr; | 15419 | bool *fast_math_on_ptr; |
| 15244 | AstNode **fast_math_set_node_ptr; | 15420 | AstNode **fast_math_set_node_ptr; |
| 15245 | if (target_type->id == TypeTableEntryIdBlock) { | 15421 | if (target_type->id == ZigTypeIdBlock) { |
| 15246 | ScopeBlock *block_scope = (ScopeBlock *)target_val->data.x_block; | 15422 | ScopeBlock *block_scope = (ScopeBlock *)target_val->data.x_block; |
| 15247 | fast_math_on_ptr = &block_scope->fast_math_on; | 15423 | fast_math_on_ptr = &block_scope->fast_math_on; |
| 15248 | fast_math_set_node_ptr = &block_scope->fast_math_set_node; | 15424 | fast_math_set_node_ptr = &block_scope->fast_math_set_node; |
| 15249 | } else if (target_type->id == TypeTableEntryIdFn) { | 15425 | } else if (target_type->id == ZigTypeIdFn) { |
| 15250 | assert(target_val->data.x_ptr.special == ConstPtrSpecialFunction); | 15426 | assert(target_val->data.x_ptr.special == ConstPtrSpecialFunction); |
| 15251 | FnTableEntry *target_fn = target_val->data.x_ptr.data.fn.fn_entry; | 15427 | ZigFn *target_fn = target_val->data.x_ptr.data.fn.fn_entry; |
| 15252 | assert(target_fn->def_scope); | 15428 | assert(target_fn->def_scope); |
| 15253 | fast_math_on_ptr = &target_fn->def_scope->fast_math_on; | 15429 | fast_math_on_ptr = &target_fn->def_scope->fast_math_on; |
| 15254 | fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node; | 15430 | fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node; |
| 15255 | } else if (target_type->id == TypeTableEntryIdMetaType) { | 15431 | } else if (target_type->id == ZigTypeIdMetaType) { |
| 15256 | ScopeDecls *decls_scope; | 15432 | ScopeDecls *decls_scope; |
| 15257 | TypeTableEntry *type_arg = target_val->data.x_type; | 15433 | ZigType *type_arg = target_val->data.x_type; |
| 15258 | if (type_arg->id == TypeTableEntryIdStruct) { | 15434 | if (type_arg->id == ZigTypeIdStruct) { |
| 15259 | decls_scope = type_arg->data.structure.decls_scope; | 15435 | decls_scope = type_arg->data.structure.decls_scope; |
| 15260 | } else if (type_arg->id == TypeTableEntryIdEnum) { | 15436 | } else if (type_arg->id == ZigTypeIdEnum) { |
| 15261 | decls_scope = type_arg->data.enumeration.decls_scope; | 15437 | decls_scope = type_arg->data.enumeration.decls_scope; |
| 15262 | } else if (type_arg->id == TypeTableEntryIdUnion) { | 15438 | } else if (type_arg->id == ZigTypeIdUnion) { |
| 15263 | decls_scope = type_arg->data.unionation.decls_scope; | 15439 | decls_scope = type_arg->data.unionation.decls_scope; |
| 15264 | } else { | 15440 | } else { |
| 15265 | ir_add_error_node(ira, target_instruction->source_node, | 15441 | ir_add_error_node(ira, target_instruction->source_node, |
| ... | @@ -15294,7 +15470,7 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, | ... | @@ -15294,7 +15470,7 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 15294 | return ira->codegen->builtin_types.entry_void; | 15470 | return ira->codegen->builtin_types.entry_void; |
| 15295 | } | 15471 | } |
| 15296 | | 15472 | |
| 15297 | static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, | 15473 | static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15298 | IrInstructionSliceType *slice_type_instruction) | 15474 | IrInstructionSliceType *slice_type_instruction) |
| 15299 | { | 15475 | { |
| 15300 | Error err; | 15476 | Error err; |
| ... | @@ -15304,7 +15480,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, | ... | @@ -15304,7 +15480,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15304 | return ira->codegen->builtin_types.entry_invalid; | 15480 | return ira->codegen->builtin_types.entry_invalid; |
| 15305 | } | 15481 | } |
| 15306 | | 15482 | |
| 15307 | TypeTableEntry *child_type = ir_resolve_type(ira, slice_type_instruction->child_type->other); | 15483 | ZigType *child_type = ir_resolve_type(ira, slice_type_instruction->child_type->other); |
| 15308 | if (type_is_invalid(child_type)) | 15484 | if (type_is_invalid(child_type)) |
| 15309 | return ira->codegen->builtin_types.entry_invalid; | 15485 | return ira->codegen->builtin_types.entry_invalid; |
| 15310 | | 15486 | |
| ... | @@ -15318,42 +15494,42 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, | ... | @@ -15318,42 +15494,42 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15318 | bool is_volatile = slice_type_instruction->is_volatile; | 15494 | bool is_volatile = slice_type_instruction->is_volatile; |
| 15319 | | 15495 | |
| 15320 | switch (child_type->id) { | 15496 | switch (child_type->id) { |
| 15321 | case TypeTableEntryIdInvalid: // handled above | 15497 | case ZigTypeIdInvalid: // handled above |
| 15322 | zig_unreachable(); | 15498 | zig_unreachable(); |
| 15323 | case TypeTableEntryIdUnreachable: | 15499 | case ZigTypeIdUnreachable: |
| 15324 | case TypeTableEntryIdUndefined: | 15500 | case ZigTypeIdUndefined: |
| 15325 | case TypeTableEntryIdNull: | 15501 | case ZigTypeIdNull: |
| 15326 | case TypeTableEntryIdBlock: | 15502 | case ZigTypeIdBlock: |
| 15327 | case TypeTableEntryIdArgTuple: | 15503 | case ZigTypeIdArgTuple: |
| 15328 | case TypeTableEntryIdOpaque: | 15504 | case ZigTypeIdOpaque: |
| 15329 | ir_add_error_node(ira, slice_type_instruction->base.source_node, | 15505 | ir_add_error_node(ira, slice_type_instruction->base.source_node, |
| 15330 | buf_sprintf("slice of type '%s' not allowed", buf_ptr(&child_type->name))); | 15506 | buf_sprintf("slice of type '%s' not allowed", buf_ptr(&child_type->name))); |
| 15331 | return ira->codegen->builtin_types.entry_invalid; | 15507 | return ira->codegen->builtin_types.entry_invalid; |
| 15332 | case TypeTableEntryIdMetaType: | 15508 | case ZigTypeIdMetaType: |
| 15333 | case TypeTableEntryIdVoid: | 15509 | case ZigTypeIdVoid: |
| 15334 | case TypeTableEntryIdBool: | 15510 | case ZigTypeIdBool: |
| 15335 | case TypeTableEntryIdInt: | 15511 | case ZigTypeIdInt: |
| 15336 | case TypeTableEntryIdFloat: | 15512 | case ZigTypeIdFloat: |
| 15337 | case TypeTableEntryIdPointer: | 15513 | case ZigTypeIdPointer: |
| 15338 | case TypeTableEntryIdArray: | 15514 | case ZigTypeIdArray: |
| 15339 | case TypeTableEntryIdStruct: | 15515 | case ZigTypeIdStruct: |
| 15340 | case TypeTableEntryIdComptimeFloat: | 15516 | case ZigTypeIdComptimeFloat: |
| 15341 | case TypeTableEntryIdComptimeInt: | 15517 | case ZigTypeIdComptimeInt: |
| 15342 | case TypeTableEntryIdOptional: | 15518 | case ZigTypeIdOptional: |
| 15343 | case TypeTableEntryIdErrorUnion: | 15519 | case ZigTypeIdErrorUnion: |
| 15344 | case TypeTableEntryIdErrorSet: | 15520 | case ZigTypeIdErrorSet: |
| 15345 | case TypeTableEntryIdEnum: | 15521 | case ZigTypeIdEnum: |
| 15346 | case TypeTableEntryIdUnion: | 15522 | case ZigTypeIdUnion: |
| 15347 | case TypeTableEntryIdFn: | 15523 | case ZigTypeIdFn: |
| 15348 | case TypeTableEntryIdNamespace: | 15524 | case ZigTypeIdNamespace: |
| 15349 | case TypeTableEntryIdBoundFn: | 15525 | case ZigTypeIdBoundFn: |
| 15350 | case TypeTableEntryIdPromise: | 15526 | case ZigTypeIdPromise: |
| 15351 | { | 15527 | { |
| 15352 | if ((err = type_ensure_zero_bits_known(ira->codegen, child_type))) | 15528 | if ((err = type_ensure_zero_bits_known(ira->codegen, child_type))) |
| 15353 | return ira->codegen->builtin_types.entry_invalid; | 15529 | return ira->codegen->builtin_types.entry_invalid; |
| 15354 | TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, | 15530 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 15355 | is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0); | 15531 | is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0); |
| 15356 | TypeTableEntry *result_type = get_slice_type(ira->codegen, slice_ptr_type); | 15532 | ZigType *result_type = get_slice_type(ira->codegen, slice_ptr_type); |
| 15357 | ConstExprValue *out_val = ir_build_const_from(ira, &slice_type_instruction->base); | 15533 | ConstExprValue *out_val = ir_build_const_from(ira, &slice_type_instruction->base); |
| 15358 | out_val->data.x_type = result_type; | 15534 | out_val->data.x_type = result_type; |
| 15359 | return ira->codegen->builtin_types.entry_type; | 15535 | return ira->codegen->builtin_types.entry_type; |
| ... | @@ -15362,7 +15538,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, | ... | @@ -15362,7 +15538,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15362 | zig_unreachable(); | 15538 | zig_unreachable(); |
| 15363 | } | 15539 | } |
| 15364 | | 15540 | |
| 15365 | static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsm *asm_instruction) { | 15541 | static ZigType *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsm *asm_instruction) { |
| 15366 | assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr); | 15542 | assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr); |
| 15367 | | 15543 | |
| 15368 | AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr; | 15544 | AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr; |
| ... | @@ -15392,7 +15568,7 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA | ... | @@ -15392,7 +15568,7 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA |
| 15392 | IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length); | 15568 | IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length); |
| 15393 | IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length); | 15569 | IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length); |
| 15394 | | 15570 | |
| 15395 | TypeTableEntry *return_type = ira->codegen->builtin_types.entry_void; | 15571 | ZigType *return_type = ira->codegen->builtin_types.entry_void; |
| 15396 | for (size_t i = 0; i < asm_expr->output_list.length; i += 1) { | 15572 | for (size_t i = 0; i < asm_expr->output_list.length; i += 1) { |
| 15397 | AsmOutput *asm_output = asm_expr->output_list.at(i); | 15573 | AsmOutput *asm_output = asm_expr->output_list.at(i); |
| 15398 | if (asm_output->return_type) { | 15574 | if (asm_output->return_type) { |
| ... | @@ -15414,51 +15590,55 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA | ... | @@ -15414,51 +15590,55 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA |
| 15414 | return return_type; | 15590 | return return_type; |
| 15415 | } | 15591 | } |
| 15416 | | 15592 | |
| 15417 | static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, | 15593 | static ZigType *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 15418 | IrInstructionArrayType *array_type_instruction) | 15594 | IrInstructionArrayType *array_type_instruction) |
| 15419 | { | 15595 | { |
| | 15596 | Error err; |
| | 15597 | |
| 15420 | IrInstruction *size_value = array_type_instruction->size->other; | 15598 | IrInstruction *size_value = array_type_instruction->size->other; |
| 15421 | uint64_t size; | 15599 | uint64_t size; |
| 15422 | if (!ir_resolve_usize(ira, size_value, &size)) | 15600 | if (!ir_resolve_usize(ira, size_value, &size)) |
| 15423 | return ira->codegen->builtin_types.entry_invalid; | 15601 | return ira->codegen->builtin_types.entry_invalid; |
| 15424 | | 15602 | |
| 15425 | IrInstruction *child_type_value = array_type_instruction->child_type->other; | 15603 | IrInstruction *child_type_value = array_type_instruction->child_type->other; |
| 15426 | TypeTableEntry *child_type = ir_resolve_type(ira, child_type_value); | 15604 | ZigType *child_type = ir_resolve_type(ira, child_type_value); |
| 15427 | if (type_is_invalid(child_type)) | 15605 | if (type_is_invalid(child_type)) |
| 15428 | return ira->codegen->builtin_types.entry_invalid; | 15606 | return ira->codegen->builtin_types.entry_invalid; |
| 15429 | switch (child_type->id) { | 15607 | switch (child_type->id) { |
| 15430 | case TypeTableEntryIdInvalid: // handled above | 15608 | case ZigTypeIdInvalid: // handled above |
| 15431 | zig_unreachable(); | 15609 | zig_unreachable(); |
| 15432 | case TypeTableEntryIdUnreachable: | 15610 | case ZigTypeIdUnreachable: |
| 15433 | case TypeTableEntryIdUndefined: | 15611 | case ZigTypeIdUndefined: |
| 15434 | case TypeTableEntryIdNull: | 15612 | case ZigTypeIdNull: |
| 15435 | case TypeTableEntryIdBlock: | 15613 | case ZigTypeIdBlock: |
| 15436 | case TypeTableEntryIdArgTuple: | 15614 | case ZigTypeIdArgTuple: |
| 15437 | case TypeTableEntryIdOpaque: | 15615 | case ZigTypeIdOpaque: |
| 15438 | ir_add_error_node(ira, array_type_instruction->base.source_node, | 15616 | ir_add_error_node(ira, array_type_instruction->base.source_node, |
| 15439 | buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name))); | 15617 | buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name))); |
| 15440 | return ira->codegen->builtin_types.entry_invalid; | 15618 | return ira->codegen->builtin_types.entry_invalid; |
| 15441 | case TypeTableEntryIdMetaType: | 15619 | case ZigTypeIdMetaType: |
| 15442 | case TypeTableEntryIdVoid: | 15620 | case ZigTypeIdVoid: |
| 15443 | case TypeTableEntryIdBool: | 15621 | case ZigTypeIdBool: |
| 15444 | case TypeTableEntryIdInt: | 15622 | case ZigTypeIdInt: |
| 15445 | case TypeTableEntryIdFloat: | 15623 | case ZigTypeIdFloat: |
| 15446 | case TypeTableEntryIdPointer: | 15624 | case ZigTypeIdPointer: |
| 15447 | case TypeTableEntryIdArray: | 15625 | case ZigTypeIdArray: |
| 15448 | case TypeTableEntryIdStruct: | 15626 | case ZigTypeIdStruct: |
| 15449 | case TypeTableEntryIdComptimeFloat: | 15627 | case ZigTypeIdComptimeFloat: |
| 15450 | case TypeTableEntryIdComptimeInt: | 15628 | case ZigTypeIdComptimeInt: |
| 15451 | case TypeTableEntryIdOptional: | 15629 | case ZigTypeIdOptional: |
| 15452 | case TypeTableEntryIdErrorUnion: | 15630 | case ZigTypeIdErrorUnion: |
| 15453 | case TypeTableEntryIdErrorSet: | 15631 | case ZigTypeIdErrorSet: |
| 15454 | case TypeTableEntryIdEnum: | 15632 | case ZigTypeIdEnum: |
| 15455 | case TypeTableEntryIdUnion: | 15633 | case ZigTypeIdUnion: |
| 15456 | case TypeTableEntryIdFn: | 15634 | case ZigTypeIdFn: |
| 15457 | case TypeTableEntryIdNamespace: | 15635 | case ZigTypeIdNamespace: |
| 15458 | case TypeTableEntryIdBoundFn: | 15636 | case ZigTypeIdBoundFn: |
| 15459 | case TypeTableEntryIdPromise: | 15637 | case ZigTypeIdPromise: |
| 15460 | { | 15638 | { |
| 15461 | TypeTableEntry *result_type = get_array_type(ira->codegen, child_type, size); | 15639 | if ((err = ensure_complete_type(ira->codegen, child_type))) |
| | 15640 | return ira->codegen->builtin_types.entry_invalid; |
| | 15641 | ZigType *result_type = get_array_type(ira->codegen, child_type, size); |
| 15462 | ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base); | 15642 | ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base); |
| 15463 | out_val->data.x_type = result_type; | 15643 | out_val->data.x_type = result_type; |
| 15464 | return ira->codegen->builtin_types.entry_type; | 15644 | return ira->codegen->builtin_types.entry_type; |
| ... | @@ -15467,13 +15647,13 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, | ... | @@ -15467,13 +15647,13 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 15467 | zig_unreachable(); | 15647 | zig_unreachable(); |
| 15468 | } | 15648 | } |
| 15469 | | 15649 | |
| 15470 | static TypeTableEntry *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInstructionPromiseType *instruction) { | 15650 | static ZigType *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInstructionPromiseType *instruction) { |
| 15471 | TypeTableEntry *promise_type; | 15651 | ZigType *promise_type; |
| 15472 | | 15652 | |
| 15473 | if (instruction->payload_type == nullptr) { | 15653 | if (instruction->payload_type == nullptr) { |
| 15474 | promise_type = ira->codegen->builtin_types.entry_promise; | 15654 | promise_type = ira->codegen->builtin_types.entry_promise; |
| 15475 | } else { | 15655 | } else { |
| 15476 | TypeTableEntry *payload_type = ir_resolve_type(ira, instruction->payload_type->other); | 15656 | ZigType *payload_type = ir_resolve_type(ira, instruction->payload_type->other); |
| 15477 | if (type_is_invalid(payload_type)) | 15657 | if (type_is_invalid(payload_type)) |
| 15478 | return ira->codegen->builtin_types.entry_invalid; | 15658 | return ira->codegen->builtin_types.entry_invalid; |
| 15479 | | 15659 | |
| ... | @@ -15485,47 +15665,47 @@ static TypeTableEntry *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrIns | ... | @@ -15485,47 +15665,47 @@ static TypeTableEntry *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrIns |
| 15485 | return ira->codegen->builtin_types.entry_type; | 15665 | return ira->codegen->builtin_types.entry_type; |
| 15486 | } | 15666 | } |
| 15487 | | 15667 | |
| 15488 | static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira, | 15668 | static ZigType *ir_analyze_instruction_size_of(IrAnalyze *ira, |
| 15489 | IrInstructionSizeOf *size_of_instruction) | 15669 | IrInstructionSizeOf *size_of_instruction) |
| 15490 | { | 15670 | { |
| 15491 | Error err; | 15671 | Error err; |
| 15492 | IrInstruction *type_value = size_of_instruction->type_value->other; | 15672 | IrInstruction *type_value = size_of_instruction->type_value->other; |
| 15493 | TypeTableEntry *type_entry = ir_resolve_type(ira, type_value); | 15673 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 15494 | | 15674 | |
| 15495 | if ((err = ensure_complete_type(ira->codegen, type_entry))) | 15675 | if ((err = ensure_complete_type(ira->codegen, type_entry))) |
| 15496 | return ira->codegen->builtin_types.entry_invalid; | 15676 | return ira->codegen->builtin_types.entry_invalid; |
| 15497 | | 15677 | |
| 15498 | switch (type_entry->id) { | 15678 | switch (type_entry->id) { |
| 15499 | case TypeTableEntryIdInvalid: // handled above | 15679 | case ZigTypeIdInvalid: // handled above |
| 15500 | zig_unreachable(); | 15680 | zig_unreachable(); |
| 15501 | case TypeTableEntryIdUnreachable: | 15681 | case ZigTypeIdUnreachable: |
| 15502 | case TypeTableEntryIdUndefined: | 15682 | case ZigTypeIdUndefined: |
| 15503 | case TypeTableEntryIdNull: | 15683 | case ZigTypeIdNull: |
| 15504 | case TypeTableEntryIdBlock: | 15684 | case ZigTypeIdBlock: |
| 15505 | case TypeTableEntryIdComptimeFloat: | 15685 | case ZigTypeIdComptimeFloat: |
| 15506 | case TypeTableEntryIdComptimeInt: | 15686 | case ZigTypeIdComptimeInt: |
| 15507 | case TypeTableEntryIdBoundFn: | 15687 | case ZigTypeIdBoundFn: |
| 15508 | case TypeTableEntryIdMetaType: | 15688 | case ZigTypeIdMetaType: |
| 15509 | case TypeTableEntryIdNamespace: | 15689 | case ZigTypeIdNamespace: |
| 15510 | case TypeTableEntryIdArgTuple: | 15690 | case ZigTypeIdArgTuple: |
| 15511 | case TypeTableEntryIdOpaque: | 15691 | case ZigTypeIdOpaque: |
| 15512 | ir_add_error_node(ira, size_of_instruction->base.source_node, | 15692 | ir_add_error_node(ira, size_of_instruction->base.source_node, |
| 15513 | buf_sprintf("no size available for type '%s'", buf_ptr(&type_entry->name))); | 15693 | buf_sprintf("no size available for type '%s'", buf_ptr(&type_entry->name))); |
| 15514 | return ira->codegen->builtin_types.entry_invalid; | 15694 | return ira->codegen->builtin_types.entry_invalid; |
| 15515 | case TypeTableEntryIdVoid: | 15695 | case ZigTypeIdVoid: |
| 15516 | case TypeTableEntryIdBool: | 15696 | case ZigTypeIdBool: |
| 15517 | case TypeTableEntryIdInt: | 15697 | case ZigTypeIdInt: |
| 15518 | case TypeTableEntryIdFloat: | 15698 | case ZigTypeIdFloat: |
| 15519 | case TypeTableEntryIdPointer: | 15699 | case ZigTypeIdPointer: |
| 15520 | case TypeTableEntryIdArray: | 15700 | case ZigTypeIdArray: |
| 15521 | case TypeTableEntryIdStruct: | 15701 | case ZigTypeIdStruct: |
| 15522 | case TypeTableEntryIdOptional: | 15702 | case ZigTypeIdOptional: |
| 15523 | case TypeTableEntryIdErrorUnion: | 15703 | case ZigTypeIdErrorUnion: |
| 15524 | case TypeTableEntryIdErrorSet: | 15704 | case ZigTypeIdErrorSet: |
| 15525 | case TypeTableEntryIdEnum: | 15705 | case ZigTypeIdEnum: |
| 15526 | case TypeTableEntryIdUnion: | 15706 | case ZigTypeIdUnion: |
| 15527 | case TypeTableEntryIdFn: | 15707 | case ZigTypeIdFn: |
| 15528 | case TypeTableEntryIdPromise: | 15708 | case ZigTypeIdPromise: |
| 15529 | { | 15709 | { |
| 15530 | uint64_t size_in_bytes = type_size(ira->codegen, type_entry); | 15710 | uint64_t size_in_bytes = type_size(ira->codegen, type_entry); |
| 15531 | ConstExprValue *out_val = ir_build_const_from(ira, &size_of_instruction->base); | 15711 | ConstExprValue *out_val = ir_build_const_from(ira, &size_of_instruction->base); |
| ... | @@ -15536,14 +15716,14 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira, | ... | @@ -15536,14 +15716,14 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira, |
| 15536 | zig_unreachable(); | 15716 | zig_unreachable(); |
| 15537 | } | 15717 | } |
| 15538 | | 15718 | |
| 15539 | static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) { | 15719 | static ZigType *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) { |
| 15540 | IrInstruction *value = instruction->value->other; | 15720 | IrInstruction *value = instruction->value->other; |
| 15541 | if (type_is_invalid(value->value.type)) | 15721 | if (type_is_invalid(value->value.type)) |
| 15542 | return ira->codegen->builtin_types.entry_invalid; | 15722 | return ira->codegen->builtin_types.entry_invalid; |
| 15543 | | 15723 | |
| 15544 | TypeTableEntry *type_entry = value->value.type; | 15724 | ZigType *type_entry = value->value.type; |
| 15545 | | 15725 | |
| 15546 | if (type_entry->id == TypeTableEntryIdOptional) { | 15726 | if (type_entry->id == ZigTypeIdOptional) { |
| 15547 | if (instr_is_comptime(value)) { | 15727 | if (instr_is_comptime(value)) { |
| 15548 | ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefBad); | 15728 | ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefBad); |
| 15549 | if (!maybe_val) | 15729 | if (!maybe_val) |
| ... | @@ -15556,7 +15736,7 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn | ... | @@ -15556,7 +15736,7 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn |
| 15556 | | 15736 | |
| 15557 | ir_build_test_nonnull_from(&ira->new_irb, &instruction->base, value); | 15737 | ir_build_test_nonnull_from(&ira->new_irb, &instruction->base, value); |
| 15558 | return ira->codegen->builtin_types.entry_bool; | 15738 | return ira->codegen->builtin_types.entry_bool; |
| 15559 | } else if (type_entry->id == TypeTableEntryIdNull) { | 15739 | } else if (type_entry->id == ZigTypeIdNull) { |
| 15560 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 15740 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 15561 | out_val->data.x_bool = false; | 15741 | out_val->data.x_bool = false; |
| 15562 | return ira->codegen->builtin_types.entry_bool; | 15742 | return ira->codegen->builtin_types.entry_bool; |
| ... | @@ -15567,26 +15747,26 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn | ... | @@ -15567,26 +15747,26 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn |
| 15567 | } | 15747 | } |
| 15568 | } | 15748 | } |
| 15569 | | 15749 | |
| 15570 | static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, | 15750 | static ZigType *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, |
| 15571 | IrInstructionUnwrapOptional *unwrap_maybe_instruction) | 15751 | IrInstructionUnwrapOptional *unwrap_maybe_instruction) |
| 15572 | { | 15752 | { |
| 15573 | IrInstruction *value = unwrap_maybe_instruction->value->other; | 15753 | IrInstruction *value = unwrap_maybe_instruction->value->other; |
| 15574 | if (type_is_invalid(value->value.type)) | 15754 | if (type_is_invalid(value->value.type)) |
| 15575 | return ira->codegen->builtin_types.entry_invalid; | 15755 | return ira->codegen->builtin_types.entry_invalid; |
| 15576 | | 15756 | |
| 15577 | TypeTableEntry *ptr_type = value->value.type; | 15757 | ZigType *ptr_type = value->value.type; |
| 15578 | assert(ptr_type->id == TypeTableEntryIdPointer); | 15758 | assert(ptr_type->id == ZigTypeIdPointer); |
| 15579 | | 15759 | |
| 15580 | TypeTableEntry *type_entry = ptr_type->data.pointer.child_type; | 15760 | ZigType *type_entry = ptr_type->data.pointer.child_type; |
| 15581 | if (type_is_invalid(type_entry)) { | 15761 | if (type_is_invalid(type_entry)) { |
| 15582 | return ira->codegen->builtin_types.entry_invalid; | 15762 | return ira->codegen->builtin_types.entry_invalid; |
| 15583 | } else if (type_entry->id != TypeTableEntryIdOptional) { | 15763 | } else if (type_entry->id != ZigTypeIdOptional) { |
| 15584 | ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node, | 15764 | ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node, |
| 15585 | buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name))); | 15765 | buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name))); |
| 15586 | return ira->codegen->builtin_types.entry_invalid; | 15766 | return ira->codegen->builtin_types.entry_invalid; |
| 15587 | } | 15767 | } |
| 15588 | TypeTableEntry *child_type = type_entry->data.maybe.child_type; | 15768 | ZigType *child_type = type_entry->data.maybe.child_type; |
| 15589 | TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, child_type, | 15769 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 15590 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, | 15770 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 15591 | PtrLenSingle, | 15771 | PtrLenSingle, |
| 15592 | get_abi_alignment(ira->codegen, child_type), 0, 0); | 15772 | get_abi_alignment(ira->codegen, child_type), 0, 0); |
| ... | @@ -15595,7 +15775,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, | ... | @@ -15595,7 +15775,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, |
| 15595 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); | 15775 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| 15596 | if (!val) | 15776 | if (!val) |
| 15597 | return ira->codegen->builtin_types.entry_invalid; | 15777 | return ira->codegen->builtin_types.entry_invalid; |
| 15598 | ConstExprValue *maybe_val = const_ptr_pointee(ira->codegen, val); | 15778 | ConstExprValue *maybe_val = ir_const_ptr_pointee(ira, val, unwrap_maybe_instruction->base.source_node); |
| | 15779 | if (maybe_val == nullptr) |
| | 15780 | return ira->codegen->builtin_types.entry_invalid; |
| 15599 | | 15781 | |
| 15600 | if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { | 15782 | if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 15601 | if (optional_value_is_null(maybe_val)) { | 15783 | if (optional_value_is_null(maybe_val)) { |
| ... | @@ -15619,12 +15801,12 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, | ... | @@ -15619,12 +15801,12 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, |
| 15619 | return result_type; | 15801 | return result_type; |
| 15620 | } | 15802 | } |
| 15621 | | 15803 | |
| 15622 | static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) { | 15804 | static ZigType *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) { |
| 15623 | IrInstruction *value = ctz_instruction->value->other; | 15805 | IrInstruction *value = ctz_instruction->value->other; |
| 15624 | if (type_is_invalid(value->value.type)) { | 15806 | if (type_is_invalid(value->value.type)) { |
| 15625 | return ira->codegen->builtin_types.entry_invalid; | 15807 | return ira->codegen->builtin_types.entry_invalid; |
| 15626 | } else if (value->value.type->id == TypeTableEntryIdInt) { | 15808 | } else if (value->value.type->id == ZigTypeIdInt) { |
| 15627 | TypeTableEntry *return_type = get_smallest_unsigned_int_type(ira->codegen, | 15809 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, |
| 15628 | value->value.type->data.integral.bit_count); | 15810 | value->value.type->data.integral.bit_count); |
| 15629 | if (value->value.special != ConstValSpecialRuntime) { | 15811 | if (value->value.special != ConstValSpecialRuntime) { |
| 15630 | size_t result = bigint_ctz(&value->value.data.x_bigint, | 15812 | size_t result = bigint_ctz(&value->value.data.x_bigint, |
| ... | @@ -15643,12 +15825,12 @@ static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionC | ... | @@ -15643,12 +15825,12 @@ static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionC |
| 15643 | } | 15825 | } |
| 15644 | } | 15826 | } |
| 15645 | | 15827 | |
| 15646 | static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) { | 15828 | static ZigType *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) { |
| 15647 | IrInstruction *value = clz_instruction->value->other; | 15829 | IrInstruction *value = clz_instruction->value->other; |
| 15648 | if (type_is_invalid(value->value.type)) { | 15830 | if (type_is_invalid(value->value.type)) { |
| 15649 | return ira->codegen->builtin_types.entry_invalid; | 15831 | return ira->codegen->builtin_types.entry_invalid; |
| 15650 | } else if (value->value.type->id == TypeTableEntryIdInt) { | 15832 | } else if (value->value.type->id == ZigTypeIdInt) { |
| 15651 | TypeTableEntry *return_type = get_smallest_unsigned_int_type(ira->codegen, | 15833 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, |
| 15652 | value->value.type->data.integral.bit_count); | 15834 | value->value.type->data.integral.bit_count); |
| 15653 | if (value->value.special != ConstValSpecialRuntime) { | 15835 | if (value->value.special != ConstValSpecialRuntime) { |
| 15654 | size_t result = bigint_clz(&value->value.data.x_bigint, | 15836 | size_t result = bigint_clz(&value->value.data.x_bigint, |
| ... | @@ -15667,12 +15849,12 @@ static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionC | ... | @@ -15667,12 +15849,12 @@ static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionC |
| 15667 | } | 15849 | } |
| 15668 | } | 15850 | } |
| 15669 | | 15851 | |
| 15670 | static TypeTableEntry *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) { | 15852 | static ZigType *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) { |
| 15671 | IrInstruction *value = instruction->value->other; | 15853 | IrInstruction *value = instruction->value->other; |
| 15672 | if (type_is_invalid(value->value.type)) | 15854 | if (type_is_invalid(value->value.type)) |
| 15673 | return ira->codegen->builtin_types.entry_invalid; | 15855 | return ira->codegen->builtin_types.entry_invalid; |
| 15674 | | 15856 | |
| 15675 | if (value->value.type->id != TypeTableEntryIdInt && value->value.type->id != TypeTableEntryIdComptimeInt) { | 15857 | if (value->value.type->id != ZigTypeIdInt && value->value.type->id != ZigTypeIdComptimeInt) { |
| 15676 | ir_add_error(ira, value, | 15858 | ir_add_error(ira, value, |
| 15677 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name))); | 15859 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name))); |
| 15678 | return ira->codegen->builtin_types.entry_invalid; | 15860 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -15688,7 +15870,7 @@ static TypeTableEntry *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstru | ... | @@ -15688,7 +15870,7 @@ static TypeTableEntry *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstru |
| 15688 | bigint_init_unsigned(&out_val->data.x_bigint, result); | 15870 | bigint_init_unsigned(&out_val->data.x_bigint, result); |
| 15689 | return ira->codegen->builtin_types.entry_num_lit_int; | 15871 | return ira->codegen->builtin_types.entry_num_lit_int; |
| 15690 | } | 15872 | } |
| 15691 | if (value->value.type->id == TypeTableEntryIdComptimeInt) { | 15873 | if (value->value.type->id == ZigTypeIdComptimeInt) { |
| 15692 | Buf *val_buf = buf_alloc(); | 15874 | Buf *val_buf = buf_alloc(); |
| 15693 | bigint_append_buf(val_buf, &val->data.x_bigint, 10); | 15875 | bigint_append_buf(val_buf, &val->data.x_bigint, 10); |
| 15694 | ir_add_error(ira, &instruction->base, | 15876 | ir_add_error(ira, &instruction->base, |
| ... | @@ -15713,11 +15895,11 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source | ... | @@ -15713,11 +15895,11 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source |
| 15713 | if (type_is_invalid(value->value.type)) | 15895 | if (type_is_invalid(value->value.type)) |
| 15714 | return ira->codegen->invalid_instruction; | 15896 | return ira->codegen->invalid_instruction; |
| 15715 | | 15897 | |
| 15716 | if (value->value.type->id == TypeTableEntryIdEnum) { | 15898 | if (value->value.type->id == ZigTypeIdEnum) { |
| 15717 | return value; | 15899 | return value; |
| 15718 | } | 15900 | } |
| 15719 | | 15901 | |
| 15720 | if (value->value.type->id != TypeTableEntryIdUnion) { | 15902 | if (value->value.type->id != ZigTypeIdUnion) { |
| 15721 | ir_add_error(ira, value, | 15903 | ir_add_error(ira, value, |
| 15722 | buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value.type->name))); | 15904 | buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value.type->name))); |
| 15723 | return ira->codegen->invalid_instruction; | 15905 | return ira->codegen->invalid_instruction; |
| ... | @@ -15731,8 +15913,8 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source | ... | @@ -15731,8 +15913,8 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source |
| 15731 | return ira->codegen->invalid_instruction; | 15913 | return ira->codegen->invalid_instruction; |
| 15732 | } | 15914 | } |
| 15733 | | 15915 | |
| 15734 | TypeTableEntry *tag_type = value->value.type->data.unionation.tag_type; | 15916 | ZigType *tag_type = value->value.type->data.unionation.tag_type; |
| 15735 | assert(tag_type->id == TypeTableEntryIdEnum); | 15917 | assert(tag_type->id == ZigTypeIdEnum); |
| 15736 | | 15918 | |
| 15737 | if (instr_is_comptime(value)) { | 15919 | if (instr_is_comptime(value)) { |
| 15738 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); | 15920 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| ... | @@ -15752,7 +15934,7 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source | ... | @@ -15752,7 +15934,7 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source |
| 15752 | return result; | 15934 | return result; |
| 15753 | } | 15935 | } |
| 15754 | | 15936 | |
| 15755 | static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, | 15937 | static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 15756 | IrInstructionSwitchBr *switch_br_instruction) | 15938 | IrInstructionSwitchBr *switch_br_instruction) |
| 15757 | { | 15939 | { |
| 15758 | IrInstruction *target_value = switch_br_instruction->target_value->other; | 15940 | IrInstruction *target_value = switch_br_instruction->target_value->other; |
| ... | @@ -15784,7 +15966,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, | ... | @@ -15784,7 +15966,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 15784 | if (type_is_invalid(case_value->value.type)) | 15966 | if (type_is_invalid(case_value->value.type)) |
| 15785 | return ir_unreach_error(ira); | 15967 | return ir_unreach_error(ira); |
| 15786 | | 15968 | |
| 15787 | if (case_value->value.type->id == TypeTableEntryIdEnum) { | 15969 | if (case_value->value.type->id == ZigTypeIdEnum) { |
| 15788 | case_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, case_value); | 15970 | case_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, case_value); |
| 15789 | if (type_is_invalid(case_value->value.type)) | 15971 | if (type_is_invalid(case_value->value.type)) |
| 15790 | return ir_unreach_error(ira); | 15972 | return ir_unreach_error(ira); |
| ... | @@ -15831,7 +16013,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, | ... | @@ -15831,7 +16013,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 15831 | if (type_is_invalid(new_value->value.type)) | 16013 | if (type_is_invalid(new_value->value.type)) |
| 15832 | continue; | 16014 | continue; |
| 15833 | | 16015 | |
| 15834 | if (new_value->value.type->id == TypeTableEntryIdEnum) { | 16016 | if (new_value->value.type->id == ZigTypeIdEnum) { |
| 15835 | new_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, new_value); | 16017 | new_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, new_value); |
| 15836 | if (type_is_invalid(new_value->value.type)) | 16018 | if (type_is_invalid(new_value->value.type)) |
| 15837 | continue; | 16019 | continue; |
| ... | @@ -15860,7 +16042,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, | ... | @@ -15860,7 +16042,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 15860 | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); | 16042 | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| 15861 | } | 16043 | } |
| 15862 | | 16044 | |
| 15863 | static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, | 16045 | static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 15864 | IrInstructionSwitchTarget *switch_target_instruction) | 16046 | IrInstructionSwitchTarget *switch_target_instruction) |
| 15865 | { | 16047 | { |
| 15866 | Error err; | 16048 | Error err; |
| ... | @@ -15868,25 +16050,28 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, | ... | @@ -15868,25 +16050,28 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 15868 | if (type_is_invalid(target_value_ptr->value.type)) | 16050 | if (type_is_invalid(target_value_ptr->value.type)) |
| 15869 | return ira->codegen->builtin_types.entry_invalid; | 16051 | return ira->codegen->builtin_types.entry_invalid; |
| 15870 | | 16052 | |
| 15871 | if (target_value_ptr->value.type->id == TypeTableEntryIdMetaType) { | 16053 | if (target_value_ptr->value.type->id == ZigTypeIdMetaType) { |
| 15872 | assert(instr_is_comptime(target_value_ptr)); | 16054 | assert(instr_is_comptime(target_value_ptr)); |
| 15873 | TypeTableEntry *ptr_type = target_value_ptr->value.data.x_type; | 16055 | ZigType *ptr_type = target_value_ptr->value.data.x_type; |
| 15874 | assert(ptr_type->id == TypeTableEntryIdPointer); | 16056 | assert(ptr_type->id == ZigTypeIdPointer); |
| 15875 | ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); | 16057 | ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); |
| 15876 | out_val->type = ira->codegen->builtin_types.entry_type; | 16058 | out_val->type = ira->codegen->builtin_types.entry_type; |
| 15877 | out_val->data.x_type = ptr_type->data.pointer.child_type; | 16059 | out_val->data.x_type = ptr_type->data.pointer.child_type; |
| 15878 | return out_val->type; | 16060 | return out_val->type; |
| 15879 | } | 16061 | } |
| 15880 | | 16062 | |
| 15881 | if (target_value_ptr->value.type->id != TypeTableEntryIdPointer) { | 16063 | if (target_value_ptr->value.type->id != ZigTypeIdPointer) { |
| 15882 | ir_add_error(ira, target_value_ptr, buf_sprintf("invalid deref on switch target")); | 16064 | ir_add_error(ira, target_value_ptr, buf_sprintf("invalid deref on switch target")); |
| 15883 | return ira->codegen->builtin_types.entry_invalid; | 16065 | return ira->codegen->builtin_types.entry_invalid; |
| 15884 | } | 16066 | } |
| 15885 | | 16067 | |
| 15886 | TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type; | 16068 | ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 15887 | ConstExprValue *pointee_val = nullptr; | 16069 | ConstExprValue *pointee_val = nullptr; |
| 15888 | if (instr_is_comptime(target_value_ptr)) { | 16070 | if (instr_is_comptime(target_value_ptr)) { |
| 15889 | pointee_val = const_ptr_pointee(ira->codegen, &target_value_ptr->value); | 16071 | pointee_val = ir_const_ptr_pointee(ira, &target_value_ptr->value, target_value_ptr->source_node); |
| | 16072 | if (pointee_val == nullptr) |
| | 16073 | return ira->codegen->builtin_types.entry_invalid; |
| | 16074 | |
| 15890 | if (pointee_val->special == ConstValSpecialRuntime) | 16075 | if (pointee_val->special == ConstValSpecialRuntime) |
| 15891 | pointee_val = nullptr; | 16076 | pointee_val = nullptr; |
| 15892 | } | 16077 | } |
| ... | @@ -15894,20 +16079,20 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, | ... | @@ -15894,20 +16079,20 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 15894 | return ira->codegen->builtin_types.entry_invalid; | 16079 | return ira->codegen->builtin_types.entry_invalid; |
| 15895 | | 16080 | |
| 15896 | switch (target_type->id) { | 16081 | switch (target_type->id) { |
| 15897 | case TypeTableEntryIdInvalid: | 16082 | case ZigTypeIdInvalid: |
| 15898 | zig_unreachable(); | 16083 | zig_unreachable(); |
| 15899 | case TypeTableEntryIdMetaType: | 16084 | case ZigTypeIdMetaType: |
| 15900 | case TypeTableEntryIdVoid: | 16085 | case ZigTypeIdVoid: |
| 15901 | case TypeTableEntryIdBool: | 16086 | case ZigTypeIdBool: |
| 15902 | case TypeTableEntryIdInt: | 16087 | case ZigTypeIdInt: |
| 15903 | case TypeTableEntryIdFloat: | 16088 | case ZigTypeIdFloat: |
| 15904 | case TypeTableEntryIdComptimeFloat: | 16089 | case ZigTypeIdComptimeFloat: |
| 15905 | case TypeTableEntryIdComptimeInt: | 16090 | case ZigTypeIdComptimeInt: |
| 15906 | case TypeTableEntryIdPointer: | 16091 | case ZigTypeIdPointer: |
| 15907 | case TypeTableEntryIdPromise: | 16092 | case ZigTypeIdPromise: |
| 15908 | case TypeTableEntryIdFn: | 16093 | case ZigTypeIdFn: |
| 15909 | case TypeTableEntryIdNamespace: | 16094 | case ZigTypeIdNamespace: |
| 15910 | case TypeTableEntryIdErrorSet: | 16095 | case ZigTypeIdErrorSet: |
| 15911 | if (pointee_val) { | 16096 | if (pointee_val) { |
| 15912 | ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); | 16097 | ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); |
| 15913 | copy_const_val(out_val, pointee_val, true); | 16098 | copy_const_val(out_val, pointee_val, true); |
| ... | @@ -15917,7 +16102,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, | ... | @@ -15917,7 +16102,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 15917 | | 16102 | |
| 15918 | ir_build_load_ptr_from(&ira->new_irb, &switch_target_instruction->base, target_value_ptr); | 16103 | ir_build_load_ptr_from(&ira->new_irb, &switch_target_instruction->base, target_value_ptr); |
| 15919 | return target_type; | 16104 | return target_type; |
| 15920 | case TypeTableEntryIdUnion: { | 16105 | case ZigTypeIdUnion: { |
| 15921 | AstNode *decl_node = target_type->data.unionation.decl_node; | 16106 | AstNode *decl_node = target_type->data.unionation.decl_node; |
| 15922 | if (!decl_node->data.container_decl.auto_enum && | 16107 | if (!decl_node->data.container_decl.auto_enum && |
| 15923 | decl_node->data.container_decl.init_arg_expr == nullptr) | 16108 | decl_node->data.container_decl.init_arg_expr == nullptr) |
| ... | @@ -15928,9 +16113,9 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, | ... | @@ -15928,9 +16113,9 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 15928 | buf_sprintf("consider 'union(enum)' here")); | 16113 | buf_sprintf("consider 'union(enum)' here")); |
| 15929 | return ira->codegen->builtin_types.entry_invalid; | 16114 | return ira->codegen->builtin_types.entry_invalid; |
| 15930 | } | 16115 | } |
| 15931 | TypeTableEntry *tag_type = target_type->data.unionation.tag_type; | 16116 | ZigType *tag_type = target_type->data.unionation.tag_type; |
| 15932 | assert(tag_type != nullptr); | 16117 | assert(tag_type != nullptr); |
| 15933 | assert(tag_type->id == TypeTableEntryIdEnum); | 16118 | assert(tag_type->id == ZigTypeIdEnum); |
| 15934 | if (pointee_val) { | 16119 | if (pointee_val) { |
| 15935 | ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); | 16120 | ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); |
| 15936 | bigint_init_bigint(&out_val->data.x_enum_tag, &pointee_val->data.x_union.tag); | 16121 | bigint_init_bigint(&out_val->data.x_enum_tag, &pointee_val->data.x_union.tag); |
| ... | @@ -15953,7 +16138,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, | ... | @@ -15953,7 +16138,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 15953 | ir_link_new_instruction(union_tag_inst, &switch_target_instruction->base); | 16138 | ir_link_new_instruction(union_tag_inst, &switch_target_instruction->base); |
| 15954 | return tag_type; | 16139 | return tag_type; |
| 15955 | } | 16140 | } |
| 15956 | case TypeTableEntryIdEnum: { | 16141 | case ZigTypeIdEnum: { |
| 15957 | if ((err = type_ensure_zero_bits_known(ira->codegen, target_type))) | 16142 | if ((err = type_ensure_zero_bits_known(ira->codegen, target_type))) |
| 15958 | return ira->codegen->builtin_types.entry_invalid; | 16143 | return ira->codegen->builtin_types.entry_invalid; |
| 15959 | if (target_type->data.enumeration.src_field_count < 2) { | 16144 | if (target_type->data.enumeration.src_field_count < 2) { |
| ... | @@ -15975,17 +16160,17 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, | ... | @@ -15975,17 +16160,17 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 15975 | ir_link_new_instruction(enum_value, &switch_target_instruction->base); | 16160 | ir_link_new_instruction(enum_value, &switch_target_instruction->base); |
| 15976 | return target_type; | 16161 | return target_type; |
| 15977 | } | 16162 | } |
| 15978 | case TypeTableEntryIdErrorUnion: | 16163 | case ZigTypeIdErrorUnion: |
| 15979 | case TypeTableEntryIdUnreachable: | 16164 | case ZigTypeIdUnreachable: |
| 15980 | case TypeTableEntryIdArray: | 16165 | case ZigTypeIdArray: |
| 15981 | case TypeTableEntryIdStruct: | 16166 | case ZigTypeIdStruct: |
| 15982 | case TypeTableEntryIdUndefined: | 16167 | case ZigTypeIdUndefined: |
| 15983 | case TypeTableEntryIdNull: | 16168 | case ZigTypeIdNull: |
| 15984 | case TypeTableEntryIdOptional: | 16169 | case ZigTypeIdOptional: |
| 15985 | case TypeTableEntryIdBlock: | 16170 | case ZigTypeIdBlock: |
| 15986 | case TypeTableEntryIdBoundFn: | 16171 | case ZigTypeIdBoundFn: |
| 15987 | case TypeTableEntryIdArgTuple: | 16172 | case ZigTypeIdArgTuple: |
| 15988 | case TypeTableEntryIdOpaque: | 16173 | case ZigTypeIdOpaque: |
| 15989 | ir_add_error(ira, &switch_target_instruction->base, | 16174 | ir_add_error(ira, &switch_target_instruction->base, |
| 15990 | buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name))); | 16175 | buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name))); |
| 15991 | return ira->codegen->builtin_types.entry_invalid; | 16176 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -15993,7 +16178,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, | ... | @@ -15993,7 +16178,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 15993 | zig_unreachable(); | 16178 | zig_unreachable(); |
| 15994 | } | 16179 | } |
| 15995 | | 16180 | |
| 15996 | static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) { | 16181 | static ZigType *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) { |
| 15997 | IrInstruction *target_value_ptr = instruction->target_value_ptr->other; | 16182 | IrInstruction *target_value_ptr = instruction->target_value_ptr->other; |
| 15998 | if (type_is_invalid(target_value_ptr->value.type)) | 16183 | if (type_is_invalid(target_value_ptr->value.type)) |
| 15999 | return ira->codegen->builtin_types.entry_invalid; | 16184 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -16002,14 +16187,14 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr | ... | @@ -16002,14 +16187,14 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr |
| 16002 | if (type_is_invalid(prong_value->value.type)) | 16187 | if (type_is_invalid(prong_value->value.type)) |
| 16003 | return ira->codegen->builtin_types.entry_invalid; | 16188 | return ira->codegen->builtin_types.entry_invalid; |
| 16004 | | 16189 | |
| 16005 | assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer); | 16190 | assert(target_value_ptr->value.type->id == ZigTypeIdPointer); |
| 16006 | TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type; | 16191 | ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 16007 | if (target_type->id == TypeTableEntryIdUnion) { | 16192 | if (target_type->id == ZigTypeIdUnion) { |
| 16008 | ConstExprValue *prong_val = ir_resolve_const(ira, prong_value, UndefBad); | 16193 | ConstExprValue *prong_val = ir_resolve_const(ira, prong_value, UndefBad); |
| 16009 | if (!prong_val) | 16194 | if (!prong_val) |
| 16010 | return ira->codegen->builtin_types.entry_invalid; | 16195 | return ira->codegen->builtin_types.entry_invalid; |
| 16011 | | 16196 | |
| 16012 | assert(prong_value->value.type->id == TypeTableEntryIdEnum); | 16197 | assert(prong_value->value.type->id == ZigTypeIdEnum); |
| 16013 | TypeUnionField *field = find_union_field_by_tag(target_type, &prong_val->data.x_enum_tag); | 16198 | TypeUnionField *field = find_union_field_by_tag(target_type, &prong_val->data.x_enum_tag); |
| 16014 | | 16199 | |
| 16015 | if (instr_is_comptime(target_value_ptr)) { | 16200 | if (instr_is_comptime(target_value_ptr)) { |
| ... | @@ -16017,7 +16202,10 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr | ... | @@ -16017,7 +16202,10 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr |
| 16017 | if (!target_value_ptr) | 16202 | if (!target_value_ptr) |
| 16018 | return ira->codegen->builtin_types.entry_invalid; | 16203 | return ira->codegen->builtin_types.entry_invalid; |
| 16019 | | 16204 | |
| 16020 | ConstExprValue *pointee_val = const_ptr_pointee(ira->codegen, target_val_ptr); | 16205 | ConstExprValue *pointee_val = ir_const_ptr_pointee(ira, target_val_ptr, instruction->base.source_node); |
| | 16206 | if (pointee_val == nullptr) |
| | 16207 | return ira->codegen->builtin_types.entry_invalid; |
| | 16208 | |
| 16021 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 16209 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 16022 | out_val->data.x_ptr.special = ConstPtrSpecialRef; | 16210 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 16023 | out_val->data.x_ptr.mut = target_val_ptr->data.x_ptr.mut; | 16211 | out_val->data.x_ptr.mut = target_val_ptr->data.x_ptr.mut; |
| ... | @@ -16035,14 +16223,14 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr | ... | @@ -16035,14 +16223,14 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr |
| 16035 | } | 16223 | } |
| 16036 | } | 16224 | } |
| 16037 | | 16225 | |
| 16038 | static TypeTableEntry *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) { | 16226 | static ZigType *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) { |
| 16039 | IrInstruction *value = instruction->value->other; | 16227 | IrInstruction *value = instruction->value->other; |
| 16040 | IrInstruction *new_instruction = ir_analyze_union_tag(ira, &instruction->base, value); | 16228 | IrInstruction *new_instruction = ir_analyze_union_tag(ira, &instruction->base, value); |
| 16041 | ir_link_new_instruction(new_instruction, &instruction->base); | 16229 | ir_link_new_instruction(new_instruction, &instruction->base); |
| 16042 | return new_instruction->value.type; | 16230 | return new_instruction->value.type; |
| 16043 | } | 16231 | } |
| 16044 | | 16232 | |
| 16045 | static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) { | 16233 | static ZigType *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) { |
| 16046 | IrInstruction *name_value = import_instruction->name->other; | 16234 | IrInstruction *name_value = import_instruction->name->other; |
| 16047 | Buf *import_target_str = ir_resolve_str(ira, name_value); | 16235 | Buf *import_target_str = ir_resolve_str(ira, name_value); |
| 16048 | if (!import_target_str) | 16236 | if (!import_target_str) |
| ... | @@ -16074,29 +16262,20 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi | ... | @@ -16074,29 +16262,20 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi |
| 16074 | os_path_join(search_dir, import_target_path, &full_path); | 16262 | os_path_join(search_dir, import_target_path, &full_path); |
| 16075 | | 16263 | |
| 16076 | Buf *import_code = buf_alloc(); | 16264 | Buf *import_code = buf_alloc(); |
| 16077 | Buf *abs_full_path = buf_alloc(); | 16265 | Buf *resolved_path = buf_alloc(); |
| 16078 | int err; | | |
| 16079 | if ((err = os_path_real(&full_path, abs_full_path))) { | | |
| 16080 | if (err == ErrorFileNotFound) { | | |
| 16081 | ir_add_error_node(ira, source_node, | | |
| 16082 | buf_sprintf("unable to find '%s'", buf_ptr(import_target_path))); | | |
| 16083 | return ira->codegen->builtin_types.entry_invalid; | | |
| 16084 | } else { | | |
| 16085 | ira->codegen->error_during_imports = true; | | |
| 16086 | ir_add_error_node(ira, source_node, | | |
| 16087 | buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err))); | | |
| 16088 | return ira->codegen->builtin_types.entry_invalid; | | |
| 16089 | } | | |
| 16090 | } | | |
| 16091 | | 16266 | |
| 16092 | auto import_entry = ira->codegen->import_table.maybe_get(abs_full_path); | 16267 | Buf *resolve_paths[] = { &full_path, }; |
| | 16268 | *resolved_path = os_path_resolve(resolve_paths, 1); |
| | 16269 | |
| | 16270 | auto import_entry = ira->codegen->import_table.maybe_get(resolved_path); |
| 16093 | if (import_entry) { | 16271 | if (import_entry) { |
| 16094 | ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base); | 16272 | ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base); |
| 16095 | out_val->data.x_import = import_entry->value; | 16273 | out_val->data.x_import = import_entry->value; |
| 16096 | return ira->codegen->builtin_types.entry_namespace; | 16274 | return ira->codegen->builtin_types.entry_namespace; |
| 16097 | } | 16275 | } |
| 16098 | | 16276 | |
| 16099 | if ((err = os_fetch_file_path(abs_full_path, import_code, true))) { | 16277 | int err; |
| | 16278 | if ((err = os_fetch_file_path(resolved_path, import_code, true))) { |
| 16100 | if (err == ErrorFileNotFound) { | 16279 | if (err == ErrorFileNotFound) { |
| 16101 | ir_add_error_node(ira, source_node, | 16280 | ir_add_error_node(ira, source_node, |
| 16102 | buf_sprintf("unable to find '%s'", buf_ptr(import_target_path))); | 16281 | buf_sprintf("unable to find '%s'", buf_ptr(import_target_path))); |
| ... | @@ -16107,7 +16286,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi | ... | @@ -16107,7 +16286,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi |
| 16107 | return ira->codegen->builtin_types.entry_invalid; | 16286 | return ira->codegen->builtin_types.entry_invalid; |
| 16108 | } | 16287 | } |
| 16109 | } | 16288 | } |
| 16110 | ImportTableEntry *target_import = add_source_file(ira->codegen, target_package, abs_full_path, import_code); | 16289 | ImportTableEntry *target_import = add_source_file(ira->codegen, target_package, resolved_path, import_code); |
| 16111 | | 16290 | |
| 16112 | scan_import(ira->codegen, target_import); | 16291 | scan_import(ira->codegen, target_import); |
| 16113 | | 16292 | |
| ... | @@ -16117,14 +16296,14 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi | ... | @@ -16117,14 +16296,14 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi |
| 16117 | | 16296 | |
| 16118 | } | 16297 | } |
| 16119 | | 16298 | |
| 16120 | static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira, | 16299 | static ZigType *ir_analyze_instruction_array_len(IrAnalyze *ira, |
| 16121 | IrInstructionArrayLen *array_len_instruction) | 16300 | IrInstructionArrayLen *array_len_instruction) |
| 16122 | { | 16301 | { |
| 16123 | IrInstruction *array_value = array_len_instruction->array_value->other; | 16302 | IrInstruction *array_value = array_len_instruction->array_value->other; |
| 16124 | TypeTableEntry *type_entry = array_value->value.type; | 16303 | ZigType *type_entry = array_value->value.type; |
| 16125 | if (type_is_invalid(type_entry)) { | 16304 | if (type_is_invalid(type_entry)) { |
| 16126 | return ira->codegen->builtin_types.entry_invalid; | 16305 | return ira->codegen->builtin_types.entry_invalid; |
| 16127 | } else if (type_entry->id == TypeTableEntryIdArray) { | 16306 | } else if (type_entry->id == ZigTypeIdArray) { |
| 16128 | return ir_analyze_const_usize(ira, &array_len_instruction->base, | 16307 | return ir_analyze_const_usize(ira, &array_len_instruction->base, |
| 16129 | type_entry->data.array.len); | 16308 | type_entry->data.array.len); |
| 16130 | } else if (is_slice(type_entry)) { | 16309 | } else if (is_slice(type_entry)) { |
| ... | @@ -16148,16 +16327,16 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira, | ... | @@ -16148,16 +16327,16 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira, |
| 16148 | } | 16327 | } |
| 16149 | } | 16328 | } |
| 16150 | | 16329 | |
| 16151 | static TypeTableEntry *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) { | 16330 | static ZigType *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) { |
| 16152 | IrInstruction *value = ref_instruction->value->other; | 16331 | IrInstruction *value = ref_instruction->value->other; |
| 16153 | return ir_analyze_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile); | 16332 | return ir_analyze_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile); |
| 16154 | } | 16333 | } |
| 16155 | | 16334 | |
| 16156 | static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruction *instruction, | 16335 | static ZigType *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruction *instruction, |
| 16157 | TypeTableEntry *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields) | 16336 | ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields) |
| 16158 | { | 16337 | { |
| 16159 | Error err; | 16338 | Error err; |
| 16160 | assert(container_type->id == TypeTableEntryIdUnion); | 16339 | assert(container_type->id == ZigTypeIdUnion); |
| 16161 | | 16340 | |
| 16162 | if ((err = ensure_complete_type(ira->codegen, container_type))) | 16341 | if ((err = ensure_complete_type(ira->codegen, container_type))) |
| 16163 | return ira->codegen->builtin_types.entry_invalid; | 16342 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -16219,14 +16398,14 @@ static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, Ir | ... | @@ -16219,14 +16398,14 @@ static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, Ir |
| 16219 | return container_type; | 16398 | return container_type; |
| 16220 | } | 16399 | } |
| 16221 | | 16400 | |
| 16222 | static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction, | 16401 | static ZigType *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction, |
| 16223 | TypeTableEntry *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields) | 16402 | ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields) |
| 16224 | { | 16403 | { |
| 16225 | Error err; | 16404 | Error err; |
| 16226 | if (container_type->id == TypeTableEntryIdUnion) { | 16405 | if (container_type->id == ZigTypeIdUnion) { |
| 16227 | return ir_analyze_container_init_fields_union(ira, instruction, container_type, instr_field_count, fields); | 16406 | return ir_analyze_container_init_fields_union(ira, instruction, container_type, instr_field_count, fields); |
| 16228 | } | 16407 | } |
| 16229 | if (container_type->id != TypeTableEntryIdStruct || is_slice(container_type)) { | 16408 | if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) { |
| 16230 | ir_add_error(ira, instruction, | 16409 | ir_add_error(ira, instruction, |
| 16231 | buf_sprintf("type '%s' does not support struct initialization syntax", | 16410 | buf_sprintf("type '%s' does not support struct initialization syntax", |
| 16232 | buf_ptr(&container_type->name))); | 16411 | buf_ptr(&container_type->name))); |
| ... | @@ -16339,7 +16518,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru | ... | @@ -16339,7 +16518,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru |
| 16339 | return container_type; | 16518 | return container_type; |
| 16340 | } | 16519 | } |
| 16341 | | 16520 | |
| 16342 | static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira, | 16521 | static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16343 | IrInstructionContainerInitList *instruction) | 16522 | IrInstructionContainerInitList *instruction) |
| 16344 | { | 16523 | { |
| 16345 | IrInstruction *container_type_value = instruction->container_type->other; | 16524 | IrInstruction *container_type_value = instruction->container_type->other; |
| ... | @@ -16347,21 +16526,21 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira | ... | @@ -16347,21 +16526,21 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 16347 | return ira->codegen->builtin_types.entry_invalid; | 16526 | return ira->codegen->builtin_types.entry_invalid; |
| 16348 | | 16527 | |
| 16349 | size_t elem_count = instruction->item_count; | 16528 | size_t elem_count = instruction->item_count; |
| 16350 | if (container_type_value->value.type->id == TypeTableEntryIdMetaType) { | 16529 | if (container_type_value->value.type->id == ZigTypeIdMetaType) { |
| 16351 | TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value); | 16530 | ZigType *container_type = ir_resolve_type(ira, container_type_value); |
| 16352 | if (type_is_invalid(container_type)) | 16531 | if (type_is_invalid(container_type)) |
| 16353 | return ira->codegen->builtin_types.entry_invalid; | 16532 | return ira->codegen->builtin_types.entry_invalid; |
| 16354 | | 16533 | |
| 16355 | if (container_type->id == TypeTableEntryIdStruct && !is_slice(container_type) && elem_count == 0) { | 16534 | if (container_type->id == ZigTypeIdStruct && !is_slice(container_type) && elem_count == 0) { |
| 16356 | return ir_analyze_container_init_fields(ira, &instruction->base, container_type, | 16535 | return ir_analyze_container_init_fields(ira, &instruction->base, container_type, |
| 16357 | 0, nullptr); | 16536 | 0, nullptr); |
| 16358 | } else if (is_slice(container_type) || container_type->id == TypeTableEntryIdArray) { | 16537 | } else if (is_slice(container_type) || container_type->id == ZigTypeIdArray) { |
| 16359 | // array is same as slice init but we make a compile error if the length is wrong | 16538 | // array is same as slice init but we make a compile error if the length is wrong |
| 16360 | TypeTableEntry *child_type; | 16539 | ZigType *child_type; |
| 16361 | if (container_type->id == TypeTableEntryIdArray) { | 16540 | if (container_type->id == ZigTypeIdArray) { |
| 16362 | child_type = container_type->data.array.child_type; | 16541 | child_type = container_type->data.array.child_type; |
| 16363 | if (container_type->data.array.len != elem_count) { | 16542 | if (container_type->data.array.len != elem_count) { |
| 16364 | TypeTableEntry *literal_type = get_array_type(ira->codegen, child_type, elem_count); | 16543 | ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count); |
| 16365 | | 16544 | |
| 16366 | ir_add_error(ira, &instruction->base, | 16545 | ir_add_error(ira, &instruction->base, |
| 16367 | buf_sprintf("expected %s literal, found %s literal", | 16546 | buf_sprintf("expected %s literal, found %s literal", |
| ... | @@ -16369,12 +16548,12 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira | ... | @@ -16369,12 +16548,12 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 16369 | return ira->codegen->builtin_types.entry_invalid; | 16548 | return ira->codegen->builtin_types.entry_invalid; |
| 16370 | } | 16549 | } |
| 16371 | } else { | 16550 | } else { |
| 16372 | TypeTableEntry *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry; | 16551 | ZigType *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry; |
| 16373 | assert(pointer_type->id == TypeTableEntryIdPointer); | 16552 | assert(pointer_type->id == ZigTypeIdPointer); |
| 16374 | child_type = pointer_type->data.pointer.child_type; | 16553 | child_type = pointer_type->data.pointer.child_type; |
| 16375 | } | 16554 | } |
| 16376 | | 16555 | |
| 16377 | TypeTableEntry *fixed_size_array_type = get_array_type(ira->codegen, child_type, elem_count); | 16556 | ZigType *fixed_size_array_type = get_array_type(ira->codegen, child_type, elem_count); |
| 16378 | | 16557 | |
| 16379 | ConstExprValue const_val = {}; | 16558 | ConstExprValue const_val = {}; |
| 16380 | const_val.special = ConstValSpecialStatic; | 16559 | const_val.special = ConstValSpecialStatic; |
| ... | @@ -16437,7 +16616,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira | ... | @@ -16437,7 +16616,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 16437 | container_type_value, elem_count, new_items); | 16616 | container_type_value, elem_count, new_items); |
| 16438 | ir_add_alloca(ira, new_instruction, fixed_size_array_type); | 16617 | ir_add_alloca(ira, new_instruction, fixed_size_array_type); |
| 16439 | return fixed_size_array_type; | 16618 | return fixed_size_array_type; |
| 16440 | } else if (container_type->id == TypeTableEntryIdVoid) { | 16619 | } else if (container_type->id == ZigTypeIdVoid) { |
| 16441 | if (elem_count != 0) { | 16620 | if (elem_count != 0) { |
| 16442 | ir_add_error_node(ira, instruction->base.source_node, | 16621 | ir_add_error_node(ira, instruction->base.source_node, |
| 16443 | buf_sprintf("void expression expects no arguments")); | 16622 | buf_sprintf("void expression expects no arguments")); |
| ... | @@ -16457,9 +16636,9 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira | ... | @@ -16457,9 +16636,9 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 16457 | } | 16636 | } |
| 16458 | } | 16637 | } |
| 16459 | | 16638 | |
| 16460 | static TypeTableEntry *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, IrInstructionContainerInitFields *instruction) { | 16639 | static ZigType *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, IrInstructionContainerInitFields *instruction) { |
| 16461 | IrInstruction *container_type_value = instruction->container_type->other; | 16640 | IrInstruction *container_type_value = instruction->container_type->other; |
| 16462 | TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value); | 16641 | ZigType *container_type = ir_resolve_type(ira, container_type_value); |
| 16463 | if (type_is_invalid(container_type)) | 16642 | if (type_is_invalid(container_type)) |
| 16464 | return ira->codegen->builtin_types.entry_invalid; | 16643 | return ira->codegen->builtin_types.entry_invalid; |
| 16465 | | 16644 | |
| ... | @@ -16467,50 +16646,50 @@ static TypeTableEntry *ir_analyze_instruction_container_init_fields(IrAnalyze *i | ... | @@ -16467,50 +16646,50 @@ static TypeTableEntry *ir_analyze_instruction_container_init_fields(IrAnalyze *i |
| 16467 | instruction->field_count, instruction->fields); | 16646 | instruction->field_count, instruction->fields); |
| 16468 | } | 16647 | } |
| 16469 | | 16648 | |
| 16470 | static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruction, | 16649 | static ZigType *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruction, |
| 16471 | IrInstruction *target_type_value, bool is_max) | 16650 | IrInstruction *target_type_value, bool is_max) |
| 16472 | { | 16651 | { |
| 16473 | TypeTableEntry *target_type = ir_resolve_type(ira, target_type_value); | 16652 | ZigType *target_type = ir_resolve_type(ira, target_type_value); |
| 16474 | if (type_is_invalid(target_type)) | 16653 | if (type_is_invalid(target_type)) |
| 16475 | return ira->codegen->builtin_types.entry_invalid; | 16654 | return ira->codegen->builtin_types.entry_invalid; |
| 16476 | switch (target_type->id) { | 16655 | switch (target_type->id) { |
| 16477 | case TypeTableEntryIdInvalid: | 16656 | case ZigTypeIdInvalid: |
| 16478 | zig_unreachable(); | 16657 | zig_unreachable(); |
| 16479 | case TypeTableEntryIdInt: | 16658 | case ZigTypeIdInt: |
| 16480 | { | 16659 | { |
| 16481 | ConstExprValue *out_val = ir_build_const_from(ira, source_instruction); | 16660 | ConstExprValue *out_val = ir_build_const_from(ira, source_instruction); |
| 16482 | eval_min_max_value(ira->codegen, target_type, out_val, is_max); | 16661 | eval_min_max_value(ira->codegen, target_type, out_val, is_max); |
| 16483 | return ira->codegen->builtin_types.entry_num_lit_int; | 16662 | return ira->codegen->builtin_types.entry_num_lit_int; |
| 16484 | } | 16663 | } |
| 16485 | case TypeTableEntryIdBool: | 16664 | case ZigTypeIdBool: |
| 16486 | case TypeTableEntryIdVoid: | 16665 | case ZigTypeIdVoid: |
| 16487 | { | 16666 | { |
| 16488 | ConstExprValue *out_val = ir_build_const_from(ira, source_instruction); | 16667 | ConstExprValue *out_val = ir_build_const_from(ira, source_instruction); |
| 16489 | eval_min_max_value(ira->codegen, target_type, out_val, is_max); | 16668 | eval_min_max_value(ira->codegen, target_type, out_val, is_max); |
| 16490 | return target_type; | 16669 | return target_type; |
| 16491 | } | 16670 | } |
| 16492 | case TypeTableEntryIdEnum: | 16671 | case ZigTypeIdEnum: |
| 16493 | case TypeTableEntryIdFloat: | 16672 | case ZigTypeIdFloat: |
| 16494 | case TypeTableEntryIdMetaType: | 16673 | case ZigTypeIdMetaType: |
| 16495 | case TypeTableEntryIdUnreachable: | 16674 | case ZigTypeIdUnreachable: |
| 16496 | case TypeTableEntryIdPointer: | 16675 | case ZigTypeIdPointer: |
| 16497 | case TypeTableEntryIdPromise: | 16676 | case ZigTypeIdPromise: |
| 16498 | case TypeTableEntryIdArray: | 16677 | case ZigTypeIdArray: |
| 16499 | case TypeTableEntryIdStruct: | 16678 | case ZigTypeIdStruct: |
| 16500 | case TypeTableEntryIdComptimeFloat: | 16679 | case ZigTypeIdComptimeFloat: |
| 16501 | case TypeTableEntryIdComptimeInt: | 16680 | case ZigTypeIdComptimeInt: |
| 16502 | case TypeTableEntryIdUndefined: | 16681 | case ZigTypeIdUndefined: |
| 16503 | case TypeTableEntryIdNull: | 16682 | case ZigTypeIdNull: |
| 16504 | case TypeTableEntryIdOptional: | 16683 | case ZigTypeIdOptional: |
| 16505 | case TypeTableEntryIdErrorUnion: | 16684 | case ZigTypeIdErrorUnion: |
| 16506 | case TypeTableEntryIdErrorSet: | 16685 | case ZigTypeIdErrorSet: |
| 16507 | case TypeTableEntryIdUnion: | 16686 | case ZigTypeIdUnion: |
| 16508 | case TypeTableEntryIdFn: | 16687 | case ZigTypeIdFn: |
| 16509 | case TypeTableEntryIdNamespace: | 16688 | case ZigTypeIdNamespace: |
| 16510 | case TypeTableEntryIdBlock: | 16689 | case ZigTypeIdBlock: |
| 16511 | case TypeTableEntryIdBoundFn: | 16690 | case ZigTypeIdBoundFn: |
| 16512 | case TypeTableEntryIdArgTuple: | 16691 | case ZigTypeIdArgTuple: |
| 16513 | case TypeTableEntryIdOpaque: | 16692 | case ZigTypeIdOpaque: |
| 16514 | { | 16693 | { |
| 16515 | const char *err_format = is_max ? | 16694 | const char *err_format = is_max ? |
| 16516 | "no max value available for type '%s'" : | 16695 | "no max value available for type '%s'" : |
| ... | @@ -16523,19 +16702,19 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_ | ... | @@ -16523,19 +16702,19 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_ |
| 16523 | zig_unreachable(); | 16702 | zig_unreachable(); |
| 16524 | } | 16703 | } |
| 16525 | | 16704 | |
| 16526 | static TypeTableEntry *ir_analyze_instruction_min_value(IrAnalyze *ira, | 16705 | static ZigType *ir_analyze_instruction_min_value(IrAnalyze *ira, |
| 16527 | IrInstructionMinValue *instruction) | 16706 | IrInstructionMinValue *instruction) |
| 16528 | { | 16707 | { |
| 16529 | return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, false); | 16708 | return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, false); |
| 16530 | } | 16709 | } |
| 16531 | | 16710 | |
| 16532 | static TypeTableEntry *ir_analyze_instruction_max_value(IrAnalyze *ira, | 16711 | static ZigType *ir_analyze_instruction_max_value(IrAnalyze *ira, |
| 16533 | IrInstructionMaxValue *instruction) | 16712 | IrInstructionMaxValue *instruction) |
| 16534 | { | 16713 | { |
| 16535 | return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, true); | 16714 | return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, true); |
| 16536 | } | 16715 | } |
| 16537 | | 16716 | |
| 16538 | static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira, | 16717 | static ZigType *ir_analyze_instruction_compile_err(IrAnalyze *ira, |
| 16539 | IrInstructionCompileErr *instruction) | 16718 | IrInstructionCompileErr *instruction) |
| 16540 | { | 16719 | { |
| 16541 | IrInstruction *msg_value = instruction->msg->other; | 16720 | IrInstruction *msg_value = instruction->msg->other; |
| ... | @@ -16559,7 +16738,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira, | ... | @@ -16559,7 +16738,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira, |
| 16559 | return ira->codegen->builtin_types.entry_invalid; | 16738 | return ira->codegen->builtin_types.entry_invalid; |
| 16560 | } | 16739 | } |
| 16561 | | 16740 | |
| 16562 | static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) { | 16741 | static ZigType *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) { |
| 16563 | Buf buf = BUF_INIT; | 16742 | Buf buf = BUF_INIT; |
| 16564 | fprintf(stderr, "| "); | 16743 | fprintf(stderr, "| "); |
| 16565 | for (size_t i = 0; i < instruction->msg_count; i += 1) { | 16744 | for (size_t i = 0; i < instruction->msg_count; i += 1) { |
| ... | @@ -16579,7 +16758,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInst | ... | @@ -16579,7 +16758,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInst |
| 16579 | return ira->codegen->builtin_types.entry_void; | 16758 | return ira->codegen->builtin_types.entry_void; |
| 16580 | } | 16759 | } |
| 16581 | | 16760 | |
| 16582 | static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) { | 16761 | static ZigType *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) { |
| 16583 | IrInstruction *value = instruction->value->other; | 16762 | IrInstruction *value = instruction->value->other; |
| 16584 | if (type_is_invalid(value->value.type)) | 16763 | if (type_is_invalid(value->value.type)) |
| 16585 | return ira->codegen->builtin_types.entry_invalid; | 16764 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -16588,9 +16767,9 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc | ... | @@ -16588,9 +16767,9 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc |
| 16588 | if (type_is_invalid(casted_value->value.type)) | 16767 | if (type_is_invalid(casted_value->value.type)) |
| 16589 | return ira->codegen->builtin_types.entry_invalid; | 16768 | return ira->codegen->builtin_types.entry_invalid; |
| 16590 | | 16769 | |
| 16591 | TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 16770 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 16592 | true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); | 16771 | true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); |
| 16593 | TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type); | 16772 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 16594 | if (casted_value->value.special == ConstValSpecialStatic) { | 16773 | if (casted_value->value.special == ConstValSpecialStatic) { |
| 16595 | ErrorTableEntry *err = casted_value->value.data.x_err_set; | 16774 | ErrorTableEntry *err = casted_value->value.data.x_err_set; |
| 16596 | if (!err->cached_error_name_val) { | 16775 | if (!err->cached_error_name_val) { |
| ... | @@ -16607,13 +16786,13 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc | ... | @@ -16607,13 +16786,13 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc |
| 16607 | return str_type; | 16786 | return str_type; |
| 16608 | } | 16787 | } |
| 16609 | | 16788 | |
| 16610 | static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) { | 16789 | static ZigType *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) { |
| 16611 | Error err; | 16790 | Error err; |
| 16612 | IrInstruction *target = instruction->target->other; | 16791 | IrInstruction *target = instruction->target->other; |
| 16613 | if (type_is_invalid(target->value.type)) | 16792 | if (type_is_invalid(target->value.type)) |
| 16614 | return ira->codegen->builtin_types.entry_invalid; | 16793 | return ira->codegen->builtin_types.entry_invalid; |
| 16615 | | 16794 | |
| 16616 | assert(target->value.type->id == TypeTableEntryIdEnum); | 16795 | assert(target->value.type->id == ZigTypeIdEnum); |
| 16617 | | 16796 | |
| 16618 | if (instr_is_comptime(target)) { | 16797 | if (instr_is_comptime(target)) { |
| 16619 | if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type))) | 16798 | if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type))) |
| ... | @@ -16628,7 +16807,7 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIn | ... | @@ -16628,7 +16807,7 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIn |
| 16628 | IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope, | 16807 | IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope, |
| 16629 | instruction->base.source_node, target); | 16808 | instruction->base.source_node, target); |
| 16630 | ir_link_new_instruction(result, &instruction->base); | 16809 | ir_link_new_instruction(result, &instruction->base); |
| 16631 | TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra( | 16810 | ZigType *u8_ptr_type = get_pointer_to_type_extra( |
| 16632 | ira->codegen, ira->codegen->builtin_types.entry_u8, | 16811 | ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 16633 | true, false, PtrLenUnknown, | 16812 | true, false, PtrLenUnknown, |
| 16634 | get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), | 16813 | get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), |
| ... | @@ -16637,12 +16816,12 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIn | ... | @@ -16637,12 +16816,12 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIn |
| 16637 | return result->value.type; | 16816 | return result->value.type; |
| 16638 | } | 16817 | } |
| 16639 | | 16818 | |
| 16640 | static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, | 16819 | static ZigType *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 16641 | IrInstructionFieldParentPtr *instruction) | 16820 | IrInstructionFieldParentPtr *instruction) |
| 16642 | { | 16821 | { |
| 16643 | Error err; | 16822 | Error err; |
| 16644 | IrInstruction *type_value = instruction->type_value->other; | 16823 | IrInstruction *type_value = instruction->type_value->other; |
| 16645 | TypeTableEntry *container_type = ir_resolve_type(ira, type_value); | 16824 | ZigType *container_type = ir_resolve_type(ira, type_value); |
| 16646 | if (type_is_invalid(container_type)) | 16825 | if (type_is_invalid(container_type)) |
| 16647 | return ira->codegen->builtin_types.entry_invalid; | 16826 | return ira->codegen->builtin_types.entry_invalid; |
| 16648 | | 16827 | |
| ... | @@ -16655,7 +16834,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, | ... | @@ -16655,7 +16834,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 16655 | if (type_is_invalid(field_ptr->value.type)) | 16834 | if (type_is_invalid(field_ptr->value.type)) |
| 16656 | return ira->codegen->builtin_types.entry_invalid; | 16835 | return ira->codegen->builtin_types.entry_invalid; |
| 16657 | | 16836 | |
| 16658 | if (container_type->id != TypeTableEntryIdStruct) { | 16837 | if (container_type->id != ZigTypeIdStruct) { |
| 16659 | ir_add_error(ira, type_value, | 16838 | ir_add_error(ira, type_value, |
| 16660 | buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name))); | 16839 | buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name))); |
| 16661 | return ira->codegen->builtin_types.entry_invalid; | 16840 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -16672,7 +16851,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, | ... | @@ -16672,7 +16851,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 16672 | return ira->codegen->builtin_types.entry_invalid; | 16851 | return ira->codegen->builtin_types.entry_invalid; |
| 16673 | } | 16852 | } |
| 16674 | | 16853 | |
| 16675 | if (field_ptr->value.type->id != TypeTableEntryIdPointer) { | 16854 | if (field_ptr->value.type->id != ZigTypeIdPointer) { |
| 16676 | ir_add_error(ira, field_ptr, | 16855 | ir_add_error(ira, field_ptr, |
| 16677 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name))); | 16856 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name))); |
| 16678 | return ira->codegen->builtin_types.entry_invalid; | 16857 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -16682,7 +16861,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, | ... | @@ -16682,7 +16861,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 16682 | uint32_t field_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, field->type_entry); | 16861 | uint32_t field_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, field->type_entry); |
| 16683 | uint32_t parent_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, container_type); | 16862 | uint32_t parent_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, container_type); |
| 16684 | | 16863 | |
| 16685 | TypeTableEntry *field_ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry, | 16864 | ZigType *field_ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry, |
| 16686 | field_ptr->value.type->data.pointer.is_const, | 16865 | field_ptr->value.type->data.pointer.is_const, |
| 16687 | field_ptr->value.type->data.pointer.is_volatile, | 16866 | field_ptr->value.type->data.pointer.is_volatile, |
| 16688 | PtrLenSingle, | 16867 | PtrLenSingle, |
| ... | @@ -16691,7 +16870,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, | ... | @@ -16691,7 +16870,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 16691 | if (type_is_invalid(casted_field_ptr->value.type)) | 16870 | if (type_is_invalid(casted_field_ptr->value.type)) |
| 16692 | return ira->codegen->builtin_types.entry_invalid; | 16871 | return ira->codegen->builtin_types.entry_invalid; |
| 16693 | | 16872 | |
| 16694 | TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, container_type, | 16873 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type, |
| 16695 | casted_field_ptr->value.type->data.pointer.is_const, | 16874 | casted_field_ptr->value.type->data.pointer.is_const, |
| 16696 | casted_field_ptr->value.type->data.pointer.is_volatile, | 16875 | casted_field_ptr->value.type->data.pointer.is_volatile, |
| 16697 | PtrLenSingle, | 16876 | PtrLenSingle, |
| ... | @@ -16730,12 +16909,12 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, | ... | @@ -16730,12 +16909,12 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 16730 | return result_type; | 16909 | return result_type; |
| 16731 | } | 16910 | } |
| 16732 | | 16911 | |
| 16733 | static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira, | 16912 | static ZigType *ir_analyze_instruction_offset_of(IrAnalyze *ira, |
| 16734 | IrInstructionOffsetOf *instruction) | 16913 | IrInstructionOffsetOf *instruction) |
| 16735 | { | 16914 | { |
| 16736 | Error err; | 16915 | Error err; |
| 16737 | IrInstruction *type_value = instruction->type_value->other; | 16916 | IrInstruction *type_value = instruction->type_value->other; |
| 16738 | TypeTableEntry *container_type = ir_resolve_type(ira, type_value); | 16917 | ZigType *container_type = ir_resolve_type(ira, type_value); |
| 16739 | if (type_is_invalid(container_type)) | 16918 | if (type_is_invalid(container_type)) |
| 16740 | return ira->codegen->builtin_types.entry_invalid; | 16919 | return ira->codegen->builtin_types.entry_invalid; |
| 16741 | | 16920 | |
| ... | @@ -16747,7 +16926,7 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira, | ... | @@ -16747,7 +16926,7 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira, |
| 16747 | if (!field_name) | 16926 | if (!field_name) |
| 16748 | return ira->codegen->builtin_types.entry_invalid; | 16927 | return ira->codegen->builtin_types.entry_invalid; |
| 16749 | | 16928 | |
| 16750 | if (container_type->id != TypeTableEntryIdStruct) { | 16929 | if (container_type->id != ZigTypeIdStruct) { |
| 16751 | ir_add_error(ira, type_value, | 16930 | ir_add_error(ira, type_value, |
| 16752 | buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name))); | 16931 | buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name))); |
| 16753 | return ira->codegen->builtin_types.entry_invalid; | 16932 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -16773,7 +16952,7 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira, | ... | @@ -16773,7 +16952,7 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira, |
| 16773 | return ira->codegen->builtin_types.entry_num_lit_int; | 16952 | return ira->codegen->builtin_types.entry_num_lit_int; |
| 16774 | } | 16953 | } |
| 16775 | | 16954 | |
| 16776 | static void ensure_field_index(TypeTableEntry *type, const char *field_name, size_t index) | 16955 | static void ensure_field_index(ZigType *type, const char *field_name, size_t index) |
| 16777 | { | 16956 | { |
| 16778 | Buf *field_name_buf; | 16957 | Buf *field_name_buf; |
| 16779 | | 16958 | |
| ... | @@ -16784,17 +16963,17 @@ static void ensure_field_index(TypeTableEntry *type, const char *field_name, siz | ... | @@ -16784,17 +16963,17 @@ static void ensure_field_index(TypeTableEntry *type, const char *field_name, siz |
| 16784 | (buf_deinit(field_name_buf), true)); | 16963 | (buf_deinit(field_name_buf), true)); |
| 16785 | } | 16964 | } |
| 16786 | | 16965 | |
| 16787 | static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, TypeTableEntry *root) { | 16966 | static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, ZigType *root) { |
| 16788 | Error err; | 16967 | Error err; |
| 16789 | static ConstExprValue *type_info_var = nullptr; | 16968 | static ConstExprValue *type_info_var = nullptr; |
| 16790 | static TypeTableEntry *type_info_type = nullptr; | 16969 | static ZigType *type_info_type = nullptr; |
| 16791 | if (type_info_var == nullptr) { | 16970 | if (type_info_var == nullptr) { |
| 16792 | type_info_var = get_builtin_value(ira->codegen, "TypeInfo"); | 16971 | type_info_var = get_builtin_value(ira->codegen, "TypeInfo"); |
| 16793 | assert(type_info_var->type->id == TypeTableEntryIdMetaType); | 16972 | assert(type_info_var->type->id == ZigTypeIdMetaType); |
| 16794 | | 16973 | |
| 16795 | assertNoError(ensure_complete_type(ira->codegen, type_info_var->data.x_type)); | 16974 | assertNoError(ensure_complete_type(ira->codegen, type_info_var->data.x_type)); |
| 16796 | type_info_type = type_info_var->data.x_type; | 16975 | type_info_type = type_info_var->data.x_type; |
| 16797 | assert(type_info_type->id == TypeTableEntryIdUnion); | 16976 | assert(type_info_type->id == ZigTypeIdUnion); |
| 16798 | } | 16977 | } |
| 16799 | | 16978 | |
| 16800 | if (type_name == nullptr && root == nullptr) | 16979 | if (type_name == nullptr && root == nullptr) |
| ... | @@ -16802,7 +16981,7 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na | ... | @@ -16802,7 +16981,7 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na |
| 16802 | else if (type_name == nullptr) | 16981 | else if (type_name == nullptr) |
| 16803 | return root; | 16982 | return root; |
| 16804 | | 16983 | |
| 16805 | TypeTableEntry *root_type = (root == nullptr) ? type_info_type : root; | 16984 | ZigType *root_type = (root == nullptr) ? type_info_type : root; |
| 16806 | | 16985 | |
| 16807 | ScopeDecls *type_info_scope = get_container_scope(root_type); | 16986 | ScopeDecls *type_info_scope = get_container_scope(root_type); |
| 16808 | assert(type_info_scope != nullptr); | 16987 | assert(type_info_scope != nullptr); |
| ... | @@ -16815,17 +16994,17 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na | ... | @@ -16815,17 +16994,17 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na |
| 16815 | TldVar *tld = (TldVar *)entry; | 16994 | TldVar *tld = (TldVar *)entry; |
| 16816 | assert(tld->base.id == TldIdVar); | 16995 | assert(tld->base.id == TldIdVar); |
| 16817 | | 16996 | |
| 16818 | VariableTableEntry *var = tld->var; | 16997 | ZigVar *var = tld->var; |
| 16819 | | 16998 | |
| 16820 | if ((err = ensure_complete_type(ira->codegen, var->value->type))) | 16999 | if ((err = ensure_complete_type(ira->codegen, var->value->type))) |
| 16821 | return ira->codegen->builtin_types.entry_invalid; | 17000 | return ira->codegen->builtin_types.entry_invalid; |
| 16822 | assert(var->value->type->id == TypeTableEntryIdMetaType); | 17001 | assert(var->value->type->id == ZigTypeIdMetaType); |
| 16823 | return var->value->data.x_type; | 17002 | return var->value->data.x_type; |
| 16824 | } | 17003 | } |
| 16825 | | 17004 | |
| 16826 | static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope) { | 17005 | static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope) { |
| 16827 | Error err; | 17006 | Error err; |
| 16828 | TypeTableEntry *type_info_definition_type = ir_type_info_get_type(ira, "Definition", nullptr); | 17007 | ZigType *type_info_definition_type = ir_type_info_get_type(ira, "Definition", nullptr); |
| 16829 | if ((err = ensure_complete_type(ira->codegen, type_info_definition_type))) | 17008 | if ((err = ensure_complete_type(ira->codegen, type_info_definition_type))) |
| 16830 | return err; | 17009 | return err; |
| 16831 | | 17010 | |
| ... | @@ -16833,15 +17012,15 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco | ... | @@ -16833,15 +17012,15 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 16833 | ensure_field_index(type_info_definition_type, "is_pub", 1); | 17012 | ensure_field_index(type_info_definition_type, "is_pub", 1); |
| 16834 | ensure_field_index(type_info_definition_type, "data", 2); | 17013 | ensure_field_index(type_info_definition_type, "data", 2); |
| 16835 | | 17014 | |
| 16836 | TypeTableEntry *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type); | 17015 | ZigType *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type); |
| 16837 | if ((err = ensure_complete_type(ira->codegen, type_info_definition_data_type))) | 17016 | if ((err = ensure_complete_type(ira->codegen, type_info_definition_data_type))) |
| 16838 | return err; | 17017 | return err; |
| 16839 | | 17018 | |
| 16840 | TypeTableEntry *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type); | 17019 | ZigType *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type); |
| 16841 | if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_type))) | 17020 | if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_type))) |
| 16842 | return err; | 17021 | return err; |
| 16843 | | 17022 | |
| 16844 | TypeTableEntry *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type); | 17023 | ZigType *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type); |
| 16845 | if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_inline_type))) | 17024 | if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_inline_type))) |
| 16846 | return err; | 17025 | return err; |
| 16847 | | 17026 | |
| ... | @@ -16862,7 +17041,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco | ... | @@ -16862,7 +17041,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 16862 | // Skip comptime blocks and test functions. | 17041 | // Skip comptime blocks and test functions. |
| 16863 | if (curr_entry->value->id != TldIdCompTime) { | 17042 | if (curr_entry->value->id != TldIdCompTime) { |
| 16864 | if (curr_entry->value->id == TldIdFn) { | 17043 | if (curr_entry->value->id == TldIdFn) { |
| 16865 | FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry; | 17044 | ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry; |
| 16866 | if (fn_entry->is_test) | 17045 | if (fn_entry->is_test) |
| 16867 | continue; | 17046 | continue; |
| 16868 | } | 17047 | } |
| ... | @@ -16888,7 +17067,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco | ... | @@ -16888,7 +17067,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 16888 | if (curr_entry->value->id == TldIdCompTime) { | 17067 | if (curr_entry->value->id == TldIdCompTime) { |
| 16889 | continue; | 17068 | continue; |
| 16890 | } else if (curr_entry->value->id == TldIdFn) { | 17069 | } else if (curr_entry->value->id == TldIdFn) { |
| 16891 | FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry; | 17070 | ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry; |
| 16892 | if (fn_entry->is_test) | 17071 | if (fn_entry->is_test) |
| 16893 | continue; | 17072 | continue; |
| 16894 | } | 17073 | } |
| ... | @@ -16913,11 +17092,11 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco | ... | @@ -16913,11 +17092,11 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 16913 | switch (curr_entry->value->id) { | 17092 | switch (curr_entry->value->id) { |
| 16914 | case TldIdVar: | 17093 | case TldIdVar: |
| 16915 | { | 17094 | { |
| 16916 | VariableTableEntry *var = ((TldVar *)curr_entry->value)->var; | 17095 | ZigVar *var = ((TldVar *)curr_entry->value)->var; |
| 16917 | if ((err = ensure_complete_type(ira->codegen, var->value->type))) | 17096 | if ((err = ensure_complete_type(ira->codegen, var->value->type))) |
| 16918 | return ErrorSemanticAnalyzeFail; | 17097 | return ErrorSemanticAnalyzeFail; |
| 16919 | | 17098 | |
| 16920 | if (var->value->type->id == TypeTableEntryIdMetaType) | 17099 | if (var->value->type->id == ZigTypeIdMetaType) |
| 16921 | { | 17100 | { |
| 16922 | // We have a variable of type 'type', so it's actually a type definition. | 17101 | // We have a variable of type 'type', so it's actually a type definition. |
| 16923 | // 0: Data.Type: type | 17102 | // 0: Data.Type: type |
| ... | @@ -16944,7 +17123,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco | ... | @@ -16944,7 +17123,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 16944 | // 2: Data.Fn: Data.FnDef | 17123 | // 2: Data.Fn: Data.FnDef |
| 16945 | bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 2); | 17124 | bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 2); |
| 16946 | | 17125 | |
| 16947 | FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry; | 17126 | ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry; |
| 16948 | assert(!fn_entry->is_test); | 17127 | assert(!fn_entry->is_test); |
| 16949 | | 17128 | |
| 16950 | AstNodeFnProto *fn_node = (AstNodeFnProto *)(fn_entry->proto_node); | 17129 | AstNodeFnProto *fn_node = (AstNodeFnProto *)(fn_entry->proto_node); |
| ... | @@ -16992,7 +17171,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco | ... | @@ -16992,7 +17171,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 16992 | // lib_name: ?[]const u8 | 17171 | // lib_name: ?[]const u8 |
| 16993 | ensure_field_index(fn_def_val->type, "lib_name", 6); | 17172 | ensure_field_index(fn_def_val->type, "lib_name", 6); |
| 16994 | fn_def_fields[6].special = ConstValSpecialStatic; | 17173 | fn_def_fields[6].special = ConstValSpecialStatic; |
| 16995 | TypeTableEntry *u8_ptr = get_pointer_to_type_extra( | 17174 | ZigType *u8_ptr = get_pointer_to_type_extra( |
| 16996 | ira->codegen, ira->codegen->builtin_types.entry_u8, | 17175 | ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 16997 | true, false, PtrLenUnknown, | 17176 | true, false, PtrLenUnknown, |
| 16998 | get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), | 17177 | get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), |
| ... | @@ -17030,7 +17209,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco | ... | @@ -17030,7 +17209,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 17030 | | 17209 | |
| 17031 | for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) | 17210 | for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) |
| 17032 | { | 17211 | { |
| 17033 | VariableTableEntry *arg_var = fn_entry->variable_list.at(fn_arg_index); | 17212 | ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index); |
| 17034 | ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.s_none.elements[fn_arg_index]; | 17213 | ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.s_none.elements[fn_arg_index]; |
| 17035 | ConstExprValue *arg_name = create_const_str_lit(ira->codegen, &arg_var->name); | 17214 | ConstExprValue *arg_name = create_const_str_lit(ira->codegen, &arg_var->name); |
| 17036 | init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, buf_len(&arg_var->name), true); | 17215 | init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, buf_len(&arg_var->name), true); |
| ... | @@ -17044,7 +17223,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco | ... | @@ -17044,7 +17223,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 17044 | } | 17223 | } |
| 17045 | case TldIdContainer: | 17224 | case TldIdContainer: |
| 17046 | { | 17225 | { |
| 17047 | TypeTableEntry *type_entry = ((TldContainer *)curr_entry->value)->type_entry; | 17226 | ZigType *type_entry = ((TldContainer *)curr_entry->value)->type_entry; |
| 17048 | if ((err = ensure_complete_type(ira->codegen, type_entry))) | 17227 | if ((err = ensure_complete_type(ira->codegen, type_entry))) |
| 17049 | return ErrorSemanticAnalyzeFail; | 17228 | return ErrorSemanticAnalyzeFail; |
| 17050 | | 17229 | |
| ... | @@ -17071,20 +17250,20 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco | ... | @@ -17071,20 +17250,20 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 17071 | return ErrorNone; | 17250 | return ErrorNone; |
| 17072 | } | 17251 | } |
| 17073 | | 17252 | |
| 17074 | static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry *ptr_type_entry) { | 17253 | static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_entry) { |
| 17075 | TypeTableEntry *attrs_type; | 17254 | ZigType *attrs_type; |
| 17076 | uint32_t size_enum_index; | 17255 | uint32_t size_enum_index; |
| 17077 | if (is_slice(ptr_type_entry)) { | 17256 | if (is_slice(ptr_type_entry)) { |
| 17078 | attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index].type_entry; | 17257 | attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index].type_entry; |
| 17079 | size_enum_index = 2; | 17258 | size_enum_index = 2; |
| 17080 | } else if (ptr_type_entry->id == TypeTableEntryIdPointer) { | 17259 | } else if (ptr_type_entry->id == ZigTypeIdPointer) { |
| 17081 | attrs_type = ptr_type_entry; | 17260 | attrs_type = ptr_type_entry; |
| 17082 | size_enum_index = (ptr_type_entry->data.pointer.ptr_len == PtrLenSingle) ? 0 : 1; | 17261 | size_enum_index = (ptr_type_entry->data.pointer.ptr_len == PtrLenSingle) ? 0 : 1; |
| 17083 | } else { | 17262 | } else { |
| 17084 | zig_unreachable(); | 17263 | zig_unreachable(); |
| 17085 | } | 17264 | } |
| 17086 | | 17265 | |
| 17087 | TypeTableEntry *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr); | 17266 | ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr); |
| 17088 | assertNoError(ensure_complete_type(ira->codegen, type_info_pointer_type)); | 17267 | assertNoError(ensure_complete_type(ira->codegen, type_info_pointer_type)); |
| 17089 | | 17268 | |
| 17090 | ConstExprValue *result = create_const_vals(1); | 17269 | ConstExprValue *result = create_const_vals(1); |
| ... | @@ -17096,7 +17275,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry | ... | @@ -17096,7 +17275,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry |
| 17096 | | 17275 | |
| 17097 | // size: Size | 17276 | // size: Size |
| 17098 | ensure_field_index(result->type, "size", 0); | 17277 | ensure_field_index(result->type, "size", 0); |
| 17099 | TypeTableEntry *type_info_pointer_size_type = ir_type_info_get_type(ira, "Size", type_info_pointer_type); | 17278 | ZigType *type_info_pointer_size_type = ir_type_info_get_type(ira, "Size", type_info_pointer_type); |
| 17100 | assertNoError(ensure_complete_type(ira->codegen, type_info_pointer_size_type)); | 17279 | assertNoError(ensure_complete_type(ira->codegen, type_info_pointer_size_type)); |
| 17101 | fields[0].special = ConstValSpecialStatic; | 17280 | fields[0].special = ConstValSpecialStatic; |
| 17102 | fields[0].type = type_info_pointer_size_type; | 17281 | fields[0].type = type_info_pointer_size_type; |
| ... | @@ -17127,7 +17306,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry | ... | @@ -17127,7 +17306,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry |
| 17127 | }; | 17306 | }; |
| 17128 | | 17307 | |
| 17129 | static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, TypeEnumField *enum_field, | 17308 | static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, TypeEnumField *enum_field, |
| 17130 | TypeTableEntry *type_info_enum_field_type) | 17309 | ZigType *type_info_enum_field_type) |
| 17131 | { | 17310 | { |
| 17132 | enum_field_val->special = ConstValSpecialStatic; | 17311 | enum_field_val->special = ConstValSpecialStatic; |
| 17133 | enum_field_val->type = type_info_enum_field_type; | 17312 | enum_field_val->type = type_info_enum_field_type; |
| ... | @@ -17144,7 +17323,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, | ... | @@ -17144,7 +17323,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, |
| 17144 | enum_field_val->data.x_struct.fields = inner_fields; | 17323 | enum_field_val->data.x_struct.fields = inner_fields; |
| 17145 | } | 17324 | } |
| 17146 | | 17325 | |
| 17147 | static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, ConstExprValue **out) { | 17326 | static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstExprValue **out) { |
| 17148 | Error err; | 17327 | Error err; |
| 17149 | assert(type_entry != nullptr); | 17328 | assert(type_entry != nullptr); |
| 17150 | assert(!type_is_invalid(type_entry)); | 17329 | assert(!type_is_invalid(type_entry)); |
| ... | @@ -17159,20 +17338,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17159,20 +17338,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17159 | ConstExprValue *result = nullptr; | 17338 | ConstExprValue *result = nullptr; |
| 17160 | switch (type_entry->id) | 17339 | switch (type_entry->id) |
| 17161 | { | 17340 | { |
| 17162 | case TypeTableEntryIdInvalid: | 17341 | case ZigTypeIdInvalid: |
| 17163 | zig_unreachable(); | 17342 | zig_unreachable(); |
| 17164 | case TypeTableEntryIdMetaType: | 17343 | case ZigTypeIdMetaType: |
| 17165 | case TypeTableEntryIdVoid: | 17344 | case ZigTypeIdVoid: |
| 17166 | case TypeTableEntryIdBool: | 17345 | case ZigTypeIdBool: |
| 17167 | case TypeTableEntryIdUnreachable: | 17346 | case ZigTypeIdUnreachable: |
| 17168 | case TypeTableEntryIdComptimeFloat: | 17347 | case ZigTypeIdComptimeFloat: |
| 17169 | case TypeTableEntryIdComptimeInt: | 17348 | case ZigTypeIdComptimeInt: |
| 17170 | case TypeTableEntryIdUndefined: | 17349 | case ZigTypeIdUndefined: |
| 17171 | case TypeTableEntryIdNull: | 17350 | case ZigTypeIdNull: |
| 17172 | case TypeTableEntryIdNamespace: | 17351 | case ZigTypeIdNamespace: |
| 17173 | case TypeTableEntryIdBlock: | 17352 | case ZigTypeIdBlock: |
| 17174 | case TypeTableEntryIdArgTuple: | 17353 | case ZigTypeIdArgTuple: |
| 17175 | case TypeTableEntryIdOpaque: | 17354 | case ZigTypeIdOpaque: |
| 17176 | *out = nullptr; | 17355 | *out = nullptr; |
| 17177 | return ErrorNone; | 17356 | return ErrorNone; |
| 17178 | default: | 17357 | default: |
| ... | @@ -17186,7 +17365,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17186,7 +17365,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17186 | | 17365 | |
| 17187 | // Fallthrough if we don't find one. | 17366 | // Fallthrough if we don't find one. |
| 17188 | } | 17367 | } |
| 17189 | case TypeTableEntryIdInt: | 17368 | case ZigTypeIdInt: |
| 17190 | { | 17369 | { |
| 17191 | result = create_const_vals(1); | 17370 | result = create_const_vals(1); |
| 17192 | result->special = ConstValSpecialStatic; | 17371 | result->special = ConstValSpecialStatic; |
| ... | @@ -17208,7 +17387,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17208,7 +17387,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17208 | | 17387 | |
| 17209 | break; | 17388 | break; |
| 17210 | } | 17389 | } |
| 17211 | case TypeTableEntryIdFloat: | 17390 | case ZigTypeIdFloat: |
| 17212 | { | 17391 | { |
| 17213 | result = create_const_vals(1); | 17392 | result = create_const_vals(1); |
| 17214 | result->special = ConstValSpecialStatic; | 17393 | result->special = ConstValSpecialStatic; |
| ... | @@ -17225,12 +17404,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17225,12 +17404,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17225 | | 17404 | |
| 17226 | break; | 17405 | break; |
| 17227 | } | 17406 | } |
| 17228 | case TypeTableEntryIdPointer: | 17407 | case ZigTypeIdPointer: |
| 17229 | { | 17408 | { |
| 17230 | result = create_ptr_like_type_info(ira, type_entry); | 17409 | result = create_ptr_like_type_info(ira, type_entry); |
| 17231 | break; | 17410 | break; |
| 17232 | } | 17411 | } |
| 17233 | case TypeTableEntryIdArray: | 17412 | case ZigTypeIdArray: |
| 17234 | { | 17413 | { |
| 17235 | result = create_const_vals(1); | 17414 | result = create_const_vals(1); |
| 17236 | result->special = ConstValSpecialStatic; | 17415 | result->special = ConstValSpecialStatic; |
| ... | @@ -17252,7 +17431,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17252,7 +17431,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17252 | | 17431 | |
| 17253 | break; | 17432 | break; |
| 17254 | } | 17433 | } |
| 17255 | case TypeTableEntryIdOptional: | 17434 | case ZigTypeIdOptional: |
| 17256 | { | 17435 | { |
| 17257 | result = create_const_vals(1); | 17436 | result = create_const_vals(1); |
| 17258 | result->special = ConstValSpecialStatic; | 17437 | result->special = ConstValSpecialStatic; |
| ... | @@ -17269,7 +17448,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17269,7 +17448,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17269 | | 17448 | |
| 17270 | break; | 17449 | break; |
| 17271 | } | 17450 | } |
| 17272 | case TypeTableEntryIdPromise: | 17451 | case ZigTypeIdPromise: |
| 17273 | { | 17452 | { |
| 17274 | result = create_const_vals(1); | 17453 | result = create_const_vals(1); |
| 17275 | result->special = ConstValSpecialStatic; | 17454 | result->special = ConstValSpecialStatic; |
| ... | @@ -17295,7 +17474,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17295,7 +17474,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17295 | | 17474 | |
| 17296 | break; | 17475 | break; |
| 17297 | } | 17476 | } |
| 17298 | case TypeTableEntryIdEnum: | 17477 | case ZigTypeIdEnum: |
| 17299 | { | 17478 | { |
| 17300 | result = create_const_vals(1); | 17479 | result = create_const_vals(1); |
| 17301 | result->special = ConstValSpecialStatic; | 17480 | result->special = ConstValSpecialStatic; |
| ... | @@ -17317,7 +17496,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17317,7 +17496,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17317 | // fields: []TypeInfo.EnumField | 17496 | // fields: []TypeInfo.EnumField |
| 17318 | ensure_field_index(result->type, "fields", 2); | 17497 | ensure_field_index(result->type, "fields", 2); |
| 17319 | | 17498 | |
| 17320 | TypeTableEntry *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr); | 17499 | ZigType *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr); |
| 17321 | uint32_t enum_field_count = type_entry->data.enumeration.src_field_count; | 17500 | uint32_t enum_field_count = type_entry->data.enumeration.src_field_count; |
| 17322 | | 17501 | |
| 17323 | ConstExprValue *enum_field_array = create_const_vals(1); | 17502 | ConstExprValue *enum_field_array = create_const_vals(1); |
| ... | @@ -17345,7 +17524,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17345,7 +17524,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17345 | | 17524 | |
| 17346 | break; | 17525 | break; |
| 17347 | } | 17526 | } |
| 17348 | case TypeTableEntryIdErrorSet: | 17527 | case ZigTypeIdErrorSet: |
| 17349 | { | 17528 | { |
| 17350 | result = create_const_vals(1); | 17529 | result = create_const_vals(1); |
| 17351 | result->special = ConstValSpecialStatic; | 17530 | result->special = ConstValSpecialStatic; |
| ... | @@ -17357,7 +17536,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17357,7 +17536,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17357 | // errors: []TypeInfo.Error | 17536 | // errors: []TypeInfo.Error |
| 17358 | ensure_field_index(result->type, "errors", 0); | 17537 | ensure_field_index(result->type, "errors", 0); |
| 17359 | | 17538 | |
| 17360 | TypeTableEntry *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr); | 17539 | ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr); |
| 17361 | uint32_t error_count = type_entry->data.error_set.err_count; | 17540 | uint32_t error_count = type_entry->data.error_set.err_count; |
| 17362 | ConstExprValue *error_array = create_const_vals(1); | 17541 | ConstExprValue *error_array = create_const_vals(1); |
| 17363 | error_array->special = ConstValSpecialStatic; | 17542 | error_array->special = ConstValSpecialStatic; |
| ... | @@ -17394,7 +17573,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17394,7 +17573,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17394 | | 17573 | |
| 17395 | break; | 17574 | break; |
| 17396 | } | 17575 | } |
| 17397 | case TypeTableEntryIdErrorUnion: | 17576 | case ZigTypeIdErrorUnion: |
| 17398 | { | 17577 | { |
| 17399 | result = create_const_vals(1); | 17578 | result = create_const_vals(1); |
| 17400 | result->special = ConstValSpecialStatic; | 17579 | result->special = ConstValSpecialStatic; |
| ... | @@ -17417,7 +17596,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17417,7 +17596,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17417 | | 17596 | |
| 17418 | break; | 17597 | break; |
| 17419 | } | 17598 | } |
| 17420 | case TypeTableEntryIdUnion: | 17599 | case ZigTypeIdUnion: |
| 17421 | { | 17600 | { |
| 17422 | result = create_const_vals(1); | 17601 | result = create_const_vals(1); |
| 17423 | result->special = ConstValSpecialStatic; | 17602 | result->special = ConstValSpecialStatic; |
| ... | @@ -17451,7 +17630,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17451,7 +17630,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17451 | // fields: []TypeInfo.UnionField | 17630 | // fields: []TypeInfo.UnionField |
| 17452 | ensure_field_index(result->type, "fields", 2); | 17631 | ensure_field_index(result->type, "fields", 2); |
| 17453 | | 17632 | |
| 17454 | TypeTableEntry *type_info_union_field_type = ir_type_info_get_type(ira, "UnionField", nullptr); | 17633 | ZigType *type_info_union_field_type = ir_type_info_get_type(ira, "UnionField", nullptr); |
| 17455 | uint32_t union_field_count = type_entry->data.unionation.src_field_count; | 17634 | uint32_t union_field_count = type_entry->data.unionation.src_field_count; |
| 17456 | | 17635 | |
| 17457 | ConstExprValue *union_field_array = create_const_vals(1); | 17636 | ConstExprValue *union_field_array = create_const_vals(1); |
| ... | @@ -17463,7 +17642,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17463,7 +17642,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17463 | | 17642 | |
| 17464 | init_const_slice(ira->codegen, &fields[2], union_field_array, 0, union_field_count, false); | 17643 | init_const_slice(ira->codegen, &fields[2], union_field_array, 0, union_field_count, false); |
| 17465 | | 17644 | |
| 17466 | TypeTableEntry *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr); | 17645 | ZigType *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr); |
| 17467 | | 17646 | |
| 17468 | for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) { | 17647 | for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) { |
| 17469 | TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index]; | 17648 | TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index]; |
| ... | @@ -17502,7 +17681,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17502,7 +17681,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17502 | | 17681 | |
| 17503 | break; | 17682 | break; |
| 17504 | } | 17683 | } |
| 17505 | case TypeTableEntryIdStruct: | 17684 | case ZigTypeIdStruct: |
| 17506 | { | 17685 | { |
| 17507 | if (type_entry->data.structure.is_slice) { | 17686 | if (type_entry->data.structure.is_slice) { |
| 17508 | result = create_ptr_like_type_info(ira, type_entry); | 17687 | result = create_ptr_like_type_info(ira, type_entry); |
| ... | @@ -17524,7 +17703,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17524,7 +17703,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17524 | // fields: []TypeInfo.StructField | 17703 | // fields: []TypeInfo.StructField |
| 17525 | ensure_field_index(result->type, "fields", 1); | 17704 | ensure_field_index(result->type, "fields", 1); |
| 17526 | | 17705 | |
| 17527 | TypeTableEntry *type_info_struct_field_type = ir_type_info_get_type(ira, "StructField", nullptr); | 17706 | ZigType *type_info_struct_field_type = ir_type_info_get_type(ira, "StructField", nullptr); |
| 17528 | uint32_t struct_field_count = type_entry->data.structure.src_field_count; | 17707 | uint32_t struct_field_count = type_entry->data.structure.src_field_count; |
| 17529 | | 17708 | |
| 17530 | ConstExprValue *struct_field_array = create_const_vals(1); | 17709 | ConstExprValue *struct_field_array = create_const_vals(1); |
| ... | @@ -17576,7 +17755,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17576,7 +17755,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17576 | | 17755 | |
| 17577 | break; | 17756 | break; |
| 17578 | } | 17757 | } |
| 17579 | case TypeTableEntryIdFn: | 17758 | case ZigTypeIdFn: |
| 17580 | { | 17759 | { |
| 17581 | result = create_const_vals(1); | 17760 | result = create_const_vals(1); |
| 17582 | result->special = ConstValSpecialStatic; | 17761 | result->special = ConstValSpecialStatic; |
| ... | @@ -17629,7 +17808,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17629,7 +17808,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17629 | fields[4].data.x_optional = async_alloc_type; | 17808 | fields[4].data.x_optional = async_alloc_type; |
| 17630 | } | 17809 | } |
| 17631 | // args: []TypeInfo.FnArg | 17810 | // args: []TypeInfo.FnArg |
| 17632 | TypeTableEntry *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr); | 17811 | ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr); |
| 17633 | size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count - | 17812 | size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count - |
| 17634 | (is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC); | 17813 | (is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC); |
| 17635 | | 17814 | |
| ... | @@ -17681,10 +17860,10 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17681,10 +17860,10 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17681 | | 17860 | |
| 17682 | break; | 17861 | break; |
| 17683 | } | 17862 | } |
| 17684 | case TypeTableEntryIdBoundFn: | 17863 | case ZigTypeIdBoundFn: |
| 17685 | { | 17864 | { |
| 17686 | TypeTableEntry *fn_type = type_entry->data.bound_fn.fn_type; | 17865 | ZigType *fn_type = type_entry->data.bound_fn.fn_type; |
| 17687 | assert(fn_type->id == TypeTableEntryIdFn); | 17866 | assert(fn_type->id == ZigTypeIdFn); |
| 17688 | if ((err = ir_make_type_info_value(ira, fn_type, &result))) | 17867 | if ((err = ir_make_type_info_value(ira, fn_type, &result))) |
| 17689 | return err; | 17868 | return err; |
| 17690 | | 17869 | |
| ... | @@ -17698,16 +17877,16 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, | ... | @@ -17698,16 +17877,16 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17698 | return ErrorNone; | 17877 | return ErrorNone; |
| 17699 | } | 17878 | } |
| 17700 | | 17879 | |
| 17701 | static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira, | 17880 | static ZigType *ir_analyze_instruction_type_info(IrAnalyze *ira, |
| 17702 | IrInstructionTypeInfo *instruction) | 17881 | IrInstructionTypeInfo *instruction) |
| 17703 | { | 17882 | { |
| 17704 | Error err; | 17883 | Error err; |
| 17705 | IrInstruction *type_value = instruction->type_value->other; | 17884 | IrInstruction *type_value = instruction->type_value->other; |
| 17706 | TypeTableEntry *type_entry = ir_resolve_type(ira, type_value); | 17885 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 17707 | if (type_is_invalid(type_entry)) | 17886 | if (type_is_invalid(type_entry)) |
| 17708 | return ira->codegen->builtin_types.entry_invalid; | 17887 | return ira->codegen->builtin_types.entry_invalid; |
| 17709 | | 17888 | |
| 17710 | TypeTableEntry *result_type = ir_type_info_get_type(ira, nullptr, nullptr); | 17889 | ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr); |
| 17711 | | 17890 | |
| 17712 | ConstExprValue *payload; | 17891 | ConstExprValue *payload; |
| 17713 | if ((err = ir_make_type_info_value(ira, type_entry, &payload))) | 17892 | if ((err = ir_make_type_info_value(ira, type_entry, &payload))) |
| ... | @@ -17719,7 +17898,7 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira, | ... | @@ -17719,7 +17898,7 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira, |
| 17719 | out_val->data.x_union.payload = payload; | 17898 | out_val->data.x_union.payload = payload; |
| 17720 | | 17899 | |
| 17721 | if (payload != nullptr) { | 17900 | if (payload != nullptr) { |
| 17722 | assert(payload->type->id == TypeTableEntryIdStruct); | 17901 | assert(payload->type->id == ZigTypeIdStruct); |
| 17723 | payload->data.x_struct.parent.id = ConstParentIdUnion; | 17902 | payload->data.x_struct.parent.id = ConstParentIdUnion; |
| 17724 | payload->data.x_struct.parent.data.p_union.union_val = out_val; | 17903 | payload->data.x_struct.parent.data.p_union.union_val = out_val; |
| 17725 | } | 17904 | } |
| ... | @@ -17727,24 +17906,24 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira, | ... | @@ -17727,24 +17906,24 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira, |
| 17727 | return result_type; | 17906 | return result_type; |
| 17728 | } | 17907 | } |
| 17729 | | 17908 | |
| 17730 | static TypeTableEntry *ir_analyze_instruction_type_id(IrAnalyze *ira, | 17909 | static ZigType *ir_analyze_instruction_type_id(IrAnalyze *ira, |
| 17731 | IrInstructionTypeId *instruction) | 17910 | IrInstructionTypeId *instruction) |
| 17732 | { | 17911 | { |
| 17733 | IrInstruction *type_value = instruction->type_value->other; | 17912 | IrInstruction *type_value = instruction->type_value->other; |
| 17734 | TypeTableEntry *type_entry = ir_resolve_type(ira, type_value); | 17913 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 17735 | if (type_is_invalid(type_entry)) | 17914 | if (type_is_invalid(type_entry)) |
| 17736 | return ira->codegen->builtin_types.entry_invalid; | 17915 | return ira->codegen->builtin_types.entry_invalid; |
| 17737 | | 17916 | |
| 17738 | ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeId"); | 17917 | ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeId"); |
| 17739 | assert(var_value->type->id == TypeTableEntryIdMetaType); | 17918 | assert(var_value->type->id == ZigTypeIdMetaType); |
| 17740 | TypeTableEntry *result_type = var_value->data.x_type; | 17919 | ZigType *result_type = var_value->data.x_type; |
| 17741 | | 17920 | |
| 17742 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 17921 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 17743 | bigint_init_unsigned(&out_val->data.x_enum_tag, type_id_index(type_entry)); | 17922 | bigint_init_unsigned(&out_val->data.x_enum_tag, type_id_index(type_entry)); |
| 17744 | return result_type; | 17923 | return result_type; |
| 17745 | } | 17924 | } |
| 17746 | | 17925 | |
| 17747 | static TypeTableEntry *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira, | 17926 | static ZigType *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira, |
| 17748 | IrInstructionSetEvalBranchQuota *instruction) | 17927 | IrInstructionSetEvalBranchQuota *instruction) |
| 17749 | { | 17928 | { |
| 17750 | if (ira->new_irb.exec->parent_exec != nullptr && !ira->new_irb.exec->is_generic_instantiation) { | 17929 | if (ira->new_irb.exec->parent_exec != nullptr && !ira->new_irb.exec->is_generic_instantiation) { |
| ... | @@ -17765,9 +17944,9 @@ static TypeTableEntry *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *i | ... | @@ -17765,9 +17944,9 @@ static TypeTableEntry *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *i |
| 17765 | return ira->codegen->builtin_types.entry_void; | 17944 | return ira->codegen->builtin_types.entry_void; |
| 17766 | } | 17945 | } |
| 17767 | | 17946 | |
| 17768 | static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) { | 17947 | static ZigType *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) { |
| 17769 | IrInstruction *type_value = instruction->type_value->other; | 17948 | IrInstruction *type_value = instruction->type_value->other; |
| 17770 | TypeTableEntry *type_entry = ir_resolve_type(ira, type_value); | 17949 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 17771 | if (type_is_invalid(type_entry)) | 17950 | if (type_is_invalid(type_entry)) |
| 17772 | return ira->codegen->builtin_types.entry_invalid; | 17951 | return ira->codegen->builtin_types.entry_invalid; |
| 17773 | | 17952 | |
| ... | @@ -17779,7 +17958,7 @@ static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstru | ... | @@ -17779,7 +17958,7 @@ static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstru |
| 17779 | return out_val->type; | 17958 | return out_val->type; |
| 17780 | } | 17959 | } |
| 17781 | | 17960 | |
| 17782 | static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) { | 17961 | static ZigType *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) { |
| 17783 | AstNode *node = instruction->base.source_node; | 17962 | AstNode *node = instruction->base.source_node; |
| 17784 | assert(node->type == NodeTypeFnCallExpr); | 17963 | assert(node->type == NodeTypeFnCallExpr); |
| 17785 | AstNode *block_node = node->data.fn_call_expr.params.at(0); | 17964 | AstNode *block_node = node->data.fn_call_expr.params.at(0); |
| ... | @@ -17787,7 +17966,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc | ... | @@ -17787,7 +17966,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc |
| 17787 | ScopeCImport *cimport_scope = create_cimport_scope(node, instruction->base.scope); | 17966 | ScopeCImport *cimport_scope = create_cimport_scope(node, instruction->base.scope); |
| 17788 | | 17967 | |
| 17789 | // Execute the C import block like an inline function | 17968 | // Execute the C import block like an inline function |
| 17790 | TypeTableEntry *void_type = ira->codegen->builtin_types.entry_void; | 17969 | ZigType *void_type = ira->codegen->builtin_types.entry_void; |
| 17791 | IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type, | 17970 | IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type, |
| 17792 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, | 17971 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, |
| 17793 | &cimport_scope->buf, block_node, nullptr, nullptr); | 17972 | &cimport_scope->buf, block_node, nullptr, nullptr); |
| ... | @@ -17838,7 +18017,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc | ... | @@ -17838,7 +18017,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc |
| 17838 | return ira->codegen->builtin_types.entry_namespace; | 18017 | return ira->codegen->builtin_types.entry_namespace; |
| 17839 | } | 18018 | } |
| 17840 | | 18019 | |
| 17841 | static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) { | 18020 | static ZigType *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) { |
| 17842 | IrInstruction *name_value = instruction->name->other; | 18021 | IrInstruction *name_value = instruction->name->other; |
| 17843 | if (type_is_invalid(name_value->value.type)) | 18022 | if (type_is_invalid(name_value->value.type)) |
| 17844 | return ira->codegen->builtin_types.entry_invalid; | 18023 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -17857,7 +18036,7 @@ static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstru | ... | @@ -17857,7 +18036,7 @@ static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstru |
| 17857 | return ira->codegen->builtin_types.entry_void; | 18036 | return ira->codegen->builtin_types.entry_void; |
| 17858 | } | 18037 | } |
| 17859 | | 18038 | |
| 17860 | static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) { | 18039 | static ZigType *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) { |
| 17861 | IrInstruction *name = instruction->name->other; | 18040 | IrInstruction *name = instruction->name->other; |
| 17862 | if (type_is_invalid(name->value.type)) | 18041 | if (type_is_invalid(name->value.type)) |
| 17863 | return ira->codegen->builtin_types.entry_invalid; | 18042 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -17884,7 +18063,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc | ... | @@ -17884,7 +18063,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc |
| 17884 | return ira->codegen->builtin_types.entry_void; | 18063 | return ira->codegen->builtin_types.entry_void; |
| 17885 | } | 18064 | } |
| 17886 | | 18065 | |
| 17887 | static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) { | 18066 | static ZigType *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) { |
| 17888 | IrInstruction *name = instruction->name->other; | 18067 | IrInstruction *name = instruction->name->other; |
| 17889 | if (type_is_invalid(name->value.type)) | 18068 | if (type_is_invalid(name->value.type)) |
| 17890 | return ira->codegen->builtin_types.entry_invalid; | 18069 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -17903,7 +18082,7 @@ static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstruct | ... | @@ -17903,7 +18082,7 @@ static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstruct |
| 17903 | return ira->codegen->builtin_types.entry_void; | 18082 | return ira->codegen->builtin_types.entry_void; |
| 17904 | } | 18083 | } |
| 17905 | | 18084 | |
| 17906 | static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) { | 18085 | static ZigType *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) { |
| 17907 | IrInstruction *name = instruction->name->other; | 18086 | IrInstruction *name = instruction->name->other; |
| 17908 | if (type_is_invalid(name->value.type)) | 18087 | if (type_is_invalid(name->value.type)) |
| 17909 | return ira->codegen->builtin_types.entry_invalid; | 18088 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -17917,8 +18096,11 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr | ... | @@ -17917,8 +18096,11 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr |
| 17917 | Buf source_dir_path = BUF_INIT; | 18096 | Buf source_dir_path = BUF_INIT; |
| 17918 | os_path_dirname(import->path, &source_dir_path); | 18097 | os_path_dirname(import->path, &source_dir_path); |
| 17919 | | 18098 | |
| 17920 | Buf file_path = BUF_INIT; | 18099 | Buf *resolve_paths[] = { |
| 17921 | os_path_resolve(&source_dir_path, rel_file_path, &file_path); | 18100 | &source_dir_path, |
| | 18101 | rel_file_path, |
| | 18102 | }; |
| | 18103 | Buf file_path = os_path_resolve(resolve_paths, 2); |
| 17922 | | 18104 | |
| 17923 | // load from file system into const expr | 18105 | // load from file system into const expr |
| 17924 | Buf *file_contents = buf_alloc(); | 18106 | Buf *file_contents = buf_alloc(); |
| ... | @@ -17942,8 +18124,8 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr | ... | @@ -17942,8 +18124,8 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr |
| 17942 | return get_array_type(ira->codegen, ira->codegen->builtin_types.entry_u8, buf_len(file_contents)); | 18124 | return get_array_type(ira->codegen, ira->codegen->builtin_types.entry_u8, buf_len(file_contents)); |
| 17943 | } | 18125 | } |
| 17944 | | 18126 | |
| 17945 | static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) { | 18127 | static ZigType *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) { |
| 17946 | TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->other); | 18128 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->other); |
| 17947 | if (type_is_invalid(operand_type)) | 18129 | if (type_is_invalid(operand_type)) |
| 17948 | return ira->codegen->builtin_types.entry_invalid; | 18130 | return ira->codegen->builtin_types.entry_invalid; |
| 17949 | | 18131 | |
| ... | @@ -17952,7 +18134,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct | ... | @@ -17952,7 +18134,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct |
| 17952 | return ira->codegen->builtin_types.entry_invalid; | 18134 | return ira->codegen->builtin_types.entry_invalid; |
| 17953 | | 18135 | |
| 17954 | // TODO let this be volatile | 18136 | // TODO let this be volatile |
| 17955 | TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); | 18137 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 17956 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type); | 18138 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type); |
| 17957 | if (type_is_invalid(casted_ptr->value.type)) | 18139 | if (type_is_invalid(casted_ptr->value.type)) |
| 17958 | return ira->codegen->builtin_types.entry_invalid; | 18140 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18023,7 +18205,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct | ... | @@ -18023,7 +18205,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct |
| 18023 | return result->value.type; | 18205 | return result->value.type; |
| 18024 | } | 18206 | } |
| 18025 | | 18207 | |
| 18026 | static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) { | 18208 | static ZigType *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) { |
| 18027 | IrInstruction *order_value = instruction->order_value->other; | 18209 | IrInstruction *order_value = instruction->order_value->other; |
| 18028 | if (type_is_invalid(order_value->value.type)) | 18210 | if (type_is_invalid(order_value->value.type)) |
| 18029 | return ira->codegen->builtin_types.entry_invalid; | 18211 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18036,26 +18218,26 @@ static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructio | ... | @@ -18036,26 +18218,26 @@ static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructio |
| 18036 | return ira->codegen->builtin_types.entry_void; | 18218 | return ira->codegen->builtin_types.entry_void; |
| 18037 | } | 18219 | } |
| 18038 | | 18220 | |
| 18039 | static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) { | 18221 | static ZigType *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) { |
| 18040 | IrInstruction *dest_type_value = instruction->dest_type->other; | 18222 | IrInstruction *dest_type_value = instruction->dest_type->other; |
| 18041 | TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value); | 18223 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 18042 | if (type_is_invalid(dest_type)) | 18224 | if (type_is_invalid(dest_type)) |
| 18043 | return ira->codegen->builtin_types.entry_invalid; | 18225 | return ira->codegen->builtin_types.entry_invalid; |
| 18044 | | 18226 | |
| 18045 | if (dest_type->id != TypeTableEntryIdInt && | 18227 | if (dest_type->id != ZigTypeIdInt && |
| 18046 | dest_type->id != TypeTableEntryIdComptimeInt) | 18228 | dest_type->id != ZigTypeIdComptimeInt) |
| 18047 | { | 18229 | { |
| 18048 | ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); | 18230 | ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 18049 | return ira->codegen->builtin_types.entry_invalid; | 18231 | return ira->codegen->builtin_types.entry_invalid; |
| 18050 | } | 18232 | } |
| 18051 | | 18233 | |
| 18052 | IrInstruction *target = instruction->target->other; | 18234 | IrInstruction *target = instruction->target->other; |
| 18053 | TypeTableEntry *src_type = target->value.type; | 18235 | ZigType *src_type = target->value.type; |
| 18054 | if (type_is_invalid(src_type)) | 18236 | if (type_is_invalid(src_type)) |
| 18055 | return ira->codegen->builtin_types.entry_invalid; | 18237 | return ira->codegen->builtin_types.entry_invalid; |
| 18056 | | 18238 | |
| 18057 | if (src_type->id != TypeTableEntryIdInt && | 18239 | if (src_type->id != ZigTypeIdInt && |
| 18058 | src_type->id != TypeTableEntryIdComptimeInt) | 18240 | src_type->id != ZigTypeIdComptimeInt) |
| 18059 | { | 18241 | { |
| 18060 | ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name))); | 18242 | ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name))); |
| 18061 | return ira->codegen->builtin_types.entry_invalid; | 18243 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18084,12 +18266,12 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc | ... | @@ -18084,12 +18266,12 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc |
| 18084 | return dest_type; | 18266 | return dest_type; |
| 18085 | } | 18267 | } |
| 18086 | | 18268 | |
| 18087 | static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) { | 18269 | static ZigType *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) { |
| 18088 | TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other); | 18270 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18089 | if (type_is_invalid(dest_type)) | 18271 | if (type_is_invalid(dest_type)) |
| 18090 | return ira->codegen->builtin_types.entry_invalid; | 18272 | return ira->codegen->builtin_types.entry_invalid; |
| 18091 | | 18273 | |
| 18092 | if (dest_type->id != TypeTableEntryIdInt) { | 18274 | if (dest_type->id != ZigTypeIdInt) { |
| 18093 | ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); | 18275 | ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 18094 | return ira->codegen->builtin_types.entry_invalid; | 18276 | return ira->codegen->builtin_types.entry_invalid; |
| 18095 | } | 18277 | } |
| ... | @@ -18098,7 +18280,7 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc | ... | @@ -18098,7 +18280,7 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc |
| 18098 | if (type_is_invalid(target->value.type)) | 18280 | if (type_is_invalid(target->value.type)) |
| 18099 | return ira->codegen->builtin_types.entry_invalid; | 18281 | return ira->codegen->builtin_types.entry_invalid; |
| 18100 | | 18282 | |
| 18101 | if (target->value.type->id == TypeTableEntryIdComptimeInt) { | 18283 | if (target->value.type->id == ZigTypeIdComptimeInt) { |
| 18102 | if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) { | 18284 | if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) { |
| 18103 | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, | 18285 | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, |
| 18104 | CastOpNumLitToConcrete, false); | 18286 | CastOpNumLitToConcrete, false); |
| ... | @@ -18111,7 +18293,7 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc | ... | @@ -18111,7 +18293,7 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc |
| 18111 | } | 18293 | } |
| 18112 | } | 18294 | } |
| 18113 | | 18295 | |
| 18114 | if (target->value.type->id != TypeTableEntryIdInt) { | 18296 | if (target->value.type->id != ZigTypeIdInt) { |
| 18115 | ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'", | 18297 | ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'", |
| 18116 | buf_ptr(&target->value.type->name))); | 18298 | buf_ptr(&target->value.type->name))); |
| 18117 | return ira->codegen->builtin_types.entry_invalid; | 18299 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18125,12 +18307,12 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc | ... | @@ -18125,12 +18307,12 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc |
| 18125 | return dest_type; | 18307 | return dest_type; |
| 18126 | } | 18308 | } |
| 18127 | | 18309 | |
| 18128 | static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) { | 18310 | static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) { |
| 18129 | TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other); | 18311 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18130 | if (type_is_invalid(dest_type)) | 18312 | if (type_is_invalid(dest_type)) |
| 18131 | return ira->codegen->builtin_types.entry_invalid; | 18313 | return ira->codegen->builtin_types.entry_invalid; |
| 18132 | | 18314 | |
| 18133 | if (dest_type->id != TypeTableEntryIdFloat) { | 18315 | if (dest_type->id != ZigTypeIdFloat) { |
| 18134 | ir_add_error(ira, instruction->dest_type, | 18316 | ir_add_error(ira, instruction->dest_type, |
| 18135 | buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name))); | 18317 | buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name))); |
| 18136 | return ira->codegen->builtin_types.entry_invalid; | 18318 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18140,12 +18322,12 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr | ... | @@ -18140,12 +18322,12 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr |
| 18140 | if (type_is_invalid(target->value.type)) | 18322 | if (type_is_invalid(target->value.type)) |
| 18141 | return ira->codegen->builtin_types.entry_invalid; | 18323 | return ira->codegen->builtin_types.entry_invalid; |
| 18142 | | 18324 | |
| 18143 | if (target->value.type->id == TypeTableEntryIdComptimeInt || | 18325 | if (target->value.type->id == ZigTypeIdComptimeInt || |
| 18144 | target->value.type->id == TypeTableEntryIdComptimeFloat) | 18326 | target->value.type->id == ZigTypeIdComptimeFloat) |
| 18145 | { | 18327 | { |
| 18146 | if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) { | 18328 | if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) { |
| 18147 | CastOp op; | 18329 | CastOp op; |
| 18148 | if (target->value.type->id == TypeTableEntryIdComptimeInt) { | 18330 | if (target->value.type->id == ZigTypeIdComptimeInt) { |
| 18149 | op = CastOpIntToFloat; | 18331 | op = CastOpIntToFloat; |
| 18150 | } else { | 18332 | } else { |
| 18151 | op = CastOpNumLitToConcrete; | 18333 | op = CastOpNumLitToConcrete; |
| ... | @@ -18160,7 +18342,7 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr | ... | @@ -18160,7 +18342,7 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr |
| 18160 | } | 18342 | } |
| 18161 | } | 18343 | } |
| 18162 | | 18344 | |
| 18163 | if (target->value.type->id != TypeTableEntryIdFloat) { | 18345 | if (target->value.type->id != ZigTypeIdFloat) { |
| 18164 | ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", | 18346 | ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", |
| 18165 | buf_ptr(&target->value.type->name))); | 18347 | buf_ptr(&target->value.type->name))); |
| 18166 | return ira->codegen->builtin_types.entry_invalid; | 18348 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18173,12 +18355,12 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr | ... | @@ -18173,12 +18355,12 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr |
| 18173 | return dest_type; | 18355 | return dest_type; |
| 18174 | } | 18356 | } |
| 18175 | | 18357 | |
| 18176 | static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) { | 18358 | static ZigType *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) { |
| 18177 | TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other); | 18359 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18178 | if (type_is_invalid(dest_type)) | 18360 | if (type_is_invalid(dest_type)) |
| 18179 | return ira->codegen->builtin_types.entry_invalid; | 18361 | return ira->codegen->builtin_types.entry_invalid; |
| 18180 | | 18362 | |
| 18181 | if (dest_type->id != TypeTableEntryIdErrorSet) { | 18363 | if (dest_type->id != ZigTypeIdErrorSet) { |
| 18182 | ir_add_error(ira, instruction->dest_type, | 18364 | ir_add_error(ira, instruction->dest_type, |
| 18183 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name))); | 18365 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name))); |
| 18184 | return ira->codegen->builtin_types.entry_invalid; | 18366 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18188,7 +18370,7 @@ static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrIns | ... | @@ -18188,7 +18370,7 @@ static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrIns |
| 18188 | if (type_is_invalid(target->value.type)) | 18370 | if (type_is_invalid(target->value.type)) |
| 18189 | return ira->codegen->builtin_types.entry_invalid; | 18371 | return ira->codegen->builtin_types.entry_invalid; |
| 18190 | | 18372 | |
| 18191 | if (target->value.type->id != TypeTableEntryIdErrorSet) { | 18373 | if (target->value.type->id != ZigTypeIdErrorSet) { |
| 18192 | ir_add_error(ira, instruction->target, | 18374 | ir_add_error(ira, instruction->target, |
| 18193 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value.type->name))); | 18375 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value.type->name))); |
| 18194 | return ira->codegen->builtin_types.entry_invalid; | 18376 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18201,8 +18383,8 @@ static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrIns | ... | @@ -18201,8 +18383,8 @@ static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrIns |
| 18201 | return dest_type; | 18383 | return dest_type; |
| 18202 | } | 18384 | } |
| 18203 | | 18385 | |
| 18204 | static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) { | 18386 | static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) { |
| 18205 | TypeTableEntry *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->other); | 18387 | ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->other); |
| 18206 | if (type_is_invalid(dest_child_type)) | 18388 | if (type_is_invalid(dest_child_type)) |
| 18207 | return ira->codegen->builtin_types.entry_invalid; | 18389 | return ira->codegen->builtin_types.entry_invalid; |
| 18208 | | 18390 | |
| ... | @@ -18213,12 +18395,12 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr | ... | @@ -18213,12 +18395,12 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr |
| 18213 | bool src_ptr_const; | 18395 | bool src_ptr_const; |
| 18214 | bool src_ptr_volatile; | 18396 | bool src_ptr_volatile; |
| 18215 | uint32_t src_ptr_align; | 18397 | uint32_t src_ptr_align; |
| 18216 | if (target->value.type->id == TypeTableEntryIdPointer) { | 18398 | if (target->value.type->id == ZigTypeIdPointer) { |
| 18217 | src_ptr_const = target->value.type->data.pointer.is_const; | 18399 | src_ptr_const = target->value.type->data.pointer.is_const; |
| 18218 | src_ptr_volatile = target->value.type->data.pointer.is_volatile; | 18400 | src_ptr_volatile = target->value.type->data.pointer.is_volatile; |
| 18219 | src_ptr_align = target->value.type->data.pointer.alignment; | 18401 | src_ptr_align = target->value.type->data.pointer.alignment; |
| 18220 | } else if (is_slice(target->value.type)) { | 18402 | } else if (is_slice(target->value.type)) { |
| 18221 | TypeTableEntry *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; | 18403 | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; |
| 18222 | src_ptr_const = src_ptr_type->data.pointer.is_const; | 18404 | src_ptr_const = src_ptr_type->data.pointer.is_const; |
| 18223 | src_ptr_volatile = src_ptr_type->data.pointer.is_volatile; | 18405 | src_ptr_volatile = src_ptr_type->data.pointer.is_volatile; |
| 18224 | src_ptr_align = src_ptr_type->data.pointer.alignment; | 18406 | src_ptr_align = src_ptr_type->data.pointer.alignment; |
| ... | @@ -18228,15 +18410,15 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr | ... | @@ -18228,15 +18410,15 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr |
| 18228 | src_ptr_align = get_abi_alignment(ira->codegen, target->value.type); | 18410 | src_ptr_align = get_abi_alignment(ira->codegen, target->value.type); |
| 18229 | } | 18411 | } |
| 18230 | | 18412 | |
| 18231 | TypeTableEntry *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type, | 18413 | ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type, |
| 18232 | src_ptr_const, src_ptr_volatile, PtrLenUnknown, | 18414 | src_ptr_const, src_ptr_volatile, PtrLenUnknown, |
| 18233 | src_ptr_align, 0, 0); | 18415 | src_ptr_align, 0, 0); |
| 18234 | TypeTableEntry *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); | 18416 | ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); |
| 18235 | | 18417 | |
| 18236 | TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 18418 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 18237 | src_ptr_const, src_ptr_volatile, PtrLenUnknown, | 18419 | src_ptr_const, src_ptr_volatile, PtrLenUnknown, |
| 18238 | src_ptr_align, 0, 0); | 18420 | src_ptr_align, 0, 0); |
| 18239 | TypeTableEntry *u8_slice = get_slice_type(ira->codegen, u8_ptr); | 18421 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); |
| 18240 | | 18422 | |
| 18241 | IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice); | 18423 | IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice); |
| 18242 | if (type_is_invalid(casted_value->value.type)) | 18424 | if (type_is_invalid(casted_value->value.type)) |
| ... | @@ -18281,7 +18463,7 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr | ... | @@ -18281,7 +18463,7 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr |
| 18281 | return dest_slice_type; | 18463 | return dest_slice_type; |
| 18282 | } | 18464 | } |
| 18283 | | 18465 | |
| 18284 | static TypeTableEntry *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) { | 18466 | static ZigType *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) { |
| 18285 | IrInstruction *target = instruction->target->other; | 18467 | IrInstruction *target = instruction->target->other; |
| 18286 | if (type_is_invalid(target->value.type)) | 18468 | if (type_is_invalid(target->value.type)) |
| 18287 | return ira->codegen->builtin_types.entry_invalid; | 18469 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18292,20 +18474,20 @@ static TypeTableEntry *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruc | ... | @@ -18292,20 +18474,20 @@ static TypeTableEntry *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruc |
| 18292 | return ira->codegen->builtin_types.entry_invalid; | 18474 | return ira->codegen->builtin_types.entry_invalid; |
| 18293 | } | 18475 | } |
| 18294 | | 18476 | |
| 18295 | TypeTableEntry *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; | 18477 | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; |
| 18296 | | 18478 | |
| 18297 | TypeTableEntry *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 18479 | ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 18298 | src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown, | 18480 | src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown, |
| 18299 | src_ptr_type->data.pointer.alignment, 0, 0); | 18481 | src_ptr_type->data.pointer.alignment, 0, 0); |
| 18300 | TypeTableEntry *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); | 18482 | ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); |
| 18301 | | 18483 | |
| 18302 | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_slice_type, CastOpResizeSlice, true); | 18484 | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_slice_type, CastOpResizeSlice, true); |
| 18303 | ir_link_new_instruction(result, &instruction->base); | 18485 | ir_link_new_instruction(result, &instruction->base); |
| 18304 | return dest_slice_type; | 18486 | return dest_slice_type; |
| 18305 | } | 18487 | } |
| 18306 | | 18488 | |
| 18307 | static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) { | 18489 | static ZigType *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) { |
| 18308 | TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other); | 18490 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18309 | if (type_is_invalid(dest_type)) | 18491 | if (type_is_invalid(dest_type)) |
| 18310 | return ira->codegen->builtin_types.entry_invalid; | 18492 | return ira->codegen->builtin_types.entry_invalid; |
| 18311 | | 18493 | |
| ... | @@ -18313,7 +18495,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrIns | ... | @@ -18313,7 +18495,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrIns |
| 18313 | if (type_is_invalid(target->value.type)) | 18495 | if (type_is_invalid(target->value.type)) |
| 18314 | return ira->codegen->builtin_types.entry_invalid; | 18496 | return ira->codegen->builtin_types.entry_invalid; |
| 18315 | | 18497 | |
| 18316 | if (target->value.type->id != TypeTableEntryIdInt && target->value.type->id != TypeTableEntryIdComptimeInt) { | 18498 | if (target->value.type->id != ZigTypeIdInt && target->value.type->id != ZigTypeIdComptimeInt) { |
| 18317 | ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'", | 18499 | ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'", |
| 18318 | buf_ptr(&target->value.type->name))); | 18500 | buf_ptr(&target->value.type->name))); |
| 18319 | return ira->codegen->builtin_types.entry_invalid; | 18501 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18324,8 +18506,8 @@ static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrIns | ... | @@ -18324,8 +18506,8 @@ static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrIns |
| 18324 | return dest_type; | 18506 | return dest_type; |
| 18325 | } | 18507 | } |
| 18326 | | 18508 | |
| 18327 | static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) { | 18509 | static ZigType *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) { |
| 18328 | TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other); | 18510 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18329 | if (type_is_invalid(dest_type)) | 18511 | if (type_is_invalid(dest_type)) |
| 18330 | return ira->codegen->builtin_types.entry_invalid; | 18512 | return ira->codegen->builtin_types.entry_invalid; |
| 18331 | | 18513 | |
| ... | @@ -18333,18 +18515,32 @@ static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrIns | ... | @@ -18333,18 +18515,32 @@ static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrIns |
| 18333 | if (type_is_invalid(target->value.type)) | 18515 | if (type_is_invalid(target->value.type)) |
| 18334 | return ira->codegen->builtin_types.entry_invalid; | 18516 | return ira->codegen->builtin_types.entry_invalid; |
| 18335 | | 18517 | |
| | 18518 | if (target->value.type->id == ZigTypeIdComptimeInt) { |
| | 18519 | IrInstruction *casted_value = ir_implicit_cast(ira, target, dest_type); |
| | 18520 | if (type_is_invalid(casted_value->value.type)) |
| | 18521 | return ira->codegen->builtin_types.entry_invalid; |
| | 18522 | ir_link_new_instruction(casted_value, &instruction->base); |
| | 18523 | return casted_value->value.type; |
| | 18524 | } |
| | 18525 | |
| | 18526 | if (target->value.type->id != ZigTypeIdFloat && target->value.type->id != ZigTypeIdComptimeFloat) { |
| | 18527 | ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", |
| | 18528 | buf_ptr(&target->value.type->name))); |
| | 18529 | return ira->codegen->builtin_types.entry_invalid; |
| | 18530 | } |
| | 18531 | |
| 18336 | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt, false); | 18532 | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt, false); |
| 18337 | ir_link_new_instruction(result, &instruction->base); | 18533 | ir_link_new_instruction(result, &instruction->base); |
| 18338 | return dest_type; | 18534 | return dest_type; |
| 18339 | } | 18535 | } |
| 18340 | | 18536 | |
| 18341 | static TypeTableEntry *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) { | 18537 | static ZigType *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) { |
| 18342 | IrInstruction *target = instruction->target->other; | 18538 | IrInstruction *target = instruction->target->other; |
| 18343 | if (type_is_invalid(target->value.type)) | 18539 | if (type_is_invalid(target->value.type)) |
| 18344 | return ira->codegen->builtin_types.entry_invalid; | 18540 | return ira->codegen->builtin_types.entry_invalid; |
| 18345 | | 18541 | |
| 18346 | IrInstruction *casted_target; | 18542 | IrInstruction *casted_target; |
| 18347 | if (target->value.type->id == TypeTableEntryIdErrorSet) { | 18543 | if (target->value.type->id == ZigTypeIdErrorSet) { |
| 18348 | casted_target = target; | 18544 | casted_target = target; |
| 18349 | } else { | 18545 | } else { |
| 18350 | casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set); | 18546 | casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set); |
| ... | @@ -18357,7 +18553,7 @@ static TypeTableEntry *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstr | ... | @@ -18357,7 +18553,7 @@ static TypeTableEntry *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstr |
| 18357 | return result->value.type; | 18553 | return result->value.type; |
| 18358 | } | 18554 | } |
| 18359 | | 18555 | |
| 18360 | static TypeTableEntry *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) { | 18556 | static ZigType *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) { |
| 18361 | IrInstruction *target = instruction->target->other; | 18557 | IrInstruction *target = instruction->target->other; |
| 18362 | if (type_is_invalid(target->value.type)) | 18558 | if (type_is_invalid(target->value.type)) |
| 18363 | return ira->codegen->builtin_types.entry_invalid; | 18559 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18371,12 +18567,12 @@ static TypeTableEntry *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstr | ... | @@ -18371,12 +18567,12 @@ static TypeTableEntry *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstr |
| 18371 | return result->value.type; | 18567 | return result->value.type; |
| 18372 | } | 18568 | } |
| 18373 | | 18569 | |
| 18374 | static TypeTableEntry *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) { | 18570 | static ZigType *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) { |
| 18375 | IrInstruction *target = instruction->target->other; | 18571 | IrInstruction *target = instruction->target->other; |
| 18376 | if (type_is_invalid(target->value.type)) | 18572 | if (type_is_invalid(target->value.type)) |
| 18377 | return ira->codegen->builtin_types.entry_invalid; | 18573 | return ira->codegen->builtin_types.entry_invalid; |
| 18378 | | 18574 | |
| 18379 | if (target->value.type->id != TypeTableEntryIdBool) { | 18575 | if (target->value.type->id != ZigTypeIdBool) { |
| 18380 | ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'", | 18576 | ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'", |
| 18381 | buf_ptr(&target->value.type->name))); | 18577 | buf_ptr(&target->value.type->name))); |
| 18382 | return ira->codegen->builtin_types.entry_invalid; | 18578 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18392,13 +18588,13 @@ static TypeTableEntry *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInst | ... | @@ -18392,13 +18588,13 @@ static TypeTableEntry *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInst |
| 18392 | return ira->codegen->builtin_types.entry_num_lit_int; | 18588 | return ira->codegen->builtin_types.entry_num_lit_int; |
| 18393 | } | 18589 | } |
| 18394 | | 18590 | |
| 18395 | TypeTableEntry *u1_type = get_int_type(ira->codegen, false, 1); | 18591 | ZigType *u1_type = get_int_type(ira->codegen, false, 1); |
| 18396 | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt, false); | 18592 | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt, false); |
| 18397 | ir_link_new_instruction(result, &instruction->base); | 18593 | ir_link_new_instruction(result, &instruction->base); |
| 18398 | return u1_type; | 18594 | return u1_type; |
| 18399 | } | 18595 | } |
| 18400 | | 18596 | |
| 18401 | static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) { | 18597 | static ZigType *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) { |
| 18402 | IrInstruction *is_signed_value = instruction->is_signed->other; | 18598 | IrInstruction *is_signed_value = instruction->is_signed->other; |
| 18403 | bool is_signed; | 18599 | bool is_signed; |
| 18404 | if (!ir_resolve_bool(ira, is_signed_value, &is_signed)) | 18600 | if (!ir_resolve_bool(ira, is_signed_value, &is_signed)) |
| ... | @@ -18414,12 +18610,12 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc | ... | @@ -18414,12 +18610,12 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc |
| 18414 | return ira->codegen->builtin_types.entry_type; | 18610 | return ira->codegen->builtin_types.entry_type; |
| 18415 | } | 18611 | } |
| 18416 | | 18612 | |
| 18417 | static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) { | 18613 | static ZigType *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) { |
| 18418 | IrInstruction *value = instruction->value->other; | 18614 | IrInstruction *value = instruction->value->other; |
| 18419 | if (type_is_invalid(value->value.type)) | 18615 | if (type_is_invalid(value->value.type)) |
| 18420 | return ira->codegen->builtin_types.entry_invalid; | 18616 | return ira->codegen->builtin_types.entry_invalid; |
| 18421 | | 18617 | |
| 18422 | TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool; | 18618 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| 18423 | | 18619 | |
| 18424 | IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type); | 18620 | IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type); |
| 18425 | if (type_is_invalid(casted_value->value.type)) | 18621 | if (type_is_invalid(casted_value->value.type)) |
| ... | @@ -18439,7 +18635,7 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc | ... | @@ -18439,7 +18635,7 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc |
| 18439 | return bool_type; | 18635 | return bool_type; |
| 18440 | } | 18636 | } |
| 18441 | | 18637 | |
| 18442 | static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) { | 18638 | static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) { |
| 18443 | IrInstruction *dest_ptr = instruction->dest_ptr->other; | 18639 | IrInstruction *dest_ptr = instruction->dest_ptr->other; |
| 18444 | if (type_is_invalid(dest_ptr->value.type)) | 18640 | if (type_is_invalid(dest_ptr->value.type)) |
| 18445 | return ira->codegen->builtin_types.entry_invalid; | 18641 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18452,15 +18648,15 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi | ... | @@ -18452,15 +18648,15 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi |
| 18452 | if (type_is_invalid(count_value->value.type)) | 18648 | if (type_is_invalid(count_value->value.type)) |
| 18453 | return ira->codegen->builtin_types.entry_invalid; | 18649 | return ira->codegen->builtin_types.entry_invalid; |
| 18454 | | 18650 | |
| 18455 | TypeTableEntry *dest_uncasted_type = dest_ptr->value.type; | 18651 | ZigType *dest_uncasted_type = dest_ptr->value.type; |
| 18456 | bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) && | 18652 | bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) && |
| 18457 | dest_uncasted_type->data.pointer.is_volatile; | 18653 | dest_uncasted_type->data.pointer.is_volatile; |
| 18458 | | 18654 | |
| 18459 | TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; | 18655 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 18460 | TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8; | 18656 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 18461 | uint32_t dest_align = (dest_uncasted_type->id == TypeTableEntryIdPointer) ? | 18657 | uint32_t dest_align = (dest_uncasted_type->id == ZigTypeIdPointer) ? |
| 18462 | dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); | 18658 | dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); |
| 18463 | TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, | 18659 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, |
| 18464 | PtrLenUnknown, dest_align, 0, 0); | 18660 | PtrLenUnknown, dest_align, 0, 0); |
| 18465 | | 18661 | |
| 18466 | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr); | 18662 | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr); |
| ... | @@ -18531,7 +18727,7 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi | ... | @@ -18531,7 +18727,7 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi |
| 18531 | return ira->codegen->builtin_types.entry_void; | 18727 | return ira->codegen->builtin_types.entry_void; |
| 18532 | } | 18728 | } |
| 18533 | | 18729 | |
| 18534 | static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) { | 18730 | static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) { |
| 18535 | IrInstruction *dest_ptr = instruction->dest_ptr->other; | 18731 | IrInstruction *dest_ptr = instruction->dest_ptr->other; |
| 18536 | if (type_is_invalid(dest_ptr->value.type)) | 18732 | if (type_is_invalid(dest_ptr->value.type)) |
| 18537 | return ira->codegen->builtin_types.entry_invalid; | 18733 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18544,22 +18740,22 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi | ... | @@ -18544,22 +18740,22 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi |
| 18544 | if (type_is_invalid(count_value->value.type)) | 18740 | if (type_is_invalid(count_value->value.type)) |
| 18545 | return ira->codegen->builtin_types.entry_invalid; | 18741 | return ira->codegen->builtin_types.entry_invalid; |
| 18546 | | 18742 | |
| 18547 | TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8; | 18743 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 18548 | TypeTableEntry *dest_uncasted_type = dest_ptr->value.type; | 18744 | ZigType *dest_uncasted_type = dest_ptr->value.type; |
| 18549 | TypeTableEntry *src_uncasted_type = src_ptr->value.type; | 18745 | ZigType *src_uncasted_type = src_ptr->value.type; |
| 18550 | bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) && | 18746 | bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) && |
| 18551 | dest_uncasted_type->data.pointer.is_volatile; | 18747 | dest_uncasted_type->data.pointer.is_volatile; |
| 18552 | bool src_is_volatile = (src_uncasted_type->id == TypeTableEntryIdPointer) && | 18748 | bool src_is_volatile = (src_uncasted_type->id == ZigTypeIdPointer) && |
| 18553 | src_uncasted_type->data.pointer.is_volatile; | 18749 | src_uncasted_type->data.pointer.is_volatile; |
| 18554 | uint32_t dest_align = (dest_uncasted_type->id == TypeTableEntryIdPointer) ? | 18750 | uint32_t dest_align = (dest_uncasted_type->id == ZigTypeIdPointer) ? |
| 18555 | dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); | 18751 | dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); |
| 18556 | uint32_t src_align = (src_uncasted_type->id == TypeTableEntryIdPointer) ? | 18752 | uint32_t src_align = (src_uncasted_type->id == ZigTypeIdPointer) ? |
| 18557 | src_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); | 18753 | src_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); |
| 18558 | | 18754 | |
| 18559 | TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; | 18755 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 18560 | TypeTableEntry *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, | 18756 | ZigType *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, |
| 18561 | PtrLenUnknown, dest_align, 0, 0); | 18757 | PtrLenUnknown, dest_align, 0, 0); |
| 18562 | TypeTableEntry *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile, | 18758 | ZigType *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile, |
| 18563 | PtrLenUnknown, src_align, 0, 0); | 18759 | PtrLenUnknown, src_align, 0, 0); |
| 18564 | | 18760 | |
| 18565 | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut); | 18761 | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut); |
| ... | @@ -18666,20 +18862,20 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi | ... | @@ -18666,20 +18862,20 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi |
| 18666 | return ira->codegen->builtin_types.entry_void; | 18862 | return ira->codegen->builtin_types.entry_void; |
| 18667 | } | 18863 | } |
| 18668 | | 18864 | |
| 18669 | static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) { | 18865 | static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) { |
| 18670 | IrInstruction *ptr_ptr = instruction->ptr->other; | 18866 | IrInstruction *ptr_ptr = instruction->ptr->other; |
| 18671 | if (type_is_invalid(ptr_ptr->value.type)) | 18867 | if (type_is_invalid(ptr_ptr->value.type)) |
| 18672 | return ira->codegen->builtin_types.entry_invalid; | 18868 | return ira->codegen->builtin_types.entry_invalid; |
| 18673 | | 18869 | |
| 18674 | TypeTableEntry *ptr_type = ptr_ptr->value.type; | 18870 | ZigType *ptr_type = ptr_ptr->value.type; |
| 18675 | assert(ptr_type->id == TypeTableEntryIdPointer); | 18871 | assert(ptr_type->id == ZigTypeIdPointer); |
| 18676 | TypeTableEntry *array_type = ptr_type->data.pointer.child_type; | 18872 | ZigType *array_type = ptr_type->data.pointer.child_type; |
| 18677 | | 18873 | |
| 18678 | IrInstruction *start = instruction->start->other; | 18874 | IrInstruction *start = instruction->start->other; |
| 18679 | if (type_is_invalid(start->value.type)) | 18875 | if (type_is_invalid(start->value.type)) |
| 18680 | return ira->codegen->builtin_types.entry_invalid; | 18876 | return ira->codegen->builtin_types.entry_invalid; |
| 18681 | | 18877 | |
| 18682 | TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; | 18878 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 18683 | IrInstruction *casted_start = ir_implicit_cast(ira, start, usize); | 18879 | IrInstruction *casted_start = ir_implicit_cast(ira, start, usize); |
| 18684 | if (type_is_invalid(casted_start->value.type)) | 18880 | if (type_is_invalid(casted_start->value.type)) |
| 18685 | return ira->codegen->builtin_types.entry_invalid; | 18881 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18696,26 +18892,26 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio | ... | @@ -18696,26 +18892,26 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 18696 | end = nullptr; | 18892 | end = nullptr; |
| 18697 | } | 18893 | } |
| 18698 | | 18894 | |
| 18699 | TypeTableEntry *return_type; | 18895 | ZigType *return_type; |
| 18700 | | 18896 | |
| 18701 | if (array_type->id == TypeTableEntryIdArray) { | 18897 | if (array_type->id == ZigTypeIdArray) { |
| 18702 | uint32_t byte_alignment = ptr_type->data.pointer.alignment; | 18898 | uint32_t byte_alignment = ptr_type->data.pointer.alignment; |
| 18703 | if (array_type->data.array.len == 0 && byte_alignment == 0) { | 18899 | if (array_type->data.array.len == 0 && byte_alignment == 0) { |
| 18704 | byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type); | 18900 | byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type); |
| 18705 | } | 18901 | } |
| 18706 | bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic && | 18902 | bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic && |
| 18707 | ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst; | 18903 | ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst; |
| 18708 | TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type, | 18904 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type, |
| 18709 | ptr_type->data.pointer.is_const || is_comptime_const, | 18905 | ptr_type->data.pointer.is_const || is_comptime_const, |
| 18710 | ptr_type->data.pointer.is_volatile, | 18906 | ptr_type->data.pointer.is_volatile, |
| 18711 | PtrLenUnknown, | 18907 | PtrLenUnknown, |
| 18712 | byte_alignment, 0, 0); | 18908 | byte_alignment, 0, 0); |
| 18713 | return_type = get_slice_type(ira->codegen, slice_ptr_type); | 18909 | return_type = get_slice_type(ira->codegen, slice_ptr_type); |
| 18714 | } else if (array_type->id == TypeTableEntryIdPointer) { | 18910 | } else if (array_type->id == ZigTypeIdPointer) { |
| 18715 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { | 18911 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { |
| 18716 | TypeTableEntry *main_type = array_type->data.pointer.child_type; | 18912 | ZigType *main_type = array_type->data.pointer.child_type; |
| 18717 | if (main_type->id == TypeTableEntryIdArray) { | 18913 | if (main_type->id == ZigTypeIdArray) { |
| 18718 | TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, | 18914 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, |
| 18719 | main_type->data.pointer.child_type, | 18915 | main_type->data.pointer.child_type, |
| 18720 | array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, | 18916 | array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, |
| 18721 | PtrLenUnknown, | 18917 | PtrLenUnknown, |
| ... | @@ -18726,7 +18922,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio | ... | @@ -18726,7 +18922,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 18726 | return ira->codegen->builtin_types.entry_invalid; | 18922 | return ira->codegen->builtin_types.entry_invalid; |
| 18727 | } | 18923 | } |
| 18728 | } else { | 18924 | } else { |
| 18729 | TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.pointer.child_type, | 18925 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.pointer.child_type, |
| 18730 | array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, | 18926 | array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, |
| 18731 | PtrLenUnknown, | 18927 | PtrLenUnknown, |
| 18732 | array_type->data.pointer.alignment, 0, 0); | 18928 | array_type->data.pointer.alignment, 0, 0); |
| ... | @@ -18737,7 +18933,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio | ... | @@ -18737,7 +18933,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 18737 | } | 18933 | } |
| 18738 | } | 18934 | } |
| 18739 | } else if (is_slice(array_type)) { | 18935 | } else if (is_slice(array_type)) { |
| 18740 | TypeTableEntry *ptr_type = array_type->data.structure.fields[slice_ptr_index].type_entry; | 18936 | ZigType *ptr_type = array_type->data.structure.fields[slice_ptr_index].type_entry; |
| 18741 | return_type = get_slice_type(ira->codegen, ptr_type); | 18937 | return_type = get_slice_type(ira->codegen, ptr_type); |
| 18742 | } else { | 18938 | } else { |
| 18743 | ir_add_error(ira, &instruction->base, | 18939 | ir_add_error(ira, &instruction->base, |
| ... | @@ -18754,25 +18950,36 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio | ... | @@ -18754,25 +18950,36 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 18754 | size_t abs_offset; | 18950 | size_t abs_offset; |
| 18755 | size_t rel_end; | 18951 | size_t rel_end; |
| 18756 | bool ptr_is_undef = false; | 18952 | bool ptr_is_undef = false; |
| 18757 | if (array_type->id == TypeTableEntryIdArray || | 18953 | if (array_type->id == ZigTypeIdArray || |
| 18758 | (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle)) | 18954 | (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle)) |
| 18759 | { | 18955 | { |
| 18760 | if (array_type->id == TypeTableEntryIdPointer) { | 18956 | if (array_type->id == ZigTypeIdPointer) { |
| 18761 | TypeTableEntry *child_array_type = array_type->data.pointer.child_type; | 18957 | ZigType *child_array_type = array_type->data.pointer.child_type; |
| 18762 | assert(child_array_type->id == TypeTableEntryIdArray); | 18958 | assert(child_array_type->id == ZigTypeIdArray); |
| 18763 | parent_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value); | 18959 | parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node); |
| 18764 | array_val = const_ptr_pointee(ira->codegen, parent_ptr); | 18960 | if (parent_ptr == nullptr) |
| | 18961 | return ira->codegen->builtin_types.entry_invalid; |
| | 18962 | |
| | 18963 | array_val = ir_const_ptr_pointee(ira, parent_ptr, instruction->base.source_node); |
| | 18964 | if (array_val == nullptr) |
| | 18965 | return ira->codegen->builtin_types.entry_invalid; |
| | 18966 | |
| 18765 | rel_end = child_array_type->data.array.len; | 18967 | rel_end = child_array_type->data.array.len; |
| 18766 | abs_offset = 0; | 18968 | abs_offset = 0; |
| 18767 | } else { | 18969 | } else { |
| 18768 | array_val = const_ptr_pointee(ira->codegen, &ptr_ptr->value); | 18970 | array_val = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node); |
| | 18971 | if (array_val == nullptr) |
| | 18972 | return ira->codegen->builtin_types.entry_invalid; |
| 18769 | rel_end = array_type->data.array.len; | 18973 | rel_end = array_type->data.array.len; |
| 18770 | parent_ptr = nullptr; | 18974 | parent_ptr = nullptr; |
| 18771 | abs_offset = 0; | 18975 | abs_offset = 0; |
| 18772 | } | 18976 | } |
| 18773 | } else if (array_type->id == TypeTableEntryIdPointer) { | 18977 | } else if (array_type->id == ZigTypeIdPointer) { |
| 18774 | assert(array_type->data.pointer.ptr_len == PtrLenUnknown); | 18978 | assert(array_type->data.pointer.ptr_len == PtrLenUnknown); |
| 18775 | parent_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value); | 18979 | parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node); |
| | 18980 | if (parent_ptr == nullptr) |
| | 18981 | return ira->codegen->builtin_types.entry_invalid; |
| | 18982 | |
| 18776 | if (parent_ptr->special == ConstValSpecialUndef) { | 18983 | if (parent_ptr->special == ConstValSpecialUndef) { |
| 18777 | array_val = nullptr; | 18984 | array_val = nullptr; |
| 18778 | abs_offset = 0; | 18985 | abs_offset = 0; |
| ... | @@ -18803,7 +19010,10 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio | ... | @@ -18803,7 +19010,10 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 18803 | zig_panic("TODO slice of ptr cast from function"); | 19010 | zig_panic("TODO slice of ptr cast from function"); |
| 18804 | } | 19011 | } |
| 18805 | } else if (is_slice(array_type)) { | 19012 | } else if (is_slice(array_type)) { |
| 18806 | ConstExprValue *slice_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value); | 19013 | ConstExprValue *slice_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node); |
| | 19014 | if (slice_ptr == nullptr) |
| | 19015 | return ira->codegen->builtin_types.entry_invalid; |
| | 19016 | |
| 18807 | parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index]; | 19017 | parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index]; |
| 18808 | ConstExprValue *len_val = &slice_ptr->data.x_struct.fields[slice_len_index]; | 19018 | ConstExprValue *len_val = &slice_ptr->data.x_struct.fields[slice_len_index]; |
| 18809 | | 19019 | |
| ... | @@ -18871,11 +19081,11 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio | ... | @@ -18871,11 +19081,11 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 18871 | size_t index = abs_offset + start_scalar; | 19081 | size_t index = abs_offset + start_scalar; |
| 18872 | bool is_const = slice_is_const(return_type); | 19082 | bool is_const = slice_is_const(return_type); |
| 18873 | init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const, PtrLenUnknown); | 19083 | init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const, PtrLenUnknown); |
| 18874 | if (array_type->id == TypeTableEntryIdArray) { | 19084 | if (array_type->id == ZigTypeIdArray) { |
| 18875 | ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut; | 19085 | ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut; |
| 18876 | } else if (is_slice(array_type)) { | 19086 | } else if (is_slice(array_type)) { |
| 18877 | ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut; | 19087 | ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut; |
| 18878 | } else if (array_type->id == TypeTableEntryIdPointer) { | 19088 | } else if (array_type->id == ZigTypeIdPointer) { |
| 18879 | ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut; | 19089 | ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut; |
| 18880 | } | 19090 | } |
| 18881 | } else if (ptr_is_undef) { | 19091 | } else if (ptr_is_undef) { |
| ... | @@ -18917,12 +19127,12 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio | ... | @@ -18917,12 +19127,12 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 18917 | return return_type; | 19127 | return return_type; |
| 18918 | } | 19128 | } |
| 18919 | | 19129 | |
| 18920 | static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) { | 19130 | static ZigType *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) { |
| 18921 | Error err; | 19131 | Error err; |
| 18922 | IrInstruction *container = instruction->container->other; | 19132 | IrInstruction *container = instruction->container->other; |
| 18923 | if (type_is_invalid(container->value.type)) | 19133 | if (type_is_invalid(container->value.type)) |
| 18924 | return ira->codegen->builtin_types.entry_invalid; | 19134 | return ira->codegen->builtin_types.entry_invalid; |
| 18925 | TypeTableEntry *container_type = ir_resolve_type(ira, container); | 19135 | ZigType *container_type = ir_resolve_type(ira, container); |
| 18926 | | 19136 | |
| 18927 | if ((err = ensure_complete_type(ira->codegen, container_type))) | 19137 | if ((err = ensure_complete_type(ira->codegen, container_type))) |
| 18928 | return ira->codegen->builtin_types.entry_invalid; | 19138 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18930,13 +19140,13 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns | ... | @@ -18930,13 +19140,13 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns |
| 18930 | uint64_t result; | 19140 | uint64_t result; |
| 18931 | if (type_is_invalid(container_type)) { | 19141 | if (type_is_invalid(container_type)) { |
| 18932 | return ira->codegen->builtin_types.entry_invalid; | 19142 | return ira->codegen->builtin_types.entry_invalid; |
| 18933 | } else if (container_type->id == TypeTableEntryIdEnum) { | 19143 | } else if (container_type->id == ZigTypeIdEnum) { |
| 18934 | result = container_type->data.enumeration.src_field_count; | 19144 | result = container_type->data.enumeration.src_field_count; |
| 18935 | } else if (container_type->id == TypeTableEntryIdStruct) { | 19145 | } else if (container_type->id == ZigTypeIdStruct) { |
| 18936 | result = container_type->data.structure.src_field_count; | 19146 | result = container_type->data.structure.src_field_count; |
| 18937 | } else if (container_type->id == TypeTableEntryIdUnion) { | 19147 | } else if (container_type->id == ZigTypeIdUnion) { |
| 18938 | result = container_type->data.unionation.src_field_count; | 19148 | result = container_type->data.unionation.src_field_count; |
| 18939 | } else if (container_type->id == TypeTableEntryIdErrorSet) { | 19149 | } else if (container_type->id == ZigTypeIdErrorSet) { |
| 18940 | if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) { | 19150 | if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) { |
| 18941 | return ira->codegen->builtin_types.entry_invalid; | 19151 | return ira->codegen->builtin_types.entry_invalid; |
| 18942 | } | 19152 | } |
| ... | @@ -18955,10 +19165,10 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns | ... | @@ -18955,10 +19165,10 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns |
| 18955 | return ira->codegen->builtin_types.entry_num_lit_int; | 19165 | return ira->codegen->builtin_types.entry_num_lit_int; |
| 18956 | } | 19166 | } |
| 18957 | | 19167 | |
| 18958 | static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) { | 19168 | static ZigType *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) { |
| 18959 | Error err; | 19169 | Error err; |
| 18960 | IrInstruction *container_type_value = instruction->container_type->other; | 19170 | IrInstruction *container_type_value = instruction->container_type->other; |
| 18961 | TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value); | 19171 | ZigType *container_type = ir_resolve_type(ira, container_type_value); |
| 18962 | if (type_is_invalid(container_type)) | 19172 | if (type_is_invalid(container_type)) |
| 18963 | return ira->codegen->builtin_types.entry_invalid; | 19173 | return ira->codegen->builtin_types.entry_invalid; |
| 18964 | | 19174 | |
| ... | @@ -18971,7 +19181,7 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst | ... | @@ -18971,7 +19181,7 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst |
| 18971 | if (!ir_resolve_usize(ira, index_value, &member_index)) | 19181 | if (!ir_resolve_usize(ira, index_value, &member_index)) |
| 18972 | return ira->codegen->builtin_types.entry_invalid; | 19182 | return ira->codegen->builtin_types.entry_invalid; |
| 18973 | | 19183 | |
| 18974 | if (container_type->id == TypeTableEntryIdStruct) { | 19184 | if (container_type->id == ZigTypeIdStruct) { |
| 18975 | if (member_index >= container_type->data.structure.src_field_count) { | 19185 | if (member_index >= container_type->data.structure.src_field_count) { |
| 18976 | ir_add_error(ira, index_value, | 19186 | ir_add_error(ira, index_value, |
| 18977 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", | 19187 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| ... | @@ -18983,7 +19193,7 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst | ... | @@ -18983,7 +19193,7 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst |
| 18983 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 19193 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 18984 | out_val->data.x_type = field->type_entry; | 19194 | out_val->data.x_type = field->type_entry; |
| 18985 | return ira->codegen->builtin_types.entry_type; | 19195 | return ira->codegen->builtin_types.entry_type; |
| 18986 | } else if (container_type->id == TypeTableEntryIdUnion) { | 19196 | } else if (container_type->id == ZigTypeIdUnion) { |
| 18987 | if (member_index >= container_type->data.unionation.src_field_count) { | 19197 | if (member_index >= container_type->data.unionation.src_field_count) { |
| 18988 | ir_add_error(ira, index_value, | 19198 | ir_add_error(ira, index_value, |
| 18989 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", | 19199 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| ... | @@ -19002,10 +19212,10 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst | ... | @@ -19002,10 +19212,10 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst |
| 19002 | } | 19212 | } |
| 19003 | } | 19213 | } |
| 19004 | | 19214 | |
| 19005 | static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) { | 19215 | static ZigType *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) { |
| 19006 | Error err; | 19216 | Error err; |
| 19007 | IrInstruction *container_type_value = instruction->container_type->other; | 19217 | IrInstruction *container_type_value = instruction->container_type->other; |
| 19008 | TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value); | 19218 | ZigType *container_type = ir_resolve_type(ira, container_type_value); |
| 19009 | if (type_is_invalid(container_type)) | 19219 | if (type_is_invalid(container_type)) |
| 19010 | return ira->codegen->builtin_types.entry_invalid; | 19220 | return ira->codegen->builtin_types.entry_invalid; |
| 19011 | | 19221 | |
| ... | @@ -19017,7 +19227,7 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst | ... | @@ -19017,7 +19227,7 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst |
| 19017 | if (!ir_resolve_usize(ira, index_value, &member_index)) | 19227 | if (!ir_resolve_usize(ira, index_value, &member_index)) |
| 19018 | return ira->codegen->builtin_types.entry_invalid; | 19228 | return ira->codegen->builtin_types.entry_invalid; |
| 19019 | | 19229 | |
| 19020 | if (container_type->id == TypeTableEntryIdStruct) { | 19230 | if (container_type->id == ZigTypeIdStruct) { |
| 19021 | if (member_index >= container_type->data.structure.src_field_count) { | 19231 | if (member_index >= container_type->data.structure.src_field_count) { |
| 19022 | ir_add_error(ira, index_value, | 19232 | ir_add_error(ira, index_value, |
| 19023 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", | 19233 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| ... | @@ -19029,7 +19239,7 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst | ... | @@ -19029,7 +19239,7 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst |
| 19029 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 19239 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19030 | init_const_str_lit(ira->codegen, out_val, field->name); | 19240 | init_const_str_lit(ira->codegen, out_val, field->name); |
| 19031 | return out_val->type; | 19241 | return out_val->type; |
| 19032 | } else if (container_type->id == TypeTableEntryIdEnum) { | 19242 | } else if (container_type->id == ZigTypeIdEnum) { |
| 19033 | if (member_index >= container_type->data.enumeration.src_field_count) { | 19243 | if (member_index >= container_type->data.enumeration.src_field_count) { |
| 19034 | ir_add_error(ira, index_value, | 19244 | ir_add_error(ira, index_value, |
| 19035 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", | 19245 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| ... | @@ -19041,7 +19251,7 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst | ... | @@ -19041,7 +19251,7 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst |
| 19041 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 19251 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19042 | init_const_str_lit(ira->codegen, out_val, field->name); | 19252 | init_const_str_lit(ira->codegen, out_val, field->name); |
| 19043 | return out_val->type; | 19253 | return out_val->type; |
| 19044 | } else if (container_type->id == TypeTableEntryIdUnion) { | 19254 | } else if (container_type->id == ZigTypeIdUnion) { |
| 19045 | if (member_index >= container_type->data.unionation.src_field_count) { | 19255 | if (member_index >= container_type->data.unionation.src_field_count) { |
| 19046 | ir_add_error(ira, index_value, | 19256 | ir_add_error(ira, index_value, |
| 19047 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", | 19257 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| ... | @@ -19060,76 +19270,76 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst | ... | @@ -19060,76 +19270,76 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst |
| 19060 | } | 19270 | } |
| 19061 | } | 19271 | } |
| 19062 | | 19272 | |
| 19063 | static TypeTableEntry *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) { | 19273 | static ZigType *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) { |
| 19064 | ir_build_breakpoint_from(&ira->new_irb, &instruction->base); | 19274 | ir_build_breakpoint_from(&ira->new_irb, &instruction->base); |
| 19065 | return ira->codegen->builtin_types.entry_void; | 19275 | return ira->codegen->builtin_types.entry_void; |
| 19066 | } | 19276 | } |
| 19067 | | 19277 | |
| 19068 | static TypeTableEntry *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) { | 19278 | static ZigType *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) { |
| 19069 | ir_build_return_address_from(&ira->new_irb, &instruction->base); | 19279 | ir_build_return_address_from(&ira->new_irb, &instruction->base); |
| 19070 | | 19280 | |
| 19071 | TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8; | 19281 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 19072 | TypeTableEntry *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); | 19282 | ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); |
| 19073 | return u8_ptr_const; | 19283 | return u8_ptr_const; |
| 19074 | } | 19284 | } |
| 19075 | | 19285 | |
| 19076 | static TypeTableEntry *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) { | 19286 | static ZigType *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) { |
| 19077 | ir_build_frame_address_from(&ira->new_irb, &instruction->base); | 19287 | ir_build_frame_address_from(&ira->new_irb, &instruction->base); |
| 19078 | | 19288 | |
| 19079 | TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8; | 19289 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 19080 | TypeTableEntry *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); | 19290 | ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); |
| 19081 | return u8_ptr_const; | 19291 | return u8_ptr_const; |
| 19082 | } | 19292 | } |
| 19083 | | 19293 | |
| 19084 | static TypeTableEntry *ir_analyze_instruction_handle(IrAnalyze *ira, IrInstructionHandle *instruction) { | 19294 | static ZigType *ir_analyze_instruction_handle(IrAnalyze *ira, IrInstructionHandle *instruction) { |
| 19085 | ir_build_handle_from(&ira->new_irb, &instruction->base); | 19295 | ir_build_handle_from(&ira->new_irb, &instruction->base); |
| 19086 | | 19296 | |
| 19087 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); | 19297 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 19088 | assert(fn_entry != nullptr); | 19298 | assert(fn_entry != nullptr); |
| 19089 | return get_promise_type(ira->codegen, fn_entry->type_entry->data.fn.fn_type_id.return_type); | 19299 | return get_promise_type(ira->codegen, fn_entry->type_entry->data.fn.fn_type_id.return_type); |
| 19090 | } | 19300 | } |
| 19091 | | 19301 | |
| 19092 | static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) { | 19302 | static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) { |
| 19093 | Error err; | 19303 | Error err; |
| 19094 | IrInstruction *type_value = instruction->type_value->other; | 19304 | IrInstruction *type_value = instruction->type_value->other; |
| 19095 | if (type_is_invalid(type_value->value.type)) | 19305 | if (type_is_invalid(type_value->value.type)) |
| 19096 | return ira->codegen->builtin_types.entry_invalid; | 19306 | return ira->codegen->builtin_types.entry_invalid; |
| 19097 | TypeTableEntry *type_entry = ir_resolve_type(ira, type_value); | 19307 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 19098 | | 19308 | |
| 19099 | if ((err = type_ensure_zero_bits_known(ira->codegen, type_entry))) | 19309 | if ((err = type_ensure_zero_bits_known(ira->codegen, type_entry))) |
| 19100 | return ira->codegen->builtin_types.entry_invalid; | 19310 | return ira->codegen->builtin_types.entry_invalid; |
| 19101 | | 19311 | |
| 19102 | switch (type_entry->id) { | 19312 | switch (type_entry->id) { |
| 19103 | case TypeTableEntryIdInvalid: | 19313 | case ZigTypeIdInvalid: |
| 19104 | zig_unreachable(); | 19314 | zig_unreachable(); |
| 19105 | case TypeTableEntryIdMetaType: | 19315 | case ZigTypeIdMetaType: |
| 19106 | case TypeTableEntryIdUnreachable: | 19316 | case ZigTypeIdUnreachable: |
| 19107 | case TypeTableEntryIdComptimeFloat: | 19317 | case ZigTypeIdComptimeFloat: |
| 19108 | case TypeTableEntryIdComptimeInt: | 19318 | case ZigTypeIdComptimeInt: |
| 19109 | case TypeTableEntryIdUndefined: | 19319 | case ZigTypeIdUndefined: |
| 19110 | case TypeTableEntryIdNull: | 19320 | case ZigTypeIdNull: |
| 19111 | case TypeTableEntryIdNamespace: | 19321 | case ZigTypeIdNamespace: |
| 19112 | case TypeTableEntryIdBlock: | 19322 | case ZigTypeIdBlock: |
| 19113 | case TypeTableEntryIdBoundFn: | 19323 | case ZigTypeIdBoundFn: |
| 19114 | case TypeTableEntryIdArgTuple: | 19324 | case ZigTypeIdArgTuple: |
| 19115 | case TypeTableEntryIdVoid: | 19325 | case ZigTypeIdVoid: |
| 19116 | case TypeTableEntryIdOpaque: | 19326 | case ZigTypeIdOpaque: |
| 19117 | ir_add_error(ira, instruction->type_value, | 19327 | ir_add_error(ira, instruction->type_value, |
| 19118 | buf_sprintf("no align available for type '%s'", buf_ptr(&type_entry->name))); | 19328 | buf_sprintf("no align available for type '%s'", buf_ptr(&type_entry->name))); |
| 19119 | return ira->codegen->builtin_types.entry_invalid; | 19329 | return ira->codegen->builtin_types.entry_invalid; |
| 19120 | case TypeTableEntryIdBool: | 19330 | case ZigTypeIdBool: |
| 19121 | case TypeTableEntryIdInt: | 19331 | case ZigTypeIdInt: |
| 19122 | case TypeTableEntryIdFloat: | 19332 | case ZigTypeIdFloat: |
| 19123 | case TypeTableEntryIdPointer: | 19333 | case ZigTypeIdPointer: |
| 19124 | case TypeTableEntryIdPromise: | 19334 | case ZigTypeIdPromise: |
| 19125 | case TypeTableEntryIdArray: | 19335 | case ZigTypeIdArray: |
| 19126 | case TypeTableEntryIdStruct: | 19336 | case ZigTypeIdStruct: |
| 19127 | case TypeTableEntryIdOptional: | 19337 | case ZigTypeIdOptional: |
| 19128 | case TypeTableEntryIdErrorUnion: | 19338 | case ZigTypeIdErrorUnion: |
| 19129 | case TypeTableEntryIdErrorSet: | 19339 | case ZigTypeIdErrorSet: |
| 19130 | case TypeTableEntryIdEnum: | 19340 | case ZigTypeIdEnum: |
| 19131 | case TypeTableEntryIdUnion: | 19341 | case ZigTypeIdUnion: |
| 19132 | case TypeTableEntryIdFn: | 19342 | case ZigTypeIdFn: |
| 19133 | { | 19343 | { |
| 19134 | uint64_t align_in_bytes = get_abi_alignment(ira->codegen, type_entry); | 19344 | uint64_t align_in_bytes = get_abi_alignment(ira->codegen, type_entry); |
| 19135 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 19345 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| ... | @@ -19140,16 +19350,16 @@ static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruc | ... | @@ -19140,16 +19350,16 @@ static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruc |
| 19140 | zig_unreachable(); | 19350 | zig_unreachable(); |
| 19141 | } | 19351 | } |
| 19142 | | 19352 | |
| 19143 | static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) { | 19353 | static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) { |
| 19144 | IrInstruction *type_value = instruction->type_value->other; | 19354 | IrInstruction *type_value = instruction->type_value->other; |
| 19145 | if (type_is_invalid(type_value->value.type)) | 19355 | if (type_is_invalid(type_value->value.type)) |
| 19146 | return ira->codegen->builtin_types.entry_invalid; | 19356 | return ira->codegen->builtin_types.entry_invalid; |
| 19147 | | 19357 | |
| 19148 | TypeTableEntry *dest_type = ir_resolve_type(ira, type_value); | 19358 | ZigType *dest_type = ir_resolve_type(ira, type_value); |
| 19149 | if (type_is_invalid(dest_type)) | 19359 | if (type_is_invalid(dest_type)) |
| 19150 | return ira->codegen->builtin_types.entry_invalid; | 19360 | return ira->codegen->builtin_types.entry_invalid; |
| 19151 | | 19361 | |
| 19152 | if (dest_type->id != TypeTableEntryIdInt) { | 19362 | if (dest_type->id != ZigTypeIdInt) { |
| 19153 | ir_add_error(ira, type_value, | 19363 | ir_add_error(ira, type_value, |
| 19154 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); | 19364 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 19155 | return ira->codegen->builtin_types.entry_invalid; | 19365 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -19169,7 +19379,7 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst | ... | @@ -19169,7 +19379,7 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst |
| 19169 | | 19379 | |
| 19170 | IrInstruction *casted_op2; | 19380 | IrInstruction *casted_op2; |
| 19171 | if (instruction->op == IrOverflowOpShl) { | 19381 | if (instruction->op == IrOverflowOpShl) { |
| 19172 | TypeTableEntry *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, | 19382 | ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, |
| 19173 | dest_type->data.integral.bit_count - 1); | 19383 | dest_type->data.integral.bit_count - 1); |
| 19174 | casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type); | 19384 | casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type); |
| 19175 | } else { | 19385 | } else { |
| ... | @@ -19182,8 +19392,8 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst | ... | @@ -19182,8 +19392,8 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst |
| 19182 | if (type_is_invalid(result_ptr->value.type)) | 19392 | if (type_is_invalid(result_ptr->value.type)) |
| 19183 | return ira->codegen->builtin_types.entry_invalid; | 19393 | return ira->codegen->builtin_types.entry_invalid; |
| 19184 | | 19394 | |
| 19185 | TypeTableEntry *expected_ptr_type; | 19395 | ZigType *expected_ptr_type; |
| 19186 | if (result_ptr->value.type->id == TypeTableEntryIdPointer) { | 19396 | if (result_ptr->value.type->id == ZigTypeIdPointer) { |
| 19187 | expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type, | 19397 | expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type, |
| 19188 | false, result_ptr->value.type->data.pointer.is_volatile, | 19398 | false, result_ptr->value.type->data.pointer.is_volatile, |
| 19189 | PtrLenSingle, | 19399 | PtrLenSingle, |
| ... | @@ -19203,7 +19413,9 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst | ... | @@ -19203,7 +19413,9 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst |
| 19203 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 19413 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19204 | BigInt *op1_bigint = &casted_op1->value.data.x_bigint; | 19414 | BigInt *op1_bigint = &casted_op1->value.data.x_bigint; |
| 19205 | BigInt *op2_bigint = &casted_op2->value.data.x_bigint; | 19415 | BigInt *op2_bigint = &casted_op2->value.data.x_bigint; |
| 19206 | ConstExprValue *pointee_val = const_ptr_pointee(ira->codegen, &casted_result_ptr->value); | 19416 | ConstExprValue *pointee_val = ir_const_ptr_pointee(ira, &casted_result_ptr->value, casted_result_ptr->source_node); |
| | 19417 | if (pointee_val == nullptr) |
| | 19418 | return ira->codegen->builtin_types.entry_invalid; |
| 19207 | BigInt *dest_bigint = &pointee_val->data.x_bigint; | 19419 | BigInt *dest_bigint = &pointee_val->data.x_bigint; |
| 19208 | switch (instruction->op) { | 19420 | switch (instruction->op) { |
| 19209 | case IrOverflowOpAdd: | 19421 | case IrOverflowOpAdd: |
| ... | @@ -19237,15 +19449,15 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst | ... | @@ -19237,15 +19449,15 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst |
| 19237 | return ira->codegen->builtin_types.entry_bool; | 19449 | return ira->codegen->builtin_types.entry_bool; |
| 19238 | } | 19450 | } |
| 19239 | | 19451 | |
| 19240 | static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) { | 19452 | static ZigType *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) { |
| 19241 | IrInstruction *value = instruction->value->other; | 19453 | IrInstruction *value = instruction->value->other; |
| 19242 | if (type_is_invalid(value->value.type)) | 19454 | if (type_is_invalid(value->value.type)) |
| 19243 | return ira->codegen->builtin_types.entry_invalid; | 19455 | return ira->codegen->builtin_types.entry_invalid; |
| 19244 | | 19456 | |
| 19245 | TypeTableEntry *type_entry = value->value.type; | 19457 | ZigType *type_entry = value->value.type; |
| 19246 | if (type_is_invalid(type_entry)) { | 19458 | if (type_is_invalid(type_entry)) { |
| 19247 | return ira->codegen->builtin_types.entry_invalid; | 19459 | return ira->codegen->builtin_types.entry_invalid; |
| 19248 | } else if (type_entry->id == TypeTableEntryIdErrorUnion) { | 19460 | } else if (type_entry->id == ZigTypeIdErrorUnion) { |
| 19249 | if (instr_is_comptime(value)) { | 19461 | if (instr_is_comptime(value)) { |
| 19250 | ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad); | 19462 | ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad); |
| 19251 | if (!err_union_val) | 19463 | if (!err_union_val) |
| ... | @@ -19258,7 +19470,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc | ... | @@ -19258,7 +19470,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc |
| 19258 | } | 19470 | } |
| 19259 | } | 19471 | } |
| 19260 | | 19472 | |
| 19261 | TypeTableEntry *err_set_type = type_entry->data.error_union.err_set_type; | 19473 | ZigType *err_set_type = type_entry->data.error_union.err_set_type; |
| 19262 | if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) { | 19474 | if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) { |
| 19263 | return ira->codegen->builtin_types.entry_invalid; | 19475 | return ira->codegen->builtin_types.entry_invalid; |
| 19264 | } | 19476 | } |
| ... | @@ -19273,7 +19485,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc | ... | @@ -19273,7 +19485,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc |
| 19273 | | 19485 | |
| 19274 | ir_build_test_err_from(&ira->new_irb, &instruction->base, value); | 19486 | ir_build_test_err_from(&ira->new_irb, &instruction->base, value); |
| 19275 | return ira->codegen->builtin_types.entry_bool; | 19487 | return ira->codegen->builtin_types.entry_bool; |
| 19276 | } else if (type_entry->id == TypeTableEntryIdErrorSet) { | 19488 | } else if (type_entry->id == ZigTypeIdErrorSet) { |
| 19277 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 19489 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19278 | out_val->data.x_bool = true; | 19490 | out_val->data.x_bool = true; |
| 19279 | return ira->codegen->builtin_types.entry_bool; | 19491 | return ira->codegen->builtin_types.entry_bool; |
| ... | @@ -19284,26 +19496,28 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc | ... | @@ -19284,26 +19496,28 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc |
| 19284 | } | 19496 | } |
| 19285 | } | 19497 | } |
| 19286 | | 19498 | |
| 19287 | static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, | 19499 | static ZigType *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, |
| 19288 | IrInstructionUnwrapErrCode *instruction) | 19500 | IrInstructionUnwrapErrCode *instruction) |
| 19289 | { | 19501 | { |
| 19290 | IrInstruction *value = instruction->value->other; | 19502 | IrInstruction *value = instruction->value->other; |
| 19291 | if (type_is_invalid(value->value.type)) | 19503 | if (type_is_invalid(value->value.type)) |
| 19292 | return ira->codegen->builtin_types.entry_invalid; | 19504 | return ira->codegen->builtin_types.entry_invalid; |
| 19293 | TypeTableEntry *ptr_type = value->value.type; | 19505 | ZigType *ptr_type = value->value.type; |
| 19294 | | 19506 | |
| 19295 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. | 19507 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. |
| 19296 | assert(ptr_type->id == TypeTableEntryIdPointer); | 19508 | assert(ptr_type->id == ZigTypeIdPointer); |
| 19297 | | 19509 | |
| 19298 | TypeTableEntry *type_entry = ptr_type->data.pointer.child_type; | 19510 | ZigType *type_entry = ptr_type->data.pointer.child_type; |
| 19299 | if (type_is_invalid(type_entry)) { | 19511 | if (type_is_invalid(type_entry)) { |
| 19300 | return ira->codegen->builtin_types.entry_invalid; | 19512 | return ira->codegen->builtin_types.entry_invalid; |
| 19301 | } else if (type_entry->id == TypeTableEntryIdErrorUnion) { | 19513 | } else if (type_entry->id == ZigTypeIdErrorUnion) { |
| 19302 | if (instr_is_comptime(value)) { | 19514 | if (instr_is_comptime(value)) { |
| 19303 | ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad); | 19515 | ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad); |
| 19304 | if (!ptr_val) | 19516 | if (!ptr_val) |
| 19305 | return ira->codegen->builtin_types.entry_invalid; | 19517 | return ira->codegen->builtin_types.entry_invalid; |
| 19306 | ConstExprValue *err_union_val = const_ptr_pointee(ira->codegen, ptr_val); | 19518 | ConstExprValue *err_union_val = ir_const_ptr_pointee(ira, ptr_val, instruction->base.source_node); |
| | 19519 | if (err_union_val == nullptr) |
| | 19520 | return ira->codegen->builtin_types.entry_invalid; |
| 19307 | if (err_union_val->special != ConstValSpecialRuntime) { | 19521 | if (err_union_val->special != ConstValSpecialRuntime) { |
| 19308 | ErrorTableEntry *err = err_union_val->data.x_err_union.err; | 19522 | ErrorTableEntry *err = err_union_val->data.x_err_union.err; |
| 19309 | assert(err); | 19523 | assert(err); |
| ... | @@ -19323,27 +19537,27 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, | ... | @@ -19323,27 +19537,27 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, |
| 19323 | } | 19537 | } |
| 19324 | } | 19538 | } |
| 19325 | | 19539 | |
| 19326 | static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, | 19540 | static ZigType *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 19327 | IrInstructionUnwrapErrPayload *instruction) | 19541 | IrInstructionUnwrapErrPayload *instruction) |
| 19328 | { | 19542 | { |
| 19329 | assert(instruction->value->other); | 19543 | assert(instruction->value->other); |
| 19330 | IrInstruction *value = instruction->value->other; | 19544 | IrInstruction *value = instruction->value->other; |
| 19331 | if (type_is_invalid(value->value.type)) | 19545 | if (type_is_invalid(value->value.type)) |
| 19332 | return ira->codegen->builtin_types.entry_invalid; | 19546 | return ira->codegen->builtin_types.entry_invalid; |
| 19333 | TypeTableEntry *ptr_type = value->value.type; | 19547 | ZigType *ptr_type = value->value.type; |
| 19334 | | 19548 | |
| 19335 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. | 19549 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. |
| 19336 | assert(ptr_type->id == TypeTableEntryIdPointer); | 19550 | assert(ptr_type->id == ZigTypeIdPointer); |
| 19337 | | 19551 | |
| 19338 | TypeTableEntry *type_entry = ptr_type->data.pointer.child_type; | 19552 | ZigType *type_entry = ptr_type->data.pointer.child_type; |
| 19339 | if (type_is_invalid(type_entry)) { | 19553 | if (type_is_invalid(type_entry)) { |
| 19340 | return ira->codegen->builtin_types.entry_invalid; | 19554 | return ira->codegen->builtin_types.entry_invalid; |
| 19341 | } else if (type_entry->id == TypeTableEntryIdErrorUnion) { | 19555 | } else if (type_entry->id == ZigTypeIdErrorUnion) { |
| 19342 | TypeTableEntry *payload_type = type_entry->data.error_union.payload_type; | 19556 | ZigType *payload_type = type_entry->data.error_union.payload_type; |
| 19343 | if (type_is_invalid(payload_type)) { | 19557 | if (type_is_invalid(payload_type)) { |
| 19344 | return ira->codegen->builtin_types.entry_invalid; | 19558 | return ira->codegen->builtin_types.entry_invalid; |
| 19345 | } | 19559 | } |
| 19346 | TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, payload_type, | 19560 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type, |
| 19347 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, | 19561 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 19348 | PtrLenSingle, | 19562 | PtrLenSingle, |
| 19349 | get_abi_alignment(ira->codegen, payload_type), 0, 0); | 19563 | get_abi_alignment(ira->codegen, payload_type), 0, 0); |
| ... | @@ -19351,7 +19565,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, | ... | @@ -19351,7 +19565,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 19351 | ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad); | 19565 | ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad); |
| 19352 | if (!ptr_val) | 19566 | if (!ptr_val) |
| 19353 | return ira->codegen->builtin_types.entry_invalid; | 19567 | return ira->codegen->builtin_types.entry_invalid; |
| 19354 | ConstExprValue *err_union_val = const_ptr_pointee(ira->codegen, ptr_val); | 19568 | ConstExprValue *err_union_val = ir_const_ptr_pointee(ira, ptr_val, instruction->base.source_node); |
| | 19569 | if (err_union_val == nullptr) |
| | 19570 | return ira->codegen->builtin_types.entry_invalid; |
| 19355 | if (err_union_val->special != ConstValSpecialRuntime) { | 19571 | if (err_union_val->special != ConstValSpecialRuntime) { |
| 19356 | ErrorTableEntry *err = err_union_val->data.x_err_union.err; | 19572 | ErrorTableEntry *err = err_union_val->data.x_err_union.err; |
| 19357 | if (err != nullptr) { | 19573 | if (err != nullptr) { |
| ... | @@ -19377,7 +19593,8 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, | ... | @@ -19377,7 +19593,8 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 19377 | | 19593 | |
| 19378 | } | 19594 | } |
| 19379 | | 19595 | |
| 19380 | static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) { | 19596 | static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) { |
| | 19597 | Error err; |
| 19381 | AstNode *proto_node = instruction->base.source_node; | 19598 | AstNode *proto_node = instruction->base.source_node; |
| 19382 | assert(proto_node->type == NodeTypeFnProto); | 19599 | assert(proto_node->type == NodeTypeFnProto); |
| 19383 | | 19600 | |
| ... | @@ -19419,9 +19636,25 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc | ... | @@ -19419,9 +19636,25 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc |
| 19419 | IrInstruction *param_type_value = instruction->param_types[fn_type_id.next_param_index]->other; | 19636 | IrInstruction *param_type_value = instruction->param_types[fn_type_id.next_param_index]->other; |
| 19420 | if (type_is_invalid(param_type_value->value.type)) | 19637 | if (type_is_invalid(param_type_value->value.type)) |
| 19421 | return ira->codegen->builtin_types.entry_invalid; | 19638 | return ira->codegen->builtin_types.entry_invalid; |
| 19422 | param_info->type = ir_resolve_type(ira, param_type_value); | 19639 | ZigType *param_type = ir_resolve_type(ira, param_type_value); |
| 19423 | if (type_is_invalid(param_info->type)) | 19640 | if (type_is_invalid(param_type)) |
| | 19641 | return ira->codegen->builtin_types.entry_invalid; |
| | 19642 | if ((err = type_ensure_zero_bits_known(ira->codegen, param_type))) |
| 19424 | return ira->codegen->builtin_types.entry_invalid; | 19643 | return ira->codegen->builtin_types.entry_invalid; |
| | 19644 | if (type_requires_comptime(param_type)) { |
| | 19645 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| | 19646 | ir_add_error(ira, &instruction->base, |
| | 19647 | buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'", |
| | 19648 | buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc))); |
| | 19649 | return ira->codegen->builtin_types.entry_invalid; |
| | 19650 | } |
| | 19651 | param_info->type = param_type; |
| | 19652 | fn_type_id.next_param_index += 1; |
| | 19653 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| | 19654 | out_val->data.x_type = get_generic_fn_type(ira->codegen, &fn_type_id); |
| | 19655 | return ira->codegen->builtin_types.entry_type; |
| | 19656 | } |
| | 19657 | param_info->type = param_type; |
| 19425 | } | 19658 | } |
| 19426 | | 19659 | |
| 19427 | } | 19660 | } |
| ... | @@ -19435,7 +19668,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc | ... | @@ -19435,7 +19668,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc |
| 19435 | fn_type_id.return_type = ir_resolve_type(ira, return_type_value); | 19668 | fn_type_id.return_type = ir_resolve_type(ira, return_type_value); |
| 19436 | if (type_is_invalid(fn_type_id.return_type)) | 19669 | if (type_is_invalid(fn_type_id.return_type)) |
| 19437 | return ira->codegen->builtin_types.entry_invalid; | 19670 | return ira->codegen->builtin_types.entry_invalid; |
| 19438 | if (fn_type_id.return_type->id == TypeTableEntryIdOpaque) { | 19671 | if (fn_type_id.return_type->id == ZigTypeIdOpaque) { |
| 19439 | ir_add_error(ira, instruction->return_type, | 19672 | ir_add_error(ira, instruction->return_type, |
| 19440 | buf_sprintf("return type cannot be opaque")); | 19673 | buf_sprintf("return type cannot be opaque")); |
| 19441 | return ira->codegen->builtin_types.entry_invalid; | 19674 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -19458,7 +19691,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc | ... | @@ -19458,7 +19691,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc |
| 19458 | return ira->codegen->builtin_types.entry_type; | 19691 | return ira->codegen->builtin_types.entry_type; |
| 19459 | } | 19692 | } |
| 19460 | | 19693 | |
| 19461 | static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) { | 19694 | static ZigType *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) { |
| 19462 | IrInstruction *value = instruction->value->other; | 19695 | IrInstruction *value = instruction->value->other; |
| 19463 | if (type_is_invalid(value->value.type)) | 19696 | if (type_is_invalid(value->value.type)) |
| 19464 | return ira->codegen->builtin_types.entry_invalid; | 19697 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -19468,15 +19701,15 @@ static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrIn | ... | @@ -19468,15 +19701,15 @@ static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrIn |
| 19468 | return ira->codegen->builtin_types.entry_bool; | 19701 | return ira->codegen->builtin_types.entry_bool; |
| 19469 | } | 19702 | } |
| 19470 | | 19703 | |
| 19471 | static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, | 19704 | static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 19472 | IrInstructionCheckSwitchProngs *instruction) | 19705 | IrInstructionCheckSwitchProngs *instruction) |
| 19473 | { | 19706 | { |
| 19474 | IrInstruction *target_value = instruction->target_value->other; | 19707 | IrInstruction *target_value = instruction->target_value->other; |
| 19475 | TypeTableEntry *switch_type = target_value->value.type; | 19708 | ZigType *switch_type = target_value->value.type; |
| 19476 | if (type_is_invalid(switch_type)) | 19709 | if (type_is_invalid(switch_type)) |
| 19477 | return ira->codegen->builtin_types.entry_invalid; | 19710 | return ira->codegen->builtin_types.entry_invalid; |
| 19478 | | 19711 | |
| 19479 | if (switch_type->id == TypeTableEntryIdEnum) { | 19712 | if (switch_type->id == ZigTypeIdEnum) { |
| 19480 | HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {}; | 19713 | HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {}; |
| 19481 | field_prev_uses.init(switch_type->data.enumeration.src_field_count); | 19714 | field_prev_uses.init(switch_type->data.enumeration.src_field_count); |
| 19482 | | 19715 | |
| ... | @@ -19491,7 +19724,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira | ... | @@ -19491,7 +19724,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira |
| 19491 | if (type_is_invalid(end_value->value.type)) | 19724 | if (type_is_invalid(end_value->value.type)) |
| 19492 | return ira->codegen->builtin_types.entry_invalid; | 19725 | return ira->codegen->builtin_types.entry_invalid; |
| 19493 | | 19726 | |
| 19494 | if (start_value->value.type->id != TypeTableEntryIdEnum) { | 19727 | if (start_value->value.type->id != ZigTypeIdEnum) { |
| 19495 | ir_add_error(ira, range->start, buf_sprintf("not an enum type")); | 19728 | ir_add_error(ira, range->start, buf_sprintf("not an enum type")); |
| 19496 | return ira->codegen->builtin_types.entry_invalid; | 19729 | return ira->codegen->builtin_types.entry_invalid; |
| 19497 | } | 19730 | } |
| ... | @@ -19499,7 +19732,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira | ... | @@ -19499,7 +19732,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira |
| 19499 | BigInt start_index; | 19732 | BigInt start_index; |
| 19500 | bigint_init_bigint(&start_index, &start_value->value.data.x_enum_tag); | 19733 | bigint_init_bigint(&start_index, &start_value->value.data.x_enum_tag); |
| 19501 | | 19734 | |
| 19502 | assert(end_value->value.type->id == TypeTableEntryIdEnum); | 19735 | assert(end_value->value.type->id == ZigTypeIdEnum); |
| 19503 | BigInt end_index; | 19736 | BigInt end_index; |
| 19504 | bigint_init_bigint(&end_index, &end_value->value.data.x_enum_tag); | 19737 | bigint_init_bigint(&end_index, &end_value->value.data.x_enum_tag); |
| 19505 | | 19738 | |
| ... | @@ -19535,7 +19768,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira | ... | @@ -19535,7 +19768,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira |
| 19535 | } | 19768 | } |
| 19536 | } | 19769 | } |
| 19537 | } | 19770 | } |
| 19538 | } else if (switch_type->id == TypeTableEntryIdErrorSet) { | 19771 | } else if (switch_type->id == ZigTypeIdErrorSet) { |
| 19539 | if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) { | 19772 | if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) { |
| 19540 | return ira->codegen->builtin_types.entry_invalid; | 19773 | return ira->codegen->builtin_types.entry_invalid; |
| 19541 | } | 19774 | } |
| ... | @@ -19553,10 +19786,10 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira | ... | @@ -19553,10 +19786,10 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira |
| 19553 | if (type_is_invalid(end_value->value.type)) | 19786 | if (type_is_invalid(end_value->value.type)) |
| 19554 | return ira->codegen->builtin_types.entry_invalid; | 19787 | return ira->codegen->builtin_types.entry_invalid; |
| 19555 | | 19788 | |
| 19556 | assert(start_value->value.type->id == TypeTableEntryIdErrorSet); | 19789 | assert(start_value->value.type->id == ZigTypeIdErrorSet); |
| 19557 | uint32_t start_index = start_value->value.data.x_err_set->value; | 19790 | uint32_t start_index = start_value->value.data.x_err_set->value; |
| 19558 | | 19791 | |
| 19559 | assert(end_value->value.type->id == TypeTableEntryIdErrorSet); | 19792 | assert(end_value->value.type->id == ZigTypeIdErrorSet); |
| 19560 | uint32_t end_index = end_value->value.data.x_err_set->value; | 19793 | uint32_t end_index = end_value->value.data.x_err_set->value; |
| 19561 | | 19794 | |
| 19562 | if (start_index != end_index) { | 19795 | if (start_index != end_index) { |
| ... | @@ -19592,7 +19825,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira | ... | @@ -19592,7 +19825,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira |
| 19592 | } | 19825 | } |
| 19593 | | 19826 | |
| 19594 | free(field_prev_uses); | 19827 | free(field_prev_uses); |
| 19595 | } else if (switch_type->id == TypeTableEntryIdInt) { | 19828 | } else if (switch_type->id == ZigTypeIdInt) { |
| 19596 | RangeSet rs = {0}; | 19829 | RangeSet rs = {0}; |
| 19597 | for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) { | 19830 | for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) { |
| 19598 | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; | 19831 | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| ... | @@ -19619,8 +19852,8 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira | ... | @@ -19619,8 +19852,8 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira |
| 19619 | if (!end_val) | 19852 | if (!end_val) |
| 19620 | return ira->codegen->builtin_types.entry_invalid; | 19853 | return ira->codegen->builtin_types.entry_invalid; |
| 19621 | | 19854 | |
| 19622 | assert(start_val->type->id == TypeTableEntryIdInt || start_val->type->id == TypeTableEntryIdComptimeInt); | 19855 | assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt); |
| 19623 | assert(end_val->type->id == TypeTableEntryIdInt || end_val->type->id == TypeTableEntryIdComptimeInt); | 19856 | assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt); |
| 19624 | AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint, | 19857 | AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint, |
| 19625 | start_value->source_node); | 19858 | start_value->source_node); |
| 19626 | if (prev_node != nullptr) { | 19859 | if (prev_node != nullptr) { |
| ... | @@ -19648,15 +19881,15 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira | ... | @@ -19648,15 +19881,15 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira |
| 19648 | return ira->codegen->builtin_types.entry_void; | 19881 | return ira->codegen->builtin_types.entry_void; |
| 19649 | } | 19882 | } |
| 19650 | | 19883 | |
| 19651 | static TypeTableEntry *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, | 19884 | static ZigType *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, |
| 19652 | IrInstructionCheckStatementIsVoid *instruction) | 19885 | IrInstructionCheckStatementIsVoid *instruction) |
| 19653 | { | 19886 | { |
| 19654 | IrInstruction *statement_value = instruction->statement_value->other; | 19887 | IrInstruction *statement_value = instruction->statement_value->other; |
| 19655 | TypeTableEntry *statement_type = statement_value->value.type; | 19888 | ZigType *statement_type = statement_value->value.type; |
| 19656 | if (type_is_invalid(statement_type)) | 19889 | if (type_is_invalid(statement_type)) |
| 19657 | return ira->codegen->builtin_types.entry_invalid; | 19890 | return ira->codegen->builtin_types.entry_invalid; |
| 19658 | | 19891 | |
| 19659 | if (statement_type->id != TypeTableEntryIdVoid) { | 19892 | if (statement_type->id != ZigTypeIdVoid) { |
| 19660 | ir_add_error(ira, &instruction->base, buf_sprintf("expression value is ignored")); | 19893 | ir_add_error(ira, &instruction->base, buf_sprintf("expression value is ignored")); |
| 19661 | } | 19894 | } |
| 19662 | | 19895 | |
| ... | @@ -19664,7 +19897,7 @@ static TypeTableEntry *ir_analyze_instruction_check_statement_is_void(IrAnalyze | ... | @@ -19664,7 +19897,7 @@ static TypeTableEntry *ir_analyze_instruction_check_statement_is_void(IrAnalyze |
| 19664 | return ira->codegen->builtin_types.entry_void; | 19897 | return ira->codegen->builtin_types.entry_void; |
| 19665 | } | 19898 | } |
| 19666 | | 19899 | |
| 19667 | static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) { | 19900 | static ZigType *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) { |
| 19668 | IrInstruction *msg = instruction->msg->other; | 19901 | IrInstruction *msg = instruction->msg->other; |
| 19669 | if (type_is_invalid(msg->value.type)) | 19902 | if (type_is_invalid(msg->value.type)) |
| 19670 | return ir_unreach_error(ira); | 19903 | return ir_unreach_error(ira); |
| ... | @@ -19674,9 +19907,9 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio | ... | @@ -19674,9 +19907,9 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio |
| 19674 | return ir_unreach_error(ira); | 19907 | return ir_unreach_error(ira); |
| 19675 | } | 19908 | } |
| 19676 | | 19909 | |
| 19677 | TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 19910 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 19678 | true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); | 19911 | true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); |
| 19679 | TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type); | 19912 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 19680 | IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type); | 19913 | IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type); |
| 19681 | if (type_is_invalid(casted_msg->value.type)) | 19914 | if (type_is_invalid(casted_msg->value.type)) |
| 19682 | return ir_unreach_error(ira); | 19915 | return ir_unreach_error(ira); |
| ... | @@ -19688,40 +19921,40 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio | ... | @@ -19688,40 +19921,40 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio |
| 19688 | } | 19921 | } |
| 19689 | | 19922 | |
| 19690 | static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) { | 19923 | static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) { |
| 19691 | TypeTableEntry *target_type = target->value.type; | 19924 | ZigType *target_type = target->value.type; |
| 19692 | assert(!type_is_invalid(target_type)); | 19925 | assert(!type_is_invalid(target_type)); |
| 19693 | | 19926 | |
| 19694 | TypeTableEntry *result_type; | 19927 | ZigType *result_type; |
| 19695 | uint32_t old_align_bytes; | 19928 | uint32_t old_align_bytes; |
| 19696 | | 19929 | |
| 19697 | if (target_type->id == TypeTableEntryIdPointer) { | 19930 | if (target_type->id == ZigTypeIdPointer) { |
| 19698 | result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes); | 19931 | result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes); |
| 19699 | old_align_bytes = target_type->data.pointer.alignment; | 19932 | old_align_bytes = target_type->data.pointer.alignment; |
| 19700 | } else if (target_type->id == TypeTableEntryIdFn) { | 19933 | } else if (target_type->id == ZigTypeIdFn) { |
| 19701 | FnTypeId fn_type_id = target_type->data.fn.fn_type_id; | 19934 | FnTypeId fn_type_id = target_type->data.fn.fn_type_id; |
| 19702 | old_align_bytes = fn_type_id.alignment; | 19935 | old_align_bytes = fn_type_id.alignment; |
| 19703 | fn_type_id.alignment = align_bytes; | 19936 | fn_type_id.alignment = align_bytes; |
| 19704 | result_type = get_fn_type(ira->codegen, &fn_type_id); | 19937 | result_type = get_fn_type(ira->codegen, &fn_type_id); |
| 19705 | } else if (target_type->id == TypeTableEntryIdOptional && | 19938 | } else if (target_type->id == ZigTypeIdOptional && |
| 19706 | target_type->data.maybe.child_type->id == TypeTableEntryIdPointer) | 19939 | target_type->data.maybe.child_type->id == ZigTypeIdPointer) |
| 19707 | { | 19940 | { |
| 19708 | TypeTableEntry *ptr_type = target_type->data.maybe.child_type; | 19941 | ZigType *ptr_type = target_type->data.maybe.child_type; |
| 19709 | old_align_bytes = ptr_type->data.pointer.alignment; | 19942 | old_align_bytes = ptr_type->data.pointer.alignment; |
| 19710 | TypeTableEntry *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes); | 19943 | ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes); |
| 19711 | | 19944 | |
| 19712 | result_type = get_optional_type(ira->codegen, better_ptr_type); | 19945 | result_type = get_optional_type(ira->codegen, better_ptr_type); |
| 19713 | } else if (target_type->id == TypeTableEntryIdOptional && | 19946 | } else if (target_type->id == ZigTypeIdOptional && |
| 19714 | target_type->data.maybe.child_type->id == TypeTableEntryIdFn) | 19947 | target_type->data.maybe.child_type->id == ZigTypeIdFn) |
| 19715 | { | 19948 | { |
| 19716 | FnTypeId fn_type_id = target_type->data.maybe.child_type->data.fn.fn_type_id; | 19949 | FnTypeId fn_type_id = target_type->data.maybe.child_type->data.fn.fn_type_id; |
| 19717 | old_align_bytes = fn_type_id.alignment; | 19950 | old_align_bytes = fn_type_id.alignment; |
| 19718 | fn_type_id.alignment = align_bytes; | 19951 | fn_type_id.alignment = align_bytes; |
| 19719 | TypeTableEntry *fn_type = get_fn_type(ira->codegen, &fn_type_id); | 19952 | ZigType *fn_type = get_fn_type(ira->codegen, &fn_type_id); |
| 19720 | result_type = get_optional_type(ira->codegen, fn_type); | 19953 | result_type = get_optional_type(ira->codegen, fn_type); |
| 19721 | } else if (is_slice(target_type)) { | 19954 | } else if (is_slice(target_type)) { |
| 19722 | TypeTableEntry *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry; | 19955 | ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry; |
| 19723 | old_align_bytes = slice_ptr_type->data.pointer.alignment; | 19956 | old_align_bytes = slice_ptr_type->data.pointer.alignment; |
| 19724 | TypeTableEntry *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes); | 19957 | ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes); |
| 19725 | result_type = get_slice_type(ira->codegen, result_ptr_type); | 19958 | result_type = get_slice_type(ira->codegen, result_ptr_type); |
| 19726 | } else { | 19959 | } else { |
| 19727 | ir_add_error(ira, target, | 19960 | ir_add_error(ira, target, |
| ... | @@ -19759,16 +19992,16 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 | ... | @@ -19759,16 +19992,16 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 19759 | return result; | 19992 | return result; |
| 19760 | } | 19993 | } |
| 19761 | | 19994 | |
| 19762 | static TypeTableEntry *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCast *instruction) { | 19995 | static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCast *instruction) { |
| 19763 | Error err; | 19996 | Error err; |
| 19764 | | 19997 | |
| 19765 | IrInstruction *dest_type_value = instruction->dest_type->other; | 19998 | IrInstruction *dest_type_value = instruction->dest_type->other; |
| 19766 | TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value); | 19999 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 19767 | if (type_is_invalid(dest_type)) | 20000 | if (type_is_invalid(dest_type)) |
| 19768 | return ira->codegen->builtin_types.entry_invalid; | 20001 | return ira->codegen->builtin_types.entry_invalid; |
| 19769 | | 20002 | |
| 19770 | IrInstruction *ptr = instruction->ptr->other; | 20003 | IrInstruction *ptr = instruction->ptr->other; |
| 19771 | TypeTableEntry *src_type = ptr->value.type; | 20004 | ZigType *src_type = ptr->value.type; |
| 19772 | if (type_is_invalid(src_type)) | 20005 | if (type_is_invalid(src_type)) |
| 19773 | return ira->codegen->builtin_types.entry_invalid; | 20006 | return ira->codegen->builtin_types.entry_invalid; |
| 19774 | | 20007 | |
| ... | @@ -19835,33 +20068,33 @@ static TypeTableEntry *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruc | ... | @@ -19835,33 +20068,33 @@ static TypeTableEntry *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruc |
| 19835 | static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) { | 20068 | static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) { |
| 19836 | assert(val->special == ConstValSpecialStatic); | 20069 | assert(val->special == ConstValSpecialStatic); |
| 19837 | switch (val->type->id) { | 20070 | switch (val->type->id) { |
| 19838 | case TypeTableEntryIdInvalid: | 20071 | case ZigTypeIdInvalid: |
| 19839 | case TypeTableEntryIdMetaType: | 20072 | case ZigTypeIdMetaType: |
| 19840 | case TypeTableEntryIdOpaque: | 20073 | case ZigTypeIdOpaque: |
| 19841 | case TypeTableEntryIdBoundFn: | 20074 | case ZigTypeIdBoundFn: |
| 19842 | case TypeTableEntryIdArgTuple: | 20075 | case ZigTypeIdArgTuple: |
| 19843 | case TypeTableEntryIdNamespace: | 20076 | case ZigTypeIdNamespace: |
| 19844 | case TypeTableEntryIdBlock: | 20077 | case ZigTypeIdBlock: |
| 19845 | case TypeTableEntryIdUnreachable: | 20078 | case ZigTypeIdUnreachable: |
| 19846 | case TypeTableEntryIdComptimeFloat: | 20079 | case ZigTypeIdComptimeFloat: |
| 19847 | case TypeTableEntryIdComptimeInt: | 20080 | case ZigTypeIdComptimeInt: |
| 19848 | case TypeTableEntryIdUndefined: | 20081 | case ZigTypeIdUndefined: |
| 19849 | case TypeTableEntryIdNull: | 20082 | case ZigTypeIdNull: |
| 19850 | case TypeTableEntryIdPromise: | 20083 | case ZigTypeIdPromise: |
| 19851 | zig_unreachable(); | 20084 | zig_unreachable(); |
| 19852 | case TypeTableEntryIdVoid: | 20085 | case ZigTypeIdVoid: |
| 19853 | return; | 20086 | return; |
| 19854 | case TypeTableEntryIdBool: | 20087 | case ZigTypeIdBool: |
| 19855 | buf[0] = val->data.x_bool ? 1 : 0; | 20088 | buf[0] = val->data.x_bool ? 1 : 0; |
| 19856 | return; | 20089 | return; |
| 19857 | case TypeTableEntryIdInt: | 20090 | case ZigTypeIdInt: |
| 19858 | bigint_write_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count, | 20091 | bigint_write_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count, |
| 19859 | codegen->is_big_endian); | 20092 | codegen->is_big_endian); |
| 19860 | return; | 20093 | return; |
| 19861 | case TypeTableEntryIdFloat: | 20094 | case ZigTypeIdFloat: |
| 19862 | float_write_ieee597(val, buf, codegen->is_big_endian); | 20095 | float_write_ieee597(val, buf, codegen->is_big_endian); |
| 19863 | return; | 20096 | return; |
| 19864 | case TypeTableEntryIdPointer: | 20097 | case ZigTypeIdPointer: |
| 19865 | if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { | 20098 | if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 19866 | BigInt bn; | 20099 | BigInt bn; |
| 19867 | bigint_init_unsigned(&bn, val->data.x_ptr.data.hard_coded_addr.addr); | 20100 | bigint_init_unsigned(&bn, val->data.x_ptr.data.hard_coded_addr.addr); |
| ... | @@ -19870,7 +20103,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue | ... | @@ -19870,7 +20103,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 19870 | } else { | 20103 | } else { |
| 19871 | zig_unreachable(); | 20104 | zig_unreachable(); |
| 19872 | } | 20105 | } |
| 19873 | case TypeTableEntryIdArray: | 20106 | case ZigTypeIdArray: |
| 19874 | { | 20107 | { |
| 19875 | size_t buf_i = 0; | 20108 | size_t buf_i = 0; |
| 19876 | expand_undef_array(codegen, val); | 20109 | expand_undef_array(codegen, val); |
| ... | @@ -19881,19 +20114,19 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue | ... | @@ -19881,19 +20114,19 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 19881 | } | 20114 | } |
| 19882 | } | 20115 | } |
| 19883 | return; | 20116 | return; |
| 19884 | case TypeTableEntryIdStruct: | 20117 | case ZigTypeIdStruct: |
| 19885 | zig_panic("TODO buf_write_value_bytes struct type"); | 20118 | zig_panic("TODO buf_write_value_bytes struct type"); |
| 19886 | case TypeTableEntryIdOptional: | 20119 | case ZigTypeIdOptional: |
| 19887 | zig_panic("TODO buf_write_value_bytes maybe type"); | 20120 | zig_panic("TODO buf_write_value_bytes maybe type"); |
| 19888 | case TypeTableEntryIdErrorUnion: | 20121 | case ZigTypeIdErrorUnion: |
| 19889 | zig_panic("TODO buf_write_value_bytes error union"); | 20122 | zig_panic("TODO buf_write_value_bytes error union"); |
| 19890 | case TypeTableEntryIdErrorSet: | 20123 | case ZigTypeIdErrorSet: |
| 19891 | zig_panic("TODO buf_write_value_bytes pure error type"); | 20124 | zig_panic("TODO buf_write_value_bytes pure error type"); |
| 19892 | case TypeTableEntryIdEnum: | 20125 | case ZigTypeIdEnum: |
| 19893 | zig_panic("TODO buf_write_value_bytes enum type"); | 20126 | zig_panic("TODO buf_write_value_bytes enum type"); |
| 19894 | case TypeTableEntryIdFn: | 20127 | case ZigTypeIdFn: |
| 19895 | zig_panic("TODO buf_write_value_bytes fn type"); | 20128 | zig_panic("TODO buf_write_value_bytes fn type"); |
| 19896 | case TypeTableEntryIdUnion: | 20129 | case ZigTypeIdUnion: |
| 19897 | zig_panic("TODO buf_write_value_bytes union type"); | 20130 | zig_panic("TODO buf_write_value_bytes union type"); |
| 19898 | } | 20131 | } |
| 19899 | zig_unreachable(); | 20132 | zig_unreachable(); |
| ... | @@ -19902,33 +20135,33 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue | ... | @@ -19902,33 +20135,33 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 19902 | static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) { | 20135 | static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) { |
| 19903 | assert(val->special == ConstValSpecialStatic); | 20136 | assert(val->special == ConstValSpecialStatic); |
| 19904 | switch (val->type->id) { | 20137 | switch (val->type->id) { |
| 19905 | case TypeTableEntryIdInvalid: | 20138 | case ZigTypeIdInvalid: |
| 19906 | case TypeTableEntryIdMetaType: | 20139 | case ZigTypeIdMetaType: |
| 19907 | case TypeTableEntryIdOpaque: | 20140 | case ZigTypeIdOpaque: |
| 19908 | case TypeTableEntryIdBoundFn: | 20141 | case ZigTypeIdBoundFn: |
| 19909 | case TypeTableEntryIdArgTuple: | 20142 | case ZigTypeIdArgTuple: |
| 19910 | case TypeTableEntryIdNamespace: | 20143 | case ZigTypeIdNamespace: |
| 19911 | case TypeTableEntryIdBlock: | 20144 | case ZigTypeIdBlock: |
| 19912 | case TypeTableEntryIdUnreachable: | 20145 | case ZigTypeIdUnreachable: |
| 19913 | case TypeTableEntryIdComptimeFloat: | 20146 | case ZigTypeIdComptimeFloat: |
| 19914 | case TypeTableEntryIdComptimeInt: | 20147 | case ZigTypeIdComptimeInt: |
| 19915 | case TypeTableEntryIdUndefined: | 20148 | case ZigTypeIdUndefined: |
| 19916 | case TypeTableEntryIdNull: | 20149 | case ZigTypeIdNull: |
| 19917 | case TypeTableEntryIdPromise: | 20150 | case ZigTypeIdPromise: |
| 19918 | zig_unreachable(); | 20151 | zig_unreachable(); |
| 19919 | case TypeTableEntryIdVoid: | 20152 | case ZigTypeIdVoid: |
| 19920 | return; | 20153 | return; |
| 19921 | case TypeTableEntryIdBool: | 20154 | case ZigTypeIdBool: |
| 19922 | val->data.x_bool = (buf[0] != 0); | 20155 | val->data.x_bool = (buf[0] != 0); |
| 19923 | return; | 20156 | return; |
| 19924 | case TypeTableEntryIdInt: | 20157 | case ZigTypeIdInt: |
| 19925 | bigint_read_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count, | 20158 | bigint_read_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count, |
| 19926 | codegen->is_big_endian, val->type->data.integral.is_signed); | 20159 | codegen->is_big_endian, val->type->data.integral.is_signed); |
| 19927 | return; | 20160 | return; |
| 19928 | case TypeTableEntryIdFloat: | 20161 | case ZigTypeIdFloat: |
| 19929 | float_read_ieee597(val, buf, codegen->is_big_endian); | 20162 | float_read_ieee597(val, buf, codegen->is_big_endian); |
| 19930 | return; | 20163 | return; |
| 19931 | case TypeTableEntryIdPointer: | 20164 | case ZigTypeIdPointer: |
| 19932 | { | 20165 | { |
| 19933 | val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; | 20166 | val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 19934 | BigInt bn; | 20167 | BigInt bn; |
| ... | @@ -19937,35 +20170,35 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue | ... | @@ -19937,35 +20170,35 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 19937 | val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&bn); | 20170 | val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&bn); |
| 19938 | return; | 20171 | return; |
| 19939 | } | 20172 | } |
| 19940 | case TypeTableEntryIdArray: | 20173 | case ZigTypeIdArray: |
| 19941 | zig_panic("TODO buf_read_value_bytes array type"); | 20174 | zig_panic("TODO buf_read_value_bytes array type"); |
| 19942 | case TypeTableEntryIdStruct: | 20175 | case ZigTypeIdStruct: |
| 19943 | zig_panic("TODO buf_read_value_bytes struct type"); | 20176 | zig_panic("TODO buf_read_value_bytes struct type"); |
| 19944 | case TypeTableEntryIdOptional: | 20177 | case ZigTypeIdOptional: |
| 19945 | zig_panic("TODO buf_read_value_bytes maybe type"); | 20178 | zig_panic("TODO buf_read_value_bytes maybe type"); |
| 19946 | case TypeTableEntryIdErrorUnion: | 20179 | case ZigTypeIdErrorUnion: |
| 19947 | zig_panic("TODO buf_read_value_bytes error union"); | 20180 | zig_panic("TODO buf_read_value_bytes error union"); |
| 19948 | case TypeTableEntryIdErrorSet: | 20181 | case ZigTypeIdErrorSet: |
| 19949 | zig_panic("TODO buf_read_value_bytes pure error type"); | 20182 | zig_panic("TODO buf_read_value_bytes pure error type"); |
| 19950 | case TypeTableEntryIdEnum: | 20183 | case ZigTypeIdEnum: |
| 19951 | zig_panic("TODO buf_read_value_bytes enum type"); | 20184 | zig_panic("TODO buf_read_value_bytes enum type"); |
| 19952 | case TypeTableEntryIdFn: | 20185 | case ZigTypeIdFn: |
| 19953 | zig_panic("TODO buf_read_value_bytes fn type"); | 20186 | zig_panic("TODO buf_read_value_bytes fn type"); |
| 19954 | case TypeTableEntryIdUnion: | 20187 | case ZigTypeIdUnion: |
| 19955 | zig_panic("TODO buf_read_value_bytes union type"); | 20188 | zig_panic("TODO buf_read_value_bytes union type"); |
| 19956 | } | 20189 | } |
| 19957 | zig_unreachable(); | 20190 | zig_unreachable(); |
| 19958 | } | 20191 | } |
| 19959 | | 20192 | |
| 19960 | static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBitCast *instruction) { | 20193 | static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBitCast *instruction) { |
| 19961 | Error err; | 20194 | Error err; |
| 19962 | IrInstruction *dest_type_value = instruction->dest_type->other; | 20195 | IrInstruction *dest_type_value = instruction->dest_type->other; |
| 19963 | TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value); | 20196 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 19964 | if (type_is_invalid(dest_type)) | 20197 | if (type_is_invalid(dest_type)) |
| 19965 | return ira->codegen->builtin_types.entry_invalid; | 20198 | return ira->codegen->builtin_types.entry_invalid; |
| 19966 | | 20199 | |
| 19967 | IrInstruction *value = instruction->value->other; | 20200 | IrInstruction *value = instruction->value->other; |
| 19968 | TypeTableEntry *src_type = value->value.type; | 20201 | ZigType *src_type = value->value.type; |
| 19969 | if (type_is_invalid(src_type)) | 20202 | if (type_is_invalid(src_type)) |
| 19970 | return ira->codegen->builtin_types.entry_invalid; | 20203 | return ira->codegen->builtin_types.entry_invalid; |
| 19971 | | 20204 | |
| ... | @@ -19982,18 +20215,18 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc | ... | @@ -19982,18 +20215,18 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc |
| 19982 | } | 20215 | } |
| 19983 | | 20216 | |
| 19984 | switch (src_type->id) { | 20217 | switch (src_type->id) { |
| 19985 | case TypeTableEntryIdInvalid: | 20218 | case ZigTypeIdInvalid: |
| 19986 | case TypeTableEntryIdMetaType: | 20219 | case ZigTypeIdMetaType: |
| 19987 | case TypeTableEntryIdOpaque: | 20220 | case ZigTypeIdOpaque: |
| 19988 | case TypeTableEntryIdBoundFn: | 20221 | case ZigTypeIdBoundFn: |
| 19989 | case TypeTableEntryIdArgTuple: | 20222 | case ZigTypeIdArgTuple: |
| 19990 | case TypeTableEntryIdNamespace: | 20223 | case ZigTypeIdNamespace: |
| 19991 | case TypeTableEntryIdBlock: | 20224 | case ZigTypeIdBlock: |
| 19992 | case TypeTableEntryIdUnreachable: | 20225 | case ZigTypeIdUnreachable: |
| 19993 | case TypeTableEntryIdComptimeFloat: | 20226 | case ZigTypeIdComptimeFloat: |
| 19994 | case TypeTableEntryIdComptimeInt: | 20227 | case ZigTypeIdComptimeInt: |
| 19995 | case TypeTableEntryIdUndefined: | 20228 | case ZigTypeIdUndefined: |
| 19996 | case TypeTableEntryIdNull: | 20229 | case ZigTypeIdNull: |
| 19997 | ir_add_error(ira, dest_type_value, | 20230 | ir_add_error(ira, dest_type_value, |
| 19998 | buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name))); | 20231 | buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name))); |
| 19999 | return ira->codegen->builtin_types.entry_invalid; | 20232 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20008,18 +20241,18 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc | ... | @@ -20008,18 +20241,18 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc |
| 20008 | } | 20241 | } |
| 20009 | | 20242 | |
| 20010 | switch (dest_type->id) { | 20243 | switch (dest_type->id) { |
| 20011 | case TypeTableEntryIdInvalid: | 20244 | case ZigTypeIdInvalid: |
| 20012 | case TypeTableEntryIdMetaType: | 20245 | case ZigTypeIdMetaType: |
| 20013 | case TypeTableEntryIdOpaque: | 20246 | case ZigTypeIdOpaque: |
| 20014 | case TypeTableEntryIdBoundFn: | 20247 | case ZigTypeIdBoundFn: |
| 20015 | case TypeTableEntryIdArgTuple: | 20248 | case ZigTypeIdArgTuple: |
| 20016 | case TypeTableEntryIdNamespace: | 20249 | case ZigTypeIdNamespace: |
| 20017 | case TypeTableEntryIdBlock: | 20250 | case ZigTypeIdBlock: |
| 20018 | case TypeTableEntryIdUnreachable: | 20251 | case ZigTypeIdUnreachable: |
| 20019 | case TypeTableEntryIdComptimeFloat: | 20252 | case ZigTypeIdComptimeFloat: |
| 20020 | case TypeTableEntryIdComptimeInt: | 20253 | case ZigTypeIdComptimeInt: |
| 20021 | case TypeTableEntryIdUndefined: | 20254 | case ZigTypeIdUndefined: |
| 20022 | case TypeTableEntryIdNull: | 20255 | case ZigTypeIdNull: |
| 20023 | ir_add_error(ira, dest_type_value, | 20256 | ir_add_error(ira, dest_type_value, |
| 20024 | buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name))); | 20257 | buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name))); |
| 20025 | return ira->codegen->builtin_types.entry_invalid; | 20258 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20057,10 +20290,10 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc | ... | @@ -20057,10 +20290,10 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc |
| 20057 | return dest_type; | 20290 | return dest_type; |
| 20058 | } | 20291 | } |
| 20059 | | 20292 | |
| 20060 | static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) { | 20293 | static ZigType *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) { |
| 20061 | Error err; | 20294 | Error err; |
| 20062 | IrInstruction *dest_type_value = instruction->dest_type->other; | 20295 | IrInstruction *dest_type_value = instruction->dest_type->other; |
| 20063 | TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value); | 20296 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 20064 | if (type_is_invalid(dest_type)) | 20297 | if (type_is_invalid(dest_type)) |
| 20065 | return ira->codegen->builtin_types.entry_invalid; | 20298 | return ira->codegen->builtin_types.entry_invalid; |
| 20066 | | 20299 | |
| ... | @@ -20102,7 +20335,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstr | ... | @@ -20102,7 +20335,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstr |
| 20102 | return dest_type; | 20335 | return dest_type; |
| 20103 | } | 20336 | } |
| 20104 | | 20337 | |
| 20105 | static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, | 20338 | static ZigType *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 20106 | IrInstructionDeclRef *instruction) | 20339 | IrInstructionDeclRef *instruction) |
| 20107 | { | 20340 | { |
| 20108 | Tld *tld = instruction->tld; | 20341 | Tld *tld = instruction->tld; |
| ... | @@ -20119,7 +20352,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, | ... | @@ -20119,7 +20352,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 20119 | case TldIdVar: | 20352 | case TldIdVar: |
| 20120 | { | 20353 | { |
| 20121 | TldVar *tld_var = (TldVar *)tld; | 20354 | TldVar *tld_var = (TldVar *)tld; |
| 20122 | VariableTableEntry *var = tld_var->var; | 20355 | ZigVar *var = tld_var->var; |
| 20123 | | 20356 | |
| 20124 | IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var); | 20357 | IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var); |
| 20125 | if (type_is_invalid(var_ptr->value.type)) | 20358 | if (type_is_invalid(var_ptr->value.type)) |
| ... | @@ -20141,7 +20374,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, | ... | @@ -20141,7 +20374,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 20141 | case TldIdFn: | 20374 | case TldIdFn: |
| 20142 | { | 20375 | { |
| 20143 | TldFn *tld_fn = (TldFn *)tld; | 20376 | TldFn *tld_fn = (TldFn *)tld; |
| 20144 | FnTableEntry *fn_entry = tld_fn->fn_entry; | 20377 | ZigFn *fn_entry = tld_fn->fn_entry; |
| 20145 | assert(fn_entry->type_entry); | 20378 | assert(fn_entry->type_entry); |
| 20146 | | 20379 | |
| 20147 | if (tld_fn->extern_lib_name != nullptr) { | 20380 | if (tld_fn->extern_lib_name != nullptr) { |
| ... | @@ -20163,12 +20396,12 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, | ... | @@ -20163,12 +20396,12 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 20163 | zig_unreachable(); | 20396 | zig_unreachable(); |
| 20164 | } | 20397 | } |
| 20165 | | 20398 | |
| 20166 | static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) { | 20399 | static ZigType *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) { |
| 20167 | IrInstruction *target = instruction->target->other; | 20400 | IrInstruction *target = instruction->target->other; |
| 20168 | if (type_is_invalid(target->value.type)) | 20401 | if (type_is_invalid(target->value.type)) |
| 20169 | return ira->codegen->builtin_types.entry_invalid; | 20402 | return ira->codegen->builtin_types.entry_invalid; |
| 20170 | | 20403 | |
| 20171 | TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; | 20404 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 20172 | | 20405 | |
| 20173 | if (get_codegen_ptr_type(target->value.type) == nullptr) { | 20406 | if (get_codegen_ptr_type(target->value.type) == nullptr) { |
| 20174 | ir_add_error(ira, target, | 20407 | ir_add_error(ira, target, |
| ... | @@ -20186,7 +20419,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr | ... | @@ -20186,7 +20419,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr |
| 20186 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); | 20419 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 20187 | if (!val) | 20420 | if (!val) |
| 20188 | return ira->codegen->builtin_types.entry_invalid; | 20421 | return ira->codegen->builtin_types.entry_invalid; |
| 20189 | if (val->type->id == TypeTableEntryIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { | 20422 | if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 20190 | IrInstruction *result = ir_create_const(&ira->new_irb, instruction->base.scope, | 20423 | IrInstruction *result = ir_create_const(&ira->new_irb, instruction->base.scope, |
| 20191 | instruction->base.source_node, usize); | 20424 | instruction->base.source_node, usize); |
| 20192 | bigint_init_unsigned(&result->value.data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr); | 20425 | bigint_init_unsigned(&result->value.data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr); |
| ... | @@ -20202,16 +20435,16 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr | ... | @@ -20202,16 +20435,16 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr |
| 20202 | return usize; | 20435 | return usize; |
| 20203 | } | 20436 | } |
| 20204 | | 20437 | |
| 20205 | static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) { | 20438 | static ZigType *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) { |
| 20206 | Error err; | 20439 | Error err; |
| 20207 | TypeTableEntry *child_type = ir_resolve_type(ira, instruction->child_type->other); | 20440 | ZigType *child_type = ir_resolve_type(ira, instruction->child_type->other); |
| 20208 | if (type_is_invalid(child_type)) | 20441 | if (type_is_invalid(child_type)) |
| 20209 | return ira->codegen->builtin_types.entry_invalid; | 20442 | return ira->codegen->builtin_types.entry_invalid; |
| 20210 | | 20443 | |
| 20211 | if (child_type->id == TypeTableEntryIdUnreachable) { | 20444 | if (child_type->id == ZigTypeIdUnreachable) { |
| 20212 | ir_add_error(ira, &instruction->base, buf_sprintf("pointer to noreturn not allowed")); | 20445 | ir_add_error(ira, &instruction->base, buf_sprintf("pointer to noreturn not allowed")); |
| 20213 | return ira->codegen->builtin_types.entry_invalid; | 20446 | return ira->codegen->builtin_types.entry_invalid; |
| 20214 | } else if (child_type->id == TypeTableEntryIdOpaque && instruction->ptr_len == PtrLenUnknown) { | 20447 | } else if (child_type->id == ZigTypeIdOpaque && instruction->ptr_len == PtrLenUnknown) { |
| 20215 | ir_add_error(ira, &instruction->base, buf_sprintf("unknown-length pointer to opaque")); | 20448 | ir_add_error(ira, &instruction->base, buf_sprintf("unknown-length pointer to opaque")); |
| 20216 | return ira->codegen->builtin_types.entry_invalid; | 20449 | return ira->codegen->builtin_types.entry_invalid; |
| 20217 | } | 20450 | } |
| ... | @@ -20235,7 +20468,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruc | ... | @@ -20235,7 +20468,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruc |
| 20235 | return ira->codegen->builtin_types.entry_type; | 20468 | return ira->codegen->builtin_types.entry_type; |
| 20236 | } | 20469 | } |
| 20237 | | 20470 | |
| 20238 | static TypeTableEntry *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) { | 20471 | static ZigType *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) { |
| 20239 | uint32_t align_bytes; | 20472 | uint32_t align_bytes; |
| 20240 | IrInstruction *align_bytes_inst = instruction->align_bytes->other; | 20473 | IrInstruction *align_bytes_inst = instruction->align_bytes->other; |
| 20241 | if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes)) | 20474 | if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes)) |
| ... | @@ -20253,7 +20486,7 @@ static TypeTableEntry *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstr | ... | @@ -20253,7 +20486,7 @@ static TypeTableEntry *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstr |
| 20253 | return result->value.type; | 20486 | return result->value.type; |
| 20254 | } | 20487 | } |
| 20255 | | 20488 | |
| 20256 | static TypeTableEntry *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) { | 20489 | static ZigType *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) { |
| 20257 | Buf *name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque", instruction->base.source_node); | 20490 | Buf *name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque", instruction->base.source_node); |
| 20258 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 20491 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 20259 | out_val->data.x_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node, | 20492 | out_val->data.x_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node, |
| ... | @@ -20261,7 +20494,7 @@ static TypeTableEntry *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInst | ... | @@ -20261,7 +20494,7 @@ static TypeTableEntry *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInst |
| 20261 | return ira->codegen->builtin_types.entry_type; | 20494 | return ira->codegen->builtin_types.entry_type; |
| 20262 | } | 20495 | } |
| 20263 | | 20496 | |
| 20264 | static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstructionSetAlignStack *instruction) { | 20497 | static ZigType *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstructionSetAlignStack *instruction) { |
| 20265 | uint32_t align_bytes; | 20498 | uint32_t align_bytes; |
| 20266 | IrInstruction *align_bytes_inst = instruction->align_bytes->other; | 20499 | IrInstruction *align_bytes_inst = instruction->align_bytes->other; |
| 20267 | if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes)) | 20500 | if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes)) |
| ... | @@ -20272,7 +20505,7 @@ static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, Ir | ... | @@ -20272,7 +20505,7 @@ static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, Ir |
| 20272 | return ira->codegen->builtin_types.entry_invalid; | 20505 | return ira->codegen->builtin_types.entry_invalid; |
| 20273 | } | 20506 | } |
| 20274 | | 20507 | |
| 20275 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); | 20508 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 20276 | if (fn_entry == nullptr) { | 20509 | if (fn_entry == nullptr) { |
| 20277 | ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function")); | 20510 | ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function")); |
| 20278 | return ira->codegen->builtin_types.entry_invalid; | 20511 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20301,9 +20534,9 @@ static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, Ir | ... | @@ -20301,9 +20534,9 @@ static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, Ir |
| 20301 | return ira->codegen->builtin_types.entry_void; | 20534 | return ira->codegen->builtin_types.entry_void; |
| 20302 | } | 20535 | } |
| 20303 | | 20536 | |
| 20304 | static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) { | 20537 | static ZigType *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) { |
| 20305 | IrInstruction *fn_type_inst = instruction->fn_type->other; | 20538 | IrInstruction *fn_type_inst = instruction->fn_type->other; |
| 20306 | TypeTableEntry *fn_type = ir_resolve_type(ira, fn_type_inst); | 20539 | ZigType *fn_type = ir_resolve_type(ira, fn_type_inst); |
| 20307 | if (type_is_invalid(fn_type)) | 20540 | if (type_is_invalid(fn_type)) |
| 20308 | return ira->codegen->builtin_types.entry_invalid; | 20541 | return ira->codegen->builtin_types.entry_invalid; |
| 20309 | | 20542 | |
| ... | @@ -20312,7 +20545,7 @@ static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruc | ... | @@ -20312,7 +20545,7 @@ static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruc |
| 20312 | if (!ir_resolve_usize(ira, arg_index_inst, &arg_index)) | 20545 | if (!ir_resolve_usize(ira, arg_index_inst, &arg_index)) |
| 20313 | return ira->codegen->builtin_types.entry_invalid; | 20546 | return ira->codegen->builtin_types.entry_invalid; |
| 20314 | | 20547 | |
| 20315 | if (fn_type->id != TypeTableEntryIdFn) { | 20548 | if (fn_type->id != ZigTypeIdFn) { |
| 20316 | ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name))); | 20549 | ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name))); |
| 20317 | return ira->codegen->builtin_types.entry_invalid; | 20550 | return ira->codegen->builtin_types.entry_invalid; |
| 20318 | } | 20551 | } |
| ... | @@ -20340,21 +20573,21 @@ static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruc | ... | @@ -20340,21 +20573,21 @@ static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruc |
| 20340 | return ira->codegen->builtin_types.entry_type; | 20573 | return ira->codegen->builtin_types.entry_type; |
| 20341 | } | 20574 | } |
| 20342 | | 20575 | |
| 20343 | static TypeTableEntry *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) { | 20576 | static ZigType *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) { |
| 20344 | Error err; | 20577 | Error err; |
| 20345 | IrInstruction *target_inst = instruction->target->other; | 20578 | IrInstruction *target_inst = instruction->target->other; |
| 20346 | TypeTableEntry *enum_type = ir_resolve_type(ira, target_inst); | 20579 | ZigType *enum_type = ir_resolve_type(ira, target_inst); |
| 20347 | if (type_is_invalid(enum_type)) | 20580 | if (type_is_invalid(enum_type)) |
| 20348 | return ira->codegen->builtin_types.entry_invalid; | 20581 | return ira->codegen->builtin_types.entry_invalid; |
| 20349 | | 20582 | |
| 20350 | if (enum_type->id == TypeTableEntryIdEnum) { | 20583 | if (enum_type->id == ZigTypeIdEnum) { |
| 20351 | if ((err = ensure_complete_type(ira->codegen, enum_type))) | 20584 | if ((err = ensure_complete_type(ira->codegen, enum_type))) |
| 20352 | return ira->codegen->builtin_types.entry_invalid; | 20585 | return ira->codegen->builtin_types.entry_invalid; |
| 20353 | | 20586 | |
| 20354 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 20587 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 20355 | out_val->data.x_type = enum_type->data.enumeration.tag_int_type; | 20588 | out_val->data.x_type = enum_type->data.enumeration.tag_int_type; |
| 20356 | return ira->codegen->builtin_types.entry_type; | 20589 | return ira->codegen->builtin_types.entry_type; |
| 20357 | } else if (enum_type->id == TypeTableEntryIdUnion) { | 20590 | } else if (enum_type->id == ZigTypeIdUnion) { |
| 20358 | if ((err = ensure_complete_type(ira->codegen, enum_type))) | 20591 | if ((err = ensure_complete_type(ira->codegen, enum_type))) |
| 20359 | return ira->codegen->builtin_types.entry_invalid; | 20592 | return ira->codegen->builtin_types.entry_invalid; |
| 20360 | | 20593 | |
| ... | @@ -20378,7 +20611,7 @@ static TypeTableEntry *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstruc | ... | @@ -20378,7 +20611,7 @@ static TypeTableEntry *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstruc |
| 20378 | } | 20611 | } |
| 20379 | } | 20612 | } |
| 20380 | | 20613 | |
| 20381 | static TypeTableEntry *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) { | 20614 | static ZigType *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) { |
| 20382 | IrInstruction *target_inst = instruction->target->other; | 20615 | IrInstruction *target_inst = instruction->target->other; |
| 20383 | if (type_is_invalid(target_inst->value.type)) | 20616 | if (type_is_invalid(target_inst->value.type)) |
| 20384 | return ira->codegen->builtin_types.entry_invalid; | 20617 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20393,7 +20626,7 @@ static TypeTableEntry *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructi | ... | @@ -20393,7 +20626,7 @@ static TypeTableEntry *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructi |
| 20393 | return result->value.type; | 20626 | return result->value.type; |
| 20394 | } | 20627 | } |
| 20395 | | 20628 | |
| 20396 | static TypeTableEntry *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstructionCoroId *instruction) { | 20629 | static ZigType *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstructionCoroId *instruction) { |
| 20397 | IrInstruction *promise_ptr = instruction->promise_ptr->other; | 20630 | IrInstruction *promise_ptr = instruction->promise_ptr->other; |
| 20398 | if (type_is_invalid(promise_ptr->value.type)) | 20631 | if (type_is_invalid(promise_ptr->value.type)) |
| 20399 | return ira->codegen->builtin_types.entry_invalid; | 20632 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20405,7 +20638,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstruct | ... | @@ -20405,7 +20638,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstruct |
| 20405 | return result->value.type; | 20638 | return result->value.type; |
| 20406 | } | 20639 | } |
| 20407 | | 20640 | |
| 20408 | static TypeTableEntry *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstructionCoroAlloc *instruction) { | 20641 | static ZigType *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstructionCoroAlloc *instruction) { |
| 20409 | IrInstruction *coro_id = instruction->coro_id->other; | 20642 | IrInstruction *coro_id = instruction->coro_id->other; |
| 20410 | if (type_is_invalid(coro_id->value.type)) | 20643 | if (type_is_invalid(coro_id->value.type)) |
| 20411 | return ira->codegen->builtin_types.entry_invalid; | 20644 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20417,14 +20650,14 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstr | ... | @@ -20417,14 +20650,14 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstr |
| 20417 | return result->value.type; | 20650 | return result->value.type; |
| 20418 | } | 20651 | } |
| 20419 | | 20652 | |
| 20420 | static TypeTableEntry *ir_analyze_instruction_coro_size(IrAnalyze *ira, IrInstructionCoroSize *instruction) { | 20653 | static ZigType *ir_analyze_instruction_coro_size(IrAnalyze *ira, IrInstructionCoroSize *instruction) { |
| 20421 | IrInstruction *result = ir_build_coro_size(&ira->new_irb, instruction->base.scope, instruction->base.source_node); | 20654 | IrInstruction *result = ir_build_coro_size(&ira->new_irb, instruction->base.scope, instruction->base.source_node); |
| 20422 | ir_link_new_instruction(result, &instruction->base); | 20655 | ir_link_new_instruction(result, &instruction->base); |
| 20423 | result->value.type = ira->codegen->builtin_types.entry_usize; | 20656 | result->value.type = ira->codegen->builtin_types.entry_usize; |
| 20424 | return result->value.type; | 20657 | return result->value.type; |
| 20425 | } | 20658 | } |
| 20426 | | 20659 | |
| 20427 | static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstructionCoroBegin *instruction) { | 20660 | static ZigType *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstructionCoroBegin *instruction) { |
| 20428 | IrInstruction *coro_id = instruction->coro_id->other; | 20661 | IrInstruction *coro_id = instruction->coro_id->other; |
| 20429 | if (type_is_invalid(coro_id->value.type)) | 20662 | if (type_is_invalid(coro_id->value.type)) |
| 20430 | return ira->codegen->builtin_types.entry_invalid; | 20663 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20433,7 +20666,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr | ... | @@ -20433,7 +20666,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr |
| 20433 | if (type_is_invalid(coro_mem_ptr->value.type)) | 20666 | if (type_is_invalid(coro_mem_ptr->value.type)) |
| 20434 | return ira->codegen->builtin_types.entry_invalid; | 20667 | return ira->codegen->builtin_types.entry_invalid; |
| 20435 | | 20668 | |
| 20436 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); | 20669 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 20437 | assert(fn_entry != nullptr); | 20670 | assert(fn_entry != nullptr); |
| 20438 | IrInstruction *result = ir_build_coro_begin(&ira->new_irb, instruction->base.scope, instruction->base.source_node, | 20671 | IrInstruction *result = ir_build_coro_begin(&ira->new_irb, instruction->base.scope, instruction->base.source_node, |
| 20439 | coro_id, coro_mem_ptr); | 20672 | coro_id, coro_mem_ptr); |
| ... | @@ -20442,13 +20675,13 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr | ... | @@ -20442,13 +20675,13 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr |
| 20442 | return result->value.type; | 20675 | return result->value.type; |
| 20443 | } | 20676 | } |
| 20444 | | 20677 | |
| 20445 | static TypeTableEntry *ir_analyze_instruction_get_implicit_allocator(IrAnalyze *ira, IrInstructionGetImplicitAllocator *instruction) { | 20678 | static ZigType *ir_analyze_instruction_get_implicit_allocator(IrAnalyze *ira, IrInstructionGetImplicitAllocator *instruction) { |
| 20446 | IrInstruction *result = ir_get_implicit_allocator(ira, &instruction->base, instruction->id); | 20679 | IrInstruction *result = ir_get_implicit_allocator(ira, &instruction->base, instruction->id); |
| 20447 | ir_link_new_instruction(result, &instruction->base); | 20680 | ir_link_new_instruction(result, &instruction->base); |
| 20448 | return result->value.type; | 20681 | return result->value.type; |
| 20449 | } | 20682 | } |
| 20450 | | 20683 | |
| 20451 | static TypeTableEntry *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, IrInstructionCoroAllocFail *instruction) { | 20684 | static ZigType *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, IrInstructionCoroAllocFail *instruction) { |
| 20452 | IrInstruction *err_val = instruction->err_val->other; | 20685 | IrInstruction *err_val = instruction->err_val->other; |
| 20453 | if (type_is_invalid(err_val->value.type)) | 20686 | if (type_is_invalid(err_val->value.type)) |
| 20454 | return ir_unreach_error(ira); | 20687 | return ir_unreach_error(ira); |
| ... | @@ -20459,7 +20692,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, Ir | ... | @@ -20459,7 +20692,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, Ir |
| 20459 | return ir_finish_anal(ira, result->value.type); | 20692 | return ir_finish_anal(ira, result->value.type); |
| 20460 | } | 20693 | } |
| 20461 | | 20694 | |
| 20462 | static TypeTableEntry *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrInstructionCoroSuspend *instruction) { | 20695 | static ZigType *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrInstructionCoroSuspend *instruction) { |
| 20463 | IrInstruction *save_point = nullptr; | 20696 | IrInstruction *save_point = nullptr; |
| 20464 | if (instruction->save_point != nullptr) { | 20697 | if (instruction->save_point != nullptr) { |
| 20465 | save_point = instruction->save_point->other; | 20698 | save_point = instruction->save_point->other; |
| ... | @@ -20478,7 +20711,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrIns | ... | @@ -20478,7 +20711,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrIns |
| 20478 | return result->value.type; | 20711 | return result->value.type; |
| 20479 | } | 20712 | } |
| 20480 | | 20713 | |
| 20481 | static TypeTableEntry *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstructionCoroEnd *instruction) { | 20714 | static ZigType *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstructionCoroEnd *instruction) { |
| 20482 | IrInstruction *result = ir_build_coro_end(&ira->new_irb, instruction->base.scope, | 20715 | IrInstruction *result = ir_build_coro_end(&ira->new_irb, instruction->base.scope, |
| 20483 | instruction->base.source_node); | 20716 | instruction->base.source_node); |
| 20484 | ir_link_new_instruction(result, &instruction->base); | 20717 | ir_link_new_instruction(result, &instruction->base); |
| ... | @@ -20486,7 +20719,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstruc | ... | @@ -20486,7 +20719,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstruc |
| 20486 | return result->value.type; | 20719 | return result->value.type; |
| 20487 | } | 20720 | } |
| 20488 | | 20721 | |
| 20489 | static TypeTableEntry *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstructionCoroFree *instruction) { | 20722 | static ZigType *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstructionCoroFree *instruction) { |
| 20490 | IrInstruction *coro_id = instruction->coro_id->other; | 20723 | IrInstruction *coro_id = instruction->coro_id->other; |
| 20491 | if (type_is_invalid(coro_id->value.type)) | 20724 | if (type_is_invalid(coro_id->value.type)) |
| 20492 | return ira->codegen->builtin_types.entry_invalid; | 20725 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20498,12 +20731,12 @@ static TypeTableEntry *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstru | ... | @@ -20498,12 +20731,12 @@ static TypeTableEntry *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstru |
| 20498 | IrInstruction *result = ir_build_coro_free(&ira->new_irb, instruction->base.scope, | 20731 | IrInstruction *result = ir_build_coro_free(&ira->new_irb, instruction->base.scope, |
| 20499 | instruction->base.source_node, coro_id, coro_handle); | 20732 | instruction->base.source_node, coro_id, coro_handle); |
| 20500 | ir_link_new_instruction(result, &instruction->base); | 20733 | ir_link_new_instruction(result, &instruction->base); |
| 20501 | TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false); | 20734 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false); |
| 20502 | result->value.type = get_optional_type(ira->codegen, ptr_type); | 20735 | result->value.type = get_optional_type(ira->codegen, ptr_type); |
| 20503 | return result->value.type; | 20736 | return result->value.type; |
| 20504 | } | 20737 | } |
| 20505 | | 20738 | |
| 20506 | static TypeTableEntry *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstructionCoroResume *instruction) { | 20739 | static ZigType *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstructionCoroResume *instruction) { |
| 20507 | IrInstruction *awaiter_handle = instruction->awaiter_handle->other; | 20740 | IrInstruction *awaiter_handle = instruction->awaiter_handle->other; |
| 20508 | if (type_is_invalid(awaiter_handle->value.type)) | 20741 | if (type_is_invalid(awaiter_handle->value.type)) |
| 20509 | return ira->codegen->builtin_types.entry_invalid; | 20742 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20519,7 +20752,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInst | ... | @@ -20519,7 +20752,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInst |
| 20519 | return result->value.type; | 20752 | return result->value.type; |
| 20520 | } | 20753 | } |
| 20521 | | 20754 | |
| 20522 | static TypeTableEntry *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstructionCoroSave *instruction) { | 20755 | static ZigType *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstructionCoroSave *instruction) { |
| 20523 | IrInstruction *coro_handle = instruction->coro_handle->other; | 20756 | IrInstruction *coro_handle = instruction->coro_handle->other; |
| 20524 | if (type_is_invalid(coro_handle->value.type)) | 20757 | if (type_is_invalid(coro_handle->value.type)) |
| 20525 | return ira->codegen->builtin_types.entry_invalid; | 20758 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20531,12 +20764,12 @@ static TypeTableEntry *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstru | ... | @@ -20531,12 +20764,12 @@ static TypeTableEntry *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstru |
| 20531 | return result->value.type; | 20764 | return result->value.type; |
| 20532 | } | 20765 | } |
| 20533 | | 20766 | |
| 20534 | static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructionCoroPromise *instruction) { | 20767 | static ZigType *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructionCoroPromise *instruction) { |
| 20535 | IrInstruction *coro_handle = instruction->coro_handle->other; | 20768 | IrInstruction *coro_handle = instruction->coro_handle->other; |
| 20536 | if (type_is_invalid(coro_handle->value.type)) | 20769 | if (type_is_invalid(coro_handle->value.type)) |
| 20537 | return ira->codegen->builtin_types.entry_invalid; | 20770 | return ira->codegen->builtin_types.entry_invalid; |
| 20538 | | 20771 | |
| 20539 | if (coro_handle->value.type->id != TypeTableEntryIdPromise || | 20772 | if (coro_handle->value.type->id != ZigTypeIdPromise || |
| 20540 | coro_handle->value.type->data.promise.result_type == nullptr) | 20773 | coro_handle->value.type->data.promise.result_type == nullptr) |
| 20541 | { | 20774 | { |
| 20542 | ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'", | 20775 | ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'", |
| ... | @@ -20544,7 +20777,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrIns | ... | @@ -20544,7 +20777,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrIns |
| 20544 | return ira->codegen->builtin_types.entry_invalid; | 20777 | return ira->codegen->builtin_types.entry_invalid; |
| 20545 | } | 20778 | } |
| 20546 | | 20779 | |
| 20547 | TypeTableEntry *coro_frame_type = get_promise_frame_type(ira->codegen, | 20780 | ZigType *coro_frame_type = get_promise_frame_type(ira->codegen, |
| 20548 | coro_handle->value.type->data.promise.result_type); | 20781 | coro_handle->value.type->data.promise.result_type); |
| 20549 | | 20782 | |
| 20550 | IrInstruction *result = ir_build_coro_promise(&ira->new_irb, instruction->base.scope, | 20783 | IrInstruction *result = ir_build_coro_promise(&ira->new_irb, instruction->base.scope, |
| ... | @@ -20554,7 +20787,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrIns | ... | @@ -20554,7 +20787,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrIns |
| 20554 | return result->value.type; | 20787 | return result->value.type; |
| 20555 | } | 20788 | } |
| 20556 | | 20789 | |
| 20557 | static TypeTableEntry *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, IrInstructionCoroAllocHelper *instruction) { | 20790 | static ZigType *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, IrInstructionCoroAllocHelper *instruction) { |
| 20558 | IrInstruction *alloc_fn = instruction->alloc_fn->other; | 20791 | IrInstruction *alloc_fn = instruction->alloc_fn->other; |
| 20559 | if (type_is_invalid(alloc_fn->value.type)) | 20792 | if (type_is_invalid(alloc_fn->value.type)) |
| 20560 | return ira->codegen->builtin_types.entry_invalid; | 20793 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20566,17 +20799,17 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, | ... | @@ -20566,17 +20799,17 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, |
| 20566 | IrInstruction *result = ir_build_coro_alloc_helper(&ira->new_irb, instruction->base.scope, | 20799 | IrInstruction *result = ir_build_coro_alloc_helper(&ira->new_irb, instruction->base.scope, |
| 20567 | instruction->base.source_node, alloc_fn, coro_size); | 20800 | instruction->base.source_node, alloc_fn, coro_size); |
| 20568 | ir_link_new_instruction(result, &instruction->base); | 20801 | ir_link_new_instruction(result, &instruction->base); |
| 20569 | TypeTableEntry *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false); | 20802 | ZigType *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false); |
| 20570 | result->value.type = get_optional_type(ira->codegen, u8_ptr_type); | 20803 | result->value.type = get_optional_type(ira->codegen, u8_ptr_type); |
| 20571 | return result->value.type; | 20804 | return result->value.type; |
| 20572 | } | 20805 | } |
| 20573 | | 20806 | |
| 20574 | static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) { | 20807 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) { |
| 20575 | TypeTableEntry *operand_type = ir_resolve_type(ira, op); | 20808 | ZigType *operand_type = ir_resolve_type(ira, op); |
| 20576 | if (type_is_invalid(operand_type)) | 20809 | if (type_is_invalid(operand_type)) |
| 20577 | return ira->codegen->builtin_types.entry_invalid; | 20810 | return ira->codegen->builtin_types.entry_invalid; |
| 20578 | | 20811 | |
| 20579 | if (operand_type->id == TypeTableEntryIdInt) { | 20812 | if (operand_type->id == ZigTypeIdInt) { |
| 20580 | if (operand_type->data.integral.bit_count < 8) { | 20813 | if (operand_type->data.integral.bit_count < 8) { |
| 20581 | ir_add_error(ira, op, | 20814 | ir_add_error(ira, op, |
| 20582 | buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type", | 20815 | buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type", |
| ... | @@ -20603,8 +20836,8 @@ static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruct | ... | @@ -20603,8 +20836,8 @@ static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruct |
| 20603 | return operand_type; | 20836 | return operand_type; |
| 20604 | } | 20837 | } |
| 20605 | | 20838 | |
| 20606 | static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) { | 20839 | static ZigType *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) { |
| 20607 | TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other); | 20840 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other); |
| 20608 | if (type_is_invalid(operand_type)) | 20841 | if (type_is_invalid(operand_type)) |
| 20609 | return ira->codegen->builtin_types.entry_invalid; | 20842 | return ira->codegen->builtin_types.entry_invalid; |
| 20610 | | 20843 | |
| ... | @@ -20613,7 +20846,7 @@ static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstr | ... | @@ -20613,7 +20846,7 @@ static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstr |
| 20613 | return ira->codegen->builtin_types.entry_invalid; | 20846 | return ira->codegen->builtin_types.entry_invalid; |
| 20614 | | 20847 | |
| 20615 | // TODO let this be volatile | 20848 | // TODO let this be volatile |
| 20616 | TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); | 20849 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 20617 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); | 20850 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 20618 | if (type_is_invalid(casted_ptr->value.type)) | 20851 | if (type_is_invalid(casted_ptr->value.type)) |
| 20619 | return ira->codegen->builtin_types.entry_invalid; | 20852 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20661,8 +20894,8 @@ static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstr | ... | @@ -20661,8 +20894,8 @@ static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstr |
| 20661 | return result->value.type; | 20894 | return result->value.type; |
| 20662 | } | 20895 | } |
| 20663 | | 20896 | |
| 20664 | static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) { | 20897 | static ZigType *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) { |
| 20665 | TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other); | 20898 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other); |
| 20666 | if (type_is_invalid(operand_type)) | 20899 | if (type_is_invalid(operand_type)) |
| 20667 | return ira->codegen->builtin_types.entry_invalid; | 20900 | return ira->codegen->builtin_types.entry_invalid; |
| 20668 | | 20901 | |
| ... | @@ -20670,7 +20903,7 @@ static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInst | ... | @@ -20670,7 +20903,7 @@ static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInst |
| 20670 | if (type_is_invalid(ptr_inst->value.type)) | 20903 | if (type_is_invalid(ptr_inst->value.type)) |
| 20671 | return ira->codegen->builtin_types.entry_invalid; | 20904 | return ira->codegen->builtin_types.entry_invalid; |
| 20672 | | 20905 | |
| 20673 | TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true); | 20906 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true); |
| 20674 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); | 20907 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 20675 | if (type_is_invalid(casted_ptr->value.type)) | 20908 | if (type_is_invalid(casted_ptr->value.type)) |
| 20676 | return ira->codegen->builtin_types.entry_invalid; | 20909 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20704,12 +20937,12 @@ static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInst | ... | @@ -20704,12 +20937,12 @@ static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInst |
| 20704 | return result->value.type; | 20937 | return result->value.type; |
| 20705 | } | 20938 | } |
| 20706 | | 20939 | |
| 20707 | static TypeTableEntry *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) { | 20940 | static ZigType *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) { |
| 20708 | TypeTableEntry *promise_type = ir_resolve_type(ira, instruction->promise_type->other); | 20941 | ZigType *promise_type = ir_resolve_type(ira, instruction->promise_type->other); |
| 20709 | if (type_is_invalid(promise_type)) | 20942 | if (type_is_invalid(promise_type)) |
| 20710 | return ira->codegen->builtin_types.entry_invalid; | 20943 | return ira->codegen->builtin_types.entry_invalid; |
| 20711 | | 20944 | |
| 20712 | if (promise_type->id != TypeTableEntryIdPromise || promise_type->data.promise.result_type == nullptr) { | 20945 | if (promise_type->id != ZigTypeIdPromise || promise_type->data.promise.result_type == nullptr) { |
| 20713 | ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'", | 20946 | ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'", |
| 20714 | buf_ptr(&promise_type->name))); | 20947 | buf_ptr(&promise_type->name))); |
| 20715 | return ira->codegen->builtin_types.entry_invalid; | 20948 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20720,12 +20953,12 @@ static TypeTableEntry *ir_analyze_instruction_promise_result_type(IrAnalyze *ira | ... | @@ -20720,12 +20953,12 @@ static TypeTableEntry *ir_analyze_instruction_promise_result_type(IrAnalyze *ira |
| 20720 | return ira->codegen->builtin_types.entry_type; | 20953 | return ira->codegen->builtin_types.entry_type; |
| 20721 | } | 20954 | } |
| 20722 | | 20955 | |
| 20723 | static TypeTableEntry *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) { | 20956 | static ZigType *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) { |
| 20724 | TypeTableEntry *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->other); | 20957 | ZigType *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->other); |
| 20725 | if (type_is_invalid(promise_result_type)) | 20958 | if (type_is_invalid(promise_result_type)) |
| 20726 | return ira->codegen->builtin_types.entry_invalid; | 20959 | return ira->codegen->builtin_types.entry_invalid; |
| 20727 | | 20960 | |
| 20728 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); | 20961 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 20729 | assert(fn_entry != nullptr); | 20962 | assert(fn_entry != nullptr); |
| 20730 | | 20963 | |
| 20731 | if (type_can_fail(promise_result_type)) { | 20964 | if (type_can_fail(promise_result_type)) { |
| ... | @@ -20737,17 +20970,17 @@ static TypeTableEntry *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, | ... | @@ -20737,17 +20970,17 @@ static TypeTableEntry *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, |
| 20737 | return out_val->type; | 20970 | return out_val->type; |
| 20738 | } | 20971 | } |
| 20739 | | 20972 | |
| 20740 | static TypeTableEntry *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira, | 20973 | static ZigType *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira, |
| 20741 | IrInstructionMergeErrRetTraces *instruction) | 20974 | IrInstructionMergeErrRetTraces *instruction) |
| 20742 | { | 20975 | { |
| 20743 | IrInstruction *coro_promise_ptr = instruction->coro_promise_ptr->other; | 20976 | IrInstruction *coro_promise_ptr = instruction->coro_promise_ptr->other; |
| 20744 | if (type_is_invalid(coro_promise_ptr->value.type)) | 20977 | if (type_is_invalid(coro_promise_ptr->value.type)) |
| 20745 | return ira->codegen->builtin_types.entry_invalid; | 20978 | return ira->codegen->builtin_types.entry_invalid; |
| 20746 | | 20979 | |
| 20747 | assert(coro_promise_ptr->value.type->id == TypeTableEntryIdPointer); | 20980 | assert(coro_promise_ptr->value.type->id == ZigTypeIdPointer); |
| 20748 | TypeTableEntry *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type; | 20981 | ZigType *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type; |
| 20749 | assert(promise_frame_type->id == TypeTableEntryIdStruct); | 20982 | assert(promise_frame_type->id == ZigTypeIdStruct); |
| 20750 | TypeTableEntry *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry; | 20983 | ZigType *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry; |
| 20751 | | 20984 | |
| 20752 | if (!type_can_fail(promise_result_type)) { | 20985 | if (!type_can_fail(promise_result_type)) { |
| 20753 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 20986 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| ... | @@ -20770,7 +21003,7 @@ static TypeTableEntry *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ir | ... | @@ -20770,7 +21003,7 @@ static TypeTableEntry *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ir |
| 20770 | return result->value.type; | 21003 | return result->value.type; |
| 20771 | } | 21004 | } |
| 20772 | | 21005 | |
| 20773 | static TypeTableEntry *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) { | 21006 | static ZigType *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) { |
| 20774 | IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope, | 21007 | IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope, |
| 20775 | instruction->base.source_node); | 21008 | instruction->base.source_node); |
| 20776 | ir_link_new_instruction(result, &instruction->base); | 21009 | ir_link_new_instruction(result, &instruction->base); |
| ... | @@ -20778,7 +21011,7 @@ static TypeTableEntry *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, | ... | @@ -20778,7 +21011,7 @@ static TypeTableEntry *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, |
| 20778 | return result->value.type; | 21011 | return result->value.type; |
| 20779 | } | 21012 | } |
| 20780 | | 21013 | |
| 20781 | static TypeTableEntry *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *ira, IrInstructionMarkErrRetTracePtr *instruction) { | 21014 | static ZigType *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *ira, IrInstructionMarkErrRetTracePtr *instruction) { |
| 20782 | IrInstruction *err_ret_trace_ptr = instruction->err_ret_trace_ptr->other; | 21015 | IrInstruction *err_ret_trace_ptr = instruction->err_ret_trace_ptr->other; |
| 20783 | if (type_is_invalid(err_ret_trace_ptr->value.type)) | 21016 | if (type_is_invalid(err_ret_trace_ptr->value.type)) |
| 20784 | return ira->codegen->builtin_types.entry_invalid; | 21017 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20790,8 +21023,8 @@ static TypeTableEntry *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze * | ... | @@ -20790,8 +21023,8 @@ static TypeTableEntry *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze * |
| 20790 | return result->value.type; | 21023 | return result->value.type; |
| 20791 | } | 21024 | } |
| 20792 | | 21025 | |
| 20793 | static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) { | 21026 | static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) { |
| 20794 | TypeTableEntry *float_type = ir_resolve_type(ira, instruction->type->other); | 21027 | ZigType *float_type = ir_resolve_type(ira, instruction->type->other); |
| 20795 | if (type_is_invalid(float_type)) | 21028 | if (type_is_invalid(float_type)) |
| 20796 | return ira->codegen->builtin_types.entry_invalid; | 21029 | return ira->codegen->builtin_types.entry_invalid; |
| 20797 | | 21030 | |
| ... | @@ -20799,7 +21032,7 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction | ... | @@ -20799,7 +21032,7 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction |
| 20799 | if (type_is_invalid(op->value.type)) | 21032 | if (type_is_invalid(op->value.type)) |
| 20800 | return ira->codegen->builtin_types.entry_invalid; | 21033 | return ira->codegen->builtin_types.entry_invalid; |
| 20801 | | 21034 | |
| 20802 | bool ok_type = float_type->id == TypeTableEntryIdComptimeFloat || float_type->id == TypeTableEntryIdFloat; | 21035 | bool ok_type = float_type->id == ZigTypeIdComptimeFloat || float_type->id == ZigTypeIdFloat; |
| 20803 | if (!ok_type) { | 21036 | if (!ok_type) { |
| 20804 | ir_add_error(ira, instruction->type, buf_sprintf("@sqrt does not support type '%s'", buf_ptr(&float_type->name))); | 21037 | ir_add_error(ira, instruction->type, buf_sprintf("@sqrt does not support type '%s'", buf_ptr(&float_type->name))); |
| 20805 | return ira->codegen->builtin_types.entry_invalid; | 21038 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20816,9 +21049,9 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction | ... | @@ -20816,9 +21049,9 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction |
| 20816 | | 21049 | |
| 20817 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 21050 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 20818 | | 21051 | |
| 20819 | if (float_type->id == TypeTableEntryIdComptimeFloat) { | 21052 | if (float_type->id == ZigTypeIdComptimeFloat) { |
| 20820 | bigfloat_sqrt(&out_val->data.x_bigfloat, &val->data.x_bigfloat); | 21053 | bigfloat_sqrt(&out_val->data.x_bigfloat, &val->data.x_bigfloat); |
| 20821 | } else if (float_type->id == TypeTableEntryIdFloat) { | 21054 | } else if (float_type->id == ZigTypeIdFloat) { |
| 20822 | switch (float_type->data.floating.bit_count) { | 21055 | switch (float_type->data.floating.bit_count) { |
| 20823 | case 16: | 21056 | case 16: |
| 20824 | out_val->data.x_f16 = f16_sqrt(val->data.x_f16); | 21057 | out_val->data.x_f16 = f16_sqrt(val->data.x_f16); |
| ... | @@ -20842,7 +21075,7 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction | ... | @@ -20842,7 +21075,7 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction |
| 20842 | return float_type; | 21075 | return float_type; |
| 20843 | } | 21076 | } |
| 20844 | | 21077 | |
| 20845 | assert(float_type->id == TypeTableEntryIdFloat); | 21078 | assert(float_type->id == ZigTypeIdFloat); |
| 20846 | if (float_type->data.floating.bit_count != 16 && | 21079 | if (float_type->data.floating.bit_count != 16 && |
| 20847 | float_type->data.floating.bit_count != 32 && | 21080 | float_type->data.floating.bit_count != 32 && |
| 20848 | float_type->data.floating.bit_count != 64) { | 21081 | float_type->data.floating.bit_count != 64) { |
| ... | @@ -20857,13 +21090,13 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction | ... | @@ -20857,13 +21090,13 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction |
| 20857 | return result->value.type; | 21090 | return result->value.type; |
| 20858 | } | 21091 | } |
| 20859 | | 21092 | |
| 20860 | static TypeTableEntry *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) { | 21093 | static ZigType *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) { |
| 20861 | Error err; | 21094 | Error err; |
| 20862 | IrInstruction *target = instruction->target->other; | 21095 | IrInstruction *target = instruction->target->other; |
| 20863 | if (type_is_invalid(target->value.type)) | 21096 | if (type_is_invalid(target->value.type)) |
| 20864 | return ira->codegen->builtin_types.entry_invalid; | 21097 | return ira->codegen->builtin_types.entry_invalid; |
| 20865 | | 21098 | |
| 20866 | if (target->value.type->id != TypeTableEntryIdEnum) { | 21099 | if (target->value.type->id != ZigTypeIdEnum) { |
| 20867 | ir_add_error(ira, instruction->target, | 21100 | ir_add_error(ira, instruction->target, |
| 20868 | buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name))); | 21101 | buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name))); |
| 20869 | return ira->codegen->builtin_types.entry_invalid; | 21102 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20872,21 +21105,21 @@ static TypeTableEntry *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInst | ... | @@ -20872,21 +21105,21 @@ static TypeTableEntry *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInst |
| 20872 | if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type))) | 21105 | if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type))) |
| 20873 | return ira->codegen->builtin_types.entry_invalid; | 21106 | return ira->codegen->builtin_types.entry_invalid; |
| 20874 | | 21107 | |
| 20875 | TypeTableEntry *tag_type = target->value.type->data.enumeration.tag_int_type; | 21108 | ZigType *tag_type = target->value.type->data.enumeration.tag_int_type; |
| 20876 | | 21109 | |
| 20877 | IrInstruction *result = ir_analyze_enum_to_int(ira, &instruction->base, target, tag_type); | 21110 | IrInstruction *result = ir_analyze_enum_to_int(ira, &instruction->base, target, tag_type); |
| 20878 | ir_link_new_instruction(result, &instruction->base); | 21111 | ir_link_new_instruction(result, &instruction->base); |
| 20879 | return result->value.type; | 21112 | return result->value.type; |
| 20880 | } | 21113 | } |
| 20881 | | 21114 | |
| 20882 | static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) { | 21115 | static ZigType *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) { |
| 20883 | Error err; | 21116 | Error err; |
| 20884 | IrInstruction *dest_type_value = instruction->dest_type->other; | 21117 | IrInstruction *dest_type_value = instruction->dest_type->other; |
| 20885 | TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value); | 21118 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 20886 | if (type_is_invalid(dest_type)) | 21119 | if (type_is_invalid(dest_type)) |
| 20887 | return ira->codegen->builtin_types.entry_invalid; | 21120 | return ira->codegen->builtin_types.entry_invalid; |
| 20888 | | 21121 | |
| 20889 | if (dest_type->id != TypeTableEntryIdEnum) { | 21122 | if (dest_type->id != ZigTypeIdEnum) { |
| 20890 | ir_add_error(ira, instruction->dest_type, | 21123 | ir_add_error(ira, instruction->dest_type, |
| 20891 | buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name))); | 21124 | buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name))); |
| 20892 | return ira->codegen->builtin_types.entry_invalid; | 21125 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -20895,7 +21128,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInst | ... | @@ -20895,7 +21128,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInst |
| 20895 | if ((err = type_ensure_zero_bits_known(ira->codegen, dest_type))) | 21128 | if ((err = type_ensure_zero_bits_known(ira->codegen, dest_type))) |
| 20896 | return ira->codegen->builtin_types.entry_invalid; | 21129 | return ira->codegen->builtin_types.entry_invalid; |
| 20897 | | 21130 | |
| 20898 | TypeTableEntry *tag_type = dest_type->data.enumeration.tag_int_type; | 21131 | ZigType *tag_type = dest_type->data.enumeration.tag_int_type; |
| 20899 | | 21132 | |
| 20900 | IrInstruction *target = instruction->target->other; | 21133 | IrInstruction *target = instruction->target->other; |
| 20901 | if (type_is_invalid(target->value.type)) | 21134 | if (type_is_invalid(target->value.type)) |
| ... | @@ -20910,7 +21143,30 @@ static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInst | ... | @@ -20910,7 +21143,30 @@ static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInst |
| 20910 | return result->value.type; | 21143 | return result->value.type; |
| 20911 | } | 21144 | } |
| 20912 | | 21145 | |
| 20913 | static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) { | 21146 | static ZigType *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstructionCheckRuntimeScope *instruction) { |
| | 21147 | IrInstruction *block_comptime_inst = instruction->scope_is_comptime->other; |
| | 21148 | bool scope_is_comptime; |
| | 21149 | if (!ir_resolve_bool(ira, block_comptime_inst, &scope_is_comptime)) |
| | 21150 | return ira->codegen->builtin_types.entry_invalid; |
| | 21151 | |
| | 21152 | IrInstruction *is_comptime_inst = instruction->is_comptime->other; |
| | 21153 | bool is_comptime; |
| | 21154 | if (!ir_resolve_bool(ira, is_comptime_inst, &is_comptime)) |
| | 21155 | return ira->codegen->builtin_types.entry_invalid; |
| | 21156 | |
| | 21157 | if (!scope_is_comptime && is_comptime) { |
| | 21158 | ErrorMsg *msg = ir_add_error(ira, &instruction->base, |
| | 21159 | buf_sprintf("comptime control flow inside runtime block")); |
| | 21160 | add_error_note(ira->codegen, msg, block_comptime_inst->source_node, |
| | 21161 | buf_sprintf("runtime block created here")); |
| | 21162 | return ira->codegen->builtin_types.entry_invalid; |
| | 21163 | } |
| | 21164 | |
| | 21165 | ir_build_const_from(ira, &instruction->base); |
| | 21166 | return ira->codegen->builtin_types.entry_void; |
| | 21167 | } |
| | 21168 | |
| | 21169 | static ZigType *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) { |
| 20914 | switch (instruction->id) { | 21170 | switch (instruction->id) { |
| 20915 | case IrInstructionIdInvalid: | 21171 | case IrInstructionIdInvalid: |
| 20916 | case IrInstructionIdWidenOrShorten: | 21172 | case IrInstructionIdWidenOrShorten: |
| ... | @@ -21186,19 +21442,21 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi | ... | @@ -21186,19 +21442,21 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi |
| 21186 | return ir_analyze_instruction_int_to_enum(ira, (IrInstructionIntToEnum *)instruction); | 21442 | return ir_analyze_instruction_int_to_enum(ira, (IrInstructionIntToEnum *)instruction); |
| 21187 | case IrInstructionIdEnumToInt: | 21443 | case IrInstructionIdEnumToInt: |
| 21188 | return ir_analyze_instruction_enum_to_int(ira, (IrInstructionEnumToInt *)instruction); | 21444 | return ir_analyze_instruction_enum_to_int(ira, (IrInstructionEnumToInt *)instruction); |
| | 21445 | case IrInstructionIdCheckRuntimeScope: |
| | 21446 | return ir_analyze_instruction_check_runtime_scope(ira, (IrInstructionCheckRuntimeScope *)instruction); |
| 21189 | } | 21447 | } |
| 21190 | zig_unreachable(); | 21448 | zig_unreachable(); |
| 21191 | } | 21449 | } |
| 21192 | | 21450 | |
| 21193 | static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction) { | 21451 | static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction) { |
| 21194 | TypeTableEntry *instruction_type = ir_analyze_instruction_nocast(ira, instruction); | 21452 | ZigType *instruction_type = ir_analyze_instruction_nocast(ira, instruction); |
| 21195 | instruction->value.type = instruction_type; | 21453 | instruction->value.type = instruction_type; |
| 21196 | | 21454 | |
| 21197 | if (instruction->other) { | 21455 | if (instruction->other) { |
| 21198 | instruction->other->value.type = instruction_type; | 21456 | instruction->other->value.type = instruction_type; |
| 21199 | } else { | 21457 | } else { |
| 21200 | assert(instruction_type->id == TypeTableEntryIdInvalid || | 21458 | assert(instruction_type->id == ZigTypeIdInvalid || |
| 21201 | instruction_type->id == TypeTableEntryIdUnreachable); | 21459 | instruction_type->id == ZigTypeIdUnreachable); |
| 21202 | instruction->other = instruction; | 21460 | instruction->other = instruction; |
| 21203 | } | 21461 | } |
| 21204 | | 21462 | |
| ... | @@ -21207,8 +21465,8 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins | ... | @@ -21207,8 +21465,8 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins |
| 21207 | | 21465 | |
| 21208 | // This function attempts to evaluate IR code while doing type checking and other analysis. | 21466 | // This function attempts to evaluate IR code while doing type checking and other analysis. |
| 21209 | // It emits a new IrExecutable which is partially evaluated IR code. | 21467 | // It emits a new IrExecutable which is partially evaluated IR code. |
| 21210 | TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec, | 21468 | ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec, |
| 21211 | TypeTableEntry *expected_type, AstNode *expected_type_source_node) | 21469 | ZigType *expected_type, AstNode *expected_type_source_node) |
| 21212 | { | 21470 | { |
| 21213 | assert(!old_exec->invalid); | 21471 | assert(!old_exec->invalid); |
| 21214 | assert(expected_type == nullptr || !type_is_invalid(expected_type)); | 21472 | assert(expected_type == nullptr || !type_is_invalid(expected_type)); |
| ... | @@ -21217,7 +21475,7 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl | ... | @@ -21217,7 +21475,7 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl |
| 21217 | old_exec->analysis = ira; | 21475 | old_exec->analysis = ira; |
| 21218 | ira->codegen = codegen; | 21476 | ira->codegen = codegen; |
| 21219 | | 21477 | |
| 21220 | FnTableEntry *fn_entry = exec_fn_entry(old_exec); | 21478 | ZigFn *fn_entry = exec_fn_entry(old_exec); |
| 21221 | bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync; | 21479 | bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync; |
| 21222 | ira->explicit_return_type = is_async ? get_promise_type(codegen, expected_type) : expected_type; | 21480 | ira->explicit_return_type = is_async ? get_promise_type(codegen, expected_type) : expected_type; |
| 21223 | | 21481 | |
| ... | @@ -21249,13 +21507,13 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl | ... | @@ -21249,13 +21507,13 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl |
| 21249 | continue; | 21507 | continue; |
| 21250 | } | 21508 | } |
| 21251 | | 21509 | |
| 21252 | TypeTableEntry *return_type = ir_analyze_instruction(ira, old_instruction); | 21510 | ZigType *return_type = ir_analyze_instruction(ira, old_instruction); |
| 21253 | if (type_is_invalid(return_type) && ir_should_inline(new_exec, old_instruction->scope)) { | 21511 | if (type_is_invalid(return_type) && ir_should_inline(new_exec, old_instruction->scope)) { |
| 21254 | return ira->codegen->builtin_types.entry_invalid; | 21512 | return ira->codegen->builtin_types.entry_invalid; |
| 21255 | } | 21513 | } |
| 21256 | | 21514 | |
| 21257 | // unreachable instructions do their own control flow. | 21515 | // unreachable instructions do their own control flow. |
| 21258 | if (return_type->id == TypeTableEntryIdUnreachable) | 21516 | if (return_type->id == ZigTypeIdUnreachable) |
| 21259 | continue; | 21517 | continue; |
| 21260 | | 21518 | |
| 21261 | ira->instruction_index += 1; | 21519 | ira->instruction_index += 1; |
| ... | @@ -21301,6 +21559,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -21301,6 +21559,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 21301 | case IrInstructionIdOverflowOp: // TODO when we support multiple returns this can be side effect free | 21559 | case IrInstructionIdOverflowOp: // TODO when we support multiple returns this can be side effect free |
| 21302 | case IrInstructionIdCheckSwitchProngs: | 21560 | case IrInstructionIdCheckSwitchProngs: |
| 21303 | case IrInstructionIdCheckStatementIsVoid: | 21561 | case IrInstructionIdCheckStatementIsVoid: |
| | 21562 | case IrInstructionIdCheckRuntimeScope: |
| 21304 | case IrInstructionIdPanic: | 21563 | case IrInstructionIdPanic: |
| 21305 | case IrInstructionIdSetEvalBranchQuota: | 21564 | case IrInstructionIdSetEvalBranchQuota: |
| 21306 | case IrInstructionIdPtrType: | 21565 | case IrInstructionIdPtrType: |