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

Add ArrayVecCopy, which is a copyable ArrayVec #34

Closed
wants to merge 2 commits into from

Conversation

tbu-
Copy link
Collaborator

@tbu- tbu- commented Apr 26, 2016

Also add a common "backend" for ArrayVec, ArrayString and ArrayVecCopy.

@bluss
Copy link
Owner

bluss commented Apr 28, 2016

This looks interesting, good split. I indicated in #32 I would probably not accept this PR, but I'll need some time to look at it.

@bluss
Copy link
Owner

bluss commented Sep 21, 2016

I would like to revive this. The specialization trail doesn't seem to work out properly yet

@tbu-
Copy link
Collaborator Author

tbu- commented Sep 21, 2016

So I can rebase this with a chance of approval?

@bluss
Copy link
Owner

bluss commented Sep 21, 2016

Yes.

Please revisit this change: assert!(mem::size_of::() <= 28);

in nightly we should have no drop flags and it should not grow at all. And I think that's a requirement, we don't want arrayvec to grow more.

{
#[inline]
fn clone(&self) -> Self {
ArrayVecCopy { inner: self.inner.clone() }
Copy link
Owner

Choose a reason for hiding this comment

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

this can be just *self

Copy link
Collaborator Author

@tbu- tbu- Sep 21, 2016

Choose a reason for hiding this comment

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

The current implementation can potentially copy less, i.e. considering a 1024 byte array which has a length of 3, this implementation only copies three bytes whereas *self would copy 1024.

Copy link
Owner

Choose a reason for hiding this comment

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

Hm, ok, so the rest of it is uninitialized. Great.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, but this is already the case for any new ArrayVec, all the elements are uninitialized there.

`RawArrayVec` does not concern itself with the dropping or non-dropping
of elements when it goes out of scope.
@tbu-
Copy link
Collaborator Author

tbu- commented Sep 21, 2016

Rebased. Tightened the assertion.

type QuadArray = ArrayVec<[u32; 3]>;
println!("{}", mem::size_of::<QuadArray>());
assert!(mem::size_of::<QuadArray>() <= 24);
assert!(mem::size_of::<QuadArray>() <= 20);
Copy link
Owner

Choose a reason for hiding this comment

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

great that the new wrapper types don't cost any size anymore (no drop flags), but this will need to stay 24 to pass on stable as I guess you saw from travis

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On stable this will be 28 though.

Copy link
Owner

Choose a reason for hiding this comment

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

I just realized. I am a bit slow today! That's not good.

Copy link
Owner

@bluss bluss Sep 21, 2016

Choose a reason for hiding this comment

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

Isn't the reason that NoDrop is now around both the array and its length?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could declare that regression as fine, because it'll go away eventually (without further intervention).

Copy link
Owner

Choose a reason for hiding this comment

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

I want to see if it can be solved

@bluss bluss mentioned this pull request Sep 21, 2016
@bluss
Copy link
Owner

bluss commented Sep 21, 2016

Trying a second time in #40

@tbu-
Copy link
Collaborator Author

tbu- commented Nov 11, 2016

It seems that drop flags are removed from stable, at least if I read the release announcement correctly. Would you be interested in a rebased patch, now that it doesn't regress on stable anymore?

@bluss
Copy link
Owner

bluss commented Nov 11, 2016

I'd like to get ArrayVecCopy in, but I still prefer the trait based approach. But.. now I'm just trying to find out which of the two approaches that squares better with this kind of representation for arrayvec

@tbu-
Copy link
Collaborator Author

tbu- commented Jan 27, 2017

I would redo this if desired. I'm still looking for an ArrayVecCopy for my project.

@tbu-
Copy link
Collaborator Author

tbu- commented Mar 17, 2017

The regression is long gone.

Meh. Can you tell me whether I can close this pull request? There's still need for a copyable array vec in the ecosystem (see e.g. https://www.reddit.com/r/rust/comments/5zvve7/arrayinit_safe_array_initialization/), but this doesn't seem to move, neither does your second PR in #40.

@bluss
Copy link
Owner

bluss commented Mar 17, 2017

Right, I haven't had time. If I use #40, can I use your commits there? To be practical about myself, that's the one that be likely to merge.

It's not good that this stops with me, I need to figure out how to bring other people on board to take care of the project.

@tbu-
Copy link
Collaborator Author

tbu- commented Mar 17, 2017

Yes, you can use my commits there if you want. (Not sure if they're helpful though, probably easier to rewrite.)

I'd also redo this pull request if you would merge it.

@bluss
Copy link
Owner

bluss commented Mar 17, 2017

Oh right, so to get this on track. There are unreleased changes on the master branch

  • arrayvec will have another 0.3.x release
  • merge arrayvec copy, bump the minimum Rust version and release a new major version (0.4.x)

@bluss
Copy link
Owner

bluss commented Mar 17, 2017

Any wishes in particular when it comes to minimum supported Rust version?

@bluss
Copy link
Owner

bluss commented Mar 17, 2017

Oh I had forgotten that we have generic_array as public dependency too. Need to check up on that.

@tbu-
Copy link
Collaborator Author

tbu- commented Mar 18, 2017

Redoing this PR now. I don't think we need a new minimum Rust version, the older ones will continue to work, although they may use a little more memory. Minimum version for the current amount of memory seems to be 1.13.0 according to my comment in this pull request.

@bluss
Copy link
Owner

bluss commented Mar 18, 2017

I didn't understand the amount of memory thing. Current minimum version for arrayvec is Rust 1.2 according to travis, that's the one I want to change.

@tbu-
Copy link
Collaborator Author

tbu- commented Mar 18, 2017

Rust versions prior to 1.13 had a drop flag inserted in every struct implementing Drop. This is no longer the case, which is why this pull request is no longer worse on memory than the current code.

Users with a Rust version smaller than 1.13 will have a regression of memory usage (not much, it's one more drop flag for the ArrayVec struct).

@bluss
Copy link
Owner

bluss commented Mar 18, 2017

I don't think you should redo this PR. This is based on that I said I prefer #40. I don't want you to feel like you are wasting time (again).

@tbu-
Copy link
Collaborator Author

tbu- commented Mar 18, 2017

Ah, thanks for clarifying. I somehow misunderstood you there.

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.

None yet

2 participants