-
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.
Replace quoted type variables in signature of HOAS pattern result (#1…
…6951) To be able to construct the lambda returned by the HOAS pattern we need: first resolve the type variables and then use the result to construct the signature of the lambdas. To simplify this transformation, `QuoteMatcher` returns a `Seq[MatchResult]` instead of an untyped `Tuple` containing `Expr[?]`. The tuple is created once we have accumulated and processed all extracted values. Fixes #15165
- Loading branch information
Showing
9 changed files
with
164 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dotty.tools.dotc.util | ||
|
||
import scala.util.boundary | ||
|
||
/** Return type that indicates that the method returns a T or aborts to the enclosing boundary with a `None` */ | ||
type optional[T] = boundary.Label[None.type] ?=> T | ||
|
||
/** A prompt for `Option`, which establishes a boundary which `_.?` on `Option` can return */ | ||
object optional: | ||
inline def apply[T](inline body: optional[T]): Option[T] = | ||
boundary(Some(body)) | ||
|
||
extension [T](r: Option[T]) | ||
inline def ? (using label: boundary.Label[None.type]): T = r match | ||
case Some(x) => x | ||
case None => boundary.break(None) | ||
|
||
inline def break()(using label: boundary.Label[None.type]): Nothing = | ||
boundary.break(None) |
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,9 @@ | ||
import scala.quoted.* | ||
|
||
inline def valToFun[T](inline expr: T): T = | ||
${ impl('expr) } | ||
|
||
def impl[T: Type](expr: Expr[T])(using quotes: Quotes): Expr[T] = | ||
expr match | ||
case '{ { val ident = ($a: α); $rest(ident): T } } => | ||
'{ { (y: α) => $rest(y) }.apply(???) } |
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,4 @@ | ||
def test = valToFun { | ||
val a: Int = 1 | ||
a + 1 | ||
} |
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,16 @@ | ||
import scala.quoted.* | ||
|
||
inline def valToFun[T](inline expr: T): T = | ||
${ impl('expr) } | ||
|
||
def impl[T: Type](expr: Expr[T])(using quotes: Quotes): Expr[T] = | ||
expr match | ||
case '{ { val ident = ($a: α); $rest(ident): T } } => | ||
'{ | ||
{ (y: α) => | ||
${ | ||
val bound = '{ ${ rest }(y) } | ||
Expr.betaReduce(bound) | ||
} | ||
}.apply($a) | ||
} |
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,4 @@ | ||
def test = valToFun { | ||
val a: Int = 1 | ||
a + 1 | ||
} |
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,9 @@ | ||
import scala.quoted.* | ||
|
||
inline def valToFun[T](inline expr: T): T = | ||
${ impl('expr) } | ||
|
||
def impl[T: Type](expr: Expr[T])(using quotes: Quotes): Expr[T] = | ||
expr match | ||
case '{ type α; { val ident = ($a: `α`); $rest(ident): `α` & T } } => | ||
'{ { (y: α) => $rest(y) }.apply(???) } |
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,4 @@ | ||
def test = valToFun { | ||
val a: Int = 1 | ||
a + 1 | ||
} |