| ... | ... | @@ -961,18 +961,14 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind |
| 961 | 961 | return entry; |
| 962 | 962 | } |
| 963 | 963 | |
| 964 | | ConstExprValue *analyze_const_value_allow_lazy(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry, |
| 965 | | Buf *type_name, bool allow_lazy) |
| 964 | ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry, |
| 965 | Buf *type_name, UndefAllowed undef) |
| 966 | 966 | { |
| 967 | 967 | size_t backward_branch_count = 0; |
| 968 | 968 | size_t backward_branch_quota = default_backward_branch_quota; |
| 969 | 969 | return ir_eval_const_value(g, scope, node, type_entry, |
| 970 | 970 | &backward_branch_count, &backward_branch_quota, |
| 971 | | nullptr, nullptr, node, type_name, nullptr, nullptr, allow_lazy); |
| 972 | | } |
| 973 | | |
| 974 | | ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry, Buf *type_name) { |
| 975 | | return analyze_const_value_allow_lazy(g, scope, node, type_entry, type_name, false); |
| 971 | nullptr, nullptr, node, type_name, nullptr, nullptr, undef); |
| 976 | 972 | } |
| 977 | 973 | |
| 978 | 974 | static Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *parent_type, |
| ... | ... | @@ -1162,22 +1158,12 @@ static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, Cons |
| 1162 | 1158 | } |
| 1163 | 1159 | |
| 1164 | 1160 | ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) { |
| 1165 | | ConstExprValue *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type, nullptr); |
| 1161 | ConstExprValue *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type, |
| 1162 | nullptr, UndefBad); |
| 1166 | 1163 | if (type_is_invalid(result->type)) |
| 1167 | 1164 | return g->builtin_types.entry_invalid; |
| 1168 | | |
| 1169 | | assert(result->special != ConstValSpecialRuntime); |
| 1170 | | // Reject undefined as valid `type` type even though the specification |
| 1171 | | // allows it to be casted to anything. |
| 1172 | | // See also ir_resolve_type() |
| 1173 | | if (result->special == ConstValSpecialUndef) { |
| 1174 | | add_node_error(g, node, |
| 1175 | | buf_sprintf("expected type 'type', found '%s'", |
| 1176 | | buf_ptr(&g->builtin_types.entry_undef->name))); |
| 1177 | | return g->builtin_types.entry_invalid; |
| 1178 | | } |
| 1179 | | |
| 1180 | | assert(result->data.x_type != nullptr); |
| 1165 | src_assert(result->special == ConstValSpecialStatic, node); |
| 1166 | src_assert(result->data.x_type != nullptr, node); |
| 1181 | 1167 | return result->data.x_type; |
| 1182 | 1168 | } |
| 1183 | 1169 | |
| ... | ... | @@ -1225,7 +1211,8 @@ void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_cou |
| 1225 | 1211 | } |
| 1226 | 1212 | |
| 1227 | 1213 | static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_t *result) { |
| 1228 | | ConstExprValue *align_result = analyze_const_value(g, scope, node, get_align_amt_type(g), nullptr); |
| 1214 | ConstExprValue *align_result = analyze_const_value(g, scope, node, get_align_amt_type(g), |
| 1215 | nullptr, UndefBad); |
| 1229 | 1216 | if (type_is_invalid(align_result->type)) |
| 1230 | 1217 | return false; |
| 1231 | 1218 | |
| ... | ... | @@ -1247,7 +1234,7 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf ** |
| 1247 | 1234 | ZigType *ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false, |
| 1248 | 1235 | PtrLenUnknown, 0, 0, 0, false); |
| 1249 | 1236 | ZigType *str_type = get_slice_type(g, ptr_type); |
| 1250 | | ConstExprValue *result_val = analyze_const_value(g, scope, node, str_type, nullptr); |
| 1237 | ConstExprValue *result_val = analyze_const_value(g, scope, node, str_type, nullptr, UndefBad); |
| 1251 | 1238 | if (type_is_invalid(result_val->type)) |
| 1252 | 1239 | return false; |
| 1253 | 1240 | |
| ... | ... | @@ -2261,7 +2248,8 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { |
| 2261 | 2248 | |
| 2262 | 2249 | if (tag_value != nullptr) { |
| 2263 | 2250 | // A user-specified value is available |
| 2264 | | ConstExprValue *result = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr); |
| 2251 | ConstExprValue *result = analyze_const_value(g, scope, tag_value, tag_int_type, |
| 2252 | nullptr, UndefBad); |
| 2265 | 2253 | if (type_is_invalid(result->type)) { |
| 2266 | 2254 | enum_type->data.enumeration.resolve_status = ResolveStatusInvalid; |
| 2267 | 2255 | continue; |
| ... | ... | @@ -2377,8 +2365,8 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { |
| 2377 | 2365 | return ErrorSemanticAnalyzeFail; |
| 2378 | 2366 | } |
| 2379 | 2367 | |
| 2380 | | ConstExprValue *field_type_val = analyze_const_value_allow_lazy(g, scope, |
| 2381 | | field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, true); |
| 2368 | ConstExprValue *field_type_val = analyze_const_value(g, scope, |
| 2369 | field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef); |
| 2382 | 2370 | if (type_is_invalid(field_type_val->type)) { |
| 2383 | 2371 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; |
| 2384 | 2372 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -2660,8 +2648,8 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 2660 | 2648 | return ErrorSemanticAnalyzeFail; |
| 2661 | 2649 | } |
| 2662 | 2650 | } else { |
| 2663 | | ConstExprValue *field_type_val = analyze_const_value_allow_lazy(g, scope, |
| 2664 | | field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, true); |
| 2651 | ConstExprValue *field_type_val = analyze_const_value(g, scope, |
| 2652 | field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef); |
| 2665 | 2653 | if (type_is_invalid(field_type_val->type)) { |
| 2666 | 2654 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 2667 | 2655 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -2726,7 +2714,8 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 2726 | 2714 | // In a second pass we will fill in the unspecified ones. |
| 2727 | 2715 | if (tag_value != nullptr) { |
| 2728 | 2716 | ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type; |
| 2729 | | ConstExprValue *result = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr); |
| 2717 | ConstExprValue *result = analyze_const_value(g, scope, tag_value, tag_int_type, |
| 2718 | nullptr, UndefBad); |
| 2730 | 2719 | if (type_is_invalid(result->type)) { |
| 2731 | 2720 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 2732 | 2721 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -2929,7 +2918,7 @@ void typecheck_panic_fn(CodeGen *g, TldFn *tld_fn, ZigFn *panic_fn) { |
| 2929 | 2918 | fake_decl->data.symbol_expr.symbol = tld_fn->base.name; |
| 2930 | 2919 | |
| 2931 | 2920 | // call this for the side effects of casting to panic_fn_type |
| 2932 | | analyze_const_value(g, tld_fn->base.parent_scope, fake_decl, panic_fn_type, nullptr); |
| 2921 | analyze_const_value(g, tld_fn->base.parent_scope, fake_decl, panic_fn_type, nullptr, UndefBad); |
| 2933 | 2922 | } |
| 2934 | 2923 | |
| 2935 | 2924 | ZigType *get_test_fn_type(CodeGen *g) { |
| ... | ... | @@ -3075,7 +3064,8 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 3075 | 3064 | static void resolve_decl_comptime(CodeGen *g, TldCompTime *tld_comptime) { |
| 3076 | 3065 | assert(tld_comptime->base.source_node->type == NodeTypeCompTime); |
| 3077 | 3066 | AstNode *expr_node = tld_comptime->base.source_node->data.comptime_expr.expr; |
| 3078 | | analyze_const_value(g, tld_comptime->base.parent_scope, expr_node, g->builtin_types.entry_void, nullptr); |
| 3067 | analyze_const_value(g, tld_comptime->base.parent_scope, expr_node, g->builtin_types.entry_void, |
| 3068 | nullptr, UndefBad); |
| 3079 | 3069 | } |
| 3080 | 3070 | |
| 3081 | 3071 | static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) { |
| ... | ... | @@ -3443,8 +3433,8 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) { |
| 3443 | 3433 | if (explicit_type && explicit_type->id == ZigTypeIdInvalid) { |
| 3444 | 3434 | implicit_type = explicit_type; |
| 3445 | 3435 | } else if (var_decl->expr) { |
| 3446 | | init_value = analyze_const_value_allow_lazy(g, tld_var->base.parent_scope, var_decl->expr, explicit_type, |
| 3447 | | var_decl->symbol, allow_lazy); |
| 3436 | init_value = analyze_const_value(g, tld_var->base.parent_scope, var_decl->expr, explicit_type, |
| 3437 | var_decl->symbol, allow_lazy ? LazyOk : UndefOk); |
| 3448 | 3438 | assert(init_value); |
| 3449 | 3439 | implicit_type = init_value->type; |
| 3450 | 3440 | |
| ... | ... | @@ -3599,7 +3589,8 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco |
| 3599 | 3589 | using_namespace->base.resolution = TldResolutionResolving; |
| 3600 | 3590 | assert(using_namespace->base.source_node->type == NodeTypeUsingNamespace); |
| 3601 | 3591 | ConstExprValue *result = analyze_const_value(g, &dest_decls_scope->base, |
| 3602 | | using_namespace->base.source_node->data.using_namespace.expr, g->builtin_types.entry_type, nullptr); |
| 3592 | using_namespace->base.source_node->data.using_namespace.expr, g->builtin_types.entry_type, |
| 3593 | nullptr, UndefBad); |
| 3603 | 3594 | using_namespace->using_namespace_value = result; |
| 3604 | 3595 | |
| 3605 | 3596 | if (type_is_invalid(result->type)) { |