authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-03-12 00:08:52-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-03-12 00:08:52-04:00
log49c3922037ef0b913466e707d85a4e085f6e9716
tree58904795206468e87acd5ad3dc9c491111d076f6
parentc18059a3ddcaec1bef18180ec797fe41baeac7f3

fix incorrect setEvalBranchQuota compile error

closes #688

3 files changed, 24 insertions(+), 1 deletions(-)

src/all_types.hpp+1
...@@ -49,6 +49,7 @@ struct IrExecutable {...@@ -49,6 +49,7 @@ struct IrExecutable {
49 size_t backward_branch_quota;49 size_t backward_branch_quota;
50 bool invalid;50 bool invalid;
51 bool is_inline;51 bool is_inline;
52 bool is_generic_instantiation;
52 FnTableEntry *fn_entry;53 FnTableEntry *fn_entry;
53 Buf *c_import_buf;54 Buf *c_import_buf;
54 AstNode *source_node;55 AstNode *source_node;
src/ir.cpp+2-1
...@@ -12127,6 +12127,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -12127,6 +12127,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
12127 impl_fn->ir_executable.parent_exec = ira->new_irb.exec;12127 impl_fn->ir_executable.parent_exec = ira->new_irb.exec;
12128 impl_fn->analyzed_executable.source_node = call_instruction->base.source_node;12128 impl_fn->analyzed_executable.source_node = call_instruction->base.source_node;
12129 impl_fn->analyzed_executable.parent_exec = ira->new_irb.exec;12129 impl_fn->analyzed_executable.parent_exec = ira->new_irb.exec;
12130 impl_fn->analyzed_executable.is_generic_instantiation = true;
1213012131
12131 ira->codegen->fn_defs.append(impl_fn);12132 ira->codegen->fn_defs.append(impl_fn);
12132 }12133 }
...@@ -15234,7 +15235,7 @@ static TypeTableEntry *ir_analyze_instruction_type_id(IrAnalyze *ira,...@@ -15234,7 +15235,7 @@ static TypeTableEntry *ir_analyze_instruction_type_id(IrAnalyze *ira,
15234static TypeTableEntry *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,15235static TypeTableEntry *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
15235 IrInstructionSetEvalBranchQuota *instruction)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 ir_add_error(ira, &instruction->base,15239 ir_add_error(ira, &instruction->base,
15239 buf_sprintf("@setEvalBranchQuota must be called from the top of the comptime stack"));15240 buf_sprintf("@setEvalBranchQuota must be called from the top of the comptime stack"));
15240 return ira->codegen->builtin_types.entry_invalid;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,3 +448,24 @@ test "comptime function with mutable pointer is not memoized" {
448fn increment(value: &i32) void {448fn increment(value: &i32) void {
449 *value += 1;449 *value += 1;
450}450}
451
452fn 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
461fn 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
469test "@setEvalBranchQuota at same scope as generic function call" {
470 assert(doesAlotT(u32, 2) == 2);
471}