Skip to content

Commit

Permalink
fix: Avoid infinite loops/extremely slow optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Oct 6, 2019
1 parent b00cbea commit dc7ec72
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions vm/src/core/interpreter.rs
Expand Up @@ -974,7 +974,7 @@ impl<'a, 'e> Compiler<'a, 'e> {
) -> Option<CExpr<'e>> {
let mut replaced_expr = Vec::new();
let mut expr = Reduced::Local(expr);
loop {
for _ in 0..10 {
let replaced_expr_len = replaced_expr.len();
let new_expr = self
.peek_reduced_expr_fn(expr.clone(), &mut |cost, e| {
Expand Down Expand Up @@ -1018,20 +1018,20 @@ impl<'a, 'e> Compiler<'a, 'e> {
continue;
}

return replaced_expr
.into_iter()
.rev()
.find(|(cost, e)| {
*cost <= 10 && !self.contains_unbound_variables(e.as_ref())
})
.map(|(_, e)| e.into_local(&self.allocator));
break;
}
Some(e) => {
expr = Reduced::Local(e);
replaced_expr.push((0, Reduced::Local(e)));
}
}
}

replaced_expr
.into_iter()
.rev()
.find(|(cost, e)| *cost <= 10 && !self.contains_unbound_variables(e.as_ref()))
.map(|(_, e)| e.into_local(&self.allocator))
}

fn inline_call<'b>(
Expand Down Expand Up @@ -1159,7 +1159,7 @@ impl<'a, 'e> Compiler<'a, 'e> {
mut expr: ReducedExpr<'e>,
report_reduction: &mut dyn FnMut(Cost, &ReducedExpr<'e>),
) -> CostBinding<'e> {
loop {
for _ in 0..10 {
let new_bind = expr.clone().with(self.allocator, |resolver, expr| {
match peek_through_lets(expr) {
Expr::Ident(ref id, _) => {
Expand Down Expand Up @@ -1229,6 +1229,10 @@ impl<'a, 'e> Compiler<'a, 'e> {
}
}
}
CostBinding {
cost: 0,
bind: Binding::Expr(expr),
}
}

fn project_reduced(
Expand Down

0 comments on commit dc7ec72

Please sign in to comment.