-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Beta-reduce directly applied PolymorphicFunction (#16623)
Beta-reduce directly applied PolymorphicFunction such as ```scala ([Z] => (arg: Z) => { def a: Z = arg; a }).apply[Int](2) ``` into ```scala type Z = Int val arg = 2 def a: Z = arg a ``` Apply this beta reduction in the `BetaReduce` phase and `Expr.betaReduce`. Also, refactor the beta-reduce logic to avoid code duplication. Fixes #15968
- Loading branch information
Showing
12 changed files
with
191 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
type Z = java.lang.String | ||
"foo".toString() | ||
} | ||
"foo".toString() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import scala.quoted.* | ||
|
||
inline def macroPolyFun[A](inline arg: A, inline f: [Z] => Z => String): String = | ||
${ macroPolyFunImpl[A]('arg, 'f) } | ||
|
||
private def macroPolyFunImpl[A: Type](arg: Expr[A], f: Expr[[Z] => Z => String])(using Quotes): Expr[String] = | ||
Expr(Expr.betaReduce('{ $f($arg) }).show) | ||
|
||
|
||
inline def macroFun[A](inline arg: A, inline f: A => String): String = | ||
${ macroFunImpl[A]('arg, 'f) } | ||
|
||
private def macroFunImpl[A: Type](arg: Expr[A], f: Expr[A => String])(using Quotes): Expr[String] = | ||
Expr(Expr.betaReduce('{ $f($arg) }).show) | ||
|
Oops, something went wrong.