forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop special handling in recheckApplication
In recheckApplication we implemented a rule that computed the capture set of an application `f(a)` by being the "better" of either the capture set of `f` union capture set of `a` or the capture set of the result type of `f(a)`. This relies on capture monotinicity, which we try to get away from. Also, it's semantically dubious if the type of the argument `a` is a type variable that can be instantiated to a capturing type as in the following example: ```scala trait Iterator[+A] ... def flatMap[B](f: A => IterableOnce[B]^): Iterator[B]^{this, f} ``` Here, we account for every capability in `IterableOnce[B]^` already in `f`. But those capabilities could also come from `A` if `A` is instantiated in the actual function argument to a capturing type. There was extensive breakage once the special handling was dropped. One example is the `flatMap` definition above. We leave that as a potential soundness hold for now, but the right way to fix `flatMap` would be by adding a capture set variable: ```scala def flatMap[B, C^](f: A => IterableOnce[B]^{C^}): Iterator[B]^{this, f, C^} ``` The problem is that this currently cannot be done in a way that allows flatMap to be called as before, passing a single type argument for `B`. We'd have to change the system to either allow curried type parameters or optional type parameters for capture sets. Another issue is that now more reach capabilities are registered as used by the enclosing method. An example is lazylist-exceptions.scala, which has been moved to pending. Here, the use is spurious because it happens inside an anonymous class creation on the right hand side of the method. With refined use checking, the use would not propagate to the method, so the reach capability should not be leaking. But to get there we need to implement refined use checking first.
- Loading branch information
Showing
23 changed files
with
90 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import language.experimental.captureChecking | ||
import caps.Capability | ||
|
||
trait File extends Capability | ||
|
||
class Resource[T <: Capability](gen: T): | ||
def use[U](f: T => U): U = | ||
f(gen) // error | ||
|
||
@main def run = | ||
val myFile: File = ??? | ||
val r = Resource(myFile) // error | ||
() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class C | ||
def test(x: C^, y: C^) = | ||
class D { | ||
println(x) | ||
def foo() = println(y) | ||
} | ||
val d = D() | ||
val _: D^{y} = d // error, should be ok | ||
val _: D = d // error | ||
|
||
val f = () => println(D()) | ||
val _: () ->{x} Unit = f // ok | ||
val _: () -> Unit = f // should be error | ||
|
||
def g = () => | ||
println(x) | ||
() => println(y) | ||
val _: () ->{x} () ->{y} Unit = g // error, should be ok | ||
val _: () -> () -> Unit = g // error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
-- [E007] Type Mismatch Error: tests/neg/i19470.scala:9:12 ------------------------------------------------------------- | ||
9 | List(foo(f())) // error | ||
| ^^^^^^^^ | ||
| Found: Inv[box IO^{f?}] | ||
| Found: Inv[box IO^{f*?}] | ||
| Required: box Inv[box IO^?]^? | ||
| | ||
| longer explanation available when compiling with `-explain` |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
...-args/captures/lazylists-exceptions.scala → ...margs/captures/lazylists-exceptions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// Needs better use handling | ||
import language.experimental.saferExceptions | ||
|
||
trait LazyList[+A]: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters