@@ -20,7 +20,6 @@ import Flags._
2020import scala .annotation .{nowarn ,tailrec }
2121import Variance ._
2222import scala .collection .mutable .ListBuffer
23- import scala .util .chaining ._
2423
2524private [internal]trait TypeMaps {
2625self :SymbolTable =>
@@ -665,24 +664,27 @@ private[internal] trait TypeMaps {
665664 }
666665
667666/** 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
671670
672671private [this ]var fromHasTermSymbol = false
673672private [this ]var fromMin = Int .MaxValue
674673private [this ]var fromMax = Int .MinValue
675674private [this ]var fromSize = 0
676675
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
679680
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 = {
681683// OPT this check was 2-3% of some profiles, demoted to -Xdev
682684if (isDeveloper) assert(sameLength(from, to)," Unsound substitution from" + from+ " to" + to)
683685
684- _from = from0
685- _to = to0
686+ from = from0
687+ to = to0
686688
687689 fromHasTermSymbol= false
688690 fromMin= Int .MaxValue
@@ -783,7 +785,11 @@ private[internal] trait TypeMaps {
783785 }
784786
785787/** 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
787793
788794protected def toType (fromTpe :Type ,sym :Symbol )= fromTpematch {
789795case TypeRef (pre, _, args)=> copyTypeRef(fromTpe, pre, sym, args)
@@ -845,19 +851,14 @@ private[internal] trait TypeMaps {
845851
846852object SubstSymMap {
847853def 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)
856856 }
857857
858858/** 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
861862
862863override protected def toType (fromtp :Type ,tp :Type )= tp
863864