Skip to content

[WIP] Break TransmuteFrom into Shrink vs Overwrite #2567

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

Conversation

joshlf
Copy link
Member

@joshlf joshlf commented Jun 5, 2025

Generalize `SizeEq`, renaming it to `SizeCompat`, and supporting casts
which do not preserve referent size.

This requires fairly deep surgery in our transmute taxonomy. We can no
longer rely on `SizeCompat::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)
- Tearing transmutes (in which the source value is larger than the
  destination value *and* the destination permits mutation). In a
  tearing 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.)

Makes progress on #1817

Co-authored-by: Jack Wrenn <[email protected]>
gherrit-pr-id: I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b
@joshlf joshlf force-pushed the I1e15473bf871e5b53a6c093e6a79f48e6498aa04 branch from feb1f37 to a2f2308 Compare June 6, 2025 16:24
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch from 20f0bc3 to 9728eab Compare June 6, 2025 16:24
Also, only implement TryTransmuteFromPtr once in terms of
MutationCompatible.

gherrit-pr-id: I1e15473bf871e5b53a6c093e6a79f48e6498aa04
@joshlf joshlf force-pushed the I1e15473bf871e5b53a6c093e6a79f48e6498aa04 branch from a2f2308 to 11d3b7e Compare June 6, 2025 16:43
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch 2 times, most recently from 5a377c4 to 7a0c2de Compare June 6, 2025 17:25
@joshlf joshlf closed this Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant