You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This attribute forces programmers to acknowledge every
copy that is required to happen in the body of the
function. only those copies that make sense according
to Swift's ownership rules are "required".
The way this is implemented is to flag every non-explicit
copy in a function as an error. This keeps SILGen and the
Swift language in sync about what copies are actually
happening, which motivates fixes for cases where SILGen
can be more clever.
This also means that there is _no_ hand-holding to avoid
exclusivity violations. Static checking will continue to
catch some cases, but for other cases, like class objects,
it is up to the programmer to understand where they may
need to rewrite code with mutable references. This is
where the "manual" comes from. For example,
```swift
// unsafe if x === y
swap(&x.a, &y.a)
// a safe rewrite
let t = copy x.a
x.a = copy y.a
y.a = consume t
```
0 commit comments