Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix sorting for iterables that define copymutable #52086

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented Nov 8, 2023

copymutable is only defined to return an array for abstract arrays, but that is only what this method is never called with. For other types, it has a default of collect (which means the default behavior appears to give an array), but can be changed by other types (such as AbstractSet) to do something different.

Correction to #46104

`copymutable` is only defined to return an array for abstract arrays,
but that is only what this method is never called with. For other types,
it has a default of `collect`, but can be changed by other types (such
as AbstractSet) to do something different.

Refs #46104
@vtjnash vtjnash added the backport 1.10 Change should be backported to the 1.10 release label Nov 8, 2023
@LilithHafner
Copy link
Member

Since we only support sorting abstract arrays with sort! (and that's all we can support because we need length and random access getindex and setindex) this seems reasonable.

This would be inconvenient for iterable and sortable non-abstractarray types that bring their own copymutable and sort! methods. However, in that case all they have to do is define Base.sort(x::MyType; kw...) = sort!(copymutable(x); kw...), so not a big loss.

collect isn't perrfect; we want collect_to_abstractarray. However, if we ever do add collect_to_abstractarray, I think we could switch this as a minor or non-breaking change.

@LilithHafner LilithHafner added the sorting Put things in order label Nov 8, 2023
Copy link
Member

@LilithHafner LilithHafner left a comment

Choose a reason for hiding this comment

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

LGTM, though we should probably wait to see if triage decides to revert #46104 before we merge this.

@vtjnash vtjnash added the merge me PR is reviewed. Merge when all tests are passing label Nov 8, 2023
@vtjnash
Copy link
Member Author

vtjnash commented Nov 8, 2023

We don't need triage to approve merging a bugfix, even if there may be later changes to the API

@LilithHafner LilithHafner merged commit f99e6bf into master Nov 9, 2023
8 of 11 checks passed
@LilithHafner LilithHafner deleted the jn/sort-nonvector-collect branch November 9, 2023 01:44
@LilithHafner LilithHafner removed the merge me PR is reviewed. Merge when all tests are passing label Nov 9, 2023
jishnub pushed a commit that referenced this pull request Nov 10, 2023
Two chagnes wrapped into one `Base.copymutable` => `Base.copymutable` &
`collect` and `Base.copymutable` => `similar` & words.

Followup for #52086 and #46104; also fixes #51932 (though we still may
want to make `copymutable` public at some point)

---------

Co-authored-by: Jameson Nash <vtjnash@gmail.com>
KristofferC pushed a commit that referenced this pull request Nov 13, 2023
KristofferC pushed a commit that referenced this pull request Nov 13, 2023
Two chagnes wrapped into one `Base.copymutable` => `Base.copymutable` &
`collect` and `Base.copymutable` => `similar` & words.

Followup for #52086 and #46104; also fixes #51932 (though we still may
want to make `copymutable` public at some point)

---------

Co-authored-by: Jameson Nash <vtjnash@gmail.com>
(cherry picked from commit 42c088b)
@KristofferC KristofferC mentioned this pull request Nov 13, 2023
39 tasks
KristofferC added a commit that referenced this pull request Nov 16, 2023
KristofferC added a commit that referenced this pull request Nov 16, 2023
@KristofferC KristofferC removed the backport 1.10 Change should be backported to the 1.10 release label Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sorting Put things in order
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants