Skip to content

Don't panic if a query branched on an untracked state#1075

Merged
MichaReiser merged 4 commits intosalsa-rs:masterfrom
MichaReiser:backdate-untracked-read
Mar 20, 2026
Merged

Don't panic if a query branched on an untracked state#1075
MichaReiser merged 4 commits intosalsa-rs:masterfrom
MichaReiser:backdate-untracked-read

Conversation

@MichaReiser
Copy link
Contributor

@MichaReiser MichaReiser commented Mar 20, 2026

After a change to an input (e.g., a file was modified), Salsa re-executes all queries that read that input or depend on any such query. To limit invalidation, Salsa can backdate a query. If a query computes to the same value as in the previous revision, Salsa considers it unchanged and skips re-executing dependent queries. This is called backdating a query. The reason it's called backdating is that Salsa tracks the revision in which a query was last changed; backdating sets the last-changed revision "back" to the revision from before the input change. During backdating, Salsa enforces that the revision is indeed going backwards. That is, the revision Salsa backdates to (or the last changed revision from the previous query run) must be smaller (older) than the last changed revision from the current run.

Under normal circumstances, this invariant should always hold because for a query result to change, the query has to read some input that was changed in the current revision (at least in a revision newer than the last run). This ensures that the last changed revision from the new run is never older than that from the previous run. However, this invariant can be violated if a query branches on a state that isn't tracked in Salsa. Salsa will rerun the query because one of its inputs changed, but the query branches on some untracked state before reading that input, so that the query's last changed revision might be earlier than when the input changed.

Reading an untracked state in a query is always a bug (unless you call db.untracked_read), and it can lead to stale results. But I don't think it's an error severe enough to warrant Salsa panicking.

Related discussion: #Contributing to Salsa > assertion failed: old_memo.revisions.changed_at <= revisions

Related ty PR that fixed a few unintentional untracked reads.

@netlify
Copy link

netlify bot commented Mar 20, 2026

Deploy Preview for salsa-rs canceled.

Name Link
🔨 Latest commit 1699379
🔍 Latest deploy log https://app.netlify.com/projects/salsa-rs/deploys/69bd2bcd0c9f1500088d0323

@MichaReiser MichaReiser force-pushed the backdate-untracked-read branch from 535c160 to 254307a Compare March 20, 2026 10:43

assert!(old_memo.revisions.changed_at <= revisions.changed_at);
if old_memo.revisions.changed_at > revisions.changed_at {
let message = format_args!(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, 1.85 doesn't like the format_args lifetime. I'll switch to format

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 20, 2026

Merging this PR will improve performance by 4.07%

⚡ 1 improved benchmark
✅ 12 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
amortized[SupertypeInput] 3 µs 2.9 µs +4.07%

Comparing MichaReiser:backdate-untracked-read (1699379) with master (53421c2)

Open in CodSpeed

@MichaReiser MichaReiser marked this pull request as ready for review March 20, 2026 12:09
@MichaReiser MichaReiser added this pull request to the merge queue Mar 20, 2026
Merged via the queue into salsa-rs:master with commit b7faeba Mar 20, 2026
12 checks passed
@MichaReiser MichaReiser deleted the backdate-untracked-read branch March 20, 2026 12:19
This was referenced Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants