authorgravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2018-04-26 14:29:27+03:00
committergravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2018-04-26 14:29:27+03:00
log7a91e4736a4151bd41b65b6e3b395cc51c443162
tree700ba05610f280b9a4045929b7973d80a53fb58a
parentbb56360bfaa317809bd3c742a655b357bd5b6226

Reset parent on cached TypeInfo values if we need to.


2 files changed, 53 insertions(+), 7 deletions(-)

src/codegen.cpp+2-1
......@@ -6348,7 +6348,6 @@ static void define_builtin_compile_vars(CodeGen *g) {
63486348 buf_appendf(contents, "};\n\n");
63496349 }
63506350 {
6351 // @TODO Add method info where methods are supported.
63526351 // @TODO Add Namespace info.
63536352 buf_appendf(contents,
63546353 "pub const TypeInfo = union(TypeId) {\n"
......@@ -6449,6 +6448,7 @@ static void define_builtin_compile_vars(CodeGen *g) {
64496448 " layout: ContainerLayout,\n"
64506449 " tag_type: Int,\n"
64516450 " fields: []EnumField,\n"
6451 " methods: []Method,\n"
64526452 " };\n"
64536453 "\n"
64546454 " pub const UnionField = struct {\n"
......@@ -6461,6 +6461,7 @@ static void define_builtin_compile_vars(CodeGen *g) {
64616461 " layout: ContainerLayout,\n"
64626462 " tag_type: ?Enum,\n"
64636463 " fields: []UnionField,\n"
6464 " methods: []Method,\n"
64646465 " };\n"
64656466 "\n"
64666467 " pub const CallingConvention = enum {\n"
src/ir.cpp+51-6
......@@ -15810,17 +15810,61 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na
1581015810static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *parent,
1581115811 ssize_t parent_field_index, TypeTableEntry *type_entry)
1581215812{
15813 assert(type_entry != nullptr);
15814 assert(!type_is_invalid(type_entry));
15815
1581315816 // Lookup an available value in our cache.
1581415817 auto entry = ira->codegen->type_info_cache.maybe_get(type_entry);
1581515818 if (entry != nullptr)
15816 return entry->value;
15819 {
15820 // Override the parent if we need to.
15821 ConstExprValue *result = entry->value;
1581715822
15818 ConstExprValue *result = nullptr;
15823 assert(result->type->id == TypeTableEntryIdStruct);
1581915824
15820 // @TODO
15821 // We should probably cache the values generated with a type_entry key.
15822 assert(type_entry != nullptr);
15823 assert(!type_is_invalid(type_entry));
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 ConstExprValue *result = nullptr;
1582415868
1582515869 switch (type_entry->id)
1582615870 {
......@@ -16042,6 +16086,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
1604216086 zig_unreachable();
1604316087 }
1604416088
16089 // Cache the returned value.
1604516090 assert(result != nullptr);
1604616091 ira->codegen->type_info_cache.put(type_entry, result);
1604716092 return result;