1
1
mirror of https://github.com/tweag/nickel.git synced 2024-09-20 16:08:14 +03:00

Avoid future should_update() test for thunks containing WHNFs

This commit is contained in:
Yann Hamdaoui 2021-01-26 12:32:50 +01:00
parent 7d85ae1913
commit 4bcaf4b7fa

View File

@ -157,6 +157,11 @@ impl Thunk {
self.data.borrow().state
}
/// Set the state to evaluated.
pub fn set_evaluated(&mut self) {
self.data.borrow_mut().state = ThunkState::Evaluated;
}
/// Generate an update frame from this thunk and set the state to `Blackholed`. Return an
/// error if the thunk was already black-holed.
pub fn to_update_frame(&mut self) -> Result<ThunkUpdateFrame, BlackholedError> {
@ -458,9 +463,8 @@ where
.ok_or(EvalError::UnboundIdentifier(x.clone(), pos.clone()))?;
std::mem::drop(env); // thunk may be a 1RC pointer
if thunk.state() != ThunkState::Evaluated
&& should_update(&thunk.borrow().body.term)
{
if thunk.state() != ThunkState::Evaluated {
if should_update(&thunk.borrow().body.term) {
match thunk.to_update_frame() {
Ok(thunk_upd) => stack.push_thunk(thunk_upd),
Err(BlackholedError) => {
@ -468,6 +472,11 @@ where
}
}
}
// If the thunk isn't to be updated, directly set the evaluated flag.
else {
thunk.set_evaluated();
}
}
call_stack.push(StackElem::Var(thunk.ident_kind(), x, pos));
thunk.into_closure()