Skip to content

Commit

Permalink
strip nested capturing types before box adaptation
Browse files Browse the repository at this point in the history
  • Loading branch information
Linyxus committed Sep 28, 2022
1 parent f2bc25e commit 43ca7c6
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/cc/CaptureOps.scala
Original file line number Diff line number Diff line change
@@ -121,6 +121,11 @@ extension (tp: Type)
case _ =>
tp

def isCapturingType(using Context): Boolean =
tp match
case CapturingType(_, _) => true
case _ => false

extension (sym: Symbol)

/** Does this symbol allow results carrying the universal capability?
17 changes: 11 additions & 6 deletions compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
@@ -623,15 +623,19 @@ class CheckCaptures extends Recheck, SymTransformer:
i"adapting $actual $arrow $expected"

def adapt(actual: Type, expected: Type, covariant: Boolean): Type = trace(adaptInfo(actual, expected, covariant), recheckr, show = true) {
val actualTp = actual match
case actual @ CapturingType(parent, cs) =>
(parent, cs, actual.isBoxed)
def destructCapturingType(tp: Type, reconstruct: Type => Type): ((Type, CaptureSet, Boolean), Type => Type) = tp match
case tp @ CapturingType(parent, cs) =>
if parent.isCapturingType then
destructCapturingType(parent, res => reconstruct(tp.derivedCapturingType(res, cs)))
else
((parent, cs, tp.isBoxed), reconstruct)
case actual =>
(actual, CaptureSet(), false)
((actual, CaptureSet(), false), reconstruct)

val (actualTp, recon) = destructCapturingType(actual, x => x)
val (parent1, cs1, isBoxed1) = adaptCapturingType(actualTp, expected, covariant)

CapturingType(parent1, cs1, isBoxed1)
recon(CapturingType(parent1, cs1, isBoxed1))
}

def adaptCapturingType(actual: (Type, CaptureSet, Boolean),
@@ -652,7 +656,8 @@ class CheckCaptures extends Recheck, SymTransformer:
(aargs1, ares1) =>
rinfo.derivedLambdaType(paramInfos = aargs1, resType = ares1)
.toFunctionType(isJava = false, alwaysDependent = true))
case _ => (parent, cs)
case _ =>
(parent, cs)
}

if needsAdaptation then

0 comments on commit 43ca7c6

Please sign in to comment.