Commit Graph

747 Commits

Author SHA1 Message Date
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
3bb8fa848a nfc: !isNoncopyable() -> isCopyable() 2025-08-28 12:13:21 -07:00
Janat Baig
798c0f51a4 Merge branch 'main' into temp-branch 2025-08-23 11:11:04 -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
b939bdc31a [SIL] Initial Implemention of thunk support for local contexts 2025-08-09 19:39:29 -04:00
John McCall
bee053f1f0 Switch InitializationPtr to use PossiblyUniquePtr so that we can just
forward existing initializations around when necessary.
2025-08-02 02:13:25 -04:00
Anthony Latsis
bbd84429a0 Merge pull request #83400 from swiftlang/jepa-main
Address `llvm::PointerUnion::{is,get}` deprecations
2025-07-30 17:19:58 +01:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
Joe Groff
42d1ca3338 SILGen: Fix positioning of store_borrow for addressable references to closure captures.
These get passed to the closure body in SIL as function arguments to the entry
point, so the alloc_stack necessarily has to appear inside of the value's lifetime,
and the store_borrow needs to be placed after that alloc_stack.
2025-07-28 17:04:49 -07:00
Joe Groff
22a8b2817c Merge pull request #83009 from jckarter/case-binding-addressable-scopes
SILGen: Properly set up addressability scopes for case pattern bindings.
2025-07-14 07:57:11 -07:00
Joe Groff
c24801ace6 SILGen: Properly set up addressability scopes for case pattern bindings.
In order to accommodate case bodies with multiple case labels, the AST
represents the bindings in each pattern as a distinct declaration from
the matching binding in the case body, and SILGen shares the variable
representation between the two declarations. That means that the two
declarations also need to be able to share an addressable representation.
Add an "alias" state to the addressable buffer data structures so that
we can refer back to the original case label var decl when the case body
var decl is brought into scope, so that accesses through either decl
properly force the addressable representation.

Fixes rdar://154543619.
2025-07-11 11:41:39 -07:00
Joe Groff
3b98bcb0a3 SILGen: Don't try to project static stored properties as addressable from their base.
An oversight from https://github.com/swiftlang/swift/pull/82288. Fixes #82368 / rdar://153837014.
2025-07-07 19:50:05 -07:00
Allan Shortlidge
39b6c608b0 SILGen: Reorganize code related to availability.
NFC.
2025-06-23 15:57:34 -07:00
Joe Groff
9904d6c318 SILGen: Establish an addressability scope for closure captures.
This allows a captured variable to serve as the root of an addressable dependency.
Fixes the compiler crash in rdar://150479326.
2025-05-30 14:03:27 -07:00
Allan Shortlidge
4aa516aebb SILGen: Fix if #available for unavailable custom domains in zippered modules.
When generating SIL for an `if #available(SomeDomain)` query in code being
compiled for a zippered target, the generated code was mis-compiled if
`SomeDomain` were disabled at compile time. Empty version ranges need to be
handled explicitly by `SILGenFunction::emitZipperedOSVersionRangeCheck()`.

