Skip to content

POC: package_by_file_query() rather than package field in File#1249

Draft
DavisVaughan wants to merge 5 commits into
mainfrom
oak/salsa-11-scan-library-davis
Draft

POC: package_by_file_query() rather than package field in File#1249
DavisVaughan wants to merge 5 commits into
mainfrom
oak/salsa-11-scan-library-davis

Conversation

@DavisVaughan

@DavisVaughan DavisVaughan commented May 29, 2026

Copy link
Copy Markdown
Contributor

🔥 UNREVIEWED

Core change (oak_db):

  • crates/oak_db/src/file.rs — removed the package: Option<Package> input field from File. Added a #[salsa::tracked] File::package(db) query that derives ownership. File::root is unchanged (still routes through root_by_package for correct nested-root selection).
  • crates/oak_db/src/db.rs — added root_file_package_index (a per-root File → Package tracked index, parallel to the existing root_url_index) and package_by_file_query, which walks live roots' indexes in workspace-then-library order and returns the first hit. Same granularity and walk shape as file_by_url.
  • crates/oak_db/src/inputs.rs — rewrote the placement-invariant doc blocks on Package.files, Root.scripts, and OrphanRoot.files to describe single-source-of-truth instead.

Scanner (oak_scan):

  • upsert_file no longer writes a back-pointer. It still drops a file from a different old package (the rare nested-root case) using the derived old.package(db), and still cleans up orphan placement.
  • set_root_stale lost its file.set_package(None) loop entirely — eviction now falls out of containment automatically.

Also

One note for later: narrow_package_top_level's "file not in package files" warning branch
is now logically unreachable (the package is derived from that membership) — I kept it as
a defensive guard and reworded the message.

@lionel-

lionel- commented May 31, 2026

Copy link
Copy Markdown
Contributor

That's exactly how it worked in a previous iteration where I implemented a map query for packages, just like there is one for files. I made it a field because it seems nice as a discriminator in operations over files (natural match file.package syntax to dispatch package vs script behaviour). It also has fewer invalidation events (no dependencies on roots), which while not crucial, still seems nice for such a common lookup.

@lionel- lionel- force-pushed the oak/salsa-11-scan-library branch from d50f230 to 76a82b0 Compare June 10, 2026 10:07
Base automatically changed from oak/salsa-11-scan-library to main June 10, 2026 10:11
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