| ... | @@ -11276,7 +11276,6 @@ static bool optional_value_is_null(ConstExprValue *val) { | ... | @@ -11276,7 +11276,6 @@ static bool optional_value_is_null(ConstExprValue *val) { |
| 11276 | } | 11276 | } |
| 11277 | | 11277 | |
| 11278 | static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { | 11278 | static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 11279 | Error err; | | |
| 11280 | IrInstruction *op1 = bin_op_instruction->op1->child; | 11279 | IrInstruction *op1 = bin_op_instruction->op1->child; |
| 11281 | if (type_is_invalid(op1->value.type)) | 11280 | if (type_is_invalid(op1->value.type)) |
| 11282 | return ira->codegen->invalid_instruction; | 11281 | return ira->codegen->invalid_instruction; |
| ... | @@ -11470,10 +11469,19 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -11470,10 +11469,19 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 11470 | if (casted_op2 == ira->codegen->invalid_instruction) | 11469 | if (casted_op2 == ira->codegen->invalid_instruction) |
| 11471 | return ira->codegen->invalid_instruction; | 11470 | return ira->codegen->invalid_instruction; |
| 11472 | | 11471 | |
| 11473 | if ((err = type_resolve(ira->codegen, resolved_type, ResolveStatusZeroBitsKnown))) | 11472 | bool requires_comptime; |
| 11474 | return ira->codegen->invalid_instruction; | 11473 | switch (type_requires_comptime(ira->codegen, resolved_type)) { |
| | 11474 | case ReqCompTimeYes: |
| | 11475 | requires_comptime = true; |
| | 11476 | break; |
| | 11477 | case ReqCompTimeNo: |
| | 11478 | requires_comptime = false; |
| | 11479 | break; |
| | 11480 | case ReqCompTimeInvalid: |
| | 11481 | return ira->codegen->invalid_instruction; |
| | 11482 | } |
| 11475 | | 11483 | |
| 11476 | bool one_possible_value = !type_requires_comptime(resolved_type) && !type_has_bits(resolved_type); | 11484 | bool one_possible_value = !requires_comptime && !type_has_bits(resolved_type); |
| 11477 | if (one_possible_value || (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2))) { | 11485 | if (one_possible_value || (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2))) { |
| 11478 | ConstExprValue *op1_val = one_possible_value ? &casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad); | 11486 | ConstExprValue *op1_val = one_possible_value ? &casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad); |
| 11479 | if (op1_val == nullptr) | 11487 | if (op1_val == nullptr) |
| ... | @@ -12406,42 +12414,41 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruct | ... | @@ -12406,42 +12414,41 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruct |
| 12406 | ZigType *result_type = casted_init_value->value.type; | 12414 | ZigType *result_type = casted_init_value->value.type; |
| 12407 | if (type_is_invalid(result_type)) { | 12415 | if (type_is_invalid(result_type)) { |
| 12408 | result_type = ira->codegen->builtin_types.entry_invalid; | 12416 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 12409 | } else { | 12417 | } else if (result_type->id == ZigTypeIdUnreachable || result_type->id == ZigTypeIdOpaque) { |
| 12410 | if ((err = type_resolve(ira->codegen, result_type, ResolveStatusZeroBitsKnown))) { | 12418 | ir_add_error_node(ira, source_node, |
| 12411 | result_type = ira->codegen->builtin_types.entry_invalid; | 12419 | buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name))); |
| 12412 | } | 12420 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 12413 | } | 12421 | } |
| 12414 | | 12422 | |
| 12415 | if (!type_is_invalid(result_type)) { | 12423 | switch (type_requires_comptime(ira->codegen, result_type)) { |
| 12416 | if (result_type->id == ZigTypeIdUnreachable || | 12424 | case ReqCompTimeInvalid: |
| 12417 | result_type->id == ZigTypeIdOpaque) | 12425 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 12418 | { | 12426 | break; |
| | 12427 | case ReqCompTimeYes: { |
| | 12428 | var_class_requires_const = true; |
| | 12429 | if (!var->gen_is_const && !is_comptime_var) { |
| 12419 | ir_add_error_node(ira, source_node, | 12430 | ir_add_error_node(ira, source_node, |
| 12420 | buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name))); | 12431 | buf_sprintf("variable of type '%s' must be const or comptime", |
| | 12432 | buf_ptr(&result_type->name))); |
| 12421 | result_type = ira->codegen->builtin_types.entry_invalid; | 12433 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 12422 | } else if (type_requires_comptime(result_type)) { | 12434 | } |
| | 12435 | break; |
| | 12436 | } |
| | 12437 | case ReqCompTimeNo: |
| | 12438 | if (casted_init_value->value.special == ConstValSpecialStatic && |
| | 12439 | casted_init_value->value.type->id == ZigTypeIdFn && |
| | 12440 | casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways) |
| | 12441 | { |
| 12423 | var_class_requires_const = true; | 12442 | var_class_requires_const = true; |
| 12424 | if (!var->gen_is_const && !is_comptime_var) { | 12443 | if (!var->src_is_const && !is_comptime_var) { |
| 12425 | ir_add_error_node(ira, source_node, | 12444 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 12426 | buf_sprintf("variable of type '%s' must be const or comptime", | 12445 | buf_sprintf("functions marked inline must be stored in const or comptime var")); |
| 12427 | buf_ptr(&result_type->name))); | 12446 | AstNode *proto_node = casted_init_value->value.data.x_ptr.data.fn.fn_entry->proto_node; |
| | 12447 | add_error_note(ira->codegen, msg, proto_node, buf_sprintf("declared here")); |
| 12428 | result_type = ira->codegen->builtin_types.entry_invalid; | 12448 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 12429 | } | 12449 | } |
| 12430 | } else { | | |
| 12431 | if (casted_init_value->value.special == ConstValSpecialStatic && | | |
| 12432 | casted_init_value->value.type->id == ZigTypeIdFn && | | |
| 12433 | casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways) | | |
| 12434 | { | | |
| 12435 | var_class_requires_const = true; | | |
| 12436 | if (!var->src_is_const && !is_comptime_var) { | | |
| 12437 | ErrorMsg *msg = ir_add_error_node(ira, source_node, | | |
| 12438 | buf_sprintf("functions marked inline must be stored in const or comptime var")); | | |
| 12439 | AstNode *proto_node = casted_init_value->value.data.x_ptr.data.fn.fn_entry->proto_node; | | |
| 12440 | add_error_note(ira->codegen, msg, proto_node, buf_sprintf("declared here")); | | |
| 12441 | result_type = ira->codegen->builtin_types.entry_invalid; | | |
| 12442 | } | | |
| 12443 | } | | |
| 12444 | } | 12450 | } |
| | 12451 | break; |
| 12445 | } | 12452 | } |
| 12446 | | 12453 | |
| 12447 | if (var->value->type != nullptr && !is_comptime_var) { | 12454 | if (var->value->type != nullptr && !is_comptime_var) { |
| ... | @@ -12912,10 +12919,15 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod | ... | @@ -12912,10 +12919,15 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 12912 | } | 12919 | } |
| 12913 | | 12920 | |
| 12914 | if (!comptime_arg) { | 12921 | if (!comptime_arg) { |
| 12915 | if (type_requires_comptime(casted_arg->value.type)) { | 12922 | switch (type_requires_comptime(ira->codegen, casted_arg->value.type)) { |
| | 12923 | case ReqCompTimeYes: |
| 12916 | ir_add_error(ira, casted_arg, | 12924 | ir_add_error(ira, casted_arg, |
| 12917 | buf_sprintf("parameter of type '%s' requires comptime", buf_ptr(&casted_arg->value.type->name))); | 12925 | buf_sprintf("parameter of type '%s' requires comptime", buf_ptr(&casted_arg->value.type->name))); |
| 12918 | return false; | 12926 | return false; |
| | 12927 | case ReqCompTimeInvalid: |
| | 12928 | return false; |
| | 12929 | case ReqCompTimeNo: |
| | 12930 | break; |
| 12919 | } | 12931 | } |
| 12920 | | 12932 | |
| 12921 | casted_args[fn_type_id->param_count] = casted_arg; | 12933 | casted_args[fn_type_id->param_count] = casted_arg; |
| ... | @@ -13388,12 +13400,15 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call | ... | @@ -13388,12 +13400,15 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call |
| 13388 | inst_fn_type_id.return_type = specified_return_type; | 13400 | inst_fn_type_id.return_type = specified_return_type; |
| 13389 | } | 13401 | } |
| 13390 | | 13402 | |
| 13391 | if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusZeroBitsKnown))) | 13403 | switch (type_requires_comptime(ira->codegen, specified_return_type)) { |
| 13392 | return ira->codegen->invalid_instruction; | 13404 | case ReqCompTimeYes: |
| 13393 | | | |
| 13394 | if (type_requires_comptime(specified_return_type)) { | | |
| 13395 | // Throw out our work and call the function as if it were comptime. | 13405 | // Throw out our work and call the function as if it were comptime. |
| 13396 | return ir_analyze_fn_call(ira, call_instruction, fn_entry, fn_type, fn_ref, first_arg_ptr, true, FnInlineAuto); | 13406 | return ir_analyze_fn_call(ira, call_instruction, fn_entry, fn_type, fn_ref, first_arg_ptr, |
| | 13407 | true, FnInlineAuto); |
| | 13408 | case ReqCompTimeInvalid: |
| | 13409 | return ira->codegen->invalid_instruction; |
| | 13410 | case ReqCompTimeNo: |
| | 13411 | break; |
| 13397 | } | 13412 | } |
| 13398 | } | 13413 | } |
| 13399 | IrInstruction *async_allocator_inst = nullptr; | 13414 | IrInstruction *async_allocator_inst = nullptr; |
| ... | @@ -14334,11 +14349,16 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct | ... | @@ -14334,11 +14349,16 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 14334 | | 14349 | |
| 14335 | } else { | 14350 | } else { |
| 14336 | // runtime known element index | 14351 | // runtime known element index |
| 14337 | if (type_requires_comptime(return_type)) { | 14352 | switch (type_requires_comptime(ira->codegen, return_type)) { |
| | 14353 | case ReqCompTimeYes: |
| 14338 | ir_add_error(ira, elem_index, | 14354 | ir_add_error(ira, elem_index, |
| 14339 | buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known", | 14355 | buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known", |
| 14340 | buf_ptr(&return_type->data.pointer.child_type->name))); | 14356 | buf_ptr(&return_type->data.pointer.child_type->name))); |
| 14341 | return ira->codegen->invalid_instruction; | 14357 | return ira->codegen->invalid_instruction; |
| | 14358 | case ReqCompTimeInvalid: |
| | 14359 | return ira->codegen->invalid_instruction; |
| | 14360 | case ReqCompTimeNo: |
| | 14361 | break; |
| 14342 | } | 14362 | } |
| 14343 | if (ptr_align < abi_align) { | 14363 | if (ptr_align < abi_align) { |
| 14344 | if (elem_size >= ptr_align && elem_size % ptr_align == 0) { | 14364 | if (elem_size >= ptr_align && elem_size % ptr_align == 0) { |
| ... | @@ -19390,7 +19410,6 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, | ... | @@ -19390,7 +19410,6 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 19390 | } | 19410 | } |
| 19391 | | 19411 | |
| 19392 | static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) { | 19412 | static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) { |
| 19393 | Error err; | | |
| 19394 | AstNode *proto_node = instruction->base.source_node; | 19413 | AstNode *proto_node = instruction->base.source_node; |
| 19395 | assert(proto_node->type == NodeTypeFnProto); | 19414 | assert(proto_node->type == NodeTypeFnProto); |
| 19396 | | 19415 | |
| ... | @@ -19429,11 +19448,8 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct | ... | @@ -19429,11 +19448,8 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct |
| 19429 | if (type_is_invalid(param_type_value->value.type)) | 19448 | if (type_is_invalid(param_type_value->value.type)) |
| 19430 | return ira->codegen->invalid_instruction; | 19449 | return ira->codegen->invalid_instruction; |
| 19431 | ZigType *param_type = ir_resolve_type(ira, param_type_value); | 19450 | ZigType *param_type = ir_resolve_type(ira, param_type_value); |
| 19432 | if (type_is_invalid(param_type)) | 19451 | switch (type_requires_comptime(ira->codegen, param_type)) { |
| 19433 | return ira->codegen->invalid_instruction; | 19452 | case ReqCompTimeYes: |
| 19434 | if ((err = type_resolve(ira->codegen, param_type, ResolveStatusZeroBitsKnown))) | | |
| 19435 | return ira->codegen->invalid_instruction; | | |
| 19436 | if (type_requires_comptime(param_type)) { | | |
| 19437 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { | 19453 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 19438 | ir_add_error(ira, param_type_value, | 19454 | ir_add_error(ira, param_type_value, |
| 19439 | buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'", | 19455 | buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'", |
| ... | @@ -19443,6 +19459,10 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct | ... | @@ -19443,6 +19459,10 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct |
| 19443 | param_info->type = param_type; | 19459 | param_info->type = param_type; |
| 19444 | fn_type_id.next_param_index += 1; | 19460 | fn_type_id.next_param_index += 1; |
| 19445 | return ir_const_type(ira, &instruction->base, get_generic_fn_type(ira->codegen, &fn_type_id)); | 19461 | return ir_const_type(ira, &instruction->base, get_generic_fn_type(ira->codegen, &fn_type_id)); |
| | 19462 | case ReqCompTimeInvalid: |
| | 19463 | return ira->codegen->invalid_instruction; |
| | 19464 | case ReqCompTimeNo: |
| | 19465 | break; |
| 19446 | } | 19466 | } |
| 19447 | if (!type_has_bits(param_type) && !calling_convention_allows_zig_types(fn_type_id.cc)) { | 19467 | if (!type_has_bits(param_type) && !calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 19448 | ir_add_error(ira, param_type_value, | 19468 | ir_add_error(ira, param_type_value, |