@@ -77,22 +77,27 @@ yield the same results as using the global optimisation option for speed.
77
77
# Reference-level explanation
78
78
[ reference-level-explanation ] : #reference-level-explanation
79
79
80
- The ` #[optimize(size)] ` attribute applied to an item will instruct the optimisation pipeline to
81
- avoid applying optimisations that could result in a size increase and machine code generator to
82
- generate code that’s smaller rather than faster.
80
+ The ` #[optimize(size)] ` attribute applied to an item or expression will instruct the optimisation
81
+ pipeline to avoid applying optimisations that could result in a size increase and machine code
82
+ generator to generate code that’s smaller rather than faster.
83
83
84
- The ` #[optimize(speed)] ` attribute applied to an item will instruct the optimisation pipeline to
85
- apply optimisations that are likely to yield performance wins and machine code generator to
86
- generate code that’s faster rather than smaller.
84
+ The ` #[optimize(speed)] ` attribute applied to an item or expression will instruct the optimisation
85
+ pipeline to apply optimisations that are likely to yield performance wins and machine code
86
+ generator to generate code that’s faster rather than smaller.
87
87
88
88
The ` #[optimize] ` attributes are just a hint to the compiler and are not guaranteed to result in
89
89
any different code.
90
90
91
91
If an ` #[optimize] ` attribute is applied to some grouping item (such as ` mod ` or a crate), it
92
- propagates transitively to all items defined within the grouping item.
92
+ propagates transitively to all items defined within the grouping item. Note, that a function is
93
+ also a “grouping” item for the purposes of this RFC, and ` #[optimize] ` attribute applied to a
94
+ function will propagate to other functions or closures defined within the body of the function.
93
95
94
- It is an error to specify multiple incompatible ` #[optimize] ` options to a single item at once.
95
- A more explicit ` #[optimize] ` attribute overrides a propagated attribute.
96
+ ` #[optimize] ` attribute may also be applied to a closure expression using the currently unstable
97
+ ` stmt_expr_attributes ` feature.
98
+
99
+ It is an error to specify multiple incompatible ` #[optimize] ` options to a single item or
100
+ expression at once. A more explicit ` #[optimize] ` attribute overrides a propagated attribute.
96
101
97
102
` #[optimize(speed)] ` is a no-op when a global optimisation for speed option is set (i.e. `-C
98
103
opt-level=1-3` ). Similarly ` #[ optimize(size)] ` is a no-op when a global optimisation for size
@@ -101,6 +106,12 @@ are done globally (i.e. `-C opt-level=0`). In all other cases the *exact* intera
101
106
` #[optimize] ` attribute with the global optimization level is not specified and is left up to
102
107
implementation to decide.
103
108
109
+ ` #[optimize] ` attribute applied to non function-like items (such as ` struct ` ) or non function-like
110
+ expressions (i.e. not closures) is considered “unused” as of this RFC and should fire the
111
+ ` unused_attribute ` lint (unless the same attribute was used for a function-like item or expression,
112
+ via e.g. propagation). Some future RFC may assign some behaviour to this attribute with respect to
113
+ such definitions.
114
+
104
115
# Implementation approach
105
116
106
117
For the LLVM backend, these attributes may be implemented in a following manner:
@@ -159,3 +170,4 @@ embedded use-cases.
159
170
conjunction with the optimisation for speed option (e.g. ` -Copt-level=s3 ` could be equivalent to
160
171
` -Copt-level=3 ` and ` #[optimize(size)] ` on the crate item);
161
172
* This may matter for users of ` #[optimize(speed)] ` .
173
+ * Are the propagation and ` unused_attr ` approaches right?
0 commit comments