Repository navigation
Friendly hint and docs clarification for array.sorted - #7528
Merged
Merged
Conversation
The recent switch to glidesort made it more common to run into this code path, i.e. with `range(1,9).map(v => (v, [])).sorted()`. Let's be nice and point users in the right direction c:
laurmaedje
enabled auto-merge
December 5, 2025 15:50
Member
|
Thanks! This is nice. :) |
laurmaedje
added a commit
that referenced
this pull request
Dec 11, 2025
Co-Authored-By: Laurenz <[email protected]>
1 task done
Dikluwe
pushed a commit
to Dikluwe/typst-crystalline
that referenced
this pull request
Sep 12, 2026
Co-authored-by: Laurenz <[email protected]>
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.
Background
0.14.1(#7520) changed the algorithm used byarray.sorted; fromslice::sort_by(driftsort) toglidesort. This slightly alters which elements are actually compared1, which causes inputs that previously passed silently despite not technically having been valid to now error more frequently (but still not always).Previous discussion on Discord: Typst › contributors 🗪
Samples
((1, []), (1, []))((1, []), (2, []))range(1,8).map(v => (v, []))range(1,9).map(v => (v, []))((1, 1), (2, 1), (3, 1), (4, []), (5, 1), (6, 1), (7, 1), (8, 1))((1, 1), (2, 1), (3, 1), (4, 1), (5, []), (6, 1), (7, 1), (8, 1))New Hint
Especially the volatility makes debugging this issue in one's document difficult. To counteract the source of confusion, I propose a new hint be added to the error generated in this code path:
It's not too noisy if the user knows something about the input array was wrong (see the changes for existing tests), but helps those determined to sort the given input find their way to a solution. We present keywords which help experienced users recall their options and allow newer ones to look up the most relevant information in the documentation.
The hint isn't applied to the branch where
byis given because at that point we can't do much; the user has to figure out how to solve the error case. Same for an error withinkey.Personally, I really don't like that invalid inputs sometimes work, but also see that checking this more extensively would be pretty difficult. Maybe something to consider for the future alongside #6285 (comment).
Doc Comment change
Not much to say here. If you believe it doesn't matter as much as I feel rn but like the hint, I'll gladly drop this part.
Footnotes
https://github.com/Voultapher/sort-research-rs/blob/main/writeup/driftsort_introduction/text.md#components-from-glidesort-which-are-not-incorporated ↩