Commit Graph

7469 Commits

Author SHA1 Message Date
Meghana Gupta
b75eac9836 Use @guaranteed result convention for borrow accessors returning trivial types 2026-01-30 14:29:06 -08:00
Dario Rexin
21fbc94a75 Merge pull request #86858 from drexin/wip-borrow-accessors
[IRGen] Return large loadable types as @guaranteed_address
2026-01-30 09:17:30 -08:00
Dario Rexin
6af54cd164 [IRGen] Return large loadable types as @guaranteed_address
rdar://167713693

The LoadableByAddress pass recognizes large loadable types in borrow accessors and returns them by @guaranteed_address.
This prevents stack allocations and unnecessary copies.

Co-authored-by: Meghana Gupta <meghana_gupta@apple.com>
2026-01-29 13:33:47 -08: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
Joe Groff
2423a6364c IRGen: Support for fixed-layout borrows. 2026-01-23 08:02:09 -08:00
Joe Groff
5f49668577 Builtin.dereferenceBorrow should maintain the memory location of addressable values. 2026-01-23 08:02:09 -08:00
Erik Eckstein
18063707b5 Optimizer: enable complete OSSA lifetimes throughout the pass pipeline
This new OSSA invariant simplifies many optimizations because they don't have to take care of the corner case of incomplete lifetimes in dead-end blocks.

The implementation basically consists of these changes:
* add the lifetime completion utility
* add a flag in SILFunction which tells optimization that they need to run the lifetime completion utility
* let all optimizations complete lifetimes if necessary
* enable the ownership verifier to check complete lifetimes
2026-01-22 17:41:48 +01: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
Erik Eckstein
e3e8c24201 SIL: add the infinite_loop_true_condition builtin
The value of the builtin is true, but the compiler doesn't know.
This builtin is used to break infinite loops.
2026-01-22 17:41:23 +01:00
Hiroshi Yamauchi
867bd732b2 Fix swift tests for Windows ARM64 (#86558) 2026-01-21 16:08:58 -08:00
Yuta Saito
e1e99e896f Merge pull request #86624 from kateinoigakukun/yt/enable-aggressive-reg2mem
[wasm] Enable aggressive reg2mem optimization
2026-01-20 20:13:10 +09:00
Yuta Saito
fa58351169 Revert "Merge pull request #77509 from aschwaighofer/disable_test_wasm"
This reverts commit 17ab8977fd, reversing
changes made to 828fff5eb6.
2026-01-19 18:27:54 +09: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
Aidan Hall
d1811937ed Merge pull request #86013 from aidan-hall/generated-function-names
Create closure destructors with internal linkage
2026-01-13 10:45:59 +00: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
Slava Pestov
d09c773536 IRGen: Fix yet another typed throws crash
- Fixes https://github.com/swiftlang/swift/issues/86347.
2026-01-08 14:20:42 -05:00
Aidan Hall
f167273086 Create HeapLayout destructors with internal linkage
This makes these symbols visible in backtraces, at the cost of binary size.

The long-term goal is to generate these functions with LinkOnceODRLinkage, using
the contents of the HeapLayout to produce a mangled name, so they can be
deduplicated across modules.

In order to make the symbols more meaningful when they appear in backtraces,
use the name parameter passed to emitUnmanagedAlloc to produce a destructor name
with the format __swift_{name}_destructor.

rdar://149084103
2026-01-06 15:30:06 +00: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
Dario Rexin
1f8e88d659 Merge pull request #85908 from drexin/wip-163631865
[IRGen] Use proper linkage for async function pointers to partial app…
2025-12-11 09:52:51 -08:00
Dario Rexin
0fdca11e46 [IRGen] Use proper linkage for async function pointers to partial apply forwarders
rdar://163631865

Under certain circumstances the same symbol can be used for different implementations of the forwarders.
The forwarders themselves are already emitted with "internal" LLVM linkage, but some particularities in
the mapping from SILLinkage to LLVM linkage caused async function pointers to partial apply forwarders
to be emitted with linkonce_odr instead, which caused the wrong forwarder to be called at runtime, causing
unexpected behavior and crashes.
2025-12-08 11:30:22 -08:00
Ben Cohen
58f661cfba Allow Equatable: ~Escapable (#85854)
Adds `~Escapable` to #85746
2025-12-08 09:50:50 -08:00
Dan Blackwell
161d00f803 [Sanitizers] Add support for -sanitize=memtag-stack (#85515)
This sanitizer adds MTE (memory tagging extension) checks to stack
variable accesses. Enablement simply requires setting an attribute on
function definitions, and the instrumentation is added by LLVM.

The corresponding swift-driver change is at:
https://github.com/swiftlang/swift-driver/pull/2016.

rdar://161721201
2025-12-05 08:51:42 +00:00
Michael Gottesman
e1cc41a372 [irgen] Add test for b6dfb30f1e.
This is a new file I added and while cleaning up my commit tree, it got dropped.
Just committing it separately now.
2025-12-03 12:42:39 -08:00
Ben Cohen
fbb420f38d Allow Equatable: ~Copyable (#85746)
Under review
[here](https://forums.swift.org/t/se-0499-support-copyable-escapable-in-simple-standard-library-protocols/83297).
Multi-part version of #85079.
2025-12-03 05:45:38 -08:00
Kavon Farvardin
1f696739ef Merge pull request #85450 from kavon/keypath-metadata-fix
IRGen/ABI: fix count of requirements in getAddrOfGenericEnvironment
2025-12-02 03:23:49 -08:00
Kavon Farvardin
38af19b95a IRGen/ABI: fix count of requirements in getAddrOfGenericEnvironment
`irgen::addGenericRequirements` will later filter out Copyable
and Escapable requirements, so this field's count isn't accurate
if it's using the pre-filtered number.

This should in theory only affect the metadata emission for keypaths,
specifically, the caller `IRGenModule::getAddrOfKeyPathPattern`.
2025-12-01 15:07:34 -08:00
Ryan Mansfield
625458d5d7 [Test] Add missing .ptrauth patterns to test/IRGen/builtins.swift
Add optional .ptrauth suffix patterns for arm64e pointer authentication.
2025-11-22 14:11:56 -05:00
Xi Ge
be5d4b3747 Merge pull request #85600 from nkcsgexi/159408187
OriginallyDefinedIn: always use 1.0 as the starting platform version for $ld$previous directives
2025-11-20 14:33:03 -08:00
Xi Ge
db1b398ea0 OriginallyDefinedIn: always use 1.0 as the starting platform version for $ld$previous directives
Before this change, we were sometimes using introductory platform version as the starting version where
a symbol is considered belonging to the original binary. However, this is insufficient
because backdeploying to a platform version prior to a symbol's introductory version can happen. When it
happens, we should expect the moved symbol to be found in the moved-from library, not the moved-to one. Expecting
the symbol to be found in the moved-to library can lead to crasher.

Resolves: rdar://159408187
2025-11-20 09:19:28 -08:00
Arnold Schwaighofer
d0df11069f Merge pull request #85595 from aschwaighofer/irgen_specialized_metadata_vw_nested_types
IRGen: Detect nested generic types during generation of the vwt of specialized metadata
2025-11-20 08:24:26 -05:00
Arnold Schwaighofer
9b7dafbcb1 Test case 2025-11-19 11:26:49 -08:00
Dario Rexin
7b02395192 Merge pull request #85566 from drexin/wip-163794474
[Test] Make IRGen/coroutine_accessors.swift more resilient against co…
2025-11-19 08:27:02 -08:00
Dario Rexin
c7aa2df73e [Test] Fix test/IRGen/builtins.swift for arm64e
rdar://164236484

Added optional .ptrauth suffix to make the test pass on arm64e
2025-11-18 11:56:06 -08:00
Dario Rexin
a8bddeedb8 [Test] Make IRGen/coroutine_accessors.swift more resilient against code gen changes
rdar://163794474

The sequence number in duplicate symbol names is not relevant for the test, so we should not check for the specific number
2025-11-18 11:41:57 -08:00
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