Commit Graph

12869 Commits

Author SHA1 Message Date
Allan Shortlidge
d19d4ee99b IRGen: Use AvailabilityRange::forDeploymentTarget().
It should be preferred over querying the deployment range from the availability
domain returned by `ASTContext::getTargetAvailabilityDomain()`.

NFC.
2025-07-17 14:14:21 -07:00
Slava Pestov
de068cb130 Merge pull request #83070 from slavapestov/remove-redundant-functor
AST: Remove MakeAbstractConformanceForGenericType
2025-07-15 23:44:59 -04:00
Allan Shortlidge
fa267fefff Merge pull request #83051 from tshortli/diagnose-more-invalid-os-versions
Sema: Diagnose invalid platform versions in more places
2025-07-15 17:06:39 -07:00
Slava Pestov
ee440f3c91 AST: Remove MakeAbstractConformanceForGenericType
While the intent behind this functor was noble, it has grown in complexity
considerably over the years, and it seems to be nothing but a source of
crashes in practice. I don't want to deal with it anymore, so I've decided
to just subsume all usages with LookUpConformanceInModule instead.
2025-07-15 16:34:11 -04:00
Meghana Gupta
a4ad806319 Merge pull request #82890 from meg-gupta/simplifyendcowaddr
Add simplification for end_cow_mutation_addr
2025-07-15 07:37:13 -07:00
Allan Shortlidge
910989c2c2 AST: Store parsed version in OriginallyDefinedInAttr instead of canonical.
Canonicalize the version on-demand instead.

NFC, part of rdar://155558161.
2025-07-14 16:04:04 -07:00
Meghana Gupta
e317a603fc Add simplification for end_cow_mutation_addr
We insert end_cow_mutation_addr for lifetime dependent values dependent on mutable addresses.
end_cow_mutation_addr can be simplified to end_cow_mutation after other optimizations like inlining, specialization etc

This PR adds an instruction simplification to transform end_cow_mutation_addr to end_cow_mutation.
This can enable array optimizations which look for end_cow_mutation.
2025-07-14 13:46:13 -07:00
Doug Gregor
badba55bf1 [IRGen] Mangling of nonisolated(nonsending) function types was introduced in Swift 6.2
We can't use mangled named when back-deploying earlier.
2025-07-11 14:24:54 -07:00
Doug Gregor
f3eca93e7f [IRGen] Don't use mangled names for metadata including Span et al when back-deploying
If back-deploying prior to the introduction of name mangling and
runtime support for invertible constraints (~Copyable, ~Escapable),
don't use mangled names to access metadata. The code already existed
for this, but had a carve-out that still used mangled names for
standard library types that have always existed but got generalized to
support non-copyable & non-escapable types.

Tweak that carve-out to not apply to types like Span that come from a
back-deployment library. Fixes crashes when using metadata for Span et
al on older platforms.

Fixes rdar://155639204.
2025-07-11 14:24:53 -07:00
Arnold Schwaighofer
0442c7c417 Merge pull request #82646 from aschwaighofer/wip_opt_remarks_wmo
Support LLVM optimization remarks in WMO mode
2025-07-02 10:40:35 -07:00
Doug Gregor
46572f80a2 Merge pull request #82661 from DougGregor/back-deploy-main-actor-isolated-deinit
[SE-0371] Back-deploy support for main-actor-isolated deinit
2025-07-01 20:50:19 -07:00
Joe Groff
1c75d3b740 Merge pull request #82323 from jckarter/addressable-for-dependencies-vw-flag
Add an "addressable for dependencies" flag to value witness flags.
2025-07-01 13:02:17 -07:00
Arnold Schwaighofer
b30bd40b83 Add code to create llvm::RemarkStreamer objects for all the LLVMModules in WMO mode
rdar://154403078
2025-07-01 07:19:33 -07:00
Konrad `ktoso` Malawski
441f9f8ad3 Merge pull request #82611 from ktoso/wip-cleanup-mergeconflict-potential 2025-07-01 12:08:25 +09:00
Doug Gregor
7789a0ce64 [SE-0371] Back-deploy support for main-actor-isolated deinit
When targeting a platform that predates the introduction of isolated
deinit, make a narrow exception that allows main-actor-isolated deinit
to work through a special, inlineable entrypoint that is
back-deployed. This implementation

  1. Calls into the real implementation when available, otherwise
  2. Checks if we're on the main thread, destroying immediately when
we are, otherwise
  3. Creates a new task on the main actor to handle destruction.

This implementation is less efficient than the implementation in the
runtime, but allows us to back-deploy this functionality as far back
as concurrency goes.

Fixes rdar://151029118.
2025-06-30 17:38:08 -07:00
Augusto Noronha
0c20222aea Merge pull request #81700 from augusto2112/revert-debug-info-witness-table
Revert "Merge pull request #79171 from augusto2112/debug-info-witness…
2025-06-30 15:28:15 -07:00
Arnold Schwaighofer
7ddf75c791 Merge pull request #82107 from tobias-stadler/remarks-fix-llvm-setup
[IRGen] Setup LLVMRemarkStreamer using existing RemarkStreamer
2025-06-30 13:50:31 -07:00
Konrad 'ktoso' Malawski
1f87f60d6c Revert revert & fix distributed protocol and TBD handling
This reverts a revert that was done internally here https://stashweb.sd.apple.com/projects/DEVTOOLS/repos/swift/pull-requests/8697/overview
and corrects some issues with the reverted code while at it.

This fix is crucial to land for correctness and necessary to fix the
rdar://144568615 which had a fix submitted however that assumed that
THIS change also was present, so the fix submitted for 144568615 is
incomplete without this change as well.

This enables, and adds more TBD testing and was explicitly checked
against the GameKit reproducer project from rdar://144568615.

I will also upstream the necessary parts missing from OSS repo there so
we have alignment between all branches.
2025-06-30 11:13:05 +09:00
nate-chandler
76fd74753b Merge pull request #82510 from nate-chandler/rdar80334865
[IRGen] Sign these function pointers.
2025-06-26 12:02:07 -07:00
Nate Chandler
c108d480ab [IRGen] Sign these function pointers.
Value witness tables for prespecialized metadata for multi payload enums
contain references to `swift_getMultiPayloadEnumTagSinglePayload` and
`swift_storeMultiPayloadEnumTagSinglePayload`.  On platforms with
ptrauth, those functions must be signed.  Use the same helper when
adding these functions to the table as is used to add every single other
function to the table.

