Commit Graph

12816 Commits

Author SHA1 Message Date
Konrad 'ktoso' Malawski
7c21ea8b7d [Distributed] More IRGenMangler fixes for distributed thunks
We also need to mangle the dispatch thunks to distributed thunks
uniquely.
2025-06-04 21:07:56 +09:00
Konrad 'ktoso' Malawski
84a8adbd4c [Distributed] IRGen mangler must mangle distributed thunk 2025-06-04 21:07:06 +09:00
Susana Monteiro
71b7de4f61 Merge pull request #81867 from swiftlang/susmonteiro/6.2-metadata-private-fields
🍒 [cxx-interop] Ensure field offset vector matches the structs/fields metadata
2025-06-02 16:46:00 +01:00
Egor Zhdan
ee5f7ad262 [cxx-interop] Do not crash when emitting layout of std::string
If a `[[no_unique_address]]` field has zero size according to Clang, and field has a type that isn't representable in Swift, Swift would previously try to add an opaque field of size 1 for it.

This is wrong and was causing crashes for `std::string` while emitting a padding field:
```
_LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T1> _LIBCPP_CONCAT3(__padding1_, __LINE__, _);
```

rdar://151941799
(cherry picked from commit a7c174431f)
2025-05-30 17:33:31 +01:00
susmonteiro
2e66b84e9f [cxx-interop] Ensure field offset vector matches the structs/fields metadata
The field offset vector should be consistent with the type metadata emitted for structs and fields. If we don't emit metadata for private C++ fields, then the field offset vector shouldn't include these fields.

This is a follow-up to https://github.com/swiftlang/swift/pull/81838/https://github.com/swiftlang/swift/pull/81740
(cherry picked from c3077bfedb and 7686f05f28)
2025-05-30 13:12:47 +01:00
Shubham Sandeep Rastogi
bc7e9531f2 Merge pull request #81753 from rastogishubham/CompDir6.2
[6.2] Set the Compilation directory when generating the Skeleton CU
2025-05-28 10:06:33 -07:00
Shubham Sandeep Rastogi
de425be15b Set the Compilation directory when generating the Skeleton CU
When creating a skeleton Compile Unit, the DIFile passed
in, it always uses the include path. This leads to the DW_AT_comp_dir
being wrong, if the -file-compilation-dir option is passed, we need to
use the remapped compilation dir passed in to the DIFile instead.

This patch fixes that problem.

(cherry picked from commit b286b1c3a5)
2025-05-23 14:43:57 -07:00
susmonteiro
d81d6547ba [cxx-interop] Fix metadata mismatch regarding fields of structs
In https://github.com/swiftlang/swift/pull/78467 and https://github.com/swiftlang/swift/pull/78961, we stopped emitting metadata for private C++ fields. However, this created a mismatch between the fields emitted and the number of fields + their offsets in the StructDescriptor.

