Skip to content

Conversation

@Lysxia
Copy link
Contributor

@Lysxia Lysxia commented Nov 4, 2025

I'm working on a rustc driver (Creusot) which needs to modify the MIR read by two queries, mir_borrowck and check_liveness, in different ways for each query. Both of these queries use mir_promoted to read the MIR, which is immutable (until it is stolen).

This adds an escape hatch so rustc drivers can mutate MIR for specific queries. And this removes get_mut which is unused and also unusable now that there's no way to get a &mut Steal from the rustc API.

Another approach may be to override the queries to modify the MIR after having read it from mir_promoted. However the implementation of queries is largely hidden, so I can't just copy their code to then modify it. A solution would be to parameterize the queries with callbacks which get instantiated with mir_promoted by default, but that seems more involved and ad hoc. That's why I'm proposing this smaller change instead.

@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 Nov 4, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 4, 2025

r? @davidtwco

rustbot has assigned @davidtwco.
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

@bjorn3
Copy link
Member

bjorn3 commented Nov 4, 2025

I'm pretty sure this will break incr comp badly if used. Please at least give it a much scarier method name.

For modifying mir_promoted a better option may be to instead override the mir_promoted query and within this override call the original query, copy the MIR out of the Steal, modify it and put it back into a new Steal. You can call the original mir_promoted query by doing something like https://github.com/rust-lang/miri/blob/3ab6735110fb308177900c33ff865b5a767979a8/src/bin/miri.rs#L132-L134

@Lysxia
Copy link
Contributor Author

Lysxia commented Nov 4, 2025

That's what we were doing before. The problem now is that I want different callers of mir_promoted to get different MIR, to hide different bits from mir_borrowck and from check_liveness.

@Lysxia Lysxia changed the title Replace Steal::get_mut with Steal::borrow_mut Add Steal::risky_hack_borrow_mut Nov 4, 2025
and remove unused Steal::get_mut
@Lysxia
Copy link
Contributor Author

Lysxia commented Nov 4, 2025

Following your suggestion, I renamed it to something more dissuasive. I am of course open to discuss and implement more robust alternatives!

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. 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.

4 participants