-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
FnOnce
etc? (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.
GrayJack
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.