Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some more refactorings towards removing driver queries #132410

Merged
merged 7 commits into from
Nov 28, 2024

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Oct 31, 2024

Follow up to #127184

Custom driver breaking change

The after_analysis callback is changed to accept TyCtxt instead of Queries. The only safe query in Queries to call at this point is global_ctxt() which allows you to enter the TyCtxt either way. To fix your custom driver, replace the queries: &'tcx Queries<'tcx> argument with tcx: TyCtxt<'tcx> and remove your queries.global_ctxt().unwrap().enter(|tcx| { ... }) call and only keep the contents of the closure.

Custom driver deprecation

The after_crate_root_parsing callback is now deprecated. Several custom drivers are incorrectly calling queries.global_ctxt() from inside of it, which causes some driver code to be skipped. As such I would like to either remove it in the future or if custom drivers still need it, change it to accept an &rustc_ast::Crate instead.

@rustbot
Copy link
Collaborator

rustbot commented Oct 31, 2024

r? @pnkfelix

rustbot has assigned @pnkfelix.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 31, 2024
@rustbot
Copy link
Collaborator

rustbot commented Oct 31, 2024

The Miri subtree was changed

cc @rust-lang/miri

@jieyouxu
Copy link
Member

Probably compat relnotes for custom drivers?

@bjorn3
Copy link
Member Author

bjorn3 commented Oct 31, 2024

Probably compat relnotes for custom drivers?

Custom drivers are unstable and by the time we get release notes all custom drivers that are still maintained will have updated already for at least a month. If you are writing a custom driver you have to be looking for PR's when something breaks anyway.

@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the yet_another_driver_refactor_round branch from aaf0567 to 86b0254 Compare October 31, 2024 17:08
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the yet_another_driver_refactor_round branch from 86b0254 to c2423f3 Compare October 31, 2024 18:42
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the yet_another_driver_refactor_round branch from c2423f3 to 7e7a344 Compare October 31, 2024 19:52
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the yet_another_driver_refactor_round branch from 7e7a344 to a30d62f Compare November 1, 2024 09:21
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the yet_another_driver_refactor_round branch 2 times, most recently from 5bc8708 to dd67650 Compare November 1, 2024 10:23
This allows simplifying the call site and make_input by using a single
match instead of two levels of if's.
This allows re-entrant entering of the GlobalCtxt
We now only exit the GlobalCtxt when calling a callback and all the way
at the end when the GlobalCtxt is about to be destroyed.
@bjorn3 bjorn3 force-pushed the yet_another_driver_refactor_round branch from dd67650 to 74fdbb7 Compare November 9, 2024 17:55
There is no other query that may need to be called at that point anyway.
Several custom drivers are incorrectly calling queries.global_ctxt()
from inside of it, which causes some driver code to be skipped. As such
I would like to either remove it in the future or if custom drivers
still need it, change it to accept an &rustc_ast::Crate instead.
@bjorn3 bjorn3 force-pushed the yet_another_driver_refactor_round branch from 74fdbb7 to 159ba4c Compare November 9, 2024 18:43
@bjorn3 bjorn3 mentioned this pull request Nov 19, 2024
Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

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

Just a nit and r=me

compiler/rustc_driver_impl/src/lib.rs Outdated Show resolved Hide resolved
@bjorn3
Copy link
Member Author

bjorn3 commented Nov 27, 2024

@bors r=cjgillot

@bors
Copy link
Contributor

bors commented Nov 27, 2024

📌 Commit dc65c63 has been approved by cjgillot

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 27, 2024
joboet added a commit to joboet/rust that referenced this pull request Nov 27, 2024
…_round, r=cjgillot

Some more refactorings towards removing driver queries

Follow up to rust-lang#127184

## Custom driver breaking change

The `after_analysis` callback is changed to accept `TyCtxt` instead of `Queries`. The only safe query in `Queries` to call at this point is `global_ctxt()` which allows you to enter the `TyCtxt` either way. To fix your custom driver, replace the `queries: &'tcx Queries<'tcx>` argument with `tcx: TyCtxt<'tcx>` and remove your `queries.global_ctxt().unwrap().enter(|tcx| { ... })` call and only keep the contents of the closure.

## Custom driver deprecation

The `after_crate_root_parsing` callback is now deprecated. Several custom drivers are incorrectly calling `queries.global_ctxt()` from inside of it, which causes some driver code to be skipped. As such I would like to either remove it in the future or if custom drivers still need it, change it to accept an `&rustc_ast::Crate` instead.
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 27, 2024
Rollup of 6 pull requests

Successful merges:

 - rust-lang#116161 (Stabilize `extended_varargs_abi_support`)
 - rust-lang#132410 (Some more refactorings towards removing driver queries)
 - rust-lang#133418 (coverage: Store coverage source regions as `Span` until codegen)
 - rust-lang#133498 (Add missing code examples on `LocalKey`)
 - rust-lang#133518 (Structurally resolve before checking `!` in HIR typeck)
 - rust-lang#133521 (Structurally resolve before matching on type of projection)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 28, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#132410 (Some more refactorings towards removing driver queries)
 - rust-lang#133418 (coverage: Store coverage source regions as `Span` until codegen)
 - rust-lang#133498 (Add missing code examples on `LocalKey`)
 - rust-lang#133518 (Structurally resolve before checking `!` in HIR typeck)
 - rust-lang#133521 (Structurally resolve before matching on type of projection)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit af1ca15 into rust-lang:master Nov 28, 2024
6 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Nov 28, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 28, 2024
Rollup merge of rust-lang#132410 - bjorn3:yet_another_driver_refactor_round, r=cjgillot

Some more refactorings towards removing driver queries

Follow up to rust-lang#127184

## Custom driver breaking change

The `after_analysis` callback is changed to accept `TyCtxt` instead of `Queries`. The only safe query in `Queries` to call at this point is `global_ctxt()` which allows you to enter the `TyCtxt` either way. To fix your custom driver, replace the `queries: &'tcx Queries<'tcx>` argument with `tcx: TyCtxt<'tcx>` and remove your `queries.global_ctxt().unwrap().enter(|tcx| { ... })` call and only keep the contents of the closure.

## Custom driver deprecation

The `after_crate_root_parsing` callback is now deprecated. Several custom drivers are incorrectly calling `queries.global_ctxt()` from inside of it, which causes some driver code to be skipped. As such I would like to either remove it in the future or if custom drivers still need it, change it to accept an `&rustc_ast::Crate` instead.
@bjorn3 bjorn3 deleted the yet_another_driver_refactor_round branch November 28, 2024 08:35
@bjorn3 bjorn3 mentioned this pull request Nov 28, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 9, 2024
A bunch of cleanups

These are all extracted from a branch I have to get rid of driver queries. Most of the commits are not directly necessary for this, but were found in the process of implementing the removal of driver queries.

Previous PR: rust-lang#132410
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 9, 2024
Rollup merge of rust-lang#133567 - bjorn3:various_cleanups, r=cjgillot

A bunch of cleanups

These are all extracted from a branch I have to get rid of driver queries. Most of the commits are not directly necessary for this, but were found in the process of implementing the removal of driver queries.

Previous PR: rust-lang#132410
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Dec 9, 2024
A bunch of cleanups

These are all extracted from a branch I have to get rid of driver queries. Most of the commits are not directly necessary for this, but were found in the process of implementing the removal of driver queries.

Previous PR: rust-lang/rust#132410
github-merge-queue bot pushed a commit to model-checking/kani that referenced this pull request Dec 9, 2024
Upgrade toolchain to 12/09.

Culprit PRs:
- rust-lang/rust#132410
- rust-lang/rust#133746
- Unnecessary `map_or` [clippy
lint](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or)

As with previous toolchain upgrades, it's unclear why the LLBC tests
regressed.

Resolves #3754

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
@bjorn3 bjorn3 added the A-driver Area: rustc_driver that ties everything together into the `rustc` compiler label Dec 10, 2024
bjorn3 pushed a commit to rust-lang/rustc_codegen_cranelift that referenced this pull request Dec 11, 2024
A bunch of cleanups

These are all extracted from a branch I have to get rid of driver queries. Most of the commits are not directly necessary for this, but were found in the process of implementing the removal of driver queries.

Previous PR: rust-lang/rust#132410
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 13, 2024
…l, r=oli-obk

Stop using driver queries in the public API

Follow up to rust-lang#132410 and rust-lang#133567

The next PR will completely get rid of driver queries. That PR will also contains some non-trivial refactorings enabled by no longer needing to support entering TyCtxt multiple times after it is constructed. The changes in the current PR have been split out to make it easier to review the api changes and to reduce the size of the next PR to review.

## Custom driver breaking change

The `after_crate_root_parsing` and `after_expansion` callbacks now accept `ast::Crate` and `TyCtxt` respectively rather than `Queries`. The only safe query in `Queries` to call inside these callbacks are `parse()` and `global_ctxt()` respectively which allows you to access the `ast::Crate` and `TyCtxt` either way. To fix your custom driver, replace the `queries: &'tcx Queries<'tcx>` argument with `crate_: ast::Crate` and `tcx: TyCtxt<'tcx>` respectively and for `after_expansion` remove your `queries.global_ctxt().unwrap().enter(|tcx| { ... })` call and only keep the contents of the closure.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 14, 2024
Rollup merge of rust-lang#134130 - bjorn3:prepare_driver_query_removal, r=oli-obk

Stop using driver queries in the public API

Follow up to rust-lang#132410 and rust-lang#133567

The next PR will completely get rid of driver queries. That PR will also contains some non-trivial refactorings enabled by no longer needing to support entering TyCtxt multiple times after it is constructed. The changes in the current PR have been split out to make it easier to review the api changes and to reduce the size of the next PR to review.

## Custom driver breaking change

The `after_crate_root_parsing` and `after_expansion` callbacks now accept `ast::Crate` and `TyCtxt` respectively rather than `Queries`. The only safe query in `Queries` to call inside these callbacks are `parse()` and `global_ctxt()` respectively which allows you to access the `ast::Crate` and `TyCtxt` either way. To fix your custom driver, replace the `queries: &'tcx Queries<'tcx>` argument with `crate_: ast::Crate` and `tcx: TyCtxt<'tcx>` respectively and for `after_expansion` remove your `queries.global_ctxt().unwrap().enter(|tcx| { ... })` call and only keep the contents of the closure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-driver Area: rustc_driver that ties everything together into the `rustc` compiler A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants