Swift Proposal: Move Function
In this document, we propose adding a new function called
move
to the swift standard library, which ends the lifetime of a specific locallet
, localvar
, orconsuming
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 makemove
’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:
- Porting Graphing Calculator From C++ to Swift
- Roadmap for Improving Swift Performance Predictability
- Swift Ownership Manifesto
Update (2022-07-28): See also: Hacker News.