| author | |
| committer | |
| log | 49c3922037ef0b913466e707d85a4e085f6e9716 |
| tree | 58904795206468e87acd5ad3dc9c491111d076f6 |
| parent | c18059a3ddcaec1bef18180ec797fe41baeac7f3 |
closes #6883 files changed, 24 insertions(+), 1 deletions(-)
src/all_types.hpp+1| ... | ... | @@ -49,6 +49,7 @@ struct IrExecutable { |
| 49 | 49 | size_t backward_branch_quota; |
| 50 | 50 | bool invalid; |
| 51 | 51 | bool is_inline; |
| 52 | bool is_generic_instantiation; | |
| 52 | 53 | FnTableEntry *fn_entry; |
| 53 | 54 | Buf *c_import_buf; |
| 54 | 55 | AstNode *source_node; |
src/ir.cpp+2-1| ... | ... | @@ -12127,6 +12127,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 12127 | 12127 | impl_fn->ir_executable.parent_exec = ira->new_irb.exec; |
| 12128 | 12128 | impl_fn->analyzed_executable.source_node = call_instruction->base.source_node; |
| 12129 | 12129 | impl_fn->analyzed_executable.parent_exec = ira->new_irb.exec; |
| 12130 | impl_fn->analyzed_executable.is_generic_instantiation = true; | |
| 12130 | 12131 | |
| 12131 | 12132 | ira->codegen->fn_defs.append(impl_fn); |
| 12132 | 12133 | } |
| ... | ... | @@ -15234,7 +15235,7 @@ static TypeTableEntry *ir_analyze_instruction_type_id(IrAnalyze *ira, |
| 15234 | 15235 | static TypeTableEntry *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira, |
| 15235 | 15236 | IrInstructionSetEvalBranchQuota *instruction) |
| 15236 | 15237 | { |
| 15237 | if (ira->new_irb.exec->parent_exec != nullptr) { | |
| 15238 | if (ira->new_irb.exec->parent_exec != nullptr && !ira->new_irb.exec->is_generic_instantiation) { | |
| 15238 | 15239 | ir_add_error(ira, &instruction->base, |
| 15239 | 15240 | buf_sprintf("@setEvalBranchQuota must be called from the top of the comptime stack")); |
| 15240 | 15241 | return ira->codegen->builtin_types.entry_invalid; |
test/cases/eval.zig+21| ... | ... | @@ -448,3 +448,24 @@ test "comptime function with mutable pointer is not memoized" { |
| 448 | 448 | fn increment(value: &i32) void { |
| 449 | 449 | *value += 1; |
| 450 | 450 | } |
| 451 | ||
| 452 | fn generateTable(comptime T: type) [1010]T { | |
| 453 | var res : [1010]T = undefined; | |
| 454 | var i : usize = 0; | |
| 455 | while (i < 1010) : (i += 1) { | |
| 456 | res[i] = T(i); | |
| 457 | } | |
| 458 | return res; | |
| 459 | } | |
| 460 | ||
| 461 | fn doesAlotT(comptime T: type, value: usize) T { | |
| 462 | @setEvalBranchQuota(5000); | |
| 463 | const table = comptime blk: { | |
| 464 | break :blk generateTable(T); | |
| 465 | }; | |
| 466 | return table[value]; | |
| 467 | } | |
| 468 | ||
| 469 | test "@setEvalBranchQuota at same scope as generic function call" { | |
| 470 | assert(doesAlotT(u32, 2) == 2); | |
| 471 | } |