Skip to content

Commit 70bdaef

Browse files
committed
Remove another dynamic zalsa call
1 parent 523d4c8 commit 70bdaef

File tree

5 files changed

+22
-34
lines changed

5 files changed

+22
-34
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,10 @@ macro_rules! setup_tracked_fn {
203203
db: &dyn $Db,
204204
) -> &$zalsa::interned::IngredientImpl<$Configuration> {
205205
let zalsa = db.zalsa();
206-
Self::intern_ingredient_(db, zalsa)
206+
Self::intern_ingredient_(zalsa)
207207
}
208208
#[inline]
209209
fn intern_ingredient_<'z>(
210-
db: &dyn $Db,
211210
zalsa: &'z $zalsa::Zalsa
212211
) -> &'z $zalsa::interned::IngredientImpl<$Configuration> {
213212
// SAFETY: `lookup_jar_by_type` returns a valid ingredient index, and the second
@@ -267,11 +266,10 @@ macro_rules! setup_tracked_fn {
267266
$($cycle_recovery_fn)*(db, value, count, $($input_id),*)
268267
}
269268

270-
fn id_to_input<$db_lt>(db: &$db_lt Self::DbView, key: salsa::Id) -> Self::Input<$db_lt> {
271-
let zalsa = db.zalsa();
269+
fn id_to_input<$db_lt>(zalsa: &$db_lt $zalsa::Zalsa, key: salsa::Id) -> Self::Input<$db_lt> {
272270
$zalsa::macro_if! {
273271
if $needs_interner {
274-
$Configuration::intern_ingredient_(db, zalsa).data(zalsa, key).clone()
272+
$Configuration::intern_ingredient_(zalsa).data(zalsa, key).clone()
275273
} else {
276274
$zalsa::FromIdWithDb::from_id(key, zalsa)
277275
}
@@ -393,16 +391,15 @@ macro_rules! setup_tracked_fn {
393391
}
394392

395393
$zalsa::attach($db, || {
394+
let (zalsa, zalsa_local) = $db.zalsas();
396395
let result = $zalsa::macro_if! {
397396
if $needs_interner {
398397
{
399-
let (zalsa, zalsa_local) = $db.zalsas();
400-
let key = $Configuration::intern_ingredient_($db, zalsa).intern_id(zalsa, zalsa_local, ($($input_id),*), |_, data| data);
398+
let key = $Configuration::intern_ingredient_(zalsa).intern_id(zalsa, zalsa_local, ($($input_id),*), |_, data| data);
401399
$Configuration::fn_ingredient_($db, zalsa).fetch($db, zalsa, zalsa_local, key)
402400
}
403401
} else {
404402
{
405-
let (zalsa, zalsa_local) = $db.zalsas();
406403
$Configuration::fn_ingredient_($db, zalsa).fetch($db, zalsa, zalsa_local, $zalsa::AsId::as_id(&($($input_id),*)))
407404
}
408405
}

src/function.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ pub trait Configuration: Any {
6969
/// This invokes user code in form of the `Eq` impl.
7070
fn values_equal<'db>(old_value: &Self::Output<'db>, new_value: &Self::Output<'db>) -> bool;
7171

72-
// FIXME: This should take a `&Zalsa`
7372
/// Convert from the id used internally to the value that execute is expecting.
7473
/// This is a no-op if the input to the function is a salsa struct.
75-
fn id_to_input(db: &Self::DbView, key: Id) -> Self::Input<'_>;
74+
fn id_to_input(zalsa: &Zalsa, key: Id) -> Self::Input<'_>;
7675

7776
/// Returns the size of any heap allocations in the output value, in bytes.
7877
fn heap_size(_value: &Self::Output<'_>) -> usize {

src/function/execute.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::function::{Configuration, IngredientImpl};
44
use crate::sync::atomic::{AtomicBool, Ordering};
55
use crate::zalsa::{MemoIngredientIndex, Zalsa, ZalsaDatabase};
66
use crate::zalsa_local::{ActiveQueryGuard, QueryRevisions};
7-
use crate::{Event, EventKind, Id, Revision};
7+
use crate::{Event, EventKind, Id};
88

99
impl<C> IngredientImpl<C>
1010
where
@@ -41,16 +41,11 @@ where
4141

4242
let (new_value, mut revisions) = match C::CYCLE_STRATEGY {
4343
CycleRecoveryStrategy::Panic => {
44-
Self::execute_query(db, active_query, opt_old_memo, zalsa.current_revision(), id)
44+
Self::execute_query(db, zalsa, active_query, opt_old_memo, id)
4545
}
4646
CycleRecoveryStrategy::FallbackImmediate => {
47-
let (mut new_value, mut revisions) = Self::execute_query(
48-
db,
49-
active_query,
50-
opt_old_memo,
51-
zalsa.current_revision(),
52-
id,
53-
);
47+
let (mut new_value, mut revisions) =
48+
Self::execute_query(db, zalsa, active_query, opt_old_memo, id);
5449

5550
if let Some(cycle_heads) = revisions.cycle_heads_mut() {
5651
// Did the new result we got depend on our own provisional value, in a cycle?
@@ -77,7 +72,7 @@ where
7772
let active_query = db
7873
.zalsa_local()
7974
.push_query(database_key_index, IterationCount::initial());
80-
new_value = C::cycle_initial(db, C::id_to_input(db, id));
75+
new_value = C::cycle_initial(db, C::id_to_input(zalsa, id));
8176
revisions = active_query.pop();
8277
// We need to set `cycle_heads` and `verified_final` because it needs to propagate to the callers.
8378
// When verifying this, we will see we have fallback and mark ourselves verified.
@@ -136,13 +131,8 @@ where
136131
let mut opt_last_provisional: Option<&Memo<'db, C>> = None;
137132
loop {
138133
let previous_memo = opt_last_provisional.or(opt_old_memo);
139-
let (mut new_value, mut revisions) = Self::execute_query(
140-
db,
141-
active_query,
142-
previous_memo,
143-
zalsa.current_revision(),
144-
id,
145-
);
134+
let (mut new_value, mut revisions) =
135+
Self::execute_query(db, zalsa, active_query, previous_memo, id);
146136

147137
// Did the new result we got depend on our own provisional value, in a cycle?
148138
if let Some(cycle_heads) = revisions
@@ -192,7 +182,7 @@ where
192182
db,
193183
&new_value,
194184
iteration_count.as_u32(),
195-
C::id_to_input(db, id),
185+
C::id_to_input(zalsa, id),
196186
) {
197187
crate::CycleRecoveryAction::Iterate => {}
198188
crate::CycleRecoveryAction::Fallback(fallback_value) => {
@@ -258,9 +248,9 @@ where
258248
#[inline]
259249
fn execute_query<'db>(
260250
db: &'db C::DbView,
251+
zalsa: &'db Zalsa,
261252
active_query: ActiveQueryGuard<'db>,
262253
opt_old_memo: Option<&Memo<'db, C>>,
263-
current_revision: Revision,
264254
id: Id,
265255
) -> (C::Output<'db>, QueryRevisions) {
266256
if let Some(old_memo) = opt_old_memo {
@@ -275,14 +265,16 @@ where
275265
// * ensure that tracked struct created during the previous iteration
276266
// (and are owned by the query) are alive even if the query in this iteration no longer creates them.
277267
// * ensure the final returned memo depends on all inputs from all iterations.
278-
if old_memo.may_be_provisional() && old_memo.verified_at.load() == current_revision {
268+
if old_memo.may_be_provisional()
269+
&& old_memo.verified_at.load() == zalsa.current_revision()
270+
{
279271
active_query.seed_iteration(&old_memo.revisions);
280272
}
281273
}
282274

283275
// Query was not previously executed, or value is potentially
284276
// stale, or value is absent. Let's execute!
285-
let new_value = C::execute(db, C::id_to_input(db, id));
277+
let new_value = C::execute(db, C::id_to_input(zalsa, id));
286278

287279
(new_value, active_query.pop())
288280
}

src/function/fetch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ where
180180
inserting and returning fixpoint initial value"
181181
);
182182
let revisions = QueryRevisions::fixpoint_initial(database_key_index);
183-
let initial_value = C::cycle_initial(db, C::id_to_input(db, id));
183+
let initial_value = C::cycle_initial(db, C::id_to_input(zalsa, id));
184184
Some(self.insert_memo(
185185
zalsa,
186186
id,
@@ -194,7 +194,7 @@ where
194194
);
195195
let active_query =
196196
zalsa_local.push_query(database_key_index, IterationCount::initial());
197-
let fallback_value = C::cycle_initial(db, C::id_to_input(db, id));
197+
let fallback_value = C::cycle_initial(db, C::id_to_input(zalsa, id));
198198
let mut revisions = active_query.pop();
199199
revisions.set_cycle_heads(CycleHeads::initial(database_key_index));
200200
// We need this for `cycle_heads()` to work. We will unset this in the outer `execute()`.

src/function/memo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ mod _memory_usage {
497497
unimplemented!()
498498
}
499499

500-
fn id_to_input(_: &Self::DbView, _: Id) -> Self::Input<'_> {
500+
fn id_to_input(_: &Zalsa, _: Id) -> Self::Input<'_> {
501501
unimplemented!()
502502
}
503503

0 commit comments

Comments
 (0)