@@ -745,64 +745,55 @@ object Contexts {
745
745
override def addBound (sym : Symbol , bound : Type , isUpper : Boolean )(implicit ctx : Context ): Boolean = try {
746
746
boundCache = SimpleIdentityMap .Empty
747
747
boundAdditionInProgress = true
748
- @ annotation.tailrec def stripInst (tp : Type ): Type = tp match {
748
+ @ annotation.tailrec def stripInternalTypeVar (tp : Type ): Type = tp match {
749
749
case tv : TypeVar =>
750
750
val inst = instType(tv)
751
- if (inst.exists) stripInst (inst) else tv
751
+ if (inst.exists) stripInternalTypeVar (inst) else tv
752
752
case _ => tp
753
753
}
754
754
755
- def cautiousSubtype (tp1 : Type , tp2 : Type , isSubtype : Boolean ): Boolean = {
755
+ def externalizedSubtype (tp1 : Type , tp2 : Type , isSubtype : Boolean ): Boolean = {
756
756
val externalizedTp1 = removeTypeVars(tp1)
757
757
val externalizedTp2 = removeTypeVars(tp2)
758
758
759
- def descr = {
760
- def op = s " frozen_ ${if (isSubtype) " <:<" else " >:>" }"
761
- i " $tp1 $op $tp2\n\t $externalizedTp1 $op $externalizedTp2"
762
- }
763
- // gadts.println(descr)
764
-
765
- val res =
766
- // TypeComparer.explain[Boolean](gadts.println) { implicit ctx =>
759
+ (
767
760
if (isSubtype) externalizedTp1 frozen_<:< externalizedTp2
768
761
else externalizedTp2 frozen_<:< externalizedTp1
769
- // }
770
-
771
- gadts.println( i " $descr = $res" )
772
- res
762
+ ).reporting({ res =>
763
+ val descr = i " $externalizedTp1 frozen_ ${ if (isSubtype) " <:< " else " >:> " } $externalizedTp2 "
764
+ i " $descr = $res"
765
+ }, gadts)
773
766
}
774
767
775
- def unify (tv : TypeVar , tp : Type ): Unit = {
776
- gadts.println(i " manually unifying $tv with $tp" )
777
- constraint = constraint.updateEntry(tv.origin, tp)
778
- }
779
-
780
- val symTvar : TypeVar = stripInst(tvar(sym)) match {
768
+ val symTvar : TypeVar = stripInternalTypeVar(tvar(sym)) match {
781
769
case tv : TypeVar => tv
782
770
case inst =>
783
- gadts.println( i " instantiated: $sym -> $ inst" )
784
- // this is wrong in general, but "correct" due to a subtype check in TypeComparer#narrowGadtBounds
785
- return true
771
+ val externalizedInst = removeTypeVars( inst)
772
+ gadts.println( i " instantiated: $sym -> $externalizedInst " )
773
+ return if (isUpper) isSubType(externalizedInst , bound) else isSubType(bound, externalizedInst)
786
774
}
787
775
788
776
val internalizedBound = insertTypeVars(bound)
789
- val res = stripInst(internalizedBound) match {
790
- case boundTvar : TypeVar =>
791
- if (boundTvar eq symTvar) true
792
- else if (isUpper) addLess(symTvar.origin, boundTvar.origin)
793
- else addLess(boundTvar.origin, symTvar.origin)
794
- case bound =>
795
- if (cautiousSubtype(symTvar, bound, isSubtype = ! isUpper)) { unify(symTvar, bound); true }
796
- else if (isUpper) addUpperBound(symTvar.origin, bound)
797
- else addLowerBound(symTvar.origin, bound)
798
- }
799
-
800
- gadts.println {
777
+ (
778
+ stripInternalTypeVar(internalizedBound) match {
779
+ case boundTvar : TypeVar =>
780
+ if (boundTvar eq symTvar) true
781
+ else if (isUpper) addLess(symTvar.origin, boundTvar.origin)
782
+ else addLess(boundTvar.origin, symTvar.origin)
783
+ case bound =>
784
+ if (externalizedSubtype(symTvar, bound, isSubtype = ! isUpper)) {
785
+ gadts.println(i " manually unifying $symTvar with $bound" )
786
+ constraint = constraint.updateEntry(symTvar.origin, bound)
787
+ true
788
+ }
789
+ else if (isUpper) addUpperBound(symTvar.origin, bound)
790
+ else addLowerBound(symTvar.origin, bound)
791
+ }
792
+ ).reporting({ res =>
801
793
val descr = if (isUpper) " upper" else " lower"
802
794
val op = if (isUpper) " <:" else " >:"
803
795
i " adding $descr bound $sym $op $bound = $res\t ( $symTvar $op $internalizedBound ) "
804
- }
805
- res
796
+ }, gadts)
806
797
} finally boundAdditionInProgress = false
807
798
808
799
override def bounds (sym : Symbol )(implicit ctx : Context ): TypeBounds = {
@@ -813,7 +804,7 @@ object Contexts {
813
804
val tb = constraint.fullBounds(tv.origin)
814
805
removeTypeVars(tb).asInstanceOf [TypeBounds ]
815
806
}
816
- val res =
807
+ (
817
808
if (boundAdditionInProgress || ctx.mode.is(Mode .GADTflexible )) retrieveBounds
818
809
else boundCache(sym) match {
819
810
case tb : TypeBounds => tb
@@ -822,8 +813,10 @@ object Contexts {
822
813
boundCache = boundCache.updated(sym, bounds)
823
814
bounds
824
815
}
825
- // gadts.println(i"gadt bounds $sym: $res")
826
- res
816
+ ).reporting({ res =>
817
+ // i"gadt bounds $sym: $res"
818
+ " "
819
+ }, gadts)
827
820
}
828
821
}
829
822
0 commit comments