Commit Graph

965 Commits

Author SHA1 Message Date
swift-ci
764fecbc01 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-21 20:34:25 -07:00
nate-chandler
397a25c377 Merge pull request #68608 from nate-chandler/rdar115468707
[CanonicalizeOSSALifetime] Extend lexical lifetimes to unreachables.
2023-09-21 20:25:46 -07:00
swift-ci
c55b21f2b5 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-21 16:10:25 -07:00
Nate Chandler
6c6776234a [CanOSSALife] Lexical lifetimes go to unreachables
When canonicalizing the lifetime of a lexical value, deinit barriers are
respected. This is done by walking backwards from lifetime ends and
adding encountered deinit barriers to liveness.

Only destroy lifetime ends were walked back from under the assumption
that lifetimes would be complete. Without complete OSSA lifetimes,
however, it's necessary to also necessary to consider lifetimes that end
with unreachables. Unfortunately, we can't simply walk back from those
unreachables because there may be instructions which are secretly users
of the value being canonicalized (e.g. destroys of `partial_apply`s to
which a `begin_borrow` of the value was passed). Such uses don't appear
in the use list because lifetime canonicalization expects complete
lifetimes and only visits lifetime ends of `begin_borrow`s.

Here, instead, the instructions before the relevant unreachables are
added to liveness. In order to determine which unreachables are
relevant, it's necessary to have a liveness that includes the original
destroys. So a copy of liveness is created and those destroys are added
to it.

rdar://115468707
2023-09-21 14:02:43 -07:00
Kavon Farvardin
d0a9e78da0 [Mangling] Support function specializations that remove async 2023-09-21 12:20:24 -07:00
swift-ci
e59baf89ed Merge remote-tracking branch 'origin/main' into rebranch 2023-09-20 17:56:36 -07:00
Nate Chandler
9006be10e3 [CanOSSALifetime] Respect lexical lifetimes flag.
Don't respect deinit barriers when canonicalizing if lexical lifetimes
are disabled.
2023-09-20 13:40:08 -07:00
Kuba Mracek
89df0426e0 [embedded] Specialize vtables when processing instructions, not bulk 2023-09-20 09:41:09 -07:00
Kuba Mracek
03f927eca1 [embedded] Perform VTable specialization iteratively as part of MandatoryPerformanceOptimizations 2023-09-20 09:41:09 -07:00
swift-ci
ae30cba296 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-13 10:20:48 -07:00
Kuba (Brecka) Mracek
b503f2831b Merge pull request #68461 from kubamracek/embedded-classes-generic
[embedded] Initial support for generic classes in embedded Swift
2023-09-13 10:01:50 -07:00
swift-ci
aeb4460bff Merge remote-tracking branch 'origin/main' into rebranch 2023-09-12 19:34:23 -07:00
Michael Gottesman
82fbde0e04 [send-non-sendable] Ensure that we properly warn if a field of a final actor is transferred.
Previously, we were not recognizing that a ref_element_addr from an actor object
is equivalent to the actor object and we shouldn't allow for it to be consumed.

rdar://115132118
2023-09-12 12:46:37 -05:00
Michael Gottesman
3a377a3e51 [send-non-sendable] When logging the pseudo-ir dump out the root representative value associated with pseudo-ir ids.
Really, we should just be using representative values here in general since it
serves the same purpose and makes it easier to trace back values. But this in
the short term makes the output easier to reason about.
2023-09-12 12:11:44 -05:00
Michael Gottesman
42df9c4c72 [send-non-sendable] Cleanup logging a little.
Specifically:

1. Converted llvm::errs() -> llvm::dbgs() when using LLVM_DEBUG.
2. Converted a dump method on errs to be a print method on dbgs that is called from dump with print(llvm::dbgs()).
2023-09-12 12:11:44 -05:00
Kuba Mracek
d0c2a4ccf8 [embedded] Initial support for generic classes in embedded Swift
- VTableSpecializer, a new pass that synthesizes a new vtable per each observed concrete type used
- Don't use full type metadata refs in embedded Swift
- Lazily emit specialized class metadata (LazySpecializedClassMetadata) in IRGen
- Don't emit regular class metadata for a class decl if it's generic (only emit the specialized metadata)
2023-09-12 09:44:54 -07:00
Michael Gottesman
a1daf817f3 [send-non-sendable] Remove ASCII color from log output.
Not everyone uses color output and having to remove the ASCII color support is
annoying.
2023-09-11 09:07:29 -05:00
swift-ci
4fe55c5732 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-11 00:35:20 -07:00
Andrew Trick
f46d79149d ClosureLifetimeFixup review feedback 2023-08-10 18:51:48 -07:00
Andrew Trick
9c24933bd4 Fix compiler crashes with consuming and borrowing keywords.
Without this fix, the new 'consuming' and 'borrowing' keywords cannot
be used with trivial types. Which means, for example, they can't be
used in macro expansions that work on various types.

Fixes patterns like:

public func test1(i: consuming Int) -> Int {
  takeClosure { [i = copy i] in i }
}

public func test2(i: borrowing Int) -> Int {
  takeClosure { [i = copy i] in i }
}

public func test3(i: consuming Int) -> Int {
  takeClosure { i }
}

// Sadly, test4 is still incorrectly diagnosed.
public func test4(i: borrowing Int) -> Int {
  takeClosure { i }
}

Fixes rdar://112795074 (Crash compiling function that has a macro annotation and uses `consuming`)
2023-08-10 11:17:45 -07:00
swift-ci
be3a013d93 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-02 12:34:03 -07:00
Ikko Eltociear Ashimine
a4ab34475a [SILOptimizer] Fix typo in KeyPathProjector.h
addres -> address
2023-08-01 16:40:07 +09:00
swift-ci
e24988e633 Merge remote-tracking branch 'origin/main' into rebranch 2023-07-28 09:44:12 -07:00
Joshua Turcotti
2eade1d1b5 Merge pull request #67511 from JTurcotti/tweaks
[SendNonSendable] Assorted Bugfixes and Tweaks
2023-07-28 09:24:36 -07:00
jturcotti
bb2f3c011e rename DeferredSendableChecking pass to SendNonSendable pass, handle more instructions such as try_apply and begin_apply, and fix bugs 2023-07-27 16:45:29 -07:00
Evan Wilde
309aed4925 Add SmallSetVector replacement
llvm::SmallSetVector changed semantics
(https://reviews.llvm.org/D152497) resulting in build failures in Swift.
The old semantics allowed usage of types that did not have an
`operator==` because `SmallDenseSet` uses `DenseSetInfo<T>::isEqual` to
determine equality. The new implementation switched to using
`std::find`, which internally uses `operator==`. This type is used
pretty frequently with `swift::Type`, which intentionally deletes
`operator==` as it is not the canonical type and therefore cannot be
compared in normal circumstances.

This patch adds a new type-alias to the Swift namespace that provides
the old semantic behavior for `SmallSetVector`. I've also gone through
and replaced usages of `llvm::SmallSetVector` with the
`Swift::SmallSetVector` in places where we're storing a type that
doesn't implement or explicitly deletes `operator==`. The changes to
`llvm::SmallSetVector` should improve compile-time performance, so I
left the `llvm::SmallSetVector` where possible.
2023-07-25 12:28:27 -07:00
Erik Eckstein
2384a0c6f4 Optimizer: remove the now unused LSLocation utilities 2023-07-21 07:19:56 +02:00
jturcotti
853ef7cf3c fix bugs that present themselves when handling multiarg and varargs functions, including adding better debug dump methods 2023-07-20 14:01:08 -07:00
jturcotti
a83d7aa39c improve diagnostics about data races; highlight the individual expressions being sent and accessed as precisely as possible, and include information about specific non-sendable types and isolation crossings 2023-07-19 17:27:16 -07:00
jturcotti
55e8f9f2ed improve debug output, finalize explicit constructor refactor, and begin improving diagnostic messages 2023-07-18 15:58:56 -07:00
jturcotti
3868f1dc27 perform refactor to use named types as elements and regions in partitions, and ensure that all SILValues are converted once to TrackableSILValues in the SendNonSendable analysis pass 2023-07-18 13:32:43 -07:00
jturcotti
34113c4c0f implement searching for a ConsumeReason instead of just diagnosing accesses to consumed values 2023-07-14 16:12:52 -07:00
jturcotti
1d130390be add more comprehensive cases to tests, and fix many bugs, relying on much more potent resolution of addresses 2023-07-14 09:28:27 -07:00
jturcotti
1a716d82cf replace use of internal "projections" tracking map with usage of memutils' AccessStorage utilities 2023-07-14 09:28:26 -07:00
jturcotti
e7a1747af2 Tweak, improve, and debug the PartitionAnalysis engine until a fairly comprehensive suite of simple tests passes (region_based_sendability.swift) 2023-07-11 11:12:38 -07:00
jturcotti
29bd728f4c Begin to fill in the SendNonSendable SIL pass using a PartitionAnalysis engine, works for some simple examples but needs to address address values in SIL. 2023-07-10 15:20:14 -07:00
jturcotti
aae9f43bda Write PartitionUtils.h, implementing common utilities for manipulating a partition data structure that will be used for flow-sensitive, region-based Sendable checking. 2023-07-10 15:20:14 -07:00
Nate Chandler
4374b6b58f [Test] Moved test_spec parsing to SIL.
In preparation for moving unit test infrastructure there so that it can
be used anywhere the SIL library is used.
2023-07-04 11:51:36 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Meghana Gupta
6da1df23c8 Merge pull request #66825 from meg-gupta/addressphilast
Sink address projections in ArrayPropertyOpt and enable verification to ensure we have no address phis
2023-06-23 12:27:42 -07:00
Meghana Gupta
03b8c49371 Merge pull request #66645 from meg-gupta/mixinremovesmall
Simplify forwarding instruction definitions in SIL
2023-06-21 13:02:13 -07:00
Meghana Gupta
46bed7c617 Add SinkAddressProjections::newProjections 2023-06-21 12:33:32 -07:00
Meghana Gupta
b08eb62569 Rename SinkAddressProjections::projections -> SinkAddressProjections::oldProjections 2023-06-21 12:24:26 -07:00
Joe Groff
26d8d84270 Merge pull request #66651 from jckarter/noncopyable-address-only-borrowed-capture
ClosureLifetimeFixup: Remove copy of borrowed move-only nonescaping captures when possible.
2023-06-21 09:36:18 -07:00
Joe Groff
ed2cbca04f ClosureLifetimeFixup: Remove copy of borrowed move-only nonescaping captures when possible.
SILGen introduces a copy of the capture, because the semantics of escaping partial_apply's
requires the closure to take ownership of the parameters. We don't know when a closure is
strictly nonescaping or its final lifetime until ClosureLifetimeFixup runs, but that replaces
the consume of the copy with a borrow of the copy normally, hoping later passes fix it up.
We can't wait that long for move-only types, which can't be copied, so try to remove the
copy up front when the copy lives long enough and has no interfering uses other than the
partial_apply. rdar://110137169
2023-06-20 12:10:31 -07:00
Erik Eckstein
7839b54b8a GenericSpecializer: drop metatype arguments in specialized functions
And replace them with explicit `metatype` instruction in the entry block.
This allows such metatype instructions to be deleted if they are dead.

This was already done for performance-annotated functions. But now do this for all functions.

It is essential that performance-annotated functions are specialized in the same way as other functions.
Because otherwise it can happen that the same specialization has different performance characteristics in different modules.
And it's up to the linker to select one of those ODR functions when linking.

Also, dropping metatype arguments is good for performance and code size in general.

This change also contains a few bug fixes for dropping metatype arguments.

rdar://110509780
2023-06-15 21:42:01 +02:00
Meghana Gupta
16c300c2af Remove OwnershipForwardingConversionInst, ConversionInst.
Add new ConversionOperation abstraction, use this in place of ConversionInst
2023-06-15 10:53:28 -07:00
Andrew Trick
280761f0d1 [move-only] Fix SILOptimizer code motion to preserve value deinits
Multiple code motion and ARC related passes were removing struct/enum
deinits.

Passes fixed include:
- SILCombine
- EarlyCodeMotion
- ReleaseHoisting
- *many* passes that rely on ARC analysis (RCIndentity)
2023-06-06 09:17:53 -07:00
Andrew Trick
f7d30d4f8b [move-only] Fix SILOptimizer expansion to preserve deinits.
Many basic SIL passes were silently deleting the struct deinit:
- SROA
- Mem2Reg
- RLE
- DSE
- FunctionSignatureOpts
- LowerAggregates

Fixes rdar://109849028 ([move-only] LowerAggregateInstrs eliminates struct deinitialization)
2023-06-06 09:17:53 -07:00