Error ABI
13 days ago
- #error-handling
- #Rust
- #ABI
- Using algebraic data types (ADTs) for errors can pessimize the happy path due to large error objects inflating `size_of<Result<T, E>>`.
- Mature error handling libraries (e.g., Rust's `failure` and `anyhow`) hide errors behind thin pointers to mitigate ABI issues, but this requires a global allocator.
- Three potential ABIs for returning results: default (registers/stack), optimized (reserve a register for `E`), and unwinding (jump to error recovery address).
- Unwinding may be the optimal error ABI, as suggested by benchmarks and sources like Joe Duffy's blog and a related video.
- The compiler needs to be aware of error ABIs, with surface-level semantics varying based on language abstraction capabilities.