Skip to content

Commit 44bdec1

Browse files
committed
Rename OuterAccessors to ExplicitOuter
Better to keep the old name for easy cross-referencing with Scala 2.
1 parent a661bed commit 44bdec1

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Compiler {
5454
new ElimRepeated,
5555
new ElimLocals),
5656
List(new ExtensionMethods),
57-
List(new TailRec, new OuterAccessors),
57+
List(new TailRec, new ExplicitOuter),
5858
List(new PatternMatcher,
5959
// new LazyValTranformContext().transformer, // disabled, awaiting fixes
6060
new Splitter),

src/dotty/tools/dotc/TypeErasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotc
33
package core
44

55
import Symbols._, Types._, Contexts._, Flags._, Names._, StdNames._, Decorators._, Flags.JavaDefined
6-
import dotc.transform.OuterAccessors._
6+
import dotc.transform.ExplicitOuter._
77
import util.DotClass
88

99
/** Erased types are:

src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import scala.collection.mutable.ListBuffer
2424
import dotty.tools.dotc.core.Flags
2525
import ValueClasses._
2626
import TypeUtils._
27-
import OuterAccessors._
27+
import ExplicitOuter._
2828
import typer.Mode
2929

3030
class Erasure extends Phase with DenotTransformer { thisTransformer =>

src/dotty/tools/dotc/transform/OuterAccessors.scala renamed to src/dotty/tools/dotc/transform/ExplicitOuter.scala

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,34 @@ import SymUtils._
1616
import util.Attachment
1717
import collection.mutable
1818

19-
/** This phase decorates News and parent constructors of non-static inner classes
20-
* with an attachment indicating the outer reference as a tree. This is necessary because
21-
* outer prefixes are erased, and explicit outer runs only after erasure.
19+
/** This phase adds outer accessors to classes and traits that need them.
20+
* Compared to Scala 2.x, it tries to minimize the set of classes
21+
* that take outer accessors and also tries to minimize the number
22+
* of objects referred to by outer accessors. This helps prevent space
23+
* leaks.
24+
*
25+
* The following things are delayed until erasure and are performed
26+
* by class OuterOps:
27+
*
28+
* - add outer parameters to constructors
29+
* - pass outer arguments in constructor calls
30+
* - replace outer this by outer paths.
2231
*/
23-
class OuterAccessors extends MiniPhaseTransform with InfoTransformer { thisTransformer =>
24-
import OuterAccessors._
32+
class ExplicitOuter extends MiniPhaseTransform with InfoTransformer { thisTransformer =>
33+
import ExplicitOuter._
2534
import ast.tpd._
2635

2736
val Outer = new Attachment.Key[Tree]
2837

29-
override def phaseName: String = "outerAccessors"
38+
override def phaseName: String = "ExplicitOuter"
3039

3140
override def treeTransformPhase = thisTransformer.next
3241

3342
/** Add outer accessors if a class always needs an outer pointer */
3443
override def transformInfo(tp: Type, sym: Symbol)(implicit ctx: Context) = tp match {
3544
case tp @ ClassInfo(_, cls, _, decls, _) if needsOuterAlways(cls) =>
3645
val newDecls = decls.cloneScope
37-
newOuterAccessors(cls).foreach(newDecls.enter)
46+
newExplicitOuter(cls).foreach(newDecls.enter)
3847
tp.derivedClassInfo(decls = newDecls)
3948
case _ =>
4049
tp
@@ -58,7 +67,7 @@ class OuterAccessors extends MiniPhaseTransform with InfoTransformer { thisTrans
5867
newOuterSym(cls, cls, nme.OUTER, Private | ParamAccessor)
5968

6069
/** The outer accessor and potentially outer param accessor needed for class `cls` */
61-
private def newOuterAccessors(cls: ClassSymbol)(implicit ctx: Context) =
70+
private def newExplicitOuter(cls: ClassSymbol)(implicit ctx: Context) =
6271
newOuterAccessor(cls, cls) :: (if (cls is Trait) Nil else newOuterParamAccessor(cls) :: Nil)
6372

6473
/** First, add outer accessors if a class does not have them yet and it references an outer this.
@@ -76,7 +85,7 @@ class OuterAccessors extends MiniPhaseTransform with InfoTransformer { thisTrans
7685
val cls = ctx.owner.asClass
7786
val isTrait = cls.is(Trait)
7887
if (needsOuterIfReferenced(cls) && !needsOuterAlways(cls) && referencesOuter(cls, impl))
79-
newOuterAccessors(cls).foreach(_.enteredAfter(thisTransformer))
88+
newExplicitOuter(cls).foreach(_.enteredAfter(thisTransformer))
8089
if (hasOuter(cls)) {
8190
val newDefs = new mutable.ListBuffer[Tree]
8291
if (isTrait)
@@ -107,7 +116,7 @@ class OuterAccessors extends MiniPhaseTransform with InfoTransformer { thisTrans
107116
}
108117
}
109118

110-
object OuterAccessors {
119+
object ExplicitOuter {
111120
import ast.tpd._
112121

113122
private val LocalInstantiationSite = Module | Private
@@ -146,7 +155,7 @@ object OuterAccessors {
146155
cls.info.member(outerAccName(cls)).suchThat(_ is OuterAccessor).symbol orElse
147156
cls.info.decls.find(_ is OuterAccessor).getOrElse(NoSymbol)
148157

149-
/** Class has an outer accessor. Can be called only after phase OuterAccessors. */
158+
/** Class has an outer accessor. Can be called only after phase ExplicitOuter. */
150159
private def hasOuter(cls: ClassSymbol)(implicit ctx: Context): Boolean =
151160
needsOuterIfReferenced(cls) && outerAccessor(cls).exists
152161

0 commit comments

Comments
 (0)