Commit Graph

2664 Commits

Author SHA1 Message Date
Joe Groff
f627832f94 Merge pull request #86952 from jckarter/type-instantiation-propagate-afd
Runtime: Propagate addressable-for-dependencies bit in generic and resilient type layout.
2026-02-04 08:03:43 -08:00
Joe Groff
8f14c35630 Runtime: Propagate addressable-for-dependencies bit in generic and resilient type layout.
Now that the bit controls `Borrow`'s layout, it must be set properly for runtime-instantiated types.
2026-02-02 18:43:46 -08:00
Ramon Asuncion
156fc69561 [Test][Interpreter] Remove unnecessary REQUIRES: shell from convenience_init_per_delegation 2026-02-01 16:58:27 -05:00
Michael Gottesman
f118042e89 Merge pull request #86829 from gottesmm/pr-ff14cd21e6863ca70bf669d1677136eb30ea259e
[IRGen] Fix crash when getting nonisolated(nonsending) function metadata on older runtimes
2026-01-29 05:36:11 -08:00
Michael Gottesman
223acb337c [IRGen] Fix crash when getting nonisolated(nonsending) function metadata on older runtimes
When compiling for a triple that predates typed throws,
`swift_getFunctionMetadataExtended` is conditionally available and emitted as a
weak external symbol. Previously, when such code ran on a older runtime where
`swift_getFunctionMetadataExtended` was uanvailable, accessing function metadata
for a `nonisolated(nonsending)` function would crash by invoking the null
`swift_getFunctionMetadataExtended`.

This patch adds a runtime null check when emitting metadata accessors for simple
`nonisolated(nonsending)` functions (those without typed throws or other
extended flags) in such situations. If `swift_getFunctionMetadataExtended` is
unavailable at runtime, we fall back to `swift_getFunctionMetadata`, returning
`@concurrent` function metadata instead.

This trade-off is acceptable because:
- Function metadata is not required to call a `nonisolated(nonsending)` function
- This enables use of these functions in frameworks like SwiftUI on older OS versions

Known limitations of the fallback path:
- Dynamic casts between `nonisolated(nonsending)` and `@concurrent` will incorrectly succeed
- Reflection will report `nonisolated(nonsending)` functions as `@concurrent`
- Existential erasure will lose the `nonisolated(nonsending)` attribute

These edge cases will produce obvious crashes during testing if misused, since
`nonisolated(nonsending)` expects its first parameter to be an actor while
`@concurrent` does not. This makes the increased compatibility worth the
trade-off.

rdar://158970802
2026-01-29 00:30:33 -08:00
Dario Rexin
88d3282897 Merge pull request #86764 from drexin/wip-168715030
[IRGen] Don't set HasLayoutString flag on lazy type context descripto…
2026-01-28 01:38:25 -08:00
Dario Rexin
0bbc3b7f07 [IRGen] Don't set HasLayoutString flag on lazy type context descriptor of non-copyable types
rdar://168715030

There was a copyability check missing, that caused the flag to be set for non-copyable types.
2026-01-27 10:49:33 -08:00
Mike Ash
6218178e05 [Test] Mark demangle_retroactive_equatable.swift as requiring executable_test.
rdar://168324883
2026-01-16 17:54:54 -05:00
Slava Pestov
b729fcb85b Merge pull request #86594 from slavapestov/fix-rdar168023786
ASTMangler: Fix incorrect mangling of retroactive conformances to marker protocols
2026-01-16 12:37:43 -05:00
Slava Pestov
f8f48d173c ASTMangler: Fix incorrect mangling of retroactive conformances to marker protocols
We turn off the AllowMarkerProtocols mangler flag when
mangling the types that are passed into the runtime demangler.

The logic in appendAnyProtocolConformance() was wrong when
this flag was set; we would early exit from this function,
but then appendRetroactiveConformances() would still call
appendListSeparator(). The would result in an invalid mangled
string which could not be parsed by the demangler.

In particular, this meant that the recent changes to generalize
Equatable to allow non-Copyable and non-Escapable conformers
could introduce runtime crashes, because a mangled string for
a retroactive conformance to Equatable could be incorrect.

The fix is to handle AllowMarkerProtocols further up in
forEachConditionalConformance().

Note that this change should not directly change ABI, because
AllowMarkerProtocols is on for symbol names.

When AllowMarkerProtocols is on, we still always mangle
conformances to Copyable and Escapable in this code path.

