coio-rs
coio-rs copied to clipboard
Unwind error if the Coroutine::yield_with is inlined
Now we can only add #[inline(never)]
on the Coroutine::yield_with
method.
You can reproduce it anytime by replacing it with #[inline(always)]
, and then call cargo test --release
, you will see the coroutine_unwinds_on_drop
test will fail.
$ cargo test --release
...
test coroutine::test::coroutine_unwinds_on_drop ... FAILED
...
failures:
---- coroutine::test::coroutine_unwinds_on_drop stdout ----
thread 'coroutine::test::coroutine_unwinds_on_drop' panicked at 'assertion failed: `(left == right)` (left: `0`, right: `1`)', src/coroutine.rs:593
note: Run with `RUST_BACKTRACE=1` for a backtrace.
failures:
coroutine::test::coroutine_unwinds_on_drop
test result: FAILED. 26 passed; 1 failed; 0 ignored; 0 measured
error: test failed
We really should keep this issue open until we've found the reason.
It's not that bad that this method can't be inlined safely but it still annoys me to no end... The only thing that comes to my mind as a plausible reason though, is that Rust's (or LLVM's) ABI does something funky somewhere which Boost.Context does not know and thus something isn't carried over correctly. For instance some kind of stack frame pointer which isn't updated every time because LLVM viewed it as unnecessary.
coroutine_unwind
causes undefined behavior by unwinding through extern "C"
Proposed:
Check a flag after context.resume
returns and start unwinding there.
Small performance hit, need to keep the flag in the Coroutine
and check it on every switch, but it should allow inlining.
I'll try to get it working and PR later today.
Hmm, I think it doesn't require a flag in Coroutine
. You can make use of the data
field in the Transport
.
Hey @glasswings! If you intend to stick with this project for a while I can offer you to give you a quick introduction into how coio works and answer all your questions. You can ping me at my mail address if you want to and if you're comfortable with voice chat, because typing everything down would take ages. :smile: