Closed
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.