fix(diff): pair colliding facts positionally instead of last-write-wins - #81
Merged
Conversation
factKey is not unique and no prop can make it so: Swift declares the same
class twice under mutually exclusive #if/#else branches, overloaded methods
share a name and symbol_kind, and a dependency fact's name already embeds
its import target, so two imports of one target in one file are identical in
name, props and relations. Such facts differ only by line, and line may not
enter identity (diff.go:388, TestCompute_LineShiftIsNotAChange).
Keying them into a map[string]Fact silently dropped all but one. Two symptoms:
- Deleting a dropped fact produced no diff entry at all. 172 facts across
three corpus repos were absent from the diff's map entirely.
- The on-disk baseline and the in-memory current iterate facts in different
orders, so the surviving representative differed between the two sides and
diff_snapshot reported a changed fact between byte-identical fact sets.
groupByKey now buckets facts into map[string][]Fact, sorts each bucket by
intraGroupOrder (line, propsJSON, relationsJSON), and pairs the two sides
positionally. Line is used only as an ordinal within a group that already
shares an identity; it never enters factKey, so a lone fact that merely moves
is still unchanged.
sortAll orders by factSortKey rather than factKey. Once colliding facts both
survive, factKey no longer totally orders them, and the collections are built
by ranging over a map -- sort.Slice would have left their order to Go's
randomized map iteration, breaking the package's byte-identical-output promise.
The KindRoute/KindStorage discriminators are kept. They are no longer
load-bearing for correctness but still pair a route's GET and DELETE facts by
method rather than by position.
No cacheVersion bump: internal/diff emits no facts. Verified -- facts.jsonl
hashed identically before and after.
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.
factKey is not unique and no prop can make it so: Swift declares the same class twice under mutually exclusive #if/#else branches, overloaded methods share a name and symbol_kind, and a dependency fact's name already embeds its import target, so two imports of one target in one file are identical in name, props and relations. Such facts differ only by line, and line may not enter identity (diff.go:388, TestCompute_LineShiftIsNotAChange).
Keying them into a map[string]Fact silently dropped all but one. Two symptoms:
groupByKey now buckets facts into map[string][]Fact, sorts each bucket by intraGroupOrder (line, propsJSON, relationsJSON), and pairs the two sides positionally. Line is used only as an ordinal within a group that already shares an identity; it never enters factKey, so a lone fact that merely moves is still unchanged.
sortAll orders by factSortKey rather than factKey. Once colliding facts both survive, factKey no longer totally orders them, and the collections are built by ranging over a map -- sort.Slice would have left their order to Go's randomized map iteration, breaking the package's byte-identical-output promise.
The KindRoute/KindStorage discriminators are kept. They are no longer load-bearing for correctness but still pair a route's GET and DELETE facts by method rather than by position.
No cacheVersion bump: internal/diff emits no facts. Verified -- facts.jsonl hashed identically before and after.