Skip to main content

Compiler

Struct Compiler 

Source
pub struct Compiler {
    pub(crate) storage: Storage<Self>,
    pub(crate) inputs: Arc<Mutex<Inputs>>,
    pub(crate) vfs: Arc<dyn VirtualFileSystem>,
    pub(crate) debug_tx: Option<Sender<DebugEvent>>,
}

Fields§

§storage: Storage<Self>§inputs: Arc<Mutex<Inputs>>

Extra information about our inputs that the rest of Dada compiler doesn’t have to know (e.g., they’re URL etc).

This is behind a mutex but we have an invariant that we only modify things in the mutex if we have &mut access to the compiler.

§vfs: Arc<dyn VirtualFileSystem>

Mediates all access to the file system.

§debug_tx: Option<Sender<DebugEvent>>

Directory where debug logs are written.

Implementations§

Source§

impl Compiler

Source

pub fn new( vfs: impl VirtualFileSystem, debug_tx: Option<Sender<DebugEvent>>, ) -> Self

Source

pub fn fork(&self) -> Fork<Self>

Create a “fork” of the compiler that has only &self access. This is meant to be used from another thread.

Source

pub fn load_source_file( &mut self, source_url: &(impl ToUrl + ?Sized), ) -> Fallible<SourceFile>

Load the contents of source_url and then open it with those contents.

Source

pub fn open_source_file( &mut self, source_url: &(impl ToUrl + ?Sized), contents: Result<String, String>, ) -> Fallible<SourceFile>

“Open” a source file with the given contents. This will find an existing SourceFile if one exists and update its content. If none exists, a new SourceFile will be created and the containing crate will be added.

Source

pub fn get_previously_opened_source_file( &mut self, source_url: &(impl ToUrl + ?Sized), ) -> Fallible<SourceFile>

Get the SourceFile for the given path. Errors if no source file was opened yet.

Source

pub fn add_crate_containing_source_file( &mut self, source_url: &Url, ) -> Fallible<Krate>

Given a .dada file, finds the enclosing crate and adds it into the list of crates. Given some path a/b/c.dada, we decide that c is a submodule of a/b if there exists a a/b.dada; otherwise, c is considered a crate of its own.

Source

pub fn add_crate_with_root_path(&mut self, root_url: &Url) -> Fallible<Krate>

Add a crate that is rooted in the given dada file. The crate is named after the file name.

Source

pub fn codegen_main_fn(&self, source_file: SourceFile) -> &Option<Vec<u8>>

Codegen the main function of a source file.

Source

pub fn check_all(&self, source_file: SourceFile) -> Vec<&Diagnostic>

Compute all diagnostics for a source file.

Source

pub fn probe_variable_type(&self, span: AbsoluteSpan) -> Option<String>

Return type of the variable found at the given span or None if there is no variable there.

Source

pub fn probe_expression_type(&self, span: AbsoluteSpan) -> Option<String>

Return type of the variable found at the given span or None if there is no variable there.

Source

pub fn probe_ast(&self, span: AbsoluteSpan) -> Option<String>

Return compact AST representation of the expression at the given span.

Source

pub(crate) fn deduplicated(diagnostics: Vec<&Diagnostic>) -> Vec<&Diagnostic>

Source

pub fn fn_asts(&self, source_file: SourceFile) -> String

Source

pub fn root(&self) -> CompilationRoot

Access the [CompilationRoot], from which all crates and sources can be reached.

Source

pub(crate) fn add_crate( &mut self, crate_name: String, new_source: impl Into<KrateSource>, ) -> Fallible<Krate>

Add a crate named crate_name sourced at source into our list.

We can never have two crates with the same name. If a crate k named crate_name already exists, we check if k has the same source. If so, the existing crate is returned. Otherwise, an error results.

Source

pub(crate) fn get_source_file(&self, url: &Url) -> Option<SourceFile>

If there is a source file registered at path, return it. Else return None.

Source

pub(crate) fn get_or_create_source_file(&self, url: &Url) -> SourceFile

Get or create a source-file at a given path.

Trait Implementations§

Source§

impl Clone for Compiler

Source§

fn clone(&self) -> Compiler

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Database for Compiler

Source§

fn salsa_event(&self, event: &dyn Fn() -> Event)

This function is invoked by the salsa runtime at various points during execution. You can customize what happens by implementing the [UserData][] trait. By default, the event is logged at level debug using tracing facade. Read more
§

fn trigger_lru_eviction(&mut self)

Enforces current LRU limits, evicting entries if necessary. Read more
§

fn synthetic_write(&mut self, durability: Durability)

A “synthetic write” causes the system to act as though some input of durability durability has changed, triggering a new revision. This is mostly useful for profiling scenarios. Read more
§

fn report_untracked_read(&self)

Reports that the query depends on some state unknown to salsa. Read more
§

fn ingredient_debug_name( &self, ingredient_index: IngredientIndex, ) -> Cow<'_, str>

Return the “debug name” (i.e., the struct name, etc) for an “ingredient”, which are the fine-grained components we use to track data. This is intended for debugging and the contents of the returned string are not semver-guaranteed. Read more
§

fn unwind_if_revision_cancelled(&self)

Starts unwinding the stack if the current revision is cancelled. Read more
§

fn attach<R>(&self, op: impl FnOnce(&Self) -> R) -> R
where Self: Sized,

Execute op with the database in thread-local storage for debug print-outs.
Source§

impl Db for Compiler

Source§

fn url_display(&self, url: &Url) -> String

Convert the url into a string suitable for showing the user.
Source§

fn root(&self) -> CompilationRoot

Access the [CompilationRoot], from which all crates and sources can be reached.
Source§

fn source_file<'db>( &'db self, krate: Krate, modules: &[Identifier<'db>], ) -> SourceFile

Load a source-file from the given directory. The modules is a list of parent modules that translates to a file path.
Source§

fn debug_tx(&self) -> Option<Sender<DebugEvent>>

Controls whether type-checking and other parts of the compiler will dump debug logs. If None is returned, no debugging output is emitted. If Some is returned, it should supply a directory where .json files will be created. The dada_debug crate will monitor this directory and serve up the information for use in debugging.
Source§

impl HasStorage for Compiler

Source§

fn storage(&self) -> &Storage<Self>

Source§

fn storage_mut(&mut self) -> &mut Storage<Self>

Source§

impl Db for Compiler

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsDynDatabase for T
where T: Database,

§

fn as_dyn_database(&self) -> &(dyn Database + 'static)

§

fn as_dyn_database_mut(&mut self) -> &mut (dyn Database + 'static)

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Lookup<T> for T

§

fn into_owned(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ZalsaDatabase for T
where T: HasStorage,

§

fn zalsa(&self) -> &Zalsa

§

fn zalsa_mut(&mut self) -> &mut Zalsa

§

fn zalsa_local(&self) -> &ZalsaLocal

§

fn fork_db(&self) -> Box<dyn Database>

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T