mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Push checkmate through env
This commit is contained in:
parent
8097ee3342
commit
87d108eccc
16 changed files with 190 additions and 29 deletions
|
@ -24,7 +24,7 @@ impl Collector {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn unify(&mut self, subs: &s::Subs, to: s::Variable, from: s::Variable) {
|
||||
pub fn unify(&mut self, subs: &s::Subs, from: s::Variable, to: s::Variable) {
|
||||
let to = to.as_schema(subs);
|
||||
let from = from.as_schema(subs);
|
||||
self.add_event(VariableEvent::Unify { to, from });
|
||||
|
@ -61,7 +61,7 @@ impl Collector {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn start_unification(&mut self, subs: &s::Subs, left: &s::Variable, right: &s::Variable) {
|
||||
pub fn start_unification(&mut self, subs: &s::Subs, left: s::Variable, right: s::Variable) {
|
||||
let left = left.as_schema(subs);
|
||||
let right = right.as_schema(subs);
|
||||
// TODO add mode
|
||||
|
@ -72,11 +72,32 @@ impl Collector {
|
|||
right,
|
||||
mode,
|
||||
subevents,
|
||||
success: None,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn end_unification(&mut self) {
|
||||
pub fn end_unification(
|
||||
&mut self,
|
||||
subs: &s::Subs,
|
||||
left: s::Variable,
|
||||
right: s::Variable,
|
||||
success: bool,
|
||||
) {
|
||||
let current_event = self.get_path_event();
|
||||
match current_event {
|
||||
Event::Unification {
|
||||
left: l,
|
||||
right: r,
|
||||
success: s,
|
||||
..
|
||||
} => {
|
||||
assert_eq!(left.as_schema(subs), *l);
|
||||
assert_eq!(right.as_schema(subs), *r);
|
||||
assert!(s.is_none());
|
||||
*s = Some(success);
|
||||
}
|
||||
_ => panic!("end_unification called when not in a unification"),
|
||||
}
|
||||
assert!(matches!(current_event, Event::Unification { .. }));
|
||||
self.current_event_path.pop();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,39 @@ mod schema;
|
|||
pub use collector::Collector;
|
||||
|
||||
pub fn is_checkmate_enabled() -> bool {
|
||||
let flag = std::env::var("ROC_CHECKMATE");
|
||||
flag.as_deref() == Ok("1")
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
let flag = std::env::var("ROC_CHECKMATE");
|
||||
flag.as_deref() == Ok("1")
|
||||
}
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! debug_checkmate {
|
||||
($opt_collector:expr, $cm:ident => $expr:expr) => {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
if let Some($cm) = $opt_collector.as_mut() {
|
||||
$expr
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! with_checkmate {
|
||||
($opt_collector:expr, { on => $on:expr, off => $off:expr, }) => {{
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
$on
|
||||
}
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
$off
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use serde::Serialize;
|
|||
#[derive(Serialize)]
|
||||
pub enum Constraint {}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[derive(Serialize, Debug, PartialEq)]
|
||||
pub struct Variable(pub u32);
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
@ -197,6 +197,7 @@ pub enum Event {
|
|||
left: Variable,
|
||||
right: Variable,
|
||||
mode: UnificationMode,
|
||||
success: Option<bool>,
|
||||
subevents: Vec<Event>,
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue