-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Plain trait for ComponentBytes soundness
- Loading branch information
Showing
6 changed files
with
41 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2691083
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.
We do in fact have a whole lot of competing traits for
Plain
🤓https://crates.io/crates/bytemuck has its own
Pod
trait, this is what's already used inimage
. Don't think it has a derive macro but then again Plain doesn't either. https://crates.io/crates/zerocopy also has a similar trait and it does have a derive macro, but it's a heavier dependency.@danielhenrymantilla has figured out a way to implement the derive with a macro-by-example so that compile time would not be inflated by
syn
, but I'm not aware of any crate incorporating that yet.2691083
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.
An effort to unify the traits is underway but is not in a usable shape yet: https://github.com/rust-secure-code/mem-markers
2691083
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.
A significant reason for choosing
bytemuck
overPlain
was its scope: It has willingly committed to a small core of operations in order to have a1.0
release very early. Since the trait bound is part of the interface, it was very important to choose a stable dependency inimage
.2691083
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.
Also this change is not SemVer compatible to
0.8.18
.2691083
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 know it's technically a semver break, but:
2691083
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've reviewed source of
plain
andbytemuck
, and I preferplain
. It's much smaller, simpler and does exactly that one thing. Bytemuck throws in zeroing, casts, and tries to be clever with markingOption<NonZero<T>>
asPod
type. It's not unsafe per Rust's definition, but nonsense for pixel types.2691083
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.
Thank you for your comments. They're helpful.
2691083
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.
plain
probably didn't add them in because the stabilization ofOption<NonZero>
layout happened sometime in the 3 years of Rust development thatplain
appears to be lagging behind. For example:This paragraph from its documentation is similarly outdated. It did change and it was slated.
2691083
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.
@Shnatsel that crate looks nice. At a first glance the distinction between
AsBytes
andByteComplete
looks useful foras_bytes
andas_bytes_mut
respectively.Do you expect to release at least the "pod" subset of the crate anytime soon?
2691083
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.
There was discussion on releasing a 0.1 on crates.io soon; I believe the presence of a motivating example would accelerate that.
I suggest talking directly to the people responsible for mem-markers. Their discussion is hosted on Rust Zulip in
#project-safe-transmute
.2691083
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.
Regarding semver, I'd prefer my broken code to stop compiling instead of silently staying broken, so I'm in favor of this shipping in a semver-compatible release even though it is an API break.
2691083
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.
#35 fixed in 0.8.20