Hi,
I've been away from embedded rust a while, and suddenly someone wrote the Embassy async runtime for embedded targets! Wow ... I mean WOW!
For fun and glory I want to understand this better, and make a minimal build, removing debug and trace-lines to see how compact a build I can produce.
I now have a build that can toggle a pin based on a timer, that take 4016 bytes, - quite pretty, but now I notice 'something' is leaking these text strings into the binary:
async fn` resumed after completion
assertion failed: n < 4
assertion failed: n < 32
It's not much ... but is there any way to avoid that?
I can read, that (real) assertions is always enabled in rust, regardless of debug/release build.
I accept that, but the message could ideally be empty, and the code would just panic.
What is leaking the string e.g. "resumed after completion" into the build?
It's apparently not the embassy source code itself.
This sounds like something that would come from the Future implementation that the compiler automatically generates for an async function. Those sorts of futures aren't designed to be polled again after they run to completion, so it triggers a panic.
I'm not sure how you would get rid of those strings, though.
Note that according to the documentation of Future, a different behavior would be conforming (and thus could be implemented by the compiler):
Once a future has completed (returned Ready from poll), calling its poll method again may panic, block forever, or cause other kinds of problems; the Future trait places no requirements on the effects of such a call. However, as the poll method is not marked unsafe, Rust’s usual rules apply: calls must never cause undefined behavior (memory corruption, incorrect use of unsafe functions, or the like), regardless of the future’s state.
I could imagine a (future) compiler option which (for example) just causes the program to halt (or panic without a message, which might be nicer) if such a completed async fn future is polled again.
As others have pointed out, the compiler adds this panic message.
AFAIK, the simplest way to get rid of the message is to rebuild the standard library with a nightly build of rustc using the panic_immediate_abort flag.
(I've only tested this on my 64-bit Linux machine)
Install nightly if needed: rustup default nightly
Add panic = "abort" to [profile.release]
Rebuild with the following Cargo command: cargo +nightly build --release -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-unknown-linux-gnu
You can also add this optimization to your Cargo configuration. See:
As written earlier, your suggestion solved my problem, thanks!
Out of curiosity:
The rust LTO optimizer is so effective, that I now wonder why the strings are not eliminated just by inserting an empty panic_handler():