Commit Graph

2864 Commits

Author SHA1 Message Date
Michael Gottesman
7fff6cd037 [region-isolation] Only perform merge assignment if we capture an address in a partial_apply rather than if we send it to any function apply.
Semantically these are the only cases where we would want to force an address to
be merged. Some notes:

1. When we have a box, the project_box is considered to come from the box and is
considered non uniquely identified.

2. The only place this was really triggering was when we created temporary
partial applies to pass to a function when using address only types. Since this
temporaries are never reassigned to, there isn't any reason to require them to
be merged.

3. In the case where we have an alloc_stack grabbed by a partial_apply, we still
appropriately merge.
2023-10-24 16:35:01 -07:00
Michael Gottesman
9dfc9b6a2d [region-isolation] Track if a non-Sendable value was derived from an actor and treat its region as being within an actor's isolation domain.
Importantly, we determine at the error stage if a specific value that is
transferred is within the same region of a value that is Actor derived. This
means that we can in a flow insensitive manner determine the values that are
actor derived and then via propagating those values into various regions
determine the issue... using our region analysis to handle the flow sensitivity.

One important case to reason about here is that since we are relying on the
region propagation for flow sensitivity is that this solves the var case for
us. A var when declared is never marked as actor derived. Var uses only become
actor derived if the var was merged into a region that contain is actor
derived. That means that re-assigning to a non-actor derived value, eliminates
the actor derived bit.

As part of this, I also discovered I could just get rid of the captured uniquely
identified array in favor of just passing in an actor derived flag.

rdar://115656589
2023-10-24 16:35:00 -07:00
Michael Gottesman
d069169c0d Fix some typos. 2023-10-24 12:47:11 -07:00
Michael Gottesman
926b4b1bb3 [region-isolation] Change TransferredReason to use a std::multimap.
In a future commit, I think I am going to change this to use a
SmallFrozenMultiMap so we can avoid the heap cost in most cases. For now though
I am just changing it to a std::multimap to make it cleaner and avoid having to
reason about when to freeze the SmallFrozenMultiMap.
2023-10-24 12:47:11 -07:00
Michael Gottesman
81a20e8609 [region-isolation] Convert some if(!condition) { assert(false) } -> assert(condition). 2023-10-24 12:47:11 -07:00
Michael Gottesman
bf647116e0 Merge pull request #69342 from gottesmm/small-region-isolation-fixes
[region-based-isolation] Stack of smaller fixes before a larger fix
2023-10-24 10:18:47 -07:00
nate-chandler
1a6d76ec47 Merge pull request #69314 from nate-chandler/opaque-values/20231020/1/coalesce-use-projections-into-phis
[AddressLowering] Allow use-projection into phi.
2023-10-24 07:06:32 -07:00
Nate Chandler
48f4b5aac4 [AddressLowering] Allow use-projection into phi.
Resolves numerous regressions when enabling AddressLowering early in the
pipeline.

Previously, if a value incoming into a phi had storage which itself was
a use-projection out of some other storage, PhiStorageOptimizer bailed
out.  The result was unnecessary "moves" (i.e. `copy_addr [take] [init]`
instructions).

Here, this bailout is removed.  In order to do this, it is necessary to
find (1) all values whose storage recursively project out of an incoming
value (such a value may have storage which is either a use _or_ a def
projection) and (2) the block which dominates the defs of all these
values.

Together, these values are used to compute liveness to determine
interference.  Previously, the live region was that between the uses of
an incoming value and its defining block.  Now, it is that between the
uses of any of the values found in (1) and the dominating block found in
(2).
2023-10-23 16:18:57 -07:00
Michael Gottesman
2c0efe6b8b [region-isolation] Go through the implementation again changing Consume -> Transfer.
I just missed these.
2023-10-23 13:52:14 -07:00
Michael Gottesman
01b1475d62 [region-isolation] Emit errors directly in ConsumeRequireAccumulator rather than passing in callbacks.
This indirection is premature abstraction since the only two places we actually
use these callbacks is to print the accumulated output and to emit our
errors. With this change, I was able to simplify how print works and inline in
the actual diagnostic emission making it easier to understand the code.

Additionally, in a subsequent commit I am going to need to ensure that we do not
emit an error here if the source cause of our error is due to an actor. To
implement that I would need to change tryDiagnoseAsCallsite to signal to the
machinery that it needs to not emit requires and then fail further up as
well. Given that there really wasn't a need for this abstraction in the first
place and the amount of munging needed to express this, I decided to just make
this change and make it easier. If we truly need this flexibility, we can always
add it back later.
2023-10-23 12:24:17 -07:00
Michael Gottesman
cbc12410b3 [region-isolation] Eliminate unnecessary helper.
SILValues always have a SILType... so just use getType().isAddress().
2023-10-23 12:24:17 -07:00
Michael Gottesman
a8886e7619 Delete an incorrect assert
If we consume a value in a block and then reinitialize it before the end of the
block, this assert will always fail.
2023-10-23 12:24:17 -07:00
Michael Gottesman
d598da596a [sil] Implement SILType::isActor().
Just a helper that calls getASTType()->isActorType().

