Commit Graph

54 Commits

Author SHA1 Message Date
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
Robert Widmann
0f94164d3b Replace Hand-Rolled MAX/MIN with std::max/std::min
We're using C++ 14+ at least now across the project so these should not be necessary. It's also kind of wild that the definitions we had across different subsystems had different definitions.
2025-01-22 11:18:35 -07: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
Gabor Horvath
0eab959d2b [cxx-interop] Do not export enums with indirect associated values
We do not support any sort of indirect enums yet, the code gets into an
infinite recursion. Let's skip exporting these types to C++ for now
until proper support is implemented.

rdar://134852756
2024-08-30 13:34:28 +01:00
Gabor Horvath
67fbe8f025 [cxx-interop] Fix test encoding data layout in expectations
As a result the test fail on certain watchOS targets.

rdar://124466216
2024-08-05 16:03:41 +01:00
Gabor Horvath
e195093aee [cxx-interop] Fix the printing of types with generic arguments
Previously the code got the declaration for types with generic
arguments and the printer used the declaration. This was a lossy
operation, we printed the type with generic parameters instead of the
arguments. This patch makes sure we print the type with the arguments.
Unfortunately, the code structure is not the most clear, type printing
is currently inherently part of the function signature printing. This
code path needs to be factored out in the future to make the code easier
to understand.

rdar://130679337
2024-07-22 13:42:24 +02: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
Gabor Horvath
53861a4e00 [cxx-interop] Avoid emitting methods that cause name clash
In Swift, we can have enum elements and methods with the same name, they are overloaded.
Unfortunately, this feature is not supported by C++ interop at the moment. This patch
avoids emitting the methods with name collisions to make sure the resulting header
can be compiler. A proper fix should follow in a later PR.

rdar://128162252
2024-06-10 12:35:44 +01:00
Meghana Gupta
5380f4d097 Disable an Interop test in CI 2024-04-09 11:01:33 -07: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
Alexis Laferrière
b03d4faec2 Tests: disable C++ interop test on armv7k 2024-03-12 11:20:48 -07:00
Doug Gregor
b5fc2fc036 [Generated header] Emit members of enum extensions into C++ class
As we do with Swift structs, emit the members of extensions of Swift
enums into the corresponding C++ class. This includes exposing more of
the Optional API from the standard library into Swift.
2024-03-05 21:54:47 -08:00
Alex Lorenz
71ef7e8d3d [interop][SwiftToCxx] do not expose unsupported enums yet
This includes indirect enums, enums with multiple associated values, or enums whose associated value is a type we don't yet support
2023-04-20 18:05:00 -07:00
Alex Lorenz
5ca0b5a0c5 [interop][SwiftToCxx] ensure we always expose limited set of APIs from Swift's standard library to C++
Fixes https://github.com/apple/swift/issues/64340
2023-03-17 18:24: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
7caf34c190 [interop][SwiftToCxx] apply inline and artificial attributes to lambdas used with returnNewValue 2023-03-03 11:45:46 -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
0b0cc99c98 [interop][SwiftToCxx] avoid -Wshadow warning for C++ representation of enum member parameters 2023-02-08 12:33:18 -08:00
Alex Lorenz
13ff3fe0b6 Merge pull request #62952 from WANGJIEKE/cxx-interop-enum-associated-value-class-type
[Interop][SwiftToCxx] Add class type support for enum with associated value
2023-01-19 12:47:37 -08:00
Alex Lorenz
cc5b557cee [interop][SwiftToCxx] Attach SWIFT_SYMBOL to C++ enum case declarations 2023-01-12 14:01:30 -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
Tongjie Wang
b27f35b1a0 improve test case: add retainCount check 2023-01-10 15:08:51 -08:00
Tongjie Wang
3aea6a8977 [Interop][SwiftToCxx] Add class type support for enum with associated value 2023-01-10 13:40:34 -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
8336edd344 [interop][SwiftToCxx] add support for constructing generic enum cases in C++
We only support cases with no payload, or one associated value still
2022-11-03 12:21:27 -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
Tongjie Wang
90e8d16794 [Introp][SwiftToCxx] Fix enum implementation test related to stub struct 2022-09-09 23:48:22 -07:00
Tongjie Wang
5a55cd7ba2 [Interop][SwiftToCxx] Support printing methods and properties for enums 2022-09-08 11:05:20 -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
Tongjie Wang
911cfe9fbb print static struct member as inline and improve test cases 2022-08-30 17:19:00 -07:00
Tongjie Wang
cbc23cbafc [Interop][SwiftToCxx] Support enum creation from Cxx 2022-08-29 20:16:52 -07:00
Tongjie Wang
7f9fadb7d8 Fix type for resilient enum case global variables 2022-08-18 12:31:40 -07:00
Tongjie Wang
ae73a03ec0 Merge branch 'main' into fix-value-witness-table-type 2022-08-18 09:57:57 -07:00
Tongjie Wang
7115e64689 update test case 2022-08-15 20:24:40 -07:00
Tongjie Wang
482e1ac80f [Interop][SwiftToCxx] Implement the new enum header design 2022-08-15 15:31:43 -07:00
Tongjie Wang
ff28b56e15 [Interop][SwiftToCxx] add support for resilient enum 2022-08-08 14:37:13 -07:00
Tongjie Wang
d34e086c79 Change return type of getEnumTag in value witness table
make it actually matches the description above
2022-08-04 18:41:16 -07:00
Alex Lorenz
fa99c7864e [interop][SwiftToCxx] re-enable enum runtime tests on ARM64e 2022-07-28 12:13:49 +01:00
Tongjie Wang
5b2c6e5b53 use placement new so we don't destory an enum twice 2022-07-25 08:27:19 -07: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
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
Tongjie Wang
23d60acbc2 sort cases based on their assigned tag indices before printing 2022-07-06 12:46:11 -07:00
Tongjie Wang
e7ea37f7d6 print C's abort in default branch 2022-07-05 12:06:38 -07:00
Tongjie Wang
7ebcb7b33a [Interop][SwiftToCxx] Implement enum case switching 2022-06-30 22:41:15 -07:00
Alex Lorenz
0dae89613a Merge pull request #59669 from WANGJIEKE/cxx-interop-enum-cases-class
[Interop][SwiftToCxx] Emit helper cases class in C++ for Swift enum
2022-06-25 11:00:28 +01:00
Tongjie Wang
7c962b2d65 Improve C++ case printing 2022-06-24 04:01:41 -07:00
Tongjie Wang
b5721806fb [Interop][SwiftToCxx] Fix small enum tests 2022-06-23 14:17:04 -07:00