Skip to content

[move-only] Refactor CanonicalizeOSSA so we can emit nicer non-consuming use notes and increase quality of errors. #63429

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 Feb 4, 2023

Specifically:

  1. I refactored CanonicalizeOSSA so that callers (that is the move object checker) are able to use its internal liveness information before it does any rewriting. This change in design let me eliminate the callbacks from its rewriting implementation and also emit the missing non-consuming use remarks.
  2. I changed how we emit the actual diagnostic in the move only object checker so instead of just dumping all of the consuming/non-consuming uses, we actually go search for a reachable use from the non-boundary consuming use that we found. This means that when we emit the error, you will not see consuming boundary uses that are not actually important to the boundary computation.

…ime into an API that computes liveness and a second API that rewrites copies/destroys and fix up MoveOnly checkers to use it.

For those who are unaware, CanonicalizeOSSALifetime::canonicalizeValueLifetime()
is really a high level driver routine for the functionality of
CanonicalizeOSSALifetime that computes liveness and then rewrites copies using
boundary information. This change introduces splits the implementation of
canonicalizeValueLifetime into two parts: a first part called computeLiveness
and a second part called rewriteLifetimes. Internally canonicalizeValueLifetime
still just calls these two methods.

The reason why I am doing this is that it lets the move only object checker use
the raw liveness information computed before the rewriting mucks with the
analysis information. This information is used by the checker to compute the raw
liveness boundary of a value and use that information to determine the list of
consuming uses not on the boundary, consuming uses on the boundary, and
non-consuming uses on the boundary. This is then used by later parts of the
checker to emit our errors.

Some additional benefits of doing this are:

1. I was able to eliminate callbacks in the rewriting stage of
CanonicalOSSALifetimes which previously gave the checker this information.

2. Previously the move checker did not have access to the non-consuming boundary
uses causing us to always fail appropriately, but sadly not emit a note showing
the non-consuming use. I am going to wire this up in a subsequent commit.

The other change to the implementation of the move checker that this caused is
that I needed to add an extra diagnostic check for instructions that consume the
value twice or consume the value and use the value. The reason why this must be
done is that liveness does not distinguish in between different operands on the
same instruction meaning such an error would be lost.
…or objects and emit more precise errors for consuming use errors.

Specifically, previously if we emitted an error we just dumped all of the
consuming uses. Now instead for each consuming use that needs a copy, we perform
a search for a specific boundary use (consuming or non-consuming) that is
reachable from the former and emit a specialized error for it. Thus we emit for
the two consuming case the normal consumed twice error, and now for
non-consuming errors we emit the "use after consume" error.
@gottesmm
Copy link
Contributor Author

gottesmm commented Feb 4, 2023

@swift-ci smoke test

@gottesmm gottesmm merged commit f2e04ce into swiftlang:main Feb 4, 2023
@gottesmm gottesmm deleted the pr-0b6d2f3c0f1d40368a9489ac7050351ea7e317bd branch February 4, 2023 21:23
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