Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Properly force enum variants #1835

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> {
.map(|result| result.body)
}

/// Same as [Self::eval_full], but takes a closure as an argument instead of a term.
pub fn eval_full_closure(&mut self, t0: Closure) -> Result<Closure, EvalError> {
self.eval_deep_closure_impl(t0, false)
.map(|result| Closure {
Expand Down
21 changes: 21 additions & 0 deletions core/src/eval/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,10 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> {
env: Environment::new(),
})
}
Term::EnumVariant { arg, .. } => Ok(Closure {
body: seq_terms(std::iter::once(arg), pos_op),
env,
}),
yannham marked this conversation as resolved.
Show resolved Hide resolved
_ => {
if let Some((next, ..)) = self.stack.pop_arg(&self.cache) {
Ok(next)
Expand Down Expand Up @@ -1063,6 +1067,23 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> {
env: Environment::new(),
})
}
// For an enum variant, `force x` is simply equivalent to `deep_seq x x`, as
// there's no lazy pending contract to apply.
Term::EnumVariant { tag, arg, attrs } => {
let cont = RichTerm::new(
Term::EnumVariant {
tag,
arg: arg.clone(),
attrs,
},
pos.into_inherited(),
);

Ok(Closure {
body: seq_terms(std::iter::once(arg), pos_op, cont),
env,
})
}
_ => Ok(Closure {
body: RichTerm { term: t, pos },
env
Expand Down
7 changes: 7 additions & 0 deletions core/tests/integration/inputs/adts/deep_seq_enum.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# test.type = 'error'
#
# [test.metadata]
# error = 'EvalError::BlameError'

# Check that deep_seq correctly evaluates the content of an enum variant
%deep_seq% ('Foo 5 | [| 'Foo String |]) null
7 changes: 7 additions & 0 deletions core/tests/integration/inputs/adts/force_enum.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# test.type = 'error'
#
# [test.metadata]
# error = 'EvalError::BlameError'

# Check that force correctly evaluates the content of an enum variant
%force% ('Foo 5 | [| 'Foo String |])
Loading