Skip to content

Commit 4e04b19

Browse files
committed
Don't flag local fresh capabilities as errors in markFree
1 parent c658e3c commit 4e04b19

File tree

18 files changed

+56
-73
lines changed

18 files changed

+56
-73
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,15 @@ class CheckCaptures extends Recheck, SymTransformer:
486486
// The path-use.scala neg test contains an example.
487487
val underlying = CaptureSet.ofTypeDeeply(c1.widen)
488488
capt.println(i"Widen reach $c to $underlying in ${env.owner}")
489-
underlying.disallowRootCapability: () =>
490-
report.error(em"Local reach capability $c leaks into capture scope of ${env.ownerString}", tree.srcPos)
491-
recur(underlying, env, null)
489+
if ccConfig.useSepChecks then
490+
recur(underlying.filter(!_.isMaxCapability), env, null)
491+
// we don't want to disallow underlying Fresh.Cap, since these are typically locally created
492+
// fresh capabilities. We don't need to also follow the hidden set since separation
493+
// checking makes ure that locally hidden references need to go to @consume parameters.
494+
else
495+
underlying.disallowRootCapability: () =>
496+
report.error(em"Local reach capability $c leaks into capture scope of ${env.ownerString}", tree.srcPos)
497+
recur(underlying, env, null)
492498
case c: TypeRef if c.isParamPath =>
493499
checkUseDeclared(c, env, null)
494500
case _ =>

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
| ^^^^
44
| reference ops* is not included in the allowed capture set {}
55
| of an enclosing function literal with expected type () -> Unit
6-
-- Error: tests/neg-custom-args/captures/delayedRunops.scala:23:13 -----------------------------------------------------
7-
23 | runOps(ops1) // error
8-
| ^^^^
9-
| Local reach capability ops1* leaks into capture scope of enclosing function
106
-- Error: tests/neg-custom-args/captures/delayedRunops.scala:29:13 -----------------------------------------------------
117
29 | runOps(ops1) // error
128
| ^^^^

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import caps.{use, consume}
2020
def delayedRunOps2(@consume ops: List[() => Unit]): () ->{} Unit =
2121
() =>
2222
val ops1: List[() => Unit] = ops // error
23-
runOps(ops1) // error
23+
runOps(ops1) // was error
2424

2525
// unsound: impure operation pretended pure
2626
def delayedRunOps3(ops: List[() => Unit]): () ->{} Unit =

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,3 @@
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^
2424
|Type variable X of value leaked cannot be instantiated to Boxed[box IO^] -> (ex$20: caps.Exists) -> Boxed[box IO^{ex$20}] since
2525
|the part box IO^{ex$20} of that type captures the root capability `cap`.
26-
-- Error: tests/neg-custom-args/captures/i21401.scala:18:21 ------------------------------------------------------------
27-
18 | val y: IO^{x*} = x.unbox // error
28-
| ^^^^^^^
29-
| Local reach capability x* leaks into capture scope of method test2

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ def test2() =
1515
val a = usingIO[IO^](x => x) // error
1616
val leaked: [R, X <: Boxed[IO^] -> R] -> (op: X) -> R = usingIO[Res](mkRes) // error
1717
val x: Boxed[IO^] = leaked[Boxed[IO^], Boxed[IO^] -> Boxed[IO^]](x => x) // error // error
18-
val y: IO^{x*} = x.unbox // error
18+
val y: IO^{x*} = x.unbox // was error
1919
y.println("boom")

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
| ^^^^^^^
44
| Local reach capability x* leaks into capture scope of method foo.
55
| To allow this, the parameter x should be declared with a @use annotation
6-
-- Error: tests/neg-custom-args/captures/i21442.scala:18:14 ------------------------------------------------------------
7-
18 | val io = x1.unbox // error
8-
| ^^^^^^^^
9-
| Local reach capability x1* leaks into capture scope of method bar
106
-- Error: tests/neg-custom-args/captures/i21442.scala:17:10 ------------------------------------------------------------
117
17 | val x1: Boxed[IO^] = x // error
128
| ^^^^^^^^^^

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ def foo(x: Boxed[IO^]): Unit =
1515
// But, no type error reported.
1616
def bar(x: Boxed[IO^]): Unit =
1717
val x1: Boxed[IO^] = x // error
18-
val io = x1.unbox // error
18+
val io = x1.unbox // was error
1919
io.use()

tests/neg-custom-args/captures/leak-problem.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test(): Unit =
2525
def useBoxedAsync1(@use x: Box[Async^]): Unit = x.get.read()
2626

2727
val xs: Box[Async^] = ???
28-
val xsLambda = () => useBoxedAsync(xs) // error
28+
val xsLambda = () => useBoxedAsync(xs) // was error now ok
2929
val _: () ->{xs*} Unit = xsLambda
3030
val _: () -> Unit = xsLambda // error
3131

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

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/neg-custom-args/captures/path-use.scala

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)