Skip to content

Fix stability of Definition entities#1253

Merged
lionel- merged 4 commits into
mainfrom
oak/salsa-17-interning
Jun 19, 2026
Merged

Fix stability of Definition entities#1253
lionel- merged 4 commits into
mainfrom
oak/salsa-17-interning

Conversation

@lionel-

@lionel- lionel- commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Branched from #1252
Progress towards #1212

Like in ty, our Definitions are a tracked struct with some degree of stability across edits. Unlike in ty, the definitions are not created within the semantic index, they are created outside so that we keep the index salsa-free, which allows it to be easily reused to figure out data flow dependencies in non-salsa contexts.

Because the definitions are created outside the index we need to be a bit careful. This is a tracked struct, not an interned one, and that means that different Salsa queries create different instances of the definition that don't compare equal, even if they are the same definition. (See https://hackmd.io/5ddaZLKYSVC_YTTD3SzRDw?view#Tracked-Structs, thanks to @DavisVaughan for finding this doc.)

To ensure definitions have a single identity, we now funnel all definitions lookup through a single File::definitions() query that creates a map of Definition keyed by Scope and DefId (bundled in a new struct DefinitionSite).

New tests ensure that definitions are not invalidated when they shift in a file or when definitions are inserted before (which changes the lookup key but not the definition ID, so downstream queries remain valid even if their key is now outdated).

@DavisVaughan DavisVaughan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like this!

Comment thread crates/oak_db/src/definition.rs Outdated
Comment thread crates/oak_db/src/definition.rs Outdated
@lionel- lionel- force-pushed the oak/salsa-16-document-wire-url branch from 14bacca to 7743983 Compare June 10, 2026 14:32
@lionel- lionel- force-pushed the oak/salsa-17-interning branch from 0cd9628 to 25c9de8 Compare June 10, 2026 14:33
@lionel- lionel- force-pushed the oak/salsa-16-document-wire-url branch from 7743983 to a9b0bf2 Compare June 11, 2026 09:42
@lionel- lionel- force-pushed the oak/salsa-17-interning branch from 25c9de8 to 798be33 Compare June 11, 2026 12:36
@lionel- lionel- force-pushed the oak/salsa-16-document-wire-url branch from c4a0c66 to 58bcce0 Compare June 19, 2026 13:50
Base automatically changed from oak/salsa-16-document-wire-url to main June 19, 2026 13:50
@lionel- lionel- force-pushed the oak/salsa-17-interning branch from e4f1586 to b80334b Compare June 19, 2026 13:51
@lionel- lionel- merged commit 8e10374 into main Jun 19, 2026
17 checks passed
@lionel- lionel- deleted the oak/salsa-17-interning branch June 19, 2026 13:52
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants