Skip to content

Commit 9d96159

Browse files
committed
Update doc comments
1 parent e97ebe0 commit 9d96159

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ abstract class Constraint extends Showable {
166166
*/
167167
def hasConflictingTypeVarsFor(tl: TypeLambda, that: Constraint): Boolean
168168

169-
/** A map that associates type variables with all other type variables that
170-
* refer to them in their bounds covariantly, such that, if the type variable
171-
* is isntantiated to a larger type, the constraint would be narrowed.
169+
/** A map that associates type parameters of this constraint with all other type
170+
* parameters that refer to them in their bounds covariantly, such that, if the
171+
* type parameter is instantiated to a larger type, the constraint would be narrowed.
172172
*/
173173
def coDeps: Constraint.ReverseDeps
174174

175-
/** A map that associates type variables with all other type variables that
176-
* refer to them in their bounds covariantly, such that, if the type variable
177-
* is isntantiated to a smaller type, the constraint would be narrowed.
175+
/** A map that associates type parameters of this constraint with all other type
176+
* parameters that refer to them in their bounds covariantly, such that, if the
177+
* type parameter is instantiated to a smaller type, the constraint would be narrowed.
178178
*/
179179
def contraDeps: Constraint.ReverseDeps
180180

@@ -209,7 +209,6 @@ abstract class Constraint extends Showable {
209209
object Constraint:
210210
type ReverseDeps = SimpleIdentityMap[TypeParamRef, SimpleIdentitySet[TypeParamRef]]
211211

212-
213212
/** When calling `Constraint#addLess(p1, p2, ...)`, the caller might end up
214213
* unifying one parameter with the other, this enum lets `addLess` know which
215214
* direction the unification will take.

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import config.Config
1111
import config.Printers.constr
1212
import reflect.ClassTag
1313
import Constraint.ReverseDeps
14-
import NameKinds.DepParamName
1514
import annotation.tailrec
1615
import annotation.internal.sharable
1716
import cc.{CapturingType, derivedCapturingType}
@@ -223,7 +222,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
223222
if tvar == null then NoType
224223
else tvar
225224

226-
// ------------- TypeVar dependencies -----------------------------------
225+
// ------------- Type parameter dependencies ----------------------------------------
227226

228227
var coDeps, contraDeps: ReverseDeps = SimpleIdentityMap.empty
229228

@@ -233,10 +232,11 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
233232
tv.origin
234233
val param = origin(tv)
235234
val excluded = except.map(origin)
235+
val qualifies: TypeParamRef => Boolean = !excluded.contains(_)
236236
def test(deps: ReverseDeps, lens: ConstraintLens[List[TypeParamRef]]) =
237237
val depending = deps(param)
238-
null != depending && depending.exists(!excluded.contains(_))
239-
|| lens(this, tv.origin.binder, tv.origin.paramNum).exists(!excluded.contains(_))
238+
null != depending && depending.exists(qualifies)
239+
|| lens(this, tv.origin.binder, tv.origin.paramNum).exists(qualifies)
240240
//.showing(i"outer depends on $tv with ${tvdeps.toList}%, % = $result")
241241
if co then test(coDeps, upperLens) else test(contraDeps, lowerLens)
242242

@@ -259,12 +259,12 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
259259
end Adjuster
260260

261261
/** Adjust dependencies to account for the delta of previous entry `prevEntry`
262-
* and new bound `entry` for the type variable `tvar`.
262+
* and new bound `entry` for the type parameter `srcParam`.
263263
*/
264264
def adjustDeps(entry: Type | Null, prevEntry: Type | Null, srcParam: TypeParamRef)(using Context): this.type =
265265
val adjuster = new Adjuster(srcParam)
266266

267-
/** Adjust reverse depemdencies of all type parameters referenced by `bound`
267+
/** Adjust reverse dependencies of all type parameters referenced by `bound`
268268
* @param isLower `bound` is a lower bound
269269
* @param add if true, add referenced variables to dependencoes, otherwise drop them.
270270
*/
@@ -316,8 +316,8 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
316316
this
317317
end adjustDeps
318318

319-
/** Adjust dependencies to account for adding or dropping `entries` to the
320-
* constraint.
319+
/** Adjust dependencies to account for adding or dropping all `entries` associated
320+
* with `poly`.
321321
* @param add if true, entries is added, otherwise it is dropped
322322
*/
323323
def adjustDeps(poly: TypeLambda, entries: Array[Type], add: Boolean)(using Context): this.type =
@@ -327,7 +327,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
327327
else adjustDeps(NoType, entries(n), poly.paramRefs(n))
328328
this
329329

330-
/** If `tp` is a type variable, remove all its reverse dependencies */
330+
/** Remove all reverse dependencies of `param` */
331331
def dropDeps(param: TypeParamRef)(using Context): Unit =
332332
coDeps = coDeps.remove(param)
333333
contraDeps = contraDeps.remove(param)
@@ -589,8 +589,11 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
589589

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

592-
def replaceParam(tp: Type, atPoly: TypeLambda, atIdx: Int): Type =
593-
current.ensureNonCyclic(atPoly.paramRefs(atIdx), tp.substParam(param, replacement))
592+
def replaceParam(entry: Type, atPoly: TypeLambda, atIdx: Int): Type =
593+
val pref = atPoly.paramRefs(atIdx)
594+
val newEntry = current.ensureNonCyclic(pref, entry.substParam(param, replacement))
595+
adjustDeps(newEntry, entry, pref)
596+
newEntry
594597

595598
current.foreachParam { (p, i) =>
596599
current = boundsLens.map(this, current, p, i,

0 commit comments

Comments
 (0)