SILGen still miscompiles `if #unavailable` queries generally in code compiled
for a zippered target (rdar://147929876).

Resolves rdar://150888941.
2025-05-25 08:27:12 -07:00
Allan Shortlidge
cce02961f9 AST/SILGen: Make availability ranges stored by PoundAvailableInfo optional.
Rather than representing a missing availability range on `PoundAvailableInfo`
with a default-constructed `AvailabilityRange` (empty), store the ranges as
optionals instead. This allows an empty range to represent an availability
condition which is known to be false at compile time, which will be necessary
when generating SIL for `if #available` queries that check custom availability
domains.
2025-04-01 07:46:46 -07:00
Joe Groff
85425fbe9c SILGen: Adjust allocation point for addressable representations.
Allocate the stack buffer at the point where the cleanup is introduced, so that
the stack allocations always follow scope stack discipline.
2025-03-17 21:37:08 -07:00
Joe Groff
da813458a6 SILGen: Emit an addressable representation for immutable bindings on demand.
To ensure that dependent values have a persistent-enough memory representation
to point into, when an immutable binding is referenced as an addressable
argument to a call, have SILGen retroactively emit a stack allocation and
materialization that covers the binding's scope.
2025-03-12 18:35:42 -07:00
Michael Gottesman
f6349aaf1e Revert "SILGen: Emit an addressable representation for immutable bindings on demand."
This reverts commit 19a99ea42b.

rdar://146864906
2025-03-12 13:24:33 -07:00
Joe Groff
19a99ea42b SILGen: Emit an addressable representation for immutable bindings on demand.
To ensure that dependent values have a persistent-enough memory representation
to point into, when an immutable binding is referenced as an addressable
argument to a call, have SILGen retroactively emit a stack allocation and
materialization that covers the binding's scope.
2025-03-11 15:15:48 -07:00
Alex Martini
633f101e0a Fix double 'the the' in various places 2025-02-14 17:27:51 -08:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Michael Gottesman
6058b1d9bd [silgen] Change SILGen to emit ignored_user for emitIgnoredExpr and black hole initialization. 2025-01-22 21:12:36 -08:00
Hamish Knight
91ae5d6345 [AST] NFC: Rename getArgumentInterfaceType -> getPayloadInterfaceType
IMO this is a slightly clearer name, many of its
uses already use the term "payload".
2024-09-29 17:05:14 +01:00
Allan Shortlidge
4c3a009c2b SILGen: Remove triplesAreValidForZippering() assert.
This assert was correctly catching the fact that `-target-variant` is not being
normalized at the same time as `-target` when building arm64e modules from
swiftinterface. That should be fixed, but at the moment it isn't causing any
concrete harm and the assertion fails when building against the SDKs included
with the latest Xcode 16 betas.

Resolves rdar://133020098.
2024-09-04 22:39:21 -07:00
John McCall
0dd54eb13c Fix an assertion under -disable-availability-checking in zippered mode 2024-08-01 17:18:38 -04:00
Andrew Trick
dc56f8e110 [SILGen] emit local variable scopes for trivial values.
Required for SIL analysis of local variable scopes. For example, to track
lifetime dependence on a variable.

Example:

.swift:

    func foo(i: Int) {
      let v = i

.sil:

    %1 = move_value [var_decl] %0 : $Int // starts the variable scope
    extend_lifetime %1 : $Int            // ends the variable scope

Rewrite getValueForLexicalLifetimeBinding. The previous implementation was
incomprehensible to me. This will potentially change functionality by removing
previous corner cases that look like nonsense to me.

Adds an unfortunate FIXME to allow migration without affecting fake metatype
locals produced by function conversion!
2024-07-26 08:27:31 -07:00
Allan Shortlidge
6fb6a56b20 SILGen: Introduce macCatalyst support for if #available.
Upstream the necessary changes to compile `if #available` queries correctly
when a `macabi` target triple or a `-target-variant` is specified.
2024-07-23 17:00:10 -07:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 2024-07-06 12:05:46 -04:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Nate Chandler
c35b86a30d [SILGen] Borrow into in_guaranteed.
Don't create a copy in order to pass a value `@in_guaranteed`.  Just
`store_borrow` the value.

rdar://128710064
2024-06-06 15:45:22 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Nate Chandler
373cc84329 [SILGen] Move non-trivial none-ownership values.
All non-trivial values which correspond to `VarDecl`s must be marked
appropriately so that they can be found by the relevant checker.  Here,
values with none ownership are marked.
2024-03-09 23:19:30 -08:00
Nate Chandler
24c9046365 [NFC] SILGen: Invert control flow. 2024-03-09 21:32:42 -08:00
Nate Chandler
dff0b2efaa [SILGen] Allocs for VDs are var_decl.
Annotate alloc_stack instructions that correspond to VarDecls with the
var_decl flag.
2024-03-08 22:28:22 -08:00
Nate Chandler
37d8984bea [NFC] SIL: Typed move_value's isFromVarDecl. 2024-03-08 22:28:22 -08:00
Nate Chandler
83bc56fd5b [NFC] SIL: Typed begin_borrow's isFromVarDecl. 2024-03-08 22:28:22 -08:00
Nate Chandler
46b08bd386 [SIL] NFC: Typed move_value's hasPointerEscape. 2024-03-08 22:27:52 -08:00
Nate Chandler
70d90b4b43 [NFC] SIL: Typed begin_borrow's hasPointerEscape. 2024-03-08 22:27:52 -08:00
Nate Chandler
7db84f25b1 [NFC] SIL: Typed move_value's isLexical. 2024-03-08 22:27:52 -08:00
Nate Chandler
9f6c30919b [NFC] SIL: Typed begin_borrow's isLexical. 2024-03-08 22:27:50 -08:00
Nate Chandler
c6eb3112b5 [NFC] SIL: Typed alloc_stack's isLexical. 2024-03-08 21:24:39 -08:00
Nate Chandler
ec6b447b68 [NFC] SIL: Typed alloc_box's hasDynamicLifetime. 2024-03-08 21:24:39 -08:00
Nate Chandler
dfa5c9814b [NFC] SIL: Typed alloc_stack's hasDynamicLifetime. 2024-03-08 21:24:39 -08:00
Nate Chandler
e10d595328 [NFC] SIL: Typed alloc_box's wasMoved.
Help avoid errors with boolean flags by using the new
UsesMoveableValueDebugInfo_t.
2024-03-08 21:24:39 -08:00