Skip to content

Commit a6d0f65

Browse files
committed
Revert "Emit mixin forwarders as bridges"
This reverts commit 6d0f9ca. Forward port of most commits in scala/scala#8037 Compensate some of the consequences by adding the `MixedIn` flag. In addition to the use seen in the diff in `BCodeHelpers`, the JS backend has an existing test for `isOneOf(Bridge | MixedIn)` which needs this compensation.
1 parent d31094f commit a6d0f65

File tree

17 files changed

+83
-79
lines changed

17 files changed

+83
-79
lines changed

compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ trait BCodeHelpers extends BCodeIdiomatic {
491491
report.debuglog(s"Potentially conflicting names for forwarders: $conflictingNames")
492492

493493
for (m0 <- sortedMembersBasedOnFlags(moduleClass.info, required = Method, excluded = ExcludedForwarder)) {
494-
val m = if (m0.is(Bridge)) m0.nextOverriddenSymbol else m0
494+
val m = if (m0.isOneOf(Bridge | MixedIn)) m0.nextOverriddenSymbol else m0
495495
if (m == NoSymbol)
496496
report.log(s"$m0 is a bridge method that overrides nothing, something went wrong in a previous phase.")
497497
else if (m.isType || m.is(Deferred) || (m.owner eq defn.ObjectClass) || m.isConstructor || m.name.is(ExpandedName))
@@ -507,10 +507,7 @@ trait BCodeHelpers extends BCodeIdiomatic {
507507
// we generate ACC_SYNTHETIC forwarders so Java compilers ignore them.
508508
val isSynthetic =
509509
m0.name.is(NameKinds.SyntheticSetterName) ||
510-
// Only hide bridges generated at Erasure, mixin forwarders are also
511-
// marked as bridge but shouldn't be hidden since they don't have a
512-
// non-bridge overload.
513-
m0.is(Bridge) && m0.initial.validFor.firstPhaseId == erasurePhase.next.id
510+
m0.is(Bridge)
514511
addForwarder(jclass, moduleClass, m, isSynthetic)
515512
}
516513
}

compiler/src/dotty/tools/dotc/transform/Mixin.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase =>
306306
for (meth <- mixin.info.decls.toList if needsMixinForwarder(meth))
307307
yield {
308308
util.Stats.record("mixin forwarders")
309-
transformFollowing(DefDef(mkForwarderSym(meth.asTerm, Bridge), forwarderRhsFn(meth)))
309+
transformFollowing(DefDef(mkForwarderSym(meth.asTerm, extraFlags = MixedIn), forwarderRhsFn(meth)))
310310
}
311311

312312
cpy.Template(impl)(

compiler/test/dotc/run-test-pickling.excludelist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ i9473.scala
1212
i13433.scala
1313
i13433b.scala
1414
macros-in-same-project1
15-
mixin-forwarder-overload
1615
t10889
1716
t3452d
1817
t3452e
1918
t3452g
2019
t7374
21-
t8905
2220
tuple-drop.scala
2321
tuple-ops.scala
2422
tuple-ops.scala

tests/run/mixin-bridge-methods.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// scalajs: --skip
2+
3+
trait Foo {
4+
def getFoo() = "foo"
5+
}
6+
7+
class Sub extends Foo {
8+
def getBar() = "bar"
9+
}
10+
11+
object Test {
12+
def main(args: Array[String]): Unit = {
13+
val ms = classOf[Sub].getDeclaredMethods
14+
assert(ms forall (x => !x.isBridge), ms mkString " ")
15+
}
16+
}

tests/run/mixin-forwarder-overload/A.scala

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/run/mixin-forwarder-overload/Test.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/run/mixin-signatures.check

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
class Test$bar1$ {
2+
public java.lang.String Test$bar1$.f(java.lang.Object)
23
public java.lang.Object Test$bar1$.f(java.lang.Object) <bridge> <synthetic>
3-
public java.lang.String Test$bar1$.f(java.lang.Object) <bridge> <synthetic>
44
public java.lang.String Test$bar1$.g(java.lang.String)
55
public java.lang.Object Test$bar1$.g(java.lang.Object) <bridge> <synthetic>
66
public java.lang.String Test$bar1$.g(java.lang.Object) <bridge> <synthetic>
7-
public java.lang.Object Test$bar1$.h(java.lang.Object) <bridge> <synthetic>
7+
public java.lang.Object Test$bar1$.h(java.lang.Object)
88
}
99

1010
class Test$bar2$ {
11+
public java.lang.Object Test$bar2$.f(java.lang.String)
1112
public java.lang.Object Test$bar2$.f(java.lang.Object) <bridge> <synthetic>
12-
public java.lang.Object Test$bar2$.f(java.lang.String) <bridge> <synthetic>
1313
public java.lang.String Test$bar2$.g(java.lang.String)
1414
public java.lang.Object Test$bar2$.g(java.lang.Object) <bridge> <synthetic>
1515
public java.lang.Object Test$bar2$.g(java.lang.String) <bridge> <synthetic>
16-
public java.lang.Object Test$bar2$.h(java.lang.Object) <bridge> <synthetic>
16+
public java.lang.Object Test$bar2$.h(java.lang.Object)
1717
}
1818

1919
class Test$bar3$ {
@@ -23,7 +23,7 @@ class Test$bar3$ {
2323
public java.lang.String Test$bar3$.g(java.lang.String)
2424
public java.lang.Object Test$bar3$.g(java.lang.Object) <bridge> <synthetic>
2525
public java.lang.String Test$bar3$.g(java.lang.Object) <bridge> <synthetic>
26-
public java.lang.Object Foo3.h(java.lang.Object) <bridge> <synthetic>
26+
public java.lang.Object Foo3.h(java.lang.Object)
2727
}
2828

2929
class Test$bar4$ {
@@ -33,7 +33,7 @@ class Test$bar4$ {
3333
public java.lang.String Test$bar4$.g(java.lang.String)
3434
public java.lang.Object Test$bar4$.g(java.lang.Object) <bridge> <synthetic>
3535
public java.lang.Object Test$bar4$.g(java.lang.String) <bridge> <synthetic>
36-
public java.lang.Object Foo4.h(java.lang.Object) <bridge> <synthetic>
36+
public java.lang.Object Foo4.h(java.lang.Object)
3737
}
3838

3939
class Test$bar5$ {
@@ -45,7 +45,7 @@ class Test$bar5$ {
4545
public java.lang.Object Test$bar5$.g(java.lang.Object) <bridge> <synthetic>
4646
public java.lang.Object Test$bar5$.g(java.lang.String) <bridge> <synthetic>
4747
public java.lang.String Test$bar5$.g(java.lang.Object) <bridge> <synthetic>
48-
public java.lang.Object Test$bar5$.h(java.lang.Object) <bridge> <synthetic>
48+
public java.lang.Object Test$bar5$.h(java.lang.Object)
4949
}
5050

5151
interface Foo1 {

tests/run/t3452b-bcode/J_2.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class J_2 {
2+
public static void j() {
3+
StringSearch.search("test");
4+
StringSearch.searchC("test");
5+
}
6+
}

tests/run/t3452b-bcode/S_1.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
trait Search[M] {
2+
def search(input: M): C[Int] = {
3+
println("Search received: " + input)
4+
null
5+
}
6+
}
7+
8+
class SearchC[M] {
9+
def searchC(input: M): C[Int] = {
10+
println("SearchC received: " + input)
11+
null
12+
}
13+
}
14+
15+
object StringSearch extends SearchC[String] with Search[String]
16+
17+
trait C[T]

tests/run/t3452b-bcode/S_3.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// scalajs: --skip
2+
3+
object Test {
4+
def main(args: Array[String]): Unit = {
5+
J_2.j()
6+
}
7+
}

tests/run/t3452d/A.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ trait TraversableLike[A, Repr] {
22
def tail: Repr = null.asInstanceOf[Repr]
33
}
44

5-
abstract class AbstractTrav[A] extends TraversableLike[A, Iterable[A]]
5+
abstract class AbstractTrav[A] extends TraversableLike[A, Traversable[A]]
66

77
class C[A] extends AbstractTrav[A]

tests/run/t3452d/Test.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
public class Test {
44
public static void main(String[] args) {
55
C<String> c = new C<String>();
6-
scala.collection.Iterable<String> ls = c.tail();
6+
// TODO add a bridge during mixin so we can expose
7+
// sharper generic signature for `tail`.
8+
/*Traversable<String>*/ Object ls = c.tail();
79
}
810
}

tests/run/t3452g/A.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ trait TraversableLike[A, Repr] {
44

55
abstract class AbstractTrav[A] extends TraversableLike[A, AbstractTrav[A]]
66

7-
class C1 extends AbstractTrav[String]
8-
97
object O extends AbstractTrav[String]
108

11-
class C2[A] extends AbstractTrav[A]
9+
class C[A] extends AbstractTrav[A]

tests/run/t3452g/Test.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// scalajs: --skip
22

33
public class Test {
4-
public static void main(String[] args) {
5-
AbstractTrav<String> lsSharp1 = new C1().tail();
4+
public static void main(String[] args) {
5+
// To get better types here, we would need to
6+
// add bridge during mixin so we can expose
7+
// a generic return type of Traversable<A>, because the erasure
8+
// of this (Traversable) differs from the erasure of the mixed
9+
// method (erasure(Repr) = Object)
610

7-
// Object is the result type for the static forwarder (might be because of #11305)
8-
Object lsSharp2 = O.tail();
11+
Object lsSharp = O.tail();
912

10-
AbstractTrav<String> lsSharp3 = new C2<String>().tail();
11-
}
13+
Object lsSharp2 = new C<String>().tail();
14+
}
1215
}

tests/run/t3452h.scala

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
class Mix___eFoo_I_wBar__f extends Foo_I_ with Bar__f { f; }
1+
class Mix extends Foo with Bar { f; }
22
trait T
3-
abstract class Foo_I_ { class I extends T ; def f: I ; f; }
4-
trait Bar__f { type I>:Null<:T; def f: I = {null}; f; def gobble: I = {null}}
3+
abstract class Foo {
4+
class I extends T
5+
def f: I
6+
f
7+
}
8+
trait Bar {
9+
type I >: Null <: T
10+
def f: I = null
11+
f
12+
def gobble: I = null
13+
}
514

615
object Test extends App {
7-
new Mix___eFoo_I_wBar__f
16+
new Mix
817
}

tests/run/t8905/DoubleRDD.scala

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/run/t8905/Test.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)