-
Notifications
You must be signed in to change notification settings - Fork 116
Generalize SizeEq to SizeFrom, support shrinking #2580
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
Open
joshlf
wants to merge
2
commits into
main
Choose a base branch
from
I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or 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 was referenced Jun 9, 2025
0dc4ac5
to
5f19ed9
Compare
e430a16
to
4abed50
Compare
5f19ed9
to
df3a207
Compare
4abed50
to
7e1bf34
Compare
15f9941
to
0d9185f
Compare
d3aad92
to
9fda82b
Compare
0d9185f
to
c18affd
Compare
9fda82b
to
eef2e15
Compare
c18affd
to
50bb997
Compare
In `transmute!`, support an `#![allow(shrink)]` attribute which is invoked as follows: transmute!(#![allow(shrink)] src); When this attribute is provided, `transmute!` will permit shrinking transmutes, in which the destination value may be smaller than the source value. Co-authored-by: Jack Wrenn <[email protected]> gherrit-pr-id: I46b18b4b1d10507b7e1d2e01b09dc4960cfcdce1
Generalize `SizeEq`, renaming it to `SizeFrom`, and supporting casts which shrink rather than preserve referent size. This requires fairly deep surgery in our transmute taxonomy. We can no longer rely on `SizeFrom::cast_from_raw` preserving referent size, which means that all pointer transmutes must now reason about two types of transmutes: - Size-shrinking transmutes (in which the source value is larger than the destination value) - Overwriting transmutes (in which the source value is larger than the destination value *and* the destination permits mutation). In an overwriting transmute, the resulting value is a concatenation of a valid `T` and the *suffix* of a valid `U`. (Note that size-preserving transmutes can be viewed as a special case of size-shrinking transmutes.) In order to support these semantics, we split `TransmuteFrom` into two traits: `TransmuteFrom` (which supports shriking transmutes) and `TransmuteOverwrite` (which supports overwriting transmutes). While we're here, we simplify the relationship between `TryTransmuteFromPtr`, `MutationCompatible`, and `Read`. In particular, `TryTransmuteFromPtr` now has a single blanket impl which is bounded by `MutationCompatible`, and `MutationCompatible` now directly supports three cases (and no longer delegates to `Read`): - Exclusive reference transmutes in which the destination type may be transmuted into the source type - Shared reference transmutes in which both the source and the destination type are `Immutable` - Shared reference transmutes which permit interior mutation, in which the source and destination types may both be transmuted into one another, and in which the source and destination types support compatible interior mutation Makes progress on #1817 Co-authored-by: Jack Wrenn <[email protected]> gherrit-pr-id: I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b
50bb997
to
8e4a6e5
Compare
eef2e15
to
3fc3abf
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## I46b18b4b1d10507b7e1d2e01b09dc4960cfcdce1 #2580 +/- ##
=============================================================================
+ Coverage 88.72% 88.75% +0.02%
=============================================================================
Files 20 20
Lines 5332 5335 +3
=============================================================================
+ Hits 4731 4735 +4
+ Misses 601 600 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Base automatically changed from
I46b18b4b1d10507b7e1d2e01b09dc4960cfcdce1
to
main
June 10, 2025 15:56
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Generalize
SizeEq
, renaming it toSizeFrom
, and supporting castswhich shrink rather than preserve referent size.
This requires fairly deep surgery in our transmute taxonomy. We can no
longer rely on
SizeFrom::cast_from_raw
preserving referent size, whichmeans that all pointer transmutes must now reason about two types of
transmutes:
the destination value)
destination value and the destination permits mutation). In an
overwriting transmute, the resulting value is a concatenation of a
valid
T
and the suffix of a validU
.(Note that size-preserving transmutes can be viewed as a special case of
size-shrinking transmutes.)
In order to support these semantics, we split
TransmuteFrom
into twotraits:
TransmuteFrom
(which supports shriking transmutes) andTransmuteOverwrite
(which supports overwriting transmutes).While we're here, we simplify the relationship between
TryTransmuteFromPtr
,MutationCompatible
, andRead
. In particular,TryTransmuteFromPtr
now has a single blanket impl which is bounded byMutationCompatible
, andMutationCompatible
now directly supportsthree cases (and no longer delegates to
Read
):transmuted into the source type
destination type are
Immutable
the source and destination types may both be transmuted into one
another, and in which the source and destination types support
compatible interior mutation
Makes progress on #1817
Co-authored-by: Jack Wrenn [email protected]
This PR is on branch transmute-ref-dst.