Skip to content

Replace scala.quoted.qctx with scala.quoted.reflect #10289

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

Closed

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Nov 12, 2020

The only reason we added qctx was to have a simple way to access the reflection in context using qctx.reflect. There are no other uses of this method. It is much simpler for users if they a provided with the method reflect that those the same as qctx.reflect. The name qctx is also a bit obscure and is not that simple to identify in the API.

To use reflection inside a method

def f(using QuoteContext) = { // or (using qctx: QuoteContext)
-   import qctx.reflect._ // equivalent to import qctx.reflect._
+   import reflect._ // equivalent to import qctx.reflect._
  ...
}

or to use reflection in the signature of a method

- def f(using QuoteContext)(tree: qctx.reflect.Tree): qctx.reflect.Position = ...
+ def f(using QuoteContext)(tree: reflect.Tree): reflect.Position = ...

@nicolasstucki nicolasstucki self-assigned this Nov 12, 2020
@liufengyun
Copy link
Contributor

Is the Scala 3 feature going to stay? The worry I have is that either Scala 3 drops the feature or it makes Scala 3 difficult to drop the feature.

@nicolasstucki nicolasstucki force-pushed the replace-qctx-with-reflect branch from 4cd4497 to ddc1bb3 Compare November 12, 2020 10:14
@nicolasstucki
Copy link
Contributor Author

Which feature?

@nicolasstucki nicolasstucki force-pushed the replace-qctx-with-reflect branch from ddc1bb3 to b85f2fc Compare November 12, 2020 14:22
@liufengyun
Copy link
Contributor

Which feature?

I mean the following:

def reflect(using qctx: QuoteContext): qctx.reflect.type = qctx.reflect

@smarter
Copy link
Member

smarter commented Nov 12, 2020

I don't understand how this works, reflect is a def so it's not stable, and we're only supposed to allow import from stable prefixes unless something changed? (Also when I see import reflect._ I would assume it's about scala.reflect).

@smarter
Copy link
Member

smarter commented Nov 12, 2020

#10295

@nicolasstucki
Copy link
Contributor Author

That def returns a stable path and it is that path that is taken into account for the stability.

def reflect(using q: QuoteContext): q.reflect.type = q.reflect

def f(using q: QuoteContext)
  // reflect.Tree   ==>    reflect(q).Tree   ==>   q.reflect.Tree
  import reflect.Tree

@nicolasstucki
Copy link
Contributor Author

Is the Scala 3 feature going to stay? The worry I have is that either Scala 3 drops the feature or it makes Scala 3 difficult to drop the feature.

Which feature?

I mean the following:

def reflect(using qctx: QuoteContext): qctx.reflect.type = qctx.reflect

We need to support that, it is equivalent to a more concrete version of summon.

inline def summon[T](using x: T): x.type = x

If we would drop the feature we would have to remove summon.

@nicolasstucki nicolasstucki force-pushed the replace-qctx-with-reflect branch 4 times, most recently from 96f3759 to 69890f9 Compare November 19, 2020 08:29
@nicolasstucki nicolasstucki force-pushed the replace-qctx-with-reflect branch from 69890f9 to 4286623 Compare November 20, 2020 16:15
@nicolasstucki nicolasstucki marked this pull request as ready for review November 21, 2020 18:16
* def f(using QuoteContext)(tree: reflect.Tree): reflect.Position = ...
* ```
*/
def reflect(using qctx: QuoteContext): qctx.reflect.type = qctx.reflect
Copy link
Contributor

Choose a reason for hiding this comment

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

What about #10295 ? There is no precedent in the language where we can import an unstable prefix. Or at least, with inline and checks?

Meanwhile, it seems to me that import qctx.reflect._ is better than import reflect._, as the former tells some information about the relationship between qctx and reflect, while the latter makes me wonder what's the magic behind.

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