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

Add set_dcx to ParseSess #130299

Merged
merged 1 commit into from
Sep 13, 2024
Merged

Add set_dcx to ParseSess #130299

merged 1 commit into from
Sep 13, 2024

Conversation

vetleras
Copy link

After this PR was merged, it is no longer possible to inject one's own Emitter in the way described in the Compiler Development Guide. The reason is that the dcx field in ParseSess is no longer public, so it is not possible to update the dcx field with a DiagCtxt that contains one's own Emitter in the psess_created callback in rustc_interface::Config. The only way I have found to insert my own DiagCtxt is by creating an entirely new ParseSess and replacing the old one. This is not a good solution as the original ParseSess contains fields I would like to keep. (In my case the problem is that I lose the cfg and check-cfg fields of the original.)

The solution proposed in this PR is to add a set_dcx method to ParseSess. Per my limited understanding of the rustc codebase this should be fine as set_dcx requires a mutable reference to ParseSess, which is as far as I know only available in the psess_created callback (outside of rustc_interface::run_compiler).

If this PR is accepted, I will create a new PR to update the aforementioned example in the Compiler Development Guide.

@rustbot
Copy link
Collaborator

rustbot commented Sep 13, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added 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 Sep 13, 2024
@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member

lgtm

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Sep 13, 2024

📌 Commit bde1f4d has been approved by compiler-errors

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 Sep 13, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 13, 2024
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#129320 (Fix crash when labeling arguments for call_once and friends)
 - rust-lang#130266 (target: default to the medium code model on LoongArch targets)
 - rust-lang#130297 (Dataflow cleanups)
 - rust-lang#130299 (Add set_dcx to ParseSess)
 - rust-lang#130301 (some fixes for clashing_extern_declarations lint)
 - rust-lang#130305 (Clippy: consider msrv for const context for const_float_bits_conv)

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

Rollup of 6 pull requests

Successful merges:

 - rust-lang#129320 (Fix crash when labeling arguments for call_once and friends)
 - rust-lang#130266 (target: default to the medium code model on LoongArch targets)
 - rust-lang#130297 (Dataflow cleanups)
 - rust-lang#130299 (Add set_dcx to ParseSess)
 - rust-lang#130301 (some fixes for clashing_extern_declarations lint)
 - rust-lang#130305 (Clippy: consider msrv for const context for const_float_bits_conv)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b0e3235 into rust-lang:master Sep 13, 2024
6 checks passed
@rustbot rustbot added this to the 1.83.0 milestone Sep 13, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 13, 2024
Rollup merge of rust-lang#130299 - vetleras:add_set_dcx, r=compiler-errors

Add set_dcx to ParseSess

After [this](rust-lang#126623) PR was merged, it is no longer possible to inject one's own `Emitter` in the way [described in the Compiler Development Guide](https://rustc-dev-guide.rust-lang.org/rustc-driver-getting-diagnostics.html). The reason is that the `dcx` field in `ParseSess` is no longer public, so it is not possible to update the `dcx` field with a `DiagCtxt` that contains one's own `Emitter` in the `psess_created` callback in `rustc_interface::Config`. The only way I have found to insert my own `DiagCtxt` is by creating an entirely new `ParseSess` and replacing the old one. This is not a good solution as the original `ParseSess` contains fields I would like to keep. (In my case the problem is that I lose the `cfg` and `check-cfg` fields of the original.)

The solution proposed in this PR is to add a `set_dcx` method to `ParseSess`. Per my limited understanding of the rustc codebase this should be fine as `set_dcx` requires a mutable reference to `ParseSess`, which is as far as I know only available in the `psess_created` callback (outside of `rustc_interface::run_compiler`).

If this PR is accepted, I will create a new PR to update the aforementioned example in the Compiler Development Guide.
@vetleras vetleras deleted the add_set_dcx branch September 16, 2024 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants