Repository navigation
cmp: keep cycle-reference reporting specific to each side - #414
Open
adenzhou1350 wants to merge 3 commits into
Open
adenzhou1350 wants to merge 3 commits into
adenzhou1350 wants to merge 3 commits into
Conversation
Signed-off-by: Xucheng Zhou <aden1350@outlook.com>
Signed-off-by: Xucheng Zhou <aden1350@outlook.com>
There was a problem hiding this comment.
Code Review
This pull request refactors the cycle detection logic in go-cmp to correctly handle cross-side cycle references. It changes pointerReferences from a slice to a struct with a stack and a side indicator, and introduces a Split method to project ancestors onto each side of the comparison. This prevents formatting one side from incorrectly stopping at an ancestor that only exists on the other side. Tests are added to verify this behavior. Feedback on the changes suggests adding explicit parentheses to a complex boolean expression in report_references.go to clarify operator precedence and improve readability.
Signed-off-by: Xucheng Zhou <209601943+adenzhou1350@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #284.
When formatting a single left or right value, the reporter currently checks for cycles against ancestors from both arguments. A pointer that only occurs on the opposite side can therefore truncate the current value too early, leaving indistinguishable removed and inserted lines.
Keep paired ancestors for the combined diff, but use side-specific stack views when formatting individual values. The views preserve ordinary cycle detection without copying the ancestor stacks. Comparison/equality semantics are unchanged.
Validation on Linux/amd64, Go 1.26.9:
go test ./...andgo test -race ./...pass, with existing golden reports unchanged.AllowUnexported, now expands the left-side nested structure while retaining the right-side back-reference.Developed and validated with assistance from OpenAI Codex. The upstream Go/OS CI matrix remains to run.