Skip to content

Commit 4b543e8

Browse files
authored
Revert "Emit mixin forwarders as ordinary, non-bridge methods again" (#23613)
Reverts #21890 The new build catches an issue when building `scala3-sbt-bridge-bootstrapped`. At the moment, I don't have the resources to handle the failure.
2 parents 59e0717 + 5453403 commit 4b543e8

32 files changed

+103
-245
lines changed

.gitmodules

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
[submodule "community-build/community-projects/scala-parallel-collections"]
101101
path = community-build/community-projects/scala-parallel-collections
102102
url = https://github.com/dotty-staging/scala-parallel-collections.git
103-
branch = serialisation-stability-fix
104103
[submodule "community-build/community-projects/scala-collection-compat"]
105104
path = community-build/community-projects/scala-collection-compat
106105
url = https://github.com/dotty-staging/scala-collection-compat.git

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import dotty.tools.dotc.core.Types.*
3131
import dotty.tools.dotc.core.TypeErasure
3232
import dotty.tools.dotc.transform.GenericSignatures
3333
import dotty.tools.dotc.transform.ElimErasedValueType
34-
import dotty.tools.dotc.transform.Mixin
3534
import dotty.tools.io.AbstractFile
3635
import dotty.tools.dotc.report
3736

@@ -396,20 +395,12 @@ trait BCodeHelpers extends BCodeIdiomatic {
396395
*/
397396
def getGenericSignature(sym: Symbol, owner: Symbol): String = {
398397
atPhase(erasurePhase) {
399-
def computeMemberTpe(): Type =
398+
val memberTpe =
400399
if (sym.is(Method)) sym.denot.info
401400
else if sym.denot.validFor.phaseId > erasurePhase.id && sym.isField && sym.getter.exists then
402401
// Memoization field of getter entered after erasure, see run/i17069 for an example
403402
sym.getter.denot.info.resultType
404403
else owner.denot.thisType.memberInfo(sym)
405-
406-
val memberTpe = if sym.is(MixedIn) then
407-
mixinPhase.asInstanceOf[Mixin].mixinForwarderGenericInfos.get(sym) match
408-
case Some(genericInfo) => genericInfo
409-
case none => computeMemberTpe()
410-
else
411-
computeMemberTpe()
412-
413404
getGenericSignatureHelper(sym, owner, memberTpe).orNull
414405
}
415406
}
@@ -500,7 +491,7 @@ trait BCodeHelpers extends BCodeIdiomatic {
500491
report.debuglog(s"Potentially conflicting names for forwarders: $conflictingNames")
501492

502493
for (m0 <- sortedMembersBasedOnFlags(moduleClass.info, required = Method, excluded = ExcludedForwarder)) {
503-
val m = if (m0.isOneOf(Bridge | MixedIn)) m0.nextOverriddenSymbol else m0
494+
val m = if (m0.is(Bridge)) m0.nextOverriddenSymbol else m0
504495
if (m == NoSymbol)
505496
report.log(s"$m0 is a bridge method that overrides nothing, something went wrong in a previous phase.")
506497
else if (m.isType || m.is(Deferred) || (m.owner eq defn.ObjectClass) || m.isConstructor || m.name.is(ExpandedName))
@@ -516,7 +507,10 @@ trait BCodeHelpers extends BCodeIdiomatic {
516507
// we generate ACC_SYNTHETIC forwarders so Java compilers ignore them.
517508
val isSynthetic =
518509
m0.name.is(NameKinds.SyntheticSetterName) ||
519-
m0.is(Bridge)
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
520514
addForwarder(jclass, moduleClass, m, isSynthetic)
521515
}
522516
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I, val frontendAcce
299299
// illegal combination of modifiers at the bytecode level so
300300
// suppress final if abstract if present.
301301
&& !sym.isOneOf(AbstractOrTrait)
302-
// Bridges can be final, but final bridges confuse some frameworks
302+
// Mixin forwarders are bridges and can be final, but final bridges confuse some frameworks
303303
&& !sym.is(Bridge), ACC_FINAL)
304304
.addFlagIf(sym.isStaticMember, ACC_STATIC)
305305
.addFlagIf(sym.is(Bridge), ACC_BRIDGE | ACC_SYNTHETIC)

compiler/src/dotty/tools/dotc/core/Phases.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ object Phases {
239239
private var myErasurePhase: Phase = uninitialized
240240
private var myElimErasedValueTypePhase: Phase = uninitialized
241241
private var myLambdaLiftPhase: Phase = uninitialized
242-
private var myMixinPhase: Phase = uninitialized
243242
private var myCountOuterAccessesPhase: Phase = uninitialized
244243
private var myFlattenPhase: Phase = uninitialized
245244
private var myGenBCodePhase: Phase = uninitialized
@@ -267,7 +266,6 @@ object Phases {
267266
final def gettersPhase: Phase = myGettersPhase
268267
final def erasurePhase: Phase = myErasurePhase
269268
final def elimErasedValueTypePhase: Phase = myElimErasedValueTypePhase
270-
final def mixinPhase: Phase = myMixinPhase
271269
final def lambdaLiftPhase: Phase = myLambdaLiftPhase
272270
final def countOuterAccessesPhase = myCountOuterAccessesPhase
273271
final def flattenPhase: Phase = myFlattenPhase
@@ -297,7 +295,6 @@ object Phases {
297295
myErasurePhase = phaseOfClass(classOf[Erasure])
298296
myElimErasedValueTypePhase = phaseOfClass(classOf[ElimErasedValueType])
299297
myPatmatPhase = phaseOfClass(classOf[PatternMatcher])
300-
myMixinPhase = phaseOfClass(classOf[Mixin])
301298
myLambdaLiftPhase = phaseOfClass(classOf[LambdaLift])
302299
myCountOuterAccessesPhase = phaseOfClass(classOf[CountOuterAccesses])
303300
myFlattenPhase = phaseOfClass(classOf[Flatten])
@@ -553,7 +550,6 @@ object Phases {
553550
def gettersPhase(using Context): Phase = ctx.base.gettersPhase
554551
def erasurePhase(using Context): Phase = ctx.base.erasurePhase
555552
def elimErasedValueTypePhase(using Context): Phase = ctx.base.elimErasedValueTypePhase
556-
def mixinPhase(using Context): Phase = ctx.base.mixinPhase
557553
def lambdaLiftPhase(using Context): Phase = ctx.base.lambdaLiftPhase
558554
def flattenPhase(using Context): Phase = ctx.base.flattenPhase
559555
def genBCodePhase(using Context): Phase = ctx.base.genBCodePhase

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import StdNames.*
1616
import Names.*
1717
import NameKinds.*
1818
import NameOps.*
19-
import Phases.erasurePhase
2019
import ast.Trees.*
2120

2221
import dotty.tools.dotc.transform.sjs.JSSymUtils.isJSType
@@ -116,15 +115,6 @@ object Mixin {
116115
class Mixin extends MiniPhase with SymTransformer { thisPhase =>
117116
import ast.tpd.*
118117

119-
/** Infos before erasure of the generated mixin forwarders.
120-
*
121-
* These will be used to generate Java generic signatures of the mixin
122-
* forwarders. Normally we use the types before erasure; we cannot do that
123-
* for mixin forwarders since they are created after erasure, and therefore
124-
* their type history does not have anything recorded for before erasure.
125-
*/
126-
val mixinForwarderGenericInfos = MutableSymbolMap[Type]()
127-
128118
override def phaseName: String = Mixin.name
129119

130120
override def description: String = Mixin.description
@@ -315,25 +305,8 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase =>
315305
for (meth <- mixin.info.decls.toList if needsMixinForwarder(meth))
316306
yield {
317307
util.Stats.record("mixin forwarders")
318-
transformFollowing(DefDef(mkMixinForwarderSym(meth.asTerm), forwarderRhsFn(meth)))
319-
}
320-
321-
def mkMixinForwarderSym(target: TermSymbol): TermSymbol =
322-
val sym = mkForwarderSym(target, extraFlags = MixedIn)
323-
val (infoBeforeErasure, isDifferentThanInfoNow) = atPhase(erasurePhase) {
324-
val beforeErasure = cls.thisType.memberInfo(target)
325-
(beforeErasure, !(beforeErasure =:= sym.info))
308+
transformFollowing(DefDef(mkForwarderSym(meth.asTerm, Bridge), forwarderRhsFn(meth)))
326309
}
327-
if isDifferentThanInfoNow then
328-
// The info before erasure would not have been the same as the info now.
329-
// We want to store it for the backend to compute the generic Java signature.
330-
// However, we must still avoid doing that if erasing that signature would
331-
// not give the same erased type. If it doesn't, we'll just give a completely
332-
// incorrect Java signature. (This could be improved by generating dedicated
333-
// bridges, but we don't go that far; scalac doesn't either.)
334-
if TypeErasure.transformInfo(target, infoBeforeErasure) =:= sym.info then
335-
mixinForwarderGenericInfos(sym) = infoBeforeErasure
336-
sym
337310

338311
cpy.Template(impl)(
339312
constr =

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ i9473.scala
1212
i13433.scala
1313
i13433b.scala
1414
macros-in-same-project1
15+
mixin-forwarder-overload
1516
t10889
1617
t3452d
1718
t3452e
1819
t3452g
1920
t7374
21+
t8905
2022
tuple-drop.scala
2123
tuple-ops.scala
2224
tuple-ops.scala

project/Scala2LibraryBootstrappedMiMaFilters.scala

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -193,45 +193,7 @@ object Scala2LibraryBootstrappedMiMaFilters {
193193
"scala.util.matching.Regex.Groups", "scala.util.matching.Regex.Match",
194194
"scala.util.package.chaining",
195195
"scala.util.Using.Manager", "scala.util.Using.Releasable", "scala.util.Using#Releasable.AutoCloseableIsReleasable",
196-
).map(ProblemFilters.exclude[MissingFieldProblem]) ++ Seq(
197-
// DirectMissingMethodProblem by flags being changed from ACC_PUBLIC, ACC_BRIDGE, ACC_SYNTHETIC to ACC_PUBLIC in mixin forwarders:
198-
// * from java.util.Comparator:
199-
Seq("reversed", "thenComparing", "thenComparingInt", "thenComparingLong", "thenComparingInt", "thenComparingDouble").flatMap { method =>
200-
Seq(
201-
ProblemFilters.exclude[DirectMissingMethodProblem](s"scala.Enumeration#ValueOrdering.$method"),
202-
ProblemFilters.exclude[DirectMissingMethodProblem](s"scala.concurrent.duration.Deadline#DeadlineIsOrdered.$method"),
203-
ProblemFilters.exclude[DirectMissingMethodProblem](s"scala.concurrent.duration.Duration#DurationIsOrdered.$method"),
204-
ProblemFilters.exclude[DirectMissingMethodProblem](s"scala.concurrent.duration.FiniteDuration#FiniteDurationIsOrdered.$method"),
205-
ProblemFilters.exclude[DirectMissingMethodProblem](s"scala.math.Numeric#*.$method"),
206-
ProblemFilters.exclude[DirectMissingMethodProblem](s"scala.math.Ordering#*.$method"),
207-
)
208-
},
209-
// * from java.util.Spliterator:
210-
Seq("getExactSizeIfKnown", "hasCharacteristics", "getComparator").flatMap { method =>
211-
Seq(
212-
ProblemFilters.exclude[DirectMissingMethodProblem](s"scala.collection.DoubleStepper#DoubleStepperSpliterator.$method"),
213-
ProblemFilters.exclude[DirectMissingMethodProblem](s"scala.collection.IntStepper#IntStepperSpliterator.$method"),
214-
ProblemFilters.exclude[DirectMissingMethodProblem](s"scala.collection.LongStepper#LongStepperSpliterator.$method"),
215-
)
216-
},
217-
// * from java.util.Enumeration:
218-
Seq(
219-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#IteratorWrapper.asIterator"),
220-
),
221-
// * from java.lang.CharSequence:
222-
Seq(
223-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.Predef#ArrayCharSequence.isEmpty"),
224-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.Predef#SeqCharSequence.isEmpty"),
225-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.ArrayCharSequence.isEmpty")
226-
),
227-
// FinalMethodProblem - seems to be a bug in MiMa, as neither new or old version do not have final modifier.
228-
// What did change is that sizeHint, and requireBounds had `final` added, but that does not get reported.
229-
Seq(
230-
ProblemFilters.exclude[FinalMethodProblem]("scala.**.sizeHint$default$2"),
231-
ProblemFilters.exclude[FinalMethodProblem]("scala.collection.mutable.ArrayDeque.requireBounds$default$2")
232-
)
233-
).flatten
234-
196+
).map(ProblemFilters.exclude[MissingFieldProblem])
235197
}
236198
)
237199
}

tests/pos/11484/A_2.java

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/pos/11484/C_1.scala

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

0 commit comments

Comments
 (0)