Skip to content

Implement a "MaybeUninit" and use it conditionally (0.4.x version) #114

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

Merged
merged 4 commits into from
Dec 16, 2018

Conversation

bluss
Copy link
Owner

@bluss bluss commented Dec 15, 2018

This change is for the 0.4.x release series of arrayvec,
not master.

Implement a "MaybeUninit" and use it conditionally

Use a build script to detect if we can use MaybeUninit or NoDrop.
Enabling unstable features automatically is not ideal, but since it's
a soundness issue we should do it.

Use a MaybeUninit-like union on nightly when we can. We use a feature
detection script in build.rs, so that we also go back to the fallback if
the unstable feature changes in an unexpected way.

We need to continue to use NoDrop for best working stable
implementation, but we eagerly use our union solution where we can,
currently only in nightlies.

Rustc feature probe code written by @cuviper, taken from num-bigint.

Remove use of uninitialized in ArrayString

We can't fix this properly (MaybeUninit with a union) until we change
the user visible API (we need to require that A: Copy.

As a temporary solution for arrayvec version 0.4.*, we use zeroed to
initialize an array of bytes, instead of using uninitialized. This may
have a negative performance impact, but the fix is to upgrade to future
arrayvec 0.5.

This also changes the use_union feature to do nothing. This is
allowed, as has been indicated in the feature description in docs.

There are no user visible API changes but the size of ArrayVec types may
change due to the enabling of the MaybeUninit feature.

Closes #86 (now obsolete)

This seems like a trivial test, but since it can fail, it shows us that
we don't have a sound implementation yet.
@bluss
Copy link
Owner Author

bluss commented Dec 15, 2018

This will be merged into master after 0.4, and we'll make a release with similar code for 0.5.x release series too.

Thougths on updating 0.4.x? It's quite widely used, so it would be good to put a sounder implementation out there, if only on nightly. We're doing the best we can with stable.

@bluss bluss force-pushed the maybe-uninit-0.4 branch 2 times, most recently from 15e1430 to 433d40e Compare December 15, 2018 14:06
Use a build script to detect if we can use MaybeUninit or NoDrop.
Enabling unstable features automatically is not ideal, but since it's
a soundness issue we should do it.

Use a MaybeUninit-like union on nightly when we can. We use a feature
detection script in build.rs, so that we also go back to the fallback if
the unstable feature changes in an unexpected way.

We need to continue to use NoDrop for best working stable
implementation, but we eagerly use our union solution where we can,
currently only in nightlies.

Rustc feature probe code written by Josh Stone (cuviper),
taken from num-bigint.
We can't fix this properly (MaybeUninit with a union) until we change
the user visible API (we need to require that A: Copy.

As a temporary solution for arrayvec version 0.4.*, we use zeroed to
initialize an array of bytes, instead of using uninitialized. This may
have a negative performance impact, but the fix is to upgrade to future
arrayvec 0.5.
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.

1 participant