Commit Graph

3452 Commits

Author SHA1 Message Date
John Hui
27f970af5e Merge pull request #86995 from j-hui/all-star
[cxx-interop] Fix confusion between multiply and dereference operators
2026-02-06 06:04:14 -08:00
Egor Zhdan
bdb500d5e8 Merge pull request #86988 from egorzhdan/egorzhdan/only-valid-operators
[cxx-interop] Do not emit invalid C++ operator declarations
2026-02-06 11:39:10 +00:00
John Hui
77e50e8ee1 [cxx-interop] Account for non-member deref operator*() (NFC)
Note that new code path doesn't actually seem to be taken, due to
NameImporter logic that renames non-member operators differently.

Adds some test case to at least document current behavior.
2026-02-05 14:13:03 -08:00
Gábor Horváth
b07ff82a8c Merge pull request #86983 from Xazax-hun/module-interface-printing-suppressible
[cxx-interop] Fix printing suppressible conformances for imported types
2026-02-05 14:33:14 +00:00
Egor Zhdan
4876ce976a [cxx-interop] Do not emit invalid C++ operator declarations
When generating a reverse interop header for a Swift module that declares `func ===` for a Swift type, we were printing `operator===`, which isn't valid in C++.

This teaches reverse interop to only print operators that are valid in C++.

rdar://169474185
2026-02-05 12:59:04 +00:00
John Hui
5b124bc54d [cxx-interop] Fix confusion between multiply and dereference operators
c2952b7 mistakenly treated the binary C++ operator*() ("multiply") as
the unary operator*() ("dereference"), preventing ClangImporter from
synthesizing the Swift func *(_:_) operator. This patch fixes the issue
and adds some tests to exercise the scenario.

rdar://169448888
2026-02-04 19:04:49 -08:00
Gabor Horvath
838bfc30cd [cxx-interop] Fix printing suppressible conformances for imported types
We only added the old attributes but those are not picked up by
ASTPrinter. This PR adds inherited entries which is the correct
representation of these conformances.

rdar://157868143
2026-02-04 15:31:45 +00:00
Gábor Horváth
ae06200ce6 Merge pull request #86938 from Xazax-hun/existentials-reverse-interop-crash
[cxx-interop] Fix crash trying to expose Swift existentials to C++
2026-02-02 21:03:34 +00:00
Henrik G. Olsson
cdb58756d3 Merge pull request #86884 from hnrklssn/enable-std-span-interface
Enable std span interface
2026-02-02 08:34:00 -08:00
Gabor Horvath
9ebb656b27 [cxx-interop] Fix crash trying to expose Swift existentials to C++
Confusingly, isObjC on an existential does not check if the super class
is actually ObjC. Make the check stricter to avoid a crash down the
line.

rdar://169210092
2026-02-02 16:07:52 +00:00
Henrik G. Olsson
58e1db52ad [cxx-interop] fix std-span-interface.swift
On some Linux versions (e.g. UBI9) this test failed because __counted_by
was already defined, but defined to nothing. I haven't figured out how
or why, because I was debugging via CI output, but this should fix it.

rdar://163085444
2026-01-31 21:15:30 -08:00
Henrik G. Olsson
e03df70ee2 Merge pull request #86838 from hnrklssn/swiftify-text-interface
[Swiftify] don't attach macro if plugin unavailable
2026-01-31 13:28:17 -08:00
Henrik G. Olsson
56ef1a9348 [DiagnosticVerifier] support quoting paths with ''
Windows paths can contain colons (etc. C:\foo\bar), which the diagnostic
verifier would confuse for the end of the path. By quoting them we can
ignore all colons until the matching single quote character.
2026-01-30 21:39:26 -08:00
Henrik G. Olsson
c67e1f06ae Merge pull request #86883 from hnrklssn/swiftify-mutating-self
[Swiftify] fix borrow syntax for lifetimebound on mutating self
2026-01-30 12:25:44 -08:00
Egor Zhdan
8353524e9a Merge pull request #86892 from egorzhdan/egorzhdan/macro-cf-options
[cxx-interop] Import macro-declared `CF_OPTIONS` enums correctly
2026-01-30 19:55:36 +00:00
Gábor Horváth
88a9d748ca Merge pull request #86421 from Xazax-hun/bridge-intrusive-ptrs 2026-01-30 19:16:29 +00:00
John Hui
06662c6d1e Merge pull request #86880 from j-hui/successor-s01e10 2026-01-30 07:59:52 -08:00
Egor Zhdan
fec952734b [cxx-interop] Import macro-declared CF_OPTIONS enums correctly
This makes sure that Swift correctly imports `CF_OPTIONS`/`NS_OPTIONS` types in C++ interop mode, such as:
```
typedef CF_OPTIONS(NSUInteger, TEST(Enum))
```

`CF_OPTIONS`/`NS_OPTIONS` macros have different expansions in C++ language mode, which forces us to have extra logic to handle them correctly with C++ interop enabled.

rdar://166528719
2026-01-30 14:47:59 +00:00
Henrik G. Olsson
4def7528f6 [Swiftify] fix borrow syntax for lifetimebound on mutating self
Mutating methods that borrow self should use the @_lifetime(&self)
syntax.

rdar://153484170
2026-01-29 22:43:52 -08:00
Henrik G. Olsson
81b0973602 [CxxInterop] add --match-full-lines to filecheck (NFC)
This makes sure e.g. all mutating methods are accurately reflected as
such.
2026-01-29 22:19:14 -08:00
John Hui
535fc76a43 [cxx-interop] Fix lazy lookup for synthesized successor() method
Protocol conformance checking requests a qualified name lookup of
"successor()", not "successor", which is a compound name with zero
arguments rather than a simple name.

Teach ClangRecordMemberLookup to be aware of this. Without accounting
for this, protocol conformances will fail.

rdar://169217941
2026-01-29 15:05:15 -08:00
Henrik G. Olsson
2718628ead remove unneeded experimental feature from test 2026-01-29 10:34:15 -08:00
Henrik G. Olsson
c0b30892a6 [Swiftify] don't attach macro if plugin unavailable
At the moment plugin paths do not get passed along when consuming a
textual interface of an imported module. Normally this is not an issue,
because all macros have already been expanded at this point, but this is
not the case for _SwiftifyImport which belongs to a clang module but is
expanded while gompiling a dependent Swift module. This would cause an
error when trying to expand the macro. Since most textual interfaces
don't call any safe wrappers at the moment, this unblocks the
compilation by checking whether the macro plugin can be loaded before
attaching the macro, and emitting a warning if not. Long term we'll want
to pass along the plugin path to swift-api-digester, but this will do
for now.

