Skip to content

Fix/phases etc #97

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

Closed
wants to merge 6 commits into from
Closed
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
16 changes: 8 additions & 8 deletions src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ class Compiler {
ctx.usePhases(phases)
val rootScope = new MutableScope
val bootstrap = ctx.fresh
.withPeriod(Period(nextRunId, FirstPhaseId))
.withScope(rootScope)
.setPeriod(Period(nextRunId, FirstPhaseId))
.setScope(rootScope)
rootScope.enter(ctx.definitions.RootPackage)(bootstrap)
val start = bootstrap.fresh
.withOwner(defn.RootClass)
.withTyper(new Typer)
.withNewMode(Mode.ImplicitsEnabled)
.withTyperState(new MutableTyperState(ctx.typerState, new ConsoleReporter()(ctx), isCommittable = true))
.setOwner(defn.RootClass)
.setTyper(new Typer)
.setMode(Mode.ImplicitsEnabled)
.setTyperState(new MutableTyperState(ctx.typerState, new ConsoleReporter()(ctx), isCommittable = true))
ctx.definitions.init(start) // set context of definitions to start
def addImport(ctx: Context, sym: Symbol) =
ctx.fresh.withImportInfo(ImportInfo.rootImport(sym)(ctx))
(start.withRunInfo(new RunInfo(start)) /: defn.RootImports)(addImport)
ctx.fresh.setImportInfo(ImportInfo.rootImport(sym)(ctx))
(start.setRunInfo(new RunInfo(start)) /: defn.RootImports)(addImport)
}

