-
Notifications
You must be signed in to change notification settings - Fork 104
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
Add DstLayout::extend
#633
Conversation
56e41cc
to
439b94b
Compare
0b10804
to
96f3ff3
Compare
301a488
to
17af0f8
Compare
src/lib.rs
Outdated
debug_assert!(max_align.is_power_of_two()); | ||
debug_assert!(self._align.get() <= max_align.get()); |
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 assert that field._align.get() <= Self::MAX_ALIGN
?
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 didn't mean to assert debug_assert!(self._align.get() <= max_align.get());
, and revised the PR accordingly. I don't think we need to peek into self
and field
and make sure they're valid — that's the job of DstLayout
's constructors.
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 don't currently document anywhere that DstLayout
's align
field is guaranteed to have a particular maximum value - that's just a consequence of Rust's type rules. IMO we should either explicitly document that as an invariant and add comments at construction sites proving that it's upheld, or we should assert it here out of an abundance of caution. As this code is currently written, it could break in the future if Rust raises the maximum alignment.
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 made three changes:
- I've verified, with Kani, that this method is robust to future increases of Rust's maximum-allowed alignment.
- I've added debug assertions that fire if we see an alignment exceeding Rust's current maximum-allowed alignment.
- I've replaced the
+
operations with explicit checked adds, and panic messages explaining what went wrong.
354f4df
to
37d1bff
Compare
23c9256
to
7b3af4a
Compare
This method is comparable to `Layout::extend`, but also handles dynamically sized types. Makes progress towards #29.
7b3af4a
to
72b8e16
Compare
DstLayout::extend
is comparable toalloc::Layout
, except that it additionally handles DSTs. This is the first of two steps needed forDstLayout
to support an API in the form of:(The next step is implementing
DstLayout::pad_to_align
).Despite the similarities between
DstLayout::extend
andLayout::extend
, the former cannot be implemented in terms of the latter becauseLayout::extend
is notconst
. This introduces a risk that our computations here diverge from those inLayout::extend
, but this PR also includes Kani proofs thatDstLayout::extend
behaves comparably toLayout::extend
.Makes progress towards #29.