rdar://80334865
2025-06-25 16:24:40 -07:00
Dave Lee
ce7a3b39a4 IRGen: Emit objc type encoding for ivars (#81967)
ObjC ivar metadata has up to now emitted an empty string for the ivar's objc type encoding. Conversely, ObjC property metadata is emitted with an objc type encoding. This changes the compiler to also emit an objc type encoding for ivars.

The motivation for this change is for lldb to print ivars of classes declared in Objective-C but implemented in Swift, as defined in [SE-0436](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0436-objc-implementation.md). Without the presence of type encoding for ivars, lldb is unable to present to the user the ivars/properties of instances of such classes.

rdar://138569299
2025-06-25 15:39:23 -07:00
Saleem Abdulrasool
d0b34c2b67 Merge pull request #82170 from compnerd/internalise
IRGen: internalise well known types with static linking
2025-06-23 19:31:22 -07:00
Daniil Kovalev
644f364d3d [AutoDiff] Use LinkEntity::SecondaryPointer for diff witness (#82412)
If `LinkEntity::isTypeKind()` is true, `IRGenModule::getAddrOfLLVMVariable` assumes that we can safely call
`LinkEntity::getType()`, which does `reinterpret_cast` of `LinkEntity::Pointer` to `TypeBase *`. However, for SIL
differentiability witness, the pointer has `SILDifferentiabilityWitness *` type, which is not derived from `TypeBase`. So, such a cast is not allowed.

Just as with `ProtocolWitnessTableLazyAccessFunction` and `ProtocolWitnessTableLazyCacheVariable` link entity kinds (which are also type kinds), we should use `SecondaryPointer` instead of `Pointer` for storing payload here, while setting `Pointer` to `nullptr`.
2025-06-23 16:18:07 -07:00
Anthony Latsis
1ceeb7089b Merge pull request #82338 from AnthonyLatsis/jepa
ASTBridging: Bridge more enums directly
2025-06-20 23:13:50 +01:00
Dario Rexin
6db11b60a3 Merge pull request #82347 from drexin/wip-153681688
[IRGen] Fix placeholder logic for emission of conditionally inverted …
2025-06-19 09:05:48 -07:00
Anthony Latsis
3e9923f0c0 ASTBridging: Bridge swift::AccessorKind directly 2025-06-19 04:26:52 +01:00
michael-yuji
cf2f7154a5 Merge pull request #77836 from michael-yuji/mchiu/freebsd
[FreeBSD] Adding FreeBSD support
2025-06-18 19:59:48 -07:00
Dario Rexin
545cf1ee0a Merge pull request #82240 from drexin/wip-149882902
[IRGen] Emit null check before swift_conformsToProtocol for nullable …
2025-06-18 15:56:39 -07:00
Joe Groff
7e99e84070 Add an "addressable for dependencies" flag to value witness flags.
This may be useful for type layout of borrow fields in the future, should we
decide that addressable-for-dependencies borrows should always be represented
by a pointer. rdar://153650278
2025-06-18 12:47:16 -07:00
Dario Rexin
5ec58209dc [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 11:28:13 -07:00
(null)
aaf283258b Merge branch 'main' into mchiu/freebsd 2025-06-17 15:41:57 -04:00
(null)
cf041b126e address pltaform orders and other nits 2025-06-17 15:37:49 -04:00
(null)
d6811260a9 Merge commit '665515c781999a81094bbe4f8302a7cb1a6a6b39' into mchiu/freebsd 2025-06-17 15:12:23 -04:00
nate-chandler
5b37832e1f Merge pull request #82280 from nate-chandler/rdar151726387
[IRGen] Fix FixedArray of fixedSize 1 element addressing.
2025-06-17 06:39:31 -07:00
Nate Chandler
6e8170c34d [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:41 -07:00
Dario Rexin
2a3999049f [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:11 -07:00
Alastair Houghton
6936e2b4cd Merge pull request #82176 from al45tair/eng/PR-148168098
[IRGen] Don't use GOTPCREL relocations for x86 ELF.
2025-06-13 10:23:54 +01:00
Tobias Stadler
76568372f4 [IRGen] Setup LLVMRemarkStreamer using existing RemarkStreamer
Calling setupLLVMOptimizationRemarks overwrites the MainRemarkStreamer
in the LLVM context. This prevents LLVM from serializing the remark meta
information for the already emitted SIL remarks into the object file.
Without the meta information bitstream remarks don't work correctly.

Instead, emit SIL remarks and LLVM remarks to the same RemarkSerializer,
and keep the file stream alive until after CodeGen.
2025-06-12 18:31:41 +01:00
Stephen Canon
9259c3eec4 Add new interleave and deinterleave builtins (#81689)
Ideally we'd be able to use the llvm interleave2 and deinterleave2
intrinsics instead of adding these, but deinterleave currently isn't
available from Swift, and even if you hack that in, the codegen from
LLVM is worse than what shufflevector produces for both x86 and arm. So
in the medium-term we'll use these builtins, and hope to remove them in
favor of [de]interleave2 at some future point.
2025-06-12 12:01:53 -04:00
Saleem Abdulrasool
7fa316c71d IRGen: internalise well known types with static linking
When statically linking the standard library ensure that we emit the
well known metadata and accessors with internal linkage. This fixes a
number of warnings about incorrect DLL storage when building Foundation
on Windows for static linking.
2025-06-11 11:23:21 -07:00
Alastair Houghton
cc6389366c [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-11 12:03:38 +01:00
Susana Monteiro
6164af2f46 Merge pull request #81832 from swiftlang/susmonteiro/class-metadata-private-fields
[cxx-interop] Support for printing C++ foreign references
2025-06-11 11:58:45 +01:00
susmonteiro
848fad0021 [cxx-interop] Support for printing C++ foreign references 2025-06-10 12:15:21 +01:00
Konrad `ktoso` Malawski
21291a41bd Merge pull request #82009 from ktoso/wip-fix-computed-variables-arm64-protocol-dist 2025-06-09 12:14:37 +09:00
Konrad 'ktoso' Malawski
30d54531a7 [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 16:58:00 +09:00
Doug Gregor
bc4cf1236b [SIL] Generalize CastingIsolatedConformances to CheckedCastInstOptions
We are going to need to add more flags to the various checked cast
instructions. Generalize the CastingIsolatedConformances bit in all of
these SIL instructions to an "options" struct that's easier to extend.

Precursor to rdar://152335805.
2025-06-04 17:12:28 -07:00
Konrad `ktoso` Malawski
84c2c38556 Merge pull request #81958 from ktoso/wip-distributed-irgenmangler-more 2025-06-04 21:02:52 +09:00
Konrad 'ktoso' Malawski
cc532fbbd9 [Distributed] More IRGenMangler fixes for distributed thunks
We also need to mangle the dispatch thunks to distributed thunks
uniquely.
2025-06-04 08:40:19 +09:00
eeckstein
50c6824263 Merge pull request #81935 from eeckstein/min-pointer-value-option
IRGen: add an option `-min-valid-pointer-value` to override the target's LeastValidPointerValue
2025-06-03 19:21:58 +02:00
Saleem Abdulrasool
51645d00a3 Merge pull request #81754 from compnerd/closed
IRGen: honour `-static-libclosure` in block creation
2025-06-03 08:35:07 -07:00