@@ -61,6 +61,8 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
61
61
(start.setRun(this ) /: defn.RootImportFns )(addImport)
62
62
}
63
63
64
+ private [this ] var compiling = false
65
+
64
66
private [this ] var myCtx = rootContext(ictx)
65
67
66
68
/** The context created for this run */
@@ -72,8 +74,6 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
72
74
private [this ] var myUnits : List [CompilationUnit ] = _
73
75
private [this ] var myUnitsCached : List [CompilationUnit ] = _
74
76
private [this ] var myFiles : Set [AbstractFile ] = _
75
- private [this ] val myLateUnits = mutable.ListBuffer [CompilationUnit ]()
76
- private [this ] var myLateFiles = mutable.Set [AbstractFile ]()
77
77
78
78
/** The compilation units currently being compiled, this may return different
79
79
* results over time.
@@ -95,11 +95,11 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
95
95
myFiles
96
96
}
97
97
98
- /** Units that are added from source completers but that are not compiled in current run. */
99
- def lateUnits : List [ CompilationUnit ] = myLateUnits.toList
98
+ /** The source files of all late entered symbols, as a set */
99
+ private [ this ] var lateFiles = mutable. Set [ AbstractFile ]()
100
100
101
- /** The source files of all late units, as a set */
102
- def lateFiles : collection. Set [ AbstractFile ] = myLateFiles
101
+ /** Actions that need to be performed at the end of the current compilation run */
102
+ private [ this ] var finalizeActions = mutable. ListBuffer [() => Unit ]()
103
103
104
104
def getSource (fileName : String ): SourceFile = {
105
105
val f = new PlainFile (io.Path (fileName))
@@ -148,6 +148,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
148
148
149
149
protected def compileUnits ()(implicit ctx : Context ) = Stats .maybeMonitored {
150
150
ctx.checkSingleThreaded()
151
+ compiling = true
151
152
152
153
// If testing pickler, make sure to stop after pickling phase:
153
154
val stopAfter =
@@ -189,24 +190,31 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
189
190
ctx.phases.foreach(_.initContext(runCtx))
190
191
runPhases(runCtx)
191
192
if (! ctx.reporter.hasErrors) Rewrites .writeBack()
193
+ while (finalizeActions.nonEmpty) {
194
+ val action = finalizeActions.remove(0 )
195
+ action()
196
+ }
197
+ compiling = false
192
198
}
193
199
194
200
/** Enter top-level definitions of classes and objects contain in Scala source file `file`.
195
201
* The newly added symbols replace any previously entered symbols.
202
+ * If `typeCheck = true`, also run typer on the compilation unit.
196
203
*/
197
- def enterRoots (file : AbstractFile )(implicit ctx : Context ): Unit =
204
+ def lateCompile (file : AbstractFile , typeCheck : Boolean )(implicit ctx : Context ): Unit =
198
205
if (! files.contains(file) && ! lateFiles.contains(file)) {
206
+ lateFiles += file
199
207
val unit = new CompilationUnit (getSource(file.path))
200
- myLateUnits += unit
201
- myLateFiles += file
202
- enterRoots(unit)(runContext.fresh.setCompilationUnit(unit))
208
+ def process ()(implicit ctx : Context ) = {
209
+ unit.untpdTree = new Parser (unit.source).parse()
210
+ ctx.typer.lateEnter(unit.untpdTree)
211
+ def typeCheckUnit () = unit.tpdTree = ctx.typer.typedExpr(unit.untpdTree)
212
+ if (typeCheck)
213
+ if (compiling) finalizeActions += (() => typeCheckUnit()) else typeCheckUnit()
214
+ }
215
+ process()(runContext.fresh.setCompilationUnit(unit))
203
216
}
204
217
205
- private def enterRoots (unit : CompilationUnit )(implicit ctx : Context ): Unit = {
206
- unit.untpdTree = new Parser (unit.source).parse()
207
- ctx.typer.lateEnter(unit.untpdTree)
208
- }
209
-
210
218
private sealed trait PrintedTree
211
219
private /* final*/ case class SomePrintedTree (phase : String , tree : String ) extends PrintedTree
212
220
private object NoPrintedTree extends PrintedTree
0 commit comments