Commit Graph

382 Commits

Author SHA1 Message Date
Egor Zhdan
aed5614ec2 [cxx-interop] Explicitly disable -fmodules-local-submodule-visibility
Clang implicitly enables local submodule visibility when compiling in C++20 mode. ClangImporter does not support it, so let's disable it explicitly.

rdar://108959307 / https://github.com/apple/swift/issues/65710
2023-05-05 21:02:16 +01:00
Zoe Carver
f358cbea8e Merge pull request #65578 from zoecarver/disable-rvalue-ref
[cxx-interop] Disable rvalue references. We don't support them correc…
2023-05-04 10:15:56 -07:00
Alex Lorenz
62fd801828 [interop] C++ parameter of reference type should be imported as its pointee type in Swift even if parameter's type is type alias
This finally allows std::vector.push_back to be called with the pushed value directly passed into it
2023-05-03 18:23:03 -07:00
Alex Lorenz
9a57840c2e Merge pull request #65598 from hyp/eng/loop-std-vector-test-reenable
[interop] NFC, test, re-enable unit test for the for loop iteration o…
2023-05-03 10:52:44 -07:00
Alex Lorenz
17abf2cd3e [interop] NFC, test, re-enable unit test for the for loop iteration over std::vector 2023-05-02 14:54:40 -07:00
Egor Zhdan
46b730db69 [cxx-interop] Update a test on Linux
libstdc++ currently cannot be split into submodules due to the way some types are defined, e.g. there are multiple headers that define `size_t`, so those headers must be a single (sub-)module.
2023-05-02 18:37:03 +01:00
Alex Lorenz
3282fb7bc1 Merge pull request #65437 from hyp/eng/nomathinthiscompiler
[interop] avoid importing math functions from the C++ standard library
2023-04-28 07:21:13 -07:00
Alex Lorenz
8e7766bf18 [interop] avoid importing math functions from the C++ standard library
They cause ambiguities with math functions from platform's libc
2023-04-27 10:25:51 -07:00
Alex Lorenz
0fff76915b [interop] Ensure an FRT or a pointer to struct/class gets a Swift type name for a C++ template parameter
In the follow-up, I should also expand this to cover pointers to builtin types too, but for now lets go with a miminal fix here
2023-04-26 14:48:21 -07:00
Egor Zhdan
d5f5d4bd55 [cxx-interop] Make CxxConvertibleToCollection.forEach public
This allows clients to iterate over a C++ container which doesn't provide random access with a `.forEach` call.

rdar://107995558
2023-04-18 14:43:43 +01:00
Puyan Lotfi
6180387a05 [cxx-interop] Adding std.string initializer for UnsafePointer<CChar>?
Currently without an initializer for the unsafe char pointer type swiftc
hits an assert around not being able to handle conversions of unsafe
pointers with Any type. This patch adds the ability to convert to a
std::string.

This is to address issue https://github.com/apple/swift/issues/61218
2023-04-12 22:03:57 -04:00
Egor Zhdan
242a432919 [cxx-interop] Conform std::string to Hashable
rdar://107709149
2023-04-06 16:15:40 +01:00
Egor Zhdan
8f58eafbd3 [cxx-interop] Make sure interop does not trigger TBD validation errors
This disables TBD validation when C++ interop is enabled, unless an explicit `-validate-tbd-against-ir=` flag was passed.

rdar://83405989 / https://github.com/apple/swift/issues/56458
2023-04-05 16:06:09 +01:00
Egor Zhdan
5520a49ed6 [cxx-interop] Enable use-std-optional test on Linux 2023-04-04 17:10:28 +01:00
Egor Zhdan
b9fc256b27 [cxx-interop] Enable a test on Linux
This test no longer causes a crash on Linux, so let's try enabling it.
2023-04-03 22:27:43 +01:00
Alex Lorenz
48503bfadd [shims] ensure that _SwiftConcurrency has the same Swift interface regardless of whether C++ interop is enabled
This ensures that a module built from Swift interface file (and as such interop is disabled),
that references 'exit' (from _SwiftConcurrencyShims module) can resolve the module reference to
'exit' even when it's being imported when interop is enabled (and thus it loads a different underlying _SwiftConcurrencyShims).
2023-03-28 18:42:26 -07:00
Egor Zhdan
62cb187a3b [cxx-interop] Add operators for comparing and concatenating std::strings
The original C++ operators are not currently imported into Swift because they are defined as a non-member templated functions.

