Skip to content

More dotc refactorings #6861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 17, 2019
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
* @see https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.4
*/
def getGenericSignature(sym: Symbol, owner: Symbol): String = {
ctx.atPhase(ctx.erasurePhase) { implicit ctx =>
ctx.atPhase(ctx.erasurePhase) {
val memberTpe =
if (sym.is(Flags.Method)) sym.denot.info
else owner.denot.thisType.memberInfo(sym)
Expand All @@ -533,7 +533,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
// But for now, just like we did in mixin, we just avoid writing a wrong generic signature
// (one that doesn't erase to the actual signature). See run/t3452b for a test case.

val memberTpe = ctx.atPhase(ctx.erasurePhase) { implicit ctx => moduleClass.denot.thisType.memberInfo(sym) }
val memberTpe = ctx.atPhase(ctx.erasurePhase) { moduleClass.denot.thisType.memberInfo(sym) }
val erasedMemberType = TypeErasure.erasure(memberTpe)
if (erasedMemberType =:= sym.denot.info)
getGenericSignature(sym, moduleClass, memberTpe).orNull
Expand Down Expand Up @@ -782,7 +782,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma

private def definedClasses(phase: Phase) =
if (sym.isDefinedInCurrentRun)
ctx.atPhase(phase) { implicit ctx =>
ctx.atPhase(phase) {
toDenot(sym).info.decls.filter(_.isClass)
}
else Nil
Expand Down Expand Up @@ -835,13 +835,13 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
* such objects.
*/
def isTopLevelModuleClass: Boolean = sym.isModuleClass &&
ctx.atPhase(ctx.flattenPhase) { implicit ctx =>
ctx.atPhase(ctx.flattenPhase) {
toDenot(sym).owner.is(Flags.PackageClass)
}

def addRemoteRemoteExceptionAnnotation: Unit = ()

def samMethod(): Symbol = ctx.atPhase(ctx.erasurePhase) { implicit ctx =>
def samMethod(): Symbol = ctx.atPhase(ctx.erasurePhase) {
toDenot(sym).info.abstractTermMembers.toList match {
case x :: Nil => x.symbol
case Nil => abort(s"${sym.show} is not a functional interface. It doesn't have abstract methods")
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
val (cl1, cl2) =
if (classSymbol.effectiveName.toString < dupClassSym.effectiveName.toString) (classSymbol, dupClassSym)
else (dupClassSym, classSymbol)
ctx.atPhase(ctx.typerPhase) { implicit ctx =>
ctx.warning(s"${cl1.show} differs only in case from ${cl2.showLocated}. " +
ctx.atPhase(ctx.typerPhase) {
the[Context].warning(s"${cl1.show} differs only in case from ${cl2.showLocated}. " +
"Such classes will overwrite one another on case-insensitive filesystems.", cl1.sourcePos)
}
}
Expand Down Expand Up @@ -263,7 +263,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter

// ----------- compiler and sbt's callbacks

val (fullClassName, isLocal) = ctx.atPhase(ctx.sbtExtractDependenciesPhase) { implicit ctx =>
val (fullClassName, isLocal) = ctx.atPhase(ctx.sbtExtractDependenciesPhase) {
(ExtractDependencies.classNameAsString(claszSymbol), claszSymbol.isLocal)
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,7 @@ class JSCodeGen()(implicit ctx: Context) {
if (isStat) {
boxedResult
} else {
val tpe = ctx.atPhase(ctx.elimErasedValueTypePhase) { implicit ctx =>
val tpe = ctx.atPhase(ctx.elimErasedValueTypePhase) {
sym.info.finalResultType
}
unbox(boxedResult, tpe)
Expand Down Expand Up @@ -2578,13 +2578,13 @@ class JSCodeGen()(implicit ctx: Context) {
def paramNamesAndTypes(implicit ctx: Context): List[(Names.TermName, Type)] =
sym.info.paramNamess.flatten.zip(sym.info.paramInfoss.flatten)

val wereRepeated = ctx.atPhase(ctx.elimRepeatedPhase) { implicit ctx =>
val wereRepeated = ctx.atPhase(ctx.elimRepeatedPhase) {
val list = for ((name, tpe) <- paramNamesAndTypes)
yield (name -> tpe.isRepeatedParam)
list.toMap
}

val paramTypes = ctx.atPhase(ctx.elimErasedValueTypePhase) { implicit ctx =>
val paramTypes = ctx.atPhase(ctx.elimErasedValueTypePhase) {
paramNamesAndTypes.toMap
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/backend/sjs/JSInterop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object JSInterop {
/** Is this symbol a JavaScript type? */
def isJSType(sym: Symbol)(implicit ctx: Context): Boolean = {
//sym.hasAnnotation(jsdefn.RawJSTypeAnnot)
ctx.atPhase(ctx.erasurePhase) { implicit ctx =>
ctx.atPhase(ctx.erasurePhase) {
sym.derivesFrom(jsdefn.JSAnyClass)
}
}
Expand All @@ -32,7 +32,7 @@ object JSInterop {
* much as *accessor* methods created for `val`s and `var`s.
*/
def isJSGetter(sym: Symbol)(implicit ctx: Context): Boolean = {
sym.info.firstParamTypes.isEmpty && ctx.atPhase(ctx.erasurePhase) { implicit ctx =>
sym.info.firstParamTypes.isEmpty && ctx.atPhase(ctx.erasurePhase) {
sym.info.isParameterless
}
}
Expand Down
16 changes: 8 additions & 8 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,32 +124,32 @@ object Annotations {
}

/** Create an annotation where the tree is computed lazily. */
def deferred(sym: Symbol, treeFn: Context => Tree)(implicit ctx: Context): Annotation =
def deferred(sym: Symbol)(treeFn: given Context => Tree)(implicit ctx: Context): Annotation =
new LazyAnnotation {
override def symbol(implicit ctx: Context): Symbol = sym
def complete(implicit ctx: Context) = treeFn(ctx)
def complete(implicit ctx: Context) = treeFn given ctx
}

/** Create an annotation where the symbol and the tree are computed lazily. */
def deferredSymAndTree(symf: Context => Symbol, treeFn: Context => Tree)(implicit ctx: Context): Annotation =
def deferredSymAndTree(symf: given Context => Symbol)(treeFn: given Context => Tree)(implicit ctx: Context): Annotation =
new LazyAnnotation {
private[this] var mySym: Symbol = _

override def symbol(implicit ctx: Context): Symbol = {
if (mySym == null || mySym.defRunId != ctx.runId) {
mySym = symf(ctx)
mySym = symf given ctx
assert(mySym != null)
}
mySym
}
def complete(implicit ctx: Context) = treeFn(ctx)
def complete(implicit ctx: Context) = treeFn given ctx
}

def deferred(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation =
deferred(atp.classSymbol, implicit ctx => New(atp, args))
deferred(atp.classSymbol)(New(atp, args))

def deferredResolve(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation =
deferred(atp.classSymbol, implicit ctx => resolveConstructor(atp, args))
deferred(atp.classSymbol)(resolveConstructor(atp, args))

def makeAlias(sym: TermSymbol)(implicit ctx: Context): Annotation =
apply(defn.AliasAnnot, List(
Expand All @@ -165,7 +165,7 @@ object Annotations {
New(defn.ChildAnnotType.appliedTo(sym.owner.thisType.select(sym.name, sym)), Nil)
.withSpan(span)
}
deferred(defn.ChildAnnot, implicit ctx => makeChildLater(ctx))
deferred(defn.ChildAnnot)(makeChildLater(ctx))
}

/** A regular, non-deferred Child annotation */
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ object Contexts {
/** Run `op` as if it was run in a fresh explore typer state, but possibly
* optimized to re-use the current typer state.
*/
final def test[T](op: Context => T): T = typerState.test(op)(this)
final def test[T](op: given Context => T): T = typerState.test(op)(this)

/** Is this a context for the members of a class definition? */
def isClassDefContext: Boolean =
Expand Down Expand Up @@ -404,7 +404,7 @@ object Contexts {
case _ => None
}
ctx.fresh.setImportInfo(
new ImportInfo(implicit ctx => sym, imp.selectors, impNameOpt, imp.importDelegate))
ImportInfo(sym, imp.selectors, impNameOpt, imp.importDelegate))
}

/** Does current phase use an erased types interpretation? */
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Decorators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ object Decorators {
* give more info about type variables and to disambiguate where needed.
*/
def ex(args: Any*)(implicit ctx: Context): String =
explained(implicit ctx => em(args: _*))
explained(em(args: _*))
}

implicit class ArrayInterpolator[T <: AnyRef](val arr: Array[T]) extends AnyVal {
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Periods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ abstract class Periods { self: Context =>
op(ctx.fresh.setPeriod(pd))

/** Execute `op` at given phase id */
def atPhase[T](pid: PhaseId)(op: Context => T): T =
op(ctx.withPhase(pid))
def atPhase[T](pid: PhaseId)(op: given Context => T): T =
op given ctx.withPhase(pid)

/** The period containing the current period where denotations do not change.
* We compute this by taking as first phase the first phase less or equal to
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ trait Phases {
}

/** Execute `op` at given phase */
def atPhase[T](phase: Phase)(op: Context => T): T =
def atPhase[T](phase: Phase)(op: given Context => T): T =
atPhase(phase.id)(op)

def atNextPhase[T](op: Context => T): T = atPhase(phase.next)(op)
def atNextPhase[T](op: given Context => T): T = atPhase(phase.next)(op)

def atPhaseNotLaterThan[T](limit: Phase)(op: Context => T): T =
if (!limit.exists || phase <= limit) op(this) else atPhase(limit)(op)
def atPhaseNotLaterThan[T](limit: Phase)(op: given Context => T): T =
if (!limit.exists || phase <= limit) op given this else atPhase(limit)(op)

def isAfterTyper: Boolean = base.isAfterTyper(phase)
}
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
//}
assert(!ctx.settings.YnoDeepSubtypes.value)
if (Config.traceDeepSubTypeRecursions && !this.isInstanceOf[ExplainingTypeComparer])
ctx.log(TypeComparer.explained(implicit ctx => ctx.typeComparer.isSubType(tp1, tp2, approx)))
ctx.log(TypeComparer.explained(the[Context].typeComparer.isSubType(tp1, tp2, approx)))
}
// Eliminate LazyRefs before checking whether we have seen a type before
val normalize = new TypeMap {
Expand Down Expand Up @@ -2307,15 +2307,15 @@ object TypeComparer {
*/
val FreshApprox: ApproxState = new ApproxState(4)

/** Show trace of comparison operations when performing `op` as result string */
def explaining[T](say: String => Unit)(op: Context => T)(implicit ctx: Context): T = {
/** Show trace of comparison operations when performing `op` */
def explaining[T](say: String => Unit)(op: given Context => T)(implicit ctx: Context): T = {
val nestedCtx = ctx.fresh.setTypeComparerFn(new ExplainingTypeComparer(_))
val res = try { op(nestedCtx) } finally { say(nestedCtx.typeComparer.lastTrace()) }
val res = try { op given nestedCtx } finally { say(nestedCtx.typeComparer.lastTrace()) }
res
}

/** Like [[explaining]], but returns the trace instead */
def explained[T](op: Context => T)(implicit ctx: Context): String = {
def explained[T](op: given Context => T)(implicit ctx: Context): String = {
var trace: String = null
try { explaining(trace = _)(op) } catch { case ex: Throwable => ex.printStackTrace }
trace
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/TyperState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ class TyperState(private val previous: TyperState /* | Null */) {
* typerstate. If it is unshared, run `op` in current typerState, restoring typerState
* to previous state afterwards.
*/
def test[T](op: Context => T)(implicit ctx: Context): T =
def test[T](op: given Context => T)(implicit ctx: Context): T =
if (isShared)
op(ctx.fresh.setExploreTyperState())
op given ctx.fresh.setExploreTyperState()
else {
val savedConstraint = myConstraint
val savedReporter = myReporter
Expand All @@ -114,7 +114,7 @@ class TyperState(private val previous: TyperState /* | Null */) {
testReporter.inUse = true
testReporter
}
try op(ctx)
try op given ctx
finally {
testReporter.inUse = false
resetConstraintTo(savedConstraint)
Expand Down
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,7 @@ class TreeUnpickler(reader: TastyReader,
val lazyAnnotTree = readLaterWithOwner(end, rdr => ctx => rdr.readTerm()(ctx))

owner =>
Annotation.deferredSymAndTree(
implicit ctx => tp.typeSymbol,
implicit ctx => lazyAnnotTree(owner).complete)
Annotation.deferredSymAndTree(tp.typeSymbol)(lazyAnnotTree(owner).complete)
}

/** Create symbols for the definitions in the statement sequence between
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -972,9 +972,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
val start = readIndex
val atp = readTypeRef()
val phase = ctx.phase
Annotation.deferred(
atp.typeSymbol, implicit ctx =>
atReadPos(start, () => readAnnotationContents(end)(ctx.withPhase(phase))))
Annotation.deferred(atp.typeSymbol)(
atReadPos(start, () => readAnnotationContents(end)(the[Context].withPhase(phase))))
}

/* Read an abstract syntax tree */
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/interactive/Interactive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,16 @@ object Interactive {
*/
def localize(symbol: Symbol, sourceDriver: InteractiveDriver, targetDriver: InteractiveDriver): Symbol = {

def in[T](driver: InteractiveDriver)(fn: Context => T): T =
fn(driver.currentCtx)
def in[T](driver: InteractiveDriver)(fn: given Context => T): T =
fn given driver.currentCtx

if (sourceDriver == targetDriver) symbol
else {
val owners = in(sourceDriver) { implicit ctx =>
val owners = in(sourceDriver) {
symbol.ownersIterator.toList.reverse.map(_.name)
}
in(targetDriver) { implicit ctx =>
val base: Symbol = ctx.definitions.RootClass
in(targetDriver) {
val base: Symbol = defn.RootClass
owners.tail.foldLeft(base) { (prefix, symbolName) =>
if (prefix.exists) prefix.info.member(symbolName).symbol
else NoSymbol
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/printing/Formatting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ object Formatting {
* ex"disambiguate $tpe1 and $tpe2"
* ```
*/
def explained(op: Context => String)(implicit ctx: Context): String = {
def explained(op: given Context => String)(implicit ctx: Context): String = {
val seen = new Seen
val msg = op(explainCtx(seen))
val msg = op given explainCtx(seen)
val addendum = explanations(seen)
if (addendum.isEmpty) msg else msg ++ "\n\n" ++ addendum
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class CheckReentrant extends MiniPhase {
private[this] var seen: Set[ClassSymbol] = Set()
private[this] var indent: Int = 0

private val sharableAnnot = new CtxLazy(implicit ctx =>
private val sharableAnnot = new CtxLazy(given ctx =>
ctx.requiredClass("scala.annotation.internal.sharable"))
private val unsharedAnnot = new CtxLazy(implicit ctx =>
private val unsharedAnnot = new CtxLazy(given ctx =>
ctx.requiredClass("scala.annotation.internal.unshared"))

def isIgnored(sym: Symbol)(implicit ctx: Context): Boolean =
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/CtxLazy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import core.Contexts.Context
* A typical use case is a lazy val in a phase object which exists once per root context where
* the expression intiializing the lazy val depends only on the root context, but not any changes afterwards.
*/
class CtxLazy[T](expr: Context => T) {
class CtxLazy[T](expr: given Context => T) {
private[this] var myValue: T = _
private[this] var forced = false
def apply()(implicit ctx: Context): T = {
if (!forced) {
myValue = expr(ctx)
myValue = expr given ctx
forced = true
}
myValue
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/ElimByName.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ElimByName extends TransformByNameApply with InfoTransformer {
private def applyIfFunction(tree: Tree, ftree: Tree)(implicit ctx: Context) =
if (isByNameRef(ftree)) {
val tree0 = transformFollowing(tree)
ctx.atPhase(next) { implicit ctx => tree0.select(defn.Function0_apply).appliedToNone }
ctx.atPhase(next) { tree0.select(defn.Function0_apply).appliedToNone }
}
else tree

Expand All @@ -61,7 +61,7 @@ class ElimByName extends TransformByNameApply with InfoTransformer {
}

override def transformValDef(tree: ValDef)(implicit ctx: Context): Tree =
ctx.atPhase(next) { implicit ctx =>
ctx.atPhase(next) {
if (exprBecomesFunction(tree.symbol))
cpy.ValDef(tree)(tpt = tree.tpt.withType(tree.symbol.info))
else tree
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
* Also transform trees inside method annotation
*/
override def transformDefDef(tree: DefDef)(implicit ctx: Context): Tree =
ctx.atPhase(thisPhase) { implicit ctx =>
ctx.atPhase(thisPhase) {
if (tree.symbol.info.isVarArgsMethod && overridesJava(tree.symbol))
addVarArgsBridge(tree)
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ object ExplicitOuter {

/** Ensure that class `cls` has outer accessors */
def ensureOuterAccessors(cls: ClassSymbol)(implicit ctx: Context): Unit =
ctx.atPhase(ctx.explicitOuterPhase.next) { implicit ctx =>
ctx.atPhase(ctx.explicitOuterPhase.next) {
if (!hasOuter(cls))
newOuterAccessors(cls).foreach(_.enteredAfter(ctx.explicitOuterPhase.asInstanceOf[DenotTransformer]))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ object ExtensionMethods {

/** Return the extension method that corresponds to given instance method `meth`. */
def extensionMethod(imeth: Symbol)(implicit ctx: Context): TermSymbol =
ctx.atPhase(ctx.extensionMethodsPhase.next) { implicit ctx =>
ctx.atPhase(ctx.extensionMethodsPhase.next) {
// FIXME use toStatic instead?
val companion = imeth.owner.companionModule
val companionInfo = companion.info
Expand Down
Loading