This means that even with this change, mangling a symbol name
that contains a retroactive conformance to Equatable can output
a different string than in Swift 6.3, which means we have an ABI
break. That problem requires a separate fix.

- Fixes rdar://problem/168023786.
2026-01-15 22:11:30 -05:00
Pavel Yaskevich
88905a47a1 [Concurrency] Fix stripConcurrency to strip only global actor isolation
The original condition was removing not just global actor isolation
but any isolation set on the function type. This leads to incorrect
conversions in AST and miscompiles.

Resolves: https://github.com/swiftlang/swift/issues/86332
Resolves: rdar://167712422
2026-01-14 14:51:32 -08:00
Dario Rexin
3906a5b040 [IRGen] Fix direct result type mapping in IRGenThunk::emit
rdar://167636802

The type was not mapped to its native representation before writing it into the combined explosion
2026-01-12 13:31:42 -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
Kavon Farvardin
458b62c9ed introduce UnderscoreOwned feature
This experimental feature allows you to override the default behavior
of a 'get' returning a noncopyable type, so that it returns an owned
value rather than a borrow, when that getter is exposed in opaque
interfaces like protocol requirements or resilient types.

resolves rdar://157318147
2026-01-06 16:39:54 -08:00
Tim Kientzle
104dba920b [SE-0474] Implement yielding borrow and yielding mutate syntax
This does not rename all the internal variables, functions, and types
whose names were based on the old syntax.

I think it adds new syntax support everywhere it's needed while
retaining enough of the old syntax support that early adopters will
see nice deprecation messages guiding them to the new syntax.
2026-01-03 15:07:10 -08:00
Mike Ash
d54bbe84ed [Test] Disable objc_getClass.NotPresent on macOS 10.15.
The test is crashing there, and it's testing runtime behavior that's not going to change on 10.15 at this point.

