Expose alloc as a selectable feature#582
Conversation
|
Hello! This PR follows from the associated discussion thread: I expect it will need (quite?) a few iterations - I'm happy to make progress by mining it for ideas that we can split into separate patches or PRs if necessary. |
I'll make a separate PR for it and add a test case.
That's a fair concern, because I don't think I described what I was actually up to there. The underlying motivation was around updating the CI workflow to allow I figured we could keep the intent of For something to experiment with I grabbed backhand. As it's regular userspace I'm not sure it gives the greatest appreciation for the problem, but it's start. Rather than pull out the
Here's the impact after switching backhand to my local deku tree: [I] 0 andrew@heihei ~/s/g/w/backhand (master)> git grep '^deku ='
backhand/Cargo.toml:deku = { path = "/home/andrew/src/github.com/sharksforarms/deku", default-features = false, features = ["std"] }Given deku's features are explicitly specified by backhand, I force-enabled [I] 0 andrew@heihei ~/s/g/w/backhand (master)> cargo build --release --features="deku/descriptive-errors"
Finished `release` profile [optimized] target(s) in 0.06s
[I] 0 andrew@heihei ~/s/g/w/backhand (master)> bloaty -d sections target/release/unsquashfs-backhand | grep '[.]rodata$'
8.5% 530Ki 10.7% 530Ki .rodata
[I] 0 andrew@heihei ~/s/g/w/backhand (master)> readelf --string-dump .rodata target/release/unsquashfs-backhand | grep --color=never --only-matching -E "Field failed assertion.{5}"
Field failed assertion: Dir
Field failed assertion: Sup
Field failed assertion: Sup
Field failed assertion: Sup
Field failed assertion: Ext
Field failed assertion: Bas
Field failed assertion: DirFor comparison, without enabling [I] 0 andrew@heihei ~/s/g/w/backhand (master)> cargo build --release
Finished `release` profile [optimized] target(s) in 0.05s
[I] 0 andrew@heihei ~/s/g/w/backhand (master)> bloaty -d sections target/release/unsquashfs-backhand | grep '[.]rodata$'
8.5% 529Ki 10.7% 529Ki .rodata
[I] 0 andrew@heihei ~/s/g/w/backhand (master)> readelf --string-dump .rodata target/release/unsquashfs-backhand | grep --color=never --only-matching -E "Field failed assertion.{5}"
Field failed assertionevent
Field failed assertionCouldIt appears the string coalescing behaves (mostly) as I'd expect, given we discard the non-constant portions of the strings in I can squash the |
Hmm, having poked a bit I'm not sure I have a need for the patch yet. I'll drop it for now. I expect I triggered the panic at some point to prompt the rework, but I'll bring it back when I need it. |
|
Any thoughts or feelings on this one so far? I'm wary of the "ugh" factor of the size and tediousness of some of the current approaches. Let me know if I should rework it to address either (even just for the sake of making the changes easier to consume for review). |
|
@wcampbell0x2a thanks! Backing up slightly:
I hadn't actually gone ahead with that as I was waiting on your feedback. However, I'll do so shortly given my impression that the discussion above was reasonable. Let me know otherwise. |
Oh yes. I think I'm in favor of that patch. |
The expectation failed, and further, dead_code triggered on the enum
type itself:
error: enum `Data` is never used
--> tests/test_own_impl.rs:5:14
|
5 | pub enum Data {
| ^^^^
|
= note: `-D dead-code` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(dead_code)]`
error: this lint expectation is unfulfilled
--> tests/test_own_impl.rs:8:18
|
8 | #[expect(dead_code)]
| ^^^^^^^^^
|
= note: `-D unfulfilled-lint-expectations` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(unfulfilled_lint_expectations)]`
Signed-off-by: Andrew Jeffery <[email protected]>
The type is mentioned in commentary on a separate struct, so keep it
for now. Addresses:
error: enum `NestedEnum2` is never used
--> tests/test_alloc.rs:28:6
|
28 | enum NestedEnum2 {
| ^^^^^^^^^^^
|
= note: `-D dead-code` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(dead_code)]`
Signed-off-by: Andrew Jeffery <[email protected]>
The struct was introduced in 59fc760 ("Add count Vec<u8> Specializations (sharksforarms#481)") but yields: error: struct `CountFromCtxWrapper` is never constructed --> benches/deku.rs:135:16 | 135 | pub struct CountFromCtxWrapper { | ^^^^^^^^^^^^^^^^^^^ | = note: `-D dead-code` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(dead_code)]` Mark it as expected for now. Signed-off-by: Andrew Jeffery <[email protected]>
There's too much use of BitVec and the like for it to be sensible to separate them. Signed-off-by: Andrew Jeffery <[email protected]>
Don't make it harder than necessary to use no_std. Signed-off-by: Andrew Jeffery <[email protected]>
|
Okay, I've tidied up the I've also updated the changelog in both 721e24e and 2478ffc. Hopefully that's not a hindrance! |
sharksforarms
left a comment
There was a problem hiding this comment.
Thanks! Looks like a good cleanup of some testing/errors too
Enable use of deku in tightly constrained environments. Signed-off-by: Andrew Jeffery <[email protected]>
Replace DekuError::AssertionNoStr with DekuError::Assertion, in concert
with the deku_error!() macro. deku_error!() discards dynamic formatting
when the capability unavailable, usually due to feature selection.
Discarding the unique portion of error strings provides the compiler the
opportunity to coalesce string constants, reducing space required for
.rodata in the spirit of AssertionNoStr.
Introducing descriptive-errors and enabling it by default gives us a
couple of things:
- Maintains the current behaviour where `--features no-assert-string`
_isn't_ specified,
- What I feel is desirable behaviour if we pass --all-features to `cargo
build`, where the no-assert-string feature didn't, and
- The ability to control the error message behaviour (though alloc is
required for descriptive messages)
Demonstrating the impact on wcampbell0x2a/backhand, with
descriptive-errors enabled[^1] we have:
$ cargo build --release --features="deku/descriptive-errors"
Finished `release` profile [optimized] target(s) in 0.06s
$ bloaty -d sections target/release/unsquashfs-backhand | grep '[.]rodata$'
8.5% 530Ki 10.7% 530Ki .rodata
$ readelf --string-dump .rodata target/release/unsquashfs-backhand | grep --color=never --only-matching -E "Field failed assertion.{5}"
Field failed assertion: Dir
Field failed assertion: Sup
Field failed assertion: Sup
Field failed assertion: Sup
Field failed assertion: Ext
Field failed assertion: Bas
Field failed assertion: Dir
$
And without:
$ cargo build --release
Finished `release` profile [optimized] target(s) in 0.05s
$ bloaty -d sections target/release/unsquashfs-backhand | grep '[.]rodata$'
8.5% 529Ki 10.7% 529Ki .rodata
$ readelf --string-dump .rodata target/release/unsquashfs-backhand | grep --color=never --only-matching -E "Field failed assertion.{5}"
Field failed assertionevent
Field failed assertionCould
$
[^1]: For the purpose of clarity in the demonstration I temporarily
changed the patch such that descriptive-errors _isn't_ in the
default features
Signed-off-by: Andrew Jeffery <[email protected]>
Signed-off-by: Andrew Jeffery <[email protected]>
|
Thanks @sharksforarms and @wcampbell0x2a ! |
|
Thank you for the contribution! |
`no-assert-string` was replaced with `descriptive-errors` back in sharksforarms#582
`no-assert-string` was replaced with `descriptive-errors` back in #582 Co-authored-by: Emmanuel Thompson <[email protected]>
Some environments prefer to avoid
allocin addition to building withno_std.