| ... | ... | @@ -25267,6 +25267,19 @@ static ZigType *get_const_field_meta_type(IrAnalyze *ira, AstNode *source_node, |
| 25267 | 25267 | return value->data.x_type; |
| 25268 | 25268 | } |
| 25269 | 25269 | |
| 25270 | static ZigType *get_const_field_meta_type_optional(IrAnalyze *ira, AstNode *source_node, |
| 25271 | ZigValue *struct_value, const char *name, size_t field_index) |
| 25272 | { |
| 25273 | ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index); |
| 25274 | if (value == nullptr) |
| 25275 | return ira->codegen->invalid_inst_gen->value->type; |
| 25276 | assert(value->type->id == ZigTypeIdOptional); |
| 25277 | assert(value->type->data.maybe.child_type == ira->codegen->builtin_types.entry_type); |
| 25278 | if (value->data.x_optional == nullptr) |
| 25279 | return nullptr; |
| 25280 | return value->data.x_optional->data.x_type; |
| 25281 | } |
| 25282 | |
| 25270 | 25283 | static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeId tagTypeId, ZigValue *payload) { |
| 25271 | 25284 | Error err; |
| 25272 | 25285 | switch (tagTypeId) { |
| ... | ... | @@ -25388,14 +25401,42 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 25388 | 25401 | return ira->codegen->builtin_types.entry_undef; |
| 25389 | 25402 | case ZigTypeIdNull: |
| 25390 | 25403 | return ira->codegen->builtin_types.entry_null; |
| 25391 | | case ZigTypeIdOptional: |
| 25392 | | case ZigTypeIdErrorUnion: |
| 25404 | case ZigTypeIdOptional: { |
| 25405 | assert(payload->special == ConstValSpecialStatic); |
| 25406 | assert(payload->type == ir_type_info_get_type(ira, "Optional", nullptr)); |
| 25407 | ZigType *child_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 0); |
| 25408 | return get_optional_type(ira->codegen, child_type); |
| 25409 | } |
| 25410 | case ZigTypeIdErrorUnion: { |
| 25411 | assert(payload->special == ConstValSpecialStatic); |
| 25412 | assert(payload->type == ir_type_info_get_type(ira, "ErrorUnion", nullptr)); |
| 25413 | ZigType *err_set_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "error_set", 0); |
| 25414 | ZigType *payload_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "payload", 1); |
| 25415 | return get_error_union_type(ira->codegen, err_set_type, payload_type); |
| 25416 | } |
| 25417 | case ZigTypeIdOpaque: { |
| 25418 | Buf *bare_name = buf_alloc(); |
| 25419 | Buf *full_name = get_anon_type_name(ira->codegen, |
| 25420 | ira->old_irb.exec, "opaque", source_instr->scope, source_instr->source_node, bare_name); |
| 25421 | return get_opaque_type(ira->codegen, |
| 25422 | source_instr->scope, source_instr->source_node, buf_ptr(full_name), bare_name); |
| 25423 | } |
| 25424 | case ZigTypeIdVector: { |
| 25425 | assert(payload->special == ConstValSpecialStatic); |
| 25426 | assert(payload->type == ir_type_info_get_type(ira, "Vector", nullptr)); |
| 25427 | BigInt *len = get_const_field_lit_int(ira, source_instr->source_node, payload, "len", 0); |
| 25428 | ZigType *child_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 1); |
| 25429 | return get_vector_type(ira->codegen, bigint_as_u32(len), child_type); |
| 25430 | } |
| 25431 | case ZigTypeIdAnyFrame: { |
| 25432 | assert(payload->special == ConstValSpecialStatic); |
| 25433 | assert(payload->type == ir_type_info_get_type(ira, "AnyFrame", nullptr)); |
| 25434 | ZigType *child_type = get_const_field_meta_type_optional(ira, source_instr->source_node, payload, "child", 0); |
| 25435 | return get_any_frame_type(ira->codegen, child_type); |
| 25436 | } |
| 25393 | 25437 | case ZigTypeIdErrorSet: |
| 25394 | 25438 | case ZigTypeIdEnum: |
| 25395 | | case ZigTypeIdOpaque: |
| 25396 | 25439 | case ZigTypeIdFnFrame: |
| 25397 | | case ZigTypeIdAnyFrame: |
| 25398 | | case ZigTypeIdVector: |
| 25399 | 25440 | case ZigTypeIdEnumLiteral: |
| 25400 | 25441 | ir_add_error(ira, source_instr, buf_sprintf( |
| 25401 | 25442 | "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId))); |