Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make default bridge generation smarter #2520

Closed
@sjrd

Description

@sjrd

Since 2.12.0-M5 does not generate explicit bridges to default methods in classes anymore, the linker has more responsibility in creating default method bridges. But the way it does this is suboptimal. Consider:

trait Foo {
  def foo(): Int = 5
}
class A extends Foo
class B extends A
class C extends A

An ideal solution (and what happened when scalac generated the bridges) is to create the bridge in A:

class A extends Foo {
  def foo(): Int = this.Foo::foo()
}
class B extends A
class C extends A

But the way the linker works for now is a bit stupid, and it will generate bridges in all the instantiated subclasses of A. So if A, B and C are all instantiated, we end up with

class A extends Foo {
  def foo(): Int = this.Foo::foo()
}
class B extends A {
  def foo(): Int = this.Foo::foo()
}
class C extends A {
  def foo(): Int = this.Foo::foo()
}

We should make the default bridge generation smarter so that it generates a bridge in the most appropriate place in the parent chain of a class.

Metadata

Metadata

Assignees

Labels

optimizationOptimization only. Does not affect semantics or correctness.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions