Commit Graph

617 Commits

Author SHA1 Message Date
Egor Zhdan
fec48f9e63 [cxx-interop] Synthesize a deprecated zero initializer for C++ structs
When importing a C header in the C++ language mode, Clang/Swift treat C structs as C++ structs.

Currently Swift synthesizes a default initializer that zero-initializes the backing memory of the struct for C structs, but not for C++ structs.

This is causing issues in existing projects that use C libraries and rely on having the default initializer available in Swift. This change enables the synthesis of a default initializer for C++ structs. Since many C++ structs are not designed to be initialized this way, the initializer is marked as deprecated in Swift.

rdar://109727620
2023-05-31 13:41:25 +01:00
Alex Lorenz
2c4188b8f4 [cxx-interop] mark C++ classes with trivial_abi attribute as unavailable in Swift 2023-05-09 16:23:36 -07:00
zoecarver
408ce853d0 [diags][cxx-interop] for-loop -> for-in loop. 2023-05-04 10:26:45 -07:00
zoecarver
b2988f6e98 [diags][cxx-interop] Update diagnostic for 'begin' to suggest using a for-loop instead.
Does not fix the fix-it. The current fix it will be left as a stop-gap solution and we can hopefully update this fix it in the near future to actually plop in a for loop (too much work for this PR though).
2023-05-03 09:05:55 -07:00
Alex Lorenz
89b1c6391f Revert "[cxx-interop] Treat un-instantiated templated types as unsafe"
This reverts commit c81325461a.

This caused https://github.com/apple/swift/issues/65446
2023-05-01 10:25:47 -07:00
Alex Lorenz
f45d9f7662 Merge pull request #65056 from hyp/eng/no-never-ever
[interop] do not import functions whose return type is not imported
2023-04-12 08:20:04 -07:00
Alex Lorenz
5fa6d08f33 Merge pull request #65043 from hyp/eng/diag-clenup
[interop] make interop diagnostics more consistent with the rest of S…
2023-04-12 06:53:26 -07:00
Alex Lorenz
8e0c17b274 [interop] do not import functions whose return type is not imported 2023-04-11 08:27:45 -07:00
Alex Lorenz
b60d635db7 [interop] make interop diagnostics more consistent with the rest of Swift diagnostics 2023-04-10 16:20:07 -07:00
Alex Lorenz
c2315060b6 [interop] mark C++ virtual functions as unavailable in Swift
They're not yet supported
2023-04-10 11:51:38 -07:00
Alex Lorenz
612eefffd4 Merge pull request #64911 from hyp/eng/grand-macro-rename
[interop] update names and add docs for the interop C++ helper macros
2023-04-06 17:17:52 -07:00
Alex Lorenz
64a4b3159c [interop] add SWIFT_ prefix to the C++ interop annotations 2023-04-06 12:11:25 -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
nate-chandler
7e15303407 Merge pull request #42019 from nate-chandler/rdar90495704
[SILOpt] Run DestroyAddrHoisting in the mandatory pipeline when optimizing.
2023-04-04 16:37:30 -07:00
Alex Lorenz
30d0c17bf9 [interop] update names and add docs for the interop C++ helper macros 2023-04-04 15:13:59 -07:00
Egor Zhdan
2f99a4ee89 Merge pull request #64897 from apple/egorzhdan/pointy-is-scary
[cxx-interop] Treat un-instantiated templated types as unsafe
2023-04-04 19:44:37 +01:00
Nate Chandler
90f7af22c9 [SILOpt] Run DestroyAddrHoisting in mandatory.
Run DestroyAddrHoisting in the pipeline where DestroyHoisting was
previously running.  Avoid extra ARC traffic that having no form of
destroy hoisting in the mandatory pipeline results in.

rdar://90495704
2023-04-04 11:11:34 -07:00
Egor Zhdan
c81325461a [cxx-interop] Treat un-instantiated templated types as unsafe
When determining whether a C++ method is safe to be imported, we look at its return type to see if it stores any pointers in its fields.

If the type is templated, we might not have its definition available yet. Unfortunately we cannot instantiate it on the spot, since the Clang AST would be read and written at the same time.

Let's stay on the safe side and treat such methods as unsafe.

rdar://107609381
2023-04-04 15:33:09 +01:00
Egor Zhdan
283d6642d2 Merge pull request #64877 from apple/egorzhdan/test-mutable-members
[cxx-interop] Update tests for mutable struct fields
2023-04-04 11:24:29 +01:00
Egor Zhdan
0e8ef4c05c [cxx-interop] Update tests for mutable struct fields
Methods that are marked as `const` in C++ can still modify a field of the object if the field is marked as `mutable`.

We previously imported all methods of structs with mutable fields as mutating in Swift. Unfortunately this doesn't work well with libstdc++, which uses mutable fields for some commonly used container types.

Our current user model assumes that we trust the `const` keyword on a C++ method, and import them as non-mutating in Swift. Let's make sure the tests reflect that.
2023-04-03 21:46:56 +01:00
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