Commit Graph

2643 Commits

Author SHA1 Message Date
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
Alexis Laferrière
a8cf1a477f IRGen: Use C compatible representation for @cdecl enums
https://github.com/swiftlang/swift/issues/83738
2025-08-19 13:40:09 -07:00
Alejandro Alonso
9b67867dbb Restrict existential test to just built 2025-08-19 12:34:14 -07:00
Dario Rexin
3c66c17a37 [Test] Disable Interpreter/typed_throws_abi.swift on back deployment runtime
rdar://158442662

This is not supported on back deployment runtimes.
2025-08-18 11:19:29 -07:00
Mykola (Nickolas) Pokhylets
31470bbd1e Merge pull request #82732 from nickolas-pohilets/mpokhylets/weak-let-feature
Wrap SE-0481 into an upcoming feature until source incompatibilities are resolved
2025-08-14 23:59:28 +02:00
Alexis Laferrière
ddb13d1cf3 Tests: Update tests importing AppKit from the SDK to use a local cache
Tests importing AppKit have a tendency to be flaky when they share a
module cache with other builds using a different set of framework search
flags. Make sure they use a local cache, otherwise the compiler can
reuse incompatible cached modules.

Alternatively, we could align all builds using the same cache to have
exactly the same framework search paths or enable explicit module
builds. I picked the module cache as it's the most reliable solution in
the short and long term.

rdar://142949965
2025-08-11 13:57:28 -07:00
Pavel Yaskevich
387b4ff2d3 [CSSimplify] Skip member access on existential checks if base is existential only due to marker protocols
If the base type is composed with marker protocol(s) i.e.
`<<Type>> & Sendable`, let's skip this check because such
compositions are always opened and simplified down to a
superclass bound post-Sema.

Resolves: rdar://148782046
2025-08-04 17:00:48 -07:00
Mykola Pokhylets
89f8f8b9bf Wrap only changes related to the closure frontend logic 2025-08-02 20:24:46 +02:00
Mykola Pokhylets
ae48446716 Wrap SE-0481 into an upcoming feature until source incompatibilities are resolved 2025-08-02 20:24:21 +02:00
Evan Wilde
de23d4b251 FreeBSD: PIC cdecl_official_run.swift Client.o
Swift defaults to PIC everywhere. The Swift toolchain clang emits PIC
relocatable objects by default without passing `-fPIC` on Linux, so the
emitted Client.o is relocatable. This is not the case on FreeBSD, where
clang uses the static relocation model by default resulting in a link
failure due to mixing relocations with non-relocatable objects.

```
ld.lld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
```

Passing `-fPIC` where needed.
2025-07-24 15:08:19 -07:00
Alexis Laferrière
3cfd3f9c32 Tests: Fix missing dylib on device in cdecl_implementation_run.swift
rdar://155529527
2025-07-11 09:34:23 -07:00
Alexis Laferrière
e63a1dea0a Tests: Add missing -target clang flags in @cdecl Interpreter tests
rdar://155013885&155529527
2025-07-10 09:21:31 -07:00
Alexis Laferrière
cb3d82094a Merge pull request #82706 from xymus/cdecl-implementation-tests
Sema: Add `@cdecl @implementation` tests
2025-07-09 09:44:09 -07:00
Alexis Laferrière
38f88efe6d Interpreter: Add @cdecl @implementation test variant 2025-07-07 09:52:27 -07:00
Alexis Laferrière
8cf3a824b6 AST: Fix crash on references to @cdecl enums at code generation
Add related end-to-end test.
2025-07-02 11:25:49 -07:00
Slava Pestov
610887cdb4 Re-enable some tests that were disabled a long time ago 2025-06-25 22:07:23 -04:00
Dario Rexin
61581563c8 [Test] Fix Interpreter/layout_string_witnesses_dynamic.swift
rdar://151476435

Two tests incorrectly assigned values to an uninitialized pointer instead of initializing it. This caused crashes on some distros.
2025-06-16 15:16:46 -07:00
Mykola Pokhylets
de3a87c0ab Merge branch 'main' into mpokhylets/weak-let 2025-05-23 17:26:49 +02:00
Slava Pestov
490edfa523 Merge pull request #81564 from slavapestov/fix-issue-78191
IRGen: Fix miscompile when a generic parameter is fixed to a tuple containing a pack
2025-05-21 00:06:59 -04:00
Anthony Latsis
eafc48fb1a [test] Fix REQUIRES line in test 2025-05-20 12:08:44 +01:00
Dario Rexin
b6e7f96c76 Disable layout_string_witnesses_dynamic.swift
rdar://151476435

The test is currently crashing on Amazon Linux 2, so until we have a solution, we are disabling it.
2025-05-19 18:39:34 -07:00
Slava Pestov
f17baefd7a IRGen: Fix miscompile when a generic parameter is fixed to a tuple containing a pack
If you had something like:

    struct G<T> {
      func f<each U>(_: repeat each U) where T == (repeat each U) {}
    }

We would fulfill 'each U' from the metadata for 'G<(repeat each U)>',
by taking apart the tuple metadata for `(repeat each U)` and forming
a pack.

However this code path was only intended to kick in for a tuple
conformance witness thunk. In the general case, this optimization
is not correct, because if 'each U' is substituted with a
one-element pack, the generic argument of `G<(repeat each U)>` is
just that one element's metadata, and not a tuple. In fact, we
cannot distinguish the one-element tuple case, because the wrapped
element may itself be a tuple.

The fix is to just split off FulfillmentMap::searchTupleTypeMetadata()
from searchTypeMetadata(), and only call the former when we're in
the specific situation that requires it.

- Fixes https://github.com/swiftlang/swift/issues/78191.
- Fixes rdar://problem/135325886.
2025-05-16 17:34:11 -04:00