-
Notifications
You must be signed in to change notification settings - Fork 145
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
fix(vm): Don't let rustc think the Array type can't exist #398
Conversation
THe use of `Void` in the `Array` type was meant to absolutely prevent the `Array` type from existing except behind a pointer which is invalid (except the empty array I guess) as the elements are stored inline behind the length field. Unfortunately rust-lang/rust#45225 made rustc think that fields of the `Array` type could not exist at all and placed fields of `Array` at the start of any struct containing them, causing any write to the `Array` to overwrite other fields.
Since having a valid value of type |
vm/src/array.rs
Outdated
/// Abstract array type which have their length store inline with the elements. | ||
/// Fills the same role as Box<[T]> but takes only 8 bytes on the stack instead of 16 | ||
#[repr(C)] | ||
pub struct Array<T: Copy> { | ||
len: usize, | ||
array_start: [T; 0], | ||
_marker: self::internal::CantConstruct, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought just having private fields meant that folks couldn't construct it 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the intention is that it shouldn't be constructed even accidentally from this module.
The use of
Void
in theArray
type was meant to absolutely prevent theArray
type from existing except behind a pointer which is invalid (except the empty array I guess) as the elements are stored inline behind the length field.Unfortunately rust-lang/rust#45225 made rustc think that fields of the
Array
type could not exist at all and placed fields ofArray
at the start of any struct containing them, causing any write to theArray
to overwrite other fields.Fixes #396