@@ -186,22 +186,24 @@ Expr.betaReduce(_): Expr[(T1, ..., Tn) => R] => ((Expr[T1], ..., Expr[Tn]) => Ex
186
186
Types are not directly affected by the phase consistency principle.
187
187
It is possible to use types defined at any level in any other level.
188
188
But, if a type is used in a subsequent stage it will need to be lifted to a ` Type ` .
189
- The resulting value of ` Type ` will be subject to PCP.
190
189
Indeed, the definition of ` to ` above uses ` T ` in the next stage, there is a
191
190
quote but no splice between the parameter binding of ` T ` and its
192
- usage. But the code can be rewritten by adding a binding of a ` Type[T] ` tag :
191
+ usage. But the code can be rewritten by adding an explicit binding of a ` Type[T] ` :
193
192
194
193
``` scala
195
- def to [T , R ](f : Expr [T ] => Expr [R ])(using Type [T ], Type [R ], Quotes ): Expr [T => R ] =
196
- ' { (x : T ) => $ { f(' x ) } }
194
+ def to [T , R ](f : Expr [T ] => Expr [R ])(using t : Type [T ])( using Type [R ], Quotes ): Expr [T => R ] =
195
+ ' { (x : t. Underlying ) => $ { f(' x ) } }
197
196
```
198
197
199
198
In this version of ` to ` , the type of ` x ` is now the result of
200
- splicing the ` Type ` value ` t ` . This operation _ is_ splice correct -- there
201
- is one quote and one splice between the use of ` t ` and its definition.
199
+ inserting the type ` Type[T] ` and selecting its ` Underlying ` .
200
+
201
+ To avoid clutter, the compiler converts any type reference to
202
+ a type ` T ` in subsequent phases to ` summon[Type[T]].Underlying ` .
203
+
204
+ And to avoid duplication it does it once per type, and creates
205
+ an alias for that type at the start of the quote.
202
206
203
- To avoid clutter, the Scala implementation tries to convert any type
204
- reference to a type ` T ` in subsequent phases to a type-splice, by rewriting ` T ` to ` summon[Type[T]].Underlying ` .
205
207
For instance, the user-level definition of ` to ` :
206
208
207
209
``` scala
@@ -213,7 +215,10 @@ would be rewritten to
213
215
214
216
``` scala
215
217
def to [T , R ](f : Expr [T ] => Expr [R ])(using t : Type [T ], r : Type [R ])(using Quotes ): Expr [T => R ] =
216
- ' { (x : t.Underlying ) => $ { f(' x ) } }
218
+ ' {
219
+ type T = t.Underlying
220
+ (x : T ) => $ { f(' x ) }
221
+ }
217
222
```
218
223
219
224
The ` summon ` query succeeds because there is a given instance of
0 commit comments