I also updated the two places in SNS that we use this.
2023-10-23 12:24:17 -07:00
Mishal Shah
aa6a588f45 Merge pull request #69163 from apple/rebranch
Merge `rebranch` into `main` to support `stable/20230725` llvm-project branch
2023-10-23 09:26:37 -07:00
Nate Chandler
4d3c32d261 [AddressLowering] NFC: Added print.
Allow in-IR tests to print to stdout.
2023-10-20 18:16:38 -07:00
Andrew Trick
f1bec99705 Merge pull request #69250 from atrick/fix-deserialize-access
Fix deserialization to avoid invoking a pass N times per function
2023-10-20 11:02:25 -07:00
nate-chandler
407ebdcd6c Merge pull request #69276 from nate-chandler/opaque-values/20231019/1/fix-move-skipping
[AddressLowering] Move into secondary use.
2023-10-20 10:20:47 -07:00
Erik Eckstein
1ec71a3568 PerformanceDiagnostics: exclude error handling from performance-checked code
This was changed in https://github.com/apple/swift/pull/69121. But it's a bit to early because we don't have typed throws, yet.

rdar://117219154
2023-10-20 10:33:48 +02:00
Ben Barham
360c5d8465 Merge remote-tracking branch 'origin/main' into 20231019-merge-main
Conflicts:
  - `lib/AST/TypeCheckRequests.cpp` renamed `isMoveOnly` which requires
    a static_cast on rebranch because `Optional` is now a `std::optional`.
2023-10-19 16:16:23 -07:00
Joe Groff
251becbbdd Merge pull request #69263 from jckarter/move-only-loadable-to-address-reabstraction
Move only loadable to address reabstraction
2023-10-19 09:33:36 -07:00
Nate Chandler
69aaeb6682 [AddressLowering] Move into secondary use.
If a value's storage is a use projection out of some use,
AddressLowering correctly does not move into that storage when
initializing the composing use of the operand for the user into whose
storage it projects.

Previously, however, it was only checked that the value's storage was a
use projection at all.  When initializing the composing use of the
operand of some _other_ user of the value (i.e. a user into whose
storage it does _not_ project), the result was a missing move.

Here, this is fixed by only skipping the move when the value's storage
is a projection _and_ it projects into the storage of the user of the
operand at hand.
2023-10-19 09:00:52 -07:00
Nate Chandler
09511a726e [AddressLowering] NFC: Marked dump const. 2023-10-19 09:00:52 -07:00
Kuba Mracek
db10e78eb2 [embedded] Start diagnosing metatype/value_metatype instructions in embedded Swift 2023-10-18 16:51:10 -07:00
Andrew Trick
ef29250dcb Fix deserialization to avoid invoking a pass N times per function
Deserialization is calling AccessMarkerElimination repeatedly on the
same function.

The bug was introduced here:

commit 872bf40e17
Date:   Mon Aug 13 10:24:20 2018

    [sil-optimizer] Centralize how we send out serialization notifications.

Where the code that uniques the deserialization callbacks was simply
removed!

As a result, this pass was being invoked a number of times equal to
the number of functions in the module *multiplied* by the number of
functions being deserialized.

Fixes rdar://117141871 (Building spends most of its time in
AccessMarkerElimination)
2023-10-18 10:32:04 -07:00
Joe Groff
4bd466a6c3 Remove allow list for MarkUnresolvedNonCopyableValueInst markers.
If SILGen emitted a marker, that ought to be indication enough that move only checking
is necessary.
2023-10-17 14:32:26 -07:00
Evan Wilde
312bd47f4c Merge remote-tracking branch 'main' into 'rebranch' 2023-10-16 23:00:12 -07:00
nate-chandler
366514bd98 Merge pull request #69202 from nate-chandler/opaque-values/20231016/1/single-phi-incoming-value
[AddressLowering] Fixed single arg phi edge case.
2023-10-16 17:17:44 -07:00
Joe Groff
25061fb281 Merge pull request #69169 from jckarter/store-borrow-lifetime-nesting
SIL: Treat store_borrow as borrowing its source, and have the move-only checker account for borrow scopes.
2023-10-16 13:51:40 -07:00
Nate Chandler
43d26ceba3 [AddressLowering] Fixed single arg phi edge case.
Not every phi with a single incoming value can be coalesced.  Explicitly
check whether it is coalesceable and only coalesce it if so.
2023-10-16 12:35:40 -07:00
Evan Wilde
37ede16142 Merge remote-tracking branch 'main' into rebranch
Conflicts:
  lib/SILOptimizer/Mandatory/ClosureLifetimeFixup.cpp
2023-10-16 09:31:37 -07:00
Joe Groff
1dcf271fe0 SIL: Treat store_borrow as borrowing its source, and have the move-only checker account for borrow scopes.
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.
2023-10-16 09:12:25 -07:00
Joe Groff
e4be36bb1f Merge pull request #69191 from jckarter/moveonly-closure-lifetime-fixup-parameter-index-fix
ClosureLifetimeFixup: Fix parameter indexing issue.
2023-10-16 08:06:15 -07:00
Mishal Shah
3594f8ecaf Merge remote-tracking branch 'origin/main' into rebranch
Conflicts:
	test/IRGen/opaque-pointer-llvm.swift
2023-10-15 23:49:40 -07:00
Kuba (Brecka) Mracek
b257a02e69 Merge pull request #69081 from kubamracek/embedded-existential-diag
[embedded] Improve the diagnostic message when using an existential
2023-10-14 18:17:06 -07:00
Joe Groff
cb6f2b02f5 ClosureLifetimeFixup: Fix parameter indexing issue.
When deciding whether to clean up copies of noncopyable captures, I got
the parameter indexing wrong when the closure has non-capture arguments.
Fixing this allows noncopyable captures to work in more general
circumstances.
2023-10-14 10:00:21 -07:00
Andrew Trick
135d62007a Fix DiagnoseLifetimeIssues handling of nonescaping arguments.
Function call arguments were not being treated as liveness uses.

Unblocks SIL: Treat store_borrow as borrowing its source, and have the
move-only checker account for borrow scopes. #69169
https://github.com/apple/swift/pull/69169
2023-10-13 20:54:30 -07:00
swift-ci
2c8c0a1176 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-11 05:54:01 -07:00
Erik Eckstein
e2a268ed70 PerformanceDiagnostics: fix handling of infinite loops and change error handling
* Don't exclude code which end up in an infinite loop. rdar://116705459
* Don't exclude error handling code (throw, catch). Errors are existentials and will always allocate. Once we have typed throws it will be possible to do error handling without allocations.
2023-10-11 12:02:51 +02:00
Evan Wilde
24d0db249b Merge remote-tracking branch 'main' into 'rebranch'
Conflicts:
  CMakeLists.txt
    Take new BRIDGING_MODE

  SwiftCompilerSources/Sources/SIL/GlobalVariable.swift
    Take new
2023-10-09 17:21:23 -07:00
Kuba Mracek
d5b1abb726 [embedded] Improve the diagnostic message when using an existential 2023-10-09 16:20:08 -07:00
Andrew Trick
69a884565a Fix ownership of select_enum instruction
This instruction was given forwarding ownership in the original OSSA
implementation. That will obviously lead to memory leaks. Remove
ownership from this instruction and verify that it is never used for
non-trivial types.
2023-10-08 01:34:48 -07:00
swift-ci
a48b6d0f90 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-04 18:04:12 -07:00
Anton Korobeynikov
4d391f0f8e Add Differentiable requirements to pattern substitutions / pattern generic signature (#68777)
Add `Differentiable` requirements to pattern substitutions / pattern generic signature when calculating constrained function type. Also, add requirements for differentiable results as well.

Fixes #65487
2023-10-04 14:48:03 -07:00
swift-ci
f0bd604d71 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-02 09:33:57 -07:00
Pavel Yaskevich
24c4fcc10e [DI] Fix check that ignores loads related to assign_or_init and assign_by_wrapper
For cases where init accessor field has a nonmutating set we need
ignore copies and borrows associated with load of "self" because
they are going to be erased together with the setter application
by DI.
2023-09-29 13:18:54 -07:00
swift-ci
6c89a2244b Merge remote-tracking branch 'origin/main' into rebranch 2023-09-28 08:58:02 -07:00
Michael Gottesman
631ad05f33 Merge pull request #68712 from gottesmm/pr-8f27a8f70da71ca09280019764955e3b64882190
[isolation-regions] Eliminate unnecessary heap allocations used for temporary values
2023-09-28 10:43:10 -05:00
swift-ci
2e6b1cd2f7 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-28 07:13:53 -07:00
swift-ci
7fc36edb98 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-27 09:34:12 -07:00
Kuba Mracek
7c5962b8a7 [embedded] Prefer Module.getOptions().EmbeddedSwift in SIL code 2023-09-27 09:04:02 -07:00