{"id":21224,"date":"2018-04-12T13:59:33","date_gmt":"2018-04-12T17:59:33","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=21224"},"modified":"2018-04-12T13:59:33","modified_gmt":"2018-04-12T17:59:33","slug":"behind-the-scenes-improvements-in-swift-4-1","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2018\/04\/12\/behind-the-scenes-improvements-in-swift-4-1\/","title":{"rendered":"Behind-the-Scenes Improvements in Swift 4.1"},"content":{"rendered":"<p><a href=\"https:\/\/medium.com\/@slavapestov\/behind-the-scenes-improvements-in-swift-4-1-269dd56e30c2\">Slava Pestov<\/a>:<\/p>\n<blockquote cite=\"https:\/\/medium.com\/@slavapestov\/behind-the-scenes-improvements-in-swift-4-1-269dd56e30c2\"><p>The <em>bridging peephole<\/em> 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 <code>NSArray<\/code> 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.<\/p><p>[&#8230;]<\/p><p>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 <a href=\"https:\/\/github.com\/apple\/swift\/pull\/15671\">being developed on the master branch<\/a>.<\/p><p>[&#8230;]<\/p><p>This is why Swift 4.0 did not allow the default implementation of a protocol method returning <code>Self<\/code> to be used on a class. In Swift 4.1, this problem is solved by having protocol witness thunks for classes preserve the metadata for <code>Self<\/code> 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.<\/p><\/blockquote>\n\n<p>Previously: <a href=\"https:\/\/mjtsai.com\/blog\/2018\/04\/01\/swift-4-1\/\">Swift 4.1<\/a>, <a href=\"https:\/\/mjtsai.com\/blog\/2017\/08\/29\/swift-4-bridging-peephole-for-as-casts\/\">Swift 4: Bridging Peephole for &ldquo;as&rdquo; Casts<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Slava Pestov: 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, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2018-04-12T17:59:34Z","apple_news_api_id":"da5438a5-ec33-4889-a36e-a3e6c91069f8","apple_news_api_modified_at":"2018-04-12T17:59:37Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/A2lQ4pewzSImjbqPmyRBp-A","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[],"tags":[255,46,138,71,901,943],"class_list":["post-21224","post","type-post","status-publish","format-standard","hentry","tag-compiler","tag-languagedesign","tag-optimization","tag-programming","tag-swift-programming-language","tag-swift-runtime"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/21224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=21224"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/21224\/revisions"}],"predecessor-version":[{"id":21225,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/21224\/revisions\/21225"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=21224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=21224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=21224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}