@@ -445,8 +445,6 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
445
445
}
446
446
}
447
447
448
- assert(type_is_resolved(child_type, ResolveStatusZeroBitsKnown));
449
-
450
448
ZigType *entry = new_type_table_entry(ZigTypeIdPointer);
451
449
452
450
const char *star_str = ptr_len_to_star_str(ptr_len);
@@ -476,8 +474,6 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons
476
474
buf_ptr(&child_type->name));
477
475
}
478
476
479
- assert(child_type->id != ZigTypeIdInvalid);
480
-
481
477
if (type_has_bits(child_type)) {
482
478
entry->abi_size = g->builtin_types.entry_usize->abi_size;
483
479
entry->size_in_bits = g->builtin_types.entry_usize->size_in_bits;
@@ -689,7 +685,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
689
685
entry->data.structure.fields_by_name.put(ptr_field_name, &entry->data.structure.fields[slice_ptr_index]);
690
686
entry->data.structure.fields_by_name.put(len_field_name, &entry->data.structure.fields[slice_len_index]);
691
687
692
- switch (type_requires_comptime(g, ptr_type)) {
688
+ switch (type_requires_comptime(g, ptr_type, entry )) {
693
689
case ReqCompTimeInvalid:
694
690
zig_unreachable();
695
691
case ReqCompTimeNo:
@@ -945,12 +941,18 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind
945
941
return entry;
946
942
}
947
943
948
- ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry, Buf *type_name) {
944
+ ConstExprValue *analyze_const_value_allow_lazy(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry,
945
+ Buf *type_name, bool allow_lazy)
946
+ {
949
947
size_t backward_branch_count = 0;
950
948
size_t backward_branch_quota = default_backward_branch_quota;
951
949
return ir_eval_const_value(g, scope, node, type_entry,
952
950
&backward_branch_count, &backward_branch_quota,
953
- nullptr, nullptr, node, type_name, nullptr, nullptr);
951
+ nullptr, nullptr, node, type_name, nullptr, nullptr, allow_lazy);
952
+ }
953
+
954
+ ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry, Buf *type_name) {
955
+ return analyze_const_value_allow_lazy(g, scope, node, type_entry, type_name, false);
954
956
}
955
957
956
958
ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
@@ -1355,7 +1357,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
1355
1357
case ZigTypeIdVector:
1356
1358
case ZigTypeIdFnFrame:
1357
1359
case ZigTypeIdAnyFrame:
1358
- switch (type_requires_comptime(g, type_entry)) {
1360
+ switch (type_requires_comptime(g, type_entry, fn_entry->type_entry )) {
1359
1361
case ReqCompTimeNo:
1360
1362
break;
1361
1363
case ReqCompTimeYes:
@@ -1451,7 +1453,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
1451
1453
case ZigTypeIdVector:
1452
1454
case ZigTypeIdFnFrame:
1453
1455
case ZigTypeIdAnyFrame:
1454
- switch (type_requires_comptime(g, fn_type_id.return_type)) {
1456
+ switch (type_requires_comptime(g, fn_type_id.return_type, fn_entry->type_entry )) {
1455
1457
case ReqCompTimeInvalid:
1456
1458
return g->builtin_types.entry_invalid;
1457
1459
case ReqCompTimeYes:
@@ -2164,7 +2166,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
2164
2166
struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2165
2167
return ErrorSemanticAnalyzeFail;
2166
2168
}
2167
- switch (type_requires_comptime(g, field_type)) {
2169
+ switch (type_requires_comptime(g, field_type, struct_type )) {
2168
2170
case ReqCompTimeYes:
2169
2171
struct_type->data.structure.requires_comptime = true;
2170
2172
break;
@@ -2422,7 +2424,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
2422
2424
return ErrorSemanticAnalyzeFail;
2423
2425
}
2424
2426
2425
- switch (type_requires_comptime(g, field_type)) {
2427
+ switch (type_requires_comptime(g, field_type, union_type )) {
2426
2428
case ReqCompTimeInvalid:
2427
2429
union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2428
2430
return ErrorSemanticAnalyzeFail;
@@ -4754,11 +4756,12 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
4754
4756
zig_unreachable();
4755
4757
}
4756
4758
4757
- ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry ) {
4759
+ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty, ZigType *parent_type ) {
4758
4760
Error err;
4759
- if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown)))
4760
- return ReqCompTimeInvalid;
4761
- switch (type_entry->id) {
4761
+ if (ty == parent_type) {
4762
+ return ReqCompTimeNo;
4763
+ }
4764
+ switch (ty->id) {
4762
4765
case ZigTypeIdInvalid:
4763
4766
case ZigTypeIdOpaque:
4764
4767
zig_unreachable();
@@ -4772,23 +4775,27 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry) {
4772
4775
case ZigTypeIdArgTuple:
4773
4776
return ReqCompTimeYes;
4774
4777
case ZigTypeIdArray:
4775
- return type_requires_comptime(g, type_entry ->data.array.child_type);
4778
+ return type_requires_comptime(g, ty ->data.array.child_type, parent_type );
4776
4779
case ZigTypeIdStruct:
4777
- return type_entry->data.structure.requires_comptime ? ReqCompTimeYes : ReqCompTimeNo;
4780
+ if ((err = type_resolve(g, ty, ResolveStatusZeroBitsKnown)))
4781
+ return ReqCompTimeInvalid;
4782
+ return ty->data.structure.requires_comptime ? ReqCompTimeYes : ReqCompTimeNo;
4778
4783
case ZigTypeIdUnion:
4779
- return type_entry->data.unionation.requires_comptime ? ReqCompTimeYes : ReqCompTimeNo;
4784
+ if ((err = type_resolve(g, ty, ResolveStatusZeroBitsKnown)))
4785
+ return ReqCompTimeInvalid;
4786
+ return ty->data.unionation.requires_comptime ? ReqCompTimeYes : ReqCompTimeNo;
4780
4787
case ZigTypeIdOptional:
4781
- return type_requires_comptime(g, type_entry ->data.maybe.child_type);
4788
+ return type_requires_comptime(g, ty ->data.maybe.child_type, parent_type );
4782
4789
case ZigTypeIdErrorUnion:
4783
- return type_requires_comptime(g, type_entry ->data.error_union.payload_type);
4790
+ return type_requires_comptime(g, ty ->data.error_union.payload_type, parent_type );
4784
4791
case ZigTypeIdPointer:
4785
- if (type_entry ->data.pointer.child_type->id == ZigTypeIdOpaque) {
4792
+ if (ty ->data.pointer.child_type->id == ZigTypeIdOpaque) {
4786
4793
return ReqCompTimeNo;
4787
4794
} else {
4788
- return type_requires_comptime(g, type_entry ->data.pointer.child_type);
4795
+ return type_requires_comptime(g, ty ->data.pointer.child_type, parent_type );
4789
4796
}
4790
4797
case ZigTypeIdFn:
4791
- return type_entry ->data.fn.is_generic ? ReqCompTimeYes : ReqCompTimeNo;
4798
+ return ty ->data.fn.is_generic ? ReqCompTimeYes : ReqCompTimeNo;
4792
4799
case ZigTypeIdEnum:
4793
4800
case ZigTypeIdErrorSet:
4794
4801
case ZigTypeIdBool:
@@ -5726,6 +5733,9 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5726
5733
case ConstValSpecialRuntime:
5727
5734
buf_appendf(buf, "(runtime value)");
5728
5735
return;
5736
+ case ConstValSpecialLazy:
5737
+ buf_appendf(buf, "(lazy value)");
5738
+ return;
5729
5739
case ConstValSpecialUndef:
5730
5740
buf_appendf(buf, "undefined");
5731
5741
return;
0 commit comments