| ... | ... | @@ -15810,6 +15810,15 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na |
| 15810 | 15810 | static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *parent, |
| 15811 | 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 | 15822 | assert(type_entry != nullptr); |
| 15814 | 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 | 15841 | return nullptr; |
| 15833 | 15842 | case TypeTableEntryIdInt: |
| 15834 | 15843 | { |
| 15835 | | ConstExprValue *payload = create_const_vals(1); |
| 15836 | | payload->special = ConstValSpecialStatic; |
| 15837 | | payload->type = ir_type_info_get_type(ira, "Int"); |
| 15844 | result = create_const_vals(1); |
| 15845 | result->special = ConstValSpecialStatic; |
| 15846 | result->type = ir_type_info_get_type(ira, "Int"); |
| 15838 | 15847 | |
| 15839 | 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 | 15853 | // is_signed: bool |
| 15845 | | ensure_field_index(payload->type, "is_signed", 0); |
| 15854 | ensure_field_index(result->type, "is_signed", 0); |
| 15846 | 15855 | fields[0].special = ConstValSpecialStatic; |
| 15847 | 15856 | fields[0].type = ira->codegen->builtin_types.entry_bool; |
| 15848 | 15857 | fields[0].data.x_bool = type_entry->data.integral.is_signed; |
| 15849 | 15858 | // bits: u8 |
| 15850 | | ensure_field_index(payload->type, "bits", 1); |
| 15859 | ensure_field_index(result->type, "bits", 1); |
| 15851 | 15860 | fields[1].special = ConstValSpecialStatic; |
| 15852 | 15861 | fields[1].type = ira->codegen->builtin_types.entry_u8; |
| 15853 | 15862 | bigint_init_unsigned(&fields[1].data.x_bigint, type_entry->data.integral.bit_count); |
| 15854 | | |
| 15855 | | return payload; |
| 15863 | break; |
| 15856 | 15864 | } |
| 15857 | 15865 | case TypeTableEntryIdFloat: |
| 15858 | 15866 | { |
| 15859 | | ConstExprValue *payload = create_const_vals(1); |
| 15860 | | payload->special = ConstValSpecialStatic; |
| 15861 | | payload->type = ir_type_info_get_type(ira, "Float"); |
| 15867 | result = create_const_vals(1); |
| 15868 | result->special = ConstValSpecialStatic; |
| 15869 | result->type = ir_type_info_get_type(ira, "Float"); |
| 15862 | 15870 | |
| 15863 | 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 | 15876 | // bits: u8 |
| 15869 | | ensure_field_index(payload->type, "bits", 0); |
| 15877 | ensure_field_index(result->type, "bits", 0); |
| 15870 | 15878 | fields[0].special = ConstValSpecialStatic; |
| 15871 | 15879 | fields[0].type = ira->codegen->builtin_types.entry_u8; |
| 15872 | 15880 | bigint_init_unsigned(&fields->data.x_bigint, type_entry->data.floating.bit_count); |
| 15873 | | |
| 15874 | | return payload; |
| 15881 | break; |
| 15875 | 15882 | } |
| 15876 | 15883 | case TypeTableEntryIdPointer: |
| 15877 | 15884 | { |
| 15878 | | ConstExprValue *payload = create_const_vals(1); |
| 15879 | | payload->special = ConstValSpecialStatic; |
| 15880 | | payload->type = ir_type_info_get_type(ira, "Pointer"); |
| 15885 | result = create_const_vals(1); |
| 15886 | result->special = ConstValSpecialStatic; |
| 15887 | result->type = ir_type_info_get_type(ira, "Pointer"); |
| 15881 | 15888 | |
| 15882 | 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 | 15894 | // is_const: bool |
| 15888 | | ensure_field_index(payload->type, "is_const", 0); |
| 15895 | ensure_field_index(result->type, "is_const", 0); |
| 15889 | 15896 | fields[0].special = ConstValSpecialStatic; |
| 15890 | 15897 | fields[0].type = ira->codegen->builtin_types.entry_bool; |
| 15891 | 15898 | fields[0].data.x_bool = type_entry->data.pointer.is_const; |
| 15892 | 15899 | // is_volatile: bool |
| 15893 | | ensure_field_index(payload->type, "is_volatile", 1); |
| 15900 | ensure_field_index(result->type, "is_volatile", 1); |
| 15894 | 15901 | fields[1].special = ConstValSpecialStatic; |
| 15895 | 15902 | fields[1].type = ira->codegen->builtin_types.entry_bool; |
| 15896 | 15903 | fields[1].data.x_bool = type_entry->data.pointer.is_volatile; |
| 15897 | 15904 | // alignment: u32 |
| 15898 | | ensure_field_index(payload->type, "alignment", 2); |
| 15905 | ensure_field_index(result->type, "alignment", 2); |
| 15899 | 15906 | fields[2].special = ConstValSpecialStatic; |
| 15900 | 15907 | fields[2].type = ira->codegen->builtin_types.entry_u32; |
| 15901 | 15908 | bigint_init_unsigned(&fields[2].data.x_bigint, type_entry->data.pointer.alignment); |
| 15902 | 15909 | // child: &TypeInfo |
| 15903 | | ensure_field_index(payload->type, "child", 3); |
| 15910 | ensure_field_index(result->type, "child", 3); |
| 15904 | 15911 | |
| 15905 | 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 | 15924 | type_entry->data.pointer.child_type); |
| 15918 | 15925 | |
| 15919 | 15926 | fields[3].data.x_ptr.data.ref.pointee = union_val; |
| 15920 | | return payload; |
| 15927 | break; |
| 15921 | 15928 | } |
| 15922 | 15929 | case TypeTableEntryIdArray: |
| 15923 | 15930 | { |
| 15924 | | ConstExprValue *payload = create_const_vals(1); |
| 15925 | | payload->special = ConstValSpecialStatic; |
| 15926 | | payload->type = ir_type_info_get_type(ira, "Array"); |
| 15931 | result = create_const_vals(1); |
| 15932 | result->special = ConstValSpecialStatic; |
| 15933 | result->type = ir_type_info_get_type(ira, "Array"); |
| 15927 | 15934 | |
| 15928 | 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 | 15940 | // len: usize |
| 15934 | | ensure_field_index(payload->type, "len", 0); |
| 15941 | ensure_field_index(result->type, "len", 0); |
| 15935 | 15942 | fields[0].special = ConstValSpecialStatic; |
| 15936 | 15943 | fields[0].type = ira->codegen->builtin_types.entry_usize; |
| 15937 | 15944 | bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.array.len); |
| 15938 | 15945 | // child: &TypeInfo |
| 15939 | | ensure_field_index(payload->type, "child", 1); |
| 15946 | ensure_field_index(result->type, "child", 1); |
| 15940 | 15947 | |
| 15941 | 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 | 15960 | type_entry->data.array.child_type); |
| 15954 | 15961 | |
| 15955 | 15962 | fields[1].data.x_ptr.data.ref.pointee = union_val; |
| 15956 | | return payload; |
| 15963 | break; |
| 15957 | 15964 | } |
| 15958 | 15965 | case TypeTableEntryIdMaybe: |
| 15959 | 15966 | { |
| 15960 | | ConstExprValue *payload = create_const_vals(1); |
| 15961 | | payload->special = ConstValSpecialStatic; |
| 15962 | | payload->type = ir_type_info_get_type(ira, "Nullable"); |
| 15967 | result = create_const_vals(1); |
| 15968 | result->special = ConstValSpecialStatic; |
| 15969 | result->type = ir_type_info_get_type(ira, "Nullable"); |
| 15963 | 15970 | |
| 15964 | 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 | 15976 | // child: &TypeInfo |
| 15970 | | ensure_field_index(payload->type, "child", 0); |
| 15977 | ensure_field_index(result->type, "child", 0); |
| 15971 | 15978 | |
| 15972 | 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 | 15991 | type_entry->data.maybe.child_type); |
| 15985 | 15992 | |
| 15986 | 15993 | fields[0].data.x_ptr.data.ref.pointee = union_val; |
| 15987 | | return payload; |
| 15994 | break; |
| 15988 | 15995 | } |
| 15989 | 15996 | case TypeTableEntryIdPromise: |
| 15990 | 15997 | { |
| 15991 | | ConstExprValue *payload = create_const_vals(1); |
| 15992 | | payload->special = ConstValSpecialStatic; |
| 15993 | | payload->type = ir_type_info_get_type(ira, "Promise"); |
| 15998 | result = create_const_vals(1); |
| 15999 | result->special = ConstValSpecialStatic; |
| 16000 | result->type = ir_type_info_get_type(ira, "Promise"); |
| 15994 | 16001 | |
| 15995 | 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 | 16007 | // child: ?&TypeInfo |
| 16001 | | ensure_field_index(payload->type, "child", 0); |
| 16008 | ensure_field_index(result->type, "child", 0); |
| 16002 | 16009 | |
| 16003 | 16010 | TypeTableEntry *type_info_type = ir_type_info_get_type(ira, nullptr); |
| 16004 | 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 | 16036 | maybe_value->data.x_ptr.data.ref.pointee = union_val; |
| 16030 | 16037 | fields[0].data.x_maybe = maybe_value; |
| 16031 | 16038 | } |
| 16032 | | return payload; |
| 16039 | break; |
| 16033 | 16040 | } |
| 16034 | 16041 | default: |
| 16035 | 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 | 16050 | static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira, |