| ... | ... | @@ -8556,6 +8556,9 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 8556 | 8556 | add_node_error(irb->codegen, node, |
| 8557 | 8557 | buf_sprintf("inferred array size invalid here")); |
| 8558 | 8558 | return irb->codegen->invalid_instruction; |
| 8559 | case NodeTypeVarFieldType: |
| 8560 | return ir_lval_wrap(irb, scope, |
| 8561 | ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_var), lval, result_loc); |
| 8559 | 8562 | } |
| 8560 | 8563 | zig_unreachable(); |
| 8561 | 8564 | } |
| ... | ... | @@ -8715,6 +8718,9 @@ ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprVal |
| 8715 | 8718 | assert(val != nullptr); |
| 8716 | 8719 | assert(const_val->type->id == ZigTypeIdPointer); |
| 8717 | 8720 | ZigType *expected_type = const_val->type->data.pointer.child_type; |
| 8721 | if (expected_type == codegen->builtin_types.entry_var) { |
| 8722 | return val; |
| 8723 | } |
| 8718 | 8724 | switch (type_has_one_possible_value(codegen, expected_type)) { |
| 8719 | 8725 | case OnePossibleValueInvalid: |
| 8720 | 8726 | return nullptr; |
| ... | ... | @@ -13502,6 +13508,9 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 13502 | 13508 | } |
| 13503 | 13509 | if (ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 13504 | 13510 | ConstExprValue *pointee = const_ptr_pointee_unchecked(ira->codegen, &ptr->value); |
| 13511 | if (child_type == ira->codegen->builtin_types.entry_var) { |
| 13512 | child_type = pointee->type; |
| 13513 | } |
| 13505 | 13514 | if (pointee->special != ConstValSpecialRuntime) { |
| 13506 | 13515 | IrInstruction *result = ir_const(ira, source_instruction, child_type); |
| 13507 | 13516 | |
| ... | ... | @@ -19857,13 +19866,24 @@ static IrInstruction *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIns |
| 19857 | 19866 | return ir_analyze_test_non_null(ira, &instruction->base, value); |
| 19858 | 19867 | } |
| 19859 | 19868 | |
| 19869 | static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) { |
| 19870 | ir_assert(ptr->value.type->id == ZigTypeIdPointer, ptr); |
| 19871 | ZigType *elem_type = ptr->value.type->data.pointer.child_type; |
| 19872 | if (elem_type != g->builtin_types.entry_var) |
| 19873 | return elem_type; |
| 19874 | |
| 19875 | if (ir_resolve_lazy(g, ptr->source_node, &ptr->value)) |
| 19876 | return g->builtin_types.entry_invalid; |
| 19877 | |
| 19878 | assert(value_is_comptime(&ptr->value)); |
| 19879 | ConstExprValue *pointee = const_ptr_pointee_unchecked(g, &ptr->value); |
| 19880 | return pointee->type; |
| 19881 | } |
| 19882 | |
| 19860 | 19883 | static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 19861 | 19884 | IrInstruction *base_ptr, bool safety_check_on, bool initializing) |
| 19862 | 19885 | { |
| 19863 | | ZigType *ptr_type = base_ptr->value.type; |
| 19864 | | assert(ptr_type->id == ZigTypeIdPointer); |
| 19865 | | |
| 19866 | | ZigType *type_entry = ptr_type->data.pointer.child_type; |
| 19886 | ZigType *type_entry = get_ptr_elem_type(ira->codegen, base_ptr); |
| 19867 | 19887 | if (type_is_invalid(type_entry)) |
| 19868 | 19888 | return ira->codegen->invalid_instruction; |
| 19869 | 19889 | |
| ... | ... | @@ -19901,7 +19921,8 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 19901 | 19921 | |
| 19902 | 19922 | ZigType *child_type = type_entry->data.maybe.child_type; |
| 19903 | 19923 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 19904 | | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, PtrLenSingle, 0, 0, 0, false); |
| 19924 | base_ptr->value.type->data.pointer.is_const, base_ptr->value.type->data.pointer.is_volatile, |
| 19925 | PtrLenSingle, 0, 0, 0, false); |
| 19905 | 19926 | |
| 19906 | 19927 | bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, child_type, type_entry); |
| 19907 | 19928 | |
| ... | ... | @@ -21627,20 +21648,15 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty |
| 21627 | 21648 | fields[5]->special = ConstValSpecialStatic; |
| 21628 | 21649 | fields[5]->type = ira->codegen->builtin_types.entry_bool; |
| 21629 | 21650 | fields[5]->data.x_bool = attrs_type->data.pointer.allow_zero; |
| 21630 | | // sentinel: ?*const c_void |
| 21631 | | ZigType *ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_c_void, true); |
| 21651 | // sentinel: var |
| 21632 | 21652 | ensure_field_index(result->type, "sentinel", 6); |
| 21633 | 21653 | fields[6]->special = ConstValSpecialStatic; |
| 21634 | | fields[6]->type = get_optional_type(ira->codegen, ptr_type); |
| 21635 | | if (attrs_type->data.pointer.sentinel == nullptr) { |
| 21636 | | fields[6]->data.x_optional = nullptr; |
| 21654 | if (attrs_type->data.pointer.sentinel != nullptr) { |
| 21655 | fields[6]->type = get_optional_type(ira->codegen, attrs_type->data.pointer.child_type); |
| 21656 | fields[6]->data.x_optional = attrs_type->data.pointer.sentinel; |
| 21637 | 21657 | } else { |
| 21638 | | ConstExprValue *ptr_val = create_const_vals(1); |
| 21639 | | fields[6]->data.x_optional = ptr_val; |
| 21640 | | ptr_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 21641 | | ptr_val->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 21642 | | ptr_val->data.x_ptr.data.ref.pointee = create_const_vals(1); |
| 21643 | | copy_const_val(ptr_val->data.x_ptr.data.ref.pointee, attrs_type->data.pointer.sentinel, false); |
| 21658 | fields[6]->type = ira->codegen->builtin_types.entry_null; |
| 21659 | fields[6]->data.x_optional = nullptr; |
| 21644 | 21660 | } |
| 21645 | 21661 | |
| 21646 | 21662 | return result; |
| ... | ... | @@ -21762,23 +21778,10 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 21762 | 21778 | fields[1]->special = ConstValSpecialStatic; |
| 21763 | 21779 | fields[1]->type = ira->codegen->builtin_types.entry_type; |
| 21764 | 21780 | fields[1]->data.x_type = type_entry->data.array.child_type; |
| 21765 | | // sentinel: ?*const c_void |
| 21781 | // sentinel: var |
| 21766 | 21782 | fields[2]->special = ConstValSpecialStatic; |
| 21767 | | ZigType *ptr_type = get_pointer_to_type(ira->codegen, |
| 21768 | | ira->codegen->builtin_types.entry_c_void, true); |
| 21769 | | fields[2]->type = get_optional_type(ira->codegen, ptr_type); |
| 21770 | | if (type_entry->data.array.sentinel == nullptr) { |
| 21771 | | fields[2]->data.x_optional = nullptr; |
| 21772 | | } else { |
| 21773 | | ConstExprValue *ptr_val = create_const_vals(1); |
| 21774 | | fields[2]->data.x_optional = ptr_val; |
| 21775 | | ptr_val->type = ptr_type; |
| 21776 | | ptr_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 21777 | | ptr_val->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 21778 | | ptr_val->data.x_ptr.data.ref.pointee = create_const_vals(1); |
| 21779 | | copy_const_val(ptr_val->data.x_ptr.data.ref.pointee, type_entry->data.array.sentinel, false); |
| 21780 | | } |
| 21781 | | |
| 21783 | fields[2]->type = get_optional_type(ira->codegen, type_entry->data.array.child_type); |
| 21784 | fields[2]->data.x_optional = type_entry->data.array.sentinel; |
| 21782 | 21785 | break; |
| 21783 | 21786 | } |
| 21784 | 21787 | case ZigTypeIdVector: { |
| ... | ... | @@ -22290,15 +22293,18 @@ static ConstExprValue *get_const_field(IrAnalyze *ira, ConstExprValue *struct_va |
| 22290 | 22293 | return struct_value->data.x_struct.fields[field_index]; |
| 22291 | 22294 | } |
| 22292 | 22295 | |
| 22293 | | static ConstExprValue *get_const_field_variant(IrAnalyze *ira, ConstExprValue *struct_value, |
| 22294 | | const char *name, size_t field_index) |
| 22296 | static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *struct_value, |
| 22297 | const char *name, size_t field_index, ZigType *elem_type, ConstExprValue **result) |
| 22295 | 22298 | { |
| 22296 | 22299 | ConstExprValue *field_val = get_const_field(ira, struct_value, name, field_index); |
| 22297 | | assert(field_val->type->id == ZigTypeIdOptional); |
| 22298 | | ConstExprValue *opt_val = field_val->data.x_optional; |
| 22299 | | if (opt_val == nullptr) return nullptr; |
| 22300 | | assert(opt_val->type->id == ZigTypeIdPointer); |
| 22301 | | return const_ptr_pointee_unchecked(ira->codegen, opt_val); |
| 22300 | IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type); |
| 22301 | IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst, |
| 22302 | get_optional_type(ira->codegen, elem_type)); |
| 22303 | if (type_is_invalid(casted_field_inst->value.type)) |
| 22304 | return ErrorSemanticAnalyzeFail; |
| 22305 | |
| 22306 | *result = casted_field_inst->value.data.x_optional; |
| 22307 | return ErrorNone; |
| 22302 | 22308 | } |
| 22303 | 22309 | |
| 22304 | 22310 | static bool get_const_field_bool(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index) |
| ... | ... | @@ -22323,6 +22329,7 @@ static ZigType *get_const_field_meta_type(IrAnalyze *ira, ConstExprValue *struct |
| 22323 | 22329 | } |
| 22324 | 22330 | |
| 22325 | 22331 | static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, ZigTypeId tagTypeId, ConstExprValue *payload) { |
| 22332 | Error err; |
| 22326 | 22333 | switch (tagTypeId) { |
| 22327 | 22334 | case ZigTypeIdInvalid: |
| 22328 | 22335 | zig_unreachable(); |
| ... | ... | @@ -22364,8 +22371,16 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi |
| 22364 | 22371 | assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type)); |
| 22365 | 22372 | BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag); |
| 22366 | 22373 | PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index); |
| 22374 | ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 4); |
| 22375 | ConstExprValue *sentinel; |
| 22376 | if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6, |
| 22377 | elem_type, &sentinel))) |
| 22378 | { |
| 22379 | return nullptr; |
| 22380 | } |
| 22381 | |
| 22367 | 22382 | ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen, |
| 22368 | | get_const_field_meta_type(ira, payload, "child", 4), |
| 22383 | elem_type, |
| 22369 | 22384 | get_const_field_bool(ira, payload, "is_const", 1), |
| 22370 | 22385 | get_const_field_bool(ira, payload, "is_volatile", 2), |
| 22371 | 22386 | ptr_len, |
| ... | ... | @@ -22373,22 +22388,26 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi |
| 22373 | 22388 | 0, // bit_offset_in_host |
| 22374 | 22389 | 0, // host_int_bytes |
| 22375 | 22390 | get_const_field_bool(ira, payload, "is_allowzero", 5), |
| 22376 | | VECTOR_INDEX_NONE, |
| 22377 | | nullptr, |
| 22378 | | get_const_field_variant(ira, payload, "sentinel", 6) |
| 22379 | | ); |
| 22391 | VECTOR_INDEX_NONE, nullptr, sentinel); |
| 22380 | 22392 | if (size_enum_index != 2) |
| 22381 | 22393 | return ptr_type; |
| 22382 | 22394 | return get_slice_type(ira->codegen, ptr_type); |
| 22383 | 22395 | } |
| 22384 | | case ZigTypeIdArray: |
| 22396 | case ZigTypeIdArray: { |
| 22385 | 22397 | assert(payload->special == ConstValSpecialStatic); |
| 22386 | 22398 | assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr)); |
| 22399 | ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 1); |
| 22400 | ConstExprValue *sentinel; |
| 22401 | if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2, |
| 22402 | elem_type, &sentinel))) |
| 22403 | { |
| 22404 | return nullptr; |
| 22405 | } |
| 22387 | 22406 | return get_array_type(ira->codegen, |
| 22388 | | get_const_field_meta_type(ira, payload, "child", 1), |
| 22407 | elem_type, |
| 22389 | 22408 | bigint_as_u64(get_const_field_lit_int(ira, payload, "len", 0)), |
| 22390 | | get_const_field_variant(ira, payload, "sentinel", 2) |
| 22391 | | ); |
| 22409 | sentinel); |
| 22410 | } |
| 22392 | 22411 | case ZigTypeIdComptimeFloat: |
| 22393 | 22412 | return ira->codegen->builtin_types.entry_num_lit_float; |
| 22394 | 22413 | case ZigTypeIdComptimeInt: |