diff --git a/src/machine/machine_state_impl.rs b/src/machine/machine_state_impl.rs index 5de07140..f7cda917 100644 --- a/src/machine/machine_state_impl.rs +++ b/src/machine/machine_state_impl.rs @@ -201,6 +201,14 @@ impl MachineState { } fn bind_with_occurs_check(&mut self, r: Ref, addr: Addr) { + if let Ref::StackCell(..) = r { + // local variable optimization -- r cannot occur in the + // data structure bound to addr, so don't bother + // traversing it. + self.bind(r, addr); + return; + } + let mut fail = false; for addr in self.acyclic_pre_order_iter(addr) {