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.
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
target_feature 1.1 #2396
target_feature 1.1 #2396
Changes from 11 commits
76c213b
54083aa
2fec554
f9d4905
39e03e3
aa79d09
b73fc95
96c3abb
48f4616
c82ebf9
cf7f513
f2894b0
4315371
578c30d
6e5ce9d
a81b5a6
6b9a16f
71b9069
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Related RFC: #2585
But the proposal here still makes sense regardless of that.
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.
This seems unfortunate. However, it is fixable by allowing attributes on types syntactically as proposed in #2602. Can you note this as a future possibility? (We have forward compat with this, so it doesn't need to be part of the proposal right now.)
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.
It's not just a matter of syntax, but also semantics, since the attribute would need to be part of the function type, figure out coercions if any, be able to
impl Trait for #[target_feature(eanble = "avx")] fn(...) -> ... { ... }
, etc.And well, in general, the coercion of a
#[target_feature]
fn pointer to a barefn
is unsound, so any kind of future extension would need to solve that problem, but AFAIK nobody has proposed a solution to it.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.
I've added a note, but I'm not sure what you are asking can work.
You are basically asking for, given a trait
Foo
with safe and unsafe methods, a way to implement the safe methods asunsafe fn
s such that code is parametric over that (e.g. because target-feature makes afn
unsafe). This is trivial if all methods in the trait areunsafe
, but if there is one safe method,Foo
could be object safe, and calling its methods would be safe, so I have no idea how we could make anunsafe
version of it sound through that safe API.The realization is that being parametric over target feature is like being parametric over unsafe:
So AFAICT,
impl #[target_feature] Trait
can only work if allTrait
methods areunsafe
, and even then, notice howbaz
does not have a#[target_feature]
attribute, meaning that the call tounsafe { x.foo() }
has little chances of "proving" whether safety is provided, since that would depend on the target features, and these are not specified anywhere.