Commit Graph

13339 Commits

Author SHA1 Message Date
Mike Ash
3d15cdea45 Merge pull request #86963 from mikeash/direct-runtime-new-build-fixes
[Runtime] Always look for the SwiftDirect package in the new Runtime build.
2026-02-05 14:32:13 -05:00
Kavon Farvardin
006a0a494a Reparenting: require an extension
This change forces you to write ``@reparented` relationships
on an extension of a protocol, rather than on the protocol
itself.

The ProtocolConformance needs to be associated with some
GenericContext and IRGen expects it to be an ExtensionDecl.
That environment defines under what conditions the conformance
exists. We also need to define witnesses for the new parent's
requirements in an extension anyway, so it's a natural fit.

The previous workaround for this was kind of awful, as it'd
require searching all the protocol's extensions and "guess"
which extension they want to represent the conformance. While
we could try to synthesize an extension, there's two
challenges there:

1. Due to SuppressedAssociatedTypes, it's not so simple to
synthesize an unconstrained ExtensionDecl.
2. We currently rely on same-type requirements to pin the
associated types to particular witnesses of those requirements
in the extension. So it's not purely unconstrained! For example,

```
extension Seq: @reparented BorrowSeq where Iter == MyIter {}
```

The constraints that are disallowed (but not yet diagnosed)
are conditional conformance requirements, as the default
conformance for a reparenting cannot depend on those.

Thus, it's better that programmers to specify the extension.
2026-02-03 16:40:21 -08:00
Kavon Farvardin
ed65f8bb55 Mangling: support Self in associated conformance descriptor
For reparenting, we rely on a default associated conformance witness accessor
to build the witness table for 'Self: NewParent' at runtime. This means that
when mangling the symbol for such a descriptor, we need support for there
being no associated type at all; it's just tau_0_0 aka Self as the subject.

This patch extends _default_ associated conformance witness accessor mangling
to support a GenericTypeParamType for the subject, as the non-default accessors
already quietly did have support; see `mangleAssociatedConformanceDescriptor`.
It was quiet in the sense that there was no demangling support for it, nor
documentation about it either. So I've brought both kinds of witness accessor
manglings up-to-par, without extending the `assoc-type-name` grammar itself.
2026-02-03 16:39:19 -08:00
Kavon Farvardin
eb7fe3c8a3 Reparenting: initial functionality 2026-02-03 16:39:19 -08:00
Mike Ash
85d1ac02de [Runtime] Always look for the SwiftDirect package in the new Runtime build.
Remove the SwiftCore_ENABLE_DIRECT_RETAIN_RELEASE option and the corresponding option from the various subprojects. Instead, unconditionally find_package(SwiftSwiftDirectRuntime) but without REQUIRED. We expect that if the compiler is emitting DirectRuntime calls, the library will be available, so there's no need to configure that separately.

Also refine the check for HasSwiftSwiftDirectRuntimeLibrary to exclude DriverKit.
2026-02-03 13:07:37 -05:00
Felipe de Azevedo Piovezan
92191a0f4a Merge pull request #86936 from felipepiovezan/felipe/coro_line_table_issue
[IRGenSIL][DebugInfo] Fix location of Coroutine/Async exit code
2026-02-03 17:35:00 +00:00
Felipe de Azevedo Piovezan
ecaa1011ca [IRGenSIL][DebugInfo] Extend lifetime of variables in coroutines
Just like in async functions, coroutines will go through the CoroSplit
flow. As such, variables in O0 need to go through the same treatment
they undergo for async functions: an `asm` directive is emitted so to
create a use of the variable after each split point.
2026-02-02 17:33:11 +00:00
Felipe de Azevedo Piovezan
e14ff72d70 [IRGenSIL][DebugInfo] Fix location of Coroutine/Async exit code
Exit code should not inherit the location of the previous basic block;
instead, it should contain line zero to denote that this is not
associated with any user code.

Without this patch, stepping over code code like:

```
1. yielding mutate {
2.   yield &member_int
3.   blah
4.   blah
}
```

Would go from line 3, to line 4, to line 2.

rdar://149106144
2026-02-02 15:20:13 +00:00
Felipe de Azevedo Piovezan
80fc0e8b63 [IRGenSIL][NFC] Rewords comments and reduce scope of variables
These comments were verbose and too personal, making it hard to
understand the point being made.

Some comments were duplicated.

Some comments could be merged by placing them where they are relevant.
2026-02-02 15:18:18 +00:00
Felipe de Azevedo Piovezan
1e00daa140 Merge pull request #86810 from felipepiovezan/felipe/simplify_debug_info_logic
[DebugInfo] Reword location heuristic to address yielding accessor location problem
2026-02-02 10:42:12 +00: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
Felipe de Azevedo Piovezan
cafb8bba51 [IRGenSIL][NFC] Remove old DebugInfo workaround that is no longer needed
SILDebugScopes should now be properly serialized.
2026-01-30 16:29:28 +00:00
Felipe de Azevedo Piovezan
15e6fc5cbb [IRGenSIL][NFCI] Further simplify DebugInfo location logic
When lowering an instruction, the intended logic seems to be:

1. If `I` does not contains a cleanup location, use that.
2. If `I` has a cleanup location, but there are other "normal" locations
   afterwards, use the previous instruction location to avoid jumps in the line
   table (unless there was no location).
3. Otherwise (`I` has a cleanup location and it's all cleanup locations
   afterwards), use the location of the last instruction in the BB.

This is currently expressed in a very convoluted way. This patch
simplifies it.
2026-01-30 16:29:28 +00:00
Felipe de Azevedo Piovezan
559d9e5b50 [DebugInfo] Fix return debug location of borrowing accessor's second funclet
When the main IRGenSIL loop decides to use the previous instruction's
location, it does so by emitting a compiler generated location. This is
creating an issue where the return address of a borrowing accessor is
landing on such a cleanup location, making the parent frame have no line
associated with it.

Why not use the last instruction's location instead? No tests fail with
this change, and it seems to keep the literal meaning of the "use the
last location" boolean variable that already exists in code.
2026-01-30 16:29:28 +00: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
Felipe de Azevedo Piovezan
2243cf1a78 [DebugInfo][NFC] Factor out DebugInfo in main IRGenSIL loop
There is a lot of stateful code in the middle of the main IRGenSIL loop
that makes it really hard to understand what is going on. This commit is
a very modest attempt at reducing the cognitive burden in this area by:

1. Moving it out to a helper function
2. Removing one of the stateful booleans, as it can be re-computed from
   the previous instruction.

The hope is that, with this patch, we can reason a bit better about the
"CleanupLocation" situation, though even in the new state it is hard to
spot redundant code.
2026-01-29 10:37:54 +00: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
Alejandro Alonso
b1a1576429 Merge pull request #86828 from Azoy/borrow-promotion
[SILOptimizer] Add instruction simplifications for init_borrow_addr, dereference_borrow, and dereference_addr_borrow
2026-01-28 09:59:45 -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
Alejandro Alonso
9f95dc7695 Simplify init_borrow_addr when the borrow type is statically known
make sure we register as well as add test
2026-01-27 11:03:53 -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
Alejandro Alonso
632d6f4257 WIP: Dependent borrow layout 2026-01-23 08:02:10 -08:00
Joe Groff
2423a6364c IRGen: Support for fixed-layout borrows. 2026-01-23 08:02:09 -08:00
Joe Groff
2f02c7cda3 SIL: Introduce instructions for forming and dereferencing Builtin.Borrow.
Since after address lowering, `Borrow` can remain loadable with a known-
layout address-only referent, we need instructions that handle three
forms:

- borrow and referent are both loadable values
- borrow is a value, but referent is address-only
- borrow and referent are both address-only
2026-01-23 08:02:01 -08:00
Joe Groff
bc166d5a8c Add a Builtin.Borrow type.
This will represent the layout of a borrow of a value.
2026-01-23 07:46:50 -08:00
Arnold Schwaighofer
e6ea70720c Merge pull request #86691 from aschwaighofer/embedded_existential_fix_outline_path
[embedded] [existentials] Fix the on-heap storage paths - what was I thinking
2026-01-23 07:24:41 -08: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
Arnold Schwaighofer
25dd981911 [embedded] [existentials] Fix the on-heap storage paths
Call swift_releaseBox on all the copy-on-write paths of existentials.
2026-01-21 09:38:27 -08:00
Meghana Gupta
7c6b13f511 Remove unnecessary Borrow and Mutate kinds from method descriptors and protocol requirements
Changing runtime in anyway can effect backward deployability.

Treeat borrow and mutate accessors as a regular method since they don't need any differentiated
runtime handling.
2026-01-20 11:44:18 -08:00
Meghana Gupta
a3adcf103a Update borrow and mutate accessors as opaque accessors 2026-01-20 11:43:59 -08:00
Susana Monteiro
a8ef103a83 Merge pull request #86531 from susmonteiro/susmonteiro/move-noncopyable-diagnostic
[cxx-interop] Fix occasionally omitted diagnostic
2026-01-16 08:57:50 +00:00
John Hui
cc70009c91 Merge pull request #86369 from j-hui/protected-dtors
[cxx-interop] Support inherited protected destructors and copy/move constructors
2026-01-15 21:13:46 -08:00
susmonteiro
11f1ec8fe4 [cxx-interop] Fix occasionally omitted diagnostic 2026-01-15 13:21:11 +00:00
Hiroshi Yamauchi
6f60adf009 Use a separate DIRefMap cache for existential typealiases (#86368)
After https://github.com/swiftlang/swift/pull/85655, DI types for
existential typealiases and their inner protocol types are created,
which may encounter conflicts in the DIRefMap cache and assert failures
because they can have identical mangled names. This change fixes this
issue by using a separate cache for existential typealiases to avoid
such conflicts.

Issue https://github.com/swiftlang/swift/issues/86313
2026-01-14 13:50:59 -08:00
John Hui
a35a0ad696 [cxx-interop] Support inherited protected destructors and copy/move constructors
C++ classes can have protected destructors, copy constructors, and move
constructors. This pattern prevents that class from being directly
constructed, copied, or moved directly, but permits those operations on
types that inherit from it.

Those protected special members are inaccessible in the base class, but
are indirectly accessible in the derived class, so they shouldn't
prevent that derived class from being imported in Swift.

Such members were previously causing the derived class to be
incorrectly considered as having unknown copyability.

Note that, at the time of this patch, Swift cannot (directly) access any
members inherited from the base class with the protected special member,
because doing so relies on that base class being imported on its own
(which it can't without a public dtor/copy ctor/move ctor).

rdar://167555864
2026-01-14 09:35:22 -08:00
eeckstein
12348bc86f Merge pull request #86512 from eeckstein/fix-check-incremental
utils: fix the check-incremental script by adding new IR saving options
2026-01-13 21:57:04 +00: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
Erik Eckstein
6f3a4b04c3 IRGen: add options -save-irgen <file> and -save-ir <file>
Those options can be used to save LLVM IR before and after LLVM optimizations to a file.
In contrast to `-emit-irgen` and `-emit-ir` the compiler doesn't stop an continues to e.g. create the regular output object file
2026-01-13 10:45:38 +01: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
Doug Gregor
f4aa5c1051 Merge pull request #86424 from DougGregor/unchecked-never-call-beginendaccess
Always suppress swift_(begin|end)Access calls with `-enforce-exclusivity=unchecked`
2026-01-09 22:10:50 -08:00
Hiroshi Yamauchi
a3e5f0bcef Set up the AST-affecting ClangImporter CodeGenOpts options early (#86175)
This is to keep clang module cache hashes consistent throughout the
build and avoid inconsistent hash errors due to the CodeGenOpts
changing at the IRGen phase in the middle of a build.

https://github.com/swiftlang/swift/issues/86116
2026-01-09 10:38:46 -08:00
Doug Gregor
d73cd34805 Always suppress swift_(begin|end)Access calls with -enforce-exclusivity=unchecked
The exclusivity enforcement command-line flags currently impact the
generation of SIL within the current module. However, it does not
impact any SIL that was deserialized from another module, which means
that `-enforce-exclusivity=unchecked` doesn't actually remove all of
the dynamic exclusivity checks.

When dynamic exclusivity is disabled, lower SIL
begin_access/end_access instructions to nothing to ensure that we
won't do any dynamic exclusivity checks.

Use this to better model the reality of dynamic exclusivity checking
in Embedded Swift, which effectively turned off all dynamic
exclusivity checking by having empty stub implementations of
swift_(begin|end)Access. Instead, have Embedded Swift default to
`-enforce-exclusivity=unchecked`, so that it never emits calls to
swift_(begin|end)Access. Remove the stub implementations of
swift_(begin|end)Access from the Embedded Swift runtime, since we will
no longer generate calls to them by default.

Moving forward, this will allow us to conditionally enable the new
implementation of dynamic exclusivity checking by specifying
`-enforce-exclusivity=checked` for Embedded Swift builds. We'll stage
that in over time to avoid breaking existing Embedded Swift clients.
2026-01-09 09:26:39 -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
Steven Wu
160ee3a66e Merge pull request #86194 from cachemeifyoucan/eng/PR-167054494
[DebugInfo] CAS built swift TU should have CASID as dwo_name for PCM
2026-01-05 14:39:10 -08:00
Susana Monteiro
b99409c5bc Merge pull request #86261 from susmonteiro/susmonteiro/remove-rdar-link
[cxx-interop] Remove radar link from FIXME
2026-01-05 15:22:27 +00:00
Tim Kientzle
56635157fa Switch IRGen debug info to standard terminology 2026-01-04 08:56:53 -08: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