rdar://147263490
(cherry picked from commit 72b13b3b48)
2025-05-23 11:16:09 +01:00
Stephen Canon
85b304220f [6.2] Implement Builtin.select binding llvm select instruction (#81665)
Not used (yet), but needed to implement SIMD.replacing(with:where:)
idiomatically, and probably useful otherwise.

**Explanation:** Makes select available in Swift's builtin module, which
allows implementing concrete SIMD operations more efficiently.
**Risk:** Low. New builtin protected by a feature flag, currently
unused.
**Testing:** New tests added.
**Reviewers:** @eeckstein, @Azoy 
**Main branch PR:** https://github.com/swiftlang/swift/pull/81598
2025-05-21 19:14:33 -04:00
Slava Pestov
7a334bc094 Merge pull request #81565 from slavapestov/fix-issue-78191-6.2
[6.2] IRGen: Fix miscompile when a generic parameter is fixed to a tuple containing a pack
2025-05-20 15:35:23 -04:00
Erik Eckstein
1f3bff3f77 IRGen: fix failing unconditional class casts
When unconditionally casting from a base to a final derived class, e.g. `base as! Derived`, the program did not abort with a trap.
Instead the resulting null-pointer caused a crash later in the program.
This fix inserts a trap condition for the failing case of such a cast.

rdar://151462303
2025-05-20 07:39:16 +02:00
Erik Eckstein
442db1bdc0 IRGen: extract generating a cond_fail into a utility function emitConditionalTrap
NFC
2025-05-20 07:39:16 +02:00
Erik Eckstein
31cd6f9ffd IRGen: move FailBBs from IRGenSILFunction to its base class IRGenFunction
NFC
2025-05-20 07:39:16 +02:00
Slava Pestov
85bdf45b44 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:35:30 -04:00
Dario Rexin
8299d7be0b Merge pull request #81531 from drexin/wip-151176697-6.2
[6.2][IRGen] Don't set HasLayoutString flag on non-copyable generic types
2025-05-15 20:27:24 -07:00
Dario Rexin
75c581d3a0 [IRGen] Don't set HasLayoutString flag on non-copyable generic types
rdar://151176697

While generic types generally have layout strings (when enabled), non-copyable types don't, so
we have to make sure the flag does not get set.
2025-05-15 10:25:33 -07:00
Slava Pestov
bf8d836074 IRGen: Fix out-of-order task_dealloc with parameter pack metadata
We deallocate an instruction's packs at points where no further
control flow path uses the value. In the case of an alloc_stack,
this will be right after the dealloc_stack. Thus, if alloc_stack
allocates some packs to build type metadata for a tuple type
that contains a pack, and then proceeds to allocate a value
large enough to hold the tuple, we will free the second allocation
first, before we free the pack, as expected.

However, after stack allocating the value, alloc_stack does
some further work to emit debug info. This could result in
emission of additional metadata packs.

Split up the debug info emission into two parts; the first we do
before we perform the stack allocation, the rest we do after.

- Fixes https://github.com/swiftlang/swift/issues/67702.
- Fixes rdar://problem/141363236.
2025-05-15 12:24:14 -04:00
Shubham Sandeep Rastogi
cf204f2e05 Set debug location to Coroutine call expression
If debug info generation is enabled, set debug location to the
coroutine call instruction to make sure there are no issues with invalid
debug information in LTO.

This happens because in LTO, if a call to a function doesn't contain a
debug location, we see the warning:

inlinable function call in a function with debug info must have a
!dbg location

ld: warning: Invalid debug info found, debug info will be stripped

Which then strips the debug info from the entire .o file linked into the
dylib.

(cherry picked from commit 17e756ba81)
2025-05-13 17:34:05 -07:00
Dario Rexin
51489ac69b Merge pull request #81381 from drexin/wip-wip-150722907-6.2
[6.2][IRGen] Emit llvm fneg operation for Builtin.fneg_*
2025-05-09 09:27:16 -07:00
Konrad `ktoso` Malawski
d3248fc0c4 Merge pull request #81394 from ktoso/pick-wip-sign-protocol-ptr
[6.2][Distributed] pointer auth protocol pointers as we use conformsToProtocol
2025-05-09 19:26:46 +09:00
Konrad 'ktoso' Malawski
0a2989ab5c [Distributed] pointer auth protocol pointers as we use conformsToProtocol 2025-05-09 11:16:00 +09:00
Dario Rexin
7502c75806 [IRGen] Emit llvm fneg operation for Builtin.fneg_*
rdar://150722907

The original handling was a workaround before LLVM added the fneg operation. Now that it has it, we should use it.
2025-05-08 13:52:07 -07:00
Konrad `ktoso` Malawski
f6a864a188 Merge pull request #81135 from ktoso/pick-22b20e731eaa70746d3c21bf8c44836aa49dfabb
[6.2][Concurrency] Change isIsolatingCurrent... to return Bool?
2025-05-02 07:53:12 +09:00
Meghana Gupta
cc72edb119 Introduce end_cow_mutation_addr instruction 2025-04-30 14:38:48 -07:00
Konrad 'ktoso' Malawski
eaf0b15ea3 [Concurrency] Change isIsolatingCurrent... to return Bool?
This changes the isIsolatingCurrentContext function to return `Bool?`
and removes all the witness table trickery we did previously to detect
if it was implemented or not. This comes at a cost of trying to invoke
it always, before `checkIsolated`, but it makes for an simpler
implementation and more checkable even by third party Swift code which
may want to ask this question.

Along with the `withSerialExecutor` function, this now enables us to
check the isolation at runtime when we have an `any Actor` e.g. from
`#isolation`.

Updates SE-0471 according to
https://forums.swift.org/t/se-0471-improved-custom-serialexecutor-isolation-checking-for-concurrency-runtime/78834/
review discussions
2025-04-28 19:17:58 +09:00
Gabor Horvath
291a63fd80 [6.2][cxx-interop] Fix a crash with [[no_unique_address]]
Explanation: Swift does not support storing fields in the padding of the previous
fields just yet, so let's not import fields like that from C++.
Represent them as opaque blobs instead.
Issue: rdar://149072458
Risk: Low, the fix is targeted at a scenario that was crashing before.
Testing: Regression test added.
Original PR: #80786
Reviewer:
2025-04-25 12:51:13 +01:00
Arnold Schwaighofer
345d1a64c9 [6.2] LoadableByAddress: Fix shouldTransformYields to use (properly) substituted
types

Scope: The LoadableByAddress pass fails on some Swift source because it
ignores pattern substitutions.

Risk: Low. Many source patterns where this difference matters should have
crashed.

Fix: Don't ignore pattern substitutions.

Testing: The project that crashed no longer does. Unit test added.

rdar://149281263
issues/80818

(cherry picked from commit 521fb07523)
2025-04-22 08:16:52 -07:00
Arnold Schwaighofer
9775681216 Merge pull request #80907 from aschwaighofer/large_types_reg2mem_unchecked_bitwise_cast_propagate_6.2
[6.2] LargeTypesReg2Mem: Add unchecked_bitwise_cast to the projections we need to propagate largeness from destination to source operand
2025-04-22 07:31:49 -07:00
Konrad 'ktoso' Malawski
694af3317a [Distributed] Distributed actor usage through protocol with lib-evo must work
This corrects how we were dealing with dispatch thunks -- mostly be
removing a lot of special casing we did but doesn't seem necessary and
instead we correct and emit all the necessary information int TBD.

This builds on  https://github.com/swiftlang/swift/pull/74935 by further refining how we fixed that issue, and adds more regression tests. It also removes a load of special casing of distributed thunks in library evolution mode, which is great.

Resolves and adds regression test for for rdar://145292018

This is also a more proper fix to the previously resolved but in a not-great-way which caused other issues:
- resolves rdar://128284016
- resolves rdar://128310903

Review followup, cleanup test
2025-04-21 20:33:22 +09:00
Arnold Schwaighofer
e3133f736a [6.2] LargeTypesReg2Mem: Add unchecked_bitwise_cast to the projections we need to propagate largeness from destination to source operand
Scope: Fixes a compiler crash in some version of swift-collections
Issue: An instruction whose result type address'ness needs to be
propagated to its operand was not handled.
Risk: Low, this case would have crashed without the change.
Testing: Unit test added. The compiler successfully compiled the project
after this change.
Original PR: https://github.com/swiftlang/swift/pull/80888

rdar://148545382
(cherry picked from commit 370b7e8219)
2025-04-18 07:23:52 -07:00
John Hui
d7b44f4e94 Merge pull request #80718 from j-hui/fix-interop-private-debug-symbols-6.2 2025-04-15 17:08:18 -07:00
Rashmi Mudduluru
942eddf01e [SUA][IRGen] Add stub for swift_coroFrameAlloc that weakly links against the runtime function (#79889) (#80769)
* [SUA][IRGen] Add stub for swift_coroFrameAlloc that weakly links against the runtime function

This commit modifies IRGen to emit a stub function `__swift_coroFrameAllocStub` instead of the
newly introduced swift-rt function `swift_coroFrameAlloc`. The stub checks whether the runtime has the symbol
`swift_coroFrameAlloc` and dispatches to it if it exists, uses `malloc` otherwise. This ensures the
ability to back deploy the feature to older OS targets.

rdar://145239850
(cherry picked from commit 5e2f20b2d8)
2025-04-15 16:45:41 -07:00
Andrew Trick
097dba34ff Merge pull request #80709 from atrick/62-irgen-addressable
[6.2] Fix IRGen for @_addressable params which may be "captured".
2025-04-11 18:03:01 -07:00
Slava Pestov
b0b4a646f6 Merge pull request #80676 from slavapestov/fix-rdar148698142-6.2
[6.2] IRGen: Fix silly mistake in MetadataPath::followComponent()
2025-04-10 14:59:44 -04:00
Andrew Trick
e048dd1cf1 Fix IRGen for @_addressable params which may be "captured".
Simply omit the 'nocapture' attribute on the parameter.

Fixes rdar://148039510 ([nonescapable] IRGen: lower addressable
params to LLVM: captures(ret: address, provenance))

(cherry picked from commit 2d9df8ff78)
2025-04-10 09:43:13 -07:00
John Hui
bafcb9dcca [cxx-interop] Do not get private discriminator for private Clang types (#80485)
When generating debug symbols for private Clang types (which we started
importing recently), the compiler crashes due to an assertion failure
from ClangModuleUnit::getDiscriminatorForPrivateDecl(), which is called
by getFilePrivateScope().

This patch fixes the issue crash by not calling getFilePrivateScope()
for Clang types. A discriminator is usually needed to disambiguate
private Swift types declared in different files, but Clang types follow
different scoping conventions that make this discriminator unnecessary.

rdar://148481025
(cherry picked from commit dd2f465025)
2025-04-10 06:54:58 -07:00
Adrian Prantl
95e7092889 [IRGenSIL] Factor out shouldUseDispatchThunk() (NFC)
(cherry picked from commit c4f073d39a)
2025-04-09 14:30:50 -07:00
Adrian Prantl
b2e24a9433 [IRGen] Improve legibility of conditional (NFC)
(cherry picked from commit 5a36f3baac)
2025-04-09 14:30:50 -07:00
Adrian Prantl
0231a3881b [LLDB] Fix conditional to also support AccessLevel::Open
This fixes crashes in LLDB expression evaluation when calling virtual
Open functions.

rdar://147797657
(cherry picked from commit f4a0f4b339)
2025-04-09 14:30:50 -07:00
Slava Pestov
cca31be781 IRGen: Convert null pointer derefs into unconditional asserts 2025-04-09 11:54:20 -04:00
Slava Pestov
f8bf194ece IRGen: Fix silly mistake in MetadataPath::followComponent()
This fixes a regression from a00157ec43.

My change made it so that sourceKey.Kind was checked after being
overwritten with an abstract conformance, so we would never take
the if statement. Incredibly, it almost worked.

Fixes rdar://problem/148698142.
2025-04-09 11:54:19 -04:00
Konrad `ktoso` Malawski
99ff7880ae Merge pull request #80574 from ktoso/wip-pickwip-tapi-validation
[6.2][Distributed] Fix distributed accessors for resilient modules
2025-04-09 08:31:35 +09:00
Nate Chandler
926bad2543 [IRGen] Fix type of deleted coro error func.
It was previously erroneously an async function pointer.  Also fix the
name.
2025-04-07 11:43:13 -07:00
Konrad 'ktoso' Malawski
df76286fba [Distributed] Dont emit TBD also for distributed thunks
This resolves pedantic "all" TBD validation issues, i.e. we dont emit
unexpected records anymore - we would before as we only checked for
is_distributed but we also want to skip those for is_distributed_thunk

resolves rdar://128284016
2025-04-07 13:19:01 +09:00
Konrad 'ktoso' Malawski
139d878940 [Distributed] Accessor must be available cross module in resilient mode
This is an important fix for libraries using @Resolvable in resilient
libraries. Without the fix we're missing an accessor and this will fail
some remote calls which make use of remote calls on resolvable
protocols. This would manifest as missing accessor error thrown by the
executeDistributedTarget function.

resolves rdar://148224780
2025-04-07 13:19:00 +09:00
Nate Chandler
63a1bb0705 [CoroutineAccessors] Use async bit in descriptors.
To facilitate back deployment, make use of the fact that the async bit
has up to now never been set for read and modify accessors and claim
that set bit to indicate that it is a callee-allocated coroutine.  This
has the virtue of being completely back deployable because like async
function pointers coro function pointers must be auth'd and signed as
data.
2025-04-04 15:50:11 -07:00
nate-chandler
0e2ca9a07d Merge pull request #80483 from nate-chandler/general-coro/20250327/2
[CoroutineAccessors] Open-code a task_dealloc_thru
2025-04-03 21:21:06 -07:00
Augusto Noronha
cac0abbfde Merge pull request #80380 from augusto2112/fix-opaque
[DebugInfo] Use underlying type of global variables with opaque type
2025-04-03 15:39:11 -07:00
Nate Chandler
cb68533649 [CoroutineAccessors] Open-code a task_dealloc_thru
When building for back-deployment, emit calls to an open-coded
`_swift_task_dealloc_through` function rather than the runtime
`swift_task_dealloc_through` which doesn't exist on them.
2025-04-03 13:45:27 -07:00
Kuba (Brecka) Mracek
eb1c92575d Merge pull request #80416 from kubamracek/embedded-mergeable-global-refs
[embedded] Fix compilation crash with -num-threads and -mergeable-symbols
2025-04-03 08:49:26 -07:00