Skip to content
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

Deduplicate JavaDeprecatedAttr in ClassfileParser #10422

Merged
merged 1 commit into from Jul 5, 2023

Conversation

som-snytt
Copy link
Contributor

@scala-jenkins scala-jenkins added this to the 2.13.12 milestone Jun 6, 2023
@SethTisue SethTisue added prio:blocker release blocker (used only by core team, only near release time) release-notes worth highlighting in next release notes labels Jun 7, 2023
@SethTisue
Copy link
Member

👀

!!    1 - run/t9644.scala                           [output differs]
% diff /home/jenkins/workspace/scala-2.13.x-validate-main/test/files/run/t9644.check /home/jenkins/workspace/scala-2.13.x-validate-main/test/files/run/t9644-run.log--- empty
+++ t9644-run.log
@@ -1,0 +1,42 @@
+scala.MatchError: new java.lang.annotation.Retention(value = RUNTIME) (of class scala.reflect.internal.Trees$Apply)
+	at Test$.delayedEndpoint$Test$1(t9644.scala:14)
+	at Test$delayedInit$body.apply(t9644.scala:5)
+	at scala.Function0.apply$mcV$sp(Function0.scala:42)

@som-snytt
Copy link
Contributor Author

som-snytt commented Jun 7, 2023

This implements the old hrhino suggestion to maintain annotation order in sym.addAnnotation, which changes the order for annotations other than runtime attrs read by class file parser.

Still need to check whether there was a general assumption that annotations from source were built in reverse.

@som-snytt som-snytt force-pushed the issue/12799-inherited-annots branch from 0ebbcae to b2eda2d Compare June 7, 2023 03:26
@som-snytt
Copy link
Contributor Author

My first edit retained last added annotation, which I changed when I fixed the failing test. It makes sense to prefer the DeprecatedAttr to its runtime twin; probably they are identical. Scala annotations maybe be multiple, such as throws.

@som-snytt som-snytt marked this pull request as ready for review June 7, 2023 19:34
@som-snytt som-snytt marked this pull request as draft June 10, 2023 18:03
@som-snytt
Copy link
Contributor Author

Reminder to self to check how deprecation is emitted.

@som-snytt som-snytt force-pushed the issue/12799-inherited-annots branch from b2eda2d to 5c32b00 Compare June 10, 2023 21:51
@som-snytt
Copy link
Contributor Author

This now implements the lrytz suggestion to confine the special handling to class file parser.

@som-snytt som-snytt force-pushed the issue/12799-inherited-annots branch from abadc56 to 334a256 Compare June 11, 2023 20:09
@som-snytt
Copy link
Contributor Author

Of course the since test must be constrained to javaVersion: 9+, as Lukas had mentioned on an old ticket somewhere. So the neg test is for that check, and the run test always runs (so however CI is set up, it must undergo a jdk 8 test).

@som-snytt som-snytt marked this pull request as ready for review June 13, 2023 17:46
@som-snytt som-snytt changed the title Only ingest matching Java attributes once Only ingest matching Java attributes once [ci: last-only] Jun 16, 2023
@som-snytt som-snytt changed the title Only ingest matching Java attributes once [ci: last-only] Deduplicate JavaDeprecatedAttr in ClassfileParser [ci: last-only] Jun 16, 2023
test/files/neg/t12799.check Outdated Show resolved Hide resolved
test/files/run/t9644.scala Outdated Show resolved Hide resolved
@som-snytt
Copy link
Contributor Author

Thanks, I was so consumed with the previous edit that I did not drill down to answer your question.

@lrytz
Copy link
Member

lrytz commented Jun 21, 2023

Are we sure that the DeprecatedATTR is visited before the anntoation, or should we safe-guard there too? https://github.com/scala/scala/blob/v2.13.11/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala#L827-L831

Also, for the attribute we also add an annotation to the synthetic companion module symbol, but we don't do so for the annotation. This means the "since" message doesn't show when accessing a static member:

scala> new A
           ^
       warning: class A is deprecated (since you like it)
val res0: A = A@2c26ba07

scala> A.foo
       ^
       warning: class A is deprecated

@som-snytt
Copy link
Contributor Author

I intended not to assume DeprecatedATTR is seen before the runtime attr, which is why the previous edit touched addAnnotation, but I neglected to update that spot to use the new method on the last refactor.

I'll tackle Nr 2 after coffee.

@som-snytt
Copy link
Contributor Author

som-snytt commented Jul 2, 2023

I noticed on a recent dotty ticket about @BeanProperty that Scala treats @Deprecated as an ordinary annotation only. But @deprecated distributes deprecation attribute to all var accessors. I haven't checked for the Scala annotation yet.

Edit: @deprecated winds up on everything, including both mutators if @BeanProperty. Actually the meta annots are listed in the Scaladoc.

bean.scala:34: warning: variable y in class Bean is deprecated (since 0.1): Bad var
  def reset() = b.y = 0
                  ^
bean.scala:35: warning: method setY in class Bean is deprecated (since 0.1): Bad var
  def kill() = b.setY(0)
                 ^

@som-snytt
Copy link
Contributor Author

som-snytt commented Jul 2, 2023

Last commit addresses both review comments: There is no reason to assume attribute ordering, so don't add plain deprecated if it already has it. There is no test. When adding the annotation, also check the static module, verified by test.

Did not squash! (My tweaking should be squashed.)

test/files/run/t12799/C.java Outdated Show resolved Hide resolved
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

LGTM otherwise. I think this can be a single commit.

In particular, do not retain two copies.

Preserve annotation order although not meaningful.

Co-authored-by: Lukas Rytz <lukas.rytz@gmail.com>
@som-snytt som-snytt force-pushed the issue/12799-inherited-annots branch from 54ebd41 to 287d33c Compare July 5, 2023 08:45
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

Thank you !

@som-snytt som-snytt changed the title Deduplicate JavaDeprecatedAttr in ClassfileParser [ci: last-only] Deduplicate JavaDeprecatedAttr in ClassfileParser Jul 5, 2023
@lrytz lrytz merged commit 5148ddd into scala:2.13.x Jul 5, 2023
3 checks passed
@som-snytt som-snytt deleted the issue/12799-inherited-annots branch July 5, 2023 10:50
@SethTisue SethTisue removed the prio:blocker release blocker (used only by core team, only near release time) label Jul 6, 2023
dongjoon-hyun pushed a commit to apache/spark that referenced this pull request Sep 30, 2023
### What changes were proposed in this pull request?
This pr aims to upgrade Scala from 2.13.11 to 2.13.12.

Additionally, this pr adds ``-Wconf:msg=legacy-binding:s`` to suppress similar compiler warnings as below:

```
[ERROR] /Users/yangjie01/SourceCode/git/spark-mine-13/core/src/main/scala/org/apache/spark/deploy/client/StandaloneAppClient.scala:171: reference to stop is ambiguous;
it is both defined in the enclosing class StandaloneAppClient and inherited in the enclosing class ClientEndpoint as method stop (defined in trait RpcEndpoint, inherited through parent trait ThreadSafeRpcEndpoint)
In Scala 2, symbols inherited from a superclass shadow symbols defined in an outer scope.
Such references are ambiguous in Scala 3. To continue using the inherited symbol, write `this.stop`.
Or use `-Wconf:msg=legacy-binding:s` to silence this warning. [quickfixable]
Applicable -Wconf / nowarn filters for this fatal warning: msg=<part of the message>, cat=other, site=org.apache.spark.deploy.client.StandaloneAppClient.ClientEndpoint.receive
```

### Why are the changes needed?
The new version bring some regression fixes:
- scala/scala#10422
- scala/scala#10424

And a new feature: Quickfixes
```
For some errors and warnings, the compiler now suggests an edit that could fix the issue. Tooling such as IDEs can then offer the edits, or the compiler itself will make the change if run again with -quickfix.
```
- scala/scala#10406
- scala/scala#10482
- scala/scala#10484

The release notes as follows:
- https://github.com/scala/scala/releases/tag/v2.13.12

### Does this PR introduce _any_ user-facing change?
Yes, Scala version changed.

### How was this patch tested?
Pass Github

### Was this patch authored or co-authored using generative AI tooling?
NO

Closes #43185 from LuciferYang/SPARK-45331.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
4 participants