Skip to content

[Runtime] Handle Error-conforming-to-NSObject casting fully. #28700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 15, 2019

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Dec 11, 2019

Rather than attempting Error bridging early when trying to dynamically
cast to NSError or NSObject, treat it as the last thing we do when
all else fails. Push most of this code over into Objective-C-specific
handling rather than #ifdef'd into the main casting logic to make that
slightly more clear.

One oddity of Error/NSError bridging is that a class that conforms to
Error can be dynamically cast to NSObject via Error bridging. This has
always been known to the static compiler, but the runtime itself was
not always handling such a cast uniformly. Do so now,
uniformly. However, this forced us to weaken an assertion, because
casting a class type to NSError or NSObject can produce an object with
a different identity.

Fixes rdar://problem/57393991.

@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 8767ec3

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 8767ec3

@mikeash mikeash requested a review from tbkka December 11, 2019 16:31
@mikeash
Copy link
Contributor

mikeash commented Dec 11, 2019

Looks OK to me! I also added @tbkka as a reviewer. At this point he probably knows this code better than I do.

You should also revert the disabled test from #28406.

@DougGregor
Copy link
Member Author

Yikes, I thought #28406 had already been reverted with the rest. And it's still unfixed, thank you.

@mikeash
Copy link
Contributor

mikeash commented Dec 11, 2019

D'oh. :(

I missed a case where an Error-conforming class is dynamically casted
to NSObject (via NSError). Fix it.
This prevents runtime differences on as? from affecting this test.
…SObject.

Rather than attempting Error bridging early when trying to dynamically
cast to NSError or NSObject, treat it as the *last* thing we do when
all else fails. Push most of this code over into Objective-C-specific
handling rather than #ifdef'd into the main casting logic to make that
slightly more clear.

One oddity of Error/NSError bridging is that a class that conforms to
Error can be dynamically cast to NSObject via Error bridging. This has
always been known to the static compiler, but the runtime itself was
not always handling such a cast uniformly. Do so now,
uniformly. However, this forced us to weaken an assertion, because
casting a class type to NSError or NSObject can produce an object with
a different identity.

Fixes rdar://problem/57393991.
@DougGregor DougGregor force-pushed the bridge-all-the-errors branch from 8767ec3 to 169dbcd Compare December 14, 2019 07:55
@DougGregor
Copy link
Member Author

@swift-ci please test

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test macOS

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please test macOS

@DougGregor
Copy link
Member Author

@swift-ci please test platform macOS

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 8767ec3

@DougGregor
Copy link
Member Author

@swift-ci please test platform macOS

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 169dbcd

@DougGregor
Copy link
Member Author

@swift-ci please test Linux

@DougGregor
Copy link
Member Author

I'm going to merge because other PRs will be built on top of this, but we'll back it out of there are any concerns.

@DougGregor DougGregor merged commit 6cc1337 into swiftlang:master Dec 15, 2019
@DougGregor DougGregor deleted the bridge-all-the-errors branch December 15, 2019 01:06
@mikeash
Copy link
Contributor

mikeash commented Dec 16, 2019

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants