Commit Graph

6238 Commits

Author SHA1 Message Date
Egor Zhdan
04726c04e3 Merge pull request #83181 from egorzhdan/egorzhdan/default-arg-lifetime-conformance
[cxx-interop] Prevent protocol conformance table from being prematurely populated
2025-07-21 12:22:44 +01:00
Egor Zhdan
f0a32d104d [cxx-interop] Prevent protocol conformance table from being prematurely populated
We've started seeing build failures where the conformance of a `std::vector` instantiation to `CxxVector` is missing. This was because the LifetimeDependenceInfoRequest triggers the protocol conformance table for the instantiation to be built before the synthesized conformance gets added.

This works around the issue by preventing LifetimeDependenceInfoRequest from running for the synthesized default argument generator function, which was the culprit of this particular failure.

rdar://155977071
2025-07-18 20:19:30 +01:00
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
susmonteiro
585ca5e2da [cxx-interop] Adding swift_name attributes to virtual methods overrides 2025-07-17 16:23:32 +01:00
Gábor Horváth
cbc0e80efb Merge pull request #83032 from Xazax-hun/import-source-loc-assert
[cxx-interop] Fix assert failure due to invalid location
2025-07-15 14:14:54 +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
Gabor Horvath
f6940446a2 [cxx-interop] Fix assert failure due to invalid location
We hit an assert failure do to creating a range where the begin was a
valid source location while the end range was an invalid one.
Unfortunately, I was not able to create a minimal reproducer but I was
able to verify that this fix works because I was able to reproduce this
issue while compiling Swift with a patched version of Clang.

rdar://155379027
2025-07-14 16:27:16 +01:00
Allan Shortlidge
96d0450d62 Merge pull request #82940 from tshortli/silgen-custom-availability-domain-query
ClangImporter: Generate and call custom availability domain predicates
2025-07-10 13:16:14 -07: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
Allan Shortlidge
3d722e1919 ClangImporter: Generate and call custom availability domain predicates.
When importing custom availability domains with dynamic predicates from Clang
modules, synthesize predicate functions for `if #available` queries and call
them when generating SIL.

Resolves rdar://138441312.
2025-07-10 08:15:01 -07:00
Saleem Abdulrasool
9ee19116d4 ClangImporter: permit redundancy in the Generate PCM job
`-Xcc` flags are internal to the C compiler; we have `-vfsoverlay` now
which directly passes the VFS overlay. Because the VFS overlay flags are
automatically passed along to the clang scanner, we need to pass along
`-vfsoverlay` to the Swift frontend to ensure that any VFS overlays are
honoured. Most likely this was a workaround for `-vfsoverlay` not
getting propagated originally and when the restriction was lifted the
exercised codepath was not heavily tested.
2025-07-09 14:57:54 -07: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
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
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
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
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
Ben Barham
d9b220c954 Merge pull request #82708 from Bigcheese/dev/importer-ub
[ClangImporter] Fix dangling reference.
2025-07-04 00:13:43 -07:00
Pavel Yaskevich
ed5fd4eeaf Merge pull request #82673 from xedin/rdar-154695053
[Concurrency] SE-0463: `Sendable` inference on sync and async variant…
2025-07-03 23:17:19 -07:00
Saleem Abdulrasool
a2f5d2a746 Merge pull request #82699 from compnerd/feature
ClangImporter: remove Darwin alias workaround, introduce feature
2025-07-03 13:45:45 -07: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
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
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
Saleem Abdulrasool
c08372a91d ClangImporter: remove Darwin alias workaround, introduce feature
Introduce a feature flag to add the importing of macro aliases. Remove
the Darwin specific carve out.
2025-07-02 08:30:03 -07:00
susmonteiro
b3e228845b [cxx-interop] Allow virtual methods to be renamed with swift_name 2025-07-02 16:09:02 +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
Michael Spencer
75ac27dc3d [ClangImporter] Fix dangling reference.
LookupOverloadedBinOp stores `Args` for later use, so store the
backing array on the stack instead of using a temporary.

This fixes a crash that appeared under some build configurations.

Related to rdar://154291418
2025-07-01 17:49:14 -07: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
Gábor Horváth
11cb7e5800 Merge pull request #82333 from swiftlang/gaborh/default-arg-duplicate-symbols 2025-07-01 13:50:00 +02:00
Steven Wu
da3d9f39bd Merge pull request #82608 from cachemeifyoucan/eng/PR-153851818 2025-07-01 01:49:43 -07:00
Pavel Yaskevich
30f0fa8d75 [Concurrency] SE-0463: Sendable inference on sync and async variants of imported APIs should match
This is a follow-up to https://github.com/swiftlang/swift/pull/82085
which made it so async variant doesn't get `@Sendable` inferred because
the proposal specified that inference should happen only on completion
handler parameter type of a synchronous variant of an imported API.

This runs into implementation issues related to thunking in some
cases were async convention expects the type of a completion handler
to match exactly for both variants of the imported API.

Resolves: rdar://154695053
2025-07-01 00:05:20 -07:00
Egor Zhdan
d203591201 Merge pull request #82626 from swiftlang/egorzhdan/nfc-move-header
[cxx-interop] NFC: Move a header from `include` into `lib`
2025-06-30 20:40:04 +01:00
Henrik G. Olsson
e9ba8f8a03 Merge pull request #81855 from hnrklssn/swiftify-availability-check-sdk
[Swiftify] Adjust _SwiftifyImport invocation to align with the signature
2025-06-30 12:00:20 -07:00
Steven Wu
cebe173ada [ScanDependencies] Fix a bug in rewrite from #81454
When improving the speed of dependency scanning when the new clang API
to speed up bridging, some unintended change was introduced. This
restore the scanner to the behavior before #81454

rdar://153851818
2025-06-30 10:49:44 -07: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
Egor Zhdan
0dd18ed427 [cxx-interop] NFC: Move a header from include into lib
CXXMethodBridging.h isn't supposed to be used outside of ClangImporter, so let's keep it inside of ClangImporter's implementation.
2025-06-30 15:58:00 +01:00
Gabor Horvath
33e41f1281 [cxx-interop] Fix duplicate symbol error with default arguments
We synthesize a Swift function that only calls a C++ funtion that
produces the default argument. We produce this function for each module
that imports the C++ function with the default argument. This symbol
needs to be public as it is created in the context of the Clang module
and used from the Swift module. To avoid the linker errors, we always
emit this function into the client which is also the right thing to do
as the whole body is a single function call.

rdar://138513915
2025-06-30 08:23:52 +01:00
Henrik G. Olsson
1d1c64220c Don't attach @_SwiftifyImport if macro declaration not found 2025-06-27 21:37:41 -07:00
Henrik G. Olsson
bd11926bf7 [Swiftify] Adjust _SwiftifyImport invocation to align with the signature
of the macro in the currently laoded macro module

Stdlib macros are shipped with the SDK, so we need to make sure that the
way we invoke the macro matches the version of the macro in the SDK.
This patch skips the `spanAvailability` parameter if it isn't present.
There's no good way to test this, because we will always pick up the
current macro in our llvm-lit test suite, but I've tested it manually.

rdar://152278292
2025-06-27 19:10:23 -07:00
Henrik G. Olsson
374658aae0 [Swiftify] Don't import counted_by with suffixed integer literals (#82469)
Integer literal expressions with types that are not of type `int` are
printed with a suffix to indicate the type (e.g. `123U` or `456L` for
`unsigned` and `long`). This is not valid syntax for integer literals in
Swift, so until we fully translate the count expr syntax to Swift we
need to avoid importing these count expressions.

Also fixes some -Werror related stuff in test cases.

rdar://154141719
2025-06-27 09:27:50 -07:00
Egor Zhdan
f8664adbad Merge pull request #82496 from swiftlang/egorzhdan/allow-qual-swift-name
[cxx-interop] Allow import-as-member for types in namespaces
2025-06-27 13:22:25 +01:00
Anthony Latsis
1f89bb6a94 Merge pull request #82452 from swiftlang/jepa2
Sema: Fix the insertion location for conformances attributes
2025-06-26 21:38:41 +01:00
Pavel Yaskevich
32a0d80b60 Merge pull request #82085 from xedin/rdar-149811049
[ClangImporter] SE-0463: Implement `@Sendable` inference exception for global actor isolated functions
2025-06-26 09:26:28 -07:00
Egor Zhdan
e95f6a3ce9 [cxx-interop] Allow import-as-member for types in namespaces
This adds support for `swift_name` attribute being used with C++ types that are declared within namespaces, e.g.
```
__attribute__((swift_name("MyNamespace.MyType.my_method()")))
```

Previously import-as-member would only accept a top-level unqualified type name.

rdar://138934888
2025-06-26 12:39:50 +01:00
Argyrios Kyrtzidis
d385e8c87a Merge pull request #81792 from sina-mahdavi/sina-mahdavi/fix-llvm-prefix-mapping-calls
fix calls to llvm prefix mapping functions to use space-separated opt…
2025-06-25 13:19:21 -07:00
Gabor Horvath
7474a51691 [cxx-interop] Avoid copies when accessing pointee
Previously, we would get two copies, one accessing the pointee and one
when we pass the pointee as a method as the implicit self argument.
These copies are unsafe as they might introduce slicing. When
addressable paramaters features are enabled, we no longer make these
copies for the standard STL types. Custom smart pointers can replicate
this by making the lifetime dependency between the implicit object
parameter and the returned reference of operator* explicit via a
lifetime annotation.

rdar://154213694&128293252&112690482
2025-06-25 17:09:55 +01:00
Artem Chikin
705b1a667f Merge pull request #82429 from artemcm/ScannerInvalidBinaryModuleRefactor
[Dependency Scanning] Refactor the scanner to simplify layering
2025-06-25 09:03:18 -07:00
Sina Mahdavi
7090b7e145 fix calls to llvm prefix mapping functions to use space-separated option format 2025-06-24 13:32:55 -07:00