Skip to content

Commit 473fe77

Browse files
committed
Add method to track parameter dependency status
1 parent 48bd96d commit 473fe77

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,7 +2331,7 @@ object Types {
23312331
def apply(tp: Type) = tp match {
23322332
case tp @ TypeRef(pre, name) =>
23332333
tp.info match {
2334-
case TypeAlias(alias) if depStatus(pre) == TrueDeps => apply(alias)
2334+
case TypeAlias(alias) if depStatus(NoDeps, pre) == TrueDeps => apply(alias)
23352335
case _ => mapOver(tp)
23362336
}
23372337
case _ =>
@@ -2343,8 +2343,9 @@ object Types {
23432343
else resType
23442344

23452345
var myDependencyStatus: DependencyStatus = Unknown
2346+
var myParamDependencyStatus: DependencyStatus = Unknown
23462347

2347-
private def depStatus(tp: Type)(implicit ctx: Context): DependencyStatus = {
2348+
private def depStatus(initial: DependencyStatus, tp: Type)(implicit ctx: Context): DependencyStatus = {
23482349
def combine(x: DependencyStatus, y: DependencyStatus) = {
23492350
val status = (x & StatusMask) max (y & StatusMask)
23502351
val provisional = (x | y) & Provisional
@@ -2368,7 +2369,7 @@ object Types {
23682369
case _ => foldOver(status, tp)
23692370
}
23702371
}
2371-
depStatusAcc(NoDeps, tp)
2372+
depStatusAcc(initial, tp)
23722373
}
23732374

23742375
/** The dependency status of this method. Some examples:
@@ -2382,17 +2383,36 @@ object Types {
23822383
private def dependencyStatus(implicit ctx: Context): DependencyStatus = {
23832384
if (myDependencyStatus != Unknown) myDependencyStatus
23842385
else {
2385-
val result = depStatus(resType)
2386+
val result = depStatus(NoDeps, resType)
23862387
if ((result & Provisional) == 0) myDependencyStatus = result
23872388
(result & StatusMask).toByte
23882389
}
23892390
}
23902391

2392+
/** The parameter dependency status of this method. Analogous to `dependencyStatus`,
2393+
* but tracking dependencies in same parameter list.
2394+
*/
2395+
private def paramDependencyStatus(implicit ctx: Context): DependencyStatus = {
2396+
if (myParamDependencyStatus != Unknown) myParamDependencyStatus
2397+
else {
2398+
val result =
2399+
if (paramTypes.isEmpty) NoDeps
2400+
else (NoDeps /: paramTypes.tail)(depStatus(_, _))
2401+
if ((result & Provisional) == 0) myParamDependencyStatus = result
2402+
(result & StatusMask).toByte
2403+
}
2404+
}
2405+
23912406
/** Does result type contain references to parameters of this method type,
23922407
* which cannot be eliminated by de-aliasing?
23932408
*/
23942409
def isDependent(implicit ctx: Context): Boolean = dependencyStatus == TrueDeps
23952410

2411+
/** Does one of the parameter types contain references to earlier parameters
2412+
* of this method type which cannot be eliminated by de-aliasing?
2413+
*/
2414+
def isParamDependent(implicit ctx: Context): Boolean = paramDependencyStatus == TrueDeps
2415+
23962416
protected def computeSignature(implicit ctx: Context): Signature =
23972417
resultSignature.prepend(paramTypes, isJava)
23982418

0 commit comments

Comments
 (0)