authorgravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2018-04-26 18:18:47+03:00
committergravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2018-04-26 18:18:47+03:00
logfbbbee6b72991b65c31a8eac8f1edfc3d1a88b59
tree5b8d11c6d73c9bea57f09d2b52ae984337775def
parent4aa5d87ada56f9887d49c7a2a80246e0bb9d5fb9

Switched to shallow TypeInfo.


2 files changed, 69 insertions(+), 226 deletions(-)

src/codegen.cpp+12-12
...@@ -6390,12 +6390,12 @@ static void define_builtin_compile_vars(CodeGen *g) {...@@ -6390,12 +6390,12 @@ static void define_builtin_compile_vars(CodeGen *g) {
6390 " is_const: bool,\n"6390 " is_const: bool,\n"
6391 " is_volatile: bool,\n"6391 " is_volatile: bool,\n"
6392 " alignment: u32,\n"6392 " alignment: u32,\n"
6393 " child: &TypeInfo,\n"6393 " child: type,\n"
6394 " };\n"6394 " };\n"
6395 "\n"6395 "\n"
6396 " pub const Array = struct {\n"6396 " pub const Array = struct {\n"
6397 " len: usize,\n"6397 " len: usize,\n"
6398 " child: &TypeInfo,\n"6398 " child: type,\n"
6399 " };\n"6399 " };\n"
6400 "\n"6400 "\n"
6401 " pub const ContainerLayout = enum {\n"6401 " pub const ContainerLayout = enum {\n"
...@@ -6412,7 +6412,7 @@ static void define_builtin_compile_vars(CodeGen *g) {...@@ -6412,7 +6412,7 @@ static void define_builtin_compile_vars(CodeGen *g) {
6412 " pub const StructField = struct {\n"6412 " pub const StructField = struct {\n"
6413 " name: []const u8,\n"6413 " name: []const u8,\n"
6414 " offset: usize,\n"6414 " offset: usize,\n"
6415 " type_info: &TypeInfo,\n"6415 " field_type: type,\n"
6416 " };\n"6416 " };\n"
6417 "\n"6417 "\n"
6418 " pub const Struct = struct {\n"6418 " pub const Struct = struct {\n"
...@@ -6422,12 +6422,12 @@ static void define_builtin_compile_vars(CodeGen *g) {...@@ -6422,12 +6422,12 @@ static void define_builtin_compile_vars(CodeGen *g) {
6422 " };\n"6422 " };\n"
6423 "\n"6423 "\n"
6424 " pub const Nullable = struct {\n"6424 " pub const Nullable = struct {\n"
6425 " child: &TypeInfo,\n"6425 " child: type,\n"
6426 " };\n"6426 " };\n"
6427 "\n"6427 "\n"
6428 " pub const ErrorUnion = struct {\n"6428 " pub const ErrorUnion = struct {\n"
6429 " error_set: &ErrorSet,\n"6429 " error_set: &ErrorSet,\n"
6430 " payload: &TypeInfo,\n"6430 " payload: type,\n"
6431 " };\n"6431 " };\n"
6432 "\n"6432 "\n"
6433 " pub const Error = struct {\n"6433 " pub const Error = struct {\n"
...@@ -6446,7 +6446,7 @@ static void define_builtin_compile_vars(CodeGen *g) {...@@ -6446,7 +6446,7 @@ static void define_builtin_compile_vars(CodeGen *g) {
6446 "\n"6446 "\n"
6447 " pub const Enum = struct {\n"6447 " pub const Enum = struct {\n"
6448 " layout: ContainerLayout,\n"6448 " layout: ContainerLayout,\n"
6449 " tag_type: &Int,\n"6449 " tag_type: type,\n"
6450 " fields: []EnumField,\n"6450 " fields: []EnumField,\n"
6451 " methods: []Method,\n"6451 " methods: []Method,\n"
6452 " };\n"6452 " };\n"
...@@ -6454,12 +6454,12 @@ static void define_builtin_compile_vars(CodeGen *g) {...@@ -6454,12 +6454,12 @@ static void define_builtin_compile_vars(CodeGen *g) {
6454 " pub const UnionField = struct {\n"6454 " pub const UnionField = struct {\n"
6455 " name: []const u8,\n"6455 " name: []const u8,\n"
6456 " enum_field: EnumField,\n"6456 " enum_field: EnumField,\n"
6457 " type_info: &TypeInfo,\n"6457 " field_type: type,\n"
6458 " };\n"6458 " };\n"
6459 "\n"6459 "\n"
6460 " pub const Union = struct {\n"6460 " pub const Union = struct {\n"
6461 " layout: ContainerLayout,\n"6461 " layout: ContainerLayout,\n"
6462 " tag_type: ?Enum,\n"6462 " tag_type: type,\n"
6463 " fields: []UnionField,\n"6463 " fields: []UnionField,\n"
6464 " methods: []Method,\n"6464 " methods: []Method,\n"
6465 " };\n"6465 " };\n"
...@@ -6476,24 +6476,24 @@ static void define_builtin_compile_vars(CodeGen *g) {...@@ -6476,24 +6476,24 @@ static void define_builtin_compile_vars(CodeGen *g) {
6476 " pub const FnArg = struct {\n"6476 " pub const FnArg = struct {\n"
6477 " is_comptime: bool,\n"6477 " is_comptime: bool,\n"
6478 " name: []const u8,\n"6478 " name: []const u8,\n"
6479 " type_info: &TypeInfo,\n"6479 " arg_type: type,\n"
6480 " };\n"6480 " };\n"
6481 "\n"6481 "\n"
6482 " pub const Fn = struct {\n"6482 " pub const Fn = struct {\n"
6483 " calling_convention: CallingConvention,\n"6483 " calling_convention: CallingConvention,\n"
6484 " is_generic: bool,\n"6484 " is_generic: bool,\n"
6485 " is_varargs: bool,\n"6485 " is_varargs: bool,\n"
6486 " return_type: &TypeInfo,\n"6486 " return_type: type,\n"
6487 " args: []FnArg,\n"6487 " args: []FnArg,\n"
6488 " };\n"6488 " };\n"
6489 "\n"6489 "\n"
6490 " pub const BoundFn = struct {\n"6490 " pub const BoundFn = struct {\n"
6491 " bound_type: &TypeInfo,\n"6491 " bound_type: type,\n"
6492 " fn_info: Fn,\n"6492 " fn_info: Fn,\n"
6493 " };\n"6493 " };\n"
6494 "\n"6494 "\n"
6495 " pub const Promise = struct {\n"6495 " pub const Promise = struct {\n"
6496 " child: ?&TypeInfo,\n"6496 " child: type,\n"
6497 " };\n"6497 " };\n"
6498 "};\n\n");6498 "};\n\n");
6499 assert(ContainerLayoutAuto == 0);6499 assert(ContainerLayoutAuto == 0);
src/ir.cpp+57-214
...@@ -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}
1575015750
15751static 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
15776static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_name)15751static 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}
1580915784
15810static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *parent,15785static 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));
1581515789
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");
1589515822
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;
1589815825
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: bool15826 // 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);
1591215836
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");
1592015844
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;
1592315847
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: u815848 // 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);
1593215853
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");
1594015861
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;
1594315864
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: bool15865 // 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: &TypeInfo15880 // 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));
1597515885
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");
1598815893
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;
1599115896
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: usize15897 // 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: &TypeInfo15902 // 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));
1601215907
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");
1602515915
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;
1602815918
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;
1605015924
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");
1605815932
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;
1606115935
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;
1607315941
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 else15944 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 }
1609715946
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");
1610515954
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;
1610815957
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: ContainerLayout15958 // 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.Int15963 // 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.EnumField15968 // fields: []TypeInfo.EnumField
16132 ensure_field_index(result->type, "fields", 2);15969 ensure_field_index(result->type, "fields", 2);
1613315970
...@@ -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
1617216009
16173 // @TODO16010 // @TODO
16174 // methods: []TypeInfo.Method16011 // 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");
1618216019
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;
1618516022
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.Error16023 // errors: []TypeInfo.Error
16190 ensure_field_index(result->type, "errors", 0);16024 ensure_field_index(result->type, "errors", 0);
1619116025
...@@ -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 }
1623116065
16232 return result;16066 break;
16233 }16067 }
16234 default:
16235 zig_unreachable();
16236 }16068 }
1623716069
16238 zig_unreachable();16070 assert(result != nullptr);
16071 ira->codegen->type_info_cache.put(type_entry, result);
16072 return result;
16239}16073}
1624016074
16241static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,16075static 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 }
1625516098
16256 return result_type;16099 return result_type;
16257}16100}