Commit Graph

12781 Commits

Author SHA1 Message Date
Dario Rexin
96d6eb87ee Merge pull request #82352 from drexin/wip-153681688-6.2
[6.2][IRGen] Fix placeholder logic for emission of conditionally inverted protocols
2025-06-23 18:22:26 -07:00
Egor Zhdan
bf20dab48c Merge pull request #82185 from swiftlang/susmonteiro/6.2-class-metadata-private-fields
🍒 [cxx-interop] Support for printing C++ foreign references
2025-06-23 17:52:00 +01:00
Dario Rexin
dc71b7e4c4 Merge pull request #82241 from drexin/wip-149882902-6.2
[6.2][IRGen] Emit null check before swift_conformsToProtocol for nullable metatypes
2025-06-18 15:56:50 -07:00
Dario Rexin
ae8c455170 [IRGen] Fix placeholder logic for emission of conditionally inverted protocols
rdar://153681688

Instead fo counting the actual conformances, the logic took the size of the bit field, i.e. used the highest set bit, so when a type had a conditional conformance only on ~Escapable, but not on ~Copyable, it would still add 2 placeholders, but only fill one.
2025-06-18 14:47:40 -07:00
Nate Chandler
2cf7ef5fdc [IRGen] Fix FixedArray of fixedSize 1 elt addring.
When a `FixedArray`'s fixed size is 1, it looks like `[1 x %Ty]`. Given
an array's address, performing an operation on each element's address
entail's indexing into the array to each element's index to produce an
element's address for each index.  That is true even when the array
consists of a single element.  In that case, produce an address for that
single element by indexing to index 0 into each passed-in array.

rdar://151726387
2025-06-16 20:34:22 -07:00
Dario Rexin
533e215f6f [IRGen] Emit null check before swift_conformsToProtocol for nullable metatypes
rdar://149882902

swift_conformsToProtocol does not properly handle nullptr values, which can currently be passed if the source type is an optional metatype. This change adds emission of a null check before calling the runtime function in these cases.
2025-06-13 17:00:49 -07:00
Alastair Houghton
20df87c940 [IRGen] Don't use GOTPCREL relocations for x86 ELF.
Unforunately, x86 ELF linkers like to optimize GOTPCREL relocations by
replacing `mov` instructions that go via the GOT with `lea` instructions
that do not.

That would be fine, but they aren't very selective and will happily
perform this transformation in non-code sections if they think that
the bytes before a relocation look like a `mov` instruction.

This corrupts our metadata.

rdar://148168098
2025-06-13 10:25:56 +01:00
susmonteiro
862efcf3a0 [cxx-interop] Support for printing C++ foreign references
Adds support for printing a C++ foreign reference in Swift.

Also skips metadata of private fields in C++ records imported as Swift classes, following up on #81035

(cherry-picked from 848fad0021)
2025-06-11 17:13:01 +01:00
Konrad `ktoso` Malawski
2e368ce31c Merge pull request #82010 from ktoso/pick-wip-fix-computed-variables-arm64-protocol-dist
[6.2][Distributed] Fix computed properties in protocols on arm64e
2025-06-10 09:08:59 +09:00
Allan Shortlidge
c9d5e4b26c Merge pull request #82038 from tshortli/language-modes-and-features-in-module-trace-6.2
[6.2] Frontend: Add language mode and enabled features to `.SWIFT_TRACE`
2025-06-05 23:35:32 -07:00
Arnold Schwaighofer
cf81104407 Merge pull request #80989 from aschwaighofer/loadable_by_address_fix_yields_pattern_subst_6.2
[6.2] LoadableByAddress: Fix shouldTransformYields to use (properly) substituted types
2025-06-05 17:16:31 -07:00
Erik Eckstein
7435a0366a IRGen: Fix an unused static function warning.
Move a static inline function into the cpp file.

NFC.
2025-06-05 15:39:33 -07:00
Pavel Yaskevich
608a37ad04 Merge pull request #81997 from xedin/using-for-default-isolation-in-file-context-6.2
[6.2][AST/Sema] SE-0478: Implement using declaration under an experimental flag
2025-06-05 00:44:21 -07:00
Konrad 'ktoso' Malawski
362783c0f8 [Distributed] Don't drop dist get accessors from witness tables.
This actually manifested as an pointer auth crash, but the real reason
being is that we messed up the order of elements in the witness table.
If we'd skip the accessor like this, the types we sign/auth with would
no longer align and manifest in a crash.

There is no real reason to skip this entry so we just bring it back, and
avoid making this special in any way.

This unlocks a few tests as well as corrects any distributed+protocol
use where a requirement distributed var was _followed by_ other
requirements.

resolves rdar://125628060
2025-06-05 12:16:20 +09:00
Pavel Yaskevich
d057429e9a [AST] Add new declaration - using
Initially this declaration is going to be used to determine
per-file default actor isolation i.e. `using @MainActor` and
`using nonisolated` but it could be extended to support other
file-global settings in the future.

(cherry picked from commit aabfebec03)
2025-06-04 13:16:55 -07:00
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