Commit Graph

2865 Commits

Author SHA1 Message Date
Gabor Horvath
e8c8cded25 [cxx-interop] Fix name mangling for reference types
Fixes #83097

rdar://155973210
2025-07-18 17:57:54 +01:00
Susana Monteiro
0337f7e64a Merge pull request #83067 from susmonteiro/rename-virtual-methods
[cxx-interop] Adding swift_name attributes to virtual methods overrides
2025-07-18 11:57:46 +01:00
Gábor Horváth
4b9ef8c53c Merge pull request #83130 from Xazax-hun/objc-configurable-from-frontend
[cxx-interop] Configure requires ObjC from frontend option
2025-07-18 02:29:48 +01:00
Artem Chikin
57dd4cefdb Merge pull request #83139 from artemcm/DoNotCleanCacheWithoutMess
[Test] Do not clear the module cache when not needed between compiler runs
2025-07-17 15:53:36 -07:00
Gabor Horvath
4b64abdc45 [cxx-interop] Configure requires ObjC from frontend option
We sometimes don't have the information in the modulemaps whether a
module requires ObjC or not. This info is useful for reverse interop.
This PR introduces a frontend flag to have a comma separated list of
modules that we should import as if they had "requires ObjC" in their
modulemaps.
2025-07-17 21:29:50 +01:00
Artem Chikin
ebbb493852 [Test] Do not clear the module cache when not needed between compiler runs
In 'no-cxx-overlay-for-non-interop-interface.swift', test semantics should not be affected by having a persistent module cache between them
2025-07-17 10:40:38 -07:00
susmonteiro
585ca5e2da [cxx-interop] Adding swift_name attributes to virtual methods overrides 2025-07-17 16:23:32 +01:00
Erik Eckstein
dbb1c53e33 tests: fix Interop/Cxx/foreign-reference/array-of-classes.swift
This test can only run on the host OS

rdar://156051900
2025-07-17 16:00:15 +02:00
Erik Eckstein
f962d76362 GenericSpecializer: don't pre-specialize C++ reference type for AnyObject
Reference counting is not compatible.
Fixes a runtime crash if a C++ reference type is put into an Array.

