-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[os_log][SIL Optimization] Make new os log APIs @_transparent and change OSLogOptimization pass so that inlining is not performed. #24971
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
@swift-ci Please test |
Build failed |
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.
So to be clear: you marked the initializer with a semantic call so you could just constant fold it instead of inlining it?
SILInstruction *currInst = &(*currI); | ||
|
||
// Break if currInst is a release_value of 'oslogMessage'. | ||
if (auto *releaseValueInst = dyn_cast<ReleaseValueInst>(currInst)) { |
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.
- For this to work when ownership is enabled, you need to at least handle destroy_value and probably need to look through copy_value.
- Is this a struct or a class? If it is a class, you probably also need strong_release.
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.
So to be clear: you marked the initializer with a semantic call so you could just constant fold it instead of inlining it?
Yes, that's right. One thing I would add is that the initializer was always constant evaluated but was mandatorily inlined earlier and then evaluated. Now it is marked with @_semantics and not mandatorily inlined (it can still be constant evaluated), and more importantly it is used to identify the range of instructions to evaluate.
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.
- For this to work when ownership is enabled, you need to at least handle destroy_value and probably need to look through copy_value.
- Is this a struct or a class? If it is a class, you probably also need strong_release.
This is a struct. I see. Thanks for the update, I will watch out for that. Actually, this condition is more of a safe guard and in reality the evaluation should break even before this instruction as there will instructions that it cannot constant evaluate (due to the implementation of os_log) and will bail out earlier.
@swift-ci Please test linux platform |
Can you add the destroy-value and copy value plz |
Okay. Will |
I pushed a commit that makes the OSLogOptimization pass work on ownership SIL. The following are the two main changes:
There is still a problem in this pass that causes ownership verification to fail. (Basically, the string initialization instructions that are created to fold string literals are not released.) Excepting this, the pass works on ownership SIL (i.e., when ownership stripping happens after serialization). I will a create follow up PR to address this problem, and also create PRs for changes to the constant evaluator to handle ownership SIL instructions. |
@swift-ci Please test |
Build failed |
Build failed |
@ravikandhadai was the lack of releasing of the initialization instructions a /real/ bug? |
Also, you may want to look at destructure_struct as well. |
change OSLogOptimization pass so that inlining is not performed.
on ownership SIL.
44a397d
to
4d4609a
Compare
Yes, it was a leak, but only discovered by the ownership verifier. Basically, when an instruction like The main changes for this is in the function |
@swift-ci Please test |
Build failed |
Build failed |
@swift-ci Please test macOS Platform |
Build failed |
@swift-ci Please smoke test macOS Platform |
1 similar comment
@swift-ci Please smoke test macOS Platform |
@swift-ci Please test macOS Platform |
Build failed |
@swift-ci Please clean test macOS Platform |
@atrick @eeckstein, I have made a change to the OSLogOptimization pass to address an issue raised by @gottesmm. Basically, I have removed inlining from the pass, which caused problems as the pass was in the mandatory pipeline but wasn't using Mandatory inlining (which happens earlier). The reason for that was that the pass used @_semantics attribute to identify log calls, extract the custom string interpolation argument of the call, and identify the instructions that must be constant evaluated. The call and the @_semantics attribute will be lost by mandatory inlining.
This commit changes how the instructions to constant evaluate are identified. The new approach uses the "initializer" calls of the custom string interpolation type: 'OSLogMessage' to drive the constant evaluation and folding. The initializer calls need not be inlined and are constant evaluable. The main benefit of the current approach is that, it will kick in at every place where the type 'OSLogMessage' is instantiated using a string interpolation, regardless of whether or not it is passed to a os_log call. E.g. the optimization will also apply to cases like the following.
A note: the diagnostics in this pass will be subsumed and enhanced by a new pass that will enforce the library implementation model (by checking if the implementation is constant evaluable etc.) and also the user model for the log calls (by checking if the log calls are passed a string interpolation). The diagnostics in this pass will eventually become redundant and should just be asserts/noops.