Dump roc checkmate

This commit is contained in:
Ayaz Hafiz 2023-07-16 15:01:00 -05:00
parent 1282110ef5
commit fcd733e1df
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
8 changed files with 119 additions and 10 deletions

View file

@ -12,6 +12,7 @@ roc_checkmate_schema = { path = "../checkmate_schema" }
roc_module = { path = "../module" }
roc_solve_schema = { path = "../solve_schema" }
roc_types = { path = "../types" }
chrono.workspace = true
[build-dependencies]
roc_checkmate_schema = { path = "../checkmate_schema" }

View file

@ -1,3 +1,5 @@
use std::error::Error;
use roc_checkmate_schema::{AllEvents, Event, VariableEvent};
use roc_types::subs as s;
@ -105,6 +107,11 @@ impl Collector {
self.current_event_path.pop();
}
pub fn write(&self, writer: impl std::io::Write) -> Result<(), Box<dyn Error>> {
self.events.write(writer)?;
Ok(())
}
fn add_event(&mut self, event: impl Into<Event>) {
let mut event = event.into();
let is_appendable = EventW::Sub(&mut event).appendable();

View file

@ -27,6 +27,26 @@ macro_rules! debug_checkmate {
};
}
#[macro_export]
macro_rules! dump_checkmate {
($opt_collector:expr) => {
#[cfg(debug_assertions)]
{
if let Some(cm) = $opt_collector.as_ref() {
$crate::dump_checkmate(cm);
}
}
};
}
pub fn dump_checkmate(collector: &Collector) {
let timestamp = chrono::Utc::now().format("%Y%m%d_%H%M%S");
let filename = format!("checkmate_{timestamp}.json");
let fi = std::fs::File::create(&filename).unwrap();
collector.write(fi).unwrap();
eprintln!("Wrote checkmate output to {filename}");
}
#[macro_export]
macro_rules! with_checkmate {
({ on => $on:expr, off => $off:expr, }) => {{

View file

@ -229,4 +229,8 @@ impl AllEvents {
pub fn schema() -> RootSchema {
schema_for!(AllEvents)
}
pub fn write(&self, writer: impl std::io::Write) -> Result<(), serde_json::Error> {
serde_json::to_writer(writer, self)
}
}

View file

@ -3244,6 +3244,8 @@ fn finish(
let exposed_values = exposed_vars_by_symbol.iter().map(|x| x.0).collect();
roc_checkmate::dump_checkmate!(checkmate);
LoadedModule {
module_id: state.root_id,
interns,
@ -3261,9 +3263,6 @@ fn finish(
timings: state.timings,
docs_by_module: documentation,
abilities_store,
#[cfg(debug_assertions)]
checkmate,
}
}

View file

@ -46,9 +46,6 @@ pub struct LoadedModule {
pub timings: MutMap<ModuleId, ModuleTiming>,
pub docs_by_module: VecMap<ModuleId, ModuleDocumentation>,
pub abilities_store: AbilitiesStore,
#[cfg(debug_assertions)]
pub checkmate: Option<roc_checkmate::Collector>,
}
impl LoadedModule {