You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
28
28
```scala
29
29
SimpleExpr::= ...
30
30
| `'` alphaid // quoted identifier
@@ -42,7 +42,7 @@ Lastly, the quoted type pattern simply contains a type.
42
42
### Splices
43
43
Splices come in three flavors: spliced identifiers, spliced blocks and splice patterns.
44
44
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 Scala2. Therefore to mitigate the cost of migration, we still support them.
46
46
We work around this by only allowing spliced identifiers[^3] within quoted blocks or quoted block patterns (`inQuoteBlock`).
47
47
Splice blocks and splice patterns can contain an arbitrary block or pattern respectively.
48
48
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.
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`:
@@ -229,7 +229,7 @@ To do this, the resulting `RunInstance` class is loaded in the JVM using Java Re
229
229
230
230
Quotes and splices are primitive forms in the generated typed abstract syntax trees.
231
231
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).
233
233
234
234
#### Typing Quoted Expressions
235
235
@@ -473,7 +473,7 @@ In general, the splice normal form has the shape `${ <lambda>.apply(<args>*) }`
473
473
474
474
##### Function references normalization
475
475
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.
477
477
Therefore function references cannot be transformed by the normalization as directly as other expressions as we cannot represent `'{f}` with a method reference type.
478
478
We can use the eta-expanded form of `f` in the normalized form.
479
479
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
626
626
The AST is pickled into TASTy, which is a sequence of bytes.
627
627
This sequence of bytes needs to be instantiated in the bytecode, but unfortunately it cannot be dumped into the classfile as bytes.
628
628
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.
630
630
631
631
```scala
632
632
// 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
697
697
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.
698
698
699
699
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.
702
702
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.
0 commit comments