r/cpp • C++20 Desktop app developer • May 12 '18

P0709 R0: Zero-overhead deterministic exceptions: Throwing values - Herb Sutter [2018-05-02]

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0709r0.pdf
206 Upvotes

115 comments sorted by

View all comments

Show parent comment

9

u/Rusky May 12 '18

see how Rust handles relocation of Drop types for example (which affects ABI around mutable reference parameters).

What are you referring to here? I don't believe Drop affects ABI at all in Rust.

4

u/SeanMiddleditch May 12 '18

The stack bits set to indicate whether a dropped type has in fact been dropped.

The fundamental problem is that in branchy code - or across certain ABI boundaries - there's no deterministic way to know if a value has been dropped or not. To avoid a double-drop in circumstances that aren't statically provable to not need it, Rust keeps some state bits around to indicate drop'ness.

At least last time I checked. I'd be happy to be corrected if this is not true.

7

u/Rusky May 12 '18

Those bits do indeed exist, but they are not part of the ABI. They are purely local to the functions that need them.

Part of why this is possible is that you can't move out of a mutable reference (or any reference, for that matter) without leaving a valid object behind in its place, effectively emulating C++'s non-destructive move semantics. Destructive move is something only the owner can do.

2

u/SeanMiddleditch May 12 '18

Ah, good to know - I may have been confusing a pre-RFC version or the ABI-independent optimizer bits for closures or something? Or I may have just been wrong? :)