-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #8290: Make Expr.betaReduce give up when it sees a non-function typed closure #8293
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
…ion typed closure expression This commit addresses 2 issues with existing betaReduce behaviour: - when given a non-function typed closure the previous iteration could easily fail to resolve the correct apply method, or even successfully inline the wrong code (see added test cases) - if betaReduce did not successfully inline, it would return a transformed tree. This was fine until the above change made it possible to give up while inside a closureDef, which could insert a type ascription inside the closureDef's block, leading to betaReduce returning invalid trees (the closureDef block can only contain a DefDef and Closure, no type ascriptions). Fixing this issue would add meaningless complexity, so instead this commit changes betaReduce to cleanly give up by returning the function tree unchanged, only generating the code necessary to call it. Note: this change affects a few tests that were checking for betaReduce's slight changes to the function tree. Testing the correctness of this change is done by adding cases to existing tests for betaReduce's treatment of type ascriptions.
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.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Commit Messages
We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).
Please stick to these guidelines for commit messages:
- Separate subject from body with a blank line
- When fixing an issue, start your commit message with
Fix #<ISSUE-NBR>:
- Limit the subject line to 72 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line ("Add" instead of "Added")
- Wrap the body at 80 characters
- Use the body to explain what and why vs. how
adapted from https://chris.beams.io/posts/git-commit
Have an awesome day! ☀️
Sorry, I have no idea why git decides that when I push an unrelated thing it should just delete a branch that I pushed before. |
i = i.+(1) | ||
} | ||
while ({ | ||
val x$2: scala.Int = i | ||
f.apply(x$2) | ||
f.apply(i) |
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 change looks fishy
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.
How so? I figured it would make sense for betaReduce to either behave like f.appliedToArgs(...)
or a full inlining. (with this case being appliedToArgs
)
If the other way is preferred, can you explain why so I can know for future PRs?
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.
(the other way being "pull all the args out into vals or defs, then either inline or appliedToArgs")
I'm working on some major refactoring for this logic in #8457. I also adapted the contents of this PR. The fix looks good. |
Thank you for the fix |
Moved to #8457 |
Review by @nicolasstucki
This PR addresses 2 issues with existing betaReduce behaviour:
when given a non-function typed closure the previous iteration could easily fail to resolve the correct apply method, or even successfully inline the wrong code (see added test cases)
if betaReduce did not successfully inline, it would return a transformed tree. This was fine until the above change made it possible to give up while inside a closureDef, which could insert a type ascription inside the closureDef's block, leading to betaReduce returning invalid trees (the closureDef block can only contain a DefDef and Closure, no type ascriptions).
Fixing this issue would add meaningless complexity, so instead this commit changes betaReduce to cleanly give up by returning the function tree unchanged, only generating the code necessary to call it.
Note: this change affects a few tests that were checking for betaReduce's slight changes to the function tree.
Testing the correctness of this change is done by adding cases to existing tests for betaReduce's treatment of type ascriptions.