Skip to content

internal: remove input queries from #[query_group]#22639

Open
ada4a wants to merge 3 commits into
rust-lang:masterfrom
ada4a:unquerygroup-expand_proc_attr_macros
Open

internal: remove input queries from #[query_group]#22639
ada4a wants to merge 3 commits into
rust-lang:masterfrom
ada4a:unquerygroup-expand_proc_attr_macros

Conversation

@ada4a

@ada4a ada4a commented Jun 25, 2026

Copy link
Copy Markdown
Contributor
  • First two commits move the last remaining input queries
  • The third commit removes the input query support from #[query_group]

cc @Veykril

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 25, 2026
@ada4a

ada4a commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Left some stylistic questions in the code, mainly for future such PRs

@ada4a ada4a force-pushed the unquerygroup-expand_proc_attr_macros branch from 7fe164e to 3656520 Compare June 25, 2026 13:32
@ada4a

ada4a commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Let me draft this while I investigate the test failures...

@ada4a ada4a marked this pull request as draft June 25, 2026 13:43
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 25, 2026
@ada4a

ada4a commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author
  • in hir_def's macro_expansion_tests::mbe tests, there are several ones which have +syntaxctxt included, and they fail because the numeric SyntaxContext ids (?) have changed. Though the ids all seem to change consistently (17408->16384)
  • in hir_def's hir-def expr_store::tests::body::block::nested_module_scoping, the salsa id, crate id, and the block id of a module have changed
  • in ide_db's symbol_index::tests, the module id, EditionedFileIds, and struct ids have changed -- again, consistently (everything fell by 0x400)

While I have no idea why those ids would change as a result of this PR, the fact that the changes are all consistent seems like a good sign?

@ada4a ada4a changed the title move DefDatabased::expand_proc_attr_macros out of the query group internal: move DefDatabased::expand_proc_attr_macros out of the query group Jun 25, 2026
@ada4a ada4a marked this pull request as ready for review June 25, 2026 16:39
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 25, 2026
@Veykril

Veykril commented Jun 25, 2026

Copy link
Copy Markdown
Member

Its because this change changes the salsa ingredient order which thus changes the page allocator and IDs of the allocation

@ada4a

ada4a commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

So.. it's fine? Should I just update the tests?

@Veykril

Veykril commented Jun 25, 2026

Copy link
Copy Markdown
Member

Oh yea its fine and expected, meant to add that, so just update the tests

Comment thread crates/rust-analyzer/src/reload.rs Outdated
// TODO: should I create `AnalysisHost::{update_,}expand_proc_attr_macros` to clean this up?
// TODO: we don't use `raw_db` mutably until we go into the `if` -- is it a problem that I
// still get it mutably in an eager manner? I did this to avoid needing two separate calls, to
// `raw_database` and `raw_database_mut`. Or maybe I should just inline `raw_db`?

@ChayimFriedman2 ChayimFriedman2 Jun 26, 2026

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.

the rust-analyzer crate does depend on analysis crates, but we should avoid adding new such dependencies where possible. But I also don't think exposing the struct wholesale is a good idea; instead, export a fn set_expand_proc_attr_macros(value: bool).

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.

Added a setter and a getter, but called the former set_expand_proc_attr_macros_with_durability, to match base_db::set_all_crates_with_durability. The change is in a separate commit to simplify review, but I'd like to squash the commit before merging

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 think we should have only a setter, with no durability (that is, it sets the durability itself), that checks for equality with the previous value like here. hir is a high-level interface.

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.

Agree with the proposal to change the setter, but I don't think we can quite get rid of the getter, because it has one legitimate user:

&& !crate::db::get_expand_proc_attr_macros(self.db) =>

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.

That's in hir-def, it can access the input struct directly.

Comment thread crates/rust-analyzer/src/reload.rs Outdated
Comment on lines +115 to +117
// TODO: `ide`'s Cargo.toml says that it should avoid depending on `hir-*` crates directly,
// and go through `hir` re-exports instead. `rust-analyzer` OTOH does seems to depend on `hir-*`
// after all. So, should I import `ExpandProcAttrMacros` through `hir` or `hir_def`?

@Veykril Veykril Jun 25, 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.

Generally speaking we should at the very minimum have a re-export from hir instead then. Though even there the question then arises whether we shouldn't have a more "stable" interface for the given thing. We have not been very dilligent with keeping the separation maintained at the moment.

View changes since the review

@Veykril

Veykril commented Jun 26, 2026

Copy link
Copy Markdown
Member

Also coming back to the IDs in tests changing, ideally we wouldn't print those in tests at all / would "normalize" them such that they are stable wrt to the test, not to the salsa databass state, but no one has gotten around to changing that (also unsure how easy that is)

@ada4a

ada4a commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Should I maybe combine this PR and #22641, and rename this to something like "internal: remove input queries from query_group", to match #22328? Since that's what these two PRs are really intending to do

@ada4a ada4a changed the title internal: move DefDatabased::expand_proc_attr_macros out of the query group internal: move DefDatabase::expand_proc_attr_macros out of the query group Jun 26, 2026
@Veykril

Veykril commented Jun 26, 2026

Copy link
Copy Markdown
Member

yea re-using one of these for both changes seems fine to me

@ada4a ada4a changed the title internal: move DefDatabase::expand_proc_attr_macros out of the query group internal: remove input queries from #[query_group] Jun 26, 2026
ada4a added 3 commits June 26, 2026 20:37
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)]`.
@ada4a ada4a force-pushed the unquerygroup-expand_proc_attr_macros branch from c0dfbc4 to 5834f7a Compare June 26, 2026 18:41

@ada4a ada4a left a comment

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.

I went ahead and removed the support for #[salsa::input] after all, because it's nice to have the query-group-macro tests reflect the most current way of writing query groups (and just to test my own understanding).

View changes since this review

Comment on lines -85 to +84
"salsa_event(WillExecute { database_key: create_data_HelloWorldDatabase(Id(0)) })",
"salsa_event(WillCheckCancellation)",
"salsa_event(DidValidateMemoizedValue { database_key: create_data_HelloWorldDatabase(Id(0)) })",
"salsa_event(WillCheckCancellation)",
"salsa_event(WillExecute { database_key: invoke_length_query_shim(Id(800)) })",
"salsa_event(WillExecute { database_key: create_data_HelloWorldDatabase(Id(400)) })",
"salsa_event(WillCheckCancellation)",
"salsa_event(WillExecute { database_key: invoke_length_query_shim(Id(c00)) })",

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.

are these changes to be expected?..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants