Skip to content

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

Merged

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented May 11, 2020

We already do this for quoted terms. We missed this last one.
After this change, we won't need to do implicit search after pickling anymore.

  • Keep track of quote context in quoted types (as done in quoted terms)
  • Look for QuoteContext when synthesizing Type (instead of in ReifyQuotes)
  • Remove given from Type. XYZTag (already handled by synthesized types and quote reification)
  • Add missing QuoteContext in tests
  • Remove extra Type context bounds from tests (never needed)

@nicolasstucki nicolasstucki self-assigned this May 11, 2020
@nicolasstucki nicolasstucki force-pushed the find-quoted-type-context-early branch 6 times, most recently from 3b6f80c to 6746d17 Compare May 12, 2020 11:39
@nicolasstucki nicolasstucki requested a review from liufengyun May 12, 2020 12:34
@nicolasstucki nicolasstucki marked this pull request as ready for review May 12, 2020 12:34
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

// '[ x.$splice ] --> x
transform(t)
case _ =>
super.transform(tree)
Copy link
Contributor

Choose a reason for hiding this comment

The 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 '{ e: F[$x]}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

@@ -1,3 +1,3 @@
object Test {
def test(using quoted.QuoteContext) = {
Macro.ff(3)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not clear why using quoted.QuoteContext is necessary for macro usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 quoted.Type as an implicit. This might only be used to write a macro that is used in a macro implementation, hence the QuoteContext.

Previously it worked because we never used the Type and by chance it stayed encoded as a QuoteContext ?=> Type[T] which was never called. That is why we missed the need for a QuoteContext.

The current approach homogeneously requires the quote context for all Type quotes as we do with Expr quotes. This helps to find out missing QuoteContext early in the pipeline.

@@ -1,6 +1,6 @@
import scala.quoted._
def foo[T](using qctx: QuoteContext, tpe: Type[T]): Expr[Any] =
'{
'{ (qctx: QuoteContext) ?=>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary? BTW, the recommended syntax is (using QuoteContext) => e if I remember correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that is the quote context for the next stage. Similar reason as the previous one. Will change the syntax.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@@ -1,30 +1,30 @@
import scala.quoted._


inline def isFunctionType[T:Type]: Boolean = ${ isFunctionTypeImpl('[T]) }
inline def isFunctionType[T]: Boolean = ${ isFunctionTypeImpl('[T]) }
Copy link
Contributor

Choose a reason for hiding this comment

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

This is nice, improves meta-programming experience a lot 👍

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 proves the point made in the previous comment. Here the calls failed to compile and I noticed at once that we had an extra Type that was not needed.

@@ -92,6 +92,13 @@ abstract class TreeMapWithStages(@constructorOnly ictx: Context) extends TreeMap
}

tree match {
case Apply(Select(Quoted(quotedTree), _), _) if quotedTree.isType =>
Copy link
Contributor

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?

Copy link
Contributor Author

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 the Quoted/Spliced extractor at some point, but I would prefer to do it on it's own PR.

We already do this for quoted terms. We missed this last one.
After this change we won't need to do implicit search after pickling anymore.
@nicolasstucki nicolasstucki force-pushed the find-quoted-type-context-early branch from 6746d17 to 47a1586 Compare May 13, 2020 08:04
nicolasstucki and others added 2 commits May 13, 2020 12:01
@nicolasstucki nicolasstucki merged commit 22d841a into scala:master May 13, 2020
@nicolasstucki nicolasstucki deleted the find-quoted-type-context-early branch May 13, 2020 12:59
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.

2 participants