@@ -186,22 +186,24 @@ Expr.betaReduce(_): Expr[(T1, ..., Tn) => R] => ((Expr[T1], ..., Expr[Tn]) => Ex
186186Types are not directly affected by the phase consistency principle.
187187It is possible to use types defined at any level in any other level.
188188But, 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.
190189Indeed, the definition of ` to ` above uses ` T ` in the next stage, there is a
191190quote 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] ` :
193192
194193``` 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 ) } }
197196```
198197
199198In 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.
202206
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 ` .
205207For instance, the user-level definition of ` to ` :
206208
207209``` scala
@@ -213,7 +215,10 @@ would be rewritten to
213215
214216``` scala
215217def 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+ }
217222```
218223
219224The ` summon ` query succeeds because there is a given instance of
0 commit comments