Commit Graph

382 Commits

Author SHA1 Message Date
Egor Zhdan
8e2f0e2d50 Merge pull request #75877 from swiftlang/egorzhdan/std-map-init
[cxx-interop] Allow initializing `std::map` from Swift Dictionary
2024-08-14 21:49:56 +01:00
Egor Zhdan
9fe13ece49 [cxx-interop] Allow initializing std::map from Swift Dictionary
This adds initializers for `std::map` and `std::unordered_map` that take a Swift dictionary as a single parameter.

rdar://133691563
2024-08-14 13:32:30 +01:00
Alex Lorenz
d35af38ce4 Merge pull request #75721 from hyp/eng/75691
[windows] split out complex module from ucrt module, to allow new swi…
2024-08-12 08:30:47 -07:00
Egor Zhdan
bfe72b4be9 Merge pull request #75589 from swiftlang/egorzhdan/linux-libcxx-interop
[cxx-interop] Allow compiling with libc++ on Linux
2024-08-09 13:42:29 +01:00
Egor Zhdan
059f0f97d1 [cxx-interop] Allow compiling with libc++ on Linux
This makes sure that Swift respects `-Xcc -stdlib=libc++` flags.

Clang already has existing logic to discover the system-wide libc++ installation on Linux. We rely on that logic here.

Importing a Swift module that was built with a different C++ stdlib is not supported and emits an error.

The Cxx module can be imported when compiling with any C++ stdlib. The synthesized conformances, e.g. to CxxRandomAccessCollection also work. However, CxxStdlib currently cannot be imported when compiling with libc++, since on Linux it refers to symbols from libstdc++ which have different mangled names in libc++.

rdar://118357548 / https://github.com/swiftlang/swift/issues/69825
2024-08-08 16:24:58 +01:00
Alex Lorenz
b62eafd866 [windows] split out complex module from ucrt module, to allow new swift-foundation to import ucrt when C++ interoperability is enabled
Fixes https://github.com/swiftlang/swift/issues/75691
2024-08-06 11:33:03 -07:00
Susana Monteiro
7bda2b3e81 Merge pull request #75474 from swiftlang/susmonteiro/cxx-span-tests
[cxx-interop] Test: initialize std::span in C++ from Swift array
2024-07-25 18:09:26 +01:00
smonteiro2
2541735714 [cxx-interop] Test: initialize std::span in C++ from Swift array 2024-07-25 15:05:57 +01:00
smonteiro2
0ef50125a3 [cxx-interop] Constructor Span(baseAddress, count) is deprecated
This constructor is unsafe, as it allows creating a `std::span` with a count higher than the size of the sequence of objects it refers to. Therefore, when hardening is enabled, an out-of-bounds access won't trap.
We make it deprecated to discourage its use.
2024-07-25 11:48:50 +01:00
Egor Zhdan
71c27a9d17 Merge pull request #75395 from swiftlang/egorzhdan/std-function-test
[cxx-interop] Add one more test for `std::function`
2024-07-22 19:28:45 +01:00
Egor Zhdan
d7212ff7f5 [cxx-interop] Add one more test for std::function
While initializing a `std::function` that takes `const std::string&` as a parameter currently crashes, changing the parameter type to `std::string` should work fine.
2024-07-22 13:54:09 +01:00
smonteiro2
684e9ebf0c [cxx-interop] Implements CxxMutableSpan, created from an UnsafeMutableBufferPointer
* Added tests for generic functions
* Add some tests for mutable spans
* Initialize ConstSpan from UnsafeMutableBufferPointer
* Change hardening flag
2024-07-19 10:38:52 +01:00
Egor Zhdan
b7fc492b14 [cxx-interop] Conditionally re-enable a test for std::function, pt 3
This also disables the test on Fedora.

rdar://125816354
2024-07-05 16:12:40 +01:00
Susana Monteiro
bb16e50237 Merge pull request #74970 from swiftlang/susmonteiro/cxx-span-class-tests
[cxx-interop] Add tests for std::span inside struct
2024-07-05 12:13:46 +01:00
smonteiro2
f75a2f596f Add tests for span inside struct 2024-07-04 16:02:27 +01:00
Egor Zhdan
6c17565bd3 [cxx-interop] Conditionally re-enable a test for std::function, pt 2
The post-commit CI uses a slightly different version of UBI.

rdar://125816354
2024-07-04 15:28:49 +01:00
Egor Zhdan
af311ff003 [cxx-interop] Conditionally re-enable a test for std::function
Let's re-enable the test on all platforms except Ubuntu 22.04 and UBI 9, which are shipped with libstdc++11.

rdar://125816354
2024-07-03 12:36:13 +01:00
susmonteiro
e86099c26d [cxx-interop] Implements constructor for std::span from UnsafeBufferPointer
Tests: init span from UnsafeBufferPointer, for loop, map, filter, init Array from span, span of strings
2024-07-01 16:07:28 +01:00
susmonteiro
9aa132bd71 [cxx-interop] Enable hardening when running tests for std::span
Add tests that receive std::span as param
2024-06-28 15:01:23 +01:00
Pavel Yaskevich
0987555a9c [Tests] NFC: Temporarily disable test/Interop/Cxx/stdlib/use-std-function.swift
The test is blocking nightly toolchains.
2024-06-27 21:12:40 -07:00
Egor Zhdan
9d6e36b512 Merge pull request #74771 from susmonteiro/susmonteiro/cxx-span-fix-failing-test
[cxx-interop] Add requirement executable_test
2024-06-27 17:33:36 +01:00
susmonteiro
b3107586f6 [cxx-interop] Add requirement executable_test
rdar://130527435
2024-06-26 12:32:09 +01:00
Alex Lorenz
0c7621d282 Merge pull request #74541 from hyp/eng/lookup-imported-member-operator-cxx
[cxx-interop][serialization] resolve x-refs to instantiated/synthesiz…
2024-06-25 08:45:02 -07:00
Alex Lorenz
983fb8025a [cxx-interop][serialization] resolve x-refs to instantiated/synthesized C++ iterator conformance operators
These x-refs might not be resolvable using regular lookup from the 'std' module as they could be instantiated/synthesized
by the clang importer. Augment the lookup logic in that case to try clang importer lookup logic that is used during
the conformance to the C++ iterator protocol.
2024-06-20 14:51:34 -07:00
Susana Monteiro
823e809db5 Merge pull request #74426 from apple/susmonteiro/cxx-span
[cxx-interop] Add `std::span` tests
2024-06-18 17:58:03 +01:00
susmonteiro
76feea8fa7 [cxx-interop] Add std::span tests
Add compiler flag to specify C++20

Disable swift-ci linux tests
2024-06-18 14:32:49 +01:00
Egor Zhdan
7c165272c5 Merge pull request #71396 from apple/egorzhdan/cxx-std-function
[cxx-interop] Allow initializing `std::function` from Swift closures
2024-06-17 12:31:56 +01:00
Egor Zhdan
3243228897 [cxx-interop] Allow initializing std::function from Swift closures
This adds a Swift initializer to instantiations of `std::function` that accepts a Swift closure with `@convention(c)`.

rdar://103979602
2024-06-14 19:05:45 +01:00
Alex Lorenz
98b74d8010 [android] do not import stdatomic from android's libc++
android's libc++ uses an older module map that requires C++23 for stdatomic, and thus it fails to compile with anything else
2024-06-12 10:04:14 -07:00
Egor Zhdan
b330376a43 [cxx-interop] Pull changes from swift-6 compat mode into swift-5.9
This gives projects using C++ interop compat mode 5.9 access to the new features such as virtual methods and move-only types.

rdar://126485814
2024-04-24 11:53:31 +01:00
Egor Zhdan
1be7230876 [cxx-interop] Use C++17 standard by default
Clang is using C++17 standard version by default since Clang 16.

Swift’s ClangImporter should do the same, to make sure that clients who run clang and then swiftc without explicit std version see consistent behavior.

rdar://125777068
2024-04-02 16:23:32 +01:00
Daniel Rodríguez Troitiño
8b4821f1a8 [cxx-interop] Fix test header to declare linkage for a implicit template (#72522)
The header was defining a function, the function created a lambda, and
the lambda was transformed into a `std::function`. This transformation
is incorrect because the function scope does not have linkage, so the
instantiated types will not have linkage either, causing the error
below.

```
.../include/c++/11.2.0/bits/invoke.h:104:5:
error: function 'std::__invoke_r<int, (lambda at .../swift/test/Interop/Cxx/stdlib/Inputs/std-function.h:9:10) &, int>' is used but not defined in this translation unit, and cannot be defined in any other translation unit because its type does not have linkage
102 │   template<typename _Res, typename _Callable, typename... _Args>
103 │     constexpr enable_if_t<is_invocable_r_v<_Res, _Callable,
    _Args...>, _Res>
    104 │     __invoke_r(_Callable&& __fn, _Args&&... __args)
        │     ╰─ error: function 'std::__invoke_r<int, (lambda at .../swift/test/Interop/Cxx/stdlib/Inputs/std-function.h:9:10) &, int>' is used but not defined in this translation unit, and cannot be defined in any other translation unit because its type does not have linkage
        105 │     noexcept(is_nothrow_invocable_r_v<_Res, _Callable,
            _Args...>)
  106 │     {

  }
```

Declaring the function `inline` forces each TU to have their own copies
of the function, which avoids the instantiated templates from being in a
different TU than the one using them.

The header would not have worked in a normal C++ program, since none of
the functions declare linkage, they would have been defined in each TU
that included the header and it would fail linking as soon as two of
those TU tried to be linked together. Declaring the functions `inline`
avoids the problem (a more normal header, only with declarations, would
also worked).
2024-03-23 07:55:28 -07:00
Egor Zhdan
19a257b36b [cxx-interop] Test stdlib support with newer C++ standards 2024-03-21 16:44:38 +00:00
Egor Zhdan
7df8812feb Merge pull request #72006 from naknut/remove_LIBCPP_DISABLE_AVAILABILITY
Remove -D_LIBCPP_DISABLE_AVAILABILITY from tests
2024-03-19 16:18:36 +00:00
Egor Zhdan
53fb6531f2 [cxx-interop] Add conversions between std::chrono::duration and Swift.Duration
rdar://123696734
2024-03-01 13:15:05 +00:00
Egor Zhdan
78b9de1391 [cxx-interop] Run tests with swift-6 compat mode 2024-02-23 16:24:14 +00:00
Marcus Isaksson
df759eeb85 Remove -D_LIBCPP_DISABLE_AVAILABILITY from tests 2024-02-23 13:57:53 +01:00
Egor Zhdan
db424e23cb Merge pull request #71243 from apple/egorzhdan/std-vector-bridging-header
[cxx-interop] Make automatic conformances work with the bridging header
2024-02-01 13:14:10 +00:00
Egor Zhdan
c26fe86754 [cxx-interop] Make automatic conformances work with the bridging header
For C++ types that are defined in the bridging header, or are `#include`-d from the bridging header, we did not generate the automatic conformances to `CxxSequence`, `CxxRandomAccessCollection` protocols.

To check whether we should try to conform a C++ type to those protocols, the compiler checks for the presence of `requires cplusplus` in the module declaration in a modulemap file. This check is there to prevent us from accidentally pulling in `Cxx`/`CxxStdlib` modules when a client is importing a C library.

This change makes sure those conformances are generated.

rdar://121927459
2024-01-31 13:56:18 +00:00
Egor Zhdan
840b1dfee8 Merge pull request #71181 from apple/egorzhdan/default-arg-copy-ctor
[cxx-interop] Check for unsafe types of default arguments consistently
2024-01-29 16:13:13 +00:00
Egor Zhdan
d594f475ee [cxx-interop] Check for unsafe types of default arguments consistently
If the C++ type of a function parameter defines a custom copy constructor, assume that it is safe to use from Swift. This matches the heuristic that we use to detect if a C++ method is safe based on the return type.

rdar://121391798
2024-01-26 19:26:27 +00:00
Egor Zhdan
77f18eef4b Merge pull request #71153 from apple/egorzhdan/fix-split-libcxx-tests
[cxx-interop] Fix tests with split libc++ module
2024-01-26 16:55:26 +00:00
Egor Zhdan
997b2490ce [cxx-interop] Only run certain tests with older libc++
rdar://119869070
2024-01-26 13:49:11 +00:00
Egor Zhdan
8c807d9b33 [cxx-interop] Fix tests with split libc++ module
rdar://119869070
2024-01-25 20:07:40 +00:00
Egor Zhdan
4979879d25 [cxx-interop] Do not pass -tools-directory in tests
ClangImporter is now able to find the C++ stdlib on its own, let's not provide any explicit options that control this in tests.

rdar://119869070
2024-01-25 14:22:17 +00:00
Egor Zhdan
3cb2500711 [cxx-interop] Cleanup tests: rename a test file for consistency 2024-01-24 17:34:17 +00:00
Egor Zhdan
0d5a6fa406 [cxx-interop] Cleanup tests: merge two std::string tests 2024-01-24 17:33:52 +00:00
Egor Zhdan
206164013b Merge pull request #70772 from apple/egorzhdan/std-function-initial-tests
[cxx-interop] Initial tests for `std::function` usage
2024-01-17 13:25:02 +00:00
Egor Zhdan
a61d9333e9 [cxx-interop] Re-export C++ stdlib in tests that require it 2024-01-16 18:07:29 +00:00
Egor Zhdan
ef702ad6f6 [cxx-interop] Split some modules in tests
This cleans up the C++ iteration tests and makes sure that we test the setup where a C++ iterator and a C++ collection are defined in different Clang modules.
2024-01-16 17:54:23 +00:00