-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Stabilize target_feature_11 #116114
base: master
Are you sure you want to change the base?
Stabilize target_feature_11 #116114
Conversation
#116078 has been merged and added a test with |
10c6f3a
to
f0748b2
Compare
Thanks for the heads up! I realized the stdarch submodule uses the feature as well. I'm not quite sure how to work around that. (cc @Amanieu) |
I don't think any workaround is needed? stdarch doesn't specify its own features since it is directly included in libcore. |
Do we make the issue around target features affecting ABI any worse with this? If I understand the RFC correctly, then this allows safe code to do something like extern "C" fn no_target_feature(x: __m256) {}
#[target_feature(enable = "avx")]
extern "C" fn with_target_feature(x: __m256) {
no_target_feature(x);
} Calling (See #116558 for the ABI issue itself.) |
One potential fix for that would be to deny using this feature for non- |
@RalfJung is it indeed UB or is the caller aware of those target features? In general when there is call of a function with ABI X (and I consider target features to be part of the ABI), then no matter what the ABI of the surrounding context is, the way X gets invoked should always be through that X ABI. That's a should and not a does because I don't know if it's actually implemented that way. |
That's not how it works, and that's not how it could possibly work since So right now unfortunately the target features of the caller are used to compute the ABI. It's terrible but it's what we got. Also see #116558. |
Right now on stable we require
IMO one can refine this later on to allow some fn pointer conversions safely while banning others. But it's generally in the domain of the "safe transmute" project.
Yeah then the current target_feature 1.1 implementation is not sound and, I would think this is a clear case for a stabilization blocker. |
I think I'd rather fix the ABI to not depend on target features, than equiv function pointers with target feature information. But anyway that's a discussion for #116558. Note that this doesn't just affect |
I had been wondering about that, which is why I didn't immediately push for stabilizing this again. I don't believe anyone really knows since our ABI code is a mess. |
I support limiting it to |
I'll restate here what I said in #116558 (comment): If we want to take advantage of |
Note that the reproducer for #116558 only uses |
You said this in the linked comment
to me that sounds like the opposite of what you were saying. Which one do you mean? |
I see, you're right. So it sounds to me like this is less of a TF 1.1 problem, and more like it is impossible to use even existing |
The issue isn't with TF1.1, but I feel like allowing more things in safe code here would be a mistake given the pitfalls we currently have. |
☔ The latest upstream changes (presumably #116550) made this pull request unmergeable. Please resolve the merge conflicts. |
Both :). Those are different statements but I don't think they are opposites. |
rust-lang/lang-team#235 suggests a design to resolve the ABI issues, which would then hopefully unblock target-feature 1.1. |
Stabilization report
This is a redo of #99767. Most of this commit and report were copied from that PR. Thanks @LeSeulArtichaut!
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 theFn*
traits.However, calling them from other
#[target_feature]
functions with a superset of features is safe.Test cases
Tests for this feature can be found in
src/test/ui/rfcs/rfc-2396-target_feature-11/
.Edge cases
Closures
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 appropriateFn*
traits.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.Closures accept
#[inline(always)]
, even within functions marked with#[target_feature]
. Since these attributes conflict,#[inline(always)]
wins out to maintain compatibility.Special functions
#[target_feature]
is allowed onmain
#108645#[target_feature]
is allowed on default implementations #108646#[target_feature]
on lang item functions #115910The
#[target_feature]
attribute is forbidden from a variety of special functions, such asmain
, current and future lang items (e.g.#[start]
,#[panic_handler]
), and default trait implementations.Documentation
target_feature_11
feature reference#1181cc tracking issue #69098
cc @workingjubilee
r? @rust-lang/lang