Skip to content

Commit 17e1d55

Browse files
committed
Simplify Scala 2 trait support
Drop vestigial code related to Scala 2.11 support. In particular, we created a fake impl class in AugmentScala2Trait only to add its members to the trait in LinkScala2Impls. We now directly add the members to the trait in LinkScala2Impls. We could potentially simplify things even further by getting rid of LinkScala2Impls since the static `foo$` methods in Scala 2 traits always forward to instance methods `foo`, but that could have performance implication as detailed in #5928, so we keep things as-is for now, but eventually we should either switch Dotty trait encoding to also use static forwarders, or not use them at all.
1 parent 757e2d1 commit 17e1d55

28 files changed

+102
-198
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class BTypesFromSymbols[I <: BackendInterface](val int: I) extends BTypes {
6161
}
6262

6363
private def setClassInfo(classSym: Symbol, classBType: ClassBType): ClassBType = {
64-
val superClassSym = if (classSym.isImplClass) ObjectClass else classSym.superClass
64+
val superClassSym = classSym.superClass
6565
assert(
6666
if (classSym == ObjectClass)
6767
superClassSym == NoSymbol

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ abstract class BackendInterface extends BackendInterfaceDefinitions {
484484
def isStrictFP: Boolean
485485
def isLabel: Boolean
486486
def hasPackageFlag: Boolean
487-
def isImplClass: Boolean
488487
def isInterface: Boolean
489488
def isGetter: Boolean
490489
def isSetter: Boolean

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,6 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
666666
def isStrictFP: Boolean = false // todo: implement
667667
def isLabel: Boolean = sym is Flags.Label
668668
def hasPackageFlag: Boolean = sym is Flags.Package
669-
def isImplClass: Boolean = sym is Flags.ImplClass
670669
def isInterface: Boolean = (sym is Flags.PureInterface) || (sym is Flags.Trait)
671670
def isGetter: Boolean = toDenot(sym).isGetter
672671
def isSetter: Boolean = toDenot(sym).isSetter
@@ -683,7 +682,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
683682

684683
def isFinal: Boolean = sym is Flags.Final
685684
def isStaticMember: Boolean = (sym ne NoSymbol) &&
686-
((sym is Flags.JavaStatic) || (owner is Flags.ImplClass) || toDenot(sym).hasAnnotation(ctx.definitions.ScalaStaticAnnot))
685+
((sym is Flags.JavaStatic) || toDenot(sym).hasAnnotation(ctx.definitions.ScalaStaticAnnot))
687686
// guard against no sumbol cause this code is executed to select which call type(static\dynamic) to use to call array.clone
688687

689688
def isBottomClass: Boolean = (sym ne defn.NullClass) && (sym ne defn.NothingClass)
@@ -701,7 +700,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
701700
def isNonBottomSubClass(other: Symbol): Boolean = sym.derivesFrom(other)
702701
def hasAnnotation(ann: Symbol): Boolean = toDenot(sym).hasAnnotation(ann)
703702
def shouldEmitForwarders: Boolean =
704-
(sym is Flags.Module) && !(sym is Flags.ImplClass) && sym.isStatic
703+
(sym is Flags.Module) && sym.isStatic
705704
def isJavaEntryPoint: Boolean = CollectEntryPoints.isJavaEntryPoint(sym)
706705

707706
def isClassConstructor: Boolean = toDenot(sym).isClassConstructor

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,8 +1575,6 @@ class JSCodeGen()(implicit ctx: Context) {
15751575
genApplyJSMethodGeneric(tree, sym, genExpr(receiver), genActualJSArgs(sym, args), isStat)
15761576
/*else
15771577
genApplyJSClassMethod(genExpr(receiver), sym, genActualArgs(sym, args))*/
1578-
} else if (foreignIsImplClass(sym.owner)) {
1579-
genTraitImplApply(sym, args.map(genExpr))
15801578
} else if (sym.isClassConstructor) {
15811579
// Calls to constructors are always statically linked
15821580
genApplyMethodStatically(genExpr(receiver), sym, genActualArgs(sym, args))
@@ -2022,12 +2020,6 @@ class JSCodeGen()(implicit ctx: Context) {
20222020
toIRType(patchedResultType(method)))
20232021
}
20242022

2025-
/** Gen a call to a Scala2 impl class method. */
2026-
private def genTraitImplApply(method: Symbol, arguments: List[js.Tree])(
2027-
implicit pos: Position): js.Tree = {
2028-
genApplyStatic(method, arguments)
2029-
}
2030-
20312023
/** Gen a call to a non-exposed method of a non-native JS class. */
20322024
private def genApplyJSClassMethod(receiver: js.Tree, method: Symbol,
20332025
arguments: List[js.Tree])(implicit pos: Position): js.Tree = {

compiler/src/dotty/tools/backend/sjs/JSEncoding.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,6 @@ object JSEncoding {
185185
js.Ident(localNames.localSymbolName(sym), Some(sym.unexpandedName.decoded))
186186
}
187187

188-
def foreignIsImplClass(sym: Symbol)(implicit ctx: Context): Boolean =
189-
sym.name.endsWith(nme.IMPL_CLASS_SUFFIX.toString)
190-
191188
def encodeClassType(sym: Symbol)(implicit ctx: Context): jstpe.Type = {
192189
if (sym == defn.ObjectClass) jstpe.AnyType
193190
else if (isJSType(sym)) jstpe.AnyType

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class Compiler {
8181
new ElimByName, // Expand by-name parameter references
8282
new CollectNullableFields, // Collect fields that can be nulled out after use in lazy initialization
8383
new ElimOuterSelect, // Expand outer selections
84-
new AugmentScala2Traits, // Expand traits defined in Scala 2.x to simulate old-style rewritings
84+
new AugmentScala2Traits, // Augments Scala2 traits with additional members needed for mixin composition.
8585
new ResolveSuper, // Implement super accessors and add forwarders to trait methods
8686
new FunctionXXLForwarders, // Add forwarders for FunctionXXL apply method
8787
new ArrayConstructors) :: // Intercept creation of (non-generic) arrays and intrinsify.

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ object Flags {
340340
/** An unpickled Scala 2.x class */
341341
final val Scala2x: FlagSet = typeFlag(26, "<scala-2.x>")
342342

343+
final val Scala2xTrait: FlagSet = Scala2x | Trait
344+
343345
final val SuperAccessorOrScala2x: FlagSet = Scala2x.toCommonFlags
344346

345347
/** A method that has default params */
@@ -413,11 +415,6 @@ object Flags {
413415
/** Symbol is a self name */
414416
final val SelfName: FlagSet = termFlag(54, "<selfname>")
415417

416-
/** Symbol is an implementation class of a Scala2 trait */
417-
final val ImplClass: FlagSet = typeFlag(54, "<implclass>")
418-
419-
final val SelfNameOrImplClass: FlagSet = SelfName.toCommonFlags
420-
421418
/** An existentially bound symbol (Scala 2.x only) */
422419
final val Scala2ExistentialCommon: FlagSet = commonFlag(55, "<existential>")
423420
final val Scala2Existential: FlagSet = Scala2ExistentialCommon.toTypeFlags
@@ -428,14 +425,11 @@ object Flags {
428425
/** A module variable (Scala 2.x only) */
429426
final val Scala2ModuleVar: FlagSet = termFlag(57, "<modulevar>")
430427

431-
/** A Scala 2.12 trait that has been augmented with static members */
432-
final val Scala_2_12_Augmented: FlagSet = typeFlag(57, "<scala_2_12_augmented>")
433-
434-
/** A definition that's initialized before the super call (Scala 2.x only) */
435-
final val Scala2PreSuper: FlagSet = termFlag(58, "<presuper>")
436-
437-
/** A Scala 2.12 or higher trait */
438-
final val Scala_2_12_Trait: FlagSet = typeFlag(58, "<scala_2_12_trait>")
428+
/** A Scala 2.x trait that has been partially augmented.
429+
* This is set in `AugmentScala2Trait` and reset in `LinkScala2Impls`
430+
* when the trait is fully augmented.
431+
*/
432+
final val Scala2xPartiallyAugmented: FlagSet = typeFlag(57, "<scala-2.x-partially-augmented>")
439433

440434
/** A macro */
441435
final val Macro: FlagSet = commonFlag(59, "<macro>")
@@ -497,7 +491,7 @@ object Flags {
497491
* is completed)
498492
*/
499493
final val AfterLoadFlags: FlagSet =
500-
FromStartFlags | AccessFlags | Final | AccessorOrSealed | LazyOrTrait | SelfNameOrImplClass
494+
FromStartFlags | AccessFlags | Final | AccessorOrSealed | LazyOrTrait | SelfName.toCommonFlags
501495

502496
assert(FromStartFlags.isTermFlags && FromStartFlags.isTypeFlags)
503497
// TODO: Should check that FromStartFlags do not change in completion
@@ -549,7 +543,7 @@ object Flags {
549543

550544
/** Flags that can apply to a module class */
551545
final val RetainedModuleClassFlags: FlagSet = RetainedModuleValAndClassFlags |
552-
ImplClass | Enum | Opaque
546+
Enum | Opaque
553547

554548
/** Flags that are copied from a synthetic companion to a user-defined one
555549
* when the two are merged. See: Namer.mergeCompanionDefs

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ object Mode {
6969
/** We are currently unpickling Scala2 info */
7070
val Scala2Unpickling: Mode = newMode(13, "Scala2Unpickling")
7171

72-
/** We are currently unpickling from Java 8 or higher */
73-
val Java8Unpickling: Mode = newMode(14, "Java8Unpickling")
74-
7572
/** Use Scala2 scheme for overloading and implicit resolution */
7673
val OldOverloadingResolution: Mode = newMode(15, "OldOverloadingResolution")
7774

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,6 @@ object NameOps {
141141
name.replace { case VariantName(invariant, _) => invariant }
142142
}
143143

144-
def implClassName: N = likeSpacedN(name ++ tpnme.IMPL_CLASS_SUFFIX)
145-
146-
def traitOfImplClassName: N = {
147-
val suffix = tpnme.IMPL_CLASS_SUFFIX.toString
148-
assert(name.endsWith(suffix), name)
149-
likeSpacedN(name.mapLast(_.dropRight(suffix.length)))
150-
}
151-
152144
def errorName: N = likeSpacedN(name ++ nme.ERROR)
153145

154146
/** Map variance value -1, +1 to 0, 1 */

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ object StdNames {
128128
val EMPTY_PACKAGE: N = "<empty>"
129129
val EXCEPTION_RESULT_PREFIX: N = "exceptionResult"
130130
val EXPAND_SEPARATOR: N = str.EXPAND_SEPARATOR
131-
val IMPL_CLASS_SUFFIX: N = "$class"
132131
val IMPORT: N = "<import>"
133132
val MODULE_SUFFIX: N = str.MODULE_SUFFIX
134133
val OPS_PACKAGE: N = "<special-ops>"

0 commit comments

Comments
 (0)