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

caching: remove optimization bringing false positive cache hits #145

Merged
merged 1 commit into from
Jul 10, 2020

Conversation

bjaglin
Copy link
Collaborator

@bjaglin bjaglin commented Jul 10, 2020

scalacenter/scalafix#1164 (comment)

If a file is patched during a scalafix run, it's not safe to assume that all rules observed the updated content of that file and thus can
be skipped next time. It is if we have only one rule (which we could check) or if the patch is applied after the first rule (which we can't tell). For correctness, stamping should happen before rule execution.

@@ -216,6 +217,7 @@ $ exec chmod 000 src/main/scala/Valid.scala
> scalafix --check ProcedureSyntax
-> test:scalafix --check ProcedureSyntax
> test:scalafix ProcedureSyntax
> test:scalafix ProcedureSyntax
Copy link
Collaborator Author

@bjaglin bjaglin Jul 10, 2020

Choose a reason for hiding this comment

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

a second run is needed for the cache to converge since there is a rewrite involved

> set scalafixConfig := None
$ mkdir src/test/scala
$ copy-file files/ProcedureSyntax.scala src/test/scala/ToPatch.scala
$ copy-file files/Valid.scala src/test/scala/Valid.scala
# avoid rounding in mtime that could cause false negatives in `newer`
$ sleep 1000
> test:scalafix ProcedureSyntax
> test:scalafix ProcedureSyntax DisableSyntax
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

adding a second rule for exhibiting the scenario, even though behavior is the same no matter how many rules we have (but it might change one day)

If a file is patched during a scalafix run, it's not safe to assume
that all rules observed the updated content of that file and thus can
be skipped next time. It is if we have only one rule (which we could
check) or if the patch is applied after the first rule (which we can't
tell). For correctness, stamping should happen before rule execution.
$ newer src/test/scala/ToPatch.scala src/test/scala/Valid.scala
$ exec chmod 000 src/test/scala/ToPatch.scala
$ exec chmod 000 src/test/scala/Valid.scala
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

irrelevant to the assertion, it's just useful to assert above via newer that ToPatch was updated

@bjaglin bjaglin marked this pull request as ready for review July 10, 2020 10:55
Copy link
Contributor

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

I'm not familiar enough with the sbt Tracked API to review the actual fix, but thank you for the quick followup! 🙏

@bjaglin bjaglin merged commit 66b5f29 into scalacenter:master Jul 10, 2020
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