Skip to content

Commit 1de6b6d

Browse files
committed
Change the wording to accomodate expressions
Additionally, clarify propagation of the attribute.
1 parent cef2ebc commit 1de6b6d

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

text/0000-optimise-attr.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,27 @@ yield the same results as using the global optimisation option for speed.
7777
# Reference-level explanation
7878
[reference-level-explanation]: #reference-level-explanation
7979

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

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

8888
The `#[optimize]` attributes are just a hint to the compiler and are not guaranteed to result in
8989
any different code.
9090

9191
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.
9395

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

97102
`#[optimize(speed)]` is a no-op when a global optimisation for speed option is set (i.e. `-C
98103
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
101106
`#[optimize]` attribute with the global optimization level is not specified and is left up to
102107
implementation to decide.
103108

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+
104115
# Implementation approach
105116

106117
For the LLVM backend, these attributes may be implemented in a following manner:
@@ -159,3 +170,4 @@ embedded use-cases.
159170
conjunction with the optimisation for speed option (e.g. `-Copt-level=s3` could be equivalent to
160171
`-Copt-level=3` and `#[optimize(size)]` on the crate item);
161172
* This may matter for users of `#[optimize(speed)]`.
173+
* Are the propagation and `unused_attr` approaches right?

0 commit comments

Comments
 (0)