authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-11-24 16:15:58-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-11-24 16:15:58-05:00
log3d2752cc3677535ddfbeeefba4036633bcab01dc
tree461cb6fc9eaf9ccbc8e6c8ea5207a380ecbcca2b
parent56a8f2b018a6ee1f1116a64d34803511a6fbad80
signature Commit is signed but in an unrecognized format.

refactor type_requires_comptime to have possible error

fixes a compiler crash when building https://github.com/AndreaOrru/zen

4 files changed, 129 insertions(+), 84 deletions(-)

src/analyze.cpp+49-36
...@@ -1619,13 +1619,16 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -1619,13 +1619,16 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
1619 case ZigTypeIdUnion:1619 case ZigTypeIdUnion:
1620 case ZigTypeIdFn:1620 case ZigTypeIdFn:
1621 case ZigTypeIdPromise:1621 case ZigTypeIdPromise:
1622 if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown)))1622 switch (type_requires_comptime(g, type_entry)) {
1623 return g->builtin_types.entry_invalid;1623 case ReqCompTimeNo:
1624 if (type_requires_comptime(type_entry)) {1624 break;
1625 add_node_error(g, param_node->data.param_decl.type,1625 case ReqCompTimeYes:
1626 buf_sprintf("parameter of type '%s' must be declared comptime",1626 add_node_error(g, param_node->data.param_decl.type,
1627 buf_ptr(&type_entry->name)));1627 buf_sprintf("parameter of type '%s' must be declared comptime",
1628 return g->builtin_types.entry_invalid;1628 buf_ptr(&type_entry->name)));
1629 return g->builtin_types.entry_invalid;
1630 case ReqCompTimeInvalid:
1631 return g->builtin_types.entry_invalid;
1629 }1632 }
1630 break;1633 break;
1631 }1634 }
...@@ -1711,10 +1714,13 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -1711,10 +1714,13 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
1711 case ZigTypeIdUnion:1714 case ZigTypeIdUnion:
1712 case ZigTypeIdFn:1715 case ZigTypeIdFn:
1713 case ZigTypeIdPromise:1716 case ZigTypeIdPromise:
1714 if ((err = type_resolve(g, fn_type_id.return_type, ResolveStatusZeroBitsKnown)))1717 switch (type_requires_comptime(g, fn_type_id.return_type)) {
1715 return g->builtin_types.entry_invalid;1718 case ReqCompTimeInvalid:
1716 if (type_requires_comptime(fn_type_id.return_type)) {1719 return g->builtin_types.entry_invalid;
1717 return get_generic_fn_type(g, &fn_type_id);1720 case ReqCompTimeYes:
1721 return get_generic_fn_type(g, &fn_type_id);
1722 case ReqCompTimeNo:
1723 break;
1718 }1724 }
1719 break;1725 break;
1720 }1726 }
...@@ -2560,8 +2566,6 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {...@@ -2560,8 +2566,6 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
2560static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {2566static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
2561 assert(struct_type->id == ZigTypeIdStruct);2567 assert(struct_type->id == ZigTypeIdStruct);
25622568
2563 Error err;
2564
2565 if (struct_type->data.structure.resolve_status == ResolveStatusInvalid)2569 if (struct_type->data.structure.resolve_status == ResolveStatusInvalid)
2566 return ErrorSemanticAnalyzeFail;2570 return ErrorSemanticAnalyzeFail;
2567 if (struct_type->data.structure.resolve_status >= ResolveStatusZeroBitsKnown)2571 if (struct_type->data.structure.resolve_status >= ResolveStatusZeroBitsKnown)
...@@ -2619,13 +2623,15 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {...@@ -2619,13 +2623,15 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
2619 buf_sprintf("enums, not structs, support field assignment"));2623 buf_sprintf("enums, not structs, support field assignment"));
2620 }2624 }
26212625
2622 if ((err = type_resolve(g, field_type, ResolveStatusZeroBitsKnown))) {2626 switch (type_requires_comptime(g, field_type)) {
2623 struct_type->data.structure.resolve_status = ResolveStatusInvalid;2627 case ReqCompTimeYes:
2624 continue;2628 struct_type->data.structure.requires_comptime = true;
2625 }2629 break;
26262630 case ReqCompTimeInvalid:
2627 if (type_requires_comptime(field_type)) {2631 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2628 struct_type->data.structure.requires_comptime = true;2632 continue;
2633 case ReqCompTimeNo:
2634 break;
2629 }2635 }
26302636
2631 if (!type_has_bits(field_type))2637 if (!type_has_bits(field_type))
...@@ -2890,11 +2896,17 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -2890,11 +2896,17 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
2890 }2896 }
2891 union_field->type_entry = field_type;2897 union_field->type_entry = field_type;
28922898
2893 if (type_requires_comptime(field_type)) {2899 switch (type_requires_comptime(g, field_type)) {
2894 union_type->data.unionation.requires_comptime = true;2900 case ReqCompTimeInvalid:
2901 union_type->data.unionation.is_invalid = true;
2902 continue;
2903 case ReqCompTimeYes:
2904 union_type->data.unionation.requires_comptime = true;
2905 break;
2906 case ReqCompTimeNo:
2907 break;
2895 }2908 }
28962909
2897
2898 if (field_node->data.struct_field.value != nullptr && !decl_node->data.container_decl.auto_enum) {2910 if (field_node->data.struct_field.value != nullptr && !decl_node->data.container_decl.auto_enum) {
2899 ErrorMsg *msg = add_node_error(g, field_node->data.struct_field.value,2911 ErrorMsg *msg = add_node_error(g, field_node->data.struct_field.value,
2900 buf_sprintf("non-enum union field assignment"));2912 buf_sprintf("non-enum union field assignment"));
...@@ -5089,7 +5101,10 @@ bool type_has_bits(ZigType *type_entry) {...@@ -5089,7 +5101,10 @@ bool type_has_bits(ZigType *type_entry) {
5089 return !type_entry->zero_bits;5101 return !type_entry->zero_bits;
5090}5102}
50915103
5092bool type_requires_comptime(ZigType *type_entry) {5104ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry) {
5105 Error err;
5106 if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown)))
5107 return ReqCompTimeInvalid;
5093 switch (type_entry->id) {5108 switch (type_entry->id) {
5094 case ZigTypeIdInvalid:5109 case ZigTypeIdInvalid:
5095 case ZigTypeIdOpaque:5110 case ZigTypeIdOpaque:
...@@ -5102,27 +5117,25 @@ bool type_requires_comptime(ZigType *type_entry) {...@@ -5102,27 +5117,25 @@ bool type_requires_comptime(ZigType *type_entry) {
5102 case ZigTypeIdNamespace:5117 case ZigTypeIdNamespace:
5103 case ZigTypeIdBoundFn:5118 case ZigTypeIdBoundFn:
5104 case ZigTypeIdArgTuple:5119 case ZigTypeIdArgTuple:
5105 return true;5120 return ReqCompTimeYes;
5106 case ZigTypeIdArray:5121 case ZigTypeIdArray:
5107 return type_requires_comptime(type_entry->data.array.child_type);5122 return type_requires_comptime(g, type_entry->data.array.child_type);
5108 case ZigTypeIdStruct:5123 case ZigTypeIdStruct:
5109 assert(type_is_resolved(type_entry, ResolveStatusZeroBitsKnown));5124 return type_entry->data.structure.requires_comptime ? ReqCompTimeYes : ReqCompTimeNo;
5110 return type_entry->data.structure.requires_comptime;
5111 case ZigTypeIdUnion:5125 case ZigTypeIdUnion:
5112 assert(type_is_resolved(type_entry, ResolveStatusZeroBitsKnown));5126 return type_entry->data.unionation.requires_comptime ? ReqCompTimeYes : ReqCompTimeNo;
5113 return type_entry->data.unionation.requires_comptime;
5114 case ZigTypeIdOptional:5127 case ZigTypeIdOptional:
5115 return type_requires_comptime(type_entry->data.maybe.child_type);5128 return type_requires_comptime(g, type_entry->data.maybe.child_type);
5116 case ZigTypeIdErrorUnion:5129 case ZigTypeIdErrorUnion:
5117 return type_requires_comptime(type_entry->data.error_union.payload_type);5130 return type_requires_comptime(g, type_entry->data.error_union.payload_type);
5118 case ZigTypeIdPointer:5131 case ZigTypeIdPointer:
5119 if (type_entry->data.pointer.child_type->id == ZigTypeIdOpaque) {5132 if (type_entry->data.pointer.child_type->id == ZigTypeIdOpaque) {
5120 return false;5133 return ReqCompTimeNo;
5121 } else {5134 } else {
5122 return type_requires_comptime(type_entry->data.pointer.child_type);5135 return type_requires_comptime(g, type_entry->data.pointer.child_type);
5123 }5136 }
5124 case ZigTypeIdFn:5137 case ZigTypeIdFn:
5125 return type_entry->data.fn.is_generic;5138 return type_entry->data.fn.is_generic ? ReqCompTimeYes : ReqCompTimeNo;
5126 case ZigTypeIdEnum:5139 case ZigTypeIdEnum:
5127 case ZigTypeIdErrorSet:5140 case ZigTypeIdErrorSet:
5128 case ZigTypeIdBool:5141 case ZigTypeIdBool:
...@@ -5131,7 +5144,7 @@ bool type_requires_comptime(ZigType *type_entry) {...@@ -5131,7 +5144,7 @@ bool type_requires_comptime(ZigType *type_entry) {
5131 case ZigTypeIdVoid:5144 case ZigTypeIdVoid:
5132 case ZigTypeIdUnreachable:5145 case ZigTypeIdUnreachable:
5133 case ZigTypeIdPromise:5146 case ZigTypeIdPromise:
5134 return false;5147 return ReqCompTimeNo;
5135 }5148 }
5136 zig_unreachable();5149 zig_unreachable();
5137}5150}
src/analyze.hpp+7-1
...@@ -87,7 +87,6 @@ ZigFn *create_fn(CodeGen *g, AstNode *proto_node);...@@ -87,7 +87,6 @@ ZigFn *create_fn(CodeGen *g, AstNode *proto_node);
87ZigFn *create_fn_raw(CodeGen *g, FnInline inline_value);87ZigFn *create_fn_raw(CodeGen *g, FnInline inline_value);
88void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_count_alloc);88void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_count_alloc);
89AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index);89AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index);
90bool type_requires_comptime(ZigType *type_entry);
91Error ATTRIBUTE_MUST_USE ensure_complete_type(CodeGen *g, ZigType *type_entry);90Error ATTRIBUTE_MUST_USE ensure_complete_type(CodeGen *g, ZigType *type_entry);
92Error ATTRIBUTE_MUST_USE type_resolve(CodeGen *g, ZigType *type_entry, ResolveStatus status);91Error ATTRIBUTE_MUST_USE type_resolve(CodeGen *g, ZigType *type_entry, ResolveStatus status);
93void complete_enum(CodeGen *g, ZigType *enum_type);92void complete_enum(CodeGen *g, ZigType *enum_type);
...@@ -216,4 +215,11 @@ bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id);...@@ -216,4 +215,11 @@ bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id);
216215
217uint32_t get_host_int_bytes(CodeGen *g, ZigType *struct_type, TypeStructField *field);216uint32_t get_host_int_bytes(CodeGen *g, ZigType *struct_type, TypeStructField *field);
218217
218enum ReqCompTime {
219 ReqCompTimeInvalid,
220 ReqCompTimeNo,
221 ReqCompTimeYes,
222};
223ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry);
224
219#endif225#endif
src/codegen.cpp+8-2
...@@ -6281,8 +6281,14 @@ static void do_code_gen(CodeGen *g) {...@@ -6281,8 +6281,14 @@ static void do_code_gen(CodeGen *g) {
6281 }6281 }
6282 if (ir_get_var_is_comptime(var))6282 if (ir_get_var_is_comptime(var))
6283 continue;6283 continue;
6284 if (type_requires_comptime(var->value->type))6284 switch (type_requires_comptime(g, var->value->type)) {
6285 continue;6285 case ReqCompTimeInvalid:
6286 zig_unreachable();
6287 case ReqCompTimeYes:
6288 continue;
6289 case ReqCompTimeNo:
6290 break;
6291 }
62866292
6287 if (var->src_arg_index == SIZE_MAX) {6293 if (var->src_arg_index == SIZE_MAX) {
6288 var->value_ref = build_alloca(g, var->value->type, buf_ptr(&var->name), var->align_bytes);6294 var->value_ref = build_alloca(g, var->value->type, buf_ptr(&var->name), var->align_bytes);
src/ir.cpp+65-45
...@@ -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}
1127711277
11278static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {11278static 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;
1147211471
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 }
1147511483
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 }
1241412422
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 }
1244612453
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 }
1291312920
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 }
1292012932
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 }
1339013402
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
1433414349
14335 } else {14350 } else {
14336 // runtime known element index14351 // 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}
1939119411
19392static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) {19412static 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);
1939619415
...@@ -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,