Skip to content

Make the Vec data structure layout match raw::Slice. #18303

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 1 commit into from
Oct 28, 2014

Conversation

cgaebel
Copy link
Contributor

@cgaebel cgaebel commented Oct 25, 2014

Fixes #18302

r? @thestinger

@rust-highfive
Copy link
Contributor

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@thestinger
Copy link
Contributor

@cgaebel: Since Vec<T> doesn't use repr(C), it would technically be undefined behaviour to rely on the on the representation. I still think it's worth having the order match Slice because in practice the compiler is only going to reorder fields when it reduces the size (never these) or if something like randomization is enabled for hardening.

@cgaebel
Copy link
Contributor Author

cgaebel commented Oct 25, 2014

Hmmm then would be make sense to mark both raw::Slice and Vec as #[repr(C)] ?

@thestinger
Copy link
Contributor

@cgaebel: I don't think Vec<T> should be repr(C). The Slice type does need to be repr(C) to have a guarantee of matching the compiler representation.

@thestinger
Copy link
Contributor

In the case where struct randomization isn't enabled, matching the representation of slices should allow more optimizations by LLVM. It does make sense to define it in the same order but that order being preserved is not guaranteed by the language.

@cgaebel
Copy link
Contributor Author

cgaebel commented Oct 25, 2014

Maybe I'm just not understanding what you're saying, but doesn't #[repr(C)] guarantee the order be preserved?

@thestinger
Copy link
Contributor

It does guarantee that, but tagging stuff as #[repr(C)] when it's not actually needed would make randomization less useful.

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Oct 27, 2014
@bors bors merged commit 87a5f0d into rust-lang:master Oct 28, 2014
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.

Reorder Vec fields
5 participants