rdar://162832379
2025-12-19 17:30:28 -05:00
Ryan Mansfield
a7e22a36c8 [test] Mark issue-78598.swift as unsupported on back deployment runtime. 2025-12-08 08:15:10 -05:00
Ryan Mansfield
223fc0895f Merge pull request #85721 from rjmansfield/fix-issue-78598-back-deployment
[Test] Fix Interpreter/issue-78598.swift to work with back deployment
2025-12-04 08:59:56 -05:00
finagolfin
87800caf34 [Test] Mark new Interpreter/issue-85020 test as executable_test (#85790)
Otherwise, various [non-executable CI like Android
fail](https://ci.swift.org/job/oss-swift-package-swift-sdk-for-android/110/console).
2025-12-02 11:21:59 -08:00
Ryan Mansfield
6f739af543 [Test] Fix Interpreter/issue-78598.swift to work with back deployment
The test uses -target %target-swift-5.9-abi-triple which expands to
macOS 14.0, causing the linker to emit chained fixups. Add %no-fixup-chains
to allow the test to run on older OS versions like 10.14.4 that don't
support chained fixups.

rdar://165227305
2025-11-27 11:00:27 -05:00
Clack Cole
d350bc7198 [CSOptimizer] test: Add test case for issue #85020
Overload resolution picks wrong initializer for some metatype arguments

https://github.com/swiftlang/swift/issues/85020
2025-11-21 18:34:04 -07:00
finagolfin
b57012039b [Test] Mark new test as executable_test (#85443)
Otherwise, various [non-executable CI like Android
fail](https://ci.swift.org/job/oss-swift-package-swift-sdk-for-android/75/console).
2025-11-11 17:00:03 -08: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
Mike Ash
7bb9579434 [Runtime] Fix copying in extended existential value witnesses.
Instead of copying the data and the type and witnesses separately, use the size in the value witness table and copy everything at once.

copyTypeInto assumed the type was an ordinary existential. When it was actually an extended existential, it would do an incorrect cast and read part of a pointer as the number of witness tables to copy. This would typically result in a large buffer overflow and crash. At this point we already know the type's size, so we can use that info directly rather than essentially recomputing it.

rdar://163980446
2025-11-07 23:38:09 -05:00
Alexis Laferrière
94113f4a83 SE-496: Remove references to features CDecl and CImplementation 2025-10-29 17:31:20 -07:00
Mike Ash
3a0b3924df Merge pull request #85044 from mikeash/emit-into-client-retain-release
[IRGen][Runtime] Add emit-into-client retain/release calls for Darwin ARM64.
2025-10-28 12:09:01 -04:00
Mike Ash
93fae78e04 [IRGen][Runtime] Add emit-into-client retain/release calls for Darwin ARM64.
This is currently disabled by default. Building the client library can be enabled with the CMake option SWIFT_BUILD_CLIENT_RETAIN_RELEASE, and using the library can be enabled with the flags -Xfrontend -enable-client-retain-release.

To improve retain/release performance, we build a static library containing optimized implementations of the fast paths of swift_retain, swift_release, and the corresponding bridgeObject functions. This avoids going through a stub to make a cross-library call.

IRGen gains awareness of these new functions and emits calls to them when the functionality is enabled and the target supports them. Two options are added to force use of them on or off: -enable-client-retain-release and -disable-client-retain-release. When enabled, the compiler auto-links the static library containing the implementations.

The new calls also use LLVM's preserve_most calling convention. Since retain/release doesn't need a large number of scratch registers, this is mostly harmless for the implementation, while allowing callers to improve code size and performance by spilling fewer registers around refcounting calls. (Experiments with an even more aggressive calling convention preserving x2 and up showed an insignificant savings in code size, so preserve_most seems to be a good middle ground.)

Since the implementations are embedded into client binaries, any change in the runtime's refcounting implementation needs to stay compatible with this new fast path implementation. This is ensured by having the implementation use a runtime-provided mask to check whether it can proceed into its fast path. The mask is provided as the address of the absolute symbol _swift_retainRelease_slowpath_mask_v1. If that mask ANDed with the object's current refcount field is non-zero, then we take the slow path. A future runtime that changes the refcounting implementation can adjust this mask to match, or set the mask to all 1s to disable the old embedded fast path entirely (as long as the new representation never uses 0 as a valid refcount field value).

As part of this work, the overall approach for bridgeObjectRetain is changed slightly. Previously, it would mask off the spare bits from the native pointer and then call through to swift_retain. This either lost the spare bits in the return value (when tail calling swift_retain) which is problematic since it's supposed to return its parameter, or it required pushing a stack frame which is inefficient. Now, swift_retain takes on the responsibility of masking off spare bits from the parameter and preserving them in the return value. This is a trivial addition to the fast path (just a quick mask and an extra register for saving the original value) and makes bridgeObjectRetain quite a bit more efficient when implemented correctly to return the exact value it was passed.

The runtime's implementations of swift_retain/release are now also marked as preserve_most so that they can be tail called from the client library. preserve_most is compatible with callers expecting the standard calling convention so this doesn't break any existing clients. Some ugly tricks were needed to prevent the compiler from creating unnecessary stack frames with the new calling convention. Avert your eyes.

To allow back deployment, the runtime now has aliases for these functions called swift_retain_preservemost and swift_release_preservemost. The client library brings weak definitions of these functions that save the extra registers and call through to swift_retain/release. This allows them to work correctly on older runtimes, with a small performance penalty, while still running at full speed on runtimes that have the new preservemost symbols.

Although this is only supported on Darwin at the moment, it shouldn't be too much work to adapt it to other ARM64 targets. We need to ensure the assembly plays nice with the other platforms' assemblers, and make sure the implementation is correct for the non-ObjC-interop case.

rdar://122595871
2025-10-27 12:00:28 -04:00
Joe Groff
b219d4089c Merge pull request #85077 from jckarter/moveonly-after-definit-cleanup
DI: Place cleanups for partially-initialized non-`Copyable` values on the `mark_unresolved_noncopyable` marker.
2025-10-24 07:33:30 -07:00
Kavon Farvardin
19bd65c89b OpaqueValues: add support for property wrappers
resolves rdar://163071245
2025-10-23 16:31:01 -07:00
Joe Groff
ff627e5392 DI: Place cleanups for partially-initialized non-Copyable values on the mark_unresolved_noncopyable marker.
This ensures that move checking sees the cleanups when determining a value's lifetime and doesn't
try to insert its own cleanup leading to a double destroy. Fixes #85063 | rdar://163194098.
2025-10-23 13:11:19 -07:00
Alejandro Alonso
bc04d6dcf7 Don't check suppressed protocols when the extended existential is metatype constrained 2025-10-15 10:57:52 -07:00
Henrik G. Olsson
cbc0ec3b88 Add -verify-ignore-unrelated where necessary (NFC)
These are tests that fail in the next commit without this flag. This
does not add -verify-ignore-unrelated to all tests with -verify, only
the ones that would fail without it. This is NFC since this flag is
currently a no-op.
2025-10-04 14:19:52 -07:00
Alejandro Alonso
2b00d3f123 Correctly sext instead of zext for negative integer types 2025-10-02 10:27:44 -07:00
Michael Gottesman
c2f19625c7 [reference-bindings] Disable a test when we backdeploy.
This is an experimental feature that is not being actively worked on. Disable
the test when we backwards deploy for now to fix the bots. I am not deleting the
test since it seems to be working on the main bots and it makes sense to at
least keep that going to prevent further breakage.

rdar://159026031
2025-10-01 11:58:08 -07:00
Erik Eckstein
2f124cf564 Remove the -enable-ossa-modules option.
OSSA modules are enabled by default.
The compiler still accepts this option but it has no effect.
2025-09-26 08:01:08 +02:00
Alexis Laferrière
9ec824c20b Parser: Rename the experimental attribute @cdecl to @c
There's no users of `@cdecl` yet so we can do a direct rename. The
legacy `@_cdecl` remains unaffected.
2025-09-19 11:55:07 -07:00
Alexis Laferrière
8e8ae6a301 Merge pull request #84331 from xymus/fix-cdecl-run-test-back-compat
Tests: Allow Interpreter/cdecl_official_run.swift to run on older OSes
2025-09-17 09:08:21 -07:00
Alexis Laferrière
2a2a188e41 Tests: Allow Interpreter/cdecl_official_run.swift to run against older OSes
rdar://160448792
2025-09-16 13:29:47 -07:00
Yuta Saito
2b6ea81b9e Merge pull request #84285 from kateinoigakukun/yt/fix-tagged-funcptr
[Legacy Driver][wasm] Pass `--table-base` to reserve low function addresses
2025-09-16 08:26:04 +09:00
Yuta Saito
5431bb115b [test][wasm] Add test to kill the missing func addr reservation 2025-09-15 14:30:10 +00:00
Erik Eckstein
ddea9f6aa0 Optimizer: switch to the new ConstantCapturePropagation pass in the pass pipeline 2025-09-04 08:15:46 +02:00
Dario Rexin
c38db438b2 Merge pull request #83922 from drexin/wip-159143492
[IRGen] Fix computation of spare bits for fixed arrays
2025-08-29 09:21:50 -07:00
Mike Ash
788e3c0138 Merge pull request #83948 from mikeash/objc-getclass-test-availability
[Test] Gate newer objc_getClass tests on OS version.
2025-08-28 20:04:50 -04:00
Dario Rexin
81af291c4f [IRGen] Fix computation of spare bits for fixed arrays
rdar://159143492

Previously all bits after the spare bits of the first element were marked as spare bits. This caused enum tags to be stored in bits used by the payload.
2025-08-28 12:27:40 -07:00
Mike Ash
45f795240e Merge pull request #83951 from mikeash/builtin-bridge-object-test-fix
[Test] Don't test builtin_bridge_object.swift on older OSes.
2025-08-27 18:17:45 -04:00
Dario Rexin
69cafe42a3 Merge pull request #83837 from drexin/wip-157795547
[IRGen] Do not set HasLayoutString flag for non-copyable types requir…
2025-08-27 13:58:59 -07:00
Mike Ash
d82c6a20d5 [Test] Don't test builtin_bridge_object.swift on older OSes.
This test sets a specific target triple which is too new for some older OSes. There's no need to run this test in back-deployment testing, so make it only run when testing a fresh-built runtime.

rdar://159026118
2025-08-27 12:37:19 -04:00
Mike Ash
e1fff8127e [Test] Gate newer objc_getClass tests on OS version.
The last two tests in the NotPresent test check for fixes that went into 5.3. Testing these against earlier runtimes will fail. Add availability checks so we only test when the fix is present.

While we're here, switch the symbolic references test to use indirect references. Direct references are very likely to pass the test even without the fix, as the reference is likely to point to readable memory. Indirect references make this much more likely to crash by then reading and dereferencing a pointer from the memory the relative pointer points to.

rdar://159034772
2025-08-27 11:53:06 -04:00
Dario Rexin
67d0a22e2f [IRGen] Do not set HasLayoutString flag for non-copyable types requiring metadata instantiation
rdar://157795547

When types contain stored properties of resilient types, we instantiate their metadata at runtime. If those types are non-copyable, they won't have layout strings, so we must not set the flag.
2025-08-20 17:12:59 -07:00
Alexis Laferrière
7642d410af Merge pull request #83814 from xymus/cdecl-enum-layout
IRGen: Use C compatible representation for `@cdecl` enums
2025-08-20 10:39:09 -07:00