Commit Graph

22 Commits

Author SHA1 Message Date
Egor Zhdan
19a257b36b [cxx-interop] Test stdlib support with newer C++ standards 2024-03-21 16:44:38 +00:00
Egor Zhdan
78b9de1391 [cxx-interop] Run tests with swift-6 compat mode 2024-02-23 16:24:14 +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
0d5a6fa406 [cxx-interop] Cleanup tests: merge two std::string tests 2024-01-24 17:33:52 +00:00
Egor Zhdan
7218a831a2 [cxx-interop] Test stdlib with the upcoming compat version 2023-11-22 20:12:08 +00:00
Egor Zhdan
dab1cb5e12 [cxx-interop] Simplify a std::string test
`std::string` can be accessed directly from Swift, there is no need to go through a using-decl.
2023-06-13 17:22:21 +01: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
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
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
Egor Zhdan
0a8e838b47 [cxx-interop] Enable test/Interop/Cxx/stdlib/use-std-string.swift on Windows 2023-01-06 18:30:30 +00:00
Egor Zhdan
e3c58386b7 [cxx-interop] Recognize CxxStdlib as an alias for std
C++ standard library module is called `std`. To make it more clear to a Swift developer that this module is a C++ stdlib, and not a Swift stdlib, let's rename it to `CxxStdlib`.

This is the first step in the module rename. We don't ban `std` in this patch to be able to build SwiftCompilerSources with hosttools until a new Swift compiler is shipped.
2022-09-15 14:37:38 +01:00
Egor Zhdan
abf56bcb33 [cxx-interop] Extract libstdc++ installation path from Clang
To inject a modulemap into the libstdc++ directory, Swift needs to know the path of the libstdc++ installation. Previously it was assumed to be `/usr/include/c++/{version}`, however, this might not be the case. For example, on CentOS the stdlib is located at `/opt/rh/devtoolset-{version}/root/usr/include/c++/{version}`.

This change teaches Swift to extract the libstdc++ include paths from the Clang driver, and fixes C++ stdlib lookup on CentOS.

rdar://93341210
2022-05-18 19:27:29 +01:00
Egor Zhdan
37f0426fec [cxx-interop] Disable failing tests to unblock nightly toolchains
rdar://93341210
2022-05-17 20:27:10 +01:00
Egor Zhdan
7db3666e43 [cxx-interop] Fix test/Interop/Cxx/stdlib/use-std-string.swift
Temporarily disable the checks for mutable fields in a C++ struct. A better solution would be to use some heuristic to detect if a method mutates a mutable field, and allow the user to adjust mutability with the existing `nonmutating` annotation.

rdar://92621793
2022-05-03 16:36:40 +01:00
Ben Barham
7582350f9a [Test] Temporarily disable test/Interop/Cxx/stdlib/use-std-string.swift 2022-05-02 15:22:55 -07:00
Egor Zhdan
fca494e66d [cxx-interop] Ignore mutable fields when detecting method mutability
rdar://91961524
2022-04-19 18:23:32 +01:00
Egor Zhdan
2131d20fa9 [cxx-interop] Fix libstdc++ test failure with CentOS 7
CentOS 7 comes with an outdated libstdc++ version. In that version, `std::basic_string` has a `mutable` member, which makes all of `basic_string`'s member functions mutating in Swift. This prevents us from calling `size()` or `empty()` on an immutable value of `std.string`.

rdar://91548568
rdar://91670704
2022-04-14 12:47:18 +01:00
Erik Eckstein
b4ed14764a tests: disable two C++ interop tests to unblock CI
rdar://91670704
rdar://91548568
2022-04-13 08:43:52 +02:00
Egor Zhdan
a3e914364a [cxx-interop] Import libstdc++ as a Clang module
This change adds a module map for libstdc++, which allows it to be properly imported into Swift as a module. The module map is installed into `usr/lib/swift/linux/{arch}` similarly to `glibc.modulemap`, and is passed to Clang as `-fmodule-map-file`.

That means it is now possible to import std directly from Swift on Linux, when C++ interop is enabled.

The module map currently declares a single `std` module without splitting the headers into submodules. This is going to change in the near future.

rdar://87654514
2022-04-08 14:10:04 +01:00
zoecarver
839839f924 [cxx-interop] Rename enable-cxx-interop -> enable-experimental-cxx-interop.
Also removes the driver flag, this will now also always be guarded on `-Xfrontend`.
2022-04-07 19:15:25 -07:00
Ehud Adler
0056129d57 [cxx-interop] std::string::push_back is broken (#41240)
* [cxx-interop] fix  std::string::push_back by fixing mapping between clang/swift self/this type for cxx methods

* cleanup

* Fix unit test

* XFail test: operators/member-inline on linux-android

* add `C++` in expandExternalSignatureTypes comment

* Fix rebase

* Fix mapping issue in externalizeArguments

* Improve cxx_interop_ir test regex
2022-03-08 13:09:38 -05:00
zoecarver
fefe39e89e [cxx-interop] Add a basic test for using std::string. 2022-02-02 14:31:04 -08:00