This change adds the operators as Swift extension functions. This also adds an `Equatable` conformance for `std::string`.

rdar://107017882
2023-03-23 18:00:50 +00:00
Alex Lorenz
861d99fa25 [interop] expand std.pair tests after non-trivial record fix 2023-03-17 17:02:14 -07:00
Alex Lorenz
827af150ab [interop] ensure std::pair is imported into Swift 2023-03-14 07:29:48 -07:00
Alex Lorenz
83ebd7d446 [interop] NFC, add a test for importing a C++ module that imports string_view 2023-03-07 16:25:57 -08:00
Egor Zhdan
ac72084854 Merge pull request #63683 from apple/egorzhdan/cxx-optional
[cxx-interop] Add `CxxOptional` protocol for `std::optional` ergonomics
2023-03-06 10:43:05 +00:00
Egor Zhdan
a12986ade4 [cxx-interop] Add CxxOptional protocol for std::optional ergonomics
This adds a protocol to the C++ standard library overlay which will improve the ergonomics of `std::optional` when used from Swift code.

As of now, the overlay adds an initializer of `Swift.Optional` that takes an instance of `CxxOptional` as a parameter.
2023-03-03 19:41:30 +01:00
Egor Zhdan
ed0cee9ce6 [cxx-interop] Conform std::u16string to CustomStringConvertible and CustomDebugStringConvertible
This conforms `std::u16string` to two protocols that `std::string` already conforms to.

rdar://106037638
2023-02-28 19:02:45 +00:00
Egor Zhdan
9d9e015a9f Merge pull request #63833 from apple/egorzhdan/cxx-u16string-reland
Revert "Revert "[cxx-interop] Add conversions between `std::u16string` and `Swift.String`""
2023-02-24 19:59:47 +00:00
Egor Zhdan
9818312da4 Revert "Revert "[cxx-interop] Add conversions between std::u16string and Swift.String""
This re-lands https://github.com/apple/swift/pull/61695 since the linker error on CentOS has been fixed in https://github.com/apple/swift/pull/63058.

This reverts commit e97b1c8e
2023-02-22 18:31:36 +00:00
zoecarver
5c99afcd9b [tests] Fix platform specific tests and reverse interop tests. 2023-02-20 17:58:10 -08:00
zoecarver
985db63e2b [tests] Update tests based on new template name importing rules. 2023-02-20 17:58:10 -08:00
Egor Zhdan
2ea015a46c Merge pull request #63653 from apple/egorzhdan/cxx-ambiguous-pointee
[cxx-interop] Do not synthesize ambiguous pointee properties
2023-02-14 23:03:09 +00:00
Egor Zhdan
cc23f46c92 [cxx-interop] Add a test for std::optional usage from Swift 2023-02-14 17:47:08 +00:00
Egor Zhdan
63f90fe082 [cxx-interop] Partially re-enable a test on Linux
`std::map` conformance to `CxxDictionary` is synthesized properly, only the `std::unordered_map` conformance is problematic.
Let's make sure we test the `std::map` conformance with libstdc++ on Linux.
2023-02-14 15:54:13 +00:00
Egor Zhdan
919eea7045 [cxx-interop] Add CxxDictionary protocol for std::map ergonomics
This adds a protocol to the C++ standard library overlay which will improve the ergonomics of `std::map` and `std::unordered_map` when used from Swift code.

As of now, `CxxDictionary` adds a subscript with an optional return type that mimics the subscript of `Swift.Dictionary`.

Similar to https://github.com/apple/swift/pull/63244.
2023-02-09 14:31:06 +00:00
Alex Lorenz
e025a49edc [interop] NFC, test, drop libcxx-in-sdk requirement
CI is running with SDKs that have libc++ already
2023-02-08 09:20:43 -08:00
Egor Zhdan
bf341ac51c [cxx-interop] Require begin() and end() to be non-mutating for auto-conformed container types
This makes sure that Swift is only auto-conforming C++ container types to `CxxSequence`/`CxxConvertibleToCollection` if they expose non-mutating `begin()` and `end()` methods.

We might want to make `begin()` and `end()` non-mutating in the near future to enable performance optimizations. This change makes sure that client code relying on the automatic conformances doesn't suddenly stop compiling if/when the mutability requirement on the protocol function changes.
2023-02-07 19:08:25 +00:00
Egor Zhdan
34c2b0e50d [cxx-interop] Make String.init(std.string) unlabeled
`Swift.String` can be initialized from any other type with an unlabeled initializer, which is either going to use the `CustomStringConvertible` conformance, or reflection. We would like clients to use the most suitable initializer, which is the one that takes `std.string` as a parameter. For instance, that allows us to attach a doc comment to the initializer.

This change makes the initializer unlabeled to make sure it is chosed by overload resolution when a client invokes `String(myCxxString)`.
2023-02-02 12:47:08 +00:00
Egor Zhdan
d0164ddfb5 Merge pull request #63245 from whiteio/whiteio/add-customstringconvertible-conformance-to-std-string
Make std::string conform to CustomStringConvertible
2023-02-02 12:40:28 +00:00
Egor Zhdan
3983442f97 Merge pull request #63244 from apple/egorzhdan/cxx-set-protocol
[cxx-interop] Add `CxxSet` protocol for `std::set` ergonomics
2023-02-01 16:36:24 +00:00
Alex Lorenz
e6e7bd0629 Merge pull request #63296 from hyp/eng/print-ns-interface-quick
[interop] AST printer should only visit one original namespace decl t…
2023-01-31 14:56:30 -08:00
Alex Lorenz
da30593e93 [interop] test - update to use CxxStdlib module name for printing libc++ interface 2023-01-30 09:19:55 -08:00
Alex Lorenz
62f4ce65c2 [interop] check if CI can find libc++ from swift-ide-test finally 2023-01-29 19:05:34 -08:00
Alex Lorenz
8c6d50ce09 [interop][test] only run libc++ module interface printing test when the SDK has libc++ 2023-01-29 16:25:47 -08:00
Alex Lorenz
88c8893e80 [interop] AST printer should only visit one original namespace decl to avoid printing redecls over and over again
Also, lookup namespace members directly without doing a lookup. This helps us print the libc++ module interface in < 1s on M1
2023-01-29 12:01:07 -08:00
Alex Lorenz
fe6e8ecbe0 Merge pull request #63294 from hyp/eng/ntd-crash-fix
[interop] verify that a C++ record is a Swift nominal type before try…
2023-01-29 10:40:25 -08:00
Alex Lorenz
25bcd26f3b [interop] verify that a C++ record is a Swift nominal type before trying to add explicit protocol conformances
This fixes the issue where we crashed printing foundation
2023-01-29 06:32:03 -08:00
Alex Lorenz
1139f4674b Merge pull request #62820 from zoecarver/revert-883a9abf53799591dbb4c074bc3dd682327f3fcb
Revert "[cxx-interop] Fix crash when indexing with C++ interop enabled."
2023-01-29 06:30:54 -08:00
Alex Lorenz
700eb9334b [interop] update import-foundation-with-indexing.swift to only run on SDK with fixed CF_OPTIONS 2023-01-28 17:11:06 -08:00
Alex Lorenz
0eca9f7388 update import-foundation-with-indexing.swift to check that we actually indexed Foundation 2023-01-28 16:39:08 -08:00
Chris White
7c126bcc88 Make std.string conform to CustomStringConvertible 2023-01-28 16:48:47 +00:00
Egor Zhdan
35553d9306 Merge pull request #62698 from whiteio/whiteio/add-customdebugstringconvertible-conformance-to-std-string
Make std::string conform to CustomDebugStringConvertible
2023-01-26 22:17:08 +00:00
Egor Zhdan
6366878308 [cxx-interop] Add CxxSet protocol for std::set ergonomics
This adds a protocol to the C++ standard library overlay which will improve the ergonomics of `std::set`, `std::unordered_set` and `std::multiset` when used from Swift code.

As of now, `CxxSet` adds a `contains` function to C++ sets.

C++ stdlib set types are automatically conformed to `CxxSet`: `std::set`, `unordered_set`, `std::multiset`. Custom user types are not conformed to `CxxSet` automatically: while a custom type might have an interface similar to `std::set`, the semantics might differ, and adding a conformance would cause confusion.
2023-01-26 19:35:30 +00:00
Egor Zhdan
ee6b9b2a67 [cxx-interop] Disallow import std, require import CxxStdlib
`CxxStdlib` will now be the only accepted module name for the C++ standard library module in Swift.
2023-01-26 14:15:56 +00:00