Skip to content

Commit a9b68f8

Browse files
authored
Merge pull request #1033 from sbillig/salsa-update
salsa 3.0
2 parents d657932 + f662719 commit a9b68f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+543
-669
lines changed

Cargo.lock

Lines changed: 36 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ resolver = "2"
55
[profile.dev.package.solc]
66
opt-level = 3
77

8+
[workspace.dependencies]
9+
salsa = { git = "https://github.com/salsa-rs/salsa", rev = "e4d65a656fc68d0fb759b292ceae2aff2c785c5d" }
10+
811
[profile.dev]
912
# Set to 0 to make the build faster and debugging more difficult.
1013
debug = 1

crates/common2/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ description = "Provides HIR definition and lowering for Fe lang."
1313
semver = "1.0.17"
1414
camino = "1.1.4"
1515
smol_str = "0.1.24"
16-
salsa = { git = "https://github.com/salsa-rs/salsa", rev = "a1bf3a6" }
16+
salsa.workspace = true
1717
indexmap = "2.2"
1818
parser = { path = "../parser2", package = "fe-parser2" }
19+
paste = "1.0.15"

crates/common2/src/indexmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{
33
ops::{Deref, DerefMut},
44
};
55

6-
use salsa::update::Update;
6+
use salsa::Update;
77

88
#[derive(Debug, Clone)]
99
pub struct IndexMap<K, V, S = RandomState>(indexmap::IndexMap<K, V, S>);

crates/common2/src/input.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use camino::Utf8PathBuf;
2+
use salsa::Setter;
23
use smol_str::SmolStr;
34

