Skip to content

Commit df75afc

Browse files
Apply suggestions from code review
Co-authored-by: Dimi Racordon <[email protected]>
1 parent c76dc80 commit df75afc

File tree

7 files changed

+17
-20
lines changed

7 files changed

+17
-20
lines changed

docs/_docs/reference/contextual/context-bounds.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ The syntax of function types and function literals
199199
is generalized as follows to allow context bounds for generic type parameters.
200200

201201
```ebnf
202-
FunType ::= FunTypeArgs (‘=>’ | ?=>) Type
202+
FunType ::= FunTypeArgs ('=>' | '?=>') Type
203203
| DefTypeParamClause '=>' Type
204-
FunExpr ::= FunParams (‘=>’ | ?=>) Expr
205-
| DefTypeParamClause ‘=>’ Expr
204+
FunExpr ::= FunParams ('=>' | '?=>') Expr
205+
| DefTypeParamClause '=>' Expr
206206
```
207207
The syntax for abstract type members is generalized as follows to allow context bounds:
208208

docs/_docs/reference/contextual/deferred-givens.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SortedString[A] extends Sorted:
4040
override given Ord[String] = ...
4141
```
4242

43-
Note that the implementing given needs an `override` modifier since the `deferred` given in class `Sorted` counts as a concrete (i.e. not abstract) definition. In a sense, the `deferred` right hand side in `Sorted` is like a (magic, compiler-supported) macro, with the peculiarity that the macro's implementation also affects subclasses.
43+
Note that the implementing given needs an `override` modifier since the `deferred` given in class `Sorted` counts as a concrete (i.e. not abstract) definition. In a sense, `deferred` on the right-hand side in `Sorted` is like a (magic, compiler-supported) macro, with the peculiarity that the macro's implementation also affects subclasses.
4444

4545
## Abstract Givens
4646

@@ -52,6 +52,6 @@ trait HasOrd[T]:
5252
```
5353
An abstract given has the form `given name: Type` without a right-hand side or arguments to the type.
5454

55-
Since Scala 3.6, abstract givens are made redundant by deferred givens. Deferred givens can replace abstract givens. They have better ergonomics, since deferred givens get naturally implemented in inheriting classes, so there is no longer any need for boilerplate to fill in definitions of abstract givens.
55+
Since Scala 3.6, abstract givens are made redundant by deferred givens. Deferred givens have better ergonomics, since they get naturally implemented in inheriting classes, so there is no longer any need for boilerplate to fill in definitions of abstract givens.
5656

5757
It is therefore recommended that software architectures relying on abstract givens be migrated to use deferred givens instead. Abstract givens are still supported in Scala 3.6, but will likely be deprecated and phased out over time.

docs/_docs/reference/contextual/givens.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ given Position = enclosingTree.position
8383
## Given Instance Initialization
8484

8585
An unconditional given instance without parameters is initialized on-demand, the first
86-
time it is accessed. If the given is a simple alias to some immutable value, the given is implemented as a simple forwarder, without incurring the cost of a field to hold a cached value. If a given is conditional, a fresh instance is created for each reference.
86+
time it is accessed. If the given is a mere alias to some immutable value, the given is implemented as a simple forwarder, without incurring the cost of a field to hold a cached value. If a given is conditional, a fresh instance is created for each reference.
8787

8888
## Syntax
8989

90-
Here is the full syntax for given instances. Some of these forms of givens are explained on a separate page on [Other Forms of Givens](../more-givens.md).
90+
Here is the full syntax for given instances. Some of these forms of givens are explained in a separate page: [Other Forms of Givens](../more-givens.md).
9191

9292
```ebnf
9393
Here is the complete context-free syntax for all proposed features.
@@ -106,7 +106,7 @@ GivenConditional ::= DefTypeParamClause
106106
GivenType ::= AnnotType1 {id [nl] AnnotType1}
107107
```
108108
109-
A given instance starts with the reserved word `given`, which is followed by
109+
A given instance starts with the reserved keyword `given`, which is followed by
110110
111111
- An optional name and a colon
112112
- An optional list of conditions.

docs/_docs/reference/contextual/more-givens.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,12 @@ given listOrd: [T] => (ord: Ord[T]) => Ord[List[T]]:
4343

4444
## By Name Givens
4545

46-
We sometimes find it necessary that a given alias is re-evaluated each time it is called. For instance, say we have a mutable variable `curCtx` and we want to define a given that returns the current value of that variable. A normal given alias will not do since by default given aliases are mapped to lazy vals.
47-
48-
In general, we want to avoid re-evaluation of givens. But there are situations like the one above where we want to specify _by-name_ evaluation instead. This is achieved by writing a conditional given with an empty parameter list:
46+
Though in general we want to avoid re-evaluating a given, there are situations where such a re-evaluation may be necessary. For instance, say we have a mutable variable `curCtx` and we want to define a given that returns the current value of that variable. A normal given alias will not do since by default given aliases are mapped to lazy vals. In this case, we can specify a _by-name_ evaluation insteadby writing a conditional given with an empty parameter list:
4947
```scala
5048
val curCtx: Context
5149
given context: () => Context = curCtx
5250
```
53-
With this definition, each time a `Context` is summoned we evaluate `context` function, which produces the current value of `curCtx`.
51+
With this definition, each time a `Context` is summoned we evaluate the `context` function, which produces the current value of `curCtx`.
5452

5553
## Given Macros
5654

docs/_docs/reference/contextual/previous-givens.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ Note that the inline methods within the given instances may be `transparent`.
161161
The inlining of given instances will not inline/duplicate the implementation of the given, it will just inline the instantiation of that instance.
162162
This is used to help dead code elimination of the given instances that are not used after inlining.
163163

164-
165164
## Pattern-Bound Given Instances
166165

167166
Given instances can also appear in patterns. Example:
@@ -215,12 +214,12 @@ Here is the syntax for given instances:
215214

216215
```ebnf
217216
TmplDef ::= ...
218-
| given GivenDef
217+
| 'given' GivenDef
219218
GivenDef ::= [GivenSig] StructuralInstance
220219
| [GivenSig] AnnotType ‘=’ Expr
221220
| [GivenSig] AnnotType
222-
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’
223-
StructuralInstance ::= ConstrApp {with ConstrApp} [‘with’ TemplateBody]
221+
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ':'
222+
StructuralInstance ::= ConstrApp {'with' ConstrApp} [‘with’ TemplateBody]
224223
```
225224

226225
A given instance starts with the reserved word `given` and an optional _signature_. The signature

docs/_docs/reference/experimental/typeclasses.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ a bit cumbersome and limiting for standard generic programming patterns. Much ha
1818
This note shows that with some fairly small and reasonable tweaks to Scala's syntax and typing rules we can obtain a much better scheme for working with type classes, or do generic programming in general.
1919

2020
The bulk of the suggested improvements has been implemented and is available
21-
in under source version `future` if the additional experimental language import `modularity` is present. For instance, using the following command:
21+
in source version `future` if the additional experimental language import `modularity` is present. For instance, using the following command:
2222

2323
```
2424
scala compile -source:future -language:experimental.modularity

docs/_docs/reference/syntax.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ ParamValueType ::= Type [‘*’]
214214
TypeArgs ::= ‘[’ Types ‘]’
215215
Refinement ::= :<<< [RefineDcl] {semi [RefineDcl]} >>>
216216
TypeBounds ::= [‘>:’ Type] [‘<:’ Type]
217-
TypeAndCtxBounds ::= TypeBounds [‘:’ ContextBounds]
217+
TypeAndCtxBounds ::= TypeBounds [':' ContextBounds]
218218
ContextBounds ::= ContextBound
219-
| ContextBound `:` ContextBounds -- to be deprecated
219+
| ContextBound ':' ContextBounds -- to be deprecated
220220
| '{' ContextBound {',' ContextBound} '}'
221221
ContextBound ::= Type ['as' id]
222222
Types ::= Type {‘,’ Type}
@@ -441,7 +441,7 @@ TypeDef ::= id [HkTypeParamClause] {FunParamClause}TypeBounds
441441
TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef
442442
| [‘case’] ‘object’ ObjectDef
443443
| ‘enum’ EnumDef
444-
| given (GivenDef | OldGivenDef)
444+
| 'given' (GivenDef | OldGivenDef)
445445
ClassDef ::= id ClassConstr [Template]
446446
ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses
447447
ConstrMods ::= {Annotation} [AccessModifier]

0 commit comments

Comments
 (0)