Commit Graph

9293 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
2ec717b115 [Concurrency] TaskExecutor ownership fixes (#74000) 2024-06-14 22:56:33 +09:00
Erik Eckstein
532535faad SIL: enable some SIL linkage related asserts in release builds
To catch wrong linkage bugs with a release-built compiler

related to rdar://129318806
2024-06-14 11:55:14 +02:00
Ellie Shin
0a734c2a62 [PackageCMO] Global var and accessor linkage should be kept private/hidden in SILGen.
This PR contains changes that ensure the following:
* Global accessor linkage is kept hidden if its decl is resilient.
  - LinkageLimit::Never is returned for Global Accessor if its decl is resilient.
  - Since it's kept hidden, the use site should not expect a call to a global accessor
    if the static var decl being accessed is resilient. The bypassing resilience logic
    in AbstractStorageDecl::isResilient(accessingModule, decl) has been removed; to be
    addressed in Package CMO optimization pass.
* sil_global linkage is kept private if its decl is resilient.

Resolves rdar://129829925
2024-06-14 01:34:34 -07:00
nate-chandler
3aca85bfb3 Merge pull request #74298 from nate-chandler/rdar129593468
[NoncopyableWrapperElim] Process undef values.
2024-06-12 06:55:48 -07:00
Nate Chandler
f39b70a86d [NFC] SIL: Extracted remove "any" m-o wrapping. 2024-06-11 16:25:29 -07:00
Nate Chandler
b5b637c72e [NFC] SIL: Renamed helper.
removing...To -> removing...From
2024-06-11 16:25:11 -07:00
eeckstein
8dec8f6058 Merge pull request #74259 from eeckstein/fix-fixed-abi-runtime-effects
PerformanceDiagnostics: avoid false meta-data alarms for non-loadable types
2024-06-11 07:26:34 +02:00
nate-chandler
0351ecd6fb Merge pull request #74196 from nate-chandler/lifetime-completion/20240606/1
[LifetimeCompletion] Removed "with leaks" mode.
2024-06-10 11:32:44 -07:00
nate-chandler
a2b2087a5e Merge pull request #74198 from nate-chandler/rdar128900124
[MoveOnly] Call mutating methods on existentials.
2024-06-10 11:29:45 -07:00
Erik Eckstein
717880e844 PerformanceDiagnostics: avoid false meta-data alarms for non-loadable types
Non-loadable types don't necessarily need metadata, for example, structs with `@_rawLayout`

https://github.com/apple/swift/issues/73951
2024-06-10 18:25:08 +02:00
Doug Gregor
25830d6bc3 Merge pull request #74225 from DougGregor/flow-sensitive-actor-init-isolation
Teach `#isolation` to respect the flow-sensitive nature of actor initializers
2024-06-10 01:52:38 -07:00
Doug Gregor
d1ae73f436 Handle flow-sensitive #isolation in distributed actor initializers.
Distributed actors can be treated as actors by accessing the `asLocalActor`
property. When lowering `#isolation` in a distributed actor initializer,
use a separate builtin `flowSensitiveDistributedSelfIsolation` to
capture the conformance to `DistributedActor`, and have Definite
Initialization introduce the call to the `asLocalActor` getter when
needed.
2024-06-09 22:48:43 -07:00
Doug Gregor
956243cd7e Teach #isolation to respect the flow-sensitive nature of actor initializers
Actor initializers have a flow-sensitive property where they are isolated
to the actor being initialized only after the actor instance itself is
fully-initialized. However, this behavior was not being reflected in
the expansion of `#isolation`, which was always expanding to `self`,
even before `self` is fully formed.

This led to a source compatibility issue with code that used the async
for..in loop within an actor initializer *prior* to the point where the
actor was fully initialized, because the type checker is introducing
the `#isolation` (SE-0421) but Definite Initialization properly rejects
the use of `self` before it is initialized.

Address this issue by delaying the expansion of `#isolation` until
after the actor is fully initialized. In SILGen, we introduce a new
builtin for this case (and *just* this case) called
`flowSensitiveSelfIsolation`, which takes in `self` as its argument
and produces an `(any Actor)?`. Definite initialization does not treat
this as a use of `self`. Rather, it tracks these builtins and
replaces them either with `self` (if it is fully-initialized at this
point) or `nil` (if it is not fully-initialized at this point),
mirroring the flow-sensitive isolation semantics described in SE-0327.

Fixes rdar://127080037.
2024-06-07 14:54:20 -07:00
Nate Chandler
e2fcdb4524 [MoveOnlyAddressChecker] Handle init_exi_addr.
It's a pass-through for FSPL's purposes.

rdar://128900124
2024-06-06 19:04:41 -07:00
Nate Chandler
5dc3cf1296 [LifetimeCompletion] Removed "with leaks" mode.
Now that the two known issues which resulted in invalid SIL being
provided to lifetime completion have been addressed, tighten up the
completion done on the availability boundary not to allow leaks.
2024-06-06 16:48:46 -07:00
Meghana Gupta
af1d6017f9 Merge pull request #74132 from meg-gupta/deleteresultdependson
Remove resultDependsOn/resultDependsOnSelf
2024-06-06 10:23:31 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Nate Chandler
84da0ed4c5 [LifetimeCompletion] Add extend_lifetimes.
The new instructions are inserted after every "user" (according to
InteriorLiveness' SSAPrunedLiveness instance) outside the linear
liveness boundary.
2024-06-05 16:28:28 -07:00
Nate Chandler
087bf6a75b [LifetimeCompletion] NFC: Add helper.
It visits users discovered by an SSAPrunedLiveness instance (such as
that used by InteriorLiveness) which are outside the LinearLifetime
boundary.
2024-06-05 16:28:28 -07:00
Nate Chandler
65397fafb3 [NFC] LifetimeCompletion: Tweaked helper class.
VisitAvailabilityBoundary now has a single public method.
2024-06-05 16:28:28 -07:00
Nate Chandler
a52cc7ae19 [NFC] LifetimeCompletion: Note boundary kind.
When visiting an availability boundary, note what kind of end is
involved.  For now, there's only one.
2024-06-05 16:28:28 -07:00
Nate Chandler
b2d7247cdf [SIL] Verify extend_lifetime instruction. 2024-06-05 16:28:28 -07:00
Nate Chandler
81fa65772f [OwnershipLiveness] End at extend_lifetime.
When visiting consumes, also visit `extend_lifetime` instructions.
These instructions are not lifetime ending, but together with the
consumes, they enclose the users of a value.

Add a flag to LinearLiveness to control whether these instructions are
added so that the verifier can use verify that all such instructions
appear outside the linear lifetime boundary (not including them).
2024-06-05 16:28:28 -07:00
Nate Chandler
2a5d07522d [SIL] Add extend_lifetime instruction.
It indicates that the value's lifetime continues to at least this point.
The boundary formed by all consuming uses together with these
instructions will encompass all uses of the value.
2024-06-05 16:28:26 -07:00
Nate Chandler
77d26e1eff [NFC] LifetimeCompletion: Rename helper fn.
It visits the availability boundary, so call it
`visitAvailabilityBoundary`.  It's not clear what "unreachable lifetime
ends" are.
2024-06-05 16:27:45 -07:00
Nate Chandler
9d7db52bed [NFC] PrunedLiveness: Tweaked enum wrapper.
Clarify methods.  Unfortunately, without other changes I haven't
identified, the `enum class` can't be made an `enum` for ideal usage.
2024-06-05 16:27:45 -07:00
Meghana Gupta
470fa2f365 Remove resultDependsOn/resultDependsOnSelf 2024-06-05 11:36:16 -07:00
Ellie Shin
c70c52175b Merge pull request #74070 from apple/elsh/pcmo-fixes
[SIL][PackageCMO] Fix dispatch thunk linker error and update table serialization
2024-06-04 18:30:25 -07:00
nate-chandler
365f811330 Merge pull request #74072 from nate-chandler/rdar64375208
[TypeLowering] Return pseudogeneric @autoreleasing
2024-06-04 16:53:48 -07:00
Ellie Shin
af9e5e6378 Merge branch 'main' into elsh/pcmo-fixes 2024-06-04 11:41:35 -07:00
Ellie Shin
6216ec648f Merge pull request #73902 from apple/elsh/pkg-cmo-inline
[SIL][PackageCMO] Allow optimizing [serialized_for_pkg] functions
2024-06-04 11:39:19 -07:00
Hamish Knight
6698ef4708 Merge pull request #74067 from hamishknight/macroscope
[Coverage] Avoid recording regions from macro expansions
2024-06-04 18:58:09 +01:00
Ellie Shin
5a0c73c45f Add isPackageCMOEnabled check for MethodInst and KeyPathInst.
Update lambda in table serialization.
Add more tests.
2024-06-03 23:39:04 -07:00
Hamish Knight
6c930f7aaa [Coverage] Also walk MacroExpansionDecls
Make sure we walk macro expansion decls to handle
cases where e.g a binding introduces control flow.
This should be a pretty uncommon case since bindings
introduced by macros aren't actually usable when
expanded in local contexts, but handle it all the
same.
2024-06-03 12:14:56 +01:00
Hamish Knight
95cbced7a0 [Coverage] Avoid profiling functions with body macros
These replace the body of the function, and as such
shouldn't be profiled.
2024-06-03 12:14:56 +01:00
Hamish Knight
98f0200f64 [Coverage] Avoid recording regions from macro expansions
Ignore any regions recorded while inside a macro
expansion, but account for any control flow that
may have happened such that the exit count is
correctly adjusted. This allows e.g throwing function
calls to behave correctly within the expansion.

rdar://129081384
2024-06-03 12:14:56 +01:00
Hamish Knight
f2a0b46d3e [Coverage] NFC: Set the SourceFile on CoverageMapping
Saves having to pass it as a parameter to
`emitSourceRegions`.
2024-06-03 12:14:56 +01:00
Michael Gottesman
88729b9e34 [sending] Make {Transferring,Sending}ArgsAndResults a LANGUAGE_FEATURE instead of an UPCOMING_FEATURE.
TLDR: This makes it so that we always can parse sending/transferring but changes
the semantic language effects to be keyed on RegionBasedIsolation instead.

----

The key thing that makes this all work is that I changed all of the "special"
semantic changes originally triggered on *ArgsAndResults to now be triggered
based on RegionBasedIsolation being enabled. This makes a lot of sense since we
want these semantic changes specifically to be combined with the checkers that
RegionBasedIsolation turns on. As a result, even though this causes these two
features to always be enabled, we just parse it but we do not use it for
anything semantically.

rdar://128961672
2024-06-01 23:25:16 -07:00
Michael Gottesman
c7124e431a [sending] Fix recent alloc_stack as indirect result isolation inference to infer disconnected if the alloc stack is used as a sending indirect result.
I also fixed an issue that I found where we were not substituting SILResultInfo
flags which was causing us to drop when substituting sil_sending. I added a
SILVerifier check to make sure that we do not break this again.
2024-06-01 23:25:16 -07:00
Andrew Trick
e06fc99667 Fix SILCombine to delete dead end_access instructions.
Otherwise, the SILVerifier will raise an error.

Fixes rdar://121599876 (SILCombine should delete instructions in
blocks dominated by cond_fail -1)
2024-05-31 23:01:34 -07:00
Nate Chandler
2d03664e45 [TypeLowering] Return pseudogeneric @autoreleasing
Previously, when a pseudogeneric function returned a type parameter, it
was unowned.  That resulted in invalid OSSA out of SILGen.  Here, this
is fixed to use the @autoreleasing convention.

rdar://64375208
2024-05-31 18:42:25 -07:00
Ellie Shin
fd07578b29 Package CMO fixes.
* Do not use [serialized_for_package] for witness method before Package CMO.
* Update v-table and witness-table and their entry serialization.
  -- Allow non-serialized but visible entries in a serialized table so they
    can be optimized by other SIL opt passes.
* Only serialize MethodInst if it has the right visibility.

Resolves rdar://129089105&129088935
2024-05-31 17:05:00 -07:00
Slava Pestov
ea1c3cd4ed SIL: Update lowerCaptureContextParameters() for PackElementExpr captures 2024-05-30 16:39:49 -04:00
Slava Pestov
fc25690723 SIL: Update getLoweredLocalCaptures() for PackElementExpr captures 2024-05-30 16:39:49 -04:00
Slava Pestov
52e908363f Sema: Collect PackElementExpr captures in CaptureInfoRequest 2024-05-30 16:39:49 -04:00
Holly Borla
135e3f2ee9 Merge pull request #73889 from hborla/deprecate-anyactor
[Concurrency] Deprecate `AnyActor`.
2024-05-30 09:36:35 -07:00
Holly Borla
c20b0e0956 [Concurrency] Obsolete AnyActor in Swift 6 using a typealias. 2024-05-29 22:59:19 -07:00
Ellie Shin
4ecfc96578 [SIL][PackageCMO] Allow optimizing [serialized_for_pkg] functions during SIL
inlining, generic/closure specialization, and devirtualization optimization passes.

SILFunction::canBeInlinedIntoCaller now exlicitly requires a caller's SerializedKind_t arg.
isAnySerialized() is added as a convenience function that checks if [serialized] or [serialized_for_pkg].

Resolves rdar://128704752
2024-05-27 23:05:56 -07:00
nate-chandler
5b027139d5 Merge pull request #73857 from nate-chandler/rdar125864434
[MoveOnly] Call borrowing methods on existentials.
2024-05-24 12:14:52 -07:00
Ellie Shin
5ccc4cd394 SIL function can be serialized with different kinds: [serialized] or
[serialized_for_package] if Package CMO is enabled. The latter kind
allows a function to be serialized even if it contains loadable types,
if Package CMO is enabled. Renamed IsSerialized_t as SerializedKind_t.

The tri-state serialization kind requires validating inlinability
depending on the serialization kinds of callee vs caller; e.g. if the
callee is [serialized_for_package], the caller must be _not_ [serialized].
Renamed `hasValidLinkageForFragileInline` as `canBeInlinedIntoCaller`
that takes in its caller's SerializedKind as an argument. Another argument
`assumeFragileCaller` is also added to ensure that the calle sites of
this function know the caller is serialized unless it's called for SIL
inlining optimization passes.

The [serialized_for_package] attribute is allowed for SIL function, global var,
v-table, and witness-table.

Resolves rdar://128406520
2024-05-23 15:53:02 -07:00