-
Notifications
You must be signed in to change notification settings - Fork 10.5k
5.10: [SIL] Key consume checking off var_decl attr. #70068
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
nate-chandler
merged 4 commits into
swiftlang:release/5.10
from
nate-chandler:cherrypick/release/5.10/rdar118059326
Nov 29, 2023
Merged
5.10: [SIL] Key consume checking off var_decl attr. #70068
nate-chandler
merged 4 commits into
swiftlang:release/5.10
from
nate-chandler:cherrypick/release/5.10/rdar118059326
Nov 29, 2023
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previously, the lexical attribute on begin_borrow instructions was used. This doesn't work for values without lexical lifetimes which are consumed, e.g. stdlib CoW types. Here, the new var_decl attribute on begin_borrow is keyed off of instead. This flag encodes exactly that a value corresponds to a source-level VarDecl, which is the condition under which checking needs to run. rdar://118059326
@swift-ci please test |
@swift-ci please test source compatibility |
tbkka
approved these changes
Nov 28, 2023
Source compat failures match the failures in baseline tracked at #70072 . |
nate-chandler
added a commit
to nate-chandler/swift
that referenced
this pull request
Dec 1, 2023
**Description**: Run OSLogMandatoryOptTest.swift only in configurations with release stdlibs. swiftlang#70068 introduced a simple but widespread change to SIL. It required updating a number of tests. The updates amounted to inserting numerous of `begin_borrow [var_decl]` instructions. On 5.10--but not main--OSLogMandatoryOptTest.swift had to be updated as well: several new `begin_borrow [var_decl]` instructions had to be FileCheck'd. These instructions all came from inlining code from the OSLogTestHelper target, a target which is built in the same configuration as the stdlib. In fact, they all came from inlining the `_osLogTestHelper(_:assertion:)` function. When building OSLogTestHelper for release, no optimization passes are run on the function because it is marked `@_optimize(none)`. `SemanticARCOpts` would have deleted these borrow scopes, but it doesn't run on the function. When building OSLogTestHelper for debug, however, `MandatoryARCOpts` (a subset of `SemanticARCOpts`) _does_ run despite the function being marked `@_optimize(none)`. That's because it's part of the `OnonePassPipeline` which is mandatory, meaning that every pass runs on each function, regardless of it being annotated `@_optimize(none)`. As a result the `begin_borrow [var_decl]` instructions--which FileCheck lines were added to match--are deleted before FileCheck runs. So the new check lines fail to match the deleted instructions. Besides the absence of these new `begin_borrow [var_decl]` instructions, there is no difference between the function in debug vs release. In particular, removing the newly added check lines allows the test to pass in a configuration with a debug stdlib. Rather than duplicate the test for debug configurations, just disable it in them. ---- On main, the new `begin_borrow [var_decl]` instructions were already deleted by a new mandatory `begin_borrow` simplification that exists only on main but not release/5.10, so they weren't present to be FileCheck'd in either configuration, which is why the test wasn't updated for main. Risk: None. Test-only change. **Scope**: Zero. Affects a test. **Original PR**: No. **Reviewed By**: Andrew Trick ( @atrick ) **Testing**: Yes, this is a test change. **Resolves**: rdar://118954955
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description: Key consume checking off SIL-level variable markers.
The diagnostic pass responsible for checking the validity of lifetimes of a value corresponding to a source-level variable which has been
consume
d requires two pieces of information: (1) the root value which corresponds to the variable that wasconsume
d and (2) where the value wasconsume
d . It uses (1) to determine which values to check and (2) to determine where their final use must be. The second is provided by amove_value [allows_diagnostics]
instruction.Previously, the pass relied on
begin_borrow [lexical]
instructions for the first. Such instructions, however, exist to describe the lifetimes of values which are tied to lexical scopes and which cannot be shortened over deinit barriers. Not every type of variable has a lexical lifetime, however; for example, stdlib CoW types do not. As a result, the pass--which expected (1) to be provided in the form of abegin_borrow [lexical]
--when no such instruction exists, would fail to check that value. The result was incorrect diagnostics.Here, a new marker is used to indicate the existence of a source-level variable to diagnostic passes:
begin_borrow [var_decl]
. Such instructions are emitted for all non-trivial values which correspond to AST VarDecls, aka source-level variables. The pass now expects (1) to be indicated by these new markers. The result is correct diagnostics since all variables of non-trivial type (which are also the only variables which can be consumed) will be checked by the pass.Risk: Low. This perturbs the ownership SIL to be more similar to 5.9's SIL than it was prior to this patch.
Scope: Affects variable lifetime representation.
Original PR: #70054
Reviewed By: Andrew Trick ( @atrick )
Testing: Added tests.
Resolves: rdar://118059326