aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-04-13 16:53:53 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-04-13 16:55:59 -0400
commit68d7e4a1b60a52b59bc148a81458a89b9b739ab1 (patch)
treedb7f34838133a838c19634c8870c78ef154ca306 /src/ir.cpp
parenta43fd7a550c3cae7443f09e4294cfccb6bdf0320 (diff)
downloadzig-68d7e4a1b60a52b59bc148a81458a89b9b739ab1.tar.gz
zig-68d7e4a1b60a52b59bc148a81458a89b9b739ab1.zip
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
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp34
1 files changed, 13 insertions, 21 deletions
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);