Commit Graph

7433 Commits

Author SHA1 Message Date
Yuta Saito
8748213d52 Merge pull request #85524 from kateinoigakukun/yt/fix-non-reg2mem-rle-crash 2025-11-16 23:10:20 +09:00
Yuta Saito
fba5c9d1a3 test: Skip test/IRGen/moveonly_value_functions.swift for Wasm archs 2025-11-15 19:29:56 +00:00
Doug Gregor
a1ce6e66df Merge pull request #85498 from DougGregor/retain-calling-convention-from-c
Retain the Swift calling convention when it's on an imported C declaration
2025-11-13 21:40:03 -08:00
Doug Gregor
7517425398 Update test for Windows 2025-11-13 16:35:02 -08:00
Doug Gregor
e0139bcc0c Retain the Swift calling convention when it's on an imported C declaration
Fixes #69264.
2025-11-13 11:34:01 -08:00
Doug Gregor
669f6dc83f Merge pull request #85463 from DougGregor/autolink-multithreaded-ir
[Multi-threaded IRGen] Ensure that autolink info gets into each object file
2025-11-12 16:43:37 -08:00
Doug Gregor
cc78bb5ebf [Multi-threaded IRGen] Ensure that autolink info gets into each object file
When performing multi-threaded IRGen, all of the link libraries used
for autolinking went (only) into the first object file. If the object
files were then placed in a static archive, the autolinking would only
kick in if clients that link the static library reference something in
the first object file. This causes link failures.

Make sure that we put the autolink information into each of the object
files we create when doing multi-threaded IRGen.

Fixes the rest of rdar://162400654.
2025-11-12 11:37:19 -08:00
Doug Gregor
2002b90531 Merge pull request #85425 from DougGregor/irgen-multithreaded-lazy-global-var
[IRGen] Correctly assign lazily-emitted global variables in multi-threaded IRGen
2025-11-11 13:10:00 -08:00
Doug Gregor
bce3fa000b [IRGen] Correctly assign lazily-emitted global variables in multi-threaded IRGen
With multi-threaded IRGen, the global variables associated with "once"
initialization tokens were not getting colocated with their actual
global variables, which caused the initialization code to get split
across different files. This issue manifest as autolinking errors in
some projects.

Fixes rdar://162400654.
2025-11-10 23:08:57 -08:00
Slava Pestov
29202436ca Try to fix test/IRGen/fulfillment_map_key_equality.swift for 32-bit targets 2025-11-10 13:45:36 -05:00
Michael Gottesman
4d48b9ac78 Disable a test on 32 bit to unblock CI. 2025-11-10 10:24:03 -08:00
Doug Gregor
087aee833f Merge pull request #85396 from DougGregor/se-0497-export
[SE-0497] Implement @export attribute syntax
2025-11-08 23:46:06 -08:00
Mike Ash
cc8e6fd877 Merge pull request #85260 from mikeash/client-rr-library-rename
[Runtime] Rename ClientRetainRelease library to SwiftDirectRuntime.
2025-11-08 12:40:27 -05:00
Slava Pestov
e5e79486e0 Merge pull request #85357 from slavapestov/workaround-rdar160649141
IRGen: Terrible workaround for problem in searchNominalTypeMetadata()
2025-11-08 05:10:53 -05:00
Doug Gregor
020b69d4b6 [SE-0497] Implement @export attribute syntax
Implement the @export(implementation) and @export(interface) attributes
to replace @_alwaysEmitIntoClient and @_neverEmitIntoClient. Provide a
warning + Fix-It to start staging out the very-new
@_neverEmitIntoClient. We'll hold off on pushing folks toward
@_alwaysEmitIntoClient for a little longer.
2025-11-07 22:00:40 -08:00
Slava Pestov
1adfad0df2 IRGen: Terrible workaround for problem in searchNominalTypeMetadata()
This fixes a regression introduced by e3c8f423bc,
but the root cause was actually a subtle invariant violation
in IRGen.

FulfillmentMap's use of canonical types as keys assumes that
canonical type equality is sufficient for checking if two types
"are the same". However, this is not true when those types
contain type parameters, because two distinct type parameters
might belong to the same equivalence class.

Thus, when we take the type's context substitution map, and
apply it to each type parameter in our given list of
requirements, the substitution operation could output a
different but equivalent type parameter.

As a workaround for this problem, try to preserve the old
behavior of subst() in this specific case.

