Skip to content

Remove crate from salsa EditionedFileId#21767

Merged
Veykril merged 2 commits intorust-lang:masterfrom
Veykril:push-xxyxurxwwmvy
Mar 9, 2026
Merged

Remove crate from salsa EditionedFileId#21767
Veykril merged 2 commits intorust-lang:masterfrom
Veykril:push-xxyxurxwwmvy

Conversation

@Veykril
Copy link
Member

@Veykril Veykril commented Mar 6, 2026

Fixes #21721

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 6, 2026
@Veykril Veykril enabled auto-merge March 6, 2026 12:40
@Veykril Veykril force-pushed the push-xxyxurxwwmvy branch 2 times, most recently from 86ae3d8 to b784fb3 Compare March 6, 2026 12:56
@Veykril Veykril added this pull request to the merge queue Mar 6, 2026
@Veykril Veykril removed this pull request from the merge queue due to a manual request Mar 6, 2026
This broke the contract of `HashEqLike`, causing interning to return different IDs
@Veykril Veykril force-pushed the push-xxyxurxwwmvy branch from b784fb3 to d9560f8 Compare March 7, 2026 07:01
@Veykril Veykril changed the title fix: Fix invalid PartialEq impl for EditionedFileIdData Remove crate-based EditionedFileIdData Mar 7, 2026
@Veykril Veykril force-pushed the push-xxyxurxwwmvy branch 4 times, most recently from b33ecf3 to 6d08c43 Compare March 8, 2026 18:43
@Veykril Veykril force-pushed the push-xxyxurxwwmvy branch from 6d08c43 to 5abc9af Compare March 8, 2026 18:45
@Veykril Veykril changed the title Remove crate-based EditionedFileIdData Remove crate from salsa EditionedFileId Mar 8, 2026
@Veykril Veykril changed the title Remove crate from salsa EditionedFileId Remove crate from salsa EditionedFileId Mar 8, 2026
@Veykril Veykril added this pull request to the merge queue Mar 9, 2026
@ChayimFriedman2
Copy link
Contributor

@Veykril did you measure the memory impact?

Merged via the queue into rust-lang:master with commit 018847f Mar 9, 2026
17 checks passed
@Veykril Veykril deleted the push-xxyxurxwwmvy branch March 9, 2026 08:07
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 9, 2026
@Veykril Veykril requested a review from Copilot March 9, 2026 09:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors EditionedFileId to no longer carry a Crate, and threads crate context explicitly where required (notably item-tree lowering), aiming to fix a regression around span/origin handling in large workspaces (rust-analyzer issue #21721).

Changes:

  • Simplify base_db::EditionedFileId to wrap only span::EditionedFileId and remove “guess origin” APIs.
  • Update item-tree queries/APIs to accept an explicit Crate parameter and adjust call sites accordingly.
  • Refresh affected tests/fixtures and golden test outputs to match new IDs/behavior.

Reviewed changes

Copilot reviewed 38 out of 38 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
crates/test-fixture/src/lib.rs Switch fixture helpers to construct EditionedFileId from span::EditionedFileId without crate guessing.
crates/rust-analyzer/src/cli/ssr.rs Update SSR CLI to use EditionedFileId::current_edition.
crates/rust-analyzer/src/cli/analysis_stats.rs Thread Crate into item-tree calls; adjust source-root iteration.
crates/load-cargo/src/lib.rs Use span_file_id accessors when producing proc-macro span responses.
crates/ide/src/view_item_tree.rs Pass an explicit crate into file_item_tree for debug item-tree rendering.
crates/ide/src/typing/on_enter.rs Replace current_edition_guess_origin usage with current_edition.
crates/ide/src/typing.rs Remove crate-guessing wrapper creation; pick a crate and construct EditionedFileId directly.
crates/ide/src/signature_help.rs Update expected signature-help output ordering.
crates/ide/src/references.rs Update reference-search scope construction to new EditionedFileId API.
crates/ide/src/lib.rs Replace current_edition_guess_origin usage with current_edition in multiple APIs.
crates/ide-ssr/src/from_comment.rs Use current_edition when parsing comment-based SSR patterns.
crates/ide-db/src/traits.rs Update test fixture EditionedFileId construction to from_span_file_id.
crates/ide-db/src/test_data/test_symbols_with_imports.txt Update golden IDs after interned-ID changes.
crates/ide-db/src/test_data/test_symbols_exclude_imports.txt Update golden IDs after interned-ID changes.
crates/ide-db/src/test_data/test_symbol_index_collection.txt Update golden salsa IDs after query/input changes.
crates/ide-db/src/test_data/test_doc_alias.txt Update golden salsa IDs after query/input changes.
crates/ide-db/src/search.rs Construct EditionedFileId without embedding crate context.
crates/hir/src/semantics/child_by_source.rs Adjust derive-macro mapping to obtain a crate without HirFileId::krate.
crates/hir/src/semantics.rs Update edition attachment fallbacks to current_edition and remove crate from EditionedFileId::new.
crates/hir/src/lib.rs Update macro diagnostic span/file-id comparisons to new accessor naming.
crates/hir-ty/src/tests/macros.rs Update cfg-test fixture to use a non-test cfg key.
crates/hir-ty/src/tests/incremental.rs Update incremental event expectations (new shim/query names).
crates/hir-expand/src/span_map.rs Use span_file_id when building real span maps.
crates/hir-expand/src/lib.rs Remove HirFileId::krate helper and adjust edition retrieval.
crates/hir-expand/src/db.rs Resolve spans via from_span_file_id rather than guessing origin crate.
crates/hir-expand/src/builtin/fn_macro.rs Construct EditionedFileId without crate in include/relative-file logic.
crates/hir-def/src/nameres/tests/incremental.rs Update item-tree query call sites to pass db.test_crate().
crates/hir-def/src/nameres/mod_resolution.rs Drop Crate threading from module-file resolution and adjust EditionedFileId construction.
crates/hir-def/src/nameres/collector.rs Thread crate context into item-tree lowering and adjust tests using test_crate.
crates/hir-def/src/macro_expansion_tests/mod.rs Use db.test_crate() instead of extracting crate from file id.
crates/hir-def/src/macro_expansion_tests/mbe.rs Update golden expansion spans/IDs after interned-ID changes.
crates/hir-def/src/item_tree/tests.rs Pass crate explicitly into file_item_tree in tests.
crates/hir-def/src/item_tree/lower.rs Store crate in lowering context to obtain cfg options without HirFileId::krate.
crates/hir-def/src/item_tree.rs Change tracked item-tree queries to accept Crate; plumb crate through TreeId::item_tree.
crates/hir-def/src/expr_store/tests/body/block.rs Update golden BlockId after interned-ID changes.
crates/hir-def/src/db.rs Change DefDatabase::file_item_tree signature to include Crate.
crates/base-db/src/input.rs Update Crate::root_file_id to construct EditionedFileId without crate.
crates/base-db/src/editioned_file_id.rs Replace custom interned struct (with crate) with a simpler #[salsa::interned] wrapper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

View changes since this review

Comment on lines +73 to +79
let krate = db
.relevant_crates(position.file_id)
.first()
.map_or(Edition::CURRENT, |crates| crates.data(db).edition);
// FIXME: We are hitting the database here, if we are unlucky this call might block momentarily
// causing the editor to feel sluggish! We need to make this bail if it would block too long?
let editioned_file_id_wrapper = EditionedFileId::from_span_guess_origin(
db,
span::EditionedFileId::new(position.file_id, edition),
);
.copied()
.unwrap_or_else(|| *db.all_crates().first().unwrap());
let edition = krate.data(db).edition;
let editioned_file_id_wrapper = EditionedFileId::new(db, position.file_id, edition);
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

unwrap_or_else(|| *db.all_crates().first().unwrap()) can panic when the crate graph hasn’t been populated yet (e.g., during startup), crashing on-type assists. Consider falling back to Edition::CURRENT (and/or early-return None) when there is no relevant crate, instead of unwrapping all_crates().first().

Copilot uses AI. Check for mistakes.
Comment on lines 125 to 141
let mut item_tree_sw = self.stop_watch();
let source_roots = krates
.iter()
.cloned()
.map(|krate| db.file_source_root(krate.root_file(db)).source_root_id(db))
.map(|krate| (db.file_source_root(krate.root_file(db)).source_root_id(db), krate))
.unique();

let mut dep_loc = 0;
let mut workspace_loc = 0;
let mut dep_item_trees = 0;
let mut workspace_item_trees = 0;

let mut workspace_item_stats = PrettyItemStats::default();
let mut dep_item_stats = PrettyItemStats::default();

for source_root_id in source_roots {
for (source_root_id, krate) in source_roots {
let source_root = db.source_root(source_root_id).source_root(db);
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

source_roots is now deduped with .unique() over (SourceRootId, Crate), which means the same SourceRootId will be visited once per crate (common for workspace roots). This can dramatically increase the amount of work (re-scanning/parsing/item-tree building the same files repeatedly) and skew LOC/item-tree counts. Consider keeping uniqueness by SourceRootId and choosing a representative crate per root (or determining a per-file crate inside the loop via relevant_crates(file_id) as needed).

Copilot uses AI. Check for mistakes.
@@ -1,305 +1,46 @@
//! Defines [`EditionedFileId`], an interned wrapper around [`span::EditionedFileId`] that
//! is interned (so queries can take it) and remembers its crate.
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The module-level doc comment still claims EditionedFileId “remembers its crate”, but the type no longer stores a crate. Please update this comment to reflect the new semantics (interned wrapper around span::EditionedFileId only).

Suggested change
//! is interned (so queries can take it) and remembers its crate.
//! is interned (so queries can take it) and stores only the underlying `span::EditionedFileId`.

Copilot uses AI. Check for mistakes.
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.

[BUG] Broader Regression: Go-to-Def, Rename, and References broken in macro attribute blocks (Large Workspace)

4 participants