rdar://168967555
2026-01-29 10:34:11 -08:00
Hiroshi Yamauchi
60a4620f2d Fix test trap-on-exception-irgen-msvc.swift with no-assert build (#86821)
The return value differs between %0 and %1 when LLVM_ENABLE_ASSERTIONS
is false.
2026-01-29 09:51:17 -08:00
Egor Zhdan
da572845c3 Merge pull request #86818 from egorzhdan/egorzhdan/method-returning-frt
[cxx-interop] Methods that return references to FRT are safe
2026-01-29 16:17:11 +00:00
Gábor Horváth
cfebf3583b Merge pull request #86867 from hnrklssn/disable-swiftify-protocol
[Swiftify] disable safe interop for ObjC protocols
2026-01-29 10:36:46 +00:00
Henrik G. Olsson
66a3bea341 [Swiftify] disable safe interop for ObjC protocols
This removes the swiftifyProtocol function, because it fundamentally
incompatible with our layering. By iterating over the protocol members
of the node we are currently importing, we immediately force all members
to be imported. This can lead to cycles and various hard-to-debug import
failures. Instead we need to attach the extension macro when importing
each invidvidual method. This will take some plumbing however, because
that may happen after the protocol's macros have already been expanded,
preventing later macros from being expanded.

rdar://168500103
2026-01-28 20:28:02 -08:00
Henrik G. Olsson
5eb27e81cf macos -> macosx 2026-01-28 09:04:36 -08:00
Gabor Horvath
96ee6eaf18 [cxx-interop] Implicitly bridge annotated smart pointers to reference types
This PR introduces implicit bridging from annotated smart pointers to
reference counted objects to Swift foreign reference types. The bridging
only happens when these smart pointers are passed around by value. The
frontend only sees the Swift foreign reference types in the signature
and the actual bridging happens during SILGen when we look at the
original clang types and note that they differ significantly from the
native types.

The bridging of parameters did not quite fit into the existing structure
of bridging conversions as smart pointers are non-trivial types passed
around as addresses and existing bridging conversions were implemented
for types passed directly.

rdar://156521316
2026-01-28 12:34:21 +00:00
Henrik G. Olsson
68196b5c66 fix availability test for watchOS and visionOS
rdar://168985007
2026-01-27 14:12:39 -08:00
Rintaro Ishizaki
dd04117df6 [Test] Disable a failing test case
rdar://168985007
2026-01-27 10:00:35 -08:00
Rintaro Ishizaki
f4ae57cab7 [Test] Disable a failing test case
rdar://168985007
2026-01-27 09:58:07 -08:00
Egor Zhdan
2c4e37fb31 [cxx-interop] Methods that return references to FRT are safe
If a C++ method returns a foreign reference type as a pointer (`MyImmortal*`), Swift correctly treats the method as safe. However, if the method returns a foreign reference type as a reference (`MyImmortal&`), Swift assumed that the method is unsafe.

This change adjusts the heuristic to treat such methods as safe. It also addresses a FIXME comment: previously, if the returned foreign reference type has inherited its `import_reference` attribute from a base class, the safety heuristic did not correctly detect the type as an FRT.

rdar://168057355
2026-01-27 16:54:44 +00:00
Henrik G. Olsson
a65e5613d3 Merge pull request #86613 from hnrklssn/swiftify-clang-availability
[ClangImporter] Don't import empty availability attributes
2026-01-26 20:06:45 -08:00
Henrik G. Olsson
d7829cd181 Merge pull request #86766 from hnrklssn/swiftify-fix-owning-module
[Swiftify] get module from canonical decl



This aligns the logic in SwiftifyDecl.cpp for fetching the owning module with that of the rest of the compiler. Previously we would fetch the owning module from the clang decl directly associated with the Swift decl, whereas the rest of the compiler looks at the canoncial (first) decl to determine ownership. This mismatch resulted in a state where swiftifyImpl did not think the decl originated in a bridging header (because it was not imported into the __ObjC module), but it also didn't find an owning module on the clang decl. This occured when a bridging header would import a header from a module, and then redeclare a function from that module.

rdar://168703691
2026-01-24 13:00:15 -08:00
finagolfin
6f81699db2 [test] Fix a test for 32-bit Android armv7 and enable another one for 64-bit (#86732)
noncopyable-irgen is simply missing the armv7 triple, while the new
std::optional test only fails on Android armv7.
2026-01-25 01:00:33 +05:30
Henrik G. Olsson
decfed10bc silence backtrace warning 2026-01-23 20:43:45 -08:00
Henrik G. Olsson
8d49c3c2c6 [ClangImporter] Don't import empty availability attributes
When compilng for tvOS, `availability(ios,introduced=2.0)` seems to
imply `availability(tvos)`. This gets imported as `@available(tvOS)`,
which is invalid Swift syntax. Normally this attribute has no effect,
but when attaching a macro to such a function the macro gets invalid
Swift syntax as input.

rdar://168272342
2026-01-23 20:04:06 -08:00
Henrik G. Olsson
398f09bb2e [Swiftify] get module from canonical decl
This aligns the logic in SwiftifyDecl.cpp for fetching the owning module
with that of the rest of the compiler. Previously we would fetch the
owning module from the clang decl directly associated with the Swift
decl, whereas the rest of the compiler looks at the canoncial (first)
decl to determine ownership. This mismatch resulted in a state where
swiftifyImpl did not think the decl originated in a bridging header
(because it was not imported into the __ObjC module), but it also didn't
find an owning module on the clang decl. This occured when a bridging
header would import a header from a module, and then redeclare a
function from that module.

rdar://168703691
2026-01-23 18:45:18 -08:00
John Hui
cd8e4c29d2 [cxx-interop] Skip over static_assert when importing members
Not doing so prevents member-wise initializers from being synthesized

Fixes #86730
2026-01-23 09:48:36 -08:00
Egor Zhdan
4384452f27 Merge pull request #83372 from egorzhdan/egorzhdan/std-variant
[cxx-interop] Test trivial usage of `std::variant` from Swift
2026-01-23 17:48:30 +00:00
Pavel Yaskevich
76881aebc0 Merge pull request #86713 from xedin/rdar-158224838
[ImportDecl] Replace `@Sendable` with synthesized protocol attribute …
2026-01-23 06:43:57 -08:00
Max Desiatov
a353caa375 Mark use-std-optional-lib.swift test as unsupported on Android
Unblocking nightly toolchain snapshots due to failing Android builds https://ci.swift.org/job/oss-swift-package-swift-sdk-for-android/202/
2026-01-22 21:06:30 +00:00
Max Desiatov
b5b193a444 Mark noncopyable-irgen.swift test as unsupported on Android
Unblocking nightly toolchain snapshots due to failing Android builds https://ci.swift.org/job/oss-swift-package-swift-sdk-for-android/202/
2026-01-22 21:05:13 +00:00
Pavel Yaskevich
c7f6b417c2 [ImportDecl] Replace @Sendable with synthesized protocol attribute on a type
Currently the importer simply adds new "synthesized protocol" attribute
for `Sendable` which is problematic during type-checking because the new
attribute is supposed to replace `@Sendable` and properly synthesize the
conformance.

Resolves: rdar://158224838
2026-01-22 11:02:50 -08:00
John Hui
e6669db10a Merge pull request #86685 from j-hui/annotate-frt-ctors
[cxx-interop] Support ownership annotations on FRT constructors
2026-01-22 03:20:02 -08:00
finagolfin
31f7cc99fd [test] Fix noncopyable-irgen.swift failure on Android (#86692)
Android uses libc++, just like Darwin, so it has the same error message
for the constructor, not the one linux has with libstdc++, so check the
specific OS also.

Otherwise, we see this error on the Android
CI:
```
15:49:14      // expected-TEST7-LINUX-error@-7 {{call to deleted constructor of 'std::unique_ptr<int>'}}
15:49:14                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15:49:14                                         call to implicitly-deleted copy constructor of 'std::unique_ptr<int>'
```
2026-01-22 12:46:07 +05:30
John Hui
5dbc8c25f9 [cxx-interop] Support ownership annotations on FRT constructors
We were previously marking synthesized FRT initializers as
"returns_retained" unconditionally (for non-immortal types), which can
cause memory errors and also suppresses diagnostics about the lack of
such annotations.

This patch fixes that behavior, and also adjusts the source locations of
the synthesized C++ factory method to point to the actual constructor
decl when its location is available, so that the diagnostics make sense
when warning about the lack of annotations.

rdar://163127315
2026-01-21 16:23:53 -08:00
Hiroshi Yamauchi
867bd732b2 Fix swift tests for Windows ARM64 (#86558) 2026-01-21 16:08:58 -08:00
Gábor Horváth
14fee5235b Merge pull request #86651 from Xazax-hun/reenable-span-test-windows
[cxx-interop] Reenable use-std-span test
2026-01-21 21:44:37 +00:00