Commit Graph

58 Commits

Author SHA1 Message Date
Gábor Horváth
9c6e4dd3c5 Merge pull request #80586 from swiftlang/gaborh/nested-reverse-interop-fixes-on-6.2 2025-04-14 11:11:01 -07:00
Gábor Horváth
8e6daf75ec [6.2][cxx-interop] Fix a rare compilation error in reverse interop header
Explanation: Fix a compilation error in the generated reverse interop
header when a nested foreign type is used in a generic context and it is
reexposed to C++.
Issue: rdar://148597079
Risk: Low, the fix is fairly targeted to the affected scenario.
Testing: Added tests to test suite
Reviewer: @egorzhdan
2025-04-08 11:32:08 +01: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
8a3beca30d [cxx-interop] Avoid spurious type aliases in reverse interop
To support nested structs, we emit type aliases in the outer class.
Unfortunately, we emitted these type aliases unconditionally, even if
the actualy nested struct was not emitted to the reverse interop header
(due to visibility or the construct being unsupported). This PR fixed
this issue by checking first if the nested entity should be included in
the reverse interop header.

rdar://141688074
2024-12-19 11:02:19 +00:00
Gabor Horvath
22b46d3c9c [cxx-interop] Mark some zero-sized value types as unavailable
Currently, we do not support exporting zero-sized value types from Swift
to C++. It needs some work on our end as these types are not part of the
lowered signature. In the meantime, this PR makes sure that common (but
not all) zero sized types are properly marked as unavailable. This is
important as the proper diagnostic will give users a hint how to work
around this problem. Moreover, it is really easy to hit this when
someone is experimenting with interop, so it is important to not have a
cryptic failure mode.

rdar://138122545
2024-10-28 14:00:35 +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
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
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
de10b4155e [interop][SwiftToCxx] support copy-assignment operation for Swift value types and prohibit move assignment explicitly
Fixes https://github.com/apple/swift/issues/66324

Note: move semantics for Swift value types are not yet supported in C++
2023-06-06 15:55:30 -07:00
Alex Lorenz
39d86bc701 [interop][SwiftToCxx] the not yet implemented move constructor for Swift value types should lead to link error when a move is used in Swift, not runtime error 2023-05-07 08:55:28 -07:00
Alex Lorenz
e6e43c6b80 [interop][SwiftToCxx] do not assert when emitting non-resilient structs with opaque layout 2023-04-20 18:46:07 -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
94c1de7611 [interop][SwiftToCxx] use 'SWIFT_INLINE_PRIVATE_HELPER' macro for static returnNewValue functions to ensure attribute(used) isn't applied to them 2023-03-15 09:13:38 -07:00
Alex Lorenz
3cce09e769 [interop][SwiftToCxx] annotate several value members types as 'noexcept'
C++/clang is more strict about requiring noexcept in templates so we need some explicit annotations
2023-03-12 11:49:14 -07:00
Alex Lorenz
0dc90d38c1 [interop][SwiftToCxx] emit Swift's stdlib inside of 'swift' namespace 2023-03-09 17:32:43 -08:00
Alex Lorenz
97dc2758d7 Merge pull request #64075 from hyp/eng/lambda-attrs
[interop][SwiftToCxx] use 'nodebug' for inline thunks and apply inline and artificial attributes to lambd…
2023-03-03 21:37:25 -08:00
Alex Lorenz
7caf34c190 [interop][SwiftToCxx] apply inline and artificial attributes to lambdas used with returnNewValue 2023-03-03 11:45:46 -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
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
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
ae549531ac Merge pull request #61225 from hyp/eng/fwd-generic-trait
[interop][SwiftToCxx] Declare the generic usability type trait before…
2022-09-21 15:56:14 -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
1d6d3ff970 [interop][SwiftToCxx] trap on moves of Swift values for now
Move support will be added later
2022-09-21 06:59:29 -07:00
Alex Lorenz
1696f94223 [interop][SwiftToCxx] reimplement function lowering to correctly distinguish between direct/indirect return values and parameters 2022-09-07 11:43:38 -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
489c16e906 [interop][SwiftToCxx] fix the circular depedency issue for struct emission 2022-08-19 15:02:56 -07:00
Alex Lorenz
f371c4307b [interop][SwiftToCxx] pass boxed resilient value types to generic functions correctly 2022-08-09 14:16:58 -07:00
Alex Lorenz
c537cd2383 [interop][SwiftToCxx] NFC, move swift::_impl::OpaqueStorage into _SwiftCxxInteroperability shims header 2022-08-09 13:57:34 -07:00
Alex Lorenz
330fc0b07a [interop][SwiftToCxx] generic functions should return value types correctly 2022-08-09 05:20:58 -07:00
Alex Lorenz
bf224c75a6 [interop][SwiftToCxx] pass structs to generic functions 2022-08-08 15:28:00 -07:00
Alex Lorenz
93b6e1bf05 [interop][SwiftToCxx] NFC, add test coverage for resilient mutating method 2022-08-08 13:08:54 -07:00
Alex Lorenz
8da01aa0f1 Merge pull request #60087 from WANGJIEKE/cxx-interop-extract-enum-payload
[Interop][SwiftToCxx] Initial support for getting associated values from enum
2022-07-28 12:06:44 +01:00
Tongjie Wang
38b6947fdd update test case for arm64e value witness table authentication 2022-07-18 18:21:12 -07:00
Tongjie Wang
290e527b0b [Interop][SwiftToCxx] Initial support for getting associated values from enum
improve test cases

add support for primitive types
2022-07-18 18:19:00 -07:00
Alex Lorenz
23ed6e8c9f [interop][SwiftToCxx] support instance property setters in C++ 2022-07-18 17:49:51 +01:00
Alex Lorenz
5b05d3dc67 [interop][SwiftToCxx] arm64e: authenticate value witness table in C++
Fixes arm64e test failures for C++ interop tests
2022-07-18 13:50:32 +01:00
Alex Lorenz
8fa37c214d Mark SwiftToCxx execution tests as unsupported on arm64e for now 2022-06-22 22:19:10 +01:00
Alex Lorenz
455007e63e [interop][SwiftToCxx] NFC, add a test case for emitting @frozen structs 2022-06-21 16:53:59 -07:00
Alex Lorenz
38387ad500 [interop][SwiftToCxx] add _Nonnull to resilient struct constructor that takes in VWT 2022-06-15 21:51:11 -07:00
Alex Lorenz
f577330b40 [interop][SwiftToCxx] fix copy constructor for resilient structs 2022-06-15 20:56:42 -07:00
Alex Lorenz
5474d7e54d [interop][SwiftToCxx] Add support for emitting resilient struct bindings 2022-06-15 20:33:23 -07:00
Alex Lorenz
d7fd1233a9 [interop][SwiftToCxx] emit instance property getters for structs 2022-06-14 17:20:37 -07:00
Alex Lorenz
776c5d6ba0 Merge pull request #59418 from WANGJIEKE/cxx-interop-inout-struct
[interop][SwiftToCxx] Pass struct to function as inout
2022-06-14 17:06:16 -07:00