Skip to content
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

Handle binding of beta reduced inlined lambdas #16377

Merged
merged 2 commits into from
Nov 23, 2022

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Nov 18, 2022

Handle all inline beta-reduction in the InlineReducer. All these
applications will contain Inlined nodes that need to be handled
without changing the nestedness of expressions in inlining scopes.

Fixes #16374

Handle all inline beta-reduction in the InlineReducer. All these
applications will contain `Inlined` nodes that need to be handled
without changing the nestedness of expressions in inlining scopes.

Fixes scala#16374
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

case Inlined(call, bindings, expr) if bindings.forall(isPureBinding) =>
recur(expr).map(cpy.Inlined(cl)(call, bindings, _))
case Typed(expr, tpt) =>
recur(expr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we don't preserve the Typed node here?

Suggested change
recur(expr)
recur(expr).map(cpy.Typed(cl)(_, tpt))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is intentional. This ascription is on the lambda and hence has the lambda type, but the result of this transformation has the type of the result of this lambda. Dropping it is the simplest option. We could attempt to add the ascription again on the result. This would be more complicated and would also prevent optimizations on constants. We also do the same in https://github.com/lampepfl/dotty/blob/main/compiler/src/dotty/tools/dotc/transform/BetaReduce.scala#L57-L58.

@smarter smarter assigned nicolasstucki and unassigned smarter Nov 22, 2022
@smarter smarter merged commit 75f35a9 into scala:main Nov 23, 2022
@smarter smarter deleted the fix-#16374 branch November 23, 2022 08:24
@Kordyjan Kordyjan added this to the 3.3.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inline and beta reduction can generate incorrect Inlined trees
3 participants