Skip to content

Commit

Permalink
Stabilize target_feature_11
Browse files Browse the repository at this point in the history
  • Loading branch information
calebzulawski committed Sep 25, 2023
1 parent 6f13ea0 commit f0748b2
Show file tree
Hide file tree
Showing 33 changed files with 70 additions and 151 deletions.
27 changes: 8 additions & 19 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
{
if tcx.sess.target.is_like_wasm || tcx.sess.opts.actually_rustdoc {
// The `#[target_feature]` attribute is allowed on
// WebAssembly targets on all functions, including safe
// ones. Other targets require that `#[target_feature]` is
// only applied to unsafe functions (pending the
// `target_feature_11` feature) because on most targets
// WebAssembly targets on all functions. Prior to stabilizing
// the `target_feature_11` feature, `#[target_feature]` was
// only permitted on safe functions because on most targets
// execution of instructions that are not supported is
// considered undefined behavior. For WebAssembly which is a
// 100% safe target at execution time it's not possible to
Expand All @@ -295,17 +294,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
// if a target is documenting some wasm-specific code then
// it's not spuriously denied.
//
// This exception needs to be kept in sync with allowing
// `#[target_feature]` on `main` and `start`.
} else if !tcx.features().target_feature_11 {
let mut err = feature_err(
&tcx.sess.parse_sess,
sym::target_feature_11,
attr.span,
"`#[target_feature(..)]` can only be applied to `unsafe` functions",
);
err.span_label(tcx.def_span(did), "not an `unsafe` function");
err.emit();
// Now that `#[target_feature]` is permitted on safe functions,
// this exception must still exist for allowing the attribute on
// `main`, `start`, and other functions that are not usually
// allowed.
} else {
check_target_feature_trait_unsafe(tcx, did, attr.span);
}
Expand Down Expand Up @@ -535,10 +527,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
// its parent function, which effectively inherits the features anyway. Boxing this closure
// would result in this closure being compiled without the inherited target features, but this
// is probably a poor usage of `#[inline(always)]` and easily avoided by not using the attribute.
if tcx.features().target_feature_11
&& tcx.is_closure(did.to_def_id())
&& codegen_fn_attrs.inline != InlineAttr::Always
{
if tcx.is_closure(did.to_def_id()) && codegen_fn_attrs.inline != InlineAttr::Always {
let owner_id = tcx.parent(did.to_def_id());
if tcx.def_kind(owner_id).has_codegen_attrs() {
codegen_fn_attrs
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ declare_features! (
(accepted, struct_variant, "1.0.0", None, None),
/// Allows `#[target_feature(...)]`.
(accepted, target_feature, "1.27.0", None, None),
/// Allows the use of `#[target_feature]` on safe functions.
(accepted, target_feature_11, "CURRENT_RUSTC_VERSION", Some(69098), None),
/// Allows `fn main()` with return types which implements `Termination` (RFC 1937).
(accepted, termination_trait, "1.26.0", Some(43301), None),
/// Allows `#[test]` functions where the return type implements `Termination` (RFC 1937).
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,6 @@ declare_features! (
(active, strict_provenance, "1.61.0", Some(95228), None),
/// Allows string patterns to dereference values to match them.
(active, string_deref_patterns, "1.67.0", Some(87121), None),
/// Allows the use of `#[target_feature]` on safe functions.
(active, target_feature_11, "1.45.0", Some(69098), None),
/// Allows using `#[thread_local]` on `static` items.
(active, thread_local, "1.0.0", Some(29594), None),
/// Allows defining `trait X = A + B;` alias items.
Expand Down
1 change: 0 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@
#![feature(simd_ffi)]
#![feature(staged_api)]
#![feature(stmt_expr_attributes)]
#![feature(target_feature_11)]
#![feature(trait_alias)]
#![feature(transparent_unions)]
#![feature(try_blocks)]
Expand Down
1 change: 0 additions & 1 deletion tests/assembly/closure-inherit-target-feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// make sure the feature is not enabled at compile-time
// compile-flags: -C opt-level=3 -C target-feature=-sse4.1 -C llvm-args=-x86-asm-syntax=intel

#![feature(target_feature_11)]
#![crate_type = "rlib"]

use std::arch::x86_64::{__m128, _mm_blend_ps};
Expand Down
1 change: 0 additions & 1 deletion tests/codegen/target-feature-inline-closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// compile-flags: -Copt-level=3

#![crate_type = "lib"]
#![feature(target_feature_11)]

#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::*;
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/inline/inline_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#![crate_type = "lib"]
#![feature(no_sanitize)]
#![feature(target_feature_11)]
#![feature(c_variadic)]

// EMIT_MIR inline_compatibility.inlined_target_feature.Inline.diff
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/asm/x86_64/issue-89875.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// needs-asm-support
// only-x86_64

#![feature(target_feature_11)]

use std::arch::asm;

#[target_feature(enable = "avx")]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/lang-items/start_lang_item_with_target_feature.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// only-x86_64
// check-fail

#![feature(lang_items, no_core, target_feature_11)]
#![feature(lang_items, no_core)]
#![no_core]

#[lang = "copy"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// compile-flags:-C panic=abort
// only-x86_64

#![feature(target_feature_11)]
#![no_std]
#![no_main]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: `panic_impl` language item function is not allowed to have `#[target_feature]`
--> $DIR/panic-handler-with-target-feature.rs:11:1
--> $DIR/panic-handler-with-target-feature.rs:10:1
|
LL | #[target_feature(enable = "avx2")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/rfcs/rfc-2396-target_feature-11/check-pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// revisions: mir thir
// [thir]compile-flags: -Z thir-unsafeck

#![feature(target_feature_11)]

#[target_feature(enable = "sse2")]
const fn sse2() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// [thir]compile-flags: -Z thir-unsafeck
// only-x86_64

#![feature(target_feature_11)]

#[target_feature(enable="avx")]
fn also_use_avx() {
println!("Hello from AVX")
Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.mir.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/fn-ptr.rs:11:21
--> $DIR/fn-ptr.rs:9:21
|
LL | #[target_feature(enable = "sse2")]
| ---------------------------------- `#[target_feature]` added here
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// [thir]compile-flags: -Z thir-unsafeck
// only-x86_64

#![feature(target_feature_11)]

#[target_feature(enable = "sse2")]
fn foo() {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/fn-ptr.rs:11:21
--> $DIR/fn-ptr.rs:9:21
|
LL | #[target_feature(enable = "sse2")]
| ---------------------------------- `#[target_feature]` added here
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/rfcs/rfc-2396-target_feature-11/fn-traits.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// only-x86_64

#![feature(target_feature_11)]

#[target_feature(enable = "avx")]
fn foo() {}

Expand Down
24 changes: 12 additions & 12 deletions tests/ui/rfcs/rfc-2396-target_feature-11/fn-traits.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: expected a `Fn<()>` closure, found `fn() {foo}`
--> $DIR/fn-traits.rs:24:10
--> $DIR/fn-traits.rs:22:10
|
LL | call(foo);
| ---- ^^^ expected an `Fn<()>` closure, found `fn() {foo}`
Expand All @@ -10,13 +10,13 @@ LL | call(foo);
= note: wrap the `fn() {foo}` in a closure with no arguments: `|| { /* code */ }`
= note: `#[target_feature]` functions do not implement the `Fn` traits
note: required by a bound in `call`
--> $DIR/fn-traits.rs:11:17
--> $DIR/fn-traits.rs:9:17
|
LL | fn call(f: impl Fn()) {
| ^^^^ required by this bound in `call`

error[E0277]: expected a `FnMut<()>` closure, found `fn() {foo}`
--> $DIR/fn-traits.rs:25:14
--> $DIR/fn-traits.rs:23:14
|
LL | call_mut(foo);
| -------- ^^^ expected an `FnMut<()>` closure, found `fn() {foo}`
Expand All @@ -27,13 +27,13 @@ LL | call_mut(foo);
= note: wrap the `fn() {foo}` in a closure with no arguments: `|| { /* code */ }`
= note: `#[target_feature]` functions do not implement the `Fn` traits
note: required by a bound in `call_mut`
--> $DIR/fn-traits.rs:15:21
--> $DIR/fn-traits.rs:13:21
|
LL | fn call_mut(f: impl FnMut()) {
| ^^^^^^^ required by this bound in `call_mut`

error[E0277]: expected a `FnOnce<()>` closure, found `fn() {foo}`
--> $DIR/fn-traits.rs:26:15
--> $DIR/fn-traits.rs:24:15
|
LL | call_once(foo);
| --------- ^^^ expected an `FnOnce<()>` closure, found `fn() {foo}`
Expand All @@ -44,13 +44,13 @@ LL | call_once(foo);
= note: wrap the `fn() {foo}` in a closure with no arguments: `|| { /* code */ }`
= note: `#[target_feature]` functions do not implement the `Fn` traits
note: required by a bound in `call_once`
--> $DIR/fn-traits.rs:19:22
--> $DIR/fn-traits.rs:17:22
|
LL | fn call_once(f: impl FnOnce()) {
| ^^^^^^^^ required by this bound in `call_once`

error[E0277]: expected a `Fn<()>` closure, found `unsafe fn() {foo_unsafe}`
--> $DIR/fn-traits.rs:28:10
--> $DIR/fn-traits.rs:26:10
|
LL | call(foo_unsafe);
| ---- ^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }`
Expand All @@ -61,13 +61,13 @@ LL | call(foo_unsafe);
= note: wrap the `unsafe fn() {foo_unsafe}` in a closure with no arguments: `|| { /* code */ }`
= note: `#[target_feature]` functions do not implement the `Fn` traits
note: required by a bound in `call`
--> $DIR/fn-traits.rs:11:17
--> $DIR/fn-traits.rs:9:17
|
LL | fn call(f: impl Fn()) {
| ^^^^ required by this bound in `call`

error[E0277]: expected a `FnMut<()>` closure, found `unsafe fn() {foo_unsafe}`
--> $DIR/fn-traits.rs:30:14
--> $DIR/fn-traits.rs:28:14
|
LL | call_mut(foo_unsafe);
| -------- ^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }`
Expand All @@ -78,13 +78,13 @@ LL | call_mut(foo_unsafe);
= note: wrap the `unsafe fn() {foo_unsafe}` in a closure with no arguments: `|| { /* code */ }`
= note: `#[target_feature]` functions do not implement the `Fn` traits
note: required by a bound in `call_mut`
--> $DIR/fn-traits.rs:15:21
--> $DIR/fn-traits.rs:13:21
|
LL | fn call_mut(f: impl FnMut()) {
| ^^^^^^^ required by this bound in `call_mut`

error[E0277]: expected a `FnOnce<()>` closure, found `unsafe fn() {foo_unsafe}`
--> $DIR/fn-traits.rs:32:15
--> $DIR/fn-traits.rs:30:15
|
LL | call_once(foo_unsafe);
| --------- ^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }`
Expand All @@ -95,7 +95,7 @@ LL | call_once(foo_unsafe);
= note: wrap the `unsafe fn() {foo_unsafe}` in a closure with no arguments: `|| { /* code */ }`
= note: `#[target_feature]` functions do not implement the `Fn` traits
note: required by a bound in `call_once`
--> $DIR/fn-traits.rs:19:22
--> $DIR/fn-traits.rs:17:22
|
LL | fn call_once(f: impl FnOnce()) {
| ^^^^^^^^ required by this bound in `call_once`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// only-x86_64

#![feature(target_feature_11)]

#[target_feature(enable = "avx2")]
fn main() {}
//~^ ERROR `main` function is not allowed to have `#[target_feature]`
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: `main` function is not allowed to have `#[target_feature]`
--> $DIR/issue-108645-target-feature-on-main.rs:6:1
--> $DIR/issue-108645-target-feature-on-main.rs:4:1
|
LL | fn main() {}
| ^^^^^^^^^ `main` function is not allowed to have `#[target_feature]`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// only-x86_64

#![feature(start)]
#![feature(target_feature_11)]

#[start]
#[target_feature(enable = "avx2")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: `#[start]` function is not allowed to have `#[target_feature]`
--> $DIR/issue-108645-target-feature-on-start.rs:7:1
--> $DIR/issue-108645-target-feature-on-start.rs:6:1
|
LL | #[target_feature(enable = "avx2")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// [thir]compile-flags: -Z thir-unsafeck
// only-x86_64

#![feature(target_feature_11)]

#[target_feature(enable = "avx")]
pub unsafe fn test() {
({
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/rfcs/rfc-2396-target_feature-11/issue-99876.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// check-pass

#![feature(target_feature_11)]

struct S<T>(T)
where
[T; (|| {}, 1).1]: Copy;
Expand Down
Loading

0 comments on commit f0748b2

Please sign in to comment.