8000 fix(types): replace pointer-address Ord with discriminant Ord; fix count-distinct O(n²) by adityamukho · Pull Request #73 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

fix(types): replace pointer-address Ord with discriminant Ord; fix count-distinct O(n²) - #73

Merged
adityamukho merged 1 commit into
mainfrom
fix/value-ord-and-count-distinct
Apr 3, 2026
Merged

adityamukho merged 1 commit into
mainfrom
fix/value-ord-and-count-distinct

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Summary

Changes

  • src/graph/types.rs: replace pointer-address fallthrough in Ord::cmp with deterministic discriminant comparison; add two regression tests
  • src/query/datalog/functions.rs: replace Vec::contains dedup in count-distinct and sum-distinct with BTreeSet

Test plan

  • value_ord_cross_variant_is_antisymmetric — proves the old code violated antisymmetry; passes with the fix
  • value_ord_cross_variant_is_stable — ordering depends only on variant type, not inner value
  • All 729 existing tests continue to pass

🤖 Generated with Claude Code

…or Value

Value::Ord's cross-variant fallthrough compared stack-frame pointer addresses,
which is non-deterministic across call contexts and violates Rust's Ord contract
(BTreeMap/BTreeSet require a consistent total order). This caused incorrect
aggregation grouping (PR #71) and wrong OR/OrJoin deduplication (PR #68).

Fix: use a stable u8 discriminant per variant for cross-variant ordering.

Also fix the O(n²) Vec::contains deduplication in count-distinct and sum-distinct
(issue #50, which PR #66 claimed to fix but did not): replace with BTreeSet,
which is now safe because Value::Ord is a correct total order.

Adds two regression tests:
- value_ord_cross_variant_is_antisymmetric: proves the old code violated
  antisymmetry (cmp(a,b) must equal reverse(cmp(b,a)))
- value_ord_cross_variant_is_stable: cross-variant ordering must depend only
  on the variant type, not the inner value

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@adityamukho adityamukho added bug Something isn't working performance Benchmark performance regressions critical Critical severity issue labels Apr 3, 2026
@codecov
codecov Bot commented Apr 3, 2026 •
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.90%. Comparing base (2188e34) to head (9b979c0).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #73      +/-   ##
==========================================
+ Coverage   84.70%   84.90%   +0.20%     
==========================================
  Files          25       25              
  Lines        4484     4478       -6     
==========================================
+ Hits         3798     3802       +4     
+ Misses        686      676      -10     
Files with missing lines Coverage Δ
src/graph/types.rs 85.07% <100.00%> (+14.92%) ⬆️
src/query/datalog/functions.rs 83.56% <100.00%> (-0.46%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@adityamukho
adityamukho merged commit 8888122 into main Apr 3, 2026
15 checks passed
@adityamukho
adityamukho deleted the fix/value-ord-and-count-distinct branch April 3, 2026 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working critical Critical severity issue performance Benchmark performance regressions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0