Skip to content

Commit 8fc864d

Browse files
committed
Unwrap target_feature
1 parent 9571d4d commit 8fc864d

File tree

1 file changed

+16
-44
lines changed

1 file changed

+16
-44
lines changed

src/attributes/codegen.md

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ r[attributes.codegen.target_feature]
9393
## The `target_feature` attribute
9494

9595
r[attributes.codegen.target_feature.intro]
96-
The *`target_feature` [attribute]* may be applied to a function to
97-
enable code generation of that function for specific platform architecture
98-
features. It uses the [MetaListNameValueStr] syntax with a single key of
99-
`enable` whose value is a string of comma-separated feature names to enable.
96+
The *`target_feature` [attribute]* may be applied to a function to enable code generation of that function for specific platform architecture features. It uses the [MetaListNameValueStr] syntax with a single key of `enable` whose value is a string of comma-separated feature names to enable.
10097

10198
```rust
10299
# #[cfg(target_feature = "avx2")]
@@ -105,26 +102,19 @@ fn foo_avx2() {}
105102
```
106103

107104
r[attributes.codegen.target_feature.arch]
108-
Each [target architecture] has a set of features that may be enabled. It is an
109-
error to specify a feature for a target architecture that the crate is not
110-
being compiled for.
105+
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.
111106

112107
r[attributes.codegen.target_feature.closures]
113-
Closures defined within a `target_feature`-annotated function inherit the
114-
attribute from the enclosing function.
108+
Closures defined within a `target_feature`-annotated function inherit the attribute from the enclosing function.
115109

116110
r[attributes.codegen.target_feature.target-ub]
117-
It is [undefined behavior] to call a function that is compiled with a feature
118-
that is not supported on the current platform the code is running on, *except*
119-
if the platform explicitly documents this to be safe.
111+
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.
120112

121113
r[attributes.codegen.target_feature.safety-restrictions]
122114
The following restrictions apply unless otherwise specified by the platform rules below:
123115

124-
- Safe `#[target_feature]` functions (and closures that inherit the attribute) can only be safely called within a caller that enables all the `target_feature`s that the callee enables.
125-
This restriction does not apply in an `unsafe` context.
126-
- Safe `#[target_feature]` functions (and closures that inherit the attribute) can only be coerced to *safe* function pointers in contexts that enable all the `target_feature`s that the coercee enables.
127-
This restriction does not apply to `unsafe` function pointers.
116+
- Safe `#[target_feature]` functions (and closures that inherit the attribute) can only be safely called within a caller that enables all the `target_feature`s that the callee enables. This restriction does not apply in an `unsafe` context.
117+
- Safe `#[target_feature]` functions (and closures that inherit the attribute) can only be coerced to *safe* function pointers in contexts that enable all the `target_feature`s that the coercee enables. This restriction does not apply to `unsafe` function pointers.
128118

129119
Implicitly enabled features are included in this rule. For example an `sse2` function can call ones marked with `sse`.
130120

@@ -169,9 +159,7 @@ The `#[target_feature]` attribute is not allowed on the following places:
169159
- safe default functions in traits
170160

171161
r[attributes.codegen.target_feature.inline]
172-
Functions marked with `target_feature` are not inlined into a context that
173-
does not support the given features. The `#[inline(always)]` attribute may not
174-
be used with a `target_feature` attribute.
162+
Functions marked with `target_feature` are not inlined into a context that does not support the given features. The `#[inline(always)]` attribute may not be used with a `target_feature` attribute.
175163

176164
r[attributes.codegen.target_feature.availability]
177165
### Available features
@@ -181,9 +169,7 @@ The following is a list of the available feature names.
181169
r[attributes.codegen.target_feature.x86]
182170
#### `x86` or `x86_64`
183171

184-
Executing code with unsupported features is undefined behavior on this platform.
185-
Hence on this platform usage of `#[target_feature]` functions follows the
186-
[above restrictions][attributes.codegen.target_feature.safety-restrictions].
172+
Executing code with unsupported features is undefined behavior on this platform. Hence on this platform usage of `#[target_feature]` functions follows the [above restrictions][attributes.codegen.target_feature.safety-restrictions].
187173

188174
Feature | Implicitly Enables | Description
189175
------------|--------------------|-------------------
@@ -303,11 +289,9 @@ Feature | Implicitly Enables | Description
303289
r[attributes.codegen.target_feature.aarch64]
304290
#### `aarch64`
305291

