{"id":36596,"date":"2022-07-26T15:18:21","date_gmt":"2022-07-26T19:18:21","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=36596"},"modified":"2022-07-28T16:12:39","modified_gmt":"2022-07-28T20:12:39","slug":"swift-proposal-move-function","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2022\/07\/26\/swift-proposal-move-function\/","title":{"rendered":"Swift Proposal: Move Function"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0366-move-function.md\">SE-0366<\/a> (<a href=\"https:\/\/forums.swift.org\/t\/se-0366-move-function-use-after-move-diagnostic\/59202\">forum<\/a>):<\/p>\n<blockquote cite=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0366-move-function.md\"><p>In this document, we propose adding a new function called <code>move<\/code> to the swift\nstandard library, which ends the lifetime of a specific local <code>let<\/code>,\nlocal <code>var<\/code>, or <code>consuming<\/code> function parameter, and which enforces this\nby causing the compiler to emit a diagnostic upon any uses that are after the\nmove function. This allows for code that relies on <strong>forwarding ownership<\/strong>\nof values for performance or correctness to communicate that requirement to\nthe compiler and to human readers.<\/p>\n<p>[&#8230;]<\/p>\n<p>As a function, <code>move<\/code> is rather unusual, since it only accepts certain forms of\nexpression as its argument, and it doesn&rsquo;t really have any runtime behavior\nof its own, acting more as a marker for the compiler to perform additional\nanalysis. As such, many have suggested alternative spellings that make <code>move<\/code>&rsquo;s\nspecial nature more syntactically distinct[&#8230;]<\/p>\n<p>[&#8230;]<\/p>\n<p>Another useful tool for programmers is to be able to suppress Swift&rsquo;s usual\nimplicit copying rules for a type, specific values, or a scope. The <code>move<\/code> function\nas proposed is not intended to be a replacement for move-only types or for\n&ldquo;no-implicit-copy&rdquo; constraints on values or scopes. The authors believe that\nthere is room in the language for both features; <code>move<\/code> is a useful incremental\nannotation for code that is value type- or object-oriented which needs\nminor amounts of fine control for performance.<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\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<li><a href=\"https:\/\/mjtsai.com\/blog\/2017\/02\/18\/swift-ownership-manifesto\/\">Swift Ownership Manifesto<\/a><\/li>\n<\/ul>\n\n<p id=\"swift-proposal-move-function-update-2022-07-28\">Update (2022-07-28): See also: <a href=\"https:\/\/news.ycombinator.com\/item?id=32263630\">Hacker News<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>SE-0366 (forum): In this document, we propose adding a new function called move to the swift standard library, which ends the lifetime of a specific local let, local var, or consuming function parameter, and which enforces this by causing the compiler to emit a diagnostic upon any uses that are after the move function. This [&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":"2022-07-26T19:18:23Z","apple_news_api_id":"20ead14f-5e11-4fc6-839d-b68671efcdd9","apple_news_api_modified_at":"2022-07-28T20:12:42Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAQ==","apple_news_api_share_url":"https:\/\/apple.news\/AIOrRT14RT8aDnbaGce_N2Q","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-36596","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\/36596","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=36596"}],"version-history":[{"count":3,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/36596\/revisions"}],"predecessor-version":[{"id":36616,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/36596\/revisions\/36616"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=36596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=36596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=36596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}