| ... | ... | @@ -685,7 +685,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) { |
| 685 | 685 | entry->data.structure.fields_by_name.put(ptr_field_name, &entry->data.structure.fields[slice_ptr_index]); |
| 686 | 686 | entry->data.structure.fields_by_name.put(len_field_name, &entry->data.structure.fields[slice_len_index]); |
| 687 | 687 | |
| 688 | | switch (type_requires_comptime(g, ptr_type, entry)) { |
| 688 | switch (type_requires_comptime(g, ptr_type)) { |
| 689 | 689 | case ReqCompTimeInvalid: |
| 690 | 690 | zig_unreachable(); |
| 691 | 691 | case ReqCompTimeNo: |
| ... | ... | @@ -1016,9 +1016,9 @@ Error type_val_resolve_is_opaque_type(CodeGen *g, ConstExprValue *type_val, bool |
| 1016 | 1016 | zig_unreachable(); |
| 1017 | 1017 | } |
| 1018 | 1018 | |
| 1019 | | static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue *type_val, ZigType *parent_type) { |
| 1019 | static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue *type_val) { |
| 1020 | 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 | 1023 | switch (type_val->data.x_lazy->id) { |
| 1024 | 1024 | case LazyValueIdInvalid: |
| ... | ... | @@ -1028,17 +1028,17 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue |
| 1028 | 1028 | LazyValueSliceType *lazy_slice_type = reinterpret_cast<LazyValueSliceType *>(type_val->data.x_lazy); |
| 1029 | 1029 | if (type_is_invalid(lazy_slice_type->elem_type)) |
| 1030 | 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 | 1033 | case LazyValueIdPtrType: { |
| 1034 | 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 | 1037 | case LazyValueIdFnType: { |
| 1038 | 1038 | LazyValueFnType *lazy_fn_type = reinterpret_cast<LazyValueFnType *>(type_val->data.x_lazy); |
| 1039 | 1039 | if (lazy_fn_type->is_generic) |
| 1040 | 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 | 1042 | case ReqCompTimeInvalid: |
| 1043 | 1043 | return ReqCompTimeInvalid; |
| 1044 | 1044 | case ReqCompTimeYes: |
| ... | ... | @@ -1051,7 +1051,7 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue |
| 1051 | 1051 | AstNode *param_node = lazy_fn_type->proto_node->data.fn_proto.params.at(i); |
| 1052 | 1052 | bool param_is_var_args = param_node->data.param_decl.is_var_args; |
| 1053 | 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 | 1055 | case ReqCompTimeInvalid: |
| 1056 | 1056 | return ReqCompTimeInvalid; |
| 1057 | 1057 | case ReqCompTimeYes: |
| ... | ... | @@ -1517,7 +1517,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc |
| 1517 | 1517 | case ZigTypeIdVector: |
| 1518 | 1518 | case ZigTypeIdFnFrame: |
| 1519 | 1519 | case ZigTypeIdAnyFrame: |
| 1520 | | switch (type_requires_comptime(g, type_entry, fn_entry->type_entry)) { |
| 1520 | switch (type_requires_comptime(g, type_entry)) { |
| 1521 | 1521 | case ReqCompTimeNo: |
| 1522 | 1522 | break; |
| 1523 | 1523 | case ReqCompTimeYes: |
| ... | ... | @@ -1613,7 +1613,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc |
| 1613 | 1613 | case ZigTypeIdVector: |
| 1614 | 1614 | case ZigTypeIdFnFrame: |
| 1615 | 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 | 1617 | case ReqCompTimeInvalid: |
| 1618 | 1618 | return g->builtin_types.entry_invalid; |
| 1619 | 1619 | case ReqCompTimeYes: |
| ... | ... | @@ -1745,7 +1745,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { |
| 1745 | 1745 | |
| 1746 | 1746 | AstNode *decl_node = struct_type->data.structure.decl_node; |
| 1747 | 1747 | |
| 1748 | | if (struct_type->data.structure.resolve_loop_flag) { |
| 1748 | if (struct_type->data.structure.resolve_loop_flag_other) { |
| 1749 | 1749 | if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) { |
| 1750 | 1750 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; |
| 1751 | 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 | 1760 | size_t field_count = struct_type->data.structure.src_field_count; |
| 1761 | 1761 | |
| 1762 | 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; |
| 1764 | 1764 | |
| 1765 | 1765 | uint32_t *host_int_bytes = packed ? allocate<uint32_t>(struct_type->data.structure.gen_field_count) : nullptr; |
| 1766 | 1766 | |
| ... | ... | @@ -1877,7 +1877,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { |
| 1877 | 1877 | struct_type->size_in_bits = size_in_bits; |
| 1878 | 1878 | struct_type->data.structure.resolve_status = ResolveStatusSizeKnown; |
| 1879 | 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 | 1881 | struct_type->data.structure.host_int_bytes = host_int_bytes; |
| 1882 | 1882 | |
| 1883 | 1883 | return ErrorNone; |
| ... | ... | @@ -2275,7 +2275,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { |
| 2275 | 2275 | AstNode *decl_node = struct_type->data.structure.decl_node; |
| 2276 | 2276 | assert(decl_node->type == NodeTypeContainerDecl); |
| 2277 | 2277 | |
| 2278 | | if (struct_type->data.structure.resolve_loop_flag) { |
| 2278 | if (struct_type->data.structure.resolve_loop_flag_zero_bits) { |
| 2279 | 2279 | if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) { |
| 2280 | 2280 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; |
| 2281 | 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 | 2285 | return ErrorSemanticAnalyzeFail; |
| 2286 | 2286 | } |
| 2287 | 2287 | |
| 2288 | | struct_type->data.structure.resolve_loop_flag = true; |
| 2288 | struct_type->data.structure.resolve_loop_flag_zero_bits = true; |
| 2289 | 2289 | |
| 2290 | 2290 | assert(!struct_type->data.structure.fields); |
| 2291 | 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 | 2343 | type_struct_field->src_index = i; |
| 2344 | 2344 | type_struct_field->gen_index = SIZE_MAX; |
| 2345 | 2345 | |
| 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 | 2347 | case ReqCompTimeYes: |
| 2348 | 2348 | struct_type->data.structure.requires_comptime = true; |
| 2349 | 2349 | break; |
| ... | ... | @@ -2370,7 +2370,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { |
| 2370 | 2370 | gen_field_index += 1; |
| 2371 | 2371 | } |
| 2372 | 2372 | |
| 2373 | | struct_type->data.structure.resolve_loop_flag = false; |
| 2373 | struct_type->data.structure.resolve_loop_flag_zero_bits = false; |
| 2374 | 2374 | struct_type->data.structure.gen_field_count = (uint32_t)gen_field_index; |
| 2375 | 2375 | if (gen_field_index != 0) { |
| 2376 | 2376 | struct_type->abi_size = SIZE_MAX; |
| ... | ... | @@ -2400,7 +2400,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) { |
| 2400 | 2400 | |
| 2401 | 2401 | AstNode *decl_node = struct_type->data.structure.decl_node; |
| 2402 | 2402 | |
| 2403 | | if (struct_type->data.structure.resolve_loop_flag) { |
| 2403 | if (struct_type->data.structure.resolve_loop_flag_other) { |
| 2404 | 2404 | if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) { |
| 2405 | 2405 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; |
| 2406 | 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 | 2409 | return ErrorSemanticAnalyzeFail; |
| 2410 | 2410 | } |
| 2411 | 2411 | |
| 2412 | | struct_type->data.structure.resolve_loop_flag = true; |
| 2412 | struct_type->data.structure.resolve_loop_flag_other = true; |
| 2413 | 2413 | assert(decl_node->type == NodeTypeContainerDecl); |
| 2414 | 2414 | |
| 2415 | 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 | 2444 | } |
| 2445 | 2445 | } |
| 2446 | 2446 | |
| 2447 | | struct_type->data.structure.resolve_loop_flag = false; |
| 2447 | struct_type->data.structure.resolve_loop_flag_other = false; |
| 2448 | 2448 | |
| 2449 | 2449 | if (struct_type->data.structure.resolve_status == ResolveStatusInvalid) { |
| 2450 | 2450 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -2614,7 +2614,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 2614 | 2614 | return ErrorSemanticAnalyzeFail; |
| 2615 | 2615 | } |
| 2616 | 2616 | |
| 2617 | | switch (type_requires_comptime(g, field_type, union_type)) { |
| 2617 | switch (type_requires_comptime(g, field_type)) { |
| 2618 | 2618 | case ReqCompTimeInvalid: |
| 2619 | 2619 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 2620 | 2620 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -4959,11 +4959,8 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) { |
| 4959 | 4959 | zig_unreachable(); |
| 4960 | 4960 | } |
| 4961 | 4961 | |
| 4962 | | ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty, ZigType *parent_type) { |
| 4962 | ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty) { |
| 4963 | 4963 | Error err; |
| 4964 | | if (ty == parent_type) { |
| 4965 | | return ReqCompTimeNo; |
| 4966 | | } |
| 4967 | 4964 | switch (ty->id) { |
| 4968 | 4965 | case ZigTypeIdInvalid: |
| 4969 | 4966 | zig_unreachable(); |
| ... | ... | @@ -4977,8 +4974,12 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty, ZigType *parent_type |
| 4977 | 4974 | case ZigTypeIdArgTuple: |
| 4978 | 4975 | return ReqCompTimeYes; |
| 4979 | 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 | 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 | 4983 | if ((err = type_resolve(g, ty, ResolveStatusZeroBitsKnown))) |
| 4983 | 4984 | return ReqCompTimeInvalid; |
| 4984 | 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 | 4988 | return ReqCompTimeInvalid; |
| 4988 | 4989 | return ty->data.unionation.requires_comptime ? ReqCompTimeYes : ReqCompTimeNo; |
| 4989 | 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 | 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 | 4994 | case ZigTypeIdPointer: |
| 4994 | 4995 | if (ty->data.pointer.child_type->id == ZigTypeIdOpaque) { |
| 4995 | 4996 | return ReqCompTimeNo; |
| 4996 | 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 | 5000 | case ZigTypeIdFn: |
| 5000 | 5001 | return ty->data.fn.is_generic ? ReqCompTimeYes : ReqCompTimeNo; |