Repository navigation
Lower the LLVM IR output of the generated output - #492
Conversation
|
Thanks for looking at this @bolshoytoster! The internal/public type split is so that if you add |
|
Thanks for the explaination. There's still an improvement from just the |
|
I'm not really sure what to do about the MSRV test failure.
|
|
It looks like I could also use an inner const: fn all() {
const ALL: $BitFlags = {
let mut truncated = <$T as $crate::Bits>::EMPTY;
let mut _i = 0;
$(
$crate::__bitflags_expr_safe_attrs!(
$(#[$inner $($args)*])*
{{
truncated |= <$PublicBitFlags as $crate::Flags>::FLAGS[_i]
.value().bits();
_i += 1;
}}
);
)*
$BitFlags(truncated)
};
ALL
}But that seems a little ugly. |
|
Thanks for working on this @bolshoytoster. I think using an inner const might be the best approach here. We are pretty conservative with our MSRV in |
|
The last issue is the compile-fail tests are giving different error messages. It looks like the difference is just semantic ( - error[E0015]: cannot call non-const operator in constant functions
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
... |
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
- --> tests/compile-fail/bitflags_custom_bits.rs:42:1
|
- 42 | impl BitOr for MyInt {
- | ^^^^^^^^^^^^^^^^^^^^
- = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants+ error[E0015]: cannot call non-const operator in constants
--> tests/compile-fail/bitflags_custom_bits.rs:132:1
|
132 | / bitflags! {
133 | | struct Flags128: MyInt {
134 | | const A = MyInt(0b0000_0001u8);
135 | | const B = MyInt(0b0000_0010u8);
... |
138 | | }
| |_^
|
note: impl defined here, but it is not `const`
+ --> tests/compile-fail/bitflags_custom_bits.rs:64:1
|
+ 64 | impl BitOrAssign for MyInt {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: calls in constants are limited to constant functions, tuple structs and tuple variantsCan I bless it? |
|
Looks good! Yeh the compile fail tests regularly change anyways just from changes in |

This PR lowers the LLVM IR (and MIR) sizes of the generated
allandfrom_namefunctions. (#491)I have wrapped
allinconst {}, which causes it to be evaluated early on. I also decided to simplify the function to reduce what it's evaluating (before:after:
)
I have measured the bloat by adding this file (emulating wgpu's 58-flag
FeaturesWGPU) asexamples/all_bloat.rs:and running
cargo llvm-lines --example all_bloat/cargo llvm-lines --example all_bloat --release.I got the MIR output with
cargo asm --example all_bloat --mir "fn _::<impl at src/lib.rs:658:9: 658:29>::all() -> InternalBitFlags" 0