-
Notifications
You must be signed in to change notification settings - Fork 844
[WIP] Prevent side-effect binding elimination #6527
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
|
Almost everything is passing, except Perhaps the IL for those 2 tests can be updated to match the new behavior (un-eliminated binding). |
KevinRansom
left a comment
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 feels like a good change.
I can't help thinking that some working, but buggy code is now going to work differently following a recompile with an updated compiler. However, I am in favour of developers fixing their code.
|
Rebased to latest. |
|
Including us, by the looks: |
|
@KevinRansom Yes, that's what is mentioned in my second comment, see above. |
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.
I'm not sure of the change. Binding elimination of x for let x = e in match x with ... is a safe optimization regardless if e causes a side effect or not.
What is your reasoning for the change? You said:
prevents multiple executions of the same pattern match test with side-effects
I'm not quite sure I understand this. Can you expand this explanation with an example?
|
@TIHan The test included in the PR provides an example. will be converted to (in pseudo-code): |
|
@ncave Thanks, that gives me clarity, specifically your pseudo-code. It's great that you have identified this. In principle, I think the optimized AST should not have a representation of multiple executions from the match optimization of what you described: if side_effect() then ...
else if side_effect() then ...
else ...This doesn't feel right for both side effect and side effect free executions, not just side effects. However, the actual IL generated doesn't have the multiple executions; somewhere down the line it gets re-written or IL generated in a special way. With your change, the IL gets generated differently; the binding elimination doesn't happen and it creates a local. Therefore, this hurts an existing optimization for us. My assumption is that this is for Fable; you all are relying on the optimized AST and you all hit this. Is that correct? |
|
@TIHan Yes, this issue (as stated in the PR) is manifesting in Optimized AST only. I'm unaware what other clients (besides Fable) are a consumer of optimized F# AST. |
dsyme
left a comment
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.
needs a matching issue
|
@dsyme Yes, it's unrelated to #6333. In plain words, the match test binding elimination optimization is incorrect when there are multiple cases (more than 2) to match, and the match test has side effects. But it's possible it may be a bit strong in its current form, perhaps we need to only check for side effects if more than 1 replacement is made. I'll see if I can fix that. |
|
@ncave Yes, I understand that this must fix an issue in the optimized expression trees being seen via the FCS API. However it seems to affect generated code too, by disabling the application of the optimization when it is sound. Two questions
Either way I really want to dig into what's up here, understand it, make sure we have full info on the issue and . THanks :) |
|
Keeping it downstream as not many clients use optimized AST. |
In Optimized AST, prevents binding elimination of pattern match tests with side-effects.
(i.e. prevents multiple executions of the same pattern match test with side-effects).