Skip to content

Conversation

@joshlf
Copy link
Member

@joshlf joshlf commented Mar 28, 2025

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]


This PR is on branch transmute-ref-dst.

@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch from 9ab2be6 to c1009fc Compare March 28, 2025 19:43
@joshlf joshlf force-pushed the Ib4bc62202e0b3b09d155333b525087f7aa8f02c2 branch from 522d450 to 7d3a9b3 Compare March 28, 2025 19:43
@codecov-commenter
Copy link

codecov-commenter commented Mar 28, 2025

Codecov Report

Attention: Patch coverage is 96.61017% with 2 lines in your changes missing coverage. Please review.

Project coverage is 88.93%. Comparing base (71bc399) to head (3d8da5b).

Files with missing lines Patch % Lines
src/lib.rs 92.30% 1 Missing ⚠️
src/util/macros.rs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2472      +/-   ##
==========================================
+ Coverage   88.91%   88.93%   +0.02%     
==========================================
  Files          20       20              
  Lines        5313     5316       +3     
==========================================
+ Hits         4724     4728       +4     
+ Misses        589      588       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch from c1009fc to 6338896 Compare March 28, 2025 23:11
@joshlf joshlf force-pushed the Ib4bc62202e0b3b09d155333b525087f7aa8f02c2 branch 2 times, most recently from fbb37b8 to bb9b06d Compare March 28, 2025 23:31
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch from 6338896 to 2115a6d Compare March 28, 2025 23:31
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch from 2115a6d to 7b9a12f Compare April 7, 2025 22:33
@joshlf joshlf force-pushed the Ib4bc62202e0b3b09d155333b525087f7aa8f02c2 branch from bb9b06d to 38c910a Compare April 7, 2025 22:33
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch from 7b9a12f to baf0a15 Compare April 7, 2025 23:35
@joshlf joshlf force-pushed the Ib4bc62202e0b3b09d155333b525087f7aa8f02c2 branch from 38c910a to 454f974 Compare April 7, 2025 23:35
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch from baf0a15 to 9ac6a2d Compare June 3, 2025 19:13
@joshlf joshlf force-pushed the Ib4bc62202e0b3b09d155333b525087f7aa8f02c2 branch from 454f974 to f5fcda2 Compare June 3, 2025 19:13
Base automatically changed from Ib4bc62202e0b3b09d155333b525087f7aa8f02c2 to main June 3, 2025 19:50
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch 2 times, most recently from 7733216 to cd6fc04 Compare June 4, 2025 15:40
@joshlf joshlf changed the base branch from main to I910c77e45532313e316ee443f9cf70d0d74cff67 June 4, 2025 15:41
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch from cd6fc04 to 674049b Compare June 4, 2025 16:01
Base automatically changed from I910c77e45532313e316ee443f9cf70d0d74cff67 to main June 4, 2025 16:17
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch 4 times, most recently from fa37094 to 97e2096 Compare June 4, 2025 19:53
@joshlf joshlf changed the title [WIP] Generalize SizeEq to SizeCompat Generalize SizeEq to SizeCompat Jun 4, 2025
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch from 97e2096 to 20f0bc3 Compare June 5, 2025 20:09
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch 2 times, most recently from 9728eab to 5a377c4 Compare June 6, 2025 17:24
@joshlf joshlf changed the title Generalize SizeEq to SizeCompat Generalize SizeEq to SizeFrom, support shrinking Jun 6, 2025
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch from 5a377c4 to 7a0c2de Compare June 6, 2025 17:25
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch 2 times, most recently from 9d12b2e to 7fbc7b4 Compare June 9, 2025 17:39
@joshlf joshlf changed the base branch from main to I1945c8e554dd80a0475462d0dc5e0ae1eb2e9ac4 June 9, 2025 17:39
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch from 7fbc7b4 to 63fc907 Compare June 9, 2025 17:44
@joshlf joshlf force-pushed the I1945c8e554dd80a0475462d0dc5e0ae1eb2e9ac4 branch from 5774b01 to 30ab41e Compare June 9, 2025 17:44
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch from 63fc907 to 5d699c7 Compare June 9, 2025 18:12
@joshlf joshlf force-pushed the I1945c8e554dd80a0475462d0dc5e0ae1eb2e9ac4 branch 2 times, most recently from 077c7bd to a6f8897 Compare June 9, 2025 18:15
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch 3 times, most recently from 31b5471 to 291b87b Compare June 9, 2025 18:43
Base automatically changed from I1945c8e554dd80a0475462d0dc5e0ae1eb2e9ac4 to main June 9, 2025 18:50
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch from 291b87b to 9b25166 Compare June 9, 2025 19:11
@joshlf joshlf changed the base branch from main to I1945c8e554dd80a0475462d0dc5e0ae1eb2e9ac4 June 9, 2025 19:11
Copy link
Collaborator

@jswrenn jswrenn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch from 9b25166 to 3d8da5b Compare June 9, 2025 19:12
@joshlf joshlf changed the base branch from I1945c8e554dd80a0475462d0dc5e0ae1eb2e9ac4 to main June 9, 2025 19:12
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
@joshlf joshlf force-pushed the I6c793a9620ad75bdc0d26ab7c7cd1a0c7bef1b8b branch from 3d8da5b to 88213f3 Compare June 9, 2025 19:18
@joshlf joshlf changed the base branch from main to I46b18b4b1d10507b7e1d2e01b09dc4960cfcdce1 June 9, 2025 19:18
@joshlf joshlf deleted the branch I46b18b4b1d10507b7e1d2e01b09dc4960cfcdce1 June 9, 2025 19:18
@joshlf joshlf closed this Jun 9, 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.

3 participants