Repository navigation
docs: panic-never (+ question about panic detection in async code) - #7
peter-lyons-kehl wants to merge 1 commit into
Conversation
|
Looks good to me! With regards to point 2: as alluded to in the blog, it is in fact LLVM that optimizes that async block away. (all code is optimized away for that matter) In the MIR and in the non-optimized LLVM-IR passed to LLVM this panic is there. To verify this, run rustc with For example: define internal noundef zeroext i1 @_RNCNvCs8v9h2daBvVj_11panic_never5inner0B3_(ptr noundef nonnull align 1 %_1, ptr noalias noundef align 8 dereferenceable(32) %_task_context) unnamed_addr #1 {
start:
[..]
br i1 %4, label %bb5, label %bb1
bb5: ; preds = %bb5, %start
br i1 false, label %bb5, label %panicThe only reason LLVM is capable of optimizing this panic out is because your executor implementation in the example is not complete: instead of continuously polling a future, it is only polled once. For real-world executors this panic is not eliminated. (that would look like collection of futures, and a loop which iterates on all of them and switches based on the async block state machine) CGA is only capable of reasoning about the application within the confines of rustc & the generated MIR. |
|
Wow. More to learn and investigate (for me). What exact [target.'cfg(target_os="linux")']
rustflags = ["-C", "link-arg=-nostartfiles"]I've tried [target.'cfg(target_os="linux")']
rustflags = ["-C", "link-arg=-nostartfiles", "--emit=mir", "-C", "no-prepopulate-passes"]Then Google suggested |
|
With a recent nightly, you should be able to run the following on your project: cargo +nightly rustc --example async_panic_none --release -- --emit=mir,llvm-ir -C no-prepopulate-passesYou will find the LLVM-IR at |
80d8cfd to
7ceac7e
Compare
|
Thank you Wouter @Wassasin. I've removed the mention of |
|
Here's how to re-use same code for non- |
hi Wouter @Wassasin,
I did create a PR: japaric/panic-never#3 from https://github.com/peter-lyons-kehl/panic-never-rs to upstream https://github.com/japaric/panic-never (https://crates.io/crates/panic-never). However, its author has been overloaded, so it may take long. Hence I've mentioned my repo, too.
In addition to this PR, https://tweedegolf.nl/en/blog/242/finding-panics-with-call-graph-analyzer reads "each async block has a panic path, implicitly". That is incorrect. See https://github.com/peter-lyons-kehl/panic-never-rs/tree/master/examples/async_panic_none.