Commit Graph

12930 Commits

Author SHA1 Message Date
Gabor Horvath
4af3992bb4 [cxx-interop] Restrict the uses of anonymous types
Make sure they are excluded from the reflection metadata (although in
the future we want to make sure indirect fields are included). Make sure
the users cannot refer to the anonymous field, only its members.
2025-10-10 17:46:22 +01:00
Anton Korobeynikov
7668666ad2 Support differentiation of wrapped value modify accessors (#78794)
Some fixes for coroutines with normal results and `partial_apply` of coroutines were required.

Fixes #55084
2025-09-10 02:30:26 -07:00
Yuta Saito
401b705295 Merge pull request #81348 from kateinoigakukun/yt/dyn-replace-asan
IRGen: Disable ASan for the auto dynamic replacement array
2025-09-10 17:46:04 +09:00
Doug Gregor
66a730b638 [Embedded] Remove -mergeable-symbols
This option is no longer necessary, because we emit weak definitions
for any imported modules. Fixes rdar://158364032.
2025-09-08 17:44:51 -07:00
Gábor Horváth
56a525b0c9 Merge pull request #84152 from Xazax-hun/add-nullptr-to-metadata
[cxx-interop] Make the size of anonymous types metadata is unchanged
2025-09-08 17:44:43 +01:00
Gabor Horvath
cae23fd098 [cxx-interop] Make the size of anonymous types metadata is unchanged
Add a null pointer to the value witness table instead of completely
skipping emitting the pointer.
2025-09-08 11:51:10 +01:00
John McCall
92352b817d Merge pull request #84130 from rjmccall/nominal-type-visitor
[NFC] Introduce a convenience specialization of CanTypeVisitor
2025-09-06 13:59:33 -04:00
Doug Gregor
ab15602af5 Merge pull request #84110 from DougGregor/lazy-irgen-global-variables
[IRGen] Lazily emit SIL global variables
2025-09-05 13:36:42 -07:00
John McCall
64d020ec45 [NFC] Introduce a convenience specialization of CanTypeVisitor that
forwards the paired nominal type methods to common implementations.
2025-09-05 14:02:36 -04:00
Gábor Horváth
8cc45ddec3 Merge pull request #84105 from Xazax-hun/no-vwt-for-anon-types
[cxx-interop] Basic support for anonymous structs with non-copyable fields
2025-09-05 09:07:17 +01:00
Doug Gregor
dbc30dc5c9 [IRGen] Cache the layout of the LLVM struct type for statically-initialized objects
Lazy emission of SIL global variables caused us to go through the
creation of two different LLVM struct types for the same
initialization, tripping an assertion in LLVM. Cache it along with
other information about the static-initialized object rather than
rebuilding it.

Also fix the lazy_globals test to account for the laziness,
generalizing it to also run on arm64 so I won't miss it locally.
2025-09-04 15:58:32 -07:00
Doug Gregor
4009814783 [IRGen] Lazily emit SIL global variables
Delay the emission of SIL global variables that aren't externally
visible until they are actually used. This is the same lazy emission
approach that we use for a number of other entities, such as SIL
functions.

Part of rdar://158363967.
2025-09-04 13:03:15 -07:00
Gabor Horvath
0c909a8395 [cxx-interop] Basic support for anonymous structs with non-copyable fields
Anonymous structs cannot be copied or moved, these operations only can
happen to their enclosing non-anonymous types. Stop trying to emit
special member functions and value witness tables for these structs.
2025-09-04 15:20:17 +01:00
Janat Baig
f21eb5375e Merge branch 'main' into temp-branch 2025-09-02 20:23:25 -04:00
Dario Rexin
c38db438b2 Merge pull request #83922 from drexin/wip-159143492
[IRGen] Fix computation of spare bits for fixed arrays
2025-08-29 09:21:50 -07:00
Kavon Farvardin
bb8b1e1b42 Merge pull request #83984 from kavon/avoid-not-noncopyable
nfc: avoid !isNoncopyable()
2025-08-28 17:46:39 -07:00
Dario Rexin
81af291c4f [IRGen] Fix computation of spare bits for fixed arrays
rdar://159143492

Previously all bits after the spare bits of the first element were marked as spare bits. This caused enum tags to be stored in bits used by the payload.
2025-08-28 12:27:40 -07:00
Kavon Farvardin
3bb8fa848a nfc: !isNoncopyable() -> isCopyable() 2025-08-28 12:13:21 -07:00
Erik Eckstein
dca75c4e5c IRGen: revert hack to look for specialized deinits 2025-08-28 08:04:49 +02:00
Dario Rexin
69cafe42a3 Merge pull request #83837 from drexin/wip-157795547
[IRGen] Do not set HasLayoutString flag for non-copyable types requir…
2025-08-27 13:58:59 -07:00
Slava Pestov
6c1a2fdf1d Merge pull request #83899 from slavapestov/fix-issue83539
IRGen: Fix crash trying to emit capture descriptor involving element archetype
2025-08-26 21:33:43 -04:00
Doug Gregor
a5fa3edf54 Merge pull request #83909 from DougGregor/embedded-darwin-reserve-4kb
[Embedded] Only reserve 4KB in embedded Darwin targets
2025-08-26 04:55:46 -07:00
Doug Gregor
923689c2b4 [Embedded] Only reserve 4KB in embedded Darwin targets
Non-embedded Darwin targets reserve the first 4GB of address space. All
other targets reserve 4KB of address space. Make Embedded Darwin
targets only reserve the first 4KB (as with other targets), since they
aren't in userspace.

Fixes rdar://158981013.
2025-08-25 23:21:34 -07:00
Doug Gregor
f9394adf49 Merge pull request #83906 from DougGregor/specialized-deinit-in-destroy-outlining
[IRGen] Look for a specialized deinit when forming a call in IRGen
2025-08-25 21:48:53 -07:00
Doug Gregor
beeb45def1 [IRGen] Look for a specialized deinit when forming a call in IRGen
When outlining a destroy operation, we form direct calls to the deinit
of noncopyable types. For generic types, this was always calling into
unspecialized generics, which is... deeply unfortunate.

Look for a specialized deinit and call that instead. This eliminates a
compiler assertion in Embedded Swift, and should improve performance
with noncopyable generics elsewhere.

Fixes rdar://159054138 and #72627 / rdar://157131184.
2025-08-25 16:13:12 -07:00
Slava Pestov
831043c132 IRGen: Fix crash trying to emit capture descriptor involving element archetype
We could encode local archetypes in reflection info by performing the
local archetype transform, to get an extended generic signature together
with substitutions for the added generic parameters.

However, for now, let's just not crash. This generalizes an earlier hack
for opened existential archetypes. Instead of replacing them with
nonsensical type parameters though, let's just not emit the whole
descriptor.

- Fixes https://github.com/swiftlang/swift/issues/83539.
- Fixes rdar://157554723.
2025-08-25 12:42:49 -04:00
Anthony Latsis
2640584847 Merge pull request #83854 from swiftlang/jepa-main2
IRGen: Mark some `llvm::APInt` constructions as signed
2025-08-24 08:42:34 +01:00
Egor Zhdan
d1a1f70c61 Merge pull request #83850 from egorzhdan/egorzhdan/frt-indirection
[cxx-interop] Pass foreign reference types with correct level of indirection
2025-08-24 04:50:59 +01:00
Janat Baig
798c0f51a4 Merge branch 'main' into temp-branch 2025-08-23 11:11:04 -04:00
JanBaig
52895fefc3 [SIL] Remove AssignByWrapper references from SIL passes 2025-08-22 23:20:53 -04:00
Egor Zhdan
0a766e59ce [cxx-interop] Pass foreign reference types with correct level of indirection
When calling a C++ function that takes a reference to a pointer to a foreign reference type, Swift would previously pass a pointer to the foreign reference type as an argument (instead of a reference to a pointer), which resulted in invalid memory accesses.

This was observed when using `std::vector<ImmortalRef*>::push_back`.

rdar://150791778
2025-08-22 11:56:57 +01:00
Anthony Latsis
b765ade82a IRGen: Mark some llvm::APInt constructions as signed
Fixes an assertion failure in the rebranch `llvm::APInt` ctor on 32-bit
Windows. We were hitting the assertion because `uint64_t(-2)` does not
fit into 32 bits when treated as unsigned.

These assertions were enabled by default
https://github.com/llvm/llvm-project/pull/114539.
2025-08-21 19:54:52 +01:00
Egor Zhdan
ed70a1bb1a Merge pull request #83802 from egorzhdan/egorzhdan/frt-windows
[cxx-interop] Enable reference-counted types on Windows
2025-08-21 09:56:41 +01:00
Dario Rexin
67d0a22e2f [IRGen] Do not set HasLayoutString flag for non-copyable types requiring metadata instantiation
rdar://157795547

When types contain stored properties of resilient types, we instantiate their metadata at runtime. If those types are non-copyable, they won't have layout strings, so we must not set the flag.
2025-08-20 17:12:59 -07:00
Alexis Laferrière
7642d410af Merge pull request #83814 from xymus/cdecl-enum-layout
IRGen: Use C compatible representation for `@cdecl` enums
2025-08-20 10:39:09 -07:00
Egor Zhdan
b440c4ff70 [cxx-interop] Enable reference-counted types on Windows
This enables the use of reference-counted foreign reference types on Windows. As it turns out, the assertion that was failing on Windows previously was unnecessary. This also enabled many of the tests on Windows.

rdar://154694125 / resolves https://github.com/swiftlang/swift/issues/82643
2025-08-20 12:35:10 +01:00
Alexis Laferrière
a8cf1a477f IRGen: Use C compatible representation for @cdecl enums
https://github.com/swiftlang/swift/issues/83738
2025-08-19 13:40:09 -07:00
Doug Gregor
9a20ebac5b [Embedded] Emit weak definitions for imported symbols
When Embedded Swift emits a symbol that was imported from another
module, ensure that the symbol is emitted as a weak definition. This
way, importing the same module (and using its symbol) into several
different modules doesn't cause duplicate-symbol errors at link time.
Rather, the linker will merge the different symbol definitions. This
makes Embedded Swift libraries work without resorting to
`-mergeable-symbols` or `-emit-empty-object-file`.
2025-08-17 15:26:08 -07:00
nate-chandler
a868d92ad0 Merge pull request #83683 from nate-chandler/rdar158083136
[InlineArray] Fix outlining metadata collection.
2025-08-13 03:26:32 -07:00
Nate Chandler
3078e95074 [InlineArray] Fix outlining metadata collection.
The metadata of the element type is required for outlining.

rdar://158083136
2025-08-12 14:22:50 -07:00
Yuta Saito
b9128d48b5 IRGen: Disable ASan for the auto dynamic replacement array 2025-08-11 06:53:36 +00:00
Arnold Schwaighofer
c55753b0d7 Merge pull request #83590 from aschwaighofer/largetypes_reg2mem_single_user_peephole
LargeTypesReg2Mem: Peephole load followed by single user to reuse the load's address
2025-08-08 07:37:25 -07:00
Arnold Schwaighofer
1e8e3b82df LargeTypesReg2Mem: Peephole load followed by single user to reuse the load's address
For example the pattern:

```
%e = load %1 : SomeEnum
switch_enum %e
```

The switch_enum_addr should reuse the load's address operand instead of
creating a new location for the SSA value of %e.

While we are there also don't create a new stack location for extracting payload
in a switch_enum_addr case target basic block if that extracted payload is not
used. That is if the basic block arguments in all switch target blocks are
unused in the switch_enum version.

```
switch_enum %enum, case #Optional.some!enumelt: bb1,
                   case #Optional.none!enumelt: bb2

bb2(%payload : $Payload):
   // unused %payload value
```

rdar://156602951
2025-08-07 07:21:51 -07:00
Allan Shortlidge
78f50ba741 AST: Refactor ConditionallyAvailableSubstitutions to use AvailabilityQuery.
Conditionally available opaque return types should support availability
conditions that are evaluated in any availability domain. Update
`ConditionallyAvailableSubstitutions` to model its conditions with
`AvailabilityQuery` instead of assuming that conditions are always a single
version query for the current platform.
2025-08-06 18:01:10 -07:00
Erik Eckstein
201bb44d2f IRGen: allow all kind of Builtin.zeroInitializer in statically initialized globals
Just use the same method to create the zero initializer constant as in `emitBuiltinCall`.
2025-08-03 17:25:42 +02:00
John McCall
46be95847b Extract TypeLowering's recursive type properties into a header, add
functions to compute them directly without a TypeLowering object, and
change a lot of getTypeLowering call sites to just use that.

There is one subtle change here that I think is okay: SILBuilder used to
use different TypeExpansionContexts when inserting into a global:
- getTypeLowering() always used a minimal context when inserting into
  a global
- getTypeExpansionContext() always returned a maximal context for the
  module scope
The latter seems more correct, as AFAIK global initializers are never
inlinable. If they are, we probably need to configure the builder with
an actual context properly rather than making global assumptions.

This is incremental progress towards computing this for most types
without a TypeLowering, and hopefully eventually removing TL entirely.
2025-08-01 15:00:57 -04:00
Anthony Latsis
bbd84429a0 Merge pull request #83400 from swiftlang/jepa-main
Address `llvm::PointerUnion::{is,get}` deprecations
2025-07-30 17:19:58 +01:00
JanBaig
988a3dcf25 [SIL] Introduce new SILDeclRef 2025-07-29 21:16:11 -04:00
Doug Gregor
9194fa0ab7 Merge pull request #83364 from DougGregor/noncopyable-imported-c-struct-destroy
[Clang importer] Allow noncopyable C structs to define "destroy" operation
2025-07-29 18:16:05 -07:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00