Commit Graph

597 Commits

Author SHA1 Message Date
Evan Wilde
cbe02abd69 Allow merged function in copy call
The copy operation is getting merged, resulting in the addition of `_Tm`
to the end of the `_ZN31NonTrivialCopyAndCopyMoveAssignC2ERKS` symbol
causing this test to fail. Adding that case.
2023-03-31 22:44:33 -07:00
Evan Wilde
37f770db81 Split arguments to C1ERKS copy assignment
This patch splits the parameters going into the copy assignment from
`instance2` into `instance`.

Some builds of the compiler are emitting additional annotations on the
pointer.

The resulting parameters on Linux (on my box anyway) look like this:
`(%struct.NonTrivialCopyAndCopyMoveAssign* noundef nonnull align 4 dereferenceable(5) %2, %struct.NonTrivialCopyAndCopyMoveAssign* noundef nonnull align 4 dereferenceable(5) %4)`

These annotations look reasonable, but they don't show up on macOS.
I've added check-same to ensure that the parameter passing is still
happening while ignoring the additional annotations.
2023-03-31 22:34:49 -07:00
Alex Lorenz
b5766fd215 [interop] do not assume we need to IRGen destructors of fields inside a record with an explicit destructor 2023-03-26 12:24:57 -07:00
Zoe Carver
b90f789df3 Merge pull request #64438 from zoecarver/fixits-for-clang-types-swiftpm-2 2023-03-21 08:28:34 -07:00
zoecarver
1513df619b [cxx-interop][nfc] Fix test fallout. 2023-03-20 17:34:19 -07:00
Alex Lorenz
7320cd877c [interop] ensure IRGen reaches code referenced through destructor invoked using the 'delete' statement in C++ 2023-03-20 17:25:29 -07:00
zoecarver
048e5c73f6 [cxx-interop] Update fix-its to use new macro naming. 2023-03-20 16:14:42 -07:00
zoecarver
41f01e3d8c [nfc] Add a test for the attribute fix-its. 2023-03-20 16:14:42 -07:00
Alex Lorenz
0c214fe559 Merge pull request #64466 from hyp/eng/inontrivvy
[interop] C++ record should use AddressOnly type layout only when it's non-trivial for purpose of calls
2023-03-18 07:11:14 -07:00
Zoe Carver
e3b3e82dca Merge pull request #64460 from zoecarver/factor-owned-attr-into-is-safe-req
[cxx-interop] Object model: fix crash when importing explicitly owned…
2023-03-17 20:32:23 -07:00
Alex Lorenz
e26109f71e Merge pull request #64459 from hyp/eng/conforms_to++
[interop] 'conforms_to' attribute should be qualified with module name
2023-03-17 20:18:37 -07:00
Alex Lorenz
863f98755e [interop] C++ record should use AddressOnly type layout only when it's non-trivial for purpose of calls
A record that's non trivia for purpose of calls, as defined in Itanium ABI is allowed to have non-trivial copy/move assignment operators, but it most not have non-trivial constructors or destructors. This change ensures that a C++ record with a non-trivial copy assignment operator but trivial other members can be passed/returned directly by value, so that the compiler can accept the returned value correctly when calling a C++ function.
2023-03-17 17:02:14 -07:00
Alex Lorenz
de56accb96 Merge pull request #64397 from hyp/eng/destroy-before-assigncopytake
[interop] C++ destination record should be destroyed before being cop…
2023-03-17 16:14:06 -07:00
Alex Lorenz
90d1c24674 [interop] 'conforms_to' attribute should be qualified with module name
Also, improve the diagnostics for 'conforms_to'
2023-03-17 15:09:27 -07:00
zoecarver
0795083237 [cxx-interop] Object model: fix crash when importing explicitly owned type. 2023-03-17 13:57:24 -07:00
Alex Lorenz
3e4669b472 [interop] fix tests for assignWithCopy/Take fixes 2023-03-17 11:49:07 -07:00
Egor Zhdan
9247d53082 [cxx-interop] Do not auto-complete unsafe underscored methods, part 2
Previous patch removed unsafe C++ methods from the module interface, but not from auto-completion results.

rdar://103252957
2023-03-17 18:04:22 +00:00
Alex Lorenz
8b7b1347eb [interop] C++ destination record should be destroyed before being copied into during assignWithCopy / assignWithTake 2023-03-15 12:33:31 -07:00
Egor Zhdan
201a3b1076 Merge pull request #64287 from apple/egorzhdan/do-not-auto-complete-unsafe
[cxx-interop] Do not auto-complete unsafe underscored methods
2023-03-13 00:06:32 +00:00
Egor Zhdan
8326c84bfc [cxx-interop] Do not auto-complete unsafe underscored methods
e.g. `__beginUnsafe()` or `__endUnsafe()` which return iterators

rdar://103252957
2023-03-10 19:31:04 +00:00
Alex Lorenz
cd03a2f8eb [interop] ensure IRGen traverses inherited C++ constructors correctly 2023-03-09 14:46:45 -08:00
Butta
9e3492cef1 [android][test] Fix two C++ Interop tests that were recently updated on macOS
These flags were recently added to the macOS versions of these tests in #63809.
2023-03-07 18:57:09 +05:30
Dario Rexin
a8d4d57f11 [IRGen] Generate compressed representation of value witnesses (#63813)
rdar://105837040

* WIP: Store layout string in type metadata

* WIP: More cases working

* WIP: Layout strings almost working

* Add layout string pointer to struct metadata

* Fetch bytecode layout strings from metadata in runtime

* More efficient bytecode layout

* Add support for interpreted generics in layout strings

* Layout string instantiation, take and more

* Remove duplicate information from layout strings

* Include size of previous object in next objects offset to reduce number of increments at runtime

* Add support for existentials

* Build type layout strings with StructBuilder to support target sizes and metadata pointers

* Add support for resilient types

* Properly cache layout strings in compiler

* Generic resilient types working

* Non-generic resilient types working

* Instantiate resilient type in layout when possible

* Fix a few issues around alignment and signing

* Disable generics, fix static alignment

* Fix MultiPayloadEnum size when no extra tag is necessary

* Fixes after rebase

* Cleanup

* Fix most tests

* Fix objcImplementattion and non-Darwin builds

* Fix BytecodeLayouts on non-Darwin

* Fix Linux build

* Fix sizes in linux tests

* Sign layout string pointers

* Use nullptr instead of debug value
2023-02-24 15:40:28 -08:00
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
Alex Lorenz
c9252370e6 [interop] test, fixup remaining exception tests 2023-02-22 19:24:16 -08:00
Alex Lorenz
9feb76419b [interop] ignore exceptions in existing interop tests 2023-02-22 11:00:51 -08:00
Zoe Carver
5406f1aafe Merge pull request #63673 from zoecarver/fixits-for-common-swiftifications
[cxx-interop] Offer fix-it to re-write ".at(42)" as "[42]".
2023-02-22 10:13:36 -08:00
zoecarver
38658a051f [cxx-interop] Fix test for linux; bail if we didn't load the overlay. 2023-02-21 10:52:57 -08:00
zoecarver
ffec6a297b [nfc] Add 'is' in diagnostic message. 2023-02-20 17:48:08 -08:00
zoecarver
256335c1ea [nfc] Require MacOS for the vector test. 2023-02-20 17:47:48 -08:00
zoecarver
c0416b1450 [cxx-interop] Tests for the recent diganostics and fix-its. 2023-02-20 15:58:38 -08:00
Egor Zhdan
fc5215f0f8 [cxx-interop] Treat C++ structs that store iterators as unsafe
C++ types that store pointers as fields are treated as unsafe in Swift. Types that store other types that in turn store pointers are also treated as unsafe.

Types that store raw C++ iterators are also treated as unsafe in Swift. However, a type that stores another type that stores a raw iterator was previously imported as safe. This change fixes that.

rdar://105493479
2023-02-15 13:50:35 +00:00
Zoe Carver
c1a50cf00c Merge pull request #63506 from zoecarver/runtime-crash-ref-in-ctor 2023-02-12 10:04:17 -08:00
zoecarver
c00c762146 [tests] Fix SILGen tests to have Windows mangling 2023-02-10 09:27:11 -08:00
zoecarver
4f72147279 [cxx-interop] Use "c function conventions" for static methods and ctors (not "cxx method conventions").
Otherwise we will incorrectly use the "self" type's conventions when lowering the parameters (off-by-one).
2023-02-09 17:10:16 -08:00
Egor Zhdan
9e35a175e9 [cxx-interop] Members of private base classes should not be exposed
Trying to use members of C++ private base classes from Swift causes an assertion failure in ClangImporter:

```
<build dir>/swift/lib/swift/macosx/arm64/libcxxshim.h:2:66: error: cannot cast 'A' to its private base class 'B'
To __swift_interopStaticCast(From from) { return static_cast<To>(from); }
                                                                 ^
```

Such members should not be exposed.

rdar://103871000
2023-01-04 13:41:50 +00:00
Egor Zhdan
745d92d9cb [cxx-interop] Allow instantiated operator methods to serve as protocol conformance witnesses
If a templated C++ class declares an operator as a member function, and is instantiated using a typedef or a using-decl on the C++ side, it previously could not be conformed to a Swift protocol that requires the operator function despite matching signatures.

This was due to a Swift name lookup issue: operators, unlike regular member functions, are found by doing an unqualified lookup. Since C++ class template specializations and their members are not added to `SwiftLookupTable`, when doing qualified lookup members are searched by looking at all of the members of the specialization and choosing the ones with matching names. With unqualified lookup, we cannot rely on knowing the right specialization and need to search for all the operators in a given module.

This change adds synthesized operator thunks to `SwiftLookupTable` to make them discoverable by unqualified lookup.
2023-01-03 13:57:08 +00:00
Egor Zhdan
abfd790bb4 Merge pull request #62575 from apple/egorzhdan/cxx-disambiguate
[cxx-interop] Disambiguate const and non-const methods consistently
2022-12-19 17:36:03 +00:00
Egor Zhdan
168ef490af [cxx-interop] Disambiguate const and non-const methods consistently
When importing a C++ struct that contains two methods that only differ in const-ness, we append `Mutating` to the name of the non-const method to make it possible to call from Swift unambiguously.

Unfortunately that logic was dependent on the order in which we import methods of a class: the `Mutating` suffix was added when another method with the same name was already imported.

This caused lookup failures, and the behavior was incorrect when the pair of methods return instances of an unsafe type: the const overload was renamed as `Unsafe` properly, but the non-const overload was not renamed.
2022-12-19 15:03:04 +00:00
Mike Pinkerton
742d47893d Failing tests for runtime polymorphism. 2022-12-15 16:14:13 -05:00
Zoe Carver
9850906570 Merge pull request #62330 from zoecarver/conforms-to-attr
[cxx-interop] Add ability to specify protocol conformance on C++ side.
2022-12-13 16:28:31 -08:00
Butta
dc06fc0160 [android][test] Disable new C++ Interop test
Also, add flag and comment from `build-script-util` that was missed in the
recent Python translation, #38507.
2022-12-12 01:11:46 +05:30
Alex Lorenz
934183f854 [cxx-interop] Emit IR for std::get in structured bindings declaration 2022-12-07 15:54:11 -08:00
zoecarver
665d3e1db4 [cxx-interop] Add diagnostics for explicit protocol conformance on the C++ side. 2022-12-02 10:04:48 -08:00
zoecarver
5eb7c7a6cf [cxx-interop] Add ability to specify protocol conformance on C++ side. 2022-11-30 17:26:15 -07:00
Egor Zhdan
c307ccc37f [cxx-interop] Emit IR for custom operator new
Fixes https://github.com/apple/swift/issues/62182
2022-11-23 13:15:50 +00:00
Saleem Abdulrasool
2ed5bdf01e test: enable C++ class inheritance test on Windows
Now that this test builds on Windows, we can finally unmark it as
UNSUPPORTED on windows.
2022-11-09 08:20:56 -08:00
Butta
4b22ca1550 [android][test] Fix two C++ Interop tests that were split off for Android, enable two more new ones, and set an executable_test
Also, make some related changes, like updating a path in the Android doc, making sure the
`unknown` vendor is always used, and using `CPU` instead of `CODEGENERATOR`.
2022-11-08 22:13:36 +05:30
Egor Zhdan
6ca60b075e [cxx-interop] Emit IR for virtual methods
Even if a virtual method is not used directly from Swift, it might get emitted into the vtable, and in that case the IR for it should be emitted to avoid linker errors.

Fixes https://github.com/apple/swift/issues/61730.
2022-11-01 13:10:44 -07:00
Allan Shortlidge
0fd7e24724 Tests: Add REQUIRES: CPU=x86_64 in a few Interop tests.
These tests fail when run locally on Apple Silicon Macs because they specify `-target x86_64-apple-macosx10.9` instead of `%target-cpu-apple-macosx10.9`. Tests that have architecture specific output should require that architecture.
2022-10-29 14:20:17 -07:00