authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-27 17:11:43-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-27 17:13:34-04:00
log009e90f446ec7a81d602906fda9b17a6af1859f5
treecebcac299214f9db88acd0015bafe26b7d4be657
parent2f2215c9f46f0a75ce65803af84984b4a5f3741c
signaturelock-open Commit is signed but in an unrecognized format.

fix @typeInfo unable to distinguish compile error vs no-payload

closes #1421 closes #1426

2 files changed, 82 insertions(+), 68 deletions(-)

src/ir.cpp+65-68
...@@ -14444,8 +14444,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -14444,8 +14444,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
14444 ConstExprValue *payload_val = union_val->data.x_union.payload;14444 ConstExprValue *payload_val = union_val->data.x_union.payload;
1444514445
14446 TypeTableEntry *field_type = field->type_entry;14446 TypeTableEntry *field_type = field->type_entry;
14447 if (field_type->id == TypeTableEntryIdVoid)14447 if (field_type->id == TypeTableEntryIdVoid) {
14448 {
14449 assert(payload_val == nullptr);14448 assert(payload_val == nullptr);
14450 payload_val = create_const_vals(1);14449 payload_val = create_const_vals(1);
14451 payload_val->special = ConstValSpecialStatic;14450 payload_val->special = ConstValSpecialStatic;
...@@ -16797,12 +16796,11 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na...@@ -16797,12 +16796,11 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na
16797 return var->value->data.x_type;16796 return var->value->data.x_type;
16798}16797}
1679916798
16800static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope)16799static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope) {
16801{
16802 Error err;16800 Error err;
16803 TypeTableEntry *type_info_definition_type = ir_type_info_get_type(ira, "Definition", nullptr);16801 TypeTableEntry *type_info_definition_type = ir_type_info_get_type(ira, "Definition", nullptr);
16804 if ((err = ensure_complete_type(ira->codegen, type_info_definition_type)))16802 if ((err = ensure_complete_type(ira->codegen, type_info_definition_type)))
16805 return false;16803 return err;
1680616804
16807 ensure_field_index(type_info_definition_type, "name", 0);16805 ensure_field_index(type_info_definition_type, "name", 0);
16808 ensure_field_index(type_info_definition_type, "is_pub", 1);16806 ensure_field_index(type_info_definition_type, "is_pub", 1);
...@@ -16810,38 +16808,33 @@ static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop...@@ -16810,38 +16808,33 @@ static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
1681016808
16811 TypeTableEntry *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type);16809 TypeTableEntry *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type);
16812 if ((err = ensure_complete_type(ira->codegen, type_info_definition_data_type)))16810 if ((err = ensure_complete_type(ira->codegen, type_info_definition_data_type)))
16813 return false;16811 return err;
1681416812
16815 TypeTableEntry *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type);16813 TypeTableEntry *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type);
16816 if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_type)))16814 if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_type)))
16817 return false;16815 return err;
1681816816
16819 TypeTableEntry *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type);16817 TypeTableEntry *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type);
16820 if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_inline_type)))16818 if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_inline_type)))
16821 return false;16819 return err;
1682216820
16823 // Loop through our definitions once to figure out how many definitions we will generate info for.16821 // Loop through our definitions once to figure out how many definitions we will generate info for.
16824 auto decl_it = decls_scope->decl_table.entry_iterator();16822 auto decl_it = decls_scope->decl_table.entry_iterator();
16825 decltype(decls_scope->decl_table)::Entry *curr_entry = nullptr;16823 decltype(decls_scope->decl_table)::Entry *curr_entry = nullptr;
16826 int definition_count = 0;16824 int definition_count = 0;
1682716825
16828 while ((curr_entry = decl_it.next()) != nullptr)16826 while ((curr_entry = decl_it.next()) != nullptr) {
16829 {
16830 // If the definition is unresolved, force it to be resolved again.16827 // If the definition is unresolved, force it to be resolved again.
16831 if (curr_entry->value->resolution == TldResolutionUnresolved)16828 if (curr_entry->value->resolution == TldResolutionUnresolved) {
16832 {
16833 resolve_top_level_decl(ira->codegen, curr_entry->value, false, curr_entry->value->source_node);16829 resolve_top_level_decl(ira->codegen, curr_entry->value, false, curr_entry->value->source_node);
16834 if (curr_entry->value->resolution != TldResolutionOk)16830 if (curr_entry->value->resolution != TldResolutionOk) {
16835 {16831 return ErrorSemanticAnalyzeFail;
16836 return false;
16837 }16832 }
16838 }16833 }
1683916834
16840 // Skip comptime blocks and test functions.16835 // Skip comptime blocks and test functions.
16841 if (curr_entry->value->id != TldIdCompTime)16836 if (curr_entry->value->id != TldIdCompTime) {
16842 {16837 if (curr_entry->value->id == TldIdFn) {
16843 if (curr_entry->value->id == TldIdFn)
16844 {
16845 FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;16838 FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
16846 if (fn_entry->is_test)16839 if (fn_entry->is_test)
16847 continue;16840 continue;
...@@ -16863,13 +16856,11 @@ static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop...@@ -16863,13 +16856,11 @@ static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
16863 decl_it = decls_scope->decl_table.entry_iterator();16856 decl_it = decls_scope->decl_table.entry_iterator();
16864 curr_entry = nullptr; 16857 curr_entry = nullptr;
16865 int definition_index = 0;16858 int definition_index = 0;
16866 while ((curr_entry = decl_it.next()) != nullptr)16859 while ((curr_entry = decl_it.next()) != nullptr) {
16867 {
16868 // Skip comptime blocks and test functions.16860 // Skip comptime blocks and test functions.
16869 if (curr_entry->value->id == TldIdCompTime)16861 if (curr_entry->value->id == TldIdCompTime) {
16870 continue;16862 continue;
16871 else if (curr_entry->value->id == TldIdFn)16863 } else if (curr_entry->value->id == TldIdFn) {
16872 {
16873 FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;16864 FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
16874 if (fn_entry->is_test)16865 if (fn_entry->is_test)
16875 continue;16866 continue;
...@@ -16892,13 +16883,12 @@ static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop...@@ -16892,13 +16883,12 @@ static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
16892 inner_fields[2].data.x_union.parent.data.p_struct.struct_val = definition_val;16883 inner_fields[2].data.x_union.parent.data.p_struct.struct_val = definition_val;
16893 inner_fields[2].data.x_union.parent.data.p_struct.field_index = 1;16884 inner_fields[2].data.x_union.parent.data.p_struct.field_index = 1;
1689416885
16895 switch (curr_entry->value->id)16886 switch (curr_entry->value->id) {
16896 {
16897 case TldIdVar:16887 case TldIdVar:
16898 {16888 {
16899 VariableTableEntry *var = ((TldVar *)curr_entry->value)->var;16889 VariableTableEntry *var = ((TldVar *)curr_entry->value)->var;
16900 if ((err = ensure_complete_type(ira->codegen, var->value->type)))16890 if ((err = ensure_complete_type(ira->codegen, var->value->type)))
16901 return false;16891 return ErrorSemanticAnalyzeFail;
1690216892
16903 if (var->value->type->id == TypeTableEntryIdMetaType)16893 if (var->value->type->id == TypeTableEntryIdMetaType)
16904 {16894 {
...@@ -17029,7 +17019,7 @@ static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop...@@ -17029,7 +17019,7 @@ static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
17029 {17019 {
17030 TypeTableEntry *type_entry = ((TldContainer *)curr_entry->value)->type_entry;17020 TypeTableEntry *type_entry = ((TldContainer *)curr_entry->value)->type_entry;
17031 if ((err = ensure_complete_type(ira->codegen, type_entry)))17021 if ((err = ensure_complete_type(ira->codegen, type_entry)))
17032 return false;17022 return ErrorSemanticAnalyzeFail;
1703317023
17034 // This is a type.17024 // This is a type.
17035 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 0);17025 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 0);
...@@ -17051,7 +17041,7 @@ static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop...@@ -17051,7 +17041,7 @@ static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
17051 }17041 }
1705217042
17053 assert(definition_index == definition_count);17043 assert(definition_index == definition_count);
17054 return true;17044 return ErrorNone;
17055}17045}
1705617046
17057static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry *ptr_type_entry) {17047static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry *ptr_type_entry) {
...@@ -17109,30 +17099,31 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry...@@ -17109,30 +17099,31 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry
17109 return result;17099 return result;
17110};17100};
1711117101
17112static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry) {17102static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, TypeEnumField *enum_field,
17113 Error err;17103 TypeTableEntry *type_info_enum_field_type)
17114 assert(type_entry != nullptr);17104{
17115 assert(!type_is_invalid(type_entry));17105 enum_field_val->special = ConstValSpecialStatic;
17106 enum_field_val->type = type_info_enum_field_type;
1711617107
17117 if ((err = ensure_complete_type(ira->codegen, type_entry)))17108 ConstExprValue *inner_fields = create_const_vals(2);
17118 return nullptr;17109 inner_fields[1].special = ConstValSpecialStatic;
17110 inner_fields[1].type = ira->codegen->builtin_types.entry_usize;
1711917111
17120 const auto make_enum_field_val = [ira](ConstExprValue *enum_field_val, TypeEnumField *enum_field,17112 ConstExprValue *name = create_const_str_lit(ira->codegen, enum_field->name);
17121 TypeTableEntry *type_info_enum_field_type) {17113 init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(enum_field->name), true);
17122 enum_field_val->special = ConstValSpecialStatic;
17123 enum_field_val->type = type_info_enum_field_type;
1712417114
17125 ConstExprValue *inner_fields = create_const_vals(2);17115 bigint_init_bigint(&inner_fields[1].data.x_bigint, &enum_field->value);
17126 inner_fields[1].special = ConstValSpecialStatic;
17127 inner_fields[1].type = ira->codegen->builtin_types.entry_usize;
1712817116
17129 ConstExprValue *name = create_const_str_lit(ira->codegen, enum_field->name);17117 enum_field_val->data.x_struct.fields = inner_fields;
17130 init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(enum_field->name), true);17118}
1713117119
17132 bigint_init_bigint(&inner_fields[1].data.x_bigint, &enum_field->value);17120static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, ConstExprValue **out) {
17121 Error err;
17122 assert(type_entry != nullptr);
17123 assert(!type_is_invalid(type_entry));
1713317124
17134 enum_field_val->data.x_struct.fields = inner_fields;17125 if ((err = ensure_complete_type(ira->codegen, type_entry)))
17135 };17126 return err;
1713617127
17137 if (type_entry == ira->codegen->builtin_types.entry_global_error_set) {17128 if (type_entry == ira->codegen->builtin_types.entry_global_error_set) {
17138 zig_panic("TODO implement @typeInfo for global error set");17129 zig_panic("TODO implement @typeInfo for global error set");
...@@ -17155,13 +17146,16 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -17155,13 +17146,16 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
17155 case TypeTableEntryIdBlock:17146 case TypeTableEntryIdBlock:
17156 case TypeTableEntryIdArgTuple:17147 case TypeTableEntryIdArgTuple:
17157 case TypeTableEntryIdOpaque:17148 case TypeTableEntryIdOpaque:
17158 return nullptr;17149 *out = nullptr;
17150 return ErrorNone;
17159 default:17151 default:
17160 {17152 {
17161 // Lookup an available value in our cache.17153 // Lookup an available value in our cache.
17162 auto entry = ira->codegen->type_info_cache.maybe_get(type_entry);17154 auto entry = ira->codegen->type_info_cache.maybe_get(type_entry);
17163 if (entry != nullptr)17155 if (entry != nullptr) {
17164 return entry->value;17156 *out = entry->value;
17157 return ErrorNone;
17158 }
1716517159
17166 // Fallthrough if we don't find one.17160 // Fallthrough if we don't find one.
17167 }17161 }
...@@ -17312,15 +17306,15 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -17312,15 +17306,15 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
17312 {17306 {
17313 TypeEnumField *enum_field = &type_entry->data.enumeration.fields[enum_field_index];17307 TypeEnumField *enum_field = &type_entry->data.enumeration.fields[enum_field_index];
17314 ConstExprValue *enum_field_val = &enum_field_array->data.x_array.s_none.elements[enum_field_index];17308 ConstExprValue *enum_field_val = &enum_field_array->data.x_array.s_none.elements[enum_field_index];
17315 make_enum_field_val(enum_field_val, enum_field, type_info_enum_field_type);17309 make_enum_field_val(ira, enum_field_val, enum_field, type_info_enum_field_type);
17316 enum_field_val->data.x_struct.parent.id = ConstParentIdArray;17310 enum_field_val->data.x_struct.parent.id = ConstParentIdArray;
17317 enum_field_val->data.x_struct.parent.data.p_array.array_val = enum_field_array;17311 enum_field_val->data.x_struct.parent.data.p_array.array_val = enum_field_array;
17318 enum_field_val->data.x_struct.parent.data.p_array.elem_index = enum_field_index;17312 enum_field_val->data.x_struct.parent.data.p_array.elem_index = enum_field_index;
17319 }17313 }
17320 // defs: []TypeInfo.Definition17314 // defs: []TypeInfo.Definition
17321 ensure_field_index(result->type, "defs", 3);17315 ensure_field_index(result->type, "defs", 3);
17322 if (!ir_make_type_info_defs(ira, &fields[3], type_entry->data.enumeration.decls_scope))17316 if ((err = ir_make_type_info_defs(ira, &fields[3], type_entry->data.enumeration.decls_scope)))
17323 return nullptr;17317 return err;
1732417318
17325 break;17319 break;
17326 }17320 }
...@@ -17346,8 +17340,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -17346,8 +17340,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
17346 error_array->data.x_array.s_none.elements = create_const_vals(error_count);17340 error_array->data.x_array.s_none.elements = create_const_vals(error_count);
1734717341
17348 init_const_slice(ira->codegen, &fields[0], error_array, 0, error_count, false);17342 init_const_slice(ira->codegen, &fields[0], error_array, 0, error_count, false);
17349 for (uint32_t error_index = 0; error_index < error_count; error_index++)17343 for (uint32_t error_index = 0; error_index < error_count; error_index++) {
17350 {
17351 ErrorTableEntry *error = type_entry->data.error_set.errors[error_index];17344 ErrorTableEntry *error = type_entry->data.error_set.errors[error_index];
17352 ConstExprValue *error_val = &error_array->data.x_array.s_none.elements[error_index];17345 ConstExprValue *error_val = &error_array->data.x_array.s_none.elements[error_index];
1735317346
...@@ -17425,9 +17418,9 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -17425,9 +17418,9 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
17425 tag_type->type = ira->codegen->builtin_types.entry_type;17418 tag_type->type = ira->codegen->builtin_types.entry_type;
17426 tag_type->data.x_type = type_entry->data.unionation.tag_type;17419 tag_type->data.x_type = type_entry->data.unionation.tag_type;
17427 fields[1].data.x_optional = tag_type;17420 fields[1].data.x_optional = tag_type;
17428 }17421 } else {
17429 else
17430 fields[1].data.x_optional = nullptr;17422 fields[1].data.x_optional = nullptr;
17423 }
17431 // fields: []TypeInfo.UnionField17424 // fields: []TypeInfo.UnionField
17432 ensure_field_index(result->type, "fields", 2);17425 ensure_field_index(result->type, "fields", 2);
1743317426
...@@ -17460,7 +17453,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -17460,7 +17453,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
17460 inner_fields[1].data.x_optional = nullptr;17453 inner_fields[1].data.x_optional = nullptr;
17461 } else {17454 } else {
17462 inner_fields[1].data.x_optional = create_const_vals(1);17455 inner_fields[1].data.x_optional = create_const_vals(1);
17463 make_enum_field_val(inner_fields[1].data.x_optional, union_field->enum_field, type_info_enum_field_type);17456 make_enum_field_val(ira, inner_fields[1].data.x_optional, union_field->enum_field, type_info_enum_field_type);
17464 }17457 }
1746517458
17466 inner_fields[2].special = ConstValSpecialStatic;17459 inner_fields[2].special = ConstValSpecialStatic;
...@@ -17477,8 +17470,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -17477,8 +17470,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
17477 }17470 }
17478 // defs: []TypeInfo.Definition17471 // defs: []TypeInfo.Definition
17479 ensure_field_index(result->type, "defs", 3);17472 ensure_field_index(result->type, "defs", 3);
17480 if (!ir_make_type_info_defs(ira, &fields[3], type_entry->data.unionation.decls_scope))17473 if ((err = ir_make_type_info_defs(ira, &fields[3], type_entry->data.unionation.decls_scope)))
17481 return nullptr;17474 return err;
1748217475
17483 break;17476 break;
17484 }17477 }
...@@ -17551,8 +17544,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -17551,8 +17544,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
17551 }17544 }
17552 // defs: []TypeInfo.Definition17545 // defs: []TypeInfo.Definition
17553 ensure_field_index(result->type, "defs", 2);17546 ensure_field_index(result->type, "defs", 2);
17554 if (!ir_make_type_info_defs(ira, &fields[2], type_entry->data.structure.decls_scope))17547 if ((err = ir_make_type_info_defs(ira, &fields[2], type_entry->data.structure.decls_scope)))
17555 return nullptr;17548 return err;
1755617549
17557 break;17550 break;
17558 }17551 }
...@@ -17665,7 +17658,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -17665,7 +17658,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
17665 {17658 {
17666 TypeTableEntry *fn_type = type_entry->data.bound_fn.fn_type;17659 TypeTableEntry *fn_type = type_entry->data.bound_fn.fn_type;
17667 assert(fn_type->id == TypeTableEntryIdFn);17660 assert(fn_type->id == TypeTableEntryIdFn);
17668 result = ir_make_type_info_value(ira, fn_type);17661 if ((err = ir_make_type_info_value(ira, fn_type, &result)))
17662 return err;
1766917663
17670 break;17664 break;
17671 }17665 }
...@@ -17673,12 +17667,14 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -17673,12 +17667,14 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
1767317667
17674 assert(result != nullptr);17668 assert(result != nullptr);
17675 ira->codegen->type_info_cache.put(type_entry, result);17669 ira->codegen->type_info_cache.put(type_entry, result);
17676 return result;17670 *out = result;
17671 return ErrorNone;
17677}17672}
1767817673
17679static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,17674static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,
17680 IrInstructionTypeInfo *instruction)17675 IrInstructionTypeInfo *instruction)
17681{17676{
17677 Error err;
17682 IrInstruction *type_value = instruction->type_value->other;17678 IrInstruction *type_value = instruction->type_value->other;
17683 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);17679 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
17684 if (type_is_invalid(type_entry))17680 if (type_is_invalid(type_entry))
...@@ -17686,15 +17682,16 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,...@@ -17686,15 +17682,16 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,
1768617682
17687 TypeTableEntry *result_type = ir_type_info_get_type(ira, nullptr, nullptr);17683 TypeTableEntry *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
1768817684
17685 ConstExprValue *payload;
17686 if ((err = ir_make_type_info_value(ira, type_entry, &payload)))
17687 return ira->codegen->builtin_types.entry_invalid;
17688
17689 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);17689 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
17690 out_val->type = result_type;17690 out_val->type = result_type;
17691 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry));17691 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry));
17692
17693 ConstExprValue *payload = ir_make_type_info_value(ira, type_entry);
17694 out_val->data.x_union.payload = payload;17692 out_val->data.x_union.payload = payload;
1769517693
17696 if (payload != nullptr)17694 if (payload != nullptr) {
17697 {
17698 assert(payload->type->id == TypeTableEntryIdStruct);17695 assert(payload->type->id == TypeTableEntryIdStruct);
17699 payload->data.x_struct.parent.id = ConstParentIdUnion;17696 payload->data.x_struct.parent.id = ConstParentIdUnion;
17700 payload->data.x_struct.parent.data.p_union.union_val = out_val;17697 payload->data.x_struct.parent.data.p_union.union_val = out_val;
test/compile_errors.zig+17
...@@ -1,6 +1,23 @@...@@ -1,6 +1,23 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompileErrorContext) void {3pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "@typeInfo causing depend on itself compile error",
6 \\const start = struct {
7 \\ fn crash() bug() {
8 \\ return bug;
9 \\ }
10 \\};
11 \\fn bug() void {
12 \\ _ = @typeInfo(start).Struct;
13 \\}
14 \\export fn entry() void {
15 \\ var boom = start.crash();
16 \\}
17 ,
18 ".tmp_source.zig:2:5: error: 'crash' depends on itself",
19 );
20
4 cases.add(21 cases.add(
5 "@handle() called outside of function definition",22 "@handle() called outside of function definition",
6 \\var handle_undef: promise = undefined;23 \\var handle_undef: promise = undefined;