Skip to content

Commit 8ee7aca

Browse files
committed
WIP simplify symbol AddInterfaces / Mixin
1 parent 812c409 commit 8ee7aca

File tree

3 files changed

+13
-56
lines changed

3 files changed

+13
-56
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,12 @@ abstract class BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
145145
assert(classSym.isClass, classSym)
146146

147147
def doesNotExist(method: Symbol) = {
148-
// (1) SI-9124, some trait methods don't exist in the generated interface. see comment in BTypes.
149-
// (2) Value classes. Member methods of value classes exist in the generated box class. However,
148+
// Value classes. Member methods of value classes exist in the generated box class. However,
150149
// nested methods lifted into a value class are moved to the companion object and don't exist
151150
// in the value class itself. We can identify such nested methods: the initial enclosing class
152151
// is a value class, but the current owner is some other class (the module class).
153-
method.owner.isTrait && method.isImplOnly || { // (1)
154-
val enclCls = nextEnclosingClass(method)
155-
exitingPickler(enclCls.isDerivedValueClass) && method.owner != enclCls // (2)
156-
}
152+
val enclCls = nextEnclosingClass(method)
153+
exitingPickler(enclCls.isDerivedValueClass) && method.owner != enclCls
157154
}
158155

159156
def enclosingMethod(sym: Symbol): Option[Symbol] = {

src/compiler/scala/tools/nsc/transform/AddInterfaces.scala

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,6 @@ abstract class AddInterfaces extends InfoTransform { self: Erasure =>
1818
*/
1919
override def phaseNewFlags: Long = lateDEFERRED
2020

21-
/** Is given trait member symbol a member of the trait's interface
22-
* after this transform is performed?
23-
*/
24-
def isInterfaceMember(sym: Symbol) = (
25-
sym.isType || {
26-
sym.info // initialize to set lateMETHOD flag if necessary
27-
28-
( sym.isMethod
29-
&& !sym.isLabel
30-
)
31-
}
32-
)
33-
34-
/** Does symbol need an implementation method? */
35-
def needsImplMethod(sym: Symbol) = (
36-
sym.isMethod
37-
&& isInterfaceMember(sym)
38-
&& (!sym.hasFlag(DEFERRED | SUPERACCESSOR) || (sym hasFlag lateDEFERRED))
39-
)
40-
4121
def transformMixinInfo(tp: Type): Type = tp match {
4222
case ClassInfoType(parents, decls, clazz) if clazz.isPackageClass || !clazz.isJavaDefined =>
4323

@@ -48,17 +28,7 @@ abstract class AddInterfaces extends InfoTransform { self: Erasure =>
4828
if (clazz.isTrait) ObjectTpe :: tl
4929
else parents
5030
}
51-
val decls1 = scopeTransform(clazz) {
52-
decls filter { sym =>
53-
if (clazz.isTrait) {
54-
isInterfaceMember(sym) || (sym.isTerm)
55-
} else sym.isClass || sym.isTerm
56-
}
57-
}
58-
// if (clazz.isTrait) {
59-
// decls1.enter(clazz.newMethod(nme.MIXIN_CONSTRUCTOR, clazz.pos, Flags.PROTECTED | Flags.ARTIFACT) setInfo MethodType(Nil, UnitTpe))
60-
// }
61-
ClassInfoType(parents1, decls1, clazz)
31+
ClassInfoType(parents1, decls, clazz)
6232
case _ =>
6333
tp
6434
}

src/compiler/scala/tools/nsc/transform/Mixin.scala

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,18 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
4343
* methods in the impl class (because they can have arbitrary initializers)
4444
*/
4545
private def isImplementedStatically(sym: Symbol) = (
46-
erasure.isInterfaceMember(sym)
47-
&& erasure.needsImplMethod(sym)
46+
sym.isMethod
47+
&& (!sym.hasFlag(DEFERRED | SUPERACCESSOR) || (sym hasFlag lateDEFERRED))
4848
&& sym.owner.isTrait
4949
&& sym.isMethod
5050
&& (!sym.isModule || sym.hasFlag(PRIVATE | LIFTED))
5151
&& (!(sym hasFlag (ACCESSOR | SUPERACCESSOR)) || sym.isLazy)
52+
&& !sym.isPrivate
53+
&& !sym.hasAllFlags(LIFTED | MODULE | METHOD)
54+
&& !sym.isConstructor
55+
&& (!sym.hasFlag(notPRIVATE | LIFTED) || sym.hasFlag(ACCESSOR | SUPERACCESSOR | MODULE))
5256
)
5357

54-
/** A member of a trait is static only if it belongs only to the
55-
* implementation class, not the interface, and it is implemented
56-
* statically.
57-
*/
58-
private def isStaticOnly(sym: Symbol) =
59-
isImplementedStatically(sym) && sym.isImplOnly
60-
61-
/** A member of a trait is forwarded if it is implemented statically and it
62-
* is also visible in the trait's interface. In that case, a forwarder to
63-
* the member's static implementation will be added to the class that
64-
* inherits the trait.
65-
*/
66-
private def isForwarded(sym: Symbol) =
67-
isImplementedStatically(sym) && !sym.isImplOnly
68-
6958
private def isFieldWithBitmap(field: Symbol) = {
7059
field.info // ensure that nested objects are transformed
7160
// For checkinit consider normal value getters
@@ -247,7 +236,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
247236

248237
/* Mix in members of implementation class mixinClass into class clazz */
249238
def mixinTraitForwarders(mixinClass: Symbol) {
250-
for (member <- mixinClass.info.decls ; if isForwarded(member)) {
239+
for (member <- mixinClass.info.decls ; if isImplementedStatically(member)) {
251240
member overridingSymbol clazz match {
252241
case NoSymbol =>
253242
if (clazz.info.findMember(member.name, 0, 0L, stableOnly = false).alternatives contains member)
@@ -484,7 +473,8 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
484473
* - A super accessor for every super accessor in a mixin class
485474
* - Forwarders for all methods that are implemented statically
486475
* All superaccessors are completed with right-hand sides (@see completeSuperAccessor)
487-
* @param clazz The class to which definitions are added
476+
*
477+
* @param clazz The class to which definitions are added
488478
*/
489479
private def addNewDefs(clazz: Symbol, stats: List[Tree]): List[Tree] = {
490480
val newDefs = mutable.ListBuffer[Tree]()

0 commit comments

Comments
 (0)