Commit Graph

2 Commits

Author SHA1 Message Date
Doug Gregor
3fa07a0e7a Implement swift_willThrow variant for typed throws.
`swift_willThrow` is called with an error right before it is thrown.
This existing entrypoint requires an already-boxed error existential;
with typed errors, we don't have the error existential on hand, so we
would need to allocate the box to throw a typed error. That's not okay.

Introduce a new `swift_willThrowTypedImpl` entry point into the runtime
that will first check for the presence of an error handler and, if one
is present, box the error to provide to the error handler. This
maintains the no-allocations path for typed errors while still
allowing existing error handlers to work.

This new entrypoint isn't available on older Swift runtimes, so create
a back-deployable shim called by the compiler. On new-enough platforms,
this will call through to `swift_willThrowTypedImpl`. On older
platforms, we drop the error and don't call the registered will-throw
handler at all. This is a compromise that avoids boxing when throwing
typed errors, at the cost of a slightly different experience for this
new feature on older runtimes.

Fixes rdar://119828459.
2024-02-05 15:06:55 -08:00
John McCall
1c82c71486 Make an Error.h that declares the public ABI for errors.
NFC except that I added swift_errorRetain and swift_errorRelease
functions on non-ObjC targets so that we have consistent
functions to call in the runtime.  I have not changed everywhere
in the runtime to use these, nor have I changed the compiler to
call them.
2021-02-21 23:45:07 -05:00