Skip to content

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

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Nov 28, 2023

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 consumed requires two pieces of information: (1) the root value which corresponds to the variable that was consumed and (2) where the value was consumed . It uses (1) to determine which values to check and (2) to determine where their final use must be. The second is provided by a move_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 a begin_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

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
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please test source compatibility

@nate-chandler nate-chandler marked this pull request as ready for review November 28, 2023 21:35
@nate-chandler nate-chandler requested a review from a team as a code owner November 28, 2023 21:35
@nate-chandler
Copy link
Contributor Author

Source compat failures match the failures in baseline tracked at #70072 .

@nate-chandler nate-chandler merged commit 929b569 into swiftlang:release/5.10 Nov 29, 2023
@nate-chandler nate-chandler deleted the cherrypick/release/5.10/rdar118059326 branch November 29, 2023 03:19
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants