-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/internal/refactor/inline: analyzer is non-deterministic #67335
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
Comments
cc: @adonovan |
Thanks for the very helpful test case, which reproduces the bug for me. My immediate guess as to the cause is that the order in which the files (e.g. caller and callee) are added to the token.FileSet is nondeterministic, and that the relative token.Pos values affect the formatter logic that decides when to insert a line break. (That would make this a symptom of #20744.) [Update: doesn't seem to be exactly that. The Pos values of caller and callee are completely deterministic in the test. When I enable logging (Options.Logf) I notice that the logged binding decl has the same nondeterminism problem in isolation when printed with |
Seems like this is not going to make it to v0.17. @adonovan it sounds like you've spent some time thinking about this -- is there a quick fix? |
Change https://go.dev/cl/629979 mentions this issue: |
I could not reproduce this, I'm afraid. I suspect it has to do with the offsets caused by import reformatting, which I have fixed in #67336. Therefore, I think this fixed but can't be sure, so I'll bump to the next release. |
Running the test exactly as it appears in the issue body, I can still reproduce the failure nondeterministically (20%) at master (1e0d4ee). I also notice that the output deterministically (100%) includes a blank line after the import of "context". |
Logically separate the rewriting of imports from the rest of the file, so that floating comments don't wander into the import block. Fixes golang/go#67336 Updates golang/go#67335 Change-Id: I14bcbe1d15bf9abaed7535bdcf871b25c47c9a11 Reviewed-on: https://go-review.googlesource.com/c/tools/+/629979 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
Just ran into this in a test I added, and could reproduce reliable within a couple seconds. The problem is (again) that we're formatting callee nodes using the caller fset. If ever the callee positions are actually in range of a file in the caller fileset, we can end up with an erroneous line break in between nodes. I have a fix, which is to clear positions correctly before we ever splice in callee nodes. |
Change https://go.dev/cl/633256 mentions this issue: |
Change https://go.dev/cl/633718 mentions this issue: |
Go version
not relevant
Output of
go env
in your module/workspace:What did you do?
While preparing the reproducer for (https://go.dev/issue/67336), I encounter non-determinism in the analyzer or test-framework. I don't know if there is a smaller reproducer either.
What did you see happen?
Sometimes the test fails (non-deterministically) with:
I don't know if this is an issue with the test framework or with the analyzer.
What did you expect to see?
I would expect the test to always pass (minus the bug tracked in https://go.dev/issue/67336).
The text was updated successfully, but these errors were encountered: