Commit Graph

2864 Commits

Author SHA1 Message Date
L-j-h-c
913dcd62b8 [Gardening] fix typos across docs and codebase
fix typos across docs and codebase
2023-02-17 23:55:16 +09:00
Joe Groff
69e4b95fb8 SIL: Model noescape partial_applys with ownership in OSSA.
Although nonescaping closures are representationally trivial pointers to their
on-stack context, it is useful to model them as borrowing their captures, which
allows for checking correct use of move-only values across the closure, and
lets us model the lifetime dependence between a closure and its captures without
an ad-hoc web of `mark_dependence` instructions.

During ownership elimination, We eliminate copy/destroy_value instructions and
end the partial_apply's lifetime with an explicit dealloc_stack as before,
for compatibility with existing IRGen and non-OSSA aware passes.
2023-02-16 21:43:53 -08:00
swift-ci
32244f2663 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-12 22:13:08 -08:00
Michael Gottesman
c832b41b7b [move-only] Teach the move checker how to handle global_addr.
As part of this I also had to change how we emit global_addr in
SILGenLValue. Specifically, only for noncopyable types, we no longer emit a
single global_addr at the beginning of the function (in a sense auto-CSEing) and
instead always emit a new global_addr for each access. The reason why we do this
is that otherwise, access base visitor will consider all accesses to the global
to be for the same single access. In contrast, by always emitting the
global_addr each time, we provide a new base for each access allowing us to emit
the diagnostics that we want to.

rdar://102794400
2023-02-12 17:39:27 -08:00
Michael Gottesman
e58c45fa1e [move-only] Add support for ref_element_addr with AssignableButNotConsumable semantics.
rdar://104874497
2023-02-12 17:39:27 -08:00
Michael Gottesman
b0a316796a [move-only] Restructure move only diagnostics so that we can properly emit diagnostics for ref_element_addr and global_addr. 2023-02-12 17:39:27 -08:00
swift-ci
0531c93947 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-10 19:13:41 -08:00
Michael Gottesman
a4fc911812 Merge pull request #63577 from gottesmm/pr-afe5ea6bd7ed4135b577a80d00a7c74a78dfe73c
[debug-info] Add a new super class of DebugVarCarryingInst called VarDeclCarryingInst
2023-02-10 18:58:35 -08:00
Michael Gottesman
85ea8b5d5b [move-only] Rename CheckKind::NoImplicitCopy -> CheckKind::ConsumableAndAssignable
This fits the name of the check better. The reason I am doing this renaming is
b/c I am going to add a nonconsumable but assignable check for
global_addr/ref_element_addr/captures with var semantics.
2023-02-10 13:46:19 -08:00
Michael Gottesman
87829aaa32 [move-only] Rename CheckKind::NoCopy -> CheckKind::NoConsumeOrAssign.
This reflects better the true meaning of this check which is that a value marked
with this check cannot be consumed on its boundary at all (when performing
let/var checking) and cannot be assigned over when performing var checking.
2023-02-10 13:46:19 -08:00
Michael Gottesman
cec4896615 [debug-info] Add a new super class of DebugVarCarryingInst called VarDeclCarryingInst.
I discovered when working with improving the debug output of the move only
address checker that I had a need for lightweight thing like
DebugVarCarryingInst but that only could vend a VarDecl (unlike
DebugVarCarryingInst which also can vend a SILDebugVariable). As an example,
this lets one write a high level API that uses the standard API to loop over a
bunch of instructions all that vend a VarDecl and construct a stringified path
component list.

rdar://105293841
2023-02-10 13:37:59 -08:00
swift-ci
ff1899f6ec Merge remote-tracking branch 'origin/main' into rebranch 2023-02-09 09:33:22 -08:00
Pavel Yaskevich
8eebb5bec1 Merge pull request #63522 from xedin/revert-type-wrappers
[AST/Sema/SIL] Revert TypeWrappers feature functionality
2023-02-09 09:27:18 -08:00
swift-ci
962e99f385 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-09 01:13:59 -08:00
eeckstein
df6677b1b6 Merge pull request #63494 from eeckstein/instruction-passes
Optimizer: Replace the MandatoryCombine pass with a Simplification pass, which is implemented in Swift
2023-02-09 10:03:31 +01:00
swift-ci
358a73d425 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-09 00:33:48 -08:00
Erik Eckstein
d25b1ed834 Optimizer: Replace the MandatoryCombine pass with a Simplification pass, which is implemented in Swift
The Swift Simplification pass can do more than the old MandatoryCombine pass: simplification of more instruction types and dead code elimination.
The result is a better -Onone performance while still keeping debug info consistent.

Currently following code patterns are simplified:
* `struct` -> `struct_extract`
* `enum` -> `unchecked_enum_data`
* `partial_apply` -> `apply`
* `br` to a 1:1 related block
* `cond_br` with a constant condition
* `isConcrete` and `is_same_metadata` builtins

More simplifications can be added in the future.

rdar://96708429
rdar://104562580
2023-02-09 06:50:05 +01:00
Michael Gottesman
a624fece3e [move-only] Move MoveOnlyObjectChecker /before/ MoveOnlyAddressChecker in the pass pipeline and move post checker verification into the MoveOnlyAddressChecker.
The reason why I am doing this is that:

1. There are sometimes copy_value on move only values loaded from memory that
the MoveOnlyAddressChecker needs to eliminate.

2. Previously, the move only address checker did not rewrite copy_value ->
explicit_copy_value if it failed in diagnostics (it did handle load [copy] and
copy_addr though). This could then cause the copy_value elimination verification
in the MoveOnlyObjectChecker to then fail. So this suggested that I needed to
move the verification from the object checkt to the address checker.

3. If we run the verification in the address checker, then the object checker
(which previously ran before the address checker) naturally needed to run
/before/ the address checker.
2023-02-08 13:29:39 -08:00
Michael Gottesman
e70a7228cc [move-only] Integrate BorrowToDestructureTransform into the AddressChecker so we handle load [copy] switch_enum. 2023-02-08 13:22:59 -08:00
Michael Gottesman
f4877645b8 [move-only][borrow2destructure] Add support for processing switch_enum.
As mentioned previously, I am right now creating new Implementations for each
switch_enum argument. Once I get tests working I am going to refactor and reuse
the same implementation so I can reuse memory.

NOTE: This currently does not impact SILGen since I did not change SILGenPattern
to emit noncopyable switched upon values as guaranteed. Keep in mind that I am
not going to do this for no implicit copy though since no implicit copy values
cannot contain move only values so we do not need to work with destructures.
2023-02-08 13:21:34 -08:00
Pavel Yaskevich
e0bf2ff854 [SIL/DI] NFC: Remove TypeWrappers feature functionality 2023-02-08 10:14:29 -08:00
Michael Gottesman
e9e704eb73 [move-only][borrow2destructure] Move destructureNeedingUses, instToInterestingOperandIdnexMap, and blocksToUses into the implementation.
For now, I am creating new implementations every time... but once I get the
tests passing, I am going to improve the performance by reusing the same
Implementation for all computations so we can reuse memory.
2023-02-07 16:35:36 -08:00
Michael Gottesman
83918054f8 [move-only][borrow2destructure] Split cleanup code into the borrow specific cleanup and inserting compensating destroys. 2023-02-07 16:35:34 -08:00
Michael Gottesman
b244df0702 [move-only][borrow2destructure] Sink liveness into the implementation and allow for it to be initialized separately from construction. 2023-02-07 16:34:48 -08:00
Michael Gottesman
69a163551f [move-only] Hide the AvailableValue impl used by BorrowToDestructureTransform in the implementation file. 2023-02-07 16:34:45 -08:00
Michael Gottesman
5d1fe77a0f [move-only] Move the rest of the actual computation from the borrowToDestructureTransform driver to the local Implementation. 2023-02-07 16:34:01 -08:00
Michael Gottesman
c25d58d838 [move-only] Refactor BorrowToDestructureTransform::gatherBorrows into an implementation local static function. 2023-02-07 16:32:23 -08:00
Michael Gottesman
4b6a87a041 [move-only] Begin extracting out the impl of BorrowToDestructure from its interface by moving gatherUses onto the impl. 2023-02-07 16:31:15 -08:00
Michael Gottesman
bd81c0d41d [move-only] Move header info for borrow to destructure transform into its own header and out of MoveOnlyObjectChecker.h 2023-02-07 16:31:14 -08:00
Michael Gottesman
91686c0758 [move-only] Refactor some helper structs out of BorrowToDestructureTransform into a private namespace in preparation for sinking into the implementation file. 2023-02-07 16:29:40 -08:00
Michael Gottesman
a4985bf056 [move-only] Change MoveOnlyBorrowToDestructureTransform into a driver invoked by the tester/main checker pass rather than a utility.
This is in preparation for sinking the main computation of the pass into an
implementation local helper struct that can process multiple values. I am doing
this so we can use the same code to process switch_enum arguments and am using
the current implementation to make sure I don't break anything.
2023-02-07 16:29:31 -08:00
Michael Gottesman
d5aea69335 [sil] Refactor field sensitive pruned liveness so it can be used with different sized root values. 2023-02-07 16:27:28 -08:00
Michael Gottesman
3b72951148 [sil] Provide FieldSensitivePrunedLiveness with its own implementation of PrunedLiveBlocks called FieldSensitivePrunedLiveBlocks.
This will let the non-field sensitive version use a more performant
implementation internally. This is important since PrunedLiveBlocks is used in
the hot path when working with Ownership SSA, while the field sensitive version
is only used for certain diagnostics.

