Skip to content

Commit 717bce7

Browse files
committed
Convert Symbols to using clauses
1 parent d8cd2bb commit 717bce7

File tree

12 files changed

+84
-71
lines changed

12 files changed

+84
-71
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import scala.collection.mutable
88
import scala.collection.generic.Clearable
99

1010
import dotty.tools.dotc.core.Flags._
11+
import dotty.tools.dotc.core.Contexts.inContext
1112
import dotty.tools.dotc.core.Symbols._
1213
import dotty.tools.dotc.core.Phases.Phase
1314
import dotty.tools.dotc.transform.SymUtils._
@@ -228,8 +229,9 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
228229
// After lambdalift (which is where we are), the rawowoner field contains the enclosing class.
229230
val enclosingClassSym = {
230231
if (innerClassSym.isClass) {
231-
val ct = ctx.withPhase(ctx.flattenPhase.prev)
232-
toDenot(innerClassSym)(ct).owner.enclosingClass(ct)
232+
inContext(ctx.withPhase(ctx.flattenPhase.prev)) {
233+
toDenot(innerClassSym).owner.enclosingClass
234+
}
233235
}
234236
else innerClassSym.enclosingClass(ctx.withPhase(ctx.flattenPhase.prev))
235237
} //todo is handled specially for JavaDefined symbols in scalac
@@ -255,7 +257,7 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
255257
if (innerClassSym.isAnonymousClass || innerClassSym.isAnonymousFunction) None
256258
else {
257259
val original = innerClassSym.initial
258-
Some(innerClassSym.name(ctx.withPhase(original.validFor.phaseId)).mangledString) // moduleSuffix for module classes
260+
Some(innerClassSym.name(using ctx.withPhase(original.validFor.phaseId)).mangledString) // moduleSuffix for module classes
259261
}
260262
}
261263

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ object DottyBackendInterface {
137137
// for example by specialization
138138
val original = toDenot(sym).initial
139139
val validity = original.validFor
140-
val shiftedContext = ctx.withPhase(validity.phaseId)
141-
toDenot(sym)(shiftedContext).isStatic(shiftedContext)
140+
inContext(ctx.withPhase(validity.phaseId)) {
141+
toDenot(sym).isStatic
142+
}
142143
}
143144

144145

@@ -148,8 +149,9 @@ object DottyBackendInterface {
148149
// it is very tricky in presence of classes(and annonymous classes) defined inside supper calls.
149150
if (sym.exists) {
150151
val validity = toDenot(sym).initial.validFor
151-
val shiftedContext = ctx.withPhase(validity.phaseId)
152-
toDenot(sym)(shiftedContext).lexicallyEnclosingClass(shiftedContext)
152+
inContext(ctx.withPhase(validity.phaseId)) {
153+
toDenot(sym).lexicallyEnclosingClass
154+
}
153155
} else NoSymbol
154156

155157
/**

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
833833
def traverse(tree: Tree)(implicit ctx: Context) = tree match {
834834
case tree: DefTree =>
835835
val sym = tree.symbol
836-
val prevDenot = sym.denot(ctx.withPhase(trans))
836+
val prevDenot = sym.denot(using ctx.withPhase(trans))
837837
if (prevDenot.effectiveOwner == from.skipWeakOwner) {
838838
val d = sym.copySymDenotation(owner = to)
839839
d.installAfter(trans)

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

Lines changed: 56 additions & 54 deletions
Large diffs are not rendered by default.

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
147147

148148
import Scala2Unpickler._
149149

150-
val moduleRoot: SymDenotation = moduleClassRoot.sourceModule(ictx).denot(ictx)
150+
val moduleRoot: SymDenotation = inContext(ictx) { moduleClassRoot.sourceModule.denot }
151151
assert(moduleRoot.isTerm)
152152

153153
checkVersion(ictx)
154154

155-
private val loadingMirror = defn(ictx) // was: mirrorThatLoaded(classRoot)
155+
private val loadingMirror = defn(using ictx) // was: mirrorThatLoaded(classRoot)
156156

157157
/** A map from entry numbers to array offsets */
158158
private val index = createIndex

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
9393
override def prepareForValDef(vdef: ValDef)(implicit ctx: Context): Context = {
9494
val sym = vdef.symbol(ctx.withPhase(thisPhase))
9595
if (captured contains sym) {
96-
val newd = sym.denot(ctx.withPhase(thisPhase)).copySymDenotation(
96+
val newd = sym.denot(using ctx.withPhase(thisPhase)).copySymDenotation(
9797
info = refClass(sym.info.classSymbol, sym.hasAnnotation(defn.VolatileAnnot)).typeRef,
9898
initFlags = sym.flags &~ Mutable)
9999
newd.removeAnnotation(defn.VolatileAnnot)
@@ -117,7 +117,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
117117
override def transformIdent(id: Ident)(implicit ctx: Context): Tree = {
118118
val vble = id.symbol
119119
if (captured.contains(vble))
120-
id.select(nme.elem).ensureConforms(vble.denot(ctx.withPhase(thisPhase)).info)
120+
id.select(nme.elem).ensureConforms(vble.denot(using ctx.withPhase(thisPhase)).info)
121121
else id
122122
}
123123

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete
117117
case ClassInfo(pre, cls, _, _, _) if cls is ModuleClass =>
118118
cls.linkedClass match {
119119
case valueClass: ClassSymbol if isDerivedValueClass(valueClass) =>
120-
val info1 = cls.denot(ctx.withPhase(ctx.phase.next)).asClass.classInfo.derivedClassInfo(prefix = pre)
120+
val info1 = cls.denot(using ctx.withPhase(ctx.phase.next)).asClass.classInfo.derivedClassInfo(prefix = pre)
121121
ref.derivedSingleDenotation(ref.symbol, info1)
122122
case _ => ref
123123
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class TransformByNameApply extends MiniPhase { thisPhase: DenotTransfor
2323

2424
/** The info of the tree's symbol before it is potentially transformed in this phase */
2525
private def originalDenotation(tree: Tree)(implicit ctx: Context) =
26-
tree.symbol.denot(ctx.withPhase(thisPhase))
26+
tree.symbol.denot(using ctx.withPhase(thisPhase))
2727

2828
/** If denotation had an ExprType before, it now gets a function type */
2929
protected def exprBecomesFunction(symd: SymDenotation)(implicit ctx: Context): Boolean =

compiler/src/dotty/tools/dotc/transform/init/Summarization.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ object Summarization {
327327
cls.info match {
328328
case cinfo: ClassInfo =>
329329
val source = {
330-
implicit val ctx2: Context = theCtx.withSource(cls.source(theCtx))
330+
implicit val ctx2: Context = theCtx.withSource(cls.source(using theCtx))
331331
TypeTree(cls.typeRef).withSpan(cls.span)
332332
}
333333

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ object RefChecks {
534534
// Give a specific error message for abstract vars based on why it fails:
535535
// It could be unimplemented, have only one accessor, or be uninitialized.
536536
if (underlying.is(Mutable)) {
537-
val isMultiple = grouped.getOrElse(underlying.name(ctx), Nil).size > 1
537+
val isMultiple = grouped.getOrElse(underlying.name, Nil).size > 1
538538

539539
// If both getter and setter are missing, squelch the setter error.
540540
if (member.isSetter && isMultiple) ()

tests/pos-with-compiler/i143.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ import dotty.tools.dotc.core.Contexts._
77

88
class TC5(val ctx: Context) extends AnyVal {
99
def candidates(mbr: SingleDenotation): Boolean = {
10-
mbr.symbol.denot(ctx).exists
10+
mbr.symbol.denot(using ctx).exists
1111
}
1212
}

tests/pos/inlinetuple.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test:
2+
3+
def g(x: Int, y: Int) = x + y
4+
inline def f(inline x: (Int, Int)) = g(x._1, x._2)
5+
6+
val x = f((1, 2))
7+

0 commit comments

Comments
 (0)