Skip to content

Commit ba78c70

Browse files
committed
Update specs and internal syntax
1 parent 27c6866 commit ba78c70

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

docs/_docs/internals/syntax.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ type val var while with yield
140140
### Soft keywords
141141

142142
```
143-
as derives end extension infix inline opaque open throws transparent using | * + -
143+
as derives end erased extension infix inline opaque open throws transparent using | * + -
144144
```
145145

146146
See the [separate section on soft keywords](../reference/soft-modifier.md) for additional
@@ -180,13 +180,13 @@ Type ::= FunType
180180
| FunParamClause ‘=>>’ Type TermLambdaTypeTree(ps, t)
181181
| MatchType
182182
| InfixType
183-
FunType ::= FunTypeArgs (‘=>’ | ‘?=>’) Type Function(ts, t)
183+
FunType ::= FunTypeArgs (‘=>’ | ‘?=>’) Type Function(ts, t) | FunctionWithMods(ts, t, mods, erasedParams)
184184
| HKTypeParamClause '=>' Type PolyFunction(ps, t)
185185
FunTypeArgs ::= InfixType
186186
| ‘(’ [ FunArgTypes ] ‘)’
187187
| FunParamClause
188188
FunParamClause ::= ‘(’ TypedFunParam {‘,’ TypedFunParam } ‘)’
189-
TypedFunParam ::= id ‘:’ Type
189+
TypedFunParam ::= [`erased`] id ‘:’ Type
190190
MatchType ::= InfixType `match` <<< TypeCaseClauses >>>
191191
InfixType ::= RefinedType {id [nl] RefinedType} InfixOp(t1, op, t2)
192192
RefinedType ::= AnnotType {[nl] Refinement} RefinedTypeTree(t, ds)
@@ -207,8 +207,8 @@ Singleton ::= SimpleRef
207207
| SimpleLiteral
208208
| Singleton ‘.’ id
209209
Singletons ::= Singleton { ‘,’ Singleton }
210-
FunArgType ::= Type
211-
| ‘=>’ Type PrefixOp(=>, t)
210+
FunArgType ::= [`erased`] Type
211+
| [`erased`] ‘=>’ Type PrefixOp(=>, t)
212212
FunArgTypes ::= FunArgType { ‘,’ FunArgType }
213213
ParamType ::= [‘=>’] ParamValueType
214214
ParamValueType ::= [‘into’] ExactParamType Into(t)
@@ -229,7 +229,7 @@ BlockResult ::= FunParams (‘=>’ | ‘?=>’) Block
229229
| HkTypeParamClause ‘=>’ Block
230230
| Expr1
231231
FunParams ::= Bindings
232-
| id
232+
| [`erased`] id
233233
| ‘_’
234234
Expr1 ::= [‘inline’] ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[semi] ‘else’ Expr] If(Parens(cond), thenp, elsep?)
235235
| [‘inline’] ‘if’ Expr ‘then’ Expr [[semi] ‘else’ Expr] If(cond, thenp, elsep?)
@@ -376,13 +376,13 @@ UsingParamClause ::= [nl] ‘(’ ‘using’ (DefTermParams | FunArgTypes)
376376
DefImplicitClause ::= [nl] ‘(’ ‘implicit’ DefTermParams ‘)’
377377
378378
DefTermParams ::= DefTermParam {‘,’ DefTermParam}
379-
DefTermParam ::= {Annotation} [‘inline’] Param ValDef(mods, id, tpe, expr) -- point of mods at id.
379+
DefTermParam ::= {Annotation} [`erased`] [‘inline’] Param ValDef(mods, id, tpe, expr) -- point of mods at id.
380380
Param ::= id ‘:’ ParamType [‘=’ Expr]
381381
```
382382

383383
### Bindings and Imports
384384
```ebnf
385-
Bindings ::= ‘(’ [Binding {‘,’ Binding}] ‘)’
385+
Bindings ::= ‘(’[`erased`] [Binding {‘,’ [`erased`] Binding}] ‘)’
386386
Binding ::= (id | ‘_’) [‘:’ Type] ValDef(_, id, tpe, EmptyTree)
387387
388388
Modifier ::= LocalModifier

docs/_docs/reference/experimental/erased-defs-spec.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ TODO: complete
1919

2020
def g(erased x: Int) = ...
2121

22-
(erased x: Int) => ...
23-
def h(x: (erased Int) => Int) = ...
22+
(erased x: Int, y: Int) => ...
23+
def h(x: (Int, erased Int) => Int) = ...
2424

2525
class K(erased x: Int) { ... }
2626
erased class E {}
@@ -34,12 +34,12 @@ TODO: complete
3434

3535
3. Functions
3636
* `(erased x1: T1, x2: T2, ..., xN: TN) => y : (erased T1, T2, ..., TN) => R`
37-
* `(given erased x1: T1, x2: T2, ..., xN: TN) => y: (given erased T1, T2, ..., TN) => R`
37+
* `(given x1: T1, erased x2: T2, ..., xN: TN) => y: (given T1, erased T2, ..., TN) => R`
3838
* `(given erased T1) => R <:< erased T1 => R`
39-
* `(given erased T1, T2) => R <:< (erased T1, T2) => R`
39+
* `(given T1, erased T2) => R <:< (T1, erased T2) => R`
4040
* ...
4141

42-
Note that there is no subtype relation between `(erased T) => R` and `T => R` (or `(given erased T) => R` and `(given T) => R`)
42+
Note that there is no subtype relation between `(erased T) => R` and `T => R` (or `(given erased T) => R` and `(given T) => R`). The `erased` parameters must match exactly in their respective positions.
4343

4444

4545
4. Eta expansion
@@ -51,7 +51,8 @@ TODO: complete
5151
* All `erased` parameters are removed from the function
5252
* All argument to `erased` parameters are not passed to the function
5353
* All `erased` definitions are removed
54-
* All `(erased T1, T2, ..., TN) => R` and `(given erased T1, T2, ..., TN) => R` become `() => R`
54+
* `(erased ET1, erased ET2, T1, ..., erased ETN, TM) => R` are erased to `(T1, ..., TM) => R`.
55+
* `(given erased ET1, erased ET2, T1, ..., erased ETN, TM) => R` are erased to `(given T1, ..., TM) => R`.
5556

5657

5758
6. Overloading
@@ -60,11 +61,10 @@ TODO: complete
6061

6162

6263
7. Overriding
63-
* Member definitions overriding each other must both be `erased` or not be `erased`
64-
* `def foo(x: T): U` cannot be overridden by `def foo(erased x: T): U` and vice-versa
65-
*
66-
64+
* Member definitions overriding each other must both be `erased` or not be `erased`.
65+
* `def foo(x: T): U` cannot be overridden by `def foo(erased x: T): U` and vice-versa.
6766

6867
8. Type Restrictions
6968
* For dependent functions, `erased` parameters are limited to realizable types, that is, types that are inhabited by non-null values.
7069
This restriction stops us from using a bad bound introduced by an erased value, which leads to unsoundness (see #4060).
70+
* Polymorphic functions with erased parameters are currently not supported, and will be rejected by the compiler. This is purely an implementation restriction, and might be lifted in the future.

docs/_docs/reference/experimental/erased-defs.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ semantics and they are completely erased.
5454
## How to define erased terms?
5555

5656
Parameters of methods and functions can be declared as erased, placing `erased`
57-
in front of a parameter list (like `given`).
57+
in front of each erased parameter (like `inline`).
5858

5959
```scala
60-
def methodWithErasedEv(erased ev: Ev): Int = 42
60+
def methodWithErasedEv(erased ev: Ev, x: Int): Int = x + 2
6161

62-
val lambdaWithErasedEv: erased Ev => Int =
63-
(erased ev: Ev) => 42
62+
val lambdaWithErasedEv: (erased Ev, Int) => Int =
63+
(erased ev, x) => x + 2
6464
```
6565

6666
`erased` parameters will not be usable for computations, though they can be used
@@ -80,7 +80,7 @@ parameters.
8080

8181
```scala
8282
erased val erasedEvidence: Ev = ...
83-
methodWithErasedEv(erasedEvidence)
83+
methodWithErasedEv(erasedEvidence, 40) // 42
8484
```
8585

8686
## What happens with erased values at runtime?
@@ -89,15 +89,15 @@ As `erased` are guaranteed not to be used in computations, they can and will be
8989
erased.
9090

9191
```scala
92-
// becomes def methodWithErasedEv(): Int at runtime
93-
def methodWithErasedEv(erased ev: Ev): Int = ...
92+
// becomes def methodWithErasedEv(x: Int): Int at runtime
93+
def methodWithErasedEv(x: Int, erased ev: Ev): Int = ...
9494

9595
def evidence1: Ev = ...
9696
erased def erasedEvidence2: Ev = ... // does not exist at runtime
9797
erased val erasedEvidence3: Ev = ... // does not exist at runtime
9898

99-
// evidence1 is not evaluated and no value is passed to methodWithErasedEv
100-
methodWithErasedEv(evidence1)
99+
// evidence1 is not evaluated and only `x` is passed to methodWithErasedEv
100+
methodWithErasedEv(x, evidence1)
101101
```
102102

103103
## State machine with erased evidence example

0 commit comments

Comments
 (0)