-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New phase: FunctionalInterfaces. Rewires closures to implement more specific types of Function SAMs. #488
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
Conversation
Rewires closures to implement more specific types of Function SAMs.
It seems that loading a class from class path does not define the class in previous phases. Are InfoTransformers applied? It seems to violate a lot of assumptions of what types&symbols are after erasure, as unerased types could leak into trees.
Function0, Function1, Function2 are all specialized for different type params. FunctionalInterface filters out classes that are known to not exists and relies on getClassIfDefined for a precise check.
@AlexSikia, you could be interested to reuse this. |
@odersky please review. |
So, currently something like: val x: Function1[Int,Int] = elem => elem + 1 Is rewritten as: val x: Function1[Int, Int] = {
def $anonfun(elem: Int): Int = elem.+(1)
closure($anonfun) // Pretty-print of Closure(Nil, $anonfun, EmptyTree)
} But if instead it was rewritten as: val x: Function1[Int, Int] = {
def $anonfun(elem: Int): Int = elem.+(1)
closure($anonfun:Function1[Int,Int]) // Pretty-print of Closure(Nil, $anonfun, Function1[Int, Int])
} Then this phase would not be needed: you could just replace |
I believe that this commit is entirely different from what specialization is about. Specialization knows nothing about SAM's and their particularities. |
What your phase does: Closure(Nil, $anonfun, EmptyTree) ===> Closure(Nil, $anonfun, Function$mcXX...) One of the thing that specialization does: new Foo[Int] ===> new Foo$mcXX... It seems like it wouldn't be very hard to extend specialization to do: Closure(Nil, $anonfun, Function1[Int]) ===> Closure(Nil, $anonfun, Function1$mcXX...) (As a bonus, it would also work for SAM types which are not FunctionN.) |
No it's not what it does! It does |
|
||
def phaseName: String = "functionalInterfaces" | ||
|
||
var allowedReturnTypes: Set[Symbol] = _ // moved here to make it explicit what specializations are generated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make private?
Otherwise LGTM |
New phase: FunctionalInterfaces. Rewires closures to implement more specific types of Function SAMs.
No description provided.