Commit Graph

785 Commits

Author SHA1 Message Date
Kavon Farvardin
38c61d7dd6 Merge pull request #85054 from kavon/opaque-values/fixes-3
OpaqueValues: add support for property wrappers
2025-10-23 22:18:54 -07:00
Kavon Farvardin
19bd65c89b OpaqueValues: add support for property wrappers
resolves rdar://163071245
2025-10-23 16:31:01 -07:00
Joe Groff
d7ea0b821e SILGen: Subscripts can also be borrowed bases.
SILGenBorrowedBaseVisitor did not take subscripts into account during its
visit. Add this case following the handling of MemberRefExpr for properties.
Fixes rdar://163022690.
2025-10-21 11:50:16 -07:00
Meghana Gupta
4b7297ac2f Update SILGen for unsafe mutate accessors 2025-10-07 14:12:15 -07:00
Meghana Gupta
4da3114904 Disable generating access scope during emission of borrowed/mutable return 2025-10-07 14:12:12 -07:00
Meghana Gupta
282e3351f6 Handle mutate accessors similar to borrow accessors in call emission 2025-10-07 14:12:11 -07:00
Meghana Gupta
3103be60bc Update SILGen for mutate accessors 2025-10-07 14:12:10 -07:00
Meghana Gupta
65a59a5847 Update borrow accessor diagnostics 2025-10-02 07:18:30 -07:00
Meghana Gupta
78a165d3ef Fix SILGenBorrowedBaseVisitor::isNonCopyableBaseBorrow 2025-10-02 07:18:26 -07:00
Meghana Gupta
c2dab58876 Update SILGen for ~Copyable borrow accessors
Introduce copy_value + mark_unresolved_non_copyable_value + begin_borrow at the return value of
borrow accessor apply to drive move-only diagnostics.

Also strip the copy_value + mark_unresolved_non_copyable_value + begin_borrow trio in a few places, since
they create an artificial scope out of which we cannot return values in a borrow accessor
without resorting to unsafe SIL operations currently.

Borrow accessor diagnostics allow stripping these instructions safely in the following places:

- return value of a borrow accessor
- self argument reference in the borrow accessor return expression and borrow accessor apply
2025-10-02 07:18:23 -07:00
Meghana Gupta
e98f3522c8 [NFC] Rename LVOptions::withBorrow -> LVOptions::forGuaranteedReturn
Also add forGuaranteedAddressReturn
2025-10-02 07:18:20 -07: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
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
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
9fe489ce22 Introduce borrow and mutate as new accessor kinds
And handle them in various covered switches
2025-09-09 14:30:26 -07:00
Janat Baig
f21eb5375e Merge branch 'main' into temp-branch 2025-09-02 20:23:25 -04: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
Janat Baig
798c0f51a4 Merge branch 'main' into temp-branch 2025-08-23 11:11:04 -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
John McCall
46be95847b Extract TypeLowering's recursive type properties into a header, add
functions to compute them directly without a TypeLowering object, and
change a lot of getTypeLowering call sites to just use that.

There is one subtle change here that I think is okay: SILBuilder used to
use different TypeExpansionContexts when inserting into a global:
- getTypeLowering() always used a minimal context when inserting into
  a global
- getTypeExpansionContext() always returned a maximal context for the
  module scope
The latter seems more correct, as AFAIK global initializers are never
inlinable. If they are, we probably need to configure the builder with
an actual context properly rather than making global assumptions.

This is incremental progress towards computing this for most types
without a TypeLowering, and hopefully eventually removing TL entirely.
2025-08-01 15:00:57 -04:00
Joe Groff
0e94c63494 SILGen: Have emitSemanticStore cast off concurrency annotations.
If a function is being semantically treated as having different concurrency
annotations because of a `@preconcurrency` import or language mode setting,
then SILGen may try to store an argument or result for a call using a value
that differs only in concurrency annotations, which can be safely bitcast
away.

Fixes rdar://154520999
2025-07-16 12:41:01 -07:00
Joe Groff
761faaa169 SILGen: Handle struct fields and addressors as addressable storage.
When accessing stored properties out of an addressable variable or parameter
binding, the stored property's address inside the addressable storage of the
aggregate is itself addressable. Also, if a computed property is implemented
using an addressor, treat that as a sign that the returned address should be
used as addressable storage as well. rdar://152280207
2025-06-16 20:23:47 -07:00
Nate Chandler
7697a49ee9 [CoroutineAccessors] Only reference when available
Don't bind references to storage to use (new ABI) coroutine accessors
unless they're guaranteed to be available.  For example, when building
against a resilient module that has coroutine accessors, they can only
be used if the deployment target is >= the version of Swift that
includes the feature.

rdar://148783895
2025-04-15 21:13:57 -07:00
nate-chandler
2e1494df9f Merge pull request #80701 from nate-chandler/rdar148941214
[CoroutineAccessors] Use yield_once_2 on Darwin and Linux.
2025-04-10 14:46:05 -07:00
Nate Chandler
b76a76bdf1 [CoroutineAccessors] Unwind based on feature.
Now that coroutine kind (and consequently ABI) for the accessors is
keyed off a SIL option, it's no longer possible to read whether a given
SILFunction arose from a read/modify coroutine just by checking its
coroutine kind.  Regardless of ABI, read/modify coroutines may only
unwind (i.e. are only permitted not to "run to completion") if the
relevant experimental (soon to be deleted) feature is enabled.
2025-04-10 07:41:37 -07:00
Joe Groff
3b7093c7ce SILGen: Use [unsafe] access markers for move-only storage when exclusivity enforcement is disabled.
The move-only checker relies on access markers to understand access scopes, so eliding them
entirely leads to miscompiles. We can emit `begin_access [unsafe]` to semantically delimit
exclusivity scopes while still doing no runtime checking. Fixes rdar://147546262.
2025-04-07 17:08:42 -07:00
Joe Groff
98d6480ddb Merge pull request #80275 from jckarter/classify-address-projections
SILGen: Properly classify LValue component projections in more cases.
2025-03-26 09:16:09 -07:00
Joe Groff
f990413d39 SILGen: Properly classify LValue component projections in more cases.
PR #79084 adjusted the projection logic for addressor accessors to avoid
a temporary materialization in cases where the base value is already in
memory; however, many LValue physical components were still unconditionally
using `ManagedValue::forLValue` and causing unnecessary materializations
from already-read-accessed memory locations. Fixes rdar://147705667.
2025-03-25 09:55:31 -07:00
Amritpan Kaur
60e03a85d9 [SILGen] Lower applied keypath methods. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
e5362c761d [NFC] Refactor subscript argument evaluation for reuse. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
e7e354d989 [NFC] Generalize subscript code for methods. 2025-03-19 10:54:09 -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
2df3211690 Merge pull request #79903 from jckarter/addressable-representation-silgen
SILGen: Emit an addressable representation for immutable bindings on demand.
2025-03-12 08:02:05 -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
nate-chandler
38c8cc8ff4 Merge pull request #77661 from nate-chandler/general-coro/20241115/1
[CoroutineAccessors] Default implementations are transparent.
2025-03-07 11:39:21 -08:00
Joe Groff
19329e3e03 SILGen: Treat read-formal-accessed lvalues as borrows.
A read access asserts that the memory location is immutable for the duration
of the access, so it can be treated as a borrow rather than a mutable lvalue.
Doing this allows the borrow formal access scope fixes from #79084 to apply
to situations where a loadable type undergoes an accessor-based access with
indirect arguments (such as for public accessors when library evolution is
enabled for the type). Fixes rdar://143334632.
2025-02-04 08:23:34 -08:00
Joe Groff
44b431690d SILGen: Materialize addressor bases for the formal access scope of the entire access.
The return pointer may point into the materialized base value, so if the base needs
materialization, ensure that materialization covers any futher projection of the
value.
2025-01-31 18:08:53 -08:00
Joe Groff
f9d9d75768 SILGen: Change codegen for loading from no-implicit-copy lvalues.
Previously, we would emit this as

  %1 = load [copy] %address
  %2 = moveonly_wrapper_to_copyable [owned] %1

which is difficult for move-only checking to handle, since %2 looks like a
consume of %1, making it difficult to determine %1's true lifetime. Change
this to

  %1 = moveonly_wrapper_to_copyable_addr %address
  %2 = load [copy] %address

which is handled better by move-only checking, improving the accuracy of
existing move-checking as well as fixing a spurious diagnostic when
indirect parameters get passed as by-value arguments to other functions.
2025-01-06 21:34:56 -08:00
Nate Chandler
38a9ef71cb [NFC] Fixed function name spelling. 2024-11-19 15:52:24 -08:00
Slava Pestov
47156e006b AST: Introduce ProtocolConformanceRef::forAbstract() 2024-11-16 16:16:06 -05:00
Nate Chandler
da71271d8f [CoroutineAccessors] Synthesize default req impls.
When a protocol which has a read (or modify) requirement is built with
the CoroutineAccessors feature, it gains a read2 (or modify2,
respectively) requirement.  For this to be compatible with binaries
built without the feature, a default implementation for these new
requirements must be provided.  Cause these new accessor requirements to
have default implementations by returning `true` from
`doesAccessorHaveBody` when the context is a `ProtocolDecl` and the
relevant availability check passes.
2024-11-07 16:47:09 -08:00
Nate Chandler
f1f0ccdeff [NFC] Improved predicate names. 2024-11-06 20:52:21 -08:00
Joe Groff
1772f021b1 Merge pull request #75193 from jckarter/reabstract-before-abi-safe-lvalue-conversion
SILGen: Reabstract subexpr lvalue before ABISafeConversion.
2024-10-28 12:00:26 -07:00
Nate Chandler
091368ba21 [CoroutineAccessors] Added read.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
Nate Chandler
98a2e6a7df [CoroutineAccessors] Added modify.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00