Skip to content

Commit eed5803

Browse files
committed
Make substitution in replace constraint aware
1 parent 4a01bbd commit eed5803

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ object OrderingConstraint {
3838
}
3939

4040
/** The `current` constraint but with the entry for `param` updated to `entry`.
41-
* `current` is used linearly. If it is different from `prev` it is
41+
* `current` is used linearly. If it is different from `prev` then `current` is
4242
* known to be dead after the call. Hence it is OK to update destructively
4343
* parts of `current` which are not shared by `prev`.
4444
*/
@@ -134,6 +134,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
134134
private val lowerMap : ParamOrdering,
135135
private val upperMap : ParamOrdering,
136136
private val hardVars : TypeVars) extends Constraint {
137+
thisConstraint =>
137138

138139
import UnificationDirection.*
139140

@@ -244,7 +245,9 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
244245
//.showing(i"outer depends on $tv with ${tvdeps.toList}%, % = $result")
245246
if co then test(coDeps, upperLens) else test(contraDeps, lowerLens)
246247

247-
private class Adjuster(srcParam: TypeParamRef)(using Context) extends TypeTraverser:
248+
private class Adjuster(srcParam: TypeParamRef)(using Context)
249+
extends TypeTraverser, ConstraintAwareTraversal:
250+
248251
var add: Boolean = compiletime.uninitialized
249252
val seen = util.HashSet[LazyRef]()
250253

@@ -607,12 +610,6 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
607610

608611
def removeParam(ps: List[TypeParamRef]) = ps.filterConserve(param ne _)
609612

610-
def replaceParam(entry: Type, atPoly: TypeLambda, atIdx: Int): Type =
611-
val pref = atPoly.paramRefs(atIdx)
612-
val newEntry = current.ensureNonCyclic(pref, entry.substParam(param, replacement))
613-
adjustDeps(newEntry, entry, pref)
614-
newEntry
615-
616613
for lo <- lower(param) do
617614
current = upperLens.map(this, current, lo, removeParam)
618615
for hi <- upper(param) do

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5496,8 +5496,21 @@ object Types {
54965496
stop == StopAt.Static && tp.currentSymbol.isStatic && isStaticPrefix(tp.prefix)
54975497
|| stop == StopAt.Package && tp.currentSymbol.is(Package)
54985498
}
5499+
5500+
protected def tyconTypeParams(tp: AppliedType)(using Context): List[ParamInfo] =
5501+
tp.tyconTypeParams
54995502
end VariantTraversal
55005503

5504+
trait ConstraintAwareTraversal extends VariantTraversal:
5505+
override def tyconTypeParams(tp: AppliedType)(using Context): List[ParamInfo] =
5506+
tp.tycon match
5507+
case tycon: TypeParamRef =>
5508+
ctx.typerState.constraint.entry(tycon) match
5509+
case _: TypeBounds =>
5510+
case tp1 => if tp1.typeParams.nonEmpty then return tp1.typeParams
5511+
case _ =>
5512+
tp.tyconTypeParams
5513+
55015514
/** A supertrait for some typemaps that are bijections. Used for capture checking.
55025515
* BiTypeMaps should map capture references to capture references.
55035516
*/
@@ -5613,7 +5626,7 @@ object Types {
56135626
derivedSelect(tp, prefix1)
56145627

56155628
case tp: AppliedType =>
5616-
derivedAppliedType(tp, this(tp.tycon), mapArgs(tp.args, tp.tyconTypeParams))
5629+
derivedAppliedType(tp, this(tp.tycon), mapArgs(tp.args, tyconTypeParams(tp)))
56175630

56185631
case tp: LambdaType =>
56195632
mapOverLambda(tp)
@@ -5940,7 +5953,7 @@ object Types {
59405953
case nil =>
59415954
true
59425955
}
5943-
if (distributeArgs(args, tp.tyconTypeParams))
5956+
if (distributeArgs(args, tyconTypeParams(tp)))
59445957
range(tp.derivedAppliedType(tycon, loBuf.toList),
59455958
tp.derivedAppliedType(tycon, hiBuf.toList))
59465959
else if tycon.isLambdaSub || args.exists(isRangeOfNonTermTypes) then
@@ -6086,7 +6099,7 @@ object Types {
60866099
}
60876100
foldArgs(acc, tparams.tail, args.tail)
60886101
}
6089-
foldArgs(this(x, tycon), tp.tyconTypeParams, args)
6102+
foldArgs(this(x, tycon), tyconTypeParams(tp), args)
60906103

60916104
case _: BoundType | _: ThisType => x
60926105

0 commit comments

Comments
 (0)