rust/compiler/rustc_codegen_ssa/src
bors b583ede652 Auto merge of #99767 - LeSeulArtichaut:stable-target-feature-11, r=estebank
Stabilize `#![feature(target_feature_11)]`

## Stabilization report

### Summary

Allows for safe functions to be marked with `#[target_feature]` attributes.

Functions marked with `#[target_feature]` are generally considered as unsafe functions: they are unsafe to call, cannot be assigned to safe function pointers, and don't implement the `Fn*` traits.

However, calling them from other `#[target_feature]` functions with a superset of features is safe.

```rust
// Demonstration function
#[target_feature(enable = "avx2")]
fn avx2() {}

fn foo() {
    // Calling `avx2` here is unsafe, as we must ensure
    // that AVX is available first.
    unsafe {
        avx2();
    }
}

#[target_feature(enable = "avx2")]
fn bar() {
    // Calling `avx2` here is safe.
    avx2();
}
```

### Test cases

Tests for this feature can be found in [`src/test/ui/rfcs/rfc-2396-target_feature-11/`](b67ba9ba20/src/test/ui/rfcs/rfc-2396-target_feature-11/).

### Edge cases

- https://github.com/rust-lang/rust/issues/73631

Closures defined inside functions marked with `#[target_feature]` inherit the target features of their parent function. They can still be assigned to safe function pointers and implement the appropriate `Fn*` traits.

```rust
#[target_feature(enable = "avx2")]
fn qux() {
    let my_closure = || avx2(); // this call to `avx2` is safe
    let f: fn() = my_closure;
}
```

This means that in order to call a function with `#[target_feature]`, you must show that the target-feature is available while the function executes *and* for as long as whatever may escape from that function lives.

### Documentation

- Reference: https://github.com/rust-lang/reference/pull/1181

---
cc tracking issue #69098
r? `@ghost`
2023-02-28 01:14:56 +00:00
..
back Rename many interner functions. 2023-02-24 07:32:24 +11:00
coverageinfo
debuginfo s/eval_usize/eval_target_usize/ for clarity 2023-02-14 08:51:19 +00:00
mir Rollup merge of #108364 - Nilstrieb:validity-checks-refactor, r=compiler-errors 2023-02-27 06:11:52 +01:00
traits various: translation resources from cg backend 2023-02-22 09:15:54 +00:00
base.rs Rename many interner functions. 2023-02-24 07:32:24 +11:00
codegen_attrs.rs Auto merge of #99767 - LeSeulArtichaut:stable-target-feature-11, r=estebank 2023-02-28 01:14:56 +00:00
common.rs DELETE - fn span_invalid_monomorphization_error and localize intrinsics macros 2022-12-27 20:59:22 -05:00
errors.rs errors: generate typed identifiers in each crate 2023-02-22 09:15:53 +00:00
glue.rs Add 0..=isize::MAX range metadata to size loads from vtables 2022-12-08 01:30:07 -05:00
lib.rs errors: generate typed identifiers in each crate 2023-02-22 09:15:53 +00:00
meth.rs rustc: Remove needless lifetimes 2022-12-20 22:10:40 +01:00
mono_item.rs Store a LocalDefId in hir::AnonConst. 2022-11-13 14:06:11 +00:00
target_features.rs Rollup merge of #108086 - alexcrichton:wasm-relaxed-simd-feature, r=eholk 2023-02-17 00:19:36 +01:00