Commit Graph

1317 Commits

Author SHA1 Message Date
Pavel Yaskevich 3543e2713b Merge pull request #89667 from xedin/rdar-164739199
[SILGen] Establish correct isolation for async ObjC completion handler calls
2026-06-08 08:08:55 -07:00
Egor Zhdan 338c8eafd8 [cxx-interop] Support static dispatch for virtual methods using super
This adds support for calling virtual methods of C++ foreign reference types with static dispatch.

In C++, one can do:
```cpp
this->Base::virtualMethod()
```

Swift doesn't allow calling a particular overload of an overridden method, however, it allows calling an overload from the superclass with `super`:
```swift
extension Derived {
  public func callSuper() {
    return super.foo()
  }
}
```

For inherited FRTs, the example above behaved in an unexpected way: the call would still be dispatched dynamically, despite using the syntax reserved for static dispatch. This change makes it behave similarly to pure-Swift classes.

rdar://177619427
2026-06-07 12:14:31 +01:00
Pavel Yaskevich e33578a8b2 [SILGen] Establish correct isolation for async ObjC completion handler calls
This is specific to global-actor isolated functions because by default
async variants are `nonisolated(nonsending)` and won't switch
isolation.

If we are emitting a call to an `async` variant of an ObjC completion
handler API, we need to hop at the call site because there is no
`async` function that is going to hop in its body. Such calls are
referencing a sync variant with a special completion handler
synthesized the compiler and the isolation context has to be
established beforehand.

Resolves: rdar://164739199
2026-06-05 10:36:57 -07:00
Pavel Yaskevich 9de09d6563 [SILGen] NFC: Move ObjC completion handling under executor emission
Async variant of an ObjC API uses `get_async_continuation_addr`
so any hops have to happen before that. Currently this is no-op
because we don't emit a hop for isolated ObjC async variants but
that is changing.
2026-06-04 13:18:26 -07:00
Henrik G. Olsson 7379154883 Reapply "Merge pull request #89436 from hnrklssn/swiftify-trap-source-location"
This reverts commit 7c47f354b0.
2026-06-01 18:07:25 -07:00
Allan Shortlidge 7c47f354b0 Revert "Merge pull request #89436 from hnrklssn/swiftify-trap-source-location"
This reverts commit c223659788, reversing
changes made to 051783ea7c.
2026-05-30 07:13:56 -07:00
Henrik G. Olsson 657a1ef6d3 [SILGen] emit correct line number for macro soucrce location
When creating the SIL source location for a SourceLoc inside a macro
expansion, `getMagicFileIDString` traverses the `GeneratedSourceInfo` to
get the name of the parent source file. The call to
`getPresumedFileAndColumnForLoc` does not do this however, and instead
ends up using the line and column in the macro expansion buffer rather
than in the parent source file. Insert a call to
`getLocInOutermostSourceFile` (which `getMagicFileIDString` uses
internally) to make sure the file name and line number agree on the
source location.

rdar://177664640
2026-05-26 11:14:11 -07:00
Konrad `ktoso` Malawski ab31d297a6 [Concurrency] Remove builtin cancelAsyncTask dead code (#89342)
AFAIR we were using the "enter task cancel cleanup" in async let to
cancel tasks, however this moved to enterAsyncLetCleanup. There is no
uses of the cancel cleanup anymore.

The Task.cancel was using the builtin, but the UnsafeCurrentTask.cancel
was using the normal rutime func, which the builtin would just end up
calling anyway.

I cna't see a reason to keep the builtin path, so let's remove this dead
code.
2026-05-21 23:01:26 -07:00
Pavel Yaskevich b79a051797 [Concurrency] NFC: Rename FunctionTypeIsolation::forIsolatedCaller into forNonisolatedNonsending
Previous refactoring missed this method when the `FunctionTypeIsolation::Kind`
was renamed to `NonisolatedNonsending`.
2026-05-05 09:57:40 -07:00
Meghana Gupta 769c593658 Merge pull request #88729 from meg-gupta/borrowsilgenbug1
Fix call emission of borrow accessors on class let properties
2026-04-30 11:58:16 -07:00
Andrew Trick 645e2dc3ba Merge pull request #88699 from blevine1/pr-175724267-consuming-accessor-resilient-base
[SILGen] Mark +0 base unresolved for consuming accessor
2026-04-30 10:25:10 -07:00
Meghana Gupta 9f0f92104e Fix call emission of borrow accessors on class let properties
In `applyBorrowMutateAccessor()`, the self value was not being passed
to `getFnValue()` for class method dispatch. Fix this by correctly passing
the self value when it is required for dispatch similar to the call emission
of other accessors.
2026-04-28 21:12:18 -07:00
Benjamin Levine 5c5723c557 formatting and fix test note 2026-04-28 13:48:00 -04:00
Benjamin Levine 86999bd9bd avoid duplicate mark_unresolved_non_copyable_value instructions 2026-04-28 13:12:47 -04:00
Konrad Malawski a6617f8801 rename isNonisolatedNonsendingCaller -> isNonisolatedNonsending 2026-04-28 09:21:46 -07:00
Konrad Malawski 2b8026dd94 rename isNonIsolatedCaller -> isNonisolatedNonsendingCaller 2026-04-28 09:21:46 -07:00
Konrad Malawski 003028c17c more rename followups for isNonisolated and the enum change 2026-04-28 09:21:23 -07:00
Konrad Malawski 77ac31d946 Rename to ActorIsolation::Kind::Nonisolated*Concurrent* 2026-04-28 09:21:23 -07:00
Konrad Malawski 3beefe5bd8 Rename CallerIsolationInheriting -> NonisolatedNonsending 2026-04-28 09:21:23 -07:00
Benjamin Levine 4640b58e99 [SILGen] Mark +0 base unresolved for consuming accessor 2026-04-28 02:22:36 -04:00
Andrew Trick c73baf80dd [SILGen] diagnose invalid Builtin.borrowAt usage. 2026-04-23 10:47:43 -07:00
Elsa Keirouz 85671a9599 fix: handle addressable OpaqueValueExprs in SILGen 2026-03-25 09:51:54 +00:00
Kavon Farvardin 0283179142 Merge pull request #86815 from jamieQ/nothrow-to-throws-never-accessor-fix
[SILGen]: some fixes for throws(Never) properties & subscripts
2026-03-23 13:42:27 -07:00
Jamie 9b4dd2add2 [SILGen]: some fixes for throws(Never) properties & subscripts 2026-03-21 10:17:17 -05:00
John McCall bf851fa4dd Model the stack allocation effects of {add,remove}TaskLocalValue.
The biggest complexity here is dealing with the improper nesting of the
allocation for the argument, and I'm not very proud of the solution I found,
but for a one-off builtin, I think it'll work.
2026-03-20 00:21:40 -04:00
Kavon Farvardin 606930c649 Merge pull request #86619 from jamieQ/typed-throws-never-thunk-crash
[SILGen]: fix thunk emission for nothrow to throws(Never)
2026-03-19 08:46:59 -07:00
Pavel Yaskevich 11fbfd5da5 [Concurrency] SE-0434: Member types should get @Sendable together with global-actor isolation
Previously an inner type only got the isolation but not `@Sendable`
when `GlobalActorIsolatedTypesUsability` is enabled, this is incorrect
because with the feature enabled global-actor isolation always implies
`@Sendable` for functions and closures.

Resolves: rdar://problem/171967902
2026-03-09 17:24:59 -07:00
Gábor Horváth 88a9d748ca Merge pull request #86421 from Xazax-hun/bridge-intrusive-ptrs 2026-01-30 19:16:29 +00:00
Gabor Horvath 96ee6eaf18 [cxx-interop] Implicitly bridge annotated smart pointers to reference types
This PR introduces implicit bridging from annotated smart pointers to
reference counted objects to Swift foreign reference types. The bridging
only happens when these smart pointers are passed around by value. The
frontend only sees the Swift foreign reference types in the signature
and the actual bridging happens during SILGen when we look at the
original clang types and note that they differ significantly from the
native types.

The bridging of parameters did not quite fit into the existing structure
of bridging conversions as smart pointers are non-trivial types passed
around as addresses and existing bridging conversions were implemented
for types passed directly.

rdar://156521316
2026-01-28 12:34:21 +00:00
Joe Groff 0f3ddfbcc8 Merge pull request #86545 from jckarter/builtin-borrow
`Builtin.Borrow` implementation
2026-01-26 07:32:31 -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
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
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
Elsa Keirouz d54a572f7f [Sema] desugar ForEachStmt at AST level 2026-01-23 15:17:29 +00:00
Elsa Keirouz 27cef65d56 [AST] Introduce opaque AST nodes 2026-01-23 15:17:28 +00:00
Jamie 8e00755a07 [SILGen]: fix thunk emission for nothrow to throws(Never)
Previously attempting to emit a thunk to wrap a throws(Never) function
within a non-throwing function would crash during SILGen because it was
unconditionally assumed the outer function had an error result. Change
this so that such cases instead create a try_apply and error branch as
they did before, but replace the rethrowing logic in the error branch
with an unreachable instruction.
2026-01-21 06:44:01 -06:00
Tim Kientzle 8eabeeb8ca [SE-0474] Read2/Modify2 => YieldingBorrow/YieldingMutate
This updates a large number of internal symbols, function names,
and types to match the final approved terminology.  Matching the
surface language terminology and the compiler internals should
make the code easier for people to understand into the future.
2026-01-03 16:05:12 -08:00
Slava Pestov 783e1e104c SILGen: Fix edge case where we didn't erase opaque result type in constructor
- Fixes https://github.com/swiftlang/swift/issues/68298.
- Fixes https://github.com/swiftlang/swift/issues/68277.
2025-12-20 16:22:07 -05:00
Meghana Gupta 6f7d420f9d Fix unchecked_conversion insertion for borrow accessors 2025-12-12 11:38:26 -08:00
Adrian Prantl 0e55f81931 Merge pull request #66580 from adrian-prantl/110333983
Make source locations for standard library calls explicit
2025-12-02 08:56:32 -08:00
Slava Pestov 819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Hamish Knight 90bc9a12c7 [SILGen] Add assert to emitApplyAllocatingInitializer
Make sure we reliably assert in release builds if `getBuiltinInitDecl`
passes a null value here.
2025-11-11 15:58:24 +00:00
Slava Pestov 522a6b7c80 SILGen: Fix break/continue inside 'for ... in ... repeat' loop
We were creating the JumpDests too early, so lowering a 'break' or 'continue'
statement would perform cleanups that were recorded while evaluating the
pack expansion expression, which would cause SIL verifier errors and
runtime crashes.

- Fixes https://github.com/swiftlang/swift/issues/78598
- Fixes rdar://131847933
2025-11-10 20:51:45 -05:00
Meghana Gupta 290d2f00a3 Fix mark_unresolved_noncopyable_value instruction introduced for mutate accessor result 2025-11-06 10:55:43 -08:00
Meghana Gupta d50aa8ad87 [NFC] Comment on the use of unchecked_ownership 2025-11-06 10:55:41 -08:00
John McCall a7d7970e29 Turn finishAsyncLet into a builtin.
This is necessary because we need to model its stack-allocation
behavior, although I'm not yet doing that in this patch because
StackNesting first needs to be taught to not try to move the
deallocation.

I'm not convinced that `async let` *should* be doing a stack allocation,
but it undoubtedly *is* doing a stack allocation, and until we have an
alternative to that, we will need to model it properly.
2025-11-03 16:33:40 -08:00
John McCall 1d95fe14de Remove the deprecated and unused startAsyncLet builtin 2025-11-03 13:44:58 -08:00
Slava Pestov 4677512a74 Merge pull request #84664 from jamieQ/fix-iso-default-param-idx-bug
[SILGen]: fix a bug in isolated default argument handling
2025-10-30 03:40:49 -04:00
Meghana Gupta bef207521d Use unchecked_ownership during SILGen of borrow accessors 2025-10-23 05:19:10 -07:00
Meghana Gupta a150c67896 Remove unchecked_ownership_conversion from borrow accessor silgen 2025-10-23 05:19:04 -07:00