NOTE: I did not refactor PrunedLiveness to use the faster implementation... this
is just a quick pass over the code to prepare for that change.
2023-02-07 16:26:41 -08:00
swift-ci
91c5d2faf2 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-04 13:33:42 -08:00
Michael Gottesman
f2e04ce061 Merge pull request #63429 from gottesmm/pr-0b6d2f3c0f1d40368a9489ac7050351ea7e317bd
[move-only] Refactor CanonicalizeOSSA so we can emit nicer non-consuming use notes and increase quality of errors.
2023-02-04 13:23:15 -08:00
Michael Gottesman
9ae7ff30dd [move-only] Wire up emission of the location for non-consuming uses for objects and emit more precise errors for consuming use errors.
Specifically, previously if we emitted an error we just dumped all of the
consuming uses. Now instead for each consuming use that needs a copy, we perform
a search for a specific boundary use (consuming or non-consuming) that is
reachable from the former and emit a specialized error for it. Thus we emit for
the two consuming case the normal consumed twice error, and now for
non-consuming errors we emit the "use after consume" error.
2023-02-04 10:43:13 -08:00
Michael Gottesman
20479c96fb [move-only] Refactor CanonicalizeOSSALifetime::canonicalizeValueLifetime into an API that computes liveness and a second API that rewrites copies/destroys and fix up MoveOnly checkers to use it.
For those who are unaware, CanonicalizeOSSALifetime::canonicalizeValueLifetime()
is really a high level driver routine for the functionality of
CanonicalizeOSSALifetime that computes liveness and then rewrites copies using
boundary information. This change introduces splits the implementation of
canonicalizeValueLifetime into two parts: a first part called computeLiveness
and a second part called rewriteLifetimes. Internally canonicalizeValueLifetime
still just calls these two methods.

The reason why I am doing this is that it lets the move only object checker use
the raw liveness information computed before the rewriting mucks with the
analysis information. This information is used by the checker to compute the raw
liveness boundary of a value and use that information to determine the list of
consuming uses not on the boundary, consuming uses on the boundary, and
non-consuming uses on the boundary. This is then used by later parts of the
checker to emit our errors.

Some additional benefits of doing this are:

1. I was able to eliminate callbacks in the rewriting stage of
CanonicalOSSALifetimes which previously gave the checker this information.

2. Previously the move checker did not have access to the non-consuming boundary
uses causing us to always fail appropriately, but sadly not emit a note showing
the non-consuming use. I am going to wire this up in a subsequent commit.

The other change to the implementation of the move checker that this caused is
that I needed to add an extra diagnostic check for instructions that consume the
value twice or consume the value and use the value. The reason why this must be
done is that liveness does not distinguish in between different operands on the
same instruction meaning such an error would be lost.
2023-02-04 10:43:13 -08:00
swift-ci
a7605eb1a3 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-03 09:53:28 -08:00
Pavel Yaskevich
168027b6bd Merge pull request #63390 from xedin/rdar-104931999
[SILOptimizer] Don't diagnose unreachable instructions that belong to…
2023-02-03 09:52:41 -08:00
swift-ci
0dd8c5da66 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-02 20:54:16 -08:00
Michael Gottesman
c6942eed7d Merge pull request #63392 from gottesmm/pr-edebfaea60c9ef3f6834b82c2f5155097c04c93b
[move-only][no-implicit-copy] Some small fixes
2023-02-02 20:39:44 -08:00
Pavel Yaskevich
afaeca763e [SILOptimizer] Don't diagnose unreachable instructions that belong to no-return func
The pass is attempting to diagnose any user-written code that appears
after the result of no-return function call. It has to skip any
instructions that happen after the no-return call but are associated
with it, such as `alloc_stack` to pass result of such call indirectly.

This helps to avoid extraneous diagnostics for synthesized code i.e.
a result builder with `buildExpression`:

```
static func buildExpression<T>(_ e: T) -> T { e }
```

The following example would produce extraneous warning:

```
switch <value> {
case ...
default: fatalError()
}
```

because it is translated into:

```
switch <value> {
case ...
default: {
  var $__builderDefault = buildExpression(fatalError())
  $__builderSwitch = buildEither(second: $__builderDefault)
}
}
```

In such cases all instructions that follow `fatalError()` call
are synthesized except to `alloc_stack $Never` which is passed
to `buildExpression`, that instruction is anchored on the
`fatalError()` itself which is where the diagnostic would point,
which is incorrect.

Resolves: rdar://104775183
2023-02-02 14:20:41 -08:00
Michael Gottesman
0986bd019e [no-implicit-copy] Make sure that we eliminate initial copy_value from [no_copy] cases like we do for moveonly.
Just missed pattern matching the copyable_to_moveonlywrapper at the beginning of
the initialization sequence.

rdar://104935447
2023-02-02 13:58:25 -08:00
swift-ci
731860bdf2 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-02 09:34:01 -08:00
Meghana Gupta
cbdf6e51ec Merge pull request #63323 from meg-gupta/ptrauthaddrdiversified4
Changes to support imported structs with ptruath qualified field function pointers
2023-02-02 09:19:29 -08:00
swift-ci
d72ecc512e Merge remote-tracking branch 'origin/main' into rebranch 2023-02-01 21:54:32 -08:00
Michael Gottesman
d909c8978e [no-implicit-copy] When accessing a field from a no-implicit-copy struct, unwrap it. Also do not run the move only borrow to destructure transform error.
The reason to do the first is to ensure that when I enable -sil-verify-all, we
do not have errors due to a copy_value of a move only type.

The reason to do the second thing is that:

1. If we have a move only type that is no implicit copy, I am in a subsequent
commit going to emit a type checker error saying that one cannot do this. When
we implement consuming/borrowing bindings/etc, we can make this looser if it
gets into the way.

2. If we have a copyable no implicit copy type, then any structural accesses
that we may want to do that would require a destructure must be to a copyable
type which is ok to copy as long as we do the unwrap from the first thing.

rdar://104929957
2023-02-01 14:48:45 -08:00
Michael Gottesman
4e86268243 [move-only] Teach the borrow to destructure transform how to handle consuming/non-consuming uses on the same instruction.
NOTE: The additional errors that are occuring in the move only object checker is
b/c I tweaked checkDestructureUsesOnBoundary so that when it detects an error it
continues instead of returns. This ensures that we get more that we emit errors
for multiple violations instead of just the first one.

rdar://104900171
2023-02-01 12:04:41 -08:00
swift-ci
282e7afc12 Merge remote-tracking branch 'origin/main' into rebranch 2023-01-31 21:14:04 -08:00
Michael Gottesman
48546fd6d3 [move-only] Move BorrowToDestructureTransform back into the Object Checker rather than as a separate pass.
The reason that I am doing this is I discovered that we emit worse quality
diagnostics since if we emit an error while running the borrow to destructure
transform, we want to do a complete cleanup to be safe (e.x.: converting
copy_value -> explicit_copy_value). This causes the object checker to then not
emit any additional diagnostics for other variables that were not impacted by
the BorrowToDestructureTransform, reducing the quality of diagnostics in a
significant way that isn't needed.
2023-01-31 15:24:17 -08:00