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

Explain unsafe contracts of core::simd #245

Merged
merged 2 commits into from
Feb 10, 2022
Merged

Conversation

workingjubilee
Copy link
Member

@workingjubilee workingjubilee commented Feb 10, 2022

This permeates the module with remarks on safety for pub methods,
layout of the Simd type, correct use of intrinsics, et cetera.
This is mostly to help others curious about how core::simd works,
including other Rust contributors, unsafe library authors,
and eventually ourselves.

This closes #244.

This permeate the module with remarks on safety for pub methods,
layout of the Simd type, correct use of intrinsics, et cetera.
This is mostly to help others curious about how core::simd works,
including other Rust contributors, `unsafe` library authors,
and eventually ourselves.
@workingjubilee
Copy link
Member Author

On architectures where they're known to match (like wasm) I don't believe they're passed by reference. But on an architecture with multiple possible conventions, the callee can't possibly know all of it's caller's conventions.

My memory says this happens for wasm too. We did attempt to undo it for wasm but then had to revert that at some point to the memory-passing behavior due to it uncovering another bug.

/// It is thus sound to [`transmute`] `Simd<T, N>` to `[T; N]`, and will typically optimize to zero cost,
/// but the reverse transmutation is more likely to require a copy the compiler cannot simply elide.
///
/// # ABI "Features"
Copy link
Member

Choose a reason for hiding this comment

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

I might change this to "ABI Limitations" and "pass by reference" instead of "pass by memory", though both of these are correct too

@calebzulawski
Copy link
Member

There was a bug passing u128 by value in wasm, too, so maybe it's not the best example...

Copy link
Member

@calebzulawski calebzulawski left a comment

Choose a reason for hiding this comment

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

Left one more comment, but lgtm

@workingjubilee
Copy link
Member Author

Ah, I want to avoid the term "pass by reference", because it risks conflating this behavior with the behavior of "proper" references and borrows.

@workingjubilee workingjubilee merged commit 78a18c3 into master Feb 10, 2022
@workingjubilee workingjubilee deleted the explain-contracts branch February 10, 2022 17:33
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.

docs for to_int_unchecked should mention the safe version
4 participants