Skip to content

Commit e4ce917

Browse files
authored
Merge pull request #527 from nikomatsakis/spindle
re-enable parallel tests
2 parents 2f4f80f + bf636d2 commit e4ce917

Some content is hidden

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

49 files changed

+1101
-1453
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ macro_rules! setup_accumulator_impl {
3535
where
3636
Db: ?Sized + $zalsa::Database,
3737
{
38-
$ingredient(db.as_salsa_database()).push(db.runtime(), self);
38+
let db = db.as_salsa_database();
39+
$ingredient(db).push(db, self);
3940
}
4041
}
4142
};

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,11 @@ macro_rules! setup_input_struct {
137137
// FIXME(rust-lang/rust#65991): The `db` argument *should* have the type `dyn Database`
138138
$Db: ?Sized + $zalsa::Database,
139139
{
140-
let runtime = db.runtime();
141-
let fields = $Configuration::ingredient(db.as_salsa_database()).field(runtime, self, $field_index);
140+
let fields = $Configuration::ingredient(db.as_salsa_database()).field(
141+
db.as_salsa_database(),
142+
self,
143+
$field_index,
144+
);
142145
$zalsa::maybe_clone!(
143146
$field_option,
144147
$field_ty,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ macro_rules! setup_interned_struct {
134134
// FIXME(rust-lang/rust#65991): The `db` argument *should* have the type `dyn Database`
135135
$Db: ?Sized + salsa::Database,
136136
{
137-
let runtime = db.runtime();
138137
let current_revision = $zalsa::current_revision(db);
139-
$Configuration::ingredient(db).intern(runtime, ($($field_id,)*))
138+
$Configuration::ingredient(db).intern(db.as_salsa_database(), ($($field_id,)*))
140139
}
141140

142141
$(

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ macro_rules! setup_tracked_fn {
233233
use salsa::plumbing as $zalsa;
234234
let key = $zalsa::macro_if! {
235235
if $needs_interner {
236-
$Configuration::intern_ingredient($db).intern_id($db.runtime(), ($($input_id),*))
236+
$Configuration::intern_ingredient($db).intern_id($db.as_salsa_database(), ($($input_id),*))
237237
} else {
238238
$zalsa::AsId::as_id(&($($input_id),*))
239239
}
@@ -265,26 +265,24 @@ macro_rules! setup_tracked_fn {
265265
} }
266266
}
267267

268-
$zalsa::attach_database($db, || {
269-
let result = $zalsa::macro_if! {
270-
if $needs_interner {
271-
{
272-
let key = $Configuration::intern_ingredient($db).intern_id($db.runtime(), ($($input_id),*));
273-
$Configuration::fn_ingredient($db).fetch($db, key)
274-
}
275-
} else {
276-
$Configuration::fn_ingredient($db).fetch($db, $zalsa::AsId::as_id(&($($input_id),*)))
268+
let result = $zalsa::macro_if! {
269+
if $needs_interner {
270+
{
271+
let key = $Configuration::intern_ingredient($db).intern_id($db.as_salsa_database(), ($($input_id),*));
272+
$Configuration::fn_ingredient($db).fetch($db, key)
277273
}
278-
};
274+
} else {
275+
$Configuration::fn_ingredient($db).fetch($db, $zalsa::AsId::as_id(&($($input_id),*)))
276+
}
277+
};
279278

280-
$zalsa::macro_if! {
281-
if $return_ref {
282-
result
283-
} else {
284-
<$output_ty as std::clone::Clone>::clone(result)
285-
}
279+
$zalsa::macro_if! {
280+
if $return_ref {
281+
result
282+
} else {
283+
<$output_ty as std::clone::Clone>::clone(result)
286284
}
287-
})
285+
}
288286
}
289287
};
290288
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ macro_rules! setup_tracked_struct {
193193
$Db: ?Sized + $zalsa::Database,
194194
{
195195
$Configuration::ingredient(db.as_salsa_database()).new_struct(
196-
db.runtime(),
196+
db.as_salsa_database(),
197197
($($field_id,)*)
198198
)
199199
}
@@ -204,8 +204,7 @@ macro_rules! setup_tracked_struct {
204204
// FIXME(rust-lang/rust#65991): The `db` argument *should* have the type `dyn Database`
205205
$Db: ?Sized + $zalsa::Database,
206206
{
207-
let runtime = db.runtime();
208-
let fields = unsafe { self.0.as_ref() }.field(runtime, $field_index);
207+
let fields = unsafe { self.0.as_ref() }.field(db.as_salsa_database(), $field_index);
209208
$crate::maybe_clone!(
210209
$field_option,
211210
$field_ty,

examples/calc/type_check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ fn fix_bad_variable_in_function() {
268268
"#]],
269269
expect![[r#"
270270
[
271-
"Event: Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: parse_statements(0) } }",
272-
"Event: Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: type_check_function(0) } }",
271+
"Event: Event { thread_id: ThreadId(11), kind: WillExecute { database_key: parse_statements(0) } }",
272+
"Event: Event { thread_id: ThreadId(11), kind: WillExecute { database_key: type_check_function(0) } }",
273273
]
274274
"#]],
275275
)],

src/accumulator.rs

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use crate::{
1010
hash::FxDashMap,
1111
ingredient::{fmt_index, Ingredient, Jar},
1212
key::DependencyIndex,
13-
runtime::local_state::QueryOrigin,
13+
local_state::{self, LocalState, QueryOrigin},
1414
storage::IngredientIndex,
15-
Database, DatabaseKeyIndex, Event, EventKind, Id, Revision, Runtime,
15+
Database, DatabaseKeyIndex, Event, EventKind, Id, Revision,
1616
};
1717

1818
pub trait Accumulator: Clone + Debug + Send + Sync + 'static + Sized {
@@ -78,44 +78,48 @@ impl<A: Accumulator> IngredientImpl<A> {
7878
}
7979
}
8080

81-
pub fn push(&self, runtime: &Runtime, value: A) {
82-
let current_revision = runtime.current_revision();
83-
let (active_query, _) = match runtime.active_query() {
84-
Some(pair) => pair,
85-
None => {
86-
panic!("cannot accumulate values outside of an active query")
81+
pub fn push(&self, db: &dyn crate::Database, value: A) {
82+
local_state::attach(db, |state| {
83+
let runtime = db.runtime();
84+
let current_revision = runtime.current_revision();
85+
let (active_query, _) = match state.active_query() {
86+
Some(pair) => pair,
87+
None => {
88+
panic!("cannot accumulate values outside of an active query")
89+
}
90+
};
91+
92+
let mut accumulated_values =
93+
self.map.entry(active_query).or_insert(AccumulatedValues {
94+
values: vec![],
95+
produced_at: current_revision,
96+
});
97+
98+
// When we call `push' in a query, we will add the accumulator to the output of the query.
99+
// If we find here that this accumulator is not the output of the query,
100+
// we can say that the accumulated values we stored for this query is out of date.
101+
if !state.is_output_of_active_query(self.dependency_index()) {
102+
accumulated_values.values.truncate(0);
103+
accumulated_values.produced_at = current_revision;
87104
}
88-
};
89-
90-
let mut accumulated_values = self.map.entry(active_query).or_insert(AccumulatedValues {
91-
values: vec![],
92-
produced_at: current_revision,
93-
});
94-
95-
// When we call `push' in a query, we will add the accumulator to the output of the query.
96-
// If we find here that this accumulator is not the output of the query,
97-
// we can say that the accumulated values we stored for this query is out of date.
98-
if !runtime.is_output_of_active_query(self.dependency_index()) {
99-
accumulated_values.values.truncate(0);
100-
accumulated_values.produced_at = current_revision;
101-
}
102105

103-
runtime.add_output(self.dependency_index());
104-
accumulated_values.values.push(value);
106+
state.add_output(self.dependency_index());
107+
accumulated_values.values.push(value);
108+
})
105109
}
106110

107111
pub(crate) fn produced_by(
108112
&self,
109-
runtime: &Runtime,
113+
current_revision: Revision,
114+
local_state: &LocalState,
110115
query: DatabaseKeyIndex,
111116
output: &mut Vec<A>,
112117
) {
113-
let current_revision = runtime.current_revision();
114118
if let Some(v) = self.map.get(&query) {
115119
// FIXME: We don't currently have a good way to identify the value that was read.
116120
// You can't report is as a tracked read of `query`, because the return value of query is not being read here --
117121
// instead it is the set of values accumuated by `query`.
118-
runtime.report_untracked_read();
122+
local_state.report_untracked_read(current_revision);
119123

120124
let AccumulatedValues {
121125
values,
@@ -174,7 +178,7 @@ impl<A: Accumulator> Ingredient for IngredientImpl<A> {
174178
assert!(stale_output_key.is_none());
175179
if self.map.remove(&executor).is_some() {
176180
db.salsa_event(Event {
177-
runtime_id: db.runtime().id(),
181+
thread_id: std::thread::current().id(),
178182
kind: EventKind::DidDiscardAccumulated {
179183
executor_key: executor,
180184
accumulator: self.dependency_index(),
@@ -198,6 +202,10 @@ impl<A: Accumulator> Ingredient for IngredientImpl<A> {
198202
fn fmt_index(&self, index: Option<crate::Id>, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
199203
fmt_index(A::DEBUG_NAME, index, fmt)
200204
}
205+
206+
fn debug_name(&self) -> &'static str {
207+
A::DEBUG_NAME
208+
}
201209
}
202210

203211
impl<A> std::fmt::Debug for IngredientImpl<A>

src/runtime/active_query.rs renamed to src/active_query.rs

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,35 @@ use crate::{
99
use super::local_state::{EdgeKind, QueryEdges, QueryOrigin, QueryRevisions};
1010

1111
#[derive(Debug)]
12-
pub(super) struct ActiveQuery {
12+
pub(crate) struct ActiveQuery {
1313
/// What query is executing
14-
pub(super) database_key_index: DatabaseKeyIndex,
14+
pub(crate) database_key_index: DatabaseKeyIndex,
1515

1616
/// Minimum durability of inputs observed so far.
17-
pub(super) durability: Durability,
17+
pub(crate) durability: Durability,
1818

1919
/// Maximum revision of all inputs observed. If we observe an
2020
/// untracked read, this will be set to the most recent revision.
21-
pub(super) changed_at: Revision,
21+
pub(crate) changed_at: Revision,
2222

2323
/// Inputs: Set of subqueries that were accessed thus far.
2424
/// Outputs: Tracks values written by this query. Could be...
2525
///
2626
/// * tracked structs created
2727
/// * invocations of `specify`
2828
/// * accumulators pushed to
29-
pub(super) input_outputs: FxIndexSet<(EdgeKind, DependencyIndex)>,
29+
input_outputs: FxIndexSet<(EdgeKind, DependencyIndex)>,
3030

3131
/// True if there was an untracked read.
32-
pub(super) untracked_read: bool,
32+
untracked_read: bool,
3333

3434
/// Stores the entire cycle, if one is found and this query is part of it.
35-
pub(super) cycle: Option<Cycle>,
35+
pub(crate) cycle: Option<Cycle>,
3636

3737
/// When new entities are created, their data is hashed, and the resulting
3838
/// hash is added to this map. If it is not present, then the disambiguator is 0.
3939
/// Otherwise it is 1 more than the current value (which is incremented).
40-
pub(super) disambiguator_map: FxIndexMap<u64, Disambiguator>,
41-
}
42-
43-
pub(super) struct SavedQueryState {
44-
database_key_index: DatabaseKeyIndex,
45-
durability: Durability,
46-
changed_at: Revision,
47-
input_outputs_len: usize,
48-
untracked_read: bool,
49-
}
50-
51-
impl SavedQueryState {
52-
fn new(query: &ActiveQuery) -> Self {
53-
Self {
54-
database_key_index: query.database_key_index,
55-
durability: query.durability,
56-
changed_at: query.changed_at,
57-
input_outputs_len: query.input_outputs.len(),
58-
untracked_read: query.untracked_read,
59-
}
60-
}
40+
disambiguator_map: FxIndexMap<u64, Disambiguator>,
6141
}
6242

6343
impl ActiveQuery {
@@ -73,26 +53,6 @@ impl ActiveQuery {
7353
}
7454
}
7555

76-
pub(super) fn save_query_state(&self) -> SavedQueryState {
77-
SavedQueryState::new(self)
78-
}
79-
80-
pub(super) fn restore_query_state(&mut self, state: SavedQueryState) {
81-
assert_eq!(self.database_key_index, state.database_key_index);
82-
83-
assert!(self.durability <= state.durability);
84-
self.durability = state.durability;
85-
86-
assert!(self.changed_at >= state.changed_at);
87-
self.changed_at = state.changed_at;
88-
89-
assert!(self.input_outputs.len() >= state.input_outputs_len);
90-
self.input_outputs.truncate(state.input_outputs_len);
91-
92-
assert!(self.untracked_read >= state.untracked_read);
93-
self.untracked_read = state.untracked_read;
94-
}
95-
9656
pub(super) fn add_read(
9757
&mut self,
9858
input: DependencyIndex,

src/cycle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{database, key::DatabaseKeyIndex, Database};
1+
use crate::{key::DatabaseKeyIndex, local_state, Database};
22
use std::{panic::AssertUnwindSafe, sync::Arc};
33

44
/// Captures the participants of a cycle that occurred when executing a query.
@@ -74,7 +74,7 @@ impl Cycle {
7474

7575
impl std::fmt::Debug for Cycle {
7676
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77-
database::with_attached_database(|db| {
77+
local_state::with_attached_database(|db| {
7878
f.debug_struct("UnexpectedCycle")
7979
.field("all_participants", &self.all_participants(db))
8080
.field("unexpected_participants", &self.unexpected_participants(db))

0 commit comments

Comments
 (0)