-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Refactor: {Lvalue,Rvalue,Operand}::ty only need the locals' types, not the full &Mir #43174
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
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
A way to avoid the cloning may be to wrap The refactoring in this PR however would still be needed. EDIT: I saw the tidy errors, but I'm going to wait for feedback if this approach will be accepted at all before fixing them. |
You can allow passing the MIR to impl<'tcx> AsRef<LocalDecls<'tcx>> for LocalDecls<'tcx> { /* .. */ }
impl<'tcx> AsRef<LocalDecls<'tcx>> for Mir<'tcx> { /* .. */ }
fn ty<'a, 'gcx, D: AsRef<LocalDecls>>(&self, local_decls: D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> LvalueTy<'tcx> {
self.ty_(local_decls.as_ref(), tcx)
}
fn ty_<'a, 'gcx>(&self, local_decls: &LocalDecls<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> LvalueTy<'tcx> {
// ..
} |
The cloning does not look like such big of a deal. We need to figure out a "builder" interface for MIR, but that's for the future. |
For this I have to wrap LocalDelcs into a newtype, or else coherence checks kick in. Would that be all right, or too hevay-weight? |
@RalfJung in which crate are you adding the impls? |
@nikomatsakis in librustc. |
I made a new trait for this overloading. |
Should I be annotating these |
Oh, and another thought: I could monomorphize the big functions taking |
@bors r+ |
📌 Commit 0bbc315 has been approved by |
Refactor: {Lvalue,Rvalue,Operand}::ty only need the locals' types, not the full &Mir I am writing code that needs to call these `ty` methods while mutating MIR -- which is impossible with the current API. Even with the refactoring the situation is not great: I am cloning the `local_decls` and then passing the clone to the `ty` methods. I have to clone because `Mir::basic_blocks_mut` borrows the entire `Mir` including the `local_decls`. But even that is better than not being able to get these types at all... Cc @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
I am writing code that needs to call these
ty
methods while mutating MIR -- which is impossible with the current API.Even with the refactoring the situation is not great: I am cloning the
local_decls
and then passing the clone to thety
methods. I have to clone becauseMir::basic_blocks_mut
borrows the entireMir
including thelocal_decls
. But even that is better than not being able to get these types at all...Cc @nikomatsakis