@@ -29,26 +29,6 @@ class Expr[+T] private[scala] {
2929 final def matches (that : Expr [Any ])(given qctx : QuoteContext ): Boolean =
3030 ! scala.internal.quoted.Expr .unapply[Unit , Unit ](this )(given that , false , qctx).isEmpty
3131
32- /** Returns the undelying argument that was in the call before inlining.
33- *
34- * ```
35- * inline foo(x: Int): Int = baz(x, x)
36- * foo(bar())
37- * ```
38- * is inlined as
39- * ```
40- * val x = bar()
41- * baz(x, x)
42- * ```
43- * in this case the undelying argument of `x` will be `bar()`.
44- *
45- * Warning: Using the undelying argument directly in the expansion of a macro may change the parameter
46- * semantics from by-value to by-name.
47- */
48- def underlyingArgument (given qctx : QuoteContext ): Expr [T ] = {
49- import qctx .tasty .{given , _ }
50- this .unseal.underlyingArgument.seal.asInstanceOf [Expr [T ]]
51- }
5232}
5333
5434object Expr {
@@ -201,40 +181,4 @@ object Expr {
201181 ofTuple(elems).cast[Tuple .InverseMap [T , Expr ]]
202182 }
203183
204- // TODO generalize for any function arity (see Expr.betaReduce)
205- def open [T1 , R , X ](f : Expr [T1 => R ])(content : (Expr [R ], [t] => Expr [t] => Expr [T1 ] => Expr [t]) => X )(given qctx : QuoteContext ): X = {
206- import qctx .tasty .{given , _ }
207- val (params, bodyExpr) = paramsAndBody(f)
208- content(bodyExpr, [t] => (e : Expr [t]) => (v : Expr [T1 ]) => bodyFn[t](e.unseal, params, List (v.unseal)).seal.asInstanceOf [Expr [t]])
209- }
210-
211- def open [T1 , T2 , R , X ](f : Expr [(T1 , T2 ) => R ])(content : (Expr [R ], [t] => Expr [t] => (Expr [T1 ], Expr [T2 ]) => Expr [t]) => X )(given qctx : QuoteContext )(given DummyImplicit ): X = {
212- import qctx .tasty .{given , _ }
213- val (params, bodyExpr) = paramsAndBody(f)
214- content(bodyExpr, [t] => (e : Expr [t]) => (v1 : Expr [T1 ], v2 : Expr [T2 ]) => bodyFn[t](e.unseal, params, List (v1.unseal, v2.unseal)).seal.asInstanceOf [Expr [t]])
215- }
216-
217- def open [T1 , T2 , T3 , R , X ](f : Expr [(T1 , T2 , T3 ) => R ])(content : (Expr [R ], [t] => Expr [t] => (Expr [T1 ], Expr [T2 ], Expr [T3 ]) => Expr [t]) => X )(given qctx : QuoteContext )(given DummyImplicit , DummyImplicit ): X = {
218- import qctx .tasty .{given , _ }
219- val (params, bodyExpr) = paramsAndBody(f)
220- content(bodyExpr, [t] => (e : Expr [t]) => (v1 : Expr [T1 ], v2 : Expr [T2 ], v3 : Expr [T3 ]) => bodyFn[t](e.unseal, params, List (v1.unseal, v2.unseal, v3.unseal)).seal.asInstanceOf [Expr [t]])
221- }
222-
223- private def paramsAndBody [R ](given qctx : QuoteContext )(f : Expr [Any ]) = {
224- import qctx .tasty .{given , _ }
225- val Block (List (DefDef (" $anonfun" , Nil , List (params), _, Some (body))), Closure (Ident (" $anonfun" ), None )) = f.unseal.etaExpand
226- (params, body.seal.asInstanceOf [Expr [R ]])
227- }
228-
229- private def bodyFn [t](given qctx : QuoteContext )(e : qctx.tasty.Term , params : List [qctx.tasty.ValDef ], args : List [qctx.tasty.Term ]): qctx.tasty.Term = {
230- import qctx .tasty .{given , _ }
231- val map = params.map(_.symbol).zip(args).toMap
232- new TreeMap {
233- override def transformTerm (tree : Term )(given ctx : Context ): Term =
234- super .transformTerm(tree) match
235- case tree : Ident => map.getOrElse(tree.symbol, tree)
236- case tree => tree
237- }.transformTerm(e)
238- }
239-
240184}
0 commit comments