@@ -23,7 +23,7 @@ import config.Config
23
23
import reporting ._
24
24
import io .{AbstractFile , NoAbstractFile , PlainFile , Path }
25
25
import scala .io .Codec
26
- import collection .mutable
26
+ import collection .mutable , mutable . ArrayBuffer
27
27
import printing ._
28
28
import config .{JavaPlatform , SJSPlatform , Platform , ScalaSettings }
29
29
import classfile .ReusableDataReader
@@ -52,8 +52,10 @@ object Contexts {
52
52
private val (notNullInfosLoc, store8) = store7.newLocation[List [NotNullInfo ]]()
53
53
private val (importInfoLoc, store9) = store8.newLocation[ImportInfo | Null ]()
54
54
private val (typeAssignerLoc, store10) = store9.newLocation[TypeAssigner ](TypeAssigner )
55
+ private val (usagesLoc, store11) = store10.newLocation[Any ]() // unusages feature
56
+ private val (deferredChecksLoc, store12) = store11.newLocation[DeferredChecks ]()
55
57
56
- private val initialStore = store10
58
+ private val initialStore = store12
57
59
58
60
/** The current context */
59
61
inline def ctx (using ctx : Context ): Context = ctx
@@ -93,6 +95,9 @@ object Contexts {
93
95
inline def atPhaseNoEarlier [T ](limit : Phase )(inline op : Context ?=> T )(using Context ): T =
94
96
op(using if ! limit.exists || limit <= ctx.phase then ctx else ctx.withPhase(limit))
95
97
98
+ inline def deferredCheck (phase : String )(inline op : Context ?=> Unit )(using Context ): Unit =
99
+ ctx.deferredChecks.add(phase)(op)
100
+
96
101
inline def inMode [T ](mode : Mode )(inline op : Context ?=> T )(using ctx : Context ): T =
97
102
op(using if mode != ctx.mode then ctx.fresh.setMode(mode) else ctx)
98
103
@@ -239,6 +244,8 @@ object Contexts {
239
244
/** The current type assigner or typer */
240
245
def typeAssigner : TypeAssigner = store(typeAssignerLoc)
241
246
247
+ def deferredChecks : DeferredChecks = store(deferredChecksLoc)
248
+
242
249
/** The new implicit references that are introduced by this scope */
243
250
protected var implicitsCache : ContextualImplicits | Null = null
244
251
def implicits : ContextualImplicits = {
@@ -812,6 +819,7 @@ object Contexts {
812
819
store = initialStore
813
820
.updated(settingsStateLoc, settingsGroup.defaultState)
814
821
.updated(notNullInfosLoc, Nil )
822
+ .updated(deferredChecksLoc, DeferredChecks ())
815
823
.updated(compilationUnitLoc, NoCompilationUnit )
816
824
searchHistory = new SearchRoot
817
825
gadt = EmptyGadtConstraint
@@ -954,13 +962,13 @@ object Contexts {
954
962
955
963
protected [dotc] val indentTab : String = " "
956
964
957
- private [Contexts ] val exploreContexts = new mutable. ArrayBuffer [FreshContext ]
965
+ private [Contexts ] val exploreContexts = ArrayBuffer .empty [FreshContext ]
958
966
private [Contexts ] var exploresInUse : Int = 0
959
967
960
- private [Contexts ] val changeOwnerContexts = new mutable. ArrayBuffer [FreshContext ]
968
+ private [Contexts ] val changeOwnerContexts = ArrayBuffer .empty [FreshContext ]
961
969
private [Contexts ] var changeOwnersInUse : Int = 0
962
970
963
- private [Contexts ] val comparers = new mutable. ArrayBuffer [TypeComparer ]
971
+ private [Contexts ] val comparers = ArrayBuffer .empty [TypeComparer ]
964
972
private [Contexts ] var comparersInUse : Int = 0
965
973
966
974
private var charArray = new Array [Char ](256 )
@@ -996,4 +1004,15 @@ object Contexts {
996
1004
if (thread == null ) thread = Thread .currentThread()
997
1005
else assert(thread == Thread .currentThread(), " illegal multithreaded access to ContextBase" )
998
1006
}
1007
+
1008
+ class DeferredChecks :
1009
+ private val checks = mutable.Map [String , ArrayBuffer [Context ?=> Unit ]]()
1010
+
1011
+ def add (phase : String )(item : Context ?=> Unit ): Unit = checks.getOrElseUpdate(phase, ArrayBuffer .empty).addOne(item)
1012
+
1013
+ def run (phase : String )(using Context ): Unit =
1014
+ for items <- checks.remove(phase) do
1015
+ for item <- items do
1016
+ item
1017
+ end DeferredChecks
999
1018
}
0 commit comments