@@ -6,6 +6,9 @@ import Contexts._
66import Periods ._
77import Symbols ._
88import Phases ._
9+ import Types ._
10+ import Scopes ._
11+ import typer .{FrontEnd , Typer , ImportInfo , RefChecks }
912import Decorators ._
1013import dotty .tools .dotc .transform .TreeTransforms .TreeTransformer
1114import io .PlainFile
@@ -22,12 +25,41 @@ import dotty.tools.io.VirtualFile
2225import scala .util .control .NonFatal
2326
2427/** A compiler run. Exports various methods to compile source files */
25- class Run (comp : Compiler )(implicit ctx : Context ) {
26-
27- assert(ctx.runId <= Periods .MaxPossibleRunId )
28+ class Run (comp : Compiler , ictx : Context ) {
2829
2930 var units : List [CompilationUnit ] = _
3031
32+ /** Produces the following contexts, from outermost to innermost
33+ *
34+ * bootStrap: A context with next available runId and a scope consisting of
35+ * the RootPackage _root_
36+ * start A context with RootClass as owner and the necessary initializations
37+ * for type checking.
38+ * imports For each element of RootImports, an import context
39+ */
40+ protected [this ] def rootContext (implicit ctx : Context ): Context = {
41+ ctx.initialize()(ctx)
42+ ctx.setPhasePlan(comp.phases)
43+ val rootScope = new MutableScope
44+ val bootstrap = ctx.fresh
45+ .setPeriod(Period (comp.nextRunId, FirstPhaseId ))
46+ .setScope(rootScope)
47+ rootScope.enter(ctx.definitions.RootPackage )(bootstrap)
48+ val start = bootstrap.fresh
49+ .setOwner(defn.RootClass )
50+ .setTyper(new Typer )
51+ .addMode(Mode .ImplicitsEnabled )
52+ .setTyperState(new MutableTyperState (ctx.typerState, ctx.typerState.reporter, isCommittable = true ))
53+ .setFreshNames(new FreshNameCreator .Default )
54+ ctx.initialize()(start) // re-initialize the base context with start
55+ def addImport (ctx : Context , refFn : () => TermRef ) =
56+ ctx.fresh.setImportInfo(ImportInfo .rootImport(refFn)(ctx))
57+ (start.setRunInfo(new RunInfo (start)) /: defn.RootImportFns )(addImport)
58+ }
59+
60+ protected [this ] implicit val ctx : Context = rootContext(ictx)
61+ assert(ctx.runId <= Periods .MaxPossibleRunId )
62+
3163 def getSource (fileName : String ): SourceFile = {
3264 val f = new PlainFile (fileName)
3365 if (f.isDirectory) {
@@ -63,7 +95,17 @@ class Run(comp: Compiler)(implicit ctx: Context) {
6395 compileUnits()
6496 }
6597
66- protected def compileUnits () = Stats .monitorHeartBeat {
98+ def compileUnits (us : List [CompilationUnit ]): Unit = {
99+ units = us
100+ compileUnits()
101+ }
102+
103+ def compileUnits (us : List [CompilationUnit ], ctx : Context ): Unit = {
104+ units = us
105+ compileUnits()(ctx)
106+ }
107+
108+ protected def compileUnits ()(implicit ctx : Context ) = Stats .monitorHeartBeat {
67109 ctx.checkSingleThreaded()
68110
69111 // If testing pickler, make sure to stop after pickling phase:
@@ -76,7 +118,7 @@ class Run(comp: Compiler)(implicit ctx: Context) {
76118 ctx.usePhases(phases)
77119 var lastPrintedTree : PrintedTree = NoPrintedTree
78120 for (phase <- ctx.allPhases)
79- if (! ctx.reporter.hasErrors ) {
121+ if (phase.isRunnable ) {
80122 val start = System .currentTimeMillis
81123 units = phase.runOn(units)
82124 if (ctx.settings.Xprint .value.containsPhase(phase)) {
0 commit comments