45
use crate::{indexmap::IndexSet, InputDb};
@@ -74,9 +75,6 @@ impl InputIngot {
7475

7576
#[salsa::input]
7677
pub struct InputFile {
77-
/// A ingot id which the file belongs to.
78-
pub ingot: InputIngot,
79-
8078
/// A path to the file from the ingot root directory.
8179
#[return_ref]
8280
pub path: Utf8PathBuf,
@@ -86,8 +84,8 @@ pub struct InputFile {
8684
}
8785

8886
impl InputFile {
89-
pub fn abs_path(&self, db: &dyn InputDb) -> Utf8PathBuf {
90-
self.ingot(db).path(db).join(self.path(db))
87+
pub fn abs_path(&self, db: &dyn InputDb, ingot: InputIngot) -> Utf8PathBuf {
88+
ingot.path(db).join(self.path(db))
9189
}
9290
}
9391

crates/common2/src/lib.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
pub mod diagnostics;
22
pub mod indexmap;
33
pub mod input;
4-
54
pub use input::{InputFile, InputIngot};
65

7-
#[salsa::jar(db = InputDb)]
8-
pub struct Jar(InputIngot, InputFile);
6+
#[salsa::db]
7+
pub trait InputDb: salsa::Database {
8+
fn as_input_db(&self) -> &dyn InputDb;
9+
}
10+
11+
#[doc(hidden)]
12+
pub use paste::paste;
13+
14+
#[macro_export]
15+
macro_rules! impl_db_traits {
16+
($db_type:ty, $($trait_name:ident),+ $(,)?) => {
17+
#[salsa::db]
18+
impl salsa::Database for $db_type {
19+
fn salsa_event(&self, _event: &dyn Fn() -> salsa::Event) {}
20+
}
921

10-
pub trait InputDb: salsa::DbWithJar<Jar> {
11-
fn as_input_db(&self) -> &dyn InputDb {
12-
<Self as salsa::DbWithJar<Jar>>::as_jar_db::<'_>(self)
13-
}
22+
$(
23+
$crate::paste! {
24+
#[salsa::db]
25+
impl $trait_name for $db_type {
26+
fn [<as_ $trait_name:snake>](&self) -> &dyn $trait_name {
27+
self
28+
}
29+
}
30+
}
31+
)+
32+
};
1433
}
15-
impl<DB> InputDb for DB where DB: ?Sized + salsa::DbWithJar<Jar> {}

crates/driver2/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ description = "Provides Fe driver"
1010
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1111

1212
[dependencies]
13-
salsa = { git = "https://github.com/salsa-rs/salsa", rev = "a1bf3a6" }
13+
salsa.workspace = true
1414
codespan-reporting = "0.11"
1515

1616
hir = { path = "../hir", package = "fe-hir" }

crates/driver2/src/lib.rs

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use codespan_reporting::term::{
88
};
99
use common::{
1010
diagnostics::CompleteDiagnostic,
11+
impl_db_traits,
1112
indexmap::IndexSet,
1213
input::{IngotKind, Version},
1314
InputDb, InputFile, InputIngot,
@@ -28,31 +29,27 @@ use hir_analysis::{
2829

2930
use crate::diagnostics::ToCsDiag;
3031

31-
#[salsa::jar(db = DriverDb)]
32-
pub struct Jar(diagnostics::file_line_starts);
33-
32+
#[salsa::db]
3433
pub trait DriverDb:
35-
salsa::DbWithJar<Jar> + HirAnalysisDb + HirDb + LowerHirDb + SpannedHirDb + InputDb
36-
{
37-
}
38-
39-
impl<DB> DriverDb for DB where
40-
DB: salsa::DbWithJar<Jar> + HirAnalysisDb + HirDb + LowerHirDb + SpannedHirDb + InputDb
34+
salsa::Database + HirAnalysisDb + HirDb + LowerHirDb + SpannedHirDb + InputDb
4135
{
36+
fn as_driver_db(&self) -> &dyn DriverDb;
4237
}
4338

44-
#[derive(Default)]
45-
#[salsa::db(
46-
common::Jar,
47-
hir::Jar,
48-
hir::LowerJar,
49-
hir::SpannedJar,
50-
hir_analysis::Jar,
51-
Jar
52-
)]
39+
#[derive(Default, Clone)]
40+
#[salsa::db]
5341
pub struct DriverDataBase {
5442
storage: salsa::Storage<Self>,
5543
}
44+
impl_db_traits!(
45+
DriverDataBase,
46+
InputDb,
47+
HirDb,
48+
LowerHirDb,
49+
SpannedHirDb,
50+
HirAnalysisDb,
51+
DriverDb
52+
);
5653

5754
impl DriverDataBase {
5855
// TODO: An temporary implementation for ui testing.
@@ -72,7 +69,7 @@ impl DriverDataBase {
7269
DiagnosticsCollection(pass_manager.run_on_module(top_mod))
7370
}
7471

75-
pub fn standalone(&mut self, file_path: &path::Path, source: &str) -> InputFile {
72+
pub fn standalone(&mut self, file_path: &path::Path, source: &str) -> (InputIngot, InputFile) {
7673
let kind = IngotKind::StandAlone;
7774

7875
// We set the ingot version to 0.0.0 for stand-alone file.
@@ -87,21 +84,17 @@ impl DriverDataBase {
8784
);
8885

8986
let file_name = root_file.file_name().unwrap().to_str().unwrap();
90-
let input_file = InputFile::new(self, ingot, file_name.into(), source.to_string());
87+
let input_file = InputFile::new(self, file_name.into(), source.to_string());
9188
ingot.set_root_file(self, input_file);
9289
ingot.set_files(self, [input_file].into_iter().collect());
93-
input_file
90+
(ingot, input_file)
9491
}
9592

96-
pub fn top_mod(&self, input: InputFile) -> TopLevelMod {
97-
map_file_to_mod(self, input)
93+
pub fn top_mod(&self, ingot: InputIngot, input: InputFile) -> TopLevelMod {
94+
map_file_to_mod(self, ingot, input)
9895
}
9996
}
10097

101-
impl salsa::Database for DriverDataBase {
102-
fn salsa_event(&self, _: salsa::Event) {}
103-
}
104-
10598
pub struct DiagnosticsCollection<'db>(Vec<Box<dyn DiagnosticVoucher<'db> + 'db>>);
10699
impl<'db> DiagnosticsCollection<'db> {
107100
pub fn emit(&self, db: &'db DriverDataBase) {

crates/driver2/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ pub fn main() {
2424
let source = std::fs::read_to_string(&args.file_path).unwrap();
2525

2626
let mut db = DriverDataBase::default();
27-
let input_file = db.standalone(path, &source);
28-
let top_mod = db.top_mod(input_file);
27+
let (ingot, file) = db.standalone(path, &source);
28+
let top_mod = db.top_mod(ingot, file);
2929
let diags = db.run_on_top_mod(top_mod);
3030
diags.emit(&db);
3131

crates/hir-analysis/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repository = "https://github.com/ethereum/fe"
88
description = "Provides HIR semantic analysis for Fe lang"
99

1010
[dependencies]
11-
salsa = { git = "https://github.com/salsa-rs/salsa", rev = "a1bf3a6" }
11+
salsa.workspace = true
1212
smallvec = "1.10"
1313
rustc-hash = "1.1.0"
1414
either = "1.8"

0 commit comments

Comments
 (0)