Skip to content

Commit c69e850

Browse files
committed
Change syntax of cap parameters and members
`cap` is now a soft modifier and we abolish separate cap lists.
1 parent 38304c6 commit c69e850

18 files changed

+142
-170
lines changed

compiler/src/dotty/tools/dotc/ast/untpd.scala

+2
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
234234

235235
case class Tracked()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Tracked)
236236

237+
case class CaptureParam()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.CaptureParam)
238+
237239
/** Used under pureFunctions to mark impure function types `A => B` in `FunctionWithMods` */
238240
case class Impure()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Impure)
239241
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ object Flags {
380380
/** Tracked modifier for class parameter / a class with some tracked parameters */
381381
val (Tracked @ _, _, Dependent @ _) = newFlags(46, "tracked")
382382

383+
/** Cap modifier for capture-set parameters and capture-set members */
384+
val (_, _, CaptureParam @ _) = newFlags(47, "cap")
385+
383386
// ------------ Flags following this one are not pickled ----------------------------------
384387

385388
/** Symbol is not a member of its owner */

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

+71-104
Large diffs are not rendered by default.

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ object Scanners {
12091209

12101210
def isSoftModifier: Boolean =
12111211
token == IDENTIFIER
1212-
&& (softModifierNames.contains(name) || name == nme.erased && erasedEnabled || name == nme.tracked && trackedEnabled)
1212+
&& (softModifierNames.contains(name) || name == nme.erased && erasedEnabled || name == nme.tracked && trackedEnabled || name == nme.cap && Feature.ccEnabled)
12131213

12141214
def isSoftModifierInModifierPosition: Boolean =
12151215
isSoftModifier && inModifierPosition()
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
import caps.*
22

3-
trait Abstract[X^]:
4-
cap C >: X
3+
trait Abstract[cap X]:
4+
cap type C >: {X}
55
// Don't test the return type using Unit, because it is a pure type.
66
def boom(): AnyRef^{C}
77

8-
class Concrete extends Abstract[CapSet^{}]:
9-
cap C = {}
8+
class Concrete extends Abstract[{}]:
9+
cap type C = {}
1010
// TODO: Why do we get error without the return type here?
1111
def boom(): AnyRef = new Object
1212

13-
class Concrete2 extends Abstract[CapSet^{}]:
14-
cap C = {}
13+
class Concrete2 extends Abstract[{}]:
14+
cap type C = {}
1515
def boom(): AnyRef^ = new Object // error
1616

17-
class Concrete3 extends Abstract[CapSet^{}]:
17+
class Concrete3 extends Abstract[{}]:
1818
def boom(): AnyRef = new Object
1919

20-
class Concrete4(a: AnyRef^) extends Abstract[CapSet^{a}]:
21-
cap C = {} // error
20+
class Concrete4(a: AnyRef^) extends Abstract[{a}]:
21+
cap type C = {} // error
2222
def boom(): AnyRef^{a} = a // error
2323

24-
class Concrete5(a: AnyRef^, b: AnyRef^) extends Abstract[CapSet^{a}]:
25-
cap C = a
24+
class Concrete5(a: AnyRef^, b: AnyRef^) extends Abstract[{a}]:
25+
cap type C = {a}
2626
def boom(): AnyRef^{b} = b // error
2727

28-
class Concrete6(a: AnyRef^, b: AnyRef^) extends Abstract[CapSet^{a}]:
28+
class Concrete6(a: AnyRef^, b: AnyRef^) extends Abstract[{a}]:
2929
def boom(): AnyRef^{b} = b // error
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Error: tests/neg-custom-args/captures/capset-members2.scala:4:7 -----------------------------------------------------
2-
4 | cap C[T] // error
3-
| ^
4-
| 'cap' declarations cannot have type parameters
1+
-- Error: tests/neg-custom-args/captures/capset-members2.scala:4:12 ----------------------------------------------------
2+
4 | cap type C[T] // error
3+
| ^
4+
| 'cap type' declarations cannot have type parameters
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import caps.*
22

33
trait Foo:
4-
cap C[T] // error
4+
cap type C[T] // error
55

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
-- [E209] Syntax Error: tests/neg-custom-args/captures/capset-members3.scala:4:8 ---------------------------------------
2-
4 | cap C _ // error
3-
| ^
4-
| =, >:, or <: expected, but '_' found
1+
-- [E209] Syntax Error: tests/neg-custom-args/captures/capset-members3.scala:4:13 --------------------------------------
2+
4 | cap type C _ // error
3+
| ^
4+
| =, >:, or <: expected, but '_' found
55
|
66
| longer explanation available when compiling with `-explain`
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import caps.*
22

33
trait Foo:
4-
cap C _ // error
4+
cap type C _ // error
55

tests/pending/cap-paramlists8.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ def test =
77
val y: Any^ = ???
88
object O:
99
val z: Any^ = ???
10-
val baz3 = (i: Int) => [cap C, D <: C, E <: {C,x}] => () => [cap F >: {x,y} <: {C,E} : Ctx] => (x: Int) => 1
10+
val baz3 = (i: Int) => [cap C, cap D <: {C}, cap E <: {C,x}] => () => [cap F >: {x,y} <: {C,E} : Ctx] => (x: Int) => 1

tests/pos-custom-args/captures/cap-paramlists.scala

+14-14
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ def test =
77
val y: Any^ = ???
88
object O:
99
val z: Any^ = ???
10-
def foo[cap A >: y <: x,
11-
B,
12-
C <: {x},
13-
D : Ctx,
14-
E <: C,
15-
F <: {C},
16-
G <: {x, y},
17-
H >: {x} <: {x,y} : Ctx]()[cap I <: {y, G, H},
18-
J <: O.z,
19-
K <: {x, O.z},
20-
L <: {x, y, O.z},
21-
M >: {x, y, O.z} <: C : Ctx,
22-
N >: x <: x,
23-
O >: O.z <: O.z] = ???
10+
def foo[cap A >: {y} <: {x},
11+
cap B,
12+
cap C <: {x},
13+
cap D : Ctx,
14+
cap E <: {C},
15+
cap F <: {C},
16+
cap G <: {x, y},
17+
cap H >: {x} <: {x,y} : Ctx, T, U]()[cap I <: {y, G, H},
18+
cap J <: {O.z},
19+
cap K <: {x, O.z},
20+
cap L <: {x, y, O.z},
21+
cap M >: {x, y, O.z} <: {C} : Ctx,
22+
cap N >: {x} <: {x},
23+
cap O >: {O.z} <: {O.z}] = ???
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import language.experimental.captureChecking
22

33
trait Bar:
4-
cap C
4+
cap type C
55

6-
def useFoo[cap D](x: Bar { cap C = D} ): Any^{x.C} = ???
6+
def useFoo[cap D](x: Bar { cap type C = {D} } ): Any^{x.C} = ???

tests/pos-custom-args/captures/cap-paramlists3.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ def test =
77
val y: Any^ = ???
88
object O:
99
val z: Any^ = ???
10-
val bar = [cap C, D <: C, E <: {C,x}, F >: {x,y} <: {C,E}] => (x: Int) => 1
10+
val bar = [cap C, cap D <: {C}, cap E <: {C,x}, cap F >: {x,y} <: {C,E}] => (x: Int) => 1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import language.experimental.captureChecking
22

3-
trait Foo[cap U,V,W]:
4-
cap C = caps.cap
5-
cap D = {caps.cap}
6-
cap E >: {V,W} <: U
3+
trait Foo[cap U, cap V, cap W]:
4+
cap type C = {caps.cap}
5+
cap type D = {caps.cap}
6+
cap type E >: {V,W} <: {U}

tests/pos-custom-args/captures/cap-paramlists5.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import language.experimental.namedTypeArguments
33

44
def test2 =
55
val x: Any^ = ???
6-
def foo[cap A, B >: A](x: Int) = 1
7-
foo[cap x, x](0)
8-
foo[cap A = x, B = {x}](0)
9-
foo[cap A = {x}](0)
6+
def foo[cap A, cap B >: {A}, T](x: Int) = 1
7+
foo[{x}, {x}, Int](0)
8+
// foo[cap A = {x}, cap B = {x}](0)
9+
// foo[cap A = {x}](0)

tests/pos-custom-args/captures/cap-paramlists6.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ def test =
77
val y: Any^ = ???
88
object O:
99
val z: Any^ = ???
10-
val baz = () => [cap C, D <: C, E <: {C,x}, F >: {x,y} <: {C,E} : Ctx] => (x: Int) => 1
10+
val baz = () => [cap C, cap D <: {C}, cap E <: {C,x}, cap F >: {x,y} <: {C,E} : Ctx] => (x: Int) => 1

tests/pos-custom-args/captures/cap-paramlists7.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ def test =
77
val y: Any^ = ???
88
object O:
99
val z: Any^ = ???
10-
val baz2 = (i: Int) => [cap C, D <: C, E <: {C,x}, F >: {x,y} <: {C,E} : Ctx] => (x: Int) => 1
10+
val baz2 = (i: Int) => [cap C, cap D <: {C}, cap E <: {C,x}, cap F >: {x,y} <: {C,E} : Ctx] => (x: Int) => 1

tests/pos-custom-args/captures/capset-members.scala

+15-15
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ def test =
88
object O:
99
val z: Any^ = ???
1010
trait CaptureSet:
11-
cap A >: y <: x
12-
cap B = x
13-
cap C <: {x}
14-
cap D : Ctx
15-
cap E <: C
16-
cap F <: {C}
17-
cap G <: {x, y}
18-
cap H >: {x} <: {x,y} : Ctx
19-
cap I = {y, G, H}
20-
cap J = {O.z}
21-
cap K = {x, O.z}
22-
cap L <: {x, y, O.z}
23-
cap M >: {x, y, O.z} <: C
24-
cap N >: x <: x
25-
cap O >: O.z <: O.z
11+
cap type A >: {y} <: {x}
12+
cap type B = {x}
13+
cap type C <: {x}
14+
cap type D : Ctx
15+
cap type E <: {C}
16+
cap type F <: {C}
17+
cap type G <: {x, y}
18+
cap type H >: {x} <: {x,y} : Ctx
19+
cap type I = {y, G, H}
20+
cap type J = {O.z}
21+
cap type K = {x, O.z}
22+
cap type L <: {x, y, O.z}
23+
cap type M >: {x, y, O.z} <: {C}
24+
cap type N >: {x} <: {x}
25+
cap type O >: {O.z} <: {O.z}

0 commit comments

Comments
 (0)