Skip to content

Implement safe reference casts#235

Merged
Shnatsel merged 5 commits into
linebender:mainfrom
Shnatsel:safe-transmute-ref
May 27, 2026
Merged

Implement safe reference casts#235
Shnatsel merged 5 commits into
linebender:mainfrom
Shnatsel:safe-transmute-ref

Conversation

@Shnatsel
Copy link
Copy Markdown
Contributor

Stacked on top of #234

reimplements bytemuck::cast/cast_mut but more clearly zero-cost and failing at build time rather than at runtime

then uses those functions to expunge the remaining unchecked transmute calls

and bans unchecked transmute via clippy

@Shnatsel Shnatsel force-pushed the safe-transmute-ref branch from 90118e5 to e676c41 Compare May 27, 2026 08:48
@Shnatsel Shnatsel enabled auto-merge May 27, 2026 09:14
"checked_cast_ref requires source and destination to have the same size"
);
assert!(
align_of::<Src>() >= align_of::<Dst>(),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I guess might be obvious to others but it wasn't to me, this works because the alignment is always a power of 2, right? Otherwise, it wouldn't for example work if you could have an alignment of 5 and 4. Could you maybe add a comment linking to that https://doc.rust-lang.org/stable/reference/type-layout.html#size-and-alignment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added, thanks

@Shnatsel Shnatsel added this pull request to the merge queue May 27, 2026
@LaurenzV LaurenzV removed this pull request from the merge queue due to a manual request May 27, 2026
@Shnatsel Shnatsel enabled auto-merge May 27, 2026 10:30
@Shnatsel Shnatsel added this pull request to the merge queue May 27, 2026
Merged via the queue into linebender:main with commit 0d13b0a May 27, 2026
22 checks passed
@Shnatsel Shnatsel deleted the safe-transmute-ref branch May 27, 2026 10:34
Shnatsel added a commit to Shnatsel/fearless_simd that referenced this pull request May 27, 2026
Merged origin/main commit 0d13b0a. The merge applied cleanly.
Shnatsel added a commit to Shnatsel/fearless_simd that referenced this pull request May 27, 2026
Regenerate the branch-added AVX512 module so reference casts use checked_cast_ref and checked_cast_mut. Also apply the float bit-pattern assertion style from PR linebender#235 to the branch-added f32x16 interleaved-load test.

Validation: cargo test
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.

2 participants