Skip to content

Commit 1dc02d1

Browse files
Apply suggestions from code review
Co-authored-by: anna herlihy <[email protected]>
1 parent d8c9714 commit 1dc02d1

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

docs/_docs/reference/metaprogramming/macros-spec.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ${ hello('name) } ${ hello('{name}) }
2424

2525
### Quotes
2626
Quotes come in four flavors: quoted identifiers, quoted blocks, quoted block patterns and quoted type patterns.
27-
Scala 2 used quoted identifiers to represent `Symbol` literals. They were deprecated in Scala 3, allowing to use them for quotation.
27+
Scala 2 used quoted identifiers to represent `Symbol` literals. They were deprecated in Scala 3, allowing the syntax to be used for quotation.
2828
```scala
2929
SimpleExpr ::= ...
3030
| `'` alphaid // quoted identifier
@@ -42,7 +42,7 @@ Lastly, the quoted type pattern simply contains a type.
4242
### Splices
4343
Splices come in three flavors: spliced identifiers, spliced blocks and splice patterns.
4444
Scala specifies identifiers containing `$` as valid identifiers but reserves them for compiler and standard library use only.
45-
Unfortunately, many libraries have used such identifiers in Scala~2. Therefore to mitigate the cost of migration, we still support them.
45+
Unfortunately, many libraries have used such identifiers in Scala 2. Therefore to mitigate the cost of migration, we still support them.
4646
We work around this by only allowing spliced identifiers[^3] within quoted blocks or quoted block patterns (`inQuoteBlock`).
4747
Splice blocks and splice patterns can contain an arbitrary block or pattern respectively.
4848
They are distinguished based on their surrounding quote (`inQuotePattern`), a quote block will contain spliced blocks, and a quote block pattern will contain splice patterns.
@@ -208,7 +208,7 @@ import scala.quoted.staging.*
208208
given Compiler = Compiler.make(getClass.getClassLoader)
209209
```
210210

211-
The classloader is needed for the compiler to know which dependencies have been loaded and to load the generated code using the same classloader.
211+
The classloader is needed for the compiler to know which dependencies have been loaded and to load the generated code using the same classloader. Below is an example method `mkPower2` that is passed to `staging.run`:
212212

213213
```scala
214214
def mkPower2()(using Quotes): Expr[Double => Double] = ...
@@ -229,7 +229,7 @@ To do this, the resulting `RunInstance` class is loaded in the JVM using Java Re
229229

230230
Quotes and splices are primitive forms in the generated typed abstract syntax trees.
231231
These need to be type-checked with some extra rules, e.g., staging levels need to be checked and the references to generic types need to be adapted.
232-
Finally, quoted expressions that will be generated at run-time need to be encoded (serialized) and decoded (deserialized).
232+
Finally, quoted expressions that will be generated at run-time need to be encoded (serialized/pickled) and decoded (deserialized/unpickled).
233233

234234
#### Typing Quoted Expressions
235235

@@ -473,7 +473,7 @@ In general, the splice normal form has the shape `${ <lambda>.apply(<args>*) }`
473473

474474
##### Function references normalization
475475
A reference to a function `f` that receives parameters is not a valid value in Scala.
476-
Such a function reference `f` can be eta-expaned as `x => f(x)` to be used as a lambda value.
476+
Such a function reference `f` can be eta-expanded as `x => f(x)` to be used as a lambda value.
477477
Therefore function references cannot be transformed by the normalization as directly as other expressions as we cannot represent `'{f}` with a method reference type.
478478
We can use the eta-expanded form of `f` in the normalized form.
479479
For example, consider the reference to `f` below.
@@ -626,7 +626,7 @@ With these transformations, the contents of the quote or `Type.of` are guarantee
626626
The AST is pickled into TASTy, which is a sequence of bytes.
627627
This sequence of bytes needs to be instantiated in the bytecode, but unfortunately it cannot be dumped into the classfile as bytes.
628628
To reify it we encode the bytes into a Java `String`.
629-
In the following examples we display this encoding in human readable form with the fictitious |tasty"..."| string literal.
629+
In the following examples we display this encoding in human readable form with the fictitious `|tasty"..."|` string literal.
630630

631631
```scala
632632
// pickled AST bytes encoded in a base64 string
@@ -697,8 +697,8 @@ As the type holes are at the start of the quote, they will have the first `N` in
697697
This implies that we can place the references in a sequence `Seq(t, u, ...)` where the index in the sequence is the same as the hole index.
698698

699699
Lastly, the quote itself is replaced by a call to `QuoteUnpickler.unpickleExpr` which will unpickle the AST, evaluate the holes, i.e., splices, and wrap the resulting AST in an `Expr[Int]`.
700-
This method takes takes the pickled |tasty"..."|, the types and the hole lambda.
701-
Similarly, `Type.of` is replaced with a call to `QuoteUnpickler.unpickleType` but only receives the pickled |tasty"..."| and the types.
700+
This method takes takes the pickled `|tasty"..."|`, the types and the hole lambda.
701+
Similarly, `Type.of` is replaced with a call to `QuoteUnpickler.unpickleType` but only receives the pickled `|tasty"..."|` and the types.
702702
Because `QuoteUnpickler` is part of the self-type of the `Quotes` class, we have to cast the instance but know that this cast will always succeed.
703703

704704
```scala

docs/_docs/reference/metaprogramming/macros.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ Therefore, while evaluating the quote, it is not possible to accidentally rebind
254254
#### Well-typed
255255
If a quote is well typed, then the generated code is well typed.
256256
This is a simple consequence of tracking the type of each expression.
257-
An `Expr[T]` can only be created from a quote that contains an expression of type `T.
257+
An `Expr[T]` can only be created from a quote that contains an expression of type `T`.
258258
Conversely, an `Expr[T]` can only be spliced in a location that expects a type `T.
259259
As mentioned before, `Expr` is covariant in its type parameter.
260-
This means that an `Expr[T]` can contain an expression of a subtype of `T.
260+
This means that an `Expr[T]` can contain an expression of a subtype of `T`.
261261
When spliced in a location that expects a type `T, these expressions also have a valid type.
262262

263263
### Cross-Stage Safety
@@ -495,7 +495,7 @@ At run-time, when the pattern matches, the type of `t` and `u` will be known, an
495495

496496
As `Expr` is covariant, the statically known type of the expression might not be the actual type.
497497
Type variables can also be used to recover the precise type of the expression.
498-
``scala
498+
```scala
499499
def let(x: Expr[Any])(using Quotes): Expr[Any] =
500500
x match
501501
case '{ $x: t } =>

0 commit comments

Comments
 (0)