-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Deprecate old Expr
value extractors
#10684
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
nicolasstucki
merged 1 commit into
scala:master
from
dotty-staging:depricate-old-Const-extractor
Dec 8, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I remember in the meeting we agree to keep
Const
as an extractor. Or I misunderstood?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.
We keep it in
scala.quoted.util
as it duplicates logic inscala.quoted
. This is the only responsable action as we could add it back inscala.quoted
but we would not be able to remove it.It is already in
scala.quoted.util
.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.
It will be a pity that when a meta-programmer wants to pattern macher on a constant (which is a common need as we know in meta-programming), he has to add another library as a dependency.
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 point is that they can do it using
.value
orExpr
. Both cover all the cases thatConst
covers without the performance penalty and with better warnings in the pattern matching. It would be a pity to give them a version that is just tempting to use due to its name, but is always a worse option.We have already seen that all uses cases in our test and in the community-build where better with
.value
/Expr
. We do not have any remaining places were we would useConst
.Explaining this extractor to new users is also unnecessarily hard and confusing. After introducing
.value
/Expr
we need to tell them that they can optionally use this other variant that does less and is less performant. Why would a user want to use it then? Then the next step is to tell them that theConst
extractor does not matchConstant
, the reason being thatConst
matches whatExpr
matches but only for primitive types. This amount of confusion is too much. I know what is the difference between those extractors, but even you, having worked with them for a long time, have show confusion about the differences.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.
I basically agree with this. However, we cannot exclude some use cases where the usage of
Const(v)
in pattern matching is more convenient. If I were correct, the typical textbook examplepower
is one such usage.On the other hand, something is missing at the conceptual level if there is no capability to directly pattern match on literals, while it is possible to do so on other syntactic forms. If we remove this capability, it would be good to remove pattern matching on quotes completely, and only keep tree pattern matching in reflect, which IMHO is a reasonable choice.
It seems to me in meta-programming, inspecting literals is very natural, and having a dedicated extractor for that will not cause problems.
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.
You mean the following
power
?How would that benefit from using
Const
orExpr
? We could do the following but it only has drawbacks. CallingConst.unapply
is more expensive than.value
and we need to call it twice instead of once.We have a dedicated concept for it which is called
FromExpr
and used byExpr.unapply
. Calling itConst
orLiteral
only leads to confusion as those do not matchConstant
s orLiteral
s. They match whatExpr
matches. It does not make any sense overload concepts and bloat the API with duplicated logic. It is simpler to explainExpr
and be done with it rather than giving them another option that does less but requires the understanding theExpr
first.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.
Thanks for correcting my memory. I have in mind use cases like
case '{ power(${const(x)}. $y) } => ...
, where the usage of extractors are more convenient than.value
.It seems to be the exact reason why it cannot be renamed --- because
Expr.unapply
is not dedicated for pattern matching on literals. Missing a dedicated extractor for a category of syntactic forms seems to be a flaw at the coneptual level.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.
It could be renamed as shown in #10673. But there was some backlash against that. Either way, we cannot add every of the extractor in the library. This is why
scala.quoted.util
was created. This way we can provide different more specialized extractors such asConst
,Value
,StringContextExpr
, ... . All those extractors that are not required or not necessarily practical to all users.I cannot spend more days fixing this issue. We should just merge it. Users will be able to use trivially the
scala.quoted.util.Const
instead or other variants that we might come up with that is more inline with their goals. If in the future we see actual use cases, then we can consider moving it toscala.quoted
.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.
There might be arguments for the design I'm not aware of. Please do what makes sense.