Skip to main content

dada_ir_sym/check/debug/
export.rs

1//! Prepare the debug log for export as JSON.
2
3use std::{borrow::Cow, panic::Location};
4
5use serde::Serialize;
6
7use crate::ir::indices::InferVarIndex;
8
9#[derive(Serialize, Debug)]
10pub struct Log<'a> {
11    pub events_flat: Vec<Event<'a>>,
12    pub nested_event: NestedEvent,
13    pub infers: Vec<Infer>,
14    pub tasks: Vec<Task>,
15    // New fields
16    pub root_event_info: RootEventInfo<'a>,
17    pub total_events: usize,
18}
19
20// New structure to hold detailed root event information
21#[derive(Serialize, Debug)]
22pub struct RootEventInfo<'a> {
23    pub compiler_location: CompilerLocation<'a>,
24    pub description: String,
25}
26
27#[derive(Serialize, Debug)]
28pub struct Event<'a> {
29    /// Where in the Rust source...
30    pub compiler_location: CompilerLocation<'a>,
31
32    /// Task in which this event occurred.
33    pub task: TaskId,
34
35    /// Kind of event.
36    pub kind: &'a str,
37
38    /// Embedded JSON containing the value.
39    pub value: Cow<'a, str>,
40
41    /// If this event spawns a task, this is its id.
42    pub spawns: Option<TaskId>,
43
44    /// If this event describes creation/change to an inference variable, this is its id.
45    pub infer: Option<InferVarIndex>,
46}
47
48#[derive(Serialize, Debug)]
49pub struct CompilerLocation<'a> {
50    pub file: &'a str,
51    pub line: u32,
52    pub column: u32,
53}
54
55impl<'a> From<&'a Location<'a>> for CompilerLocation<'a> {
56    fn from(location: &'a Location<'a>) -> Self {
57        Self {
58            file: location.file(),
59            line: location.line(),
60            column: location.column(),
61        }
62    }
63}
64
65#[derive(Copy, Clone, Serialize, Debug)]
66pub struct TimeStamp {
67    pub index: usize,
68}
69
70#[derive(Serialize, Debug)]
71pub struct Task {
72    pub spawned_at: TimeStamp,
73    pub description: String,
74    pub events: Vec<TimeStamp>,
75}
76
77#[derive(Copy, Clone, Debug, Serialize)]
78pub struct TaskId {
79    pub index: usize,
80}
81
82#[derive(Serialize, Debug)]
83pub struct NestedEvent {
84    /// Index for this event in the "event by time" list
85    pub timestamp: TimeStamp,
86
87    /// "Children" events are either (a) the indented events,
88    /// if this is an indent, or (b) the events from the
89    /// spawned task, if this is a spawn.
90    pub children: Vec<NestedEvent>,
91}
92
93#[derive(Copy, Clone, Serialize, Debug)]
94pub struct InferId {
95    pub index: usize,
96}
97
98/// Information about an inference variable
99#[derive(Serialize, Debug)]
100pub struct Infer {
101    /// Location of the event that created the value of the variable
102    pub created_at: TimeStamp,
103
104    /// Location of each event that modified the value of the variable
105    pub events: Vec<TimeStamp>,
106}