Skip to content

Commit bd3ebfd

Browse files
authored
Merge pull request #390 from yeslogic/prim-step-tweaks
Always return a function from prim_step
2 parents 3ae5a29 + 2e11566 commit bd3ebfd

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

fathom/src/core/semantics.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,10 @@ type PrimStep = for<'arena> fn(&ElimEnv<'arena, '_>, &[Elim<'arena>]) -> Option<
403403

404404
macro_rules! step {
405405
($env:pat, [$($input:pat),*] => $output:expr) => {
406-
Some(|$env, spine| match spine {
406+
|$env, spine| match spine {
407407
[$(Elim::FunApp($input)),*] => Some($output),
408408
_ => return None,
409-
})
409+
}
410410
};
411411
}
412412

@@ -428,7 +428,7 @@ macro_rules! const_step {
428428

429429
/// Returns an evaluation step for a primitive, if there is one defined.
430430
#[rustfmt::skip]
431-
fn prim_step(prim: Prim) -> Option<PrimStep> {
431+
fn prim_step(prim: Prim) -> PrimStep {
432432
use std::ops::{BitAnd, BitOr, BitXor, Not};
433433
use std::convert::TryFrom;
434434

@@ -614,7 +614,7 @@ fn prim_step(prim: Prim) -> Option<PrimStep> {
614614
Prim::PosAddU32 => const_step!([x: Pos, y: U32] => Const::Pos(usize::checked_add(*x, usize::try_from(*y).ok()?)?)),
615615
Prim::PosAddU64 => const_step!([x: Pos, y: U64] => Const::Pos(usize::checked_add(*x, usize::try_from(*y).ok()?)?)),
616616

617-
_ => None,
617+
_ => |_, _| None,
618618
}
619619
}
620620

@@ -734,9 +734,7 @@ impl<'arena, 'env> ElimEnv<'arena, 'env> {
734734
spine.push(Elim::FunApp(input_expr));
735735

736736
match head {
737-
Head::Prim(prim) => prim_step(*prim)
738-
.and_then(|step| step(self, spine))
739-
.unwrap_or(head_expr),
737+
Head::Prim(prim) => prim_step(*prim)(self, spine).unwrap_or(head_expr),
740738
_ => head_expr,
741739
}
742740
}

0 commit comments

Comments
 (0)