From 68d7e4a1b60a52b59bc148a81458a89b9b739ab1 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 13 Apr 2019 16:53:53 -0400 Subject: better handle quota of setEvalBranchQuota Now that c58b80203443dcbf8b737ebdaa1f17fb20c77711 has removed the "top of the comptime stack" requirement, the branch quota can be modified somewhere other than the top of the comptime stack. This means that the quota of a parent IrExecutable has to be modifiable by an instruction in the child. Closes #2261 --- src/ir.cpp | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index de4543df4e..3d4ab45dc9 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -357,19 +357,9 @@ static void ir_ref_var(ZigVar *var) { } ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) { - ConstExprValue *result = ir_eval_const_value( ira->codegen - , scope - , node - , ira->codegen->builtin_types.entry_type - , ira->new_irb.exec->backward_branch_count - , ira->new_irb.exec->backward_branch_quota - , nullptr - , nullptr - , node - , nullptr - , ira->new_irb.exec - , nullptr - ); + ConstExprValue *result = ir_eval_const_value(ira->codegen, scope, node, ira->codegen->builtin_types.entry_type, + ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, nullptr, + node, nullptr, ira->new_irb.exec, nullptr); if (type_is_invalid(result->type)) return ira->codegen->builtin_types.entry_invalid; @@ -7965,7 +7955,7 @@ static ConstExprValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec return &codegen->invalid_instruction->value; } } - return &codegen->invalid_instruction->value; + zig_unreachable(); } static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *source_instruction) { @@ -10227,16 +10217,18 @@ static IrInstruction *ir_unreach_error(IrAnalyze *ira) { static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instruction) { size_t *bbc = ira->new_irb.exec->backward_branch_count; - size_t quota = ira->new_irb.exec->backward_branch_quota; + size_t *quota = ira->new_irb.exec->backward_branch_quota; // If we're already over quota, we've already given an error message for this. - if (*bbc > quota) { + if (*bbc > *quota) { + assert(ira->codegen->errors.length > 0); return false; } *bbc += 1; - if (*bbc > quota) { - ir_add_error(ira, source_instruction, buf_sprintf("evaluation exceeded %" ZIG_PRI_usize " backwards branches", quota)); + if (*bbc > *quota) { + ir_add_error(ira, source_instruction, + buf_sprintf("evaluation exceeded %" ZIG_PRI_usize " backwards branches", *quota)); return false; } return true; @@ -10317,7 +10309,7 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un } ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, - ZigType *expected_type, size_t *backward_branch_count, size_t backward_branch_quota, + ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota, ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, IrExecutable *parent_exec, AstNode *expected_type_source_node) { @@ -18983,8 +18975,8 @@ static IrInstruction *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ir if (!ir_resolve_usize(ira, instruction->new_quota->child, &new_quota)) return ira->codegen->invalid_instruction; - if (new_quota > ira->new_irb.exec->backward_branch_quota) { - ira->new_irb.exec->backward_branch_quota = new_quota; + if (new_quota > *ira->new_irb.exec->backward_branch_quota) { + *ira->new_irb.exec->backward_branch_quota = new_quota; } return ir_const_void(ira, &instruction->base); -- cgit v1.2.3