@@ -20,7 +20,6 @@ import Flags._
20
20
import scala .annotation .{nowarn , tailrec }
21
21
import Variance ._
22
22
import scala .collection .mutable .ListBuffer
23
- import scala .util .chaining ._
24
23
25
24
private [internal] trait TypeMaps {
26
25
self : SymbolTable =>
@@ -665,24 +664,27 @@ private[internal] trait TypeMaps {
665
664
}
666
665
667
666
/** A base class to compute all substitutions. */
668
- sealed abstract class SubstMap [T >: Null ] extends TypeMap {
669
- private [this ] var _from : List [Symbol ] = Nil
670
- private [this ] var _to : List [T ] = Nil
667
+ abstract class SubstMap [T >: Null ]( from0 : List [ Symbol ], to0 : List [ T ]) extends TypeMap {
668
+ private [this ] var from : List [Symbol ] = from0
669
+ private [this ] var to : List [T ] = to0
671
670
672
671
private [this ] var fromHasTermSymbol = false
673
672
private [this ] var fromMin = Int .MaxValue
674
673
private [this ] var fromMax = Int .MinValue
675
674
private [this ] var fromSize = 0
676
675
677
- final def from : List [Symbol ] = _from
678
- final def to : List [T ] = _to
676
+ // So SubstTypeMap can expose them publicly
677
+ // while SubstMap can continue to access them as private fields
678
+ protected [this ] final def accessFrom : List [Symbol ] = from
679
+ protected [this ] final def accessTo : List [T ] = to
679
680
680
- def reload (from0 : List [Symbol ], to0 : List [T ]): this .type = {
681
+ reset(from0, to0)
682
+ def reset (from0 : List [Symbol ], to0 : List [T ]): this .type = {
681
683
// OPT this check was 2-3% of some profiles, demoted to -Xdev
682
684
if (isDeveloper) assert(sameLength(from, to), " Unsound substitution from " + from + " to " + to)
683
685
684
- _from = from0
685
- _to = to0
686
+ from = from0
687
+ to = to0
686
688
687
689
fromHasTermSymbol = false
688
690
fromMin = Int .MaxValue
@@ -783,7 +785,11 @@ private[internal] trait TypeMaps {
783
785
}
784
786
785
787
/** A map to implement the `substSym` method. */
786
- sealed class SubstSymMap private () extends SubstMap [Symbol ] {
788
+ class SubstSymMap (from0 : List [Symbol ], to0 : List [Symbol ]) extends SubstMap [Symbol ](from0, to0) {
789
+ def this (pairs : (Symbol , Symbol )* ) = this (pairs.toList.map(_._1), pairs.toList.map(_._2))
790
+
791
+ private [this ] final def from : List [Symbol ] = accessFrom
792
+ private [this ] final def to : List [Symbol ] = accessTo
787
793
788
794
protected def toType (fromTpe : Type , sym : Symbol ) = fromTpe match {
789
795
case TypeRef (pre, _, args) => copyTypeRef(fromTpe, pre, sym, args)
@@ -845,19 +851,14 @@ private[internal] trait TypeMaps {
845
851
846
852
object SubstSymMap {
847
853
def apply (): SubstSymMap = new SubstSymMap ()
848
- def apply (from : List [Symbol ], to : List [Symbol ]): SubstSymMap = new SubstSymMap ().tap(_.reload(from, to))
849
- def apply (from : List [Symbol ], to : List [Symbol ], cmp : (Symbol , Symbol ) => Boolean ): SubstSymMap = {
850
- val ssm = new SubstSymMap () {
851
- override protected def matches (sym : Symbol , sym1 : Symbol ): Boolean = cmp(sym, sym1)
852
- }
853
- ssm.tap(_.reload(from, to))
854
- }
855
- def apply (fromto : (Symbol , Symbol )): SubstSymMap = apply(List (fromto._1), List (fromto._2))
854
+ def apply (from : List [Symbol ], to : List [Symbol ]): SubstSymMap = new SubstSymMap (from, to)
855
+ def apply (fromto : (Symbol , Symbol )): SubstSymMap = new SubstSymMap (fromto)
856
856
}
857
857
858
858
/** A map to implement the `subst` method. */
859
- class SubstTypeMap (from0 : List [Symbol ], to0 : List [Type ]) extends SubstMap [Type ] {
860
- super .reload(from0, to0)
859
+ class SubstTypeMap (from0 : List [Symbol ], to0 : List [Type ]) extends SubstMap [Type ](from0, to0) {
860
+ final def from : List [Symbol ] = accessFrom
861
+ final def to : List [Type ] = accessTo
861
862
862
863
override protected def toType (fromtp : Type , tp : Type ) = tp
863
864
0 commit comments