Skip to content

[SILOptimizer] Keep lexical lifetime markers. #39883

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

Conversation

nate-chandler
Copy link
Contributor

Previously, TempRValueElimination would peephole simple alloc_stacks, even when they were lexical; here, they are left for Mem2Reg to properly handle.

Previously, SemanticARCOpts would eliminate lexical begin_borrows, incorrectly allowing the lifetime of the value borrowed by them to be observably shortened. Here, those borrow scopes are not eliminated if they are lexical.

Added an executable test that verifies that a local variable strongly referencing a delegate object keeps that delegate alive through the call to an object that weakly references the delegate and calls out to it.

This ensures that while in OSSA, we have in the IR information about the lexical
lifetime of let variables.
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@meg-gupta
Copy link
Contributor

meg-gupta commented Oct 22, 2021

LGTM! If SIL tests don't exist for these cases with lexical borrows, can you add them too ?

Previously, TempRValueElimination would peephole simple alloc_stacks,
even when they were lexical; here, they are left for Mem2Reg to properly
handle.

Previously, SemanticARCOpts would eliminate lexical begin_borrows,
incorrectly allowing the lifetime of the value borrowed by them to be
observably shortened.  Here, those borrow scopes are not eliminated if
they are lexical.

Added an executable test that verifies that a local variable strongly
referencing a delegate object keeps that delegate alive through the call
to an object that weakly references the delegate and calls out to it.
@nate-chandler nate-chandler force-pushed the lexical_lifetimes/avoid-incorrect-elimination branch from b0ad750 to 3bb1766 Compare October 22, 2021 22:00
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

Yup!

@gottesmm
Copy link
Contributor

I am a little nervous about this. We should really run benchmarks with the flag enabled on this.
My concern is that all of these extra scopes may increase ARC traffic. My thinking is that to do this and avoid perf issues, we should consider having two parts of the ossa pipeline, a stage where we are required to have lexical lifetimes/can shrink lifetimes and a point after perhaps SemanticARCOpts runs/cleans these up where we can only remove copy/destroy and can not shrink lifetimes anymore.

@gottesmm
Copy link
Contributor

I talked with Nate. He is going to do some benchmarking with everything enabled to check for perf issues. That being said, he said he would also look into my suggestion in a week or so (which I am happy with) as follow up work.

@nate-chandler
Copy link
Contributor Author

@meg-gupta I will add the tests in a follow-up PR to unblock Michael.

@nate-chandler nate-chandler merged commit 1b3fa26 into swiftlang:main Oct 28, 2021
@nate-chandler nate-chandler deleted the lexical_lifetimes/avoid-incorrect-elimination branch October 28, 2021 17:55
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