@@ -21221,6 +21221,13 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
21221
21221
return ira->codegen->invalid_inst_gen;
21222
21222
if (type_is_invalid(struct_val->type))
21223
21223
return ira->codegen->invalid_inst_gen;
21224
+
21225
+ // This to allow lazy values to be resolved.
21226
+ if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
21227
+ source_instr->source_node, struct_val, UndefOk)))
21228
+ {
21229
+ return ira->codegen->invalid_inst_gen;
21230
+ }
21224
21231
if (initializing && struct_val->special == ConstValSpecialUndef) {
21225
21232
struct_val->data.x_struct.fields = alloc_const_vals_ptrs(ira->codegen, struct_type->data.structure.src_field_count);
21226
21233
struct_val->special = ConstValSpecialStatic;
@@ -23626,7 +23633,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
23626
23633
}
23627
23634
23628
23635
static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigValue *out_val,
23629
- ScopeDecls *decls_scope)
23636
+ ScopeDecls *decls_scope, bool resolve_types )
23630
23637
{
23631
23638
Error err;
23632
23639
ZigType *type_info_declaration_type = ir_type_info_get_type(ira, "Declaration", nullptr);
@@ -23637,6 +23644,24 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
23637
23644
ensure_field_index(type_info_declaration_type, "is_pub", 1);
23638
23645
ensure_field_index(type_info_declaration_type, "data", 2);
23639
23646
23647
+ if (!resolve_types) {
23648
+ ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, type_info_declaration_type,
23649
+ false, false, PtrLenUnknown, 0, 0, 0, false);
23650
+
23651
+ out_val->special = ConstValSpecialLazy;
23652
+ out_val->type = get_slice_type(ira->codegen, ptr_type);
23653
+
23654
+ LazyValueTypeInfoDecls *lazy_type_info_decls = heap::c_allocator.create<LazyValueTypeInfoDecls>();
23655
+ lazy_type_info_decls->ira = ira; ira_ref(ira);
23656
+ out_val->data.x_lazy = &lazy_type_info_decls->base;
23657
+ lazy_type_info_decls->base.id = LazyValueIdTypeInfoDecls;
23658
+
23659
+ lazy_type_info_decls->source_instr = source_instr;
23660
+ lazy_type_info_decls->decls_scope = decls_scope;
23661
+
23662
+ return ErrorNone;
23663
+ }
23664
+
23640
23665
ZigType *type_info_declaration_data_type = ir_type_info_get_type(ira, "Data", type_info_declaration_type);
23641
23666
if ((err = type_resolve(ira->codegen, type_info_declaration_data_type, ResolveStatusSizeKnown)))
23642
23667
return err;
@@ -24189,7 +24214,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24189
24214
// decls: []TypeInfo.Declaration
24190
24215
ensure_field_index(result->type, "decls", 3);
24191
24216
if ((err = ir_make_type_info_decls(ira, source_instr, fields[3],
24192
- type_entry->data.enumeration.decls_scope)))
24217
+ type_entry->data.enumeration.decls_scope, false )))
24193
24218
{
24194
24219
return err;
24195
24220
}
@@ -24361,7 +24386,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24361
24386
// decls: []TypeInfo.Declaration
24362
24387
ensure_field_index(result->type, "decls", 3);
24363
24388
if ((err = ir_make_type_info_decls(ira, source_instr, fields[3],
24364
- type_entry->data.unionation.decls_scope)))
24389
+ type_entry->data.unionation.decls_scope, false )))
24365
24390
{
24366
24391
return err;
24367
24392
}
@@ -24453,7 +24478,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24453
24478
// decls: []TypeInfo.Declaration
24454
24479
ensure_field_index(result->type, "decls", 2);
24455
24480
if ((err = ir_make_type_info_decls(ira, source_instr, fields[2],
24456
- type_entry->data.structure.decls_scope)))
24481
+ type_entry->data.structure.decls_scope, false )))
24457
24482
{
24458
24483
return err;
24459
24484
}
@@ -30391,6 +30416,18 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
30391
30416
switch (val->data.x_lazy->id) {
30392
30417
case LazyValueIdInvalid:
30393
30418
zig_unreachable();
30419
+ case LazyValueIdTypeInfoDecls: {
30420
+ LazyValueTypeInfoDecls *type_info_decls = reinterpret_cast<LazyValueTypeInfoDecls *>(val->data.x_lazy);
30421
+ IrAnalyze *ira = type_info_decls->ira;
30422
+
30423
+ if ((err = ir_make_type_info_decls(ira, type_info_decls->source_instr, val, type_info_decls->decls_scope, true)))
30424
+ {
30425
+ return err;
30426
+ };
30427
+
30428
+ // We can't free the lazy value here, because multiple other ZigValues might be pointing to it.
30429
+ return ErrorNone;
30430
+ }
30394
30431
case LazyValueIdAlignOf: {
30395
30432
LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(val->data.x_lazy);
30396
30433
IrAnalyze *ira = lazy_align_of->ira;
0 commit comments