@@ -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 */
@@ -96,6 +98,9 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
96
98
/** The source files of all late entered symbols, as a set */
97
99
private [this ] var lateFiles = mutable.Set [AbstractFile ]()
98
100
101
+ /** Actions that need to be performed at the end of the current compilation run */
102
+ private [this ] var finalizeActions = mutable.ListBuffer [() => Unit ]()
103
+
99
104
def getSource (fileName : String ): SourceFile = {
100
105
val f = new PlainFile (io.Path (fileName))
101
106
if (f.isDirectory) {
@@ -143,6 +148,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
143
148
144
149
protected def compileUnits ()(implicit ctx : Context ) = Stats .maybeMonitored {
145
150
ctx.checkSingleThreaded()
151
+ compiling = true
146
152
147
153
// If testing pickler, make sure to stop after pickling phase:
148
154
val stopAfter =
@@ -184,31 +190,32 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
184
190
ctx.phases.foreach(_.initContext(runCtx))
185
191
runPhases(runCtx)
186
192
if (! ctx.reporter.hasErrors) Rewrites .writeBack()
193
+ while (finalizeActions.nonEmpty) {
194
+ val action = finalizeActions.remove(0 )
195
+ action()
196
+ }
197
+ compiling = false
187
198
}
188
199
189
200
/** Enter top-level definitions of classes and objects contain in Scala source file `file`.
190
201
* The newly added symbols replace any previously entered symbols.
202
+ * If `typeCheck = true`, also run typer on the compilation unit.
191
203
*/
192
- def enterRoots (file : AbstractFile )(implicit ctx : Context ): Option [ CompilationUnit ] =
204
+ def lateCompile (file : AbstractFile , typeCheck : Boolean )(implicit ctx : Context ): Unit =
193
205
if (! files.contains(file) && ! lateFiles.contains(file)) {
194
206
lateFiles += file
195
207
val unit = new CompilationUnit (getSource(file.path))
196
- enterRoots(unit)(runContext.fresh.setCompilationUnit(unit))
197
- Some (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))
198
216
}
199
217
else None
200
218
201
- private def enterRoots (unit : CompilationUnit )(implicit ctx : Context ): Unit = {
202
- unit.untpdTree = new Parser (unit.source).parse()
203
- ctx.typer.lateEnter(unit.untpdTree)
204
- }
205
-
206
- def typedTree (unit : CompilationUnit )(implicit ctx : Context ) = {
207
- def typeCheck (implicit ctx : Context ) = ctx.typer.typedExpr(unit.untpdTree)
208
- if (unit.tpdTree.isEmpty) unit.tpdTree = typeCheck(runContext.fresh.setCompilationUnit(unit))
209
- unit.tpdTree
210
- }
211
-
212
219
private sealed trait PrintedTree
213
220
private /* final*/ case class SomePrintedTree (phase : String , tree : String ) extends PrintedTree
214
221
private object NoPrintedTree extends PrintedTree
0 commit comments