-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Keep QuoteContext found in typer for quoted.Type #8949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,13 @@ abstract class TreeMapWithStages(@constructorOnly ictx: Context) extends TreeMap | |
} | ||
|
||
tree match { | ||
case Apply(Select(Quoted(quotedTree), _), _) if quotedTree.isType => | ||
dropEmptyBlocks(quotedTree) match | ||
case Spliced(t) => | ||
// '[ x.$splice ] --> x | ||
transform(t) | ||
case _ => | ||
super.transform(tree) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the branch catch the case where the splice is in a big type, such as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
|
||
case Quoted(quotedTree) => | ||
val old = inQuoteOrSplice | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
object Test { | ||
def test(using quoted.QuoteContext) = { | ||
Macro.ff(3) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not clear why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test is awkward. The inline method is the one that requires the Previously it worked because we never used the The current approach homogeneously requires the quote context for all |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
object Test { | ||
given quoted.QuoteContext = ??? | ||
Macro.ff[Int] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
import scala.quoted._ | ||
|
||
|
||
inline def isFunctionType[T:Type]: Boolean = ${ isFunctionTypeImpl('[T]) } | ||
inline def isFunctionType[T]: Boolean = ${ isFunctionTypeImpl('[T]) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is nice, improves meta-programming experience a lot 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This proves the point made in the previous comment. Here the calls failed to compile and I noticed at once that we had an extra |
||
|
||
def isFunctionTypeImpl[T](tp: Type[T])(using qctx: QuoteContext) : Expr[Boolean] = { | ||
import qctx.tasty._ | ||
Expr(tp.unseal.tpe.isFunctionType) | ||
} | ||
|
||
|
||
inline def isContextFunctionType[T:Type]: Boolean = ${ isContextFunctionTypeImpl('[T]) } | ||
inline def isContextFunctionType[T]: Boolean = ${ isContextFunctionTypeImpl('[T]) } | ||
|
||
def isContextFunctionTypeImpl[T](tp: Type[T])(using qctx: QuoteContext) : Expr[Boolean] = { | ||
import qctx.tasty._ | ||
Expr(tp.unseal.tpe.isContextFunctionType) | ||
} | ||
|
||
|
||
inline def isErasedFunctionType[T:Type]: Boolean = ${ isErasedFunctionTypeImpl('[T]) } | ||
inline def isErasedFunctionType[T]: Boolean = ${ isErasedFunctionTypeImpl('[T]) } | ||
|
||
def isErasedFunctionTypeImpl[T](tp: Type[T])(using qctx: QuoteContext) : Expr[Boolean] = { | ||
import qctx.tasty._ | ||
Expr(tp.unseal.tpe.isErasedFunctionType) | ||
} | ||
|
||
inline def isDependentFunctionType[T:Type]: Boolean = ${ isDependentFunctionTypeImpl('[T]) } | ||
inline def isDependentFunctionType[T]: Boolean = ${ isDependentFunctionTypeImpl('[T]) } | ||
|
||
def isDependentFunctionTypeImpl[T](tp: Type[T])(using qctx: QuoteContext) : Expr[Boolean] = { | ||
import qctx.tasty._ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
val t: scala.quoted.Type[scala.Predef.String] = scala.internal.quoted.CompileTime.typeQuote[scala.Predef.String] | ||
((qctx: scala.quoted.QuoteContext) ?=> { | ||
val t: scala.quoted.Type[scala.Predef.String] = scala.internal.quoted.CompileTime.typeQuote[scala.Predef.String].apply(using qctx) | ||
|
||
(t: scala.quoted.Type[scala.Predef.String]) | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern does not seem to have enough guards, could it match unintended trees by accident?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The guard are inside the
Quoted
extractor. Only the compiler generates these trees and the rest of the shape is know. I will do a refactor of theQuoted
/Spliced
extractor at some point, but I would prefer to do it on it's own PR.