@@ -34,19 +34,17 @@ import scala.annotation.internal.sharable
3434
3535import DenotTransformers .DenotTransformer
3636import dotty .tools .dotc .profile .Profiler
37+ import dotty .tools .dotc .sbt .interfaces .IncrementalCallback
3738import util .Property .Key
3839import util .Store
39- import xsbti .AnalysisCallback
4040import plugins ._
4141import java .util .concurrent .atomic .AtomicInteger
42- import java .util .Map as JMap
4342import java .nio .file .InvalidPathException
4443
45-
4644object Contexts {
4745
4846 private val (compilerCallbackLoc, store1) = Store .empty.newLocation[CompilerCallback ]()
49- private val (sbtCallbackLoc , store2) = store1.newLocation[AnalysisCallback ]()
47+ private val (incCallbackLoc , store2) = store1.newLocation[IncrementalCallback | Null ]()
5048 private val (printerFnLoc, store3) = store2.newLocation[Context => Printer ](new RefinedPrinter (_))
5149 private val (settingsStateLoc, store4) = store3.newLocation[SettingsState ]()
5250 private val (compilationUnitLoc, store5) = store4.newLocation[CompilationUnit ]()
@@ -55,7 +53,7 @@ object Contexts {
5553 private val (notNullInfosLoc, store8) = store7.newLocation[List [NotNullInfo ]]()
5654 private val (importInfoLoc, store9) = store8.newLocation[ImportInfo | Null ]()
5755 private val (typeAssignerLoc, store10) = store9.newLocation[TypeAssigner ](TypeAssigner )
58- private val (zincVirtualFilesLoc , store11) = store10.newLocation[JMap [ String , xsbti. VirtualFile ] | Null ]()
56+ private val (zincInitialFilesLoc , store11) = store10.newLocation[util. ReadOnlySet [ AbstractFile ] | Null ]()
5957
6058 private val initialStore = store11
6159
@@ -168,10 +166,18 @@ object Contexts {
168166 def compilerCallback : CompilerCallback = store(compilerCallbackLoc)
169167
170168 /** The Zinc callback implementation if we are run from Zinc, null otherwise */
171- def sbtCallback : AnalysisCallback = store(sbtCallbackLoc)
169+ def incCallback : IncrementalCallback | Null = store(incCallbackLoc)
170+ def zincInitialFiles : util.ReadOnlySet [AbstractFile ] | Null = store(zincInitialFilesLoc)
171+
172+ /** Run `op` if there exists an incremental callback */
173+ inline def withIncCallback (inline op : IncrementalCallback => Unit ): Unit =
174+ val local = incCallback
175+ if local != null then op(local)
172176
173- /** A map from absolute path to VirtualFile if we are run from Zinc, null otherwise */
174- def zincVirtualFiles : JMap [String , xsbti.VirtualFile ] | Null = store(zincVirtualFilesLoc)
177+ def incrementalEnabled : Boolean =
178+ val local = incCallback
179+ if local != null then local.enabled
180+ else false
175181
176182 /** The current plain printer */
177183 def printerFn : Context => Printer = store(printerFnLoc)
@@ -240,7 +246,16 @@ object Contexts {
240246 /** Sourcefile corresponding to given abstract file, memoized */
241247 def getSource (file : AbstractFile , codec : => Codec = Codec (settings.encoding.value)) = {
242248 util.Stats .record(" Context.getSource" )
243- base.sources.getOrElseUpdate(file, SourceFile (file, codec))
249+ base.sources.getOrElseUpdate(file, {
250+ val zincSources = zincInitialFiles
251+ val cachedFile =
252+ if zincSources != null then zincSources.lookup(file) match
253+ case null => file
254+ case cached => cached
255+ else
256+ file
257+ SourceFile (cachedFile, codec)
258+ })
244259 }
245260
246261 /** SourceFile with given path name, memoized */
@@ -670,9 +685,8 @@ object Contexts {
670685 }
671686
672687 def setCompilerCallback (callback : CompilerCallback ): this .type = updateStore(compilerCallbackLoc, callback)
673- def setSbtCallback (callback : AnalysisCallback ): this .type = updateStore(sbtCallbackLoc, callback)
674- def setZincVirtualFiles (map : JMap [String , xsbti.VirtualFile ]): this .type =
675- updateStore(zincVirtualFilesLoc, map)
688+ def setIncCallback (callback : IncrementalCallback ): this .type = updateStore(incCallbackLoc, callback)
689+ def setZincInitialFiles (zincInitialFiles : util.ReadOnlySet [AbstractFile ]): this .type = updateStore(zincInitialFilesLoc, zincInitialFiles)
676690 def setPrinterFn (printer : Context => Printer ): this .type = updateStore(printerFnLoc, printer)
677691 def setSettings (settingsState : SettingsState ): this .type = updateStore(settingsStateLoc, settingsState)
678692 def setRun (run : Run | Null ): this .type = updateStore(runLoc, run)
0 commit comments