@@ -21192,6 +21192,13 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
21192
21192
return ira->codegen->invalid_inst_gen;
21193
21193
if (type_is_invalid(struct_val->type))
21194
21194
return ira->codegen->invalid_inst_gen;
21195
+
21196
+ // This to allow lazy values to be resolved.
21197
+ if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
21198
+ source_instr->source_node, struct_val, UndefOk)))
21199
+ {
21200
+ return ira->codegen->invalid_inst_gen;
21201
+ }
21195
21202
if (initializing && struct_val->special == ConstValSpecialUndef) {
21196
21203
struct_val->data.x_struct.fields = alloc_const_vals_ptrs(ira->codegen, struct_type->data.structure.src_field_count);
21197
21204
struct_val->special = ConstValSpecialStatic;
@@ -23597,7 +23604,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
23597
23604
}
23598
23605
23599
23606
static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigValue *out_val,
23600
- ScopeDecls *decls_scope)
23607
+ ScopeDecls *decls_scope, bool resolve_types )
23601
23608
{
23602
23609
Error err;
23603
23610
ZigType *type_info_declaration_type = ir_type_info_get_type(ira, "Declaration", nullptr);
@@ -23608,6 +23615,24 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
23608
23615
ensure_field_index(type_info_declaration_type, "is_pub", 1);
23609
23616
ensure_field_index(type_info_declaration_type, "data", 2);
23610
23617
23618
+ if (!resolve_types) {
23619
+ ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, type_info_declaration_type,
23620
+ false, false, PtrLenUnknown, 0, 0, 0, false);
23621
+
23622
+ out_val->special = ConstValSpecialLazy;
23623
+ out_val->type = get_slice_type(ira->codegen, ptr_type);
23624
+
23625
+ LazyValueTypeInfoDecls *lazy_type_info_decls = heap::c_allocator.create<LazyValueTypeInfoDecls>();
23626
+ lazy_type_info_decls->ira = ira; ira_ref(ira);
23627
+ out_val->data.x_lazy = &lazy_type_info_decls->base;
23628
+ lazy_type_info_decls->base.id = LazyValueIdTypeInfoDecls;
23629
+
23630
+ lazy_type_info_decls->source_instr = source_instr;
23631
+ lazy_type_info_decls->decls_scope = decls_scope;
23632
+
23633
+ return ErrorNone;
23634
+ }
23635
+
23611
23636
ZigType *type_info_declaration_data_type = ir_type_info_get_type(ira, "Data", type_info_declaration_type);
23612
23637
if ((err = type_resolve(ira->codegen, type_info_declaration_data_type, ResolveStatusSizeKnown)))
23613
23638
return err;
@@ -24160,7 +24185,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24160
24185
// decls: []TypeInfo.Declaration
24161
24186
ensure_field_index(result->type, "decls", 3);
24162
24187
if ((err = ir_make_type_info_decls(ira, source_instr, fields[3],
24163
- type_entry->data.enumeration.decls_scope)))
24188
+ type_entry->data.enumeration.decls_scope, false )))
24164
24189
{
24165
24190
return err;
24166
24191
}
@@ -24332,7 +24357,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24332
24357
// decls: []TypeInfo.Declaration
24333
24358
ensure_field_index(result->type, "decls", 3);
24334
24359
if ((err = ir_make_type_info_decls(ira, source_instr, fields[3],
24335
- type_entry->data.unionation.decls_scope)))
24360
+ type_entry->data.unionation.decls_scope, false )))
24336
24361
{
24337
24362
return err;
24338
24363
}
@@ -24424,7 +24449,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24424
24449
// decls: []TypeInfo.Declaration
24425
24450
ensure_field_index(result->type, "decls", 2);
24426
24451
if ((err = ir_make_type_info_decls(ira, source_instr, fields[2],
24427
- type_entry->data.structure.decls_scope)))
24452
+ type_entry->data.structure.decls_scope, false )))
24428
24453
{
24429
24454
return err;
24430
24455
}
@@ -30361,6 +30386,18 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
30361
30386
switch (val->data.x_lazy->id) {
30362
30387
case LazyValueIdInvalid:
30363
30388
zig_unreachable();
30389
+ case LazyValueIdTypeInfoDecls: {
30390
+ LazyValueTypeInfoDecls *type_info_decls = reinterpret_cast<LazyValueTypeInfoDecls *>(val->data.x_lazy);
30391
+ IrAnalyze *ira = type_info_decls->ira;
30392
+
30393
+ if ((err = ir_make_type_info_decls(ira, type_info_decls->source_instr, val, type_info_decls->decls_scope, true)))
30394
+ {
30395
+ return err;
30396
+ };
30397
+
30398
+ // We can't free the lazy value here, because multiple other ZigValues might be pointing to it.
30399
+ return ErrorNone;
30400
+ }
30364
30401
case LazyValueIdAlignOf: {
30365
30402
LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(val->data.x_lazy);
30366
30403
IrAnalyze *ira = lazy_align_of->ira;
0 commit comments