[NSError bridging] Use embedded NSError when erasing types to Error e… #3953
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's in this pull request?
Imported Cocoa error types are represented by structs wrapping an NSError. The conversion from these structs to Error would end up boxing the structs in _SwiftNativeNSError, losing identity and leading to a wrapping loop.
Instead, extract the embedded NSError if there is one. In the Swift runtime, do this as part of the dynamic cast to NSError, using a (new, defaulted) requirement in the Error type so we can avoid an extra runtime lookup of the protocol. In SILGEn, do this by looking for the _BridgedStoredNSError protocol conformance when erasing to an Error type.
Resolved bug number: (SR-1562)
AKA: rdar://problem/26370984
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
A smoke test on macOS does the following:
device standard libraries are not built.
version of these tests are not run.
A smoke test on Linux does the following:
tests are not run.
Validation Testing
Lint Testing
Note: Only members of the Apple organization can trigger swift-ci.
…xistentials.
Imported Cocoa error types are represented by structs wrapping an
NSError. The conversion from these structs to Error would end up
boxing the structs in _SwiftNativeNSError, losing identity and leading
to a wrapping loop.
Instead, extract the embedded NSError if there is one. In the Swift
runtime, do this as part of the dynamic cast to NSError, using a (new,
defaulted) requirement in the Error type so we can avoid an extra
runtime lookup of the protocol. In SILGEn, do this by looking for the
_BridgedStoredNSError protocol conformance when erasing to an Error
type. Fixes SR-1562 / rdar://problem/26370984.