Skip to content

feat: warn on #[derive(Packable)] with sub-optimal packing#21565

Open
nventuro wants to merge 2 commits intomerge-train/fairiesfrom
nico/f-260-warn-on-packable-with-small-types
Open

feat: warn on #[derive(Packable)] with sub-optimal packing#21565
nventuro wants to merge 2 commits intomerge-train/fairiesfrom
nico/f-260-warn-on-packable-with-small-types

Conversation

@nventuro
Copy link
Contributor

Emits a compile-time warning when #[derive(Packable)] is used on structs with 2+ sub-Field members (bools, integers, arrays of these) that could be bit-packed into fewer Fields manually. Uses println as a stopgap since comptime warn doesn't exist yet (noir-lang/noir#7714).

Emits a compile-time warning when `#[derive(Packable)]` is used on structs
with 2+ sub-Field members (bools, integers, arrays of these) that could be
bit-packed into fewer Fields manually. Uses `println` as a stopgap since
comptime `warn` doesn't exist yet (noir-lang/noir#7714).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Contributor

@benesjan benesjan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code:

#[derive(Packable)]
struct MyStruct {
    a: u128,
    b: u128,
}

would show the warning even thought the derived implementation would be optimal.

I think this should be handled by counting the bit sizes.

But overall think showing the warning is a very nice approach 👍

@benesjan benesjan force-pushed the nico/f-260-warn-on-packable-with-small-types branch from 090f818 to ea99baf Compare March 16, 2026 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants