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

Move MiniSet to data_structures #77028

Merged
merged 1 commit into from
Sep 24, 2020
Merged

Move MiniSet to data_structures #77028

merged 1 commit into from
Sep 24, 2020

Conversation

andjo403
Copy link
Contributor

remove the need for T to be copy from MiniSet as was done for MiniMap

MiniMap and MiniSet was added by #72412

think that this can be used in #68828

@rust-highfive
Copy link
Collaborator

r? @matthewjasper

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 21, 2020
@andjo403
Copy link
Contributor Author

@VFLashM I was unable to find a reason for the MiniSet to require clone when MiniMap did not but maybe I missed something

@VFLashM
Copy link
Contributor

VFLashM commented Sep 21, 2020 via email

Comment on lines 9 to 12
pub enum MiniMap<K, V> {
Array(ArrayVec<[(K, V); 8]>),
Copy link
Member

Choose a reason for hiding this comment

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

Might be pre-mature generalization, but I think you could make this generic over the length of the array too.

Suggested change
pub enum MiniMap<K, V> {
Array(ArrayVec<[(K, V); 8]>),
pub enum MiniMap<K, V, const N = 8> {
Array(ArrayVec<[(K, V); N]>),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hade tried but I was not able to get it to work with how arrayvec is implemented.
I get this fault:

error[E0277]: the trait bound `[T; N]: arrayvec::Array` is not satisfied in `arrayvec::ArrayVec<[T; N]>`
  --> compiler/rustc_data_structures/src/mini_set.rs:10:11
   |
10 |     Array(ArrayVec<Array<T, N>>),
   |           ^^^^^^^^^^^^^^^^^^^^^ within `arrayvec::ArrayVec<[T; N]>`, the trait `arrayvec::Array` is not implemented for `[T; N]`
   |
   = help: the following implementations were found:
             <[T; 0] as arrayvec::Array>
             <[T; 100] as arrayvec::Array>
             <[T; 1024] as arrayvec::Array>
             <[T; 10] as arrayvec::Array>
           and 53 others
   = note: required because it appears within the type `arrayvec::ArrayVec<[T; N]>`
   = note: no field of an enum variant may have a dynamically sized type
   = help: change the field's type to have a statically known size
help: borrowed types always have a statically known size
   |
10 |     Array(&ArrayVec<Array<T, N>>),
   |           ^
help: the `Box` type always has a statically known size and allocates its contents in the heap
   |
10 |     Array(Box<ArrayVec<Array<T, N>>>),
   |           ^^^^                     ^

Copy link
Contributor

Choose a reason for hiding this comment

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

I know it is possible for Set, it just has to be changed to accept single type argument - array, just like arrayvec does.
I'm not sure if it's realistically possible for map, because then you'll need a way to constrain array to be an array of pairs and then some way to extract key and value types from said pair. Not sure if it's possible without an additional bunch of hacky hardcoded traits.

Either way both solutions are quite cumbersome and have no real use as of now.

Copy link
Member

Choose a reason for hiding this comment

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

Oh haha it doesn't work because arrayvec itself hard coded some impls and didn't use const generics.

That's fine then, no need to add it. I just thought it would be nice.

@VFLashM
Copy link
Contributor

VFLashM commented Sep 22, 2020

On a side note I'm working on a huge change adding vast amount of missing API from HashMap/HashSet so MiniSet/MiniMap can be used across the board.
It is based on top of this PR.
Just a heads up if anyone needed it.

@bors
Copy link
Contributor

bors commented Sep 23, 2020

☔ The latest upstream changes (presumably #76928) made this pull request unmergeable. Please resolve the merge conflicts.

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

remove the need for T to be copy from MiniSet as was done for MiniMap
@andjo403 andjo403 changed the title Move MiniMap and MiniSet to data_structures Move MiniSet to data_structures Sep 23, 2020
@andjo403
Copy link
Contributor Author

have rebased and MiniMap was already moved by #76928 so this will now only move MiniSet as I was not able to see any PR that move that

@matthewjasper
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Sep 23, 2020

📌 Commit 6586c37 has been approved by matthewjasper

@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 Sep 23, 2020
@jyn514 jyn514 added C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 23, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Sep 24, 2020
Move MiniSet to data_structures

remove the need for T to be copy from MiniSet as was done for MiniMap

MiniMap and MiniSet was added by rust-lang#72412

think that this can be used in rust-lang#68828
@bors
Copy link
Contributor

bors commented Sep 24, 2020

⌛ Testing commit 6586c37 with merge 86b4172...

@bors
Copy link
Contributor

bors commented Sep 24, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: matthewjasper
Pushing 86b4172 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 24, 2020
@bors bors merged commit 86b4172 into rust-lang:master Sep 24, 2020
@rustbot rustbot added this to the 1.48.0 milestone Sep 24, 2020
@andjo403 andjo403 deleted the mini branch September 24, 2020 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants