Behind-the-Scenes Improvements in Swift 4.1
The bridging peephole recognizes such situations and cancels out the two complementary bridging operations; the cast now has the effect of eliminating the bridging performed by default, returning the underlying
NSArray
as a result. The peephole is implemented in the SILGen phase of the pipeline so you get the benefit even at -Onone, and the implementation also introduced some cleanups to how various value conversions and transformations are modeled in the AST and SILGen.[…]
Now in Swift 4.1, type metadata for nested generic types no longer points at the parent type, and instead includes all generic parameters for all outer scopes. The main user-visible benefit here is that a certain class of runtime deadlocks with circular type metadata is now fixed. A complete solution for the general runtime deadlock issue with circular type metadata is not part of Swift 4.1, but is being developed on the master branch.
[…]
This is why Swift 4.0 did not allow the default implementation of a protocol method returning
Self
to be used on a class. In Swift 4.1, this problem is solved by having protocol witness thunks for classes preserve the metadata forSelf
they received from the caller, instead of always taking it apart, and pass it on if the protocol requirement is satisfied by a default implementation.
Previously: Swift 4.1, Swift 4: Bridging Peephole for “as” Casts.