def newRun(implicit ctx: Context): Run = {
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class Driver extends DotClass {

def process(args: Array[String]): Reporter = {
val summary = CompilerCommand.distill(args)(initCtx)
implicit val ctx: Context = initCtx.fresh.withSettings(summary.sstate)
implicit val ctx: Context = initCtx.fresh.setSettings(summary.sstate)
val fileNames = CompilerCommand.checkUsage(summary)
try {
doCompile(newCompiler(), fileNames)
Expand Down
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/config/PathResolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ object PathResolver {

def fromPathString(path: String)(implicit ctx: Context): JavaClassPath = {
val settings = ctx.settings.classpath.update(path)
new PathResolver()(ctx.fresh.withSettings(settings)).result
new PathResolver()(ctx.fresh.setSettings(settings)).result
}

/** With no arguments, show the interesting values in Environment and Defaults.
Expand All @@ -152,7 +152,7 @@ object PathResolver {
val ArgsSummary(sstate, rest, errors) =
ctx.settings.processArguments(args.toList, true)
errors.foreach(println)
val pr = new PathResolver()(ctx.fresh.withSettings(sstate))
val pr = new PathResolver()(ctx.fresh.setSettings(sstate))
println(" COMMAND: 'scala %s'".format(args.mkString(" ")))
println("RESIDUAL: 'scala %s'\n".format(rest.mkString(" ")))
pr.result.show
Expand Down
68 changes: 34 additions & 34 deletions src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ object Contexts {
}

final def withMode(mode: Mode): Context =
if (mode != this.mode) fresh.withNewMode(mode) else this
if (mode != this.mode) fresh.setMode(mode) else this

def withPhase(phase: PhaseId): Context =
if (this.phaseId == phaseId) this else fresh.withPhase(phase)
def withPhase(phase: Phase): Context =
final def withPhase(phase: PhaseId): Context =
if (this.phaseId == phaseId) this else fresh.setPhase(phase)
final def withPhase(phase: Phase): Context =
withPhase(phase.id)

final def addMode(mode: Mode): Context = withMode(this.mode | mode)
Expand All @@ -306,36 +306,36 @@ object Contexts {
* of its attributes using the with... methods.
*/
abstract class FreshContext extends Context {
def withPeriod(period: Period): this.type = { this.period = period; this }
def withNewMode(mode: Mode): this.type = { this.mode = mode; this }
def withTyperState(typerState: TyperState): this.type = { this.typerState = typerState; this }
def withNewTyperState: this.type = withTyperState(typerState.fresh(isCommittable = true))
def withExploreTyperState: this.type = withTyperState(typerState.fresh(isCommittable = false))
def withPrinterFn(printer: Context => Printer): this.type = { this.printerFn = printer; this }
def withOwner(owner: Symbol): this.type = { assert(owner != NoSymbol); this.owner = owner; this }
def withSettings(sstate: SettingsState): this.type = { this.sstate = sstate; this }
def withCompilationUnit(compilationUnit: CompilationUnit): this.type = { this.compilationUnit = compilationUnit; this }
def withTree(tree: Tree[_ >: Untyped]): this.type = { this.tree = tree; this }
def withScope(scope: Scope): this.type = { this.scope = scope; this }
def withNewScope: this.type = { this.scope = newScope; this }
def withTypeAssigner(typeAssigner: TypeAssigner): this.type = { this.typeAssigner = typeAssigner; this }
def withTyper(typer: Typer): this.type = { this.scope = typer.scope; withTypeAssigner(typer) }
def withImportInfo(importInfo: ImportInfo): this.type = { this.importInfo = importInfo; this }
def withRunInfo(runInfo: RunInfo): this.type = { this.runInfo = runInfo; this }
def withDiagnostics(diagnostics: Option[StringBuilder]): this.type = { this.diagnostics = diagnostics; this }
def withTypeComparerFn(tcfn: Context => TypeComparer): this.type = { this.typeComparer = tcfn(this); this }
def withSearchHistory(searchHistory: SearchHistory): this.type = { this.searchHistory = searchHistory; this }
def withMoreProperties(moreProperties: Map[String, Any]): this.type = { this.moreProperties = moreProperties; this }

def withProperty(prop: (String, Any)): this.type = withMoreProperties(moreProperties + prop)

override def withPhase(pid: PhaseId): this.type = withPeriod(Period(runId, pid))
override def withPhase(phase: Phase): this.type = withPhase(phase.id)

def withSetting[T](setting: Setting[T], value: T): this.type =
withSettings(setting.updateIn(sstate, value))

def withDebug = withSetting(base.settings.debug, true)
def setPeriod(period: Period): this.type = { this.period = period; this }
def setMode(mode: Mode): this.type = { this.mode = mode; this }
def setTyperState(typerState: TyperState): this.type = { this.typerState = typerState; this }
def clearTyperState: this.type = setTyperState(typerState.fresh(isCommittable = true))
def setExploreTyperState: this.type = setTyperState(typerState.fresh(isCommittable = false))
def setPrinterFn(printer: Context => Printer): this.type = { this.printerFn = printer; this }
def setOwner(owner: Symbol): this.type = { assert(owner != NoSymbol); this.owner = owner; this }
def setSettings(sstate: SettingsState): this.type = { this.sstate = sstate; this }
def setCompilationUnit(compilationUnit: CompilationUnit): this.type = { this.compilationUnit = compilationUnit; this }
def setTree(tree: Tree[_ >: Untyped]): this.type = { this.tree = tree; this }
def setScope(scope: Scope): this.type = { this.scope = scope; this }
def clearScope: this.type = { this.scope = newScope; this }
def setTypeAssigner(typeAssigner: TypeAssigner): this.type = { this.typeAssigner = typeAssigner; this }
def setTyper(typer: Typer): this.type = { this.scope = typer.scope; setTypeAssigner(typer) }
def setImportInfo(importInfo: ImportInfo): this.type = { this.importInfo = importInfo; this }
def setRunInfo(runInfo: RunInfo): this.type = { this.runInfo = runInfo; this }
def setDiagnostics(diagnostics: Option[StringBuilder]): this.type = { this.diagnostics = diagnostics; this }
def setTypeComparerFn(tcfn: Context => TypeComparer): this.type = { this.typeComparer = tcfn(this); this }
def setSearchHistory(searchHistory: SearchHistory): this.type = { this.searchHistory = searchHistory; this }
def setMoreProperties(moreProperties: Map[String, Any]): this.type = { this.moreProperties = moreProperties; this }

def setProperty(prop: (String, Any)): this.type = setMoreProperties(moreProperties + prop)

def setPhase(pid: PhaseId): this.type = setPeriod(Period(runId, pid))
def setPhase(phase: Phase): this.type = setPhase(phase.id)

def setSetting[T](setting: Setting[T], value: T): this.type =
setSettings(setting.updateIn(sstate, value))

def setDebug = setSetting(base.settings.debug, true)
}

/** A class defining the initial context with given context base
Expand Down
55 changes: 35 additions & 20 deletions src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import printing.Printer
import io.AbstractFile
import config.Config
import util.common._
import collection.mutable.ListBuffer
import Decorators.SymbolIteratorDecorator

/** Denotations represent the meaning of symbols and named types.
Expand Down Expand Up @@ -459,7 +460,7 @@ object Denotations {
* 2) the union of all validity periods is a contiguous
* interval.
*/
var nextInRun: SingleDenotation = this
private var nextInRun: SingleDenotation = this

/** The version of this SingleDenotation that was valid in the first phase
* of this run.
Expand All @@ -470,11 +471,22 @@ object Denotations {
current
}

def history: List[SingleDenotation] = {
val b = new ListBuffer[SingleDenotation]
var current = initial
do {
b += (current)
current = current.nextInRun
}
while (current ne initial)
b.toList
}

/** Move validity period of this denotation to a new run. Throw a StaleSymbol error
* if denotation is no longer valid.
*/
private def bringForward()(implicit ctx: Context): SingleDenotation = this match {
case denot: SymDenotation if ctx.stillValid(denot) =>
case denot: SymDenotation if ctx.isValidInRun(denot) =>
if (denot.exists) assert(ctx.runId > validFor.runId, s"denotation $denot invalid in run ${ctx.runId}. ValidFor: $validFor")
var d: SingleDenotation = denot
do {
Expand Down Expand Up @@ -518,27 +530,30 @@ object Denotations {
cur = next
cur
} else {
//println(s"might need new denot for $cur, valid for ${cur.validFor} at $currentPeriod")
// not found, cur points to highest existing variant
var startPid = cur.validFor.lastPhaseId + 1
val nextTranformerId = ctx.nextDenotTransformerId(startPid)
val transformer = ctx.denotTransformers(nextTranformerId)
//println(s"transforming with $transformer")
if (currentPeriod.lastPhaseId > transformer.id)
next = transformer.transform(cur)(ctx.withPhase(startPid)).syncWithParents
if (next eq cur)
startPid = cur.validFor.firstPhaseId
val nextTransformerId = ctx.nextDenotTransformerId(cur.validFor.lastPhaseId)
if (currentPeriod.lastPhaseId <= nextTransformerId)
cur.validFor = Period(currentPeriod.runId, cur.validFor.firstPhaseId, nextTransformerId)
else {
next match {
case next: ClassDenotation => next.resetFlag(Frozen)
case _ =>
var startPid = nextTransformerId + 1
val transformer = ctx.denotTransformers(nextTransformerId)
//println(s"transforming $this with $transformer")
next = transformer.transform(cur)(ctx.withPhase(transformer)).syncWithParents
if (next eq cur)
startPid = cur.validFor.firstPhaseId
else {
next match {
case next: ClassDenotation => next.resetFlag(Frozen)
case _ =>
}
next.nextInRun = cur.nextInRun
cur.nextInRun = next
cur = next
}
next.nextInRun = cur.nextInRun
cur.nextInRun = next
cur = next
cur.validFor = Period(currentPeriod.runId, startPid, transformer.lastPhaseId)
//println(s"new denot: $cur, valid for ${cur.validFor}")
}
cur.validFor = Period(
currentPeriod.runId, startPid, transformer.lastPhaseId)
//println(s"new denot: $cur, valid for ${cur.validFor}")
cur.current // multiple transformations could be required
}
} else {
Expand All @@ -562,7 +577,7 @@ object Denotations {
case denot: SymDenotation => s"in ${denot.owner}"
case _ => ""
}
def msg = s"stale symbol; $this#${symbol.id}$ownerMsg, defined in run ${myValidFor.runId}, is referred to in run ${ctx.period.runId}"
def msg = s"stale symbol; $this#${symbol.id} $ownerMsg, defined in run ${myValidFor.runId}, is referred to in run ${ctx.runId}"
throw new StaleSymbol(msg)
}

Expand Down
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/core/Periods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ abstract class Periods extends DotClass { self: Context =>

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

/** Execute `op` at given phase id */
def atPhase[T](pid: PhaseId)(op: Context => T): T =
op(ctx.fresh.withPhase(pid))
op(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
Loading