Skip to content

Commit 0e79219

Browse files
author
Aleksander Boruch-Gruszecki
committed
Clean up comments and remove useless code
1 parent 8f796f2 commit 0e79219

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

compiler/src/dotty/tools/dotc/core/Contexts.scala

+11-18
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ object Contexts {
746746

747747
private[this] var checkInProgress = false
748748

749-
// TODO: dirty kludge - should this class be an inner class of TyperState instead?
749+
// TODO: clean up this dirty kludge
750750
private[this] var myCtx: Context = null
751751
implicit override def ctx = myCtx
752752
@forceInline private[this] final def inCtx[T](_ctx: Context)(op: => T) = {
@@ -769,8 +769,8 @@ object Contexts {
769769
val res = {
770770
import NameKinds.DepParamName
771771
// avoid registering the TypeVar with TyperState / TyperState#constraint
772-
// TyperState TypeVars get instantiated when we don't want them to (see pos/i3500.scala)
773-
// TyperState#constraint TypeVars can be narrowed in subtype checks - don't want that either
772+
// - we don't want TyperState instantiating these TypeVars
773+
// - we don't want TypeComparer constraining these TypeVars
774774
val poly = PolyType(DepParamName.fresh(sym.name.toTypeName) :: Nil)(
775775
pt => TypeBounds.empty :: Nil,
776776
pt => defn.AnyType)
@@ -796,27 +796,22 @@ object Contexts {
796796
case _ => tp
797797
}
798798

799-
def cautiousSubtype(tp1: Type, tp2: Type, isSubtype: Boolean, allowNarrowing: Boolean = false): Boolean = {
799+
def cautiousSubtype(tp1: Type, tp2: Type, isSubtype: Boolean): Boolean = {
800800
val externalizedTp1 = (new TypeVarRemovingMap)(tp1)
801801
val externalizedTp2 = (new TypeVarRemovingMap)(tp2)
802802

803803
def descr = {
804804
def op = s"frozen_${if (isSubtype) "<:<" else ">:>"}"
805-
def flex = s"GADTFlexible=$allowNarrowing"
806-
i"$tp1 $op $tp2\n\t$externalizedTp1 $op $externalizedTp2 ($flex)"
805+
i"$tp1 $op $tp2\n\t$externalizedTp1 $op $externalizedTp2"
807806
}
808807
// gadts.println(descr)
809808

810-
val outerCtx = ctx
811-
val res = {
812-
// implicit val ctx : Context =
813-
// if (allowNarrowing) outerCtx else outerCtx.fresh.retractMode(Mode.GADTflexible)
814-
809+
val res =
815810
// TypeComparer.explain[Boolean](gadts.println) { implicit ctx =>
816-
if (isSubtype) externalizedTp1 frozen_<:< externalizedTp2
811+
if (isSubtype) externalizedTp1 frozen_<:< externalizedTp2
817812
else externalizedTp2 frozen_<:< externalizedTp1
818813
// }
819-
}
814+
820815
gadts.println(i"$descr = $res")
821816
res
822817
}
@@ -825,8 +820,8 @@ object Contexts {
825820
case tv: TypeVar => tv
826821
case inst =>
827822
gadts.println(i"instantiated: $sym -> $inst")
828-
// return true
829-
return cautiousSubtype(inst, bound, isSubtype = isUpper, allowNarrowing = true)
823+
// this is wrong in general, but "correct" due to a subtype check in TypeComparer#narrowGadtBounds
824+
return true
830825
}
831826

832827
def doAddBound(bound: Type): Boolean = {
@@ -873,7 +868,6 @@ object Contexts {
873868
(new TypeVarRemovingMap)(tb).asInstanceOf[TypeBounds]
874869
}
875870
val res =
876-
// retrieveBounds
877871
if (checkInProgress || ctx.mode.is(Mode.GADTflexible)) retrieveBounds
878872
else {
879873
if (dirtyFlag) {
@@ -882,8 +876,7 @@ object Contexts {
882876
boundCache = SimpleIdentityMap.Empty.updated(sym, bounds)
883877
bounds
884878
} else boundCache(sym) match {
885-
case tb: TypeBounds =>
886-
tb
879+
case tb: TypeBounds => tb
887880
case null =>
888881
val bounds = retrieveBounds
889882
boundCache = boundCache.updated(sym, bounds)

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

-2
Original file line numberDiff line numberDiff line change
@@ -1237,8 +1237,6 @@ class TypeComparer(initctx: Context) extends ConstraintHandling {
12371237
val newBounds =
12381238
if (isUpper) TypeBounds(oldBounds.lo, oldBounds.hi & bound)
12391239
else TypeBounds(oldBounds.lo | bound, oldBounds.hi)
1240-
// gadtMap can check its own satisfiability, but the subtype check is still necessary
1241-
// see tests/patmat/gadt-nontrivial2.scala
12421240
isSubType(newBounds.lo, newBounds.hi) &&
12431241
(if (isUpper) gadtAddUpperBound(tparam, bound) else gadtAddLowerBound(tparam, bound))
12441242
}

0 commit comments

Comments
 (0)