Skip to content

[5.9][move-only] When adding implicit liveness uses for class field/global accesses, do not use the terminator, use the end access. #67089

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 4 commits into from
Jul 4, 2023

Conversation

gottesmm
Copy link
Contributor

@gottesmm gottesmm commented Jul 3, 2023

This PR contains two different, but related changes. I am going to CCC them together since the changes were both found while fixing the same test that I am uploading here.


• Description: [5.9][move-only] When adding implicit liveness uses for class field/global accesses, do not use the terminator, use the end access. The language impact is that we miscompile this type of code:

func assignableButNotConsumableEndAccessImplicitLifetimeTest(_ x: CopyableKlassWithMoveOnlyField) {
     if boolValue {
         x.moveOnlyVarStruct.nonTrivialStruct2 = NonTrivialStruct2()
     }
 }

In words, we miscompile a place where we conditionally apply an assign. The result is that we insert a destroy_addr on the value before we do the assign, causing us to destroy the original value before we do the actual assign.
• Risk: This is low risk since it only affects a corner case in a specific part of the noncopyable checker. So it cannot affect anything but noncopyable code.
• Original PR: #67088
• Reviewed By: @jckarter
• Testing: Added SIL/Swift/Interpreter tests to validate the behavior. (The interpreter test is moveonly_linkedlist.swift which I included in the last cherry-picked commit since the next commit is also needed for it).
• Resolves: rdar://111659649


• Description: [move-only] Fix a place in DI where we were not converting an assignable_but_not_consumable -> initable_but_not_consumable. I fixed this for assign but missed a place where we needed to do the same thing for copy_addr. The language impact of this change is that we miscompile initializations of generic types in certain specific cases like in moveonly_linkedlist.swift:12.
• Risk: This is low risk since it only affects a corner case in DefiniteInitialization that only applies to noncopyable code. So it cannot affect anything but noncopyable code.
• Original PR: #67088
• Reviewed By: @jckarter
• Testing: Added a SIL/Swift/Interpreter tests to validate the behavior. (The interpreter test is moveonly_linkedlist.swift)
• Resolves: rdar://111709236

@gottesmm gottesmm requested a review from a team as a code owner July 3, 2023 00:56
@gottesmm
Copy link
Contributor Author

gottesmm commented Jul 3, 2023

@swift-ci test

@nate-chandler
Copy link
Contributor

but after some recent changes to field sensitive pruned liveness, this seems to no longer work.

I tried the new @assignableButNotConsumableEndAccessImplicitLifetimeTest test case with the compiler before my recent changes to FieldSensitivePrunedLiveness (git checkout 606eef619f2d2bc6b22e1f625461cbfe779617ca + ./utils/update-checkout --scheme=main --match-timestamp) and see this verification failure

SIL verification failed: instruction isn't dominated by its operand: properlyDominates(valueI, I)
Verifying instruction:
     %7 = begin_access [modify] [dynamic] %6 : $*NonTrivialStruct // users: %10, %5, %8, %12
->   destroy_addr %7 : $*NonTrivialStruct         // id: %5
In function:
// assignableButNotConsumableEndAccessImplicitLifetimeTest

gottesmm added 4 commits July 3, 2023 15:56
…r to bisect on variables that we are checking.

These are only on in NDEBUG mode. It just makes it easier to quickly triage
which variable is causing a checking problem.

(cherry picked from commit fb487bf)
… accesses, do not use the terminator, use the end access.

Previously, when doing this I could just use the terminator both in cases of
inout and for class field/global accesses... but after some recent changes to
field sensitive pruned liveness, this seems to no longer work. So just do the
right thing and use the field access.

The specific bug was that we would introduce a destroy_addr along one of the
paths where the value wasn't defined resulting in a dominance error.

I added a SIL test that shows this fixes the issue, a swift test, and also an
Interpreter test that validates the correctness.

rdar://111659649
(cherry picked from commit 7028381)
…ble_but_not_consumable -> initable_but_not_consumable.

I fixed this for assign but missed a place where we needed to do the same thing for copy_addr.

rdar://111709236
(cherry picked from commit 0e383cd)
Both of the previous fixes in this PR were found via this test.

(cherry picked from commit 268cd76)
@gottesmm gottesmm changed the title [move-only] When adding implicit liveness uses for class field/global accesses, do not use the terminator, use the end access. [5.9][move-only] When adding implicit liveness uses for class field/global accesses, do not use the terminator, use the end access. Jul 3, 2023
@gottesmm
Copy link
Contributor Author

gottesmm commented Jul 3, 2023

@nate-chandler Ok, I could be wrong. My assumption was that it was something related to maximizing lifetime or field sensitive pruned liveness. Regardless, this needs to be fixed.

@gottesmm gottesmm force-pushed the release-5.9-111659649 branch from 0ca0cae to a53cdb0 Compare July 3, 2023 22:59
@gottesmm
Copy link
Contributor Author

gottesmm commented Jul 3, 2023

@swift-ci test

@gottesmm
Copy link
Contributor Author

gottesmm commented Jul 3, 2023

As part of testing this, I discovered another issue in DI that is tied a little to this, so I am going to CCC them together.

@gottesmm
Copy link
Contributor Author

gottesmm commented Jul 4, 2023

@swift-ci test macOS platform

@gottesmm gottesmm merged commit 20e5577 into swiftlang:release/5.9 Jul 4, 2023
@gottesmm gottesmm deleted the release-5.9-111659649 branch July 4, 2023 06:35
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.

4 participants