authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-23 15:54:51-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-23 15:54:51-04:00
logac4dd9d665ba195a6b21b3b033f27c865015ccac
treed3ae7db58ea39d073eda0fe70a9058f66cdebce3
parentbe0a9a72772566667d4c225972c6bc7c17b751ef
signature Commit is signed but in an unrecognized format.

better handling of lazy structs

this case works now: ```zig const A = struct { b_list_pointer: *const []B, }; const B = struct { a_pointer: *const A, }; const b_list: []B = [_]B{}; const a = A{ .b_list_pointer = &b_list }; const obj = B{ .a_pointer = &a }; ```

5 files changed, 44 insertions(+), 42 deletions(-)

src/all_types.hpp+2-1
...@@ -1190,7 +1190,8 @@ struct ZigTypeStruct {...@@ -1190,7 +1190,8 @@ struct ZigTypeStruct {
1190 // whether any of the fields require comptime1190 // whether any of the fields require comptime
1191 // known after ResolveStatusZeroBitsKnown1191 // known after ResolveStatusZeroBitsKnown
1192 bool requires_comptime;1192 bool requires_comptime;
1193 bool resolve_loop_flag;1193 bool resolve_loop_flag_zero_bits;
1194 bool resolve_loop_flag_other;
1194};1195};
11951196
1196struct ZigTypeOptional {1197struct ZigTypeOptional {
src/analyze.cpp+29-28
...@@ -685,7 +685,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {...@@ -685,7 +685,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
685 entry->data.structure.fields_by_name.put(ptr_field_name, &entry->data.structure.fields[slice_ptr_index]);685 entry->data.structure.fields_by_name.put(ptr_field_name, &entry->data.structure.fields[slice_ptr_index]);
686 entry->data.structure.fields_by_name.put(len_field_name, &entry->data.structure.fields[slice_len_index]);686 entry->data.structure.fields_by_name.put(len_field_name, &entry->data.structure.fields[slice_len_index]);
687687
688 switch (type_requires_comptime(g, ptr_type, entry)) {688 switch (type_requires_comptime(g, ptr_type)) {
689 case ReqCompTimeInvalid:689 case ReqCompTimeInvalid:
690 zig_unreachable();690 zig_unreachable();
691 case ReqCompTimeNo:691 case ReqCompTimeNo:
...@@ -1016,9 +1016,9 @@ Error type_val_resolve_is_opaque_type(CodeGen *g, ConstExprValue *type_val, bool...@@ -1016,9 +1016,9 @@ Error type_val_resolve_is_opaque_type(CodeGen *g, ConstExprValue *type_val, bool
1016 zig_unreachable();1016 zig_unreachable();
1017}1017}
10181018
1019static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue *type_val, ZigType *parent_type) {1019static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue *type_val) {
1020 if (type_val->special != ConstValSpecialLazy) {1020 if (type_val->special != ConstValSpecialLazy) {
1021 return type_requires_comptime(g, type_val->data.x_type, parent_type);1021 return type_requires_comptime(g, type_val->data.x_type);
1022 }1022 }
1023 switch (type_val->data.x_lazy->id) {1023 switch (type_val->data.x_lazy->id) {
1024 case LazyValueIdInvalid:1024 case LazyValueIdInvalid:
...@@ -1028,17 +1028,17 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue...@@ -1028,17 +1028,17 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue
1028 LazyValueSliceType *lazy_slice_type = reinterpret_cast<LazyValueSliceType *>(type_val->data.x_lazy);1028 LazyValueSliceType *lazy_slice_type = reinterpret_cast<LazyValueSliceType *>(type_val->data.x_lazy);
1029 if (type_is_invalid(lazy_slice_type->elem_type))1029 if (type_is_invalid(lazy_slice_type->elem_type))
1030 return ReqCompTimeInvalid;1030 return ReqCompTimeInvalid;
1031 return type_requires_comptime(g, lazy_slice_type->elem_type, parent_type);1031 return type_requires_comptime(g, lazy_slice_type->elem_type);
1032 }1032 }
1033 case LazyValueIdPtrType: {1033 case LazyValueIdPtrType: {
1034 LazyValuePtrType *lazy_ptr_type = reinterpret_cast<LazyValuePtrType *>(type_val->data.x_lazy);1034 LazyValuePtrType *lazy_ptr_type = reinterpret_cast<LazyValuePtrType *>(type_val->data.x_lazy);
1035 return type_val_resolve_requires_comptime(g, lazy_ptr_type->elem_type_val, parent_type);1035 return type_val_resolve_requires_comptime(g, lazy_ptr_type->elem_type_val);
1036 }1036 }
1037 case LazyValueIdFnType: {1037 case LazyValueIdFnType: {
1038 LazyValueFnType *lazy_fn_type = reinterpret_cast<LazyValueFnType *>(type_val->data.x_lazy);1038 LazyValueFnType *lazy_fn_type = reinterpret_cast<LazyValueFnType *>(type_val->data.x_lazy);
1039 if (lazy_fn_type->is_generic)1039 if (lazy_fn_type->is_generic)
1040 return ReqCompTimeYes;1040 return ReqCompTimeYes;
1041 switch (type_val_resolve_requires_comptime(g, lazy_fn_type->return_type, parent_type)) {1041 switch (type_val_resolve_requires_comptime(g, lazy_fn_type->return_type)) {
1042 case ReqCompTimeInvalid:1042 case ReqCompTimeInvalid:
1043 return ReqCompTimeInvalid;1043 return ReqCompTimeInvalid;
1044 case ReqCompTimeYes:1044 case ReqCompTimeYes:
...@@ -1051,7 +1051,7 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue...@@ -1051,7 +1051,7 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue
1051 AstNode *param_node = lazy_fn_type->proto_node->data.fn_proto.params.at(i);1051 AstNode *param_node = lazy_fn_type->proto_node->data.fn_proto.params.at(i);
1052 bool param_is_var_args = param_node->data.param_decl.is_var_args;1052 bool param_is_var_args = param_node->data.param_decl.is_var_args;
1053 if (param_is_var_args) break;1053 if (param_is_var_args) break;
1054 switch (type_val_resolve_requires_comptime(g, lazy_fn_type->param_types[i], parent_type)) {1054 switch (type_val_resolve_requires_comptime(g, lazy_fn_type->param_types[i])) {
1055 case ReqCompTimeInvalid:1055 case ReqCompTimeInvalid:
1056 return ReqCompTimeInvalid;1056 return ReqCompTimeInvalid;
1057 case ReqCompTimeYes:1057 case ReqCompTimeYes:
...@@ -1517,7 +1517,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -1517,7 +1517,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
1517 case ZigTypeIdVector:1517 case ZigTypeIdVector:
1518 case ZigTypeIdFnFrame:1518 case ZigTypeIdFnFrame:
1519 case ZigTypeIdAnyFrame:1519 case ZigTypeIdAnyFrame:
1520 switch (type_requires_comptime(g, type_entry, fn_entry->type_entry)) {1520 switch (type_requires_comptime(g, type_entry)) {
1521 case ReqCompTimeNo:1521 case ReqCompTimeNo:
1522 break;1522 break;
1523 case ReqCompTimeYes:1523 case ReqCompTimeYes:
...@@ -1613,7 +1613,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -1613,7 +1613,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
1613 case ZigTypeIdVector:1613 case ZigTypeIdVector:
1614 case ZigTypeIdFnFrame:1614 case ZigTypeIdFnFrame:
1615 case ZigTypeIdAnyFrame:1615 case ZigTypeIdAnyFrame:
1616 switch (type_requires_comptime(g, fn_type_id.return_type, fn_entry->type_entry)) {1616 switch (type_requires_comptime(g, fn_type_id.return_type)) {
1617 case ReqCompTimeInvalid:1617 case ReqCompTimeInvalid:
1618 return g->builtin_types.entry_invalid;1618 return g->builtin_types.entry_invalid;
1619 case ReqCompTimeYes:1619 case ReqCompTimeYes:
...@@ -1745,7 +1745,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {...@@ -1745,7 +1745,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
17451745
1746 AstNode *decl_node = struct_type->data.structure.decl_node;1746 AstNode *decl_node = struct_type->data.structure.decl_node;
17471747
1748 if (struct_type->data.structure.resolve_loop_flag) {1748 if (struct_type->data.structure.resolve_loop_flag_other) {
1749 if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) {1749 if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) {
1750 struct_type->data.structure.resolve_status = ResolveStatusInvalid;1750 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
1751 g->trace_err = add_node_error(g, decl_node,1751 g->trace_err = add_node_error(g, decl_node,
...@@ -1760,7 +1760,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {...@@ -1760,7 +1760,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
1760 size_t field_count = struct_type->data.structure.src_field_count;1760 size_t field_count = struct_type->data.structure.src_field_count;
17611761
1762 bool packed = (struct_type->data.structure.layout == ContainerLayoutPacked);1762 bool packed = (struct_type->data.structure.layout == ContainerLayoutPacked);
1763 struct_type->data.structure.resolve_loop_flag = true;1763 struct_type->data.structure.resolve_loop_flag_other = true;
17641764
1765 uint32_t *host_int_bytes = packed ? allocate<uint32_t>(struct_type->data.structure.gen_field_count) : nullptr;1765 uint32_t *host_int_bytes = packed ? allocate<uint32_t>(struct_type->data.structure.gen_field_count) : nullptr;
17661766
...@@ -1877,7 +1877,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {...@@ -1877,7 +1877,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
1877 struct_type->size_in_bits = size_in_bits;1877 struct_type->size_in_bits = size_in_bits;
1878 struct_type->data.structure.resolve_status = ResolveStatusSizeKnown;1878 struct_type->data.structure.resolve_status = ResolveStatusSizeKnown;
1879 struct_type->data.structure.gen_field_count = (uint32_t)gen_field_index;1879 struct_type->data.structure.gen_field_count = (uint32_t)gen_field_index;
1880 struct_type->data.structure.resolve_loop_flag = false;1880 struct_type->data.structure.resolve_loop_flag_other = false;
1881 struct_type->data.structure.host_int_bytes = host_int_bytes;1881 struct_type->data.structure.host_int_bytes = host_int_bytes;
18821882
1883 return ErrorNone;1883 return ErrorNone;
...@@ -2275,7 +2275,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {...@@ -2275,7 +2275,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
2275 AstNode *decl_node = struct_type->data.structure.decl_node;2275 AstNode *decl_node = struct_type->data.structure.decl_node;
2276 assert(decl_node->type == NodeTypeContainerDecl);2276 assert(decl_node->type == NodeTypeContainerDecl);
22772277
2278 if (struct_type->data.structure.resolve_loop_flag) {2278 if (struct_type->data.structure.resolve_loop_flag_zero_bits) {
2279 if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) {2279 if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) {
2280 struct_type->data.structure.resolve_status = ResolveStatusInvalid;2280 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2281 g->trace_err = add_node_error(g, decl_node,2281 g->trace_err = add_node_error(g, decl_node,
...@@ -2285,7 +2285,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {...@@ -2285,7 +2285,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
2285 return ErrorSemanticAnalyzeFail;2285 return ErrorSemanticAnalyzeFail;
2286 }2286 }
22872287
2288 struct_type->data.structure.resolve_loop_flag = true;2288 struct_type->data.structure.resolve_loop_flag_zero_bits = true;
22892289
2290 assert(!struct_type->data.structure.fields);2290 assert(!struct_type->data.structure.fields);
2291 size_t field_count = decl_node->data.container_decl.fields.length;2291 size_t field_count = decl_node->data.container_decl.fields.length;
...@@ -2343,7 +2343,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {...@@ -2343,7 +2343,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
2343 type_struct_field->src_index = i;2343 type_struct_field->src_index = i;
2344 type_struct_field->gen_index = SIZE_MAX;2344 type_struct_field->gen_index = SIZE_MAX;
23452345
2346 switch (type_val_resolve_requires_comptime(g, field_type_val, struct_type)) {2346 switch (type_val_resolve_requires_comptime(g, field_type_val)) {
2347 case ReqCompTimeYes:2347 case ReqCompTimeYes:
2348 struct_type->data.structure.requires_comptime = true;2348 struct_type->data.structure.requires_comptime = true;
2349 break;2349 break;
...@@ -2370,7 +2370,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {...@@ -2370,7 +2370,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
2370 gen_field_index += 1;2370 gen_field_index += 1;
2371 }2371 }
23722372
2373 struct_type->data.structure.resolve_loop_flag = false;2373 struct_type->data.structure.resolve_loop_flag_zero_bits = false;
2374 struct_type->data.structure.gen_field_count = (uint32_t)gen_field_index;2374 struct_type->data.structure.gen_field_count = (uint32_t)gen_field_index;
2375 if (gen_field_index != 0) {2375 if (gen_field_index != 0) {
2376 struct_type->abi_size = SIZE_MAX;2376 struct_type->abi_size = SIZE_MAX;
...@@ -2400,7 +2400,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {...@@ -2400,7 +2400,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {
24002400
2401 AstNode *decl_node = struct_type->data.structure.decl_node;2401 AstNode *decl_node = struct_type->data.structure.decl_node;
24022402
2403 if (struct_type->data.structure.resolve_loop_flag) {2403 if (struct_type->data.structure.resolve_loop_flag_other) {
2404 if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) {2404 if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) {
2405 struct_type->data.structure.resolve_status = ResolveStatusInvalid;2405 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2406 g->trace_err = add_node_error(g, decl_node,2406 g->trace_err = add_node_error(g, decl_node,
...@@ -2409,7 +2409,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {...@@ -2409,7 +2409,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {
2409 return ErrorSemanticAnalyzeFail;2409 return ErrorSemanticAnalyzeFail;
2410 }2410 }
24112411
2412 struct_type->data.structure.resolve_loop_flag = true;2412 struct_type->data.structure.resolve_loop_flag_other = true;
2413 assert(decl_node->type == NodeTypeContainerDecl);2413 assert(decl_node->type == NodeTypeContainerDecl);
24142414
2415 size_t field_count = struct_type->data.structure.src_field_count;2415 size_t field_count = struct_type->data.structure.src_field_count;
...@@ -2444,7 +2444,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {...@@ -2444,7 +2444,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {
2444 }2444 }
2445 }2445 }
24462446
2447 struct_type->data.structure.resolve_loop_flag = false;2447 struct_type->data.structure.resolve_loop_flag_other = false;
24482448
2449 if (struct_type->data.structure.resolve_status == ResolveStatusInvalid) {2449 if (struct_type->data.structure.resolve_status == ResolveStatusInvalid) {
2450 return ErrorSemanticAnalyzeFail;2450 return ErrorSemanticAnalyzeFail;
...@@ -2614,7 +2614,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -2614,7 +2614,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
2614 return ErrorSemanticAnalyzeFail;2614 return ErrorSemanticAnalyzeFail;
2615 }2615 }
26162616
2617 switch (type_requires_comptime(g, field_type, union_type)) {2617 switch (type_requires_comptime(g, field_type)) {
2618 case ReqCompTimeInvalid:2618 case ReqCompTimeInvalid:
2619 union_type->data.unionation.resolve_status = ResolveStatusInvalid;2619 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2620 return ErrorSemanticAnalyzeFail;2620 return ErrorSemanticAnalyzeFail;
...@@ -4959,11 +4959,8 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {...@@ -4959,11 +4959,8 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
4959 zig_unreachable();4959 zig_unreachable();
4960}4960}
49614961
4962ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty, ZigType *parent_type) {4962ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty) {
4963 Error err;4963 Error err;
4964 if (ty == parent_type) {
4965 return ReqCompTimeNo;
4966 }
4967 switch (ty->id) {4964 switch (ty->id) {
4968 case ZigTypeIdInvalid:4965 case ZigTypeIdInvalid:
4969 zig_unreachable();4966 zig_unreachable();
...@@ -4977,8 +4974,12 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty, ZigType *parent_type...@@ -4977,8 +4974,12 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty, ZigType *parent_type
4977 case ZigTypeIdArgTuple:4974 case ZigTypeIdArgTuple:
4978 return ReqCompTimeYes;4975 return ReqCompTimeYes;
4979 case ZigTypeIdArray:4976 case ZigTypeIdArray:
4980 return type_requires_comptime(g, ty->data.array.child_type, parent_type);4977 return type_requires_comptime(g, ty->data.array.child_type);
4981 case ZigTypeIdStruct:4978 case ZigTypeIdStruct:
4979 if (ty->data.structure.resolve_loop_flag_zero_bits) {
4980 // Does a struct which contains a pointer field to itself require comptime? No.
4981 return ReqCompTimeNo;
4982 }
4982 if ((err = type_resolve(g, ty, ResolveStatusZeroBitsKnown)))4983 if ((err = type_resolve(g, ty, ResolveStatusZeroBitsKnown)))
4983 return ReqCompTimeInvalid;4984 return ReqCompTimeInvalid;
4984 return ty->data.structure.requires_comptime ? ReqCompTimeYes : ReqCompTimeNo;4985 return ty->data.structure.requires_comptime ? ReqCompTimeYes : ReqCompTimeNo;
...@@ -4987,14 +4988,14 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty, ZigType *parent_type...@@ -4987,14 +4988,14 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty, ZigType *parent_type
4987 return ReqCompTimeInvalid;4988 return ReqCompTimeInvalid;
4988 return ty->data.unionation.requires_comptime ? ReqCompTimeYes : ReqCompTimeNo;4989 return ty->data.unionation.requires_comptime ? ReqCompTimeYes : ReqCompTimeNo;
4989 case ZigTypeIdOptional:4990 case ZigTypeIdOptional:
4990 return type_requires_comptime(g, ty->data.maybe.child_type, parent_type);4991 return type_requires_comptime(g, ty->data.maybe.child_type);
4991 case ZigTypeIdErrorUnion:4992 case ZigTypeIdErrorUnion:
4992 return type_requires_comptime(g, ty->data.error_union.payload_type, parent_type);4993 return type_requires_comptime(g, ty->data.error_union.payload_type);
4993 case ZigTypeIdPointer:4994 case ZigTypeIdPointer:
4994 if (ty->data.pointer.child_type->id == ZigTypeIdOpaque) {4995 if (ty->data.pointer.child_type->id == ZigTypeIdOpaque) {
4995 return ReqCompTimeNo;4996 return ReqCompTimeNo;
4996 } else {4997 } else {
4997 return type_requires_comptime(g, ty->data.pointer.child_type, parent_type);4998 return type_requires_comptime(g, ty->data.pointer.child_type);
4998 }4999 }
4999 case ZigTypeIdFn:5000 case ZigTypeIdFn:
5000 return ty->data.fn.is_generic ? ReqCompTimeYes : ReqCompTimeNo;5001 return ty->data.fn.is_generic ? ReqCompTimeYes : ReqCompTimeNo;
src/analyze.hpp+1-1
...@@ -221,7 +221,7 @@ enum ReqCompTime {...@@ -221,7 +221,7 @@ enum ReqCompTime {
221 ReqCompTimeNo,221 ReqCompTimeNo,
222 ReqCompTimeYes,222 ReqCompTimeYes,
223};223};
224ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry, ZigType *parent_type);224ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry);
225225
226OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry);226OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry);
227227
src/codegen.cpp+2-2
...@@ -3688,7 +3688,7 @@ static void render_async_spills(CodeGen *g) {...@@ -3688,7 +3688,7 @@ static void render_async_spills(CodeGen *g) {
3688 }3688 }
3689 if (ir_get_var_is_comptime(var))3689 if (ir_get_var_is_comptime(var))
3690 continue;3690 continue;
3691 switch (type_requires_comptime(g, var->var_type, nullptr)) {3691 switch (type_requires_comptime(g, var->var_type)) {
3692 case ReqCompTimeInvalid:3692 case ReqCompTimeInvalid:
3693 zig_unreachable();3693 zig_unreachable();
3694 case ReqCompTimeYes:3694 case ReqCompTimeYes:
...@@ -7049,7 +7049,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7049,7 +7049,7 @@ static void do_code_gen(CodeGen *g) {
7049 }7049 }
7050 if (ir_get_var_is_comptime(var))7050 if (ir_get_var_is_comptime(var))
7051 continue;7051 continue;
7052 switch (type_requires_comptime(g, var->var_type, nullptr)) {7052 switch (type_requires_comptime(g, var->var_type)) {
7053 case ReqCompTimeInvalid:7053 case ReqCompTimeInvalid:
7054 zig_unreachable();7054 zig_unreachable();
7055 case ReqCompTimeYes:7055 case ReqCompTimeYes:
src/ir.cpp+10-10
...@@ -14234,7 +14234,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -14234,7 +14234,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
14234 }14234 }
14235 }14235 }
1423614236
14237 switch (type_requires_comptime(ira->codegen, result_type, nullptr)) {14237 switch (type_requires_comptime(ira->codegen, result_type)) {
14238 case ReqCompTimeInvalid:14238 case ReqCompTimeInvalid:
14239 result_type = ira->codegen->builtin_types.entry_invalid;14239 result_type = ira->codegen->builtin_types.entry_invalid;
14240 break;14240 break;
...@@ -15200,7 +15200,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -15200,7 +15200,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
15200 }15200 }
1520115201
15202 if (!comptime_arg) {15202 if (!comptime_arg) {
15203 switch (type_requires_comptime(ira->codegen, casted_arg->value.type, nullptr)) {15203 switch (type_requires_comptime(ira->codegen, casted_arg->value.type)) {
15204 case ReqCompTimeYes:15204 case ReqCompTimeYes:
15205 ir_add_error(ira, casted_arg,15205 ir_add_error(ira, casted_arg,
15206 buf_sprintf("parameter of type '%s' requires comptime", buf_ptr(&casted_arg->value.type->name)));15206 buf_sprintf("parameter of type '%s' requires comptime", buf_ptr(&casted_arg->value.type->name)));
...@@ -15401,7 +15401,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -15401,7 +15401,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
15401 }15401 }
15402 }15402 }
1540315403
15404 switch (type_requires_comptime(ira->codegen, child_type, nullptr)) {15404 switch (type_requires_comptime(ira->codegen, child_type)) {
15405 case ReqCompTimeInvalid:15405 case ReqCompTimeInvalid:
15406 return ira->codegen->invalid_instruction;15406 return ira->codegen->invalid_instruction;
15407 case ReqCompTimeYes:15407 case ReqCompTimeYes:
...@@ -15794,7 +15794,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -15794,7 +15794,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
15794 inst_fn_type_id.return_type = specified_return_type;15794 inst_fn_type_id.return_type = specified_return_type;
15795 }15795 }
1579615796
15797 switch (type_requires_comptime(ira->codegen, specified_return_type, nullptr)) {15797 switch (type_requires_comptime(ira->codegen, specified_return_type)) {
15798 case ReqCompTimeYes:15798 case ReqCompTimeYes:
15799 // Throw out our work and call the function as if it were comptime.15799 // Throw out our work and call the function as if it were comptime.
15800 return ir_analyze_fn_call(ira, call_instruction, fn_entry, fn_type, fn_ref, first_arg_ptr,15800 return ir_analyze_fn_call(ira, call_instruction, fn_entry, fn_type, fn_ref, first_arg_ptr,
...@@ -16601,7 +16601,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -16601,7 +16601,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
16601 break;16601 break;
16602 }16602 }
1660316603
16604 switch (type_requires_comptime(ira->codegen, resolved_type, nullptr)) {16604 switch (type_requires_comptime(ira->codegen, resolved_type)) {
16605 case ReqCompTimeInvalid:16605 case ReqCompTimeInvalid:
16606 return ira->codegen->invalid_instruction;16606 return ira->codegen->invalid_instruction;
16607 case ReqCompTimeYes:16607 case ReqCompTimeYes:
...@@ -17049,7 +17049,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -17049,7 +17049,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
17049 }17049 }
17050 } else {17050 } else {
17051 // runtime known element index17051 // runtime known element index
17052 switch (type_requires_comptime(ira->codegen, return_type, nullptr)) {17052 switch (type_requires_comptime(ira->codegen, return_type)) {
17053 case ReqCompTimeYes:17053 case ReqCompTimeYes:
17054 ir_add_error(ira, elem_index,17054 ir_add_error(ira, elem_index,
17055 buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known",17055 buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known",
...@@ -19034,7 +19034,7 @@ static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *sourc...@@ -19034,7 +19034,7 @@ static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *sourc
19034 }19034 }
1903519035
19036 bool is_comptime = ir_should_inline(ira->new_irb.exec, source_instruction->scope)19036 bool is_comptime = ir_should_inline(ira->new_irb.exec, source_instruction->scope)
19037 || type_requires_comptime(ira->codegen, union_type, nullptr) == ReqCompTimeYes;19037 || type_requires_comptime(ira->codegen, union_type) == ReqCompTimeYes;
1903819038
19039 IrInstruction *result = ir_get_deref(ira, source_instruction, result_loc, nullptr);19039 IrInstruction *result = ir_get_deref(ira, source_instruction, result_loc, nullptr);
19040 if (is_comptime && !instr_is_comptime(result)) {19040 if (is_comptime && !instr_is_comptime(result)) {
...@@ -19082,7 +19082,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -19082,7 +19082,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
19082 ZigList<IrInstruction *> const_ptrs = {};19082 ZigList<IrInstruction *> const_ptrs = {};
1908319083
19084 bool is_comptime = ir_should_inline(ira->new_irb.exec, instruction->scope)19084 bool is_comptime = ir_should_inline(ira->new_irb.exec, instruction->scope)
19085 || type_requires_comptime(ira->codegen, container_type, nullptr) == ReqCompTimeYes;19085 || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes;
1908619086
1908719087
19088 // Here we iterate over the fields that have been initialized, and emit19088 // Here we iterate over the fields that have been initialized, and emit
...@@ -19260,7 +19260,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -19260,7 +19260,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
19260 }19260 }
1926119261
19262 bool is_comptime;19262 bool is_comptime;
19263 switch (type_requires_comptime(ira->codegen, container_type, nullptr)) {19263 switch (type_requires_comptime(ira->codegen, container_type)) {
19264 case ReqCompTimeInvalid:19264 case ReqCompTimeInvalid:
19265 return ira->codegen->invalid_instruction;19265 return ira->codegen->invalid_instruction;
19266 case ReqCompTimeNo:19266 case ReqCompTimeNo:
...@@ -25502,7 +25502,7 @@ static ZigType *ir_resolve_lazy_fn_type(CodeGen *codegen, IrExecutable *exec, As...@@ -25502,7 +25502,7 @@ static ZigType *ir_resolve_lazy_fn_type(CodeGen *codegen, IrExecutable *exec, As
25502 lazy_fn_type->param_types[fn_type_id.next_param_index]);25502 lazy_fn_type->param_types[fn_type_id.next_param_index]);
25503 if (type_is_invalid(param_type))25503 if (type_is_invalid(param_type))
25504 return nullptr;25504 return nullptr;
25505 switch (type_requires_comptime(codegen, param_type, nullptr)) {25505 switch (type_requires_comptime(codegen, param_type)) {
25506 case ReqCompTimeYes:25506 case ReqCompTimeYes:
25507 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {25507 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
25508 exec_add_error_node(codegen, exec, source_node,25508 exec_add_error_node(codegen, exec, source_node,