-
Notifications
You must be signed in to change notification settings - Fork 114
Teach transmute_{ref,mut}! to handle slice DSTs #2428
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
base: main
Are you sure you want to change the base?
Conversation
829b199
to
a7c40db
Compare
4d09d7c
to
f2ec335
Compare
98bbab7
to
5196fac
Compare
398966d
to
976b234
Compare
bd3b50a
to
e972a2c
Compare
e2b7f7d
to
459de15
Compare
459de15
to
424ddb4
Compare
ac7fd3f
to
85cbc73
Compare
5ebdc1a
to
7d27689
Compare
src/pointer/transmute.rs
Outdated
/// Implementations of `cast_from_raw` must satisfy that method's safety | ||
/// post-condition. | ||
pub unsafe trait SizeCompat<Src: ?Sized> { |
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 need to do this now, but it'd be more idiomatic to name this CastFrom
, after its method (and source of safety conditions). That name also conveys directionality, unlike SizeCompat
.
c5ae106
to
2d585bc
Compare
3931fcf
to
db9d6c0
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2428 +/- ##
==========================================
- Coverage 90.36% 89.80% -0.57%
==========================================
Files 19 20 +1
Lines 7808 8059 +251
==========================================
+ Hits 7056 7237 +181
- Misses 752 822 +70 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
src/pointer/transmute.rs
Outdated
t | ||
} | ||
} | ||
|
||
// TODO: Update all `TransmuteFrom` safety proofs. |
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.
TODO
db9d6c0
to
d170d54
Compare
Dismissed because we forgot this important TODO: #2428 (comment)
d170d54
to
5d7c23b
Compare
85b4437
to
522d450
Compare
fbb37b8
to
bb9b06d
Compare
bb9b06d
to
38c910a
Compare
This requires us to generalize our prior support for transmuting between unsized types. In particular, we previously used the `SizeEq` trait to denote that two types have equal sizes in the face of a cast operation (in particular, that `*const T as *const U` preserves referent size). In this commit, we add support for metadata fix-up, which means that we support casts for which `*const T as *const U` does *not* preserve referent size. Instead, we compute an affine function at compile time and apply it at runtime - computing the destination type's metadata as a function of the source metadata, `dst_meta = A + src_meta * B`. `A` and `B` are computed at compile time. We generalize `SizeEq` to permit its `cast_from_raw` method to perform a runtime metadata fix-up operation. Makes progress on #1817 Co-authored-by: Jack Wrenn <[email protected]> gherrit-pr-id: Ib4bc62202e0b3b09d155333b525087f7aa8f02c2
38c910a
to
454f974
Compare
This requires us to generalize our prior support for transmuting between
unsized types. In particular, we previously used the
SizeEq
trait todenote that two types have equal sizes in the face of a cast operation
(in particular, that
*const T as *const U
preserves referent size). Inthis commit, we add support for metadata fix-up, which means that we
support casts for which
*const T as *const U
does not preservereferent size. Instead, we compute an affine function at compile time
and apply it at runtime - computing the destination type's metadata as a
function of the source metadata,
dst_meta = A + src_meta * B
.A
andB
are computed at compile time.We generalize
SizeEq
to permit itscast_from_raw
method to perform aruntime metadata fix-up operation.
Makes progress on #1817
Co-authored-by: Jack Wrenn [email protected]
This PR is on branch transmute-ref-dst.
TransmuteFrom
safety proofs #2469