Commit Graph

14 Commits

Author SHA1 Message Date
Egor Zhdan
af014c02b3 [cxx-interop] Import iterator types that are not typedef-ed
This prevented `std::vector<std::string>` from being auto-conformed to `CxxRandomAccessCollection`.

If an iterator type is templated, and does not have an explicit instantiation via a typedef or a using-decl, its specialization will not have an owning Clang module. Make sure we treat it as a part of the Clang module that owns the template decl.

rdar://112762768 / resolves https://github.com/apple/swift/issues/67410
2023-07-24 11:25:15 +01:00
Egor Zhdan
594e63d8a3 [cxx-interop] Do not run a test in C++20 mode
This test is failing on UBI platform in C++20 mode:

```
Command Output (stderr):
--
<unknown>:0: warning: the '-enable-experimental-cxx-interop' flag is deprecated; please pass '-cxx-interoperability-mode=' instead
<unknown>:0: note: Swift will maintain source compatibility for imported APIs based on the selected compatibility mode, so updating the Swift compiler will not change how APIs are imported
<unknown>:0: warning: the '-enable-experimental-cxx-interop' flag is deprecated; please pass '-cxx-interoperability-mode=' instead
<unknown>:0: note: Swift will maintain source compatibility for imported APIs based on the selected compatibility mode, so updating the Swift compiler will not change how APIs are imported
/home/build-user/swift/test/Interop/Cxx/stdlib/use-std-vector.swift:41:14: error: for-in loop requires 'Vector' (aka 'std.vector<Int32, allocator<Int32>>') to conform to 'Sequence'
    for e in v {
             ^
/home/build-user/swift/test/Interop/Cxx/stdlib/use-std-vector.swift:52:15: error: value of type 'Vector' (aka 'std.vector<Int32, allocator<Int32>>') has no member 'map'
    let a = v.map { $0 + 5 }
            ~ ^~~

```

This makes sure we don't run this test in C++20 mode until the conformance to `CxxSequence` is synthesized correctly on UBI.

rdar://109366764
2023-05-16 12:27:25 +01:00
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
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
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
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
Egor Zhdan
1f920d5e96 [cxx-interop] Instantiate templated operator== for iterator types
C++ iterator types are often templated, and sometimes declare `operator==` as a non-member templated function. In libc++, an example of this is `__wrap_iter` which is used as an iterator type for `std::vector` and `std::string`.

We don't currently import templated non-member operators into Swift, however, we still want to support common C++ iterator patterns.

This change adds logic to instantiate templated non-member `operator==` for types that define `iterator_category` and are therefore likely to be valid iterator types.

rdar://97915515
2023-01-04 11:56:36 +00:00
Egor Zhdan
7203a05479 [cxx-interop] Replace std module name with the new spelling CxxStdlib
This is the second step in renaming the C++ stdlib module `std` into `CxxStdlib`.

See https://github.com/apple/swift/pull/61099.
2022-11-29 17:33:35 +00: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
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
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