Commit Graph

62 Commits

Author SHA1 Message Date
Gabor Horvath
8af781453c [6.2][cxx-interop] Fix a CI failure in ptrauth test
This test is not executed by the pre-commit CI, so the failure went
unnoticed after #80495. This PR updates the test to make the CI pass.

rdar://148665873
(cherry picked from commit c0b1fa1600)
2025-04-21 11:22:09 -07:00
Gábor Horváth
5f3d5a9fa7 [6.2][cxx-interop] Fix nested structs for non-opaque types
Explanation: Fixes an issue where the generated reverse interop header
would not compile for nested classes when library evolution is turned
off.
Scope: C++ reverse interop for nested classes for non-opaque types.
Issue: rdar://147882976
Risk: Low, the fix is fairly targeted. While it does affect other
(non-nested type) scenarios, those changes are fairly straightforward
making some names fully qualified. Moreover, that is well tested in our
test suite.
Testing: Added tests to test suite
Reviewer: @egorzhdan
2025-04-07 12:02:54 +01:00
Becca Royal-Gordon
da07ff577c [PrintAsClang] Warn about unstable decl order
PrintAsClang is supposed to emit declarations in the same order regardless of the compiler’s internal state, but we have repeatedly found that our current criteria are inadequate, resulting in non-functionality-affecting changes to generated header content. Add a diagnostic that’s emitted when this happens soliciting a bug report.

Since there *should* be no cases where the compiler fails to order declarations, this diagnostic is never actually emitted. Instead, we test this change by enabling `-verify` on nearly all PrintAsClang tests to make sure they are unaffected.

This did demonstrate a missing criterion that only mattered in C++ mode: extensions that varied only in their generic signature were not sorted stably. Add a sort criterion for this.
2025-02-14 21:41:36 -08:00
Gabor Horvath
8603dfe53a [cxx-interop] Support nested classes in reverse interop
Turns out we already had most of the building blocks given we already
support nested structs.

rdar://143343490
2025-02-03 14:56:31 +00:00
Gabor Horvath
94b466656e [cxx-interop] Support nested structs
It is really involved to change how methods and classes are emitted into
the header so this patch introduces the impression of nested structs
through using statements and still emits the structs themselves as top
level structs. It emits them in their own namespace to avoid name
collisions. This patch also had to change some names to be fully
qualified to avoid some name lookup errors in case of nested structs.
Moreover, nesting level of 3 and above requires C++17 because it relies
on nested namespaces. Only nested structs are supported, not nested
classes.

Since this patch is already started to grow quite big, I decided to put
it out for reviews and plan to address some of the shortcomings in a
follow-up PR.

rdar://118793469
2024-09-10 13:22:17 +01:00
Egor Zhdan
11268dd188 [cxx-interop] Print inline instead of static inline for template specializations
This fixes a number of test failures in reverse C++ interop.

Clang's behavior was changed in https://github.com/llvm/llvm-project/pull/93873, and it no longer accepts the C++ headers that Swift generates.

rdar://132283247
2024-08-09 15:46:48 +01:00
Gabor Horvath
e6c3cb3db1 [cxx-interop] Forward declare classes
The code already forward declared strutcs and enums. This patch extends
the logic to also forward declare classes. Unfortunately, there was some
fallout because some traits ended up defined multiple times for some
classes, so the code is now extended to only conditionally emit these
traits if no forward declaration was emitted for the type yet.

rdar://124022242
2024-07-18 15:27:50 +01:00
Gábor Horváth
01bd2b4f8c Merge pull request #75202 from swiftlang/gaborh/export-static-properties
[cxx-interop] Export accessors of static properties to C++
2024-07-15 05:40:07 -07:00
Gabor Horvath
fe1a4b5961 [cxx-interop] Export accessors of static properties to C++
The code wants to avoid exporting certain synthesized operators but it
inadvertently also prevented exporting accessors to static properties.

rdar://115564118
2024-07-12 16:33:35 +01:00
Gabor Horvath
6db7f0ba7a [cxx-interop] Fix test failure for arm64e test
This is a fallout from emitting Swift StdLib dependencies when all
public decls are emitted. This was not found before because the test was
not executed by the CI.

