Skip to content

Encode quote pattern matches directly on QuoteContext #10246

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

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Nov 9, 2020

Encode quote pattern matches directly on QuoteContext.

Also, split Expr.ofTupleFromSeq into parts to use switch and reduce code size.
That method had 200+ quoted pattern matches.

Part of #10222

Also split `Expr.ofTupleFromSeq` into parts to use switch and reduce code size.
That method had 400+ quoted pattern matches.
@nicolasstucki nicolasstucki force-pushed the encode-quote-pattern-match-directly-on-quote-context branch from deecadf to 330cc0b Compare November 9, 2020 15:57
@nicolasstucki nicolasstucki marked this pull request as ready for review November 9, 2020 16:29
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, LGTM

@@ -18,7 +18,8 @@ abstract class Expr[+T] private[scala] {
* ```
*/
final def matches(that: Expr[Any])(using qctx: QuoteContext): Boolean =
!scala.internal.quoted.Expr.unapply[EmptyTuple, EmptyTuple](this)(using that, qctx).isEmpty
val ExprMatch = qctx.asInstanceOf[scala.internal.quoted.QuoteContextInternal].ExprMatch
ExprMatch.unapply[EmptyTuple, EmptyTuple](this)(using that).nonEmpty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the usage, it seems to me ExprMatch and TypeMatch does not make it simpler. Do we have places where they are used as extractors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only place in the library where it is needed. But I plan to move this implementation out of the library and then I might not even need to have this call and could call the tree pattern matcher directly.

This is another method that should only be called from code generated by the compiler.

@nicolasstucki nicolasstucki merged commit 819e0b1 into scala:master Nov 9, 2020
@nicolasstucki nicolasstucki deleted the encode-quote-pattern-match-directly-on-quote-context branch November 9, 2020 17:32
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants