Auto merge of #55641 - nagisa:optimize-attr, r=pnkfelix

Implement optimize(size) and optimize(speed) attributes

This PR implements both `optimize(size)` and `optimize(speed)` attributes.

While the functionality itself works fine now, this PR is not yet complete: the code might be messy in places and, most importantly, the compiletest must be improved with functionality to run tests with custom optimization levels. Otherwise the new attribute cannot be tested properly. Oh, and not all of the RFC is implemented – attribute propagation is not implemented for example.

# TODO

* [x] Improve compiletest so that tests can be written;
* [x] Assign a proper error number (E9999 currently, no idea how to allocate a number properly);
* [ ] Perhaps reduce the duplication in LLVM attribute assignment code…
This commit is contained in:
bors 2019-01-26 07:08:18 +00:00
commit 42eb5ff404
32 changed files with 449 additions and 129 deletions

View file

@ -0,0 +1,18 @@
#![crate_type="rlib"]
#![optimize(speed)] //~ ERROR #54882
#[optimize(size)] //~ ERROR #54882
mod module {
#[optimize(size)] //~ ERROR #54882
fn size() {}
#[optimize(speed)] //~ ERROR #54882
fn speed() {}
#[optimize(banana)]
//~^ ERROR #54882
//~| ERROR E0722
fn not_known() {}
}

View file

@ -0,0 +1,50 @@
error[E0658]: #[optimize] attribute is an unstable feature (see issue #54882)
--> $DIR/feature-gate-optimize_attribute.rs:7:1
|
LL | #[optimize(size)] //~ ERROR #54882
| ^^^^^^^^^^^^^^^^^
|
= help: add #![feature(optimize_attribute)] to the crate attributes to enable
error[E0658]: #[optimize] attribute is an unstable feature (see issue #54882)
--> $DIR/feature-gate-optimize_attribute.rs:10:1
|
LL | #[optimize(speed)] //~ ERROR #54882
| ^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(optimize_attribute)] to the crate attributes to enable
error[E0658]: #[optimize] attribute is an unstable feature (see issue #54882)
--> $DIR/feature-gate-optimize_attribute.rs:13:1
|
LL | #[optimize(banana)]
| ^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(optimize_attribute)] to the crate attributes to enable
error[E0658]: #[optimize] attribute is an unstable feature (see issue #54882)
--> $DIR/feature-gate-optimize_attribute.rs:4:1
|
LL | #[optimize(size)] //~ ERROR #54882
| ^^^^^^^^^^^^^^^^^
|
= help: add #![feature(optimize_attribute)] to the crate attributes to enable
error[E0658]: #[optimize] attribute is an unstable feature (see issue #54882)
--> $DIR/feature-gate-optimize_attribute.rs:2:1
|
LL | #![optimize(speed)] //~ ERROR #54882
| ^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(optimize_attribute)] to the crate attributes to enable
error[E0722]: invalid argument
--> $DIR/feature-gate-optimize_attribute.rs:13:12
|
LL | #[optimize(banana)]
| ^^^^^^
error: aborting due to 6 previous errors
Some errors occurred: E0658, E0722.
For more information about an error, try `rustc --explain E0658`.