Commit Graph

382 Commits

Author SHA1 Message Date
Egor Zhdan
e9dd9109e7 [cxx-interop] Update the std::pair safety test
The test was passing by accident: we didn't properly check `std::pair` type for completeness, and assumed that it is incomplete.

This updates the test to actually verify the behavior that is specified in the vision document.
2024-01-12 16:21:43 +00:00
Egor Zhdan
2d0863aba2 [cxx-interop] Initial tests for std::function usage
This makes sure that `std::function` is imported consistently on supported platforms, and that it allows basic usage: calling a function with `callAsFunction`, initializing an empty function, and passing a function retrieved from C++ back to C++ as a parameter.

rdar://103979602
2024-01-11 12:02:12 +00:00
Egor Zhdan
8f8d8b058c [cxx-interop] Cleanup CxxStdlib tests
rdar://119270491
2023-12-14 15:45:43 +00:00
Egor Zhdan
af0f1fb6c6 [cxx-interop] Make two tests less restrictive
libc++ has decls that are declared outside of `inline namespace __1`, which might be printed before it.
2023-12-11 12:34:50 +00:00
Alex Lorenz
c7345d08cf Merge pull request #69790 from hyp/eng/move-only-is-back
[cxx-interop] enable support for move-only types
2023-12-06 09:43:43 -08:00
Alex Lorenz
623d3d2032 [cxx-interop] review fixes for non-copyable patch, ensure we only enable this in upcoming Swift 2023-12-05 14:16:30 -08:00
Alex Lorenz
ec931c82c4 [cxx-interop] non-copyable test windows workaround and no SIL verify for NC generic test 2023-12-05 13:42:13 -08:00
Alex Lorenz
633e7f1eb8 fix test 2023-12-02 20:03:36 -08:00
Alex Lorenz
99e6d331fb [cxx-interop] attempt to fix windows unique ptr test 2023-12-01 15:11:41 -08:00
Alex Lorenz
580ecd0893 [cxx-interop] fix Egor's review comments for move-only patch 2023-11-30 10:12:11 -08:00
Egor Zhdan
bc4cffd699 [cxx-interop] Test more of stdlib with the upcoming compat version 2023-11-28 20:49:00 +00:00
Egor Zhdan
7218a831a2 [cxx-interop] Test stdlib with the upcoming compat version 2023-11-22 20:12:08 +00:00
Alex Lorenz
5d8db5cfa1 [cxx-interop] add a testcase for setting the pointee on unique_ptr 2023-11-16 10:08:28 -08:00
zoecarver
a78a7ec4aa [cxx-interop] Cleanup: remove debug printing, enable more tests. 2023-11-16 10:08:27 -08:00
zoecarver
4ba62e1abe [cxx-interop] Add tests for std::unique_ptr. 2023-11-16 10:08:25 -08:00
Egor Zhdan
5e4e83e247 Revert "Revert "[cxx-interop] Partially disable a test on Linux""
This reverts commit 4cf34abe99.

Unfortunately still failing on Ubuntu 18.04 and Amazon Linux 2.

rdar://118401796
2023-11-14 18:41:52 +00:00
Egor Zhdan
efc008a2ca [cxx-interop] Import using decls that expose methods from private base classes
If a C++ type `Derived` inherits from `Base` privately, the public methods from `Base` should not be callable on an instance of `Derived`. However, C++ supports exposing such methods via a using declaration: `using MyPrivateBase::myPublicMethod;`.

MSVC started using this feature for `std::optional` which means Swift doesn't correctly import `var pointee: Pointee` for instantiations of `std::optional` on Windows. This prevents the automatic conformance to `CxxOptional` from being synthesized.

 rdar://114282353 / resolves https://github.com/apple/swift/issues/68068
2023-11-14 00:30:54 +00:00
Egor Zhdan
4cf34abe99 Revert "[cxx-interop] Partially disable a test on Linux"
This reverts commit ff5b698602.
2023-11-07 13:43:27 +00:00
Egor Zhdan
232259ce99 [cxx-interop] Enable an overlay test on Linux
Resolves https://github.com/apple/swift/issues/66363
2023-10-24 13:16:41 +01:00
Ben Barham
360c5d8465 Merge remote-tracking branch 'origin/main' into 20231019-merge-main
Conflicts:
  - `lib/AST/TypeCheckRequests.cpp` renamed `isMoveOnly` which requires
    a static_cast on rebranch because `Optional` is now a `std::optional`.
2023-10-19 16:16:23 -07:00
Alex Lorenz
41dc466108 Merge pull request #68846 from hyp/eng/base-member-cxx-synthesized-accessor
[cxx-interop] Use a synthesized C++ method when invoking a base metho…
2023-10-17 07:07:59 -07:00
swift-ci
ebd4bb6f0c Merge remote-tracking branch 'origin/main' into rebranch 2023-10-11 07:37:15 -07:00
Crazy凡
02a9259dda [cxx-interop] Provide similar support for std::u32string as std::string and std::u16string. 2023-10-10 16:01:15 +08:00
Evan Wilde
24d0db249b Merge remote-tracking branch 'main' into 'rebranch'
Conflicts:
  CMakeLists.txt
    Take new BRIDGING_MODE

  SwiftCompilerSources/Sources/SIL/GlobalVariable.swift
    Take new
2023-10-09 17:21:23 -07:00
Alex Lorenz
3a6a10bb87 Merge pull request #68815 from hyp/eng/re-enable-interop-rebranch-testing
[rebranch] Revert "Disabling failing Cxx Interop tests for rebranch"
2023-10-09 11:13:48 -07:00
Egor Zhdan
041005af7c [cxx-interop] Use more correct type names in C++ template parameters
When importing a C++ class template instantiation, Swift translates the template parameter type names from C++ into their Swift equivalent.

For instance, `basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>>` gets imported as `basic_string<Scalar, char_traits<Scalar>, allocator<Scalar>>`: `wchar_t` is imported as `CWideChar`, which is a typealias for `Scalar` on most platforms including Darwin. Notice that Swift goes through the `CWideChar` typealias on the specific platform. Another instantiation `basic_string<uint32_t, char_traits<uint32_t>, allocator<uint32_t>>` also gets imported as `basic_string<Scalar, char_traits<Scalar>, allocator<Scalar>>`: `uint32_t` is also imported as `Scalar`. This is problematic because we have two distinct C++ types that have the same name in Swift.

This change makes sure Swift doesn't go through typealiases when emitting names of template parameters, so `wchar_t` would now get printed as `CWideChar`, `int` would get printed as `CInt`, etc.

This also encourages clients to use the correct type (`CInt`, `CWideChar`, etc) instead of relying on platform-specific typealiases.

rdar://115673622
2023-10-09 14:57:10 +01:00
swift-ci
aabe4343f5 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-05 11:15:54 -07:00
mohanadkandil
d58943a508 Add filter method for ordered and unordered map (#67501)
Co-authored-by: mkandil <mkandil@synapse-analytics.io>
2023-10-05 19:13:34 +01:00
swift-ci
447482505a Merge remote-tracking branch 'origin/main' into rebranch 2023-10-05 08:05:25 -07:00
Alex Lorenz
ba5b1bab89 [cxx-interop] Use a synthesized C++ method when invoking a base method from a derived class synthesized method
The use of a synthesized C++ method allows us to avoid making a copy of self when invoking the base method from Swift
2023-09-29 13:52:10 -07:00
Alex Lorenz
a6bc07d255 Revert "Disabling failing Cxx Interop tests for rebranch"
This reverts commit 3aea04c440.
2023-09-27 19:06:44 -07:00
Egor Zhdan
f0be52accd [cxx-interop] Add conversion to Bool for types that define operator bool()
C++ `operator bool()` is currently imported into Swift as `__convertToBool()`, which shouldn't be used by clients directly.

This adds a new protocol into the C++ stdlib overlay: `CxxConvertibleToBool`, along with an intitializer for `Swift.Bool` taking an instance of `CxxConvertibleToBool`.

rdar://115074954
2023-09-18 14:54:45 +01:00
Evan Wilde
3aea04c440 Disabling failing Cxx Interop tests for rebranch
Disabling the following tests to get more visibility on rebranch
 -  Interop/Cxx/stdlib/overlay/std-string-overlay.swift
 -  Interop/Cxx/stdlib/use-std-map.swift
 -  Interop/Cxx/stdlib/use-std-pair.swift
 -  Interop/Cxx/stdlib/use-std-vector.swift

Radar to re-enable tests: rdar://115062687
2023-09-06 13:34:43 -07:00
swift-ci
0a6b51526d Merge remote-tracking branch 'origin/main' into rebranch 2023-09-02 08:54:11 -07:00
Saleem Abdulrasool
8f0129b777 test: disable test pending #68068 2023-09-01 10:58:43 -07:00
swift-ci
3b47e15525 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-22 12:55:59 -07:00
Egor Zhdan
c167f4045b [cxx-interop] Conform std::optional to ExpressibleByNilLiteral
This will allow passing `nil` as a parameter to a C++ function that takes a `std::optional<T>`.

rdar://114194600
2023-08-21 19:21:40 +01:00
swift-ci
735f7f424b Merge remote-tracking branch 'origin/main' into rebranch 2023-08-17 08:53:59 -07:00
Finagolfin
30ba49e7fa [android][test] Fix a handful of tests and disable one CxxToSwiftToCxx bridging test
Also, make the analogous change to apple/swift-driver#1372, which gets the
sanitizer tests working on Android again, and remove the lld_lto feature in the
tests, which is now unused.
2023-08-12 16:36:35 +05:30
swift-ci
7d6771cf8e Merge remote-tracking branch 'origin/main' into rebranch 2023-08-10 15:37:51 -07:00
Egor Zhdan
3723ff1401 [cxx-interop] Add UnsafeCxxMutableRandomAccessIterator protocol
This will be used to provide a safe overload of `std::vector::erase` in Swift.

`std::vector::erase` is not currently imported into Swift because it returns a C++ iterator.

rdar://113704853
2023-08-10 19:58:51 +01:00
Alex Lorenz
3581eb84ce Merge pull request #67843 from hyp/eng/rebranch_2023
C++ interop rebranch test fixes
2023-08-09 18:51:50 -07:00
Alex Lorenz
0e6b1ce964 [rebranch][cxx-interop] tests, pass _LIBCPP_DISABLE_AVAILABILITY to workaround libc++ format typealias availability bug 2023-08-09 15:57:56 -07:00
Alex Lorenz
3569c5d6f2 [cxx-interop] Try more stdlib and overlay tests on Windows 2023-08-09 12:59:27 -07:00
Saleem Abdulrasool
d1b63d6969 Merge pull request #67776 from compnerd/the-missing-link
IRGen: rework linking against CxxStdlib
2023-08-08 15:08:48 -07:00
Egor Zhdan
c9720ca330 Merge pull request #67796 from apple/egorzhdan/std-optional-conflict
[cxx-interop] Adjust a test
2023-08-08 20:24:57 +01:00
Alex Lorenz
1addca37a2 Merge pull request #67685 from hyp/eng/hoping-one-day-67674-gets-fixed
[cxx-interop][windows] additional fix for indirect return in methods
2023-08-08 12:13:01 -07:00
Egor Zhdan
e0d7f52467 [cxx-interop] Adjust a test
This prevents a name conflict between a Swift `protocol CxxOptional` and a C++ `using CxxOptional`.
2023-08-08 17:45:18 +01:00
Saleem Abdulrasool
1040116e32 IRGen: rework linking against CxxStdlib
Rewrite the handling for the `CxxStdlib` implicit linking to use a
slightly more functional style for filtering.  Additionally, add Windows
to the list providing the overlay.  The Windows linking scenario is a
slightly more complicated as the library names differ between static and
dynamic variants to disambiguate between import libraries and static
libraries.  Take this into account when embedding the library name so
that the linker can find the appropriate content.
2023-08-08 09:03:37 -07:00
Egor Zhdan
ff5b698602 [cxx-interop] Partially disable a test on Linux
It crashes on Ubuntu 18.04 and Amazon Linux 2.

rdar://113414160
2023-08-08 15:28:19 +01:00