Skip to content

Commit ad9d8f9

Browse files
committed
Fuse CapturingTypes
1 parent f73a73a commit ad9d8f9

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

compiler/src/dotty/tools/dotc/cc/CapturingType.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ object CapturingType:
1212

1313
def apply(parent: Type, refs: CaptureSet, boxed: Boolean = false)(using Context): Type =
1414
if refs.isAlwaysEmpty then parent
15-
else AnnotatedType(parent, CaptureAnnotation(refs, boxed)(defn.RetainsAnnot))
15+
else parent match
16+
case parent @ CapturingType(parent1, refs1) if boxed || !parent.isBoxed =>
17+
apply(parent1, refs ++ refs1, boxed)
18+
case _ =>
19+
AnnotatedType(parent, CaptureAnnotation(refs, boxed)(defn.RetainsAnnot))
1620

1721
def unapply(tp: AnnotatedType)(using Context): Option[(Type, CaptureSet)] =
1822
if ctx.phase == Phases.checkCapturesPhase && tp.annot.symbol == defn.RetainsAnnot then

compiler/src/dotty/tools/dotc/cc/Setup.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extends tpd.TreeTraverser:
2828

2929
private def box(tp: Type)(using Context): Type = tp.dealias match
3030
case tp @ CapturingType(parent, refs) if !tp.isBoxed =>
31-
CapturingType(parent, refs, boxed = true)
31+
tp.boxed
3232
case tp1 @ AppliedType(tycon, args) if defn.isNonRefinedFunction(tp1) =>
3333
val res = args.last
3434
val boxedRes = box(res)

compiler/src/dotty/tools/dotc/typer/CheckCaptures.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ class CheckCaptures extends Recheck, SymTransformer:
531531
case _ =>
532532
expected
533533
val normActual = adaptBoxed(actual, expected1, tree.srcPos)
534-
//println(i"check conforms $actual1 <<< $expected1")
534+
//println(i"check conforms $normActual <<< $expected1")
535535
super.checkConformsExpr(normActual, expected1, tree)
536536

537537
/** Adapt `actual` type to `expected` type by inserting boxing and unboxing conversions */

tests/neg-custom-args/captures/try.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def handle[E <: Exception, R <: Top](op: CanThrow[E] => R)(handler: E => R): R =
1919
catch case ex: E => handler(ex)
2020

2121
def test =
22-
val a = handle[Exception, CanThrow[Exception]] { // error !!! was for 2nd arg
22+
val a = handle[Exception, CanThrow[Exception]] { // error
2323
(x: CanThrow[Exception]) => x
2424
}{
2525
(ex: Exception) => ???

tests/pos-custom-args/captures/lazylists-mono.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ def test(E: Cap) =
2424
if xs.isEmpty then LazyNil
2525
else
2626
val cons = () => (f(xs.head), xs.tail.map(f))
27-
new LazyCons(cons.asInstanceOf) // !!!
27+
LazyCons(cons)

tests/run-custom-args/captures/colltest5/Test_2.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,9 @@ object Test {
7878
val x5 = xs.to(List)
7979
val y5: {x5} List[Int] = x5
8080
val (xs6, xs7) = xs.partition(isEven)
81-
.asInstanceOf[({xs, isEven} View[Int], {xs, isEven} View[Int])]
82-
// !!! fails deep subtyping test without the cast
8381
val ys6: {xs6, isEven} View[Int] = xs6
8482
val ys7: {xs7, isEven} View[Int] = xs7
8583
val (xs6a, xs7a) = xs.partition(_ % 2 == 0)
86-
.asInstanceOf[({xs} View[Int], {xs} View[Int])]
87-
// !!! fails deep subtyping test without the cast
8884
val ys6a: {xs6} View[Int] = xs6
8985
val ys7a: {xs7} View[Int] = xs7
9086
val xs8 = xs.drop(2)

0 commit comments

Comments
 (0)