| ... | @@ -15748,31 +15748,6 @@ static void ensure_field_index(TypeTableEntry *type, const char *field_name, siz | ... | @@ -15748,31 +15748,6 @@ static void ensure_field_index(TypeTableEntry *type, const char *field_name, siz |
| 15748 | (buf_deinit(field_name_buf), true)); | 15748 | (buf_deinit(field_name_buf), true)); |
| 15749 | } | 15749 | } |
| 15750 | | 15750 | |
| 15751 | static void ir_type_info_struct_set_parent(ConstExprValue *struct_val, ConstExprValue *parent, ssize_t parent_field_index) | | |
| 15752 | { | | |
| 15753 | assert(struct_val->type->id == TypeTableEntryIdStruct); | | |
| 15754 | assert(parent->type != nullptr && !type_is_invalid(parent->type)); | | |
| 15755 | | | |
| 15756 | switch (parent->type->id) | | |
| 15757 | { | | |
| 15758 | case TypeTableEntryIdArray: | | |
| 15759 | zig_panic("TODO - Only expected struct or union parent."); | | |
| 15760 | case TypeTableEntryIdStruct: | | |
| 15761 | assert(parent_field_index >= 0); | | |
| 15762 | struct_val->data.x_struct.parent.id = ConstParentIdStruct; | | |
| 15763 | struct_val->data.x_struct.parent.data.p_struct.struct_val = parent; | | |
| 15764 | struct_val->data.x_struct.parent.data.p_struct.field_index = parent_field_index; | | |
| 15765 | break; | | |
| 15766 | case TypeTableEntryIdUnion: | | |
| 15767 | assert(parent_field_index == -1); | | |
| 15768 | struct_val->data.x_struct.parent.id = ConstParentIdUnion; | | |
| 15769 | struct_val->data.x_struct.parent.data.p_union.union_val = parent; | | |
| 15770 | break; | | |
| 15771 | default: | | |
| 15772 | struct_val->data.x_struct.parent.id = ConstParentIdNone; | | |
| 15773 | } | | |
| 15774 | } | | |
| 15775 | | | |
| 15776 | static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_name) | 15751 | static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_name) |
| 15777 | { | 15752 | { |
| 15778 | static ConstExprValue *type_info_var = nullptr; | 15753 | static ConstExprValue *type_info_var = nullptr; |
| ... | @@ -15807,69 +15782,12 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na | ... | @@ -15807,69 +15782,12 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na |
| 15807 | return var->value->data.x_type; | 15782 | return var->value->data.x_type; |
| 15808 | } | 15783 | } |
| 15809 | | 15784 | |
| 15810 | static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *parent, | 15785 | static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry) |
| 15811 | ssize_t parent_field_index, TypeTableEntry *type_entry) | | |
| 15812 | { | 15786 | { |
| 15813 | assert(type_entry != nullptr); | 15787 | assert(type_entry != nullptr); |
| 15814 | assert(!type_is_invalid(type_entry)); | 15788 | assert(!type_is_invalid(type_entry)); |
| 15815 | | 15789 | |
| 15816 | // Lookup an available value in our cache. | 15790 | ConstExprValue *result = nullptr; |
| 15817 | auto entry = ira->codegen->type_info_cache.maybe_get(type_entry); | | |
| 15818 | if (entry != nullptr) | | |
| 15819 | { | | |
| 15820 | // Override the parent if we need to. | | |
| 15821 | ConstExprValue *result = entry->value; | | |
| 15822 | | | |
| 15823 | assert(result->type->id == TypeTableEntryIdStruct); | | |
| 15824 | | | |
| 15825 | ConstParent *curr_parent = &result->data.x_struct.parent; | | |
| 15826 | if (curr_parent->id == ConstParentIdStruct) | | |
| 15827 | { | | |
| 15828 | if (curr_parent->data.p_struct.struct_val == parent && | | |
| 15829 | parent_field_index != -1 && | | |
| 15830 | curr_parent->data.p_struct.field_index == (size_t)parent_field_index) | | |
| 15831 | { | | |
| 15832 | return result; | | |
| 15833 | } | | |
| 15834 | ConstExprValue *new_result = create_const_vals(1); | | |
| 15835 | copy_const_val(new_result, result, true); | | |
| 15836 | ir_type_info_struct_set_parent(new_result, parent, parent_field_index); | | |
| 15837 | return new_result; | | |
| 15838 | } | | |
| 15839 | else if (curr_parent->id == ConstParentIdUnion) | | |
| 15840 | { | | |
| 15841 | if (curr_parent->data.p_union.union_val == parent) | | |
| 15842 | { | | |
| 15843 | return result; | | |
| 15844 | } | | |
| 15845 | ConstExprValue *new_result = create_const_vals(1); | | |
| 15846 | copy_const_val(new_result, result, true); | | |
| 15847 | ir_type_info_struct_set_parent(new_result, parent, parent_field_index); | | |
| 15848 | return new_result; | | |
| 15849 | } | | |
| 15850 | else if (curr_parent->id == ConstParentIdNone) | | |
| 15851 | { | | |
| 15852 | if (parent->type->id != TypeTableEntryIdStruct && | | |
| 15853 | parent->type->id != TypeTableEntryIdArray && | | |
| 15854 | parent->type->id != TypeTableEntryIdUnion) | | |
| 15855 | { | | |
| 15856 | return result; | | |
| 15857 | } | | |
| 15858 | ConstExprValue *new_result = create_const_vals(1); | | |
| 15859 | copy_const_val(new_result, result, true); | | |
| 15860 | ir_type_info_struct_set_parent(new_result, parent, parent_field_index); | | |
| 15861 | return new_result; | | |
| 15862 | } | | |
| 15863 | | | |
| 15864 | return result; | | |
| 15865 | } | | |
| 15866 | | | |
| 15867 | // If the value is not present in the cache, we will build it, add it and return it. | | |
| 15868 | // We add values to the cache eagerly, as soon as we have filled out the root object's fields. | | |
| 15869 | // That way, if we need to fetch the value in a recursive call down the line, even if we need to | | |
| 15870 | // copy the value and reajust the parent, the value we get back still points to child values that | | |
| 15871 | // will be filled later. | | |
| 15872 | | | |
| 15873 | switch (type_entry->id) | 15791 | switch (type_entry->id) |
| 15874 | { | 15792 | { |
| 15875 | case TypeTableEntryIdInvalid: | 15793 | case TypeTableEntryIdInvalid: |
| ... | @@ -15887,18 +15805,24 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p | ... | @@ -15887,18 +15805,24 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 15887 | case TypeTableEntryIdArgTuple: | 15805 | case TypeTableEntryIdArgTuple: |
| 15888 | case TypeTableEntryIdOpaque: | 15806 | case TypeTableEntryIdOpaque: |
| 15889 | return nullptr; | 15807 | return nullptr; |
| | 15808 | default: |
| | 15809 | { |
| | 15810 | // Lookup an available value in our cache. |
| | 15811 | auto entry = ira->codegen->type_info_cache.maybe_get(type_entry); |
| | 15812 | if (entry != nullptr) |
| | 15813 | return entry->value; |
| | 15814 | |
| | 15815 | // Fallthrough if we don't find one. |
| | 15816 | } |
| 15890 | case TypeTableEntryIdInt: | 15817 | case TypeTableEntryIdInt: |
| 15891 | { | 15818 | { |
| 15892 | ConstExprValue *result = create_const_vals(1); | 15819 | result = create_const_vals(1); |
| 15893 | result->special = ConstValSpecialStatic; | 15820 | result->special = ConstValSpecialStatic; |
| 15894 | result->type = ir_type_info_get_type(ira, "Int"); | 15821 | result->type = ir_type_info_get_type(ira, "Int"); |
| 15895 | | 15822 | |
| 15896 | ConstExprValue *fields = create_const_vals(2); | 15823 | ConstExprValue *fields = create_const_vals(2); |
| 15897 | result->data.x_struct.fields = fields; | 15824 | result->data.x_struct.fields = fields; |
| 15898 | | 15825 | |
| 15899 | ir_type_info_struct_set_parent(result, parent, parent_field_index); | | |
| 15900 | ira->codegen->type_info_cache.put(type_entry, result); | | |
| 15901 | | | |
| 15902 | // is_signed: bool | 15826 | // is_signed: bool |
| 15903 | ensure_field_index(result->type, "is_signed", 0); | 15827 | ensure_field_index(result->type, "is_signed", 0); |
| 15904 | fields[0].special = ConstValSpecialStatic; | 15828 | fields[0].special = ConstValSpecialStatic; |
| ... | @@ -15910,40 +15834,34 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p | ... | @@ -15910,40 +15834,34 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 15910 | fields[1].type = ira->codegen->builtin_types.entry_u8; | 15834 | fields[1].type = ira->codegen->builtin_types.entry_u8; |
| 15911 | bigint_init_unsigned(&fields[1].data.x_bigint, type_entry->data.integral.bit_count); | 15835 | bigint_init_unsigned(&fields[1].data.x_bigint, type_entry->data.integral.bit_count); |
| 15912 | | 15836 | |
| 15913 | return result; | 15837 | break; |
| 15914 | } | 15838 | } |
| 15915 | case TypeTableEntryIdFloat: | 15839 | case TypeTableEntryIdFloat: |
| 15916 | { | 15840 | { |
| 15917 | ConstExprValue *result = create_const_vals(1); | 15841 | result = create_const_vals(1); |
| 15918 | result->special = ConstValSpecialStatic; | 15842 | result->special = ConstValSpecialStatic; |
| 15919 | result->type = ir_type_info_get_type(ira, "Float"); | 15843 | result->type = ir_type_info_get_type(ira, "Float"); |
| 15920 | | 15844 | |
| 15921 | ConstExprValue *fields = create_const_vals(1); | 15845 | ConstExprValue *fields = create_const_vals(1); |
| 15922 | result->data.x_struct.fields = fields; | 15846 | result->data.x_struct.fields = fields; |
| 15923 | | 15847 | |
| 15924 | ir_type_info_struct_set_parent(result, parent, parent_field_index); | | |
| 15925 | ira->codegen->type_info_cache.put(type_entry, result); | | |
| 15926 | | | |
| 15927 | // bits: u8 | 15848 | // bits: u8 |
| 15928 | ensure_field_index(result->type, "bits", 0); | 15849 | ensure_field_index(result->type, "bits", 0); |
| 15929 | fields[0].special = ConstValSpecialStatic; | 15850 | fields[0].special = ConstValSpecialStatic; |
| 15930 | fields[0].type = ira->codegen->builtin_types.entry_u8; | 15851 | fields[0].type = ira->codegen->builtin_types.entry_u8; |
| 15931 | bigint_init_unsigned(&fields->data.x_bigint, type_entry->data.floating.bit_count); | 15852 | bigint_init_unsigned(&fields->data.x_bigint, type_entry->data.floating.bit_count); |
| 15932 | | 15853 | |
| 15933 | return result; | 15854 | break; |
| 15934 | } | 15855 | } |
| 15935 | case TypeTableEntryIdPointer: | 15856 | case TypeTableEntryIdPointer: |
| 15936 | { | 15857 | { |
| 15937 | ConstExprValue *result = create_const_vals(1); | 15858 | result = create_const_vals(1); |
| 15938 | result->special = ConstValSpecialStatic; | 15859 | result->special = ConstValSpecialStatic; |
| 15939 | result->type = ir_type_info_get_type(ira, "Pointer"); | 15860 | result->type = ir_type_info_get_type(ira, "Pointer"); |
| 15940 | | 15861 | |
| 15941 | ConstExprValue *fields = create_const_vals(4); | 15862 | ConstExprValue *fields = create_const_vals(4); |
| 15942 | result->data.x_struct.fields = fields; | 15863 | result->data.x_struct.fields = fields; |
| 15943 | | 15864 | |
| 15944 | ir_type_info_struct_set_parent(result, parent, parent_field_index); | | |
| 15945 | ira->codegen->type_info_cache.put(type_entry, result); | | |
| 15946 | | | |
| 15947 | // is_const: bool | 15865 | // is_const: bool |
| 15948 | ensure_field_index(result->type, "is_const", 0); | 15866 | ensure_field_index(result->type, "is_const", 0); |
| 15949 | fields[0].special = ConstValSpecialStatic; | 15867 | fields[0].special = ConstValSpecialStatic; |
| ... | @@ -15959,175 +15877,94 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p | ... | @@ -15959,175 +15877,94 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 15959 | fields[2].special = ConstValSpecialStatic; | 15877 | fields[2].special = ConstValSpecialStatic; |
| 15960 | fields[2].type = ira->codegen->builtin_types.entry_u32; | 15878 | fields[2].type = ira->codegen->builtin_types.entry_u32; |
| 15961 | bigint_init_unsigned(&fields[2].data.x_bigint, type_entry->data.pointer.alignment); | 15879 | bigint_init_unsigned(&fields[2].data.x_bigint, type_entry->data.pointer.alignment); |
| 15962 | // child: &TypeInfo | 15880 | // child: type |
| 15963 | ensure_field_index(result->type, "child", 3); | 15881 | ensure_field_index(result->type, "child", 3); |
| 15964 | | | |
| 15965 | TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr); | | |
| 15966 | | | |
| 15967 | fields[3].special = ConstValSpecialStatic; | 15882 | fields[3].special = ConstValSpecialStatic; |
| 15968 | fields[3].type = get_pointer_to_type(ira->codegen, type_info_type, false); | 15883 | fields[3].type = ira->codegen->builtin_types.entry_type; |
| 15969 | fields[3].data.x_ptr.special = ConstPtrSpecialRef; | 15884 | fields[3].data.x_type = type_entry->data.pointer.child_type; |
| 15970 | fields[3].data.x_ptr.mut = ConstPtrMutComptimeVar; | | |
| 15971 | ConstExprValue *union_val = create_const_vals(1); | | |
| 15972 | union_val->special = ConstValSpecialStatic; | | |
| 15973 | union_val->type = type_info_type; | | |
| 15974 | bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.pointer.child_type->id)); | | |
| 15975 | | 15885 | |
| 15976 | union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, -1, | 15886 | break; |
| 15977 | type_entry->data.pointer.child_type); | | |
| 15978 | | | |
| 15979 | fields[3].data.x_ptr.data.ref.pointee = union_val; | | |
| 15980 | | | |
| 15981 | return result; | | |
| 15982 | } | 15887 | } |
| 15983 | case TypeTableEntryIdArray: | 15888 | case TypeTableEntryIdArray: |
| 15984 | { | 15889 | { |
| 15985 | ConstExprValue *result = create_const_vals(1); | 15890 | result = create_const_vals(1); |
| 15986 | result->special = ConstValSpecialStatic; | 15891 | result->special = ConstValSpecialStatic; |
| 15987 | result->type = ir_type_info_get_type(ira, "Array"); | 15892 | result->type = ir_type_info_get_type(ira, "Array"); |
| 15988 | | 15893 | |
| 15989 | ConstExprValue *fields = create_const_vals(2); | 15894 | ConstExprValue *fields = create_const_vals(2); |
| 15990 | result->data.x_struct.fields = fields; | 15895 | result->data.x_struct.fields = fields; |
| 15991 | | 15896 | |
| 15992 | ir_type_info_struct_set_parent(result, parent, parent_field_index); | | |
| 15993 | ira->codegen->type_info_cache.put(type_entry, result); | | |
| 15994 | | | |
| 15995 | // len: usize | 15897 | // len: usize |
| 15996 | ensure_field_index(result->type, "len", 0); | 15898 | ensure_field_index(result->type, "len", 0); |
| 15997 | fields[0].special = ConstValSpecialStatic; | 15899 | fields[0].special = ConstValSpecialStatic; |
| 15998 | fields[0].type = ira->codegen->builtin_types.entry_usize; | 15900 | fields[0].type = ira->codegen->builtin_types.entry_usize; |
| 15999 | bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.array.len); | 15901 | bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.array.len); |
| 16000 | // child: &TypeInfo | 15902 | // child: type |
| 16001 | ensure_field_index(result->type, "child", 1); | 15903 | ensure_field_index(result->type, "child", 1); |
| 16002 | TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr); | | |
| 16003 | | | |
| 16004 | fields[1].special = ConstValSpecialStatic; | 15904 | fields[1].special = ConstValSpecialStatic; |
| 16005 | fields[1].type = get_pointer_to_type(ira->codegen, type_info_type, false); | 15905 | fields[1].type = ira->codegen->builtin_types.entry_type; |
| 16006 | fields[1].data.x_ptr.special = ConstPtrSpecialRef; | 15906 | fields[1].data.x_type = type_entry->data.array.child_type; |
| 16007 | fields[1].data.x_ptr.mut = ConstPtrMutComptimeVar; | | |
| 16008 | ConstExprValue *union_val = create_const_vals(1); | | |
| 16009 | union_val->special = ConstValSpecialStatic; | | |
| 16010 | union_val->type = type_info_type; | | |
| 16011 | bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.array.child_type->id)); | | |
| 16012 | | 15907 | |
| 16013 | union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, -1, | 15908 | break; |
| 16014 | type_entry->data.array.child_type); | | |
| 16015 | | | |
| 16016 | fields[1].data.x_ptr.data.ref.pointee = union_val; | | |
| 16017 | | | |
| 16018 | return result; | | |
| 16019 | } | 15909 | } |
| 16020 | case TypeTableEntryIdMaybe: | 15910 | case TypeTableEntryIdMaybe: |
| 16021 | { | 15911 | { |
| 16022 | ConstExprValue *result = create_const_vals(1); | 15912 | result = create_const_vals(1); |
| 16023 | result->special = ConstValSpecialStatic; | 15913 | result->special = ConstValSpecialStatic; |
| 16024 | result->type = ir_type_info_get_type(ira, "Nullable"); | 15914 | result->type = ir_type_info_get_type(ira, "Nullable"); |
| 16025 | | 15915 | |
| 16026 | ConstExprValue *fields = create_const_vals(1); | 15916 | ConstExprValue *fields = create_const_vals(1); |
| 16027 | result->data.x_struct.fields = fields; | 15917 | result->data.x_struct.fields = fields; |
| 16028 | | 15918 | |
| 16029 | ir_type_info_struct_set_parent(result, parent, parent_field_index); | 15919 | // child: type |
| 16030 | ira->codegen->type_info_cache.put(type_entry, result); | | |
| 16031 | | | |
| 16032 | // child: &TypeInfo | | |
| 16033 | ensure_field_index(result->type, "child", 0); | 15920 | ensure_field_index(result->type, "child", 0); |
| 16034 | | | |
| 16035 | TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr); | | |
| 16036 | | | |
| 16037 | fields[0].special = ConstValSpecialStatic; | 15921 | fields[0].special = ConstValSpecialStatic; |
| 16038 | fields[0].type = get_pointer_to_type(ira->codegen, type_info_type, false); | 15922 | fields[0].type = ira->codegen->builtin_types.entry_type; |
| 16039 | fields[0].data.x_ptr.special = ConstPtrSpecialRef; | 15923 | fields[0].data.x_type = type_entry->data.maybe.child_type; |
| 16040 | fields[0].data.x_ptr.mut = ConstPtrMutComptimeVar; | | |
| 16041 | ConstExprValue *union_val = create_const_vals(1); | | |
| 16042 | union_val->special = ConstValSpecialStatic; | | |
| 16043 | union_val->type = type_info_type; | | |
| 16044 | bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.maybe.child_type->id)); | | |
| 16045 | | | |
| 16046 | union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, -1, | | |
| 16047 | type_entry->data.maybe.child_type); | | |
| 16048 | | | |
| 16049 | fields[0].data.x_ptr.data.ref.pointee = union_val; | | |
| 16050 | | 15924 | |
| 16051 | return result; | 15925 | break; |
| 16052 | } | 15926 | } |
| 16053 | case TypeTableEntryIdPromise: | 15927 | case TypeTableEntryIdPromise: |
| 16054 | { | 15928 | { |
| 16055 | ConstExprValue *result = create_const_vals(1); | 15929 | result = create_const_vals(1); |
| 16056 | result->special = ConstValSpecialStatic; | 15930 | result->special = ConstValSpecialStatic; |
| 16057 | result->type = ir_type_info_get_type(ira, "Promise"); | 15931 | result->type = ir_type_info_get_type(ira, "Promise"); |
| 16058 | | 15932 | |
| 16059 | ConstExprValue *fields = create_const_vals(1); | 15933 | ConstExprValue *fields = create_const_vals(1); |
| 16060 | result->data.x_struct.fields = fields; | 15934 | result->data.x_struct.fields = fields; |
| 16061 | | 15935 | |
| 16062 | ir_type_info_struct_set_parent(result, parent, parent_field_index); | 15936 | // @TODO ?type instead of using @typeOf(undefined) when we have no type. |
| 16063 | ira->codegen->type_info_cache.put(type_entry, result); | 15937 | // child: type |
| 16064 | | | |
| 16065 | // child: ?&TypeInfo | | |
| 16066 | ensure_field_index(result->type, "child", 0); | 15938 | ensure_field_index(result->type, "child", 0); |
| 16067 | | | |
| 16068 | TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr); | | |
| 16069 | TypeTableEntry *type_info_ptr_type = get_pointer_to_type(ira->codegen, type_info_type, false); | | |
| 16070 | | | |
| 16071 | fields[0].special = ConstValSpecialStatic; | 15939 | fields[0].special = ConstValSpecialStatic; |
| 16072 | fields[0].type = get_maybe_type(ira->codegen, type_info_ptr_type); | 15940 | fields[0].type = ira->codegen->builtin_types.entry_type; |
| 16073 | | 15941 | |
| 16074 | if (type_entry->data.promise.result_type == nullptr) | 15942 | if (type_entry->data.promise.result_type == nullptr) |
| 16075 | { | 15943 | fields[0].data.x_type = ira->codegen->builtin_types.entry_undef; |
| 16076 | fields[0].data.x_maybe = nullptr; | | |
| 16077 | } | | |
| 16078 | else | 15944 | else |
| 16079 | { | 15945 | fields[0].data.x_type = type_entry->data.promise.result_type; |
| 16080 | ConstExprValue *maybe_value = create_const_vals(1); | | |
| 16081 | maybe_value->special = ConstValSpecialStatic; | | |
| 16082 | maybe_value->type = type_info_ptr_type; | | |
| 16083 | | | |
| 16084 | maybe_value->data.x_ptr.special = ConstPtrSpecialRef; | | |
| 16085 | maybe_value->data.x_ptr.mut = ConstPtrMutComptimeVar; | | |
| 16086 | | | |
| 16087 | ConstExprValue *union_val = create_const_vals(1); | | |
| 16088 | union_val->special = ConstValSpecialStatic; | | |
| 16089 | union_val->type = type_info_type; | | |
| 16090 | bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.promise.result_type->id)); | | |
| 16091 | union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, -1, | | |
| 16092 | type_entry->data.promise.result_type); | | |
| 16093 | | | |
| 16094 | maybe_value->data.x_ptr.data.ref.pointee = union_val; | | |
| 16095 | fields[0].data.x_maybe = maybe_value; | | |
| 16096 | } | | |
| 16097 | | 15946 | |
| 16098 | return result; | 15947 | break; |
| 16099 | } | 15948 | } |
| 16100 | case TypeTableEntryIdEnum: | 15949 | case TypeTableEntryIdEnum: |
| 16101 | { | 15950 | { |
| 16102 | ConstExprValue *result = create_const_vals(1); | 15951 | result = create_const_vals(1); |
| 16103 | result->special = ConstValSpecialStatic; | 15952 | result->special = ConstValSpecialStatic; |
| 16104 | result->type = ir_type_info_get_type(ira, "Enum"); | 15953 | result->type = ir_type_info_get_type(ira, "Enum"); |
| 16105 | | 15954 | |
| 16106 | ConstExprValue *fields = create_const_vals(4); | 15955 | ConstExprValue *fields = create_const_vals(4); |
| 16107 | result->data.x_struct.fields = fields; | 15956 | result->data.x_struct.fields = fields; |
| 16108 | | 15957 | |
| 16109 | ir_type_info_struct_set_parent(result, parent, parent_field_index); | | |
| 16110 | ira->codegen->type_info_cache.put(type_entry, result); | | |
| 16111 | | | |
| 16112 | // layout: ContainerLayout | 15958 | // layout: ContainerLayout |
| 16113 | ensure_field_index(result->type, "layout", 0); | 15959 | ensure_field_index(result->type, "layout", 0); |
| 16114 | fields[0].special = ConstValSpecialStatic; | 15960 | fields[0].special = ConstValSpecialStatic; |
| 16115 | fields[0].type = ir_type_info_get_type(ira, "ContainerLayout"); | 15961 | fields[0].type = ir_type_info_get_type(ira, "ContainerLayout"); |
| 16116 | bigint_init_unsigned(&fields[0].data.x_enum_tag, type_entry->data.enumeration.layout); | 15962 | bigint_init_unsigned(&fields[0].data.x_enum_tag, type_entry->data.enumeration.layout); |
| 16117 | // tag_type: &TypeInfo.Int | 15963 | // tag_type: type |
| 16118 | ensure_field_index(result->type, "tag_type", 1); | 15964 | ensure_field_index(result->type, "tag_type", 1); |
| 16119 | | | |
| 16120 | TypeTableEntry *type_info_int_type = ir_type_info_get_type(ira, "Int"); | | |
| 16121 | | | |
| 16122 | fields[1].special = ConstValSpecialStatic; | 15965 | fields[1].special = ConstValSpecialStatic; |
| 16123 | fields[1].type = get_pointer_to_type(ira->codegen, type_info_int_type, false); | 15966 | fields[1].type = ira->codegen->builtin_types.entry_type; |
| 16124 | fields[1].data.x_ptr.special = ConstPtrSpecialRef; | 15967 | fields[1].data.x_type = type_entry->data.enumeration.tag_int_type; |
| 16125 | fields[1].data.x_ptr.mut = ConstPtrMutComptimeVar; | | |
| 16126 | | | |
| 16127 | ConstExprValue *tag_type_info_struct = ir_make_type_info_value(ira, &fields[1], -1, | | |
| 16128 | type_entry->data.enumeration.tag_int_type); | | |
| 16129 | assert(tag_type_info_struct->type == type_info_int_type); | | |
| 16130 | fields[1].data.x_ptr.data.ref.pointee = tag_type_info_struct; | | |
| 16131 | // fields: []TypeInfo.EnumField | 15968 | // fields: []TypeInfo.EnumField |
| 16132 | ensure_field_index(result->type, "fields", 2); | 15969 | ensure_field_index(result->type, "fields", 2); |
| 16133 | | 15970 | |
| ... | @@ -16172,20 +16009,17 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p | ... | @@ -16172,20 +16009,17 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 16172 | | 16009 | |
| 16173 | // @TODO | 16010 | // @TODO |
| 16174 | // methods: []TypeInfo.Method | 16011 | // methods: []TypeInfo.Method |
| 16175 | return result; | 16012 | break; |
| 16176 | } | 16013 | } |
| 16177 | case TypeTableEntryIdErrorSet: | 16014 | case TypeTableEntryIdErrorSet: |
| 16178 | { | 16015 | { |
| 16179 | ConstExprValue *result = create_const_vals(1); | 16016 | result = create_const_vals(1); |
| 16180 | result->special = ConstValSpecialStatic; | 16017 | result->special = ConstValSpecialStatic; |
| 16181 | result->type = ir_type_info_get_type(ira, "ErrorSet"); | 16018 | result->type = ir_type_info_get_type(ira, "ErrorSet"); |
| 16182 | | 16019 | |
| 16183 | ConstExprValue *fields = create_const_vals(1); | 16020 | ConstExprValue *fields = create_const_vals(1); |
| 16184 | result->data.x_struct.fields = fields; | 16021 | result->data.x_struct.fields = fields; |
| 16185 | | 16022 | |
| 16186 | ir_type_info_struct_set_parent(result, parent, parent_field_index); | | |
| 16187 | ira->codegen->type_info_cache.put(type_entry, result); | | |
| 16188 | | | |
| 16189 | // errors: []TypeInfo.Error | 16023 | // errors: []TypeInfo.Error |
| 16190 | ensure_field_index(result->type, "errors", 0); | 16024 | ensure_field_index(result->type, "errors", 0); |
| 16191 | | 16025 | |
| ... | @@ -16229,13 +16063,13 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p | ... | @@ -16229,13 +16063,13 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 16229 | error_val->data.x_struct.parent.data.p_array.elem_index = error_index; | 16063 | error_val->data.x_struct.parent.data.p_array.elem_index = error_index; |
| 16230 | } | 16064 | } |
| 16231 | | 16065 | |
| 16232 | return result; | 16066 | break; |
| 16233 | } | 16067 | } |
| 16234 | default: | | |
| 16235 | zig_unreachable(); | | |
| 16236 | } | 16068 | } |
| 16237 | | 16069 | |
| 16238 | zig_unreachable(); | 16070 | assert(result != nullptr); |
| | 16071 | ira->codegen->type_info_cache.put(type_entry, result); |
| | 16072 | return result; |
| 16239 | } | 16073 | } |
| 16240 | | 16074 | |
| 16241 | static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira, | 16075 | static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira, |
| ... | @@ -16251,7 +16085,16 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira, | ... | @@ -16251,7 +16085,16 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira, |
| 16251 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 16085 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 16252 | out_val->type = result_type; | 16086 | out_val->type = result_type; |
| 16253 | bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry->id)); | 16087 | bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry->id)); |
| 16254 | out_val->data.x_union.payload = ir_make_type_info_value(ira, out_val, -1, type_entry); | 16088 | |
| | 16089 | ConstExprValue *payload = ir_make_type_info_value(ira, type_entry); |
| | 16090 | out_val->data.x_union.payload = payload; |
| | 16091 | |
| | 16092 | if (payload != nullptr) |
| | 16093 | { |
| | 16094 | assert(payload->type->id == TypeTableEntryIdStruct); |
| | 16095 | payload->data.x_struct.parent.id = ConstParentIdUnion; |
| | 16096 | payload->data.x_struct.parent.data.p_union.union_val = out_val; |
| | 16097 | } |
| 16255 | | 16098 | |
| 16256 | return result_type; | 16099 | return result_type; |
| 16257 | } | 16100 | } |