Skip to content

target-feature 1.1: should closures inherit target-feature annotations? #73631

Closed
@nikomatsakis

Description

@nikomatsakis

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 implement FnOnce, which might be surprising and non-obvious.

Metadata

Metadata

Labels

A-target-featureArea: Enabling/disabling target features like AVX, Neon, etc.F-target_feature_11target feature 1.1 RFCT-langRelevant to the language team, which will review and decide on the PR/issue.disposition-mergeThis 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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions