| ... | @@ -15810,17 +15810,61 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na | ... | @@ -15810,17 +15810,61 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na |
| 15810 | static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *parent, | 15810 | static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *parent, |
| 15811 | ssize_t parent_field_index, TypeTableEntry *type_entry) | 15811 | ssize_t parent_field_index, TypeTableEntry *type_entry) |
| 15812 | { | 15812 | { |
| | 15813 | assert(type_entry != nullptr); |
| | 15814 | assert(!type_is_invalid(type_entry)); |
| | 15815 | |
| 15813 | // Lookup an available value in our cache. | 15816 | // Lookup an available value in our cache. |
| 15814 | auto entry = ira->codegen->type_info_cache.maybe_get(type_entry); | 15817 | auto entry = ira->codegen->type_info_cache.maybe_get(type_entry); |
| 15815 | if (entry != nullptr) | 15818 | if (entry != nullptr) |
| 15816 | return entry->value; | 15819 | { |
| | 15820 | // Override the parent if we need to. |
| | 15821 | ConstExprValue *result = entry->value; |
| 15817 | | 15822 | |
| 15818 | ConstExprValue *result = nullptr; | 15823 | assert(result->type->id == TypeTableEntryIdStruct); |
| 15819 | | 15824 | |
| 15820 | // @TODO | 15825 | ConstParent *curr_parent = &result->data.x_struct.parent; |
| 15821 | // We should probably cache the values generated with a type_entry key. | 15826 | if (curr_parent->id == ConstParentIdStruct) |
| 15822 | assert(type_entry != nullptr); | 15827 | { |
| 15823 | assert(!type_is_invalid(type_entry)); | 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 | ConstExprValue *result = nullptr; |
| 15824 | | 15868 | |
| 15825 | switch (type_entry->id) | 15869 | switch (type_entry->id) |
| 15826 | { | 15870 | { |
| ... | @@ -16042,6 +16086,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p | ... | @@ -16042,6 +16086,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 16042 | zig_unreachable(); | 16086 | zig_unreachable(); |
| 16043 | } | 16087 | } |
| 16044 | | 16088 | |
| | 16089 | // Cache the returned value. |
| 16045 | assert(result != nullptr); | 16090 | assert(result != nullptr); |
| 16046 | ira->codegen->type_info_cache.put(type_entry, result); | 16091 | ira->codegen->type_info_cache.put(type_entry, result); |
| 16047 | return result; | 16092 | return result; |