Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
strip nested capturing types before box adaptation
  • Loading branch information
Linyxus committed Sep 28, 2022
commit 43ca7c6db5b0292f8e375595393aedc217ab872d
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/cc/CaptureOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
17 changes: 11 additions & 6 deletions compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down