-
Notifications
You must be signed in to change notification settings - Fork 3
ABI-compatible Option and Result types #41
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
ABI-compatible Option and Result types #41
Conversation
License Check Results🚀 The license check job ran with the Bazel command: bazel run //:license-checkStatus: Click to expand output |
|
The created documentation from the pull request is available at: docu-html |
src/containers/inline/option.rs
Outdated
| /// Returns an optional reference to the contained value. | ||
| pub const fn as_ref(&self) -> Option<&T> { | ||
| if self.is_some { | ||
| Some(unsafe { &*self.value.as_ptr() }) |
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.
safet why this is safe to derefence maybeuninit ptr (just that we checked above is_some)
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.
other unsafe places too
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.
You're right. There's a (clippy?) lint that enforces "SAFETY" comments, maybe we should enable that.
| #[repr(C)] | ||
| pub struct InlineOption<T: Copy> { | ||
| value: MaybeUninit<T>, | ||
| is_some: bool, |
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.
Shall we specify this as reprC enum enforced to u8 with states instead realing on bool? Or use u8 and do checking on value before using 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.
This would be possible, and the ABI tool actually translates enums from the description language into repr(u8) enums in Rust. Unfortunately, the ABI types feature request dictates this memory layout; we could change the feature request, but I don't think we'd gain any benefits from this.
src/containers/inline/result.rs
Outdated
| /// Returns `true` if and only if this instance represents failure. | ||
| pub fn is_err(&self) -> bool { | ||
| !self.is_ok | ||
| } |
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.
wonder if we shall expose this or rather fallback this all into buildin types via as_ref and say this container have no direct Result API ?
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 guess there's no big advantage to having these methods, except that they generate less intermediate code which has to be optimized away by the compiler. I can remove them if you want.
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.
lets remove then for consistent usage ? and why we dont use deref?
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.
Done, as discussed
ab6489b to
772b4e2
Compare
772b4e2 to
3275d90
Compare
3275d90 to
46494a6
Compare
8095d3e to
acba861
Compare
Notes for Reviewer
The types are called
InlineOptionandInlineResultto be consistent with the other ABI-compatible data structures in the library. Like them, these types are intended to be imported in themw_comlibrary, where the zero-copy traits areimpld for the wrappers.Pre-Review Checklist for the PR Author
Checklist for the PR Reviewer
Post-review Checklist for the PR Author
References
Closes #40