Commit Graph

6865 Commits

Author SHA1 Message Date
Slava Pestov
90bfc1676d Sema: Remove some unreachable code from CSApply
I believe these code paths could only be reached by re-typechecking
invalid code in the old CSDiag implementation.
2025-09-17 16:11:53 +01:00
Kavon Farvardin
ecf701133a silgen: use isSelfParameter instead of custom check 2025-09-16 15:22:58 -07:00
Meghana Gupta
c764244df0 Merge pull request #84180 from meg-gupta/borrowandmutatepr
Add preliminary support for borrow accessors
2025-09-15 10:01:15 -07:00
Joe Groff
798621e9c5 Merge pull request #84264 from jckarter/trivial-address-only-switch
SILGen: Don't copy_addr [take] trivial address-only values.
2025-09-15 07:34:16 -07:00
Gábor Horváth
b5ef290c1c Merge pull request #84203 from Xazax-hun/handle-unowned-in-impicit-value-init
[cxx-interop] Handle Unowned values in implicit value ctors
2025-09-15 16:06:33 +02:00
Meghana Gupta
6665cd5d46 [NFC] hasGuaranteedAddressResults -> hasGuaranteedAddressResult and hasGuaranteedResults -> hasGuaranteedResult 2025-09-14 23:38:06 -07:00
Joe Groff
df8ab6ee0b SILGen: Don't copy_addr [take] trivial address-only values.
This is a new case that comes up with `InlineArray`, since an `InlineArray`
with unknown count but known trivial element type is trivial but still
address-only due to its unknown size. We are inconsistent about whether
we emit formal copies or not of these values; they should generally
be unnecessary as long as the memory location of a value is sufficiently
long-lived, but the SIL verifier still reasonably considers a `[take]` as
an invalidation of the memory, even though at runtime a take is a no-op.
Since the take is unnecessary, we can just not take when we copy out of
a trivial address location. Fixes #84141 | rdar://160007939.
2025-09-12 11:44:41 -07:00
Gabor Horvath
fe3cc6d024 [cxx-interop] Handle Unowned values in implicit value ctors
We usually have unowned values when dealing with foreign types. Make
sure the implicit value ctors will do a +1 to balance the releases. In a
release build we had a use after free over-releasing the object. In
assert builds we had an assertion failure:

Assertion failed: (value->getOwnershipKind() == OwnershipKind::Guaranteed),
function forBorrowedObjectRValue, file ManagedValue.h, line 181.

rdar://160232360
2025-09-12 12:01:59 +01:00
Konrad `ktoso` Malawski
d2a03b45d1 Merge pull request #84119 from ktoso/wip-allow-any-serialization-requirement 2025-09-12 11:08:20 +09:00
Konrad Malawski
644aa87447 Harden diagnoseForcedCastExpr for lack of cast-to type 2025-09-11 22:00:56 +09:00
Joe Groff
7a0ab9d9a8 Merge pull request #84190 from jckarter/formal-evaluation-scope-for-noncopyable-consuming-switch
SILGen: Add missing FormalEvaluationScope when evaluating consumed noncopyable switch subjects.
2025-09-10 08:13:34 -07: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
Hamish Knight
872176bdd1 Merge pull request #84149 from hamishknight/case-and-pat
A few pattern cleanups + fixes
2025-09-10 09:36:22 +01:00
Joe Groff
90182d0417 SILGen: Add missing FormalEvaluationScope when evaluating consumed noncopyable switch subjects.
After #83959, we expect noncopyable OpenExistential evaluations to have an outer
FormalEvaluationScope to forward to. However, there was no such
FormalEvaluationScope while emitting a consuming switch subject, causing an assertion
failure to trip. Add a FormalEvaluationScope tightly scoped around the evaluation in
this case, fixing rdar://160080337.
2025-09-09 16:02:57 -07:00
Meghana Gupta
8c1231e86b SILGen support for borrow accessors on Copyable types and address-only ~Copyable types 2025-09-09 14:45:44 -07:00
Meghana Gupta
6b8c91efe2 [NFC] Move StorageRefResult to a header 2025-09-09 14:45:43 -07:00
Meghana Gupta
1cff471c57 Introduce ResultConvention::Guaranteed and ResultConvention::GuaranteedAddress
ResultConvention::Guaranteed will be used by borrow accessors when the storage type can be returned by value.

ResultConvention::GuaranteedAddress will be used by mutate accessors and borrow accessors when the storage type
cannot be returned by value.
2025-09-09 14:45:40 -07:00
Joe Groff
9b271db816 Merge pull request #84143 from jckarter/protocol-objc-class-dyn-self-mismatch
SILGen: Use lowered function type parameters in objc-to-swift thunks for initializers.
2025-09-09 14:41:21 -07:00
Meghana Gupta
9fe489ce22 Introduce borrow and mutate as new accessor kinds
And handle them in various covered switches
2025-09-09 14:30:26 -07:00
John McCall
8301d5383b Fix the evaluation of #isolation in non-AFD contexts, most importantly
closures.

