Skip to content

[OpaqueValues] Handle PartialApplyInsts and @out tuples. #61846

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

nate-chandler
Copy link
Contributor

AddressLowering handles PartialApplyInsts as it handles other applies.

SILGen handles @out tuples by flattening the values when passed to the epilog block and by reconstructing the tuple in the epilog before it is returned.

Individual commit messages provide additional details.

Previously the API was only on FullApplySite, but it is useful to be
able to insert code after a partial_apply as well.
Rather than being able to handle only to FullApplySites, it now handles
PartialApplyInsts as well.
Use the CallArgRewriter to rewrite uses by partial_apply insts just as
uses by apply insts, etc., are rewritten.
When branching to the exit block, flatten an @out tuple return value
into its components, as is done for all other return values.

In the exit block, when constructing the @out tuple to return, visit the
tuple-type-tree of the return value to reconstruct the nested tuple
structure: @out tuple returns are not flattened, unlike regular tuple
returns.
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please test source compatibility

@nate-chandler
Copy link
Contributor Author

@swift-ci please test source compatibility

@nate-chandler nate-chandler marked this pull request as ready for review November 3, 2022 15:04
@nate-chandler
Copy link
Contributor Author

The source compat failures are both in the type-checker and occurring with other PR requested runs. Merging.

@nate-chandler nate-chandler merged commit f931727 into swiftlang:main Nov 3, 2022
@nate-chandler nate-chandler deleted the opaque-values/1/20221027 branch November 3, 2022 15:05
Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

This code all looks good. I'm still trying to understand the conditions under which tuples are expanded.

void insertAfterInvocation(function_ref<void(SILBuilder &)> func) const;

/// Pass a builder with insertion points that are guaranteed to be immediately
/// after this full apply site has completely finished executing.
Copy link
Contributor

Choose a reason for hiding this comment

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

/// after this full apply site has completely finished executing.

This comment still refers to a full apply site

case FullApplySiteKind::TryApplyInst:
case ApplySiteKind::ApplyInst:
case ApplySiteKind::TryApplyInst:
case ApplySiteKind::PartialApplyInst:
Copy link
Contributor

Choose a reason for hiding this comment

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

The partial application of a closure is not the same as the invocation. So this should be called insertAfterApplication.

I could imagine a useful utility that inserted code after the actual invocation by finding the uses of non-escaping closures. But that's not what this does.

static SILValue buildReturnValue(SILGenFunction &SGF, SILLocation loc,
ArrayRef<SILValue> directResults) {
if (directResults.size() == 1)
return directResults[0];

auto fnConv = SGF.F.getConventions();
if (!fnConv.useLoweredAddresses()) {
// In opaque-values code, nested @out enums are not flattened. Reconstruct
Copy link
Contributor

Choose a reason for hiding this comment

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

This says "nested @out enums". Is it specific to tuples?

I'm still trying to convince myself that it is sufficient for this buildReturnValue logic to really be tuple specific, and specific to the function convention as opposed to the reabstraction pattern. Why is this only an issue for closures being passed to generic function types?

We should have @jckarter sign off on this approach

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is specific to tuples. The flattening only occurs for tuples.

nate-chandler added a commit that referenced this pull request Nov 4, 2022
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.

3 participants