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

Fix beta-reduction with Nothing and null args #16938

Merged
merged 1 commit into from
Feb 21, 2023

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Feb 16, 2023

Use parameter type as binding type when the argument is of type Nothing or null.

Fixes part of #15165

@nicolasstucki
Copy link
Contributor Author

It fixes this sub-issue #15165 (comment)

@natsukagami
Copy link
Contributor

Why do we not always just use the parameter types?

@nicolasstucki
Copy link
Contributor Author

Using the argument type propagates call site knowledge into the implementation of the lambda. This can be used in transparent inline methods or to devirtualize a call at compile time (which could trigger further optimizations).

Copy link
Contributor

@natsukagami natsukagami left a comment

Choose a reason for hiding this comment

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

Looks good! I tried playing with it for a bit, seems solid

@@ -128,7 +128,10 @@ object BetaReduce:
ref.symbol
case _ =>
val flags = Synthetic | (param.symbol.flags & Erased)
val tpe = if arg.tpe.dealias.isInstanceOf[ConstantType] then arg.tpe.dealias else arg.tpe.widen
val tpe =
if arg.tpe.isBottomType then param.tpe.widenTermRefExpr
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why we use widenTermRefExpr here (and not widen for example), just curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To keep the type precise. For example, if we have a singleton String type we do not want to widen it to String. For example ((x: "foo") => x: "foo").apply(???) should become val x: "foo" = ???; x: "foo" and not val x: String = ???; x: "foo". The second one would not type check after beta-reduction.

@nicolasstucki nicolasstucki merged commit 1821107 into scala:main Feb 21, 2023
@nicolasstucki nicolasstucki deleted the fix-part-of-15165 branch February 21, 2023 07:52
@Kordyjan Kordyjan added this to the 3.3.1 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.

None yet

3 participants