rdar://131556373
2024-07-12 14:22:49 +01:00
Gabor Horvath
c3a02cd80d [cxx-interop] Emit Swift StdLib dependencies when all public decls emitted
The generated header would not compile without these dependencies. Moreover
users probably expect all-public option to be the most permissive filter
including the maximal amount of declarations.
2024-07-03 18:07:41 +01:00
Egor Zhdan
a0e1588417 [cxx-interop] Fix reverse interop test for virtual method dispatch on arm64e
rdar://105396625
2024-06-21 16:26:23 +01:00
Gabor Horvath
dbdd983392 [cxx-interop] Fix generated declaration order
The generated thunks for functions can refer to some internal methods of
their arguments. As a result, those generated thunks should always be
after the definitions of the corresponding argument types. The printer
ordered the declarations by name, and Swift had the convention starting
types with upper case letters and functions with lower case letters.
This naming convention together with the ordering resulted in the
correct ordering in most of the cases. There were a couple of exceptions
when people diverged from the naming conventions or wanted to export
operators. This patch fixes this problem by always ordering type decls
before function decls.

rdar://129276354
2024-06-13 15:22:03 +01:00
Becca Royal-Gordon
80f38be3b8 [PrintAsClang] Fix thunks for Never funcs
Swift-to-C++ thunk printing for functions didn’t really take into account Swift’s `Never` type. This type maps to `SWIFT_NORETURN`, but it also requires other tweaks to code generation, such as omitting the `return` keyword. (Removing that requires minor changes to many tests.)

Fixes rdar://124137073.
2024-03-29 22:12:19 -07:00
Alex Lorenz
b1d63d0938 [interop][SwiftToCxx] Use 'SWIFT_INLINE_PRIVATE_HELPER' for getTypeMetadata helper to avoid emitting a reference to it when 'DEBUG' macro is set
This is needed as the metadata for C++ types might not be actually emitted and thus we can't always reference it

Fixes https://github.com/apple/swift/issues/69234

rdar://117089662
2023-10-31 09:21:01 -07:00
Alex Lorenz
9d7460f130 [interop][SwiftToCxx] NFC, add missing include to swift-class-execution.cpp test 2023-05-08 06:54:57 -07:00
Alex Lorenz
f0967a4af1 Revert "Disable test/Interop/SwiftToCxx/class/swift-class-execution.cpp"
This reverts commit 5ce8b6cb06.
2023-05-08 06:54:47 -07:00
Arnold Schwaighofer
5ce8b6cb06 Disable test/Interop/SwiftToCxx/class/swift-class-execution.cpp
It failed on a package bot.
https://ci.swift.org/job/oss-swift-package-ubi-9/506/consoleText
rdar://109037144
2023-05-08 06:38:31 -07:00
Alex Lorenz
16b1fe173f [interop][SwiftToCxx] moving a Swift class in C++ performs a copy
C++ does not have a consuming move, so fallback to copy instead

Resolves https://github.com/apple/swift/issues/64702
2023-05-07 08:55:20 -07: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
Alex Lorenz
394c5bc7ce [interop] fix tests after fixing private annotations on the 'swift' namespace 2023-03-18 19:30:06 -07:00
Alex Lorenz
3b7c92073b Merge pull request #64265 from hyp/eng/swift-stdlib-is-swift-whoda-thunk-it
[interop][SwiftToCxx] emit Swift's stdlib inside of 'swift' namespace
2023-03-10 06:40:11 -08:00
Alex Lorenz
0dc90d38c1 [interop][SwiftToCxx] emit Swift's stdlib inside of 'swift' namespace 2023-03-09 17:32:43 -08:00
Alex Lorenz
617ead4a9d [interop][SwiftToCxx] do not emit _Concurrency APIs in the C++ section of the generated header
Fixes an issue where actors exposed its unownedExecutor property with unsupported type.
2023-03-09 10:51:22 -08:00
Augusto Noronha
6f68fb0dde Merge pull request #63950 from augusto2112/print-debug-name
Print debug name
2023-03-01 15:14:55 -08:00
Augusto Noronha
c3d3c37c15 Adapt tests to have the Swift mangled name as a field in interop types 2023-02-27 15:58:03 -08:00
Alex Lorenz
f8c3895f32 [interop][SwiftToCxx] print availability attributes for Swift decls in C++ 2023-02-27 12:07:36 -08:00
Alex Lorenz
3948a2a5d3 [interop][SwiftToCxx] annotate inline thunks with SWIFT_INLINE_THUNK
This macro applies always_inline in addition to inline. It also applies artificial, which lets debugger know that this is an artificial function. The used attribute is added in debug builds to ensure that the symbol is emitted in the binary so that LLDB can invoke it.
2023-02-24 11:23:46 -08:00
Mike Ash
20ae0ad34e [Test] Disable some failing tests on ARM64e.
Disabling these tests:
    IRGen/ptrauth-foreign.sil
    IRGen/ptrauth_field_fptr_import.swift
    Interop/SwiftToCxx/class/swift-class-virtual-method-dispatch-arm64e.swift
    Interop/SwiftToCxx/class/swift-class-virtual-method-dispatch.swift
    Interop/SwiftToCxx/class/swift-subclass-of-resilient-class-virtual-method-dispatch.swift
2023-02-14 11:39:44 -05:00
Alex Lorenz
45eb84614f test, add executable_test requirement 2023-02-13 10:35:01 -08:00
Alex Lorenz
a479641c84 [interop][SwiftToCxx] make type in test for resilient against arch changes 2023-02-13 10:32:49 -08:00
Alex Lorenz
c9f9d9025b [interop][SwiftToCxx] fix offset computation for 32 bit platforms for vtable dispatch 2023-02-13 10:30:38 -08:00
Alex Lorenz
540202fed8 [interop][SwiftToCxx] dispatch virtual Swift methods using a relative offset into the vtable for classes deriving from resilient classes 2023-02-13 10:30:32 -08:00
Alex Lorenz
981e828b2a [interop][SwiftToCxx] dispatch swift class methods using signed isa and signed method pointer on arm64e 2023-02-11 14:05:59 -08:00
Alex Lorenz
b63577d89e [interop][SwiftToCxx] use vtable/thunk to dispatch class subscript getters 2023-02-11 05:55:54 -08:00
Alex Lorenz
71e4462508 [interop][SwiftToCxx] use vtable offset/thunk to dispatch class property accessors 2023-02-11 05:55:47 -08:00
Alex Lorenz
06bfef2978 Merge pull request #63572 from hyp/eng/vtable2
[interop][SwiftToCxx] dispatch virtual calls via thunks for resilient…
2023-02-11 05:54:29 -08:00
Alex Lorenz
9e32761578 [interop][SwiftToCxx] dispatch virtual calls via thunks for resilient classes 2023-02-10 16:32:54 -08:00
Mike Ash
58d64376df [Test] Add REQUIRES: executable_test to swift-class-virtual-method-dispatch-execution.cpp. 2023-02-10 19:25:28 -05:00
Alex Lorenz
b7007cb748 [interop][SwiftToCxx] dispatch Swift class methods correctly using the vtable 2023-02-09 20:20:53 -08:00
Alex Lorenz
3b3d6c825a [interop][SwiftToCxx] Annotate emitted declarations with Clang's external_source_symbol attribute
Each emitted declaration is annotated with the external_source_symbol with its own USR, to allow Clang's indexer to recognize this declaration as a Swift declaration with a specific USR
2023-01-12 12:15:01 -08:00
Alex Lorenz
0312e0613d [interop][SwiftToCxxToSwift] hide reverse interop module namespaces from forward interop 2022-11-07 15:52:04 -08:00
Alex Lorenz
1a277f239e [interop][SwiftToCxx] actor tests should disable availability checking on macos 2022-11-02 14:40:28 -07:00
Alex Lorenz
1c19c15c78 [interop][SwiftToCxx] actor tests require Concurrency 2022-11-02 12:28:10 -07:00
Alex Lorenz
0d754e1d3f [interop][SwiftToCxx] add support for exposing non-isolated actor declarations 2022-11-02 12:17:55 -07:00
Alex Lorenz
3a9b6dce9d [interop][SwiftToCxx] add support for emitting Swift stdlib dependency in one header file
This is the default behavior. You can disable this by specifying the -clang-header-expose-decls= flag explicitly when generating the header
2022-09-28 08:08:48 -07:00
Alex Lorenz
2a05109c58 [interop][SwiftToCxx] Declare the generic usability type trait before the C++ class that represents the Swift type
This allows you to import a method that returns the type of the context in which the method is declared when such
type is a generic parameter in another type. This means that it's now possible to bridge the initializer for
RawRepresentable enums.
2022-09-21 07:57:32 -07:00
Alex Lorenz
ef5d11aab8 [interop][SwiftToCxx] NFC, Make swift::getTypeMetadata accessor part of struct template
This allows partial template specializations for adding metadata accessor for generic types 🤩
2022-08-31 17:16:45 -07:00
Alex Lorenz
330fc0b07a [interop][SwiftToCxx] generic functions should return value types correctly 2022-08-09 05:20:58 -07:00
Alex Lorenz
7ecf84a771 [interop][SwiftToCxx] ensure that resilient class values are supported 2022-08-08 13:08:54 -07:00