-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] Unexport shadow protocols #20509
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
[stdlib] Unexport shadow protocols #20509
Conversation
@swift-ci please test |
@swift-ci benchmark |
This comment has been minimized.
This comment has been minimized.
@@ -392,7 +342,7 @@ extension _ArrayBuffer { | |||
) | |||
} else { | |||
// ObjC arrays do their own subscript checking. | |||
element = _nonNative.objectAt(i) | |||
element = _nonNative[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: This was probably written this way because -objectAtIndexedSubscript:
is just going to call -objectAtIndex:
, and you might as well save that one objc_msgSend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not call -objectAtIndexedSubscript:
: _nonNative
now returns a _CocoaArrayWrapper
, which is a Swift struct. Its opaque subscript calls objectAt(_:)
, which is the shadow protocol's pet name for -objectAtIndex:
a.k.a. object(at:)
This does add an extra static function call compared to the original, but those are pretty cheap, and this is on a slow path anyway, so it shouldn't matter much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, my bad for not taking the whole patch at once. Thanks for the explanation.
Build comment file:Performance: -O
Code size: -O
Performance: -Osize
Code size: -Osize
Performance: -Onone
Code size: -swiftlibs
How to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
Interesting benchmark results. If anything, I'd have expected performance regressions and code size improvements, not the other way round. My guess is that moving some of the Array slow paths to opaque members encouraged inlining where it didn't happen before. |
Build failed |
@swift-ci please test |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@swift-ci test macOS platform |
This comment has been minimized.
This comment has been minimized.
@swift-ci please test |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test |
Build failed |
@swift-ci test |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@swift-ci Please test macOS |
Ping? Still have my own PR to go in after this one. :-) |
These shadow protocols don’t add any real type safety, and exposing them in the ABI seems unnecessary.
These shadow protocols don’t add any real type safety, and exposing them in the ABI seems unnecessary.
These shadow protocols don’t add any real type safety, and exposing them in the ABI seems unnecessary.
Also, move field declarations to the top of the struct.
It used to be a shadow protocol existential, but now it’s invariably AnyObject. I see no reason to keep supporting this unused abstraction.
These shadow protocols don’t add any real type safety, and exposing them in the ABI seems unnecessary.
… non-ObjC platforms
4c08094
to
774ff61
Compare
I rebased to resolve the ABI diff conflicts; this is now ready to merge. @swift-ci test and merge |
That's weird; I don't think I touched that. |
FYI @nkcsgexi I had to remove a type witness change that (at first glance) seems unrelated to my changes. |
@swift-ci please smoke test |
Thanks for letting me know. AFAIK, type witness can be inferred from the type. Is there any chance your other changes triggered the inferred witness change? |
On second look, it does seem very much related — and the need to remove it is explained nicely by the recent removal of Sequence.SubSequence. Everything checks out; sorry for the false alarm! 😊 |
We redefine some Cocoa interfaces in a set of shadow protocols to make select Cocoa APIs available to the stdlib. These protocols don't meaningfully increase type safety, but having them part of the ABI forces collection storage classes to expose their implementations as Swift entry points. This is unfortunate; these are internal implementation details that we may want to tweak later. (Also, the Swift names / argument types don't always match how ClangImporter imports these APIs to Swift.)
This was uncovered by @jrose-apple's improved diagnostics in #20485.