306-
On this platform the usage of `#[target_feature]` functions follows the
307-
[above restrictions][attributes.codegen.target_feature.safety-restrictions].
292+
On this platform the usage of `#[target_feature]` functions follows the [above restrictions][attributes.codegen.target_feature.safety-restrictions].
308293

309-
Further documentation on these features can be found in the [ARM Architecture
310-
Reference Manual], or elsewhere on [developer.arm.com].
294+
Further documentation on these features can be found in the [ARM Architecture Reference Manual], or elsewhere on [developer.arm.com].
311295

312296
[ARM Architecture Reference Manual]: https://developer.arm.com/documentation/ddi0487/latest
313297
[developer.arm.com]: https://developer.arm.com
@@ -366,8 +350,7 @@ Feature | Implicitly Enables | Feature Name
366350
r[attributes.codegen.target_feature.loongarch]
367351
#### `loongarch`
368352

369-
On this platform the usage of `#[target_feature]` functions follows the
370-
[above restrictions][attributes.codegen.target_feature.safety-restrictions].
353+
On this platform the usage of `#[target_feature]` functions follows the [above restrictions][attributes.codegen.target_feature.safety-restrictions].
371354

372355
Feature | Implicitly Enables | Description
373356
------------|---------------------|-------------------
@@ -392,12 +375,9 @@ Feature | Implicitly Enables | Description
392375
r[attributes.codegen.target_feature.riscv]
393376
#### `riscv32` or `riscv64`
394377

395-
On this platform the usage of `#[target_feature]` functions follows the
396-
[above restrictions][attributes.codegen.target_feature.safety-restrictions].
378+
On this platform the usage of `#[target_feature]` functions follows the [above restrictions][attributes.codegen.target_feature.safety-restrictions].
397379

398-
Further documentation on these features can be found in their respective
399-
specification. Many specifications are described in the [RISC-V ISA Manual] or
400-
in another manual hosted on the [RISC-V GitHub Account].
380+
Further documentation on these features can be found in their respective specification. Many specifications are described in the [RISC-V ISA Manual] or in another manual hosted on the [RISC-V GitHub Account].
401381

402382
[RISC-V ISA Manual]: https://github.com/riscv/riscv-isa-manual
403383
[RISC-V GitHub Account]: https://github.com/riscv
@@ -453,11 +433,7 @@ Feature | Implicitly Enables | Description
453433
r[attributes.codegen.target_feature.wasm]
454434
#### `wasm32` or `wasm64`
455435

456-
Safe `#[target_feature]` functions may always be used in safe contexts on Wasm
457-
platforms. It is impossible to cause undefined behavior via the
458-
`#[target_feature]` attribute because attempting to use instructions
459-
unsupported by the Wasm engine will fail at load time without the risk of being
460-
interpreted in a way different from what the compiler expected.
436+
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.
461437

462438
Feature | Implicitly Enables | Description
463439
----------------------|---------------------|-------------------
@@ -487,14 +463,10 @@ r[attributes.codegen.target_feature.info]
487463
### Additional information
488464

489465
r[attributes.codegen.target_feature.remark-cfg]
490-
See the [`target_feature` conditional compilation option] for selectively
491-
enabling or disabling compilation of code based on compile-time settings. Note
492-
that this option is not affected by the `target_feature` attribute, and is
493-
only driven by the features enabled for the entire crate.
466+
See the [`target_feature` conditional compilation option] for selectively enabling or disabling compilation of code based on compile-time settings. Note that this option is not affected by the `target_feature` attribute, and is only driven by the features enabled for the entire crate.
494467

495468
r[attributes.codegen.target_feature.remark-rt]
496-
See the [`is_x86_feature_detected`] or [`is_aarch64_feature_detected`] macros
497-
in the standard library for runtime feature detection on these platforms.
469+
See the [`is_x86_feature_detected`] or [`is_aarch64_feature_detected`] macros in the standard library for runtime feature detection on these platforms.
498470

499471
> [!NOTE]
500472
> `rustc` has a default set of features enabled for each target and CPU. The CPU may be chosen with the [`-C target-cpu`] flag. Individual features may be enabled or disabled for an entire crate with the [`-C target-feature`] flag.

0 commit comments

Comments
 (0)