use crate::ast::Item;
macro_rules! unreachable_by_invariant {
($phase:ident) => {
unreachable!(
"The phase {} should make this unreachable",
stringify!($phase)
)
};
}
pub(crate) use unreachable_by_invariant;
pub trait Phase {
fn apply(&self, items: &mut Vec<Item>);
}
pub mod legacy;
mod explicit_monadic;
mod filter_unprintable_items;
mod reject_not_do_lean_dsl;
macro_rules! declare_phase_kind {
{$($name:ident = $phase:expr),*$(,)?} => {
#[derive(Clone, Debug, Copy, serde::Serialize, serde::Deserialize)]
pub enum PhaseKind {
$(
#[doc = concat!("The phase [`", stringify!($phase), "].")]
$name,
)*
Legacy(crate::phase::legacy::LegacyOCamlPhase),
}
impl crate::phase::Phase for PhaseKind {
fn apply(&self, items: &mut Vec<Item>) {
match *self {
$(Self::$name => $phase.apply(items),)*
Self::Legacy(phase) => phase.apply(items),
}
}
}
};
}
declare_phase_kind! {
ExplicitMonadic = explicit_monadic::ExplicitMonadic,
RejectNotDoLeanDSL = reject_not_do_lean_dsl::RejectNotDoLeanDSL,
FilterUnprintableItems = filter_unprintable_items::FilterUnprintableItems,
}