Skip to main content

dada_ir_ast/
lib.rs

1#![allow(clippy::unused_unit)] // FIXME: salsa bug it seems
2
3use std::sync::mpsc::Sender;
4
5use ast::Identifier;
6use diagnostic::Diagnostic;
7use inputs::{CompilationRoot, Krate, SourceFile};
8use span::AbsoluteOffset;
9use url::Url;
10
11#[macro_use]
12mod macro_rules;
13
14pub mod ast;
15pub mod diagnostic;
16pub mod inputs;
17pub mod span;
18
19#[salsa::db]
20pub trait Db: salsa::Database {
21    /// Access the [`CompilationRoot`], from which all crates and sources can be reached.
22    fn root(&self) -> CompilationRoot;
23
24    /// Load a source-file from the given directory.
25    /// The modules is a list of parent modules that translates to a file path.
26    fn source_file<'db>(&'db self, krate: Krate, modules: &[Identifier<'db>]) -> SourceFile;
27
28    /// Convert the url into a string suitable for showing the user.
29    fn url_display(&self, url: &Url) -> String;
30
31    /// Controls whether type-checking and other parts of the compiler will dump debug logs.
32    /// If `None` is returned, no debugging output is emitted.
33    /// If `Some` is returned, it should supply a directory where `.json` files will be created.
34    /// The `dada_debug` crate will monitor this directory
35    /// and serve up the information for use in debugging.
36    fn debug_tx(&self) -> Option<Sender<DebugEvent>>;
37}
38
39/// A debug event
40pub struct DebugEvent {
41    /// URL from the source code the event is associated with
42    pub url: Url,
43
44    /// Start of span from the source code the event is associated with
45    pub start: AbsoluteOffset,
46
47    /// End of span from the source code the event is associated with
48    pub end: AbsoluteOffset,
49
50    /// Data associated with the event
51    pub payload: DebugEventPayload,
52}
53
54/// ata associated with debug events
55pub enum DebugEventPayload {
56    /// A diagnostic was reported
57    Diagnostic(Diagnostic),
58
59    /// A log of the results from type-checking the code at the given url.
60    /// The payload will be a `dada_ir_sym::check::debug::export::Log`.
61    CheckLog(serde_json::Value),
62}