Commit Graph

6712 Commits

Author SHA1 Message Date
John McCall
74496ea86d Fix SILGen's computation of default argument generator isolation 2025-09-09 14:26:57 -04:00
Doug Gregor
74e85c8416 [SIL] Track the parent module of a SIL global variable through serialization
As with SIL functions, track the parent module where a SIL global
variable was originally defined so that we can determine whether we
are outside of its original module for linkage purposes. Use this to
make sure we emit via a weak definition when emitting to a module
other than the originating module.

Fixes rdar://160153163.
2025-09-08 17:44:49 -07:00
Erik Eckstein
b8a49692eb Optimizer: add TypeSubstitutionCloner and func cloneAndSpecializeFunction
Also move `func cloneFunction` from ContextCommon.swift to OptUtils.swift
2025-09-04 08:15:45 +02:00
Erik Eckstein
c15f76f316 SILCloner: correctly map function argument types in cloneFunction
and remove the now unused `SILBasicBlock::cloneArgumentList`
2025-09-04 08:15:45 +02:00
Erik Eckstein
231042b9a8 SIL: some Cloner cleanups and improvements
* move some Cloner utilities from ContextCommon.swift directly into Cloner.swift
* add an `cloneRecursively` overload which doesn't require the `customGetCloned` closure argument
* some small cleanups
2025-09-04 08:15:45 +02:00
Erik Eckstein
65d69fe965 SIL/AST: add some APIs
* `GenericSignature.isEmpty`
* `Builder.emitDestroy`
* `Function.abi`
* `KeyPathInst.substitutionMap`
* `KeyPathInst.hasPattern`
2025-09-04 08:15:44 +02:00
Erik Eckstein
bc244d1122 SIL: move the FunctionBuilderTy template argument from TypeSubstCloner to remapParentFunction 2025-09-04 08:15:44 +02:00
Janat Baig
f21eb5375e Merge branch 'main' into temp-branch 2025-09-02 20:23:25 -04:00
Jakub Florek
eae7864370 Merge pull request #83988 from MAJKFL/new-sil-licm-pass-copy
New SIL LICM pass
2025-09-01 10:28:17 +01:00
eeckstein
c2cd172860 Merge pull request #83999 from eeckstein/access-enforcement-improvements
Optimizer: some small fixes and improvements for exclusivity checking
2025-08-31 07:22:00 +02:00
Erik Eckstein
3de5d6a13e SIL: add get+set for enforcement in BeginAccessInst 2025-08-30 07:29:15 +02:00
Erik Eckstein
6df033b298 SIL: only use canonical substitution maps in SIL
* When constructing instructions which have substitution maps: initialize those with the canonical SubstitutionMap
* Also initialize SILFunction::ForwardingSubMap with the canonical one

Non-canonical substitution maps may prevent generic specializations.
This fixes a problem in Embedded Swift where an error is given because a function cannot be specialized, although it should.

https://github.com/swiftlang/swift/issues/83895
rdar://159065157
2025-08-29 22:31:04 +02:00
nate-chandler
9fe43836f6 Merge pull request #83907 from nate-chandler/rdar158149082
[AllocBoxToStack] Don't destroy in dead-ends.
2025-08-28 13:36:28 -07:00
Jakub Florek
3514b2b9df Bridge array semantics call and loop tree 2025-08-28 21:00:09 +01:00
Jakub Florek
e3140e0ae0 Add new generalized cloner. 2025-08-28 20:57:57 +01:00
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
Anthony Latsis
f0bfdf63af Merge pull request #83945 from swiftlang/jepa-main2
SIL: Audit some `llvm::APInt` constructions to not hit an assertion with `implicitTrunc` set to false on rebranch
2025-08-28 12:35:25 +01: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
a241cf5e59 [MemoryLifetimeVerifier] Permit leaks in dead-ends 2025-08-27 18:05:07 -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
Anthony Latsis
2bfe2bd587 SIL: Treat -1 as signed when using it to construct an "all bits set" llvm::APInt
This should enable us to revert
73c70ee338.
2025-08-27 15:22:30 +01: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
JanBaig
be6e6e50a7 Use callback to avoid repeated allocation when collecting initialized properties 2025-08-26 14:37:57 -04:00
JanBaig
f4d9c7bb04 Add getDeclContextOrNull to AssignOrInitInst 2025-08-26 14:37:57 -04:00
Slava Pestov
9d30684f62 SIL: Cache SILFunction::getLoweredTypeInContext() 2025-08-25 16:45:45 -04:00
Slava Pestov
6c60f03f9e SIL: Split up Function.loweredFunctionType/InContext 2025-08-25 16:45:45 -04:00
Slava Pestov
11f727e143 SIL: Add no-arg overload of SILFunction::getLoweredFunctionTypeInContext() 2025-08-25 16:45:45 -04:00
Erik Eckstein
bdea6063d7 Mem2Reg: Fix lifetime completion for enum case values.
Enum types may have incomplete lifetimes in address form for trivial case values. When promoted to value form, they will end up with incomplete ossa lifetimes.
Because we know that the incomplete enum values are trivial enum cases we complete their lifetimes with `end_lifetime` instead of `destroy_value`.
This is especially important for Embedded Swift where we are not allowed to insert destroys which were not there before.

Fixes a compiler crash in Embedded Swift caused by de-virtualizing such an inserted destroy and ending up with a non-specialized generic function.

rdar://158807801
2025-08-25 09:35:46 +02:00
Janat Baig
798c0f51a4 Merge branch 'main' into temp-branch 2025-08-23 11:11:04 -04:00
JanBaig
52895fefc3 [SIL] Remove AssignByWrapper references from SIL passes 2025-08-22 23:20:53 -04:00
JanBaig
4c61096be7 [SIL] Remove AssignByWrapper handling from analysis and utils 2025-08-22 23:15:16 -04:00
JanBaig
8469740859 [SIL] Remove AssignByWrapper cloning and builder support 2025-08-22 23:13:30 -04:00
JanBaig
c2850c33c9 [SIL] Remove AssignByWrapper definition and registration 2025-08-22 23:06:59 -04:00
nate-chandler
d1637af144 Merge pull request #83789 from nate-chandler/nfc/20250818/1
[NFC] Renamed three SIL utilities.
2025-08-20 13:25:04 -07:00
Nate Chandler
aa85694237 [NFC] OSSACompleteLifetime: Renamed. 2025-08-18 09:45:19 -07: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
9a20ebac5b [Embedded] Emit weak definitions for imported symbols
When Embedded Swift emits a symbol that was imported from another
module, ensure that the symbol is emitted as a weak definition. This
way, importing the same module (and using its symbol) into several
different modules doesn't cause duplicate-symbol errors at link time.
Rather, the linker will merge the different symbol definitions. This
makes Embedded Swift libraries work without resorting to
`-mergeable-symbols` or `-emit-empty-object-file`.
2025-08-17 15:26:08 -07:00
Doug Gregor
c91a4822d3 Serialize the "markedAsUsed" bit for SILGlobalVariable 2025-08-17 15:25:50 -07:00
Andrew Trick
9d40198c0f SIL: fix miscompiles of non-Copyable struct/enum with deinits
The SIL optimizer has fundamental bugs that result in dropping non-Copyable
struct & enum the deinitializers.

Fix this by

1. correctly representing the ownership of struct & enum values that are
   initialized from trivial values.

2. checking move-only types before deleting forwarding instructions.

These bugs block other bug fixes. They are exposed by other unrelated SIL
optimizations to SIL. I'm sure its possible to expose the bugs with source-level
tests, but the current order of inlining and deinit devirtualization has been
hiding the bugs and complicates reproduction.
2025-08-15 15:03:50 -07:00
JanBaig
3d1123428c [SIL] Refactor to allow Self operand to hold local projections 2025-08-09 16:59:30 -04:00
JanBaig
ff894c4d01 [Format] Apply clang-format to recent changes 2025-08-09 12:46:18 -04:00
JanBaig
2b648eaf43 [SIL] Mark Self operand as optional for AssignOrInitInst 2025-08-08 18:39:43 -04:00
JanBaig
b2fad4bc15 [TypeLowering] Implement the interface type for the SILDeclRef 2025-08-08 18:12:55 -04:00
Nate Chandler
cbe383524c [NFC] OwnershipUtils: Add a UsePoint type.
The type is a union of an Operand (a real use) and a SILInstruction (an
implicit use).  Such a type is needed to reflect the fact that with
incomplete lifetimes, values can be implicitly destroyed at the
terminators of blocks in dead end regions (along the vaule's
availability boundary).
2025-08-08 15:08:20 -07:00
Nate Chandler
99091c93ae [NFC] OwnershipUtils: Factored out function.
For historical reasons, the existing function
(`areUsesWithinExtendedScope`) trafficked in operands rather than
instructions.  Now that PrunedLiveness has an API that deals with
instructions, add a function (`areWithinExtendedScope`) which does as
well.  Factor the existing function through this new function.
2025-08-08 14:59:36 -07:00
Nate Chandler
d49e9ea682 [NFC] PrunedLiveness: Factor out areWithinBoundary
For historical reasons, there was an API to check whether operands were
within the boundary which just checked whether those operands' users
were within the buondary.  Make a copy of the method deal in
instructions and factor the original API through it.
2025-08-08 14:53:01 -07:00
Nate Chandler
540882f23c [NFC] SIL: Promote OperandToUser to SILInstruction
Put it alongsidde OperandToValue and friends.
2025-08-05 16:27:09 -07:00
Erik Eckstein
2ab045235f InitializeStaticGlobals: allow statically initialized globals of non-loadable types 2025-08-03 17:25:43 +02:00
Erik Eckstein
5076fecd44 SIL: add the recursive property isOrContainsRawLayout to SILTypeProperties 2025-08-03 17:25:32 +02:00