Skip to content

Dotty emits unnecessary forwarders for trait methods #1206

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

Closed
lrytz opened this issue Apr 6, 2016 · 3 comments
Closed

Dotty emits unnecessary forwarders for trait methods #1206

lrytz opened this issue Apr 6, 2016 · 3 comments

Comments

@lrytz
Copy link
Member

lrytz commented Apr 6, 2016

While working on scala/scala-dev#98 to eliminate unnecessary forwarders for inherited trait methods I basically followed dotty's approach (https://github.com/lampepfl/dotty/blob/master/src/dotty/tools/dotc/transform/MixinOps.scala#L45).

I realized that dotty still emits unnecesary forwarders:

trait T1 { def f = 1 }
trait T2 extends T1 { override def f = 2 }
trait T3 { self: T1 => override def f = 2 }
class C1 extends T1 with T2 // no forwarder needed
class C2 extends T1 with T3 // forwarder needed

Dotty emits an unnecessary forwarder in C1.

See scala/scala#5085 for my patch to scala/scala.

@DarkDimius
Copy link
Contributor

@lrytz, Are you sure that in C1 no forwarder is needed?

http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.4.3.3

Otherwise, if any superinterface of C declares a method with the name and descriptor specified by the method reference that has neither its ACC_PRIVATE flag nor its ACC_STATIC flag set, one of these is arbitrarily chosen and method lookup succeeds.

Afaik, the spec says that you need it here. Am I missing something?

@lrytz
Copy link
Member Author

lrytz commented Apr 6, 2016

it's covered by the point above, IUC.

If the maximally-specific superinterface methods of C for the name and descriptor specified by the method reference include exactly one method that does not have its ACC_ABSTRACT flag set, then this method is chosen and method lookup succeeds.

see jvms-5.4.3.3, "maximally-specific method"

@smarter
Copy link
Member

smarter commented Jan 28, 2019

I believe this is now moot since scalac ended up having -Xmixin-force-forwarders default to true for performance reasons (and dotty should imitate this behavior and emit more forwarders, not less), feel free to reopen if I'm missing something.

@smarter smarter closed this as completed Jan 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants