Commit Graph

2864 Commits

Author SHA1 Message Date
Michael Gottesman
4265aa1d71 [region-isolation] Refactor InOutSendingNotDisconnectedAtExit to use the error from PartitionUtils.h rather than have its own type. 2024-10-24 16:26:12 -07:00
Michael Gottesman
16bbd260ce [region-isolation] Refactor SentNeverSendable to use the new error type generated by PartitionUtils. 2024-10-24 16:02:57 -07:00
Michael Gottesman
2e403b9a7e [region-isolation] Remove dead code path.
This also has the nice effect of making the subsequent refactoring I am going to
do simpler.
2024-10-24 15:11:50 -07:00
Michael Gottesman
f23ad55acb [region-isolation] Eliminate CRTP for errors and just pass through an error struct instead.
This is going to let me just pass through the error struct to the diagnostic
rather than having the CRTP and then constructing an info object per CRTP.
Currently, to make it easier to refactor, I changed the code in
TransferNonSendable to just take in the new error and call the current CRTP
routines. In the next commit, I am going to refactor TransferNonSendable.cpp
itself. This just makes it easier to test that I did not break anything.
2024-10-24 15:00:43 -07:00
Andrew Trick
17a3b8a8a3 [MoveAddrChecker] load from borrowed value looks through mark_depend
Required to add dependencies to unsafe addressors.
2024-10-22 09:27:02 -07:00
Andrew Trick
bdcc4099c7 [MoveObjectChecker] same-inst checking for mark_depends
Extends checkForSameInstMultipleUseErrors to ignore irrelevant unowned uses,
including the mark_dependence base operand, which is currently considered a
pointer escape.
2024-10-22 09:27:02 -07:00
Andrew Trick
508e6760ec [MoveObjectChecker] handle mark_depends
MoveOnlyBorrowsToDestructure: fix gatherBorrows to ignore mark_dependence base
operand uses.
2024-10-22 09:27:02 -07:00
Nate Chandler
9c887a1ab1 [MoveAddrChecker] Init'd looks thru mark_depend.
Extend the hack to determine whether an address begins initialized to
look through mark_dependence instructions.
2024-10-21 09:50:02 -07:00
Nate Chandler
0b47442068 [NFC] MoveAddrChecker: Extract reused expression.
To enable changing its definition.
2024-10-21 09:49:59 -07:00
Nate Chandler
062d063764 [NFC] MoveAddrChecker: Extracted function.
While the FIXME to derive whether an address begins initialized requires
auditing all sites where the instruction is emitted to begin with,
making this a predicate that depends only on the instruction can be done
now.
2024-10-21 09:49:38 -07:00
Michael Gottesman
0e0665bfbd [concurrency] Add support for HopToMainActorIfNeededThunk.
It is behind the experimental flag GenerateForceToMainActorThunks.
2024-10-17 13:31:39 -07:00
Michael Gottesman
f0f5ad54fd [thunk-lowering] Add support for mangling identity thunks.
This is just again using identity thunks to show that the behavior works before
I add in hop to main actor.
2024-10-17 11:17:38 -07:00
Andrew Trick
24ed33bec0 Merge pull request #77040 from atrick/predmem_markdep
PredictableMemOpts: handle mark_dependence
2024-10-16 14:00:46 -07:00
nate-chandler
b5e3f42cad Merge pull request #77044 from nate-chandler/rdar137960229
[DiagnoseUnreachable] Ignore dead_end destroys.
2024-10-16 09:41:48 -07:00
Nate Chandler
ce368e8220 [DiagnoseUnreachable] Ignore dead_end destroys.
Such destroys mark the lifetime end of their operands along their
availability boundary.  They are currently inserted in this test case
by the ClosureLifetimeFixup pass, but in the fullness of time they will
be present for every value which is not explicitly destroyed (that's
what complete OSSA lifetimes is mostly about).

Currently, such destroys are diagnosed by DiagnoseUnreachable.  Fix the
diagnostic pass not to diagnose these valid instructions.

rdar://137960229
2024-10-15 21:00:16 -07:00
Andrew Trick
af86ad1e16 Test predictable memopt mark_dependence semantics.
Unit tests for mark_dependence support. Required to fix unsafeAddress.
2024-10-15 16:52:07 -07:00
Andrew Trick
19c1617059 PredictableMemOpts: handle mark_dependence source promotion 2024-10-15 16:48:36 -07:00
Andrew Trick
2e9daa444d PredictableMemOpts: handle MarkDependence base uses. 2024-10-15 11:18:43 -07:00
Andrew Trick
830a3664f1 Rename overloaded computeAvailableValues.
Overloaded names create confusion.
2024-10-15 11:18:43 -07:00
Andrew Trick
1ceebec1a0 [NFC] move a block of code into the correct heading.
No source change here, only reorganization that was deferred to avoid
making diffs hard to read.
2024-10-13 16:36:20 -07:00
Andrew Trick
2fd9e5e196 PredictableMemOpt: remove non-OSSA support
PredictableMemOpt only runs with OSSA. The recent refactoring did not
preserve non-OSSA conditions because it adds complexity. This commit
just makes it official.

In the near future, this pass will be replaced by an OSSA-only pass
anyway, so this brings us one small step closer to that.
2024-10-12 23:16:18 -07:00
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
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
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
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
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
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
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
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
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
Andrew Trick
106e05f549 Merge pull request #76714 from atrick/refactor_predmemopt
[NFC] Refactor PredictableMemoryOptimization
2024-09-26 15:00:05 -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
Andrew Trick
a635e8a292 [NFC] Refactor PredictableMemoryOptimization
In preparation for adding mark_dependence support.
Required to support addressors (unsafeAddress) in places
other than UnsafePointer.pointee.
2024-09-25 18:18:59 -07:00
Erik Eckstein
7ffd270008 embedded: move the VTableSpecializer pass into MandatoryPerformanceOptimizations
MandatoryPerformanceOptimizations already did most of the vtable specialization work.
So it makes sense to remove the VTableSpecializerPass completely and do everything in MandatoryPerformanceOptimizations.
2024-09-25 19:32:14 +02:00
Kuba (Brecka) Mracek
4a51cfaf27 Merge pull request #76572 from kubamracek/embedded-class-bound-existentials
[embedded] Introduce class-bound existentials into Embedded Swift
2024-09-20 13:58:06 -07:00
Kuba Mracek
6b9a3051e3 [embedded] Introduce class-bound existentials into Embedded Swift
Motivated by need for protocol-based dynamic dispatch, which hasn't been possible in Embedded Swift due to a full ban on existentials. This lifts that restriction but only for class-bound existentials: Class-bound existentials are already (even in desktop Swift) much more lightweight than full existentials, as they don't need type metadata, their containers are typically 2 words only (reference + wtable pointer), don't incur copies (only retains+releases).

Included in this PR:
[x] Non-generic class-bound existentials, executable tests for those.
[x] Extension methods on protocols and using those from a class-bound existential.
[x] RuntimeEffects now differentiate between Existential and ExistentialClassBound.
[x] PerformanceDiagnostics don't flag ExistentialClassBound in Embedded Swift.
[x] WTables are generated in IRGen when needed.

Left for follow-up PRs:
[ ] Generic classes support
2024-09-19 07:49:50 -07:00
Doug Gregor
49aa0e966f Ensure that SourceFiles always have a backing buffer in the SourceManager
The "buffer ID" in a SourceFile, which is used to find the source file's
contents in the SourceManager, has always been optional. However, the
effectively every SourceFile actually does have a buffer ID, and the
vast majority of accesses to this information dereference the optional
without checking.

Update the handful of call sites that provided `nullopt` as the buffer
ID to provide a proper buffer instead. These were mostly unit tests
and testing programs, with a few places that passed a never-empty
optional through to the SourceFile constructor.

Then, remove optionality from the representation and accessors. It is
now the case that every SourceFile has a buffer ID, simplying a bunch
of code.
2024-09-16 21:46:42 -07:00
Kuba Mracek
e7b74051e8 [embedded] Fix generic function skipping in PerfDiags, diagnose KeyPathInsts in closures 2024-09-13 15:19:49 -07:00
nate-chandler
9ee877943e Merge pull request #76186 from nate-chandler/rdar133779160
[ODL] Handle builtins.
2024-08-30 21:54:08 -07:00
Nate Chandler
5d9802f25f [ODL] Handle builtins.
No update is needed for the values they produce.  This pass should
really be refactored not to crash on instructions that aren't explicitly
listed or at least not to compile if not every instruction is listed.

rdar://133779160
2024-08-30 16:09:11 -07:00
Allan Shortlidge
789b795cec SILOptimizer: Allow inlining of transparent functions in @backDeployed thunks.
In order for availability checks in iOS apps to be evaluated correctly when
running on macOS, the application binary must call a copy of
`_stdlib_isOSVersionAtLeast_AEIC()` that was emitted into the app, instead of
calling the `_stdlib_isOSVersionAtLeast()` function provided by the standard
library. This is because the call to the underlying compiler-rt function
`__isPlatformVersionAtLeast()` must be given the correct platform identifier
argument; if the call is not emitted into the client, then the macOS platform
identifier is used and the iOS version number will be mistakenly interpreted as
a macOS version number at runtime.

The `_stdlib_isOSVersionAtLeast()` function in the standard library is marked
`@_transparent` on iOS so that its call to `_stdlib_isOSVersionAtLeast_AEIC()`
is always inlined into the client. This works for the code generated by normal
`if #available` checks, but for the `@backDeployed` function thunks, the calls
to `_stdlib_isOSVersionAtLeast()` were not being inlined and that was causing
calls to `@backDeployed` functions to crash in iOS apps running on macOS since
their availability checks were being misevaluated.

The SIL optimizer has a heuristic which inhibits mandatory inlining in
functions that are classified as thunks, in order to save code size. This
heuristic needs to be relaxed in `@backDeployed` thunks, so that mandatory
inlining of `_stdlib_isOSVersionAtLeast()` can behave as expected. The change
should be safe since the only `@_transparent` function a `@backDeployed` thunk
is ever expected to call is `_stdlib_isOSVersionAtLeast()`.

Resolves rdar://134793410.
2024-08-29 08:43:07 -07:00
Michael Gottesman
49eee05647 [region-isolation] Treat as Sendable values that are meant to be ignored since they are marked with preconcurrency
rdar://133531625
2024-08-24 13:14:39 -04:00
Michael Gottesman
bbc4816861 [sema] Move getConcurrencyDiagnosticBehaviorLimit and hasExplicitSendableConformance out of Sema and into libAST.
I am going to expose this on TypeBase, so I am attempting to prevent a layering
violation in between AST and Sema.
2024-08-23 20:42:51 -04:00
Michael Gottesman
f075e4eb28 Change DiagnosticBehavior into a struct enum so we can put methods on it.
The reason why I am making this change is because I want to put a merge
operation on DiagnosticBehavior. This merge operation allows for
DiagnosticBehavior to work like a lattice. When one merges, one moves
potentially from fatal, error to things like note, ignore.
2024-08-22 15:59:04 -04:00
Slava Pestov
b434c9fb56 Merge pull request #75984 from slavapestov/clean-up-opened-archetype
Clean up OpenedArchetypeType construction and more
2024-08-20 16:52:55 -04:00
Slava Pestov
0c2f28fd3d AST: Remove GenericSignature parameter from OpenedArchetypeType::get() 2024-08-20 12:15:27 -04:00