| ... | ... | @@ -15864,7 +15864,11 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 15864 | 15864 | return result; |
| 15865 | 15865 | } |
| 15866 | 15866 | |
| 15867 | | ConstExprValue *result = nullptr; |
| 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. |
| 15868 | 15872 | |
| 15869 | 15873 | switch (type_entry->id) |
| 15870 | 15874 | { |
| ... | ... | @@ -15885,7 +15889,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 15885 | 15889 | return nullptr; |
| 15886 | 15890 | case TypeTableEntryIdInt: |
| 15887 | 15891 | { |
| 15888 | | result = create_const_vals(1); |
| 15892 | ConstExprValue *result = create_const_vals(1); |
| 15889 | 15893 | result->special = ConstValSpecialStatic; |
| 15890 | 15894 | result->type = ir_type_info_get_type(ira, "Int"); |
| 15891 | 15895 | |
| ... | ... | @@ -15893,6 +15897,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 15893 | 15897 | result->data.x_struct.fields = fields; |
| 15894 | 15898 | |
| 15895 | 15899 | ir_type_info_struct_set_parent(result, parent, parent_field_index); |
| 15900 | ira->codegen->type_info_cache.put(type_entry, result); |
| 15896 | 15901 | |
| 15897 | 15902 | // is_signed: bool |
| 15898 | 15903 | ensure_field_index(result->type, "is_signed", 0); |
| ... | ... | @@ -15904,11 +15909,12 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 15904 | 15909 | fields[1].special = ConstValSpecialStatic; |
| 15905 | 15910 | fields[1].type = ira->codegen->builtin_types.entry_u8; |
| 15906 | 15911 | bigint_init_unsigned(&fields[1].data.x_bigint, type_entry->data.integral.bit_count); |
| 15907 | | break; |
| 15912 | |
| 15913 | return result; |
| 15908 | 15914 | } |
| 15909 | 15915 | case TypeTableEntryIdFloat: |
| 15910 | 15916 | { |
| 15911 | | result = create_const_vals(1); |
| 15917 | ConstExprValue *result = create_const_vals(1); |
| 15912 | 15918 | result->special = ConstValSpecialStatic; |
| 15913 | 15919 | result->type = ir_type_info_get_type(ira, "Float"); |
| 15914 | 15920 | |
| ... | ... | @@ -15916,17 +15922,19 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 15916 | 15922 | result->data.x_struct.fields = fields; |
| 15917 | 15923 | |
| 15918 | 15924 | ir_type_info_struct_set_parent(result, parent, parent_field_index); |
| 15925 | ira->codegen->type_info_cache.put(type_entry, result); |
| 15919 | 15926 | |
| 15920 | 15927 | // bits: u8 |
| 15921 | 15928 | ensure_field_index(result->type, "bits", 0); |
| 15922 | 15929 | fields[0].special = ConstValSpecialStatic; |
| 15923 | 15930 | fields[0].type = ira->codegen->builtin_types.entry_u8; |
| 15924 | 15931 | bigint_init_unsigned(&fields->data.x_bigint, type_entry->data.floating.bit_count); |
| 15925 | | break; |
| 15932 | |
| 15933 | return result; |
| 15926 | 15934 | } |
| 15927 | 15935 | case TypeTableEntryIdPointer: |
| 15928 | 15936 | { |
| 15929 | | result = create_const_vals(1); |
| 15937 | ConstExprValue *result = create_const_vals(1); |
| 15930 | 15938 | result->special = ConstValSpecialStatic; |
| 15931 | 15939 | result->type = ir_type_info_get_type(ira, "Pointer"); |
| 15932 | 15940 | |
| ... | ... | @@ -15934,6 +15942,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 15934 | 15942 | result->data.x_struct.fields = fields; |
| 15935 | 15943 | |
| 15936 | 15944 | ir_type_info_struct_set_parent(result, parent, parent_field_index); |
| 15945 | ira->codegen->type_info_cache.put(type_entry, result); |
| 15937 | 15946 | |
| 15938 | 15947 | // is_const: bool |
| 15939 | 15948 | ensure_field_index(result->type, "is_const", 0); |
| ... | ... | @@ -15968,11 +15977,12 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 15968 | 15977 | type_entry->data.pointer.child_type); |
| 15969 | 15978 | |
| 15970 | 15979 | fields[3].data.x_ptr.data.ref.pointee = union_val; |
| 15971 | | break; |
| 15980 | |
| 15981 | return result; |
| 15972 | 15982 | } |
| 15973 | 15983 | case TypeTableEntryIdArray: |
| 15974 | 15984 | { |
| 15975 | | result = create_const_vals(1); |
| 15985 | ConstExprValue *result = create_const_vals(1); |
| 15976 | 15986 | result->special = ConstValSpecialStatic; |
| 15977 | 15987 | result->type = ir_type_info_get_type(ira, "Array"); |
| 15978 | 15988 | |
| ... | ... | @@ -15980,6 +15990,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 15980 | 15990 | result->data.x_struct.fields = fields; |
| 15981 | 15991 | |
| 15982 | 15992 | ir_type_info_struct_set_parent(result, parent, parent_field_index); |
| 15993 | ira->codegen->type_info_cache.put(type_entry, result); |
| 15983 | 15994 | |
| 15984 | 15995 | // len: usize |
| 15985 | 15996 | ensure_field_index(result->type, "len", 0); |
| ... | ... | @@ -15988,7 +15999,6 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 15988 | 15999 | bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.array.len); |
| 15989 | 16000 | // child: &TypeInfo |
| 15990 | 16001 | ensure_field_index(result->type, "child", 1); |
| 15991 | | |
| 15992 | 16002 | TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr); |
| 15993 | 16003 | |
| 15994 | 16004 | fields[1].special = ConstValSpecialStatic; |
| ... | ... | @@ -16004,11 +16014,12 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 16004 | 16014 | type_entry->data.array.child_type); |
| 16005 | 16015 | |
| 16006 | 16016 | fields[1].data.x_ptr.data.ref.pointee = union_val; |
| 16007 | | break; |
| 16017 | |
| 16018 | return result; |
| 16008 | 16019 | } |
| 16009 | 16020 | case TypeTableEntryIdMaybe: |
| 16010 | 16021 | { |
| 16011 | | result = create_const_vals(1); |
| 16022 | ConstExprValue *result = create_const_vals(1); |
| 16012 | 16023 | result->special = ConstValSpecialStatic; |
| 16013 | 16024 | result->type = ir_type_info_get_type(ira, "Nullable"); |
| 16014 | 16025 | |
| ... | ... | @@ -16016,6 +16027,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 16016 | 16027 | result->data.x_struct.fields = fields; |
| 16017 | 16028 | |
| 16018 | 16029 | ir_type_info_struct_set_parent(result, parent, parent_field_index); |
| 16030 | ira->codegen->type_info_cache.put(type_entry, result); |
| 16019 | 16031 | |
| 16020 | 16032 | // child: &TypeInfo |
| 16021 | 16033 | ensure_field_index(result->type, "child", 0); |
| ... | ... | @@ -16035,11 +16047,12 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 16035 | 16047 | type_entry->data.maybe.child_type); |
| 16036 | 16048 | |
| 16037 | 16049 | fields[0].data.x_ptr.data.ref.pointee = union_val; |
| 16038 | | break; |
| 16050 | |
| 16051 | return result; |
| 16039 | 16052 | } |
| 16040 | 16053 | case TypeTableEntryIdPromise: |
| 16041 | 16054 | { |
| 16042 | | result = create_const_vals(1); |
| 16055 | ConstExprValue *result = create_const_vals(1); |
| 16043 | 16056 | result->special = ConstValSpecialStatic; |
| 16044 | 16057 | result->type = ir_type_info_get_type(ira, "Promise"); |
| 16045 | 16058 | |
| ... | ... | @@ -16047,6 +16060,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 16047 | 16060 | result->data.x_struct.fields = fields; |
| 16048 | 16061 | |
| 16049 | 16062 | ir_type_info_struct_set_parent(result, parent, parent_field_index); |
| 16063 | ira->codegen->type_info_cache.put(type_entry, result); |
| 16050 | 16064 | |
| 16051 | 16065 | // child: ?&TypeInfo |
| 16052 | 16066 | ensure_field_index(result->type, "child", 0); |
| ... | ... | @@ -16080,16 +16094,91 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 16080 | 16094 | maybe_value->data.x_ptr.data.ref.pointee = union_val; |
| 16081 | 16095 | fields[0].data.x_maybe = maybe_value; |
| 16082 | 16096 | } |
| 16083 | | break; |
| 16097 | |
| 16098 | return result; |
| 16099 | } |
| 16100 | case TypeTableEntryIdEnum: |
| 16101 | { |
| 16102 | ConstExprValue *result = create_const_vals(1); |
| 16103 | result->special = ConstValSpecialStatic; |
| 16104 | result->type = ir_type_info_get_type(ira, "Enum"); |
| 16105 | |
| 16106 | ConstExprValue *fields = create_const_vals(4); |
| 16107 | result->data.x_struct.fields = fields; |
| 16108 | |
| 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 |
| 16113 | ensure_field_index(result->type, "layout", 0); |
| 16114 | fields[0].special = ConstValSpecialStatic; |
| 16115 | 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); |
| 16117 | // tag_type: &TypeInfo.Int |
| 16118 | 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; |
| 16123 | fields[1].type = get_pointer_to_type(ira->codegen, type_info_int_type, false); |
| 16124 | fields[1].data.x_ptr.special = ConstPtrSpecialRef; |
| 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 |
| 16132 | ensure_field_index(result->type, "fields", 2); |
| 16133 | |
| 16134 | TypeTableEntry *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField"); |
| 16135 | // @TODO Those cause a find_struct_type_field assertion to fail (type_entry->data.structure.complete) |
| 16136 | // ensure_field_index(type_info_enum_field_type, "name", 0); |
| 16137 | // ensure_field_index(type_info_enum_field_type, "value", 1); |
| 16138 | |
| 16139 | uint32_t enum_field_count = type_entry->data.enumeration.src_field_count; |
| 16140 | |
| 16141 | ConstExprValue *enum_field_array = create_const_vals(1); |
| 16142 | enum_field_array->special = ConstValSpecialStatic; |
| 16143 | enum_field_array->type = get_array_type(ira->codegen, type_info_enum_field_type, enum_field_count); |
| 16144 | enum_field_array->data.x_array.special = ConstArraySpecialNone; |
| 16145 | enum_field_array->data.x_array.s_none.parent.id = ConstParentIdNone; |
| 16146 | enum_field_array->data.x_array.s_none.elements = create_const_vals(enum_field_count); |
| 16147 | |
| 16148 | init_const_slice(ira->codegen, &fields[2], enum_field_array, 0, enum_field_count, false); |
| 16149 | |
| 16150 | for (uint32_t enum_field_index = 0; enum_field_index < enum_field_count; enum_field_index++) |
| 16151 | { |
| 16152 | TypeEnumField *enum_field = &type_entry->data.enumeration.fields[enum_field_index]; |
| 16153 | ConstExprValue *enum_field_val = &enum_field_array->data.x_array.s_none.elements[enum_field_index]; |
| 16154 | |
| 16155 | enum_field_val->special = ConstValSpecialStatic; |
| 16156 | enum_field_val->type = type_info_enum_field_type; |
| 16157 | |
| 16158 | ConstExprValue *inner_fields = create_const_vals(2); |
| 16159 | inner_fields[1].special = ConstValSpecialStatic; |
| 16160 | inner_fields[1].type = ira->codegen->builtin_types.entry_usize; |
| 16161 | |
| 16162 | ConstExprValue *name = create_const_str_lit(ira->codegen, enum_field->name); |
| 16163 | init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(enum_field->name), true); |
| 16164 | |
| 16165 | bigint_init_bigint(&inner_fields[1].data.x_bigint, &enum_field->value); |
| 16166 | |
| 16167 | enum_field_val->data.x_struct.fields = inner_fields; |
| 16168 | enum_field_val->data.x_struct.parent.id = ConstParentIdArray; |
| 16169 | enum_field_val->data.x_struct.parent.data.p_array.array_val = enum_field_array; |
| 16170 | enum_field_val->data.x_struct.parent.data.p_array.elem_index = enum_field_index; |
| 16171 | } |
| 16172 | |
| 16173 | // @TODO |
| 16174 | // methods: []TypeInfo.Method |
| 16175 | return result; |
| 16084 | 16176 | } |
| 16085 | 16177 | default: |
| 16086 | 16178 | zig_unreachable(); |
| 16087 | 16179 | } |
| 16088 | 16180 | |
| 16089 | | // Cache the returned value. |
| 16090 | | assert(result != nullptr); |
| 16091 | | ira->codegen->type_info_cache.put(type_entry, result); |
| 16092 | | return result; |
| 16181 | zig_unreachable(); |
| 16093 | 16182 | } |
| 16094 | 16183 | |
| 16095 | 16184 | static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira, |