Skip to content

fix: make Ord for slices lexicographic (elements first, then length)#9555

Merged
TomAFrench merged 8 commits intonoir-lang:masterfrom
radik878:fix/slice-ord-lexicographic
Aug 28, 2025
Merged

fix: make Ord for slices lexicographic (elements first, then length)#9555
TomAFrench merged 8 commits intonoir-lang:masterfrom
radik878:fix/slice-ord-lexicographic

Conversation

@radik878
Copy link
Contributor

Problem: The Ord implementation for slices [T] compared lengths before elements, contradicting the function comment and common lexicographic expectations. This also diverged from arrays [T; N] and tuples, which are lexicographically ordered. Example of the surprising behavior: [2] was considered less than [1, 1, 1] purely due to length.

Changes: Updated Ord for [T] in noir_stdlib/src/cmp.nr to compare the common prefix element-wise and, only if equal, use length as a tiebreaker. Added unit test asserting [2] > [1,1,1] and [1,2] < [1,2,3].

Goal: Align behavior with documentation and established semantics across the stdlib, ensure predictable lexicographic ordering for slices, and reduce surprises for users.

@github-actions
Copy link
Contributor

Thank you for your contribution to the Noir language.

Please do not force push to this branch after the Noir team have started review of this PR. Doing so will only delay us merging your PR as we will need to start the review process from scratch.

Thanks for your understanding.

Copy link
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you - good catch 👍

Since the stdlib was changed, I'm expecting each snapshot needs to be updated as well. Do you mind running cargo t && cargo insta review? Make sure cargo insta is installed.

@radik878
Copy link
Contributor Author

Thank you - good catch 👍

Since the stdlib was changed, I'm expecting each snapshot needs to be updated as well. Do you mind running cargo t && cargo insta review? Make sure cargo insta is installed.

Yes, i will do it, but if you don't mind, i will do it tomorrow

@radik878
Copy link
Contributor Author

radik878 commented Aug 22, 2025

Thank you - good catch 👍

Since the stdlib was changed, I'm expecting each snapshot needs to be updated as well. Do you mind running cargo t && cargo insta review? Make sure cargo insta is installed.

Hi. I fixed tests and now code compiles, but i've bumped into a problem with snapshots:
@radik878 ➜ /workspaces/noir (fix/slice-ord-lexicographic) $ cargo insta review
done: no snapshots to review
@radik878 ➜ /workspaces/noir (fix/slice-ord-lexicographic) $

and to be honest i don't know why it's like that

@jfecher
Copy link
Contributor

jfecher commented Aug 22, 2025

@radik878 did you run cargo t first to run all the tests? From the errors above it looks like there are still snapshots which haven't been updated. cargo insta review without running tests first won't do anything since it doesn't have the updated results of each test.

Also, the stdlib needs to be reformatted. You can cd into noir_stdlib and run nargo fmt.

@radik878 radik878 force-pushed the fix/slice-ord-lexicographic branch from fa79905 to a8fa180 Compare August 22, 2025 19:38
@radik878
Copy link
Contributor Author

@radik878 did you run cargo t first to run all the tests? From the errors above it looks like there are still snapshots which haven't been updated. cargo insta review without running tests first won't do anything since it doesn't have the updated results of each test.

Also, the stdlib needs to be reformatted. You can cd into noir_stdlib and run nargo fmt.

Thanks for help, looks ready

@jfecher
Copy link
Contributor

jfecher commented Aug 27, 2025

@radik878 looks like they are still outdated, maybe the branch was old and you need to git pull origin master and merge in all the changes from master then run cargo t; cargo insta review again?

I'm very sorry this PR has been blocked for as long as it has - we're working on reworking our CI to make this process easier.
If you want, I can copy over these changes into my own branch, run these locally, and make a new PR for it.

@TomAFrench TomAFrench self-requested a review August 27, 2025 23:42
@TomAFrench TomAFrench enabled auto-merge August 27, 2025 23:58
@TomAFrench TomAFrench added this pull request to the merge queue Aug 28, 2025
Merged via the queue into noir-lang:master with commit f30e342 Aug 28, 2025
118 checks passed
@radik878
Copy link
Contributor Author

@radik878 looks like they are still outdated, maybe the branch was old and you need to git pull origin master and merge in all the changes from master then run cargo t; cargo insta review again?

I'm very sorry this PR has been blocked for as long as it has - we're working on reworking our CI to make this process easier. If you want, I can copy over these changes into my own branch, run these locally, and make a new PR for it.

Thanks, i've bumped into such a system with snaphots for the first time so it was a bit difficult for me, at that moment all tests passed and snapshots updated, but yes, i think branch was outdated. But thanks for help really

github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Aug 28, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix: make Ord for slices lexicographic (elements first, then length)
(noir-lang/noir#9555)
chore(ssa): Refactor `unrolling`
(noir-lang/noir#9653)
chore(docs): Update dependency page's examples
(noir-lang/noir#9634)
fix(ssa): Constant fold Brillig calls using the SSA interpreter
(noir-lang/noir#9655)
chore: LICM refactors (noir-lang/noir#9642)
chore: add test for trait bound on implementing type
(noir-lang/noir#9652)
chore: pass `DataFlowGraph` instead of `Function` as arg
(noir-lang/noir#9656)
feat: Group one audit tests
(noir-lang/noir#9445)
fix(expand): better handling of dereferences (again)
(noir-lang/noir#9654)
feat(mem2reg): address last known value is independent of its aliases
(take three) (noir-lang/noir#9633)
chore: remove handling for slice arguments to MSM
(noir-lang/noir#9648)
fix: validate binary operations which do not allow fields
(noir-lang/noir#9649)
END_COMMIT_OVERRIDE
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Aug 28, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix: make Ord for slices lexicographic (elements first, then length)
(noir-lang/noir#9555)
chore(ssa): Refactor `unrolling`
(noir-lang/noir#9653)
chore(docs): Update dependency page's examples
(noir-lang/noir#9634)
fix(ssa): Constant fold Brillig calls using the SSA interpreter
(noir-lang/noir#9655)
chore: LICM refactors (noir-lang/noir#9642)
chore: add test for trait bound on implementing type
(noir-lang/noir#9652)
chore: pass `DataFlowGraph` instead of `Function` as arg
(noir-lang/noir#9656)
feat: Group one audit tests
(noir-lang/noir#9445)
fix(expand): better handling of dereferences (again)
(noir-lang/noir#9654)
feat(mem2reg): address last known value is independent of its aliases
(take three) (noir-lang/noir#9633)
chore: remove handling for slice arguments to MSM
(noir-lang/noir#9648)
fix: validate binary operations which do not allow fields
(noir-lang/noir#9649)
END_COMMIT_OVERRIDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants