Commit Graph

11224 Commits

Author SHA1 Message Date
Andrew Trick
60cb13e164 [NFC] PredictableMemOpts: refactor to allow extension
Fully encapsulate ownership fixup so we can extend it.
2024-10-12 23:16:12 -07:00
swift-ci
8a2edbc4c5 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-11 17:05:06 -07:00
Michael Gottesman
3050916efc Merge pull request #76982 from gottesmm/pr-635c4050850f061c438b2dc1c396806e8754666c
When printing logging, dump out the whole function.
2024-10-11 16:56:02 -07:00
nate-chandler
249831f9f3 Merge pull request #76942 from nate-chandler/general-coro/20240927/1
[CoroutineAccessors] SIL represents callee alloc.
2024-10-11 16:39:53 -07:00
Michael Gottesman
9a6090fc43 When printing logging, dump out the whole function.
Just to make it a little quicker to debug/get this information when debugging
the pass. I have been wanting this and just hadn't gotten around to adding it.
It just centralizes the last piece of information that one wants to reach for
when debugging.
2024-10-11 13:19:05 -07:00
Nate Chandler
71239d6357 [CoroutineAccessors] SIL represents callee alloc.
When its operand has coroutine kind `yield_once_2`, a `begin_apply`
instruction produces an additional value representing the storage
allocated by the callee.  This storage must be deallocated by a
`dealloc_stack` on every path out of the function.  Like any other stack
allocation, it must obey stack discipline.
2024-10-11 08:25:03 -07:00
swift-ci
cb83584ebd Merge remote-tracking branch 'origin/main' into rebranch 2024-10-11 06:34:12 -07:00
Erik Eckstein
eed8645610 Optimizer: improve the load-copy-to-borrow optimization and implement it in swift
The optimization replaces a `load [copy]` with a `load_borrow` if possible.

```
  %1 = load [copy] %0
  // no writes to %0
  destroy_value %1
```
->
```
  %1 = load_borrow %0
  // no writes to %0
  end_borrow %1
```

The new implementation uses alias-analysis (instead of a simple def-use walk), which is much more powerful.

rdar://115315849
2024-10-11 09:41:37 +02:00
Erik Eckstein
52deb58251 Optimizer: add the FunctionPassContext.completeLifetime(of: Value) utility
Implemented by bridging the OSSALifetimeCompletion utility
2024-10-11 09:41:37 +02:00
swift-ci
25f0382ca5 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-09 18:07:23 -07:00
Michael Gottesman
131ab89f49 Merge pull request #76920 from gottesmm/pr-4ab85a74d0641a99b3a480971f93b2f98f726e31
[region-isolation] Add a special error for when a closure captures a non-Sendable box.
2024-10-09 17:36:29 -07:00
Michael Gottesman
ce7a0db192 [region-isolation] Add a special error for when a closure captures a non-Sendable box.
The reason that I am modifying this error is that in situations like the
following one can have a Sendable type that triggers this error since the box
containing the value is non-Sendable.

```
func methodConsuming(x: consuming SendableKlass) async throws {
  try await withThrowingTaskGroup(of: Void.self) { group in
    group.addTask { // expected-tns-warning {{passing closure as a 'sending' parameter risks causing data races between code in the current task and concurrent execution of the closure}}
      useValue(x) // expected-tns-note {{closure captures reference to mutable var 'x' which is accessible to code in the current task}}
    }

    try await group.waitForAll()
  }
}
```

rdar://133813644
(cherry picked from commit 36c2b3cc1330c07dcf9715f8ae88d31f9dba58c4)
2024-10-09 11:14:28 -07:00
swift-ci
c2fff1cc0f Merge remote-tracking branch 'origin/main' into rebranch 2024-10-09 03:14:46 -07:00
Erik Eckstein
e50a93a34c Generic specializer: don't use pre-specialization for Array._endMutation
Pre-specialization of `Array._endMutation` (for AnyObject) prevents inlining this function and that results in sub-optimal code.
This function is basically a no-op. So it should be inlined.

Unfortunately we cannot remove the specialize-attributes anymore because the pre-specialized function(s) are now part of the stdlib's ABI.
Therefore make an exception for `Array._endMutation` in the generic specializer.
2024-10-08 17:37:17 +02:00
Erik Eckstein
c97502374b Optimizer: add constant folding of classify_bridge_object
Constant fold `classify_bridge_object` to `(false, false)` if the operand is known to be a swift class.
2024-10-08 16:24:46 +02:00
swift-ci
8d3265a328 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-07 11:34:54 -07:00
Erik Eckstein
c05234e677 MandatoryPerformanceOptimizations: specialize witness_method instructions
In Embedded Swift, witness method lookup is done from specialized witness tables.
For this to work, the type of witness_method must be specialized as well.
Otherwise the method call would be done with wrong parameter conventions (indirect instead of direct).
2024-10-07 09:00:31 +02:00
Erik Eckstein
792dee2f5f SIL: support specialized witness_method instructions
In Embedded Swift, witness method lookup is done from specialized witness tables.
For this to work, the type of witness_method must be specialized as well.
Otherwise the method call would be done with wrong parameter conventions (indirect instead of direct).
2024-10-07 09:00:31 +02:00
swift-ci
cd3016368e Merge remote-tracking branch 'origin/main' into rebranch 2024-10-05 17:14:49 -07:00
John McCall
ddcceb3d43 Merge pull request #76880 from rjmccall/actor-delegating-init-isolation
Hop to the current isolation properly in delegating async actor initializers
2024-10-05 20:10:31 -04:00
John McCall
af8115ffa3 Hop to the current isolation properly in delegating async actor initializers.
This requires two major changes.

The first is that we need to teach SILGen that the isolation of an initializer
is essentially dynamic (as far as SILGen is concerned) --- that it needs to emit
code in order to get the isolation reference.  To make this work, I needed to
refactor how we store the expected executor of a function so that it's not
always a constant value; instead, we'll need to emit code that DI will lower
properly.  Fortunately, I can largely build on top of the work that Doug previously
did to support #isolation in these functions.  The SIL we emit here around delegating
initializer calls is not ideal --- the breadcrumb hop ends up jumping to the
generic executor, and then DI actually emits the hop to the actor.  This is a little
silly, but it's hard to eliminate without special-casing the self-rebinding, which
honestly we should consider rather than the weirdly global handling of that in
SILGen today.  The optimizer should eliminate this hop pretty reliably, at least.

The second is that we need to teach DI to handle the pattern of code we get in
delegating initializers, where the builtin actually has to be passed the self var
rather than a class reference.  This is because we don't *have* a class reference
that's consistently correct in these cases.  This ended up being a fairly
straightforward generalization.

I also taught the hop_to_executor optimizer to skip over the initialization of
the default-actor header; there are a lot of simple cases where we still do emit
the prologue generic-executor hop, but at least the most trivial case is handled.
To do this better, we'd need to teach this bit of the optimizer that the properties
of self can be stored to in an initializer prior to the object having escaped, and
we don't have that information easily at hand, I think.

Fixes rdar://87485045.
2024-10-04 22:23:00 -04:00
swift-ci
16fbc330a3 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-04 03:15:55 -07:00
Andrew Trick
415d7ab7e2 [NFC] Fix a future PredictableMemOpt bug introduced by the previous commit.
This fixes a logic error that will only be exposed by the additional
functionality that motivated the cleanup. When the additional
functionality is checked in, it will contain a unit test for this fix.

This bug was introduced in:

commit 755a146730 (public/predmem_rewrite)
Author: Andrew Trick <atrick@apple.com>
Date:   Fri Sep 27 22:18:29 2024

    [NFC] rewrite PredictableMemOpts dead allocation elimination
2024-10-03 21:37:34 -07:00
swift-ci
b8a5d2d6d7 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-03 01:35:42 -07:00
Konrad `ktoso` Malawski
dea3b59331 Merge pull request #76250 from ktoso/wip-experimental-isolated-deinit 2024-10-03 17:19:10 +09:00
swift-ci
23d53573f5 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-02 19:30:23 -07:00
Michael Gottesman
f985b0ee03 [thunk-lowering] Add a pass that performs lowering of ThunkInsts.
Right now it just handles the "identity" case so we can validate the
functionality.
2024-10-02 14:15:49 -07:00
Michael Gottesman
561662d6cc [sil] Add a new instruction called ThunkInst.
For now this will only be used for HopToMainActorIfNeeded thunks. I am creating
this now since in the past there has only been one option for creating
thunks... to create the thunk in SILGen using SILGenThunk. This code is hard to
test and there is a lot of it. By using an instruction here we get a few benefits:

1. We decouple SILGen from needing to generate new kinds of thunks. This means
that SILGenThunk does not need to expand to handle more thunks.

2. All thunks implemented via ThunkInst will be easy to test in a decoupled way
with SIL tests.

3. Even though this stabilizes the patient, we still have many thunks in SILGen
and various parts of the compiler. Over time, we can swap to this model,
allowing us to hopefully eventually delete SILGenThunk.
2024-10-02 14:15:49 -07:00
swift-ci
7cc6111f96 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-02 01:53:55 -07:00
Erik Eckstein
5502373018 SIL: rename AssociatedTypeProtocolWitness -> AssociatedConformanceWitness in SILWitnessTable
To be consistent with the naming convention in the AST
2024-10-02 07:10:30 +02:00
Erik Eckstein
10782cf42b SwiftCompilerSources: introduce the AST module
As the optimizer uses more and more AST stuff, it's now time to create an "AST" module.
Initially it defines following AST datastructures:
* declarations: `Decl` + derived classes
* `Conformance`
* `SubstitutionMap`
* `Type` and `CanonicalType`

Some of those were already defined in the SIL module and are now moved to the AST module.
This change also cleans up a few things:
* proper definition of `NominalTypeDecl`-related APIs in `SIL.Type`
* rename `ProtocolConformance` to `Conformance`
* use `AST.Type`/`AST.CanonicalType` instead of `BridgedASTType` in SIL and the Optimizer
2024-10-02 07:10:29 +02:00
Erik Eckstein
44cd8d71d5 SIL: remove some const from decl arguments in SILBasicBlock and SILArgument APIs
It's not needed and would just introduce some const_casts.
2024-10-02 07:10:28 +02:00
swift-ci
e5f97d79c5 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-30 07:15:01 -07:00
nate-chandler
ba8f8ea282 Merge pull request #76526 from nate-chandler/general-coro/20240906/1
[CoroutineAccessors] Initial framing.
2024-09-30 07:04:04 -07:00
Konrad `ktoso` Malawski
45b97f146b Merge branch 'main' into wip-experimental-isolated-deinit 2024-09-30 13:47:39 +09:00
swift-ci
54d8c9feb0 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-29 14:55:02 -07:00
Hamish Knight
bf6bb650ea Merge pull request #76771 from hamishknight/rename-arg-interface-ty
[AST] NFC: Rename `getArgumentInterfaceType` -> `getPayloadInterfaceType`
2024-09-29 22:53:13 +01:00
Hamish Knight
91ae5d6345 [AST] NFC: Rename getArgumentInterfaceType -> getPayloadInterfaceType
IMO this is a slightly clearer name, many of its
uses already use the term "payload".
2024-09-29 17:05:14 +01:00
swift-ci
9b306afc1d Merge remote-tracking branch 'origin/main' into rebranch 2024-09-28 10:15:52 -07:00
Andrew Trick
f787e8f173 Merge pull request #76762 from atrick/predmem_rewrite
[NFC] rewrite PredictableMemOpts dead allocation elimination
2024-09-28 10:11:35 -07:00
Andrew Trick
755a146730 [NFC] rewrite PredictableMemOpts dead allocation elimination
Generalize the code that promotes the remaining uses of an allocation to make it
readable and extensible. We need to be able to promote allocations with more
interesting uses, namely mark_dependence.
2024-09-27 22:24:18 -07:00
Andrew Trick
b5e3b3befc [NFC] PredictableMemOpts: refactor isFullyAvailable.
For use as a general utility.
2024-09-27 22:23:29 -07:00
swift-ci
cde3e4910d Merge remote-tracking branch 'origin/main' into rebranch 2024-09-27 12:34:18 -07:00
Arnold Schwaighofer
29475100bd Merge pull request #76719 from aschwaighofer/revert_pr76656
Revert "Merge pull request #76656 from nate-chandler/rdar136388508"
2024-09-27 12:21:35 -07:00
Nate Chandler
091368ba21 [CoroutineAccessors] Added read.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
Nate Chandler
98a2e6a7df [CoroutineAccessors] Added modify.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
Ben Barham
c15bc19946 Merge remote-tracking branch 'origin/main' into main-to-rebranch
Conflicts:
  - `lib/Serialization/ModuleFileSharedCore.cpp` new headers on main
2024-09-26 16:01:56 -07:00
Andrew Trick
106e05f549 Merge pull request #76714 from atrick/refactor_predmemopt
[NFC] Refactor PredictableMemoryOptimization
2024-09-26 15:00:05 -07:00
Arnold Schwaighofer
8d8951768c Revert "Merge pull request #76656 from nate-chandler/rdar136388508"
This reverts commit b9228c81d1, reversing
changes made to 6fb2989bcf.

After PR#76686 this bailout should no longer be neccessary.

rdar://136681998
2024-09-26 09:26:21 -07:00
Erik Eckstein
d293fd9157 MoveOnlyWrappedTypeEliminator: handle open_existential_box instructions
Fixes a compiler crash

rdar://136460032
2024-09-26 09:36:54 +02:00