Commit Graph

5738 Commits

Author SHA1 Message Date
Meghana Gupta
0fb21c9156 Update unchecked_ownership insertion in the protocol witness of borrow accessors 2026-02-04 07:16:31 -08:00
Meghana Gupta
7df55d33ba Handle unsafe expression in mutate accessor return statements 2026-02-01 20:03:43 -08:00
Meghana Gupta
a210ab1050 [NFC] Add borrow accessor test with lazy 2026-01-29 15:45:17 -08:00
Meghana Gupta
4e0098583d Update for borrow/mutate accessors with ownership modifiers 2026-01-29 15:45:16 -08:00
Meghana Gupta
d1df7aa236 Diagnose trivial-type borrow accessor results using the same rules as non-trivial types 2026-01-29 15:45:06 -08:00
Arnold Schwaighofer
7ccd989a3e Merge pull request #86798 from aschwaighofer/coroutine_accessors_emitBackDeployForwardApplyAndReturnOrThrow
[CoroutineAccessors] [SILGen] Fix emitBackDeployForwardApplyAndReturnOrThrow for yield_once_2 coroutines
2026-01-28 18:24:45 -08:00
Slava Pestov
05b33684be SIL: Fix indirectness decision when lowering SIL function type with typed throws
This was never implemented properly in bcbc1da00a.

- Fixes rdar://165399229.
2026-01-28 15:35:23 +00:00
Meghana Gupta
de9dd60c75 Merge pull request #86835 from meg-gupta/banliterals
Ban returning literals from borrow accessors
2026-01-27 20:52:28 -08:00
Meghana Gupta
052ebc32da Ban returning literals from borrow accessors
literals are not "stored values" in a general sense and cannot be returned by borrow accessors
2026-01-27 16:02:29 -08:00
Arnold Schwaighofer
6f7766b92a Merge pull request #86753 from aschwaighofer/coro_access_test
[CoroutineAccessors] Add SILGen and evolution test replacing underscored accessors by yielding accessors
2026-01-27 14:02:11 -08:00
Tim Kientzle
06a51d3f9a Merge pull request #86751 from tbkka/tbkka-end-to-end-coro-test
End-to-end execution test for yielding accessors
2026-01-26 14:51:11 -08:00
Arnold Schwaighofer
9bda9c73a0 [CoroutineAccessors] [SILGen] Fix emitBackDeployForwardApplyAndReturnOrThrow for yield_once_2 coroutines
They have an stack allocation result and the token result is at a different index.

rdar://168937038
2026-01-26 11:49:50 -08:00
Sam Pyankov
c3ee2bce8e Merge pull request #86749 from sepy97/revert_public-decl-internal-protocol
Revert "Diagnose public protocol witnessed by an internal protocol ex…
2026-01-26 10:16:34 -08:00
Joe Groff
0f3ddfbcc8 Merge pull request #86545 from jckarter/builtin-borrow
`Builtin.Borrow` implementation
2026-01-26 07:32:31 -08:00
Arnold Schwaighofer
e6c4d85c97 Fix/disable test on certain platforms 2026-01-24 16:23:49 -08:00
elsa
5e9f215f31 Merge pull request #86010 from elsakeirouz/rework-for-each-desugar
Rework ForEachStmt Desugaring
2026-01-24 13:55:51 +00:00
Ian Anderson
d9af5a6186 Merge pull request #86768 from ian-twilightcoder/update-sdksettings
[test][NFC] Add more keys to test SDKSettings files
2026-01-24 03:35:31 -08:00
Tim Kientzle
925ec400f6 Merge pull request #86761 from tbkka/tbkka-force-unwind-off
[SE-0474] Force unwind off for new yielding accessors
2026-01-24 02:13:30 -08:00
Ian Anderson
8953415c58 [test][NFC] Add more keys to test SDKSettings files
Swap the key order to be consistent with the other SDKSettings files.

rdar://168700857
2026-01-23 22:47:56 -08:00
Tim Kientzle
7e32732649 [SE-0474] Force unwind off for new yielding accessors
In the context of coroutine/yielding accessors, "unwind" means
that the second half of the coroutine (code _after_ the `yield`
statement) will not run if an exception is thrown during the access.

Unwinding was the default behavor for legacy `_read`/`_modify` coroutine
accessors.
For the new `yielding borrow`/`yielding mutate` accessors, unwinding
was optional behind a separate feature flag.
But the final SE-0474 dictates that unwinding is always _disabled_ for
the new yielding accessors.  That is, the new yielding accessors always
run to completion, regardless of whether there are thrown exceptions within
the access scope.  This was deemed essential to ensure that authors of
data structures could guarantee consistency.

This PR permanently disables unwinding behavior for the new accessors.
The feature flag still exists but has no effect.
A handful of tests that verified the unwinding behavior have been
edited to ensure that unwinding does _not_ happen even when the feature
flag is specified.
2026-01-23 16:01:48 -08:00
Sam Pyankov
aa30b1a106 Merge branch 'main' into revert_public-decl-internal-protocol 2026-01-23 15:17:25 -08:00
Arnold Schwaighofer
46736e0990 [CoroutineAccessors] Add a test that makes sure we can back/foward deploy with _read,_modify definitions 2026-01-23 13:44:03 -08:00
Tim Kientzle
0d5f91b00c End-to-end execution test for yielding accessors
This verifies that yielding borrow and mutate accessors run both before
and after the access in each of the following cases:
* Simple access of a struct
* As above, but with a throw exception during the access
* As above, but through a protocol existential
2026-01-23 12:21:07 -08:00
Sam Pyankov
70835508b0 Revert "Diagnose public protocol witnessed by an internal protocol extension"
This reverts commit 6280a7001f.
rdar://168627163
2026-01-23 10:28:19 -08:00
Joe Groff
5f49668577 Builtin.dereferenceBorrow should maintain the memory location of addressable values. 2026-01-23 08:02:09 -08:00
Joe Groff
b11e8c985a SIL: Handle dereference_borrow returns in SILGenCleanup.
Make sure an `end_borrow` is emitted on the `dereference_borrow` so that
SILGenCleanup recognizes this pattern and lowers it to a `return_borrow`
as it does for returned `load_borrow`s. Add support to the Swift implementation
of `BorrowingInstruction` for `DereferenceBorrow`.
2026-01-23 08:02:09 -08:00
Joe Groff
3d543f545e SILGen: Lowering for Builtin.dereferenceBorrow.
This builtin only needs to be supported as the return of a borrow accessor,
so special case its handling as part of a storage expression in SILGenLValue.
2026-01-23 08:02:08 -08:00
Joe Groff
373211a902 SILGen: Lowering for Builtin.makeBorrow 2026-01-23 08:02:08 -08:00
Joe Groff
2243dac114 SIL: Type lowering for Builtin.Borrow.
Borrow's layout is trivial loadable when the layout of the referent is known (even
if the referent is itself nontrivial or address-only). If the referent's layout is
abstracted or resilient, then Borrow's layout is trivial address-only.
2026-01-23 07:46:52 -08:00
Elsa Keirouz
d54a572f7f [Sema] desugar ForEachStmt at AST level 2026-01-23 15:17:29 +00:00
Ian Anderson
fc628a8bfb [test][NFC] Add more keys to test SDKSettings files
Every time DarwinSDKInfo reads a new key out of SDKSettings, a boatload of test SDKSettings files need to be updated across several repositories and forks and branches. It’s tedious to be careful to update those with real values so that the tests are properly regression testing older SDKs. It’s important to be careful so that the tests are accurate, e.g. to prevent the scenario where DarwinSDKInfo starts reading a new key out of SDKSettings and assumes that it’s always available everywhere, when in reality it was only added a few releases ago and will break with older SDKs. If the test SDKSettings files continue to be updated ad hoc, it’s going to be really easy to copy/paste a default value everywhere, and then clients will see incorrect behaviors with the real SDKs, or even compiler crashes if the key is unconditionally read. Preemptively add all of the maybe-possibly-compiler relevant keys to the test SDKSettings files from the real SDKs so that the test files are an accurate representation and shouldn't need to be touched in the future. Where the test SDKSettings have intentionally doctored data, add a Comments key explaining what is changed from the real SDK, and alter the SDK name with a tag indicating the change.

rdar://168700857
2026-01-23 02:19:36 -08:00
Erik Eckstein
0f0aa0c17b Optimizer: require that there are no unreachable blocks and infinite loops in OSSA
These two new invariants eliminate corner cases which caused bugs if optimization didn't handle them.
Also, it will significantly simplify lifetime completion.

The implementation basically consists of these changes:
* add a flag in SILFunction which tells optimization if they need to take care of infinite loops
* add a utility to break infinite loops
* let all optimizations remove unreachable blocks and break infinite loops if necessary
* add verification to check the new SIL invariants

The new `breakIfniniteLoops` utility breaks infinite loops in the control flow by inserting an "artificial" loop exit to a new dead-end block with an `unreachable`.
It inserts a `cond_br` with a `builtin "infinite_loop_true_condition"`:
```
bb0:
  br bb1
bb1:
  br bb1              // back-end branch
```
->
```
bb0:
  br bb1
bb1:
  %1 = builtin "infinite_loop_true_condition"() // always true, but the compiler doesn't know
  cond_br %1, bb2, bb3
bb2:                  // new back-end block
  br bb1
bb3:                  // new dead-end block
  unreachable
```
2026-01-22 17:41:23 +01:00
Meghana Gupta
4c18d2ebdc Merge pull request #86496 from meg-gupta/borrowprotopr
Add support for borrow and mutate protocol constraints
2026-01-21 10:11:52 -08:00
Hamish Knight
cbf752e482 Merge pull request #86647 from hamishknight/pack-it-in
[AST] Avoid flattening type variable tuple singletons
2026-01-20 21:42:35 +00:00
Meghana Gupta
7826d601eb Don't add setter and modify to witness tables when a protocol has a mutate requirement 2026-01-20 11:44:16 -08:00
Meghana Gupta
bfc88b41cd [NFC] Update borrow/mutate protocol test with a frozen conformer 2026-01-20 11:44:15 -08:00
Meghana Gupta
04db3ba069 Update SerializationKind for borrowing accessors
Borrow accessors are synthesized with "direct" access semantics and cannot be serialized
when the storage is resilient.
2026-01-20 11:44:14 -08:00
Meghana Gupta
e3f8d123f2 Update protocol witness SILGen for borrow accessors 2026-01-20 11:44:09 -08:00
Kavon Farvardin
2b5f941930 Merge pull request #86413 from jamieQ/unowned-actor-miscompile
[SILGen]: strengthen assertions when creating InitExistentialRef
2026-01-20 09:43:14 -08:00
Hamish Knight
f6e2024e92 [test] Move for loop pack expansion tests to SILGen
Make sure we can SILGen these.
2026-01-20 15:17:07 +00:00
Arnold Schwaighofer
2379d856c9 Merge pull request #86605 from aschwaighofer/coroutine_accessors_read_synthesizes_yielding_borrow
[CoroutineAccessors] Emit yielding borrow when there is a _read
2026-01-19 16:42:24 -08:00
Arnold Schwaighofer
cff196cb4c [CoroutineAccessors] Emit yielding borrow when there is a _read
We want to rely on the presence of yielding borrow with the introduction
of CoroutineAccessor feature. Emit it so that when the deployment target
is the same (or higher) as the CoroutineAccessor feature introduction we can
rely on the presence of yielding borrow. (assuming that the source code
was recompiled with a current toolchain at the time of introduction of the
feature)
2026-01-16 12:33:06 -08:00
Michael Gottesman
6fc9789cd9 [silgen] Remove the [var_decl] marker from the begin_borrow generated for mutable capture boxes.
The reason I am doing this is that I want to be careful and make sure that we
can distinguish in between weak var and weak let var decls and real captures.

In the caller, we do not actually represent the capture's var decl information
in a meaningful way since the actual var decl usage is only in the closure.
After inlining, we get that var decl information from the debug_value of the
argument. So there isn't any reason not to do it and it will simplify the other
work I am doing.
2026-01-16 09:09:47 -08:00
Slava Pestov
5bcdcd1fa6 FrontendTool: Stop if SILGen emits diagnostics even when lazy type checking is off
We've had several bugs lately where SILGen produces a diagnostic,
but the resulting invalid SIL causes crashes further down in the
mandatory pipeline. To prevent this from happening, just stop after
SILGen if diagnostics were emitted, even if lazy type checking is
disabled, because the same rationale applies in either case.
2026-01-13 18:24:10 -05:00
Jamie
e87857d57e [SILGen]: sink isBridgeableObjectType assertions into SILBuilder 2026-01-13 07:40:21 -06:00
Jamie
62fedfc81c [SILGen]: enforce only expected types are used with InitExistentialRef
We currently appear to miscompile when emitting the erased isolation
existential codegen if the isolated capture is unowned. To patch this,
add new assertions that only supported types are used when creating the
instruction in the builder.
2026-01-12 08:02:51 -06:00
Tim Kientzle
37cccb34d7 Merge pull request #86425 from tbkka/tbkka-rdar149303951-part2
[SE-0474] use new "yielding borrow" terminology in SIL printing
2026-01-09 20:36:51 -08:00
Slava Pestov
027d9c9a09 Merge pull request #86415 from slavapestov/fix-issue-86414
SILGen: Fix a crash when emitting @convention(c) function pointer from a closure in some cases
2026-01-09 17:14:16 -05:00
Tim Kientzle
4955bc4568 [SE-0474] use new "yielding borrow" terminology in SIL printing
To help reduce cognitive burden for future Swift compiler engineers,
let's use the same terminology for coroutine accessors in SIL dumps
as we use in the surface language and inside the compiler.

This really just changes two lines in SILPrinter.cpp and updates
a lot of tests.  I've also copied one test to preserve the old syntax
to make sure that SIL parsing still accepts it.  That should hopefully
prevent unfortunate round-tripping issues while these changes settle.
2026-01-09 10:10:18 -08:00
Tim Kientzle
adec1f6cbe Merge pull request #86277 from tbkka/tbkka-rdar149303951-try1
[SE-0474] Implement final `yielding borrow`/`yielding mutate` naming for coroutine accessors
2026-01-09 08:52:21 -08:00