@@ -34,7 +34,7 @@ import scala.annotation.internal.sharable
3434
3535import DenotTransformers .DenotTransformer
3636import dotty .tools .dotc .profile .Profiler
37- import dotty .tools .dotc .sbt .interfaces .IncrementalCallback
37+ import dotty .tools .dotc .sbt .interfaces .{ IncrementalCallback , ProgressCallback }
3838import util .Property .Key
3939import util .Store
4040import plugins ._
@@ -53,8 +53,9 @@ object Contexts {
5353 private val (notNullInfosLoc, store8) = store7.newLocation[List [NotNullInfo ]]()
5454 private val (importInfoLoc, store9) = store8.newLocation[ImportInfo | Null ]()
5555 private val (typeAssignerLoc, store10) = store9.newLocation[TypeAssigner ](TypeAssigner )
56+ private val (progressCallbackLoc, store11) = store10.newLocation[ProgressCallback | Null ]()
5657
57- private val initialStore = store10
58+ private val initialStore = store11
5859
5960 /** The current context */
6061 inline def ctx (using ctx : Context ): Context = ctx
@@ -177,6 +178,19 @@ object Contexts {
177178 val local = incCallback
178179 local != null && local.enabled || forceRun
179180
181+ /** The Zinc compile progress callback implementation if we are run from Zinc, null otherwise */
182+ def progressCallback : ProgressCallback | Null = store(progressCallbackLoc)
183+
184+ /** Run `op` if there exists a Zinc progress callback */
185+ inline def withProgressCallback (inline op : ProgressCallback => Unit ): Unit =
186+ val local = progressCallback
187+ if local != null then op(local)
188+
189+ def cancelSignalRecorded : Boolean =
190+ val local = progressCallback
191+ val noSignalRecieved = local == null || ! local.isCancelled
192+ ! noSignalRecieved // if true then cancel request was recorded
193+
180194 /** The current plain printer */
181195 def printerFn : Context => Printer = store(printerFnLoc)
182196
@@ -675,6 +689,7 @@ object Contexts {
675689
676690 def setCompilerCallback (callback : CompilerCallback ): this .type = updateStore(compilerCallbackLoc, callback)
677691 def setIncCallback (callback : IncrementalCallback ): this .type = updateStore(incCallbackLoc, callback)
692+ def setProgressCallback (callback : ProgressCallback ): this .type = updateStore(progressCallbackLoc, callback)
678693 def setPrinterFn (printer : Context => Printer ): this .type = updateStore(printerFnLoc, printer)
679694 def setSettings (settingsState : SettingsState ): this .type = updateStore(settingsStateLoc, settingsState)
680695 def setRun (run : Run | Null ): this .type = updateStore(runLoc, run)
0 commit comments