MIR Call terminator: evaluate destination place before arguments#155932
MIR Call terminator: evaluate destination place before arguments#155932RalfJung wants to merge 1 commit intorust-lang:mainfrom
Conversation
|
Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred to the CTFE machinery This PR changes MIR cc @oli-obk, @JakobDegen, @vakaras |
|
r? @eholk rustbot has assigned @eholk. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
This feels like a step backwards since in rust-lang/rfcs#3943 I'm moving towards always having destination places (for assignments, calls, everything) evaluated last.
Isn't the order also significant due to tree/stack borrow invalidations? For example: If the destination is evaluated first then the |
|
As another data point, it seems that for |
"evaluating the destination" means computing the place. It doesn't mean writing anything to that place. Obviously the actual write can only happen after the function returns. So in your example, evaluating the destination just consists of looking up the address of For the same reason,
I can't make heads or tails of that code, but this would be quite unexpected in my eyes. I would consider this a bug in coroutine lowering. Note that this is inconsistent with functions calls already before my PR -- for function calls, the destination unambiguously gets evaluated before the call. I don't think evaluating it after the call is even an option, the only question is in which order |
|
Right, I'd forgotten that deref doesn't actually perform a read for the destination place. However you can still force a read by using index projections which perform a read of a local during destination place evaluation: You can try this in the playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=41066970b751d6dd9bc53a16010521e5 With that said, all this shows is that the evaluation order does have a semantic difference, it's not an argument on whether or not we should make the change. |
See #155680 for context.
Cc @Amanieu @rust-lang/wg-mir-opt
Looking at codegen, the order there seems to be
funcdestargsHowever, the order also should not make any semantic difference since evaluating operands and places are read-only operations. It just matters for Miri since while evaluating arguments we set up "protectors" for in-place arguments.