-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[SIL] Maintain owned argument lifetimes at inlining. #60670
[SIL] Maintain owned argument lifetimes at inlining. #60670
Conversation
23ab07c
to
4e4143d
Compare
@swift-ci please benchmark |
@swift-ci please test |
@swift-ci please test source compatibility |
95e846a
to
bdbcb8f
Compare
@swift-ci please benchmark |
|
@swift-ci please test |
@swift-ci please benchmark |
|
8f3a2b7
to
683a749
Compare
|
5de700f
to
e8727d4
Compare
|
Previously, only @owned function arguments were treated as lexical. Here, all function arguments which report themselves to be lexical (i.e. based on their type and annotation) are regarded as lexical.
Add move_value to the list of ownership instructions through which lookThroughOwnershipInsts looks.
Previously, just copies and borrows were stripped. All ownership instructions, specifically, newly, move_value instructions, should be stripped.
Add move_value to the list of instructions through which getSingleValueCopyOrCast looks.
Just like begin_borrow and copy_value, move_value should be looked through because the interpreter doesn't model the memory operation it encodes.
e8727d4
to
2171216
Compare
Enables the outlining of the ContiguousArrayStorage<StaticString> used when initializing a RawRepresentable enum whose RawValue is String into a global value to continue even when ContiguousArrayStorage has a lexical lifetime. Addresses the following regressions StringEnumRawValueInitialization 400 7680 +1820.0% **0.05x** ArrayLiteral2 78 647 +729.5% **0.12x** DataCreateSmallArray 1750 8850 +405.7% **0.20x** seen when enabling lexical lifetimes in the standard library.
Recognize lexical borrows as nested when their borrowee's guaranteed reference roots are all lexical borrows. Addresses the following regressions Breadcrumbs.MutatedUTF16ToIdx.Mixed 188 882 +369.1% **0.21x** Breadcrumbs.MutatedIdxToUTF16.Mixed 230 926 +302.6% **0.25x** seen when enabling lexical lifetimes in the standard library.
Addresses the following regressions StackPromo 10100 14400 +42.6% **0.70x** seen when enabling lexical lifetimes in the standard library.
2171216
to
3de985f
Compare
@swift-ci please benchmark |
@swift-ci please smoke test |
1d426e5
to
a9bbb1d
Compare
When encountering inside a borrow scope a non-lexical move_value or a move_value [lexical] where the borrowed value is itself already lexical, delete the move_value and regard its uses as uses of the moved-from value.
Changes to teach the optimizer pipeline about move_value require some corresponding test updates.
a9bbb1d
to
a3fa246
Compare
Borrow scopes were moved when lexical borrow scopes were no longer emitted for owned arguments. Now, they are emitted when guaranteed values are needed. Fixing these diagnostics will be tracked separately. The same issue is already visible elsewhere in this test file, e.g. in castTestSwitch1, castTestSwitch2, and castTestSwitchInLoop.
@swift-ci please test |
@swift-ci please benchmark |
|
@swift-ci please test macOS platform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
@swift-ci please test macOS platform |
Previously,
begin_borrow [lexical]
were created during SILGen for @owned arguments. Such borrows could be deleted if trivially dead, which was the original reason why @owned arguments were considered lexical and could not have their destroys hoisted.Those borrows were however important during inlining because they would maintain the lifetime of the owned argument. Unless of course the borrow scope was trivially dead. In which case the owned argument's lifetime would not be maintained. And if the caller's value was non-lexical, destroys of the value could be hoisted over deinit barriers.
Here, during inlining,
move_value [lexical]
s are introduced during inlining whever the caller's value is non-lexical. This maintains the lifetime of the owned argument even after inlining.Additionally, took the opportunity to improve the handling of guaranteed function argument lifetimes: (1) during inlining they don't get lexical borrow_scopes when the caller's value is already lexical and (2) they are recongized as lexical.