| ... | ... | @@ -33,7 +33,7 @@ struct IrAnalyze { |
| 33 | 33 | IrExecContext exec_context; |
| 34 | 34 | size_t old_bb_index; |
| 35 | 35 | size_t instruction_index; |
| 36 | | TypeTableEntry *explicit_return_type; |
| 36 | ZigType *explicit_return_type; |
| 37 | 37 | ZigList<IrInstruction *> src_implicit_return_type_list; |
| 38 | 38 | IrBasicBlock *const_predecessor_bb; |
| 39 | 39 | }; |
| ... | ... | @@ -99,38 +99,38 @@ struct ConstCastOnly { |
| 99 | 99 | }; |
| 100 | 100 | |
| 101 | 101 | struct ConstCastTypeMismatch { |
| 102 | | TypeTableEntry *wanted_type; |
| 103 | | TypeTableEntry *actual_type; |
| 102 | ZigType *wanted_type; |
| 103 | ZigType *actual_type; |
| 104 | 104 | }; |
| 105 | 105 | |
| 106 | 106 | struct ConstCastOptionalMismatch { |
| 107 | 107 | ConstCastOnly child; |
| 108 | | TypeTableEntry *wanted_child; |
| 109 | | TypeTableEntry *actual_child; |
| 108 | ZigType *wanted_child; |
| 109 | ZigType *actual_child; |
| 110 | 110 | }; |
| 111 | 111 | |
| 112 | 112 | struct ConstCastPointerMismatch { |
| 113 | 113 | ConstCastOnly child; |
| 114 | | TypeTableEntry *wanted_child; |
| 115 | | TypeTableEntry *actual_child; |
| 114 | ZigType *wanted_child; |
| 115 | ZigType *actual_child; |
| 116 | 116 | }; |
| 117 | 117 | |
| 118 | 118 | struct ConstCastSliceMismatch { |
| 119 | 119 | ConstCastOnly child; |
| 120 | | TypeTableEntry *wanted_child; |
| 121 | | TypeTableEntry *actual_child; |
| 120 | ZigType *wanted_child; |
| 121 | ZigType *actual_child; |
| 122 | 122 | }; |
| 123 | 123 | |
| 124 | 124 | struct ConstCastErrUnionErrSetMismatch { |
| 125 | 125 | ConstCastOnly child; |
| 126 | | TypeTableEntry *wanted_err_set; |
| 127 | | TypeTableEntry *actual_err_set; |
| 126 | ZigType *wanted_err_set; |
| 127 | ZigType *actual_err_set; |
| 128 | 128 | }; |
| 129 | 129 | |
| 130 | 130 | struct ConstCastErrUnionPayloadMismatch { |
| 131 | 131 | ConstCastOnly child; |
| 132 | | TypeTableEntry *wanted_payload; |
| 133 | | TypeTableEntry *actual_payload; |
| 132 | ZigType *wanted_payload; |
| 133 | ZigType *actual_payload; |
| 134 | 134 | }; |
| 135 | 135 | |
| 136 | 136 | struct ConstCastErrSetMismatch { |
| ... | ... | @@ -139,19 +139,21 @@ struct ConstCastErrSetMismatch { |
| 139 | 139 | |
| 140 | 140 | static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope); |
| 141 | 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); |
| 143 | | static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type); |
| 142 | static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction); |
| 143 | static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type); |
| 144 | 144 | static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr); |
| 145 | 145 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg); |
| 146 | 146 | static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 147 | | IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type); |
| 148 | | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var); |
| 149 | | static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op); |
| 147 | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type); |
| 148 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var); |
| 149 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op); |
| 150 | 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); |
| 152 | | static TypeTableEntry *adjust_slice_align(CodeGen *g, TypeTableEntry *slice_type, uint32_t new_align); |
| 151 | static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_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 | 157 | assert(get_codegen_ptr_type(const_val->type) != nullptr); |
| 156 | 158 | assert(const_val->special == ConstValSpecialStatic); |
| 157 | 159 | ConstExprValue *result; |
| ... | ... | @@ -181,6 +183,27 @@ ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) { |
| 181 | 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 | 207 | static bool ir_should_inline(IrExecutable *exec, Scope *scope) { |
| 185 | 208 | if (exec->is_inline) |
| 186 | 209 | return true; |
| ... | ... | @@ -213,7 +236,7 @@ static size_t exec_next_mem_slot(IrExecutable *exec) { |
| 213 | 236 | return result; |
| 214 | 237 | } |
| 215 | 238 | |
| 216 | | static FnTableEntry *exec_fn_entry(IrExecutable *exec) { |
| 239 | static ZigFn *exec_fn_entry(IrExecutable *exec) { |
| 217 | 240 | return exec->fn_entry; |
| 218 | 241 | } |
| 219 | 242 | |
| ... | ... | @@ -230,7 +253,7 @@ static bool instr_is_comptime(IrInstruction *instruction) { |
| 230 | 253 | } |
| 231 | 254 | |
| 232 | 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 | 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 | 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 | 281 | var->ref_count += 1; |
| 259 | 282 | } |
| 260 | 283 | |
| ... | ... | @@ -832,6 +855,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionSqrt *) { |
| 832 | 855 | return IrInstructionIdSqrt; |
| 833 | 856 | } |
| 834 | 857 | |
| 858 | static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckRuntimeScope *) { |
| 859 | return IrInstructionIdCheckRuntimeScope; |
| 860 | } |
| 861 | |
| 835 | 862 | template<typename T> |
| 836 | 863 | static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 837 | 864 | T *special_instruction = allocate<T>(1); |
| ... | ... | @@ -851,7 +878,7 @@ static T *ir_build_instruction(IrBuilder *irb, Scope *scope, AstNode *source_nod |
| 851 | 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 | 882 | IrInstruction *value, CastOp cast_op) |
| 856 | 883 | { |
| 857 | 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 | 931 | } |
| 905 | 932 | |
| 906 | 933 | static IrInstruction *ir_create_const(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 907 | | TypeTableEntry *type_entry) |
| 934 | ZigType *type_entry) |
| 908 | 935 | { |
| 909 | 936 | assert(type_entry); |
| 910 | 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 | 1002 | } |
| 976 | 1003 | |
| 977 | 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 | 1007 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); |
| 981 | 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 | 1012 | } |
| 986 | 1013 | |
| 987 | 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 | 1017 | IrInstruction *instruction = ir_create_const_type(irb, scope, source_node, type_entry); |
| 991 | 1018 | ir_instruction_append(irb->current_basic_block, instruction); |
| 992 | 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 | 1023 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); |
| 997 | 1024 | const_instruction->base.value.type = fn_entry->type_entry; |
| 998 | 1025 | const_instruction->base.value.special = ConstValSpecialStatic; |
| ... | ... | @@ -1002,7 +1029,7 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode * |
| 1002 | 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 | 1033 | IrInstruction *instruction = ir_create_const_fn(irb, scope, source_node, fn_entry); |
| 1007 | 1034 | ir_instruction_append(irb->current_basic_block, instruction); |
| 1008 | 1035 | return instruction; |
| ... | ... | @@ -1035,7 +1062,7 @@ static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode |
| 1035 | 1062 | } |
| 1036 | 1063 | |
| 1037 | 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 | 1067 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1041 | 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 | 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 | 1120 | IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node); |
| 1092 | 1121 | instruction->var = var; |
| 1122 | instruction->crossed_fndef_scope = crossed_fndef_scope; |
| 1093 | 1123 | |
| 1094 | 1124 | ir_ref_var(var); |
| 1095 | 1125 | |
| 1096 | 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 | 1133 | static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *array_ptr, |
| 1100 | 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 | 1206 | } |
| 1173 | 1207 | |
| 1174 | 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 | 1210 | bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator, |
| 1177 | 1211 | IrInstruction *new_stack) |
| 1178 | 1212 | { |
| ... | ... | @@ -1200,7 +1234,7 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc |
| 1200 | 1234 | } |
| 1201 | 1235 | |
| 1202 | 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 | 1238 | bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator, |
| 1205 | 1239 | IrInstruction *new_stack) |
| 1206 | 1240 | { |
| ... | ... | @@ -1349,7 +1383,7 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop |
| 1349 | 1383 | } |
| 1350 | 1384 | |
| 1351 | 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 | 1388 | IrInstructionStructInit *struct_init_instruction = ir_build_instruction<IrInstructionStructInit>(irb, scope, source_node); |
| 1355 | 1389 | struct_init_instruction->struct_type = struct_type; |
| ... | ... | @@ -1363,7 +1397,7 @@ static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode |
| 1363 | 1397 | } |
| 1364 | 1398 | |
| 1365 | 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 | 1402 | IrInstruction *new_instruction = ir_build_struct_init(irb, old_instruction->scope, |
| 1369 | 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 | 1406 | } |
| 1373 | 1407 | |
| 1374 | 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 | 1411 | IrInstructionUnionInit *union_init_instruction = ir_build_instruction<IrInstructionUnionInit>(irb, scope, source_node); |
| 1378 | 1412 | union_init_instruction->union_type = union_type; |
| ... | ... | @@ -1385,7 +1419,7 @@ static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode |
| 1385 | 1419 | } |
| 1386 | 1420 | |
| 1387 | 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 | 1424 | IrInstruction *new_instruction = ir_build_union_init(irb, old_instruction->scope, |
| 1391 | 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 | 1466 | } |
| 1433 | 1467 | |
| 1434 | 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 | 1471 | IrInstructionDeclVar *decl_var_instruction = ir_build_instruction<IrInstructionDeclVar>(irb, scope, source_node); |
| 1438 | 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 | 1484 | } |
| 1451 | 1485 | |
| 1452 | 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 | 1489 | IrInstruction *new_instruction = ir_build_var_decl(irb, old_instruction->scope, |
| 1456 | 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 | 1629 | } |
| 1596 | 1630 | |
| 1597 | 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 | 1634 | IrInstructionAsm *instruction = ir_build_instruction<IrInstructionAsm>(irb, scope, source_node); |
| 1601 | 1635 | instruction->input_list = input_list; |
| ... | ... | @@ -1619,7 +1653,7 @@ static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source |
| 1619 | 1653 | } |
| 1620 | 1654 | |
| 1621 | 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 | 1658 | IrInstruction *new_instruction = ir_build_asm(irb, old_instruction->scope, |
| 1625 | 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 | 1980 | IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value, |
| 1947 | 1981 | IrInstruction *success_order_value, IrInstruction *failure_order_value, |
| 1948 | 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 | 1985 | IrInstructionCmpxchg *instruction = ir_build_instruction<IrInstructionCmpxchg>(irb, scope, source_node); |
| 1952 | 1986 | instruction->type_value = type_value; |
| ... | ... | @@ -2259,7 +2293,7 @@ static IrInstruction *ir_build_handle_from(IrBuilder *irb, IrInstruction *old_in |
| 2259 | 2293 | |
| 2260 | 2294 | static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2261 | 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 | 2298 | IrInstructionOverflowOp *instruction = ir_build_instruction<IrInstructionOverflowOp>(irb, scope, source_node); |
| 2265 | 2299 | instruction->op = op; |
| ... | ... | @@ -2279,7 +2313,7 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode |
| 2279 | 2313 | |
| 2280 | 2314 | static IrInstruction *ir_build_overflow_op_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 2281 | 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 | 2318 | IrInstruction *new_instruction = ir_build_overflow_op(irb, old_instruction->scope, old_instruction->source_node, |
| 2285 | 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 | 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 | 3022 | static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) { |
| 2978 | 3023 | results[ReturnKindUnconditional] = 0; |
| 2979 | 3024 | results[ReturnKindError] = 0; |
| ... | ... | @@ -2999,6 +3044,7 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco |
| 2999 | 3044 | case ScopeIdLoop: |
| 3000 | 3045 | case ScopeIdSuspend: |
| 3001 | 3046 | case ScopeIdCompTime: |
| 3047 | case ScopeIdRuntime: |
| 3002 | 3048 | scope = scope->parent; |
| 3003 | 3049 | continue; |
| 3004 | 3050 | case ScopeIdDeferExpr: |
| ... | ... | @@ -3033,7 +3079,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o |
| 3033 | 3079 | Scope *defer_expr_scope = defer_node->data.defer.expr_scope; |
| 3034 | 3080 | IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope); |
| 3035 | 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 | 3083 | is_noreturn = true; |
| 3038 | 3084 | } else { |
| 3039 | 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 | 3097 | case ScopeIdLoop: |
| 3052 | 3098 | case ScopeIdSuspend: |
| 3053 | 3099 | case ScopeIdCompTime: |
| 3100 | case ScopeIdRuntime: |
| 3054 | 3101 | scope = scope->parent; |
| 3055 | 3102 | continue; |
| 3056 | 3103 | case ScopeIdDeferExpr: |
| ... | ... | @@ -3098,7 +3145,7 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) { |
| 3098 | 3145 | } |
| 3099 | 3146 | |
| 3100 | 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 | 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 | 3207 | static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) { |
| 3161 | 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 | 3211 | if (!fn_entry) { |
| 3165 | 3212 | add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition")); |
| 3166 | 3213 | return irb->codegen->invalid_instruction; |
| ... | ... | @@ -3184,7 +3231,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3184 | 3231 | IrInstruction *return_value; |
| 3185 | 3232 | if (expr_node) { |
| 3186 | 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 | 3235 | irb->exec->name_fn = exec_fn_entry(irb->exec); |
| 3189 | 3236 | return_value = ir_gen_node(irb, expr_node, scope); |
| 3190 | 3237 | irb->exec->name_fn = prev_name_fn; |
| ... | ... | @@ -3280,11 +3327,11 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3280 | 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 | 3331 | Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime, |
| 3285 | 3332 | bool skip_name_check) |
| 3286 | 3333 | { |
| 3287 | | VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1); |
| 3334 | ZigVar *variable_entry = allocate<ZigVar>(1); |
| 3288 | 3335 | variable_entry->parent_scope = parent_scope; |
| 3289 | 3336 | variable_entry->shadowable = is_shadowable; |
| 3290 | 3337 | variable_entry->mem_slot_index = SIZE_MAX; |
| ... | ... | @@ -3296,14 +3343,14 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco |
| 3296 | 3343 | buf_init_from_buf(&variable_entry->name, name); |
| 3297 | 3344 | |
| 3298 | 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 | 3347 | if (existing_var && !existing_var->shadowable) { |
| 3301 | 3348 | ErrorMsg *msg = add_node_error(codegen, node, |
| 3302 | 3349 | buf_sprintf("redeclaration of variable '%s'", buf_ptr(name))); |
| 3303 | 3350 | add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration is here")); |
| 3304 | 3351 | variable_entry->value->type = codegen->builtin_types.entry_invalid; |
| 3305 | 3352 | } else { |
| 3306 | | TypeTableEntry *type = get_primitive_type(codegen, name); |
| 3353 | ZigType *type = get_primitive_type(codegen, name); |
| 3307 | 3354 | if (type != nullptr) { |
| 3308 | 3355 | add_node_error(codegen, node, |
| 3309 | 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 | 3384 | |
| 3338 | 3385 | // Set name to nullptr to make the variable anonymous (not visible to programmer). |
| 3339 | 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 | 3388 | bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime) |
| 3342 | 3389 | { |
| 3343 | 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 | 3392 | (is_underscored ? nullptr : name), src_is_const, gen_is_const, |
| 3346 | 3393 | (is_underscored ? true : is_shadowable), is_comptime, false); |
| 3347 | 3394 | if (is_comptime != nullptr || gen_is_const) { |
| ... | ... | @@ -3363,7 +3410,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 3363 | 3410 | Scope *outer_block_scope = &scope_block->base; |
| 3364 | 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 | 3414 | if (fn_entry && fn_entry->child_scope == parent_scope) { |
| 3368 | 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 | 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 | 3800 | if (primitive_type != nullptr) { |
| 3754 | 3801 | IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_type); |
| 3755 | 3802 | if (lval == LValPtr) { |
| ... | ... | @@ -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 | 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 | 3813 | if (lval == LValPtr) |
| 3766 | 3814 | return var_ptr; |
| 3767 | 3815 | else |
| ... | ... | @@ -4980,7 +5028,8 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 4980 | 5028 | |
| 4981 | 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 | 5033 | if (then_expr_result == irb->codegen->invalid_instruction) |
| 4985 | 5034 | return then_expr_result; |
| 4986 | 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 | 5039 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 4991 | 5040 | IrInstruction *else_expr_result; |
| 4992 | 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 | 5043 | if (else_expr_result == irb->codegen->invalid_instruction) |
| 4995 | 5044 | return else_expr_result; |
| 4996 | 5045 | } else { |
| ... | ... | @@ -5217,7 +5266,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 5217 | 5266 | |
| 5218 | 5267 | IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, |
| 5219 | 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 | 5270 | is_const, is_const, is_shadowable, is_comptime); |
| 5222 | 5271 | // we detect IrInstructionIdDeclVar in gen_block to make sure the next node |
| 5223 | 5272 | // is inside var->child_scope |
| ... | ... | @@ -5271,6 +5320,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5271 | 5320 | ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline); |
| 5272 | 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 | 5324 | Buf *var_symbol = node->data.while_expr.var_symbol; |
| 5275 | 5325 | Buf *err_symbol = node->data.while_expr.err_symbol; |
| 5276 | 5326 | if (err_symbol != nullptr) { |
| ... | ... | @@ -5278,16 +5328,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5278 | 5328 | |
| 5279 | 5329 | Scope *payload_scope; |
| 5280 | 5330 | AstNode *symbol_node = node; // TODO make more accurate |
| 5281 | | VariableTableEntry *payload_var; |
| 5331 | ZigVar *payload_var; |
| 5282 | 5332 | if (var_symbol) { |
| 5283 | 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 | 5335 | true, false, false, is_comptime); |
| 5286 | 5336 | payload_scope = payload_var->child_scope; |
| 5287 | 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 | 5341 | if (err_val_ptr == irb->codegen->invalid_instruction) |
| 5292 | 5342 | return err_val_ptr; |
| 5293 | 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 | 5392 | |
| 5343 | 5393 | // TODO make it an error to write to error variable |
| 5344 | 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 | 5396 | true, false, false, is_comptime); |
| 5347 | 5397 | Scope *err_scope = err_var->child_scope; |
| 5348 | 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 | 5417 | return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); |
| 5368 | 5418 | } else if (var_symbol != nullptr) { |
| 5369 | 5419 | ir_set_cursor_at_end_and_append_block(irb, cond_block); |
| 5420 | Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime); |
| 5370 | 5421 | // TODO make it an error to write to payload variable |
| 5371 | 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 | 5425 | true, false, false, is_comptime); |
| 5374 | 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 | 5428 | if (maybe_val_ptr == irb->codegen->invalid_instruction) |
| 5377 | 5429 | return maybe_val_ptr; |
| 5378 | 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 | 5508 | ZigList<IrInstruction *> incoming_values = {0}; |
| 5457 | 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 | 5514 | loop_scope->break_block = end_block; |
| 5461 | 5515 | loop_scope->continue_block = continue_block; |
| 5462 | 5516 | loop_scope->is_comptime = is_comptime; |
| ... | ... | @@ -5474,7 +5528,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5474 | 5528 | |
| 5475 | 5529 | if (continue_expr_node) { |
| 5476 | 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 | 5532 | if (expr_result == irb->codegen->invalid_instruction) |
| 5479 | 5533 | return expr_result; |
| 5480 | 5534 | if (!instr_is_unreachable(expr_result)) |
| ... | ... | @@ -5485,7 +5539,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5485 | 5539 | if (else_node) { |
| 5486 | 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 | 5543 | if (else_result == irb->codegen->invalid_instruction) |
| 5490 | 5544 | return else_result; |
| 5491 | 5545 | if (!instr_is_unreachable(else_result)) |
| ... | ... | @@ -5539,7 +5593,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5539 | 5593 | |
| 5540 | 5594 | // TODO make it an error to write to element variable or i variable. |
| 5541 | 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 | 5597 | Scope *child_scope = elem_var->child_scope; |
| 5544 | 5598 | |
| 5545 | 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 | 5601 | IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var); |
| 5548 | 5602 | |
| 5549 | 5603 | AstNode *index_var_source_node; |
| 5550 | | VariableTableEntry *index_var; |
| 5604 | ZigVar *index_var; |
| 5551 | 5605 | if (index_node) { |
| 5552 | 5606 | index_var_source_node = index_node; |
| 5553 | 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 | 5694 | if (!scope->parent) |
| 5641 | 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 | 5698 | if (fn_entry) |
| 5645 | 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 | 5704 | |
| 5651 | 5705 | if (scope->id == ScopeIdDecls) { |
| 5652 | 5706 | ScopeDecls *decls_scope = (ScopeDecls *)scope; |
| 5653 | | TypeTableEntry *container_type = decls_scope->container_type; |
| 5707 | ZigType *container_type = decls_scope->container_type; |
| 5654 | 5708 | assert(container_type); |
| 5655 | 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 | 5806 | |
| 5753 | 5807 | IrInstruction **input_list = allocate<IrInstruction *>(node->data.asm_expr.input_list.length); |
| 5754 | 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 | 5810 | size_t return_count = 0; |
| 5757 | 5811 | bool is_volatile = node->data.asm_expr.is_volatile; |
| 5758 | 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 | 5830 | output_types[i] = return_type; |
| 5777 | 5831 | } else { |
| 5778 | 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 | 5836 | if (var) { |
| 5781 | 5837 | output_vars[i] = var; |
| 5782 | 5838 | } else { |
| ... | ... | @@ -5828,20 +5884,21 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no |
| 5828 | 5884 | |
| 5829 | 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 | 5888 | Scope *var_scope; |
| 5832 | 5889 | if (var_symbol) { |
| 5833 | 5890 | IrInstruction *var_type = nullptr; |
| 5834 | 5891 | bool is_shadowable = false; |
| 5835 | 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 | 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); |
| 5840 | | IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, scope, node, var_ptr_value); |
| 5841 | | ir_build_var_decl(irb, scope, node, var, var_type, nullptr, var_value); |
| 5896 | IrInstruction *var_ptr_value = ir_build_unwrap_maybe(irb, subexpr_scope, node, maybe_val_ptr, false); |
| 5897 | IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, subexpr_scope, node, var_ptr_value); |
| 5898 | ir_build_var_decl(irb, subexpr_scope, node, var, var_type, nullptr, var_value); |
| 5842 | 5899 | var_scope = var->child_scope; |
| 5843 | 5900 | } else { |
| 5844 | | var_scope = scope; |
| 5901 | var_scope = subexpr_scope; |
| 5845 | 5902 | } |
| 5846 | 5903 | IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var_scope); |
| 5847 | 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 | 5910 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 5854 | 5911 | IrInstruction *else_expr_result; |
| 5855 | 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 | 5914 | if (else_expr_result == irb->codegen->invalid_instruction) |
| 5858 | 5915 | return else_expr_result; |
| 5859 | 5916 | } else { |
| ... | ... | @@ -5902,20 +5959,21 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 5902 | 5959 | |
| 5903 | 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 | 5963 | Scope *var_scope; |
| 5906 | 5964 | if (var_symbol) { |
| 5907 | 5965 | IrInstruction *var_type = nullptr; |
| 5908 | 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); |
| 5910 | | VariableTableEntry *var = ir_create_var(irb, node, scope, |
| 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); |
| 5968 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, |
| 5911 | 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); |
| 5914 | | IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, scope, node, var_ptr_value); |
| 5915 | | ir_build_var_decl(irb, scope, node, var, var_type, nullptr, var_value); |
| 5971 | IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, subexpr_scope, node, err_val_ptr, false); |
| 5972 | IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, subexpr_scope, node, var_ptr_value); |
| 5973 | ir_build_var_decl(irb, subexpr_scope, node, var, var_type, nullptr, var_value); |
| 5916 | 5974 | var_scope = var->child_scope; |
| 5917 | 5975 | } else { |
| 5918 | | var_scope = scope; |
| 5976 | var_scope = subexpr_scope; |
| 5919 | 5977 | } |
| 5920 | 5978 | IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var_scope); |
| 5921 | 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 | 5991 | IrInstruction *var_type = nullptr; |
| 5934 | 5992 | bool is_shadowable = false; |
| 5935 | 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 | 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); |
| 5940 | | ir_build_var_decl(irb, scope, node, var, var_type, nullptr, var_value); |
| 5997 | IrInstruction *var_value = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr); |
| 5998 | ir_build_var_decl(irb, subexpr_scope, node, var, var_type, nullptr, var_value); |
| 5941 | 5999 | err_var_scope = var->child_scope; |
| 5942 | 6000 | } else { |
| 5943 | | err_var_scope = scope; |
| 6001 | err_var_scope = subexpr_scope; |
| 5944 | 6002 | } |
| 5945 | 6003 | else_expr_result = ir_gen_node(irb, else_node, err_var_scope); |
| 5946 | 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 | 6039 | |
| 5982 | 6040 | bool is_shadowable = false; |
| 5983 | 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 | 6043 | var_name, is_const, is_const, is_shadowable, var_is_comptime); |
| 5986 | 6044 | child_scope = var->child_scope; |
| 5987 | 6045 | IrInstruction *var_value; |
| ... | ... | @@ -6037,6 +6095,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 6037 | 6095 | ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0}; |
| 6038 | 6096 | |
| 6039 | 6097 | // First do the else and the ranges |
| 6098 | Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime); |
| 6040 | 6099 | Scope *comptime_scope = create_comptime_scope(node, scope); |
| 6041 | 6100 | AstNode *else_prong = nullptr; |
| 6042 | 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 | 6113 | |
| 6055 | 6114 | IrBasicBlock *prev_block = irb->current_basic_block; |
| 6056 | 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 | 6117 | is_comptime, var_is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values)) |
| 6059 | 6118 | { |
| 6060 | 6119 | return irb->codegen->invalid_instruction; |
| ... | ... | @@ -6121,7 +6180,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 6121 | 6180 | range_block_no, is_comptime)); |
| 6122 | 6181 | |
| 6123 | 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 | 6184 | is_comptime, var_is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values)) |
| 6126 | 6185 | { |
| 6127 | 6186 | return irb->codegen->invalid_instruction; |
| ... | ... | @@ -6165,7 +6224,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 6165 | 6224 | |
| 6166 | 6225 | IrBasicBlock *prev_block = irb->current_basic_block; |
| 6167 | 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 | 6228 | is_comptime, var_is_comptime, target_value_ptr, only_item_value, &incoming_blocks, &incoming_values)) |
| 6170 | 6229 | { |
| 6171 | 6230 | return irb->codegen->invalid_instruction; |
| ... | ... | @@ -6308,6 +6367,8 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast |
| 6308 | 6367 | // * defer expression scope => error, cannot break out of defer expression |
| 6309 | 6368 | // * loop scope => OK |
| 6310 | 6369 | |
| 6370 | ZigList<ScopeRuntime *> runtime_scopes = {}; |
| 6371 | |
| 6311 | 6372 | Scope *search_scope = continue_scope; |
| 6312 | 6373 | ScopeLoop *loop_scope; |
| 6313 | 6374 | for (;;) { |
| ... | ... | @@ -6330,6 +6391,9 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast |
| 6330 | 6391 | loop_scope = this_loop_scope; |
| 6331 | 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 | 6398 | search_scope = search_scope->parent; |
| 6335 | 6399 | } |
| ... | ... | @@ -6341,6 +6405,11 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast |
| 6341 | 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 | 6413 | IrBasicBlock *dest_block = loop_scope->continue_block; |
| 6345 | 6414 | ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, false); |
| 6346 | 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 | 6504 | Buf *var_name = var_node->data.symbol_expr.symbol; |
| 6436 | 6505 | bool is_const = true; |
| 6437 | 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 | 6508 | is_const, is_const, is_shadowable, is_comptime); |
| 6440 | 6509 | err_scope = var->child_scope; |
| 6441 | 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 | 6576 | init_tld(&tld_container->base, TldIdContainer, name, visib_mod, node, parent_scope); |
| 6508 | 6577 | |
| 6509 | 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 | 6580 | kind, node, buf_ptr(name), layout); |
| 6512 | 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 | 6596 | } |
| 6528 | 6597 | |
| 6529 | 6598 | // errors should be populated with set1's values |
| 6530 | | static TypeTableEntry *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, TypeTableEntry *set1, TypeTableEntry *set2) { |
| 6531 | | assert(set1->id == TypeTableEntryIdErrorSet); |
| 6532 | | assert(set2->id == TypeTableEntryIdErrorSet); |
| 6599 | static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigType *set1, ZigType *set2) { |
| 6600 | assert(set1->id == ZigTypeIdErrorSet); |
| 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 | 6604 | buf_resize(&err_set_type->name, 0); |
| 6536 | 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 | 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 | 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 | 6656 | buf_resize(&err_set_type->name, 0); |
| 6588 | 6657 | buf_appendf(&err_set_type->name, "error{%s}", buf_ptr(&err_entry->name)); |
| 6589 | 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 | 6674 | uint32_t err_count = node->data.err_set_decl.decls.length; |
| 6606 | 6675 | |
| 6607 | 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 | 6678 | buf_init_from_buf(&err_set_type->name, type_name); |
| 6610 | 6679 | err_set_type->is_copyable = true; |
| 6611 | 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 | 6923 | if (target_inst == irb->codegen->invalid_instruction) |
| 6855 | 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 | 6927 | if (!fn_entry) { |
| 6859 | 6928 | add_node_error(irb->codegen, node, buf_sprintf("await outside function definition")); |
| 6860 | 6929 | return irb->codegen->invalid_instruction; |
| ... | ... | @@ -6917,7 +6986,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 6917 | 6986 | IrInstruction *is_canceled_mask = ir_build_const_usize(irb, scope, node, 0x1); // 0b001 |
| 6918 | 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 | 6990 | false, false, true, const_bool_false); |
| 6922 | 6991 | IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst); |
| 6923 | 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 | 7100 | static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 7032 | 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 | 7104 | if (!fn_entry) { |
| 7036 | 7105 | add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition")); |
| 7037 | 7106 | return irb->codegen->invalid_instruction; |
| ... | ... | @@ -7320,31 +7389,31 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 7320 | 7389 | // Entry block gets a reference because we enter it to begin. |
| 7321 | 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 | 7393 | bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync; |
| 7325 | 7394 | IrInstruction *coro_id; |
| 7326 | 7395 | IrInstruction *u8_ptr_type; |
| 7327 | 7396 | IrInstruction *const_bool_false; |
| 7328 | 7397 | IrInstruction *coro_promise_ptr; |
| 7329 | 7398 | IrInstruction *err_ret_trace_ptr; |
| 7330 | | TypeTableEntry *return_type; |
| 7399 | ZigType *return_type; |
| 7331 | 7400 | Buf *result_ptr_field_name; |
| 7332 | | VariableTableEntry *coro_size_var; |
| 7401 | ZigVar *coro_size_var; |
| 7333 | 7402 | if (is_async) { |
| 7334 | 7403 | // create the coro promise |
| 7335 | 7404 | Scope *coro_scope = create_coro_prelude_scope(node, scope); |
| 7336 | 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 | 7408 | return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type; |
| 7340 | 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 | 7411 | IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type); |
| 7343 | 7412 | // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa |
| 7344 | 7413 | ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef); |
| 7345 | 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 | 7417 | IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node); |
| 7349 | 7418 | IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node, |
| 7350 | 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 | 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 | 7604 | assert(fn_entry); |
| 7536 | 7605 | |
| 7537 | 7606 | IrExecutable *ir_executable = &fn_entry->ir_executable; |
| ... | ... | @@ -7566,6 +7635,19 @@ static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, |
| 7566 | 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 | 7651 | static IrInstruction *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { |
| 7570 | 7652 | IrBasicBlock *bb = exec->basic_block_list.at(0); |
| 7571 | 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 | 7678 | return true; |
| 7597 | 7679 | } |
| 7598 | 7680 | |
| 7599 | | static bool const_val_fits_in_num_lit(ConstExprValue *const_val, TypeTableEntry *num_lit_type) { |
| 7600 | | return ((num_lit_type->id == TypeTableEntryIdComptimeFloat && |
| 7601 | | (const_val->type->id == TypeTableEntryIdFloat || const_val->type->id == TypeTableEntryIdComptimeFloat)) || |
| 7602 | | (num_lit_type->id == TypeTableEntryIdComptimeInt && |
| 7603 | | (const_val->type->id == TypeTableEntryIdInt || const_val->type->id == TypeTableEntryIdComptimeInt))); |
| 7681 | static bool const_val_fits_in_num_lit(ConstExprValue *const_val, ZigType *num_lit_type) { |
| 7682 | return ((num_lit_type->id == ZigTypeIdComptimeFloat && |
| 7683 | (const_val->type->id == ZigTypeIdFloat || const_val->type->id == ZigTypeIdComptimeFloat)) || |
| 7684 | (num_lit_type->id == ZigTypeIdComptimeInt && |
| 7685 | (const_val->type->id == ZigTypeIdInt || const_val->type->id == ZigTypeIdComptimeInt))); |
| 7604 | 7686 | } |
| 7605 | 7687 | |
| 7606 | 7688 | static bool float_has_fraction(ConstExprValue *const_val) { |
| 7607 | | if (const_val->type->id == TypeTableEntryIdComptimeFloat) { |
| 7689 | if (const_val->type->id == ZigTypeIdComptimeFloat) { |
| 7608 | 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 | 7692 | switch (const_val->type->data.floating.bit_count) { |
| 7611 | 7693 | case 16: |
| 7612 | 7694 | { |
| ... | ... | @@ -7632,9 +7714,9 @@ static bool float_has_fraction(ConstExprValue *const_val) { |
| 7632 | 7714 | } |
| 7633 | 7715 | |
| 7634 | 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 | 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 | 7720 | switch (const_val->type->data.floating.bit_count) { |
| 7639 | 7721 | case 16: |
| 7640 | 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 | 7752 | } |
| 7671 | 7753 | |
| 7672 | 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 | 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 | 7758 | switch (const_val->type->data.floating.bit_count) { |
| 7677 | 7759 | case 16: |
| 7678 | 7760 | { |
| ... | ... | @@ -7717,9 +7799,9 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) { |
| 7717 | 7799 | } |
| 7718 | 7800 | |
| 7719 | 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 | 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 | 7805 | switch (dest_val->type->data.floating.bit_count) { |
| 7724 | 7806 | case 16: |
| 7725 | 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 | 7824 | } |
| 7743 | 7825 | |
| 7744 | 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 | 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 | 7830 | switch (dest_val->type->data.floating.bit_count) { |
| 7749 | 7831 | case 16: |
| 7750 | 7832 | dest_val->data.x_f16 = x; |
| ... | ... | @@ -7767,9 +7849,9 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) { |
| 7767 | 7849 | } |
| 7768 | 7850 | |
| 7769 | 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 | 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 | 7855 | switch (dest_val->type->data.floating.bit_count) { |
| 7774 | 7856 | case 16: |
| 7775 | 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 | 7878 | } |
| 7797 | 7879 | |
| 7798 | 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 | 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 | 7884 | switch (dest_val->type->data.floating.bit_count) { |
| 7803 | 7885 | case 16: |
| 7804 | 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 | 7907 | } |
| 7826 | 7908 | |
| 7827 | 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 | 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 | 7913 | switch (dest_val->type->data.floating.bit_count) { |
| 7832 | 7914 | case 16: |
| 7833 | 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 | 7940 | } |
| 7859 | 7941 | |
| 7860 | 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 | 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 | 7946 | switch (src_val->type->data.floating.bit_count) { |
| 7865 | 7947 | case 16: |
| 7866 | 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 | 7966 | |
| 7885 | 7967 | static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) { |
| 7886 | 7968 | assert(op1->type == op2->type); |
| 7887 | | if (op1->type->id == TypeTableEntryIdComptimeFloat) { |
| 7969 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 7888 | 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 | 7972 | switch (op1->type->data.floating.bit_count) { |
| 7891 | 7973 | case 16: |
| 7892 | 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 | 8011 | } |
| 7930 | 8012 | |
| 7931 | 8013 | static Cmp float_cmp_zero(ConstExprValue *op) { |
| 7932 | | if (op->type->id == TypeTableEntryIdComptimeFloat) { |
| 8014 | if (op->type->id == ZigTypeIdComptimeFloat) { |
| 7933 | 8015 | return bigfloat_cmp_zero(&op->data.x_bigfloat); |
| 7934 | | } else if (op->type->id == TypeTableEntryIdFloat) { |
| 8016 | } else if (op->type->id == ZigTypeIdFloat) { |
| 7935 | 8017 | switch (op->type->data.floating.bit_count) { |
| 7936 | 8018 | case 16: |
| 7937 | 8019 | { |
| ... | ... | @@ -7981,9 +8063,9 @@ static Cmp float_cmp_zero(ConstExprValue *op) { |
| 7981 | 8063 | static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 7982 | 8064 | assert(op1->type == op2->type); |
| 7983 | 8065 | out_val->type = op1->type; |
| 7984 | | if (op1->type->id == TypeTableEntryIdComptimeFloat) { |
| 8066 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 7985 | 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 | 8069 | switch (op1->type->data.floating.bit_count) { |
| 7988 | 8070 | case 16: |
| 7989 | 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 | 8090 | static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 8009 | 8091 | assert(op1->type == op2->type); |
| 8010 | 8092 | out_val->type = op1->type; |
| 8011 | | if (op1->type->id == TypeTableEntryIdComptimeFloat) { |
| 8093 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 8012 | 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 | 8096 | switch (op1->type->data.floating.bit_count) { |
| 8015 | 8097 | case 16: |
| 8016 | 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 | 8117 | static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 8036 | 8118 | assert(op1->type == op2->type); |
| 8037 | 8119 | out_val->type = op1->type; |
| 8038 | | if (op1->type->id == TypeTableEntryIdComptimeFloat) { |
| 8120 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 8039 | 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 | 8123 | switch (op1->type->data.floating.bit_count) { |
| 8042 | 8124 | case 16: |
| 8043 | 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 | 8144 | static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 8063 | 8145 | assert(op1->type == op2->type); |
| 8064 | 8146 | out_val->type = op1->type; |
| 8065 | | if (op1->type->id == TypeTableEntryIdComptimeFloat) { |
| 8147 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 8066 | 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 | 8150 | switch (op1->type->data.floating.bit_count) { |
| 8069 | 8151 | case 16: |
| 8070 | 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 | 8171 | static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 8090 | 8172 | assert(op1->type == op2->type); |
| 8091 | 8173 | out_val->type = op1->type; |
| 8092 | | if (op1->type->id == TypeTableEntryIdComptimeFloat) { |
| 8174 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 8093 | 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 | 8177 | switch (op1->type->data.floating.bit_count) { |
| 8096 | 8178 | case 16: |
| 8097 | 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 | 8200 | static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 8119 | 8201 | assert(op1->type == op2->type); |
| 8120 | 8202 | out_val->type = op1->type; |
| 8121 | | if (op1->type->id == TypeTableEntryIdComptimeFloat) { |
| 8203 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 8122 | 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 | 8206 | switch (op1->type->data.floating.bit_count) { |
| 8125 | 8207 | case 16: |
| 8126 | 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 | 8229 | static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 8148 | 8230 | assert(op1->type == op2->type); |
| 8149 | 8231 | out_val->type = op1->type; |
| 8150 | | if (op1->type->id == TypeTableEntryIdComptimeFloat) { |
| 8232 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 8151 | 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 | 8235 | switch (op1->type->data.floating.bit_count) { |
| 8154 | 8236 | case 16: |
| 8155 | 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 | 8274 | static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 8193 | 8275 | assert(op1->type == op2->type); |
| 8194 | 8276 | out_val->type = op1->type; |
| 8195 | | if (op1->type->id == TypeTableEntryIdComptimeFloat) { |
| 8277 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 8196 | 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 | 8280 | switch (op1->type->data.floating.bit_count) { |
| 8199 | 8281 | case 16: |
| 8200 | 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 | 8300 | |
| 8219 | 8301 | static void float_negate(ConstExprValue *out_val, ConstExprValue *op) { |
| 8220 | 8302 | out_val->type = op->type; |
| 8221 | | if (op->type->id == TypeTableEntryIdComptimeFloat) { |
| 8303 | if (op->type->id == ZigTypeIdComptimeFloat) { |
| 8222 | 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 | 8306 | switch (op->type->data.floating.bit_count) { |
| 8225 | 8307 | case 16: |
| 8226 | 8308 | { |
| ... | ... | @@ -8248,7 +8330,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) { |
| 8248 | 8330 | } |
| 8249 | 8331 | |
| 8250 | 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 | 8334 | switch (op->type->data.floating.bit_count) { |
| 8253 | 8335 | case 16: |
| 8254 | 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 | 8353 | } |
| 8272 | 8354 | |
| 8273 | 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 | 8357 | switch (val->type->data.floating.bit_count) { |
| 8276 | 8358 | case 16: |
| 8277 | 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 | 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 | 8379 | bool explicit_cast) |
| 8298 | 8380 | { |
| 8299 | 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 | 8385 | ConstExprValue *const_val = &instruction->value; |
| 8304 | 8386 | assert(const_val->special != ConstValSpecialRuntime); |
| 8305 | 8387 | |
| 8306 | | bool const_val_is_int = (const_val->type->id == TypeTableEntryIdInt || |
| 8307 | | const_val->type->id == TypeTableEntryIdComptimeInt); |
| 8308 | | bool const_val_is_float = (const_val->type->id == TypeTableEntryIdFloat || |
| 8309 | | const_val->type->id == TypeTableEntryIdComptimeFloat); |
| 8310 | | if (other_type->id == TypeTableEntryIdFloat) { |
| 8388 | bool const_val_is_int = (const_val->type->id == ZigTypeIdInt || |
| 8389 | const_val->type->id == ZigTypeIdComptimeInt); |
| 8390 | bool const_val_is_float = (const_val->type->id == ZigTypeIdFloat || |
| 8391 | const_val->type->id == ZigTypeIdComptimeFloat); |
| 8392 | if (other_type->id == ZigTypeIdFloat) { |
| 8311 | 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 | 8395 | if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { |
| 8314 | 8396 | Buf *val_buf = buf_alloc(); |
| 8315 | 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 | 8408 | } |
| 8327 | 8409 | } else if (const_val_fits_in_num_lit(const_val, other_type)) { |
| 8328 | 8410 | return true; |
| 8329 | | } else if (other_type->id == TypeTableEntryIdOptional) { |
| 8330 | | TypeTableEntry *child_type = other_type->data.maybe.child_type; |
| 8411 | } else if (other_type->id == ZigTypeIdOptional) { |
| 8412 | ZigType *child_type = other_type->data.maybe.child_type; |
| 8331 | 8413 | if (const_val_fits_in_num_lit(const_val, child_type)) { |
| 8332 | 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 | 8416 | if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { |
| 8335 | 8417 | Buf *val_buf = buf_alloc(); |
| 8336 | 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 | 8428 | { |
| 8347 | 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 | 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 | 8436 | const_val_is_float) |
| 8355 | 8437 | { |
| 8356 | 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 | 8445 | buf_ptr(&other_type->name))); |
| 8364 | 8446 | return false; |
| 8365 | 8447 | } else { |
| 8366 | | if (other_type->id == TypeTableEntryIdComptimeInt) { |
| 8448 | if (other_type->id == ZigTypeIdComptimeInt) { |
| 8367 | 8449 | return true; |
| 8368 | 8450 | } else { |
| 8369 | 8451 | BigInt bigint; |
| ... | ... | @@ -8395,20 +8477,20 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 8395 | 8477 | return false; |
| 8396 | 8478 | } |
| 8397 | 8479 | |
| 8398 | | static bool is_slice(TypeTableEntry *type) { |
| 8399 | | return type->id == TypeTableEntryIdStruct && type->data.structure.is_slice; |
| 8480 | static bool is_slice(ZigType *type) { |
| 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 | 8485 | assert(is_slice(type)); |
| 8404 | 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 | 8490 | AstNode *source_node) |
| 8409 | 8491 | { |
| 8410 | | assert(set1->id == TypeTableEntryIdErrorSet); |
| 8411 | | assert(set2->id == TypeTableEntryIdErrorSet); |
| 8492 | assert(set1->id == ZigTypeIdErrorSet); |
| 8493 | assert(set2->id == ZigTypeIdErrorSet); |
| 8412 | 8494 | |
| 8413 | 8495 | if (!resolve_inferred_error_set(ira->codegen, set1, source_node)) { |
| 8414 | 8496 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -8430,7 +8512,7 @@ static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry |
| 8430 | 8512 | } |
| 8431 | 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 | 8516 | buf_resize(&err_set_type->name, 0); |
| 8435 | 8517 | buf_appendf(&err_set_type->name, "error{"); |
| 8436 | 8518 | |
| ... | ... | @@ -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, |
| 8463 | | TypeTableEntry *actual_type, AstNode *source_node, bool wanted_is_mutable) |
| 8544 | static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted_type, |
| 8545 | ZigType *actual_type, AstNode *source_node, bool wanted_is_mutable) |
| 8464 | 8546 | { |
| 8465 | 8547 | CodeGen *g = ira->codegen; |
| 8466 | 8548 | ConstCastOnly result = {}; |
| ... | ... | @@ -8472,9 +8554,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8472 | 8554 | // *T and [*]T may const-cast-only to ?*U and ?[*]U, respectively |
| 8473 | 8555 | // but not if we want a mutable pointer |
| 8474 | 8556 | // and not if the actual pointer has zero bits |
| 8475 | | if (!wanted_is_mutable && wanted_type->id == TypeTableEntryIdOptional && |
| 8476 | | wanted_type->data.maybe.child_type->id == TypeTableEntryIdPointer && |
| 8477 | | actual_type->id == TypeTableEntryIdPointer && type_has_bits(actual_type)) |
| 8557 | if (!wanted_is_mutable && wanted_type->id == ZigTypeIdOptional && |
| 8558 | wanted_type->data.maybe.child_type->id == ZigTypeIdPointer && |
| 8559 | actual_type->id == ZigTypeIdPointer && type_has_bits(actual_type)) |
| 8478 | 8560 | { |
| 8479 | 8561 | ConstCastOnly child = types_match_const_cast_only(ira, |
| 8480 | 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 | 8569 | } |
| 8488 | 8570 | |
| 8489 | 8571 | // *T and [*]T can always cast to *c_void |
| 8490 | | if (wanted_type->id == TypeTableEntryIdPointer && |
| 8572 | if (wanted_type->id == ZigTypeIdPointer && |
| 8491 | 8573 | wanted_type->data.pointer.ptr_len == PtrLenSingle && |
| 8492 | 8574 | wanted_type->data.pointer.child_type == g->builtin_types.entry_c_void && |
| 8493 | | actual_type->id == TypeTableEntryIdPointer && |
| 8575 | actual_type->id == ZigTypeIdPointer && |
| 8494 | 8576 | (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) && |
| 8495 | 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 | 8581 | } |
| 8500 | 8582 | |
| 8501 | 8583 | // pointer const |
| 8502 | | if (wanted_type->id == TypeTableEntryIdPointer && actual_type->id == TypeTableEntryIdPointer) { |
| 8584 | if (wanted_type->id == ZigTypeIdPointer && actual_type->id == ZigTypeIdPointer) { |
| 8503 | 8585 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 8504 | 8586 | actual_type->data.pointer.child_type, source_node, !wanted_type->data.pointer.is_const); |
| 8505 | 8587 | if (child.id != ConstCastResultIdOk) { |
| ... | ... | @@ -8523,8 +8605,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8523 | 8605 | |
| 8524 | 8606 | // slice const |
| 8525 | 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; |
| 8527 | | TypeTableEntry *wanted_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8608 | ZigType *actual_ptr_type = actual_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 | 8610 | if ((!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) && |
| 8529 | 8611 | (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile) && |
| 8530 | 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 | 8627 | } |
| 8546 | 8628 | |
| 8547 | 8629 | // maybe |
| 8548 | | if (wanted_type->id == TypeTableEntryIdOptional && actual_type->id == TypeTableEntryIdOptional) { |
| 8630 | if (wanted_type->id == ZigTypeIdOptional && actual_type->id == ZigTypeIdOptional) { |
| 8549 | 8631 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.maybe.child_type, |
| 8550 | 8632 | actual_type->data.maybe.child_type, source_node, wanted_is_mutable); |
| 8551 | 8633 | if (child.id != ConstCastResultIdOk) { |
| ... | ... | @@ -8559,7 +8641,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8559 | 8641 | } |
| 8560 | 8642 | |
| 8561 | 8643 | // error union |
| 8562 | | if (wanted_type->id == TypeTableEntryIdErrorUnion && actual_type->id == TypeTableEntryIdErrorUnion) { |
| 8644 | if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id == ZigTypeIdErrorUnion) { |
| 8563 | 8645 | ConstCastOnly payload_child = types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, |
| 8564 | 8646 | actual_type->data.error_union.payload_type, source_node, wanted_is_mutable); |
| 8565 | 8647 | if (payload_child.id != ConstCastResultIdOk) { |
| ... | ... | @@ -8584,9 +8666,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8584 | 8666 | } |
| 8585 | 8667 | |
| 8586 | 8668 | // error set |
| 8587 | | if (wanted_type->id == TypeTableEntryIdErrorSet && actual_type->id == TypeTableEntryIdErrorSet) { |
| 8588 | | TypeTableEntry *contained_set = actual_type; |
| 8589 | | TypeTableEntry *container_set = wanted_type; |
| 8669 | if (wanted_type->id == ZigTypeIdErrorSet && actual_type->id == ZigTypeIdErrorSet) { |
| 8670 | ZigType *contained_set = actual_type; |
| 8671 | ZigType *container_set = wanted_type; |
| 8590 | 8672 | |
| 8591 | 8673 | // if the container set is inferred, then this will always work. |
| 8592 | 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 | 8711 | } |
| 8630 | 8712 | |
| 8631 | 8713 | if (wanted_type == ira->codegen->builtin_types.entry_promise && |
| 8632 | | actual_type->id == TypeTableEntryIdPromise) |
| 8714 | actual_type->id == ZigTypeIdPromise) |
| 8633 | 8715 | { |
| 8634 | 8716 | return result; |
| 8635 | 8717 | } |
| 8636 | 8718 | |
| 8637 | 8719 | // fn |
| 8638 | | if (wanted_type->id == TypeTableEntryIdFn && |
| 8639 | | actual_type->id == TypeTableEntryIdFn) |
| 8720 | if (wanted_type->id == ZigTypeIdFn && |
| 8721 | actual_type->id == ZigTypeIdFn) |
| 8640 | 8722 | { |
| 8641 | 8723 | if (wanted_type->data.fn.fn_type_id.alignment > actual_type->data.fn.fn_type_id.alignment) { |
| 8642 | 8724 | result.id = ConstCastResultIdFnAlign; |
| ... | ... | @@ -8655,7 +8737,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 8655 | 8737 | return result; |
| 8656 | 8738 | } |
| 8657 | 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 | 8742 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.fn.fn_type_id.return_type, |
| 8661 | 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 | 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 | 8811 | Error err; |
| 8730 | 8812 | assert(instruction_count >= 1); |
| 8731 | 8813 | IrInstruction *prev_inst = instructions[0]; |
| ... | ... | @@ -8734,8 +8816,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8734 | 8816 | } |
| 8735 | 8817 | ErrorTableEntry **errors = nullptr; |
| 8736 | 8818 | size_t errors_count = 0; |
| 8737 | | TypeTableEntry *err_set_type = nullptr; |
| 8738 | | if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) { |
| 8819 | ZigType *err_set_type = nullptr; |
| 8820 | if (prev_inst->value.type->id == ZigTypeIdErrorSet) { |
| 8739 | 8821 | if (type_is_global_error_set(prev_inst->value.type)) { |
| 8740 | 8822 | err_set_type = ira->codegen->builtin_types.entry_global_error_set; |
| 8741 | 8823 | } else { |
| ... | ... | @@ -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 | 8839 | bool convert_to_const_slice = false; |
| 8758 | 8840 | for (size_t i = 1; i < instruction_count; i += 1) { |
| 8759 | 8841 | IrInstruction *cur_inst = instructions[i]; |
| 8760 | | TypeTableEntry *cur_type = cur_inst->value.type; |
| 8761 | | TypeTableEntry *prev_type = prev_inst->value.type; |
| 8842 | ZigType *cur_type = cur_inst->value.type; |
| 8843 | ZigType *prev_type = prev_inst->value.type; |
| 8762 | 8844 | |
| 8763 | 8845 | if (type_is_invalid(cur_type)) { |
| 8764 | 8846 | return cur_type; |
| 8765 | 8847 | } |
| 8766 | 8848 | |
| 8767 | | if (prev_type->id == TypeTableEntryIdUnreachable) { |
| 8849 | if (prev_type->id == ZigTypeIdUnreachable) { |
| 8768 | 8850 | prev_inst = cur_inst; |
| 8769 | 8851 | continue; |
| 8770 | 8852 | } |
| 8771 | 8853 | |
| 8772 | | if (cur_type->id == TypeTableEntryIdUnreachable) { |
| 8854 | if (cur_type->id == ZigTypeIdUnreachable) { |
| 8773 | 8855 | continue; |
| 8774 | 8856 | } |
| 8775 | 8857 | |
| 8776 | | if (prev_type->id == TypeTableEntryIdErrorSet) { |
| 8858 | if (prev_type->id == ZigTypeIdErrorSet) { |
| 8777 | 8859 | assert(err_set_type != nullptr); |
| 8778 | | if (cur_type->id == TypeTableEntryIdErrorSet) { |
| 8860 | if (cur_type->id == ZigTypeIdErrorSet) { |
| 8779 | 8861 | if (type_is_global_error_set(err_set_type)) { |
| 8780 | 8862 | continue; |
| 8781 | 8863 | } |
| ... | ... | @@ -8839,12 +8921,12 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8839 | 8921 | err_set_type = get_error_set_union(ira->codegen, errors, cur_type, err_set_type); |
| 8840 | 8922 | assert(errors != nullptr); |
| 8841 | 8923 | continue; |
| 8842 | | } else if (cur_type->id == TypeTableEntryIdErrorUnion) { |
| 8924 | } else if (cur_type->id == ZigTypeIdErrorUnion) { |
| 8843 | 8925 | if (type_is_global_error_set(err_set_type)) { |
| 8844 | 8926 | prev_inst = cur_inst; |
| 8845 | 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 | 8930 | if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { |
| 8849 | 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 | 8979 | } |
| 8898 | 8980 | } |
| 8899 | 8981 | |
| 8900 | | if (cur_type->id == TypeTableEntryIdErrorSet) { |
| 8901 | | if (prev_type->id == TypeTableEntryIdArray) { |
| 8982 | if (cur_type->id == ZigTypeIdErrorSet) { |
| 8983 | if (prev_type->id == ZigTypeIdArray) { |
| 8902 | 8984 | convert_to_const_slice = true; |
| 8903 | 8985 | } |
| 8904 | 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 | 8997 | update_errors_helper(ira->codegen, &errors, &errors_count); |
| 8916 | 8998 | |
| 8917 | 8999 | if (err_set_type == nullptr) { |
| 8918 | | if (prev_type->id == TypeTableEntryIdErrorUnion) { |
| 9000 | if (prev_type->id == ZigTypeIdErrorUnion) { |
| 8919 | 9001 | err_set_type = prev_type->data.error_union.err_set_type; |
| 8920 | 9002 | } else { |
| 8921 | 9003 | err_set_type = cur_type; |
| ... | ... | @@ -8948,9 +9030,9 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8948 | 9030 | continue; |
| 8949 | 9031 | } |
| 8950 | 9032 | |
| 8951 | | if (prev_type->id == TypeTableEntryIdErrorUnion && cur_type->id == TypeTableEntryIdErrorUnion) { |
| 8952 | | TypeTableEntry *prev_payload_type = prev_type->data.error_union.payload_type; |
| 8953 | | TypeTableEntry *cur_payload_type = cur_type->data.error_union.payload_type; |
| 9033 | if (prev_type->id == ZigTypeIdErrorUnion && cur_type->id == ZigTypeIdErrorUnion) { |
| 9034 | ZigType *prev_payload_type = prev_type->data.error_union.payload_type; |
| 9035 | ZigType *cur_payload_type = cur_type->data.error_union.payload_type; |
| 8954 | 9036 | |
| 8955 | 9037 | bool const_cast_prev = types_match_const_cast_only(ira, prev_payload_type, cur_payload_type, |
| 8956 | 9038 | source_node, false).id == ConstCastResultIdOk; |
| ... | ... | @@ -8962,8 +9044,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 8962 | 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; |
| 8966 | | TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 9047 | ZigType *prev_err_set_type = (err_set_type == nullptr) ? prev_type->data.error_union.err_set_type : err_set_type; |
| 9048 | ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 8967 | 9049 | |
| 8968 | 9050 | if (!resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) { |
| 8969 | 9051 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -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 | 9118 | prev_inst = cur_inst; |
| 9037 | 9119 | continue; |
| 9038 | 9120 | } |
| 9039 | 9121 | |
| 9040 | | if (cur_type->id == TypeTableEntryIdNull) { |
| 9122 | if (cur_type->id == ZigTypeIdNull) { |
| 9041 | 9123 | any_are_null = true; |
| 9042 | 9124 | continue; |
| 9043 | 9125 | } |
| ... | ... | @@ -9051,8 +9133,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9051 | 9133 | continue; |
| 9052 | 9134 | } |
| 9053 | 9135 | |
| 9054 | | if (prev_type->id == TypeTableEntryIdInt && |
| 9055 | | cur_type->id == TypeTableEntryIdInt && |
| 9136 | if (prev_type->id == ZigTypeIdInt && |
| 9137 | cur_type->id == ZigTypeIdInt && |
| 9056 | 9138 | prev_type->data.integral.is_signed == cur_type->data.integral.is_signed) |
| 9057 | 9139 | { |
| 9058 | 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 | 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 | 9147 | if (cur_type->data.floating.bit_count > prev_type->data.floating.bit_count) { |
| 9066 | 9148 | prev_inst = cur_inst; |
| 9067 | 9149 | } |
| 9068 | 9150 | continue; |
| 9069 | 9151 | } |
| 9070 | 9152 | |
| 9071 | | if (prev_type->id == TypeTableEntryIdErrorUnion && |
| 9153 | if (prev_type->id == ZigTypeIdErrorUnion && |
| 9072 | 9154 | types_match_const_cast_only(ira, prev_type->data.error_union.payload_type, cur_type, |
| 9073 | 9155 | source_node, false).id == ConstCastResultIdOk) |
| 9074 | 9156 | { |
| 9075 | 9157 | continue; |
| 9076 | 9158 | } |
| 9077 | 9159 | |
| 9078 | | if (cur_type->id == TypeTableEntryIdErrorUnion && |
| 9160 | if (cur_type->id == ZigTypeIdErrorUnion && |
| 9079 | 9161 | types_match_const_cast_only(ira, cur_type->data.error_union.payload_type, prev_type, |
| 9080 | 9162 | source_node, false).id == ConstCastResultIdOk) |
| 9081 | 9163 | { |
| 9082 | 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 | 9166 | if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { |
| 9085 | 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 | 9180 | continue; |
| 9099 | 9181 | } |
| 9100 | 9182 | |
| 9101 | | if (prev_type->id == TypeTableEntryIdOptional && |
| 9183 | if (prev_type->id == ZigTypeIdOptional && |
| 9102 | 9184 | types_match_const_cast_only(ira, prev_type->data.maybe.child_type, cur_type, |
| 9103 | 9185 | source_node, false).id == ConstCastResultIdOk) |
| 9104 | 9186 | { |
| 9105 | 9187 | continue; |
| 9106 | 9188 | } |
| 9107 | 9189 | |
| 9108 | | if (cur_type->id == TypeTableEntryIdOptional && |
| 9190 | if (cur_type->id == ZigTypeIdOptional && |
| 9109 | 9191 | types_match_const_cast_only(ira, cur_type->data.maybe.child_type, prev_type, |
| 9110 | 9192 | source_node, false).id == ConstCastResultIdOk) |
| 9111 | 9193 | { |
| ... | ... | @@ -9113,17 +9195,17 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9113 | 9195 | continue; |
| 9114 | 9196 | } |
| 9115 | 9197 | |
| 9116 | | if (cur_type->id == TypeTableEntryIdUndefined) { |
| 9198 | if (cur_type->id == ZigTypeIdUndefined) { |
| 9117 | 9199 | continue; |
| 9118 | 9200 | } |
| 9119 | 9201 | |
| 9120 | | if (prev_type->id == TypeTableEntryIdUndefined) { |
| 9202 | if (prev_type->id == ZigTypeIdUndefined) { |
| 9121 | 9203 | prev_inst = cur_inst; |
| 9122 | 9204 | continue; |
| 9123 | 9205 | } |
| 9124 | 9206 | |
| 9125 | | if (prev_type->id == TypeTableEntryIdComptimeInt || |
| 9126 | | prev_type->id == TypeTableEntryIdComptimeFloat) |
| 9207 | if (prev_type->id == ZigTypeIdComptimeInt || |
| 9208 | prev_type->id == ZigTypeIdComptimeFloat) |
| 9127 | 9209 | { |
| 9128 | 9210 | if (ir_num_lit_fits_in_other_type(ira, prev_inst, cur_type, false)) { |
| 9129 | 9211 | prev_inst = cur_inst; |
| ... | ... | @@ -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 || |
| 9137 | | cur_type->id == TypeTableEntryIdComptimeFloat) |
| 9218 | if (cur_type->id == ZigTypeIdComptimeInt || |
| 9219 | cur_type->id == ZigTypeIdComptimeFloat) |
| 9138 | 9220 | { |
| 9139 | 9221 | if (ir_num_lit_fits_in_other_type(ira, cur_inst, prev_type, false)) { |
| 9140 | 9222 | continue; |
| ... | ... | @@ -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 | 9229 | cur_type->data.array.len != prev_type->data.array.len && |
| 9148 | 9230 | types_match_const_cast_only(ira, cur_type->data.array.child_type, prev_type->data.array.child_type, |
| 9149 | 9231 | source_node, false).id == ConstCastResultIdOk) |
| ... | ... | @@ -9153,7 +9235,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9153 | 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 | 9239 | cur_type->data.array.len != prev_type->data.array.len && |
| 9158 | 9240 | types_match_const_cast_only(ira, prev_type->data.array.child_type, cur_type->data.array.child_type, |
| 9159 | 9241 | source_node, false).id == ConstCastResultIdOk) |
| ... | ... | @@ -9162,7 +9244,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9162 | 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 | 9248 | (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || |
| 9167 | 9249 | cur_type->data.array.len == 0) && |
| 9168 | 9250 | types_match_const_cast_only(ira, |
| ... | ... | @@ -9173,7 +9255,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9173 | 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 | 9259 | (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || |
| 9178 | 9260 | prev_type->data.array.len == 0) && |
| 9179 | 9261 | types_match_const_cast_only(ira, |
| ... | ... | @@ -9185,7 +9267,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9185 | 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 | 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 | 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 | 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 | 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 | 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 | 9302 | free(errors); |
| 9221 | 9303 | |
| 9222 | 9304 | if (convert_to_const_slice) { |
| 9223 | | assert(prev_inst->value.type->id == TypeTableEntryIdArray); |
| 9224 | | TypeTableEntry *ptr_type = get_pointer_to_type_extra( |
| 9305 | assert(prev_inst->value.type->id == ZigTypeIdArray); |
| 9306 | ZigType *ptr_type = get_pointer_to_type_extra( |
| 9225 | 9307 | ira->codegen, prev_inst->value.type->data.array.child_type, |
| 9226 | 9308 | true, false, PtrLenUnknown, |
| 9227 | 9309 | get_abi_alignment(ira->codegen, prev_inst->value.type->data.array.child_type), |
| 9228 | 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 | 9312 | if (err_set_type != nullptr) { |
| 9231 | 9313 | return get_error_union_type(ira->codegen, err_set_type, slice_type); |
| 9232 | 9314 | } else { |
| 9233 | 9315 | return slice_type; |
| 9234 | 9316 | } |
| 9235 | 9317 | } else if (err_set_type != nullptr) { |
| 9236 | | if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) { |
| 9318 | if (prev_inst->value.type->id == ZigTypeIdErrorSet) { |
| 9237 | 9319 | return err_set_type; |
| 9238 | | } else if (prev_inst->value.type->id == TypeTableEntryIdErrorUnion) { |
| 9320 | } else if (prev_inst->value.type->id == ZigTypeIdErrorUnion) { |
| 9239 | 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 | 9323 | return get_error_union_type(ira->codegen, err_set_type, expected_type->data.error_union.payload_type); |
| 9242 | 9324 | } else { |
| 9243 | | if (prev_inst->value.type->id == TypeTableEntryIdComptimeInt || |
| 9244 | | prev_inst->value.type->id == TypeTableEntryIdComptimeFloat) |
| 9325 | if (prev_inst->value.type->id == ZigTypeIdComptimeInt || |
| 9326 | prev_inst->value.type->id == ZigTypeIdComptimeFloat) |
| 9245 | 9327 | { |
| 9246 | 9328 | ir_add_error_node(ira, source_node, |
| 9247 | 9329 | buf_sprintf("unable to make error union out of number literal")); |
| 9248 | 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 | 9332 | ir_add_error_node(ira, source_node, |
| 9251 | 9333 | buf_sprintf("unable to make error union out of null literal")); |
| 9252 | 9334 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -9254,14 +9336,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 9254 | 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) { |
| 9258 | | if (prev_inst->value.type->id == TypeTableEntryIdComptimeInt || |
| 9259 | | prev_inst->value.type->id == TypeTableEntryIdComptimeFloat) |
| 9339 | } else if (any_are_null && prev_inst->value.type->id != ZigTypeIdNull) { |
| 9340 | if (prev_inst->value.type->id == ZigTypeIdComptimeInt || |
| 9341 | prev_inst->value.type->id == ZigTypeIdComptimeFloat) |
| 9260 | 9342 | { |
| 9261 | 9343 | ir_add_error_node(ira, source_node, |
| 9262 | 9344 | buf_sprintf("unable to make maybe out of number literal")); |
| 9263 | 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 | 9347 | return prev_inst->value.type; |
| 9266 | 9348 | } else { |
| 9267 | 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 | 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 | 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 | 9359 | if (fn_entry != nullptr) { |
| 9278 | 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 | 9367 | *dest = *src; |
| 9286 | 9368 | if (!same_global_refs) { |
| 9287 | 9369 | dest->global_refs = global_refs; |
| 9288 | | if (dest->type->id == TypeTableEntryIdStruct) { |
| 9370 | if (dest->type->id == ZigTypeIdStruct) { |
| 9289 | 9371 | dest->data.x_struct.fields = allocate_nonzero<ConstExprValue>(dest->type->data.structure.src_field_count); |
| 9290 | 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 | 9376 | |
| 9295 | 9377 | static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr, |
| 9296 | 9378 | CastOp cast_op, |
| 9297 | | ConstExprValue *other_val, TypeTableEntry *other_type, |
| 9298 | | ConstExprValue *const_val, TypeTableEntry *new_type) |
| 9379 | ConstExprValue *other_val, ZigType *other_type, |
| 9380 | ConstExprValue *const_val, ZigType *new_type) |
| 9299 | 9381 | { |
| 9300 | 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 | 9397 | break; |
| 9316 | 9398 | } |
| 9317 | 9399 | case CastOpNumLitToConcrete: |
| 9318 | | if (other_val->type->id == TypeTableEntryIdComptimeFloat) { |
| 9319 | | assert(new_type->id == TypeTableEntryIdFloat); |
| 9400 | if (other_val->type->id == ZigTypeIdComptimeFloat) { |
| 9401 | assert(new_type->id == ZigTypeIdFloat); |
| 9320 | 9402 | switch (new_type->data.floating.bit_count) { |
| 9321 | 9403 | case 16: |
| 9322 | 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 | 9415 | default: |
| 9334 | 9416 | zig_unreachable(); |
| 9335 | 9417 | } |
| 9336 | | } else if (other_val->type->id == TypeTableEntryIdComptimeInt) { |
| 9418 | } else if (other_val->type->id == ZigTypeIdComptimeInt) { |
| 9337 | 9419 | bigint_init_bigint(&const_val->data.x_bigint, &other_val->data.x_bigint); |
| 9338 | 9420 | } else { |
| 9339 | 9421 | zig_unreachable(); |
| ... | ... | @@ -9346,7 +9428,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 9346 | 9428 | zig_unreachable(); |
| 9347 | 9429 | case CastOpIntToFloat: |
| 9348 | 9430 | { |
| 9349 | | assert(new_type->id == TypeTableEntryIdFloat); |
| 9431 | assert(new_type->id == ZigTypeIdFloat); |
| 9350 | 9432 | |
| 9351 | 9433 | BigFloat bigfloat; |
| 9352 | 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 | 9453 | } |
| 9372 | 9454 | case CastOpFloatToInt: |
| 9373 | 9455 | float_init_bigint(&const_val->data.x_bigint, other_val); |
| 9374 | | if (new_type->id == TypeTableEntryIdInt) { |
| 9456 | if (new_type->id == ZigTypeIdInt) { |
| 9375 | 9457 | if (!bigint_fits_in_bits(&const_val->data.x_bigint, new_type->data.integral.bit_count, |
| 9376 | 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 | 9477 | return true; |
| 9396 | 9478 | } |
| 9397 | 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 | 9482 | if ((instr_is_comptime(value) || !type_has_bits(wanted_type)) && |
| 9401 | 9483 | cast_op != CastOpResizeSlice && cast_op != CastOpBytesToSlice) |
| ... | ... | @@ -9419,13 +9501,15 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 9419 | 9501 | } |
| 9420 | 9502 | |
| 9421 | 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 | 9507 | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment); |
| 9426 | 9508 | |
| 9427 | 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 | 9513 | if (pointee->special != ConstValSpecialRuntime) { |
| 9430 | 9514 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, |
| 9431 | 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 | 9530 | } |
| 9447 | 9531 | |
| 9448 | 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 | 9535 | wanted_type = adjust_slice_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment); |
| 9452 | 9536 | |
| 9453 | 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 | 9541 | if (pointee->special != ConstValSpecialRuntime) { |
| 9456 | | assert(value->value.type->id == TypeTableEntryIdPointer); |
| 9457 | | TypeTableEntry *array_type = value->value.type->data.pointer.child_type; |
| 9542 | assert(value->value.type->id == ZigTypeIdPointer); |
| 9543 | ZigType *array_type = value->value.type->data.pointer.child_type; |
| 9458 | 9544 | assert(is_slice(wanted_type)); |
| 9459 | 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 | 9561 | return result; |
| 9476 | 9562 | } |
| 9477 | 9563 | |
| 9478 | | static bool is_container(TypeTableEntry *type) { |
| 9479 | | return type->id == TypeTableEntryIdStruct || |
| 9480 | | type->id == TypeTableEntryIdEnum || |
| 9481 | | type->id == TypeTableEntryIdUnion; |
| 9564 | static bool is_container(ZigType *type) { |
| 9565 | return type->id == ZigTypeIdStruct || |
| 9566 | type->id == ZigTypeIdEnum || |
| 9567 | type->id == ZigTypeIdUnion; |
| 9482 | 9568 | } |
| 9483 | 9569 | |
| 9484 | 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 | 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 | 9598 | static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *const_predecessor_bb) { |
| 9500 | 9599 | ira->instruction_index = 0; |
| 9501 | 9600 | ira->old_irb.current_basic_block = old_bb; |
| ... | ... | @@ -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 | 9644 | ira->old_bb_index = SIZE_MAX; |
| 9546 | 9645 | ira->new_irb.exec->invalid = true; |
| 9547 | 9646 | return ira->codegen->builtin_types.entry_unreachable; |
| ... | ... | @@ -9564,7 +9663,7 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru |
| 9564 | 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 | 9667 | if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) { |
| 9569 | 9668 | if (!ir_emit_backward_branch(ira, source_instruction)) |
| 9570 | 9669 | return ir_unreach_error(ira); |
| ... | ... | @@ -9575,8 +9674,8 @@ static TypeTableEntry *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instru |
| 9575 | 9674 | return ira->codegen->builtin_types.entry_unreachable; |
| 9576 | 9675 | } |
| 9577 | 9676 | |
| 9578 | | static TypeTableEntry *ir_finish_anal(IrAnalyze *ira, TypeTableEntry *result_type) { |
| 9579 | | if (result_type->id == TypeTableEntryIdUnreachable) |
| 9677 | static ZigType *ir_finish_anal(IrAnalyze *ira, ZigType *result_type) { |
| 9678 | if (result_type->id == ZigTypeIdUnreachable) |
| 9580 | 9679 | ir_finish_bb(ira); |
| 9581 | 9680 | return result_type; |
| 9582 | 9681 | } |
| ... | ... | @@ -9595,16 +9694,16 @@ static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_in |
| 9595 | 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 | 9698 | ir_build_const_from(ira, instruction); |
| 9600 | 9699 | return ira->codegen->builtin_types.entry_void; |
| 9601 | 9700 | } |
| 9602 | 9701 | |
| 9603 | 9702 | static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 9604 | | ConstExprValue *pointee, TypeTableEntry *pointee_type, |
| 9703 | ConstExprValue *pointee, ZigType *pointee_type, |
| 9605 | 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 | 9707 | ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0); |
| 9609 | 9708 | IrInstruction *const_instr = ir_get_const(ira, instruction); |
| 9610 | 9709 | ConstExprValue *const_val = &const_instr->value; |
| ... | ... | @@ -9615,8 +9714,8 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio |
| 9615 | 9714 | return const_instr; |
| 9616 | 9715 | } |
| 9617 | 9716 | |
| 9618 | | static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 9619 | | ConstExprValue *pointee, TypeTableEntry *pointee_type, |
| 9717 | static ZigType *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 9718 | ConstExprValue *pointee, ZigType *pointee_type, |
| 9620 | 9719 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile) |
| 9621 | 9720 | { |
| 9622 | 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 | 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 | 9729 | ConstExprValue *const_val = ir_build_const_from(ira, instruction); |
| 9631 | 9730 | bigint_init_unsigned(&const_val->data.x_bigint, value); |
| 9632 | 9731 | return ira->codegen->builtin_types.entry_usize; |
| ... | ... | @@ -9659,8 +9758,8 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un |
| 9659 | 9758 | } |
| 9660 | 9759 | |
| 9661 | 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, |
| 9663 | | FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, |
| 9761 | ZigType *expected_type, size_t *backward_branch_count, size_t backward_branch_quota, |
| 9762 | ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, |
| 9664 | 9763 | IrExecutable *parent_exec) |
| 9665 | 9764 | { |
| 9666 | 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 | 9796 | analyzed_executable->backward_branch_count = backward_branch_count; |
| 9698 | 9797 | analyzed_executable->backward_branch_quota = backward_branch_quota; |
| 9699 | 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 | 9800 | if (type_is_invalid(result_type)) |
| 9702 | 9801 | return codegen->invalid_instruction; |
| 9703 | 9802 | |
| ... | ... | @@ -9710,11 +9809,11 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node |
| 9710 | 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 | 9813 | if (type_is_invalid(type_value->value.type)) |
| 9715 | 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 | 9817 | ir_add_error(ira, type_value, |
| 9719 | 9818 | buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name))); |
| 9720 | 9819 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -9727,14 +9826,14 @@ static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value |
| 9727 | 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 | 9830 | if (fn_value == ira->codegen->invalid_instruction) |
| 9732 | 9831 | return nullptr; |
| 9733 | 9832 | |
| 9734 | 9833 | if (type_is_invalid(fn_value->value.type)) |
| 9735 | 9834 | return nullptr; |
| 9736 | 9835 | |
| 9737 | | if (fn_value->value.type->id != TypeTableEntryIdFn) { |
| 9836 | if (fn_value->value.type->id != ZigTypeIdFn) { |
| 9738 | 9837 | ir_add_error_node(ira, fn_value->source_node, |
| 9739 | 9838 | buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value.type->name))); |
| 9740 | 9839 | return nullptr; |
| ... | ... | @@ -9748,11 +9847,11 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { |
| 9748 | 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) { |
| 9752 | | assert(wanted_type->id == TypeTableEntryIdOptional); |
| 9850 | static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { |
| 9851 | assert(wanted_type->id == ZigTypeIdOptional); |
| 9753 | 9852 | |
| 9754 | 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 | 9855 | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 9757 | 9856 | if (type_is_invalid(casted_payload->value.type)) |
| 9758 | 9857 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -9781,12 +9880,12 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc |
| 9781 | 9880 | } |
| 9782 | 9881 | |
| 9783 | 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 | 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 | 9889 | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 9791 | 9890 | if (type_is_invalid(casted_payload->value.type)) |
| 9792 | 9891 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -9812,10 +9911,10 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 9812 | 9911 | } |
| 9813 | 9912 | |
| 9814 | 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); |
| 9818 | | assert(wanted_type->id == TypeTableEntryIdErrorSet); |
| 9916 | assert(value->value.type->id == ZigTypeIdErrorSet); |
| 9917 | assert(wanted_type->id == ZigTypeIdErrorSet); |
| 9819 | 9918 | |
| 9820 | 9919 | if (instr_is_comptime(value)) { |
| 9821 | 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 | 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) { |
| 9858 | | assert(wanted_type->id == TypeTableEntryIdErrorUnion); |
| 9956 | static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { |
| 9957 | assert(wanted_type->id == ZigTypeIdErrorUnion); |
| 9859 | 9958 | |
| 9860 | 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 | 9980 | } |
| 9882 | 9981 | |
| 9883 | 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 | 9985 | if (instr_is_comptime(value)) { |
| 9887 | 9986 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| ... | ... | @@ -9905,9 +10004,9 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_ |
| 9905 | 10004 | source_instr->source_node, value, true, false); |
| 9906 | 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 | 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 | 10010 | assert(fn_entry); |
| 9912 | 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 | 10015 | } |
| 9917 | 10016 | } |
| 9918 | 10017 | |
| 9919 | | static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) { |
| 9920 | | assert(wanted_type->id == TypeTableEntryIdOptional); |
| 10018 | static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { |
| 10019 | assert(wanted_type->id == ZigTypeIdOptional); |
| 9921 | 10020 | assert(instr_is_comptime(value)); |
| 9922 | 10021 | |
| 9923 | 10022 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| ... | ... | @@ -9950,14 +10049,14 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi |
| 9950 | 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 | 10053 | is_const, is_volatile, PtrLenSingle, get_abi_alignment(ira->codegen, value->value.type), 0, 0); |
| 9955 | 10054 | IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope, |
| 9956 | 10055 | source_instruction->source_node, value, is_const, is_volatile); |
| 9957 | 10056 | new_instruction->value.type = ptr_type; |
| 9958 | 10057 | new_instruction->value.data.rh_ptr = RuntimeHintPtrStack; |
| 9959 | 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 | 10060 | assert(fn_entry); |
| 9962 | 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 | 10064 | } |
| 9966 | 10065 | |
| 9967 | 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 | 10069 | assert(is_slice(wanted_type)); |
| 9971 | 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 | 10072 | |
| 9974 | 10073 | IrInstruction *array_ptr = nullptr; |
| 9975 | 10074 | IrInstruction *array; |
| 9976 | | if (array_arg->value.type->id == TypeTableEntryIdPointer) { |
| 10075 | if (array_arg->value.type->id == ZigTypeIdPointer) { |
| 9977 | 10076 | array = ir_get_deref(ira, source_instr, array_arg); |
| 9978 | 10077 | array_ptr = array_arg; |
| 9979 | 10078 | } else { |
| 9980 | 10079 | array = array_arg; |
| 9981 | 10080 | } |
| 9982 | | TypeTableEntry *array_type = array->value.type; |
| 9983 | | assert(array_type->id == TypeTableEntryIdArray); |
| 10081 | ZigType *array_type = array->value.type; |
| 10082 | assert(array_type->id == ZigTypeIdArray); |
| 9984 | 10083 | |
| 9985 | 10084 | if (instr_is_comptime(array)) { |
| 9986 | 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 | 10110 | } |
| 10012 | 10111 | |
| 10013 | 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 | 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 | 10119 | if ((err = ensure_complete_type(ira->codegen, actual_type))) |
| 10021 | 10120 | return ira->codegen->invalid_instruction; |
| 10022 | 10121 | |
| ... | ... | @@ -10028,7 +10127,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour |
| 10028 | 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 | 10132 | if (instr_is_comptime(target)) { |
| 10034 | 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 | 10146 | } |
| 10048 | 10147 | |
| 10049 | 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); |
| 10053 | | assert(wanted_type->id == TypeTableEntryIdEnum); |
| 10151 | assert(target->value.type->id == ZigTypeIdUnion); |
| 10152 | assert(wanted_type->id == ZigTypeIdEnum); |
| 10054 | 10153 | assert(wanted_type == target->value.type->data.unionation.tag_type); |
| 10055 | 10154 | |
| 10056 | 10155 | if (instr_is_comptime(target)) { |
| ... | ... | @@ -10072,7 +10171,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou |
| 10072 | 10171 | } |
| 10073 | 10172 | |
| 10074 | 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 | 10176 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, |
| 10078 | 10177 | source_instr->source_node, wanted_type); |
| ... | ... | @@ -10081,11 +10180,11 @@ static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruc |
| 10081 | 10180 | } |
| 10082 | 10181 | |
| 10083 | 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 | 10185 | Error err; |
| 10087 | | assert(wanted_type->id == TypeTableEntryIdUnion); |
| 10088 | | assert(target->value.type->id == TypeTableEntryIdEnum); |
| 10186 | assert(wanted_type->id == ZigTypeIdUnion); |
| 10187 | assert(target->value.type->id == ZigTypeIdEnum); |
| 10089 | 10188 | |
| 10090 | 10189 | if (instr_is_comptime(target)) { |
| 10091 | 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 | 10239 | } |
| 10141 | 10240 | |
| 10142 | 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 | 10246 | if (instr_is_comptime(target)) { |
| 10148 | 10247 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 10149 | 10248 | if (!val) |
| 10150 | 10249 | return ira->codegen->invalid_instruction; |
| 10151 | | if (wanted_type->id == TypeTableEntryIdInt) { |
| 10250 | if (wanted_type->id == ZigTypeIdInt) { |
| 10152 | 10251 | if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) { |
| 10153 | 10252 | ir_add_error(ira, source_instr, |
| 10154 | 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 | 10265 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, |
| 10167 | 10266 | source_instr->source_node, wanted_type); |
| 10168 | 10267 | result->value.type = wanted_type; |
| 10169 | | if (wanted_type->id == TypeTableEntryIdInt) { |
| 10268 | if (wanted_type->id == ZigTypeIdInt) { |
| 10170 | 10269 | bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint); |
| 10171 | 10270 | } else { |
| 10172 | 10271 | float_init_float(&result->value, val); |
| ... | ... | @@ -10181,12 +10280,12 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction |
| 10181 | 10280 | } |
| 10182 | 10281 | |
| 10183 | 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 | 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 | 10290 | if ((err = ensure_complete_type(ira->codegen, wanted_type))) |
| 10192 | 10291 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -10199,7 +10298,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 10199 | 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 | 10303 | if (instr_is_comptime(target)) { |
| 10205 | 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 | 10330 | } |
| 10232 | 10331 | |
| 10233 | 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 | 10335 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 10237 | 10336 | if (!val) |
| ... | ... | @@ -10239,9 +10338,9 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction |
| 10239 | 10338 | |
| 10240 | 10339 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, |
| 10241 | 10340 | source_instr->source_node, wanted_type); |
| 10242 | | if (wanted_type->id == TypeTableEntryIdComptimeFloat) { |
| 10341 | if (wanted_type->id == ZigTypeIdComptimeFloat) { |
| 10243 | 10342 | float_init_float(&result->value, val); |
| 10244 | | } else if (wanted_type->id == TypeTableEntryIdComptimeInt) { |
| 10343 | } else if (wanted_type->id == ZigTypeIdComptimeInt) { |
| 10245 | 10344 | bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint); |
| 10246 | 10345 | } else { |
| 10247 | 10346 | zig_unreachable(); |
| ... | ... | @@ -10250,11 +10349,11 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction |
| 10250 | 10349 | } |
| 10251 | 10350 | |
| 10252 | 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 | 10355 | assert(!target->value.type->data.integral.is_signed); |
| 10257 | | assert(wanted_type->id == TypeTableEntryIdErrorSet); |
| 10356 | assert(wanted_type->id == ZigTypeIdErrorSet); |
| 10258 | 10357 | |
| 10259 | 10358 | if (instr_is_comptime(target)) { |
| 10260 | 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 | 10414 | } |
| 10316 | 10415 | |
| 10317 | 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 | 10423 | if (instr_is_comptime(target)) { |
| 10325 | 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 | 10429 | source_instr->source_node, wanted_type); |
| 10331 | 10430 | |
| 10332 | 10431 | ErrorTableEntry *err; |
| 10333 | | if (err_type->id == TypeTableEntryIdErrorUnion) { |
| 10432 | if (err_type->id == ZigTypeIdErrorUnion) { |
| 10334 | 10433 | err = val->data.x_err_union.err; |
| 10335 | | } else if (err_type->id == TypeTableEntryIdErrorSet) { |
| 10434 | } else if (err_type->id == ZigTypeIdErrorSet) { |
| 10336 | 10435 | err = val->data.x_err_set; |
| 10337 | 10436 | } else { |
| 10338 | 10437 | zig_unreachable(); |
| ... | ... | @@ -10353,10 +10452,10 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 10353 | 10452 | return result; |
| 10354 | 10453 | } |
| 10355 | 10454 | |
| 10356 | | TypeTableEntry *err_set_type; |
| 10357 | | if (err_type->id == TypeTableEntryIdErrorUnion) { |
| 10455 | ZigType *err_set_type; |
| 10456 | if (err_type->id == ZigTypeIdErrorUnion) { |
| 10358 | 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 | 10459 | err_set_type = err_type; |
| 10361 | 10460 | } else { |
| 10362 | 10461 | zig_unreachable(); |
| ... | ... | @@ -10395,12 +10494,12 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 10395 | 10494 | } |
| 10396 | 10495 | |
| 10397 | 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 | 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; |
| 10403 | | assert(array_type->id == TypeTableEntryIdArray); |
| 10501 | ZigType *array_type = wanted_type->data.pointer.child_type; |
| 10502 | assert(array_type->id == ZigTypeIdArray); |
| 10404 | 10503 | assert(array_type->data.array.len == 1); |
| 10405 | 10504 | |
| 10406 | 10505 | if (instr_is_comptime(target)) { |
| ... | ... | @@ -10408,8 +10507,10 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 10408 | 10507 | if (!val) |
| 10409 | 10508 | return ira->codegen->invalid_instruction; |
| 10410 | 10509 | |
| 10411 | | assert(val->type->id == TypeTableEntryIdPointer); |
| 10412 | | ConstExprValue *pointee = const_ptr_pointee(ira->codegen, val); |
| 10510 | assert(val->type->id == ZigTypeIdPointer); |
| 10511 | ConstExprValue *pointee = ir_const_ptr_pointee(ira, val, source_instr->source_node); |
| 10512 | if (pointee == nullptr) |
| 10513 | return ira->codegen->invalid_instruction; |
| 10413 | 10514 | if (pointee->special != ConstValSpecialRuntime) { |
| 10414 | 10515 | ConstExprValue *array_val = create_const_vals(1); |
| 10415 | 10516 | array_val->special = ConstValSpecialStatic; |
| ... | ... | @@ -10529,10 +10630,10 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa |
| 10529 | 10630 | } |
| 10530 | 10631 | |
| 10531 | 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 | 10635 | Error err; |
| 10535 | | TypeTableEntry *actual_type = value->value.type; |
| 10636 | ZigType *actual_type = value->value.type; |
| 10536 | 10637 | AstNode *source_node = source_instr->source_node; |
| 10537 | 10638 | |
| 10538 | 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 | 10648 | } |
| 10548 | 10649 | |
| 10549 | 10650 | // widening conversion |
| 10550 | | if (wanted_type->id == TypeTableEntryIdInt && |
| 10551 | | actual_type->id == TypeTableEntryIdInt && |
| 10651 | if (wanted_type->id == ZigTypeIdInt && |
| 10652 | actual_type->id == ZigTypeIdInt && |
| 10552 | 10653 | wanted_type->data.integral.is_signed == actual_type->data.integral.is_signed && |
| 10553 | 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 | 10657 | } |
| 10557 | 10658 | |
| 10558 | 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 && |
| 10560 | | actual_type->id == TypeTableEntryIdInt && !actual_type->data.integral.is_signed && |
| 10660 | if (wanted_type->id == ZigTypeIdInt && wanted_type->data.integral.is_signed && |
| 10661 | actual_type->id == ZigTypeIdInt && !actual_type->data.integral.is_signed && |
| 10561 | 10662 | wanted_type->data.integral.bit_count > actual_type->data.integral.bit_count) |
| 10562 | 10663 | { |
| 10563 | 10664 | return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type); |
| 10564 | 10665 | } |
| 10565 | 10666 | |
| 10566 | 10667 | // float widening conversion |
| 10567 | | if (wanted_type->id == TypeTableEntryIdFloat && |
| 10568 | | actual_type->id == TypeTableEntryIdFloat && |
| 10668 | if (wanted_type->id == ZigTypeIdFloat && |
| 10669 | actual_type->id == ZigTypeIdFloat && |
| 10569 | 10670 | wanted_type->data.floating.bit_count >= actual_type->data.floating.bit_count) |
| 10570 | 10671 | { |
| 10571 | 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 | 10674 | |
| 10574 | 10675 | |
| 10575 | 10676 | // cast from [N]T to []const T |
| 10576 | | if (is_slice(wanted_type) && actual_type->id == TypeTableEntryIdArray) { |
| 10577 | | TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; |
| 10578 | | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 10677 | if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) { |
| 10678 | ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; |
| 10679 | assert(ptr_type->id == ZigTypeIdPointer); |
| 10579 | 10680 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 10580 | 10681 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, |
| 10581 | 10682 | source_node, false).id == ConstCastResultIdOk) |
| ... | ... | @@ -10586,14 +10687,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10586 | 10687 | |
| 10587 | 10688 | // cast from *const [N]T to []const T |
| 10588 | 10689 | if (is_slice(wanted_type) && |
| 10589 | | actual_type->id == TypeTableEntryIdPointer && |
| 10690 | actual_type->id == ZigTypeIdPointer && |
| 10590 | 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; |
| 10594 | | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 10694 | ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; |
| 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 | 10699 | if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && |
| 10599 | 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 | 10705 | } |
| 10605 | 10706 | |
| 10606 | 10707 | // cast from [N]T to *const []const T |
| 10607 | | if (wanted_type->id == TypeTableEntryIdPointer && |
| 10708 | if (wanted_type->id == ZigTypeIdPointer && |
| 10608 | 10709 | wanted_type->data.pointer.is_const && |
| 10609 | 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 | 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 | 10716 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 10616 | 10717 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, |
| 10617 | 10718 | source_node, false).id == ConstCastResultIdOk) |
| ... | ... | @@ -10629,13 +10730,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10629 | 10730 | } |
| 10630 | 10731 | |
| 10631 | 10732 | // cast from [N]T to ?[]const T |
| 10632 | | if (wanted_type->id == TypeTableEntryIdOptional && |
| 10733 | if (wanted_type->id == ZigTypeIdOptional && |
| 10633 | 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 | 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 | 10740 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 10640 | 10741 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, |
| 10641 | 10742 | source_node, false).id == ConstCastResultIdOk) |
| ... | ... | @@ -10653,11 +10754,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10653 | 10754 | } |
| 10654 | 10755 | |
| 10655 | 10756 | // *[N]T to [*]T |
| 10656 | | if (wanted_type->id == TypeTableEntryIdPointer && |
| 10757 | if (wanted_type->id == ZigTypeIdPointer && |
| 10657 | 10758 | wanted_type->data.pointer.ptr_len == PtrLenUnknown && |
| 10658 | | actual_type->id == TypeTableEntryIdPointer && |
| 10759 | actual_type->id == ZigTypeIdPointer && |
| 10659 | 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 | 10762 | actual_type->data.pointer.alignment >= wanted_type->data.pointer.alignment && |
| 10662 | 10763 | types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 10663 | 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 | 10769 | |
| 10669 | 10770 | // *[N]T to []T |
| 10670 | 10771 | if (is_slice(wanted_type) && |
| 10671 | | actual_type->id == TypeTableEntryIdPointer && |
| 10772 | actual_type->id == ZigTypeIdPointer && |
| 10672 | 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; |
| 10676 | | assert(slice_ptr_type->id == TypeTableEntryIdPointer); |
| 10776 | ZigType *slice_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; |
| 10777 | assert(slice_ptr_type->id == ZigTypeIdPointer); |
| 10677 | 10778 | if (types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type, |
| 10678 | 10779 | actual_type->data.pointer.child_type->data.array.child_type, source_node, |
| 10679 | 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 | 10786 | |
| 10686 | 10787 | // cast from T to ?T |
| 10687 | 10788 | // note that the *T to ?*T case is handled via the "ConstCastOnly" mechanism |
| 10688 | | if (wanted_type->id == TypeTableEntryIdOptional) { |
| 10689 | | TypeTableEntry *wanted_child_type = wanted_type->data.maybe.child_type; |
| 10789 | if (wanted_type->id == ZigTypeIdOptional) { |
| 10790 | ZigType *wanted_child_type = wanted_type->data.maybe.child_type; |
| 10690 | 10791 | if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, |
| 10691 | 10792 | false).id == ConstCastResultIdOk) |
| 10692 | 10793 | { |
| 10693 | 10794 | return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); |
| 10694 | | } else if (actual_type->id == TypeTableEntryIdComptimeInt || |
| 10695 | | actual_type->id == TypeTableEntryIdComptimeFloat) |
| 10795 | } else if (actual_type->id == ZigTypeIdComptimeInt || |
| 10796 | actual_type->id == ZigTypeIdComptimeFloat) |
| 10696 | 10797 | { |
| 10697 | 10798 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) { |
| 10698 | 10799 | return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); |
| 10699 | 10800 | } else { |
| 10700 | 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 | 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 | 10807 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_child_type, value); |
| 10707 | 10808 | if (type_is_invalid(cast1->value.type)) |
| ... | ... | @@ -10713,36 +10814,38 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10713 | 10814 | |
| 10714 | 10815 | return cast2; |
| 10715 | 10816 | } else if ( |
| 10716 | | wanted_child_type->id == TypeTableEntryIdPointer && |
| 10817 | wanted_child_type->id == ZigTypeIdPointer && |
| 10717 | 10818 | wanted_child_type->data.pointer.ptr_len == PtrLenUnknown && |
| 10718 | | actual_type->id == TypeTableEntryIdPointer && |
| 10819 | actual_type->id == ZigTypeIdPointer && |
| 10719 | 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 | 10822 | actual_type->data.pointer.alignment >= wanted_child_type->data.pointer.alignment && |
| 10722 | 10823 | types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type, |
| 10723 | 10824 | actual_type->data.pointer.child_type->data.array.child_type, source_node, |
| 10724 | 10825 | !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 10725 | 10826 | { |
| 10726 | 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 | 10830 | return ir_analyze_maybe_wrap(ira, source_instr, cast1, wanted_type); |
| 10728 | 10831 | } |
| 10729 | 10832 | } |
| 10730 | 10833 | |
| 10731 | 10834 | // cast from null literal to maybe type |
| 10732 | | if (wanted_type->id == TypeTableEntryIdOptional && |
| 10733 | | actual_type->id == TypeTableEntryIdNull) |
| 10835 | if (wanted_type->id == ZigTypeIdOptional && |
| 10836 | actual_type->id == ZigTypeIdNull) |
| 10734 | 10837 | { |
| 10735 | 10838 | return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type); |
| 10736 | 10839 | } |
| 10737 | 10840 | |
| 10738 | 10841 | // cast from child type of error type to error type |
| 10739 | | if (wanted_type->id == TypeTableEntryIdErrorUnion) { |
| 10842 | if (wanted_type->id == ZigTypeIdErrorUnion) { |
| 10740 | 10843 | if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type, |
| 10741 | 10844 | source_node, false).id == ConstCastResultIdOk) |
| 10742 | 10845 | { |
| 10743 | 10846 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); |
| 10744 | | } else if (actual_type->id == TypeTableEntryIdComptimeInt || |
| 10745 | | actual_type->id == TypeTableEntryIdComptimeFloat) |
| 10847 | } else if (actual_type->id == ZigTypeIdComptimeInt || |
| 10848 | actual_type->id == ZigTypeIdComptimeFloat) |
| 10746 | 10849 | { |
| 10747 | 10850 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) { |
| 10748 | 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 | 10856 | } |
| 10754 | 10857 | |
| 10755 | 10858 | // cast from [N]T to E![]const T |
| 10756 | | if (wanted_type->id == TypeTableEntryIdErrorUnion && |
| 10859 | if (wanted_type->id == ZigTypeIdErrorUnion && |
| 10757 | 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 | 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 | 10866 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 10764 | 10867 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, |
| 10765 | 10868 | source_node, false).id == ConstCastResultIdOk) |
| ... | ... | @@ -10777,22 +10880,22 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10777 | 10880 | } |
| 10778 | 10881 | |
| 10779 | 10882 | // cast from error set to error union type |
| 10780 | | if (wanted_type->id == TypeTableEntryIdErrorUnion && |
| 10781 | | actual_type->id == TypeTableEntryIdErrorSet) |
| 10883 | if (wanted_type->id == ZigTypeIdErrorUnion && |
| 10884 | actual_type->id == ZigTypeIdErrorSet) |
| 10782 | 10885 | { |
| 10783 | 10886 | return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type); |
| 10784 | 10887 | } |
| 10785 | 10888 | |
| 10786 | 10889 | // cast from T to E!?T |
| 10787 | | if (wanted_type->id == TypeTableEntryIdErrorUnion && |
| 10788 | | wanted_type->data.error_union.payload_type->id == TypeTableEntryIdOptional && |
| 10789 | | actual_type->id != TypeTableEntryIdOptional) |
| 10890 | if (wanted_type->id == ZigTypeIdErrorUnion && |
| 10891 | wanted_type->data.error_union.payload_type->id == ZigTypeIdOptional && |
| 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 | 10895 | if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, false).id == ConstCastResultIdOk || |
| 10793 | | actual_type->id == TypeTableEntryIdNull || |
| 10794 | | actual_type->id == TypeTableEntryIdComptimeInt || |
| 10795 | | actual_type->id == TypeTableEntryIdComptimeFloat) |
| 10896 | actual_type->id == ZigTypeIdNull || |
| 10897 | actual_type->id == ZigTypeIdComptimeInt || |
| 10898 | actual_type->id == ZigTypeIdComptimeFloat) |
| 10796 | 10899 | { |
| 10797 | 10900 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); |
| 10798 | 10901 | if (type_is_invalid(cast1->value.type)) |
| ... | ... | @@ -10808,12 +10911,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10808 | 10911 | |
| 10809 | 10912 | // cast from number literal to another type |
| 10810 | 10913 | // cast from number literal to *const integer |
| 10811 | | if (actual_type->id == TypeTableEntryIdComptimeFloat || |
| 10812 | | actual_type->id == TypeTableEntryIdComptimeInt) |
| 10914 | if (actual_type->id == ZigTypeIdComptimeFloat || |
| 10915 | actual_type->id == ZigTypeIdComptimeInt) |
| 10813 | 10916 | { |
| 10814 | 10917 | if ((err = ensure_complete_type(ira->codegen, wanted_type))) |
| 10815 | 10918 | return ira->codegen->invalid_instruction; |
| 10816 | | if (wanted_type->id == TypeTableEntryIdEnum) { |
| 10919 | if (wanted_type->id == ZigTypeIdEnum) { |
| 10817 | 10920 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value); |
| 10818 | 10921 | if (type_is_invalid(cast1->value.type)) |
| 10819 | 10922 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -10823,7 +10926,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10823 | 10926 | return ira->codegen->invalid_instruction; |
| 10824 | 10927 | |
| 10825 | 10928 | return cast2; |
| 10826 | | } else if (wanted_type->id == TypeTableEntryIdPointer && |
| 10929 | } else if (wanted_type->id == ZigTypeIdPointer && |
| 10827 | 10930 | wanted_type->data.pointer.is_const) |
| 10828 | 10931 | { |
| 10829 | 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 | 10940 | return cast2; |
| 10838 | 10941 | } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) { |
| 10839 | 10942 | CastOp op; |
| 10840 | | if ((actual_type->id == TypeTableEntryIdComptimeFloat && |
| 10841 | | wanted_type->id == TypeTableEntryIdFloat) || |
| 10842 | | (actual_type->id == TypeTableEntryIdComptimeInt && |
| 10843 | | wanted_type->id == TypeTableEntryIdInt)) |
| 10943 | if ((actual_type->id == ZigTypeIdComptimeFloat && |
| 10944 | wanted_type->id == ZigTypeIdFloat) || |
| 10945 | (actual_type->id == ZigTypeIdComptimeInt && |
| 10946 | wanted_type->id == ZigTypeIdInt)) |
| 10844 | 10947 | { |
| 10845 | 10948 | op = CastOpNumLitToConcrete; |
| 10846 | | } else if (wanted_type->id == TypeTableEntryIdInt) { |
| 10949 | } else if (wanted_type->id == ZigTypeIdInt) { |
| 10847 | 10950 | op = CastOpFloatToInt; |
| 10848 | | } else if (wanted_type->id == TypeTableEntryIdFloat) { |
| 10951 | } else if (wanted_type->id == ZigTypeIdFloat) { |
| 10849 | 10952 | op = CastOpIntToFloat; |
| 10850 | 10953 | } else { |
| 10851 | 10954 | zig_unreachable(); |
| ... | ... | @@ -10859,14 +10962,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10859 | 10962 | // cast from typed number to integer or float literal. |
| 10860 | 10963 | // works when the number is known at compile time |
| 10861 | 10964 | if (instr_is_comptime(value) && |
| 10862 | | ((actual_type->id == TypeTableEntryIdInt && wanted_type->id == TypeTableEntryIdComptimeInt) || |
| 10863 | | (actual_type->id == TypeTableEntryIdFloat && wanted_type->id == TypeTableEntryIdComptimeFloat))) |
| 10965 | ((actual_type->id == ZigTypeIdInt && wanted_type->id == ZigTypeIdComptimeInt) || |
| 10966 | (actual_type->id == ZigTypeIdFloat && wanted_type->id == ZigTypeIdComptimeFloat))) |
| 10864 | 10967 | { |
| 10865 | 10968 | return ir_analyze_number_to_literal(ira, source_instr, value, wanted_type); |
| 10866 | 10969 | } |
| 10867 | 10970 | |
| 10868 | 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 | 10973 | if ((err = type_ensure_zero_bits_known(ira->codegen, actual_type))) |
| 10871 | 10974 | return ira->codegen->invalid_instruction; |
| 10872 | 10975 | |
| ... | ... | @@ -10876,7 +10979,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10876 | 10979 | } |
| 10877 | 10980 | |
| 10878 | 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 | 10983 | (wanted_type->data.unionation.decl_node->data.container_decl.auto_enum || |
| 10881 | 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 | 10992 | } |
| 10890 | 10993 | |
| 10891 | 10994 | // enum to &const union which has the enum as the tag type |
| 10892 | | if (actual_type->id == TypeTableEntryIdEnum && wanted_type->id == TypeTableEntryIdPointer) { |
| 10893 | | TypeTableEntry *union_type = wanted_type->data.pointer.child_type; |
| 10995 | if (actual_type->id == ZigTypeIdEnum && wanted_type->id == ZigTypeIdPointer) { |
| 10996 | ZigType *union_type = wanted_type->data.pointer.child_type; |
| 10894 | 10997 | if (union_type->data.unionation.decl_node->data.container_decl.auto_enum || |
| 10895 | 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 | 11015 | } |
| 10913 | 11016 | |
| 10914 | 11017 | // cast from *T to *[1]T |
| 10915 | | if (wanted_type->id == TypeTableEntryIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle && |
| 10916 | | actual_type->id == TypeTableEntryIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle) |
| 11018 | if (wanted_type->id == ZigTypeIdPointer && wanted_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; |
| 10919 | | if (array_type->id == TypeTableEntryIdArray && array_type->data.array.len == 1 && |
| 11021 | ZigType *array_type = wanted_type->data.pointer.child_type; |
| 11022 | if (array_type->id == ZigTypeIdArray && array_type->data.array.len == 1 && |
| 10920 | 11023 | types_match_const_cast_only(ira, array_type->data.array.child_type, |
| 10921 | 11024 | actual_type->data.pointer.child_type, source_node, |
| 10922 | 11025 | !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| ... | ... | @@ -10936,7 +11039,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10936 | 11039 | } |
| 10937 | 11040 | |
| 10938 | 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 | 11043 | types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 10941 | 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 | 11053 | |
| 10951 | 11054 | |
| 10952 | 11055 | // cast from undefined to anything |
| 10953 | | if (actual_type->id == TypeTableEntryIdUndefined) { |
| 11056 | if (actual_type->id == ZigTypeIdUndefined) { |
| 10954 | 11057 | return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type); |
| 10955 | 11058 | } |
| 10956 | 11059 | |
| 10957 | 11060 | // cast from something to const pointer of it |
| 10958 | 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 | 11063 | if (types_match_const_cast_only(ira, wanted_type, const_ptr_actual, source_node, false).id == ConstCastResultIdOk) { |
| 10961 | 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 | 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 | 11077 | assert(value); |
| 10975 | 11078 | assert(value != ira->codegen->invalid_instruction); |
| 10976 | 11079 | assert(!expected_type || !type_is_invalid(expected_type)); |
| ... | ... | @@ -10980,23 +11083,25 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ |
| 10980 | 11083 | return value; // anything will do |
| 10981 | 11084 | if (expected_type == value->value.type) |
| 10982 | 11085 | return value; // match |
| 10983 | | if (value->value.type->id == TypeTableEntryIdUnreachable) |
| 11086 | if (value->value.type->id == ZigTypeIdUnreachable) |
| 10984 | 11087 | return value; |
| 10985 | 11088 | |
| 10986 | 11089 | return ir_analyze_cast(ira, value, expected_type, value); |
| 10987 | 11090 | } |
| 10988 | 11091 | |
| 10989 | 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 | 11094 | if (type_is_invalid(type_entry)) { |
| 10992 | 11095 | return ira->codegen->invalid_instruction; |
| 10993 | | } else if (type_entry->id == TypeTableEntryIdPointer) { |
| 10994 | | TypeTableEntry *child_type = type_entry->data.pointer.child_type; |
| 11096 | } else if (type_entry->id == ZigTypeIdPointer) { |
| 11097 | ZigType *child_type = type_entry->data.pointer.child_type; |
| 10995 | 11098 | if (instr_is_comptime(ptr)) { |
| 10996 | 11099 | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst || |
| 10997 | 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 | 11105 | if (pointee->special != ConstValSpecialRuntime) { |
| 11001 | 11106 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope, |
| 11002 | 11107 | source_instruction->source_node, child_type); |
| ... | ... | @@ -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 | 11128 | bool is_const, bool is_volatile) |
| 11024 | 11129 | { |
| 11025 | 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 | 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 | 11163 | if (type_is_invalid(value->value.type)) |
| 11059 | 11164 | return false; |
| 11060 | 11165 | |
| ... | ... | @@ -11103,8 +11208,8 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic |
| 11103 | 11208 | return false; |
| 11104 | 11209 | |
| 11105 | 11210 | ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder"); |
| 11106 | | assert(atomic_order_val->type->id == TypeTableEntryIdMetaType); |
| 11107 | | TypeTableEntry *atomic_order_type = atomic_order_val->data.x_type; |
| 11211 | assert(atomic_order_val->type->id == ZigTypeIdMetaType); |
| 11212 | ZigType *atomic_order_type = atomic_order_val->data.x_type; |
| 11108 | 11213 | |
| 11109 | 11214 | IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type); |
| 11110 | 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 | 11228 | return false; |
| 11124 | 11229 | |
| 11125 | 11230 | ConstExprValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp"); |
| 11126 | | assert(atomic_rmw_op_val->type->id == TypeTableEntryIdMetaType); |
| 11127 | | TypeTableEntry *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type; |
| 11231 | assert(atomic_rmw_op_val->type->id == ZigTypeIdMetaType); |
| 11232 | ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type; |
| 11128 | 11233 | |
| 11129 | 11234 | IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type); |
| 11130 | 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 | 11248 | return false; |
| 11144 | 11249 | |
| 11145 | 11250 | ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage"); |
| 11146 | | assert(global_linkage_val->type->id == TypeTableEntryIdMetaType); |
| 11147 | | TypeTableEntry *global_linkage_type = global_linkage_val->data.x_type; |
| 11251 | assert(global_linkage_val->type->id == ZigTypeIdMetaType); |
| 11252 | ZigType *global_linkage_type = global_linkage_val->data.x_type; |
| 11148 | 11253 | |
| 11149 | 11254 | IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type); |
| 11150 | 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 | 11268 | return false; |
| 11164 | 11269 | |
| 11165 | 11270 | ConstExprValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode"); |
| 11166 | | assert(float_mode_val->type->id == TypeTableEntryIdMetaType); |
| 11167 | | TypeTableEntry *float_mode_type = float_mode_val->data.x_type; |
| 11271 | assert(float_mode_val->type->id == ZigTypeIdMetaType); |
| 11272 | ZigType *float_mode_type = float_mode_val->data.x_type; |
| 11168 | 11273 | |
| 11169 | 11274 | IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type); |
| 11170 | 11275 | if (type_is_invalid(casted_value->value.type)) |
| ... | ... | @@ -11183,10 +11288,10 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 11183 | 11288 | if (type_is_invalid(value->value.type)) |
| 11184 | 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 | 11292 | true, false, PtrLenUnknown, |
| 11188 | 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 | 11295 | IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type); |
| 11191 | 11296 | if (type_is_invalid(casted_value->value.type)) |
| 11192 | 11297 | return nullptr; |
| ... | ... | @@ -11219,7 +11324,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 11219 | 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 | 11328 | IrInstructionAddImplicitReturnType *instruction) |
| 11224 | 11329 | { |
| 11225 | 11330 | IrInstruction *value = instruction->value->other; |
| ... | ... | @@ -11233,7 +11338,7 @@ static TypeTableEntry *ir_analyze_instruction_add_implicit_return_type(IrAnalyze |
| 11233 | 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 | 11342 | IrInstructionReturn *return_instruction) |
| 11238 | 11343 | { |
| 11239 | 11344 | IrInstruction *value = return_instruction->value->other; |
| ... | ... | @@ -11245,7 +11350,7 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira, |
| 11245 | 11350 | return ir_unreach_error(ira); |
| 11246 | 11351 | |
| 11247 | 11352 | if (casted_value->value.special == ConstValSpecialRuntime && |
| 11248 | | casted_value->value.type->id == TypeTableEntryIdPointer && |
| 11353 | casted_value->value.type->id == ZigTypeIdPointer && |
| 11249 | 11354 | casted_value->value.data.rh_ptr == RuntimeHintPtrStack) |
| 11250 | 11355 | { |
| 11251 | 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 | 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 | 11367 | ConstExprValue *out_val = ir_build_const_from(ira, &const_instruction->base); |
| 11263 | 11368 | *out_val = const_instruction->base.value; |
| 11264 | 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 | 11373 | IrInstruction *op1 = bin_op_instruction->op1->other; |
| 11269 | 11374 | if (type_is_invalid(op1->value.type)) |
| 11270 | 11375 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -11273,7 +11378,7 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp |
| 11273 | 11378 | if (type_is_invalid(op2->value.type)) |
| 11274 | 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 | 11383 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, bool_type); |
| 11279 | 11384 | if (casted_op1 == ira->codegen->invalid_instruction) |
| ... | ... | @@ -11293,8 +11398,8 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp |
| 11293 | 11398 | if (op2_val == nullptr) |
| 11294 | 11399 | return ira->codegen->builtin_types.entry_invalid; |
| 11295 | 11400 | |
| 11296 | | assert(casted_op1->value.type->id == TypeTableEntryIdBool); |
| 11297 | | assert(casted_op2->value.type->id == TypeTableEntryIdBool); |
| 11401 | assert(casted_op1->value.type->id == ZigTypeIdBool); |
| 11402 | assert(casted_op2->value.type->id == ZigTypeIdBool); |
| 11298 | 11403 | if (bin_op_instruction->op_id == IrBinOpBoolOr) { |
| 11299 | 11404 | out_val->data.x_bool = op1_val->data.x_bool || op2_val->data.x_bool; |
| 11300 | 11405 | } else if (bin_op_instruction->op_id == IrBinOpBoolAnd) { |
| ... | ... | @@ -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 | 11447 | Error err; |
| 11343 | 11448 | IrInstruction *op1 = bin_op_instruction->op1->other; |
| 11344 | 11449 | IrInstruction *op2 = bin_op_instruction->op2->other; |
| ... | ... | @@ -11347,19 +11452,19 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 11347 | 11452 | IrBinOp op_id = bin_op_instruction->op_id; |
| 11348 | 11453 | bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq); |
| 11349 | 11454 | if (is_equality_cmp && |
| 11350 | | ((op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdOptional) || |
| 11351 | | (op2->value.type->id == TypeTableEntryIdNull && op1->value.type->id == TypeTableEntryIdOptional) || |
| 11352 | | (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull))) |
| 11455 | ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdOptional) || |
| 11456 | (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdOptional) || |
| 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 | 11460 | ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base); |
| 11356 | 11461 | out_val->data.x_bool = (op_id == IrBinOpCmpEq); |
| 11357 | 11462 | return ira->codegen->builtin_types.entry_bool; |
| 11358 | 11463 | } |
| 11359 | 11464 | IrInstruction *maybe_op; |
| 11360 | | if (op1->value.type->id == TypeTableEntryIdNull) { |
| 11465 | if (op1->value.type->id == ZigTypeIdNull) { |
| 11361 | 11466 | maybe_op = op2; |
| 11362 | | } else if (op2->value.type->id == TypeTableEntryIdNull) { |
| 11467 | } else if (op2->value.type->id == ZigTypeIdNull) { |
| 11363 | 11468 | maybe_op = op1; |
| 11364 | 11469 | } else { |
| 11365 | 11470 | zig_unreachable(); |
| ... | ... | @@ -11386,12 +11491,12 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 11386 | 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 | 11495 | if (!is_equality_cmp) { |
| 11391 | 11496 | ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors")); |
| 11392 | 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 | 11500 | if (type_is_invalid(intersect_type)) { |
| 11396 | 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 | 11577 | } |
| 11473 | 11578 | |
| 11474 | 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 | 11581 | if (type_is_invalid(resolved_type)) |
| 11477 | 11582 | return resolved_type; |
| 11478 | 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 | 11585 | |
| 11481 | 11586 | bool operator_allowed; |
| 11482 | 11587 | switch (resolved_type->id) { |
| 11483 | | case TypeTableEntryIdInvalid: |
| 11588 | case ZigTypeIdInvalid: |
| 11484 | 11589 | zig_unreachable(); // handled above |
| 11485 | 11590 | |
| 11486 | | case TypeTableEntryIdComptimeFloat: |
| 11487 | | case TypeTableEntryIdComptimeInt: |
| 11488 | | case TypeTableEntryIdInt: |
| 11489 | | case TypeTableEntryIdFloat: |
| 11591 | case ZigTypeIdComptimeFloat: |
| 11592 | case ZigTypeIdComptimeInt: |
| 11593 | case ZigTypeIdInt: |
| 11594 | case ZigTypeIdFloat: |
| 11490 | 11595 | operator_allowed = true; |
| 11491 | 11596 | break; |
| 11492 | 11597 | |
| 11493 | | case TypeTableEntryIdBool: |
| 11494 | | case TypeTableEntryIdMetaType: |
| 11495 | | case TypeTableEntryIdVoid: |
| 11496 | | case TypeTableEntryIdPointer: |
| 11497 | | case TypeTableEntryIdErrorSet: |
| 11498 | | case TypeTableEntryIdFn: |
| 11499 | | case TypeTableEntryIdOpaque: |
| 11500 | | case TypeTableEntryIdNamespace: |
| 11501 | | case TypeTableEntryIdBlock: |
| 11502 | | case TypeTableEntryIdBoundFn: |
| 11503 | | case TypeTableEntryIdArgTuple: |
| 11504 | | case TypeTableEntryIdPromise: |
| 11505 | | case TypeTableEntryIdEnum: |
| 11598 | case ZigTypeIdBool: |
| 11599 | case ZigTypeIdMetaType: |
| 11600 | case ZigTypeIdVoid: |
| 11601 | case ZigTypeIdPointer: |
| 11602 | case ZigTypeIdErrorSet: |
| 11603 | case ZigTypeIdFn: |
| 11604 | case ZigTypeIdOpaque: |
| 11605 | case ZigTypeIdNamespace: |
| 11606 | case ZigTypeIdBlock: |
| 11607 | case ZigTypeIdBoundFn: |
| 11608 | case ZigTypeIdArgTuple: |
| 11609 | case ZigTypeIdPromise: |
| 11610 | case ZigTypeIdEnum: |
| 11506 | 11611 | operator_allowed = is_equality_cmp; |
| 11507 | 11612 | break; |
| 11508 | 11613 | |
| 11509 | | case TypeTableEntryIdUnreachable: |
| 11510 | | case TypeTableEntryIdArray: |
| 11511 | | case TypeTableEntryIdStruct: |
| 11512 | | case TypeTableEntryIdUndefined: |
| 11513 | | case TypeTableEntryIdNull: |
| 11514 | | case TypeTableEntryIdErrorUnion: |
| 11515 | | case TypeTableEntryIdUnion: |
| 11614 | case ZigTypeIdUnreachable: |
| 11615 | case ZigTypeIdArray: |
| 11616 | case ZigTypeIdStruct: |
| 11617 | case ZigTypeIdUndefined: |
| 11618 | case ZigTypeIdNull: |
| 11619 | case ZigTypeIdErrorUnion: |
| 11620 | case ZigTypeIdUnion: |
| 11516 | 11621 | operator_allowed = false; |
| 11517 | 11622 | break; |
| 11518 | | case TypeTableEntryIdOptional: |
| 11623 | case ZigTypeIdOptional: |
| 11519 | 11624 | operator_allowed = is_equality_cmp && get_codegen_ptr_type(resolved_type) != nullptr; |
| 11520 | 11625 | break; |
| 11521 | 11626 | } |
| ... | ... | @@ -11543,10 +11648,10 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 11543 | 11648 | return ira->codegen->builtin_types.entry_invalid; |
| 11544 | 11649 | |
| 11545 | 11650 | bool answer; |
| 11546 | | if (resolved_type->id == TypeTableEntryIdComptimeFloat || resolved_type->id == TypeTableEntryIdFloat) { |
| 11651 | if (resolved_type->id == ZigTypeIdComptimeFloat || resolved_type->id == ZigTypeIdFloat) { |
| 11547 | 11652 | Cmp cmp_result = float_cmp(op1_val, op2_val); |
| 11548 | 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 | 11655 | Cmp cmp_result = bigint_cmp(&op1_val->data.x_bigint, &op2_val->data.x_bigint); |
| 11551 | 11656 | answer = resolve_cmp_op_id(op_id, cmp_result); |
| 11552 | 11657 | } else { |
| ... | ... | @@ -11566,7 +11671,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 11566 | 11671 | } |
| 11567 | 11672 | |
| 11568 | 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 | 11675 | ConstExprValue *known_left_val; |
| 11571 | 11676 | IrBinOp flipped_op_id; |
| 11572 | 11677 | if (instr_is_comptime(casted_op1)) { |
| ... | ... | @@ -11610,18 +11715,18 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 11610 | 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 | 11719 | IrBinOp op_id, ConstExprValue *op2_val, ConstExprValue *out_val) |
| 11615 | 11720 | { |
| 11616 | 11721 | bool is_int; |
| 11617 | 11722 | bool is_float; |
| 11618 | 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 | 11725 | is_int = true; |
| 11621 | 11726 | is_float = false; |
| 11622 | 11727 | op2_zcmp = bigint_cmp_zero(&op2_val->data.x_bigint); |
| 11623 | | } else if (type_entry->id == TypeTableEntryIdFloat || |
| 11624 | | type_entry->id == TypeTableEntryIdComptimeFloat) |
| 11728 | } else if (type_entry->id == ZigTypeIdFloat || |
| 11729 | type_entry->id == ZigTypeIdComptimeFloat) |
| 11625 | 11730 | { |
| 11626 | 11731 | is_int = false; |
| 11627 | 11732 | is_float = true; |
| ... | ... | @@ -11671,7 +11776,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, |
| 11671 | 11776 | bigint_shl(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint); |
| 11672 | 11777 | break; |
| 11673 | 11778 | case IrBinOpBitShiftLeftLossy: |
| 11674 | | assert(type_entry->id == TypeTableEntryIdInt); |
| 11779 | assert(type_entry->id == ZigTypeIdInt); |
| 11675 | 11780 | bigint_shl_trunc(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint, |
| 11676 | 11781 | type_entry->data.integral.bit_count, type_entry->data.integral.is_signed); |
| 11677 | 11782 | break; |
| ... | ... | @@ -11698,7 +11803,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, |
| 11698 | 11803 | } |
| 11699 | 11804 | break; |
| 11700 | 11805 | case IrBinOpAddWrap: |
| 11701 | | assert(type_entry->id == TypeTableEntryIdInt); |
| 11806 | assert(type_entry->id == ZigTypeIdInt); |
| 11702 | 11807 | bigint_add_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint, |
| 11703 | 11808 | type_entry->data.integral.bit_count, type_entry->data.integral.is_signed); |
| 11704 | 11809 | break; |
| ... | ... | @@ -11710,7 +11815,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, |
| 11710 | 11815 | } |
| 11711 | 11816 | break; |
| 11712 | 11817 | case IrBinOpSubWrap: |
| 11713 | | assert(type_entry->id == TypeTableEntryIdInt); |
| 11818 | assert(type_entry->id == ZigTypeIdInt); |
| 11714 | 11819 | bigint_sub_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint, |
| 11715 | 11820 | type_entry->data.integral.bit_count, type_entry->data.integral.is_signed); |
| 11716 | 11821 | break; |
| ... | ... | @@ -11722,7 +11827,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, |
| 11722 | 11827 | } |
| 11723 | 11828 | break; |
| 11724 | 11829 | case IrBinOpMultWrap: |
| 11725 | | assert(type_entry->id == TypeTableEntryIdInt); |
| 11830 | assert(type_entry->id == ZigTypeIdInt); |
| 11726 | 11831 | bigint_mul_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint, |
| 11727 | 11832 | type_entry->data.integral.bit_count, type_entry->data.integral.is_signed); |
| 11728 | 11833 | break; |
| ... | ... | @@ -11777,7 +11882,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, |
| 11777 | 11882 | break; |
| 11778 | 11883 | } |
| 11779 | 11884 | |
| 11780 | | if (type_entry->id == TypeTableEntryIdInt) { |
| 11885 | if (type_entry->id == ZigTypeIdInt) { |
| 11781 | 11886 | if (!bigint_fits_in_bits(&out_val->data.x_bigint, type_entry->data.integral.bit_count, |
| 11782 | 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 | 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 | 11899 | IrInstruction *op1 = bin_op_instruction->op1->other; |
| 11795 | 11900 | if (type_is_invalid(op1->value.type)) |
| 11796 | 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 | 11904 | ir_add_error(ira, &bin_op_instruction->base, |
| 11800 | 11905 | buf_sprintf("bit shifting operation expected integer type, found '%s'", |
| 11801 | 11906 | buf_ptr(&op1->value.type->name))); |
| ... | ... | @@ -11808,7 +11913,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp * |
| 11808 | 11913 | |
| 11809 | 11914 | IrInstruction *casted_op2; |
| 11810 | 11915 | IrBinOp op_id = bin_op_instruction->op_id; |
| 11811 | | if (op1->value.type->id == TypeTableEntryIdComptimeInt) { |
| 11916 | if (op1->value.type->id == ZigTypeIdComptimeInt) { |
| 11812 | 11917 | casted_op2 = op2; |
| 11813 | 11918 | |
| 11814 | 11919 | if (op_id == IrBinOpBitShiftLeftLossy) { |
| ... | ... | @@ -11822,10 +11927,10 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp * |
| 11822 | 11927 | return ira->codegen->builtin_types.entry_invalid; |
| 11823 | 11928 | } |
| 11824 | 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 | 11931 | op1->value.type->data.integral.bit_count - 1); |
| 11827 | 11932 | if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy && |
| 11828 | | op2->value.type->id == TypeTableEntryIdComptimeInt) { |
| 11933 | op2->value.type->id == ZigTypeIdComptimeInt) { |
| 11829 | 11934 | if (!bigint_fits_in_bits(&op2->value.data.x_bigint, |
| 11830 | 11935 | shift_amt_type->data.integral.bit_count, |
| 11831 | 11936 | op2->value.data.x_bigint.is_negative)) { |
| ... | ... | @@ -11879,7 +11984,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp * |
| 11879 | 11984 | |
| 11880 | 11985 | ir_num_lit_fits_in_other_type(ira, result_instruction, op1->value.type, false); |
| 11881 | 11986 | return op1->value.type; |
| 11882 | | } else if (op1->value.type->id == TypeTableEntryIdComptimeInt) { |
| 11987 | } else if (op1->value.type->id == ZigTypeIdComptimeInt) { |
| 11883 | 11988 | ir_add_error(ira, &bin_op_instruction->base, |
| 11884 | 11989 | buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known")); |
| 11885 | 11990 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -11890,7 +11995,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp * |
| 11890 | 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 | 11999 | IrInstruction *op1 = bin_op_instruction->op1->other; |
| 11895 | 12000 | if (type_is_invalid(op1->value.type)) |
| 11896 | 12001 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -11902,7 +12007,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 11902 | 12007 | IrBinOp op_id = bin_op_instruction->op_id; |
| 11903 | 12008 | |
| 11904 | 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 | 12011 | (op_id == IrBinOpAdd || op_id == IrBinOpSub)) |
| 11907 | 12012 | { |
| 11908 | 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 | 12022 | } |
| 11918 | 12023 | |
| 11919 | 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 | 12026 | if (type_is_invalid(resolved_type)) |
| 11922 | 12027 | return resolved_type; |
| 11923 | 12028 | |
| 11924 | | bool is_int = resolved_type->id == TypeTableEntryIdInt || resolved_type->id == TypeTableEntryIdComptimeInt; |
| 11925 | | bool is_float = resolved_type->id == TypeTableEntryIdFloat || resolved_type->id == TypeTableEntryIdComptimeFloat; |
| 12029 | bool is_int = resolved_type->id == ZigTypeIdInt || resolved_type->id == ZigTypeIdComptimeInt; |
| 12030 | bool is_float = resolved_type->id == ZigTypeIdFloat || resolved_type->id == ZigTypeIdComptimeFloat; |
| 11926 | 12031 | bool is_signed_div = ( |
| 11927 | | (resolved_type->id == TypeTableEntryIdInt && resolved_type->data.integral.is_signed) || |
| 11928 | | resolved_type->id == TypeTableEntryIdFloat || |
| 11929 | | (resolved_type->id == TypeTableEntryIdComptimeFloat && |
| 12032 | (resolved_type->id == ZigTypeIdInt && resolved_type->data.integral.is_signed) || |
| 12033 | resolved_type->id == ZigTypeIdFloat || |
| 12034 | (resolved_type->id == ZigTypeIdComptimeFloat && |
| 11930 | 12035 | ((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) != |
| 11931 | 12036 | (bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) || |
| 11932 | | (resolved_type->id == TypeTableEntryIdComptimeInt && |
| 12037 | (resolved_type->id == ZigTypeIdComptimeInt && |
| 11933 | 12038 | ((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) != |
| 11934 | 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 | 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 | 12160 | if (op_id == IrBinOpAddWrap) { |
| 12056 | 12161 | op_id = IrBinOpAdd; |
| 12057 | 12162 | } else if (op_id == IrBinOpSubWrap) { |
| ... | ... | @@ -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 | 12220 | IrInstruction *op1 = instruction->op1->other; |
| 12116 | | TypeTableEntry *op1_type = op1->value.type; |
| 12221 | ZigType *op1_type = op1->value.type; |
| 12117 | 12222 | if (type_is_invalid(op1_type)) |
| 12118 | 12223 | return ira->codegen->builtin_types.entry_invalid; |
| 12119 | 12224 | |
| 12120 | 12225 | IrInstruction *op2 = instruction->op2->other; |
| 12121 | | TypeTableEntry *op2_type = op2->value.type; |
| 12226 | ZigType *op2_type = op2->value.type; |
| 12122 | 12227 | if (type_is_invalid(op2_type)) |
| 12123 | 12228 | return ira->codegen->builtin_types.entry_invalid; |
| 12124 | 12229 | |
| ... | ... | @@ -12133,13 +12238,13 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 12133 | 12238 | ConstExprValue *op1_array_val; |
| 12134 | 12239 | size_t op1_array_index; |
| 12135 | 12240 | size_t op1_array_end; |
| 12136 | | TypeTableEntry *child_type; |
| 12137 | | if (op1_type->id == TypeTableEntryIdArray) { |
| 12241 | ZigType *child_type; |
| 12242 | if (op1_type->id == ZigTypeIdArray) { |
| 12138 | 12243 | child_type = op1_type->data.array.child_type; |
| 12139 | 12244 | op1_array_val = op1_val; |
| 12140 | 12245 | op1_array_index = 0; |
| 12141 | 12246 | op1_array_end = op1_type->data.array.len; |
| 12142 | | } else if (op1_type->id == TypeTableEntryIdPointer && |
| 12247 | } else if (op1_type->id == ZigTypeIdPointer && |
| 12143 | 12248 | op1_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 && |
| 12144 | 12249 | op1_val->data.x_ptr.special == ConstPtrSpecialBaseArray && |
| 12145 | 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 | 12254 | op1_array_index = op1_val->data.x_ptr.data.base_array.elem_index; |
| 12150 | 12255 | op1_array_end = op1_array_val->type->data.array.len - 1; |
| 12151 | 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 | 12258 | child_type = ptr_type->data.pointer.child_type; |
| 12154 | 12259 | ConstExprValue *ptr_val = &op1_val->data.x_struct.fields[slice_ptr_index]; |
| 12155 | 12260 | assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray); |
| ... | ... | @@ -12165,7 +12270,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 12165 | 12270 | ConstExprValue *op2_array_val; |
| 12166 | 12271 | size_t op2_array_index; |
| 12167 | 12272 | size_t op2_array_end; |
| 12168 | | if (op2_type->id == TypeTableEntryIdArray) { |
| 12273 | if (op2_type->id == ZigTypeIdArray) { |
| 12169 | 12274 | if (op2_type->data.array.child_type != child_type) { |
| 12170 | 12275 | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", |
| 12171 | 12276 | buf_ptr(&child_type->name), |
| ... | ... | @@ -12175,7 +12280,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 12175 | 12280 | op2_array_val = op2_val; |
| 12176 | 12281 | op2_array_index = 0; |
| 12177 | 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 | 12284 | op2_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 && |
| 12180 | 12285 | op2_val->data.x_ptr.special == ConstPtrSpecialBaseArray && |
| 12181 | 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 | 12295 | op2_array_index = op2_val->data.x_ptr.data.base_array.elem_index; |
| 12191 | 12296 | op2_array_end = op2_array_val->type->data.array.len - 1; |
| 12192 | 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 | 12299 | if (ptr_type->data.pointer.child_type != child_type) { |
| 12195 | 12300 | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", |
| 12196 | 12301 | buf_ptr(&child_type->name), |
| ... | ... | @@ -12210,15 +12315,15 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 12210 | 12315 | |
| 12211 | 12316 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 12212 | 12317 | |
| 12213 | | TypeTableEntry *result_type; |
| 12318 | ZigType *result_type; |
| 12214 | 12319 | ConstExprValue *out_array_val; |
| 12215 | 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 | 12322 | result_type = get_array_type(ira->codegen, child_type, new_len); |
| 12218 | 12323 | |
| 12219 | 12324 | out_array_val = out_val; |
| 12220 | 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 | 12327 | true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, child_type), 0, 0); |
| 12223 | 12328 | result_type = get_slice_type(ira->codegen, ptr_type); |
| 12224 | 12329 | out_array_val = create_const_vals(1); |
| ... | ... | @@ -12279,7 +12384,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 12279 | 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 | 12388 | IrInstruction *op1 = instruction->op1->other; |
| 12284 | 12389 | if (type_is_invalid(op1->value.type)) |
| 12285 | 12390 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -12296,8 +12401,8 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp |
| 12296 | 12401 | if (!ir_resolve_usize(ira, op2, &mult_amt)) |
| 12297 | 12402 | return ira->codegen->builtin_types.entry_invalid; |
| 12298 | 12403 | |
| 12299 | | TypeTableEntry *array_type = op1->value.type; |
| 12300 | | if (array_type->id != TypeTableEntryIdArray) { |
| 12404 | ZigType *array_type = op1->value.type; |
| 12405 | if (array_type->id != ZigTypeIdArray) { |
| 12301 | 12406 | ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name))); |
| 12302 | 12407 | return ira->codegen->builtin_types.entry_invalid; |
| 12303 | 12408 | } |
| ... | ... | @@ -12315,7 +12420,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp |
| 12315 | 12420 | if (array_val->data.x_array.special == ConstArraySpecialUndef) { |
| 12316 | 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 | 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 | 12435 | } |
| 12331 | 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 | 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) { |
| 12338 | | TypeTableEntry *op1_type = ir_resolve_type(ira, instruction->op1->other); |
| 12442 | static ZigType *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 12443 | ZigType *op1_type = ir_resolve_type(ira, instruction->op1->other); |
| 12339 | 12444 | if (type_is_invalid(op1_type)) |
| 12340 | 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 | 12448 | if (type_is_invalid(op2_type)) |
| 12344 | 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 | 12470 | assert(errors[error_entry->value] == nullptr); |
| 12366 | 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 | 12474 | free(errors); |
| 12370 | 12475 | |
| 12371 | 12476 | |
| ... | ... | @@ -12374,7 +12479,7 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction |
| 12374 | 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 | 12483 | IrBinOp op_id = bin_op_instruction->op_id; |
| 12379 | 12484 | switch (op_id) { |
| 12380 | 12485 | case IrBinOpInvalid: |
| ... | ... | @@ -12421,9 +12526,9 @@ static TypeTableEntry *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructi |
| 12421 | 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 | 12530 | Error err; |
| 12426 | | VariableTableEntry *var = decl_var_instruction->var; |
| 12531 | ZigVar *var = decl_var_instruction->var; |
| 12427 | 12532 | |
| 12428 | 12533 | IrInstruction *init_value = decl_var_instruction->init_value->other; |
| 12429 | 12534 | if (type_is_invalid(init_value->value.type)) { |
| ... | ... | @@ -12431,11 +12536,11 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 12431 | 12536 | return var->value->type; |
| 12432 | 12537 | } |
| 12433 | 12538 | |
| 12434 | | TypeTableEntry *explicit_type = nullptr; |
| 12539 | ZigType *explicit_type = nullptr; |
| 12435 | 12540 | IrInstruction *var_type = nullptr; |
| 12436 | 12541 | if (decl_var_instruction->var_type != nullptr) { |
| 12437 | 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 | 12544 | explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type); |
| 12440 | 12545 | if (type_is_invalid(explicit_type)) { |
| 12441 | 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 | 12555 | |
| 12451 | 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 | 12559 | if (type_is_invalid(result_type)) { |
| 12455 | 12560 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 12456 | 12561 | } else { |
| ... | ... | @@ -12460,8 +12565,8 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 12460 | 12565 | } |
| 12461 | 12566 | |
| 12462 | 12567 | if (!type_is_invalid(result_type)) { |
| 12463 | | if (result_type->id == TypeTableEntryIdUnreachable || |
| 12464 | | result_type->id == TypeTableEntryIdOpaque) |
| 12568 | if (result_type->id == ZigTypeIdUnreachable || |
| 12569 | result_type->id == ZigTypeIdOpaque) |
| 12465 | 12570 | { |
| 12466 | 12571 | ir_add_error_node(ira, source_node, |
| 12467 | 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 | 12581 | } |
| 12477 | 12582 | } else { |
| 12478 | 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 | 12585 | casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways) |
| 12481 | 12586 | { |
| 12482 | 12587 | var_class_requires_const = true; |
| ... | ... | @@ -12496,7 +12601,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 12496 | 12601 | // This means that this is actually a different variable due to, e.g. an inline while loop. |
| 12497 | 12602 | // We make a new variable so that it can hold a different type, and so the debug info can |
| 12498 | 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 | 12605 | &var->name, var->src_is_const, var->gen_is_const, var->shadowable, var->is_comptime, true); |
| 12501 | 12606 | new_var->owner_exec = var->owner_exec; |
| 12502 | 12607 | new_var->align_bytes = var->align_bytes; |
| ... | ... | @@ -12549,14 +12654,14 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 12549 | 12654 | |
| 12550 | 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 | 12658 | if (fn_entry) |
| 12554 | 12659 | fn_entry->variable_list.append(var); |
| 12555 | 12660 | |
| 12556 | 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 | 12665 | IrInstruction *name = instruction->name->other; |
| 12561 | 12666 | Buf *symbol_name = ir_resolve_str(ira, name); |
| 12562 | 12667 | if (symbol_name == nullptr) { |
| ... | ... | @@ -12585,12 +12690,12 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi |
| 12585 | 12690 | } |
| 12586 | 12691 | |
| 12587 | 12692 | switch (target->value.type->id) { |
| 12588 | | case TypeTableEntryIdInvalid: |
| 12589 | | case TypeTableEntryIdUnreachable: |
| 12693 | case ZigTypeIdInvalid: |
| 12694 | case ZigTypeIdUnreachable: |
| 12590 | 12695 | zig_unreachable(); |
| 12591 | | case TypeTableEntryIdFn: { |
| 12696 | case ZigTypeIdFn: { |
| 12592 | 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 | 12699 | CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc; |
| 12595 | 12700 | switch (cc) { |
| 12596 | 12701 | case CallingConventionUnspecified: { |
| ... | ... | @@ -12611,7 +12716,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi |
| 12611 | 12716 | break; |
| 12612 | 12717 | } |
| 12613 | 12718 | } break; |
| 12614 | | case TypeTableEntryIdStruct: |
| 12719 | case ZigTypeIdStruct: |
| 12615 | 12720 | if (is_slice(target->value.type)) { |
| 12616 | 12721 | ir_add_error(ira, target, |
| 12617 | 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 | 12726 | add_error_note(ira->codegen, msg, target->value.type->data.structure.decl_node, buf_sprintf("declared here")); |
| 12622 | 12727 | } |
| 12623 | 12728 | break; |
| 12624 | | case TypeTableEntryIdUnion: |
| 12729 | case ZigTypeIdUnion: |
| 12625 | 12730 | if (target->value.type->data.unionation.layout != ContainerLayoutExtern) { |
| 12626 | 12731 | ErrorMsg *msg = ir_add_error(ira, target, |
| 12627 | 12732 | buf_sprintf("exported union value must be declared extern")); |
| 12628 | 12733 | add_error_note(ira->codegen, msg, target->value.type->data.unionation.decl_node, buf_sprintf("declared here")); |
| 12629 | 12734 | } |
| 12630 | 12735 | break; |
| 12631 | | case TypeTableEntryIdEnum: |
| 12736 | case ZigTypeIdEnum: |
| 12632 | 12737 | if (target->value.type->data.enumeration.layout != ContainerLayoutExtern) { |
| 12633 | 12738 | ErrorMsg *msg = ir_add_error(ira, target, |
| 12634 | 12739 | buf_sprintf("exported enum value must be declared extern")); |
| 12635 | 12740 | add_error_note(ira->codegen, msg, target->value.type->data.enumeration.decl_node, buf_sprintf("declared here")); |
| 12636 | 12741 | } |
| 12637 | 12742 | break; |
| 12638 | | case TypeTableEntryIdMetaType: { |
| 12639 | | TypeTableEntry *type_value = target->value.data.x_type; |
| 12743 | case ZigTypeIdMetaType: { |
| 12744 | ZigType *type_value = target->value.data.x_type; |
| 12640 | 12745 | switch (type_value->id) { |
| 12641 | | case TypeTableEntryIdInvalid: |
| 12746 | case ZigTypeIdInvalid: |
| 12642 | 12747 | zig_unreachable(); |
| 12643 | | case TypeTableEntryIdStruct: |
| 12748 | case ZigTypeIdStruct: |
| 12644 | 12749 | if (is_slice(type_value)) { |
| 12645 | 12750 | ir_add_error(ira, target, |
| 12646 | 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 | 12755 | add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here")); |
| 12651 | 12756 | } |
| 12652 | 12757 | break; |
| 12653 | | case TypeTableEntryIdUnion: |
| 12758 | case ZigTypeIdUnion: |
| 12654 | 12759 | if (type_value->data.unionation.layout != ContainerLayoutExtern) { |
| 12655 | 12760 | ErrorMsg *msg = ir_add_error(ira, target, |
| 12656 | 12761 | buf_sprintf("exported union must be declared extern")); |
| 12657 | 12762 | add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here")); |
| 12658 | 12763 | } |
| 12659 | 12764 | break; |
| 12660 | | case TypeTableEntryIdEnum: |
| 12765 | case ZigTypeIdEnum: |
| 12661 | 12766 | if (type_value->data.enumeration.layout != ContainerLayoutExtern) { |
| 12662 | 12767 | ErrorMsg *msg = ir_add_error(ira, target, |
| 12663 | 12768 | buf_sprintf("exported enum must be declared extern")); |
| 12664 | 12769 | add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here")); |
| 12665 | 12770 | } |
| 12666 | 12771 | break; |
| 12667 | | case TypeTableEntryIdFn: { |
| 12772 | case ZigTypeIdFn: { |
| 12668 | 12773 | if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) { |
| 12669 | 12774 | ir_add_error(ira, target, |
| 12670 | 12775 | buf_sprintf("exported function type must specify calling convention")); |
| 12671 | 12776 | } |
| 12672 | 12777 | } break; |
| 12673 | | case TypeTableEntryIdInt: |
| 12674 | | case TypeTableEntryIdFloat: |
| 12675 | | case TypeTableEntryIdPointer: |
| 12676 | | case TypeTableEntryIdArray: |
| 12677 | | case TypeTableEntryIdBool: |
| 12778 | case ZigTypeIdInt: |
| 12779 | case ZigTypeIdFloat: |
| 12780 | case ZigTypeIdPointer: |
| 12781 | case ZigTypeIdArray: |
| 12782 | case ZigTypeIdBool: |
| 12678 | 12783 | break; |
| 12679 | | case TypeTableEntryIdMetaType: |
| 12680 | | case TypeTableEntryIdVoid: |
| 12681 | | case TypeTableEntryIdUnreachable: |
| 12682 | | case TypeTableEntryIdComptimeFloat: |
| 12683 | | case TypeTableEntryIdComptimeInt: |
| 12684 | | case TypeTableEntryIdUndefined: |
| 12685 | | case TypeTableEntryIdNull: |
| 12686 | | case TypeTableEntryIdOptional: |
| 12687 | | case TypeTableEntryIdErrorUnion: |
| 12688 | | case TypeTableEntryIdErrorSet: |
| 12689 | | case TypeTableEntryIdNamespace: |
| 12690 | | case TypeTableEntryIdBlock: |
| 12691 | | case TypeTableEntryIdBoundFn: |
| 12692 | | case TypeTableEntryIdArgTuple: |
| 12693 | | case TypeTableEntryIdOpaque: |
| 12694 | | case TypeTableEntryIdPromise: |
| 12784 | case ZigTypeIdMetaType: |
| 12785 | case ZigTypeIdVoid: |
| 12786 | case ZigTypeIdUnreachable: |
| 12787 | case ZigTypeIdComptimeFloat: |
| 12788 | case ZigTypeIdComptimeInt: |
| 12789 | case ZigTypeIdUndefined: |
| 12790 | case ZigTypeIdNull: |
| 12791 | case ZigTypeIdOptional: |
| 12792 | case ZigTypeIdErrorUnion: |
| 12793 | case ZigTypeIdErrorSet: |
| 12794 | case ZigTypeIdNamespace: |
| 12795 | case ZigTypeIdBlock: |
| 12796 | case ZigTypeIdBoundFn: |
| 12797 | case ZigTypeIdArgTuple: |
| 12798 | case ZigTypeIdOpaque: |
| 12799 | case ZigTypeIdPromise: |
| 12695 | 12800 | ir_add_error(ira, target, |
| 12696 | 12801 | buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name))); |
| 12697 | 12802 | break; |
| 12698 | 12803 | } |
| 12699 | 12804 | } break; |
| 12700 | | case TypeTableEntryIdVoid: |
| 12701 | | case TypeTableEntryIdBool: |
| 12702 | | case TypeTableEntryIdInt: |
| 12703 | | case TypeTableEntryIdFloat: |
| 12704 | | case TypeTableEntryIdPointer: |
| 12705 | | case TypeTableEntryIdArray: |
| 12706 | | case TypeTableEntryIdComptimeFloat: |
| 12707 | | case TypeTableEntryIdComptimeInt: |
| 12708 | | case TypeTableEntryIdUndefined: |
| 12709 | | case TypeTableEntryIdNull: |
| 12710 | | case TypeTableEntryIdOptional: |
| 12711 | | case TypeTableEntryIdErrorUnion: |
| 12712 | | case TypeTableEntryIdErrorSet: |
| 12805 | case ZigTypeIdVoid: |
| 12806 | case ZigTypeIdBool: |
| 12807 | case ZigTypeIdInt: |
| 12808 | case ZigTypeIdFloat: |
| 12809 | case ZigTypeIdPointer: |
| 12810 | case ZigTypeIdArray: |
| 12811 | case ZigTypeIdComptimeFloat: |
| 12812 | case ZigTypeIdComptimeInt: |
| 12813 | case ZigTypeIdUndefined: |
| 12814 | case ZigTypeIdNull: |
| 12815 | case ZigTypeIdOptional: |
| 12816 | case ZigTypeIdErrorUnion: |
| 12817 | case ZigTypeIdErrorSet: |
| 12713 | 12818 | zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name)); |
| 12714 | | case TypeTableEntryIdNamespace: |
| 12715 | | case TypeTableEntryIdBlock: |
| 12716 | | case TypeTableEntryIdBoundFn: |
| 12717 | | case TypeTableEntryIdArgTuple: |
| 12718 | | case TypeTableEntryIdOpaque: |
| 12719 | | case TypeTableEntryIdPromise: |
| 12819 | case ZigTypeIdNamespace: |
| 12820 | case ZigTypeIdBlock: |
| 12821 | case ZigTypeIdBoundFn: |
| 12822 | case ZigTypeIdArgTuple: |
| 12823 | case ZigTypeIdOpaque: |
| 12824 | case ZigTypeIdPromise: |
| 12720 | 12825 | ir_add_error(ira, target, |
| 12721 | 12826 | buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name))); |
| 12722 | 12827 | break; |
| ... | ... | @@ -12727,16 +12832,16 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi |
| 12727 | 12832 | } |
| 12728 | 12833 | |
| 12729 | 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 | 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 | 12840 | IrInstructionErrorReturnTrace *instruction) |
| 12736 | 12841 | { |
| 12737 | 12842 | if (instruction->optional == IrInstructionErrorReturnTrace::Null) { |
| 12738 | | TypeTableEntry *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); |
| 12843 | ZigType *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(ira->codegen); |
| 12844 | ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type); |
| 12740 | 12845 | if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) { |
| 12741 | 12846 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 12742 | 12847 | assert(get_codegen_ptr_type(optional_type) != nullptr); |
| ... | ... | @@ -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 | 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 | 12869 | if (type_is_invalid(err_set_type)) |
| 12765 | 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 | 12873 | if (type_is_invalid(payload_type)) |
| 12769 | 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 | 12877 | ir_add_error(ira, instruction->err_set->other, |
| 12773 | 12878 | buf_sprintf("expected error set type, found type '%s'", |
| 12774 | 12879 | buf_ptr(&err_set_type->name))); |
| 12775 | 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 | 12885 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 12781 | 12886 | out_val->data.x_type = result_type; |
| ... | ... | @@ -12783,7 +12888,7 @@ static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira, |
| 12783 | 12888 | } |
| 12784 | 12889 | |
| 12785 | 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 | 12892 | if (parent_fn_entry == nullptr) { |
| 12788 | 12893 | ir_add_error(ira, source_instr, buf_sprintf("no implicit allocator available")); |
| 12789 | 12894 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -12807,7 +12912,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i |
| 12807 | 12912 | } |
| 12808 | 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 | 12916 | assert(coro_allocator_var != nullptr); |
| 12812 | 12917 | IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var); |
| 12813 | 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 | 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 | 12927 | IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, IrInstruction *async_allocator_inst) |
| 12823 | 12928 | { |
| 12824 | 12929 | Buf *alloc_field_name = buf_create_from_str(ASYNC_ALLOC_FIELD_NAME); |
| 12825 | 12930 | //Buf *free_field_name = buf_create_from_str("freeFn"); |
| 12826 | | assert(async_allocator_inst->value.type->id == TypeTableEntryIdPointer); |
| 12827 | | TypeTableEntry *container_type = async_allocator_inst->value.type->data.pointer.child_type; |
| 12931 | assert(async_allocator_inst->value.type->id == ZigTypeIdPointer); |
| 12932 | ZigType *container_type = async_allocator_inst->value.type->data.pointer.child_type; |
| 12828 | 12933 | IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, alloc_field_name, &call_instruction->base, |
| 12829 | 12934 | async_allocator_inst, container_type); |
| 12830 | 12935 | if (type_is_invalid(field_ptr_inst->value.type)) { |
| 12831 | 12936 | return ira->codegen->invalid_instruction; |
| 12832 | 12937 | } |
| 12833 | | TypeTableEntry *ptr_to_alloc_fn_type = field_ptr_inst->value.type; |
| 12834 | | assert(ptr_to_alloc_fn_type->id == TypeTableEntryIdPointer); |
| 12938 | ZigType *ptr_to_alloc_fn_type = field_ptr_inst->value.type; |
| 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; |
| 12837 | | if (alloc_fn_type->id != TypeTableEntryIdFn) { |
| 12941 | ZigType *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type; |
| 12942 | if (alloc_fn_type->id != ZigTypeIdFn) { |
| 12838 | 12943 | ir_add_error(ira, &call_instruction->base, |
| 12839 | 12944 | buf_sprintf("expected allocation function, found '%s'", buf_ptr(&alloc_fn_type->name))); |
| 12840 | 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; |
| 12844 | | if (alloc_fn_return_type->id != TypeTableEntryIdErrorUnion) { |
| 12948 | ZigType *alloc_fn_return_type = alloc_fn_type->data.fn.fn_type_id.return_type; |
| 12949 | if (alloc_fn_return_type->id != ZigTypeIdErrorUnion) { |
| 12845 | 12950 | ir_add_error(ira, fn_ref, |
| 12846 | 12951 | buf_sprintf("expected allocation function to return error union, but it returns '%s'", buf_ptr(&alloc_fn_return_type->name))); |
| 12847 | 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; |
| 12850 | | TypeTableEntry *return_type = fn_type->data.fn.fn_type_id.return_type; |
| 12851 | | TypeTableEntry *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); |
| 12954 | ZigType *alloc_fn_error_set_type = alloc_fn_return_type->data.error_union.err_set_type; |
| 12955 | ZigType *return_type = fn_type->data.fn.fn_type_id.return_type; |
| 12956 | ZigType *promise_type = get_promise_type(ira->codegen, return_type); |
| 12957 | ZigType *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type); |
| 12853 | 12958 | |
| 12854 | 12959 | IrInstruction *result = ir_build_call(&ira->new_irb, call_instruction->base.scope, call_instruction->base.source_node, |
| 12855 | 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 | 12971 | IrInstruction *casted_arg; |
| 12867 | 12972 | if (param_decl_node->data.param_decl.var_token == nullptr) { |
| 12868 | 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 | 12975 | if (type_is_invalid(param_type)) |
| 12871 | 12976 | return false; |
| 12872 | 12977 | |
| ... | ... | @@ -12882,7 +12987,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node |
| 12882 | 12987 | return false; |
| 12883 | 12988 | |
| 12884 | 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 | 12991 | *exec_scope, param_name, true, arg_val, nullptr); |
| 12887 | 12992 | *exec_scope = var->child_scope; |
| 12888 | 12993 | *next_proto_i += 1; |
| ... | ... | @@ -12893,7 +12998,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node |
| 12893 | 12998 | static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node, |
| 12894 | 12999 | IrInstruction *arg, Scope **child_scope, size_t *next_proto_i, |
| 12895 | 13000 | GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstruction **casted_args, |
| 12896 | | FnTableEntry *impl_fn) |
| 13001 | ZigFn *impl_fn) |
| 12897 | 13002 | { |
| 12898 | 13003 | AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i); |
| 12899 | 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 | 13011 | } else { |
| 12907 | 13012 | if (param_decl_node->data.param_decl.var_token == nullptr) { |
| 12908 | 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 | 13015 | if (type_is_invalid(param_type)) |
| 12911 | 13016 | return false; |
| 12912 | 13017 | |
| ... | ... | @@ -12920,7 +13025,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 12920 | 13025 | } |
| 12921 | 13026 | |
| 12922 | 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 | 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 | 13045 | Buf *param_name = param_decl_node->data.param_decl.name; |
| 12941 | 13046 | if (!param_name) return false; |
| 12942 | 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 | 13049 | *child_scope, param_name, true, arg_val, nullptr); |
| 12945 | 13050 | *child_scope = var->child_scope; |
| 12946 | 13051 | var->shadowable = !comptime_arg; |
| 12947 | 13052 | |
| 12948 | 13053 | *next_proto_i += 1; |
| 12949 | | } else if (casted_arg->value.type->id == TypeTableEntryIdComptimeInt || |
| 12950 | | casted_arg->value.type->id == TypeTableEntryIdComptimeFloat) |
| 13054 | } else if (casted_arg->value.type->id == ZigTypeIdComptimeInt || |
| 13055 | casted_arg->value.type->id == ZigTypeIdComptimeFloat) |
| 12951 | 13056 | { |
| 12952 | 13057 | ir_add_error(ira, casted_arg, |
| 12953 | 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 | 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 | 13081 | size_t next_var_i = 0; |
| 12977 | 13082 | FnGenParamInfo *gen_param_info = fn_entry->type_entry->data.fn.gen_param_info; |
| 12978 | 13083 | assert(gen_param_info != nullptr); |
| ... | ... | @@ -12991,7 +13096,7 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in |
| 12991 | 13096 | } |
| 12992 | 13097 | |
| 12993 | 13098 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 12994 | | VariableTableEntry *var) |
| 13099 | ZigVar *var) |
| 12995 | 13100 | { |
| 12996 | 13101 | Error err; |
| 12997 | 13102 | while (var->next_var != nullptr) { |
| ... | ... | @@ -13002,8 +13107,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 13002 | 13107 | assert(ira->codegen->errors.length != 0); |
| 13003 | 13108 | return ira->codegen->invalid_instruction; |
| 13004 | 13109 | } |
| 13005 | | assert(var->value->type); |
| 13006 | | if (type_is_invalid(var->value->type)) |
| 13110 | if (var->value->type == nullptr || type_is_invalid(var->value->type)) |
| 13007 | 13111 | return ira->codegen->invalid_instruction; |
| 13008 | 13112 | |
| 13009 | 13113 | bool comptime_var_mem = ir_get_var_is_comptime(var); |
| ... | ... | @@ -13061,8 +13165,8 @@ no_mem_slot: |
| 13061 | 13165 | return var_ptr_instruction; |
| 13062 | 13166 | } |
| 13063 | 13167 | |
| 13064 | | static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction, |
| 13065 | | FnTableEntry *fn_entry, TypeTableEntry *fn_type, IrInstruction *fn_ref, |
| 13168 | static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction, |
| 13169 | ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref, |
| 13066 | 13170 | IrInstruction *first_arg_ptr, bool comptime_fn_call, FnInline fn_inline) |
| 13067 | 13171 | { |
| 13068 | 13172 | Error err; |
| ... | ... | @@ -13082,7 +13186,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13082 | 13186 | size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0; |
| 13083 | 13187 | for (size_t i = 0; i < call_instruction->arg_count; i += 1) { |
| 13084 | 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 | 13190 | call_param_count -= 1; |
| 13087 | 13191 | call_param_count += arg_tuple_value->data.x_arg_tuple.end_index - |
| 13088 | 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 | 13254 | |
| 13151 | 13255 | size_t next_proto_i = 0; |
| 13152 | 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 | 13259 | bool first_arg_known_bare = false; |
| 13156 | 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 | 13262 | if (type_is_invalid(param_type)) |
| 13159 | 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 | 13267 | IrInstruction *first_arg; |
| ... | ... | @@ -13190,11 +13294,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13190 | 13294 | } |
| 13191 | 13295 | |
| 13192 | 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 | 13298 | if (type_is_invalid(specified_return_type)) |
| 13195 | 13299 | return ira->codegen->builtin_types.entry_invalid; |
| 13196 | | TypeTableEntry *return_type; |
| 13197 | | TypeTableEntry *inferred_err_set_type = nullptr; |
| 13300 | ZigType *return_type; |
| 13301 | ZigType *inferred_err_set_type = nullptr; |
| 13198 | 13302 | if (fn_proto_node->data.fn_proto.auto_err_set) { |
| 13199 | 13303 | inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry); |
| 13200 | 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 | 13323 | |
| 13220 | 13324 | if (inferred_err_set_type != nullptr) { |
| 13221 | 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 | 13327 | if (result->value.data.x_err_union.err != nullptr) { |
| 13224 | 13328 | inferred_err_set_type->data.error_set.err_count = 1; |
| 13225 | 13329 | inferred_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(1); |
| 13226 | 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 | 13333 | inferred_err_set_type->data.error_set.err_count = fn_inferred_err_set_type->data.error_set.err_count; |
| 13230 | 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 | 13336 | inferred_err_set_type->data.error_set.err_count = result->value.type->data.error_set.err_count; |
| 13233 | 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 | 13353 | |
| 13250 | 13354 | IrInstruction *casted_new_stack = nullptr; |
| 13251 | 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 | 13357 | false, false, PtrLenUnknown, |
| 13254 | 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 | 13360 | IrInstruction *new_stack = call_instruction->new_stack->other; |
| 13257 | 13361 | if (type_is_invalid(new_stack->value.type)) |
| 13258 | 13362 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -13276,7 +13380,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13276 | 13380 | if (type_is_invalid(arg->value.type)) |
| 13277 | 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 | 13384 | new_fn_arg_count += arg->value.data.x_arg_tuple.end_index - arg->value.data.x_arg_tuple.start_index; |
| 13281 | 13385 | } else { |
| 13282 | 13386 | new_fn_arg_count += 1; |
| ... | ... | @@ -13287,7 +13391,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13287 | 13391 | |
| 13288 | 13392 | // Fork a scope of the function with known values for the parameters. |
| 13289 | 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 | 13395 | impl_fn->param_source_nodes = allocate<AstNode *>(new_fn_arg_count); |
| 13292 | 13396 | buf_init_from_buf(&impl_fn->symbol_name, &fn_entry->symbol_name); |
| 13293 | 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 | 13410 | size_t next_proto_i = 0; |
| 13307 | 13411 | |
| 13308 | 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 | 13415 | bool first_arg_known_bare = false; |
| 13312 | 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 | 13418 | if (type_is_invalid(param_type)) |
| 13315 | 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 | 13423 | IrInstruction *first_arg; |
| ... | ... | @@ -13335,14 +13439,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13335 | 13439 | bool found_first_var_arg = false; |
| 13336 | 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 | 13443 | assert(parent_fn_entry); |
| 13340 | 13444 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 13341 | 13445 | IrInstruction *arg = call_instruction->args[call_i]->other; |
| 13342 | 13446 | if (type_is_invalid(arg->value.type)) |
| 13343 | 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 | 13450 | for (size_t arg_tuple_i = arg->value.data.x_arg_tuple.start_index; |
| 13347 | 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 | 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 | 13462 | if (arg_var == nullptr) { |
| 13359 | 13463 | ir_add_error(ira, arg, |
| 13360 | 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 | 13505 | |
| 13402 | 13506 | ConstExprValue *var_args_val = create_const_arg_tuple(ira->codegen, |
| 13403 | 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 | 13509 | impl_fn->child_scope, param_name, true, var_args_val, nullptr); |
| 13406 | 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 | 13524 | |
| 13421 | 13525 | if (fn_proto_node->data.fn_proto.return_var_token == nullptr) { |
| 13422 | 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 | 13528 | if (type_is_invalid(specified_return_type)) |
| 13425 | 13529 | return ira->codegen->builtin_types.entry_invalid; |
| 13426 | 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 | 13532 | inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type); |
| 13429 | 13533 | } else { |
| 13430 | 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 | 13546 | if (call_instruction->is_async) { |
| 13443 | 13547 | AstNode *async_allocator_type_node = fn_proto_node->data.fn_proto.async_allocator_type; |
| 13444 | 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 | 13550 | if (type_is_invalid(async_allocator_type)) |
| 13447 | 13551 | return ira->codegen->builtin_types.entry_invalid; |
| 13448 | 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 | 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 | 13594 | if (fn_type_can_fail(&impl_fn->type_entry->data.fn.fn_type_id)) { |
| 13491 | 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 | 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 | 13618 | assert(fn_type_id->return_type != nullptr); |
| 13515 | 13619 | assert(parent_fn_entry != nullptr); |
| 13516 | 13620 | if (fn_type_can_fail(fn_type_id)) { |
| ... | ... | @@ -13521,14 +13625,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13521 | 13625 | IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count); |
| 13522 | 13626 | size_t next_arg_index = 0; |
| 13523 | 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 | 13631 | if (type_is_invalid(param_type)) |
| 13528 | 13632 | return ira->codegen->builtin_types.entry_invalid; |
| 13529 | 13633 | |
| 13530 | 13634 | IrInstruction *first_arg; |
| 13531 | | if (param_type->id == TypeTableEntryIdPointer && |
| 13635 | if (param_type->id == ZigTypeIdPointer && |
| 13532 | 13636 | handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) |
| 13533 | 13637 | { |
| 13534 | 13638 | first_arg = first_arg_ptr; |
| ... | ... | @@ -13551,7 +13655,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 13551 | 13655 | return ira->codegen->builtin_types.entry_invalid; |
| 13552 | 13656 | IrInstruction *casted_arg; |
| 13553 | 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 | 13659 | if (type_is_invalid(param_type)) |
| 13556 | 13660 | return ira->codegen->builtin_types.entry_invalid; |
| 13557 | 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 | 13671 | |
| 13568 | 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 | 13675 | if (type_is_invalid(return_type)) |
| 13572 | 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 | 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 | 13708 | IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base, |
| 13600 | 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 | 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 | 13716 | IrInstruction *fn_ref = call_instruction->fn_ref->other; |
| 13608 | 13717 | if (type_is_invalid(fn_ref->value.type)) |
| 13609 | 13718 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -13612,8 +13721,8 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction |
| 13612 | 13721 | ir_should_inline(ira->new_irb.exec, call_instruction->base.scope); |
| 13613 | 13722 | |
| 13614 | 13723 | if (is_comptime || instr_is_comptime(fn_ref)) { |
| 13615 | | if (fn_ref->value.type->id == TypeTableEntryIdMetaType) { |
| 13616 | | TypeTableEntry *dest_type = ir_resolve_type(ira, fn_ref); |
| 13724 | if (fn_ref->value.type->id == ZigTypeIdMetaType) { |
| 13725 | ZigType *dest_type = ir_resolve_type(ira, fn_ref); |
| 13617 | 13726 | if (type_is_invalid(dest_type)) |
| 13618 | 13727 | return ira->codegen->builtin_types.entry_invalid; |
| 13619 | 13728 | |
| ... | ... | @@ -13633,15 +13742,15 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction |
| 13633 | 13742 | |
| 13634 | 13743 | ir_link_new_instruction(cast_instruction, &call_instruction->base); |
| 13635 | 13744 | return ir_finish_anal(ira, cast_instruction->value.type); |
| 13636 | | } else if (fn_ref->value.type->id == TypeTableEntryIdFn) { |
| 13637 | | FnTableEntry *fn_table_entry = ir_resolve_fn(ira, fn_ref); |
| 13745 | } else if (fn_ref->value.type->id == ZigTypeIdFn) { |
| 13746 | ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref); |
| 13638 | 13747 | if (fn_table_entry == nullptr) |
| 13639 | 13748 | return ira->codegen->builtin_types.entry_invalid; |
| 13640 | 13749 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, |
| 13641 | 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 | 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 | 13754 | IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg; |
| 13646 | 13755 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, |
| 13647 | 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 | 13761 | } |
| 13653 | 13762 | } |
| 13654 | 13763 | |
| 13655 | | if (fn_ref->value.type->id == TypeTableEntryIdFn) { |
| 13764 | if (fn_ref->value.type->id == ZigTypeIdFn) { |
| 13656 | 13765 | return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type, |
| 13657 | 13766 | fn_ref, nullptr, false, FnInlineAuto); |
| 13658 | 13767 | } else { |
| ... | ... | @@ -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 | 13807 | IrInstruction *value = un_op_instruction->value->other; |
| 13667 | 13808 | |
| 13668 | | TypeTableEntry *ptr_type = value->value.type; |
| 13669 | | TypeTableEntry *child_type; |
| 13809 | ZigType *ptr_type = value->value.type; |
| 13810 | ZigType *child_type; |
| 13670 | 13811 | if (type_is_invalid(ptr_type)) { |
| 13671 | 13812 | return ira->codegen->builtin_types.entry_invalid; |
| 13672 | | } else if (ptr_type->id == TypeTableEntryIdPointer) { |
| 13813 | } else if (ptr_type->id == ZigTypeIdPointer) { |
| 13673 | 13814 | if (ptr_type->data.pointer.ptr_len == PtrLenUnknown) { |
| 13674 | 13815 | ir_add_error_node(ira, un_op_instruction->base.source_node, |
| 13675 | 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 | 13833 | if (comptime_value == nullptr) |
| 13693 | 13834 | return ira->codegen->builtin_types.entry_invalid; |
| 13694 | 13835 | |
| 13695 | | ConstExprValue *pointee = const_ptr_pointee(ira->codegen, comptime_value); |
| 13696 | | if (pointee->type == child_type) { |
| 13697 | | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base); |
| 13698 | | copy_const_val(out_val, pointee, value->value.data.x_ptr.mut == ConstPtrMutComptimeConst); |
| 13699 | | return child_type; |
| 13700 | | } |
| 13836 | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base); |
| 13837 | out_val->type = child_type; |
| 13838 | if ((err = ir_read_const_ptr(ira, un_op_instruction->base.source_node, out_val, comptime_value))) |
| 13839 | return ira->codegen->builtin_types.entry_invalid; |
| 13840 | return child_type; |
| 13701 | 13841 | } |
| 13702 | 13842 | |
| 13703 | 13843 | ir_build_load_ptr_from(&ira->new_irb, &un_op_instruction->base, value); |
| 13704 | 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 | 13848 | Error err; |
| 13709 | 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 | 13851 | if (type_is_invalid(type_entry)) |
| 13712 | 13852 | return ira->codegen->builtin_types.entry_invalid; |
| 13713 | 13853 | if ((err = ensure_complete_type(ira->codegen, type_entry))) |
| 13714 | 13854 | return ira->codegen->builtin_types.entry_invalid; |
| 13715 | 13855 | |
| 13716 | 13856 | switch (type_entry->id) { |
| 13717 | | case TypeTableEntryIdInvalid: |
| 13857 | case ZigTypeIdInvalid: |
| 13718 | 13858 | zig_unreachable(); |
| 13719 | | case TypeTableEntryIdMetaType: |
| 13720 | | case TypeTableEntryIdVoid: |
| 13721 | | case TypeTableEntryIdBool: |
| 13722 | | case TypeTableEntryIdInt: |
| 13723 | | case TypeTableEntryIdFloat: |
| 13724 | | case TypeTableEntryIdPointer: |
| 13725 | | case TypeTableEntryIdArray: |
| 13726 | | case TypeTableEntryIdStruct: |
| 13727 | | case TypeTableEntryIdComptimeFloat: |
| 13728 | | case TypeTableEntryIdComptimeInt: |
| 13729 | | case TypeTableEntryIdUndefined: |
| 13730 | | case TypeTableEntryIdNull: |
| 13731 | | case TypeTableEntryIdOptional: |
| 13732 | | case TypeTableEntryIdErrorUnion: |
| 13733 | | case TypeTableEntryIdErrorSet: |
| 13734 | | case TypeTableEntryIdEnum: |
| 13735 | | case TypeTableEntryIdUnion: |
| 13736 | | case TypeTableEntryIdFn: |
| 13737 | | case TypeTableEntryIdNamespace: |
| 13738 | | case TypeTableEntryIdBlock: |
| 13739 | | case TypeTableEntryIdBoundFn: |
| 13740 | | case TypeTableEntryIdArgTuple: |
| 13741 | | case TypeTableEntryIdPromise: |
| 13859 | case ZigTypeIdMetaType: |
| 13860 | case ZigTypeIdVoid: |
| 13861 | case ZigTypeIdBool: |
| 13862 | case ZigTypeIdInt: |
| 13863 | case ZigTypeIdFloat: |
| 13864 | case ZigTypeIdPointer: |
| 13865 | case ZigTypeIdArray: |
| 13866 | case ZigTypeIdStruct: |
| 13867 | case ZigTypeIdComptimeFloat: |
| 13868 | case ZigTypeIdComptimeInt: |
| 13869 | case ZigTypeIdUndefined: |
| 13870 | case ZigTypeIdNull: |
| 13871 | case ZigTypeIdOptional: |
| 13872 | case ZigTypeIdErrorUnion: |
| 13873 | case ZigTypeIdErrorSet: |
| 13874 | case ZigTypeIdEnum: |
| 13875 | case ZigTypeIdUnion: |
| 13876 | case ZigTypeIdFn: |
| 13877 | case ZigTypeIdNamespace: |
| 13878 | case ZigTypeIdBlock: |
| 13879 | case ZigTypeIdBoundFn: |
| 13880 | case ZigTypeIdArgTuple: |
| 13881 | case ZigTypeIdPromise: |
| 13742 | 13882 | { |
| 13743 | 13883 | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base); |
| 13744 | 13884 | out_val->data.x_type = get_optional_type(ira->codegen, type_entry); |
| 13745 | 13885 | return ira->codegen->builtin_types.entry_type; |
| 13746 | 13886 | } |
| 13747 | | case TypeTableEntryIdUnreachable: |
| 13748 | | case TypeTableEntryIdOpaque: |
| 13887 | case ZigTypeIdUnreachable: |
| 13888 | case ZigTypeIdOpaque: |
| 13749 | 13889 | ir_add_error_node(ira, un_op_instruction->base.source_node, |
| 13750 | 13890 | buf_sprintf("type '%s' not optional", buf_ptr(&type_entry->name))); |
| 13751 | 13891 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -13753,18 +13893,18 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op |
| 13753 | 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 | 13897 | IrInstruction *value = un_op_instruction->value->other; |
| 13758 | | TypeTableEntry *expr_type = value->value.type; |
| 13898 | ZigType *expr_type = value->value.type; |
| 13759 | 13899 | if (type_is_invalid(expr_type)) |
| 13760 | 13900 | return ira->codegen->builtin_types.entry_invalid; |
| 13761 | 13901 | |
| 13762 | 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) || |
| 13767 | | expr_type->id == TypeTableEntryIdComptimeInt || (is_float && !is_wrap_op)) |
| 13906 | if ((expr_type->id == ZigTypeIdInt && expr_type->data.integral.is_signed) || |
| 13907 | expr_type->id == ZigTypeIdComptimeInt || (is_float && !is_wrap_op)) |
| 13768 | 13908 | { |
| 13769 | 13909 | if (instr_is_comptime(value)) { |
| 13770 | 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 | 13920 | } else { |
| 13781 | 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 | 13924 | return expr_type; |
| 13785 | 13925 | } |
| 13786 | 13926 | |
| ... | ... | @@ -13800,13 +13940,13 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un |
| 13800 | 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 | 13944 | IrInstruction *value = instruction->value->other; |
| 13805 | | TypeTableEntry *expr_type = value->value.type; |
| 13945 | ZigType *expr_type = value->value.type; |
| 13806 | 13946 | if (type_is_invalid(expr_type)) |
| 13807 | 13947 | return ira->codegen->builtin_types.entry_invalid; |
| 13808 | 13948 | |
| 13809 | | if (expr_type->id == TypeTableEntryIdInt) { |
| 13949 | if (expr_type->id == ZigTypeIdInt) { |
| 13810 | 13950 | if (instr_is_comptime(value)) { |
| 13811 | 13951 | ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad); |
| 13812 | 13952 | if (target_const_val == nullptr) |
| ... | ... | @@ -13827,7 +13967,7 @@ static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *ins |
| 13827 | 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 | 13971 | IrUnOp op_id = un_op_instruction->op_id; |
| 13832 | 13972 | switch (op_id) { |
| 13833 | 13973 | case IrUnOpInvalid: |
| ... | ... | @@ -13845,7 +13985,7 @@ static TypeTableEntry *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructio |
| 13845 | 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 | 13989 | IrBasicBlock *old_dest_block = br_instruction->dest_block; |
| 13850 | 13990 | |
| 13851 | 13991 | bool is_comptime; |
| ... | ... | @@ -13855,21 +13995,15 @@ static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr |
| 13855 | 13995 | if (is_comptime || old_dest_block->ref_count == 1) |
| 13856 | 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); |
| 13859 | | |
| 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")); |
| 13998 | IrBasicBlock *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base); |
| 13999 | if (new_bb == nullptr) |
| 13865 | 14000 | return ir_unreach_error(ira); |
| 13866 | | } |
| 13867 | 14001 | |
| 13868 | 14002 | ir_build_br_from(&ira->new_irb, &br_instruction->base, new_bb); |
| 13869 | 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 | 14007 | IrInstruction *condition = cond_br_instruction->condition->other; |
| 13874 | 14008 | if (type_is_invalid(condition->value.type)) |
| 13875 | 14009 | return ir_unreach_error(ira); |
| ... | ... | @@ -13889,32 +14023,41 @@ static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstruct |
| 13889 | 14023 | if (is_comptime || old_dest_block->ref_count == 1) |
| 13890 | 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 | 14030 | ir_build_br_from(&ira->new_irb, &cond_br_instruction->base, new_dest_block); |
| 13894 | 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 | 14035 | IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type); |
| 13899 | 14036 | if (casted_condition == ira->codegen->invalid_instruction) |
| 13900 | 14037 | return ir_unreach_error(ira); |
| 13901 | 14038 | |
| 13902 | 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); |
| 13904 | | IrBasicBlock *new_else_block = ir_get_new_bb(ira, cond_br_instruction->else_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); |
| 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 | 14048 | ir_build_cond_br_from(&ira->new_irb, &cond_br_instruction->base, |
| 13906 | 14049 | casted_condition, new_then_block, new_else_block, nullptr); |
| 13907 | 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 | 14054 | IrInstructionUnreachable *unreachable_instruction) |
| 13912 | 14055 | { |
| 13913 | 14056 | ir_build_unreachable_from(&ira->new_irb, &unreachable_instruction->base); |
| 13914 | 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 | 14061 | if (ira->const_predecessor_bb) { |
| 13919 | 14062 | for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) { |
| 13920 | 14063 | IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i]; |
| ... | ... | @@ -13948,7 +14091,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP |
| 13948 | 14091 | IrInstruction *old_value = phi_instruction->incoming_values[i]; |
| 13949 | 14092 | assert(old_value); |
| 13950 | 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 | 14095 | continue; |
| 13953 | 14096 | |
| 13954 | 14097 | if (type_is_invalid(new_value->value.type)) |
| ... | ... | @@ -13971,22 +14114,22 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP |
| 13971 | 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 | 14118 | new_incoming_values.items, new_incoming_values.length); |
| 13976 | 14119 | if (type_is_invalid(resolved_type)) |
| 13977 | 14120 | return resolved_type; |
| 13978 | 14121 | |
| 13979 | | if (resolved_type->id == TypeTableEntryIdComptimeFloat || |
| 13980 | | resolved_type->id == TypeTableEntryIdComptimeInt || |
| 13981 | | resolved_type->id == TypeTableEntryIdNull || |
| 13982 | | resolved_type->id == TypeTableEntryIdUndefined) |
| 14122 | if (resolved_type->id == ZigTypeIdComptimeFloat || |
| 14123 | resolved_type->id == ZigTypeIdComptimeInt || |
| 14124 | resolved_type->id == ZigTypeIdNull || |
| 14125 | resolved_type->id == ZigTypeIdUndefined) |
| 13983 | 14126 | { |
| 13984 | 14127 | ir_add_error_node(ira, phi_instruction->base.source_node, |
| 13985 | 14128 | buf_sprintf("unable to infer expression type")); |
| 13986 | 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 | 14134 | // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction. |
| 13992 | 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 | 14166 | return resolved_type; |
| 14024 | 14167 | } |
| 14025 | 14168 | |
| 14026 | | static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 14027 | | VariableTableEntry *var) |
| 14028 | | { |
| 14169 | static ZigType *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var) { |
| 14029 | 14170 | IrInstruction *result = ir_get_var_ptr(ira, instruction, var); |
| 14030 | 14171 | ir_link_new_instruction(result, instruction); |
| 14031 | 14172 | return result->value.type; |
| 14032 | 14173 | } |
| 14033 | 14174 | |
| 14034 | | static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) { |
| 14035 | | VariableTableEntry *var = var_ptr_instruction->var; |
| 14036 | | return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var); |
| 14175 | static ZigType *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *instruction) { |
| 14176 | ZigVar *var = instruction->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) { |
| 14040 | | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 14191 | static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align) { |
| 14192 | assert(ptr_type->id == ZigTypeIdPointer); |
| 14041 | 14193 | return get_pointer_to_type_extra(g, |
| 14042 | 14194 | ptr_type->data.pointer.child_type, |
| 14043 | 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 | 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 | 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 | 14204 | new_align); |
| 14053 | 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) { |
| 14057 | | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 14208 | static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) { |
| 14209 | assert(ptr_type->id == ZigTypeIdPointer); |
| 14058 | 14210 | return get_pointer_to_type_extra(g, |
| 14059 | 14211 | ptr_type->data.pointer.child_type, |
| 14060 | 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 | 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 | 14219 | Error err; |
| 14068 | 14220 | IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->other; |
| 14069 | 14221 | if (type_is_invalid(array_ptr->value.type)) |
| ... | ... | @@ -14075,27 +14227,30 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14075 | 14227 | if (type_is_invalid(elem_index->value.type)) |
| 14076 | 14228 | return ira->codegen->builtin_types.entry_invalid; |
| 14077 | 14229 | |
| 14078 | | TypeTableEntry *ptr_type = orig_array_ptr_val->type; |
| 14079 | | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 14230 | ZigType *ptr_type = orig_array_ptr_val->type; |
| 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 | 14235 | // At first return_type will be the pointer type we want to return, except with an optimistic alignment. |
| 14084 | 14236 | // We will adjust return_type's alignment before returning it. |
| 14085 | | TypeTableEntry *return_type; |
| 14237 | ZigType *return_type; |
| 14086 | 14238 | |
| 14087 | 14239 | if (type_is_invalid(array_type)) { |
| 14088 | 14240 | return array_type; |
| 14089 | | } else if (array_type->id == TypeTableEntryIdArray || |
| 14090 | | (array_type->id == TypeTableEntryIdPointer && |
| 14241 | } else if (array_type->id == ZigTypeIdArray || |
| 14242 | (array_type->id == ZigTypeIdPointer && |
| 14091 | 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 | 14247 | array_type = array_type->data.pointer.child_type; |
| 14096 | 14248 | ptr_type = ptr_type->data.pointer.child_type; |
| 14097 | 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 | 14256 | if (array_type->data.array.len == 0) { |
| ... | ... | @@ -14103,7 +14258,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14103 | 14258 | buf_sprintf("index 0 outside array of size 0")); |
| 14104 | 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 | 14262 | if (ptr_type->data.pointer.unaligned_bit_count == 0) { |
| 14108 | 14263 | return_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 14109 | 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 | 14277 | elem_ptr_instruction->ptr_len, |
| 14123 | 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 | 14281 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { |
| 14127 | 14282 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14128 | 14283 | buf_sprintf("index of single-item pointer")); |
| ... | ... | @@ -14132,11 +14287,13 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14132 | 14287 | } else if (is_slice(array_type)) { |
| 14133 | 14288 | return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index].type_entry, |
| 14134 | 14289 | elem_ptr_instruction->ptr_len); |
| 14135 | | } else if (array_type->id == TypeTableEntryIdArgTuple) { |
| 14290 | } else if (array_type->id == ZigTypeIdArgTuple) { |
| 14136 | 14291 | ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad); |
| 14137 | 14292 | if (!ptr_val) |
| 14138 | 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 | 14297 | size_t start = args_val->data.x_arg_tuple.start_index; |
| 14141 | 14298 | size_t end = args_val->data.x_arg_tuple.end_index; |
| 14142 | 14299 | uint64_t elem_index_val; |
| ... | ... | @@ -14150,9 +14307,9 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14150 | 14307 | return ira->codegen->builtin_types.entry_invalid; |
| 14151 | 14308 | } |
| 14152 | 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 | 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 | 14313 | bool is_const = true; |
| 14157 | 14314 | bool is_volatile = false; |
| 14158 | 14315 | if (var) { |
| ... | ... | @@ -14167,7 +14324,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14167 | 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 | 14328 | IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize); |
| 14172 | 14329 | if (casted_elem_index == ira->codegen->invalid_instruction) |
| 14173 | 14330 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -14181,7 +14338,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14181 | 14338 | uint64_t ptr_align = return_type->data.pointer.alignment; |
| 14182 | 14339 | if (instr_is_comptime(casted_elem_index)) { |
| 14183 | 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 | 14342 | uint64_t array_len = array_type->data.array.len; |
| 14186 | 14343 | if (index >= array_len) { |
| 14187 | 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 | 14369 | return_type = adjust_ptr_align(ira->codegen, return_type, chosen_align); |
| 14213 | 14370 | } |
| 14214 | 14371 | |
| 14215 | | ConstExprValue *array_ptr_val; |
| 14216 | 14372 | if (orig_array_ptr_val->special != ConstValSpecialRuntime && |
| 14217 | | (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == TypeTableEntryIdArray) && |
| 14218 | | (array_ptr_val = const_ptr_pointee(ira->codegen, orig_array_ptr_val)) && |
| 14219 | | array_ptr_val->special != ConstValSpecialRuntime && |
| 14220 | | (array_type->id != TypeTableEntryIdPointer || |
| 14221 | | array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)) |
| 14373 | (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || |
| 14374 | array_type->id == ZigTypeIdArray)) |
| 14222 | 14375 | { |
| 14223 | | if (array_type->id == TypeTableEntryIdPointer) { |
| 14224 | | ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base); |
| 14225 | | out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut; |
| 14226 | | size_t new_index; |
| 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; |
| 14376 | ConstExprValue *array_ptr_val = ir_const_ptr_pointee(ira, orig_array_ptr_val, |
| 14377 | elem_ptr_instruction->base.source_node); |
| 14378 | if (array_ptr_val == nullptr) |
| 14379 | return ira->codegen->builtin_types.entry_invalid; |
| 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 | 14402 | break; |
| 14258 | | } |
| 14259 | | case ConstPtrSpecialBaseStruct: |
| 14260 | | zig_panic("TODO elem ptr on a const inner struct"); |
| 14261 | | case ConstPtrSpecialHardCodedAddr: |
| 14262 | | zig_unreachable(); |
| 14263 | | case ConstPtrSpecialFunction: |
| 14264 | | zig_panic("TODO element ptr of a function casted to a ptr"); |
| 14265 | | } |
| 14266 | | if (new_index >= mem_size) { |
| 14267 | | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14268 | | buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size)); |
| 14269 | | return ira->codegen->builtin_types.entry_invalid; |
| 14270 | | } |
| 14271 | | return return_type; |
| 14272 | | } else if (is_slice(array_type)) { |
| 14273 | | ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index]; |
| 14274 | | if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 14275 | | IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, |
| 14276 | | array_ptr, casted_elem_index, false, elem_ptr_instruction->ptr_len); |
| 14277 | | result->value.type = return_type; |
| 14278 | | ir_link_new_instruction(result, &elem_ptr_instruction->base); |
| 14403 | case ConstPtrSpecialBaseArray: |
| 14404 | { |
| 14405 | size_t offset = array_ptr_val->data.x_ptr.data.base_array.elem_index; |
| 14406 | new_index = offset + index; |
| 14407 | mem_size = array_ptr_val->data.x_ptr.data.base_array.array_val->type->data.array.len; |
| 14408 | old_size = mem_size - offset; |
| 14409 | |
| 14410 | assert(array_ptr_val->data.x_ptr.data.base_array.array_val); |
| 14411 | |
| 14412 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 14413 | out_val->data.x_ptr.data.base_array.array_val = |
| 14414 | array_ptr_val->data.x_ptr.data.base_array.array_val; |
| 14415 | out_val->data.x_ptr.data.base_array.elem_index = new_index; |
| 14416 | out_val->data.x_ptr.data.base_array.is_cstr = |
| 14417 | array_ptr_val->data.x_ptr.data.base_array.is_cstr; |
| 14418 | |
| 14419 | break; |
| 14420 | } |
| 14421 | case ConstPtrSpecialBaseStruct: |
| 14422 | zig_panic("TODO elem ptr on a const inner struct"); |
| 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 | 14433 | return return_type; |
| 14280 | | } |
| 14281 | | ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index]; |
| 14282 | | ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base); |
| 14283 | | uint64_t slice_len = bigint_as_unsigned(&len_field->data.x_bigint); |
| 14284 | | if (index >= slice_len) { |
| 14285 | | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14286 | | buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64, |
| 14287 | | index, slice_len)); |
| 14288 | | return ira->codegen->builtin_types.entry_invalid; |
| 14289 | | } |
| 14290 | | out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut; |
| 14291 | | switch (ptr_field->data.x_ptr.special) { |
| 14292 | | case ConstPtrSpecialInvalid: |
| 14293 | | case ConstPtrSpecialDiscard: |
| 14294 | | zig_unreachable(); |
| 14295 | | case ConstPtrSpecialRef: |
| 14296 | | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 14297 | | out_val->data.x_ptr.data.ref.pointee = ptr_field->data.x_ptr.data.ref.pointee; |
| 14298 | | break; |
| 14299 | | case ConstPtrSpecialBaseArray: |
| 14300 | | { |
| 14301 | | size_t offset = ptr_field->data.x_ptr.data.base_array.elem_index; |
| 14302 | | uint64_t new_index = offset + index; |
| 14303 | | assert(new_index < ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len); |
| 14304 | | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 14305 | | out_val->data.x_ptr.data.base_array.array_val = |
| 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; |
| 14434 | } else if (is_slice(array_type)) { |
| 14435 | ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index]; |
| 14436 | if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 14437 | IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, |
| 14438 | array_ptr, casted_elem_index, false, elem_ptr_instruction->ptr_len); |
| 14439 | result->value.type = return_type; |
| 14440 | ir_link_new_instruction(result, &elem_ptr_instruction->base); |
| 14441 | return return_type; |
| 14442 | } |
| 14443 | ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index]; |
| 14444 | ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base); |
| 14445 | uint64_t slice_len = bigint_as_unsigned(&len_field->data.x_bigint); |
| 14446 | if (index >= slice_len) { |
| 14447 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14448 | buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64, |
| 14449 | index, slice_len)); |
| 14450 | return ira->codegen->builtin_types.entry_invalid; |
| 14451 | } |
| 14452 | out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut; |
| 14453 | switch (ptr_field->data.x_ptr.special) { |
| 14454 | case ConstPtrSpecialInvalid: |
| 14455 | case ConstPtrSpecialDiscard: |
| 14456 | zig_unreachable(); |
| 14457 | case ConstPtrSpecialRef: |
| 14458 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 14459 | out_val->data.x_ptr.data.ref.pointee = ptr_field->data.x_ptr.data.ref.pointee; |
| 14310 | 14460 | break; |
| 14311 | | } |
| 14312 | | case ConstPtrSpecialBaseStruct: |
| 14313 | | zig_panic("TODO elem ptr on a slice backed by const inner struct"); |
| 14314 | | case ConstPtrSpecialHardCodedAddr: |
| 14315 | | zig_unreachable(); |
| 14316 | | case ConstPtrSpecialFunction: |
| 14317 | | zig_panic("TODO elem ptr on a slice that was ptrcast from a function"); |
| 14461 | case ConstPtrSpecialBaseArray: |
| 14462 | { |
| 14463 | size_t offset = ptr_field->data.x_ptr.data.base_array.elem_index; |
| 14464 | uint64_t new_index = offset + index; |
| 14465 | assert(new_index < ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len); |
| 14466 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 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 | 14514 | } |
| 14352 | 14515 | |
| 14353 | 14516 | static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 14354 | | TypeTableEntry *bare_struct_type, Buf *field_name, IrInstruction *source_instr, |
| 14355 | | IrInstruction *container_ptr, TypeTableEntry *container_type) |
| 14517 | ZigType *bare_struct_type, Buf *field_name, IrInstruction *source_instr, |
| 14518 | IrInstruction *container_ptr, ZigType *container_type) |
| 14356 | 14519 | { |
| 14357 | 14520 | if (!is_slice(bare_struct_type)) { |
| 14358 | 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 | 14527 | if (tld->resolution == TldResolutionInvalid) |
| 14365 | 14528 | return ira->codegen->invalid_instruction; |
| 14366 | 14529 | TldFn *tld_fn = (TldFn *)tld; |
| 14367 | | FnTableEntry *fn_entry = tld_fn->fn_entry; |
| 14530 | ZigFn *fn_entry = tld_fn->fn_entry; |
| 14368 | 14531 | if (type_is_invalid(fn_entry->type_entry)) |
| 14369 | 14532 | return ira->codegen->invalid_instruction; |
| 14370 | 14533 | |
| ... | ... | @@ -14376,11 +14539,11 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 14376 | 14539 | const char *prefix_name; |
| 14377 | 14540 | if (is_slice(bare_struct_type)) { |
| 14378 | 14541 | prefix_name = ""; |
| 14379 | | } else if (bare_struct_type->id == TypeTableEntryIdStruct) { |
| 14542 | } else if (bare_struct_type->id == ZigTypeIdStruct) { |
| 14380 | 14543 | prefix_name = "struct "; |
| 14381 | | } else if (bare_struct_type->id == TypeTableEntryIdEnum) { |
| 14544 | } else if (bare_struct_type->id == ZigTypeIdEnum) { |
| 14382 | 14545 | prefix_name = "enum "; |
| 14383 | | } else if (bare_struct_type->id == TypeTableEntryIdUnion) { |
| 14546 | } else if (bare_struct_type->id == ZigTypeIdUnion) { |
| 14384 | 14547 | prefix_name = "union "; |
| 14385 | 14548 | } else { |
| 14386 | 14549 | prefix_name = ""; |
| ... | ... | @@ -14391,18 +14554,18 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 14391 | 14554 | } |
| 14392 | 14555 | |
| 14393 | 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 | 14559 | Error err; |
| 14397 | 14560 | |
| 14398 | | TypeTableEntry *bare_type = container_ref_type(container_type); |
| 14561 | ZigType *bare_type = container_ref_type(container_type); |
| 14399 | 14562 | if ((err = ensure_complete_type(ira->codegen, bare_type))) |
| 14400 | 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 | 14566 | bool is_const = container_ptr->value.type->data.pointer.is_const; |
| 14404 | 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 | 14569 | TypeStructField *field = find_struct_type_field(bare_type, field_name); |
| 14407 | 14570 | if (field) { |
| 14408 | 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 | 14580 | return ira->codegen->invalid_instruction; |
| 14418 | 14581 | |
| 14419 | 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 | 14586 | if (type_is_invalid(struct_val->type)) |
| 14422 | 14587 | return ira->codegen->invalid_instruction; |
| 14423 | 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 | 14590 | is_const, is_volatile, PtrLenSingle, align_bytes, |
| 14426 | 14591 | (uint32_t)(ptr_bit_offset + field->packed_bits_offset), |
| 14427 | 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 | 14612 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, |
| 14448 | 14613 | source_instr, container_ptr, container_type); |
| 14449 | 14614 | } |
| 14450 | | } else if (bare_type->id == TypeTableEntryIdEnum) { |
| 14615 | } else if (bare_type->id == ZigTypeIdEnum) { |
| 14451 | 14616 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, |
| 14452 | 14617 | source_instr, container_ptr, container_type); |
| 14453 | | } else if (bare_type->id == TypeTableEntryIdUnion) { |
| 14618 | } else if (bare_type->id == ZigTypeIdUnion) { |
| 14454 | 14619 | TypeUnionField *field = find_union_type_field(bare_type, field_name); |
| 14455 | 14620 | if (field) { |
| 14456 | 14621 | if (instr_is_comptime(container_ptr)) { |
| ... | ... | @@ -14459,7 +14624,9 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 14459 | 14624 | return ira->codegen->invalid_instruction; |
| 14460 | 14625 | |
| 14461 | 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 | 14630 | if (type_is_invalid(union_val->type)) |
| 14464 | 14631 | return ira->codegen->invalid_instruction; |
| 14465 | 14632 | |
| ... | ... | @@ -14476,15 +14643,15 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 14476 | 14643 | |
| 14477 | 14644 | ConstExprValue *payload_val = union_val->data.x_union.payload; |
| 14478 | 14645 | |
| 14479 | | TypeTableEntry *field_type = field->type_entry; |
| 14480 | | if (field_type->id == TypeTableEntryIdVoid) { |
| 14646 | ZigType *field_type = field->type_entry; |
| 14647 | if (field_type->id == ZigTypeIdVoid) { |
| 14481 | 14648 | assert(payload_val == nullptr); |
| 14482 | 14649 | payload_val = create_const_vals(1); |
| 14483 | 14650 | payload_val->special = ConstValSpecialStatic; |
| 14484 | 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 | 14655 | is_const, is_volatile, |
| 14489 | 14656 | PtrLenSingle, |
| 14490 | 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 | 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 | 14702 | bool pointer_only = false; |
| 14536 | 14703 | resolve_top_level_decl(ira->codegen, tld, pointer_only, source_instruction->source_node); |
| 14537 | 14704 | if (tld->resolution == TldResolutionInvalid) |
| ... | ... | @@ -14544,7 +14711,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source |
| 14544 | 14711 | case TldIdVar: |
| 14545 | 14712 | { |
| 14546 | 14713 | TldVar *tld_var = (TldVar *)tld; |
| 14547 | | VariableTableEntry *var = tld_var->var; |
| 14714 | ZigVar *var = tld_var->var; |
| 14548 | 14715 | if (tld_var->extern_lib_name != nullptr) { |
| 14549 | 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 | 14721 | case TldIdFn: |
| 14555 | 14722 | { |
| 14556 | 14723 | TldFn *tld_fn = (TldFn *)tld; |
| 14557 | | FnTableEntry *fn_entry = tld_fn->fn_entry; |
| 14724 | ZigFn *fn_entry = tld_fn->fn_entry; |
| 14558 | 14725 | assert(fn_entry->type_entry); |
| 14559 | 14726 | |
| 14560 | 14727 | if (type_is_invalid(fn_entry->type_entry)) |
| ... | ... | @@ -14582,8 +14749,8 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source |
| 14582 | 14749 | zig_unreachable(); |
| 14583 | 14750 | } |
| 14584 | 14751 | |
| 14585 | | static ErrorTableEntry *find_err_table_entry(TypeTableEntry *err_set_type, Buf *field_name) { |
| 14586 | | assert(err_set_type->id == TypeTableEntryIdErrorSet); |
| 14752 | static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_name) { |
| 14753 | assert(err_set_type->id == ZigTypeIdErrorSet); |
| 14587 | 14754 | for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) { |
| 14588 | 14755 | ErrorTableEntry *err_table_entry = err_set_type->data.error_set.errors[i]; |
| 14589 | 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 | 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 | 14764 | Error err; |
| 14598 | 14765 | IrInstruction *container_ptr = field_ptr_instruction->container_ptr->other; |
| 14599 | 14766 | if (type_is_invalid(container_ptr->value.type)) |
| 14600 | 14767 | return ira->codegen->builtin_types.entry_invalid; |
| 14601 | 14768 | |
| 14602 | | TypeTableEntry *container_type = container_ptr->value.type->data.pointer.child_type; |
| 14603 | | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); |
| 14769 | ZigType *container_type = container_ptr->value.type->data.pointer.child_type; |
| 14770 | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 14604 | 14771 | |
| 14605 | 14772 | Buf *field_name = field_ptr_instruction->field_name_buffer; |
| 14606 | 14773 | if (!field_name) { |
| ... | ... | @@ -14616,9 +14783,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14616 | 14783 | if (type_is_invalid(container_type)) { |
| 14617 | 14784 | return container_type; |
| 14618 | 14785 | } else if (is_container_ref(container_type)) { |
| 14619 | | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); |
| 14620 | | if (container_type->id == TypeTableEntryIdPointer) { |
| 14621 | | TypeTableEntry *bare_type = container_ref_type(container_type); |
| 14786 | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 14787 | if (container_type->id == ZigTypeIdPointer) { |
| 14788 | ZigType *bare_type = container_ref_type(container_type); |
| 14622 | 14789 | IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr); |
| 14623 | 14790 | IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type); |
| 14624 | 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 | 14798 | } else if (is_array_ref(container_type)) { |
| 14632 | 14799 | if (buf_eql_str(field_name, "len")) { |
| 14633 | 14800 | ConstExprValue *len_val = create_const_vals(1); |
| 14634 | | if (container_type->id == TypeTableEntryIdPointer) { |
| 14801 | if (container_type->id == ZigTypeIdPointer) { |
| 14635 | 14802 | init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len); |
| 14636 | 14803 | } else { |
| 14637 | 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 | 14808 | bool ptr_is_const = true; |
| 14642 | 14809 | bool ptr_is_volatile = false; |
| 14643 | 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 | 14815 | buf_ptr(&container_type->name))); |
| 14649 | 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 | 14819 | ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 14653 | 14820 | if (!container_ptr_val) |
| 14654 | 14821 | return ira->codegen->builtin_types.entry_invalid; |
| 14655 | 14822 | |
| 14656 | | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); |
| 14657 | | ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val); |
| 14823 | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 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 | 14828 | if (buf_eql_str(field_name, "len")) { |
| 14660 | 14829 | ConstExprValue *len_val = create_const_vals(1); |
| 14661 | 14830 | size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index; |
| 14662 | 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 | 14834 | bool ptr_is_const = true; |
| 14666 | 14835 | bool ptr_is_volatile = false; |
| 14667 | 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 | 14841 | buf_ptr(&container_type->name))); |
| 14673 | 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 | 14845 | ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 14677 | 14846 | if (!container_ptr_val) |
| 14678 | 14847 | return ira->codegen->builtin_types.entry_invalid; |
| 14679 | 14848 | |
| 14680 | | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); |
| 14681 | | ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val); |
| 14682 | | TypeTableEntry *child_type = child_val->data.x_type; |
| 14849 | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 14850 | ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node); |
| 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 | 14855 | if (type_is_invalid(child_type)) { |
| 14685 | 14856 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -14688,14 +14859,14 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14688 | 14859 | bool ptr_is_const = true; |
| 14689 | 14860 | bool ptr_is_volatile = false; |
| 14690 | 14861 | TypeStructField *ptr_field = &child_type->data.structure.fields[slice_ptr_index]; |
| 14691 | | assert(ptr_field->type_entry->id == TypeTableEntryIdPointer); |
| 14692 | | TypeTableEntry *child_type = ptr_field->type_entry->data.pointer.child_type; |
| 14862 | assert(ptr_field->type_entry->id == ZigTypeIdPointer); |
| 14863 | ZigType *child_type = ptr_field->type_entry->data.pointer.child_type; |
| 14693 | 14864 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14694 | 14865 | create_const_type(ira->codegen, child_type), |
| 14695 | 14866 | ira->codegen->builtin_types.entry_type, |
| 14696 | 14867 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14697 | 14868 | } |
| 14698 | | if (child_type->id == TypeTableEntryIdEnum) { |
| 14869 | if (child_type->id == ZigTypeIdEnum) { |
| 14699 | 14870 | if ((err = ensure_complete_type(ira->codegen, child_type))) |
| 14700 | 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 | 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 | 14891 | (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr || |
| 14721 | 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 | 14895 | return ira->codegen->builtin_types.entry_invalid; |
| 14725 | 14896 | TypeUnionField *field = find_union_type_field(child_type, field_name); |
| 14726 | 14897 | if (field) { |
| 14727 | | TypeTableEntry *enum_type = child_type->data.unionation.tag_type; |
| 14898 | ZigType *enum_type = child_type->data.unionation.tag_type; |
| 14728 | 14899 | bool ptr_is_const = true; |
| 14729 | 14900 | bool ptr_is_volatile = false; |
| 14730 | 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 | 14907 | buf_sprintf("container '%s' has no member called '%s'", |
| 14737 | 14908 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 14738 | 14909 | return ira->codegen->builtin_types.entry_invalid; |
| 14739 | | } else if (child_type->id == TypeTableEntryIdErrorSet) { |
| 14910 | } else if (child_type->id == ZigTypeIdErrorSet) { |
| 14740 | 14911 | ErrorTableEntry *err_entry; |
| 14741 | | TypeTableEntry *err_set_type; |
| 14912 | ZigType *err_set_type; |
| 14742 | 14913 | if (type_is_global_error_set(child_type)) { |
| 14743 | 14914 | auto existing_entry = ira->codegen->error_table.maybe_get(field_name); |
| 14744 | 14915 | if (existing_entry) { |
| ... | ... | @@ -14782,7 +14953,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14782 | 14953 | bool ptr_is_volatile = false; |
| 14783 | 14954 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, const_val, |
| 14784 | 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 | 14957 | if (buf_eql_str(field_name, "bit_count")) { |
| 14787 | 14958 | bool ptr_is_const = true; |
| 14788 | 14959 | bool ptr_is_volatile = false; |
| ... | ... | @@ -14804,7 +14975,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14804 | 14975 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 14805 | 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 | 14979 | if (buf_eql_str(field_name, "bit_count")) { |
| 14809 | 14980 | bool ptr_is_const = true; |
| 14810 | 14981 | bool ptr_is_volatile = false; |
| ... | ... | @@ -14819,7 +14990,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14819 | 14990 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 14820 | 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 | 14994 | if (buf_eql_str(field_name, "Child")) { |
| 14824 | 14995 | bool ptr_is_const = true; |
| 14825 | 14996 | bool ptr_is_volatile = false; |
| ... | ... | @@ -14841,7 +15012,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14841 | 15012 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 14842 | 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 | 15016 | if (buf_eql_str(field_name, "Child")) { |
| 14846 | 15017 | bool ptr_is_const = true; |
| 14847 | 15018 | bool ptr_is_volatile = false; |
| ... | ... | @@ -14863,7 +15034,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14863 | 15034 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 14864 | 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 | 15038 | if (buf_eql_str(field_name, "Payload")) { |
| 14868 | 15039 | bool ptr_is_const = true; |
| 14869 | 15040 | bool ptr_is_volatile = false; |
| ... | ... | @@ -14884,7 +15055,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14884 | 15055 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 14885 | 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 | 15059 | if (buf_eql_str(field_name, "Child")) { |
| 14889 | 15060 | bool ptr_is_const = true; |
| 14890 | 15061 | bool ptr_is_volatile = false; |
| ... | ... | @@ -14898,7 +15069,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14898 | 15069 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 14899 | 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 | 15073 | if (buf_eql_str(field_name, "ReturnType")) { |
| 14903 | 15074 | if (child_type->data.fn.fn_type_id.return_type == nullptr) { |
| 14904 | 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 | 15111 | buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name))); |
| 14941 | 15112 | return ira->codegen->builtin_types.entry_invalid; |
| 14942 | 15113 | } |
| 14943 | | } else if (container_type->id == TypeTableEntryIdNamespace) { |
| 14944 | | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); |
| 15114 | } else if (container_type->id == ZigTypeIdNamespace) { |
| 15115 | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 14945 | 15116 | ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 14946 | 15117 | if (!container_ptr_val) |
| 14947 | 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 | 15124 | assert(namespace_val->special == ConstValSpecialStatic); |
| 14951 | 15125 | |
| 14952 | 15126 | ImportTableEntry *namespace_import = namespace_val->data.x_import; |
| ... | ... | @@ -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 | 15153 | IrInstruction *ptr = load_ptr_instruction->ptr->other; |
| 14980 | 15154 | if (type_is_invalid(ptr->value.type)) |
| 14981 | 15155 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -14986,7 +15160,7 @@ static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstruc |
| 14986 | 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 | 15164 | IrInstruction *ptr = store_ptr_instruction->ptr->other; |
| 14991 | 15165 | if (type_is_invalid(ptr->value.type)) |
| 14992 | 15166 | return ptr->value.type; |
| ... | ... | @@ -14995,7 +15169,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 14995 | 15169 | if (type_is_invalid(value->value.type)) |
| 14996 | 15170 | return value->value.type; |
| 14997 | 15171 | |
| 14998 | | if (ptr->value.type->id != TypeTableEntryIdPointer) { |
| 15172 | if (ptr->value.type->id != ZigTypeIdPointer) { |
| 14999 | 15173 | ir_add_error(ira, ptr, |
| 15000 | 15174 | buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr->value.type->name))); |
| 15001 | 15175 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -15010,7 +15184,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 15010 | 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 | 15188 | IrInstruction *casted_value = ir_implicit_cast(ira, value, child_type); |
| 15015 | 15189 | if (casted_value == ira->codegen->invalid_instruction) |
| 15016 | 15190 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -15022,7 +15196,9 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 15022 | 15196 | } |
| 15023 | 15197 | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) { |
| 15024 | 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 | 15202 | if (dest_val->special != ConstValSpecialRuntime) { |
| 15027 | 15203 | *dest_val = casted_value->value; |
| 15028 | 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 | 15209 | } |
| 15034 | 15210 | ir_add_error(ira, &store_ptr_instruction->base, |
| 15035 | 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 | 15213 | dest_val->type = ira->codegen->builtin_types.entry_invalid; |
| 15038 | 15214 | |
| 15039 | 15215 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -15044,39 +15220,39 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 15044 | 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 | 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 | 15226 | if (type_is_invalid(type_entry)) |
| 15051 | 15227 | return ira->codegen->builtin_types.entry_invalid; |
| 15052 | 15228 | switch (type_entry->id) { |
| 15053 | | case TypeTableEntryIdInvalid: |
| 15229 | case ZigTypeIdInvalid: |
| 15054 | 15230 | zig_unreachable(); // handled above |
| 15055 | | case TypeTableEntryIdComptimeFloat: |
| 15056 | | case TypeTableEntryIdComptimeInt: |
| 15057 | | case TypeTableEntryIdUndefined: |
| 15058 | | case TypeTableEntryIdNull: |
| 15059 | | case TypeTableEntryIdNamespace: |
| 15060 | | case TypeTableEntryIdBlock: |
| 15061 | | case TypeTableEntryIdBoundFn: |
| 15062 | | case TypeTableEntryIdMetaType: |
| 15063 | | case TypeTableEntryIdVoid: |
| 15064 | | case TypeTableEntryIdBool: |
| 15065 | | case TypeTableEntryIdUnreachable: |
| 15066 | | case TypeTableEntryIdInt: |
| 15067 | | case TypeTableEntryIdFloat: |
| 15068 | | case TypeTableEntryIdPointer: |
| 15069 | | case TypeTableEntryIdArray: |
| 15070 | | case TypeTableEntryIdStruct: |
| 15071 | | case TypeTableEntryIdOptional: |
| 15072 | | case TypeTableEntryIdErrorUnion: |
| 15073 | | case TypeTableEntryIdErrorSet: |
| 15074 | | case TypeTableEntryIdEnum: |
| 15075 | | case TypeTableEntryIdUnion: |
| 15076 | | case TypeTableEntryIdFn: |
| 15077 | | case TypeTableEntryIdArgTuple: |
| 15078 | | case TypeTableEntryIdOpaque: |
| 15079 | | case TypeTableEntryIdPromise: |
| 15231 | case ZigTypeIdComptimeFloat: |
| 15232 | case ZigTypeIdComptimeInt: |
| 15233 | case ZigTypeIdUndefined: |
| 15234 | case ZigTypeIdNull: |
| 15235 | case ZigTypeIdNamespace: |
| 15236 | case ZigTypeIdBlock: |
| 15237 | case ZigTypeIdBoundFn: |
| 15238 | case ZigTypeIdMetaType: |
| 15239 | case ZigTypeIdVoid: |
| 15240 | case ZigTypeIdBool: |
| 15241 | case ZigTypeIdUnreachable: |
| 15242 | case ZigTypeIdInt: |
| 15243 | case ZigTypeIdFloat: |
| 15244 | case ZigTypeIdPointer: |
| 15245 | case ZigTypeIdArray: |
| 15246 | case ZigTypeIdStruct: |
| 15247 | case ZigTypeIdOptional: |
| 15248 | case ZigTypeIdErrorUnion: |
| 15249 | case ZigTypeIdErrorSet: |
| 15250 | case ZigTypeIdEnum: |
| 15251 | case ZigTypeIdUnion: |
| 15252 | case ZigTypeIdFn: |
| 15253 | case ZigTypeIdArgTuple: |
| 15254 | case ZigTypeIdOpaque: |
| 15255 | case ZigTypeIdPromise: |
| 15080 | 15256 | { |
| 15081 | 15257 | ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base); |
| 15082 | 15258 | out_val->data.x_type = type_entry; |
| ... | ... | @@ -15088,20 +15264,20 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi |
| 15088 | 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 | 15268 | IrInstructionToPtrType *to_ptr_type_instruction) |
| 15093 | 15269 | { |
| 15094 | 15270 | IrInstruction *value = to_ptr_type_instruction->value->other; |
| 15095 | | TypeTableEntry *type_entry = value->value.type; |
| 15271 | ZigType *type_entry = value->value.type; |
| 15096 | 15272 | if (type_is_invalid(type_entry)) |
| 15097 | 15273 | return type_entry; |
| 15098 | 15274 | |
| 15099 | | TypeTableEntry *ptr_type; |
| 15100 | | if (type_entry->id == TypeTableEntryIdArray) { |
| 15275 | ZigType *ptr_type; |
| 15276 | if (type_entry->id == ZigTypeIdArray) { |
| 15101 | 15277 | ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false); |
| 15102 | 15278 | } else if (is_slice(type_entry)) { |
| 15103 | 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 | 15281 | ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad); |
| 15106 | 15282 | if (!arg_tuple_val) |
| 15107 | 15283 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -15117,15 +15293,15 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, |
| 15117 | 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 | 15297 | IrInstructionPtrTypeChild *ptr_type_child_instruction) |
| 15122 | 15298 | { |
| 15123 | 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 | 15301 | if (type_is_invalid(type_entry)) |
| 15126 | 15302 | return type_entry; |
| 15127 | 15303 | |
| 15128 | | if (type_entry->id != TypeTableEntryIdPointer) { |
| 15304 | if (type_entry->id != ZigTypeIdPointer) { |
| 15129 | 15305 | ir_add_error_node(ira, ptr_type_child_instruction->base.source_node, |
| 15130 | 15306 | buf_sprintf("expected pointer type, found '%s'", buf_ptr(&type_entry->name))); |
| 15131 | 15307 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -15136,7 +15312,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira, |
| 15136 | 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 | 15316 | if (ira->new_irb.exec->is_inline) { |
| 15141 | 15317 | // ignore setCold when running functions at compile time |
| 15142 | 15318 | ir_build_const_from(ira, &instruction->base); |
| ... | ... | @@ -15148,7 +15324,7 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc |
| 15148 | 15324 | if (!ir_resolve_bool(ira, is_cold_value, &want_cold)) |
| 15149 | 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 | 15328 | if (fn_entry == nullptr) { |
| 15153 | 15329 | ir_add_error(ira, &instruction->base, buf_sprintf("@setCold outside function")); |
| 15154 | 15330 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -15166,7 +15342,7 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc |
| 15166 | 15342 | ir_build_const_from(ira, &instruction->base); |
| 15167 | 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 | 15346 | IrInstructionSetRuntimeSafety *set_runtime_safety_instruction) |
| 15171 | 15347 | { |
| 15172 | 15348 | if (ira->new_irb.exec->is_inline) { |
| ... | ... | @@ -15187,7 +15363,7 @@ static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 15187 | 15363 | break; |
| 15188 | 15364 | } else if (scope->id == ScopeIdFnDef) { |
| 15189 | 15365 | ScopeFnDef *def_scope = (ScopeFnDef *)scope; |
| 15190 | | FnTableEntry *target_fn = def_scope->fn_entry; |
| 15366 | ZigFn *target_fn = def_scope->fn_entry; |
| 15191 | 15367 | assert(target_fn->def_scope != nullptr); |
| 15192 | 15368 | safety_off_ptr = &target_fn->def_scope->safety_off; |
| 15193 | 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 | 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 | 15403 | IrInstructionSetFloatMode *instruction) |
| 15228 | 15404 | { |
| 15229 | 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 | 15407 | if (type_is_invalid(target_type)) |
| 15232 | 15408 | return ira->codegen->builtin_types.entry_invalid; |
| 15233 | 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 | 15418 | |
| 15243 | 15419 | bool *fast_math_on_ptr; |
| 15244 | 15420 | AstNode **fast_math_set_node_ptr; |
| 15245 | | if (target_type->id == TypeTableEntryIdBlock) { |
| 15421 | if (target_type->id == ZigTypeIdBlock) { |
| 15246 | 15422 | ScopeBlock *block_scope = (ScopeBlock *)target_val->data.x_block; |
| 15247 | 15423 | fast_math_on_ptr = &block_scope->fast_math_on; |
| 15248 | 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 | 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 | 15428 | assert(target_fn->def_scope); |
| 15253 | 15429 | fast_math_on_ptr = &target_fn->def_scope->fast_math_on; |
| 15254 | 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 | 15432 | ScopeDecls *decls_scope; |
| 15257 | | TypeTableEntry *type_arg = target_val->data.x_type; |
| 15258 | | if (type_arg->id == TypeTableEntryIdStruct) { |
| 15433 | ZigType *type_arg = target_val->data.x_type; |
| 15434 | if (type_arg->id == ZigTypeIdStruct) { |
| 15259 | 15435 | decls_scope = type_arg->data.structure.decls_scope; |
| 15260 | | } else if (type_arg->id == TypeTableEntryIdEnum) { |
| 15436 | } else if (type_arg->id == ZigTypeIdEnum) { |
| 15261 | 15437 | decls_scope = type_arg->data.enumeration.decls_scope; |
| 15262 | | } else if (type_arg->id == TypeTableEntryIdUnion) { |
| 15438 | } else if (type_arg->id == ZigTypeIdUnion) { |
| 15263 | 15439 | decls_scope = type_arg->data.unionation.decls_scope; |
| 15264 | 15440 | } else { |
| 15265 | 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 | 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 | 15474 | IrInstructionSliceType *slice_type_instruction) |
| 15299 | 15475 | { |
| 15300 | 15476 | Error err; |
| ... | ... | @@ -15304,7 +15480,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15304 | 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 | 15484 | if (type_is_invalid(child_type)) |
| 15309 | 15485 | return ira->codegen->builtin_types.entry_invalid; |
| 15310 | 15486 | |
| ... | ... | @@ -15318,42 +15494,42 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15318 | 15494 | bool is_volatile = slice_type_instruction->is_volatile; |
| 15319 | 15495 | |
| 15320 | 15496 | switch (child_type->id) { |
| 15321 | | case TypeTableEntryIdInvalid: // handled above |
| 15497 | case ZigTypeIdInvalid: // handled above |
| 15322 | 15498 | zig_unreachable(); |
| 15323 | | case TypeTableEntryIdUnreachable: |
| 15324 | | case TypeTableEntryIdUndefined: |
| 15325 | | case TypeTableEntryIdNull: |
| 15326 | | case TypeTableEntryIdBlock: |
| 15327 | | case TypeTableEntryIdArgTuple: |
| 15328 | | case TypeTableEntryIdOpaque: |
| 15499 | case ZigTypeIdUnreachable: |
| 15500 | case ZigTypeIdUndefined: |
| 15501 | case ZigTypeIdNull: |
| 15502 | case ZigTypeIdBlock: |
| 15503 | case ZigTypeIdArgTuple: |
| 15504 | case ZigTypeIdOpaque: |
| 15329 | 15505 | ir_add_error_node(ira, slice_type_instruction->base.source_node, |
| 15330 | 15506 | buf_sprintf("slice of type '%s' not allowed", buf_ptr(&child_type->name))); |
| 15331 | 15507 | return ira->codegen->builtin_types.entry_invalid; |
| 15332 | | case TypeTableEntryIdMetaType: |
| 15333 | | case TypeTableEntryIdVoid: |
| 15334 | | case TypeTableEntryIdBool: |
| 15335 | | case TypeTableEntryIdInt: |
| 15336 | | case TypeTableEntryIdFloat: |
| 15337 | | case TypeTableEntryIdPointer: |
| 15338 | | case TypeTableEntryIdArray: |
| 15339 | | case TypeTableEntryIdStruct: |
| 15340 | | case TypeTableEntryIdComptimeFloat: |
| 15341 | | case TypeTableEntryIdComptimeInt: |
| 15342 | | case TypeTableEntryIdOptional: |
| 15343 | | case TypeTableEntryIdErrorUnion: |
| 15344 | | case TypeTableEntryIdErrorSet: |
| 15345 | | case TypeTableEntryIdEnum: |
| 15346 | | case TypeTableEntryIdUnion: |
| 15347 | | case TypeTableEntryIdFn: |
| 15348 | | case TypeTableEntryIdNamespace: |
| 15349 | | case TypeTableEntryIdBoundFn: |
| 15350 | | case TypeTableEntryIdPromise: |
| 15508 | case ZigTypeIdMetaType: |
| 15509 | case ZigTypeIdVoid: |
| 15510 | case ZigTypeIdBool: |
| 15511 | case ZigTypeIdInt: |
| 15512 | case ZigTypeIdFloat: |
| 15513 | case ZigTypeIdPointer: |
| 15514 | case ZigTypeIdArray: |
| 15515 | case ZigTypeIdStruct: |
| 15516 | case ZigTypeIdComptimeFloat: |
| 15517 | case ZigTypeIdComptimeInt: |
| 15518 | case ZigTypeIdOptional: |
| 15519 | case ZigTypeIdErrorUnion: |
| 15520 | case ZigTypeIdErrorSet: |
| 15521 | case ZigTypeIdEnum: |
| 15522 | case ZigTypeIdUnion: |
| 15523 | case ZigTypeIdFn: |
| 15524 | case ZigTypeIdNamespace: |
| 15525 | case ZigTypeIdBoundFn: |
| 15526 | case ZigTypeIdPromise: |
| 15351 | 15527 | { |
| 15352 | 15528 | if ((err = type_ensure_zero_bits_known(ira->codegen, child_type))) |
| 15353 | 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 | 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 | 15533 | ConstExprValue *out_val = ir_build_const_from(ira, &slice_type_instruction->base); |
| 15358 | 15534 | out_val->data.x_type = result_type; |
| 15359 | 15535 | return ira->codegen->builtin_types.entry_type; |
| ... | ... | @@ -15362,7 +15538,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15362 | 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 | 15542 | assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr); |
| 15367 | 15543 | |
| 15368 | 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 | 15568 | IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length); |
| 15393 | 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 | 15572 | for (size_t i = 0; i < asm_expr->output_list.length; i += 1) { |
| 15397 | 15573 | AsmOutput *asm_output = asm_expr->output_list.at(i); |
| 15398 | 15574 | if (asm_output->return_type) { |
| ... | ... | @@ -15414,51 +15590,55 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA |
| 15414 | 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 | 15594 | IrInstructionArrayType *array_type_instruction) |
| 15419 | 15595 | { |
| 15596 | Error err; |
| 15597 | |
| 15420 | 15598 | IrInstruction *size_value = array_type_instruction->size->other; |
| 15421 | 15599 | uint64_t size; |
| 15422 | 15600 | if (!ir_resolve_usize(ira, size_value, &size)) |
| 15423 | 15601 | return ira->codegen->builtin_types.entry_invalid; |
| 15424 | 15602 | |
| 15425 | 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 | 15605 | if (type_is_invalid(child_type)) |
| 15428 | 15606 | return ira->codegen->builtin_types.entry_invalid; |
| 15429 | 15607 | switch (child_type->id) { |
| 15430 | | case TypeTableEntryIdInvalid: // handled above |
| 15608 | case ZigTypeIdInvalid: // handled above |
| 15431 | 15609 | zig_unreachable(); |
| 15432 | | case TypeTableEntryIdUnreachable: |
| 15433 | | case TypeTableEntryIdUndefined: |
| 15434 | | case TypeTableEntryIdNull: |
| 15435 | | case TypeTableEntryIdBlock: |
| 15436 | | case TypeTableEntryIdArgTuple: |
| 15437 | | case TypeTableEntryIdOpaque: |
| 15610 | case ZigTypeIdUnreachable: |
| 15611 | case ZigTypeIdUndefined: |
| 15612 | case ZigTypeIdNull: |
| 15613 | case ZigTypeIdBlock: |
| 15614 | case ZigTypeIdArgTuple: |
| 15615 | case ZigTypeIdOpaque: |
| 15438 | 15616 | ir_add_error_node(ira, array_type_instruction->base.source_node, |
| 15439 | 15617 | buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name))); |
| 15440 | 15618 | return ira->codegen->builtin_types.entry_invalid; |
| 15441 | | case TypeTableEntryIdMetaType: |
| 15442 | | case TypeTableEntryIdVoid: |
| 15443 | | case TypeTableEntryIdBool: |
| 15444 | | case TypeTableEntryIdInt: |
| 15445 | | case TypeTableEntryIdFloat: |
| 15446 | | case TypeTableEntryIdPointer: |
| 15447 | | case TypeTableEntryIdArray: |
| 15448 | | case TypeTableEntryIdStruct: |
| 15449 | | case TypeTableEntryIdComptimeFloat: |
| 15450 | | case TypeTableEntryIdComptimeInt: |
| 15451 | | case TypeTableEntryIdOptional: |
| 15452 | | case TypeTableEntryIdErrorUnion: |
| 15453 | | case TypeTableEntryIdErrorSet: |
| 15454 | | case TypeTableEntryIdEnum: |
| 15455 | | case TypeTableEntryIdUnion: |
| 15456 | | case TypeTableEntryIdFn: |
| 15457 | | case TypeTableEntryIdNamespace: |
| 15458 | | case TypeTableEntryIdBoundFn: |
| 15459 | | case TypeTableEntryIdPromise: |
| 15619 | case ZigTypeIdMetaType: |
| 15620 | case ZigTypeIdVoid: |
| 15621 | case ZigTypeIdBool: |
| 15622 | case ZigTypeIdInt: |
| 15623 | case ZigTypeIdFloat: |
| 15624 | case ZigTypeIdPointer: |
| 15625 | case ZigTypeIdArray: |
| 15626 | case ZigTypeIdStruct: |
| 15627 | case ZigTypeIdComptimeFloat: |
| 15628 | case ZigTypeIdComptimeInt: |
| 15629 | case ZigTypeIdOptional: |
| 15630 | case ZigTypeIdErrorUnion: |
| 15631 | case ZigTypeIdErrorSet: |
| 15632 | case ZigTypeIdEnum: |
| 15633 | case ZigTypeIdUnion: |
| 15634 | case ZigTypeIdFn: |
| 15635 | case ZigTypeIdNamespace: |
| 15636 | case ZigTypeIdBoundFn: |
| 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 | 15642 | ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base); |
| 15463 | 15643 | out_val->data.x_type = result_type; |
| 15464 | 15644 | return ira->codegen->builtin_types.entry_type; |
| ... | ... | @@ -15467,13 +15647,13 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 15467 | 15647 | zig_unreachable(); |
| 15468 | 15648 | } |
| 15469 | 15649 | |
| 15470 | | static TypeTableEntry *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInstructionPromiseType *instruction) { |
| 15471 | | TypeTableEntry *promise_type; |
| 15650 | static ZigType *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInstructionPromiseType *instruction) { |
| 15651 | ZigType *promise_type; |
| 15472 | 15652 | |
| 15473 | 15653 | if (instruction->payload_type == nullptr) { |
| 15474 | 15654 | promise_type = ira->codegen->builtin_types.entry_promise; |
| 15475 | 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 | 15657 | if (type_is_invalid(payload_type)) |
| 15478 | 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 | 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 | 15669 | IrInstructionSizeOf *size_of_instruction) |
| 15490 | 15670 | { |
| 15491 | 15671 | Error err; |
| 15492 | 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 | 15675 | if ((err = ensure_complete_type(ira->codegen, type_entry))) |
| 15496 | 15676 | return ira->codegen->builtin_types.entry_invalid; |
| 15497 | 15677 | |
| 15498 | 15678 | switch (type_entry->id) { |
| 15499 | | case TypeTableEntryIdInvalid: // handled above |
| 15679 | case ZigTypeIdInvalid: // handled above |
| 15500 | 15680 | zig_unreachable(); |
| 15501 | | case TypeTableEntryIdUnreachable: |
| 15502 | | case TypeTableEntryIdUndefined: |
| 15503 | | case TypeTableEntryIdNull: |
| 15504 | | case TypeTableEntryIdBlock: |
| 15505 | | case TypeTableEntryIdComptimeFloat: |
| 15506 | | case TypeTableEntryIdComptimeInt: |
| 15507 | | case TypeTableEntryIdBoundFn: |
| 15508 | | case TypeTableEntryIdMetaType: |
| 15509 | | case TypeTableEntryIdNamespace: |
| 15510 | | case TypeTableEntryIdArgTuple: |
| 15511 | | case TypeTableEntryIdOpaque: |
| 15681 | case ZigTypeIdUnreachable: |
| 15682 | case ZigTypeIdUndefined: |
| 15683 | case ZigTypeIdNull: |
| 15684 | case ZigTypeIdBlock: |
| 15685 | case ZigTypeIdComptimeFloat: |
| 15686 | case ZigTypeIdComptimeInt: |
| 15687 | case ZigTypeIdBoundFn: |
| 15688 | case ZigTypeIdMetaType: |
| 15689 | case ZigTypeIdNamespace: |
| 15690 | case ZigTypeIdArgTuple: |
| 15691 | case ZigTypeIdOpaque: |
| 15512 | 15692 | ir_add_error_node(ira, size_of_instruction->base.source_node, |
| 15513 | 15693 | buf_sprintf("no size available for type '%s'", buf_ptr(&type_entry->name))); |
| 15514 | 15694 | return ira->codegen->builtin_types.entry_invalid; |
| 15515 | | case TypeTableEntryIdVoid: |
| 15516 | | case TypeTableEntryIdBool: |
| 15517 | | case TypeTableEntryIdInt: |
| 15518 | | case TypeTableEntryIdFloat: |
| 15519 | | case TypeTableEntryIdPointer: |
| 15520 | | case TypeTableEntryIdArray: |
| 15521 | | case TypeTableEntryIdStruct: |
| 15522 | | case TypeTableEntryIdOptional: |
| 15523 | | case TypeTableEntryIdErrorUnion: |
| 15524 | | case TypeTableEntryIdErrorSet: |
| 15525 | | case TypeTableEntryIdEnum: |
| 15526 | | case TypeTableEntryIdUnion: |
| 15527 | | case TypeTableEntryIdFn: |
| 15528 | | case TypeTableEntryIdPromise: |
| 15695 | case ZigTypeIdVoid: |
| 15696 | case ZigTypeIdBool: |
| 15697 | case ZigTypeIdInt: |
| 15698 | case ZigTypeIdFloat: |
| 15699 | case ZigTypeIdPointer: |
| 15700 | case ZigTypeIdArray: |
| 15701 | case ZigTypeIdStruct: |
| 15702 | case ZigTypeIdOptional: |
| 15703 | case ZigTypeIdErrorUnion: |
| 15704 | case ZigTypeIdErrorSet: |
| 15705 | case ZigTypeIdEnum: |
| 15706 | case ZigTypeIdUnion: |
| 15707 | case ZigTypeIdFn: |
| 15708 | case ZigTypeIdPromise: |
| 15529 | 15709 | { |
| 15530 | 15710 | uint64_t size_in_bytes = type_size(ira->codegen, type_entry); |
| 15531 | 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 | 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 | 15720 | IrInstruction *value = instruction->value->other; |
| 15541 | 15721 | if (type_is_invalid(value->value.type)) |
| 15542 | 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 | 15727 | if (instr_is_comptime(value)) { |
| 15548 | 15728 | ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefBad); |
| 15549 | 15729 | if (!maybe_val) |
| ... | ... | @@ -15556,7 +15736,7 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn |
| 15556 | 15736 | |
| 15557 | 15737 | ir_build_test_nonnull_from(&ira->new_irb, &instruction->base, value); |
| 15558 | 15738 | return ira->codegen->builtin_types.entry_bool; |
| 15559 | | } else if (type_entry->id == TypeTableEntryIdNull) { |
| 15739 | } else if (type_entry->id == ZigTypeIdNull) { |
| 15560 | 15740 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 15561 | 15741 | out_val->data.x_bool = false; |
| 15562 | 15742 | return ira->codegen->builtin_types.entry_bool; |
| ... | ... | @@ -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 | 15751 | IrInstructionUnwrapOptional *unwrap_maybe_instruction) |
| 15572 | 15752 | { |
| 15573 | 15753 | IrInstruction *value = unwrap_maybe_instruction->value->other; |
| 15574 | 15754 | if (type_is_invalid(value->value.type)) |
| 15575 | 15755 | return ira->codegen->builtin_types.entry_invalid; |
| 15576 | 15756 | |
| 15577 | | TypeTableEntry *ptr_type = value->value.type; |
| 15578 | | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 15757 | ZigType *ptr_type = value->value.type; |
| 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 | 15761 | if (type_is_invalid(type_entry)) { |
| 15582 | 15762 | return ira->codegen->builtin_types.entry_invalid; |
| 15583 | | } else if (type_entry->id != TypeTableEntryIdOptional) { |
| 15763 | } else if (type_entry->id != ZigTypeIdOptional) { |
| 15584 | 15764 | ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node, |
| 15585 | 15765 | buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name))); |
| 15586 | 15766 | return ira->codegen->builtin_types.entry_invalid; |
| 15587 | 15767 | } |
| 15588 | | TypeTableEntry *child_type = type_entry->data.maybe.child_type; |
| 15589 | | TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 15768 | ZigType *child_type = type_entry->data.maybe.child_type; |
| 15769 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 15590 | 15770 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 15591 | 15771 | PtrLenSingle, |
| 15592 | 15772 | get_abi_alignment(ira->codegen, child_type), 0, 0); |
| ... | ... | @@ -15595,7 +15775,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, |
| 15595 | 15775 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| 15596 | 15776 | if (!val) |
| 15597 | 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 | 15782 | if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 15601 | 15783 | if (optional_value_is_null(maybe_val)) { |
| ... | ... | @@ -15619,12 +15801,12 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, |
| 15619 | 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 | 15805 | IrInstruction *value = ctz_instruction->value->other; |
| 15624 | 15806 | if (type_is_invalid(value->value.type)) { |
| 15625 | 15807 | return ira->codegen->builtin_types.entry_invalid; |
| 15626 | | } else if (value->value.type->id == TypeTableEntryIdInt) { |
| 15627 | | TypeTableEntry *return_type = get_smallest_unsigned_int_type(ira->codegen, |
| 15808 | } else if (value->value.type->id == ZigTypeIdInt) { |
| 15809 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, |
| 15628 | 15810 | value->value.type->data.integral.bit_count); |
| 15629 | 15811 | if (value->value.special != ConstValSpecialRuntime) { |
| 15630 | 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 | 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 | 15829 | IrInstruction *value = clz_instruction->value->other; |
| 15648 | 15830 | if (type_is_invalid(value->value.type)) { |
| 15649 | 15831 | return ira->codegen->builtin_types.entry_invalid; |
| 15650 | | } else if (value->value.type->id == TypeTableEntryIdInt) { |
| 15651 | | TypeTableEntry *return_type = get_smallest_unsigned_int_type(ira->codegen, |
| 15832 | } else if (value->value.type->id == ZigTypeIdInt) { |
| 15833 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, |
| 15652 | 15834 | value->value.type->data.integral.bit_count); |
| 15653 | 15835 | if (value->value.special != ConstValSpecialRuntime) { |
| 15654 | 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 | 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 | 15853 | IrInstruction *value = instruction->value->other; |
| 15672 | 15854 | if (type_is_invalid(value->value.type)) |
| 15673 | 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 | 15858 | ir_add_error(ira, value, |
| 15677 | 15859 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name))); |
| 15678 | 15860 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -15688,7 +15870,7 @@ static TypeTableEntry *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstru |
| 15688 | 15870 | bigint_init_unsigned(&out_val->data.x_bigint, result); |
| 15689 | 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 | 15874 | Buf *val_buf = buf_alloc(); |
| 15693 | 15875 | bigint_append_buf(val_buf, &val->data.x_bigint, 10); |
| 15694 | 15876 | ir_add_error(ira, &instruction->base, |
| ... | ... | @@ -15713,11 +15895,11 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source |
| 15713 | 15895 | if (type_is_invalid(value->value.type)) |
| 15714 | 15896 | return ira->codegen->invalid_instruction; |
| 15715 | 15897 | |
| 15716 | | if (value->value.type->id == TypeTableEntryIdEnum) { |
| 15898 | if (value->value.type->id == ZigTypeIdEnum) { |
| 15717 | 15899 | return value; |
| 15718 | 15900 | } |
| 15719 | 15901 | |
| 15720 | | if (value->value.type->id != TypeTableEntryIdUnion) { |
| 15902 | if (value->value.type->id != ZigTypeIdUnion) { |
| 15721 | 15903 | ir_add_error(ira, value, |
| 15722 | 15904 | buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value.type->name))); |
| 15723 | 15905 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -15731,8 +15913,8 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source |
| 15731 | 15913 | return ira->codegen->invalid_instruction; |
| 15732 | 15914 | } |
| 15733 | 15915 | |
| 15734 | | TypeTableEntry *tag_type = value->value.type->data.unionation.tag_type; |
| 15735 | | assert(tag_type->id == TypeTableEntryIdEnum); |
| 15916 | ZigType *tag_type = value->value.type->data.unionation.tag_type; |
| 15917 | assert(tag_type->id == ZigTypeIdEnum); |
| 15736 | 15918 | |
| 15737 | 15919 | if (instr_is_comptime(value)) { |
| 15738 | 15920 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| ... | ... | @@ -15752,7 +15934,7 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source |
| 15752 | 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 | 15938 | IrInstructionSwitchBr *switch_br_instruction) |
| 15757 | 15939 | { |
| 15758 | 15940 | IrInstruction *target_value = switch_br_instruction->target_value->other; |
| ... | ... | @@ -15784,7 +15966,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 15784 | 15966 | if (type_is_invalid(case_value->value.type)) |
| 15785 | 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 | 15970 | case_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, case_value); |
| 15789 | 15971 | if (type_is_invalid(case_value->value.type)) |
| 15790 | 15972 | return ir_unreach_error(ira); |
| ... | ... | @@ -15831,7 +16013,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 15831 | 16013 | if (type_is_invalid(new_value->value.type)) |
| 15832 | 16014 | continue; |
| 15833 | 16015 | |
| 15834 | | if (new_value->value.type->id == TypeTableEntryIdEnum) { |
| 16016 | if (new_value->value.type->id == ZigTypeIdEnum) { |
| 15835 | 16017 | new_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, new_value); |
| 15836 | 16018 | if (type_is_invalid(new_value->value.type)) |
| 15837 | 16019 | continue; |
| ... | ... | @@ -15860,7 +16042,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 15860 | 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 | 16046 | IrInstructionSwitchTarget *switch_target_instruction) |
| 15865 | 16047 | { |
| 15866 | 16048 | Error err; |
| ... | ... | @@ -15868,25 +16050,28 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 15868 | 16050 | if (type_is_invalid(target_value_ptr->value.type)) |
| 15869 | 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 | 16054 | assert(instr_is_comptime(target_value_ptr)); |
| 15873 | | TypeTableEntry *ptr_type = target_value_ptr->value.data.x_type; |
| 15874 | | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 16055 | ZigType *ptr_type = target_value_ptr->value.data.x_type; |
| 16056 | assert(ptr_type->id == ZigTypeIdPointer); |
| 15875 | 16057 | ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); |
| 15876 | 16058 | out_val->type = ira->codegen->builtin_types.entry_type; |
| 15877 | 16059 | out_val->data.x_type = ptr_type->data.pointer.child_type; |
| 15878 | 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 | 16064 | ir_add_error(ira, target_value_ptr, buf_sprintf("invalid deref on switch target")); |
| 15883 | 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 | 16069 | ConstExprValue *pointee_val = nullptr; |
| 15888 | 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 | 16075 | if (pointee_val->special == ConstValSpecialRuntime) |
| 15891 | 16076 | pointee_val = nullptr; |
| 15892 | 16077 | } |
| ... | ... | @@ -15894,20 +16079,20 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 15894 | 16079 | return ira->codegen->builtin_types.entry_invalid; |
| 15895 | 16080 | |
| 15896 | 16081 | switch (target_type->id) { |
| 15897 | | case TypeTableEntryIdInvalid: |
| 16082 | case ZigTypeIdInvalid: |
| 15898 | 16083 | zig_unreachable(); |
| 15899 | | case TypeTableEntryIdMetaType: |
| 15900 | | case TypeTableEntryIdVoid: |
| 15901 | | case TypeTableEntryIdBool: |
| 15902 | | case TypeTableEntryIdInt: |
| 15903 | | case TypeTableEntryIdFloat: |
| 15904 | | case TypeTableEntryIdComptimeFloat: |
| 15905 | | case TypeTableEntryIdComptimeInt: |
| 15906 | | case TypeTableEntryIdPointer: |
| 15907 | | case TypeTableEntryIdPromise: |
| 15908 | | case TypeTableEntryIdFn: |
| 15909 | | case TypeTableEntryIdNamespace: |
| 15910 | | case TypeTableEntryIdErrorSet: |
| 16084 | case ZigTypeIdMetaType: |
| 16085 | case ZigTypeIdVoid: |
| 16086 | case ZigTypeIdBool: |
| 16087 | case ZigTypeIdInt: |
| 16088 | case ZigTypeIdFloat: |
| 16089 | case ZigTypeIdComptimeFloat: |
| 16090 | case ZigTypeIdComptimeInt: |
| 16091 | case ZigTypeIdPointer: |
| 16092 | case ZigTypeIdPromise: |
| 16093 | case ZigTypeIdFn: |
| 16094 | case ZigTypeIdNamespace: |
| 16095 | case ZigTypeIdErrorSet: |
| 15911 | 16096 | if (pointee_val) { |
| 15912 | 16097 | ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); |
| 15913 | 16098 | copy_const_val(out_val, pointee_val, true); |
| ... | ... | @@ -15917,7 +16102,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 15917 | 16102 | |
| 15918 | 16103 | ir_build_load_ptr_from(&ira->new_irb, &switch_target_instruction->base, target_value_ptr); |
| 15919 | 16104 | return target_type; |
| 15920 | | case TypeTableEntryIdUnion: { |
| 16105 | case ZigTypeIdUnion: { |
| 15921 | 16106 | AstNode *decl_node = target_type->data.unionation.decl_node; |
| 15922 | 16107 | if (!decl_node->data.container_decl.auto_enum && |
| 15923 | 16108 | decl_node->data.container_decl.init_arg_expr == nullptr) |
| ... | ... | @@ -15928,9 +16113,9 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 15928 | 16113 | buf_sprintf("consider 'union(enum)' here")); |
| 15929 | 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 | 16117 | assert(tag_type != nullptr); |
| 15933 | | assert(tag_type->id == TypeTableEntryIdEnum); |
| 16118 | assert(tag_type->id == ZigTypeIdEnum); |
| 15934 | 16119 | if (pointee_val) { |
| 15935 | 16120 | ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); |
| 15936 | 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 | 16138 | ir_link_new_instruction(union_tag_inst, &switch_target_instruction->base); |
| 15954 | 16139 | return tag_type; |
| 15955 | 16140 | } |
| 15956 | | case TypeTableEntryIdEnum: { |
| 16141 | case ZigTypeIdEnum: { |
| 15957 | 16142 | if ((err = type_ensure_zero_bits_known(ira->codegen, target_type))) |
| 15958 | 16143 | return ira->codegen->builtin_types.entry_invalid; |
| 15959 | 16144 | if (target_type->data.enumeration.src_field_count < 2) { |
| ... | ... | @@ -15975,17 +16160,17 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 15975 | 16160 | ir_link_new_instruction(enum_value, &switch_target_instruction->base); |
| 15976 | 16161 | return target_type; |
| 15977 | 16162 | } |
| 15978 | | case TypeTableEntryIdErrorUnion: |
| 15979 | | case TypeTableEntryIdUnreachable: |
| 15980 | | case TypeTableEntryIdArray: |
| 15981 | | case TypeTableEntryIdStruct: |
| 15982 | | case TypeTableEntryIdUndefined: |
| 15983 | | case TypeTableEntryIdNull: |
| 15984 | | case TypeTableEntryIdOptional: |
| 15985 | | case TypeTableEntryIdBlock: |
| 15986 | | case TypeTableEntryIdBoundFn: |
| 15987 | | case TypeTableEntryIdArgTuple: |
| 15988 | | case TypeTableEntryIdOpaque: |
| 16163 | case ZigTypeIdErrorUnion: |
| 16164 | case ZigTypeIdUnreachable: |
| 16165 | case ZigTypeIdArray: |
| 16166 | case ZigTypeIdStruct: |
| 16167 | case ZigTypeIdUndefined: |
| 16168 | case ZigTypeIdNull: |
| 16169 | case ZigTypeIdOptional: |
| 16170 | case ZigTypeIdBlock: |
| 16171 | case ZigTypeIdBoundFn: |
| 16172 | case ZigTypeIdArgTuple: |
| 16173 | case ZigTypeIdOpaque: |
| 15989 | 16174 | ir_add_error(ira, &switch_target_instruction->base, |
| 15990 | 16175 | buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name))); |
| 15991 | 16176 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -15993,7 +16178,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 15993 | 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 | 16182 | IrInstruction *target_value_ptr = instruction->target_value_ptr->other; |
| 15998 | 16183 | if (type_is_invalid(target_value_ptr->value.type)) |
| 15999 | 16184 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -16002,14 +16187,14 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr |
| 16002 | 16187 | if (type_is_invalid(prong_value->value.type)) |
| 16003 | 16188 | return ira->codegen->builtin_types.entry_invalid; |
| 16004 | 16189 | |
| 16005 | | assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer); |
| 16006 | | TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 16007 | | if (target_type->id == TypeTableEntryIdUnion) { |
| 16190 | assert(target_value_ptr->value.type->id == ZigTypeIdPointer); |
| 16191 | ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 16192 | if (target_type->id == ZigTypeIdUnion) { |
| 16008 | 16193 | ConstExprValue *prong_val = ir_resolve_const(ira, prong_value, UndefBad); |
| 16009 | 16194 | if (!prong_val) |
| 16010 | 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 | 16198 | TypeUnionField *field = find_union_field_by_tag(target_type, &prong_val->data.x_enum_tag); |
| 16014 | 16199 | |
| 16015 | 16200 | if (instr_is_comptime(target_value_ptr)) { |
| ... | ... | @@ -16017,7 +16202,10 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr |
| 16017 | 16202 | if (!target_value_ptr) |
| 16018 | 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 | 16209 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 16022 | 16210 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 16023 | 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 | 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 | 16227 | IrInstruction *value = instruction->value->other; |
| 16040 | 16228 | IrInstruction *new_instruction = ir_analyze_union_tag(ira, &instruction->base, value); |
| 16041 | 16229 | ir_link_new_instruction(new_instruction, &instruction->base); |
| 16042 | 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 | 16234 | IrInstruction *name_value = import_instruction->name->other; |
| 16047 | 16235 | Buf *import_target_str = ir_resolve_str(ira, name_value); |
| 16048 | 16236 | if (!import_target_str) |
| ... | ... | @@ -16074,29 +16262,20 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi |
| 16074 | 16262 | os_path_join(search_dir, import_target_path, &full_path); |
| 16075 | 16263 | |
| 16076 | 16264 | Buf *import_code = buf_alloc(); |
| 16077 | | Buf *abs_full_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 | | } |
| 16265 | Buf *resolved_path = buf_alloc(); |
| 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 | 16271 | if (import_entry) { |
| 16094 | 16272 | ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base); |
| 16095 | 16273 | out_val->data.x_import = import_entry->value; |
| 16096 | 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 | 16279 | if (err == ErrorFileNotFound) { |
| 16101 | 16280 | ir_add_error_node(ira, source_node, |
| 16102 | 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 | 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 | 16291 | scan_import(ira->codegen, target_import); |
| 16113 | 16292 | |
| ... | ... | @@ -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 | 16300 | IrInstructionArrayLen *array_len_instruction) |
| 16122 | 16301 | { |
| 16123 | 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 | 16304 | if (type_is_invalid(type_entry)) { |
| 16126 | 16305 | return ira->codegen->builtin_types.entry_invalid; |
| 16127 | | } else if (type_entry->id == TypeTableEntryIdArray) { |
| 16306 | } else if (type_entry->id == ZigTypeIdArray) { |
| 16128 | 16307 | return ir_analyze_const_usize(ira, &array_len_instruction->base, |
| 16129 | 16308 | type_entry->data.array.len); |
| 16130 | 16309 | } else if (is_slice(type_entry)) { |
| ... | ... | @@ -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 | 16331 | IrInstruction *value = ref_instruction->value->other; |
| 16153 | 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, |
| 16157 | | TypeTableEntry *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields) |
| 16335 | static ZigType *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruction *instruction, |
| 16336 | ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields) |
| 16158 | 16337 | { |
| 16159 | 16338 | Error err; |
| 16160 | | assert(container_type->id == TypeTableEntryIdUnion); |
| 16339 | assert(container_type->id == ZigTypeIdUnion); |
| 16161 | 16340 | |
| 16162 | 16341 | if ((err = ensure_complete_type(ira->codegen, container_type))) |
| 16163 | 16342 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -16219,14 +16398,14 @@ static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, Ir |
| 16219 | 16398 | return container_type; |
| 16220 | 16399 | } |
| 16221 | 16400 | |
| 16222 | | static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction, |
| 16223 | | TypeTableEntry *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields) |
| 16401 | static ZigType *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction, |
| 16402 | ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields) |
| 16224 | 16403 | { |
| 16225 | 16404 | Error err; |
| 16226 | | if (container_type->id == TypeTableEntryIdUnion) { |
| 16405 | if (container_type->id == ZigTypeIdUnion) { |
| 16227 | 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 | 16409 | ir_add_error(ira, instruction, |
| 16231 | 16410 | buf_sprintf("type '%s' does not support struct initialization syntax", |
| 16232 | 16411 | buf_ptr(&container_type->name))); |
| ... | ... | @@ -16339,7 +16518,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru |
| 16339 | 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 | 16522 | IrInstructionContainerInitList *instruction) |
| 16344 | 16523 | { |
| 16345 | 16524 | IrInstruction *container_type_value = instruction->container_type->other; |
| ... | ... | @@ -16347,21 +16526,21 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 16347 | 16526 | return ira->codegen->builtin_types.entry_invalid; |
| 16348 | 16527 | |
| 16349 | 16528 | size_t elem_count = instruction->item_count; |
| 16350 | | if (container_type_value->value.type->id == TypeTableEntryIdMetaType) { |
| 16351 | | TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value); |
| 16529 | if (container_type_value->value.type->id == ZigTypeIdMetaType) { |
| 16530 | ZigType *container_type = ir_resolve_type(ira, container_type_value); |
| 16352 | 16531 | if (type_is_invalid(container_type)) |
| 16353 | 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 | 16535 | return ir_analyze_container_init_fields(ira, &instruction->base, container_type, |
| 16357 | 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 | 16538 | // array is same as slice init but we make a compile error if the length is wrong |
| 16360 | | TypeTableEntry *child_type; |
| 16361 | | if (container_type->id == TypeTableEntryIdArray) { |
| 16539 | ZigType *child_type; |
| 16540 | if (container_type->id == ZigTypeIdArray) { |
| 16362 | 16541 | child_type = container_type->data.array.child_type; |
| 16363 | 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 | 16545 | ir_add_error(ira, &instruction->base, |
| 16367 | 16546 | buf_sprintf("expected %s literal, found %s literal", |
| ... | ... | @@ -16369,12 +16548,12 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 16369 | 16548 | return ira->codegen->builtin_types.entry_invalid; |
| 16370 | 16549 | } |
| 16371 | 16550 | } else { |
| 16372 | | TypeTableEntry *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry; |
| 16373 | | assert(pointer_type->id == TypeTableEntryIdPointer); |
| 16551 | ZigType *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry; |
| 16552 | assert(pointer_type->id == ZigTypeIdPointer); |
| 16374 | 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 | 16558 | ConstExprValue const_val = {}; |
| 16380 | 16559 | const_val.special = ConstValSpecialStatic; |
| ... | ... | @@ -16437,7 +16616,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 16437 | 16616 | container_type_value, elem_count, new_items); |
| 16438 | 16617 | ir_add_alloca(ira, new_instruction, fixed_size_array_type); |
| 16439 | 16618 | return fixed_size_array_type; |
| 16440 | | } else if (container_type->id == TypeTableEntryIdVoid) { |
| 16619 | } else if (container_type->id == ZigTypeIdVoid) { |
| 16441 | 16620 | if (elem_count != 0) { |
| 16442 | 16621 | ir_add_error_node(ira, instruction->base.source_node, |
| 16443 | 16622 | buf_sprintf("void expression expects no arguments")); |
| ... | ... | @@ -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 | 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 | 16642 | if (type_is_invalid(container_type)) |
| 16464 | 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 | 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 | 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 | 16653 | if (type_is_invalid(target_type)) |
| 16475 | 16654 | return ira->codegen->builtin_types.entry_invalid; |
| 16476 | 16655 | switch (target_type->id) { |
| 16477 | | case TypeTableEntryIdInvalid: |
| 16656 | case ZigTypeIdInvalid: |
| 16478 | 16657 | zig_unreachable(); |
| 16479 | | case TypeTableEntryIdInt: |
| 16658 | case ZigTypeIdInt: |
| 16480 | 16659 | { |
| 16481 | 16660 | ConstExprValue *out_val = ir_build_const_from(ira, source_instruction); |
| 16482 | 16661 | eval_min_max_value(ira->codegen, target_type, out_val, is_max); |
| 16483 | 16662 | return ira->codegen->builtin_types.entry_num_lit_int; |
| 16484 | 16663 | } |
| 16485 | | case TypeTableEntryIdBool: |
| 16486 | | case TypeTableEntryIdVoid: |
| 16664 | case ZigTypeIdBool: |
| 16665 | case ZigTypeIdVoid: |
| 16487 | 16666 | { |
| 16488 | 16667 | ConstExprValue *out_val = ir_build_const_from(ira, source_instruction); |
| 16489 | 16668 | eval_min_max_value(ira->codegen, target_type, out_val, is_max); |
| 16490 | 16669 | return target_type; |
| 16491 | 16670 | } |
| 16492 | | case TypeTableEntryIdEnum: |
| 16493 | | case TypeTableEntryIdFloat: |
| 16494 | | case TypeTableEntryIdMetaType: |
| 16495 | | case TypeTableEntryIdUnreachable: |
| 16496 | | case TypeTableEntryIdPointer: |
| 16497 | | case TypeTableEntryIdPromise: |
| 16498 | | case TypeTableEntryIdArray: |
| 16499 | | case TypeTableEntryIdStruct: |
| 16500 | | case TypeTableEntryIdComptimeFloat: |
| 16501 | | case TypeTableEntryIdComptimeInt: |
| 16502 | | case TypeTableEntryIdUndefined: |
| 16503 | | case TypeTableEntryIdNull: |
| 16504 | | case TypeTableEntryIdOptional: |
| 16505 | | case TypeTableEntryIdErrorUnion: |
| 16506 | | case TypeTableEntryIdErrorSet: |
| 16507 | | case TypeTableEntryIdUnion: |
| 16508 | | case TypeTableEntryIdFn: |
| 16509 | | case TypeTableEntryIdNamespace: |
| 16510 | | case TypeTableEntryIdBlock: |
| 16511 | | case TypeTableEntryIdBoundFn: |
| 16512 | | case TypeTableEntryIdArgTuple: |
| 16513 | | case TypeTableEntryIdOpaque: |
| 16671 | case ZigTypeIdEnum: |
| 16672 | case ZigTypeIdFloat: |
| 16673 | case ZigTypeIdMetaType: |
| 16674 | case ZigTypeIdUnreachable: |
| 16675 | case ZigTypeIdPointer: |
| 16676 | case ZigTypeIdPromise: |
| 16677 | case ZigTypeIdArray: |
| 16678 | case ZigTypeIdStruct: |
| 16679 | case ZigTypeIdComptimeFloat: |
| 16680 | case ZigTypeIdComptimeInt: |
| 16681 | case ZigTypeIdUndefined: |
| 16682 | case ZigTypeIdNull: |
| 16683 | case ZigTypeIdOptional: |
| 16684 | case ZigTypeIdErrorUnion: |
| 16685 | case ZigTypeIdErrorSet: |
| 16686 | case ZigTypeIdUnion: |
| 16687 | case ZigTypeIdFn: |
| 16688 | case ZigTypeIdNamespace: |
| 16689 | case ZigTypeIdBlock: |
| 16690 | case ZigTypeIdBoundFn: |
| 16691 | case ZigTypeIdArgTuple: |
| 16692 | case ZigTypeIdOpaque: |
| 16514 | 16693 | { |
| 16515 | 16694 | const char *err_format = is_max ? |
| 16516 | 16695 | "no max value available for type '%s'" : |
| ... | ... | @@ -16523,19 +16702,19 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_ |
| 16523 | 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 | 16706 | IrInstructionMinValue *instruction) |
| 16528 | 16707 | { |
| 16529 | 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 | 16712 | IrInstructionMaxValue *instruction) |
| 16534 | 16713 | { |
| 16535 | 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 | 16718 | IrInstructionCompileErr *instruction) |
| 16540 | 16719 | { |
| 16541 | 16720 | IrInstruction *msg_value = instruction->msg->other; |
| ... | ... | @@ -16559,7 +16738,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira, |
| 16559 | 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 | 16742 | Buf buf = BUF_INIT; |
| 16564 | 16743 | fprintf(stderr, "| "); |
| 16565 | 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 | 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 | 16762 | IrInstruction *value = instruction->value->other; |
| 16584 | 16763 | if (type_is_invalid(value->value.type)) |
| 16585 | 16764 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -16588,9 +16767,9 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc |
| 16588 | 16767 | if (type_is_invalid(casted_value->value.type)) |
| 16589 | 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 | 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 | 16773 | if (casted_value->value.special == ConstValSpecialStatic) { |
| 16595 | 16774 | ErrorTableEntry *err = casted_value->value.data.x_err_set; |
| 16596 | 16775 | if (!err->cached_error_name_val) { |
| ... | ... | @@ -16607,13 +16786,13 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc |
| 16607 | 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 | 16790 | Error err; |
| 16612 | 16791 | IrInstruction *target = instruction->target->other; |
| 16613 | 16792 | if (type_is_invalid(target->value.type)) |
| 16614 | 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 | 16797 | if (instr_is_comptime(target)) { |
| 16619 | 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 | 16807 | IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope, |
| 16629 | 16808 | instruction->base.source_node, target); |
| 16630 | 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 | 16811 | ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 16633 | 16812 | true, false, PtrLenUnknown, |
| 16634 | 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 | 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 | 16820 | IrInstructionFieldParentPtr *instruction) |
| 16642 | 16821 | { |
| 16643 | 16822 | Error err; |
| 16644 | 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 | 16825 | if (type_is_invalid(container_type)) |
| 16647 | 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 | 16834 | if (type_is_invalid(field_ptr->value.type)) |
| 16656 | 16835 | return ira->codegen->builtin_types.entry_invalid; |
| 16657 | 16836 | |
| 16658 | | if (container_type->id != TypeTableEntryIdStruct) { |
| 16837 | if (container_type->id != ZigTypeIdStruct) { |
| 16659 | 16838 | ir_add_error(ira, type_value, |
| 16660 | 16839 | buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name))); |
| 16661 | 16840 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -16672,7 +16851,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 16672 | 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 | 16855 | ir_add_error(ira, field_ptr, |
| 16677 | 16856 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name))); |
| 16678 | 16857 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -16682,7 +16861,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 16682 | 16861 | uint32_t field_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, field->type_entry); |
| 16683 | 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 | 16865 | field_ptr->value.type->data.pointer.is_const, |
| 16687 | 16866 | field_ptr->value.type->data.pointer.is_volatile, |
| 16688 | 16867 | PtrLenSingle, |
| ... | ... | @@ -16691,7 +16870,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 16691 | 16870 | if (type_is_invalid(casted_field_ptr->value.type)) |
| 16692 | 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 | 16874 | casted_field_ptr->value.type->data.pointer.is_const, |
| 16696 | 16875 | casted_field_ptr->value.type->data.pointer.is_volatile, |
| 16697 | 16876 | PtrLenSingle, |
| ... | ... | @@ -16730,12 +16909,12 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 16730 | 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 | 16913 | IrInstructionOffsetOf *instruction) |
| 16735 | 16914 | { |
| 16736 | 16915 | Error err; |
| 16737 | 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 | 16918 | if (type_is_invalid(container_type)) |
| 16740 | 16919 | return ira->codegen->builtin_types.entry_invalid; |
| 16741 | 16920 | |
| ... | ... | @@ -16747,7 +16926,7 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira, |
| 16747 | 16926 | if (!field_name) |
| 16748 | 16927 | return ira->codegen->builtin_types.entry_invalid; |
| 16749 | 16928 | |
| 16750 | | if (container_type->id != TypeTableEntryIdStruct) { |
| 16929 | if (container_type->id != ZigTypeIdStruct) { |
| 16751 | 16930 | ir_add_error(ira, type_value, |
| 16752 | 16931 | buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name))); |
| 16753 | 16932 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -16773,7 +16952,7 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira, |
| 16773 | 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 | 16957 | Buf *field_name_buf; |
| 16779 | 16958 | |
| ... | ... | @@ -16784,17 +16963,17 @@ static void ensure_field_index(TypeTableEntry *type, const char *field_name, siz |
| 16784 | 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 | 16967 | Error err; |
| 16789 | 16968 | static ConstExprValue *type_info_var = nullptr; |
| 16790 | | static TypeTableEntry *type_info_type = nullptr; |
| 16969 | static ZigType *type_info_type = nullptr; |
| 16791 | 16970 | if (type_info_var == nullptr) { |
| 16792 | 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 | 16974 | assertNoError(ensure_complete_type(ira->codegen, type_info_var->data.x_type)); |
| 16796 | 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 | 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 | 16981 | else if (type_name == nullptr) |
| 16803 | 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 | 16986 | ScopeDecls *type_info_scope = get_container_scope(root_type); |
| 16808 | 16987 | assert(type_info_scope != nullptr); |
| ... | ... | @@ -16815,17 +16994,17 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na |
| 16815 | 16994 | TldVar *tld = (TldVar *)entry; |
| 16816 | 16995 | assert(tld->base.id == TldIdVar); |
| 16817 | 16996 | |
| 16818 | | VariableTableEntry *var = tld->var; |
| 16997 | ZigVar *var = tld->var; |
| 16819 | 16998 | |
| 16820 | 16999 | if ((err = ensure_complete_type(ira->codegen, var->value->type))) |
| 16821 | 17000 | return ira->codegen->builtin_types.entry_invalid; |
| 16822 | | assert(var->value->type->id == TypeTableEntryIdMetaType); |
| 17001 | assert(var->value->type->id == ZigTypeIdMetaType); |
| 16823 | 17002 | return var->value->data.x_type; |
| 16824 | 17003 | } |
| 16825 | 17004 | |
| 16826 | 17005 | static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope) { |
| 16827 | 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 | 17008 | if ((err = ensure_complete_type(ira->codegen, type_info_definition_type))) |
| 16830 | 17009 | return err; |
| 16831 | 17010 | |
| ... | ... | @@ -16833,15 +17012,15 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 16833 | 17012 | ensure_field_index(type_info_definition_type, "is_pub", 1); |
| 16834 | 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 | 17016 | if ((err = ensure_complete_type(ira->codegen, type_info_definition_data_type))) |
| 16838 | 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 | 17020 | if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_type))) |
| 16842 | 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 | 17024 | if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_inline_type))) |
| 16846 | 17025 | return err; |
| 16847 | 17026 | |
| ... | ... | @@ -16862,7 +17041,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 16862 | 17041 | // Skip comptime blocks and test functions. |
| 16863 | 17042 | if (curr_entry->value->id != TldIdCompTime) { |
| 16864 | 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 | 17045 | if (fn_entry->is_test) |
| 16867 | 17046 | continue; |
| 16868 | 17047 | } |
| ... | ... | @@ -16888,7 +17067,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 16888 | 17067 | if (curr_entry->value->id == TldIdCompTime) { |
| 16889 | 17068 | continue; |
| 16890 | 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 | 17071 | if (fn_entry->is_test) |
| 16893 | 17072 | continue; |
| 16894 | 17073 | } |
| ... | ... | @@ -16913,11 +17092,11 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 16913 | 17092 | switch (curr_entry->value->id) { |
| 16914 | 17093 | case TldIdVar: |
| 16915 | 17094 | { |
| 16916 | | VariableTableEntry *var = ((TldVar *)curr_entry->value)->var; |
| 17095 | ZigVar *var = ((TldVar *)curr_entry->value)->var; |
| 16917 | 17096 | if ((err = ensure_complete_type(ira->codegen, var->value->type))) |
| 16918 | 17097 | return ErrorSemanticAnalyzeFail; |
| 16919 | 17098 | |
| 16920 | | if (var->value->type->id == TypeTableEntryIdMetaType) |
| 17099 | if (var->value->type->id == ZigTypeIdMetaType) |
| 16921 | 17100 | { |
| 16922 | 17101 | // We have a variable of type 'type', so it's actually a type definition. |
| 16923 | 17102 | // 0: Data.Type: type |
| ... | ... | @@ -16944,7 +17123,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 16944 | 17123 | // 2: Data.Fn: Data.FnDef |
| 16945 | 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 | 17127 | assert(!fn_entry->is_test); |
| 16949 | 17128 | |
| 16950 | 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 | 17171 | // lib_name: ?[]const u8 |
| 16993 | 17172 | ensure_field_index(fn_def_val->type, "lib_name", 6); |
| 16994 | 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 | 17175 | ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 16997 | 17176 | true, false, PtrLenUnknown, |
| 16998 | 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 | 17209 | |
| 17031 | 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 | 17213 | ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.s_none.elements[fn_arg_index]; |
| 17035 | 17214 | ConstExprValue *arg_name = create_const_str_lit(ira->codegen, &arg_var->name); |
| 17036 | 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 | 17223 | } |
| 17045 | 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 | 17227 | if ((err = ensure_complete_type(ira->codegen, type_entry))) |
| 17049 | 17228 | return ErrorSemanticAnalyzeFail; |
| 17050 | 17229 | |
| ... | ... | @@ -17071,20 +17250,20 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 17071 | 17250 | return ErrorNone; |
| 17072 | 17251 | } |
| 17073 | 17252 | |
| 17074 | | static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry *ptr_type_entry) { |
| 17075 | | TypeTableEntry *attrs_type; |
| 17253 | static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_entry) { |
| 17254 | ZigType *attrs_type; |
| 17076 | 17255 | uint32_t size_enum_index; |
| 17077 | 17256 | if (is_slice(ptr_type_entry)) { |
| 17078 | 17257 | attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index].type_entry; |
| 17079 | 17258 | size_enum_index = 2; |
| 17080 | | } else if (ptr_type_entry->id == TypeTableEntryIdPointer) { |
| 17259 | } else if (ptr_type_entry->id == ZigTypeIdPointer) { |
| 17081 | 17260 | attrs_type = ptr_type_entry; |
| 17082 | 17261 | size_enum_index = (ptr_type_entry->data.pointer.ptr_len == PtrLenSingle) ? 0 : 1; |
| 17083 | 17262 | } else { |
| 17084 | 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 | 17267 | assertNoError(ensure_complete_type(ira->codegen, type_info_pointer_type)); |
| 17089 | 17268 | |
| 17090 | 17269 | ConstExprValue *result = create_const_vals(1); |
| ... | ... | @@ -17096,7 +17275,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry |
| 17096 | 17275 | |
| 17097 | 17276 | // size: Size |
| 17098 | 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 | 17279 | assertNoError(ensure_complete_type(ira->codegen, type_info_pointer_size_type)); |
| 17101 | 17280 | fields[0].special = ConstValSpecialStatic; |
| 17102 | 17281 | fields[0].type = type_info_pointer_size_type; |
| ... | ... | @@ -17127,7 +17306,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry |
| 17127 | 17306 | }; |
| 17128 | 17307 | |
| 17129 | 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 | 17311 | enum_field_val->special = ConstValSpecialStatic; |
| 17133 | 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 | 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 | 17327 | Error err; |
| 17149 | 17328 | assert(type_entry != nullptr); |
| 17150 | 17329 | assert(!type_is_invalid(type_entry)); |
| ... | ... | @@ -17159,20 +17338,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17159 | 17338 | ConstExprValue *result = nullptr; |
| 17160 | 17339 | switch (type_entry->id) |
| 17161 | 17340 | { |
| 17162 | | case TypeTableEntryIdInvalid: |
| 17341 | case ZigTypeIdInvalid: |
| 17163 | 17342 | zig_unreachable(); |
| 17164 | | case TypeTableEntryIdMetaType: |
| 17165 | | case TypeTableEntryIdVoid: |
| 17166 | | case TypeTableEntryIdBool: |
| 17167 | | case TypeTableEntryIdUnreachable: |
| 17168 | | case TypeTableEntryIdComptimeFloat: |
| 17169 | | case TypeTableEntryIdComptimeInt: |
| 17170 | | case TypeTableEntryIdUndefined: |
| 17171 | | case TypeTableEntryIdNull: |
| 17172 | | case TypeTableEntryIdNamespace: |
| 17173 | | case TypeTableEntryIdBlock: |
| 17174 | | case TypeTableEntryIdArgTuple: |
| 17175 | | case TypeTableEntryIdOpaque: |
| 17343 | case ZigTypeIdMetaType: |
| 17344 | case ZigTypeIdVoid: |
| 17345 | case ZigTypeIdBool: |
| 17346 | case ZigTypeIdUnreachable: |
| 17347 | case ZigTypeIdComptimeFloat: |
| 17348 | case ZigTypeIdComptimeInt: |
| 17349 | case ZigTypeIdUndefined: |
| 17350 | case ZigTypeIdNull: |
| 17351 | case ZigTypeIdNamespace: |
| 17352 | case ZigTypeIdBlock: |
| 17353 | case ZigTypeIdArgTuple: |
| 17354 | case ZigTypeIdOpaque: |
| 17176 | 17355 | *out = nullptr; |
| 17177 | 17356 | return ErrorNone; |
| 17178 | 17357 | default: |
| ... | ... | @@ -17186,7 +17365,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17186 | 17365 | |
| 17187 | 17366 | // Fallthrough if we don't find one. |
| 17188 | 17367 | } |
| 17189 | | case TypeTableEntryIdInt: |
| 17368 | case ZigTypeIdInt: |
| 17190 | 17369 | { |
| 17191 | 17370 | result = create_const_vals(1); |
| 17192 | 17371 | result->special = ConstValSpecialStatic; |
| ... | ... | @@ -17208,7 +17387,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17208 | 17387 | |
| 17209 | 17388 | break; |
| 17210 | 17389 | } |
| 17211 | | case TypeTableEntryIdFloat: |
| 17390 | case ZigTypeIdFloat: |
| 17212 | 17391 | { |
| 17213 | 17392 | result = create_const_vals(1); |
| 17214 | 17393 | result->special = ConstValSpecialStatic; |
| ... | ... | @@ -17225,12 +17404,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17225 | 17404 | |
| 17226 | 17405 | break; |
| 17227 | 17406 | } |
| 17228 | | case TypeTableEntryIdPointer: |
| 17407 | case ZigTypeIdPointer: |
| 17229 | 17408 | { |
| 17230 | 17409 | result = create_ptr_like_type_info(ira, type_entry); |
| 17231 | 17410 | break; |
| 17232 | 17411 | } |
| 17233 | | case TypeTableEntryIdArray: |
| 17412 | case ZigTypeIdArray: |
| 17234 | 17413 | { |
| 17235 | 17414 | result = create_const_vals(1); |
| 17236 | 17415 | result->special = ConstValSpecialStatic; |
| ... | ... | @@ -17252,7 +17431,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17252 | 17431 | |
| 17253 | 17432 | break; |
| 17254 | 17433 | } |
| 17255 | | case TypeTableEntryIdOptional: |
| 17434 | case ZigTypeIdOptional: |
| 17256 | 17435 | { |
| 17257 | 17436 | result = create_const_vals(1); |
| 17258 | 17437 | result->special = ConstValSpecialStatic; |
| ... | ... | @@ -17269,7 +17448,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17269 | 17448 | |
| 17270 | 17449 | break; |
| 17271 | 17450 | } |
| 17272 | | case TypeTableEntryIdPromise: |
| 17451 | case ZigTypeIdPromise: |
| 17273 | 17452 | { |
| 17274 | 17453 | result = create_const_vals(1); |
| 17275 | 17454 | result->special = ConstValSpecialStatic; |
| ... | ... | @@ -17295,7 +17474,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17295 | 17474 | |
| 17296 | 17475 | break; |
| 17297 | 17476 | } |
| 17298 | | case TypeTableEntryIdEnum: |
| 17477 | case ZigTypeIdEnum: |
| 17299 | 17478 | { |
| 17300 | 17479 | result = create_const_vals(1); |
| 17301 | 17480 | result->special = ConstValSpecialStatic; |
| ... | ... | @@ -17317,7 +17496,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17317 | 17496 | // fields: []TypeInfo.EnumField |
| 17318 | 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 | 17500 | uint32_t enum_field_count = type_entry->data.enumeration.src_field_count; |
| 17322 | 17501 | |
| 17323 | 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 | 17524 | |
| 17346 | 17525 | break; |
| 17347 | 17526 | } |
| 17348 | | case TypeTableEntryIdErrorSet: |
| 17527 | case ZigTypeIdErrorSet: |
| 17349 | 17528 | { |
| 17350 | 17529 | result = create_const_vals(1); |
| 17351 | 17530 | result->special = ConstValSpecialStatic; |
| ... | ... | @@ -17357,7 +17536,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17357 | 17536 | // errors: []TypeInfo.Error |
| 17358 | 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 | 17540 | uint32_t error_count = type_entry->data.error_set.err_count; |
| 17362 | 17541 | ConstExprValue *error_array = create_const_vals(1); |
| 17363 | 17542 | error_array->special = ConstValSpecialStatic; |
| ... | ... | @@ -17394,7 +17573,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17394 | 17573 | |
| 17395 | 17574 | break; |
| 17396 | 17575 | } |
| 17397 | | case TypeTableEntryIdErrorUnion: |
| 17576 | case ZigTypeIdErrorUnion: |
| 17398 | 17577 | { |
| 17399 | 17578 | result = create_const_vals(1); |
| 17400 | 17579 | result->special = ConstValSpecialStatic; |
| ... | ... | @@ -17417,7 +17596,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17417 | 17596 | |
| 17418 | 17597 | break; |
| 17419 | 17598 | } |
| 17420 | | case TypeTableEntryIdUnion: |
| 17599 | case ZigTypeIdUnion: |
| 17421 | 17600 | { |
| 17422 | 17601 | result = create_const_vals(1); |
| 17423 | 17602 | result->special = ConstValSpecialStatic; |
| ... | ... | @@ -17451,7 +17630,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17451 | 17630 | // fields: []TypeInfo.UnionField |
| 17452 | 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 | 17634 | uint32_t union_field_count = type_entry->data.unionation.src_field_count; |
| 17456 | 17635 | |
| 17457 | 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 | 17642 | |
| 17464 | 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 | 17647 | for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) { |
| 17469 | 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 | 17681 | |
| 17503 | 17682 | break; |
| 17504 | 17683 | } |
| 17505 | | case TypeTableEntryIdStruct: |
| 17684 | case ZigTypeIdStruct: |
| 17506 | 17685 | { |
| 17507 | 17686 | if (type_entry->data.structure.is_slice) { |
| 17508 | 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 | 17703 | // fields: []TypeInfo.StructField |
| 17525 | 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 | 17707 | uint32_t struct_field_count = type_entry->data.structure.src_field_count; |
| 17529 | 17708 | |
| 17530 | 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 | 17755 | |
| 17577 | 17756 | break; |
| 17578 | 17757 | } |
| 17579 | | case TypeTableEntryIdFn: |
| 17758 | case ZigTypeIdFn: |
| 17580 | 17759 | { |
| 17581 | 17760 | result = create_const_vals(1); |
| 17582 | 17761 | result->special = ConstValSpecialStatic; |
| ... | ... | @@ -17629,7 +17808,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17629 | 17808 | fields[4].data.x_optional = async_alloc_type; |
| 17630 | 17809 | } |
| 17631 | 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 | 17812 | size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count - |
| 17634 | 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 | 17860 | |
| 17682 | 17861 | break; |
| 17683 | 17862 | } |
| 17684 | | case TypeTableEntryIdBoundFn: |
| 17863 | case ZigTypeIdBoundFn: |
| 17685 | 17864 | { |
| 17686 | | TypeTableEntry *fn_type = type_entry->data.bound_fn.fn_type; |
| 17687 | | assert(fn_type->id == TypeTableEntryIdFn); |
| 17865 | ZigType *fn_type = type_entry->data.bound_fn.fn_type; |
| 17866 | assert(fn_type->id == ZigTypeIdFn); |
| 17688 | 17867 | if ((err = ir_make_type_info_value(ira, fn_type, &result))) |
| 17689 | 17868 | return err; |
| 17690 | 17869 | |
| ... | ... | @@ -17698,16 +17877,16 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, |
| 17698 | 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 | 17881 | IrInstructionTypeInfo *instruction) |
| 17703 | 17882 | { |
| 17704 | 17883 | Error err; |
| 17705 | 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 | 17886 | if (type_is_invalid(type_entry)) |
| 17708 | 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 | 17891 | ConstExprValue *payload; |
| 17713 | 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 | 17898 | out_val->data.x_union.payload = payload; |
| 17720 | 17899 | |
| 17721 | 17900 | if (payload != nullptr) { |
| 17722 | | assert(payload->type->id == TypeTableEntryIdStruct); |
| 17901 | assert(payload->type->id == ZigTypeIdStruct); |
| 17723 | 17902 | payload->data.x_struct.parent.id = ConstParentIdUnion; |
| 17724 | 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 | 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 | 17910 | IrInstructionTypeId *instruction) |
| 17732 | 17911 | { |
| 17733 | 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 | 17914 | if (type_is_invalid(type_entry)) |
| 17736 | 17915 | return ira->codegen->builtin_types.entry_invalid; |
| 17737 | 17916 | |
| 17738 | 17917 | ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeId"); |
| 17739 | | assert(var_value->type->id == TypeTableEntryIdMetaType); |
| 17740 | | TypeTableEntry *result_type = var_value->data.x_type; |
| 17918 | assert(var_value->type->id == ZigTypeIdMetaType); |
| 17919 | ZigType *result_type = var_value->data.x_type; |
| 17741 | 17920 | |
| 17742 | 17921 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 17743 | 17922 | bigint_init_unsigned(&out_val->data.x_enum_tag, type_id_index(type_entry)); |
| 17744 | 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 | 17927 | IrInstructionSetEvalBranchQuota *instruction) |
| 17749 | 17928 | { |
| 17750 | 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 | 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 | 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 | 17950 | if (type_is_invalid(type_entry)) |
| 17772 | 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 | 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 | 17962 | AstNode *node = instruction->base.source_node; |
| 17784 | 17963 | assert(node->type == NodeTypeFnCallExpr); |
| 17785 | 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 | 17966 | ScopeCImport *cimport_scope = create_cimport_scope(node, instruction->base.scope); |
| 17788 | 17967 | |
| 17789 | 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 | 17970 | IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type, |
| 17792 | 17971 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, |
| 17793 | 17972 | &cimport_scope->buf, block_node, nullptr, nullptr); |
| ... | ... | @@ -17838,7 +18017,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc |
| 17838 | 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 | 18021 | IrInstruction *name_value = instruction->name->other; |
| 17843 | 18022 | if (type_is_invalid(name_value->value.type)) |
| 17844 | 18023 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -17857,7 +18036,7 @@ static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstru |
| 17857 | 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 | 18040 | IrInstruction *name = instruction->name->other; |
| 17862 | 18041 | if (type_is_invalid(name->value.type)) |
| 17863 | 18042 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -17884,7 +18063,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc |
| 17884 | 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 | 18067 | IrInstruction *name = instruction->name->other; |
| 17889 | 18068 | if (type_is_invalid(name->value.type)) |
| 17890 | 18069 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -17903,7 +18082,7 @@ static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstruct |
| 17903 | 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 | 18086 | IrInstruction *name = instruction->name->other; |
| 17908 | 18087 | if (type_is_invalid(name->value.type)) |
| 17909 | 18088 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -17917,8 +18096,11 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr |
| 17917 | 18096 | Buf source_dir_path = BUF_INIT; |
| 17918 | 18097 | os_path_dirname(import->path, &source_dir_path); |
| 17919 | 18098 | |
| 17920 | | Buf file_path = BUF_INIT; |
| 17921 | | os_path_resolve(&source_dir_path, rel_file_path, &file_path); |
| 18099 | Buf *resolve_paths[] = { |
| 18100 | &source_dir_path, |
| 18101 | rel_file_path, |
| 18102 | }; |
| 18103 | Buf file_path = os_path_resolve(resolve_paths, 2); |
| 17922 | 18104 | |
| 17923 | 18105 | // load from file system into const expr |
| 17924 | 18106 | Buf *file_contents = buf_alloc(); |
| ... | ... | @@ -17942,8 +18124,8 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr |
| 17942 | 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) { |
| 17946 | | TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->other); |
| 18127 | static ZigType *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) { |
| 18128 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->other); |
| 17947 | 18129 | if (type_is_invalid(operand_type)) |
| 17948 | 18130 | return ira->codegen->builtin_types.entry_invalid; |
| 17949 | 18131 | |
| ... | ... | @@ -17952,7 +18134,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct |
| 17952 | 18134 | return ira->codegen->builtin_types.entry_invalid; |
| 17953 | 18135 | |
| 17954 | 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 | 18138 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type); |
| 17957 | 18139 | if (type_is_invalid(casted_ptr->value.type)) |
| 17958 | 18140 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18023,7 +18205,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct |
| 18023 | 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 | 18209 | IrInstruction *order_value = instruction->order_value->other; |
| 18028 | 18210 | if (type_is_invalid(order_value->value.type)) |
| 18029 | 18211 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18036,26 +18218,26 @@ static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructio |
| 18036 | 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 | 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 | 18224 | if (type_is_invalid(dest_type)) |
| 18043 | 18225 | return ira->codegen->builtin_types.entry_invalid; |
| 18044 | 18226 | |
| 18045 | | if (dest_type->id != TypeTableEntryIdInt && |
| 18046 | | dest_type->id != TypeTableEntryIdComptimeInt) |
| 18227 | if (dest_type->id != ZigTypeIdInt && |
| 18228 | dest_type->id != ZigTypeIdComptimeInt) |
| 18047 | 18229 | { |
| 18048 | 18230 | ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 18049 | 18231 | return ira->codegen->builtin_types.entry_invalid; |
| 18050 | 18232 | } |
| 18051 | 18233 | |
| 18052 | 18234 | IrInstruction *target = instruction->target->other; |
| 18053 | | TypeTableEntry *src_type = target->value.type; |
| 18235 | ZigType *src_type = target->value.type; |
| 18054 | 18236 | if (type_is_invalid(src_type)) |
| 18055 | 18237 | return ira->codegen->builtin_types.entry_invalid; |
| 18056 | 18238 | |
| 18057 | | if (src_type->id != TypeTableEntryIdInt && |
| 18058 | | src_type->id != TypeTableEntryIdComptimeInt) |
| 18239 | if (src_type->id != ZigTypeIdInt && |
| 18240 | src_type->id != ZigTypeIdComptimeInt) |
| 18059 | 18241 | { |
| 18060 | 18242 | ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name))); |
| 18061 | 18243 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18084,12 +18266,12 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc |
| 18084 | 18266 | return dest_type; |
| 18085 | 18267 | } |
| 18086 | 18268 | |
| 18087 | | static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) { |
| 18088 | | TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18269 | static ZigType *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) { |
| 18270 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18089 | 18271 | if (type_is_invalid(dest_type)) |
| 18090 | 18272 | return ira->codegen->builtin_types.entry_invalid; |
| 18091 | 18273 | |
| 18092 | | if (dest_type->id != TypeTableEntryIdInt) { |
| 18274 | if (dest_type->id != ZigTypeIdInt) { |
| 18093 | 18275 | ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 18094 | 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 | 18280 | if (type_is_invalid(target->value.type)) |
| 18099 | 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 | 18284 | if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) { |
| 18103 | 18285 | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, |
| 18104 | 18286 | CastOpNumLitToConcrete, false); |
| ... | ... | @@ -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 | 18297 | ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'", |
| 18116 | 18298 | buf_ptr(&target->value.type->name))); |
| 18117 | 18299 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18125,12 +18307,12 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc |
| 18125 | 18307 | return dest_type; |
| 18126 | 18308 | } |
| 18127 | 18309 | |
| 18128 | | static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) { |
| 18129 | | TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18310 | static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) { |
| 18311 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18130 | 18312 | if (type_is_invalid(dest_type)) |
| 18131 | 18313 | return ira->codegen->builtin_types.entry_invalid; |
| 18132 | 18314 | |
| 18133 | | if (dest_type->id != TypeTableEntryIdFloat) { |
| 18315 | if (dest_type->id != ZigTypeIdFloat) { |
| 18134 | 18316 | ir_add_error(ira, instruction->dest_type, |
| 18135 | 18317 | buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name))); |
| 18136 | 18318 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18140,12 +18322,12 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr |
| 18140 | 18322 | if (type_is_invalid(target->value.type)) |
| 18141 | 18323 | return ira->codegen->builtin_types.entry_invalid; |
| 18142 | 18324 | |
| 18143 | | if (target->value.type->id == TypeTableEntryIdComptimeInt || |
| 18144 | | target->value.type->id == TypeTableEntryIdComptimeFloat) |
| 18325 | if (target->value.type->id == ZigTypeIdComptimeInt || |
| 18326 | target->value.type->id == ZigTypeIdComptimeFloat) |
| 18145 | 18327 | { |
| 18146 | 18328 | if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) { |
| 18147 | 18329 | CastOp op; |
| 18148 | | if (target->value.type->id == TypeTableEntryIdComptimeInt) { |
| 18330 | if (target->value.type->id == ZigTypeIdComptimeInt) { |
| 18149 | 18331 | op = CastOpIntToFloat; |
| 18150 | 18332 | } else { |
| 18151 | 18333 | op = CastOpNumLitToConcrete; |
| ... | ... | @@ -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 | 18346 | ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", |
| 18165 | 18347 | buf_ptr(&target->value.type->name))); |
| 18166 | 18348 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18173,12 +18355,12 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr |
| 18173 | 18355 | return dest_type; |
| 18174 | 18356 | } |
| 18175 | 18357 | |
| 18176 | | static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) { |
| 18177 | | TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18358 | static ZigType *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) { |
| 18359 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18178 | 18360 | if (type_is_invalid(dest_type)) |
| 18179 | 18361 | return ira->codegen->builtin_types.entry_invalid; |
| 18180 | 18362 | |
| 18181 | | if (dest_type->id != TypeTableEntryIdErrorSet) { |
| 18363 | if (dest_type->id != ZigTypeIdErrorSet) { |
| 18182 | 18364 | ir_add_error(ira, instruction->dest_type, |
| 18183 | 18365 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name))); |
| 18184 | 18366 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18188,7 +18370,7 @@ static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrIns |
| 18188 | 18370 | if (type_is_invalid(target->value.type)) |
| 18189 | 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 | 18374 | ir_add_error(ira, instruction->target, |
| 18193 | 18375 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value.type->name))); |
| 18194 | 18376 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18201,8 +18383,8 @@ static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrIns |
| 18201 | 18383 | return dest_type; |
| 18202 | 18384 | } |
| 18203 | 18385 | |
| 18204 | | static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) { |
| 18205 | | TypeTableEntry *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->other); |
| 18386 | static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) { |
| 18387 | ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->other); |
| 18206 | 18388 | if (type_is_invalid(dest_child_type)) |
| 18207 | 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 | 18395 | bool src_ptr_const; |
| 18214 | 18396 | bool src_ptr_volatile; |
| 18215 | 18397 | uint32_t src_ptr_align; |
| 18216 | | if (target->value.type->id == TypeTableEntryIdPointer) { |
| 18398 | if (target->value.type->id == ZigTypeIdPointer) { |
| 18217 | 18399 | src_ptr_const = target->value.type->data.pointer.is_const; |
| 18218 | 18400 | src_ptr_volatile = target->value.type->data.pointer.is_volatile; |
| 18219 | 18401 | src_ptr_align = target->value.type->data.pointer.alignment; |
| 18220 | 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 | 18404 | src_ptr_const = src_ptr_type->data.pointer.is_const; |
| 18223 | 18405 | src_ptr_volatile = src_ptr_type->data.pointer.is_volatile; |
| 18224 | 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 | 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 | 18414 | src_ptr_const, src_ptr_volatile, PtrLenUnknown, |
| 18233 | 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 | 18419 | src_ptr_const, src_ptr_volatile, PtrLenUnknown, |
| 18238 | 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 | 18423 | IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice); |
| 18242 | 18424 | if (type_is_invalid(casted_value->value.type)) |
| ... | ... | @@ -18281,7 +18463,7 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr |
| 18281 | 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 | 18467 | IrInstruction *target = instruction->target->other; |
| 18286 | 18468 | if (type_is_invalid(target->value.type)) |
| 18287 | 18469 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18292,20 +18474,20 @@ static TypeTableEntry *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruc |
| 18292 | 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 | 18480 | src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown, |
| 18299 | 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 | 18484 | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_slice_type, CastOpResizeSlice, true); |
| 18303 | 18485 | ir_link_new_instruction(result, &instruction->base); |
| 18304 | 18486 | return dest_slice_type; |
| 18305 | 18487 | } |
| 18306 | 18488 | |
| 18307 | | static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) { |
| 18308 | | TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18489 | static ZigType *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) { |
| 18490 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18309 | 18491 | if (type_is_invalid(dest_type)) |
| 18310 | 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 | 18495 | if (type_is_invalid(target->value.type)) |
| 18314 | 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 | 18499 | ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'", |
| 18318 | 18500 | buf_ptr(&target->value.type->name))); |
| 18319 | 18501 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18324,8 +18506,8 @@ static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrIns |
| 18324 | 18506 | return dest_type; |
| 18325 | 18507 | } |
| 18326 | 18508 | |
| 18327 | | static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) { |
| 18328 | | TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18509 | static ZigType *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) { |
| 18510 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18329 | 18511 | if (type_is_invalid(dest_type)) |
| 18330 | 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 | 18515 | if (type_is_invalid(target->value.type)) |
| 18334 | 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 | 18532 | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt, false); |
| 18337 | 18533 | ir_link_new_instruction(result, &instruction->base); |
| 18338 | 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 | 18538 | IrInstruction *target = instruction->target->other; |
| 18343 | 18539 | if (type_is_invalid(target->value.type)) |
| 18344 | 18540 | return ira->codegen->builtin_types.entry_invalid; |
| 18345 | 18541 | |
| 18346 | 18542 | IrInstruction *casted_target; |
| 18347 | | if (target->value.type->id == TypeTableEntryIdErrorSet) { |
| 18543 | if (target->value.type->id == ZigTypeIdErrorSet) { |
| 18348 | 18544 | casted_target = target; |
| 18349 | 18545 | } else { |
| 18350 | 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 | 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 | 18557 | IrInstruction *target = instruction->target->other; |
| 18362 | 18558 | if (type_is_invalid(target->value.type)) |
| 18363 | 18559 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18371,12 +18567,12 @@ static TypeTableEntry *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstr |
| 18371 | 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 | 18571 | IrInstruction *target = instruction->target->other; |
| 18376 | 18572 | if (type_is_invalid(target->value.type)) |
| 18377 | 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 | 18576 | ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'", |
| 18381 | 18577 | buf_ptr(&target->value.type->name))); |
| 18382 | 18578 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18392,13 +18588,13 @@ static TypeTableEntry *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInst |
| 18392 | 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 | 18592 | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt, false); |
| 18397 | 18593 | ir_link_new_instruction(result, &instruction->base); |
| 18398 | 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 | 18598 | IrInstruction *is_signed_value = instruction->is_signed->other; |
| 18403 | 18599 | bool is_signed; |
| 18404 | 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 | 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 | 18614 | IrInstruction *value = instruction->value->other; |
| 18419 | 18615 | if (type_is_invalid(value->value.type)) |
| 18420 | 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 | 18620 | IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type); |
| 18425 | 18621 | if (type_is_invalid(casted_value->value.type)) |
| ... | ... | @@ -18439,7 +18635,7 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc |
| 18439 | 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 | 18639 | IrInstruction *dest_ptr = instruction->dest_ptr->other; |
| 18444 | 18640 | if (type_is_invalid(dest_ptr->value.type)) |
| 18445 | 18641 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18452,15 +18648,15 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi |
| 18452 | 18648 | if (type_is_invalid(count_value->value.type)) |
| 18453 | 18649 | return ira->codegen->builtin_types.entry_invalid; |
| 18454 | 18650 | |
| 18455 | | TypeTableEntry *dest_uncasted_type = dest_ptr->value.type; |
| 18456 | | bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) && |
| 18651 | ZigType *dest_uncasted_type = dest_ptr->value.type; |
| 18652 | bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) && |
| 18457 | 18653 | dest_uncasted_type->data.pointer.is_volatile; |
| 18458 | 18654 | |
| 18459 | | TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; |
| 18460 | | TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8; |
| 18461 | | uint32_t dest_align = (dest_uncasted_type->id == TypeTableEntryIdPointer) ? |
| 18655 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 18656 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 18657 | uint32_t dest_align = (dest_uncasted_type->id == ZigTypeIdPointer) ? |
| 18462 | 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 | 18660 | PtrLenUnknown, dest_align, 0, 0); |
| 18465 | 18661 | |
| 18466 | 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 | 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 | 18731 | IrInstruction *dest_ptr = instruction->dest_ptr->other; |
| 18536 | 18732 | if (type_is_invalid(dest_ptr->value.type)) |
| 18537 | 18733 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18544,22 +18740,22 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi |
| 18544 | 18740 | if (type_is_invalid(count_value->value.type)) |
| 18545 | 18741 | return ira->codegen->builtin_types.entry_invalid; |
| 18546 | 18742 | |
| 18547 | | TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8; |
| 18548 | | TypeTableEntry *dest_uncasted_type = dest_ptr->value.type; |
| 18549 | | TypeTableEntry *src_uncasted_type = src_ptr->value.type; |
| 18550 | | bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) && |
| 18743 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 18744 | ZigType *dest_uncasted_type = dest_ptr->value.type; |
| 18745 | ZigType *src_uncasted_type = src_ptr->value.type; |
| 18746 | bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) && |
| 18551 | 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 | 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 | 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 | 18753 | src_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); |
| 18558 | 18754 | |
| 18559 | | TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; |
| 18560 | | TypeTableEntry *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, |
| 18755 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 18756 | ZigType *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, |
| 18561 | 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 | 18759 | PtrLenUnknown, src_align, 0, 0); |
| 18564 | 18760 | |
| 18565 | 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 | 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 | 18866 | IrInstruction *ptr_ptr = instruction->ptr->other; |
| 18671 | 18867 | if (type_is_invalid(ptr_ptr->value.type)) |
| 18672 | 18868 | return ira->codegen->builtin_types.entry_invalid; |
| 18673 | 18869 | |
| 18674 | | TypeTableEntry *ptr_type = ptr_ptr->value.type; |
| 18675 | | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 18676 | | TypeTableEntry *array_type = ptr_type->data.pointer.child_type; |
| 18870 | ZigType *ptr_type = ptr_ptr->value.type; |
| 18871 | assert(ptr_type->id == ZigTypeIdPointer); |
| 18872 | ZigType *array_type = ptr_type->data.pointer.child_type; |
| 18677 | 18873 | |
| 18678 | 18874 | IrInstruction *start = instruction->start->other; |
| 18679 | 18875 | if (type_is_invalid(start->value.type)) |
| 18680 | 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 | 18879 | IrInstruction *casted_start = ir_implicit_cast(ira, start, usize); |
| 18684 | 18880 | if (type_is_invalid(casted_start->value.type)) |
| 18685 | 18881 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18696,26 +18892,26 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 18696 | 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 | 18898 | uint32_t byte_alignment = ptr_type->data.pointer.alignment; |
| 18703 | 18899 | if (array_type->data.array.len == 0 && byte_alignment == 0) { |
| 18704 | 18900 | byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type); |
| 18705 | 18901 | } |
| 18706 | 18902 | bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic && |
| 18707 | 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 | 18905 | ptr_type->data.pointer.is_const || is_comptime_const, |
| 18710 | 18906 | ptr_type->data.pointer.is_volatile, |
| 18711 | 18907 | PtrLenUnknown, |
| 18712 | 18908 | byte_alignment, 0, 0); |
| 18713 | 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 | 18911 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { |
| 18716 | | TypeTableEntry *main_type = array_type->data.pointer.child_type; |
| 18717 | | if (main_type->id == TypeTableEntryIdArray) { |
| 18718 | | TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, |
| 18912 | ZigType *main_type = array_type->data.pointer.child_type; |
| 18913 | if (main_type->id == ZigTypeIdArray) { |
| 18914 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, |
| 18719 | 18915 | main_type->data.pointer.child_type, |
| 18720 | 18916 | array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, |
| 18721 | 18917 | PtrLenUnknown, |
| ... | ... | @@ -18726,7 +18922,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 18726 | 18922 | return ira->codegen->builtin_types.entry_invalid; |
| 18727 | 18923 | } |
| 18728 | 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 | 18926 | array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, |
| 18731 | 18927 | PtrLenUnknown, |
| 18732 | 18928 | array_type->data.pointer.alignment, 0, 0); |
| ... | ... | @@ -18737,7 +18933,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 18737 | 18933 | } |
| 18738 | 18934 | } |
| 18739 | 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 | 18937 | return_type = get_slice_type(ira->codegen, ptr_type); |
| 18742 | 18938 | } else { |
| 18743 | 18939 | ir_add_error(ira, &instruction->base, |
| ... | ... | @@ -18754,25 +18950,36 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 18754 | 18950 | size_t abs_offset; |
| 18755 | 18951 | size_t rel_end; |
| 18756 | 18952 | bool ptr_is_undef = false; |
| 18757 | | if (array_type->id == TypeTableEntryIdArray || |
| 18758 | | (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle)) |
| 18953 | if (array_type->id == ZigTypeIdArray || |
| 18954 | (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle)) |
| 18759 | 18955 | { |
| 18760 | | if (array_type->id == TypeTableEntryIdPointer) { |
| 18761 | | TypeTableEntry *child_array_type = array_type->data.pointer.child_type; |
| 18762 | | assert(child_array_type->id == TypeTableEntryIdArray); |
| 18763 | | parent_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value); |
| 18764 | | array_val = const_ptr_pointee(ira->codegen, parent_ptr); |
| 18956 | if (array_type->id == ZigTypeIdPointer) { |
| 18957 | ZigType *child_array_type = array_type->data.pointer.child_type; |
| 18958 | assert(child_array_type->id == ZigTypeIdArray); |
| 18959 | parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node); |
| 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 | 18967 | rel_end = child_array_type->data.array.len; |
| 18766 | 18968 | abs_offset = 0; |
| 18767 | 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 | 18973 | rel_end = array_type->data.array.len; |
| 18770 | 18974 | parent_ptr = nullptr; |
| 18771 | 18975 | abs_offset = 0; |
| 18772 | 18976 | } |
| 18773 | | } else if (array_type->id == TypeTableEntryIdPointer) { |
| 18977 | } else if (array_type->id == ZigTypeIdPointer) { |
| 18774 | 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 | 18983 | if (parent_ptr->special == ConstValSpecialUndef) { |
| 18777 | 18984 | array_val = nullptr; |
| 18778 | 18985 | abs_offset = 0; |
| ... | ... | @@ -18803,7 +19010,10 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 18803 | 19010 | zig_panic("TODO slice of ptr cast from function"); |
| 18804 | 19011 | } |
| 18805 | 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 | 19017 | parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index]; |
| 18808 | 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 | 19081 | size_t index = abs_offset + start_scalar; |
| 18872 | 19082 | bool is_const = slice_is_const(return_type); |
| 18873 | 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 | 19085 | ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut; |
| 18876 | 19086 | } else if (is_slice(array_type)) { |
| 18877 | 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 | 19089 | ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut; |
| 18880 | 19090 | } |
| 18881 | 19091 | } else if (ptr_is_undef) { |
| ... | ... | @@ -18917,12 +19127,12 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 18917 | 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 | 19131 | Error err; |
| 18922 | 19132 | IrInstruction *container = instruction->container->other; |
| 18923 | 19133 | if (type_is_invalid(container->value.type)) |
| 18924 | 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 | 19137 | if ((err = ensure_complete_type(ira->codegen, container_type))) |
| 18928 | 19138 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18930,13 +19140,13 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns |
| 18930 | 19140 | uint64_t result; |
| 18931 | 19141 | if (type_is_invalid(container_type)) { |
| 18932 | 19142 | return ira->codegen->builtin_types.entry_invalid; |
| 18933 | | } else if (container_type->id == TypeTableEntryIdEnum) { |
| 19143 | } else if (container_type->id == ZigTypeIdEnum) { |
| 18934 | 19144 | result = container_type->data.enumeration.src_field_count; |
| 18935 | | } else if (container_type->id == TypeTableEntryIdStruct) { |
| 19145 | } else if (container_type->id == ZigTypeIdStruct) { |
| 18936 | 19146 | result = container_type->data.structure.src_field_count; |
| 18937 | | } else if (container_type->id == TypeTableEntryIdUnion) { |
| 19147 | } else if (container_type->id == ZigTypeIdUnion) { |
| 18938 | 19148 | result = container_type->data.unionation.src_field_count; |
| 18939 | | } else if (container_type->id == TypeTableEntryIdErrorSet) { |
| 19149 | } else if (container_type->id == ZigTypeIdErrorSet) { |
| 18940 | 19150 | if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) { |
| 18941 | 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 | 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 | 19169 | Error err; |
| 18960 | 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 | 19172 | if (type_is_invalid(container_type)) |
| 18963 | 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 | 19181 | if (!ir_resolve_usize(ira, index_value, &member_index)) |
| 18972 | 19182 | return ira->codegen->builtin_types.entry_invalid; |
| 18973 | 19183 | |
| 18974 | | if (container_type->id == TypeTableEntryIdStruct) { |
| 19184 | if (container_type->id == ZigTypeIdStruct) { |
| 18975 | 19185 | if (member_index >= container_type->data.structure.src_field_count) { |
| 18976 | 19186 | ir_add_error(ira, index_value, |
| 18977 | 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 | 19193 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 18984 | 19194 | out_val->data.x_type = field->type_entry; |
| 18985 | 19195 | return ira->codegen->builtin_types.entry_type; |
| 18986 | | } else if (container_type->id == TypeTableEntryIdUnion) { |
| 19196 | } else if (container_type->id == ZigTypeIdUnion) { |
| 18987 | 19197 | if (member_index >= container_type->data.unionation.src_field_count) { |
| 18988 | 19198 | ir_add_error(ira, index_value, |
| 18989 | 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 | 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 | 19216 | Error err; |
| 19007 | 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 | 19219 | if (type_is_invalid(container_type)) |
| 19010 | 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 | 19227 | if (!ir_resolve_usize(ira, index_value, &member_index)) |
| 19018 | 19228 | return ira->codegen->builtin_types.entry_invalid; |
| 19019 | 19229 | |
| 19020 | | if (container_type->id == TypeTableEntryIdStruct) { |
| 19230 | if (container_type->id == ZigTypeIdStruct) { |
| 19021 | 19231 | if (member_index >= container_type->data.structure.src_field_count) { |
| 19022 | 19232 | ir_add_error(ira, index_value, |
| 19023 | 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 | 19239 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19030 | 19240 | init_const_str_lit(ira->codegen, out_val, field->name); |
| 19031 | 19241 | return out_val->type; |
| 19032 | | } else if (container_type->id == TypeTableEntryIdEnum) { |
| 19242 | } else if (container_type->id == ZigTypeIdEnum) { |
| 19033 | 19243 | if (member_index >= container_type->data.enumeration.src_field_count) { |
| 19034 | 19244 | ir_add_error(ira, index_value, |
| 19035 | 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 | 19251 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19042 | 19252 | init_const_str_lit(ira->codegen, out_val, field->name); |
| 19043 | 19253 | return out_val->type; |
| 19044 | | } else if (container_type->id == TypeTableEntryIdUnion) { |
| 19254 | } else if (container_type->id == ZigTypeIdUnion) { |
| 19045 | 19255 | if (member_index >= container_type->data.unionation.src_field_count) { |
| 19046 | 19256 | ir_add_error(ira, index_value, |
| 19047 | 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 | 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 | 19274 | ir_build_breakpoint_from(&ira->new_irb, &instruction->base); |
| 19065 | 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 | 19279 | ir_build_return_address_from(&ira->new_irb, &instruction->base); |
| 19070 | 19280 | |
| 19071 | | TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8; |
| 19072 | | TypeTableEntry *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); |
| 19281 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 19282 | ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); |
| 19073 | 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 | 19287 | ir_build_frame_address_from(&ira->new_irb, &instruction->base); |
| 19078 | 19288 | |
| 19079 | | TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8; |
| 19080 | | TypeTableEntry *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); |
| 19289 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 19290 | ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); |
| 19081 | 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 | 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 | 19298 | assert(fn_entry != nullptr); |
| 19089 | 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 | 19303 | Error err; |
| 19094 | 19304 | IrInstruction *type_value = instruction->type_value->other; |
| 19095 | 19305 | if (type_is_invalid(type_value->value.type)) |
| 19096 | 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 | 19309 | if ((err = type_ensure_zero_bits_known(ira->codegen, type_entry))) |
| 19100 | 19310 | return ira->codegen->builtin_types.entry_invalid; |
| 19101 | 19311 | |
| 19102 | 19312 | switch (type_entry->id) { |
| 19103 | | case TypeTableEntryIdInvalid: |
| 19313 | case ZigTypeIdInvalid: |
| 19104 | 19314 | zig_unreachable(); |
| 19105 | | case TypeTableEntryIdMetaType: |
| 19106 | | case TypeTableEntryIdUnreachable: |
| 19107 | | case TypeTableEntryIdComptimeFloat: |
| 19108 | | case TypeTableEntryIdComptimeInt: |
| 19109 | | case TypeTableEntryIdUndefined: |
| 19110 | | case TypeTableEntryIdNull: |
| 19111 | | case TypeTableEntryIdNamespace: |
| 19112 | | case TypeTableEntryIdBlock: |
| 19113 | | case TypeTableEntryIdBoundFn: |
| 19114 | | case TypeTableEntryIdArgTuple: |
| 19115 | | case TypeTableEntryIdVoid: |
| 19116 | | case TypeTableEntryIdOpaque: |
| 19315 | case ZigTypeIdMetaType: |
| 19316 | case ZigTypeIdUnreachable: |
| 19317 | case ZigTypeIdComptimeFloat: |
| 19318 | case ZigTypeIdComptimeInt: |
| 19319 | case ZigTypeIdUndefined: |
| 19320 | case ZigTypeIdNull: |
| 19321 | case ZigTypeIdNamespace: |
| 19322 | case ZigTypeIdBlock: |
| 19323 | case ZigTypeIdBoundFn: |
| 19324 | case ZigTypeIdArgTuple: |
| 19325 | case ZigTypeIdVoid: |
| 19326 | case ZigTypeIdOpaque: |
| 19117 | 19327 | ir_add_error(ira, instruction->type_value, |
| 19118 | 19328 | buf_sprintf("no align available for type '%s'", buf_ptr(&type_entry->name))); |
| 19119 | 19329 | return ira->codegen->builtin_types.entry_invalid; |
| 19120 | | case TypeTableEntryIdBool: |
| 19121 | | case TypeTableEntryIdInt: |
| 19122 | | case TypeTableEntryIdFloat: |
| 19123 | | case TypeTableEntryIdPointer: |
| 19124 | | case TypeTableEntryIdPromise: |
| 19125 | | case TypeTableEntryIdArray: |
| 19126 | | case TypeTableEntryIdStruct: |
| 19127 | | case TypeTableEntryIdOptional: |
| 19128 | | case TypeTableEntryIdErrorUnion: |
| 19129 | | case TypeTableEntryIdErrorSet: |
| 19130 | | case TypeTableEntryIdEnum: |
| 19131 | | case TypeTableEntryIdUnion: |
| 19132 | | case TypeTableEntryIdFn: |
| 19330 | case ZigTypeIdBool: |
| 19331 | case ZigTypeIdInt: |
| 19332 | case ZigTypeIdFloat: |
| 19333 | case ZigTypeIdPointer: |
| 19334 | case ZigTypeIdPromise: |
| 19335 | case ZigTypeIdArray: |
| 19336 | case ZigTypeIdStruct: |
| 19337 | case ZigTypeIdOptional: |
| 19338 | case ZigTypeIdErrorUnion: |
| 19339 | case ZigTypeIdErrorSet: |
| 19340 | case ZigTypeIdEnum: |
| 19341 | case ZigTypeIdUnion: |
| 19342 | case ZigTypeIdFn: |
| 19133 | 19343 | { |
| 19134 | 19344 | uint64_t align_in_bytes = get_abi_alignment(ira->codegen, type_entry); |
| 19135 | 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 | 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 | 19354 | IrInstruction *type_value = instruction->type_value->other; |
| 19145 | 19355 | if (type_is_invalid(type_value->value.type)) |
| 19146 | 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 | 19359 | if (type_is_invalid(dest_type)) |
| 19150 | 19360 | return ira->codegen->builtin_types.entry_invalid; |
| 19151 | 19361 | |
| 19152 | | if (dest_type->id != TypeTableEntryIdInt) { |
| 19362 | if (dest_type->id != ZigTypeIdInt) { |
| 19153 | 19363 | ir_add_error(ira, type_value, |
| 19154 | 19364 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 19155 | 19365 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -19169,7 +19379,7 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst |
| 19169 | 19379 | |
| 19170 | 19380 | IrInstruction *casted_op2; |
| 19171 | 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 | 19383 | dest_type->data.integral.bit_count - 1); |
| 19174 | 19384 | casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type); |
| 19175 | 19385 | } else { |
| ... | ... | @@ -19182,8 +19392,8 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst |
| 19182 | 19392 | if (type_is_invalid(result_ptr->value.type)) |
| 19183 | 19393 | return ira->codegen->builtin_types.entry_invalid; |
| 19184 | 19394 | |
| 19185 | | TypeTableEntry *expected_ptr_type; |
| 19186 | | if (result_ptr->value.type->id == TypeTableEntryIdPointer) { |
| 19395 | ZigType *expected_ptr_type; |
| 19396 | if (result_ptr->value.type->id == ZigTypeIdPointer) { |
| 19187 | 19397 | expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type, |
| 19188 | 19398 | false, result_ptr->value.type->data.pointer.is_volatile, |
| 19189 | 19399 | PtrLenSingle, |
| ... | ... | @@ -19203,7 +19413,9 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst |
| 19203 | 19413 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19204 | 19414 | BigInt *op1_bigint = &casted_op1->value.data.x_bigint; |
| 19205 | 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 | 19419 | BigInt *dest_bigint = &pointee_val->data.x_bigint; |
| 19208 | 19420 | switch (instruction->op) { |
| 19209 | 19421 | case IrOverflowOpAdd: |
| ... | ... | @@ -19237,15 +19449,15 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst |
| 19237 | 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 | 19453 | IrInstruction *value = instruction->value->other; |
| 19242 | 19454 | if (type_is_invalid(value->value.type)) |
| 19243 | 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 | 19458 | if (type_is_invalid(type_entry)) { |
| 19247 | 19459 | return ira->codegen->builtin_types.entry_invalid; |
| 19248 | | } else if (type_entry->id == TypeTableEntryIdErrorUnion) { |
| 19460 | } else if (type_entry->id == ZigTypeIdErrorUnion) { |
| 19249 | 19461 | if (instr_is_comptime(value)) { |
| 19250 | 19462 | ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad); |
| 19251 | 19463 | if (!err_union_val) |
| ... | ... | @@ -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 | 19474 | if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) { |
| 19263 | 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 | 19485 | |
| 19274 | 19486 | ir_build_test_err_from(&ira->new_irb, &instruction->base, value); |
| 19275 | 19487 | return ira->codegen->builtin_types.entry_bool; |
| 19276 | | } else if (type_entry->id == TypeTableEntryIdErrorSet) { |
| 19488 | } else if (type_entry->id == ZigTypeIdErrorSet) { |
| 19277 | 19489 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19278 | 19490 | out_val->data.x_bool = true; |
| 19279 | 19491 | return ira->codegen->builtin_types.entry_bool; |
| ... | ... | @@ -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 | 19500 | IrInstructionUnwrapErrCode *instruction) |
| 19289 | 19501 | { |
| 19290 | 19502 | IrInstruction *value = instruction->value->other; |
| 19291 | 19503 | if (type_is_invalid(value->value.type)) |
| 19292 | 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 | 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 | 19511 | if (type_is_invalid(type_entry)) { |
| 19300 | 19512 | return ira->codegen->builtin_types.entry_invalid; |
| 19301 | | } else if (type_entry->id == TypeTableEntryIdErrorUnion) { |
| 19513 | } else if (type_entry->id == ZigTypeIdErrorUnion) { |
| 19302 | 19514 | if (instr_is_comptime(value)) { |
| 19303 | 19515 | ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad); |
| 19304 | 19516 | if (!ptr_val) |
| 19305 | 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 | 19521 | if (err_union_val->special != ConstValSpecialRuntime) { |
| 19308 | 19522 | ErrorTableEntry *err = err_union_val->data.x_err_union.err; |
| 19309 | 19523 | assert(err); |
| ... | ... | @@ -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 | 19541 | IrInstructionUnwrapErrPayload *instruction) |
| 19328 | 19542 | { |
| 19329 | 19543 | assert(instruction->value->other); |
| 19330 | 19544 | IrInstruction *value = instruction->value->other; |
| 19331 | 19545 | if (type_is_invalid(value->value.type)) |
| 19332 | 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 | 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 | 19553 | if (type_is_invalid(type_entry)) { |
| 19340 | 19554 | return ira->codegen->builtin_types.entry_invalid; |
| 19341 | | } else if (type_entry->id == TypeTableEntryIdErrorUnion) { |
| 19342 | | TypeTableEntry *payload_type = type_entry->data.error_union.payload_type; |
| 19555 | } else if (type_entry->id == ZigTypeIdErrorUnion) { |
| 19556 | ZigType *payload_type = type_entry->data.error_union.payload_type; |
| 19343 | 19557 | if (type_is_invalid(payload_type)) { |
| 19344 | 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 | 19561 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 19348 | 19562 | PtrLenSingle, |
| 19349 | 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 | 19565 | ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad); |
| 19352 | 19566 | if (!ptr_val) |
| 19353 | 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 | 19571 | if (err_union_val->special != ConstValSpecialRuntime) { |
| 19356 | 19572 | ErrorTableEntry *err = err_union_val->data.x_err_union.err; |
| 19357 | 19573 | if (err != nullptr) { |
| ... | ... | @@ -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 | 19598 | AstNode *proto_node = instruction->base.source_node; |
| 19382 | 19599 | assert(proto_node->type == NodeTypeFnProto); |
| 19383 | 19600 | |
| ... | ... | @@ -19419,9 +19636,25 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc |
| 19419 | 19636 | IrInstruction *param_type_value = instruction->param_types[fn_type_id.next_param_index]->other; |
| 19420 | 19637 | if (type_is_invalid(param_type_value->value.type)) |
| 19421 | 19638 | return ira->codegen->builtin_types.entry_invalid; |
| 19422 | | param_info->type = ir_resolve_type(ira, param_type_value); |
| 19423 | | if (type_is_invalid(param_info->type)) |
| 19639 | ZigType *param_type = ir_resolve_type(ira, param_type_value); |
| 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 | 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 | 19668 | fn_type_id.return_type = ir_resolve_type(ira, return_type_value); |
| 19436 | 19669 | if (type_is_invalid(fn_type_id.return_type)) |
| 19437 | 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 | 19672 | ir_add_error(ira, instruction->return_type, |
| 19440 | 19673 | buf_sprintf("return type cannot be opaque")); |
| 19441 | 19674 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -19458,7 +19691,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc |
| 19458 | 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 | 19695 | IrInstruction *value = instruction->value->other; |
| 19463 | 19696 | if (type_is_invalid(value->value.type)) |
| 19464 | 19697 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -19468,15 +19701,15 @@ static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrIn |
| 19468 | 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 | 19705 | IrInstructionCheckSwitchProngs *instruction) |
| 19473 | 19706 | { |
| 19474 | 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 | 19709 | if (type_is_invalid(switch_type)) |
| 19477 | 19710 | return ira->codegen->builtin_types.entry_invalid; |
| 19478 | 19711 | |
| 19479 | | if (switch_type->id == TypeTableEntryIdEnum) { |
| 19712 | if (switch_type->id == ZigTypeIdEnum) { |
| 19480 | 19713 | HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {}; |
| 19481 | 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 | 19724 | if (type_is_invalid(end_value->value.type)) |
| 19492 | 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 | 19728 | ir_add_error(ira, range->start, buf_sprintf("not an enum type")); |
| 19496 | 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 | 19732 | BigInt start_index; |
| 19500 | 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 | 19736 | BigInt end_index; |
| 19504 | 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 | 19768 | } |
| 19536 | 19769 | } |
| 19537 | 19770 | } |
| 19538 | | } else if (switch_type->id == TypeTableEntryIdErrorSet) { |
| 19771 | } else if (switch_type->id == ZigTypeIdErrorSet) { |
| 19539 | 19772 | if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) { |
| 19540 | 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 | 19786 | if (type_is_invalid(end_value->value.type)) |
| 19554 | 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 | 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 | 19793 | uint32_t end_index = end_value->value.data.x_err_set->value; |
| 19561 | 19794 | |
| 19562 | 19795 | if (start_index != end_index) { |
| ... | ... | @@ -19592,7 +19825,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira |
| 19592 | 19825 | } |
| 19593 | 19826 | |
| 19594 | 19827 | free(field_prev_uses); |
| 19595 | | } else if (switch_type->id == TypeTableEntryIdInt) { |
| 19828 | } else if (switch_type->id == ZigTypeIdInt) { |
| 19596 | 19829 | RangeSet rs = {0}; |
| 19597 | 19830 | for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) { |
| 19598 | 19831 | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| ... | ... | @@ -19619,8 +19852,8 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira |
| 19619 | 19852 | if (!end_val) |
| 19620 | 19853 | return ira->codegen->builtin_types.entry_invalid; |
| 19621 | 19854 | |
| 19622 | | assert(start_val->type->id == TypeTableEntryIdInt || start_val->type->id == TypeTableEntryIdComptimeInt); |
| 19623 | | assert(end_val->type->id == TypeTableEntryIdInt || end_val->type->id == TypeTableEntryIdComptimeInt); |
| 19855 | assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt); |
| 19856 | assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt); |
| 19624 | 19857 | AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint, |
| 19625 | 19858 | start_value->source_node); |
| 19626 | 19859 | if (prev_node != nullptr) { |
| ... | ... | @@ -19648,15 +19881,15 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira |
| 19648 | 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 | 19885 | IrInstructionCheckStatementIsVoid *instruction) |
| 19653 | 19886 | { |
| 19654 | 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 | 19889 | if (type_is_invalid(statement_type)) |
| 19657 | 19890 | return ira->codegen->builtin_types.entry_invalid; |
| 19658 | 19891 | |
| 19659 | | if (statement_type->id != TypeTableEntryIdVoid) { |
| 19892 | if (statement_type->id != ZigTypeIdVoid) { |
| 19660 | 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 | 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 | 19901 | IrInstruction *msg = instruction->msg->other; |
| 19669 | 19902 | if (type_is_invalid(msg->value.type)) |
| 19670 | 19903 | return ir_unreach_error(ira); |
| ... | ... | @@ -19674,9 +19907,9 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio |
| 19674 | 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 | 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 | 19913 | IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type); |
| 19681 | 19914 | if (type_is_invalid(casted_msg->value.type)) |
| 19682 | 19915 | return ir_unreach_error(ira); |
| ... | ... | @@ -19688,40 +19921,40 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio |
| 19688 | 19921 | } |
| 19689 | 19922 | |
| 19690 | 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 | 19925 | assert(!type_is_invalid(target_type)); |
| 19693 | 19926 | |
| 19694 | | TypeTableEntry *result_type; |
| 19927 | ZigType *result_type; |
| 19695 | 19928 | uint32_t old_align_bytes; |
| 19696 | 19929 | |
| 19697 | | if (target_type->id == TypeTableEntryIdPointer) { |
| 19930 | if (target_type->id == ZigTypeIdPointer) { |
| 19698 | 19931 | result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes); |
| 19699 | 19932 | old_align_bytes = target_type->data.pointer.alignment; |
| 19700 | | } else if (target_type->id == TypeTableEntryIdFn) { |
| 19933 | } else if (target_type->id == ZigTypeIdFn) { |
| 19701 | 19934 | FnTypeId fn_type_id = target_type->data.fn.fn_type_id; |
| 19702 | 19935 | old_align_bytes = fn_type_id.alignment; |
| 19703 | 19936 | fn_type_id.alignment = align_bytes; |
| 19704 | 19937 | result_type = get_fn_type(ira->codegen, &fn_type_id); |
| 19705 | | } else if (target_type->id == TypeTableEntryIdOptional && |
| 19706 | | target_type->data.maybe.child_type->id == TypeTableEntryIdPointer) |
| 19938 | } else if (target_type->id == ZigTypeIdOptional && |
| 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 | 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 | 19945 | result_type = get_optional_type(ira->codegen, better_ptr_type); |
| 19713 | | } else if (target_type->id == TypeTableEntryIdOptional && |
| 19714 | | target_type->data.maybe.child_type->id == TypeTableEntryIdFn) |
| 19946 | } else if (target_type->id == ZigTypeIdOptional && |
| 19947 | target_type->data.maybe.child_type->id == ZigTypeIdFn) |
| 19715 | 19948 | { |
| 19716 | 19949 | FnTypeId fn_type_id = target_type->data.maybe.child_type->data.fn.fn_type_id; |
| 19717 | 19950 | old_align_bytes = fn_type_id.alignment; |
| 19718 | 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 | 19953 | result_type = get_optional_type(ira->codegen, fn_type); |
| 19721 | 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 | 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 | 19958 | result_type = get_slice_type(ira->codegen, result_ptr_type); |
| 19726 | 19959 | } else { |
| 19727 | 19960 | ir_add_error(ira, target, |
| ... | ... | @@ -19759,16 +19992,16 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 19759 | 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 | 19996 | Error err; |
| 19764 | 19997 | |
| 19765 | 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 | 20000 | if (type_is_invalid(dest_type)) |
| 19768 | 20001 | return ira->codegen->builtin_types.entry_invalid; |
| 19769 | 20002 | |
| 19770 | 20003 | IrInstruction *ptr = instruction->ptr->other; |
| 19771 | | TypeTableEntry *src_type = ptr->value.type; |
| 20004 | ZigType *src_type = ptr->value.type; |
| 19772 | 20005 | if (type_is_invalid(src_type)) |
| 19773 | 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 | 20068 | static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) { |
| 19836 | 20069 | assert(val->special == ConstValSpecialStatic); |
| 19837 | 20070 | switch (val->type->id) { |
| 19838 | | case TypeTableEntryIdInvalid: |
| 19839 | | case TypeTableEntryIdMetaType: |
| 19840 | | case TypeTableEntryIdOpaque: |
| 19841 | | case TypeTableEntryIdBoundFn: |
| 19842 | | case TypeTableEntryIdArgTuple: |
| 19843 | | case TypeTableEntryIdNamespace: |
| 19844 | | case TypeTableEntryIdBlock: |
| 19845 | | case TypeTableEntryIdUnreachable: |
| 19846 | | case TypeTableEntryIdComptimeFloat: |
| 19847 | | case TypeTableEntryIdComptimeInt: |
| 19848 | | case TypeTableEntryIdUndefined: |
| 19849 | | case TypeTableEntryIdNull: |
| 19850 | | case TypeTableEntryIdPromise: |
| 20071 | case ZigTypeIdInvalid: |
| 20072 | case ZigTypeIdMetaType: |
| 20073 | case ZigTypeIdOpaque: |
| 20074 | case ZigTypeIdBoundFn: |
| 20075 | case ZigTypeIdArgTuple: |
| 20076 | case ZigTypeIdNamespace: |
| 20077 | case ZigTypeIdBlock: |
| 20078 | case ZigTypeIdUnreachable: |
| 20079 | case ZigTypeIdComptimeFloat: |
| 20080 | case ZigTypeIdComptimeInt: |
| 20081 | case ZigTypeIdUndefined: |
| 20082 | case ZigTypeIdNull: |
| 20083 | case ZigTypeIdPromise: |
| 19851 | 20084 | zig_unreachable(); |
| 19852 | | case TypeTableEntryIdVoid: |
| 20085 | case ZigTypeIdVoid: |
| 19853 | 20086 | return; |
| 19854 | | case TypeTableEntryIdBool: |
| 20087 | case ZigTypeIdBool: |
| 19855 | 20088 | buf[0] = val->data.x_bool ? 1 : 0; |
| 19856 | 20089 | return; |
| 19857 | | case TypeTableEntryIdInt: |
| 20090 | case ZigTypeIdInt: |
| 19858 | 20091 | bigint_write_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count, |
| 19859 | 20092 | codegen->is_big_endian); |
| 19860 | 20093 | return; |
| 19861 | | case TypeTableEntryIdFloat: |
| 20094 | case ZigTypeIdFloat: |
| 19862 | 20095 | float_write_ieee597(val, buf, codegen->is_big_endian); |
| 19863 | 20096 | return; |
| 19864 | | case TypeTableEntryIdPointer: |
| 20097 | case ZigTypeIdPointer: |
| 19865 | 20098 | if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 19866 | 20099 | BigInt bn; |
| 19867 | 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 | 20103 | } else { |
| 19871 | 20104 | zig_unreachable(); |
| 19872 | 20105 | } |
| 19873 | | case TypeTableEntryIdArray: |
| 20106 | case ZigTypeIdArray: |
| 19874 | 20107 | { |
| 19875 | 20108 | size_t buf_i = 0; |
| 19876 | 20109 | expand_undef_array(codegen, val); |
| ... | ... | @@ -19881,19 +20114,19 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 19881 | 20114 | } |
| 19882 | 20115 | } |
| 19883 | 20116 | return; |
| 19884 | | case TypeTableEntryIdStruct: |
| 20117 | case ZigTypeIdStruct: |
| 19885 | 20118 | zig_panic("TODO buf_write_value_bytes struct type"); |
| 19886 | | case TypeTableEntryIdOptional: |
| 20119 | case ZigTypeIdOptional: |
| 19887 | 20120 | zig_panic("TODO buf_write_value_bytes maybe type"); |
| 19888 | | case TypeTableEntryIdErrorUnion: |
| 20121 | case ZigTypeIdErrorUnion: |
| 19889 | 20122 | zig_panic("TODO buf_write_value_bytes error union"); |
| 19890 | | case TypeTableEntryIdErrorSet: |
| 20123 | case ZigTypeIdErrorSet: |
| 19891 | 20124 | zig_panic("TODO buf_write_value_bytes pure error type"); |
| 19892 | | case TypeTableEntryIdEnum: |
| 20125 | case ZigTypeIdEnum: |
| 19893 | 20126 | zig_panic("TODO buf_write_value_bytes enum type"); |
| 19894 | | case TypeTableEntryIdFn: |
| 20127 | case ZigTypeIdFn: |
| 19895 | 20128 | zig_panic("TODO buf_write_value_bytes fn type"); |
| 19896 | | case TypeTableEntryIdUnion: |
| 20129 | case ZigTypeIdUnion: |
| 19897 | 20130 | zig_panic("TODO buf_write_value_bytes union type"); |
| 19898 | 20131 | } |
| 19899 | 20132 | zig_unreachable(); |
| ... | ... | @@ -19902,33 +20135,33 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 19902 | 20135 | static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) { |
| 19903 | 20136 | assert(val->special == ConstValSpecialStatic); |
| 19904 | 20137 | switch (val->type->id) { |
| 19905 | | case TypeTableEntryIdInvalid: |
| 19906 | | case TypeTableEntryIdMetaType: |
| 19907 | | case TypeTableEntryIdOpaque: |
| 19908 | | case TypeTableEntryIdBoundFn: |
| 19909 | | case TypeTableEntryIdArgTuple: |
| 19910 | | case TypeTableEntryIdNamespace: |
| 19911 | | case TypeTableEntryIdBlock: |
| 19912 | | case TypeTableEntryIdUnreachable: |
| 19913 | | case TypeTableEntryIdComptimeFloat: |
| 19914 | | case TypeTableEntryIdComptimeInt: |
| 19915 | | case TypeTableEntryIdUndefined: |
| 19916 | | case TypeTableEntryIdNull: |
| 19917 | | case TypeTableEntryIdPromise: |
| 20138 | case ZigTypeIdInvalid: |
| 20139 | case ZigTypeIdMetaType: |
| 20140 | case ZigTypeIdOpaque: |
| 20141 | case ZigTypeIdBoundFn: |
| 20142 | case ZigTypeIdArgTuple: |
| 20143 | case ZigTypeIdNamespace: |
| 20144 | case ZigTypeIdBlock: |
| 20145 | case ZigTypeIdUnreachable: |
| 20146 | case ZigTypeIdComptimeFloat: |
| 20147 | case ZigTypeIdComptimeInt: |
| 20148 | case ZigTypeIdUndefined: |
| 20149 | case ZigTypeIdNull: |
| 20150 | case ZigTypeIdPromise: |
| 19918 | 20151 | zig_unreachable(); |
| 19919 | | case TypeTableEntryIdVoid: |
| 20152 | case ZigTypeIdVoid: |
| 19920 | 20153 | return; |
| 19921 | | case TypeTableEntryIdBool: |
| 20154 | case ZigTypeIdBool: |
| 19922 | 20155 | val->data.x_bool = (buf[0] != 0); |
| 19923 | 20156 | return; |
| 19924 | | case TypeTableEntryIdInt: |
| 20157 | case ZigTypeIdInt: |
| 19925 | 20158 | bigint_read_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count, |
| 19926 | 20159 | codegen->is_big_endian, val->type->data.integral.is_signed); |
| 19927 | 20160 | return; |
| 19928 | | case TypeTableEntryIdFloat: |
| 20161 | case ZigTypeIdFloat: |
| 19929 | 20162 | float_read_ieee597(val, buf, codegen->is_big_endian); |
| 19930 | 20163 | return; |
| 19931 | | case TypeTableEntryIdPointer: |
| 20164 | case ZigTypeIdPointer: |
| 19932 | 20165 | { |
| 19933 | 20166 | val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 19934 | 20167 | BigInt bn; |
| ... | ... | @@ -19937,35 +20170,35 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 19937 | 20170 | val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&bn); |
| 19938 | 20171 | return; |
| 19939 | 20172 | } |
| 19940 | | case TypeTableEntryIdArray: |
| 20173 | case ZigTypeIdArray: |
| 19941 | 20174 | zig_panic("TODO buf_read_value_bytes array type"); |
| 19942 | | case TypeTableEntryIdStruct: |
| 20175 | case ZigTypeIdStruct: |
| 19943 | 20176 | zig_panic("TODO buf_read_value_bytes struct type"); |
| 19944 | | case TypeTableEntryIdOptional: |
| 20177 | case ZigTypeIdOptional: |
| 19945 | 20178 | zig_panic("TODO buf_read_value_bytes maybe type"); |
| 19946 | | case TypeTableEntryIdErrorUnion: |
| 20179 | case ZigTypeIdErrorUnion: |
| 19947 | 20180 | zig_panic("TODO buf_read_value_bytes error union"); |
| 19948 | | case TypeTableEntryIdErrorSet: |
| 20181 | case ZigTypeIdErrorSet: |
| 19949 | 20182 | zig_panic("TODO buf_read_value_bytes pure error type"); |
| 19950 | | case TypeTableEntryIdEnum: |
| 20183 | case ZigTypeIdEnum: |
| 19951 | 20184 | zig_panic("TODO buf_read_value_bytes enum type"); |
| 19952 | | case TypeTableEntryIdFn: |
| 20185 | case ZigTypeIdFn: |
| 19953 | 20186 | zig_panic("TODO buf_read_value_bytes fn type"); |
| 19954 | | case TypeTableEntryIdUnion: |
| 20187 | case ZigTypeIdUnion: |
| 19955 | 20188 | zig_panic("TODO buf_read_value_bytes union type"); |
| 19956 | 20189 | } |
| 19957 | 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 | 20194 | Error err; |
| 19962 | 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 | 20197 | if (type_is_invalid(dest_type)) |
| 19965 | 20198 | return ira->codegen->builtin_types.entry_invalid; |
| 19966 | 20199 | |
| 19967 | 20200 | IrInstruction *value = instruction->value->other; |
| 19968 | | TypeTableEntry *src_type = value->value.type; |
| 20201 | ZigType *src_type = value->value.type; |
| 19969 | 20202 | if (type_is_invalid(src_type)) |
| 19970 | 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 | 20215 | } |
| 19983 | 20216 | |
| 19984 | 20217 | switch (src_type->id) { |
| 19985 | | case TypeTableEntryIdInvalid: |
| 19986 | | case TypeTableEntryIdMetaType: |
| 19987 | | case TypeTableEntryIdOpaque: |
| 19988 | | case TypeTableEntryIdBoundFn: |
| 19989 | | case TypeTableEntryIdArgTuple: |
| 19990 | | case TypeTableEntryIdNamespace: |
| 19991 | | case TypeTableEntryIdBlock: |
| 19992 | | case TypeTableEntryIdUnreachable: |
| 19993 | | case TypeTableEntryIdComptimeFloat: |
| 19994 | | case TypeTableEntryIdComptimeInt: |
| 19995 | | case TypeTableEntryIdUndefined: |
| 19996 | | case TypeTableEntryIdNull: |
| 20218 | case ZigTypeIdInvalid: |
| 20219 | case ZigTypeIdMetaType: |
| 20220 | case ZigTypeIdOpaque: |
| 20221 | case ZigTypeIdBoundFn: |
| 20222 | case ZigTypeIdArgTuple: |
| 20223 | case ZigTypeIdNamespace: |
| 20224 | case ZigTypeIdBlock: |
| 20225 | case ZigTypeIdUnreachable: |
| 20226 | case ZigTypeIdComptimeFloat: |
| 20227 | case ZigTypeIdComptimeInt: |
| 20228 | case ZigTypeIdUndefined: |
| 20229 | case ZigTypeIdNull: |
| 19997 | 20230 | ir_add_error(ira, dest_type_value, |
| 19998 | 20231 | buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name))); |
| 19999 | 20232 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20008,18 +20241,18 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc |
| 20008 | 20241 | } |
| 20009 | 20242 | |
| 20010 | 20243 | switch (dest_type->id) { |
| 20011 | | case TypeTableEntryIdInvalid: |
| 20012 | | case TypeTableEntryIdMetaType: |
| 20013 | | case TypeTableEntryIdOpaque: |
| 20014 | | case TypeTableEntryIdBoundFn: |
| 20015 | | case TypeTableEntryIdArgTuple: |
| 20016 | | case TypeTableEntryIdNamespace: |
| 20017 | | case TypeTableEntryIdBlock: |
| 20018 | | case TypeTableEntryIdUnreachable: |
| 20019 | | case TypeTableEntryIdComptimeFloat: |
| 20020 | | case TypeTableEntryIdComptimeInt: |
| 20021 | | case TypeTableEntryIdUndefined: |
| 20022 | | case TypeTableEntryIdNull: |
| 20244 | case ZigTypeIdInvalid: |
| 20245 | case ZigTypeIdMetaType: |
| 20246 | case ZigTypeIdOpaque: |
| 20247 | case ZigTypeIdBoundFn: |
| 20248 | case ZigTypeIdArgTuple: |
| 20249 | case ZigTypeIdNamespace: |
| 20250 | case ZigTypeIdBlock: |
| 20251 | case ZigTypeIdUnreachable: |
| 20252 | case ZigTypeIdComptimeFloat: |
| 20253 | case ZigTypeIdComptimeInt: |
| 20254 | case ZigTypeIdUndefined: |
| 20255 | case ZigTypeIdNull: |
| 20023 | 20256 | ir_add_error(ira, dest_type_value, |
| 20024 | 20257 | buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name))); |
| 20025 | 20258 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20057,10 +20290,10 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc |
| 20057 | 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 | 20294 | Error err; |
| 20062 | 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 | 20297 | if (type_is_invalid(dest_type)) |
| 20065 | 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 | 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 | 20339 | IrInstructionDeclRef *instruction) |
| 20107 | 20340 | { |
| 20108 | 20341 | Tld *tld = instruction->tld; |
| ... | ... | @@ -20119,7 +20352,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 20119 | 20352 | case TldIdVar: |
| 20120 | 20353 | { |
| 20121 | 20354 | TldVar *tld_var = (TldVar *)tld; |
| 20122 | | VariableTableEntry *var = tld_var->var; |
| 20355 | ZigVar *var = tld_var->var; |
| 20123 | 20356 | |
| 20124 | 20357 | IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var); |
| 20125 | 20358 | if (type_is_invalid(var_ptr->value.type)) |
| ... | ... | @@ -20141,7 +20374,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 20141 | 20374 | case TldIdFn: |
| 20142 | 20375 | { |
| 20143 | 20376 | TldFn *tld_fn = (TldFn *)tld; |
| 20144 | | FnTableEntry *fn_entry = tld_fn->fn_entry; |
| 20377 | ZigFn *fn_entry = tld_fn->fn_entry; |
| 20145 | 20378 | assert(fn_entry->type_entry); |
| 20146 | 20379 | |
| 20147 | 20380 | if (tld_fn->extern_lib_name != nullptr) { |
| ... | ... | @@ -20163,12 +20396,12 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 20163 | 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 | 20400 | IrInstruction *target = instruction->target->other; |
| 20168 | 20401 | if (type_is_invalid(target->value.type)) |
| 20169 | 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 | 20406 | if (get_codegen_ptr_type(target->value.type) == nullptr) { |
| 20174 | 20407 | ir_add_error(ira, target, |
| ... | ... | @@ -20186,7 +20419,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr |
| 20186 | 20419 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 20187 | 20420 | if (!val) |
| 20188 | 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 | 20423 | IrInstruction *result = ir_create_const(&ira->new_irb, instruction->base.scope, |
| 20191 | 20424 | instruction->base.source_node, usize); |
| 20192 | 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 | 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 | 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 | 20441 | if (type_is_invalid(child_type)) |
| 20209 | 20442 | return ira->codegen->builtin_types.entry_invalid; |
| 20210 | 20443 | |
| 20211 | | if (child_type->id == TypeTableEntryIdUnreachable) { |
| 20444 | if (child_type->id == ZigTypeIdUnreachable) { |
| 20212 | 20445 | ir_add_error(ira, &instruction->base, buf_sprintf("pointer to noreturn not allowed")); |
| 20213 | 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 | 20448 | ir_add_error(ira, &instruction->base, buf_sprintf("unknown-length pointer to opaque")); |
| 20216 | 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 | 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 | 20472 | uint32_t align_bytes; |
| 20240 | 20473 | IrInstruction *align_bytes_inst = instruction->align_bytes->other; |
| 20241 | 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 | 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 | 20490 | Buf *name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque", instruction->base.source_node); |
| 20258 | 20491 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 20259 | 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 | 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 | 20498 | uint32_t align_bytes; |
| 20266 | 20499 | IrInstruction *align_bytes_inst = instruction->align_bytes->other; |
| 20267 | 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 | 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 | 20509 | if (fn_entry == nullptr) { |
| 20277 | 20510 | ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function")); |
| 20278 | 20511 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20301,9 +20534,9 @@ static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, Ir |
| 20301 | 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 | 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 | 20540 | if (type_is_invalid(fn_type)) |
| 20308 | 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 | 20545 | if (!ir_resolve_usize(ira, arg_index_inst, &arg_index)) |
| 20313 | 20546 | return ira->codegen->builtin_types.entry_invalid; |
| 20314 | 20547 | |
| 20315 | | if (fn_type->id != TypeTableEntryIdFn) { |
| 20548 | if (fn_type->id != ZigTypeIdFn) { |
| 20316 | 20549 | ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name))); |
| 20317 | 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 | 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 | 20577 | Error err; |
| 20345 | 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 | 20580 | if (type_is_invalid(enum_type)) |
| 20348 | 20581 | return ira->codegen->builtin_types.entry_invalid; |
| 20349 | 20582 | |
| 20350 | | if (enum_type->id == TypeTableEntryIdEnum) { |
| 20583 | if (enum_type->id == ZigTypeIdEnum) { |
| 20351 | 20584 | if ((err = ensure_complete_type(ira->codegen, enum_type))) |
| 20352 | 20585 | return ira->codegen->builtin_types.entry_invalid; |
| 20353 | 20586 | |
| 20354 | 20587 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 20355 | 20588 | out_val->data.x_type = enum_type->data.enumeration.tag_int_type; |
| 20356 | 20589 | return ira->codegen->builtin_types.entry_type; |
| 20357 | | } else if (enum_type->id == TypeTableEntryIdUnion) { |
| 20590 | } else if (enum_type->id == ZigTypeIdUnion) { |
| 20358 | 20591 | if ((err = ensure_complete_type(ira->codegen, enum_type))) |
| 20359 | 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 | 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 | 20615 | IrInstruction *target_inst = instruction->target->other; |
| 20383 | 20616 | if (type_is_invalid(target_inst->value.type)) |
| 20384 | 20617 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20393,7 +20626,7 @@ static TypeTableEntry *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructi |
| 20393 | 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 | 20630 | IrInstruction *promise_ptr = instruction->promise_ptr->other; |
| 20398 | 20631 | if (type_is_invalid(promise_ptr->value.type)) |
| 20399 | 20632 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20405,7 +20638,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstruct |
| 20405 | 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 | 20642 | IrInstruction *coro_id = instruction->coro_id->other; |
| 20410 | 20643 | if (type_is_invalid(coro_id->value.type)) |
| 20411 | 20644 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20417,14 +20650,14 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstr |
| 20417 | 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 | 20654 | IrInstruction *result = ir_build_coro_size(&ira->new_irb, instruction->base.scope, instruction->base.source_node); |
| 20422 | 20655 | ir_link_new_instruction(result, &instruction->base); |
| 20423 | 20656 | result->value.type = ira->codegen->builtin_types.entry_usize; |
| 20424 | 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 | 20661 | IrInstruction *coro_id = instruction->coro_id->other; |
| 20429 | 20662 | if (type_is_invalid(coro_id->value.type)) |
| 20430 | 20663 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20433,7 +20666,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr |
| 20433 | 20666 | if (type_is_invalid(coro_mem_ptr->value.type)) |
| 20434 | 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 | 20670 | assert(fn_entry != nullptr); |
| 20438 | 20671 | IrInstruction *result = ir_build_coro_begin(&ira->new_irb, instruction->base.scope, instruction->base.source_node, |
| 20439 | 20672 | coro_id, coro_mem_ptr); |
| ... | ... | @@ -20442,13 +20675,13 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr |
| 20442 | 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 | 20679 | IrInstruction *result = ir_get_implicit_allocator(ira, &instruction->base, instruction->id); |
| 20447 | 20680 | ir_link_new_instruction(result, &instruction->base); |
| 20448 | 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 | 20685 | IrInstruction *err_val = instruction->err_val->other; |
| 20453 | 20686 | if (type_is_invalid(err_val->value.type)) |
| 20454 | 20687 | return ir_unreach_error(ira); |
| ... | ... | @@ -20459,7 +20692,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, Ir |
| 20459 | 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 | 20696 | IrInstruction *save_point = nullptr; |
| 20464 | 20697 | if (instruction->save_point != nullptr) { |
| 20465 | 20698 | save_point = instruction->save_point->other; |
| ... | ... | @@ -20478,7 +20711,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrIns |
| 20478 | 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 | 20715 | IrInstruction *result = ir_build_coro_end(&ira->new_irb, instruction->base.scope, |
| 20483 | 20716 | instruction->base.source_node); |
| 20484 | 20717 | ir_link_new_instruction(result, &instruction->base); |
| ... | ... | @@ -20486,7 +20719,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstruc |
| 20486 | 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 | 20723 | IrInstruction *coro_id = instruction->coro_id->other; |
| 20491 | 20724 | if (type_is_invalid(coro_id->value.type)) |
| 20492 | 20725 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20498,12 +20731,12 @@ static TypeTableEntry *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstru |
| 20498 | 20731 | IrInstruction *result = ir_build_coro_free(&ira->new_irb, instruction->base.scope, |
| 20499 | 20732 | instruction->base.source_node, coro_id, coro_handle); |
| 20500 | 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 | 20735 | result->value.type = get_optional_type(ira->codegen, ptr_type); |
| 20503 | 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 | 20740 | IrInstruction *awaiter_handle = instruction->awaiter_handle->other; |
| 20508 | 20741 | if (type_is_invalid(awaiter_handle->value.type)) |
| 20509 | 20742 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20519,7 +20752,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInst |
| 20519 | 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 | 20756 | IrInstruction *coro_handle = instruction->coro_handle->other; |
| 20524 | 20757 | if (type_is_invalid(coro_handle->value.type)) |
| 20525 | 20758 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20531,12 +20764,12 @@ static TypeTableEntry *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstru |
| 20531 | 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 | 20768 | IrInstruction *coro_handle = instruction->coro_handle->other; |
| 20536 | 20769 | if (type_is_invalid(coro_handle->value.type)) |
| 20537 | 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 | 20773 | coro_handle->value.type->data.promise.result_type == nullptr) |
| 20541 | 20774 | { |
| 20542 | 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 | 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 | 20781 | coro_handle->value.type->data.promise.result_type); |
| 20549 | 20782 | |
| 20550 | 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 | 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 | 20791 | IrInstruction *alloc_fn = instruction->alloc_fn->other; |
| 20559 | 20792 | if (type_is_invalid(alloc_fn->value.type)) |
| 20560 | 20793 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20566,17 +20799,17 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, |
| 20566 | 20799 | IrInstruction *result = ir_build_coro_alloc_helper(&ira->new_irb, instruction->base.scope, |
| 20567 | 20800 | instruction->base.source_node, alloc_fn, coro_size); |
| 20568 | 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 | 20803 | result->value.type = get_optional_type(ira->codegen, u8_ptr_type); |
| 20571 | 20804 | return result->value.type; |
| 20572 | 20805 | } |
| 20573 | 20806 | |
| 20574 | | static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) { |
| 20575 | | TypeTableEntry *operand_type = ir_resolve_type(ira, op); |
| 20807 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) { |
| 20808 | ZigType *operand_type = ir_resolve_type(ira, op); |
| 20576 | 20809 | if (type_is_invalid(operand_type)) |
| 20577 | 20810 | return ira->codegen->builtin_types.entry_invalid; |
| 20578 | 20811 | |
| 20579 | | if (operand_type->id == TypeTableEntryIdInt) { |
| 20812 | if (operand_type->id == ZigTypeIdInt) { |
| 20580 | 20813 | if (operand_type->data.integral.bit_count < 8) { |
| 20581 | 20814 | ir_add_error(ira, op, |
| 20582 | 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 | 20836 | return operand_type; |
| 20604 | 20837 | } |
| 20605 | 20838 | |
| 20606 | | static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) { |
| 20607 | | TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other); |
| 20839 | static ZigType *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) { |
| 20840 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other); |
| 20608 | 20841 | if (type_is_invalid(operand_type)) |
| 20609 | 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 | 20846 | return ira->codegen->builtin_types.entry_invalid; |
| 20614 | 20847 | |
| 20615 | 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 | 20850 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 20618 | 20851 | if (type_is_invalid(casted_ptr->value.type)) |
| 20619 | 20852 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20661,8 +20894,8 @@ static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstr |
| 20661 | 20894 | return result->value.type; |
| 20662 | 20895 | } |
| 20663 | 20896 | |
| 20664 | | static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) { |
| 20665 | | TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other); |
| 20897 | static ZigType *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) { |
| 20898 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other); |
| 20666 | 20899 | if (type_is_invalid(operand_type)) |
| 20667 | 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 | 20903 | if (type_is_invalid(ptr_inst->value.type)) |
| 20671 | 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 | 20907 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 20675 | 20908 | if (type_is_invalid(casted_ptr->value.type)) |
| 20676 | 20909 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20704,12 +20937,12 @@ static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInst |
| 20704 | 20937 | return result->value.type; |
| 20705 | 20938 | } |
| 20706 | 20939 | |
| 20707 | | static TypeTableEntry *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) { |
| 20708 | | TypeTableEntry *promise_type = ir_resolve_type(ira, instruction->promise_type->other); |
| 20940 | static ZigType *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) { |
| 20941 | ZigType *promise_type = ir_resolve_type(ira, instruction->promise_type->other); |
| 20709 | 20942 | if (type_is_invalid(promise_type)) |
| 20710 | 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 | 20946 | ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'", |
| 20714 | 20947 | buf_ptr(&promise_type->name))); |
| 20715 | 20948 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20720,12 +20953,12 @@ static TypeTableEntry *ir_analyze_instruction_promise_result_type(IrAnalyze *ira |
| 20720 | 20953 | return ira->codegen->builtin_types.entry_type; |
| 20721 | 20954 | } |
| 20722 | 20955 | |
| 20723 | | static TypeTableEntry *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) { |
| 20724 | | TypeTableEntry *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->other); |
| 20956 | static ZigType *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) { |
| 20957 | ZigType *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->other); |
| 20725 | 20958 | if (type_is_invalid(promise_result_type)) |
| 20726 | 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 | 20962 | assert(fn_entry != nullptr); |
| 20730 | 20963 | |
| 20731 | 20964 | if (type_can_fail(promise_result_type)) { |
| ... | ... | @@ -20737,17 +20970,17 @@ static TypeTableEntry *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, |
| 20737 | 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 | 20974 | IrInstructionMergeErrRetTraces *instruction) |
| 20742 | 20975 | { |
| 20743 | 20976 | IrInstruction *coro_promise_ptr = instruction->coro_promise_ptr->other; |
| 20744 | 20977 | if (type_is_invalid(coro_promise_ptr->value.type)) |
| 20745 | 20978 | return ira->codegen->builtin_types.entry_invalid; |
| 20746 | 20979 | |
| 20747 | | assert(coro_promise_ptr->value.type->id == TypeTableEntryIdPointer); |
| 20748 | | TypeTableEntry *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type; |
| 20749 | | assert(promise_frame_type->id == TypeTableEntryIdStruct); |
| 20750 | | TypeTableEntry *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry; |
| 20980 | assert(coro_promise_ptr->value.type->id == ZigTypeIdPointer); |
| 20981 | ZigType *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type; |
| 20982 | assert(promise_frame_type->id == ZigTypeIdStruct); |
| 20983 | ZigType *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry; |
| 20751 | 20984 | |
| 20752 | 20985 | if (!type_can_fail(promise_result_type)) { |
| 20753 | 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 | 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 | 21007 | IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope, |
| 20775 | 21008 | instruction->base.source_node); |
| 20776 | 21009 | ir_link_new_instruction(result, &instruction->base); |
| ... | ... | @@ -20778,7 +21011,7 @@ static TypeTableEntry *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, |
| 20778 | 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 | 21015 | IrInstruction *err_ret_trace_ptr = instruction->err_ret_trace_ptr->other; |
| 20783 | 21016 | if (type_is_invalid(err_ret_trace_ptr->value.type)) |
| 20784 | 21017 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20790,8 +21023,8 @@ static TypeTableEntry *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze * |
| 20790 | 21023 | return result->value.type; |
| 20791 | 21024 | } |
| 20792 | 21025 | |
| 20793 | | static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) { |
| 20794 | | TypeTableEntry *float_type = ir_resolve_type(ira, instruction->type->other); |
| 21026 | static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) { |
| 21027 | ZigType *float_type = ir_resolve_type(ira, instruction->type->other); |
| 20795 | 21028 | if (type_is_invalid(float_type)) |
| 20796 | 21029 | return ira->codegen->builtin_types.entry_invalid; |
| 20797 | 21030 | |
| ... | ... | @@ -20799,7 +21032,7 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction |
| 20799 | 21032 | if (type_is_invalid(op->value.type)) |
| 20800 | 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 | 21036 | if (!ok_type) { |
| 20804 | 21037 | ir_add_error(ira, instruction->type, buf_sprintf("@sqrt does not support type '%s'", buf_ptr(&float_type->name))); |
| 20805 | 21038 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20816,9 +21049,9 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction |
| 20816 | 21049 | |
| 20817 | 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 | 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 | 21055 | switch (float_type->data.floating.bit_count) { |
| 20823 | 21056 | case 16: |
| 20824 | 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 | 21075 | return float_type; |
| 20843 | 21076 | } |
| 20844 | 21077 | |
| 20845 | | assert(float_type->id == TypeTableEntryIdFloat); |
| 21078 | assert(float_type->id == ZigTypeIdFloat); |
| 20846 | 21079 | if (float_type->data.floating.bit_count != 16 && |
| 20847 | 21080 | float_type->data.floating.bit_count != 32 && |
| 20848 | 21081 | float_type->data.floating.bit_count != 64) { |
| ... | ... | @@ -20857,13 +21090,13 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction |
| 20857 | 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 | 21094 | Error err; |
| 20862 | 21095 | IrInstruction *target = instruction->target->other; |
| 20863 | 21096 | if (type_is_invalid(target->value.type)) |
| 20864 | 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 | 21100 | ir_add_error(ira, instruction->target, |
| 20868 | 21101 | buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name))); |
| 20869 | 21102 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20872,21 +21105,21 @@ static TypeTableEntry *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInst |
| 20872 | 21105 | if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type))) |
| 20873 | 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 | 21110 | IrInstruction *result = ir_analyze_enum_to_int(ira, &instruction->base, target, tag_type); |
| 20878 | 21111 | ir_link_new_instruction(result, &instruction->base); |
| 20879 | 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 | 21116 | Error err; |
| 20884 | 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 | 21119 | if (type_is_invalid(dest_type)) |
| 20887 | 21120 | return ira->codegen->builtin_types.entry_invalid; |
| 20888 | 21121 | |
| 20889 | | if (dest_type->id != TypeTableEntryIdEnum) { |
| 21122 | if (dest_type->id != ZigTypeIdEnum) { |
| 20890 | 21123 | ir_add_error(ira, instruction->dest_type, |
| 20891 | 21124 | buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name))); |
| 20892 | 21125 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -20895,7 +21128,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInst |
| 20895 | 21128 | if ((err = type_ensure_zero_bits_known(ira->codegen, dest_type))) |
| 20896 | 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 | 21133 | IrInstruction *target = instruction->target->other; |
| 20901 | 21134 | if (type_is_invalid(target->value.type)) |
| ... | ... | @@ -20910,7 +21143,30 @@ static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInst |
| 20910 | 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 | 21170 | switch (instruction->id) { |
| 20915 | 21171 | case IrInstructionIdInvalid: |
| 20916 | 21172 | case IrInstructionIdWidenOrShorten: |
| ... | ... | @@ -21186,19 +21442,21 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi |
| 21186 | 21442 | return ir_analyze_instruction_int_to_enum(ira, (IrInstructionIntToEnum *)instruction); |
| 21187 | 21443 | case IrInstructionIdEnumToInt: |
| 21188 | 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 | 21448 | zig_unreachable(); |
| 21191 | 21449 | } |
| 21192 | 21450 | |
| 21193 | | static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction) { |
| 21194 | | TypeTableEntry *instruction_type = ir_analyze_instruction_nocast(ira, instruction); |
| 21451 | static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction) { |
| 21452 | ZigType *instruction_type = ir_analyze_instruction_nocast(ira, instruction); |
| 21195 | 21453 | instruction->value.type = instruction_type; |
| 21196 | 21454 | |
| 21197 | 21455 | if (instruction->other) { |
| 21198 | 21456 | instruction->other->value.type = instruction_type; |
| 21199 | 21457 | } else { |
| 21200 | | assert(instruction_type->id == TypeTableEntryIdInvalid || |
| 21201 | | instruction_type->id == TypeTableEntryIdUnreachable); |
| 21458 | assert(instruction_type->id == ZigTypeIdInvalid || |
| 21459 | instruction_type->id == ZigTypeIdUnreachable); |
| 21202 | 21460 | instruction->other = instruction; |
| 21203 | 21461 | } |
| 21204 | 21462 | |
| ... | ... | @@ -21207,8 +21465,8 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins |
| 21207 | 21465 | |
| 21208 | 21466 | // This function attempts to evaluate IR code while doing type checking and other analysis. |
| 21209 | 21467 | // It emits a new IrExecutable which is partially evaluated IR code. |
| 21210 | | TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec, |
| 21211 | | TypeTableEntry *expected_type, AstNode *expected_type_source_node) |
| 21468 | ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec, |
| 21469 | ZigType *expected_type, AstNode *expected_type_source_node) |
| 21212 | 21470 | { |
| 21213 | 21471 | assert(!old_exec->invalid); |
| 21214 | 21472 | assert(expected_type == nullptr || !type_is_invalid(expected_type)); |
| ... | ... | @@ -21217,7 +21475,7 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl |
| 21217 | 21475 | old_exec->analysis = ira; |
| 21218 | 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 | 21479 | bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync; |
| 21222 | 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 | 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 | 21511 | if (type_is_invalid(return_type) && ir_should_inline(new_exec, old_instruction->scope)) { |
| 21254 | 21512 | return ira->codegen->builtin_types.entry_invalid; |
| 21255 | 21513 | } |
| 21256 | 21514 | |
| 21257 | 21515 | // unreachable instructions do their own control flow. |
| 21258 | | if (return_type->id == TypeTableEntryIdUnreachable) |
| 21516 | if (return_type->id == ZigTypeIdUnreachable) |
| 21259 | 21517 | continue; |
| 21260 | 21518 | |
| 21261 | 21519 | ira->instruction_index += 1; |
| ... | ... | @@ -21301,6 +21559,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 21301 | 21559 | case IrInstructionIdOverflowOp: // TODO when we support multiple returns this can be side effect free |
| 21302 | 21560 | case IrInstructionIdCheckSwitchProngs: |
| 21303 | 21561 | case IrInstructionIdCheckStatementIsVoid: |
| 21562 | case IrInstructionIdCheckRuntimeScope: |
| 21304 | 21563 | case IrInstructionIdPanic: |
| 21305 | 21564 | case IrInstructionIdSetEvalBranchQuota: |
| 21306 | 21565 | case IrInstructionIdPtrType: |