Commit Graph

382 Commits

Author SHA1 Message Date
Egor Zhdan
bcc07cc4eb [cxx-interop] Enable C++ stdlib overlay on Linux 2022-06-07 16:38:28 +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
ff8464fd2a [cxx-interop] Add basic C++ stdlib overlay
This will allow us to add Swift conformances to C++ standard library types, and improve usability of the C++ standard library from Swift.
2022-05-16 13:30:35 +01:00
Zoe Carver
cb76fa1e7a Merge pull request #42379 from cabmeurer/cabmeurer/std-iterator-available-operations
[cxx-interop] Add tests for the available operations of `std::iterator`
2022-05-09 14:09:22 -07: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
Caleb Meurer
723363545e [cxx-interop] Add tests for the available operations of std::iterator 2022-04-28 19:22:16 -06: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
4feee3dfe6 [cxx-interop] Fix libstdc++ test failure with Ubuntu 18.04
When importing an older version of libstdc++, the decls might get printed in a different order. This change makes the test work properly for libstdc++-7 as well as libstdc++-9.

rdar://91518316
2022-04-12 12:08:33 +01:00
Erik Eckstein
974e97d912 temporarily disable Interop/Cxx/stdlib/libstdcxx-module-interface.swift
rdar://91518316
2022-04-09 10:43:01 +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
Egor Zhdan
626eadcf64 [cxx-interop] Import size_t as Int instead of UInt on Linux
When using libc++, Swift imports `size_t` as Int despite `size_t` being an unsigned type. This is intentional & is specified in `lib/ClangImporter/MappedTypes.def`. Previously, MappedTypes were only honored for C/C++ types declared on the file level.

In libstdc++, `size_t` is declared within `namespace std` and not on the file level, so the mapping to Int was not applied.

This change ensures that MappedTypes are also applied to types declared in `namespace std`.
2022-03-24 15:29:19 +00: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
Zoe Carver
477b4d68fa Merge pull request #40924 from zoecarver/interop-fix-linker-errors-2 2022-01-20 08:01:13 -08:00
zoecarver
b8abf84039 [cxx-interop] Comment out failing test while I find a solution.
Using std::vector in a for-loop causes problems with some configurations. See rdar://87728422 and rdar://87805795.

This is a temporary fix to make the bots green.
2022-01-19 19:35:34 -08:00
Zoe Carver
afd640842e Merge pull request #40893 from zoecarver/interop-index-store-crash
[cxx-interop] Fix crash when indexing with C++ interop enabled.
2022-01-18 13:31:26 -08:00
zoecarver
883a9abf53 [cxx-interop] Fix crash when indexing with C++ interop enabled.
This is a stop-gap solution to prevent crashes.
2022-01-18 10:20:09 -08:00
zoecarver
ba44bfecce [cxx-interop] Add -lc++ when C++ interop is enabled on Darwin. 2022-01-17 12:11:06 -08:00
zoecarver
323e2b16a7 [cxx-interop] Fix linker errors when using std-vector.
Adds tests for using std-vector and some other interesting types.

This patch fixes four mis conceptions that the compiler was previously making:

	1. Implicit destructors have no side effects. (Yes, this means we were not cleaning up some objects.)
	2. Implicit destructors have bodies. (Technically they do, but the body doesn't include CallExprs that they make when lowered to IR.)
	3. Functions other than methods can be uninstantiated templates.
	4. Uninstantiated templates may have executable code. (I.e., we can never take the fast path.)

And makes sure that we visit the destructor of any VarDecl (including parameters).
2022-01-17 11:56:15 -08:00
zoecarver
b8e52a7ad2 [cxx-interop] Lazily import members of Clang namespaces and records via requests.
Also adds a ClangImporter request zone and move some requests into it.
2021-10-20 14:52:43 -07:00
Mishal Shah
eabfce9502 Merge pull request #39657 from slavapestov/rdar84036022
Disable failing test (rdar://84036022)
2021-10-08 11:39:41 -07:00
Slava Pestov
594594182f Disable failing test (rdar://84036022) 2021-10-08 14:26:50 -04:00
David Zarzycki
61ae3aeb7c [testing] Convert XFAIL to UNSUPPORTED in C++ module testing
It's possible to build Swift where libcxx is implicitly used, so this
test is brittle if it uses XFAIL.
2021-10-07 12:56:13 -04:00
Egor Zhdan
bbd9b8f10a Merge pull request #39562 from egorzhdan/cxx-std-module-interface
C++ Interop: add a test for std module interface
2021-10-06 21:02:38 +03:00
Egor Zhdan
bb5f9ebb04 C++ Interop: add a test for std module interface
The test checks that the Swift module interface for `std` & its submodules can be generated & that it contains a couple of known declarations.
2021-10-04 20:59:14 +03:00
Daniel Rodríguez Troitiño
a96c53e5c5 [android] Disable fake-toolchain-module-interface test
Android NDK layout might not be the same as the system layout for
finding libc++ so the test seems to fail. Disabling for the time being
to avoid having the CI broken.
2021-10-01 11:52:57 -07:00
Egor Zhdan
64113270df ClangImporter: run Clang with a proper executable path (pt 2)
This change re-applies https://github.com/apple/swift/pull/36749 after it has been reverted in https://github.com/apple/swift/pull/37805 because of a broken standalone stdlib build.
2021-06-22 22:28:55 +03:00