Commit Graph

9435 Commits

Author SHA1 Message Date
Slava Pestov
f932ef4db9 SIL: Fix bug in AbstractionPattern::getFunctionThrownErrorType()
When storing a closure with type `() throws(any Error) -> ()` as
a fully opaque error, we want to leave it unchanged, instead of
re-abstracting it to throw the error indirectly. Thus, we had
a special carveout here.

However, the carveout was too broad, because if the thrown error
type contained type parameters, the resulting AbstractionPattern
was invalid.

While fixing this I realized this entire hack is unsound in some
cases, if you view the same value as a `() throws(U) -> ()` vs
an `() -> throws(any Error) -> ()`.

Perhaps we should always box the thrown error when maximally
abstracting a closure, but that would also be an ABI break.

- Fixes https://github.com/swiftlang/swift/issues/84051
2025-10-10 17:46:22 +01:00
John McCall
e5b6a88c5e Merge pull request #84181 from rjmccall/isolation-fixes
Isolation fixes for closures and defer bodies
2025-09-10 08:39:09 -04:00
nate-chandler
b740a457c3 Merge pull request #84185 from nate-chandler/rdar159211502
[SILVerifier] Ease this over-strict verification.
2025-09-09 23:47:35 -07:00
Nate Chandler
9bbfb2106b [SILVerifier] Ease this over-strict verification.
It's permitted for a `witness_method` instruction to have multiple
type-dependent operands.  This can happen when for example when one
local archetype is defined in terms of another.

rdar://159211502
2025-09-09 15:44:08 -07:00
John McCall
5fb314b475 At the SIL level, allow synchronous functions to be nonisolated(nonsending). 2025-09-09 14:26:57 -04:00
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
John McCall
92352b817d Merge pull request #84130 from rjmccall/nominal-type-visitor
[NFC] Introduce a convenience specialization of CanTypeVisitor
2025-09-06 13:59:33 -04:00
Doug Gregor
ab15602af5 Merge pull request #84110 from DougGregor/lazy-irgen-global-variables
[IRGen] Lazily emit SIL global variables
2025-09-05 13:36:42 -07:00
John McCall
64d020ec45 [NFC] Introduce a convenience specialization of CanTypeVisitor that
forwards the paired nominal type methods to common implementations.
2025-09-05 14:02:36 -04:00
Doug Gregor
4009814783 [IRGen] Lazily emit SIL global variables
Delay the emission of SIL global variables that aren't externally
visible until they are actually used. This is the same lazy emission
approach that we use for a number of other entities, such as SIL
functions.

Part of rdar://158363967.
2025-09-04 13:03:15 -07:00
Arnold Schwaighofer
6da200f047 Merge pull request #84009 from aschwaighofer/assembly_vision_all_the_things
Add a flag to annotate all functions with the `optremark` (`@_assemblyVision`) attribute
2025-09-04 08:57:44 -07:00
Doug Gregor
ba2af97a91 Merge pull request #84095 from DougGregor/embedded-deferred-codegen 2025-09-04 06:05:39 -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
Doug Gregor
bee2369212 [Embedded] Treat the entrypoint function as having a unique definition
This ensures that one can use deferred code generation everywhere with
Embedded Swift and still get the appropriate entry symbol emitted.
2025-09-03 16:29:23 -07:00
Doug Gregor
ed93b46fa6 [Embedded] Introduce DeferredCodeGen feature.
Introduce an experimental feature DeferredCodeGen, that defers the
generation of LLVM IR (and therefore object code) for all entities
within an Embedded Swift module unless they have explicitly requested
to not be emitted into the client (e.g., with
`@_neverEmitIntoClient`).

This feature is meant to generalize and subsume
-emit-empty-object-file, relying on lazy emission of entities rather
than abruptly ending the compilation pipeline before emitting any IR.

Part of rdar://158363967.
2025-09-03 15:55:47 -07: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
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
Arnold Schwaighofer
df5a8cd3cc Add a flag to annotate all functions with the optremark (@_assemblyVision) attribute
rdar://159291169
2025-08-29 09:26:13 -07:00
Kavon Farvardin
bb8b1e1b42 Merge pull request #83984 from kavon/avoid-not-noncopyable
nfc: avoid !isNoncopyable()
2025-08-28 17:46:39 -07: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
e3140e0ae0 Add new generalized cloner. 2025-08-28 20:57:57 +01:00
Kavon Farvardin
3bb8fa848a nfc: !isNoncopyable() -> isCopyable() 2025-08-28 12:13:21 -07:00
Slava Pestov
a5a8cf4a36 Merge pull request #83858 from slavapestov/covariant-result-type-part-2
AST: Continue process of removing replaceCovariantResultType()
2025-08-28 10:07:13 -04: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
Nate Chandler
a241cf5e59 [MemoryLifetimeVerifier] Permit leaks in dead-ends 2025-08-27 18:05:07 -07:00
Slava Pestov
1716832a7a AST: Remove most usages of AbstractFunctionDecl::hasDynamicSelfResult() 2025-08-27 15:34:26 -04: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
a1f0b8b98d Refactor declContext extraction 2025-08-26 16:27:35 -04:00
JanBaig
4a3938bf9c Fix: avoid getInnermostDeclContext() 2025-08-26 14:37:57 -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
JanBaig
afe83fe951 Simple refactors to getSILFunctionTypeForInitAccessor 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
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
Egor Zhdan
d1a1f70c61 Merge pull request #83850 from egorzhdan/egorzhdan/frt-indirection
[cxx-interop] Pass foreign reference types with correct level of indirection
2025-08-24 04:50:59 +01:00
Janat Baig
798c0f51a4 Merge branch 'main' into temp-branch 2025-08-23 11:11:04 -04:00
JanBaig
ba1fd9f242 Minor Comment Cleanup 2025-08-22 23:24:36 -04:00
JanBaig
52895fefc3 [SIL] Remove AssignByWrapper references from SIL passes 2025-08-22 23:20:53 -04:00
JanBaig
6f1ee54885 [SIL] Remove AssignByWrapper suport from SIL parsing and serialization 2025-08-22 23:17:54 -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
JanBaig
30d678046d [TBD] Add init accessor thunk to TBD gen 2025-08-22 10:45:08 -04:00
Egor Zhdan
0a766e59ce [cxx-interop] Pass foreign reference types with correct level of indirection
When calling a C++ function that takes a reference to a pointer to a foreign reference type, Swift would previously pass a pointer to the foreign reference type as an argument (instead of a reference to a pointer), which resulted in invalid memory accesses.

This was observed when using `std::vector<ImmortalRef*>::push_back`.

rdar://150791778
2025-08-22 11:56:57 +01:00