Repository navigation
Closed
Labels
A-target-featureArea: Enabling/disabling target features like AVX, Neon, etc.Area: Enabling/disabling target features like AVX, Neon, etc.F-target_feature_11target feature 1.1 RFCtarget feature 1.1 RFCT-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
This example currently gives an error (playground):
#![feature(target_feature_11)]
#[target_feature(enable="avx")]
fn also_use_avx() {
println!("Hello from AVX")
}
#[target_feature(enable="avx")]
fn use_avx() -> Box<dyn Fn()> {
Box::new(|| also_use_avx())
}
fn main() {
}Should it? @joshtriplett made the case that, once you enter use_avx, you have demonstrated that the target feature is present on your system, so it would make sense for closures declared within that item to "inherit" the target features from their enclosing function items (i.e., be able to invoke target-feature functions that require them, and probably also get the attributes declared within LLVM).
Some questions:
- Is there some notion of "scoped" target features? i.e., as the example demonstrates, this allows target-feature functions to "escape" into the wider world, is that a problem?
- If closures do inherit, should they still be considered to implement
FnOnceetc? (See target_feature_11 allows bypassing safety checks through Fn* traits #72012) - Would we want the ability to explicitly annotate closures with
#[target_feature(...)]? If so, that would presumably mean that explicitly annotated closures cannot implementFnOnce, which might be surprising and non-obvious.
Reacted by Eric Shimizu Karbstein
Metadata
Metadata
Assignees
Labels
A-target-featureArea: Enabling/disabling target features like AVX, Neon, etc.Area: Enabling/disabling target features like AVX, Neon, etc.F-target_feature_11target feature 1.1 RFCtarget feature 1.1 RFCT-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Activity
nikomatsakis commentedon Jun 22, 2020
cc @hanna-kruppe, @petrochenkov
calebzulawski commentedon Jun 23, 2020
I have run into boxed closures performing poorly, it isn't obvious that something like this would be exceptionally slow--orders of magnitude worse than the naive version since each intrinsic results in a
callq:Not related to closures, but inheriting features, should creating function pointers be allowed as well? For example:
nikomatsakis commentedon Jun 23, 2020
@calebzulawski I think any performance implications of boxing are pretty orthogonal to the question at hand.
The question of coercing to a fn pointer, though, is pretty germane. I think that should probably be supported, yes, by the same logic.
(I guess it would be unsafe to do outside of a suitable target-feature function?)
calebzulawski commentedon Jun 23, 2020
Sorry if I was unclear--I was referring to the fact that the intrinsics fail to inline into the closure despite it appearing within a target-feature function, unrelated to the implication of boxing the closure. Pre-target-feature-1.1 this is particularly non-obvious because the
unsafeblock is always required and there is no indication that the closure isn't inheriting the features.nikomatsakis commentedon Jul 1, 2020
@rfcbot fcp merge
Having heard no objections, I'd like to call this to question. Dear @rust-lang/lang I propose that we make the change described in the OP for the reasons that were outlined there.
rfcbot commentedon Jul 1, 2020
Team member @nikomatsakis has proposed to merge this. The next step is review by the rest of the tagged team members:
No concerns currently listed.
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
nikomatsakis commentedon Jul 6, 2020
Discussed this in our @rust-lang/lang meeting today. Notes from our minutes:
nikomatsakis commentedon Jul 20, 2020
Ping @cramertj @pnkfelix and @withoutboats -- checkbox
dbdr commentedon Sep 1, 2020
I was also expecting inner functions to inherit the target-feature annotations of the outer function. Can this question fit here or does it warrant a separate issue?
workingjubilee commentedon Sep 12, 2020
I'm sorry, I'm not sure I understand everything at hand, but would this not implicitly resolve #64609 question about the Rust calling convention / ABI in favor of yes? Or at least move it much closer to, thus bringing a soundness hole closer to resolution?
11 remaining items
Rollup merge of rust-lang#99767 - LeSeulArtichaut:stable-target-featu…
Auto merge of rust-lang#99767 - LeSeulArtichaut:stable-target-feature…
Auto merge of #99767 - LeSeulArtichaut:stable-target-feature-11, r=es…
Auto merge of #99767 - LeSeulArtichaut:stable-target-feature-11, r=es…
Auto merge of #99767 - LeSeulArtichaut:stable-target-feature-11, r=es…
Auto merge of #99767 - LeSeulArtichaut:stable-target-feature-11, r=es…
Rollup merge of rust-lang#134090 - veluca93:stable-tf11, r=oli-obk
Rollup merge of rust-lang#134090 - veluca93:stable-tf11, r=oli-obk
Rollup merge of rust-lang#134090 - veluca93:stable-tf11, r=oli-obk
Unrolled build for rust-lang#134090
Rollup merge of #134090 - veluca93:stable-tf11, r=oli-obk
Rollup merge of #134090 - veluca93:stable-tf11, r=oli-obk
Rollup merge of rust-lang#134090 - veluca93:stable-tf11, r=oli-obk
Rollup merge of rust-lang#134090 - veluca93:stable-tf11, r=oli-obk