-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Encapsulate interpreter stack(s) a bit better #104073
Conversation
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt The Miri subtree was changed cc @rust-lang/miri Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
efba19c
to
22fe237
Compare
Instead of adding the additional API to the machine, we could also create a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the machine trait is growing quite big. Having a Stack
trait could help share code between the const_eval and const_prop instances. Not sure if that's worth it though, I am fine either way.
ecx: &'a mut InterpCx<'mir, 'tcx, Self>, | ||
) -> &'a mut Vec<Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>>; | ||
) -> &'a mut Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should all have doc comments. (In particular the last two need to explain which frame they return.)
use crate::*; | ||
|
||
/// An encapsulated call stack, so encapsulated to enable efficient caching of metadata about the | ||
/// contained `Frame`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to give out mutable access to basically the entire thing; in which sense is this 'encapsulated'?
Yeah, I wasn't thinking about this thoroughly enough until this comment. After poking around for a few days I'm abandoning encapsulation as an approach here. Originally what stuck out at me was that this interface hands out a But IMO what kills this idea is the way the interpreter uses I can imagine a few solutions to this:
IMO all of these exceed the amount of complexity I'm willing to add in order to avoid the duplicate state consistency issue pointed out in rust-lang/miri#2647 (comment). |
Would it work to make the instance field private?
|
I don't think so, because |
This is what I was referring to in rust-lang/miri#2647 (comment). We no longer hand out a
&mut Vec<Frame>
anywhere, so we get control over exactly how and where frames are added to or removed from the stack. All the better-not-be-inconsistent state can be put in a small module that is easy to reason about.r? @RalfJung