Fixes rdar://160649141.
2025-11-07 18:26:30 -05:00
Mike Ash
1898b01ce6 [Runtime] Rename ClientRetainRelease library to SwiftDirectRuntime.
This library will likely become home to other fast-path-in-client functions, so give it a more general name.
2025-11-07 16:36:29 -05:00
eeckstein
552b665a9e Merge pull request #85334 from eeckstein/mandatory-destroy-hoisting
Optimizer: make destroy hoisting a mandatory pass
2025-11-07 06:45:03 +01:00
Doug Gregor
66e7a783a6 Merge pull request #85370 from DougGregor/extern-global-variables 2025-11-06 21:40:24 -08:00
Michael Gottesman
a302d4e627 Merge pull request #85224 from gottesmm/pr-6cb303a9f5f15489fa44c26d00c70155a6d7cc97
[concurrency] Create builtins for invoking specific concurrency runtime functions.
2025-11-06 20:33:16 -08:00
Erik Eckstein
62786b01e2 Optimizer: add the mandatory destroy hoisting pass
It hoists `destroy_value` instructions for non-lexical values.

```
  %1 = some_ownedValue
  ...
  last_use(%1)
  ... // other instructions
  destroy_value %1
```
->
```
  %1 = some_ownedValue
  ...
  last_use(%1)
  destroy_value %1    // <- moved after the last use
  ... // other instructions
```

In contrast to non-mandatory optimization passes, this is the only pass which hoists destroys over deinit-barriers.
This ensures consistent behavior in -Onone and optimized builds.
2025-11-06 21:00:44 +01:00
Doug Gregor
5b642f548f Extend @_extern to global and static variables
Allow external declaration of global variables via `@_extern(c)`. Such
variables need to have types represented in C (of course), have only
storage (no accessors), and cannot have initializers. At the SIL
level, we use the SIL asmname attribute to get the appropriate C name.

While here, slightly shore up the `@_extern(c)` checking, which should
fix issue #70776 / rdar://153515764.
2025-11-06 11:09:31 -08:00
Arnold Schwaighofer
05a32161de Merge pull request #85220 from nate-chandler/test/20251030/1
[Test] Fix these arm64e check lines.
2025-11-05 16:28:13 -08:00
Michael Gottesman
97b0e2ebae [concurrency] Create builtins for invoking specific concurrency runtime functions.
Specifically:

1. swift_task_addCancellationHandler
2. swift_task_removeCancellationHandler
3. swift_task_addPriorityEscalationHandler
4. swift_task_removePriorityEscalationHandler
5. swift_task_localValuePush
6. swift_task_localValuePop

rdar://109850951
2025-11-05 11:03:44 -08:00
John McCall
13937fdb4e Merge pull request #84528 from rjmccall/async-let-runtime-realism
Model async let begin/finish as builtins in SIL
2025-11-05 10:24:46 -08:00
Arnold Schwaighofer
a38adb3a20 Merge pull request #85207 from nate-chandler/general-coro/20251023/1
[CoroutineAccessors] Use typed-malloc.
2025-11-04 09:41:01 -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
Anthony Latsis
b0548203e2 [test] Clean up a few more nocapture in tests 2025-11-02 08:28:54 +00:00
Alexis Laferrière
048c9276a9 Merge pull request #85122 from xymus/official-c-attr
SE-495: Make `@c` an official feature
2025-10-30 16:06:25 -07:00
Nate Chandler
b594b82c62 [Test] Fix these arm64e check lines. 2025-10-30 11:49:13 -07:00
Nate Chandler
e0ead75622 [CoroutineAccessors] Use typed-malloc. 2025-10-30 03:59:18 -07:00
Alexis Laferrière
94113f4a83 SE-496: Remove references to features CDecl and CImplementation 2025-10-29 17:31:20 -07:00
Anthony Latsis
e0ca132af2 Merge pull request #85102 from swiftlang/jepa-main2
[test] Remove pre-rebranch `nocapture` matches
2025-10-29 22:21:38 +00:00
Yuta Saito
3e834ccf9f Merge pull request #85106 from kateinoigakukun/yt/fix-dead-stub-comdat-wasm
[wasm][IRGen] Stop attaching COMDATs to dead stub methods
2025-10-29 15:29:48 +09:00
Yuta Saito
50298bd8e5 [wasm][IRGen] Stop attaching COMDATs to dead stub methods
When generating dead stub methods for vtable entries, we should not
attach COMDATs to their definitions. This is because such stubs may be
referenced only through aliases, and the presence of a COMDAT on the
stub definition would cause the aliased symbol, we want to keep, to be
discarded from the symbol table when other object files also have a
dead stub method.

Given the following two object files generated:

```mermaid
graph TD
    subgraph O0[A.swift.o]
        subgraph C0[COMDAT Group swift_dead_method_stub]
            D0_0["[Def] swift_dead_method_stub"]
        end
        S0_0["[Symbol] swift_dead_method_stub"] --> D0_0
        S1["[Symbol] C1.dead"] --alias--> D0_0
    end

    subgraph O1[B.swift.o]
        subgraph C1[COMDAT Group swift_dead_method_stub]
            D0_1["[Def] swift_dead_method_stub"]
        end
        S0_1["[Symbol] swift_dead_method_stub"] --> D0_1
        S2["[Symbol] C2.beef"] --alias--> D0_1
    end
```

