{"id":40684,"date":"2023-09-19T15:50:35","date_gmt":"2023-09-19T19:50:35","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=40684"},"modified":"2023-10-11T16:44:05","modified_gmt":"2023-10-11T20:44:05","slug":"swift-5-9","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2023\/09\/19\/swift-5-9\/","title":{"rendered":"Swift 5.9"},"content":{"rendered":"<p><a href=\"https:\/\/www.swift.org\/blog\/swift-5.9-released\/\">Alexander Sandberg and Holly Borla<\/a> (<a href=\"https:\/\/twitter.com\/SwiftLang\/status\/1703836136148463942\">tweet<\/a>, <a href=\"https:\/\/news.ycombinator.com\/item?id=36216550\">Hacker<\/a> <a href=\"https:\/\/news.ycombinator.com\/item?id=37570840\">News<\/a>):<\/p>\n<blockquote cite=\"https:\/\/www.swift.org\/blog\/swift-5.9-released\/\"><p>This is a major new release that adds an expressive macro system to the language and introduces support for integrating Swift into C++ codebases through bidirectional interoperability.<\/p><p>It also introduces parameter packs, an improved expression evaluator while debugging, enhanced crash handling, Windows platform improvements, and more.<\/p><p>[&#8230;]<\/p><p>The new <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0366-move-function.md\"><code>consume<\/code> operator<\/a> tells Swift to deinitialize a variable and transfer its contents without copying it. The <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0377-parameter-ownership-modifiers.md\"><code>consuming<\/code> and <code>borrowing<\/code> parameter modifiers<\/a> provide hints that Swift can use to eliminate unnecessary copying and reference-counting operations when passing a parameter.<\/p><\/blockquote>\n<p>I have not been following this closely, but as far as I can tell this is for optimizations in code that you write. It doesn&rsquo;t help when your code is being called by the standard library. If you try to iterate a <code>Sequence<\/code> or sort an <code>Array<\/code> of custom objects, I think it&rsquo;s still going to do lots of unnecessary reference-counting.<\/p>\n<blockquote cite=\"https:\/\/www.swift.org\/blog\/swift-5.9-released\/\"><p>Finally, <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0390-noncopyable-structs-and-enums.md\">noncopyable structs and enums<\/a> allow you to create types which, like a class, can&rsquo;t be meaningfully copied when assigned, but like a struct or enum, do not need to be reference-counted because only one storage location can own the instance at a time.<\/p><p>[&#8230;]<\/p><ul><li>SE-0366: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0366-move-function.md\"><code>consume<\/code> operator to end the lifetime of a variable binding<\/a><\/li><li>SE-0374: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0374-clock-sleep-for.md\">Add sleep(for:) to Clock<\/a><\/li><li>SE-0377: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0377-parameter-ownership-modifiers.md\"><code>borrowing<\/code> and <code>consuming<\/code> parameter ownership modifiers<\/a><\/li><li>SE-0380: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0380-if-switch-expressions.md\"><code>if<\/code> and <code>switch<\/code> expressions<\/a><\/li><li>SE-0381: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0381-task-group-discard-results.md\">DiscardingTaskGroups<\/a><\/li><li>SE-0382: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0382-expression-macros.md\">Expression Macros<\/a><\/li><li>SE-0384: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0384-importing-forward-declared-objc-interfaces-and-protocols.md\">Importing Forward Declared Objective-C Interfaces and Protocols<\/a><\/li><li>SE-0386: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0386-package-access-modifier.md\">New access modifier: <code>package<\/code><\/a><\/li><li>SE-0388: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0388-async-stream-factory.md\">Convenience Async[Throwing]Stream.makeStream methods<\/a><\/li><li>SE-0389: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0389-attached-macros.md\">Attached Macros<\/a><\/li><li>SE-0390: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0390-noncopyable-structs-and-enums.md\">Noncopyable structs and enums<\/a><\/li><li>SE-0392: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0392-custom-actor-executors.md\">Custom Actor Executors<\/a><\/li><li>SE-0393: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0393-parameter-packs.md\">Value and Type Parameter Packs<\/a><\/li><li>SE-0394: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0394-swiftpm-expression-macros.md\">Package Manager Support for Custom Macros<\/a><\/li><li>SE-0395: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0395-observability.md\">Observation<\/a><\/li><li>SE-0396: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0396-never-codable.md\">Conform <code>Never<\/code> to <code>Codable<\/code><\/a><\/li><li>SE-0397: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0397-freestanding-declaration-macros.md\">Freestanding Declaration Macros<\/a><\/li><li>SE-0398: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0398-variadic-types.md\">Allow Generic Types to Abstract Over Packs<\/a><\/li><li>SE-0399: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0399-tuple-of-value-pack-expansion.md\">Tuple of value pack expansion<\/a><\/li><li>SE-0400: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0400-init-accessors.md\">Init Accessors<\/a><\/li><li>SE-0401: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0401-remove-property-wrapper-isolation.md\">Remove Actor Isolation Inference caused by Property Wrappers<\/a><\/li><li>SE-0402: <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0402-extension-macros.md\">Generalize <code>conformance<\/code> macros as <code>extension<\/code> macros<\/a><\/li><\/ul><\/blockquote>\n<p>Lots of good stuff here. I&rsquo;m still using Xcode 14, and the Swift compiler frequently crashes or produces incorrect results. I hope this version is better.<\/p>\n\n<p>See also: <a href=\"https:\/\/www.hackingwithswift.com\/articles\/258\/whats-new-in-swift-5-9\">Paul Hudson<\/a>.<\/p>\n\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/07\/17\/macros-in-swift-5-9\/\">Macros in Swift 5.9<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/07\/06\/swiftui-data-flow-2023\/\">SwiftUI Data Flow 2023<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/06\/16\/swift-proposal-init-accessors\/\">Swift Proposal: Init Accessors<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/06\/12\/swiftdata\/\">SwiftData<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/06\/06\/wwdc-2023-links\/\">WWDC 2023 Links<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/06\/02\/a-vision-for-using-c-from-swift\/\">A Vision for Using C++ From Swift<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/04\/03\/xcode-14-3\/\">Xcode 14.3<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/04\/03\/swift-5-8\/\">Swift 5.8<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/03\/24\/swift-proposal-value-and-type-parameter-packs\/\">Swift Proposal: Value and Type Parameter Packs<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/03\/22\/swift-proposal-noncopyable-structs-and-enums\/\">Swift Proposal: Noncopyable Structs and Enums<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/11\/17\/a-vision-for-variadic-generics-in-swift\/\">A Vision for Variadic Generics in Swift<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/08\/12\/swift-pitch-borrow-and-take-parameter-ownership-modifiers\/\">Swift Pitch: &ldquo;borrow&rdquo; and &ldquo;take&rdquo; Parameter Ownership Modifiers<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/07\/01\/porting-graphing-calculator-from-c-to-swift\/\">Porting Graphing Calculator From C++ to Swift<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2021\/12\/23\/roadmap-for-improving-swift-performance-predictability\/\">Roadmap for Improving Swift Performance Predictability<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Alexander Sandberg and Holly Borla (tweet, Hacker News): This is a major new release that adds an expressive macro system to the language and introduces support for integrating Swift into C++ codebases through bidirectional interoperability.It also introduces parameter packs, an improved expression evaluator while debugging, enhanced crash handling, Windows platform improvements, and more.[&#8230;]The new consume [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2023-09-19T19:50:38Z","apple_news_api_id":"1dcbfbbe-420a-488d-9364-58d70913249b","apple_news_api_modified_at":"2023-09-19T19:56:15Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/AHcv7vkIKSI2TZFjXCRMkmw","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":[55,46,571,138,71,901],"class_list":["post-40684","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-arc","tag-languagedesign","tag-memory-management","tag-optimization","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/40684","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=40684"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/40684\/revisions"}],"predecessor-version":[{"id":40690,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/40684\/revisions\/40690"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=40684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=40684"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=40684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}