-
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
Implement RFC 2396: #[target_feature]
1.1
#69274
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2474f0e
Allow `#[target_feature]` on safe functions
LeSeulArtichaut f2c6cbd
Prevent calls to functions with `#[target_feature]` in safe contexts
LeSeulArtichaut f9b9ba5
Prevent functions with `#[target_feature]` to be coerced to safe func…
LeSeulArtichaut 8d9f73a
Add new tests and bless old tests
LeSeulArtichaut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Tests the new rules added by RFC 2396, including: | ||
// - applying `#[target_feature]` to safe functions is allowed | ||
// - calling functions with `#[target_feature]` is allowed in | ||
// functions which have (at least) the same features | ||
// - calling functions with `#[target_feature]` is allowed in | ||
// unsafe contexts | ||
// - functions with `#[target_feature]` can coerce to unsafe fn pointers | ||
|
||
// check-pass | ||
LeSeulArtichaut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// only-x86_64 | ||
|
||
#![feature(target_feature_11)] | ||
|
||
#[target_feature(enable = "sse2")] | ||
const fn sse2() {} | ||
|
||
#[cfg(target_feature = "sse2")] | ||
const SSE2_ONLY: () = unsafe { | ||
sse2(); | ||
}; | ||
|
||
#[target_feature(enable = "sse2")] | ||
fn also_sse2() { | ||
sse2(); | ||
} | ||
|
||
#[target_feature(enable = "sse2")] | ||
#[target_feature(enable = "avx")] | ||
fn sse2_and_avx() { | ||
sse2(); | ||
} | ||
|
||
struct Foo; | ||
|
||
impl Foo { | ||
#[target_feature(enable = "sse2")] | ||
fn sse2(&self) { | ||
sse2(); | ||
} | ||
} | ||
|
||
fn main() { | ||
if cfg!(target_feature = "sse2") { | ||
unsafe { | ||
sse2(); | ||
Foo.sse2(); | ||
} | ||
} | ||
let sse2_ptr: unsafe fn() = sse2; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/test/ui/rfcs/rfc-2396-target_feature-11/feature-gate-target_feature_11.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// only-x86_64 | ||
|
||
#[target_feature(enable = "sse2")] //~ ERROR can only be applied to `unsafe` functions | ||
fn foo() {} | ||
|
||
fn main() {} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/rfcs/rfc-2396-target_feature-11/feature-gate-target_feature_11.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions | ||
--> $DIR/feature-gate-target_feature_11.rs:3:1 | ||
| | ||
LL | #[target_feature(enable = "sse2")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | fn foo() {} | ||
| ----------- not an `unsafe` function | ||
| | ||
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information | ||
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// only-x86_64 | ||
|
||
#![feature(target_feature_11)] | ||
|
||
#[target_feature(enable = "sse2")] | ||
fn foo() {} | ||
|
||
fn main() { | ||
let foo: fn() = foo; //~ ERROR mismatched types | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/fn-ptr.rs:9:21 | ||
| | ||
LL | #[target_feature(enable = "sse2")] | ||
| ---------------------------------- `#[target_feature]` added here | ||
... | ||
LL | let foo: fn() = foo; | ||
| ---- ^^^ cannot coerce functions with `#[target_feature]` to safe function pointers | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected fn pointer `fn()` | ||
found fn item `fn() {foo}` | ||
= note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not even a nit, just curious: what does this affect, and why is
TargetFeatureCast
different from the similar-in-spiritIntrinsicCast
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, there is no particular reason. This is my first
majornon-minor contribution to the compiler, so I basically searched for things similar to what I tried to implement. I wonder if we could merge the two though, since I use the distinction between the two to have an adapted error message.