Skip to content

Commit a7db8c2

Browse files
committed
Drop DenotationsBase mixin of ContextBase
1 parent 973712b commit a7db8c2

File tree

10 files changed

+76
-77
lines changed

10 files changed

+76
-77
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,6 @@ object Contexts {
656656
* compiler run.
657657
*/
658658
class ContextBase extends ContextState
659-
with Denotations.DenotationsBase
660659
with Phases.PhasesBase
661660
with Plugins {
662661

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

Lines changed: 56 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,72 +1189,67 @@ object Denotations {
11891189
s"multi-denotation with alternatives $alternatives does not implement operation $op")
11901190
}
11911191

1192-
// --------------- Context Base Trait -------------------------------
1193-
1194-
trait DenotationsBase { this: ContextBase =>
1195-
1196-
/** The current denotation of the static reference given by path,
1197-
* or a MissingRef or NoQualifyingRef instance, if it does not exist.
1198-
* if generateStubs is set, generates stubs for missing top-level symbols
1199-
*/
1200-
def staticRef(path: Name, generateStubs: Boolean = true, isPackage: Boolean = false)(using Context): Denotation = {
1201-
def select(prefix: Denotation, selector: Name): Denotation = {
1202-
val owner = prefix.disambiguate(_.info.isParameterless)
1203-
def isPackageFromCoreLibMissing: Boolean =
1204-
owner.symbol == defn.RootClass &&
1205-
(
1206-
selector == nme.scala || // if the scala package is missing, the stdlib must be missing
1207-
selector == nme.scalaShadowing // if the scalaShadowing package is missing, the dotty library must be missing
1208-
)
1209-
if (owner.exists) {
1210-
val result = if (isPackage) owner.info.decl(selector) else owner.info.member(selector)
1211-
if (result.exists) result
1212-
else if (isPackageFromCoreLibMissing) throw new MissingCoreLibraryException(selector.toString)
1213-
else {
1214-
val alt =
1215-
if (generateStubs) missingHook(owner.symbol.moduleClass, selector)
1216-
else NoSymbol
1217-
if (alt.exists) alt.denot
1218-
else MissingRef(owner, selector)
1219-
}
1192+
/** The current denotation of the static reference given by path,
1193+
* or a MissingRef or NoQualifyingRef instance, if it does not exist.
1194+
* if generateStubs is set, generates stubs for missing top-level symbols
1195+
*/
1196+
def staticRef(path: Name, generateStubs: Boolean = true, isPackage: Boolean = false)(using Context): Denotation = {
1197+
def select(prefix: Denotation, selector: Name): Denotation = {
1198+
val owner = prefix.disambiguate(_.info.isParameterless)
1199+
def isPackageFromCoreLibMissing: Boolean =
1200+
owner.symbol == defn.RootClass &&
1201+
(
1202+
selector == nme.scala || // if the scala package is missing, the stdlib must be missing
1203+
selector == nme.scalaShadowing // if the scalaShadowing package is missing, the dotty library must be missing
1204+
)
1205+
if (owner.exists) {
1206+
val result = if (isPackage) owner.info.decl(selector) else owner.info.member(selector)
1207+
if (result.exists) result
1208+
else if (isPackageFromCoreLibMissing) throw new MissingCoreLibraryException(selector.toString)
1209+
else {
1210+
val alt =
1211+
if (generateStubs) missingHook(owner.symbol.moduleClass, selector)
1212+
else NoSymbol
1213+
if (alt.exists) alt.denot
1214+
else MissingRef(owner, selector)
12201215
}
1221-
else owner
12221216
}
1223-
def recur(path: Name, wrap: TermName => Name = identity): Denotation = path match {
1224-
case path: TypeName =>
1225-
recur(path.toTermName, n => n.toTypeName)
1226-
case ModuleClassName(underlying) =>
1227-
recur(underlying, n => wrap(ModuleClassName(n)))
1228-
case QualifiedName(prefix, selector) =>
1229-
select(recur(prefix), wrap(selector))
1230-
case qn @ AnyQualifiedName(prefix, _) =>
1231-
recur(prefix, n => wrap(qn.info.mkString(n).toTermName))
1232-
case path: SimpleName =>
1233-
def recurSimple(len: Int, wrap: TermName => Name): Denotation = {
1234-
val point = path.lastIndexOf('.', len - 1)
1235-
val selector = wrap(path.slice(point + 1, len).asTermName)
1236-
val prefix =
1237-
if (point > 0) recurSimple(point, identity)
1238-
else if (selector.isTermName) defn.RootClass.denot
1239-
else defn.EmptyPackageClass.denot
1240-
select(prefix, selector)
1241-
}
1242-
recurSimple(path.length, wrap)
1243-
}
1244-
recur(path)
1217+
else owner
12451218
}
1246-
1247-
/** If we are looking for a non-existing term name in a package,
1248-
* assume it is a package for which we do not have a directory and
1249-
* enter it.
1250-
*/
1251-
def missingHook(owner: Symbol, name: Name)(using Context): Symbol =
1252-
if (owner.is(Package) && name.isTermName)
1253-
newCompletePackageSymbol(owner, name.asTermName).entered
1254-
else
1255-
NoSymbol
1219+
def recur(path: Name, wrap: TermName => Name = identity): Denotation = path match {
1220+
case path: TypeName =>
1221+
recur(path.toTermName, n => n.toTypeName)
1222+
case ModuleClassName(underlying) =>
1223+
recur(underlying, n => wrap(ModuleClassName(n)))
1224+
case QualifiedName(prefix, selector) =>
1225+
select(recur(prefix), wrap(selector))
1226+
case qn @ AnyQualifiedName(prefix, _) =>
1227+
recur(prefix, n => wrap(qn.info.mkString(n).toTermName))
1228+
case path: SimpleName =>
1229+
def recurSimple(len: Int, wrap: TermName => Name): Denotation = {
1230+
val point = path.lastIndexOf('.', len - 1)
1231+
val selector = wrap(path.slice(point + 1, len).asTermName)
1232+
val prefix =
1233+
if (point > 0) recurSimple(point, identity)
1234+
else if (selector.isTermName) defn.RootClass.denot
1235+
else defn.EmptyPackageClass.denot
1236+
select(prefix, selector)
1237+
}
1238+
recurSimple(path.length, wrap)
1239+
}
1240+
recur(path)
12561241
}
12571242

1243+
/** If we are looking for a non-existing term name in a package,
1244+
* assume it is a package for which we do not have a directory and
1245+
* enter it.
1246+
*/
1247+
def missingHook(owner: Symbol, name: Name)(using Context): Symbol =
1248+
if (owner.is(Package) && name.isTermName)
1249+
newCompletePackageSymbol(owner, name.asTermName).entered
1250+
else
1251+
NoSymbol
1252+
12581253
/** An exception for accessing symbols that are no longer valid in current run */
12591254
class StaleSymbol(msg: => String) extends Exception {
12601255
util.Stats.record("stale symbol")

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Symbols._
1111
import Contexts._
1212
import Phases._
1313
import SymDenotations._
14+
import Denotations._
1415
import printing.Texts._
1516
import printing.Printer
1617
import Types._
@@ -882,14 +883,14 @@ object Symbols {
882883

883884
def requiredPackage(path: PreName)(using Context): TermSymbol = {
884885
val name = path.toTermName
885-
ctx.base.staticRef(name, isPackage = true).requiredSymbol("package", name)(_.is(Package)).asTerm
886+
staticRef(name, isPackage = true).requiredSymbol("package", name)(_.is(Package)).asTerm
886887
}
887888

888889
def requiredPackageRef(path: PreName)(using Context): TermRef = requiredPackage(path).termRef
889890

890891
def requiredClass(path: PreName)(using Context): ClassSymbol = {
891892
val name = path.toTypeName
892-
ctx.base.staticRef(name).requiredSymbol("class", name)(_.isClass) match {
893+
staticRef(name).requiredSymbol("class", name)(_.isClass) match {
893894
case cls: ClassSymbol => cls
894895
case sym => defn.AnyClass
895896
}
@@ -902,7 +903,7 @@ object Symbols {
902903
* Returns NoSymbol otherwise. */
903904
def getClassIfDefined(path: PreName)(using Context): Symbol = {
904905
val name = path.toTypeName
905-
ctx.base.staticRef(name, generateStubs = false)
906+
staticRef(name, generateStubs = false)
906907
.requiredSymbol("class", name, generateStubs = false)(_.isClass)
907908
}
908909

@@ -917,20 +918,20 @@ object Symbols {
917918
* Returns NoSymbol otherwise. */
918919
def getPackageClassIfDefined(path: PreName)(using Context): Symbol = {
919920
val name = path.toTypeName
920-
ctx.base.staticRef(name, isPackage = true, generateStubs = false)
921+
staticRef(name, isPackage = true, generateStubs = false)
921922
.requiredSymbol("package", name, generateStubs = false)(_ is PackageClass)
922923
}
923924

924925
def requiredModule(path: PreName)(using Context): TermSymbol = {
925926
val name = path.toTermName
926-
ctx.base.staticRef(name).requiredSymbol("object", name)(_.is(Module)).asTerm
927+
staticRef(name).requiredSymbol("object", name)(_.is(Module)).asTerm
927928
}
928929

929930
def requiredModuleRef(path: PreName)(using Context): TermRef = requiredModule(path).termRef
930931

931932
def requiredMethod(path: PreName)(using Context): TermSymbol = {
932933
val name = path.toTermName
933-
ctx.base.staticRef(name).requiredSymbol("method", name)(_.is(Method)).asTerm
934+
staticRef(name).requiredSymbol("method", name)(_.is(Method)).asTerm
934935
}
935936

936937
def requiredMethodRef(path: PreName)(using Context): TermRef = requiredMethod(path).termRef

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
411411
// (3) Try as a nested object symbol.
412412
nestedObjectSymbol orElse {
413413
// (4) Call the mirror's "missing" hook.
414-
adjust(ctx.base.missingHook(owner, name)) orElse {
414+
adjust(missingHook(owner, name)) orElse {
415415
// println(owner.info.decls.toList.map(_.debugString).mkString("\n ")) // !!! DEBUG
416416
// }
417417
// (5) Create a stub symbol to defer hard failure a little longer.

compiler/src/dotty/tools/dotc/fromtasty/ReadTasty.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Decorators._
77
import Contexts.{Context, ctx}
88
import Symbols.{Symbol, ClassSymbol}
99
import SymDenotations.ClassDenotation
10+
import Denotations.staticRef
1011
import NameOps._
1112
import ast.Trees.Tree
1213
import Phases.Phase
@@ -59,7 +60,7 @@ class ReadTasty extends Phase {
5960
// Note that if both the class and the object are present, then loading the class will also load
6061
// the object, this is why we use orElse here, otherwise we could load the object twice and
6162
// create ambiguities!
62-
ctx.base.staticRef(className) match {
63+
staticRef(className) match {
6364
case clsd: ClassDenotation =>
6465
clsd.infoOrCompleter match {
6566
case info: ClassfileLoader =>

compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import dotty.tools.io.{ AbstractFile, ClassPath, ClassRepresentation, PlainFile,
1616
import ast.{Trees, tpd}
1717
import core._, core.Decorators._
1818
import Contexts._, Names._, NameOps._, Symbols._, SymDenotations._, Trees._, Types._
19+
import Denotations.staticRef
1920
import classpath._
2021
import reporting._
2122
import util._
@@ -184,7 +185,7 @@ class InteractiveDriver(val settings: List[String]) extends Driver {
184185
*/
185186
private def treesFromClassName(className: TypeName, id: String)(using Context): List[SourceTree] = {
186187
def trees(className: TypeName, id: String): List[SourceTree] = {
187-
val clsd = ctx.base.staticRef(className)
188+
val clsd = staticRef(className)
188189
clsd match {
189190
case clsd: ClassDenotation =>
190191
clsd.ensureCompleted()

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import dotty.tools.dotc.core.StdNames._
1515
import dotty.tools.dotc.core.quoted._
1616
import dotty.tools.dotc.core.Types._
1717
import dotty.tools.dotc.core.Symbols._
18+
import dotty.tools.dotc.core.Denotations.staticRef
1819
import dotty.tools.dotc.core.{NameKinds, TypeErasure}
1920
import dotty.tools.dotc.core.Constants.Constant
2021
import dotty.tools.dotc.tastyreflect.ReflectionImpl
@@ -418,7 +419,7 @@ object Splicer {
418419
val className = targetException.getMessage
419420
if (className eq null) None
420421
else {
421-
val sym = ctx.base.staticRef(className.toTypeName).symbol
422+
val sym = staticRef(className.toTypeName).symbol
422423
if (sym.isDefinedInCurrentRun) Some(sym) else None
423424
}
424425
}

compiler/test/dotty/tools/AnnotationsTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import dotc.core.Decorators._
99
import dotc.core.Contexts._
1010
import dotc.core.Phases._
1111
import dotc.core.Types._
12+
import dotc.core.Symbols._
1213

1314
import java.io.File
1415
import java.nio.file._
1516

16-
class AnnotationsTest:
1717
@Test def annotTreeNotErased: Unit =
1818
withJavaCompiled(
1919
VirtualJavaSource("Annot.java",

compiler/test/dotty/tools/SignatureTest.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import dotc.core.Decorators._
99
import dotc.core.Contexts._
1010
import dotc.core.Phases._
1111
import dotc.core.Types._
12+
import dotc.core.Symbols._
1213

1314
import java.io.File
1415
import java.nio.file._

staging/src/scala/quoted/staging/QuoteCompiler.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import dotty.tools.dotc.core.Names.TypeName
1212
import dotty.tools.dotc.core.Phases.Phase
1313
import dotty.tools.dotc.core.Scopes.{EmptyScope, newScope}
1414
import dotty.tools.dotc.core.StdNames.nme
15-
import dotty.tools.dotc.core.Symbols.defn
15+
import dotty.tools.dotc.core.Symbols._
1616
import dotty.tools.dotc.core.Types.ExprType
1717
import dotty.tools.dotc.core.quoted.PickledQuotes
1818
import dotty.tools.dotc.tastyreflect.ReflectionImpl
@@ -62,10 +62,10 @@ private class QuoteCompiler extends Compiler:
6262

6363
// Places the contents of expr in a compilable tree for a class with the following format.
6464
// `package __root__ { class ' { def apply: Any = <expr> } }`
65-
val cls = unitCtx.newCompleteClassSymbol(defn.RootClass, outputClassName, EmptyFlags,
65+
val cls = newCompleteClassSymbol(defn.RootClass, outputClassName, EmptyFlags,
6666
defn.ObjectType :: Nil, newScope, coord = pos, assocFile = assocFile).entered.asClass
67-
cls.enter(unitCtx.newDefaultConstructor(cls), EmptyScope)
68-
val meth = unitCtx.newSymbol(cls, nme.apply, Method, ExprType(defn.AnyType), coord = pos).entered
67+
cls.enter(newDefaultConstructor(cls), EmptyScope)
68+
val meth = newSymbol(cls, nme.apply, Method, ExprType(defn.AnyType), coord = pos).entered
6969

7070
val quoted =
7171
given Context = unitCtx.withOwner(meth)

0 commit comments

Comments
 (0)