Skip to content

Commit

Permalink
upgrade to the newest salsa
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Apr 5, 2024
1 parent f4e2dd9 commit a99993a
Show file tree
Hide file tree
Showing 18 changed files with 173 additions and 102 deletions.
167 changes: 110 additions & 57 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions components/dada-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ pub struct Db {
storage: salsa::Storage<Self>,
}

impl salsa::Database for Db {
fn salsa_runtime(&self) -> &salsa::Runtime {
self.storage.runtime()
}
}
impl salsa::Database for Db {}

impl salsa::ParallelDatabase for Db {
fn snapshot(&self) -> salsa::Snapshot<Self> {
Expand All @@ -49,7 +45,7 @@ impl Db {

/// Set the breakpoints within the given file where the interpreter stops and executes callbacks.
pub fn set_breakpoints(&mut self, input_file: InputFile, locations: Vec<LineColumn>) {
input_file.set_breakpoint_locations(self, locations);
input_file.set_breakpoint_locations(self).to(locations);
}

/// Checks `input_file` for compilation errors and returns all relevant diagnostics.
Expand Down
2 changes: 1 addition & 1 deletion components/dada-id/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub mod prelude {
}

/// This module is used by the `tables` macro.
#[allow(non_camel_case_types)]
pub mod table_types {
#![allow(non_camel_case_types)]
pub type alloc<K, V> = crate::alloc_table::AllocTable<K, V>;
pub type intern<K, V> = crate::intern_table::InternTable<K, V>;
}
Expand Down
9 changes: 5 additions & 4 deletions components/dada-ir/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ use crate::{
};

#[salsa::tracked]
#[customize(DebugWithDb)]
pub struct Class {
#[id]
name: Word,
pub name: Word,

input_file: InputFile,
pub input_file: InputFile,

#[return_ref]
signature_syntax: syntax::Signature,
pub signature_syntax: syntax::Signature,

/// Overall span of the class (including any body)
span: Span,
pub span: Span,
}

impl Class {
Expand Down
11 changes: 6 additions & 5 deletions components/dada-ir/src/code/bir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,24 @@ use salsa::DebugWithDb;
use super::{syntax, validated};

#[salsa::tracked]
#[customize(DebugWithDb)]
pub struct Bir {
/// Name of file containing the code from which this Bir was created.
input_file: InputFile,
pub input_file: InputFile,

/// Name of function containing the code from which this Bir was created.
function_name: Word,
pub function_name: Word,

/// Syntax tree from which this Bir was created.
syntax_tree: syntax::Tree,
pub syntax_tree: syntax::Tree,

/// The BIR bir
#[return_ref]
data: BirData,
pub data: BirData,

/// Origins of expr in the BIR. Used to trace back to a source span.
#[return_ref]
origins: Origins,
pub origins: Origins,
}

impl Anchored for Bir {
Expand Down
7 changes: 4 additions & 3 deletions components/dada-ir/src/code/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,19 @@ pub enum GenericParameter {
/// The "syntax tree" is the parsed form of a function body.
/// It maps more-or-less directly to what the user typed.
#[salsa::tracked]
#[customize(DebugWithDb)]
pub struct Tree {
/// Identifies the root expression in the function body.
#[return_ref]
data: TreeData,
pub data: TreeData,

/// Interning tables for expressions and the like.
#[return_ref]
tables: Tables,
pub tables: Tables,

/// The span information for each node in the tree.
#[return_ref]
spans: Spans,
pub spans: Spans,
}

impl DebugWithDb<dyn crate::Db> for Tree {
Expand Down
7 changes: 4 additions & 3 deletions components/dada-ir/src/code/validated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ use super::syntax;

/// The "validated" form of a particular [syntax tree](`crate::code::syntax::Tree`).
#[salsa::tracked]
#[customize(DebugWithDb)]
pub struct Tree {
/// The function that this tree is associated with.
function: Function,
pub function: Function,

#[return_ref]
data: TreeData,
pub data: TreeData,

#[return_ref]
origins: Origins,
pub origins: Origins,
}

impl DebugWithDb<dyn crate::Db + '_> for Tree {
Expand Down
4 changes: 3 additions & 1 deletion components/dada-ir/src/format_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use crate::{token_tree::TokenTree, word::Word};

#[salsa::interned]
#[customize(DebugWithDb)]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[allow(clippy::len_without_is_empty)]
pub struct FormatString {
Expand All @@ -28,8 +29,9 @@ impl salsa::DebugWithDb<dyn crate::Db + '_> for FormatString {
}

#[salsa::interned]
#[customize(DebugWithDb)]
pub struct FormatStringSection {
data: FormatStringSectionData,
pub data: FormatStringSectionData,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
Expand Down
11 changes: 6 additions & 5 deletions components/dada-ir/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ use crate::{
};

#[salsa::tracked]
#[customize(DebugWithDb)]
pub struct Function {
#[id]
name: Word,
pub name: Word,

input_file: InputFile,
pub input_file: InputFile,

/// The function signature.
#[return_ref]
signature_syntax: FunctionSignature,
pub signature_syntax: FunctionSignature,

/// The body and parameters of functions are only parsed
/// on demand by invoking (e.g.) `syntax_tree` from the
Expand All @@ -30,10 +31,10 @@ pub struct Function {
/// been parsed must be specified explicitly by the
/// creator of the function. This is used for synthesizing
/// a 'main' function from a module, for example.
unparsed_code: Option<UnparsedCode>,
pub unparsed_code: Option<UnparsedCode>,

/// Overall span of the function (including the code)
span: Span,
pub span: Span,
}

#[derive(Clone, PartialEq, Eq, Debug)]
Expand Down
8 changes: 8 additions & 0 deletions components/dada-ir/src/in_ir_db.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
use salsa::database::AsSalsaDatabase;

pub struct InIrDb<'me, T: ?Sized> {
this: &'me T,
db: &'me dyn crate::Db,
}

impl<T: ?Sized> AsSalsaDatabase for InIrDb<'_, T> {
fn as_salsa_database(&self) -> &dyn salsa::Database {
self.db.as_salsa_database()
}
}

impl<'me, T> InIrDb<'me, T> {
pub fn db(&self) -> &'me dyn crate::Db {
self.db
Expand Down
7 changes: 4 additions & 3 deletions components/dada-ir/src/input_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ use crate::{
};

#[salsa::input]
#[customize(DebugWithDb)]
pub struct InputFile {
name: Word,
pub name: Word,

/// The raw contents of this input file, as a string.
#[return_ref]
source_text: String,
pub source_text: String,

/// The locations of any breakpoints set in this file.
#[return_ref]
breakpoint_locations: Vec<LineColumn>,
pub breakpoint_locations: Vec<LineColumn>,
}

impl InputFile {
Expand Down
7 changes: 4 additions & 3 deletions components/dada-ir/src/source_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ use crate::{input_file::InputFile, item::Item};
#[salsa::tracked]
/// The result of parsing an input file like `foo.dada`, or the
/// value from the playground. A program is a collection of files.
#[customize(DebugWithDb)]
pub struct SourceFile {
#[id]
input_file: InputFile,
pub input_file: InputFile,

/// The items found in the file.
#[return_ref]
items: Vec<Item>,
pub items: Vec<Item>,

/// Top-level "main" function from this file (if any).
/// This function will also be present in `items`.
///
/// This is not a function declaed with `fn` but rather just
/// code the user added at the top of the file.
main_fn: Option<Function>,
pub main_fn: Option<Function>,
}

pub const TOP_LEVEL_FN: &str = "builtin@main";
Expand Down
7 changes: 4 additions & 3 deletions components/dada-ir/src/token_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ use crate::{
};

#[salsa::tracked]
#[customize(DebugWithDb)]
pub struct TokenTree {
input_file: InputFile,
span: Span,
pub input_file: InputFile,
pub span: Span,
#[return_ref]
tokens: Vec<Token>,
pub tokens: Vec<Token>,
}

impl Anchored for TokenTree {
Expand Down
2 changes: 2 additions & 0 deletions components/dada-ir/src/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use salsa::DebugWithDb;

#[salsa::interned]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[customize(DebugWithDb)]
pub struct Word {
#[return_ref]
pub string: String,
Expand Down Expand Up @@ -34,6 +35,7 @@ impl DebugWithDb<dyn crate::Db + '_> for Word {

#[salsa::interned]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[customize(DebugWithDb)]
pub struct Words {
#[return_ref]
pub elements: Vec<Word>,
Expand Down
2 changes: 1 addition & 1 deletion components/dada-lang/src/test_harness/heap_graph_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::test_harness::QueryKind;
use super::{Errors, Query};

impl super::Options {
#[tracing::instrument(level = "Debug", skip(self, db, errors))]
// #[tracing::instrument(level = "Debug", skip(self, db, errors))]
pub(super) async fn perform_heap_graph_query_on_db(
&self,
db: &mut dada_db::Db,
Expand Down
4 changes: 2 additions & 2 deletions components/dada-lsp/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl LspServerDatabase {
pub fn did_open(&mut self, params: DidOpenTextDocumentParams) {
let input_file = self.input_file_from_uri(&params.text_document.uri);
let source_text = params.text_document.text;
input_file.set_source_text(&mut self.db, source_text);
input_file.set_source_text(&mut self.db).to(source_text);
self.spawn_check(
params.text_document.uri,
params.text_document.version,
Expand All @@ -49,7 +49,7 @@ impl LspServerDatabase {
// Since we asked for Sync full, just grab all the text from params
let change = params.content_changes.into_iter().next().unwrap();
let source_text = change.text;
input_file.set_source_text(&mut self.db, source_text);
input_file.set_source_text(&mut self.db).to(source_text);
self.spawn_check(
params.text_document.uri,
params.text_document.version,
Expand Down
2 changes: 0 additions & 2 deletions components/dada-parse/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::string::ToString;

use crate::{
token_test::{AnyTree, TokenTest},
tokens::Tokens,
Expand Down
10 changes: 7 additions & 3 deletions components/dada-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,25 @@ impl DadaCompiler {
#[wasm_bindgen]
pub fn with_source_text(mut self, source_text: String) -> Self {
tracing::debug!("with_source_text: {source_text:?}");
self.input_file.set_source_text(&mut self.db, source_text);
self.input_file
.set_source_text(&mut self.db)
.to(source_text);
self
}

#[wasm_bindgen]
pub fn with_breakpoint(mut self, line0: u32, column0: u32) -> Self {
self.input_file
.set_breakpoint_locations(&mut self.db, vec![LineColumn::new0(line0, column0)]);
.set_breakpoint_locations(&mut self.db)
.to(vec![LineColumn::new0(line0, column0)]);
self
}

#[wasm_bindgen]
pub fn without_breakpoint(mut self) -> Self {
self.input_file
.set_breakpoint_locations(&mut self.db, vec![]);
.set_breakpoint_locations(&mut self.db)
.to(vec![]);
self
}

Expand Down

0 comments on commit a99993a

Please sign in to comment.