@@ -59,14 +59,11 @@ sealed abstract class GadtConstraint extends Showable {
59
59
/** Further constrain a path-dependent type already present in the constraint. */
60
60
def addBound (p : PathType , sym : Symbol , bound : Type , isUpper : Boolean )(using Context ): Boolean
61
61
62
- /** Record the equality between two singleton types. */
63
- def addEquality (p : PathType , q : PathType )(using Context ): Unit
62
+ /** Record the aliasing relationship between two singleton types. */
63
+ def recordPathAliasing (p : PathType , q : PathType )(using Context ): Unit
64
64
65
- /** Check whether two singleton types are equivalent. */
66
- def isEquivalent (p : PathType , q : PathType ): Boolean
67
-
68
- /** Query the representative member of a singleton type. */
69
- def reprOf (p : PathType ): PathType | Null
65
+ /** Check whether two paths are equivalent via path aliasing. */
66
+ def isAliasingPath (p : PathType , q : PathType ): Boolean
70
67
71
68
/** Scrutinee path of the current pattern matching. */
72
69
def scrutineePath : TermRef | Null
@@ -124,7 +121,7 @@ final class ProperGadtConstraint private(
124
121
private var pathDepReverseMapping : SimpleIdentityMap [TypeParamRef , TypeRef ],
125
122
private var wasConstrained : Boolean ,
126
123
private var myScrutineePath : TermRef | Null ,
127
- private var myUnionFind : SimpleIdentityMap [PathType , PathType ],
124
+ private var pathAliasingMap : SimpleIdentityMap [PathType , PathType ],
128
125
private var myPatternSkolem : SkolemType | Null ,
129
126
) extends GadtConstraint with ConstraintHandling {
130
127
import dotty .tools .dotc .config .Printers .{gadts , gadtsConstr }
@@ -137,7 +134,7 @@ final class ProperGadtConstraint private(
137
134
pathDepReverseMapping = SimpleIdentityMap .empty,
138
135
wasConstrained = false ,
139
136
myScrutineePath = null ,
140
- myUnionFind = SimpleIdentityMap .empty,
137
+ pathAliasingMap = SimpleIdentityMap .empty,
141
138
myPatternSkolem = null ,
142
139
)
143
140
@@ -392,9 +389,6 @@ final class ProperGadtConstraint private(
392
389
buf ++= " }"
393
390
buf.result
394
391
395
- /** Get the representative member of the path in the union find. */
396
- override def reprOf (p : PathType ): PathType | Null = lookupPath(p)
397
-
398
392
override def addToConstraint (params : List [Symbol ])(using Context ): Boolean = {
399
393
import NameKinds .DepParamName
400
394
@@ -512,15 +506,15 @@ final class ProperGadtConstraint private(
512
506
}
513
507
514
508
private def lookupPath (p : PathType ): PathType | Null =
515
- def recur (p : PathType ): PathType | Null = myUnionFind (p) match
509
+ def recur (p : PathType ): PathType | Null = pathAliasingMap (p) match
516
510
case null => null
517
511
case q : PathType if q eq p => q
518
512
case q : PathType =>
519
513
recur(q)
520
514
521
515
recur(p)
522
516
523
- override def addEquality (p : PathType , q : PathType )(using Context ): Unit =
517
+ override def recordPathAliasing (p : PathType , q : PathType )(using Context ): Unit =
524
518
val pRep : PathType | Null = lookupPath(p)
525
519
val qRep : PathType | Null = lookupPath(q)
526
520
@@ -529,13 +523,13 @@ final class ProperGadtConstraint private(
529
523
case (null , r : PathType ) => r
530
524
case (r : PathType , null ) => r
531
525
case (r1 : PathType , r2 : PathType ) =>
532
- myUnionFind = myUnionFind .updated(r2, r1)
526
+ pathAliasingMap = pathAliasingMap .updated(r2, r1)
533
527
r1
534
528
535
- myUnionFind = myUnionFind .updated(p, newRep)
536
- myUnionFind = myUnionFind .updated(q, newRep)
529
+ pathAliasingMap = pathAliasingMap .updated(p, newRep)
530
+ pathAliasingMap = pathAliasingMap .updated(q, newRep)
537
531
538
- override def isEquivalent (p : PathType , q : PathType ): Boolean =
532
+ override def isAliasingPath (p : PathType , q : PathType ): Boolean =
539
533
lookupPath(p) match
540
534
case null => false
541
535
case p0 : PathType => lookupPath(q) match
@@ -637,7 +631,7 @@ final class ProperGadtConstraint private(
637
631
pathDepReverseMapping,
638
632
wasConstrained,
639
633
myScrutineePath,
640
- myUnionFind ,
634
+ pathAliasingMap ,
641
635
myPatternSkolem,
642
636
)
643
637
@@ -650,7 +644,7 @@ final class ProperGadtConstraint private(
650
644
this .pathDepReverseMapping = other.pathDepReverseMapping
651
645
this .wasConstrained = other.wasConstrained
652
646
this .myScrutineePath = other.myScrutineePath
653
- this .myUnionFind = other.myUnionFind
647
+ this .pathAliasingMap = other.pathAliasingMap
654
648
this .myPatternSkolem = other.myPatternSkolem
655
649
case _ => ;
656
650
}
@@ -675,10 +669,10 @@ final class ProperGadtConstraint private(
675
669
}
676
670
677
671
def updateUnionFind () =
678
- myUnionFind (myPatternSkolem.nn) match {
672
+ pathAliasingMap (myPatternSkolem.nn) match {
679
673
case null =>
680
674
case repr : PathType =>
681
- myUnionFind = myUnionFind .updated(path, repr)
675
+ pathAliasingMap = pathAliasingMap .updated(path, repr)
682
676
}
683
677
684
678
updateMappings()
@@ -784,7 +778,7 @@ final class ProperGadtConstraint private(
784
778
}
785
779
}
786
780
sb ++= " \n Singleton equalities:\n "
787
- myUnionFind foreachBinding { case (path, _) =>
781
+ pathAliasingMap foreachBinding { case (path, _) =>
788
782
val repr = lookupPath(path)
789
783
repr match
790
784
case repr : PathType if repr ne path =>
@@ -805,8 +799,6 @@ final class ProperGadtConstraint private(
805
799
override def bounds (tp : TypeRef )(using Context ): TypeBounds | Null = null
806
800
override def fullBounds (tp : TypeRef )(using Context ): TypeBounds | Null = null
807
801
808
- override def reprOf (p : PathType ): PathType | Null = null
809
-
810
802
override def isLess (sym1 : Symbol , sym2 : Symbol )(using Context ): Boolean = unsupported(" EmptyGadtConstraint.isLess" )
811
803
override def isLess (tp1 : NamedType , tp2 : NamedType )(using Context ): Boolean = unsupported(" EmptyGadtConstraint.isLess" )
812
804
@@ -827,9 +819,9 @@ final class ProperGadtConstraint private(
827
819
override def addBound (sym : Symbol , bound : Type , isUpper : Boolean )(using Context ): Boolean = unsupported(" EmptyGadtConstraint.addBound" )
828
820
override def addBound (path : PathType , sym : Symbol , bound : Type , isUpper : Boolean )(using Context ): Boolean = unsupported(" EmptyGadtConstraint.addBound" )
829
821
830
- override def addEquality (p : PathType , q : PathType )(using Context ) = ()
822
+ override def recordPathAliasing (p : PathType , q : PathType )(using Context ) = ()
831
823
832
- override def isEquivalent (p : PathType , q : PathType ) = false
824
+ override def isAliasingPath (p : PathType , q : PathType ) = false
833
825
834
826
override def approximation (sym : Symbol , fromBelow : Boolean , maxLevel : Int )(using Context ): Type = unsupported(" EmptyGadtConstraint.approximation" )
835
827
0 commit comments