Type annotations for instruction operands are omitted, e.g.
```
%3 = struct $S(%1, %2)
```
Operand types are redundant anyway and were only used for sanity checking in the SIL parser.
But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:
* if the block with the definition appears after the block where the operand's instruction is located
* if a block or instruction is printed in isolation, e.g. in a debugger
The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
Run OSLogMandatoryOptTest.swift only in configurations with release
stdlibs.
https://github.com/apple/swift/pull/64789 introduced a simple but
widespread change to SIL. It required updating a number of tests. The
updates primarily involved replacing `begin_borrow` + `copy_value` with
`move_value` instructions.
In particular, OSLogMandatoryOptTest.swift had to be updated as well:
several new `move_value` 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 `move_value`s, 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 `move_value` 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 `move_value` 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.
rdar://119744393
Try to replace a begin_borrow with its owned operand.
This is either possible if the borrowed value (or a forwarded value if it) is copied:
```
%1 = begin_borrow %0
%2 = struct_extract %1 // a chain of forwarding instructions
%3 = copy_value %1
// ... uses of %3
end_borrow %1
```
->
```
%1 = copy_value %0
%3 = destructure_struct %0 // owned version of the forwarding instructions
// ... uses of %3
```
Or if the borrowed value is destroyed immediately after the borrow scope:
```
%1 = begin_borrow %0
%2 = struct_extract %1 // a chain of forwarding instructions
// ... uses of %2
end_borrow %1
destroy_value %1 // the only other use of %0 beside begin_borrow
```
->
```
%2 = destructure_struct %0 // owned version of the forwarding instructions
// ... uses of %2
destroy_value %2
```
When rewriting uses of a noncopyable value, the move-only checker failed to take into account
the scope of borrowing uses when establishing the final lifetimes of values. One way this
manifested was when borrowed values get reabstracted from value to in-memory representations,
using a store_borrow instruction, the lifetime of the original borrow would be ended immediately
after the store_borrow begins rather than after the matching end_borrow. Fix this by, first,
changing `store_borrow` to be treated as a borrowing use of its source rather than an
interior-pointer use; this should be more accurate overall since `store_borrow` borrows the
entire source value for a well-scoped duration balanced by `end_borrow` instructions. That done,
change MoveOnlyBorrowToDestructureUtils so that when it sees a borrow use, it ends the borrow
at the end(s) of the use's borrow scope, instead of immediately after the beginning of the use.
This change ensures all store_borrows are ended with an end_borrow, and uses of the store_borrow
destination are all in the enclosing store_borrow scope and via the store_borrow return address.
Fix tests to reflect new store_borrow pattern
In preparation for changing the default, explicitly specify the behavior
of all tests that are affected by the choice of behavior for lexical
lifetimes and copy-propagation.
The compiler stubs for testing the OSLog implementation are in need of an update. This change updates the stubs to be consistent with the current OSLog implementation, updates the existing tests, and adds new tests for String and metatype interpolations.
rdar://69719729
As of now, the sema checks for os_log allow only string interpolations to be passed
to the log calls. E.g. logger.log(foo("message")) would not be allowed. This PR
relaxes this requirement and allows it as long as foo is annotated as
@_semantics("constant_evaluable").
<rdar://problem/65215054>
This patch updates the OSLogMandatoryOptTest test suite so that
it only checks whether an expected format string appears in the SIL,
and omits checking that it is also passed to the _getGlobalStringTablePointer
builtin. The latter property is anyway necessary for the code to compile.
This is done to avoid hardcoding the begin_borrow and copy_value
instructions that may be introduced when the format string is passed
to the builtin. The begin_borrow instructions are omitted in release
builds while they appear in debug builds.
<rdar://problem/65251877>
For COW support in SIL it's required to "finalize" array literals.
_finalizeUninitializedArray is a compiler known stdlib function which is called after all elements of an array literal are stored.
This runtime function marks the array literal as finished.
%uninitialized_result_tuple = apply %_allocateUninitializedArray(%count)
%mutable_array = tuple_extract %uninitialized_result_tuple, 0
%elem_base_address = tuple_extract %uninitialized_result_tuple, 1
...
store %elem_0 to %elem_addr_0
store %elem_1 to %elem_addr_1
...
%final_array = apply %_finalizeUninitializedArray(%mutable_array)
In this commit _finalizeUninitializedArray is still a no-op because the COW support is not used in the Array implementation yet.
code for closures iff the closure is not created by the caller function
where the code is generated. Otherwise, when the closure is created
by the caller, just reuse it after copying and extending its lifetime.
Before this change new closures were created as long as all captures
of the closures were symbolic constants. This patch updates it so that
even if all captures are symbolic constants no code is generated for
closures that are already available in the caller. This avoids doing
needless work and also fixes the following bug.
<rdar://problem/61465764>
module to contain only code necessary for testing the compiler
optimizations and diagnostics. This commit comprises the following changes:
1. Rename the OSLogPrototype module to OSLogTestHelper and rename the files.
2. Make the private module: OSLogTestHelper independent of os overlay.
3. Simplify the os log test suites and make them not perform logging.
4. Enable the os log test suites on all platforms.
<rdar://problem/60542172>