Skip to content

Fix #3259: Generate overriding bridges in synthesized SAM wrappers. #3260

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 1 commit into from
Jan 19, 2018

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Jan 17, 2018

Just like Scala/JVM needs to instruct the LambdaMetaFactory to generate bridges for methods overridden by the SAM, we need to directly generate appropriate bridges in our synthesized SAM wrappers.

Instead of generating actual bridges, in the sense that they call the canonical implementation of the method, we generate bodies for all the bridges just like for the canonical method. This is fine because the bodies are just calling the closure stored in a field of the instance anyway.

Only the last commit is part of this PR. It will have to be rebased on top of #3258.

Tested locally with:

> clean
> set resolvers in Global += "scala-integration" at "https://scala-ci.typesafe.com/artifactory/scala-integration/"
> ++2.12.5-bin-707b0f3
> testSuite/test
> testSuiteJVM/test

@hrhino
Copy link

hrhino commented Jan 17, 2018

Thanks! I was going to poke at this over the weekend in case you were busy, but this is better ;)

@sjrd sjrd force-pushed the fix-sams-with-overriding-bridges branch from 4871252 to ae1a0af Compare January 17, 2018 18:54
@scala-jenkins
Copy link

Refer to this link for build results (access rights to CI server needed):

https://scala-webapps.epfl.ch/jenkins/job/scalajs-pr/4498/
https://scala-webapps.epfl.ch/jenkins/job/scalajs-matrix-build/6084/
Test FAILed.

@scala-jenkins
Copy link

Refer to this link for build results (access rights to CI server needed):

https://scala-webapps.epfl.ch/jenkins/job/scalajs-pr/4501/
https://scala-webapps.epfl.ch/jenkins/job/scalajs-matrix-build/6087/
Test FAILed.

@sjrd
Copy link
Member Author

sjrd commented Jan 17, 2018

Dear Jenkins, retest this please

@sjrd sjrd force-pushed the fix-sams-with-overriding-bridges branch from ae1a0af to 4748ffc Compare January 18, 2018 10:36
@sjrd
Copy link
Member Author

sjrd commented Jan 18, 2018

Rebased.

@sjrd sjrd changed the title DO NOT MERGE Fix #3259: Generate overriding bridges in synthesized SAM wrappers. Fix #3259: Generate overriding bridges in synthesized SAM wrappers. Jan 18, 2018
@scala-jenkins
Copy link

Refer to this link for build results (access rights to CI server needed):

https://scala-webapps.epfl.ch/jenkins/job/scalajs-pr/4503/
https://scala-webapps.epfl.ch/jenkins/job/scalajs-matrix-build/6090/
Test PASSed.

(if (isJSTest) ((testDir / "require-sam") ** "*.scala").get else Nil)
}

val hasBugWithOverridenMethods =
Copy link
Contributor

Choose a reason for hiding this comment

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

*overridden

}

for (sam <- samInfo.sam :: samBridges) {
if (seenEncodedNames.add(encodeMethodSym(sam).name))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the JVM backend does something similar (they call .disctinct here). I guess this would happen if a SAM type extends several interfaces, each defining the same method, which would then collapse as the same bridge. The most reliable way for us to detect duplicates at this point is to test uniqueness of the encodedName.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm... OK. Not very nice, but fair enough.

…ppers.

Just like Scala/JVM needs to instruct the `LambdaMetaFactory` to
generate bridges for methods overridden by the SAM, we need to
directly generate appropriate bridges in our synthesized SAM
wrappers.

Instead of generating actual *bridges*, in the sense that they call
the canonical implementation of the method, we generate bodies for
all the bridges just like for the canonical method. This is fine
because the bodies are just calling the closure stored in a field
of the instance anyway.
@sjrd sjrd force-pushed the fix-sams-with-overriding-bridges branch from 4748ffc to b6be908 Compare January 18, 2018 14:24
@sjrd
Copy link
Member Author

sjrd commented Jan 18, 2018

Updated.

@scala-jenkins
Copy link

Refer to this link for build results (access rights to CI server needed):

https://scala-webapps.epfl.ch/jenkins/job/scalajs-pr/4504/
https://scala-webapps.epfl.ch/jenkins/job/scalajs-matrix-build/6091/
Test PASSed.

@gzm0 gzm0 merged commit 211d486 into scala-js:0.6.x Jan 19, 2018
@sjrd sjrd deleted the fix-sams-with-overriding-bridges branch January 19, 2018 06:47
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.

4 participants