Skip to content

Commit

Permalink
Update reference for target_feature_11.
Browse files Browse the repository at this point in the history
  • Loading branch information
veluca93 committed Jan 24, 2025
1 parent 6cb7fc4 commit 9b4238a
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/attributes/codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,30 @@ features. It uses the [_MetaListNameValueStr_] syntax with a single key of
```rust
# #[cfg(target_feature = "avx2")]
#[target_feature(enable = "avx2")]
unsafe fn foo_avx2() {}
fn foo_avx2() {}
```

r[attributes.codegen.target_feature.arch]
Each [target architecture] has a set of features that may be enabled. It is an
error to specify a feature for a target architecture that the crate is not
being compiled for.

r[attributes.codegen.target_feature.closures]
Closures defined within a `target_feature`-annotated function inherit the
attribute from the enclosing function.

r[attributes.codegen.target_feature.target-ub]
It is [undefined behavior] to call a function that is compiled with a feature
that is not supported on the current platform the code is running on, *except*
if the platform explicitly documents this to be safe.

r[attributes.codegen.target_feature.safety]
Because of this, on many platforms safe functions and closures marked with
`target_feature` do not implement Fn traits, cannot be coerced to safe `fn`
pointers and require `unsafe` to be called. These restrictions are lifted in
contexts where the set of features enabled in the callee is a subset of the set
of features enabled in the caller.

r[attributes.codegen.target_feature.inline]
Functions marked with `target_feature` are not inlined into a context that
does not support the given features. The `#[inline(always)]` attribute may not
Expand All @@ -98,8 +109,7 @@ r[attributes.codegen.target_feature.x86]


Executing code with unsupported features is undefined behavior on this platform.
Hence this platform requires that `#[target_feature]` is only applied to [`unsafe`
functions][unsafe function].
Hence on this platform usage of `#[target_feature]` functions is usually unsafe.

Feature | Implicitly Enables | Description
------------|--------------------|-------------------
Expand Down Expand Up @@ -166,8 +176,7 @@ r[attributes.codegen.target_feature.aarch64]
#### `aarch64`


This platform requires that `#[target_feature]` is only applied to [`unsafe`
functions][unsafe function].
On this platform usage of `#[target_feature]` functions is usually unsafe.

Further documentation on these features can be found in the [ARM Architecture
Reference Manual], or elsewhere on [developer.arm.com].
Expand Down Expand Up @@ -231,8 +240,7 @@ r[attributes.codegen.target_feature.riscv]
#### `riscv32` or `riscv64`


This platform requires that `#[target_feature]` is only applied to [`unsafe`
functions][unsafe function].
On this platform usage of `#[target_feature]` functions is usually unsafe.

Further documentation on these features can be found in their respective
specification. Many specifications are described in the [RISC-V ISA Manual] or
Expand Down Expand Up @@ -293,12 +301,11 @@ r[attributes.codegen.target_feature.wasm]
#### `wasm32` or `wasm64`


`#[target_feature]` may be used with both safe and
[`unsafe` functions][unsafe function] on Wasm platforms. It is impossible to
cause undefined behavior via the `#[target_feature]` attribute because
attempting to use instructions unsupported by the Wasm engine will fail at load
time without the risk of being interpreted in a way different from what the
compiler expected.
Safe `#[target_feature]` functions may always be used in safe contexts on Wasm
platforms. It is impossible to cause undefined behavior via the
`#[target_feature]` attribute because attempting to use instructions
unsupported by the Wasm engine will fail at load time without the risk of being
interpreted in a way different from what the compiler expected.

Feature | Implicitly Enables | Description
----------------------|---------------------|-------------------
Expand Down

0 comments on commit 9b4238a

Please sign in to comment.