Skip to content

Commit 174849d

Browse files
committed
Use unique names to print empty capture set variables
1 parent 3196676 commit 174849d

34 files changed

+133
-110
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import CCState.*
2020
import TypeOps.AvoidMap
2121
import compiletime.uninitialized
2222
import Capabilities.*
23+
import Names.Name
24+
import NameKinds.CapsetName
2325

2426
/** A class for capture sets. Capture sets can be constants or variables.
2527
* Capture sets support inclusion constraints <:< where <:< is subcapturing.
@@ -738,6 +740,17 @@ object CaptureSet:
738740

739741
var description: String = ""
740742

743+
private var myRepr: Name | Null = null
744+
745+
/** A represtentation of this capture set as a unique name. We print
746+
* empty capture set variables in this representation. Bimapped sets have
747+
* the representation of their source set.
748+
*/
749+
def repr(using Context): Name = {
750+
if (myRepr == null) myRepr = CapsetName.fresh()
751+
myRepr.nn
752+
}
753+
741754
/** Check that all maps recorded in skippedMaps map `elem` to itself
742755
* or something subsumed by it.
743756
*/
@@ -1028,6 +1041,7 @@ object CaptureSet:
10281041
override def isMaybeSet: Boolean = bimap.isInstanceOf[MaybeMap]
10291042
override def toString = s"BiMapped$id($source, elems = $elems)"
10301043
override def summarize = bimap.getClass.toString
1044+
override def repr(using Context): Name = source.repr
10311045
end BiMapped
10321046

10331047
/** A variable with elements given at any time as { x <- source.elems | p(x) } */

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ object NameKinds {
328328
val ExceptionBinderName: UniqueNameKind = new UniqueNameKind("ex")
329329
val ExistentialBinderName: UniqueNameKind = new UniqueNameKind("ex$")
330330
val SkolemName: UniqueNameKind = new UniqueNameKind("?")
331+
val CapsetName: UniqueNameKind = new UniqueNameKind("'s")
331332
val SuperArgName: UniqueNameKind = new UniqueNameKind("$superArg$")
332333
val DocArtifactName: UniqueNameKind = new UniqueNameKind("$doc")
333334
val UniqueInlineName: UniqueNameKind = new UniqueNameKind("$i")

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,11 @@ class PlainPrinter(_ctx: Context) extends Printer {
173173
else if cs == CaptureSet.Fluid then "<fluid>"
174174
else
175175
val core: Text =
176-
if !cs.isConst && cs.elems.isEmpty then "?"
177-
else "{" ~ Text(cs.processElems(_.toList.map(toTextCapability)), ", ") ~ "}"
176+
if !cs.isConst && cs.elems.isEmpty then cs.asVar.repr.show
177+
else
178+
Str("'").provided(ccVerbose && !cs.isConst)
179+
~ "{" ~ Text(cs.processElems(_.toList.map(toTextCapability)), ", ") ~ "}"
178180
~ Str(".reader").provided(ccVerbose && cs.mutability == Mutability.Reader)
179-
~ Str("?").provided(ccVerbose && !cs.isConst)
180181
~ Str(s"#${cs.asVar.id}").provided(showUniqueIds && !cs.isConst)
181182
core ~ cs.optionalInfo
182183

tests/neg-custom-args/captures/box-adapt-cases.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/box-adapt-cases.scala:29:10 ------------------------------
1010
29 | x.value(cap => cap.use()) // error
1111
| ^^^^^^^^^^^^^^^^
12-
| Found: (cap: Cap^?) ->{io, fs} Int
12+
| Found: (cap: Cap^'s1) ->{io, fs} Int
1313
| Required: Cap^{io, fs} ->{io} Int
1414
| Note that capability fs is not included in capture set {io}.
1515
|

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/byname.scala:19:5 ----------------------------------------
1919
19 | h(g()) // error
2020
| ^^^
21-
| Found: () ?->{cap2} I^?
21+
| Found: () ?->{cap2} I^'s1
2222
| Required: () ?->{cap1} I
2323
| Note that capability cap2 is not included in capture set {cap1}.
2424
|
2525
| longer explanation available when compiling with `-explain`
2626
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/byname.scala:22:5 ----------------------------------------
2727
22 | h2(() => g())() // error
2828
| ^^^^^^^^^
29-
| Found: () ->{cap2} I^?
29+
| Found: () ->{cap2} I^'s2
3030
| Required: () ->{cap1} I
3131
| Note that capability cap2 is not included in capture set {cap1}.
3232
|

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/capt1.scala:8:2 ------------------------------------------
1010
8 | () => if x == null then y else y // error
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
| Found: () ->{x} C^?
12+
| Found: () ->{x} C^'s1
1313
| Required: Matchable
1414
| Note that capability x is not included in capture set {}.
1515
|
@@ -52,7 +52,7 @@
5252
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/capt1.scala:36:24 ----------------------------------------
5353
36 | val z2 = h[() -> Cap](() => x) // error // error
5454
| ^^^^^^^
55-
|Found: () ->? C^
55+
|Found: () ->'s2 C^
5656
|Required: () -> C^²
5757
|
5858
|where: ^ refers to a root capability associated with the result type of (): C^
@@ -65,7 +65,7 @@
6565
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/capt1.scala:37:5 -----------------------------------------
6666
37 | (() => C()) // error
6767
| ^^^^^^^^^
68-
|Found: () ->? C^
68+
|Found: () ->'s3 C^
6969
|Required: () -> C^²
7070
|
7171
|where: ^ refers to a root capability associated with the result type of (): C^

tests/neg-custom-args/captures/depfun-reach.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/depfun-reach.scala:12:27 ---------------------------------
22
12 | List(() => op.foreach((f,g) => { f(); g() })) // error (???)
33
| ^^^^^^^^^^^^^^^^^^^^
4-
|Found: (x$1: (() ->? Unit, () ->? Unit)^?) ->? Unit
4+
|Found: (x$1: (() ->'s1 Unit, () ->'s2 Unit)^'s3) ->'s4 Unit
55
|Required: ((() ->{op*} Unit, () ->{op*} Unit)) => Unit
66
|
77
|where: => refers to a fresh root capability created in anonymous function of type (): Unit when checking argument to parameter op of method foreach

tests/neg-custom-args/captures/effect-swaps-explicit.check

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
63 | Result:
33
64 | Future: // error, type mismatch
44
| ^
5-
| Found: Result.Ok[Future[T^?]^{fr, contextual$1}]
5+
| Found: Result.Ok[Future[T^'s1]^{fr, contextual$1}]
66
| Required: Result[Future[T], Nothing]
77
| Note that capability fr is not included in capture set {}.
88
65 | fr.await.ok
@@ -18,20 +18,20 @@
1818
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/effect-swaps-explicit.scala:69:10 ------------------------
1919
69 | Future: fut ?=> // error, type mismatch
2020
| ^
21-
|Found: (contextual$9: boundary.Label[Result[Future[T^?]^?, E^?]^?]^?) ?->{fr, async} Future[T^?]^{fr, contextual$9}
22-
|Required: (boundary.Label[Result[Future[T^?]^?, E^?]]^) ?=> Future[T^?]^?
21+
|Found: (contextual$9: boundary.Label[Result[Future[T^'s2]^'s3, E^'s4]^'s5]^'s6) ?->{fr, async} Future[T^'s7]^{fr, contextual$9}
22+
|Required: (boundary.Label[Result[Future[T^'s8]^'s9, E^'s10]]^) ?=> Future[T^'s8]^'s9
2323
|
2424
|where: ?=> refers to a fresh root capability created in method fail4 when checking argument to parameter body of method make
2525
| ^ refers to the universal root capability
2626
|
27-
|Note that capability contextual$9 cannot be included in outer capture set ?.
27+
|Note that capability contextual$9 cannot be included in outer capture set 's9.
2828
70 | fr.await.ok
2929
|
3030
| longer explanation available when compiling with `-explain`
3131
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/effect-swaps-explicit.scala:73:35 ------------------------
3232
73 | Result.make[Future[T], E]: lbl ?=> // error: type mismatch
3333
| ^
34-
|Found: (lbl: boundary.Label[Result[Future[T^?]^?, E^?]^?]^?) ?->{fr, async} Future[T^?]^{fr, lbl}
34+
|Found: (lbl: boundary.Label[Result[Future[T^'s11]^'s12, E^'s13]^'s14]^'s15) ?->{fr, async} Future[T^'s16]^{fr, lbl}
3535
|Required: (boundary.Label[Result[Future[T], E]]^) ?=> Future[T]
3636
|
3737
|where: ?=> refers to a fresh root capability created in method fail5 when checking argument to parameter body of method make

tests/neg-custom-args/captures/effect-swaps.check

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
63 | Result:
33
64 | Future: // error, type mismatch
44
| ^
5-
| Found: Result.Ok[Future[T^?]^{fr, contextual$1}]
5+
| Found: Result.Ok[Future[T^'s1]^{fr, contextual$1}]
66
| Required: Result[Future[T], Nothing]
77
| Note that capability fr is not included in capture set {}.
88
65 | fr.await.ok
@@ -18,20 +18,20 @@
1818
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/effect-swaps.scala:69:10 ---------------------------------
1919
69 | Future: fut ?=> // error, type mismatch
2020
| ^
21-
|Found: (contextual$9: boundary.Label[Result[Future[T^?]^?, E^?]^?]^?) ?->{fr, async} Future[T^?]^{fr, contextual$9}
22-
|Required: (boundary.Label[Result[Future[T^?]^?, E^?]]^) ?=> Future[T^?]^?
21+
|Found: (contextual$9: boundary.Label[Result[Future[T^'s2]^'s3, E^'s4]^'s5]^'s6) ?->{fr, async} Future[T^'s7]^{fr, contextual$9}
22+
|Required: (boundary.Label[Result[Future[T^'s8]^'s9, E^'s10]]^) ?=> Future[T^'s8]^'s9
2323
|
2424
|where: ?=> refers to a fresh root capability created in method fail4 when checking argument to parameter body of method make
2525
| ^ refers to the universal root capability
2626
|
27-
|Note that capability contextual$9 cannot be included in outer capture set ?.
27+
|Note that capability contextual$9 cannot be included in outer capture set 's9.
2828
70 | fr.await.ok
2929
|
3030
| longer explanation available when compiling with `-explain`
3131
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/effect-swaps.scala:73:35 ---------------------------------
3232
73 | Result.make[Future[T], E]: lbl ?=> // error: type mismatch
3333
| ^
34-
|Found: (lbl: boundary.Label[Result[Future[T^?]^?, E^?]^?]^?) ?->{fr, async} Future[T^?]^{fr, lbl}
34+
|Found: (lbl: boundary.Label[Result[Future[T^'s11]^'s12, E^'s13]^'s14]^'s15) ?->{fr, async} Future[T^'s16]^{fr, lbl}
3535
|Required: (boundary.Label[Result[Future[T], E]]^) ?=> Future[T]
3636
|
3737
|where: ?=> refers to a fresh root capability created in method fail5 when checking argument to parameter body of method make

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/filevar.scala:15:12 --------------------------------------
22
15 | withFile: f => // error with level checking, was OK under both schemes before
33
| ^
4-
|Found: (f: File^?) ->? Unit
4+
|Found: (f: File^'s1) ->'s2 Unit
55
|Required: (f: File^{l}) => Unit
66
|
77
|where: => refers to a fresh root capability created in anonymous function of type (using l²: scala.caps.Capability): File^{l²} -> Unit when instantiating expected result type (f: File^{l}) ->{cap} Unit of function literal
88
|
9-
|Note that capability l cannot be included in outer capture set ? of parameter f.
9+
|Note that capability l cannot be included in outer capture set 's1 of parameter f.
1010
16 | val o = Service()
1111
17 | o.file = f
1212
18 | o.log

0 commit comments

Comments
 (0)