When linking these two object files, the linker will pick one of the
COMDAT groups of `swift_dead_method_stub`. The other COMDAT group will be
discarded, along with all symbols aliased to the discarded definition,
even though those aliased symbols (`C1.dead` and `C2.beef`) are the
ones we want to keep to construct vtables.

This change stops attaching COMDATs to dead stub method definitions.
This effectively only affects WebAssembly targets because MachO's
`supportsCOMDAT` returns false, and COFF targets don't use
`linkonce_odr` for dead stub methods.

The COMDAT was added in 7e8f782457
2025-10-29 01:17:38 +00: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
Nate Chandler
042579b010 [IRGen] Address-discriminate these ptrauth ents.
They are stored at an address so that address should be used to
strengthen auth.
2025-10-27 16:09:53 -07:00
Nate Chandler
df273d6f28 [IRGen] Fix copy/paste error.
The schemas for the coro frame de/alloc functions were incorrectly not
being assigned and instead the non-frame de/alloc functions were being
assigned twice.  Fix that and add more tests.

rdar://163330882
2025-10-27 15:24:51 -07: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
Meghana Gupta
7e8d8b671f Merge pull request #85097 from meg-gupta/withdiagpr
Update borrow accessor diagnostics and synthesis
2025-10-24 15:06:19 -07:00
Kuba (Brecka) Mracek
eb23d3bc0a Merge pull request #85074 from kubamracek/section
SE-0492: Stabilize @_section/@_used into @section/@used
2025-10-24 12:29:48 -07:00
Meghana Gupta
a71dbc6d95 [NFC] Enable CHECK-IRGEN lines in a borrow accessor test 2025-10-24 04:29:53 -07:00
nate-chandler
9069d32078 Merge pull request #85055 from nate-chandler/general-coro/20251016/1
[CoroutineAccessors] Provide frame to de/allocation functions.
2025-10-23 20:17:52 -07:00
Anthony Latsis
b5aec4cc34 [test] Remove pre-rebranch nocapture matches
These were added in https://github.com/swiftlang/swift/pull/81375 (and
several other follow-up PRs because we missed a few places) and
are no longer needed.
2025-10-24 02:07:22 +01:00
Kuba Mracek
b47227b57b Remaining test a code fixes for @_section->@section rename 2025-10-23 08:43:42 -07:00
Nate Chandler
cdf9f9d58b [CoroutineAccessors] Forward frame to de/alloc fns
Pass the frame from the outer yield_once_2 coroutine into the
swift_coro_de/alloc functions and from there into all four de/allocation
witnesses.  This enables ABIs which key off of information stored in the
frame.
2025-10-22 21:00:17 -07:00
Nate Chandler
76881b1d52 [CoroutineAccessors] Add frame de/alloc functions.
To enable ABIs which store extra info in the frame, add two new slots to
the coroutine allocator function table.  For example, a frame could have
a header containing a context pointer at a negative offset from the
address returned from `swift_coro_alloc_frame`.  The frame deallocation
function would then know to deallocate more space correspondingly.
2025-10-22 21:00:17 -07:00
Kuba Mracek
adeb40f261 SE-0492: Stabilize @_section/@_used into @section/@used
Removes the underscored prefixes from the @_section and @_used attributes, making them public as @section and @used respectively. The SymbolLinkageMarkers experimental feature has been removed as these attributes are now part of the standard language. Implemented expression syntactic checking rules per SE-0492.

Major parts:
- Renamed @_section to @section and @_used to @used
- Removed the SymbolLinkageMarkers experimental feature
- Added parsing support for the old underscored names with deprecation warnings
- Updated all tests and examples to use the new attribute names
- Added syntactic validation for @section to align with SE-0492 (reusing the legality checker by @artemcm)
- Changed @DebugDescription macro to explicitly use a tuple type instead of type inferring it, to comply with the expression syntax rules
- Added a testcase for the various allowed and disallowed syntactic forms, `test/ConstValues/SectionSyntactic.swift`.
2025-10-22 16:05:39 -07:00
Nate Chandler
f8666b164b [CoroutineAccessors] Pass cator to allocation fns.
Doing so enables allocators to contain additional context for use by
allocation functions.  Because the allocator is already passed to
_swift_coro_alloc, on the fast path (no allocator, popless) no
allocation function is used, and the allocator is passed in the
swiftcoro register, this is cheap.
2025-10-22 10:59:09 -07:00
Allan Shortlidge
16dee385bf AST/Basic: Introduce the StandaloneSwiftAvailability experimental feature.
This experimental feature will be used to force the compiler to treat `Swift`
runtime availability as separate from platform availability when compiling for
targets that have the Swift runtime built-in.
2025-10-21 21:55:24 -07:00