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
Deprecate ClassfileAnnotation, introduce ConstantAnnotation #6143
Conversation
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.
Looks good. I got 99% through the review and then interrupted again.
@@ -1989,6 +1972,16 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper | |||
if (clazz.info.firstParent.typeSymbol == AnyValClass) | |||
validateDerivedValueClass(clazz, body3) | |||
|
|||
if (!clazz.isTrait && clazz.isNonBottomSubClass(ConstantAnnotationClass)) { |
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.
How about the restriction on classfile annotations that they could not be inner classes?
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.
Ah, I see this is caught by https://github.com/scala/scala/pull/6143/files#diff-4eab1aad4533a31c10565971e90f73eaR3738 (else if (!annType.typeSymbol.isJavaDefined)
)
I tried to resolve the conflicts with the web editor (cool!), but the UI hasn't caught up? |
@adriaanm Wow the web editor is pretty cool indeed 😍 |
Some by-name fails due to my incomplete merge?
|
These test failures are in current 2.13.x, since the merge of #6092 / https://github.com/scala/scala/commits/8272151ac87628e2f1165547ff4b794f3226bbbc |
In scala#6092, `-Xsource:2.13` was enabled by default. Between this PRs parent and current 2.13.x, there were some changes that depended on this flag (scala#5983, scala#6069).
Annotations that need to be written to the classfile in the Java-compatible format need to be defined in Java. Scala annotations extending ConstantAnnotation can only accept compile-time constants as argument. The implementation represents constant annotations using the `assocs` field in the AnnotationInfo, just like for Java-defined annotations. The implementation for getting the constants and building the `assocs` is the same as for Java annotations, and the same restrictions apply: arguments need to be passed as named arguments (except if there's a single argument defining the `value` parameter). This is a bit of an ad-hoc restriction for Scala-defined constant annotations, but changing it to accept positional args went over my time budget (there's no easy way to reuse the code that deals with named arguments in general). Internally, we still add the `StaticAnnotation` parent to Java-defined annotations (in the Classfile parser, Java source parser, runtime reflection) to make sure that Java annotations are not only emitted to the classfile in the Java format, but also pickled.
Also enforce the primary constructor to have a single argument list. Clarify the Scaladoc of ConstantAnnotation.
ping @adriaanm |
FTR, this change seems to be causing some temporary problems when working on the 2.13.x branch. The reference compiler, 2.13.0-M2, incorrectly typechecks This causes a failure in |
@retronym the failure only shows up when using the reference compiler with a current 2.13.x version of the library on the class- / sourcepath, not on CI where we bootstrap, correct? Would you like me to do something about it? M3 is coming out soon... |
Yes, the problem appears specific to local development without bootstrapping. I think we can just wait for the next release. I just wanted to note the problem for posterity on the off chance that it helps someone else avoid debugging it :) With the benefit of hindsight, we might have been better to defer changing our annotations to the non-deprecated parent types until the next STARR update. |
Annotations that need to be written to the classfile in the
Java-compatible format need to be defined in Java.
Scala annotations extending ConstantAnnotation can only accept
compile-time constants as argument. The implementation represents
constant annotations using the
assocs
field in the AnnotationInfo,just like for Java-defined annotations. The implementation for getting
the constants and building the
assocs
is the same as for Javaannotations, and the same restrictions apply: arguments need to be
passed as named arguments (except if there's a single argument defining
the
value
parameter). This is a bit of an ad-hoc restriction forScala-defined constant annotations, but changing it to accept positional
args went over my time budget (there's no easy way to reuse the code
that deals with named arguments in general).
Internally, we still add the
StaticAnnotation
parent to Java-definedannotations (in the Classfile parser, Java source parser, runtime
reflection) to make sure that Java annotations are not only emitted to
the classfile in the Java format, but also pickled.