Skip to content

internal: move ExpandDatabase::proc_macros out of the query group#22641

Closed
ada4a wants to merge 3 commits into
rust-lang:masterfrom
ada4a:unquerygroup-proc_macros
Closed

internal: move ExpandDatabase::proc_macros out of the query group#22641
ada4a wants to merge 3 commits into
rust-lang:masterfrom
ada4a:unquerygroup-proc_macros

Conversation

@ada4a

@ada4a ada4a commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This required several non-trivial changes:

  • Rename the existing ProcMacros::get to ProcMacros::get_for_crate (feel free to suggest a better name), to avoid clashing with the new getter created by salsa.
  • Change ProcMacroBuilder::build to take db and durability, as it will need to build ProcMacros inside the db. Also rename it to build_in, to reflect the change in functionality.
  • ProcMacros is now stored in the database directly, instead of being wrapped in an Arc. This should be fine though, since its by_crate field is marked with #[returns(ref)].

@rustbot blocked on #22639, but mostly for easier rebasing later

cc @Veykril

@rustbot rustbot added the S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work. label Jun 25, 2026
Comment on lines -93 to +104
ProcMacros(map)
ProcMacros::try_get(db)
.unwrap_or_else(|| ProcMacros::new(db, Default::default()))
.set_by_crate(db)
.with_durability(durability)
.to(map);

@ada4a ada4a Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The reason for this ugliness is twofold:

  • I can't just do ProcMacros::builder(map).durability(durability).new(db), because ProcMacros is marked as a singleton, and salsa complains (panics) if I create a new instance of it.
  • I can't just use ProcMacros::get, because some tests panic with "Option::unwrap called on None", which I assume means that ProcMacros is sometimes not yet set by the time we call this method.

Let me know if I should add this justification as a comment to the code maybe

View changes since the review

Comment thread crates/ide-db/src/lib.rs Outdated
set_all_crates_with_durability(&mut db, std::iter::empty(), Durability::HIGH);
CrateGraphBuilder::default().set_in_db(&mut db);
db.set_proc_macros_with_durability(Default::default(), Durability::MEDIUM);
_ = hir::ProcMacros::builder(Default::default()).durability(Durability::MEDIUM).new(&db);

@Veykril Veykril Jun 26, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can expose another function on ProcMacros here like init_default(&db, Durability::MEDIUM) or so, otherwise looks good to me

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done:)

@ada4a ada4a force-pushed the unquerygroup-proc_macros branch 2 times, most recently from b0001bf to f10b773 Compare June 26, 2026 10:09
@ada4a ada4a force-pushed the unquerygroup-proc_macros branch from f10b773 to 5b8cf1a Compare June 26, 2026 18:34
@ada4a ada4a closed this Jun 26, 2026
@ada4a

ada4a commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Moved into #22639

@ada4a ada4a deleted the unquerygroup-proc_macros branch June 26, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants