@@ -172,17 +172,6 @@ object Contexts {
172
172
protected def searchHistory_= (searchHistory : SearchHistory ): Unit = _searchHistory = searchHistory
173
173
final def searchHistory : SearchHistory = _searchHistory
174
174
175
- /** The current type comparer. This ones updates itself automatically for
176
- * each new context.
177
- */
178
- private var _typeComparer : TypeComparer = _
179
- protected def typeComparer_= (typeComparer : TypeComparer ): Unit = _typeComparer = typeComparer
180
- def typeComparer : TypeComparer = {
181
- if (_typeComparer.comparerCtx ne this )
182
- _typeComparer = _typeComparer.copyIn(this )
183
- _typeComparer
184
- }
185
-
186
175
/** The current source file */
187
176
private var _source : SourceFile = _
188
177
protected def source_= (source : SourceFile ): Unit = _source = source
@@ -479,7 +468,6 @@ object Contexts {
479
468
_typeAssigner = origin.typeAssigner
480
469
_gadt = origin.gadt
481
470
_searchHistory = origin.searchHistory
482
- _typeComparer = origin.typeComparer
483
471
_source = origin.source
484
472
_moreProperties = origin.moreProperties
485
473
_store = origin.store
@@ -610,7 +598,6 @@ object Contexts {
610
598
util.Stats .record(" Context.setSource" )
611
599
this .source = source
612
600
this
613
- def setTypeComparerFn (tcfn : Context => TypeComparer ): this .type = { this .typeComparer = tcfn(this ); this }
614
601
private def setMoreProperties (moreProperties : Map [Key [Any ], Any ]): this .type =
615
602
util.Stats .record(" Context.setMoreProperties" )
616
603
this .moreProperties = moreProperties
@@ -699,26 +686,57 @@ object Contexts {
699
686
val base = ctx.base
700
687
import base ._
701
688
val nestedCtx =
702
- if testsInUse < testContexts .size then
703
- testContexts(testsInUse ).reuseIn(ctx)
689
+ if exploresInUse < exploreContexts .size then
690
+ exploreContexts(exploresInUse ).reuseIn(ctx)
704
691
else
705
692
val ts = TyperState ()
706
693
.setReporter(ExploringReporter ())
707
694
.setCommittable(false )
708
695
val c = FreshContext (ctx.base).init(ctx, ctx).setTyperState(ts)
709
- testContexts += c
696
+ exploreContexts += c
710
697
c
711
- testsInUse += 1
698
+ exploresInUse += 1
712
699
val nestedTS = nestedCtx.typerState
713
700
nestedTS.init(ctx.typerState, ctx.typerState.constraint)
714
701
val result =
715
702
try op(using nestedCtx)
716
703
finally
717
704
nestedTS.reporter.asInstanceOf [ExploringReporter ].reset()
718
- testsInUse -= 1
705
+ exploresInUse -= 1
719
706
result
720
707
end explore
721
708
709
+ /** The type comparer of the kind created by `maker` to be used.
710
+ * This is the currently active type comparer CMP if
711
+ * - CMP is associated with the current context, and
712
+ * - CMP is of the kind created by maker or maker creates a plain type comparer.
713
+ * Note: plain TypeComparers always take on the kind of the outer comparer if they are in the same context.
714
+ * In other words: tracking or explaining is a sticky property in the same context.
715
+ */
716
+ private def comparer (using Context ): TypeComparer =
717
+ val base = ctx.base
718
+ if base.comparersInUse > 0
719
+ && (base.comparers(base.comparersInUse - 1 ).comparerContext eq ctx)
720
+ then
721
+ base.comparers(base.comparersInUse - 1 ).currentInstance
722
+ else
723
+ val result =
724
+ if base.comparersInUse < base.comparers.size then
725
+ base.comparers(base.comparersInUse)
726
+ else
727
+ val result = TypeComparer (ctx)
728
+ base.comparers += result
729
+ result
730
+ base.comparersInUse += 1
731
+ result.init(ctx)
732
+ result
733
+
734
+ def comparing [T ](op : TypeComparer => T )(using Context ): T =
735
+ val saved = ctx.base.comparersInUse
736
+ try op(comparer)
737
+ finally ctx.base.comparersInUse = saved
738
+ end comparing
739
+
722
740
/** A class defining the initial context with given context base
723
741
* and set of possible settings.
724
742
*/
@@ -735,7 +753,6 @@ object Contexts {
735
753
store = initialStore
736
754
.updated(settingsStateLoc, settingsGroup.defaultState)
737
755
.updated(notNullInfosLoc, Nil )
738
- typeComparer = new TypeComparer (using this )
739
756
searchHistory = new SearchRoot
740
757
gadt = EmptyGadtConstraint
741
758
}
@@ -871,14 +888,18 @@ object Contexts {
871
888
872
889
protected [dotc] val indentTab : String = " "
873
890
874
- private [dotc] val testContexts = new mutable.ArrayBuffer [FreshContext ]
875
- private [dotc] var testsInUse : Int = 0
891
+ private [Contexts ] val exploreContexts = new mutable.ArrayBuffer [FreshContext ]
892
+ private [Contexts ] var exploresInUse : Int = 0
893
+
894
+ private [Contexts ] val comparers = new mutable.ArrayBuffer [TypeComparer ]
895
+ private [Contexts ] var comparersInUse : Int = 0
876
896
877
897
def reset (): Unit = {
878
898
for ((_, set) <- uniqueSets) set.clear()
879
899
errorTypeMsg.clear()
880
900
sources.clear()
881
901
sourceNamed.clear()
902
+ comparers.clear() // forces re-evaluation of top and bottom classes in TypeComparer
882
903
}
883
904
884
905
// Test that access is single threaded
0 commit comments