Skip to content

[AddressLowering] Storage root inherits lexical. #61747

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 5 commits into from
Oct 27, 2022

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Oct 26, 2022

When a begin_borrow [lexical] is lowered, the lifetime that it describes can't be shortened (or eliminated) when lowering. In some cases, though, there will not be an alloc_stack corresponding directly to the value being borrowed.

In these cases, mark the whole aggregate lexical.

Make it clear that it's not a missed case.  It changes representation.
The switch_enum_addr consumes its operand so a copy is needed.
@nate-chandler nate-chandler requested a review from atrick October 26, 2022 18:10
@nate-chandler
Copy link
Contributor Author

@swift-ci please smoke test macOS platform

@nate-chandler nate-chandler force-pushed the opaque-values/1/20221014 branch 2 times, most recently from a966c1c to 4ddc754 Compare October 26, 2022 23:45
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler marked this pull request as ready for review October 26, 2022 23:48
@nate-chandler nate-chandler changed the title [AddressLowering] Move bound pattern into storage. [AddressLowering] Storage root inherits lexical. Oct 26, 2022
@nate-chandler
Copy link
Contributor Author

@swift-ci please test macOS platform

1 similar comment
@nate-chandler
Copy link
Contributor Author

@swift-ci please test macOS platform

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.

Nice.

Can you add the test case in which the payload is a tuple that the pattern match logic needs to destructure?

Should we also have a .sil test case for struct_extract?

@@ -2884,6 +2884,9 @@ ReturnInst::ReturnInst(SILFunction &func, SILDebugLocation debugLoc,

bool OwnershipForwardingMixin::hasSameRepresentation(SILInstruction *inst) {
switch (inst->getKind()) {
// Explicitly list instructions which definitely involve a representation
// change.
case SILInstructionKind::SwitchEnumInst:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice practice. Too bad we don't do it elsewhere.

@@ -2776,6 +2776,13 @@ void UseRewriter::visitBeginBorrowInst(BeginBorrowInst *borrow) {
allocStack->setIsLexical();
return;
}
auto storage = AccessStorageWithBase::compute(address);
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're not interested in AccessStorage, you should be able to use getAccessBase or AccessBase::compute

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, perfect! Changed to getAccessBase and checked propagated the lexical flag to it if its an alloc_stack and allowed it if it was a function argument. Added a struct extract test case for both an opaque value that needed an alloc_stack and one that was passed in.

When a `begin_borrow [lexical]` is lowered, the lifetime that it
describes can't be shortened (or eliminated) when lowering.  In some
cases, though, there will not be an alloc_stack corresponding directly
to the value being borrowed.

In these cases, mark the whole aggregate lexical.
@nate-chandler nate-chandler force-pushed the opaque-values/1/20221014 branch from 4ddc754 to c766956 Compare October 27, 2022 18:34
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler merged commit b779351 into swiftlang:main Oct 27, 2022
@nate-chandler nate-chandler deleted the opaque-values/1/20221014 branch October 27, 2022 23: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.

2 participants