Skip to content

Commit 5d3b756

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix_handle_flag_bug
2 parents 8b5cd48 + 4c8e52a commit 5d3b756

File tree

127 files changed

+2070
-2322
lines changed

Some content is hidden

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

127 files changed

+2070
-2322
lines changed

.github/workflows/test.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
- name: Format
5252
run: cargo fmt -- --check
5353
- name: Clippy
54-
run: cargo clippy --workspace --all-features --all-targets
54+
run: cargo clippy --workspace --all-features --all-targets -- -D warnings
5555
- name: Test
5656
run: cargo test --workspace --all-features --all-targets
5757
- name: Test docs
@@ -61,7 +61,6 @@ jobs:
6161

6262
miri:
6363
name: Miri
64-
continue-on-error: true # FIXME: https://github.com/salsa-rs/salsa/issues/520
6564
runs-on: ubuntu-latest
6665
steps:
6766
- name: Checkout

Cargo.toml

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ repository = "https://github.com/salsa-rs/salsa"
88
description = "A generic framework for on-demand, incrementalized computation (experimental)"
99

1010
[dependencies]
11-
arc-swap = "1.6.0"
12-
boomphf = "0.6.0"
13-
crossbeam = "0.8.1"
14-
dashmap = "6.0.1"
15-
hashlink = "0.9.1"
11+
arc-swap = "1"
12+
crossbeam = "0.8"
13+
dashmap = "6"
14+
hashlink = "0.9"
1615
indexmap = "2"
17-
orx-concurrent-vec = "2.2.0"
16+
orx-concurrent-vec = "2"
1817
tracing = "0.1"
19-
parking_lot = "0.12.1"
20-
rustc-hash = "2.0.0"
18+
parking_lot = "0.12"
19+
rustc-hash = "2"
2120
salsa-macro-rules = { version = "0.1.0", path = "components/salsa-macro-rules" }
2221
salsa-macros = { path = "components/salsa-macros" }
23-
smallvec = "1.0.0"
22+
smallvec = "1"
23+
lazy_static = "1"
2424

2525
[dev-dependencies]
2626
annotate-snippets = "0.11.4"
@@ -31,7 +31,7 @@ eyre = "0.6.8"
3131
notify-debouncer-mini = "0.4.1"
3232
ordered-float = "4.2.1"
3333
rustversion = "1.0"
34-
test-log = "0.2.11"
34+
test-log = { version ="0.2.11", features = ["trace"] }
3535
trybuild = "1.0"
3636

3737

benches/incremental.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn many_tracked_structs(criterion: &mut Criterion) {
2626
criterion.bench_function("many_tracked_structs", |b| {
2727
b.iter_batched_ref(
2828
|| {
29-
let db = salsa::default_database();
29+
let db = salsa::DatabaseImpl::new();
3030

3131
let input = Input::new(&db, 1_000);
3232
let input2 = Input::new(&db, 1);

components/salsa-macro-rules/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
mod macro_if;
1616
mod maybe_backdate;
1717
mod maybe_clone;
18+
mod maybe_default;
1819
mod setup_accumulator_impl;
1920
mod setup_input_struct;
2021
mod setup_interned_struct;

components/salsa-macro-rules/src/maybe_backdate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#[macro_export]
33
macro_rules! maybe_backdate {
44
(
5-
($maybe_clone:ident, no_backdate),
5+
($maybe_clone:ident, no_backdate, $maybe_default:ident),
66
$field_ty:ty,
77
$old_field_place:expr,
88
$new_field_place:expr,
@@ -20,7 +20,7 @@ macro_rules! maybe_backdate {
2020
};
2121

2222
(
23-
($maybe_clone:ident, backdate),
23+
($maybe_clone:ident, backdate, $maybe_default:ident),
2424
$field_ty:ty,
2525
$old_field_place:expr,
2626
$new_field_place:expr,

components/salsa-macro-rules/src/maybe_clone.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
#[macro_export]
55
macro_rules! maybe_clone {
66
(
7-
(no_clone, $maybe_backdate:ident),
7+
(no_clone, $maybe_backdate:ident, $maybe_default:ident),
88
$field_ty:ty,
99
$field_ref_expr:expr,
1010
) => {
1111
$field_ref_expr
1212
};
1313

1414
(
15-
(clone, $maybe_backdate:ident),
15+
(clone, $maybe_backdate:ident, $maybe_default:ident),
1616
$field_ty:ty,
1717
$field_ref_expr:expr,
1818
) => {
@@ -23,15 +23,15 @@ macro_rules! maybe_clone {
2323
#[macro_export]
2424
macro_rules! maybe_cloned_ty {
2525
(
26-
(no_clone, $maybe_backdate:ident),
26+
(no_clone, $maybe_backdate:ident, $maybe_default:ident),
2727
$db_lt:lifetime,
2828
$field_ty:ty
2929
) => {
3030
& $db_lt $field_ty
3131
};
3232

3333
(
34-
(clone, $maybe_backdate:ident),
34+
(clone, $maybe_backdate:ident, $maybe_default:ident),
3535
$db_lt:lifetime,
3636
$field_ty:ty
3737
) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/// Generate either `field_ref_expr` or `field_ty::default`
2+
///
3+
/// Used when generating an input's builder.
4+
#[macro_export]
5+
macro_rules! maybe_default {
6+
(
7+
($maybe_clone:ident, $maybe_backdate:ident, default),
8+
$field_ty:ty,
9+
$field_ref_expr:expr,
10+
) => {
11+
<$field_ty>::default()
12+
};
13+
14+
(
15+
($maybe_clone:ident, $maybe_backdate:ident, required),
16+
$field_ty:ty,
17+
$field_ref_expr:expr,
18+
) => {
19+
$field_ref_expr
20+
};
21+
}
22+
23+
#[macro_export]
24+
macro_rules! maybe_default_tt {
25+
(($maybe_clone:ident, $maybe_backdate:ident, default) => $($t:tt)*) => {
26+
$($t)*
27+
};
28+
29+
(($maybe_clone:ident, $maybe_backdate:ident, required) => $($t:tt)*) => {
30+
31+
};
32+
}

components/salsa-macro-rules/src/setup_accumulator_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ macro_rules! setup_accumulator_impl {
2424

2525
fn $ingredient(db: &dyn $zalsa::Database) -> &$zalsa_struct::IngredientImpl<$Struct> {
2626
$CACHE.get_or_create(db, || {
27-
db.add_or_lookup_jar_by_type(&<$zalsa_struct::JarImpl<$Struct>>::default())
27+
db.zalsa().add_or_lookup_jar_by_type(&<$zalsa_struct::JarImpl<$Struct>>::default())
2828
})
2929
}
3030

@@ -35,7 +35,7 @@ macro_rules! setup_accumulator_impl {
3535
where
3636
Db: ?Sized + $zalsa::Database,
3737
{
38-
let db = db.as_salsa_database();
38+
let db = db.as_dyn_database();
3939
$ingredient(db).push(db, self);
4040
}
4141
}

components/salsa-macro-rules/src/setup_input_struct.rs

+109-12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ macro_rules! setup_input_struct {
3232
// Indices for each field from 0..N -- must be unsuffixed (e.g., `0`, `1`).
3333
field_indices: [$($field_index:tt),*],
3434

35+
// Fields that are required (have no default value). Each item is the fields name and type.
36+
required_fields: [$($required_field_id:ident $required_field_ty:ty),*],
37+
38+
// Names for the field durability methods on the builder (typically `foo_durability`)
39+
field_durability_ids: [$($field_durability_id:ident),*],
40+
3541
// Number of fields
3642
num_fields: $N:literal,
3743

@@ -48,6 +54,7 @@ macro_rules! setup_input_struct {
4854
$zalsa:ident,
4955
$zalsa_struct:ident,
5056
$Configuration:ident,
57+
$Builder:ident,
5158
$CACHE:ident,
5259
$Db:ident,
5360
]
@@ -82,13 +89,15 @@ macro_rules! setup_input_struct {
8289
static CACHE: $zalsa::IngredientCache<$zalsa_struct::IngredientImpl<$Configuration>> =
8390
$zalsa::IngredientCache::new();
8491
CACHE.get_or_create(db, || {
85-
db.add_or_lookup_jar_by_type(&<$zalsa_struct::JarImpl<$Configuration>>::default())
92+
db.zalsa().add_or_lookup_jar_by_type(&<$zalsa_struct::JarImpl<$Configuration>>::default())
8693
})
8794
}
8895

8996
pub fn ingredient_mut(db: &mut dyn $zalsa::Database) -> (&mut $zalsa_struct::IngredientImpl<Self>, &mut $zalsa::Runtime) {
90-
let index = db.add_or_lookup_jar_by_type(&<$zalsa_struct::JarImpl<$Configuration>>::default());
91-
let (ingredient, runtime) = db.lookup_ingredient_mut(index);
97+
let zalsa_mut = db.zalsa_mut();
98+
let index = zalsa_mut.add_or_lookup_jar_by_type(&<$zalsa_struct::JarImpl<$Configuration>>::default());
99+
let current_revision = zalsa_mut.current_revision();
100+
let (ingredient, runtime) = zalsa_mut.lookup_ingredient_mut(index);
92101
let ingredient = ingredient.assert_type_mut::<$zalsa_struct::IngredientImpl<Self>>();
93102
(ingredient, runtime)
94103
}
@@ -121,14 +130,18 @@ macro_rules! setup_input_struct {
121130
}
122131

123132
impl $Struct {
124-
pub fn $new_fn<$Db>(db: &$Db, $($field_id: $field_ty),*) -> Self
133+
#[inline]
134+
pub fn $new_fn<$Db>(db: &$Db, $($required_field_id: $required_field_ty),*) -> Self
125135
where
126136
// FIXME(rust-lang/rust#65991): The `db` argument *should* have the type `dyn Database`
127137
$Db: ?Sized + salsa::Database,
128138
{
129-
let current_revision = $zalsa::current_revision(db);
130-
let stamps = $zalsa::Array::new([$zalsa::stamp(current_revision, Default::default()); $N]);
131-
$Configuration::ingredient(db.as_salsa_database()).new_input(($($field_id,)*), stamps)
139+
Self::builder($($required_field_id,)*).new(db)
140+
}
141+
142+
pub fn builder($($required_field_id: $required_field_ty),*) -> <Self as $zalsa_struct::HasBuilder>::Builder
143+
{
144+
builder::new_builder($($zalsa::maybe_default!($field_option, $field_ty, $field_id,)),*)
132145
}
133146

134147
$(
@@ -137,8 +150,8 @@ macro_rules! setup_input_struct {
137150
// FIXME(rust-lang/rust#65991): The `db` argument *should* have the type `dyn Database`
138151
$Db: ?Sized + $zalsa::Database,
139152
{
140-
let fields = $Configuration::ingredient(db.as_salsa_database()).field(
141-
db.as_salsa_database(),
153+
let fields = $Configuration::ingredient(db.as_dyn_database()).field(
154+
db.as_dyn_database(),
142155
self,
143156
$field_index,
144157
);
@@ -157,9 +170,9 @@ macro_rules! setup_input_struct {
157170
// FIXME(rust-lang/rust#65991): The `db` argument *should* have the type `dyn Database`
158171
$Db: ?Sized + $zalsa::Database,
159172
{
160-
let (ingredient, runtime) = $Configuration::ingredient_mut(db.as_salsa_database_mut());
173+
let (ingredient, revision) = $Configuration::ingredient_mut(db.as_dyn_database_mut());
161174
$zalsa::input::SetterImpl::new(
162-
runtime,
175+
revision,
163176
self,
164177
$field_index,
165178
ingredient,
@@ -174,7 +187,7 @@ macro_rules! setup_input_struct {
174187
// FIXME(rust-lang/rust#65991): The `db` argument *should* have the type `dyn Database`
175188
$Db: ?Sized + salsa::Database,
176189
{
177-
$Configuration::ingredient(db.as_salsa_database()).get_singleton_input()
190+
$Configuration::ingredient(db.as_dyn_database()).get_singleton_input()
178191
}
179192

180193
#[track_caller]
@@ -204,6 +217,90 @@ macro_rules! setup_input_struct {
204217
})
205218
}
206219
}
220+
221+
impl $zalsa_struct::HasBuilder for $Struct {
222+
type Builder = builder::$Builder;
223+
}
224+
225+
// Implement `new` here instead of inside the builder module
226+
// because $Configuration can't be named in `builder`.
227+
impl builder::$Builder {
228+
/// Creates the new input with the set values.
229+
#[must_use]
230+
pub fn new<$Db>(self, db: &$Db) -> $Struct
231+
where
232+
// FIXME(rust-lang/rust#65991): The `db` argument *should* have the type `dyn Database`
233+
$Db: ?Sized + salsa::Database
234+
{
235+
let current_revision = $zalsa::current_revision(db);
236+
let ingredient = $Configuration::ingredient(db.as_dyn_database());
237+
let (fields, stamps) = builder::builder_into_inner(self, current_revision);
238+
ingredient.new_input(fields, stamps)
239+
}
240+
}
241+
242+
mod builder {
243+
use super::*;
244+
245+
use salsa::plumbing as $zalsa;
246+
use $zalsa::input as $zalsa_struct;
247+
248+
// These are standalone functions instead of methods on `Builder` to prevent
249+
// that the enclosing module can call them.
250+
pub(super) fn new_builder($($field_id: $field_ty),*) -> $Builder {
251+
$Builder {
252+
fields: ($($field_id,)*),
253+
durabilities: [salsa::Durability::default(); $N],
254+
}
255+
}
256+
257+
pub(super) fn builder_into_inner(builder: $Builder, revision: $zalsa::Revision) -> (($($field_ty,)*), $zalsa::Array<$zalsa::Stamp, $N>) {
258+
let stamps = $zalsa::Array::new([
259+
$($zalsa::stamp(revision, builder.durabilities[$field_index])),*
260+
]);
261+
262+
(builder.fields, stamps)
263+
}
264+
265+
#[must_use]
266+
pub struct $Builder {
267+
/// The field values.
268+
fields: ($($field_ty,)*),
269+
270+
/// The durabilities per field.
271+
durabilities: [salsa::Durability; $N],
272+
}
273+
274+
impl $Builder {
275+
/// Sets the durability of all fields.
276+
///
277+
/// Overrides any previously set durabilities.
278+
pub fn durability(mut self, durability: salsa::Durability) -> Self {
279+
self.durabilities = [durability; $N];
280+
self
281+
}
282+
283+
$($zalsa::maybe_default_tt! { $field_option =>
284+
/// Sets the value of the field `$field_id`.
285+
#[must_use]
286+
pub fn $field_id(mut self, value: $field_ty) -> Self
287+
{
288+
self.fields.$field_index = value;
289+
self
290+
}
291+
})*
292+
293+
$(
294+
/// Sets the durability for the field `$field_id`.
295+
#[must_use]
296+
pub fn $field_durability_id(mut self, durability: salsa::Durability) -> Self
297+
{
298+
self.durabilities[$field_index] = durability;
299+
self
300+
}
301+
)*
302+
}
303+
}
207304
};
208305
};
209306
}

components/salsa-macro-rules/src/setup_interned_struct.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ macro_rules! setup_interned_struct {
8181
{
8282
static CACHE: $zalsa::IngredientCache<$zalsa_struct::IngredientImpl<$Configuration>> =
8383
$zalsa::IngredientCache::new();
84-
CACHE.get_or_create(db.as_salsa_database(), || {
85-
db.add_or_lookup_jar_by_type(&<$zalsa_struct::JarImpl<$Configuration>>::default())
84+
CACHE.get_or_create(db.as_dyn_database(), || {
85+
db.zalsa().add_or_lookup_jar_by_type(&<$zalsa_struct::JarImpl<$Configuration>>::default())
8686
})
8787
}
8888
}
@@ -135,7 +135,7 @@ macro_rules! setup_interned_struct {
135135
$Db: ?Sized + salsa::Database,
136136
{
137137
let current_revision = $zalsa::current_revision(db);
138-
$Configuration::ingredient(db).intern(db.as_salsa_database(), ($($field_id,)*))
138+
$Configuration::ingredient(db).intern(db.as_dyn_database(), ($($field_id,)*))
139139
}
140140

141141
$(
@@ -144,7 +144,6 @@ macro_rules! setup_interned_struct {
144144
// FIXME(rust-lang/rust#65991): The `db` argument *should* have the type `dyn Database`
145145
$Db: ?Sized + $zalsa::Database,
146146
{
147-
let runtime = db.runtime();
148147
let fields = $Configuration::ingredient(db).fields(self);
149148
$zalsa::maybe_clone!(
150149
$field_option,

components/salsa-macro-rules/src/setup_struct_fn.rs

-1
This file was deleted.

0 commit comments

Comments
 (0)