Skip to content

Check flags for newMethod, newVal and newBind #16565

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
merged 2 commits into from
May 3, 2023

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

@nicolasstucki nicolasstucki force-pushed the macro-check-valid-flags branch from e4ddc97 to b60afdc Compare December 21, 2022 12:37
@nicolasstucki nicolasstucki marked this pull request as ready for review December 21, 2022 15:02
@nicolasstucki nicolasstucki force-pushed the macro-check-valid-flags branch from b60afdc to 164e407 Compare December 21, 2022 15:15
Comment on lines 4234 to 4235
* A trait that has only abstract methods as members
* and therefore can be represented by a Java interface.
Copy link
Member

Choose a reason for hiding this comment

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

That description looks incorrect abstract override is a specific concept in Scala that is unrelated to Java interfaces: https://www.scala-lang.org/files/archive/spec/2.13/05-classes-and-objects.html#abstract-override

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

This part of the documentation comment is for PureInterface, not for AbsOverride

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 updated the docs.

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 noticed that AbsOverride is pickled as Abstract | Override and then unpickled as AbsOverride. Maybe we should not have this flag in the reflection interface and handle AbsOverride as if both Abstract and Override.

Copy link
Member

Choose a reason for hiding this comment

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

I noticed that AbsOverride is pickled as Abstract | Override and then unpickled as AbsOverride. Maybe we should not have this flag in the reflection interface and handle AbsOverride as if both Abstract and Override.

I'm not sure diverging from the compiler implementation is a good idea here. In the specification, abstract override is a separate concept from abstract and override, it just reuses existing keywords. The tasty serialization format also reuses the flags bits, but that's just an optimization.

@@ -2484,13 +2486,28 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def newMethod(owner: Symbol, name: String, tpe: TypeRepr): Symbol =
newMethod(owner, name, tpe, Flags.EmptyFlags, noSymbol)
def newMethod(owner: Symbol, name: String, tpe: TypeRepr, flags: Flags, privateWithin: Symbol): Symbol =
import Flags.*
// TODO: missing AbsOverride
checkValidFlags(flags.toTermFlags, Private | Protected | Override | Deferred | Final | Method | Implicit | Given | Local | JavaStatic) // Synthetic | ExtensionMethod | Exported | Erased | Infix | Invisible
Copy link
Member

Choose a reason for hiding this comment

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

It would be nicer to create a val for each of these long lists of flags. Also couldn't this be checked in -Ycheck?

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 idea of the -Xcheck-macros flag is to help users find the location in their implementation where the bug started. Additionally, waiting until -Ycheck can result in other derived failures or crashes before we reach the checks.

@smarter smarter assigned nicolasstucki and unassigned smarter Jan 3, 2023
@nicolasstucki nicolasstucki force-pushed the macro-check-valid-flags branch 2 times, most recently from 9fdfb4a to 09cf574 Compare January 9, 2023 12:07
@nicolasstucki nicolasstucki requested a review from smarter January 10, 2023 08:54
@nicolasstucki nicolasstucki force-pushed the macro-check-valid-flags branch from 959064f to a85d0ea Compare February 7, 2023 12:47
@nicolasstucki nicolasstucki force-pushed the macro-check-valid-flags branch from a85d0ea to a4db0c1 Compare March 9, 2023 10:16
@nicolasstucki nicolasstucki force-pushed the macro-check-valid-flags branch from a4db0c1 to 91a6b57 Compare April 25, 2023 13:24
Comment on lines 2858 to 2860
private[QuotesImpl] def validMethodFlags: Flags = Private | Protected | Override | Deferred | Final | Method | Implicit | Given | Local | JavaStatic | AbsOverride // Synthetic | ExtensionMethod | Exported | Erased | Infix | Invisible
private[QuotesImpl] def validValFlags: Flags = Private | Protected | Override | Deferred | Final | Param | Implicit | Lazy | Mutable | Local | ParamAccessor | Module | Package | Case | CaseAccessor | Given | Enum | JavaStatic | AbsOverride // Synthetic | Erased | Invisible
private[QuotesImpl] def validBindFlags: Flags = Case // | Implicit | Given | Erased
Copy link
Member

Choose a reason for hiding this comment

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

What are the commented-out flags meant to represent? A comment might be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comments

@@ -2842,6 +2854,10 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def Synthetic: Flags = dotc.core.Flags.Synthetic
def Trait: Flags = dotc.core.Flags.Trait
def Transparent: Flags = dotc.core.Flags.Transparent

private[QuotesImpl] def validMethodFlags: Flags = Private | Protected | Override | Deferred | Final | Method | Implicit | Given | Local | JavaStatic | AbsOverride // Synthetic | ExtensionMethod | Exported | Erased | Infix | Invisible
Copy link
Member

Choose a reason for hiding this comment

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

  • It looks like the list here is duplicated in the documentation of newMethod, we should add a comment here to remember to update the list in the documentation.
  • I don't think users can create JavaStatic methods.

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 don't think users can create JavaStatic methods.

We have one use case of this with the main macro annotation in tests/run-macros/annot-macro-main.

@@ -3816,7 +3816,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
*
* @param parent The owner of the binding
* @param name The name of the binding
* @param flags extra flags to with which the symbol should be constructed
* @param flags extra flags to with which the symbol should be constructed. `Case` flag will be added. Can be `Case`
Copy link
Member

Choose a reason for hiding this comment

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

If Case is always added and Case is the only valid flag, it sounds like this parameter is not actually necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the future, we might have more flags (see validBindFlags).

We could add an overload of newBind that does not require the flags.

@smarter smarter assigned nicolasstucki and unassigned smarter Apr 28, 2023
@nicolasstucki nicolasstucki force-pushed the macro-check-valid-flags branch from d3a9810 to d04a7e2 Compare May 2, 2023 09:13
@nicolasstucki nicolasstucki force-pushed the macro-check-valid-flags branch from d04a7e2 to 3c3c0fb Compare May 2, 2023 09:20
@nicolasstucki nicolasstucki requested a review from smarter May 3, 2023 13:05
@smarter smarter merged commit b8d2966 into scala:main May 3, 2023
@smarter smarter deleted the macro-check-valid-flags branch May 3, 2023 13:11
@Kordyjan Kordyjan added this to the 3.3.1 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