Commit Graph

1575 Commits

Author SHA1 Message Date
eeckstein
8cea77eac0 Merge pull request #83913 from eeckstein/fix-deinit-devirtualization-for-arrays
Optimizer: de-virtualize deinits of `builtin "destroyArray"`
2025-08-28 18:21:07 +02:00
Erik Eckstein
e5081a511f AliasAnalysis: fix aliasing of ref_tail_addr access bases
In contrast to `ref_element_addr`, tail addresses can also be obtained via a superclass (in case the derived class doesn't add any stored properties).
Therefore if the instance types differ by sub-superclass relationship, they may alias.

Fixes a miscompile
2025-08-28 08:09:39 +02:00
Erik Eckstein
8e33487471 DeinitDevirtualizer: de-virtualize deinits of builtin "destroyArray" 2025-08-28 08:05:28 +02:00
Erik Eckstein
49d3960c68 MandatoryPerformanceOptimization: de-virtualize deinits of builtin "destroyArray"
This is required for embedded swift.
rdar://157131184
2025-08-28 08:05:27 +02:00
Erik Eckstein
3da2c1476b SIL: add Builder.createCondBranch 2025-08-28 08:04:50 +02:00
Erik Eckstein
ab10dc23a5 SIL: add Context.getTupleType 2025-08-28 08:04:49 +02:00
Nate Chandler
1eafced6a2 [AllocBoxToStack] Don't destroy in dead-ends.
It is valid to leak a value on paths into dead-end regions.
Specifically, it is valid to leak an `alloc_box`.  Thus, "final
releases" in dead-end regions may not destroy the box and consequently
may not release its contents.  Therefore it's invalid to lower such final
releases to `dealloc_stack`s, let alone `destroy_addr`s.  The in-general
invalidity of that transformation results in miscompiling whenever a box
is leaked and its projected address is used after such final releases.

Fix this by not treating final releases as boundary markers of the
`alloc_box` and not lowering them to `destroy_addr`s and
`dealloc_stack`s.

rdar://158149082
2025-08-27 17:03:48 -07:00
Nate Chandler
74528eef8c [NFC] OptUtils: Promote isInLoop to internal.
It will be used by both AllocBoxToStack in addition to StackPromotion
and for the same reason.
2025-08-27 17:03:47 -07:00
Nate Chandler
f94168c875 [AllocBoxToStack] Restore isDeadEnd check.
The rewrite was missing the intentional omission of `dealloc_stack`s
corresponding to `[dead_end]` `dealloc_box`es.  Add the necessary
bridging to get to parity with the original.

Without this check, `dealloc_box [dead_end]`s are promoted to
`dealloc_stack`s but the memory projected out of such `alloc_box`s need
not be valid.

rdar://159271158
2025-08-27 17:02:27 -07:00
Slava Pestov
66dc1cc2e8 Merge pull request #83902 from slavapestov/lowered-type-in-context
Cache SILFunction::getLoweredTypeInContext()
2025-08-27 08:19:13 -04:00
Aidan Hall
53028abea9 Merge pull request #83665 from aidan-hall/fix-effects
ComputeSideEffects: compute properties even if function has an effect attribute
2025-08-27 10:34:53 +01:00
Daniil Kovalev
ae2b46e263 [AutoDiff][gardening] Auto-format ClosureSpecialization.swift (#83925)
Auto-formatting is done as a prerequisite for the ongoing series of
patches resolving #68944.
2025-08-27 06:12:47 +00:00
Erik Eckstein
56521f0c3d Optimizer: fix handling of dependent existential archetypes in alloc_stack and apply simplification
When replacing an opened existential type with the concrete type, we didn't consider that the existential archetype can also be a "dependent" type of the root archetype.
For now, just bail in this case. In future we can support dependent archetypes as well.

Fixes a compiler crash.
rdar://158594365
2025-08-26 18:01:10 +02:00
Erik Eckstein
0a8c60290f AST: add Type.interfaceTypeOfArchetype and some related APIs 2025-08-26 16:38:19 +02:00
Slava Pestov
6c60f03f9e SIL: Split up Function.loweredFunctionType/InContext 2025-08-25 16:45:45 -04:00
Janat Baig
798c0f51a4 Merge branch 'main' into temp-branch 2025-08-23 11:11:04 -04:00
JanBaig
4c61096be7 [SIL] Remove AssignByWrapper handling from analysis and utils 2025-08-22 23:15:16 -04:00
JanBaig
c2850c33c9 [SIL] Remove AssignByWrapper definition and registration 2025-08-22 23:06:59 -04:00
Aidan Hall
6a263f8ddb ComputeSideEffects: Compute for functions with effect attributes
After computing side effects, we also remove any global or argument effects that
are computed to happen, but are defined not to, based on the effect attribute.

This allows us to compute the deinit_barrier effect for such functions, fixing
the test case here: rdar://155870190

This supercedes #38324.
2025-08-22 11:42:09 +01:00
Doug Gregor
7a196ac3ba Merge pull request #83739 from DougGregor/embedded-weak-definitions-of-imports
[Embedded] Emit weak definitions for imported symbols
2025-08-17 20:25:02 -07:00
Doug Gregor
c91a4822d3 Serialize the "markedAsUsed" bit for SILGlobalVariable 2025-08-17 15:25:50 -07:00
Andrew Trick
288cef1532 LifetimeDependenceScopeFixup: extend store_borrow allocations
Extend temporary allocations (sink dealloc_stacks) initialized by a store_borrow
across lifetime dependent uses.

Fixes rdar://143159873 ([nonescapable] extend rvalue lifetimes when they are the source of a dependency)
2025-08-14 10:13:55 -07:00
Andrew Trick
b3e169be5e [NFC] Rename a variable for clarity. 2025-08-14 09:08:11 -07:00
Andrew Trick
eb1d5f484c [NFC] SwiftCompilerSources: add a correctly named filterUsers API
Rename existing filterUsers to filterUses.
2025-08-14 09:08:11 -07:00
Erik Eckstein
3a7ed92753 MandatoryPerformanceOptimizations: fix adding witness methods to the function worklist
We were missing adding witness methods of not-specialized witness tables.
This resulted in functions not being processed which led to crashes in IRGen.

rdar://158224693
2025-08-14 11:00:30 +02:00
Erik Eckstein
eaf38da903 InitializeStaticGlobals: support non-loadable enums
TODO: we don't support non-loadable enum cases with payload, yet, because IRGen support is missing.
2025-08-03 17:25:43 +02:00
Erik Eckstein
c849c7cdae InitializeStaticGlobals: support initializing globals with @_rawLayout types, like Atomic
Look through `@_rawLayout` projections, which "type casts" a raw-layout struct to it's content, which must match the like-type of the raw-layout, e.g.

```
@_rawLayout(like: T)
struct S {}

  %2 = builtin "addressOfRawLayout"<S>(%1 : $*S) : $Builtin.RawPointer
  %3 = pointer_to_address %2 to $*T
```
2025-08-03 17:25:43 +02:00
Erik Eckstein
201bb44d2f IRGen: allow all kind of Builtin.zeroInitializer in statically initialized globals
Just use the same method to create the zero initializer constant as in `emitBuiltinCall`.
2025-08-03 17:25:42 +02:00
Erik Eckstein
0a953b60ca SIL/AST: add var InjectEnumAddrInst.element and var EnumElementDecl.hasAssociatedValues 2025-08-03 11:06:15 +02:00
Erik Eckstein
eeb7946d55 SIL: add rawLayoutSubstitutedLikeType and rawLayoutSubstitutedCountType in Type 2025-08-03 11:06:14 +02:00
Erik Eckstein
8ac25d915b embedded: don't try to specialize witness tables for abstract conformances
If the conformance is abstract the witness table is specialized elsewhere - at the place where the concrete conformance is referenced.
Fixes a compiler crash.
2025-07-29 09:45:52 +02:00
Erik Eckstein
3bbba99647 SwiftCompilerSources: split the Optimizer/Context.swift file 2025-07-28 14:19:11 +02:00
Erik Eckstein
b38490b2e2 SwiftCompilerSources: move PhiUpdater.swift from the Optimizer to the SIL module 2025-07-28 14:19:11 +02:00
Erik Eckstein
41a6b8e257 SwiftCompilerSources: move SIL-related Context APIs from Optimizer to the SIL module 2025-07-28 14:19:11 +02:00
Erik Eckstein
319f49ad9f SwiftCompilerSources: move the Verifier to the SIL module 2025-07-28 14:19:11 +02:00
Erik Eckstein
1eb49ec186 SwiftCompilerSources: move ForwardingUtils and BorrowUtils to the SIL module 2025-07-28 14:19:11 +02:00
Erik Eckstein
a767261fec SwiftCompilerSources: move the getAccessBaseTest to the SIL module 2025-07-28 14:19:10 +02:00
Erik Eckstein
e95283ba38 SwiftCompilerSources: make the testing infrastructure available in the SIL module
add `Test`, which is the SIL-equivalent of `FunctionTest`.
It's invocation closure gets a `TestContext` instead of a `FunctionContext`.

^ The commit message #2 will be skipped:

^ - test
2025-07-28 14:19:10 +02:00
Erik Eckstein
e89fdb56ba SwiftCompilerSources: move SIL-related datastructures from the Optimizer to the SIL module 2025-07-28 14:19:07 +02:00
Erik Eckstein
e2129b50ce SwiftCompilerSources: move the SSAUpdater utility from the Optimizer to the SIL module 2025-07-28 14:19:07 +02:00
Erik Eckstein
65c9828cb3 SwiftCompilerSources: move the Context protocols from the Optimizer to the SIL module
This allows to move many SIL APIs and utilities, which require a context, to the SIL module.

The SIL-part of SwiftPassInvocation is extracted into a base class SILContext which now lives in SIL.

Also: simplify the begin/end-pass functions of the SwiftPassInvocation.
2025-07-28 14:19:07 +02:00
Erik Eckstein
5064297400 InstructionSimplification: simplify negated integer comparsions
Replaces a builtin "xor", which negates its operand comparison
```
  %3 = builtin "cmp_slt_Int64"(%1, %2) : $Builtin.Int1
  %4 = integer_literal $Builtin.Int1, -1
  %5 = builtin "xor_Int1"(%3, %4) : $Builtin.Int1
```
with the negated comparison
```
  %5 = builtin "cmp_ge_Int64"(%1, %2) : $Builtin.Int1
```

This makes LLVM's IPSCCP happy.

rdar://154950810
2025-07-18 07:43:51 +02:00
Erik Eckstein
12d9311b15 SILCombine: run builtin simplification as part of SILCombine
That means: make `BuiltinInst` conform to `SILCombineSimplifiable`, but still also run the legacy builtin simplification in SILCombine
2025-07-18 07:43:51 +02:00
Anthony Latsis
90f9fce339 Merge pull request #82665 from swiftlang/jepa4
Bridging: Bridge some basic classes like `swift::SourceLoc` directly
2025-07-16 08:27:12 +01:00
Anthony Latsis
6eb5d7d857 Bridging: Bridge swift::SourceLoc directly 2025-07-15 21:33:06 +01:00
Meghana Gupta
84418d290f Merge pull request #83037 from meg-gupta/fixfso2
Bailout SwiftCompilerSource's function signature opts for functions with lifetime dependencies
2025-07-15 11:56:33 -07:00
Meghana Gupta
a4ad806319 Merge pull request #82890 from meg-gupta/simplifyendcowaddr
Add simplification for end_cow_mutation_addr
2025-07-15 07:37:13 -07:00
Meghana Gupta
455990aa27 Bailout SwiftCompilerSource's function signature opts for functions with lifetime dependencies 2025-07-15 03:25:18 -07:00
Meghana Gupta
e317a603fc Add simplification for end_cow_mutation_addr
We insert end_cow_mutation_addr for lifetime dependent values dependent on mutable addresses.
end_cow_mutation_addr can be simplified to end_cow_mutation after other optimizations like inlining, specialization etc

This PR adds an instruction simplification to transform end_cow_mutation_addr to end_cow_mutation.
This can enable array optimizations which look for end_cow_mutation.
2025-07-14 13:46:13 -07:00
nate-chandler
d6b5c4fb99 Merge pull request #82798 from eeckstein/fix-let-property-lowering
LetPropertyLowering: remove redundant phis after ssa-update
2025-07-08 18:07:08 -07:00