Skip to content

[move-only] Ban partial reinitialization after consuming a value. #67145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

gottesmm
Copy link
Contributor

@gottesmm gottesmm commented Jul 6, 2023

This is similar to our ban on partial consuming a value for this release. The
reason for this is that, one can achieve a similar affect as partial consumption
via a consumption of the entire value and then a partial reinitialization. Example:

struct X : ~Copyable { var i = 5, var i2 = Klass() }
var x = X()
_ = consume x
x.i = 5

in the case above, we now have a value that is in a partially initialized state.

We still allow for move only types to have their fields initialized as long as
there is an intervening init.

rdar://111498740

@gottesmm
Copy link
Contributor Author

gottesmm commented Jul 6, 2023

@swift-ci test

Copy link
Contributor

@jckarter jckarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. There's a decent amount of new code, but it's in service to the new diagnostic, so it should be self-contained. We do want this diagnostic so we don't end up having to support code that does partial initializations before we hammer the semantics out.

@gottesmm gottesmm requested a review from jckarter July 6, 2023 02:53
This is similar to our ban on partial consuming a value for this release. The
reason for this is that, one can achieve a similar affect as partial consumption
via a consumption of the entire value and then a partial reinitialization. Example:

```swift
struct X : ~Copyable { var i = 5, var i2 = Klass() }
var x = X()
_ = consume x
x.i = 5
```

in the case above, we now have a value that is in a partially initialized state.

We still allow for move only types to have their fields initialized as long as
there is an intervening init.

rdar://111498740
@gottesmm gottesmm force-pushed the pr-694caf05ac09f8c08fb766c7589fe060c927f528 branch from 6ff00e5 to 69a03c9 Compare July 6, 2023 03:27
@gottesmm
Copy link
Contributor Author

gottesmm commented Jul 6, 2023

@swift-ci test

@gottesmm gottesmm merged commit 823f008 into swiftlang:main Jul 6, 2023
@gottesmm gottesmm deleted the pr-694caf05ac09f8c08fb766c7589fe060c927f528 branch July 6, 2023 12:24
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.

2 participants