Don't panic if a query branched on an untracked state#1075
Merged
MichaReiser merged 4 commits intosalsa-rs:masterfrom Mar 20, 2026
Merged
Don't panic if a query branched on an untracked state#1075MichaReiser merged 4 commits intosalsa-rs:masterfrom
MichaReiser merged 4 commits intosalsa-rs:masterfrom
Conversation
✅ Deploy Preview for salsa-rs canceled.
|
535c160 to
254307a
Compare
Veykril
approved these changes
Mar 20, 2026
MichaReiser
commented
Mar 20, 2026
src/function/backdate.rs
Outdated
|
|
||
| assert!(old_memo.revisions.changed_at <= revisions.changed_at); | ||
| if old_memo.revisions.changed_at > revisions.changed_at { | ||
| let message = format_args!( |
Contributor
Author
There was a problem hiding this comment.
Ugh, 1.85 doesn't like the format_args lifetime. I'll switch to format
Merging this PR will improve performance by 4.07%
Performance Changes
Comparing |
This was referenced Mar 20, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.