Skip to content

Rename ctx values #8654

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 9 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ object GenBCode {
val name: String = "genBCode"
}

class GenBCodePipeline(val int: DottyBackendInterface)(implicit val ctx: Context) extends BCodeSyncAndTry {
class GenBCodePipeline(val int: DottyBackendInterface)(implicit ctx: Context) extends BCodeSyncAndTry {

private var tree: Tree = _

Expand Down
27 changes: 11 additions & 16 deletions compiler/src/dotty/tools/backend/jvm/scalaPrimitives.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* NSC -- new Scala compiler
* Copyright 2005-2012 LAMP/EPFL
* @author Martin Odersky
*/

package dotty.tools
package backend.jvm

Expand Down Expand Up @@ -35,7 +30,7 @@ import scala.collection.immutable
*
* Inspired from the `scalac` compiler.
*/
class DottyPrimitives(ctx: Context) {
class DottyPrimitives(ictx: Context) {
import dotty.tools.backend.ScalaPrimitivesOps._

@threadUnsafe private lazy val primitives: immutable.Map[Symbol, Int] = init
Expand Down Expand Up @@ -124,7 +119,7 @@ class DottyPrimitives(ctx: Context) {
/** Initialize the primitive map */
private def init: immutable.Map[Symbol, Int] = {

implicit val ctx = this.ctx
given Context = ictx

import Symbols.defn
val primitives = Symbols.newMutableSymbolMap[Int]
Expand Down Expand Up @@ -401,14 +396,14 @@ class DottyPrimitives(ctx: Context) {
primitives.toMap
}

def isPrimitive(fun: Tree): Boolean = {
(primitives contains fun.symbol(ctx)) ||
(fun.symbol(ctx) == NoSymbol // the only trees that do not have a symbol assigned are array.{update,select,length,clone}}
&& (fun match {
case Select(_, StdNames.nme.clone_) => false // but array.clone is NOT a primitive op.
case _ => true
}))
}

def isPrimitive(fun: Tree): Boolean =
given Context = ictx
primitives.contains(fun.symbol)
|| (fun.symbol == NoSymbol // the only trees that do not have a symbol assigned are array.{update,select,length,clone}}
&& {
fun match
case Select(_, StdNames.nme.clone_) => false // but array.clone is NOT a primitive op.
case _ => true
})
}

18 changes: 9 additions & 9 deletions compiler/src/dotty/tools/dotc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ class Driver {
protected def sourcesRequired: Boolean = true

def setup(args: Array[String], rootCtx: Context): (List[String], Context) = {
val ctx = rootCtx.fresh
val summary = CompilerCommand.distill(args)(ctx)
ctx.setSettings(summary.sstate)
MacroClassLoader.init(ctx)
Positioned.updateDebugPos(ctx)
val ictx = rootCtx.fresh
val summary = CompilerCommand.distill(args)(ictx)
ictx.setSettings(summary.sstate)
MacroClassLoader.init(ictx)
Positioned.updateDebugPos(ictx)

if (!ctx.settings.YdropComments.value(ctx) || ctx.mode.is(Mode.ReadComments))
ctx.setProperty(ContextDoc, new ContextDocstrings)
if (!ictx.settings.YdropComments.value(ictx) || ictx.mode.is(Mode.ReadComments))
ictx.setProperty(ContextDoc, new ContextDocstrings)

val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)(ctx)
fromTastySetup(fileNames, ctx)
val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)(ictx)
fromTastySetup(fileNames, ictx)
}

/** Setup extra classpath and figure out class names for tasty file inputs */
Expand Down
12 changes: 5 additions & 7 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
private var myCtx = rootContext(ictx)

/** The context created for this run */
def runContext: Context = myCtx

protected implicit def ctx: Context = myCtx
assert(ctx.runId <= Periods.MaxPossibleRunId)
given runContext[Dummy_so_its_a_def] as Context = myCtx
assert(runContext.runId <= Periods.MaxPossibleRunId)

private var myUnits: List[CompilationUnit] = _
private var myUnitsCached: List[CompilationUnit] = _
Expand Down Expand Up @@ -108,12 +106,12 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
private var finalizeActions = mutable.ListBuffer[() => Unit]()

def compile(fileNames: List[String]): Unit = try {
val sources = fileNames.map(ctx.getSource(_))
val sources = fileNames.map(runContext.getSource(_))
compileSources(sources)
}
catch {
case NonFatal(ex) =>
ctx.echo(i"exception occurred while compiling $units%, %")
runContext.echo(i"exception occurred while compiling $units%, %")
throw ex
}

Expand Down Expand Up @@ -266,7 +264,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
/** Print summary; return # of errors encountered */
def printSummary(): Unit = {
printMaxConstraint()
val r = ctx.reporter
val r = runContext.reporter
r.printSummary
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ object desugar {
val originalOwner = sym.owner
def apply(tp: Type) = tp match {
case tp: NamedType if tp.symbol.exists && (tp.symbol.owner eq originalOwner) =>
val defctx = this.ctx.outersIterator.dropWhile(_.scope eq this.ctx.scope).next()
val defctx = mapCtx.outersIterator.dropWhile(_.scope eq mapCtx.scope).next()
var local = defctx.denotNamed(tp.name).suchThat(_.isParamOrAccessor).symbol
if (local.exists) (defctx.owner.thisType select local).dealiasKeepAnnots
else {
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ object Contexts {
with Plugins
with Cloneable { thiscontext =>

implicit def ctx: Context = this
implicit def thisContext: Context = this

/** All outer contexts, ending in `base.initialCtx` and then `NoContext` */
def outersIterator: Iterator[Context] = new Iterator[Context] {
Expand Down Expand Up @@ -284,10 +284,10 @@ object Contexts {
withPhase(phase.id)

final def withPhaseNoLater(phase: Phase): Context =
if (phase.exists && ctx.phase.id > phase.id) withPhase(phase) else ctx
if (phase.exists && this.phase.id > phase.id) withPhase(phase) else this

final def withPhaseNoEarlier(phase: Phase): Context =
if (phase.exists && ctx.phase.id < phase.id) withPhase(phase) else ctx
if (phase.exists && this.phase.id < phase.id) withPhase(phase) else this

// `creationTrace`-related code. To enable, uncomment the code below and the
// call to `setCreationTrace()` in this file.
Expand Down Expand Up @@ -399,15 +399,15 @@ object Contexts {
def exprContext(stat: Tree[? >: Untyped], exprOwner: Symbol): Context =
if (exprOwner == this.owner) this
else if (untpd.isSuperConstrCall(stat) && this.owner.isClass) superCallContext
else ctx.fresh.setOwner(exprOwner)
else fresh.setOwner(exprOwner)

/** A new context that summarizes an import statement */
def importContext(imp: Import[?], sym: Symbol): FreshContext = {
val impNameOpt = imp.expr match {
case ref: RefTree[?] => Some(ref.name.asTermName)
case _ => None
}
ctx.fresh.setImportInfo(ImportInfo(sym, imp.selectors, impNameOpt))
fresh.setImportInfo(ImportInfo(sym, imp.selectors, impNameOpt))
}

/** Does current phase use an erased types interpretation? */
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ object Definitions {
class Definitions {
import Definitions._

private implicit var ctx: Context = _
private var initCtx: Context = _
private given ctx[Dummy_so_its_a_def] as Context = initCtx

private def newSymbol[N <: Name](owner: Symbol, name: N, flags: FlagSet, info: Type) =
ctx.newSymbol(owner, name, flags | Permanent, info)
Expand Down Expand Up @@ -1427,7 +1428,7 @@ class Definitions {
private var isInitialized = false

def init()(implicit ctx: Context): Unit = {
this.ctx = ctx
this.initCtx = ctx
if (!isInitialized) {
// Enter all symbols from the scalaShadowing package in the scala package
for (m <- ScalaShadowingPackage.info.decls)
Expand Down
16 changes: 8 additions & 8 deletions compiler/src/dotty/tools/dotc/core/Periods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Contexts._
* run ids represent compiler runs
* phase ids represent compiler phases
*/
abstract class Periods { self: Context =>
abstract class Periods { thisCtx: Context =>
import Periods._

/** The current phase identifier */
Expand All @@ -18,11 +18,11 @@ abstract class Periods { self: Context =>

/** Execute `op` at given period */
def atPeriod[T](pd: Period)(op: Context => T): T =
op(ctx.fresh.setPeriod(pd))
op(thisCtx.fresh.setPeriod(pd))

/** Execute `op` at given phase id */
def atPhase[T](pid: PhaseId)(op: Context ?=> T): T =
op(using ctx.withPhase(pid))
op(using thisCtx.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 All @@ -31,19 +31,19 @@ abstract class Periods { self: Context =>
*/
def stablePeriod: Period = {
var first = phaseId
val nxTrans = ctx.base.nextDenotTransformerId(first)
while (first - 1 > NoPhaseId && (ctx.base.nextDenotTransformerId(first - 1) == nxTrans))
val nxTrans = thisCtx.base.nextDenotTransformerId(first)
while (first - 1 > NoPhaseId && (thisCtx.base.nextDenotTransformerId(first - 1) == nxTrans))
first -= 1
Period(runId, first, nxTrans)
}

/** Are all base types in the current period guaranteed to be the same as in period `p`? */
def hasSameBaseTypesAs(p: Period): Boolean = {
val period = this.period
val period = thisCtx.period
period == p ||
period.runId == p.runId &&
this.phases(period.phaseId).sameBaseTypesStartId ==
this.phases(p.phaseId).sameBaseTypesStartId
thisCtx.phases(period.phaseId).sameBaseTypesStartId ==
thisCtx.phases(p.phaseId).sameBaseTypesStartId
}
}

Expand Down
14 changes: 7 additions & 7 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import transform.TypeUtils._

import scala.annotation.internal.sharable

trait SymDenotations { this: Context =>
trait SymDenotations { thisCtx: Context =>
import SymDenotations._

/** Factory method for SymDenotion creation. All creations
Expand All @@ -53,9 +53,9 @@ trait SymDenotations { this: Context =>
if (denot.isOneOf(ValidForeverFlags) || denot.isRefinementClass || denot.isImport) true
else {
val initial = denot.initial
val firstPhaseId = initial.validFor.firstPhaseId.max(ctx.typerPhase.id)
if ((initial ne denot) || ctx.phaseId != firstPhaseId)
ctx.withPhase(firstPhaseId).stillValidInOwner(initial)
val firstPhaseId = initial.validFor.firstPhaseId.max(thisCtx.typerPhase.id)
if ((initial ne denot) || thisCtx.phaseId != firstPhaseId)
thisCtx.withPhase(firstPhaseId).stillValidInOwner(initial)
else
stillValidInOwner(denot)
}
Expand All @@ -78,15 +78,15 @@ trait SymDenotations { this: Context =>
def traceInvalid(denot: Denotation): Boolean = {
def show(d: Denotation) = s"$d#${d.symbol.id}"
def explain(msg: String) = {
println(s"${show(denot)} is invalid at ${this.period} because $msg")
println(s"${show(denot)} is invalid at ${thisCtx.period} because $msg")
false
}
denot match {
case denot: SymDenotation =>
def explainSym(msg: String) = explain(s"$msg\ndefined = ${denot.definedPeriodsString}")
if (denot.isOneOf(ValidForeverFlags) || denot.isRefinementClass) true
else {
implicit val ctx = this
implicit val ctx = thisCtx
val initial = denot.initial
if ((initial ne denot) || ctx.phaseId != initial.validFor.firstPhaseId)
ctx.withPhase(initial.validFor.firstPhaseId).traceInvalid(initial)
Expand Down Expand Up @@ -116,7 +116,7 @@ trait SymDenotations { this: Context =>
/** Possibly accept stale symbol with warning if in IDE */
def acceptStale(denot: SingleDenotation): Boolean =
staleOK && {
ctx.debugwarn(denot.staleSymbolMsg)
thisCtx.debugwarn(denot.staleSymbolMsg)
true
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import scala.annotation.internal.sharable
import config.Printers.typr

/** Creation methods for symbols */
trait Symbols { this: Context =>
trait Symbols { thisCtx: Context =>

// ---- Factory methods for symbol creation ----------------------
//
Expand Down Expand Up @@ -131,7 +131,7 @@ trait Symbols { this: Context =>
}

def newRefinedClassSymbol(coord: Coord = NoCoord): ClassSymbol =
newCompleteClassSymbol(ctx.owner, tpnme.REFINE_CLASS, NonMember, parents = Nil, coord = coord)
newCompleteClassSymbol(thisCtx.owner, tpnme.REFINE_CLASS, NonMember, parents = Nil, coord = coord)

/** Create a module symbol with associated module class
* from its non-info fields and a function producing the info
Expand Down Expand Up @@ -268,7 +268,7 @@ trait Symbols { this: Context =>

/** Create a symbol representing a selftype declaration for class `cls`. */
def newSelfSym(cls: ClassSymbol, name: TermName = nme.WILDCARD, selfInfo: Type = NoType): TermSymbol =
ctx.newSymbol(cls, name, SelfSymFlags, selfInfo orElse cls.classInfo.selfType, coord = cls.coord)
newSymbol(cls, name, SelfSymFlags, selfInfo orElse cls.classInfo.selfType, coord = cls.coord)

/** Create new type parameters with given owner, names, and flags.
* @param boundsFn A function that, given type refs to the newly created
Expand Down
20 changes: 10 additions & 10 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import typer.IfBottom

import scala.annotation.internal.sharable

trait TypeOps { this: Context => // TODO: Make standalone object.
trait TypeOps { thisCtx: Context => // TODO: Make standalone object.

/** The type `tp` as seen from prefix `pre` and owner `cls`. See the spec
* for what this means.
Expand Down Expand Up @@ -134,7 +134,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
}
case tp: TypeParamRef =>
if (tp.paramName.is(DepParamName)) {
val bounds = ctx.typeComparer.bounds(tp)
val bounds = thisCtx.typeComparer.bounds(tp)
if (bounds.lo.isRef(defn.NothingClass)) bounds.hi else bounds.lo
}
else {
Expand All @@ -145,9 +145,9 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
tp
case tp: AliasingBounds =>
tp.derivedAlias(simplify(tp.alias, theMap))
case AndType(l, r) if !ctx.mode.is(Mode.Type) =>
case AndType(l, r) if !thisCtx.mode.is(Mode.Type) =>
simplify(l, theMap) & simplify(r, theMap)
case OrType(l, r) if !ctx.mode.is(Mode.Type) =>
case OrType(l, r) if !thisCtx.mode.is(Mode.Type) =>
simplify(l, theMap) | simplify(r, theMap)
case _: AppliedType | _: MatchType =>
val normed = tp.tryNormalize
Expand Down Expand Up @@ -192,7 +192,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
val accu1 = if (accu exists (_ derivesFrom c)) accu else c :: accu
if (cs == c.baseClasses) accu1 else dominators(rest, accu1)
case Nil => // this case can happen because after erasure we do not have a top class anymore
assert(ctx.erasedTypes || ctx.reporter.errorsReported)
assert(thisCtx.erasedTypes || thisCtx.reporter.errorsReported)
defn.ObjectClass :: Nil
}

Expand All @@ -216,7 +216,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
case AppliedType(tycon2, args2) =>
tp1.derivedAppliedType(
mergeRefinedOrApplied(tycon1, tycon2),
ctx.typeComparer.lubArgs(args1, args2, tycon1.typeParams))
thisCtx.typeComparer.lubArgs(args1, args2, tycon1.typeParams))
case _ => fallback
}
case tp1 @ TypeRef(pre1, _) =>
Expand Down Expand Up @@ -492,15 +492,15 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
def featureEnabled(feature: TermName, owner: Symbol = NoSymbol): Boolean = {
def hasImport = {
val owner1 = if (!owner.exists) defn.LanguageModule.moduleClass else owner
ctx.importInfo != null &&
ctx.importInfo.featureImported(feature, owner1)(ctx.withPhase(ctx.typerPhase))
thisCtx.importInfo != null &&
thisCtx.importInfo.featureImported(feature, owner1)(thisCtx.withPhase(thisCtx.typerPhase))
}
val hasOption = {
def toPrefix(sym: Symbol): String =
if (!sym.exists) ""
else toPrefix(sym.owner) + sym.name + "."
val featureName = toPrefix(owner) + feature
ctx.base.settings.language.value contains featureName
thisCtx.base.settings.language.value contains featureName
}
hasOption || hasImport
}
Expand All @@ -527,7 +527,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
* This test is used when we are too early in the pipeline to consider imports.
*/
def scala2CompatSetting: Boolean =
ctx.settings.language.value.contains(nme.Scala2Compat.toString)
thisCtx.settings.language.value.contains(nme.Scala2Compat.toString)

/** Refine child based on parent
*
Expand Down
Loading