Skip to content

Commit ff2edf6

Browse files
committed
Disentangle VAR improvement and reach improvement
Make reach improvement also dependent on migthSubCapture
1 parent 9e6c50f commit ff2edf6

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,12 @@ extension (tp: Type)
401401
if variance <= 0 then t
402402
else t.dealias match
403403
case t @ CapturingType(p, cs) if cs.containsCapOrFresh =>
404-
change = true
405404
val reachRef = if cs.isReadOnly then ref.reach.readOnly else ref.reach
406-
t.derivedCapturingType(apply(p), reachRef.singletonCaptureSet)
405+
if reachRef.singletonCaptureSet.mightSubcapture(cs) then
406+
change = true
407+
t.derivedCapturingType(apply(p), reachRef.singletonCaptureSet)
408+
else
409+
t
407410
case t @ AnnotatedType(parent, ann) =>
408411
// Don't map annotations, which includes capture sets
409412
t.derivedAnnotatedType(this(parent), ann)

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,11 +1550,9 @@ class CheckCaptures extends Recheck, SymTransformer:
15501550
private def improveCaptures(widened: Type, prefix: Type)(using Context): Type = prefix match
15511551
case ref: Capability if ref.isTracked =>
15521552
widened match
1553-
case widened @ CapturingType(p, refs) if ref.singletonCaptureSet.mightSubcapture(refs) =>
1554-
val improvedCs =
1555-
if widened.isBoxed then ref.reach.singletonCaptureSet
1556-
else ref.singletonCaptureSet
1557-
widened.derivedCapturingType(p, improvedCs)
1553+
case widened @ CapturingType(p, refs)
1554+
if ref.singletonCaptureSet.mightSubcapture(refs) && !widened.isBoxed =>
1555+
widened.derivedCapturingType(p, ref.singletonCaptureSet)
15581556
.showing(i"improve $widened to $result", capt)
15591557
case _ => widened
15601558
case _ => widened
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/reaches2.scala:10:8 --------------------------------------
1+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/reaches2.scala:10:10 -------------------------------------
22
10 | ps.map((x, y) => compose1(x, y)) // error
3-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4-
| Found: List[A^? ->{ps*, cap, cap²} A^?]
5-
| Required: List[A ->{ps*} A]
6-
|
7-
| where: cap is a fresh root capability created in method mapCompose when computing deep capture set of A
8-
| cap² is a fresh root capability created in method mapCompose when computing deep capture set of A
9-
|
10-
| Note that capability cap is not included in capture set {ps*}.
3+
| ^^^^^^^^^^^^^^^^^^^^^^^
4+
| Found: (x$1: (A^? ->{ps*} A^?, A^? ->{ps*} A^?)^?) ->{ps*} A^? ->{ps*} A^?
5+
| Required: ((A ->{ps*} A, A ->{ps*} A)) -> A^? ->? A^?
6+
| Note that capability ps* is not included in capture set {}.
117
|
128
| longer explanation available when compiling with `-explain`
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
-- Error: tests/neg-custom-args/captures/sep-box.scala:41:9 ------------------------------------------------------------
22
41 | par(h1.value, h2.value) // error
33
| ^^^^^^^^
4-
|Separation failure: argument of type Ref^{h1.value*}
4+
|Separation failure: argument of type Ref^{xs*}
55
|to method par: (x: Ref^, y: Ref^): Unit
66
|corresponds to capture-polymorphic formal parameter x of type Ref^
7-
|and hides capabilities {h1.value*}.
8-
|Some of these overlap with the captures of the second argument with type Ref^{h2.value*}.
7+
|and hides capabilities {xs*}.
8+
|Some of these overlap with the captures of the second argument with type Ref^{xs*}.
99
|
10-
| Hidden set of current argument : {h1.value*}
11-
| Hidden footprint of current argument : {h1.value*, xs*}
12-
| Capture set of second argument : {h2.value*}
13-
| Footprint set of second argument : {h2.value*, xs*}
10+
| Hidden set of current argument : {xs*}
11+
| Hidden footprint of current argument : {xs*}
12+
| Capture set of second argument : {xs*}
13+
| Footprint set of second argument : {xs*}
1414
| The two sets overlap at : {xs*}
1515
|
1616
|where: ^ refers to a fresh root capability classified as Mutable created in method test when checking argument to parameter x of method par

0 commit comments

Comments
 (0)