Skip to content

Fix bytecode generation for Single Abstract Method lambdas #11839

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

Merged
merged 2 commits into from
Mar 24, 2021

Conversation

prolativ
Copy link
Contributor

Partially based on scala/scala#6087

Fixes #10068
Fixes #11676

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, @hrhino might be interested in taking a look too.

val methodName = samMethod.javaSimpleName
val samMethodType = asmMethodType(samMethod).toASMType
val needsGenericBridge = samMethodType != instantiatedMethodType
val bridgeMethods = atPhase(erasurePhase.prev){
Copy link
Member

Choose a reason for hiding this comment

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

This can actually be run at erasurePhase because when running at a certain phase we see the types as they are before the phase denotation transformer is run.

Suggested change
val bridgeMethods = atPhase(erasurePhase.prev){
val bridgeMethods = atPhase(erasurePhase) {

@@ -927,8 +927,10 @@ object Types {
*/
final def possibleSamMethods(using Context): Seq[SingleDenotation] = {
record("possibleSamMethods")
abstractTermMembers.toList.filterConserve(m =>
!m.symbol.matchingMember(defn.ObjectType).exists && !m.symbol.isSuperAccessor)
atPhaseNoLater(erasurePhase.prev) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here:

Suggested change
atPhaseNoLater(erasurePhase.prev) {
atPhaseNoLater(erasurePhase) {

Comment on lines 436 to 438
val Seq(unerasedSam) = lambdaType.possibleSamMethods
// We're now in erasure so the alternatives will have erased types
val Seq(erasedSam: MethodType) = unerasedSam.symbol.alternatives.map(_.info)
Copy link
Member

Choose a reason for hiding this comment

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

To avoid this complication I suggest changing possibleSamMethods to do .map(_.current) at the end so the denotations always correspond to the current phase.

mt.toASMType
val methodName = samMethod.javaSimpleName
val samMethodType = asmMethodType(samMethod).toASMType
val needsGenericBridge = samMethodType != instantiatedMethodType
Copy link
Member

Choose a reason for hiding this comment

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

I suggest adding the same comment than in Scala 2 for context:

Suggested change
val needsGenericBridge = samMethodType != instantiatedMethodType
// scala/bug#10334: make sure that a lambda object for `T => U` has a method `apply(T)U`, not only the `(Object)Object`
// version. Using the lambda a structural type `{def apply(t: T): U}` causes a reflective lookup for this method.
val needsGenericBridge = samMethodType != instantiatedMethodType

@smarter smarter assigned prolativ and unassigned smarter Mar 23, 2021
@prolativ prolativ force-pushed the fix-SAM-lambda-syntax branch from 9f2868f to 3372b2a Compare March 24, 2021 10:53
@prolativ prolativ force-pushed the fix-SAM-lambda-syntax branch from 3372b2a to 2ab6f5d Compare March 24, 2021 15:48
@prolativ
Copy link
Contributor Author

@smarter reworks done

@smarter smarter enabled auto-merge March 24, 2021 15:53
@griggt
Copy link
Contributor

griggt commented Mar 24, 2021

community_build_a seems to be hung, it's been running for 3.5 hours

https://github.com/lampepfl/dotty/runs/2185729042?check_suite_focus=true

@smarter
Copy link
Member

smarter commented Mar 24, 2021

Looks like it was stuck in zio, maybe it would benefit from a larger heap? Restarting for now.

@smarter smarter merged commit 9522b0f into scala:master Mar 24, 2021
@smarter smarter deleted the fix-SAM-lambda-syntax branch March 24, 2021 20:35
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 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
4 participants