Skip to content

[NFC] Utilities for lifetime dependent coroutines #77675

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 9 commits into from
Nov 18, 2024

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Nov 18, 2024

A set of NFC utilities for working with coroutines. These are currently blocking the enablement of lifetime dependent _read accessors.

A begin_apply token may be used by operands that do not end the coroutine:
mark_dependence.

We need an API that gives us only the coroutine-ending uses. This blocks
~Escapable accessors.

end_borrow is considered coroutine-ending even though it does not actually
terminate the coroutine.

We cannot simply ask isLifetimeEnding, because end_apply and abort_apply do not
end any lifetime.
Only return the EndApplyInst and AbortApplyInst uses.
To be consistent with the C++ implementation.
Add endInstructions requirement so it can be called on an unknown
ScopedInstruction.
AccessBase already identifies a base address as either a .global (addressor) or
a .pointer. When initializing an AccessBase from a pointer_to_address, precisely
identify one of these kinds of accesses, rather than simply marking it
.unidentified.

This used to be a special case in the AccessPathWalker. But that's not the right
place to handle it.
LifetimeDependence uses the address of the AccessBase to compute liveness. It is
more convenient to switch over all AccessBase kinds here rather than force all
clients to do it.
And simplify enclosingAccessScope.

These two APIs now directly compute what is being asked for. Previously, each
invocation of enclosingAccessScope would recompute the base and all nested
scopes, but throw away that information. Sometimes we do not want to compute
that information, and other times we need all of it. Instead, provide separate
APIs that do exactly what is needed.

These are common APIs used by other utilities. This avoids quadratic traversals in those
cases. It is also easier to understand and debug.

These utilities will be used in LifetimeDependenceScopeFixup.
Some utilities, like Builder.insert(after:) pass a Builder object that
represents an insertion point. That insertion point is sometimes needed to
determine which instructions to create (endApply vs. abortApply). But there is
no way to recover the insertion point. We don't want to simply return an
instruction, because that could be interpreted in different ways. Instead we
provide insertion block, but only in those situations where it makes sense and can't
be used incorrectly.
@atrick
Copy link
Contributor Author

atrick commented Nov 18, 2024

@swift-ci test

@atrick atrick merged commit ff21dde into swiftlang:main Nov 18, 2024
5 checks passed
@atrick atrick deleted the endapply_utils branch November 18, 2024 17:44
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