-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SIL] Make owned function arguments lexical. #41228
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] Make owned function arguments lexical. #41228
Conversation
d0dac47
to
97df9a3
Compare
97df9a3
to
959aeb6
Compare
As discussed, we should fix ownership RAUW before doing this so most of the CSE/SILCombine optimizations will still work on owned arguments... although adjusting the tests to handle local variables instead was very clever and we may want to keep some of those new tests too |
959aeb6
to
f007b8b
Compare
3827ab7
to
e8ff4ae
Compare
@swift-ci please benchmark |
@swift-ci please test |
Performance (x86_64): -O
Code size: -O
Performance (x86_64): -Osize
Code size: -Osize
Performance (x86_64): -Onone
Code size: -swiftlibsHow to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
e8ff4ae
to
99f9f57
Compare
@swift-ci please benchmark |
Performance (x86_64): -O
Code size: -O
Performance (x86_64): -Osize
Code size: -Osize
Performance (x86_64): -Onone
Code size: -swiftlibsHow to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
11b4548
to
6147b89
Compare
@swift-ci please test |
@nate-chandler Can you please document that in SIL.rst? E.g. under "Function Types" and/or "Ownership SSA". |
Build failed |
@eeckstein Absolutely! Sorry for leaving that out. |
Added some documentation to SIL.rst. |
@swift-ci please test |
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.
The documentation in SIL.rst looks very good!
Do you know the cause of the benchmark regressions?
2fbfbe6
to
cade25f
Compare
UpdateSSA was being used to rewrite destroys, not for its intended purpose. Besides being a misuse, it's also wasteful. Instead, just rewrite the destroys that it would have updated.
b95785f
to
6a99b7e
Compare
RAUWing a lexical value with a non-lexical value is illegal because it would result in the value's lifetime being shortened without regard to deinit barriers. RAUWing _with_ a lexical value is LEGAL so long as doing so doesn't extend its lifetime.
The destroys of owned arguments must not be hoisted over deinit barriers to respect the semantics of lexical lifetimes. Here, owned SILValues which are SILFunctionArguments are made to be lexical. Code which hoists destroys will check this field and not hoist destroys. Allowed more RAUWing to be done with lexical values; specifically, allowed the replacement of a non-lexical value with a lexical value if the replacing value's lifetime wouldn't be extended as a result. Updated tests to get owned values via applies rather than having them passed as arguments.
6a99b7e
to
2da6ac1
Compare
@swift-ci please test |
@swift-ci please benchmark |
Performance (x86_64): -O
Code size: -O
Performance (x86_64): -Osize
Code size: -Osize
Performance (x86_64): -Onone
Code size: -swiftlibsHow to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
@swift-ci please test windows 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.
Great!
The root cause of the In detail, the problem is that CanonicalizeOSSALifetime, which doesn't respect lexical lifetimes, no longer hoists the destroys of
to just after its last uses. Specifically, the destroy is not hoisted up from the end of the function to just after the apply of Before this change, SILCombine saw
and was able to rewrite it as
Now, though, the |
Is this something which is easy to fix? |
It should be reasonably straightforward. ShrinkBorrowScope has been restructured ( #41358 ) to make it easy to create the new LexicalDestroyHoisting from it. Filed rdar://88903962 . |
The destroys of owned arguments must not be hoisted over deinit barriers to respect the semantics of lexical lifetimes. Here, owned SILValues which are SILFunctionArguments are made to be lexical. Code which hoists destroys will check this field and not hoist destroys.