Skip to content

Commit 9cd486c

Browse files
committed
Make outer select names semantic
1 parent fcbe1fd commit 9cd486c

File tree

9 files changed

+27
-24
lines changed

9 files changed

+27
-24
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ object NameKinds {
242242
}
243243
}
244244

245+
/** Names of the form N_<outer>. Emitted by inliner, replaced by outer path
246+
* in ExplicitOuter.
247+
*/
248+
object OuterSelectName extends NumberedNameKind(OUTERSELECT, "OuterSelect") {
249+
def mkString(underlying: TermName, info: ThisInfo) = {
250+
assert(underlying.isEmpty)
251+
info.num + "_<outer>"
252+
}
253+
}
254+
245255
val SuperAccessorName = new PrefixNameKind(SUPERACCESSOR, "super$")
246256
val InitializerName = new PrefixNameKind(INITIALIZER, "initial$")
247257
val ShadowedName = new PrefixNameKind(SHADOWED, "(shadowed)")

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,9 @@ object NameOps {
6060
def isLocalDummyName = name startsWith LOCALDUMMY_PREFIX
6161
def isReplWrapperName = name.toSimpleName containsSlice INTERPRETER_IMPORT_WRAPPER
6262
def isSetterName = name endsWith SETTER_SUFFIX
63-
def isImportName = name startsWith IMPORT
6463
def isScala2LocalSuffix = name.endsWith(" ")
6564
def isModuleVarName(name: Name): Boolean = name.exclude(UniqueName).is(ModuleVarName)
6665
def isSelectorName = name.startsWith("_") && name.tail.forall(_.isDigit)
67-
def isOuterSelect = name.endsWith(nme.OUTER_SELECT)
6866

6967
/** Is name a variable name? */
7068
def isVariableName: Boolean = name.length > 0 && {
@@ -214,12 +212,6 @@ object NameOps {
214212
else -1
215213
}
216214

217-
/** The number of hops specified in an outer-select name */
218-
def outerSelectHops: Int = {
219-
require(isOuterSelect)
220-
name.dropRight(nme.OUTER_SELECT.length).toString.toInt
221-
}
222-
223215
/** The name of the generic runtime operation corresponding to an array operation */
224216
def genericArrayOp: TermName = name match {
225217
case nme.apply => nme.array_apply

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ object StdNames {
253253
val MODULE_INSTANCE_FIELD: N = NameTransformer.MODULE_INSTANCE_NAME // "MODULE$"
254254
val OUTER: N = "$outer"
255255
val OUTER_LOCAL: N = "$outer "
256-
val OUTER_SELECT: N = "_<outer>" // emitted by inliner, replaced by outer path in explicitouter
257256
val REFINE_CLASS: N = "<refinement>"
258257
val ROOTPKG: N = "_root_"
259258
val SELECTOR_DUMMY: N = "<unapply-selector>"

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ object TastyFormat {
228228
final val UNIQUE = 10
229229
final val DEFAULTGETTER = 11
230230
final val VARIANT = 12
231+
final val OUTERSELECT = 13
232+
231233
final val SUPERACCESSOR = 20
232234
final val PROTECTEDACCESSOR = 21
233235
final val PROTECTEDSETTER = 22

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import core.Decorators._
1111
import core.StdNames.nme
1212
import core.Names._
1313
import core.NameOps._
14+
import core.NameKinds.OuterSelectName
1415
import ast.Trees._
1516
import SymUtils._
1617
import dotty.tools.dotc.ast.tpd
@@ -61,10 +62,11 @@ class ExplicitOuter extends MiniPhaseTransform with InfoTransformer { thisTransf
6162

6263
/** Convert a selection of the form `qual.C_<OUTER>` to an outer path from `qual` to `C` */
6364
override def transformSelect(tree: Select)(implicit ctx: Context, info: TransformerInfo) =
64-
if (tree.name.isOuterSelect)
65-
outer.path(start = tree.qualifier, count = tree.name.outerSelectHops)
66-
.ensureConforms(tree.tpe)
67-
else tree
65+
tree.name match {
66+
case OuterSelectName(_, nhops) =>
67+
outer.path(start = tree.qualifier, count = nhops).ensureConforms(tree.tpe)
68+
case _ => tree
69+
}
6870

6971
/** First, add outer accessors if a class does not have them yet and it references an outer this.
7072
* If the class has outer accessors, implement them.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import scala.collection.mutable
2020
import DenotTransformers._
2121
import typer.Checking
2222
import NameOps._
23-
import NameKinds.AvoidClashName
23+
import NameKinds.{AvoidClashName, OuterSelectName}
2424
import StdNames._
2525

2626

@@ -77,7 +77,7 @@ class FirstTransform extends MiniPhaseTransform with InfoTransformer with Annota
7777

7878
override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = {
7979
tree match {
80-
case Select(qual, name) if !name.isOuterSelect && tree.symbol.exists =>
80+
case Select(qual, name) if !name.is(OuterSelectName) && tree.symbol.exists =>
8181
assert(qual.tpe derivesFrom tree.symbol.owner, i"non member selection of ${tree.symbol.showLocated} from ${qual.tpe} in $tree")
8282
case _: TypeTree =>
8383
case _: Import | _: NamedArg | _: TypTree =>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Types._, Contexts._, Constants._, Names._, NameOps._, Flags._, DenotTrans
1111
import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, Scopes._, Denotations._
1212
import util.Positions._
1313
import Decorators._
14-
import NameKinds.{ProtectedAccessorName, ProtectedSetterName}
14+
import NameKinds.{ProtectedAccessorName, ProtectedSetterName, OuterSelectName}
1515
import Symbols._, TypeUtils._
1616

1717
/** This class performs the following functions:
@@ -152,7 +152,7 @@ class SuperAccessors(thisTransformer: DenotTransformer) {
152152
*/
153153
private def ensureProtectedAccessOK(sel: Select, targs: List[Tree])(implicit ctx: Context) = {
154154
val sym = sel.symbol
155-
if (sym.isTerm && !sel.name.isOuterSelect && needsProtectedAccessor(sym, sel.pos)) {
155+
if (sym.isTerm && !sel.name.is(OuterSelectName) && needsProtectedAccessor(sym, sel.pos)) {
156156
ctx.debuglog("Adding protected accessor for " + sel)
157157
protectedAccessorCall(sel, targs)
158158
} else sel

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import core.Flags._
1313
import core.Constants._
1414
import core.StdNames._
1515
import core.NameOps._
16+
import core.NameKinds.OuterSelectName
1617
import core.Decorators._
1718
import core.TypeErasure.isErasedType
1819
import core.Phases.Phase
@@ -339,7 +340,7 @@ class TreeChecker extends Phase with SymTransformer {
339340
val sym = tree.symbol
340341
if (!tpe.isInstanceOf[WithFixedSym] &&
341342
sym.exists && !sym.is(Private) &&
342-
!tree.name.isOuterSelect // outer selects have effectively fixed symbols
343+
!tree.name.is(OuterSelectName) // outer selects have effectively fixed symbols
343344
) {
344345
val qualTpe = tree.qualifier.typeOpt
345346
val member =

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import Decorators._
1313
import Constants._
1414
import StdNames.nme
1515
import Contexts.Context
16-
import Names.{Name, TermName}
16+
import Names.{Name, TermName, EmptyTermName}
1717
import NameOps._
18-
import NameKinds.InlineAccessorName
18+
import NameKinds.{InlineAccessorName, OuterSelectName}
1919
import SymDenotations.SymDenotation
2020
import Annotations._
2121
import transform.ExplicitOuter
@@ -398,9 +398,6 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
398398
// The class that the this-proxy `selfSym` represents
399399
def classOf(selfSym: Symbol) = selfSym.info.widen.classSymbol
400400

401-
// The name of the outer selector that computes the rhs of `selfSym`
402-
def outerSelector(n: Int): TermName = n.toString.toTermName ++ nme.OUTER_SELECT
403-
404401
// The total nesting depth of the class represented by `selfSym`.
405402
def outerLevel(selfSym: Symbol): Int = classOf(selfSym).ownersIterator.length
406403

@@ -418,7 +415,7 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
418415
if (!lastSelf.exists)
419416
prefix
420417
else
421-
untpd.Select(ref(lastSelf), outerSelector(lastLevel - level)).withType(selfSym.info)
418+
untpd.Select(ref(lastSelf), OuterSelectName(EmptyTermName, lastLevel - level)).withType(selfSym.info)
422419
bindingsBuf += ValDef(selfSym.asTerm, rhs)
423420
lastSelf = selfSym
424421
lastLevel = level

0 commit comments

Comments
 (0)