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

Unify stable and unstable sort implementations in same core module #104672

Merged
merged 3 commits into from
Jan 21, 2023

Conversation

Voultapher
Copy link
Contributor

This moves the stable sort implementation to the core::slice::sort module. By virtue of being in core it can't access Vec. The two Vec used by merge sort, buf and runs, are modelled as custom types that implement the very limited required Vec interface with the help of provided allocation and free functions. This is done to allow future re-use of functions and logic between stable and unstable sort. Such as insert_head.

This is in preparation of #100856 and #104116. It only moves code, it doesn't change any of the sort related logic. This unlocks the ability to share insert_head, insert_tail, swap_if_less merge and more.

Tagging @Mark-Simulacrum I hope this allows progress on #100856, by moving merge_sort here I hope future changes will be easier to review.

This moves the stable sort implementation to the core::slice::sort module. By
virtue of being in core it can't access `Vec`. The two `Vec` used by merge sort,
`buf` and `runs`, are modelled as custom types that implement the very limited
required `Vec` interface with the help of provided allocation and free
functions. This is done to allow future re-use of functions and logic between
stable and unstable sort. Such as `insert_head`.
@rustbot
Copy link
Collaborator

rustbot commented Nov 21, 2022

r? @joshtriplett

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 21, 2022
@rustbot
Copy link
Collaborator

rustbot commented Nov 21, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

There were several unsafe blocks in the existing implementation that
were not documented with a SAFETY comment.
@Voultapher
Copy link
Contributor Author

Voultapher commented Nov 21, 2022

As a nice little side-effect, I'm seeing a small binary size decrease (eg. 363 -> 361kb) with this change for sort instantiations.

@Voultapher
Copy link
Contributor Author

@joshtriplett friendly ping, is there something blocking review of this PR?

@thomcc
Copy link
Member

thomcc commented Dec 9, 2022

r? @thomcc

@rustbot rustbot assigned thomcc and unassigned joshtriplett Dec 9, 2022
@thomcc
Copy link
Member

thomcc commented Dec 14, 2022

It only moves code, it doesn't change any of the sort related logic

This seems to be true, so I don't have any comments really.

I will say that this will be a problem if we don't perform the other sort-related changes, and it may constrain future sort implementations to share components in this way, but that's probably fine.

@bors r+

@bors
Copy link
Contributor

bors commented Dec 14, 2022

📌 Commit 4b5844f has been approved by thomcc

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 14, 2022
@thomcc
Copy link
Member

thomcc commented Dec 14, 2022

Ah, actually, I need some more time to think about a couple parts of this, sorry for the false start.

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 14, 2022
@Voultapher
Copy link
Contributor Author

Can I somehow help? This PR seems stuck again :(

@thomcc thomcc added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 18, 2023
@thomcc
Copy link
Member

thomcc commented Jan 19, 2023

Yeah, this seems fine.

@bors r+

@bors
Copy link
Contributor

bors commented Jan 19, 2023

📌 Commit 4b5844f has been approved by thomcc

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 19, 2023
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jan 20, 2023
…homcc

Unify stable and unstable sort implementations in same core module

This moves the stable sort implementation to the core::slice::sort module. By virtue of being in core it can't access `Vec`. The two `Vec` used by merge sort, `buf` and `runs`, are modelled as custom types that implement the very limited required `Vec` interface with the help of provided allocation and free functions. This is done to allow future re-use of functions and logic between stable and unstable sort. Such as `insert_head`.

This is in preparation of rust-lang#100856 and rust-lang#104116. It only moves code, it *doesn't* change any of the sort related logic. This unlocks the ability to share `insert_head`, `insert_tail`, `swap_if_less` `merge` and more.

Tagging ``@Mark-Simulacrum`` I hope this allows progress on rust-lang#100856, by moving `merge_sort` here I hope future changes will be easier to review.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 20, 2023
…homcc

Unify stable and unstable sort implementations in same core module

This moves the stable sort implementation to the core::slice::sort module. By virtue of being in core it can't access `Vec`. The two `Vec` used by merge sort, `buf` and `runs`, are modelled as custom types that implement the very limited required `Vec` interface with the help of provided allocation and free functions. This is done to allow future re-use of functions and logic between stable and unstable sort. Such as `insert_head`.

This is in preparation of rust-lang#100856 and rust-lang#104116. It only moves code, it *doesn't* change any of the sort related logic. This unlocks the ability to share `insert_head`, `insert_tail`, `swap_if_less` `merge` and more.

Tagging ```@Mark-Simulacrum``` I hope this allows progress on rust-lang#100856, by moving `merge_sort` here I hope future changes will be easier to review.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 21, 2023
…mpiler-errors

Rollup of 9 pull requests

Successful merges:

 - rust-lang#104154 (Change `bindings_with_variant_name` to deny-by-default)
 - rust-lang#104347 (diagnostics: suggest changing `s@self::{macro}`@::macro`` for exported)
 - rust-lang#104672 (Unify stable and unstable sort implementations in same core module)
 - rust-lang#107048 (check for x version updates)
 - rust-lang#107061 (Implement some more new solver candidates and fix some bugs)
 - rust-lang#107095 (rustdoc: remove redundant CSS selector `.sidebar .current`)
 - rust-lang#107112 (Fix typo in opaque_types.rs)
 - rust-lang#107124 (fix check macro expansion)
 - rust-lang#107131 (rustdoc: use CSS inline layout for radio line instead of flexbox)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 68b390a into rust-lang:master Jan 21, 2023
@rustbot rustbot added this to the 1.68.0 milestone Jan 21, 2023
@Voultapher Voultapher deleted the unify-sort-modules branch January 21, 2023 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants