Skip to content

Conversation

@eddyb
Copy link
Member

@eddyb eddyb commented Dec 7, 2020

This specifically helps with f32 <-> u32 (from_bits, to_bits) in Rust-GPU (rustc_codegen_spirv), where (AFAIK) we don't yet have enough infrastructure to turn type punning memory accesses into SSA bitcasts.
(There may be more instances, but the one I've seen myself is f32::signum from num-traits inspecting e.g. the sign bit)

Sadly I've had to make an exception for transmutes between pointers and non-pointers, as LLVM disallows using bitcast for them.

r? @nagisa cc @khyperia

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 7, 2020
Copy link
Member

@nagisa nagisa left a comment

Choose a reason for hiding this comment

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

LGTM. r=me after tests for the ptr special case are added (or found to already exist)

#[no_mangle]
pub unsafe fn byte_to_bool(byte: u8) -> bool {
std::mem::transmute(byte)
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you add special test around the pointer special case? (ptr->ptr, ptr->int, ...) I don't anticipate this PR breaking it, but it would be good to have it to be sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, added ptr->ptr, ptr->int, int->ptr, and included comments with what they might become in the future.

@eddyb
Copy link
Member Author

eddyb commented Dec 9, 2020

@bors r=nagisa

@bors
Copy link
Collaborator

bors commented Dec 9, 2020

📌 Commit 5c1d2ce has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 9, 2020
@bors
Copy link
Collaborator

bors commented Dec 10, 2020

⌛ Testing commit 5c1d2ce with merge ed6739a8568aa29b8a1aa17d7af76b8e1859cc47...

@bors
Copy link
Collaborator

bors commented Dec 10, 2020

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 10, 2020
@eddyb
Copy link
Member Author

eddyb commented Dec 10, 2020

Oops, guess the tests needs -O as well, not just -C no-prepopulate-passes.

@bors r=nagisa

@bors
Copy link
Collaborator

bors commented Dec 10, 2020

📌 Commit 718fba9 has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 10, 2020
@bors
Copy link
Collaborator

bors commented Dec 10, 2020

⌛ Testing commit 718fba9 with merge d7560e8...

@bors
Copy link
Collaborator

bors commented Dec 10, 2020

☀️ Test successful - checks-actions
Approved by: nagisa
Pushing d7560e8 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 10, 2020
@bors bors merged commit d7560e8 into rust-lang:master Dec 10, 2020
@rustbot rustbot added this to the 1.50.0 milestone Dec 10, 2020
@eddyb eddyb deleted the scalar-transmute branch December 10, 2020 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants