Skip to content

Fix MoveOnlyAddressChecker to handle value deinits. #66691

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
merged 1 commit into from
Jun 20, 2023

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Jun 16, 2023

Track liveness of self so we don't accidentally think that such types can be memberwise reinitialized.

Fixes rdar://110232973 ([move-only] Checker should distinguish in between field of single field struct vs parent field itself (was: mutation of field in noncopyable struct should not trigger deinit))

struct HighScore: ~Copyable {
    var value = 0

    consuming func finalize() {
        print("Saving score to disk…")
        discard self
    }

    deinit {
        print("Deinit is saving score to disk…")
    }
}

func createHighScore() {
    var highScore = HighScore()
    highScore.value = 20 // should not trigger deinit, but does.
    highScore.finalize()
}

createHighScore()

@atrick atrick requested review from jckarter and kavon June 16, 2023 00:48
@atrick atrick force-pushed the fix-field-liveness branch 3 times, most recently from 91c7228 to c82ce37 Compare June 19, 2023 06:50
@atrick atrick requested a review from gottesmm June 19, 2023 06:53
@atrick
Copy link
Contributor Author

atrick commented Jun 19, 2023

@swift-ci test

@atrick atrick marked this pull request as ready for review June 19, 2023 06:53
Track liveness of self so we don't accidentally think that such types
can be memberwise reinitialized.

Fixes rdar://110232973 ([move-only] Checker should distinguish in
between field of single field struct vs parent field itself (was:
mutation of field in noncopyable struct should not trigger deinit))
@atrick atrick force-pushed the fix-field-liveness branch from c82ce37 to a8c45c5 Compare June 20, 2023 01:38
@atrick
Copy link
Contributor Author

atrick commented Jun 20, 2023

This passed full testing.

@atrick
Copy link
Contributor Author

atrick commented Jun 20, 2023

@swift-ci test source compatibility

@atrick
Copy link
Contributor Author

atrick commented Jun 20, 2023

@swift-ci smoke test

@atrick
Copy link
Contributor Author

atrick commented Jun 20, 2023

The SCK failure is the same on main

@@ -350,6 +355,10 @@ void TypeTreeLeafTypeRange::constructFilteredProjections(
callback(newValue, TypeTreeLeafTypeRange(start, next));
start = next;
}
if (type.isValueTypeWithDeinit()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am fine with this as is... but I would like a larger comment here that doesn't just say 'self' has its own liveness. I wish it had the larger explanation or a reference back to the earlier explanation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. although I need to merge this now to put up a 5.9 PR

@atrick atrick merged commit 1790ca2 into swiftlang:main Jun 20, 2023
@atrick atrick deleted the fix-field-liveness branch June 20, 2023 19:04
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