Skip to content

Conversation

@gottesmm
Copy link
Contributor

This PR is doing a few things:

  1. I added a few new tests.
  2. I disabled support in the object move checker for guaranteed arguments. We do not support this for address only types, so we should be consistent.
  3. I added support for moving out of inout params with a diagnostic to make sure before end of function one re-initializes the parameter. It works also with self in mutating methods.

… to match move checking of address only parameters.
…nts.

These are verified like a var except that the parameter will have an implicit
read use on all function exit terminators. This ensures that if a programmer
moves a value out of the inout parameter, a new value must be assigned before
function exit. This is important since otherwise the convention would be
invalidated. Example:

```
func f(_ x: inout T) {
     // Move a value out of x. x does not have a value within it anymore.
     let value = _move(x)
} // So we emit an error saying there is a use here since an inout must have
  // a valid object within it upon function exit due to convention guarantees.
```

As an added side-effect of this, one can now use move as on self in mutating
contexts. Thus one can move the self value out of the self inout binding using
_move and if one does not replace self with a new value by end of function, you
will get a compile time error, e.x.:

```
struct S {
  var buffer: Klass

  mutating func doSomething() {
    let b = move(self).buffer
    // ... do some stuff, maybe get a different buffer ...
    let maybeDifferentBuffer = maybeNewBuffer(b)

    // If we do not re-initialize S with a new value by uncommenting
    // the following line, we will get a compile time error.
    // self = S(differentBuffer)
  }
}
```
@gottesmm gottesmm force-pushed the pr-eeef8aba159ca25987b89cc791a4847eb32fc2a6 branch from 0358783 to e6faa30 Compare December 13, 2021 18:41
@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm gottesmm merged commit 186713e into swiftlang:main Dec 13, 2021
@gottesmm gottesmm deleted the pr-eeef8aba159ca25987b89cc791a4847eb32fc2a6 branch December 13, 2021 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant