Make modification-code ordering traits consistent - #707
Open
SuhasSrinivasan wants to merge 1 commit into
Open
Conversation
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.
Review status: Author-reviewed and ready for ONT review.
Fixes #673.
Summary
ModCodeRepr::partial_cmpdelegate to its existing totalOrdimplementation.Severity
Severity: Low — latent logical/API consistency
Rationale: The current implementation violates Rust's ordering-law expectation and can reverse mixed-code ordering for external or future callers using
PartialOrd. Current in-tree production sorting usesOrd, so no current biological result or file is known to be wrong.Root cause
ModCodeReprderivesOrd, whose enum variant order placesCodebeforeChEbi, but manually implements mixed-variantPartialOrdin the opposite direction. Thereforea.cmp(&b)anda.partial_cmp(&b)disagree for the same mixed pair.Implementation
PartialOrd::partial_cmpnow returnsSome(self.cmp(other)). This is the conventional total-order implementation and makes equality, antisymmetry, and transitivity consistent without introducing a second ordering policy.The tests cover representative uppercase/lowercase letter codes, ordinary and boundary ChEBI values, every pair, and every ordered triple.
Preserved behavior
Ord,Vec::sort,BTreeMap, andBTreeSetbehavior remains letter codes first, then numeric ChEBI identifiers.Non-goals
Ordpolicy.Behavior before and after
Code('m')versusChEbi(1)cmpreturnsLess;partial_cmpreturnsSome(Greater)Lesspartial_cmp(a,b) == Some(cmp(a,b))sort_by(partial_cmp)on2,m,1,aa,m,1,2sort()and derivedOrdTesting
Test environment
790a88661ca19f322f3ee0741706ed10fb2de2cb9d865640e53f7099248d5f2c8ed59200337cf6fc; clean after testingCargo.lockSHA-25649c08c4c51b6f4320726551146d971fa9ef2183d40c3f6c631b2005965e242c0;rust-htslib0.46.0 andhts-sys2.2.05cecc3fb3a9336068d9e3c68d5c08d678153dd2c; replaymod_code_ordering_obeys_total_order_lawsCode/ChEbiassertion fails becausepartial_cmpreversescmp; apartial_cmpsort disagrees with ordinarysort()TMPDIR=/private/tmp/modkit-u60-test-tmp cargo test -p mod_kit mod_base_code::tests -- --nocapture --test-threads=1a,m,1,2TMPDIR=/private/tmp/modkit-u60-test-tmp cargo test --workspace --all-targets --no-fail-fast -- --test-threads=1Ordbehavior; no current output relies on the reversed mixed-kindPartialOrdbehaviorrustfmt --edition 2021 --check modkit-core/src/mod_base_code.rs;git diff --check upstream/master...HEADTests not performed
charand allu32values was performed; boundary representatives plus exhaustive pair/triple combinations exercise the ordering implementation directly.Scientific validation
Output and compatibility
<,>, and explicitpartial_cmpnow follow the existingOrdorder.PartialOrdbehavior can observe a reversal.Ord-based sort and ordered-collection behavior is unchanged.Reviewer guide
OrdplacesCodebeforeChEbi.PartialOrddelegation.cargo test -p mod_kit mod_base_code::tests -- --nocapture --test-threads=1.PartialOrdcallers.Checklist