Commit Graph

11224 Commits

Author SHA1 Message Date
Saleem Abdulrasool
a4b005bd90 Merge pull request #79230 from compnerd/fallthrough-the-cracks
SILOptimizer: address C5030
2025-02-10 08:45:58 -08:00
eeckstein
c4af3b3a8e Merge pull request #79186 from eeckstein/remove-predictable-memopt
Optimizer: replace PredictableMemoryAccessOptimizations with a "mandatory" redundant load elimination pass
2025-02-08 08:05:33 +01:00
Ellie Shin
a6458c7321 Merge pull request #76968 from swiftlang/elsh/pcmo-remove-workaround
[Package CMO] Replace workaround with assert in makeDeclUsableFromInline
2025-02-07 18:12:12 -08:00
eeckstein
e22c09c055 Merge pull request #79212 from eeckstein/remove-type-expanstion-analysis
Optimizer: Remove the TypeExpansionAnalysis
2025-02-08 00:59:40 +01:00
Arnold Schwaighofer
7a251af60c AccessEnforcement: Fix analysis to include mayReleases as potentially
executing unknown code

This means we have to claw back some performance by recognizing harmless
releases.

Such as releases on types we known don't call a deinit with unknown
side-effects.

rdar://143497196
rdar://143141695
2025-02-07 15:10:13 -08:00
Saleem Abdulrasool
4097255ea5 SILOptimizer: address C5030
i```
swift\lib\SILOptimizer\Mandatory\MoveOnlyAddressCheckerUtils.cpp(2981): warning C5030: attribute [[clang::fallthrough]] is not recognized
```

Replace the use of `clang::fallthrough` with `LLVM_FALLTHROUGH` which
properly uses the C++ standard spelling (`[[fallthrough]]`) depending on
the compiler version.
2025-02-07 15:04:38 -08:00
elsh
415ede4f4a Assert that makeDeclUsableFromInline is not called in Package CMO mode.
Removes a workaround previously added to handle types that were
overlooked during a serializability detection pass. Now that the
pass has been refactored with instruction visitor, we can replace
it with assert.

Resolves rdar://137711038
2025-02-07 12:52:57 -08:00
nate-chandler
23a049c38d Merge pull request #79205 from nate-chandler/nfc/20250206/1
[NFC] OSSACanonicalizeOwned: Simplify Def definition.
2025-02-07 08:14:53 -08:00
Erik Eckstein
319258fea2 Optimizer: Remove the TypeExpansionAnalysis
It was used in the old redundant-load- and redundant-store-elimination passes which were replaced by new implementations.
TypeExpansionAnalysis is not used anymore.
2025-02-07 11:55:27 +01:00
Erik Eckstein
0a011cddd8 Remove the old (and now obsolete) PredictableMemoryAccessOptimizations pass 2025-02-07 11:30:35 +01:00
Erik Eckstein
ba4081ee76 Optimizer: replace PredictableMemoryAccessOptimizations with MandatoryRedundantLoadElimination in the pass pipeline
PredictableMemoryAccessOptimizations has become unmaintainable as-is.
RedundantLoadElimination does (almost) the same thing as PredictableMemoryAccessOptimizations.
It's not as powerful but good enough because PredictableMemoryAccessOptimizations is actually only needed for promoting integer values for mandatory constant propagation.
And most importantly: RedundantLoadElimination does not insert additional copies which was a big problem in PredictableMemoryAccessOptimizations.

Fixes rdar://142814676
2025-02-07 11:30:35 +01:00
Nate Chandler
c6e0480e1c [NFC] OSSACanOwned: Simplify Def definition.
It's sufficient just to have a struct with a kind and a value.  There
aren't any cases where the payload's original type benefits from being
statically preserved--they're only ever obtained as `SILValue`s.  Keep
the type safety by way of constructors.
2025-02-06 17:58:20 -08:00
Michael Gottesman
7e350bb4ce Revert "[concurrency] Add Concurrent/ConcurrentUnsafe and use it instead of ActorIsolation::Nonisolated."
This reverts commit 0cb64638d0.
2025-02-06 14:05:06 -08:00
Michael Gottesman
f05f08c2c0 Revert "[concurrency] Make ActorIsolation::Nonisolated -> CallerIsolationInheriting and delete CallerIsolationInheriting."
This reverts commit 543b1e6ca3.
2025-02-06 14:04:30 -08:00
Michael Gottesman
649952e3d9 Revert "[concurrency] Convert ActorIsolation::isConcurrentUnsafe -> isUnsafe."
This reverts commit 95623c691f.
2025-02-06 14:04:29 -08:00
Andrew Trick
a54a23a1e6 Merge pull request #79177 from atrick/fix-markdep-ownership
Fix mark_dependence [nonescaping] ownership
2025-02-06 01:18:14 -08:00
Anton Korobeynikov
1e7a1d91fc Emit reabstraction thunks for implicit conversions between T.TangentType and Optional<T>.TangentType (#78076) 2025-02-05 20:57:52 -08:00
Andrew Trick
e705a6d7c3 Temporarily introduce AnyInteriorPointer operand ownership.
This is necessary to fix a recent OSSA bug that breaks common occurrences on
mark_dependence [nonescaping]. Rather than reverting that change above, we make
forward progress toward implicit borrows scopes, as was the original intention.

In the near future, all InteriorPointer instructions will create an implicit
borrow scope. This means we have the option of not emitting extraneous
begin/end_borrow instructions around intructions like ref_element_addr,
open_existential, and project_box. After that, we can also migrate
GuaranteedForwarding instructions like tuple_extract and struct_extract.
2025-02-05 16:23:02 -08:00
Ellie Shin
0e1a03a4ae Merge pull request #79140 from swiftlang/elsh/pcmo-implOnly
Package CMO: Prevent serializing types from SDK/system modules imported as @_implementationOnly.
2025-02-05 16:10:57 -08:00
elsh
cb0720b77e Package CMO: Prevent serializing types from SDK/system modules imported as @_implementationOnly.
Currently, types from @_implementationOnly modules can be serialized into client modules if their
defining modules are SDK or system modules.

However, @_implementationOnly is intended to hide types from external clients, and may cause
the type’s metadata (e.g., field offsets) to be stripped. If such types are serialized and later
accessed by a client module, it can lead to linker errors due to the missing metadata.

This PR prevents all types imported with @_implementationOnly from being serialized.

Resolves rdar://144181455
2025-02-05 11:00:37 -08:00
Joe Groff
2cd7a45fe5 Merge pull request #79149 from jckarter/borrow-to-destructure-interior-pointer-order-of-operations
BorrowToDestructureTransform: Fix order of operations when placing borrows around InteriorPointerOperands.
2025-02-05 07:40:30 -08:00
Joe Groff
1e37b67a96 BorrowToDestructureTransform: Fix order of operations when placing borrows around InteriorPointerOperands.
The code here determined the borrow scope of an InteriorPointerOperand use of a borrow using
`visitBaseValueScopeEndingUses`, but it does so after rewriting the operand, so the base
value would sometimes be incorrect leading to missing `end_borrows` in the rewritten code.
Fixes rdar://133333278.
2025-02-04 18:43:40 -08:00
Michael Gottesman
95623c691f [concurrency] Convert ActorIsolation::isConcurrentUnsafe -> isUnsafe.
This ensures it works for both nonisolated(unsafe) and concurrent(unsafe).
2025-02-03 10:56:08 -08:00
Michael Gottesman
543b1e6ca3 [concurrency] Make ActorIsolation::Nonisolated -> CallerIsolationInheriting and delete CallerIsolationInheriting. 2025-02-03 10:56:08 -08:00
Michael Gottesman
0cb64638d0 [concurrency] Add Concurrent/ConcurrentUnsafe and use it instead of ActorIsolation::Nonisolated.
This is just the first part of a larger transition.
2025-02-03 10:56:06 -08:00
Joe Groff
9e586f426a Merge pull request #79084 from jckarter/addressor-projection-lifetime
SILGen: Materialize addressor bases for the formal access scope of the entire access.
2025-02-03 08:25:58 -08:00
Joe Groff
44b431690d SILGen: Materialize addressor bases for the formal access scope of the entire access.
The return pointer may point into the materialized base value, so if the base needs
materialization, ensure that materialization covers any futher projection of the
value.
2025-01-31 18:08:53 -08:00
Meghana Gupta
53553fa172 Fix swift::areUsesWithinValueLifetime for guaranteed values
To find if all the uses are within a guaranteed value, we should find all borrow introducers.

swift::findOwnershipReferenceAggregate looks only through forwarding operations with single operands.

For simplicity, continue using swift::findOwnershipReferenceAggregate, but return false when it does
not find a borrow introducer.
2025-01-31 15:10:57 -08:00
Meghana Gupta
681a6c814a Merge pull request #78939 from meg-gupta/ossamoduleson
Enable serialization in OSSA
2025-01-30 23:25:19 -08:00
Anthony Latsis
34f9b80cbc Merge pull request #78750 from AnthonyLatsis/oryza-sativa
[Gardening] Fix some set but not used variables
2025-01-31 04:29:05 +00:00
Meghana Gupta
6f9167c29e Serialize after high level passes for -emit-sib 2025-01-30 17:10:04 -08:00
Michael Gottesman
8c19cd7de6 Merge pull request #79028 from gottesmm/more-closure-fixes
[rbi] Small tweaks to the closure patch #78837
2025-01-30 14:06:17 -08:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Ellie Shin
2de333c9e0 Merge pull request #79035 from swiftlang/elsh/pcmo-imports
Package CMO: Enable serializing decls imported with `@_spiOnly` or `package import`.
2025-01-30 13:15:33 -08:00
Erik Eckstein
5fb41a9c55 LowerHopToActor: insert borrow scope if an optional actor value is owned
The inserted switch_enum must not consume the actor value, therefore a borrow scope is needed.
Fixes an ownership error.
2025-01-30 15:09:51 +01:00
elsh
67594f1d8b Package CMO: Enable serializing decls imported with @_spiOnly or package import.
Starting in Swift 6.0, `package` access level and `@_spiOnly` attribute have been increasingly used in import statements.
However, existing import filtering prevented serialization of package APIs that included such decls, leading to a
significant drop in overall serialization. This PR removes these restrictive filters, and allows decls from SDK or system
modules to be included in serialization.

rdar://130788606
2025-01-29 23:22:17 -08:00
Michael Gottesman
8c96a8db1b [rbi] When finding closure uses in an immediately invoked closure, distinguish in between captures and parameters.
Otherwise, when one diagnoses code like the following:

```
Task {
  {
    use($0)
  }(x)
}
```

One gets that $0 was captured instead of x. Unfortunately, since function
parameters do not have locations associated with them, we do not mark x
itself... instead, we mark the closure... which is unfortunate.
2025-01-29 15:07:47 -08:00
Michael Gottesman
39e63b488f [sil] Make sure that we do not flag ignored_use as dead code when used after a try_apply or begin_apply. 2025-01-29 15:05:29 -08:00
Meghana Gupta
6a47193e0c Fix LICM for begin_access/end_access in OSSA
LICM in OSSA is enabled only for instructions involving trvial values.

begin_access/end_access is eligible for LICM in OSSA. However we need to
collect applies to check for conflicts.

rdar://143835241
2025-01-29 12:54:35 -08:00
Meghana Gupta
4fb0399dac Merge pull request #78982 from meg-gupta/fixmdi2
Fix AddressOwnership for unidentified access
2025-01-29 07:00:56 -08:00
Kuba (Brecka) Mracek
7c685ba36b Merge pull request #78915 from kubamracek/embedded-string-switch-with-cache
[embedded] Support _findStringSwitchCaseWithCache in Embedded Swift
2025-01-28 15:56:22 -08:00
eeckstein
5d23a4d1cb Merge pull request #78972 from eeckstein/fix-cmo
embedded: make sure to serialize vtable methods with the right linkage
2025-01-28 21:08:25 +01:00
Kuba Mracek
500f8ad893 [embedded] Only treat findStringSwitchCaseWithCache as anchor in early DFE, let late DFE collect it if unused 2025-01-28 10:07:54 -08:00
Kuba Mracek
e1d22b5076 [embedded] Avoid changing lookupStdlibFunction, load findStringSwitchCaseWithCache in MPO instead 2025-01-28 10:03:14 -08:00
Meghana Gupta
27fc324c8c Fix AddressOwnership for unidentified access
AccessBase can have Unindentified kind where the base value maybe
invalid.

Bailout early for such accesses in ownership rauw.
2025-01-28 09:08:38 -08:00
Erik Eckstein
3e4a4d62ed embedded: make sure to serialize vtable methods with the right linkage
In embedded mode CrossModuleOptimization must visit all vtable methods to make sure that no private/internal methods are serialized.

Fixes a compiler crash
rdar://143153941
2025-01-28 11:19:35 +01:00
Erik Eckstein
631bee446a BasicCalleeAnalysis: don't crash if the bca argument to isDeinitBarrier is null
Some clients don't provide a callee analysis to this API.
Don't crash in this case.
2025-01-28 09:15:47 +01:00
nate-chandler
8c63134570 Merge pull request #78682 from nate-chandler/rdar142636711_2
[TempRValueOpt] Invalidate insts when completing.
2025-01-27 12:53:57 -08:00
eeckstein
95f1dfbf07 Merge pull request #78885 from eeckstein/fix-without-actually-escaping
Fix two problems with `withoutActuallyEscaping`
2025-01-27 07:59:02 +01:00
Andrew Trick
f0144ab7b1 Merge pull request #78830 from atrick/fix-lifedep-trivial-deadend
SILGenCleanup: extend to handle trivial local var scopes
2025-01-25 15:34:35 -08:00