The fixes for initializers are just setting the stage for doing this
properly: we should be able to just change the isolation computation
in Sema and fix up the tests.
2025-09-09 14:26:57 -04: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
Hamish Knight
84befd43ab [AST] Make case body variables for CaseStmt non-optional
We don't really care about the distinction between empty and nil here.
2025-09-09 13:48:40 +01:00
Hamish Knight
63286ae3f0 [SILGen] Fix case emission when there are no case body vars
We want to call the `bodyEmitter`, since that has the extra logic
necessary to handle `do-catch` statements. Previously this didn't
cause any issues since `hasCaseBodyVariables` would have always been
true for parsed `do-catch`s, but I'm planning on changing that.
2025-09-09 13:48:40 +01: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
Joe Groff
4f1e895e56 SILGen: Use lowered function type parameters in objc-to-swift thunks for initializers.
Fixes a regression caused by the `self` declaration being given a `DynamicSelfType`
even though the formal type of the enclosing function sometimes still uses the
concrete base class type.

Fixes #83876 | rdar://158956768.
2025-09-08 09:42:32 -07:00
Joe Groff
cb02d6b946 Merge pull request #84084 from jckarter/global-let-addressable
SILGen: Global constants are addressable.
2025-09-04 08:02:30 -07:00
Joe Groff
ee2ee0b560 SILGen: Global constants are addressable.
A global or static `let` has a stable address, which is addressable when its
representation is naturally fully abstracted.
2025-09-03 08:38:13 -07:00
Janat Baig
f21eb5375e Merge branch 'main' into temp-branch 2025-09-02 20:23:25 -04:00
Kavon Farvardin
511971fb1d Merge pull request #83959 from kavon/rdar159079818-subscript-read-nc
silgen: allow borrow of subscript for noncopyables
2025-08-29 20:52:23 -07:00
Kavon Farvardin
4964a66277 silgen: inherit eval scope for OpenExistentialExpr
We were not able to use an existential as the base
of an access that strictly borrows the existential,
because SILGen's RValue emission would establish
a fresh evaluation scope just for the existential's
opening, and then copy the opened value out.

This is problematic for noncopyable existentials.

So this patch moves & adds FormalEvaluationScope's
around so they're broad enough to enable a
borrow of an existential. The idea behind this
refactoring is to establish top-level
FormalEvaluationScopes when initially creating
RValue's for Expr's in SILGen. Any more-tightly
scoped operations will already establish their own
nested scope, so this is mostly adding safe-guards.

I've limited the existentials fix to noncopyables
for now.

part of rdar://159079818
2025-08-29 13:30:42 -07:00
Kavon Farvardin
906a4cbcdb silgen: allow borrow of subscript for noncopyables
If a subscript uses a read accessor to yield a noncopyable value,
we'd emit an `end_apply` that's too tightly scoped to allow for
a subsequent borrowing access on the yielded value.

resolves rdar://159079818
2025-08-29 13:30:31 -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
Kavon Farvardin
3bb8fa848a nfc: !isNoncopyable() -> isCopyable() 2025-08-28 12:13:21 -07: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
Slava Pestov
66dc1cc2e8 Merge pull request #83902 from slavapestov/lowered-type-in-context
Cache SILFunction::getLoweredTypeInContext()
2025-08-27 08:19:13 -04:00
Anthony Latsis
26540ca439 SIL: Do not use -1 to construct a 1-bit llvm::APInt
A -1 truncated to 1 bit is just 1, so stop overcomplicating things here.
2025-08-27 12:41:10 +01:00
JanBaig
63888e34d9 Update SWIFTMODULE_VERSION_MINOR comment 2025-08-26 14:37:57 -04:00
Alastair Houghton
6cc4a4d823 [SILGen][Concurrency] Improve DefaultExecutorFactory lookup.
Rather than just looking at top level in the module, start by searching
the type marked as `@main`.  This means that a library that provides a
protocol or superclass that the `@main` type can conform to can specify
an executor in a reasonable manner.
2025-08-26 09:38:13 +01:00
Slava Pestov
11f727e143 SIL: Add no-arg overload of SILFunction::getLoweredFunctionTypeInContext() 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
836e20a253 [SILGen] Refactor InitializationPtr usage 2025-08-17 14:05:02 -04:00
Slava Pestov
a983323508 Merge pull request #83768 from slavapestov/replace-covariant-result-type
Sema: Remove a bunch of usages of replaceCovariantResultType()
2025-08-16 08:56:12 -04:00
Slava Pestov
b1150924a3 SILGen: Remove a usage of replaceCovariantResultType() 2025-08-15 18:37:15 -04:00
Joe Groff
dc043cf05d SILGen: Track original variable's cleanup state for addressable buffer cleanups.
Don't try to delete the value on paths where the value hasn't yet been deleted.
2025-08-13 16:51:12 -07:00
Joe Groff
bcca7ee9db SILGen: Combine related addressable buffer bookkeeping types into one place.
There's no need for two separate types here. Fully separate the addressable buffer
tracking from VarLocs as well, in order to set up for a fix to addressable references
to `if let` and `guard let` bindings.
2025-08-13 14:29:50 -07:00
JanBaig
b793db7bfa [SILGen] Inline InitializationPtr setup for init accessor @out buffer 2025-08-12 11:21:11 -04:00
JanBaig
b939bdc31a [SIL] Initial Implemention of thunk support for local contexts 2025-08-09 19:39:29 -04:00
JanBaig
ff894c4d01 [Format] Apply clang-format to recent changes 2025-08-09 12:46:18 -04:00
JanBaig
51dca5a6f7 [SILGen] Emit assign_or_init for ambiguous assignments to property-wrapper variables 2025-08-08 19:11:21 -04:00