Skip to content

Rename QuoteContext to Quotes #10432

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 Nov 21, 2020

QuoteContext is required on all signatures. To make it simpler to keep signatures on one line we shorten the name to Quotes. This name will usually be used in (using Quotes) which reads as using quotes and describes exactly why this contextual parameter is there for.

- def f[T: Type](x: Expr[T])(using QuoteContext): Expr[T] = ...
+ def f[T: Type](x: Expr[T])(using Quotes): Expr[T] = ...

@nicolasstucki nicolasstucki self-assigned this Nov 21, 2020
@nicolasstucki nicolasstucki force-pushed the shorten-name-of-quote-context branch 5 times, most recently from 9c973ed to fe6844e Compare November 21, 2020 18:18
@nicolasstucki nicolasstucki marked this pull request as ready for review November 21, 2020 18:59
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.

LGTM

using Quotes reads well, shorter, (almost) as clear in meaning as QuoteContext.

withQuotes is not as clear as withQuoteContext, but it only exists in the staging lib and not used in macros.

@@ -25,7 +25,7 @@ we need to implement a method `Eq.derived` on the companion object of `Eq` that
produces a quoted instance for `Eq[T]`. Here is a possible signature,

```scala
given derived[T: Type](using qctx: QuoteContext) as Expr[Eq[T]]
given derived[T: Type](using qctx: Quotes) as Expr[Eq[T]]
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the recommended name to replace qctx? qt or qs?

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 recommendation is not to name it. The question is what should we rename def qctx(using...)... to? I would like to try q as it would make it short for q.reflect.Tree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or we could call it quotes to have a meaningful name.

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 PR is quite large as it is. It might be better to rename that one in another PR

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd actually be in favour of renaming qctx to q, and also for creating qr as an alias to q.reflect.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think q is acceptable, given that common usage will make it clear. However, I find qr is too obscure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will use q as the standard parameter name (or no name). The contextual qctx will be renamed to quotes in #10442. #10442 also shows how to define your own alias (such as qr) in your project with a single line of code.

Copy link
Contributor

Choose a reason for hiding this comment

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

@liufengyun qr will stop being obscure if it will be the standard way to refer to the .reflect object. Based on my experience from the doctool codebase, I can tell you that qctx.reflect feels very verbose. Any codebase that uses Tasty Inspector seriously will run into the same sort of pain.

Anyway, given that we are migrating to an even more verbose name for qctx, I think we will define an alias for quotes.reflect in the doctool.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO introducing two magic names like q and qr will be too much for the learner.

I think defining a shorter name like qr for q.reflect in the user library is reasonable.

@nicolasstucki nicolasstucki force-pushed the shorten-name-of-quote-context branch from 4869939 to a5046b9 Compare November 22, 2020 08:38
@nicolasstucki nicolasstucki added this to the 3.0.0-M2 milestone Nov 22, 2020
@nicolasstucki nicolasstucki force-pushed the shorten-name-of-quote-context branch from a5046b9 to 90a3a79 Compare November 22, 2020 09:05
@nicolasstucki
Copy link
Contributor Author

@liufengyun the second commit renamed everything in the community build and in the compiler. This will need a review too.

@nicolasstucki nicolasstucki force-pushed the shorten-name-of-quote-context branch from 90a3a79 to 66c1463 Compare November 22, 2020 11:36
@nicolasstucki nicolasstucki force-pushed the shorten-name-of-quote-context branch 5 times, most recently from b5f183e to 5ef454c Compare November 23, 2020 09:52
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.

LGTM

`QuoteContext` is required on all signatures. To make it simpler to keep signatures on one line we shorten the name to `Quotes`. This name will usually be used in `(using Quotes)` which reads as _using quotes_ and descibes exactly why this contextual parameter is the.

```diff
- def f[T: Type](x: Expr[T])(using QuoteContext): Expr[T] = ...
+ def f[T: Type](x: Expr[T])(using Quotes): Expr[T] = ...
```
@nicolasstucki nicolasstucki force-pushed the shorten-name-of-quote-context branch from 54c6c34 to 80ed86a Compare November 23, 2020 12:49
@nicolasstucki nicolasstucki merged commit 37b4271 into scala:master Nov 23, 2020
@nicolasstucki nicolasstucki deleted the shorten-name-of-quote-context branch November 23, 2020 15:19
@Kordyjan Kordyjan removed this from the 3.0.0-M2 milestone Aug 2, 2023
@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.

4 participants