Skip to content

Add capture checking to some standard library classes #18192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4beba0a
Add unsafeAssumePure method
odersky Jul 12, 2023
18a9d2c
Avoid spurious dealiasing in alignDependentFunction
odersky Jul 13, 2023
cf2b2c8
Handle capture checking language imports correctly for -Ytest-pickler
odersky Jul 13, 2023
6ff1774
Keep track which classes were compiled with capture checking
odersky Jul 13, 2023
58c3041
Better interop with non-capture checked files
odersky Jul 13, 2023
66670c2
Better interop with non-capture-checked files for override checking
odersky Jul 13, 2023
8f04d3a
Better interop for non-capture-checked file for bounds checking
odersky Jul 13, 2023
80943e4
Disable mapJavaArgs when rechecking Apply nodes
odersky Jul 13, 2023
df78771
Capture check first collection classes -- original state
odersky Jul 13, 2023
a882fe9
Capture checked versions of Iterator and IterableOnce
odersky Jul 13, 2023
c0bcfbe
Drop redundant statements
odersky Jul 13, 2023
714606c
Update MimaFilters
odersky Jul 13, 2023
08deac1
Fix rebase breakage
odersky Jul 13, 2023
9734a36
Fix more rebase breakage
odersky Jul 13, 2023
8140273
Test for #16415
odersky Jul 13, 2023
12735bd
Enable test that failed in #18168
odersky Jul 13, 2023
25104d1
Improve fluidify
odersky Jul 15, 2023
e104f8e
Exclude AnyVal from set of pure base classes
odersky Jul 15, 2023
1a30250
Make assigned types of inlined expressions InferredTypes
odersky Jul 16, 2023
6c949a9
Special treatment of types of function members
odersky Jul 16, 2023
cd1a7b2
Don't adapt function and by name types when unpickling
odersky Jul 16, 2023
9c4afd6
Avpid global side effects in unpickle tests
odersky Jul 16, 2023
af8124f
Move stdlib tests to pos
odersky Jul 16, 2023
46327f5
Add {mutable,immutable}.Iterable.scala to stdlib tests
odersky Jul 16, 2023
b23bf45
Add View.scala to stdlib test
odersky Jul 16, 2023
fc9bb75
Add collection/Seq to stdlib tests
odersky Jul 16, 2023
64e95b2
Also fluidify member when doing overriding checks
odersky Jul 17, 2023
fa71a56
Add subclasses IndexedSeq, LinearSeq, {mutable,immutable}.Seq to stdl…
odersky Jul 18, 2023
0230d03
Add StrictOptimized ops to stdlib tests
odersky Jul 18, 2023
5543104
Add List and ListBuffer to stdlib test
odersky Jul 18, 2023
7c642c2
Add StringOps and StringBuilder to stdlib tests
odersky Jul 21, 2023
74696b9
Improve error message for escaping capabilities
odersky Jul 21, 2023
4b812e3
Align typer and rechecker for Labelled and Bind trees
odersky Jul 21, 2023
0a8f763
Use InferredTypeTree for @unchecked match selectors
odersky Jul 21, 2023
bd8a4de
Add test programs to stdlib tests
odersky Jul 21, 2023
8ce0521
Rename WithCaptureChecks to CaptureChecked
odersky Jul 22, 2023
7a8fae7
Update MiMaFilters
odersky Jul 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,15 @@ class CheckCaptures extends Recheck, SymTransformer:
val argType0 = f(recheckStart(arg, pt))
val argType = super.recheckFinish(argType0, arg, pt)
super.recheckFinish(argType, tree, pt)
if meth == defn.Caps_unsafeBox then

if meth == defn.Caps_unsafeAssumePure then
val arg :: Nil = tree.args: @unchecked
val argType0 = recheck(arg, pt.capturing(CaptureSet.universal))
val argType = if argType0.captureSet.isAlwaysEmpty then argType0
else argType0.widen.stripCapturing
capt.println(i"rechecking $arg with ${pt.capturing(CaptureSet.universal)}: $argType")
super.recheckFinish(argType, tree, pt)
else if meth == defn.Caps_unsafeBox then
mapArgUsing(_.forceBoxStatus(true))
else if meth == defn.Caps_unsafeUnbox then
mapArgUsing(_.forceBoxStatus(false))
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ class Definitions {
@tu lazy val CapsModule: Symbol = requiredModule("scala.caps")
@tu lazy val captureRoot: TermSymbol = CapsModule.requiredValue("cap")
@tu lazy val CapsUnsafeModule: Symbol = requiredModule("scala.caps.unsafe")
@tu lazy val Caps_unsafeAssumePure: Symbol = CapsUnsafeModule.requiredMethod("unsafeAssumePure")
@tu lazy val Caps_unsafeBox: Symbol = CapsUnsafeModule.requiredMethod("unsafeBox")
@tu lazy val Caps_unsafeUnbox: Symbol = CapsUnsafeModule.requiredMethod("unsafeUnbox")
@tu lazy val Caps_unsafeBoxFunArg: Symbol = CapsUnsafeModule.requiredMethod("unsafeBoxFunArg")
Expand Down
1 change: 0 additions & 1 deletion library/src/scala/annotation/internal/WithPureFuns.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package scala.annotation
package internal
import annotation.experimental

/** A marker annotation on a toplevel class that indicates
* that the class was typed with the pureFunctions language import.
Expand Down
6 changes: 6 additions & 0 deletions library/src/scala/caps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import annotation.experimental
object unsafe:

extension [T](x: T)
/** A specific cast operation to remove a capture set.
* If argument is of type `T^C`, assume it is of type `T` instead.
* Calls to this method are treated specially by the capture checker.
*/
def unsafeAssumePure: T = x

/** If argument is of type `cs T`, converts to type `box cs T`. This
* avoids the error that would be raised when boxing `*`.
*/
Expand Down
4 changes: 4 additions & 0 deletions tests/pos-custom-args/captures/unsafeAssumePure.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class C
import caps.unsafe.*

def foo(x: C^): C = x.unsafeAssumePure