| ... | @@ -15810,6 +15810,15 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na | ... | @@ -15810,6 +15810,15 @@ 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 | // Lookup an available value in our cache. |
| | 15814 | auto entry = ira->codegen->type_info_cache.maybe_get(type_entry); |
| | 15815 | if (entry != nullptr) |
| | 15816 | return entry->value; |
| | 15817 | |
| | 15818 | ConstExprValue *result = nullptr; |
| | 15819 | |
| | 15820 | // @TODO |
| | 15821 | // We should probably cache the values generated with a type_entry key. |
| 15813 | assert(type_entry != nullptr); | 15822 | assert(type_entry != nullptr); |
| 15814 | assert(!type_is_invalid(type_entry)); | 15823 | assert(!type_is_invalid(type_entry)); |
| 15815 | | 15824 | |
| ... | @@ -15832,75 +15841,73 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p | ... | @@ -15832,75 +15841,73 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 15832 | return nullptr; | 15841 | return nullptr; |
| 15833 | case TypeTableEntryIdInt: | 15842 | case TypeTableEntryIdInt: |
| 15834 | { | 15843 | { |
| 15835 | ConstExprValue *payload = create_const_vals(1); | 15844 | result = create_const_vals(1); |
| 15836 | payload->special = ConstValSpecialStatic; | 15845 | result->special = ConstValSpecialStatic; |
| 15837 | payload->type = ir_type_info_get_type(ira, "Int"); | 15846 | result->type = ir_type_info_get_type(ira, "Int"); |
| 15838 | | 15847 | |
| 15839 | ConstExprValue *fields = create_const_vals(2); | 15848 | ConstExprValue *fields = create_const_vals(2); |
| 15840 | payload->data.x_struct.fields = fields; | 15849 | result->data.x_struct.fields = fields; |
| 15841 | | 15850 | |
| 15842 | ir_type_info_struct_set_parent(payload, parent, parent_field_index); | 15851 | ir_type_info_struct_set_parent(result, parent, parent_field_index); |
| 15843 | | 15852 | |
| 15844 | // is_signed: bool | 15853 | // is_signed: bool |
| 15845 | ensure_field_index(payload->type, "is_signed", 0); | 15854 | ensure_field_index(result->type, "is_signed", 0); |
| 15846 | fields[0].special = ConstValSpecialStatic; | 15855 | fields[0].special = ConstValSpecialStatic; |
| 15847 | fields[0].type = ira->codegen->builtin_types.entry_bool; | 15856 | fields[0].type = ira->codegen->builtin_types.entry_bool; |
| 15848 | fields[0].data.x_bool = type_entry->data.integral.is_signed; | 15857 | fields[0].data.x_bool = type_entry->data.integral.is_signed; |
| 15849 | // bits: u8 | 15858 | // bits: u8 |
| 15850 | ensure_field_index(payload->type, "bits", 1); | 15859 | ensure_field_index(result->type, "bits", 1); |
| 15851 | fields[1].special = ConstValSpecialStatic; | 15860 | fields[1].special = ConstValSpecialStatic; |
| 15852 | fields[1].type = ira->codegen->builtin_types.entry_u8; | 15861 | fields[1].type = ira->codegen->builtin_types.entry_u8; |
| 15853 | bigint_init_unsigned(&fields[1].data.x_bigint, type_entry->data.integral.bit_count); | 15862 | bigint_init_unsigned(&fields[1].data.x_bigint, type_entry->data.integral.bit_count); |
| 15854 | | 15863 | break; |
| 15855 | return payload; | | |
| 15856 | } | 15864 | } |
| 15857 | case TypeTableEntryIdFloat: | 15865 | case TypeTableEntryIdFloat: |
| 15858 | { | 15866 | { |
| 15859 | ConstExprValue *payload = create_const_vals(1); | 15867 | result = create_const_vals(1); |
| 15860 | payload->special = ConstValSpecialStatic; | 15868 | result->special = ConstValSpecialStatic; |
| 15861 | payload->type = ir_type_info_get_type(ira, "Float"); | 15869 | result->type = ir_type_info_get_type(ira, "Float"); |
| 15862 | | 15870 | |
| 15863 | ConstExprValue *fields = create_const_vals(1); | 15871 | ConstExprValue *fields = create_const_vals(1); |
| 15864 | payload->data.x_struct.fields = fields; | 15872 | result->data.x_struct.fields = fields; |
| 15865 | | 15873 | |
| 15866 | ir_type_info_struct_set_parent(payload, parent, parent_field_index); | 15874 | ir_type_info_struct_set_parent(result, parent, parent_field_index); |
| 15867 | | 15875 | |
| 15868 | // bits: u8 | 15876 | // bits: u8 |
| 15869 | ensure_field_index(payload->type, "bits", 0); | 15877 | ensure_field_index(result->type, "bits", 0); |
| 15870 | fields[0].special = ConstValSpecialStatic; | 15878 | fields[0].special = ConstValSpecialStatic; |
| 15871 | fields[0].type = ira->codegen->builtin_types.entry_u8; | 15879 | fields[0].type = ira->codegen->builtin_types.entry_u8; |
| 15872 | bigint_init_unsigned(&fields->data.x_bigint, type_entry->data.floating.bit_count); | 15880 | bigint_init_unsigned(&fields->data.x_bigint, type_entry->data.floating.bit_count); |
| 15873 | | 15881 | break; |
| 15874 | return payload; | | |
| 15875 | } | 15882 | } |
| 15876 | case TypeTableEntryIdPointer: | 15883 | case TypeTableEntryIdPointer: |
| 15877 | { | 15884 | { |
| 15878 | ConstExprValue *payload = create_const_vals(1); | 15885 | result = create_const_vals(1); |
| 15879 | payload->special = ConstValSpecialStatic; | 15886 | result->special = ConstValSpecialStatic; |
| 15880 | payload->type = ir_type_info_get_type(ira, "Pointer"); | 15887 | result->type = ir_type_info_get_type(ira, "Pointer"); |
| 15881 | | 15888 | |
| 15882 | ConstExprValue *fields = create_const_vals(4); | 15889 | ConstExprValue *fields = create_const_vals(4); |
| 15883 | payload->data.x_struct.fields = fields; | 15890 | result->data.x_struct.fields = fields; |
| 15884 | | 15891 | |
| 15885 | ir_type_info_struct_set_parent(payload, parent, parent_field_index); | 15892 | ir_type_info_struct_set_parent(result, parent, parent_field_index); |
| 15886 | | 15893 | |
| 15887 | // is_const: bool | 15894 | // is_const: bool |
| 15888 | ensure_field_index(payload->type, "is_const", 0); | 15895 | ensure_field_index(result->type, "is_const", 0); |
| 15889 | fields[0].special = ConstValSpecialStatic; | 15896 | fields[0].special = ConstValSpecialStatic; |
| 15890 | fields[0].type = ira->codegen->builtin_types.entry_bool; | 15897 | fields[0].type = ira->codegen->builtin_types.entry_bool; |
| 15891 | fields[0].data.x_bool = type_entry->data.pointer.is_const; | 15898 | fields[0].data.x_bool = type_entry->data.pointer.is_const; |
| 15892 | // is_volatile: bool | 15899 | // is_volatile: bool |
| 15893 | ensure_field_index(payload->type, "is_volatile", 1); | 15900 | ensure_field_index(result->type, "is_volatile", 1); |
| 15894 | fields[1].special = ConstValSpecialStatic; | 15901 | fields[1].special = ConstValSpecialStatic; |
| 15895 | fields[1].type = ira->codegen->builtin_types.entry_bool; | 15902 | fields[1].type = ira->codegen->builtin_types.entry_bool; |
| 15896 | fields[1].data.x_bool = type_entry->data.pointer.is_volatile; | 15903 | fields[1].data.x_bool = type_entry->data.pointer.is_volatile; |
| 15897 | // alignment: u32 | 15904 | // alignment: u32 |
| 15898 | ensure_field_index(payload->type, "alignment", 2); | 15905 | ensure_field_index(result->type, "alignment", 2); |
| 15899 | fields[2].special = ConstValSpecialStatic; | 15906 | fields[2].special = ConstValSpecialStatic; |
| 15900 | fields[2].type = ira->codegen->builtin_types.entry_u32; | 15907 | fields[2].type = ira->codegen->builtin_types.entry_u32; |
| 15901 | bigint_init_unsigned(&fields[2].data.x_bigint, type_entry->data.pointer.alignment); | 15908 | bigint_init_unsigned(&fields[2].data.x_bigint, type_entry->data.pointer.alignment); |
| 15902 | // child: &TypeInfo | 15909 | // child: &TypeInfo |
| 15903 | ensure_field_index(payload->type, "child", 3); | 15910 | ensure_field_index(result->type, "child", 3); |
| 15904 | | 15911 | |
| 15905 | TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr); | 15912 | TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr); |
| 15906 | | 15913 | |
| ... | @@ -15917,26 +15924,26 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p | ... | @@ -15917,26 +15924,26 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 15917 | type_entry->data.pointer.child_type); | 15924 | type_entry->data.pointer.child_type); |
| 15918 | | 15925 | |
| 15919 | fields[3].data.x_ptr.data.ref.pointee = union_val; | 15926 | fields[3].data.x_ptr.data.ref.pointee = union_val; |
| 15920 | return payload; | 15927 | break; |
| 15921 | } | 15928 | } |
| 15922 | case TypeTableEntryIdArray: | 15929 | case TypeTableEntryIdArray: |
| 15923 | { | 15930 | { |
| 15924 | ConstExprValue *payload = create_const_vals(1); | 15931 | result = create_const_vals(1); |
| 15925 | payload->special = ConstValSpecialStatic; | 15932 | result->special = ConstValSpecialStatic; |
| 15926 | payload->type = ir_type_info_get_type(ira, "Array"); | 15933 | result->type = ir_type_info_get_type(ira, "Array"); |
| 15927 | | 15934 | |
| 15928 | ConstExprValue *fields = create_const_vals(2); | 15935 | ConstExprValue *fields = create_const_vals(2); |
| 15929 | payload->data.x_struct.fields = fields; | 15936 | result->data.x_struct.fields = fields; |
| 15930 | | 15937 | |
| 15931 | ir_type_info_struct_set_parent(payload, parent, parent_field_index); | 15938 | ir_type_info_struct_set_parent(result, parent, parent_field_index); |
| 15932 | | 15939 | |
| 15933 | // len: usize | 15940 | // len: usize |
| 15934 | ensure_field_index(payload->type, "len", 0); | 15941 | ensure_field_index(result->type, "len", 0); |
| 15935 | fields[0].special = ConstValSpecialStatic; | 15942 | fields[0].special = ConstValSpecialStatic; |
| 15936 | fields[0].type = ira->codegen->builtin_types.entry_usize; | 15943 | fields[0].type = ira->codegen->builtin_types.entry_usize; |
| 15937 | bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.array.len); | 15944 | bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.array.len); |
| 15938 | // child: &TypeInfo | 15945 | // child: &TypeInfo |
| 15939 | ensure_field_index(payload->type, "child", 1); | 15946 | ensure_field_index(result->type, "child", 1); |
| 15940 | | 15947 | |
| 15941 | TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr); | 15948 | TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr); |
| 15942 | | 15949 | |
| ... | @@ -15953,21 +15960,21 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p | ... | @@ -15953,21 +15960,21 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 15953 | type_entry->data.array.child_type); | 15960 | type_entry->data.array.child_type); |
| 15954 | | 15961 | |
| 15955 | fields[1].data.x_ptr.data.ref.pointee = union_val; | 15962 | fields[1].data.x_ptr.data.ref.pointee = union_val; |
| 15956 | return payload; | 15963 | break; |
| 15957 | } | 15964 | } |
| 15958 | case TypeTableEntryIdMaybe: | 15965 | case TypeTableEntryIdMaybe: |
| 15959 | { | 15966 | { |
| 15960 | ConstExprValue *payload = create_const_vals(1); | 15967 | result = create_const_vals(1); |
| 15961 | payload->special = ConstValSpecialStatic; | 15968 | result->special = ConstValSpecialStatic; |
| 15962 | payload->type = ir_type_info_get_type(ira, "Nullable"); | 15969 | result->type = ir_type_info_get_type(ira, "Nullable"); |
| 15963 | | 15970 | |
| 15964 | ConstExprValue *fields = create_const_vals(1); | 15971 | ConstExprValue *fields = create_const_vals(1); |
| 15965 | payload->data.x_struct.fields = fields; | 15972 | result->data.x_struct.fields = fields; |
| 15966 | | 15973 | |
| 15967 | ir_type_info_struct_set_parent(payload, parent, parent_field_index); | 15974 | ir_type_info_struct_set_parent(result, parent, parent_field_index); |
| 15968 | | 15975 | |
| 15969 | // child: &TypeInfo | 15976 | // child: &TypeInfo |
| 15970 | ensure_field_index(payload->type, "child", 0); | 15977 | ensure_field_index(result->type, "child", 0); |
| 15971 | | 15978 | |
| 15972 | TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr); | 15979 | TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr); |
| 15973 | | 15980 | |
| ... | @@ -15984,21 +15991,21 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p | ... | @@ -15984,21 +15991,21 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 15984 | type_entry->data.maybe.child_type); | 15991 | type_entry->data.maybe.child_type); |
| 15985 | | 15992 | |
| 15986 | fields[0].data.x_ptr.data.ref.pointee = union_val; | 15993 | fields[0].data.x_ptr.data.ref.pointee = union_val; |
| 15987 | return payload; | 15994 | break; |
| 15988 | } | 15995 | } |
| 15989 | case TypeTableEntryIdPromise: | 15996 | case TypeTableEntryIdPromise: |
| 15990 | { | 15997 | { |
| 15991 | ConstExprValue *payload = create_const_vals(1); | 15998 | result = create_const_vals(1); |
| 15992 | payload->special = ConstValSpecialStatic; | 15999 | result->special = ConstValSpecialStatic; |
| 15993 | payload->type = ir_type_info_get_type(ira, "Promise"); | 16000 | result->type = ir_type_info_get_type(ira, "Promise"); |
| 15994 | | 16001 | |
| 15995 | ConstExprValue *fields = create_const_vals(1); | 16002 | ConstExprValue *fields = create_const_vals(1); |
| 15996 | payload->data.x_struct.fields = fields; | 16003 | result->data.x_struct.fields = fields; |
| 15997 | | 16004 | |
| 15998 | ir_type_info_struct_set_parent(payload, parent, parent_field_index); | 16005 | ir_type_info_struct_set_parent(result, parent, parent_field_index); |
| 15999 | | 16006 | |
| 16000 | // child: ?&TypeInfo | 16007 | // child: ?&TypeInfo |
| 16001 | ensure_field_index(payload->type, "child", 0); | 16008 | ensure_field_index(result->type, "child", 0); |
| 16002 | | 16009 | |
| 16003 | TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr); | 16010 | TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr); |
| 16004 | TypeTableEntry *type_info_ptr_type = get_pointer_to_type(ira->codegen, type_info_type, false); | 16011 | TypeTableEntry *type_info_ptr_type = get_pointer_to_type(ira->codegen, type_info_type, false); |
| ... | @@ -16029,11 +16036,15 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p | ... | @@ -16029,11 +16036,15 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 16029 | maybe_value->data.x_ptr.data.ref.pointee = union_val; | 16036 | maybe_value->data.x_ptr.data.ref.pointee = union_val; |
| 16030 | fields[0].data.x_maybe = maybe_value; | 16037 | fields[0].data.x_maybe = maybe_value; |
| 16031 | } | 16038 | } |
| 16032 | return payload; | 16039 | break; |
| 16033 | } | 16040 | } |
| 16034 | default: | 16041 | default: |
| 16035 | zig_unreachable(); | 16042 | zig_unreachable(); |
| 16036 | } | 16043 | } |
| | 16044 | |
| | 16045 | assert(result != nullptr); |
| | 16046 | ira->codegen->type_info_cache.put(type_entry, result); |
| | 16047 | return result; |
| 16037 | } | 16048 | } |
| 16038 | | 16049 | |
| 16039 | static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira, | 16050 | static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira, |