https://github.com/swiftlang/swift/issues/83082
rdar://155919841
2025-07-16 21:30:36 +02:00
Gabor Horvath
2fc369067f [cxx-interop] Fix a test failing on iOS
The type used in the test is macOS only.
2025-07-16 11:21:01 +01:00
Gábor Horváth
761c50364c Merge pull request #83002 from Xazax-hun/guard-more-objc
[cxx-interop] Types exposed from ObjC modules should be behind a macro
2025-07-15 17:07:53 +01:00
fahadnayyar
a4eeae2a01 [cxx-interop] Re-enable warnings for unannotated C++ APIs returning SWIFT_SHARED_REFERENCE types under an experimental feature flag (#82488)
This patch re-enables diagnostics for unannotated C++ functions or
methods returning `SWIFT_SHARED_REFERENCE` types. These warnings now
fire only **once per source location**, even in the presence of multiple
template instantiations. This avoids diagnostic duplication that was a
key source of noise in the compilation of larger codebases.

These warnings were previously disabled starting in **Swift 6.2** via
[PR-#81411](https://github.com/swiftlang/swift/pull/81411) due to
concerns around false positives and excessive duplication in projects
adopting C++ interop. This patch addresses the duplication issue by
adding source-location-based caching, which ensures that a warning is
emitted only once per source location, even across template
instantiations with different types.

However, the false positive issue remains to be investigated and will be
addressed in a follow-up patch. Until that happens, the warnings are
gated behind a new experimental feature flag:
`WarnUnannotatedReturnOfCxxFrt`. This feature will be enabled by default
only after thorough qualification and testing on large C++ codebases.

rdar://154261051
2025-07-15 02:56:34 -07:00
fahadnayyar
439afd6406 Revert "Test Interop/Cxx/stdlib/overlay/custom-collection.swift fails on bots" (#82502)
I'm not able to reproduce the CI issue reported in rdar://143950805
locally. I don't have access to the logs from the failing bot link:
https://ci.swift.org/job/oss-swift_tools-RA_stdlib-RD_test-simulator/5086.

So, I'm trying to re-enable this test and do some custom PR testing to
see if the bot is still failing.

rdar://143950805
2025-07-13 16:15:11 -07:00
Gabor Horvath
9b1b9b774b [cxx-interop] Types exposed from ObjC modules should be behind a macro
Functions or template instantiations with Obj-C types should always be
behind a macro to make sure the interop header compiles cleanly in C++.

rdar://152836730
2025-07-11 18:22:39 +01:00
Anthony Latsis
06c04c52cc Merge pull request #82948 from swiftlang/jepa2
[test] Work around some C interop test failures on `stable/20250601`
2025-07-10 20:07:08 +01:00
Ben Barham
dbedb21ae2 Merge pull request #82929 from bnbarham/revert-allow-qual-swift-name
Revert "[cxx-interop] Allow import-as-member for types in namespaces"
2025-07-10 08:41:15 -07:00
Anthony Latsis
bde5b010b1 [test] Work around some C interop test failures on stable/20250601
For some reason, the `stable/20250601` Clang emits `-Wc++-keyword`
warnings in C mode when `-Weverything` is enabled. Suppress this
warning.
2025-07-10 14:39:46 +01:00
Ben Barham
dd809c6452 Revert "[cxx-interop] Allow import-as-member for types in namespaces"
This reverts commit e95f6a3ce9.
2025-07-09 12:50:34 -07:00
Gábor Horváth
529ec41815 Merge pull request #82882 from Xazax-hun/class-decl-order
[cxx-interop] Class declaration order does not matter
2025-07-09 18:21:03 +01:00
Gábor Horváth
2e789dc092 Merge pull request #82880 from Xazax-hun/do-not-generate-move-ctors
[cxx-interop] Do not generate aborting move constructors
2025-07-09 15:07:35 +01:00
Doug Gregor
b0739a55b3 Merge pull request #82850 from DougGregor/span-back-deployment-version-fixes
Fix deployment version for Span back-deployment library
2025-07-08 13:05:01 -07:00
Gábor Horváth
c33ce3f029 Merge pull request #82840 from Xazax-hun/unqualified-name-lookup-fix
[cxx-interop] Fix unqualified name lookup failure
2025-07-08 17:53:35 +01:00
Gabor Horvath
7d0a32f863 [cxx-interop] Class declaration order does not matter
Looking through the old issues found one that we already fixed. Adding a
a test to close the issue. Closing #70336.

rdar://119405019
2025-07-08 17:50:28 +01:00
Egor Zhdan
66b8960613 Merge pull request #82817 from egorzhdan/egorzhdan/dictionary-init
[cxx-interop] Allow creating Dictionary from `std::map`
2025-07-08 17:38:20 +01:00
Gabor Horvath
a13940f1c4 [cxx-interop] Do not generate aborting move constructors
In the reverse interop header we generated move constructors that call
abort at runtime. This is problematic for several reasons:
* In C++14 and below some of our own generated functions like _make
  ended up calling the move constructor. Those are calling abort and
  also trigger unreachable code warning in newer versions of Clang.
  In C++17 and up it is fine due to the guaranteed copy elision.
* Type traits are fooled and think these types are movable. As a result,
  libraries could generate calls to the aborting move ctor.

This PR removes the generation of move operations. As we generate copy
operations, the compiler will not declare or define the move operations
implicitly. Whenever the user goes out of their way and try to move an
object they will get a copy instead.

rdar://150793518
2025-07-08 16:45:58 +01:00
Gabor Horvath
4de92656dd [cxx-interop] Fix unqualified name lookup failure
When MemberImportVisibility is enabled we failed to find certain base
methods from the extensions when said base methods are imported from
C++.

rdar://154887575
2025-07-08 12:41:01 +01:00
Doug Gregor
5900c8a9e3 Update tests for Span back-deployment 2025-07-07 22:57:44 -07:00
Joe Groff
8a817da6d8 Merge pull request #82707 from jckarter/afd-clang-imports
Lower imported C structs and unions as addressable-for-dependencies.
2025-07-07 13:23:49 -07:00
Egor Zhdan
569ca005e8 Merge pull request #82680 from swiftlang/egorzhdan/enable-c-frt
[cxx-interop] Enable foreign reference types in C interop
2025-07-07 19:42:06 +01:00
Egor Zhdan
19c7884ec5 [cxx-interop] Allow creating Dictionary from std::map
This adds an initializer to `Swift.Dictionary` that takes an instance of `std::map` or `std::unordered_map`.

rdar://155050682
2025-07-05 21:54:11 +01:00
Egor Zhdan
c06951e3af Merge pull request #74146 from swiftlang/egorzhdan/std-optional-init-value
[cxx-interop] Instantiate `std::optional` value constructors
2025-07-04 16:33:28 +01:00
Susana Monteiro
7c1852e2c7 Merge pull request #82485 from swiftlang/susmonteiro/rename-virtual-methods
[cxx-interop] Allow virtual methods to be renamed with SWIFT_NAME
2025-07-03 15:19:23 +01:00
Gábor Horváth
507f82c7af Merge pull request #82717 from Xazax-hun/instantiation-fail-error-location
[cxx-interop] Add source location to instantiation error
2025-07-03 14:43:57 +01:00
Egor Zhdan
dcc3842535 [cxx-interop] Instantiate std::optional value constructors
This improves support for initializing instances of `std::optional` from Swift. Previously only a null optional could be initialized directly from Swift. Now instantiations of `std::optional` will get a Swift initializer that takes the wrapped value as a parameter.

rdar://118026392
2025-07-03 14:00:27 +01:00
Gábor Horváth
a15a2a4929 Merge pull request #82684 from swiftlang/gaborh/reverse-interop-forward-decl-crash
[cxx-interop] Fix a crash when exposing @objc Swift classes
2025-07-03 04:38:19 +01:00
Egor Zhdan
a18db8f49f Merge pull request #82579 from swiftlang/egorzhdan/import-as-member-from-namespace
[cxx-interop] Allow import-as-member for functions declared within a namespace
2025-07-02 22:49:14 +01:00
Gábor Horváth
a7e19f3d4a Merge pull request #82712 from Xazax-hun/types-nested-in-extensions
[cxx-interop] Support types nested in extensions
2025-07-02 18:52:46 +01:00
Egor Zhdan
d3dc17a067 [cxx-interop] Allow import-as-member for functions declared within a namespace
This makes it possible to use trigger import-as-member for C++ functions declared within namespaces. Previously only functions declared at the file level were supported.

rdar://138930205
2025-07-02 16:40:40 +01:00
Joe Groff
78a5f358b4 Lower imported C structs and unions as addressable-for-dependencies.
C code is highly likely to want to use pointers as references between dependent
structs, and we would like to be able to readily map these to lifetime-dependent
Swift values. Making C types addressable-for-dependencies ensures that any function
producing a dependency on such a value receives a stable in-memory address for that
value, allowing borrows and inout accesses to always be representable as pointers.

rdar://153648393
2025-07-02 08:31:18 -07:00
Gabor Horvath
201e9b437c [cxx-interop] Fix a crash when exposing @objc Swift classes
rdar://154252454
2025-07-02 16:11:08 +01:00
susmonteiro
b3e228845b [cxx-interop] Allow virtual methods to be renamed with swift_name 2025-07-02 16:09:02 +01:00
Egor Zhdan
5a6a147850 Merge pull request #82691 from swiftlang/egorzhdan/cfoptions-block-param
[cxx-interop] Fix generated header for Swift closures using `CF_OPTIONS` types
2025-07-02 14:47:03 +01:00
Gabor Horvath
15a6cca3f6 [cxx-interop] Add source location to instantiation error
Previously, the diagnostic was emitted with an unknown location.
2025-07-02 14:01:46 +01:00
Gabor Horvath
c5b18a0a9e [cxx-interop] Support types nested in extensions
The generated header did not compile due to a bug that prevented us from
referencing the correct namespaces derived from the nominal type's name
(an extension does not have a name). Moreover, we did not generate
forward declarations for the members of the extensions for classes and
enums (but we did for structs). This change also removes a workaround
that emitted String::Index as _String_Index.

rdar://153221450
2025-07-02 11:36:04 +01:00
Egor Zhdan
e95c9ecffc [cxx-interop] Fix generated header for Swift closures using CF_OPTIONS types
If a Swift class has a field, which has a closure type, which takes an instance of a `CF_OPTIONS`/`NS_OPTIONS` type as a parameter, the reverse interop logic would generate an invalid Objective-C++ header for such type.

This was discovered with UIKit's `UIControlState` type, which is declared with `NS_OPTIONS` in Objective-C, then renamed to `UIControl.State` with API Notes, and then re-exported to Objective-C++ via the generated header.

rdar://129622886
2025-07-01 19:48:38 +01:00
Egor Zhdan
9178af3ec7 [cxx-interop] Enable foreign reference types in C interop
Most of the logic for C++ foreign reference types can be applied to C types as well. Swift had a compiler flag `-Xfrontend -experimental-c-foreign-reference-types` for awhile now which enables foreign reference types without having to enable C++ interop. This change makes it the default behavior.

Since we don't expect anyone to pass `experimental-c-foreign-reference-types` currently, this also removes the frontend flag.

rdar://150308819
2025-07-01 18:46:22 +01:00
Egor Zhdan
01719983dc Merge pull request #82627 from swiftlang/egorzhdan/void-begin-crash
[cxx-interop] Do not crash for `void begin()`
2025-07-01 17:35:16 +01:00
Gábor Horváth
bd3c3024af Merge pull request #82625 from swiftlang/gaborh/nonescapable-noncopyable
[cxx-interop] Add test for move-only non-escapable types
2025-07-01 15:36:00 +02:00
Gábor Horváth
11cb7e5800 Merge pull request #82333 from swiftlang/gaborh/default-arg-duplicate-symbols 2025-07-01 13:50:00 +02:00
Gábor Horváth
b00ff4568b Merge pull request #82480 from swiftlang/gaborh/addressable_params_copy
[cxx-interop] Avoid copies when accessing pointee
2025-06-30 17:41:39 +02:00