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

Keep annotation order #15063

Merged
merged 1 commit into from
Apr 28, 2022
Merged

Conversation

raboof
Copy link
Contributor

@raboof raboof commented Apr 28, 2022

This change makes sure non-repeated annotations are kept in the order
they were found in the source code.

The motivation is not necessarily to have them in the original order,
but to have them in an order that is deterministic across rebuilds
(potentially even across different machines), for reasons discussed
further in #7661 and the corresponding scala/scala-dev#405

I tried adding an 'integration test' in tests/pos to be picked up by IdempotencyCheck.scala, but unfortunately couldn't reproduce the nondeterminism that way , so didn't end up including it in this commit.

I didn't see an obvious place for a 'unit test' of this code, I'd be
happy to add one when someone can recommend a good place to put it.

This is basically the dotty equivalent of
scala/scala@954c5d3

Fixes #14743

@raboof raboof force-pushed the keep-annotation-order-fixing-14743 branch from e5a22d2 to d359e08 Compare April 28, 2022 15:21
@smarter
Copy link
Member

smarter commented Apr 28, 2022

I tried adding an 'integration test' in tests/pos to be picked up by
IdempotencyCheck.scala, but unfortunately couldn't reproduce the
nondeterminism that way, so didn't end up including it in this commit.

I think it's worth adding a test even if you can't get it to fail for reference here, can you reproduce the problem by manually compiling that file multiple times?

@raboof raboof force-pushed the keep-annotation-order-fixing-14743 branch from d359e08 to 4d772b4 Compare April 28, 2022 15:31
Comment on lines +5 to +6
@Enabled
@Deprecated
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the test involve using the same annotation multiple times to trigger use of RepeatableAnnotations, like in scala/scala@954c5d3#diff-8bd66281732306fbd83125f4c1bba7a81797b9ed31a0857afb0b805dd6e1fe6cR258-R262 ?

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 guess that would also be useful to test, though it wasn't the scenario I was aiming to fix: because the 'annotations.groupBy(_.symbol)` doesn't have a predictable order of keys, even regular 'unrepeated' annotations would not necessarily end up in the bytecode in the same order.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I didn't realize that this code wasn't simply bypassed when no repeated annotations exist. But yeah, if you could copy the tests that are in the scala 2 PRs that would be nice: to compile multiple files at once (the .java annotation definition and the scala usage) you can create a subdirectory in tests/pos.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha, added!

@raboof
Copy link
Contributor Author

raboof commented Apr 28, 2022

I tried adding an 'integration test' in tests/pos to be picked up by
IdempotencyCheck.scala, but unfortunately couldn't reproduce the
nondeterminism that way, so didn't end up including it in this commit.

I think it's worth adding a test even if you can't get it to fail for reference here

Ok, added!

can you reproduce the problem by manually compiling that file multiple times?

No, unfortunately not...

@raboof raboof force-pushed the keep-annotation-order-fixing-14743 branch from 4d772b4 to 793304e Compare April 28, 2022 18:34
@raboof raboof requested a review from smarter April 28, 2022 18:53
@smarter smarter enabled auto-merge April 28, 2022 19:03
@@ -0,0 +1,2 @@
class Annot1(s: String) extends scala.annotation.StaticAnnotation
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these tests meant to be under tests/pos/ rather than directly under tests/?

Copy link
Member

Choose a reason for hiding this comment

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

oh indeed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, updated

@smarter smarter disabled auto-merge April 28, 2022 19:09
@@ -0,0 +1,2 @@
class Annot1(s: String) extends scala.annotation.StaticAnnotation
Copy link
Member

Choose a reason for hiding this comment

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

oh indeed

This change makes sure non-repeated annotations are kept in the order
they were found in the source code.

The motivation is not necessarily to have them in the original order,
but to have them in an order that is deterministic across rebuilds
(potentially even across different machines), for reasons discussed
further in scala#7661 and the corresponding scala/scala-dev#405

Some integration tests were added in `tests/pos` to be picked up by
`IdempotencyCheck.scala`, but unfortunately I haven't successfully
reproduced the nondeterminism that way.

I didn't see an obvious place for a 'unit test' of this code, I'd be
happy to add one when someone can recommend a good place to put it.

This is basically the dotty equivalent of
scala/scala@954c5d3

Fixes scala#14743
@raboof raboof force-pushed the keep-annotation-order-fixing-14743 branch from 793304e to 414091f Compare April 28, 2022 19:56
@raboof raboof requested review from smarter and griggt April 28, 2022 19:58
@smarter smarter enabled auto-merge April 28, 2022 20:02
@smarter smarter merged commit 35b1084 into scala:main Apr 28, 2022
@Kordyjan Kordyjan added this to the 3.2.0 milestone Aug 1, 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.

order of annotations in produced bytecode is not deterministic
4 participants