-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Closures inherit #[optimize] from the enclosing function by default. #158901
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| //! Ensure that `#[optimize]` applied to an outer function is inherited by closures | ||
| //! and their coercion shims, unless overridden by an explicit `#[optimize]` on the closure. | ||
|
|
||
| //@ compile-flags: -Copt-level=3 | ||
|
|
||
| #![feature(optimize_attribute)] | ||
| #![crate_type = "lib"] | ||
|
|
||
| // CHECK-DAG: define{{.*}}void {{.*}}test_none{{.*}}call_once{{.*}}#[[ATTR_NONE:[0-9]+]] | ||
| // CHECK-DAG: define{{.*}}void {{.*}}test_none{{.*}}B{{[0-9]+}}_() {{.*}}#[[ATTR_NONE]] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly a silly question: what's that (I get worried about anything too specific in name checks because we've been bitten before by people doing things like |
||
| // CHECK-DAG: define{{.*}}void {{.*}}test_size{{.*}}call_once{{.*}}#[[ATTR_SIZE:[0-9]+]] | ||
| // CHECK-DAG: define{{.*}}void {{.*}}test_override_size{{.*}}call_once{{.*}}#[[ATTR_SIZE]] | ||
| // CHECK-DAG: define{{.*}}void {{.*}}test_override_none{{.*}}call_once{{.*}}#[[ATTR_NONE]] | ||
|
|
||
| // CHECK-DAG: attributes #[[ATTR_NONE]] = { {{.*}}noinline{{.*}}optnone{{.*}} } | ||
| // CHECK-DAG: attributes #[[ATTR_SIZE]] = { {{.*}}optsize{{.*}} } | ||
|
|
||
| extern "C" { | ||
| fn side_effect_1(); | ||
| fn side_effect_2(); | ||
| fn side_effect_3(); | ||
| fn side_effect_4(); | ||
| } | ||
|
|
||
| #[optimize(none)] | ||
| #[no_mangle] | ||
| pub fn test_none() -> fn() { | ||
| let closure = || unsafe { side_effect_1() }; | ||
| closure | ||
| } | ||
|
|
||
| #[optimize(size)] | ||
| #[no_mangle] | ||
| pub fn test_size() -> fn() { | ||
| let closure = || unsafe { side_effect_2() }; | ||
| closure | ||
|
veluca93 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| #[optimize(none)] | ||
| #[no_mangle] | ||
| pub fn test_override_size() -> fn() { | ||
| let closure = { | ||
| #[optimize(size)] | ||
| || unsafe { side_effect_3() } | ||
| }; | ||
| closure | ||
| } | ||
|
|
||
| #[optimize(size)] | ||
| #[no_mangle] | ||
| pub fn test_override_none() -> fn() { | ||
| let closure = { | ||
| #[optimize(none)] | ||
| || unsafe { side_effect_4() } | ||
| }; | ||
| closure | ||
| } | ||
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.
suggestion: I think you can do this as a
-C no-prepopulate-passestest, right? Since we're the ones setting the attributes?That would mean you'd have no need to handle all the attributes introduced today (or could be introduced in the future) in the CHECK lines, which would hopefully let it be a touch simpler.
(Might even be able to remove the
side_effectfunctions because with no LLVM optimizations going on that shouldn't matter? Or at least only need one of them without also needing-Z merge-functions=disabled.)