Open lfolger opened 6 months ago
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 https://github.com/golang/go/issues/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 debugFormatNode(caller.Fset...)
. Passing new(token.FileSet)
makes the logging deterministic though.]
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: internal/refactor/inline: fix comment movement due to added imports
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".
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).