Skip to content

Commit 1e79a2d

Browse files
committed
Don't show redudundant existental wrappers
Don't show an `(ex$n: Exists) ->` if the bound variable does not appear in the result. The full type will be shown under -Ycc-debug. Also, avoid spurious ineffective mappings in widenReach.
1 parent b9d485a commit 1e79a2d

File tree

9 files changed

+23
-16
lines changed

9 files changed

+23
-16
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,12 @@ extension (tp: Type)
476476
*/
477477
def withReachCaptures(ref: Type)(using Context): Type =
478478
object narrowCaps extends TypeMap:
479+
var change = false
479480
def apply(t: Type) =
480481
if variance <= 0 then t
481482
else t.dealiasKeepAnnots match
482483
case t @ CapturingType(p, cs) if cs.isUniversal =>
484+
change = true
483485
t.derivedCapturingType(apply(p), ref.reach.singletonCaptureSet)
484486
case t @ AnnotatedType(parent, ann) =>
485487
// Don't map annotations, which includes capture sets
@@ -498,8 +500,11 @@ extension (tp: Type)
498500
ref match
499501
case ref: CaptureRef if ref.isTrackableRef =>
500502
val tp1 = narrowCaps(tp)
501-
if tp1 ne tp then capt.println(i"narrow $tp of $ref to $tp1")
502-
tp1
503+
if narrowCaps.change then
504+
capt.println(i"narrow $tp of $ref to $tp1")
505+
tp1
506+
else
507+
tp
503508
case _ =>
504509
tp
505510

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import config.SourceVersion.*
3030

3131
import dotty.tools.dotc.util.SourcePosition
3232
import dotty.tools.dotc.ast.untpd.{MemberDef, Modifiers, PackageDef, RefTree, Template, TypeDef, ValOrDefDef}
33-
import cc.{CaptureSet, CapturingType, toCaptureSet, IllegalCaptureRef, isRetains, ReachCapability, MaybeCapability}
33+
import cc.{CaptureSet, CapturingType, toCaptureSet, IllegalCaptureRef, isRetains, ReachCapability, MaybeCapability, Existential}
3434
import dotty.tools.dotc.parsing.JavaParsers
3535

3636
class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
@@ -285,6 +285,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
285285
if !printDebug && appliedText(tp.asInstanceOf[HKLambda].resType).isEmpty =>
286286
// don't eta contract if the application would be printed specially
287287
toText(tycon)
288+
case Existential(boundVar, unpacked)
289+
if !printDebug && !ctx.settings.YccDebug.value && !unpacked.existsPart(_ == boundVar) =>
290+
toText(unpacked)
288291
case tp: RefinedType if defn.isFunctionType(tp) && !printDebug =>
289292
toTextMethodAsFunction(tp.refinedInfo,
290293
isPure = Feature.pureFunsEnabled && !tp.typeSymbol.name.isImpureFunction,

scala2-library-cc/src/scala/collection/SeqView.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package collection
1616
import scala.annotation.nowarn
1717
import language.experimental.captureChecking
1818
import caps.unsafe.unsafeAssumePure
19-
import scala.annotation.unchecked.uncheckedCaptures
2019

2120
/** !!! Scala 2 difference: Need intermediate trait SeqViewOps to collect the
2221
* necessary functionality over which SeqViews are defined, and at the same

tests/neg-custom-args/captures/i21620.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i21620.scala:9:31 ----------------------------------------
1414
9 | val _: () -> () ->{x} Unit = f // error
1515
| ^
16-
| Found: () ->{f} () ->{x} Unit
16+
| Found: (f : () ->{x} () ->{x} Unit)
1717
| Required: () -> () ->{x} Unit
1818
|
1919
| longer explanation available when compiling with `-explain`
2020
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i21620.scala:20:33 ---------------------------------------
2121
20 | val _: () ->{} () ->{x} Unit = f // error, but could be OK
2222
| ^
23-
| Found: () ->{f} () ->{x} Unit
23+
| Found: (f : () ->{x} () ->{x} Unit)
2424
| Required: () -> () ->{x} Unit
2525
|
2626
| longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/lazylist.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazylist.scala:35:29 -------------------------------------
99
35 | val ref1c: LazyList[Int] = ref1 // error
1010
| ^^^^
11-
| Found: lazylists.LazyCons[Int]{val xs: () ->{cap1} lazylists.LazyList[Int]^?}^{ref1}
12-
| Required: lazylists.LazyList[Int]
11+
| Found: (ref1 : lazylists.LazyCons[Int]{val xs: () ->{cap1} lazylists.LazyList[Int]^?}^{cap1})
12+
| Required: lazylists.LazyList[Int]
1313
|
1414
| longer explanation available when compiling with `-explain`
1515
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazylist.scala:37:36 -------------------------------------
@@ -29,7 +29,7 @@
2929
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazylist.scala:41:42 -------------------------------------
3030
41 | val ref4c: LazyList[Int]^{cap1, ref3} = ref4 // error
3131
| ^^^^
32-
| Found: (ref4 : lazylists.LazyList[Int]^{cap3, ref2, ref1})
32+
| Found: (ref4 : lazylists.LazyList[Int]^{cap3, cap2, ref1, cap1})
3333
| Required: lazylists.LazyList[Int]^{cap1, ref3}
3434
|
3535
| longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/reaches2.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
8 | ps.map((x, y) => compose1(x, y)) // error // error
33
| ^
44
|reference ps* is not included in the allowed capture set {}
5-
|of an enclosing function literal with expected type ((box A ->{ps*} A, box A ->{ps*} A)) -> box (x$0: A^?) ->? (ex$15: caps.Exists) -> A^?
5+
|of an enclosing function literal with expected type ((box A ->{ps*} A, box A ->{ps*} A)) -> box (x$0: A^?) ->? A^?
66
-- Error: tests/neg-custom-args/captures/reaches2.scala:8:13 -----------------------------------------------------------
77
8 | ps.map((x, y) => compose1(x, y)) // error // error
88
| ^
99
|reference ps* is not included in the allowed capture set {}
10-
|of an enclosing function literal with expected type ((box A ->{ps*} A, box A ->{ps*} A)) -> box (x$0: A^?) ->? (ex$15: caps.Exists) -> A^?
10+
|of an enclosing function literal with expected type ((box A ->{ps*} A, box A ->{ps*} A)) -> box (x$0: A^?) ->? A^?

tests/neg-custom-args/captures/real-try.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
-- Error: tests/neg-custom-args/captures/real-try.scala:26:10 ----------------------------------------------------------
2828
26 | val y = try // error
2929
| ^
30-
| The result of `try` cannot have type () => (ex$8: caps.Exists) -> Cell[Unit]^? since
30+
| The result of `try` cannot have type () => Cell[Unit]^? since
3131
| that type captures the root capability `cap`.
3232
| This is often caused by a locally generated exception capability leaking as part of its result.
3333
27 | () => Cell(foo(1))

tests/neg-custom-args/captures/use-capset.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/use-capset.scala:15:50 -----------------------------------
1414
15 | val _: () -> List[Object^{io}] -> Object^{io} = h2 // error, should be ->{io}
1515
| ^^
16-
| Found: () ->? (x$0: List[box Object^{io}]^{}) ->{io} (ex$13: caps.Exists) -> Object^{io}
17-
| Required: () -> List[box Object^{io}] -> Object^{io}
16+
| Found: (h2 : () ->? (x$0: List[box Object^{io}]^{}) ->{io} Object^{io})
17+
| Required: () -> List[box Object^{io}] -> Object^{io}
1818
|
1919
| longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/uses.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/uses.scala:18:34 -----------------------------------------
1616
18 | val _: () ->{x} () ->{y} Unit = g // error, should be ok
1717
| ^
18-
| Found: () ->{x, y} (ex$7: caps.Exists) -> () ->{y} Unit
18+
| Found: () ->{x, y} () ->{y} Unit
1919
| Required: () ->{x} () ->{y} Unit
2020
|
2121
| longer explanation available when compiling with `-explain`
2222
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/uses.scala:19:28 -----------------------------------------
2323
19 | val _: () -> () -> Unit = g // error
2424
| ^
25-
| Found: () ->{x, y} (ex$7: caps.Exists) -> () ->{y} Unit
25+
| Found: () ->{x, y} () ->{y} Unit
2626
| Required: () -> () -> Unit
2727
|
2828
| longer explanation available when compiling with `-explain`

0 commit comments

Comments
 (0)