Tuesday, July 26, 2022 [Tweets] [Favorites]

Swift Proposal: Move Function

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 allows for code that relies on forwarding ownership of values for performance or correctness to communicate that requirement to the compiler and to human readers.

[…]

As a function, move is rather unusual, since it only accepts certain forms of expression as its argument, and it doesn’t really have any runtime behavior of its own, acting more as a marker for the compiler to perform additional analysis. As such, many have suggested alternative spellings that make move’s special nature more syntactically distinct[…]

[…]

Another useful tool for programmers is to be able to suppress Swift’s usual implicit copying rules for a type, specific values, or a scope. The move function as proposed is not intended to be a replacement for move-only types or for “no-implicit-copy” constraints on values or scopes. The authors believe that there is room in the language for both features; move is a useful incremental annotation for code that is value type- or object-oriented which needs minor amounts of fine control for performance.

Previously:

Update (2022-07-28): See also: Hacker News.

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment