Skip to content
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

Non-unsafe functions for PODs? #5

Closed
nabijaczleweli opened this issue Oct 5, 2017 · 3 comments
Closed

Non-unsafe functions for PODs? #5

nabijaczleweli opened this issue Oct 5, 2017 · 3 comments

Comments

@nabijaczleweli
Copy link
Owner

Since PODs (and only PODs) are actually safe to type-pun we could probably totally do that!

Now if only there was a std::is_pod<T> in Rust…

@nabijaczleweli
Copy link
Owner Author

Turns out not even PODs are safe! Great!

@nabijaczleweli nabijaczleweli changed the title Non-unsafe functions for PODs Non-unsafe functions for PODs? Oct 8, 2017
@Enet4
Copy link
Collaborator

Enet4 commented Oct 8, 2017

Better permalink.

I suggest that we attempt to grab as many situations of safe transmutation as possible in a case-by-case basis. In particular:

  • integer type (u8, i8, u16, i16, u32, i32, u64, i64, u128, i128), bool, char, or float types (f32, f64) to another integer type is safe because all possible bit states are valid integer values;
  • the same to f32 or f64 is also safe if we assume that transmuting to signalling NaNs are a no-problem. This isn't 100% agreed on, though, because certain changes in LLVM implementation details could influence this safety (see rust/#39271). On the safe side, we could probably have a function that guards, transmutes and then masks the signalling bits.
  • To bool, we could first transmute to u8, check whether each byte is either 0 or 1, and raise an error otherwise.

It's likely that we'll need separate functions for each case.

nabijaczleweli added a commit that referenced this issue Oct 9, 2017
Effectively just uses a marker trait to waive any responsibility

Also, is #[cfg(stage0)] the correct thingy to enable {i,u}128s with

Ref: #5
@nabijaczleweli
Copy link
Owner Author

Released in v0.5.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants