Commit Graph

179 Commits

Author SHA1 Message Date
Alex Lorenz
fedf86ff76 Merge pull request #63809 from hyp/eng/exception1
[interop] add itanium ABI support for trapping on uncaught exceptions when making a foreign call
2023-02-23 19:41:43 -08:00
Zoe Carver
314a652aab Merge pull request #63841 from zoecarver/remote-support-for-dependent-types
[cxx-interop] Disable support for dependent types.
2023-02-23 09:45:11 -08:00
zoecarver
de67ef26e2 [cxx-interop] Disable support for dependent types.
We should not use this hack for dependent types. We need to add proper support for dependent types (we can't just use `Any`).
2023-02-22 11:56:09 -08:00
Alex Lorenz
9feb76419b [interop] ignore exceptions in existing interop tests 2023-02-22 11:00:51 -08:00
zoecarver
985db63e2b [tests] Update tests based on new template name importing rules. 2023-02-20 17:58:10 -08:00
Egor Zhdan
ca6fd61614 Merge pull request #63063 from apple/egorzhdan/cxx-diagnostic-crash
[cxx-interop] Do not crash while generating a diagnostic for un-instantiatable template
2023-01-18 12:57:49 +01:00
Egor Zhdan
65f319a242 [cxx-interop] Do not crash while generating a diagnostic for un-instantiatable template
Swift was previously crashing while emitting an error ("could not generate C++ types from the generic Swift types provided") for C++ decls that do not have a name, such as constructors: `func->getName()` triggered an assertion.
2023-01-17 17:19:20 +00:00
Egor Zhdan
1965e74b74 [cxx-interop] Emit IR for templated static members with an out-of-line definition
This fixes https://github.com/apple/swift/issues/63055.

rdar://101539308
2023-01-17 12:09:11 +00:00
Anthony Latsis
4cb63c8a0f [NFC] Migrate remnant Jira issue references to GitHub issues 2022-12-04 08:20:34 +03:00
zoecarver
b4abb47a65 [cxx-interop] Mark un-specialized class templates as unavailable in Swift.
They don't really work, so let's not "support" them yet.
2022-10-19 17:50:53 -07:00
Egor Zhdan
1b41703b6b [cxx-interop] Do not instantiate templates in unevaluated contexts
Previously we tried to instantiate templates in unevaluated contexts. Some of these templates might not be instantiatable, which caused compile errors, while the equivalent C++ code compiles and runs with no issue.

This was problematic for `std::vector` with libstdc++ on Linux.

Fixes https://github.com/apple/swift/issues/61547.
2022-10-12 19:04:47 +01:00
Puyan Lotfi
84a69c4143 [C++-Interop] Import const &T function parameters as @in_guaranteed
When passing value types as a const-ref to a C++ API, ensure that the
caller is tasked with handling the lifetime of the instance passed in.
2022-09-12 16:27:27 -04:00
Anthony Latsis
a65f1a161e Gardening: Migrate test suite to GH issues: Interop 2022-08-31 05:20:25 +03:00
swift-ci
dafdbea8a3 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-28 01:59:13 -07:00
Egor Zhdan
44f3478289 [cxx-interop] Do not try to import uninstantiatable templates
Calling `clangSema.isCompleteType` tries to instantiate a template, and if that is impossible, returns `true`. This caused Swift to try to import invalid C++ template instantiations.

This was discovered during C++ interop adoption in SwiftCompilerSources:
Several LLVM headers declare a field with a type `DenseMap<int, ForwardDeclared>` where `ForwardDeclared` is defined in an implementation file (`.cpp`) and is not visible to ClangImporter. That is valid in C++ but caused an error when importing into Swift.
2022-07-27 23:12:32 +01:00
swift-ci
fd2a82f8e2 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-27 11:57:04 -07:00
Egor Zhdan
900ca68560 [cxx-interop] Make sure to print template instantiations in the module interface
#60246
2022-07-26 20:30:15 +01:00
swift-ci
9de631f94f Merge remote-tracking branch 'origin/main' into rebranch 2022-07-19 17:35:57 -07:00
zoecarver
6acffbbee6 [cxx-interop] Flip the switch: only import safe APIs. 2022-07-18 17:15:15 -04:00
swift-ci
cf93f5718f Merge remote-tracking branch 'origin/main' into rebranch 2022-06-30 08:54:09 -07:00
Holly Borla
6e8a581b42 [LangOptions] Remove the option to enable/disable implicit existential
opening.
2022-06-27 18:03:20 -07:00
Ben Barham
f6d432feed [next] Generalise further interop tests
See e382e15f6a for previous test fixes -
these were xfailed at the time, so weren't updated then.
2022-06-03 11:01:19 -07:00
swift-ci
25ecf91ca9 Merge remote-tracking branch 'origin/main' into rebranch 2022-05-17 10:15:00 -07:00
Caleb Meurer
2f8c32ced6 [cxx-interop] Import complex inferred dependent return types 2022-05-16 17:07:37 -06:00
Ben Barham
e382e15f6a [next] Generalise interop tests that only care about name and types
Due to a now default-enabled `undef` pass (llvm/llvm-project
1b1c8d83d3567a60280291c0adb95d1d60335509), a whole bunch of interop
IRGen tests are failing due to missing `undefs`, even though they don't
matter in these tests at all. Add regex matches so that these tests just
check for the name and types of the functions they care about.
2022-05-13 14:39:26 -07:00
Josh Soref
e75e5b5a03 Spelling interop (#42549)
* spelling: different

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: disappear

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: executable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: instantiate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: instantiation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: member

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parameter

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: section

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: trivia

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unrelated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-22 14:13:23 -07: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
27ad9389b4 Merge pull request #42222 from apple/egorzhdan/cxx-template-linker-error
[cxx-interop] Fix linker errors when a template is used from different modules
2022-04-07 22:50:49 +01:00
Egor Zhdan
e9b0c8d705 [cxx-interop] Fix linker errors when a template is used from different modules
If a templated C++ class is used from two different C++ modules, and those modules are included in Swift, Clang will create different two different redecls for the class & its methods.

For each of the methods, only one of the redecls would actually have a body, the other would have empty bodies. That prevents `ClangDeclFinder` from properly finding the symbols referenced from a method body, leading to a linker error in some cases, when the first redecl is missing a body.

This prevents `std::string` from being used on Linux:
```
/tmp/use-std-string-2dd593.o:use-std-string-2dd593.o:function void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag): error: undefined reference to 'bool __gnu_cxx::__is_null_pointer<char>(char*)'
/tmp/use-std-string-2dd593.o:use-std-string-2dd593.o:function void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag): error: undefined reference to 'std::iterator_traits<char*>::difference_type std::distance<char*>(char*, char*)'
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
```
2022-04-07 20:31:12 +01:00
zoecarver
16c8d0b4d3 [cxx-interop] Bail on parameter that are reference types to dependent types.
Currently, just like for return types, we can't import references to dependent types. Refs https://github.com/apple/swift/pull/41660.
2022-03-29 14:58:55 -07:00
Zoe Carver
687beace5e Merge pull request #41894 from apple/egorzhdan/cxx-decltype-crash
[cxx-interop] Avoid crashing when importing functions that take pointers to dependent types
2022-03-21 18:00:05 -07:00
Egor Zhdan
7bcd13b899 [cxx-interop] Avoid crashing when importing functions that take pointers to dependent types
Importing `type_traits` from libstdc++ currently causes a crash on Linux:
```
swift-ide-test: tools/clang/include/clang/AST/TypeNodes.inc:33: clang::TypeInfo clang::ASTContext::getTypeInfoImpl(const clang::Type *) const: Assertion `!T->isDependentType() && "should not see dependent types here"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/egorzh/Builds/swift/swift/bin/swift-ide-test -print-module -module-to-print=std -source-filename=x -enable-cxx-interop
1.	/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/type_traits:1110:10: importing 'std::__do_is_implicitly_default_constructible_impl'
2.	/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/type_traits:1116:22: importing 'std::__do_is_implicitly_default_constructible_impl::__test'
```

This change fixes the crash by bailing on such functions.
2022-03-21 20:33:26 +00:00
Egor Zhdan
9e919fdd1d Merge pull request #41765 from apple/egorzhdan/cxx-test-linux
[cxx-interop] Enable a test on Linux
2022-03-10 09:42:00 -08:00
Egor Zhdan
231af68205 [cxx-interop] Enable a test on Linux
This test doesn't actually rely on the C++ stdlib, I think it was disabled accidentally.

It currently passes on Linux.
2022-03-10 13:26:25 +00:00
Erik Eckstein
6a020f8f15 Stabilize and simplify SIL linkage and serialization
The main point of this change is to make sure that a shared function always has a body: both, in the optimizer pipeline and in the swiftmodule file.
This is important because the compiler always needs to emit code for a shared function. Shared functions cannot be referenced from outside the module.
In several corner cases we missed to maintain this invariant which resulted in unresolved-symbol linker errors.

As side-effect of this change we can drop the shared_external SIL linkage and the IsSerializable flag, which simplifies the serialization and linkage concept.
2022-03-09 15:28:05 +01:00
Hamish Knight
e8891b658a [test] XFAIL dependent-types.swift on 32 bit platforms
rdar://89296327
2022-03-08 14:35:04 +00:00
Zoe Carver
6d19bab9b3 Merge pull request #41611 from zoecarver/const-ref-as-value 2022-03-03 19:58:16 -08:00
Zoe Carver
9a7f5c862b Merge pull request #41569 from zoecarver/fix-class-template-metadata-issue 2022-03-03 19:57:32 -08:00
Alex Lorenz
ebb21d7ec1 [cxx-interop] Import const T& parameters as T.
This change allows Swift code to pass immutable values to const references in C++.
2022-03-03 14:42:27 -08:00
zoecarver
2749026103 [cxx-interop] Class template specializations each need their own metadata.
Make sure each class template specialization has its own metadata/value witness table. The issue here is that we got the name wrong. We need to use the mangled name so its different for each specialization.
2022-03-03 14:26:37 -08:00
zoecarver
e6a99cb969 [cxx-interop] Cache specialized function templates.
This not only prevents us from creating a bunch of FuncDecls but actually is required to prevent duplicate symbol errors.
2022-03-02 11:14:09 -08:00
Zoe Carver
5974cd0908 Merge pull request #41466 from zoecarver/support-basic-inout-case 2022-02-18 22:03:25 -08:00
Doug Gregor
e3af684772 Merge pull request #41183 from DougGregor/implicitly-open-existentials 2022-02-18 18:04:04 -08:00
zoecarver
f73e20b795 [cxx-interop] Fix crash when inout parameter is used in some "template contexts".
We used to incorrectly forward inout paramters in the thunk for both template paramters that aren't used in the signature and in the thunk for dependent types as Any.

Now this works in the simple case. We'll need to do something more complicated when we have an `inout Any` for dependent types because we will need to somehow cast without copying. This will probably require synthesising the SIL of the thunk manually.
2022-02-18 15:11:14 -08:00
zoecarver
c2b6828ff1 [nfc] XFAIL dependent-types.swift on i386 while I fix the issue.
Unblock the bots while I find a solution to the crash.
2022-02-18 14:49:21 -08:00
Doug Gregor
9a7b9c6216 Don't open existentials when calling C++ function templates
C++ function templates require specialization, which does not work with
opened existentials. Disable opening for them.
2022-02-18 11:22:57 -08:00
Zoe Carver
4a67288168 Merge pull request #41440 from zoecarver/members-with-dependent-types
[cxx-interop] Fix calling methods with dependent types.
2022-02-18 11:06:16 -08:00
zoecarver
d3950e5c9f [nfc] Disable some method tests on Windows. 2022-02-18 09:23:03 -08:00
zoecarver
47064a0eda [cxx-interop] Fix calling methods with dependent types.
Both instance members and static methods.
2022-02-18 09:21:55 -08:00
zoecarver
970489b72f [cxx-interop] [nfc] Don't emit a cast if the cast is a no-op. 2022-02-18 09:19:43 -08:00