mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
Dump roc checkmate
This commit is contained in:
parent
1282110ef5
commit
fcd733e1df
8 changed files with 119 additions and 10 deletions
|
@ -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" }
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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, }) => {{
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue