| ... | @@ -18045,11 +18045,12 @@ static PtrLen size_enum_index_to_ptr_len(BuiltinPtrSize size_enum_index) { | ... | @@ -18045,11 +18045,12 @@ static PtrLen size_enum_index_to_ptr_len(BuiltinPtrSize size_enum_index) { |
| 18045 | } | 18045 | } |
| 18046 | | 18046 | |
| 18047 | static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ptr_type_entry) { | 18047 | static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ptr_type_entry) { |
| | 18048 | CodeGen *g = ira->codegen; |
| 18048 | ZigType *attrs_type; | 18049 | ZigType *attrs_type; |
| 18049 | BuiltinPtrSize size_enum_index; | 18050 | BuiltinPtrSize size_enum_index; |
| 18050 | if (is_slice(ptr_type_entry)) { | 18051 | if (is_slice(ptr_type_entry)) { |
| 18051 | TypeStructField *ptr_field = ptr_type_entry->data.structure.fields[slice_ptr_index]; | 18052 | TypeStructField *ptr_field = ptr_type_entry->data.structure.fields[slice_ptr_index]; |
| 18052 | attrs_type = resolve_struct_field_type(ira->codegen, ptr_field); | 18053 | attrs_type = resolve_struct_field_type(g, ptr_field); |
| 18053 | size_enum_index = BuiltinPtrSizeSlice; | 18054 | size_enum_index = BuiltinPtrSizeSlice; |
| 18054 | } else if (ptr_type_entry->id == ZigTypeIdPointer) { | 18055 | } else if (ptr_type_entry->id == ZigTypeIdPointer) { |
| 18055 | attrs_type = ptr_type_entry; | 18056 | attrs_type = ptr_type_entry; |
| ... | @@ -18059,19 +18060,19 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode | ... | @@ -18059,19 +18060,19 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode |
| 18059 | } | 18060 | } |
| 18060 | | 18061 | |
| 18061 | ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr); | 18062 | ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr); |
| 18062 | assertNoError(type_resolve(ira->codegen, type_info_pointer_type, ResolveStatusSizeKnown)); | 18063 | assertNoError(type_resolve(g, type_info_pointer_type, ResolveStatusSizeKnown)); |
| 18063 | | 18064 | |
| 18064 | ZigValue *result = ira->codegen->pass1_arena->create<ZigValue>(); | 18065 | ZigValue *result = g->pass1_arena->create<ZigValue>(); |
| 18065 | result->special = ConstValSpecialStatic; | 18066 | result->special = ConstValSpecialStatic; |
| 18066 | result->type = type_info_pointer_type; | 18067 | result->type = type_info_pointer_type; |
| 18067 | | 18068 | |
| 18068 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 8); | 18069 | ZigValue **fields = alloc_const_vals_ptrs(g, 8); |
| 18069 | result->data.x_struct.fields = fields; | 18070 | result->data.x_struct.fields = fields; |
| 18070 | | 18071 | |
| 18071 | // size: Size | 18072 | // size: Size |
| 18072 | ensure_field_index(result->type, "size", 0); | 18073 | ensure_field_index(result->type, "size", 0); |
| 18073 | ZigType *type_info_pointer_size_type = ir_type_info_get_type(ira, "Size", type_info_pointer_type); | 18074 | ZigType *type_info_pointer_size_type = ir_type_info_get_type(ira, "Size", type_info_pointer_type); |
| 18074 | assertNoError(type_resolve(ira->codegen, type_info_pointer_size_type, ResolveStatusSizeKnown)); | 18075 | assertNoError(type_resolve(g, type_info_pointer_size_type, ResolveStatusSizeKnown)); |
| 18075 | fields[0]->special = ConstValSpecialStatic; | 18076 | fields[0]->special = ConstValSpecialStatic; |
| 18076 | fields[0]->type = type_info_pointer_size_type; | 18077 | fields[0]->type = type_info_pointer_size_type; |
| 18077 | bigint_init_unsigned(&fields[0]->data.x_enum_tag, size_enum_index); | 18078 | bigint_init_unsigned(&fields[0]->data.x_enum_tag, size_enum_index); |
| ... | @@ -18079,16 +18080,16 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode | ... | @@ -18079,16 +18080,16 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode |
| 18079 | // is_const: bool | 18080 | // is_const: bool |
| 18080 | ensure_field_index(result->type, "is_const", 1); | 18081 | ensure_field_index(result->type, "is_const", 1); |
| 18081 | fields[1]->special = ConstValSpecialStatic; | 18082 | fields[1]->special = ConstValSpecialStatic; |
| 18082 | fields[1]->type = ira->codegen->builtin_types.entry_bool; | 18083 | fields[1]->type = g->builtin_types.entry_bool; |
| 18083 | fields[1]->data.x_bool = attrs_type->data.pointer.is_const; | 18084 | fields[1]->data.x_bool = attrs_type->data.pointer.is_const; |
| 18084 | // is_volatile: bool | 18085 | // is_volatile: bool |
| 18085 | ensure_field_index(result->type, "is_volatile", 2); | 18086 | ensure_field_index(result->type, "is_volatile", 2); |
| 18086 | fields[2]->special = ConstValSpecialStatic; | 18087 | fields[2]->special = ConstValSpecialStatic; |
| 18087 | fields[2]->type = ira->codegen->builtin_types.entry_bool; | 18088 | fields[2]->type = g->builtin_types.entry_bool; |
| 18088 | fields[2]->data.x_bool = attrs_type->data.pointer.is_volatile; | 18089 | fields[2]->data.x_bool = attrs_type->data.pointer.is_volatile; |
| 18089 | // alignment: comptime_int | 18090 | // alignment: comptime_int |
| 18090 | ensure_field_index(result->type, "alignment", 3); | 18091 | ensure_field_index(result->type, "alignment", 3); |
| 18091 | fields[3]->type = ira->codegen->builtin_types.entry_num_lit_int; | 18092 | fields[3]->type = g->builtin_types.entry_num_lit_int; |
| 18092 | if (attrs_type->data.pointer.explicit_alignment != 0) { | 18093 | if (attrs_type->data.pointer.explicit_alignment != 0) { |
| 18093 | fields[3]->special = ConstValSpecialStatic; | 18094 | fields[3]->special = ConstValSpecialStatic; |
| 18094 | bigint_init_unsigned(&fields[3]->data.x_bigint, attrs_type->data.pointer.explicit_alignment); | 18095 | bigint_init_unsigned(&fields[3]->data.x_bigint, attrs_type->data.pointer.explicit_alignment); |
| ... | @@ -18103,27 +18104,25 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode | ... | @@ -18103,27 +18104,25 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode |
| 18103 | // address_space: AddressSpace, | 18104 | // address_space: AddressSpace, |
| 18104 | ensure_field_index(result->type, "address_space", 4); | 18105 | ensure_field_index(result->type, "address_space", 4); |
| 18105 | fields[4]->special = ConstValSpecialStatic; | 18106 | fields[4]->special = ConstValSpecialStatic; |
| 18106 | fields[4]->type = get_builtin_type(ira->codegen, "AddressSpace"); | 18107 | fields[4]->type = get_builtin_type(g, "AddressSpace"); |
| 18107 | bigint_init_unsigned(&fields[4]->data.x_enum_tag, AddressSpaceGeneric); | 18108 | bigint_init_unsigned(&fields[4]->data.x_enum_tag, AddressSpaceGeneric); |
| 18108 | // child: type | 18109 | // child: type |
| 18109 | ensure_field_index(result->type, "child", 5); | 18110 | ensure_field_index(result->type, "child", 5); |
| 18110 | fields[5]->special = ConstValSpecialStatic; | 18111 | fields[5]->special = ConstValSpecialStatic; |
| 18111 | fields[5]->type = ira->codegen->builtin_types.entry_type; | 18112 | fields[5]->type = g->builtin_types.entry_type; |
| 18112 | fields[5]->data.x_type = attrs_type->data.pointer.child_type; | 18113 | fields[5]->data.x_type = attrs_type->data.pointer.child_type; |
| 18113 | // is_allowzero: bool | 18114 | // is_allowzero: bool |
| 18114 | ensure_field_index(result->type, "is_allowzero", 6); | 18115 | ensure_field_index(result->type, "is_allowzero", 6); |
| 18115 | fields[6]->special = ConstValSpecialStatic; | 18116 | fields[6]->special = ConstValSpecialStatic; |
| 18116 | fields[6]->type = ira->codegen->builtin_types.entry_bool; | 18117 | fields[6]->type = g->builtin_types.entry_bool; |
| 18117 | fields[6]->data.x_bool = attrs_type->data.pointer.allow_zero; | 18118 | fields[6]->data.x_bool = attrs_type->data.pointer.allow_zero; |
| 18118 | // sentinel: anytype | 18119 | // sentinel: ?*const anyopaque |
| 18119 | ensure_field_index(result->type, "sentinel", 7); | 18120 | ensure_field_index(result->type, "sentinel", 7); |
| 18120 | fields[7]->special = ConstValSpecialStatic; | 18121 | fields[7]->special = ConstValSpecialStatic; |
| 18121 | if (attrs_type->data.pointer.sentinel != nullptr) { | 18122 | fields[7]->type = g->builtin_types.entry_opt_ptr_const_anyopaque; |
| 18122 | fields[7]->type = get_optional_type(ira->codegen, attrs_type->data.pointer.child_type); | 18123 | ZigValue *ptr_to_sent = (attrs_type->data.pointer.sentinel == nullptr) ? nullptr : |
| 18123 | set_optional_payload(fields[7], attrs_type->data.pointer.sentinel); | 18124 | create_const_ptr_ref(g, attrs_type->data.pointer.sentinel, true); |
| 18124 | } else { | 18125 | set_optional_payload(fields[7], ptr_to_sent); |
| 18125 | fields[7]->type = ira->codegen->builtin_types.entry_null; | | |
| 18126 | } | | |
| 18127 | | 18126 | |
| 18128 | return result; | 18127 | return result; |
| 18129 | }; | 18128 | }; |
| ... | @@ -18153,7 +18152,9 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18153,7 +18152,9 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18153 | assert(type_entry != nullptr); | 18152 | assert(type_entry != nullptr); |
| 18154 | assert(!type_is_invalid(type_entry)); | 18153 | assert(!type_is_invalid(type_entry)); |
| 18155 | | 18154 | |
| 18156 | auto entry = ira->codegen->type_info_cache.maybe_get(type_entry); | 18155 | CodeGen *g = ira->codegen; |
| | 18156 | |
| | 18157 | auto entry = g->type_info_cache.maybe_get(type_entry); |
| 18157 | if (entry != nullptr) { | 18158 | if (entry != nullptr) { |
| 18158 | *out = entry->value; | 18159 | *out = entry->value; |
| 18159 | return ErrorNone; | 18160 | return ErrorNone; |
| ... | @@ -18172,43 +18173,43 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18172,43 +18173,43 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18172 | case ZigTypeIdEnumLiteral: | 18173 | case ZigTypeIdEnumLiteral: |
| 18173 | case ZigTypeIdUndefined: | 18174 | case ZigTypeIdUndefined: |
| 18174 | case ZigTypeIdNull: | 18175 | case ZigTypeIdNull: |
| 18175 | result = ira->codegen->intern.for_void(); | 18176 | result = g->intern.for_void(); |
| 18176 | break; | 18177 | break; |
| 18177 | case ZigTypeIdInt: | 18178 | case ZigTypeIdInt: |
| 18178 | { | 18179 | { |
| 18179 | result = ira->codegen->pass1_arena->create<ZigValue>(); | 18180 | result = g->pass1_arena->create<ZigValue>(); |
| 18180 | result->special = ConstValSpecialStatic; | 18181 | result->special = ConstValSpecialStatic; |
| 18181 | result->type = ir_type_info_get_type(ira, "Int", nullptr); | 18182 | result->type = ir_type_info_get_type(ira, "Int", nullptr); |
| 18182 | | 18183 | |
| 18183 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 2); | 18184 | ZigValue **fields = alloc_const_vals_ptrs(g, 2); |
| 18184 | result->data.x_struct.fields = fields; | 18185 | result->data.x_struct.fields = fields; |
| 18185 | | 18186 | |
| 18186 | // is_signed: Signedness | 18187 | // is_signed: Signedness |
| 18187 | ensure_field_index(result->type, "signedness", 0); | 18188 | ensure_field_index(result->type, "signedness", 0); |
| 18188 | fields[0]->special = ConstValSpecialStatic; | 18189 | fields[0]->special = ConstValSpecialStatic; |
| 18189 | fields[0]->type = get_builtin_type(ira->codegen, "Signedness"); | 18190 | fields[0]->type = get_builtin_type(g, "Signedness"); |
| 18190 | bigint_init_unsigned(&fields[0]->data.x_enum_tag, !type_entry->data.integral.is_signed); | 18191 | bigint_init_unsigned(&fields[0]->data.x_enum_tag, !type_entry->data.integral.is_signed); |
| 18191 | // bits: u8 | 18192 | // bits: u8 |
| 18192 | ensure_field_index(result->type, "bits", 1); | 18193 | ensure_field_index(result->type, "bits", 1); |
| 18193 | fields[1]->special = ConstValSpecialStatic; | 18194 | fields[1]->special = ConstValSpecialStatic; |
| 18194 | fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int; | 18195 | fields[1]->type = g->builtin_types.entry_num_lit_int; |
| 18195 | bigint_init_unsigned(&fields[1]->data.x_bigint, type_entry->data.integral.bit_count); | 18196 | bigint_init_unsigned(&fields[1]->data.x_bigint, type_entry->data.integral.bit_count); |
| 18196 | | 18197 | |
| 18197 | break; | 18198 | break; |
| 18198 | } | 18199 | } |
| 18199 | case ZigTypeIdFloat: | 18200 | case ZigTypeIdFloat: |
| 18200 | { | 18201 | { |
| 18201 | result = ira->codegen->pass1_arena->create<ZigValue>(); | 18202 | result = g->pass1_arena->create<ZigValue>(); |
| 18202 | result->special = ConstValSpecialStatic; | 18203 | result->special = ConstValSpecialStatic; |
| 18203 | result->type = ir_type_info_get_type(ira, "Float", nullptr); | 18204 | result->type = ir_type_info_get_type(ira, "Float", nullptr); |
| 18204 | | 18205 | |
| 18205 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1); | 18206 | ZigValue **fields = alloc_const_vals_ptrs(g, 1); |
| 18206 | result->data.x_struct.fields = fields; | 18207 | result->data.x_struct.fields = fields; |
| 18207 | | 18208 | |
| 18208 | // bits: u8 | 18209 | // bits: u8 |
| 18209 | ensure_field_index(result->type, "bits", 0); | 18210 | ensure_field_index(result->type, "bits", 0); |
| 18210 | fields[0]->special = ConstValSpecialStatic; | 18211 | fields[0]->special = ConstValSpecialStatic; |
| 18211 | fields[0]->type = ira->codegen->builtin_types.entry_num_lit_int; | 18212 | fields[0]->type = g->builtin_types.entry_num_lit_int; |
| 18212 | bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.floating.bit_count); | 18213 | bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.floating.bit_count); |
| 18213 | | 18214 | |
| 18214 | break; | 18215 | break; |
| ... | @@ -18222,97 +18223,96 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18222,97 +18223,96 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18222 | } | 18223 | } |
| 18223 | case ZigTypeIdArray: | 18224 | case ZigTypeIdArray: |
| 18224 | { | 18225 | { |
| 18225 | result = ira->codegen->pass1_arena->create<ZigValue>(); | 18226 | result = g->pass1_arena->create<ZigValue>(); |
| 18226 | result->special = ConstValSpecialStatic; | 18227 | result->special = ConstValSpecialStatic; |
| 18227 | result->type = ir_type_info_get_type(ira, "Array", nullptr); | 18228 | result->type = ir_type_info_get_type(ira, "Array", nullptr); |
| 18228 | | 18229 | |
| 18229 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 3); | 18230 | ZigValue **fields = alloc_const_vals_ptrs(g, 3); |
| 18230 | result->data.x_struct.fields = fields; | 18231 | result->data.x_struct.fields = fields; |
| 18231 | | 18232 | |
| 18232 | // len: usize | 18233 | // len: usize |
| 18233 | ensure_field_index(result->type, "len", 0); | 18234 | ensure_field_index(result->type, "len", 0); |
| 18234 | fields[0]->special = ConstValSpecialStatic; | 18235 | fields[0]->special = ConstValSpecialStatic; |
| 18235 | fields[0]->type = ira->codegen->builtin_types.entry_num_lit_int; | 18236 | fields[0]->type = g->builtin_types.entry_num_lit_int; |
| 18236 | bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.array.len); | 18237 | bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.array.len); |
| 18237 | // child: type | 18238 | // child: type |
| 18238 | ensure_field_index(result->type, "child", 1); | 18239 | ensure_field_index(result->type, "child", 1); |
| 18239 | fields[1]->special = ConstValSpecialStatic; | 18240 | fields[1]->special = ConstValSpecialStatic; |
| 18240 | fields[1]->type = ira->codegen->builtin_types.entry_type; | 18241 | fields[1]->type = g->builtin_types.entry_type; |
| 18241 | fields[1]->data.x_type = type_entry->data.array.child_type; | 18242 | fields[1]->data.x_type = type_entry->data.array.child_type; |
| 18242 | // sentinel: anytype | 18243 | src_assert(type_entry->data.array.child_type != nullptr, source_node); |
| | 18244 | // sentinel: ?*const anyopaque |
| 18243 | fields[2]->special = ConstValSpecialStatic; | 18245 | fields[2]->special = ConstValSpecialStatic; |
| 18244 | if (type_entry->data.array.child_type != nullptr) { | 18246 | fields[2]->type = g->builtin_types.entry_opt_ptr_const_anyopaque; |
| 18245 | fields[2]->type = get_optional_type(ira->codegen, type_entry->data.array.child_type); | 18247 | ZigValue *ptr_to_sent = (type_entry->data.array.sentinel == nullptr) ? nullptr : |
| 18246 | set_optional_payload(fields[2], type_entry->data.array.sentinel); | 18248 | create_const_ptr_ref(g, type_entry->data.array.sentinel, true); |
| 18247 | } else { | 18249 | set_optional_payload(fields[2], ptr_to_sent); |
| 18248 | fields[2]->type = ira->codegen->builtin_types.entry_null; | | |
| 18249 | } | | |
| 18250 | break; | 18250 | break; |
| 18251 | } | 18251 | } |
| 18252 | case ZigTypeIdVector: { | 18252 | case ZigTypeIdVector: { |
| 18253 | result = ira->codegen->pass1_arena->create<ZigValue>(); | 18253 | result = g->pass1_arena->create<ZigValue>(); |
| 18254 | result->special = ConstValSpecialStatic; | 18254 | result->special = ConstValSpecialStatic; |
| 18255 | result->type = ir_type_info_get_type(ira, "Vector", nullptr); | 18255 | result->type = ir_type_info_get_type(ira, "Vector", nullptr); |
| 18256 | | 18256 | |
| 18257 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 2); | 18257 | ZigValue **fields = alloc_const_vals_ptrs(g, 2); |
| 18258 | result->data.x_struct.fields = fields; | 18258 | result->data.x_struct.fields = fields; |
| 18259 | | 18259 | |
| 18260 | // len: usize | 18260 | // len: usize |
| 18261 | ensure_field_index(result->type, "len", 0); | 18261 | ensure_field_index(result->type, "len", 0); |
| 18262 | fields[0]->special = ConstValSpecialStatic; | 18262 | fields[0]->special = ConstValSpecialStatic; |
| 18263 | fields[0]->type = ira->codegen->builtin_types.entry_num_lit_int; | 18263 | fields[0]->type = g->builtin_types.entry_num_lit_int; |
| 18264 | bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.vector.len); | 18264 | bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.vector.len); |
| 18265 | // child: type | 18265 | // child: type |
| 18266 | ensure_field_index(result->type, "child", 1); | 18266 | ensure_field_index(result->type, "child", 1); |
| 18267 | fields[1]->special = ConstValSpecialStatic; | 18267 | fields[1]->special = ConstValSpecialStatic; |
| 18268 | fields[1]->type = ira->codegen->builtin_types.entry_type; | 18268 | fields[1]->type = g->builtin_types.entry_type; |
| 18269 | fields[1]->data.x_type = type_entry->data.vector.elem_type; | 18269 | fields[1]->data.x_type = type_entry->data.vector.elem_type; |
| 18270 | | 18270 | |
| 18271 | break; | 18271 | break; |
| 18272 | } | 18272 | } |
| 18273 | case ZigTypeIdOptional: | 18273 | case ZigTypeIdOptional: |
| 18274 | { | 18274 | { |
| 18275 | result = ira->codegen->pass1_arena->create<ZigValue>(); | 18275 | result = g->pass1_arena->create<ZigValue>(); |
| 18276 | result->special = ConstValSpecialStatic; | 18276 | result->special = ConstValSpecialStatic; |
| 18277 | result->type = ir_type_info_get_type(ira, "Optional", nullptr); | 18277 | result->type = ir_type_info_get_type(ira, "Optional", nullptr); |
| 18278 | | 18278 | |
| 18279 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1); | 18279 | ZigValue **fields = alloc_const_vals_ptrs(g, 1); |
| 18280 | result->data.x_struct.fields = fields; | 18280 | result->data.x_struct.fields = fields; |
| 18281 | | 18281 | |
| 18282 | // child: type | 18282 | // child: type |
| 18283 | ensure_field_index(result->type, "child", 0); | 18283 | ensure_field_index(result->type, "child", 0); |
| 18284 | fields[0]->special = ConstValSpecialStatic; | 18284 | fields[0]->special = ConstValSpecialStatic; |
| 18285 | fields[0]->type = ira->codegen->builtin_types.entry_type; | 18285 | fields[0]->type = g->builtin_types.entry_type; |
| 18286 | fields[0]->data.x_type = type_entry->data.maybe.child_type; | 18286 | fields[0]->data.x_type = type_entry->data.maybe.child_type; |
| 18287 | | 18287 | |
| 18288 | break; | 18288 | break; |
| 18289 | } | 18289 | } |
| 18290 | case ZigTypeIdAnyFrame: { | 18290 | case ZigTypeIdAnyFrame: { |
| 18291 | result = ira->codegen->pass1_arena->create<ZigValue>(); | 18291 | result = g->pass1_arena->create<ZigValue>(); |
| 18292 | result->special = ConstValSpecialStatic; | 18292 | result->special = ConstValSpecialStatic; |
| 18293 | result->type = ir_type_info_get_type(ira, "AnyFrame", nullptr); | 18293 | result->type = ir_type_info_get_type(ira, "AnyFrame", nullptr); |
| 18294 | | 18294 | |
| 18295 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1); | 18295 | ZigValue **fields = alloc_const_vals_ptrs(g, 1); |
| 18296 | result->data.x_struct.fields = fields; | 18296 | result->data.x_struct.fields = fields; |
| 18297 | | 18297 | |
| 18298 | // child: ?type | 18298 | // child: ?type |
| 18299 | ensure_field_index(result->type, "child", 0); | 18299 | ensure_field_index(result->type, "child", 0); |
| 18300 | fields[0]->special = ConstValSpecialStatic; | 18300 | fields[0]->special = ConstValSpecialStatic; |
| 18301 | fields[0]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type); | 18301 | fields[0]->type = get_optional_type(g, g->builtin_types.entry_type); |
| 18302 | fields[0]->data.x_optional = (type_entry->data.any_frame.result_type == nullptr) ? nullptr : | 18302 | fields[0]->data.x_optional = (type_entry->data.any_frame.result_type == nullptr) ? nullptr : |
| 18303 | create_const_type(ira->codegen, type_entry->data.any_frame.result_type); | 18303 | create_const_type(g, type_entry->data.any_frame.result_type); |
| 18304 | break; | 18304 | break; |
| 18305 | } | 18305 | } |
| 18306 | case ZigTypeIdEnum: | 18306 | case ZigTypeIdEnum: |
| 18307 | { | 18307 | { |
| 18308 | if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown))) | 18308 | if ((err = type_resolve(g, type_entry, ResolveStatusSizeKnown))) |
| 18309 | return err; | 18309 | return err; |
| 18310 | | 18310 | |
| 18311 | result = ira->codegen->pass1_arena->create<ZigValue>(); | 18311 | result = g->pass1_arena->create<ZigValue>(); |
| 18312 | result->special = ConstValSpecialStatic; | 18312 | result->special = ConstValSpecialStatic; |
| 18313 | result->type = ir_type_info_get_type(ira, "Enum", nullptr); | 18313 | result->type = ir_type_info_get_type(ira, "Enum", nullptr); |
| 18314 | | 18314 | |
| 18315 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 5); | 18315 | ZigValue **fields = alloc_const_vals_ptrs(g, 5); |
| 18316 | result->data.x_struct.fields = fields; | 18316 | result->data.x_struct.fields = fields; |
| 18317 | | 18317 | |
| 18318 | // layout: ContainerLayout | 18318 | // layout: ContainerLayout |
| ... | @@ -18323,24 +18323,24 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18323,24 +18323,24 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18323 | // tag_type: type | 18323 | // tag_type: type |
| 18324 | ensure_field_index(result->type, "tag_type", 1); | 18324 | ensure_field_index(result->type, "tag_type", 1); |
| 18325 | fields[1]->special = ConstValSpecialStatic; | 18325 | fields[1]->special = ConstValSpecialStatic; |
| 18326 | fields[1]->type = ira->codegen->builtin_types.entry_type; | 18326 | fields[1]->type = g->builtin_types.entry_type; |
| 18327 | fields[1]->data.x_type = type_entry->data.enumeration.tag_int_type; | 18327 | fields[1]->data.x_type = type_entry->data.enumeration.tag_int_type; |
| 18328 | // fields: []TypeInfo.EnumField | 18328 | // fields: []TypeInfo.EnumField |
| 18329 | ensure_field_index(result->type, "fields", 2); | 18329 | ensure_field_index(result->type, "fields", 2); |
| 18330 | | 18330 | |
| 18331 | ZigType *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr); | 18331 | ZigType *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr); |
| 18332 | if ((err = type_resolve(ira->codegen, type_info_enum_field_type, ResolveStatusSizeKnown))) { | 18332 | if ((err = type_resolve(g, type_info_enum_field_type, ResolveStatusSizeKnown))) { |
| 18333 | zig_unreachable(); | 18333 | zig_unreachable(); |
| 18334 | } | 18334 | } |
| 18335 | uint32_t enum_field_count = type_entry->data.enumeration.src_field_count; | 18335 | uint32_t enum_field_count = type_entry->data.enumeration.src_field_count; |
| 18336 | | 18336 | |
| 18337 | ZigValue *enum_field_array = ira->codegen->pass1_arena->create<ZigValue>(); | 18337 | ZigValue *enum_field_array = g->pass1_arena->create<ZigValue>(); |
| 18338 | enum_field_array->special = ConstValSpecialStatic; | 18338 | enum_field_array->special = ConstValSpecialStatic; |
| 18339 | enum_field_array->type = get_array_type(ira->codegen, type_info_enum_field_type, enum_field_count, nullptr); | 18339 | enum_field_array->type = get_array_type(g, type_info_enum_field_type, enum_field_count, nullptr); |
| 18340 | enum_field_array->data.x_array.special = ConstArraySpecialNone; | 18340 | enum_field_array->data.x_array.special = ConstArraySpecialNone; |
| 18341 | enum_field_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(enum_field_count); | 18341 | enum_field_array->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(enum_field_count); |
| 18342 | | 18342 | |
| 18343 | init_const_slice(ira->codegen, fields[2], enum_field_array, 0, enum_field_count, false, nullptr); | 18343 | init_const_slice(g, fields[2], enum_field_array, 0, enum_field_count, false, nullptr); |
| 18344 | | 18344 | |
| 18345 | for (uint32_t enum_field_index = 0; enum_field_index < enum_field_count; enum_field_index++) | 18345 | for (uint32_t enum_field_index = 0; enum_field_index < enum_field_count; enum_field_index++) |
| 18346 | { | 18346 | { |
| ... | @@ -18361,39 +18361,39 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18361,39 +18361,39 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18361 | // is_exhaustive: bool | 18361 | // is_exhaustive: bool |
| 18362 | ensure_field_index(result->type, "is_exhaustive", 4); | 18362 | ensure_field_index(result->type, "is_exhaustive", 4); |
| 18363 | fields[4]->special = ConstValSpecialStatic; | 18363 | fields[4]->special = ConstValSpecialStatic; |
| 18364 | fields[4]->type = ira->codegen->builtin_types.entry_bool; | 18364 | fields[4]->type = g->builtin_types.entry_bool; |
| 18365 | fields[4]->data.x_bool = !type_entry->data.enumeration.non_exhaustive; | 18365 | fields[4]->data.x_bool = !type_entry->data.enumeration.non_exhaustive; |
| 18366 | | 18366 | |
| 18367 | break; | 18367 | break; |
| 18368 | } | 18368 | } |
| 18369 | case ZigTypeIdErrorSet: | 18369 | case ZigTypeIdErrorSet: |
| 18370 | { | 18370 | { |
| 18371 | result = ira->codegen->pass1_arena->create<ZigValue>(); | 18371 | result = g->pass1_arena->create<ZigValue>(); |
| 18372 | result->special = ConstValSpecialStatic; | 18372 | result->special = ConstValSpecialStatic; |
| 18373 | result->type = ir_type_info_get_type(ira, "ErrorSet", nullptr); | 18373 | result->type = ir_type_info_get_type(ira, "ErrorSet", nullptr); |
| 18374 | | 18374 | |
| 18375 | ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr); | 18375 | ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr); |
| 18376 | if (!resolve_inferred_error_set(ira->codegen, type_entry, source_node)) { | 18376 | if (!resolve_inferred_error_set(g, type_entry, source_node)) { |
| 18377 | return ErrorSemanticAnalyzeFail; | 18377 | return ErrorSemanticAnalyzeFail; |
| 18378 | } | 18378 | } |
| 18379 | if (type_is_global_error_set(type_entry)) { | 18379 | if (type_is_global_error_set(type_entry)) { |
| 18380 | result->data.x_optional = nullptr; | 18380 | result->data.x_optional = nullptr; |
| 18381 | break; | 18381 | break; |
| 18382 | } | 18382 | } |
| 18383 | if ((err = type_resolve(ira->codegen, type_info_error_type, ResolveStatusSizeKnown))) { | 18383 | if ((err = type_resolve(g, type_info_error_type, ResolveStatusSizeKnown))) { |
| 18384 | zig_unreachable(); | 18384 | zig_unreachable(); |
| 18385 | } | 18385 | } |
| 18386 | ZigValue *slice_val = ira->codegen->pass1_arena->create<ZigValue>(); | 18386 | ZigValue *slice_val = g->pass1_arena->create<ZigValue>(); |
| 18387 | result->data.x_optional = slice_val; | 18387 | result->data.x_optional = slice_val; |
| 18388 | | 18388 | |
| 18389 | uint32_t error_count = type_entry->data.error_set.err_count; | 18389 | uint32_t error_count = type_entry->data.error_set.err_count; |
| 18390 | ZigValue *error_array = ira->codegen->pass1_arena->create<ZigValue>(); | 18390 | ZigValue *error_array = g->pass1_arena->create<ZigValue>(); |
| 18391 | error_array->special = ConstValSpecialStatic; | 18391 | error_array->special = ConstValSpecialStatic; |
| 18392 | error_array->type = get_array_type(ira->codegen, type_info_error_type, error_count, nullptr); | 18392 | error_array->type = get_array_type(g, type_info_error_type, error_count, nullptr); |
| 18393 | error_array->data.x_array.special = ConstArraySpecialNone; | 18393 | error_array->data.x_array.special = ConstArraySpecialNone; |
| 18394 | error_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(error_count); | 18394 | error_array->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(error_count); |
| 18395 | | 18395 | |
| 18396 | init_const_slice(ira->codegen, slice_val, error_array, 0, error_count, false, nullptr); | 18396 | init_const_slice(g, slice_val, error_array, 0, error_count, false, nullptr); |
| 18397 | for (uint32_t error_index = 0; error_index < error_count; error_index++) { | 18397 | for (uint32_t error_index = 0; error_index < error_count; error_index++) { |
| 18398 | ErrorTableEntry *error = type_entry->data.error_set.errors[error_index]; | 18398 | ErrorTableEntry *error = type_entry->data.error_set.errors[error_index]; |
| 18399 | ZigValue *error_val = &error_array->data.x_array.data.s_none.elements[error_index]; | 18399 | ZigValue *error_val = &error_array->data.x_array.data.s_none.elements[error_index]; |
| ... | @@ -18401,14 +18401,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18401,14 +18401,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18401 | error_val->special = ConstValSpecialStatic; | 18401 | error_val->special = ConstValSpecialStatic; |
| 18402 | error_val->type = type_info_error_type; | 18402 | error_val->type = type_info_error_type; |
| 18403 | | 18403 | |
| 18404 | ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 1); | 18404 | ZigValue **inner_fields = alloc_const_vals_ptrs(g, 1); |
| 18405 | | 18405 | |
| 18406 | ZigValue *name = nullptr; | 18406 | ZigValue *name = nullptr; |
| 18407 | if (error->cached_error_name_val != nullptr) | 18407 | if (error->cached_error_name_val != nullptr) |
| 18408 | name = error->cached_error_name_val; | 18408 | name = error->cached_error_name_val; |
| 18409 | if (name == nullptr) | 18409 | if (name == nullptr) |
| 18410 | name = create_const_str_lit(ira->codegen, &error->name)->data.x_ptr.data.ref.pointee; | 18410 | name = create_const_str_lit(g, &error->name)->data.x_ptr.data.ref.pointee; |
| 18411 | init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(&error->name), true, nullptr); | 18411 | init_const_slice(g, inner_fields[0], name, 0, buf_len(&error->name), true, nullptr); |
| 18412 | | 18412 | |
| 18413 | error_val->data.x_struct.fields = inner_fields; | 18413 | error_val->data.x_struct.fields = inner_fields; |
| 18414 | error_val->parent.id = ConstParentIdArray; | 18414 | error_val->parent.id = ConstParentIdArray; |
| ... | @@ -18420,37 +18420,37 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18420,37 +18420,37 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18420 | } | 18420 | } |
| 18421 | case ZigTypeIdErrorUnion: | 18421 | case ZigTypeIdErrorUnion: |
| 18422 | { | 18422 | { |
| 18423 | result = ira->codegen->pass1_arena->create<ZigValue>(); | 18423 | result = g->pass1_arena->create<ZigValue>(); |
| 18424 | result->special = ConstValSpecialStatic; | 18424 | result->special = ConstValSpecialStatic; |
| 18425 | result->type = ir_type_info_get_type(ira, "ErrorUnion", nullptr); | 18425 | result->type = ir_type_info_get_type(ira, "ErrorUnion", nullptr); |
| 18426 | | 18426 | |
| 18427 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 2); | 18427 | ZigValue **fields = alloc_const_vals_ptrs(g, 2); |
| 18428 | result->data.x_struct.fields = fields; | 18428 | result->data.x_struct.fields = fields; |
| 18429 | | 18429 | |
| 18430 | // error_set: type | 18430 | // error_set: type |
| 18431 | ensure_field_index(result->type, "error_set", 0); | 18431 | ensure_field_index(result->type, "error_set", 0); |
| 18432 | fields[0]->special = ConstValSpecialStatic; | 18432 | fields[0]->special = ConstValSpecialStatic; |
| 18433 | fields[0]->type = ira->codegen->builtin_types.entry_type; | 18433 | fields[0]->type = g->builtin_types.entry_type; |
| 18434 | fields[0]->data.x_type = type_entry->data.error_union.err_set_type; | 18434 | fields[0]->data.x_type = type_entry->data.error_union.err_set_type; |
| 18435 | | 18435 | |
| 18436 | // payload: type | 18436 | // payload: type |
| 18437 | ensure_field_index(result->type, "payload", 1); | 18437 | ensure_field_index(result->type, "payload", 1); |
| 18438 | fields[1]->special = ConstValSpecialStatic; | 18438 | fields[1]->special = ConstValSpecialStatic; |
| 18439 | fields[1]->type = ira->codegen->builtin_types.entry_type; | 18439 | fields[1]->type = g->builtin_types.entry_type; |
| 18440 | fields[1]->data.x_type = type_entry->data.error_union.payload_type; | 18440 | fields[1]->data.x_type = type_entry->data.error_union.payload_type; |
| 18441 | | 18441 | |
| 18442 | break; | 18442 | break; |
| 18443 | } | 18443 | } |
| 18444 | case ZigTypeIdUnion: | 18444 | case ZigTypeIdUnion: |
| 18445 | { | 18445 | { |
| 18446 | if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown))) | 18446 | if ((err = type_resolve(g, type_entry, ResolveStatusSizeKnown))) |
| 18447 | return err; | 18447 | return err; |
| 18448 | | 18448 | |
| 18449 | result = ira->codegen->pass1_arena->create<ZigValue>(); | 18449 | result = g->pass1_arena->create<ZigValue>(); |
| 18450 | result->special = ConstValSpecialStatic; | 18450 | result->special = ConstValSpecialStatic; |
| 18451 | result->type = ir_type_info_get_type(ira, "Union", nullptr); | 18451 | result->type = ir_type_info_get_type(ira, "Union", nullptr); |
| 18452 | | 18452 | |
| 18453 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 4); | 18453 | ZigValue **fields = alloc_const_vals_ptrs(g, 4); |
| 18454 | result->data.x_struct.fields = fields; | 18454 | result->data.x_struct.fields = fields; |
| 18455 | | 18455 | |
| 18456 | // layout: ContainerLayout | 18456 | // layout: ContainerLayout |
| ... | @@ -18461,15 +18461,15 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18461,15 +18461,15 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18461 | // tag_type: ?type | 18461 | // tag_type: ?type |
| 18462 | ensure_field_index(result->type, "tag_type", 1); | 18462 | ensure_field_index(result->type, "tag_type", 1); |
| 18463 | fields[1]->special = ConstValSpecialStatic; | 18463 | fields[1]->special = ConstValSpecialStatic; |
| 18464 | fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type); | 18464 | fields[1]->type = get_optional_type(g, g->builtin_types.entry_type); |
| 18465 | | 18465 | |
| 18466 | AstNode *union_decl_node = type_entry->data.unionation.decl_node; | 18466 | AstNode *union_decl_node = type_entry->data.unionation.decl_node; |
| 18467 | if (union_decl_node->data.container_decl.auto_enum || | 18467 | if (union_decl_node->data.container_decl.auto_enum || |
| 18468 | union_decl_node->data.container_decl.init_arg_expr != nullptr) | 18468 | union_decl_node->data.container_decl.init_arg_expr != nullptr) |
| 18469 | { | 18469 | { |
| 18470 | ZigValue *tag_type = ira->codegen->pass1_arena->create<ZigValue>(); | 18470 | ZigValue *tag_type = g->pass1_arena->create<ZigValue>(); |
| 18471 | tag_type->special = ConstValSpecialStatic; | 18471 | tag_type->special = ConstValSpecialStatic; |
| 18472 | tag_type->type = ira->codegen->builtin_types.entry_type; | 18472 | tag_type->type = g->builtin_types.entry_type; |
| 18473 | tag_type->data.x_type = type_entry->data.unionation.tag_type; | 18473 | tag_type->data.x_type = type_entry->data.unionation.tag_type; |
| 18474 | fields[1]->data.x_optional = tag_type; | 18474 | fields[1]->data.x_optional = tag_type; |
| 18475 | } else { | 18475 | } else { |
| ... | @@ -18479,17 +18479,17 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18479,17 +18479,17 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18479 | ensure_field_index(result->type, "fields", 2); | 18479 | ensure_field_index(result->type, "fields", 2); |
| 18480 | | 18480 | |
| 18481 | ZigType *type_info_union_field_type = ir_type_info_get_type(ira, "UnionField", nullptr); | 18481 | ZigType *type_info_union_field_type = ir_type_info_get_type(ira, "UnionField", nullptr); |
| 18482 | if ((err = type_resolve(ira->codegen, type_info_union_field_type, ResolveStatusSizeKnown))) | 18482 | if ((err = type_resolve(g, type_info_union_field_type, ResolveStatusSizeKnown))) |
| 18483 | zig_unreachable(); | 18483 | zig_unreachable(); |
| 18484 | uint32_t union_field_count = type_entry->data.unionation.src_field_count; | 18484 | uint32_t union_field_count = type_entry->data.unionation.src_field_count; |
| 18485 | | 18485 | |
| 18486 | ZigValue *union_field_array = ira->codegen->pass1_arena->create<ZigValue>(); | 18486 | ZigValue *union_field_array = g->pass1_arena->create<ZigValue>(); |
| 18487 | union_field_array->special = ConstValSpecialStatic; | 18487 | union_field_array->special = ConstValSpecialStatic; |
| 18488 | union_field_array->type = get_array_type(ira->codegen, type_info_union_field_type, union_field_count, nullptr); | 18488 | union_field_array->type = get_array_type(g, type_info_union_field_type, union_field_count, nullptr); |
| 18489 | union_field_array->data.x_array.special = ConstArraySpecialNone; | 18489 | union_field_array->data.x_array.special = ConstArraySpecialNone; |
| 18490 | union_field_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(union_field_count); | 18490 | union_field_array->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(union_field_count); |
| 18491 | | 18491 | |
| 18492 | init_const_slice(ira->codegen, fields[2], union_field_array, 0, union_field_count, false, nullptr); | 18492 | init_const_slice(g, fields[2], union_field_array, 0, union_field_count, false, nullptr); |
| 18493 | | 18493 | |
| 18494 | for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) { | 18494 | for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) { |
| 18495 | TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index]; | 18495 | TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index]; |
| ... | @@ -18498,19 +18498,19 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18498,19 +18498,19 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18498 | union_field_val->special = ConstValSpecialStatic; | 18498 | union_field_val->special = ConstValSpecialStatic; |
| 18499 | union_field_val->type = type_info_union_field_type; | 18499 | union_field_val->type = type_info_union_field_type; |
| 18500 | | 18500 | |
| 18501 | ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 3); | 18501 | ZigValue **inner_fields = alloc_const_vals_ptrs(g, 3); |
| 18502 | // field_type: type | 18502 | // field_type: type |
| 18503 | inner_fields[1]->special = ConstValSpecialStatic; | 18503 | inner_fields[1]->special = ConstValSpecialStatic; |
| 18504 | inner_fields[1]->type = ira->codegen->builtin_types.entry_type; | 18504 | inner_fields[1]->type = g->builtin_types.entry_type; |
| 18505 | inner_fields[1]->data.x_type = union_field->type_entry; | 18505 | inner_fields[1]->data.x_type = union_field->type_entry; |
| 18506 | | 18506 | |
| 18507 | // alignment: comptime_int | 18507 | // alignment: comptime_int |
| 18508 | inner_fields[2]->special = ConstValSpecialStatic; | 18508 | inner_fields[2]->special = ConstValSpecialStatic; |
| 18509 | inner_fields[2]->type = ira->codegen->builtin_types.entry_num_lit_int; | 18509 | inner_fields[2]->type = g->builtin_types.entry_num_lit_int; |
| 18510 | bigint_init_unsigned(&inner_fields[2]->data.x_bigint, union_field->align); | 18510 | bigint_init_unsigned(&inner_fields[2]->data.x_bigint, union_field->align); |
| 18511 | | 18511 | |
| 18512 | ZigValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee; | 18512 | ZigValue *name = create_const_str_lit(g, union_field->name)->data.x_ptr.data.ref.pointee; |
| 18513 | init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true, nullptr); | 18513 | init_const_slice(g, inner_fields[0], name, 0, buf_len(union_field->name), true, nullptr); |
| 18514 | | 18514 | |
| 18515 | union_field_val->data.x_struct.fields = inner_fields; | 18515 | union_field_val->data.x_struct.fields = inner_fields; |
| 18516 | union_field_val->parent.id = ConstParentIdArray; | 18516 | union_field_val->parent.id = ConstParentIdArray; |
| ... | @@ -18536,14 +18536,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18536,14 +18536,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18536 | break; | 18536 | break; |
| 18537 | } | 18537 | } |
| 18538 | | 18538 | |
| 18539 | if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown))) | 18539 | if ((err = type_resolve(g, type_entry, ResolveStatusSizeKnown))) |
| 18540 | return err; | 18540 | return err; |
| 18541 | | 18541 | |
| 18542 | result = ira->codegen->pass1_arena->create<ZigValue>(); | 18542 | result = g->pass1_arena->create<ZigValue>(); |
| 18543 | result->special = ConstValSpecialStatic; | 18543 | result->special = ConstValSpecialStatic; |
| 18544 | result->type = ir_type_info_get_type(ira, "Struct", nullptr); | 18544 | result->type = ir_type_info_get_type(ira, "Struct", nullptr); |
| 18545 | | 18545 | |
| 18546 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 4); | 18546 | ZigValue **fields = alloc_const_vals_ptrs(g, 4); |
| 18547 | result->data.x_struct.fields = fields; | 18547 | result->data.x_struct.fields = fields; |
| 18548 | | 18548 | |
| 18549 | // layout: ContainerLayout | 18549 | // layout: ContainerLayout |
| ... | @@ -18555,18 +18555,18 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18555,18 +18555,18 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18555 | ensure_field_index(result->type, "fields", 1); | 18555 | ensure_field_index(result->type, "fields", 1); |
| 18556 | | 18556 | |
| 18557 | ZigType *type_info_struct_field_type = ir_type_info_get_type(ira, "StructField", nullptr); | 18557 | ZigType *type_info_struct_field_type = ir_type_info_get_type(ira, "StructField", nullptr); |
| 18558 | if ((err = type_resolve(ira->codegen, type_info_struct_field_type, ResolveStatusSizeKnown))) { | 18558 | if ((err = type_resolve(g, type_info_struct_field_type, ResolveStatusSizeKnown))) { |
| 18559 | zig_unreachable(); | 18559 | zig_unreachable(); |
| 18560 | } | 18560 | } |
| 18561 | uint32_t struct_field_count = type_entry->data.structure.src_field_count; | 18561 | uint32_t struct_field_count = type_entry->data.structure.src_field_count; |
| 18562 | | 18562 | |
| 18563 | ZigValue *struct_field_array = ira->codegen->pass1_arena->create<ZigValue>(); | 18563 | ZigValue *struct_field_array = g->pass1_arena->create<ZigValue>(); |
| 18564 | struct_field_array->special = ConstValSpecialStatic; | 18564 | struct_field_array->special = ConstValSpecialStatic; |
| 18565 | struct_field_array->type = get_array_type(ira->codegen, type_info_struct_field_type, struct_field_count, nullptr); | 18565 | struct_field_array->type = get_array_type(g, type_info_struct_field_type, struct_field_count, nullptr); |
| 18566 | struct_field_array->data.x_array.special = ConstArraySpecialNone; | 18566 | struct_field_array->data.x_array.special = ConstArraySpecialNone; |
| 18567 | struct_field_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(struct_field_count); | 18567 | struct_field_array->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(struct_field_count); |
| 18568 | | 18568 | |
| 18569 | init_const_slice(ira->codegen, fields[1], struct_field_array, 0, struct_field_count, false, nullptr); | 18569 | init_const_slice(g, fields[1], struct_field_array, 0, struct_field_count, false, nullptr); |
| 18570 | | 18570 | |
| 18571 | for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) { | 18571 | for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) { |
| 18572 | TypeStructField *struct_field = type_entry->data.structure.fields[struct_field_index]; | 18572 | TypeStructField *struct_field = type_entry->data.structure.fields[struct_field_index]; |
| ... | @@ -18575,34 +18575,37 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18575,34 +18575,37 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18575 | struct_field_val->special = ConstValSpecialStatic; | 18575 | struct_field_val->special = ConstValSpecialStatic; |
| 18576 | struct_field_val->type = type_info_struct_field_type; | 18576 | struct_field_val->type = type_info_struct_field_type; |
| 18577 | | 18577 | |
| 18578 | ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 5); | 18578 | ZigValue **inner_fields = alloc_const_vals_ptrs(g, 5); |
| 18579 | | 18579 | |
| 18580 | inner_fields[1]->special = ConstValSpecialStatic; | 18580 | inner_fields[1]->special = ConstValSpecialStatic; |
| 18581 | inner_fields[1]->type = ira->codegen->builtin_types.entry_type; | 18581 | inner_fields[1]->type = g->builtin_types.entry_type; |
| 18582 | inner_fields[1]->data.x_type = struct_field->type_entry; | 18582 | inner_fields[1]->data.x_type = struct_field->type_entry; |
| 18583 | | 18583 | |
| 18584 | // default_value: anytype | 18584 | // default_value: ?*const anyopaque |
| 18585 | inner_fields[2]->special = ConstValSpecialStatic; | 18585 | inner_fields[2]->special = ConstValSpecialStatic; |
| 18586 | inner_fields[2]->type = get_optional_type2(ira->codegen, struct_field->type_entry); | 18586 | inner_fields[2]->type = g->builtin_types.entry_opt_ptr_const_anyopaque; |
| 18587 | if (inner_fields[2]->type == nullptr) return ErrorSemanticAnalyzeFail; | 18587 | memoize_field_init_val(g, type_entry, struct_field); |
| 18588 | memoize_field_init_val(ira->codegen, type_entry, struct_field); | 18588 | if (struct_field->init_val != nullptr && |
| 18589 | if(struct_field->init_val != nullptr && type_is_invalid(struct_field->init_val->type)){ | 18589 | type_is_invalid(struct_field->init_val->type)) |
| | 18590 | { |
| 18590 | return ErrorSemanticAnalyzeFail; | 18591 | return ErrorSemanticAnalyzeFail; |
| 18591 | } | 18592 | } |
| 18592 | set_optional_payload(inner_fields[2], struct_field->init_val); | 18593 | ZigValue *ptr_to_sent = (struct_field->init_val == nullptr) ? nullptr : |
| | 18594 | create_const_ptr_ref(g, struct_field->init_val, true); |
| | 18595 | set_optional_payload(inner_fields[2], ptr_to_sent); |
| 18593 | | 18596 | |
| 18594 | // is_comptime: bool | 18597 | // is_comptime: bool |
| 18595 | inner_fields[3]->special = ConstValSpecialStatic; | 18598 | inner_fields[3]->special = ConstValSpecialStatic; |
| 18596 | inner_fields[3]->type = ira->codegen->builtin_types.entry_bool; | 18599 | inner_fields[3]->type = g->builtin_types.entry_bool; |
| 18597 | inner_fields[3]->data.x_bool = struct_field->is_comptime; | 18600 | inner_fields[3]->data.x_bool = struct_field->is_comptime; |
| 18598 | | 18601 | |
| 18599 | // alignment: comptime_int | 18602 | // alignment: comptime_int |
| 18600 | inner_fields[4]->special = ConstValSpecialStatic; | 18603 | inner_fields[4]->special = ConstValSpecialStatic; |
| 18601 | inner_fields[4]->type = ira->codegen->builtin_types.entry_num_lit_int; | 18604 | inner_fields[4]->type = g->builtin_types.entry_num_lit_int; |
| 18602 | bigint_init_unsigned(&inner_fields[4]->data.x_bigint, struct_field->align); | 18605 | bigint_init_unsigned(&inner_fields[4]->data.x_bigint, struct_field->align); |
| 18603 | | 18606 | |
| 18604 | ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee; | 18607 | ZigValue *name = create_const_str_lit(g, struct_field->name)->data.x_ptr.data.ref.pointee; |
| 18605 | init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true, nullptr); | 18608 | init_const_slice(g, inner_fields[0], name, 0, buf_len(struct_field->name), true, nullptr); |
| 18606 | | 18609 | |
| 18607 | struct_field_val->data.x_struct.fields = inner_fields; | 18610 | struct_field_val->data.x_struct.fields = inner_fields; |
| 18608 | struct_field_val->parent.id = ConstParentIdArray; | 18611 | struct_field_val->parent.id = ConstParentIdArray; |
| ... | @@ -18620,69 +18623,69 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18620,69 +18623,69 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18620 | // is_tuple: bool | 18623 | // is_tuple: bool |
| 18621 | ensure_field_index(result->type, "is_tuple", 3); | 18624 | ensure_field_index(result->type, "is_tuple", 3); |
| 18622 | fields[3]->special = ConstValSpecialStatic; | 18625 | fields[3]->special = ConstValSpecialStatic; |
| 18623 | fields[3]->type = ira->codegen->builtin_types.entry_bool; | 18626 | fields[3]->type = g->builtin_types.entry_bool; |
| 18624 | fields[3]->data.x_bool = is_tuple(type_entry); | 18627 | fields[3]->data.x_bool = is_tuple(type_entry); |
| 18625 | | 18628 | |
| 18626 | break; | 18629 | break; |
| 18627 | } | 18630 | } |
| 18628 | case ZigTypeIdFn: | 18631 | case ZigTypeIdFn: |
| 18629 | { | 18632 | { |
| 18630 | result = ira->codegen->pass1_arena->create<ZigValue>(); | 18633 | result = g->pass1_arena->create<ZigValue>(); |
| 18631 | result->special = ConstValSpecialStatic; | 18634 | result->special = ConstValSpecialStatic; |
| 18632 | result->type = ir_type_info_get_type(ira, "Fn", nullptr); | 18635 | result->type = ir_type_info_get_type(ira, "Fn", nullptr); |
| 18633 | | 18636 | |
| 18634 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 7); | 18637 | ZigValue **fields = alloc_const_vals_ptrs(g, 7); |
| 18635 | result->data.x_struct.fields = fields; | 18638 | result->data.x_struct.fields = fields; |
| 18636 | | 18639 | |
| 18637 | // calling_convention: TypeInfo.CallingConvention | 18640 | // calling_convention: TypeInfo.CallingConvention |
| 18638 | ensure_field_index(result->type, "calling_convention", 0); | 18641 | ensure_field_index(result->type, "calling_convention", 0); |
| 18639 | fields[0]->special = ConstValSpecialStatic; | 18642 | fields[0]->special = ConstValSpecialStatic; |
| 18640 | fields[0]->type = get_builtin_type(ira->codegen, "CallingConvention"); | 18643 | fields[0]->type = get_builtin_type(g, "CallingConvention"); |
| 18641 | bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.fn.fn_type_id.cc); | 18644 | bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.fn.fn_type_id.cc); |
| 18642 | // alignment: comptime_int | 18645 | // alignment: comptime_int |
| 18643 | ensure_field_index(result->type, "alignment", 1); | 18646 | ensure_field_index(result->type, "alignment", 1); |
| 18644 | fields[1]->special = ConstValSpecialStatic; | 18647 | fields[1]->special = ConstValSpecialStatic; |
| 18645 | fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int; | 18648 | fields[1]->type = g->builtin_types.entry_num_lit_int; |
| 18646 | bigint_init_unsigned(&fields[1]->data.x_bigint, get_ptr_align(ira->codegen, type_entry)); | 18649 | bigint_init_unsigned(&fields[1]->data.x_bigint, get_ptr_align(g, type_entry)); |
| 18647 | // is_generic: bool | 18650 | // is_generic: bool |
| 18648 | ensure_field_index(result->type, "is_generic", 2); | 18651 | ensure_field_index(result->type, "is_generic", 2); |
| 18649 | bool is_generic = type_entry->data.fn.is_generic; | 18652 | bool is_generic = type_entry->data.fn.is_generic; |
| 18650 | fields[2]->special = ConstValSpecialStatic; | 18653 | fields[2]->special = ConstValSpecialStatic; |
| 18651 | fields[2]->type = ira->codegen->builtin_types.entry_bool; | 18654 | fields[2]->type = g->builtin_types.entry_bool; |
| 18652 | fields[2]->data.x_bool = is_generic; | 18655 | fields[2]->data.x_bool = is_generic; |
| 18653 | // is_varargs: bool | 18656 | // is_varargs: bool |
| 18654 | ensure_field_index(result->type, "is_var_args", 3); | 18657 | ensure_field_index(result->type, "is_var_args", 3); |
| 18655 | bool is_varargs = type_entry->data.fn.fn_type_id.is_var_args; | 18658 | bool is_varargs = type_entry->data.fn.fn_type_id.is_var_args; |
| 18656 | fields[3]->special = ConstValSpecialStatic; | 18659 | fields[3]->special = ConstValSpecialStatic; |
| 18657 | fields[3]->type = ira->codegen->builtin_types.entry_bool; | 18660 | fields[3]->type = g->builtin_types.entry_bool; |
| 18658 | fields[3]->data.x_bool = is_varargs; | 18661 | fields[3]->data.x_bool = is_varargs; |
| 18659 | // return_type: ?type | 18662 | // return_type: ?type |
| 18660 | ensure_field_index(result->type, "return_type", 4); | 18663 | ensure_field_index(result->type, "return_type", 4); |
| 18661 | fields[4]->special = ConstValSpecialStatic; | 18664 | fields[4]->special = ConstValSpecialStatic; |
| 18662 | fields[4]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type); | 18665 | fields[4]->type = get_optional_type(g, g->builtin_types.entry_type); |
| 18663 | if (type_entry->data.fn.fn_type_id.return_type == nullptr) | 18666 | if (type_entry->data.fn.fn_type_id.return_type == nullptr) |
| 18664 | fields[4]->data.x_optional = nullptr; | 18667 | fields[4]->data.x_optional = nullptr; |
| 18665 | else { | 18668 | else { |
| 18666 | ZigValue *return_type = ira->codegen->pass1_arena->create<ZigValue>(); | 18669 | ZigValue *return_type = g->pass1_arena->create<ZigValue>(); |
| 18667 | return_type->special = ConstValSpecialStatic; | 18670 | return_type->special = ConstValSpecialStatic; |
| 18668 | return_type->type = ira->codegen->builtin_types.entry_type; | 18671 | return_type->type = g->builtin_types.entry_type; |
| 18669 | return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type; | 18672 | return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type; |
| 18670 | fields[4]->data.x_optional = return_type; | 18673 | fields[4]->data.x_optional = return_type; |
| 18671 | } | 18674 | } |
| 18672 | // args: []TypeInfo.FnArg | 18675 | // args: []TypeInfo.FnArg |
| 18673 | ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr); | 18676 | ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr); |
| 18674 | if ((err = type_resolve(ira->codegen, type_info_fn_arg_type, ResolveStatusSizeKnown))) { | 18677 | if ((err = type_resolve(g, type_info_fn_arg_type, ResolveStatusSizeKnown))) { |
| 18675 | zig_unreachable(); | 18678 | zig_unreachable(); |
| 18676 | } | 18679 | } |
| 18677 | size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count; | 18680 | size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count; |
| 18678 | | 18681 | |
| 18679 | ZigValue *fn_arg_array = ira->codegen->pass1_arena->create<ZigValue>(); | 18682 | ZigValue *fn_arg_array = g->pass1_arena->create<ZigValue>(); |
| 18680 | fn_arg_array->special = ConstValSpecialStatic; | 18683 | fn_arg_array->special = ConstValSpecialStatic; |
| 18681 | fn_arg_array->type = get_array_type(ira->codegen, type_info_fn_arg_type, fn_arg_count, nullptr); | 18684 | fn_arg_array->type = get_array_type(g, type_info_fn_arg_type, fn_arg_count, nullptr); |
| 18682 | fn_arg_array->data.x_array.special = ConstArraySpecialNone; | 18685 | fn_arg_array->data.x_array.special = ConstArraySpecialNone; |
| 18683 | fn_arg_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(fn_arg_count); | 18686 | fn_arg_array->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(fn_arg_count); |
| 18684 | | 18687 | |
| 18685 | init_const_slice(ira->codegen, fields[5], fn_arg_array, 0, fn_arg_count, false, nullptr); | 18688 | init_const_slice(g, fields[5], fn_arg_array, 0, fn_arg_count, false, nullptr); |
| 18686 | | 18689 | |
| 18687 | for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) { | 18690 | for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) { |
| 18688 | FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index]; | 18691 | FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index]; |
| ... | @@ -18694,22 +18697,22 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18694,22 +18697,22 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18694 | bool arg_is_generic = fn_param_info->type == nullptr; | 18697 | bool arg_is_generic = fn_param_info->type == nullptr; |
| 18695 | if (arg_is_generic) assert(is_generic); | 18698 | if (arg_is_generic) assert(is_generic); |
| 18696 | | 18699 | |
| 18697 | ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 3); | 18700 | ZigValue **inner_fields = alloc_const_vals_ptrs(g, 3); |
| 18698 | inner_fields[0]->special = ConstValSpecialStatic; | 18701 | inner_fields[0]->special = ConstValSpecialStatic; |
| 18699 | inner_fields[0]->type = ira->codegen->builtin_types.entry_bool; | 18702 | inner_fields[0]->type = g->builtin_types.entry_bool; |
| 18700 | inner_fields[0]->data.x_bool = arg_is_generic; | 18703 | inner_fields[0]->data.x_bool = arg_is_generic; |
| 18701 | inner_fields[1]->special = ConstValSpecialStatic; | 18704 | inner_fields[1]->special = ConstValSpecialStatic; |
| 18702 | inner_fields[1]->type = ira->codegen->builtin_types.entry_bool; | 18705 | inner_fields[1]->type = g->builtin_types.entry_bool; |
| 18703 | inner_fields[1]->data.x_bool = fn_param_info->is_noalias; | 18706 | inner_fields[1]->data.x_bool = fn_param_info->is_noalias; |
| 18704 | inner_fields[2]->special = ConstValSpecialStatic; | 18707 | inner_fields[2]->special = ConstValSpecialStatic; |
| 18705 | inner_fields[2]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type); | 18708 | inner_fields[2]->type = get_optional_type(g, g->builtin_types.entry_type); |
| 18706 | | 18709 | |
| 18707 | if (arg_is_generic) | 18710 | if (arg_is_generic) |
| 18708 | inner_fields[2]->data.x_optional = nullptr; | 18711 | inner_fields[2]->data.x_optional = nullptr; |
| 18709 | else { | 18712 | else { |
| 18710 | ZigValue *arg_type = ira->codegen->pass1_arena->create<ZigValue>(); | 18713 | ZigValue *arg_type = g->pass1_arena->create<ZigValue>(); |
| 18711 | arg_type->special = ConstValSpecialStatic; | 18714 | arg_type->special = ConstValSpecialStatic; |
| 18712 | arg_type->type = ira->codegen->builtin_types.entry_type; | 18715 | arg_type->type = g->builtin_types.entry_type; |
| 18713 | arg_type->data.x_type = fn_param_info->type; | 18716 | arg_type->data.x_type = fn_param_info->type; |
| 18714 | inner_fields[2]->data.x_optional = arg_type; | 18717 | inner_fields[2]->data.x_optional = arg_type; |
| 18715 | } | 18718 | } |
| ... | @@ -18733,11 +18736,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18733,11 +18736,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18733 | } | 18736 | } |
| 18734 | case ZigTypeIdOpaque: | 18737 | case ZigTypeIdOpaque: |
| 18735 | { | 18738 | { |
| 18736 | result = ira->codegen->pass1_arena->create<ZigValue>(); | 18739 | result = g->pass1_arena->create<ZigValue>(); |
| 18737 | result->special = ConstValSpecialStatic; | 18740 | result->special = ConstValSpecialStatic; |
| 18738 | result->type = ir_type_info_get_type(ira, "Opaque", nullptr); | 18741 | result->type = ir_type_info_get_type(ira, "Opaque", nullptr); |
| 18739 | | 18742 | |
| 18740 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1); | 18743 | ZigValue **fields = alloc_const_vals_ptrs(g, 1); |
| 18741 | result->data.x_struct.fields = fields; | 18744 | result->data.x_struct.fields = fields; |
| 18742 | | 18745 | |
| 18743 | // decls: []TypeInfo.Declaration | 18746 | // decls: []TypeInfo.Declaration |
| ... | @@ -18752,21 +18755,24 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour | ... | @@ -18752,21 +18755,24 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18752 | } | 18755 | } |
| 18753 | case ZigTypeIdFnFrame: | 18756 | case ZigTypeIdFnFrame: |
| 18754 | { | 18757 | { |
| 18755 | result = ira->codegen->pass1_arena->create<ZigValue>(); | 18758 | result = g->pass1_arena->create<ZigValue>(); |
| 18756 | result->special = ConstValSpecialStatic; | 18759 | result->special = ConstValSpecialStatic; |
| 18757 | result->type = ir_type_info_get_type(ira, "Frame", nullptr); | 18760 | result->type = ir_type_info_get_type(ira, "Frame", nullptr); |
| 18758 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1); | 18761 | ZigValue **fields = alloc_const_vals_ptrs(g, 1); |
| 18759 | result->data.x_struct.fields = fields; | 18762 | result->data.x_struct.fields = fields; |
| 18760 | ZigFn *fn = type_entry->data.frame.fn; | 18763 | ZigFn *fn = type_entry->data.frame.fn; |
| 18761 | // function: anytype | 18764 | // function: ?*const anyopaque |
| 18762 | ensure_field_index(result->type, "function", 0); | 18765 | ensure_field_index(result->type, "function", 0); |
| 18763 | fields[0] = create_const_fn(ira->codegen, fn); | 18766 | fields[0]->special = ConstValSpecialStatic; |
| | 18767 | fields[0]->type = get_pointer_to_type(g, g->builtin_types.entry_anyopaque, true); |
| | 18768 | fields[0]->data.x_ptr.special = ConstPtrSpecialFunction; |
| | 18769 | fields[0]->data.x_ptr.data.fn.fn_entry = fn; |
| 18764 | break; | 18770 | break; |
| 18765 | } | 18771 | } |
| 18766 | } | 18772 | } |
| 18767 | | 18773 | |
| 18768 | assert(result != nullptr); | 18774 | assert(result != nullptr); |
| 18769 | ira->codegen->type_info_cache.put(type_entry, result); | 18775 | g->type_info_cache.put(type_entry, result); |
| 18770 | *out = result; | 18776 | *out = result; |
| 18771 | return ErrorNone; | 18777 | return ErrorNone; |
| 18772 | } | 18778 | } |
| ... | @@ -18810,26 +18816,25 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue | ... | @@ -18810,26 +18816,25 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue |
| 18810 | return val; | 18816 | return val; |
| 18811 | } | 18817 | } |
| 18812 | | 18818 | |
| 18813 | static Error get_const_field_sentinel(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigValue *struct_value, | 18819 | static Error get_const_field_sentinel(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 18814 | const char *name, size_t field_index, ZigType *elem_type, ZigValue **result) | 18820 | ZigValue *struct_value, const char *name, size_t field_index, ZigType *elem_type, |
| | 18821 | ZigValue **result) |
| 18815 | { | 18822 | { |
| 18816 | ZigValue *field_val = get_const_field(ira, source_node, struct_value, name, field_index); | 18823 | ZigValue *field_val = get_const_field(ira, source_node, struct_value, name, field_index); |
| 18817 | if (field_val == nullptr) | 18824 | if (field_val == nullptr) |
| 18818 | return ErrorSemanticAnalyzeFail; | 18825 | return ErrorSemanticAnalyzeFail; |
| 18819 | | 18826 | |
| 18820 | Stage1AirInst *field_inst = ir_const_move(ira, scope, source_node, field_val); | 18827 | // type of `field_val` is `?*const anyopaque`. |
| 18821 | Stage1AirInst *casted_field_inst = ir_implicit_cast(ira, field_inst, | 18828 | if (field_val->data.x_ptr.special == ConstPtrSpecialNull) { |
| 18822 | get_optional_type(ira->codegen, elem_type)); | | |
| 18823 | if (type_is_invalid(casted_field_inst->value->type)) | | |
| 18824 | return ErrorSemanticAnalyzeFail; | | |
| 18825 | | | |
| 18826 | if (optional_value_is_null(casted_field_inst->value)) { | | |
| 18827 | *result = nullptr; | 18829 | *result = nullptr; |
| 18828 | } else { | 18830 | return ErrorNone; |
| 18829 | assert(type_has_optional_repr(casted_field_inst->value->type)); | | |
| 18830 | *result = casted_field_inst->value->data.x_optional; | | |
| 18831 | } | 18831 | } |
| 18832 | | 18832 | |
| | 18833 | ZigValue *pointee = const_ptr_pointee_unchecked_no_isf(ira->codegen, field_val); |
| | 18834 | if (pointee == nullptr) |
| | 18835 | return ErrorSemanticAnalyzeFail; |
| | 18836 | |
| | 18837 | *result = pointee; |
| 18833 | return ErrorNone; | 18838 | return ErrorNone; |
| 18834 | } | 18839 | } |
| 18835 | | 18840 | |
| ... | @@ -19043,6 +19048,10 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_ | ... | @@ -19043,6 +19048,10 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_ |
| 19043 | return ira->codegen->invalid_inst_gen->value->type; | 19048 | return ira->codegen->invalid_inst_gen->value->type; |
| 19044 | } | 19049 | } |
| 19045 | | 19050 | |
| | 19051 | if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusAlignmentKnown))) { |
| | 19052 | return ira->codegen->invalid_inst_gen->value->type; |
| | 19053 | } |
| | 19054 | |
| 19046 | ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen, | 19055 | ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen, |
| 19047 | elem_type, | 19056 | elem_type, |
| 19048 | is_const, | 19057 | is_const, |
| ... | @@ -19140,15 +19149,9 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_ | ... | @@ -19140,15 +19149,9 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_ |
| 19140 | return get_any_frame_type(ira->codegen, child_type); | 19149 | return get_any_frame_type(ira->codegen, child_type); |
| 19141 | } | 19150 | } |
| 19142 | case ZigTypeIdFnFrame: { | 19151 | case ZigTypeIdFnFrame: { |
| 19143 | assert(payload->special == ConstValSpecialStatic); | 19152 | ir_add_error_node(ira, source_node, |
| 19144 | assert(payload->type == ir_type_info_get_type(ira, "Frame", nullptr)); | 19153 | buf_sprintf("use the @Frame builtin instead of @Type")); |
| 19145 | ZigValue *function = get_const_field(ira, source_node, payload, "function", 0); | 19154 | return ira->codegen->invalid_inst_gen->value->type; |
| 19146 | if (function == nullptr) | | |
| 19147 | return ira->codegen->invalid_inst_gen->value->type; | | |
| 19148 | | | |
| 19149 | assert(function->type->id == ZigTypeIdFn); | | |
| 19150 | ZigFn *fn = function->data.x_ptr.data.fn.fn_entry; | | |
| 19151 | return get_fn_frame_type(ira->codegen, fn); | | |
| 19152 | } | 19155 | } |
| 19153 | case ZigTypeIdErrorSet: { | 19156 | case ZigTypeIdErrorSet: { |
| 19154 | assert(payload->special == ConstValSpecialStatic); | 19157 | assert(payload->special == ConstValSpecialStatic); |
| ... | @@ -19276,19 +19279,17 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_ | ... | @@ -19276,19 +19279,17 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_ |
| 19276 | ZigValue *default_value = get_const_field(ira, source_node, field_value, "default_value", 2); | 19279 | ZigValue *default_value = get_const_field(ira, source_node, field_value, "default_value", 2); |
| 19277 | if (default_value == nullptr) | 19280 | if (default_value == nullptr) |
| 19278 | return ira->codegen->invalid_inst_gen->value->type; | 19281 | return ira->codegen->invalid_inst_gen->value->type; |
| 19279 | if (default_value->type->id == ZigTypeIdNull) { | 19282 | |
| | 19283 | // type of `default_value` is `?*const anyopaque`. |
| | 19284 | if (default_value->data.x_ptr.special == ConstPtrSpecialNull) { |
| 19280 | field->init_val = nullptr; | 19285 | field->init_val = nullptr; |
| 19281 | } else if (default_value->type->id == ZigTypeIdOptional && default_value->type->data.maybe.child_type == field->type_entry) { | | |
| 19282 | field->init_val = default_value->data.x_optional; | | |
| 19283 | } else if (default_value->type == field->type_entry) { | | |
| 19284 | field->init_val = default_value; | | |
| 19285 | } else { | 19286 | } else { |
| 19286 | ir_add_error_node(ira, source_node, | 19287 | ZigValue *pointee = const_ptr_pointee_unchecked_no_isf(ira->codegen, default_value); |
| 19287 | buf_sprintf("default_value of field '%s' is of type '%s', expected '%s' or '?%s'", | 19288 | if (pointee == nullptr) |
| 19288 | buf_ptr(field->name), buf_ptr(&default_value->type->name), | 19289 | return ira->codegen->invalid_inst_gen->value->type; |
| 19289 | buf_ptr(&field->type_entry->name), buf_ptr(&field->type_entry->name))); | 19290 | field->init_val = pointee; |
| 19290 | return ira->codegen->invalid_inst_gen->value->type; | | |
| 19291 | } | 19291 | } |
| | 19292 | |
| 19292 | if ((err = get_const_field_bool(ira, source_node, field_value, "is_comptime", 3, &field->is_comptime))) | 19293 | if ((err = get_const_field_bool(ira, source_node, field_value, "is_comptime", 3, &field->is_comptime))) |
| 19293 | return ira->codegen->invalid_inst_gen->value->type; | 19294 | return ira->codegen->invalid_inst_gen->value->type; |
| 19294 | BigInt *alignment = get_const_field_lit_int(ira, source_node, field_value, "alignment", 4); | 19295 | BigInt *alignment = get_const_field_lit_int(ira, source_node, field_value, "alignment", 4); |