{"id":27309,"date":"2019-11-20T15:23:35","date_gmt":"2019-11-20T20:23:35","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=27309"},"modified":"2019-11-20T15:23:35","modified_gmt":"2019-11-20T20:23:35","slug":"how-swift-achieved-dynamic-linking-where-rust-couldnt","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2019\/11\/20\/how-swift-achieved-dynamic-linking-where-rust-couldnt\/","title":{"rendered":"How Swift Achieved Dynamic Linking Where Rust Couldn&rsquo;t"},"content":{"rendered":"<p><a href=\"https:\/\/gankra.github.io\/blah\/swift-abi\/\">Alexis Beingessner<\/a> (<a href=\"https:\/\/twitter.com\/Gankra_\/status\/1192946911969452032\">tweet<\/a>, <a href=\"https:\/\/news.ycombinator.com\/item?id=21488415\">Hacker News<\/a>):<\/p>\n<blockquote cite=\"https:\/\/gankra.github.io\/blah\/swift-abi\/\">\n<p>For those who don&rsquo;t follow Swift&rsquo;s development, ABI stability has been one of its most ambitious projects and possibly it&rsquo;s defining feature, <a href=\"https:\/\/swift.org\/blog\/abi-stability-and-more\/\">and it finally shipped in Swift 5<\/a>. The result is something I find endlessly fascinating, because I think Swift has pushed the notion of ABI stability farther than any language without much compromise.<\/p>\n<p>So I decided to write up a bunch of the interesting high-level details of Swift&rsquo;s ABI. This <strong>is not<\/strong> a complete reference for Swift&rsquo;s ABI, but rather an abstract look at its implementation strategy. If you really want to know exactly how it allocates registers or mangles names, look somewhere else.<\/p>\n<p>Also for context on why I&rsquo;m writing this, I&rsquo;m just naturally inclined to compare the design of Swift to Rust, because those are the two languages I have helped develop. Also some folks like to complain that Rust doesn&rsquo;t bother with ABI stability, and I think looking at how Swift <em>does<\/em> helps elucidate why that is.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/pcwalton\/status\/1192970475002970113\">Patrick Walton<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/pcwalton\/status\/1192970475002970113\">\n<p> I should mention that Rust tried in its early days to do witness tables (&ldquo;type descriptors&rdquo;\/&ldquo;tydescs&rdquo;). I wrote a lot of that code.<\/p>\n<p>Ironically, one of the big reasons we ripped it out was because of code bloat.<\/p>\n<p>IIRC switching to monomorphization actually <em>reduced<\/em> code size by quite a bit.<\/p>\n<p>Though the biggest reason was just performance: we couldn&rsquo;t get type descriptor overhead below 20% of the program runtime or so, which was unacceptable.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/dgregor79\/status\/1192983832783278081\">Doug Gregor<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/dgregor79\/status\/1192983832783278081\">\n<p>I still think that Swift&rsquo;s library evolution story (ties in with the ABI) is the only novel feature of the Swift language. Everything else is lovingly borrowed and integrated from other languages<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/jckarter\/status\/1192986746876678144\">Joe Groff<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/jckarter\/status\/1192986746876678144\">\n<p>Reabstraction might also be a novel implementation technique. Some papers on levity polymorphism in Haskell declared the problem unsolvable without a JIT<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2019\/04\/15\/library-evolution-for-stable-swift-abis\/\">Library Evolution for Stable Swift ABIs<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2019\/02\/07\/swift-abi-stability-and-more\/\">Swift ABI Stability and More<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2017\/01\/26\/swift-abi-stability-manifesto\/\">Swift ABI Stability Manifesto<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Alexis Beingessner (tweet, Hacker News): For those who don&rsquo;t follow Swift&rsquo;s development, ABI stability has been one of its most ambitious projects and possibly it&rsquo;s defining feature, and it finally shipped in Swift 5. The result is something I find endlessly fascinating, because I think Swift has pushed the notion of ABI stability farther than [&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":"2019-11-20T20:23:38Z","apple_news_api_id":"1b64a2c6-1142-46d5-bb45-41abe7ebaf53","apple_news_api_modified_at":"2019-11-20T20:23:39Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AG2SixhFCRtW7RUGr5-uvUw","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":[4],"tags":[46,71,408,901],"class_list":["post-27309","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-languagedesign","tag-programming","tag-rust-lang","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/27309","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=27309"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/27309\/revisions"}],"predecessor-version":[{"id":27310,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/27309\/revisions\/27310"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=27309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=27309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=27309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}