Skip to content

Conversation

@dwijnand
Copy link
Member

@dwijnand dwijnand commented Jun 1, 2020

Under -Ydelambdafy:method-ref, when a lambda is just invoking a method
(i.e. is "just a method reference"), such as foo() or x => bar(x),
(and other caveats around specialisation, boxing concerns for primitives
and its value classes, arrays, etc) then rather than emit an
invokedynamic to a helper method that invokes the target method, emit
an invokedynamic to the target method directly.

  • add some tests around serialization, ensure that the generated $deserializeLambda$ works as intended

Explanation

Note that this is opt-in, with -Ydelambdafy:method-ref. The reason it's opt-in is because there's an assumption (an "invariant") in serialisation: if you serialise the lambda from one version of some code (v1) then deserialising it in a later version (v2) should run the new (v2) behaviour.

For example, if you serialise the lambda (x => x.toString()) then deserialise it when the code is (x => x.toString().toUpperCase()), then the result should be upper-cased. Under -Ydelambdafy:method-ref the deserialised lambda will continue to just be a reference to Object's toString method. Also worth mentioning that in the same example, but with the versions swapped, the lambda will be a reference an $anonfun$... method that no longer exists in v2... which means that it will throw a LinkageError at runtime.

@scala-jenkins scala-jenkins added this to the 2.13.4 milestone Jun 1, 2020
@dwijnand dwijnand requested review from lrytz and retronym June 1, 2020 12:37
@SethTisue SethTisue added the performance the need for speed. usually compiler performance, sometimes runtime performance. label Jun 1, 2020
@dwijnand dwijnand changed the base branch from 2.13.x to 2.12.x June 4, 2020 14:34
@dwijnand dwijnand modified the milestones: 2.13.4, 2.12.12 Jun 4, 2020
@SethTisue

This comment has been minimized.

@dwijnand

This comment has been minimized.

@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Jun 4, 2020
@SethTisue

This comment has been minimized.

Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

maybe add some tests around serialization, ensure that the generated $deserializeLambda$ works as intended?

@dwijnand dwijnand force-pushed the indy-meth-refs branch 3 times, most recently from a8890ff to 75667a5 Compare June 9, 2020 16:13
@dwijnand

This comment has been minimized.

@retronym

This comment has been minimized.

@retronym retronym modified the milestones: 2.12.12, 2.12.13 Jun 23, 2020
@dwijnand dwijnand requested a review from lrytz July 17, 2020 14:10
@lrytz

This comment has been minimized.

Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

LGTM!

I guess t8549.scala failing is OK / expected?

@dwijnand

This comment has been minimized.

@dwijnand

This comment has been minimized.

@dwijnand

This comment has been minimized.

Under -Ydelambdafy:method-ref, when a lambda is just invoking a method
(i.e. is "just a method reference"), such as `foo()` or `x => bar(x)`,
then rather than emit an `invokedynamic` to a helper method that invokes
the target method, emit an `invokedynamic` to the target method
directly.
@dwijnand dwijnand merged commit e32b224 into scala:2.12.x Jul 27, 2020
@dwijnand dwijnand deleted the indy-meth-refs branch July 27, 2020 20:39
val lambdaTarget = originalTarget.attachments.get[JustMethodReference].map(_.lambdaTarget).getOrElse(originalTarget)
def asmType(sym: Symbol) = classBTypeFromSymbol(sym).toASMType

val isInterface = lambdaTarget.owner.isTrait
Copy link
Member

Choose a reason for hiding this comment

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

@dwijnand This needs to be generalized to isTraitOrInterface now that lambda implementation methods may be owned by Java interfaces.

Copy link
Member Author

Choose a reason for hiding this comment

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

@retronym retronym removed the release-notes worth highlighting in next release notes label Nov 30, 2020
@retronym
Copy link
Member

Removing the release-notes label as this is still experimental and not something that most users would need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance the need for speed. usually compiler performance, sometimes runtime performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants