Commit Graph

37 Commits

Author SHA1 Message Date
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08: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
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Slava Pestov
bbbfc62e6d ClangImporter: Fixes for non-copyable generics 2024-01-31 21:56:45 -05:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -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
Augusto Noronha
8790a9e0cf Revert "Revert "Print the Swift mangled name as a field in C++ interop generated classes""
This reverts commit 773a2aac96.
2023-02-27 14:23:08 -08:00
Augusto Noronha
773a2aac96 Revert "Print the Swift mangled name as a field in C++ interop generated classes"
This reverts commit 5b12a156f0.
2023-02-27 10:58:48 -08:00
Augusto Noronha
5b12a156f0 Print the Swift mangled name as a field in C++ interop generated classes
Print the Swift mangled name as a constexpr static char as a field in
compiler generated types so LLDB can display them nicely to users.
2023-02-24 14:01:31 -08:00
Alex Lorenz
327b989e84 [interop][SwiftToCxx] NFC, refactor printKnownCType method to ClangSyntaxPrinter for reuse 2023-02-13 10:30:25 -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
Slava Pestov
65d2d4d621 IRGen: Encapsulate fields of GenericRequirement better 2022-12-11 22:14:37 -05:00
Alex Lorenz
510b7675f4 [interop][CxxToSwiftToCxx] fix the tests for unsupported class template instantions; emit C++ type metadata accessors for type aliased templates 2022-12-08 21:28:29 -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
a66cc52109 [interop][SwiftToCxx] add static_assert type checking for generic functions in pre-C++20 mode
In the future we should also use enable_if to correctly resolve overloads
2022-11-01 17:21:01 -07:00
Alex Lorenz
4b52ae08fa [interop][SwiftToCxx] check that generics can be built in C++17/C++14 mode 2022-11-01 16:40:42 -07:00
Alex Lorenz
391b92fff7 [interop][SwiftToCxx] add some helper methods to work with Swift's Optional in C++ 2022-10-05 14:21:13 -07:00
Alex Lorenz
dd7e068391 [interop][SwiftToCxx] add a Swift stdlib overlay header
It currently provides begin and end functions for array iteration
2022-09-29 07:41:54 -07:00
Alex Lorenz
26e5742fe7 [interop][SwiftToCxx] emit generic type traits for C++ types bridged into Swift and then back to C++ 2022-09-12 12:39:30 -07:00
Alex Lorenz
a5043c354d [interop][SwiftToCxx] add support for invoking methods in generic structs 2022-08-31 20:19:19 -07:00
Alex Lorenz
7d6cdbc445 [interop][SwiftToCxx] pass generic type to a function by value (non specialized generic though) 2022-08-31 14:02:17 -07:00
Alex Lorenz
45d209fe1c [interop][SwiftToCxx] initial generic struct support 2022-08-31 14:02:15 -07:00
Tongjie Wang
cbc23cbafc [Interop][SwiftToCxx] Support enum creation from Cxx 2022-08-29 20:16:52 -07:00
Alex Lorenz
06d9fd24d4 [interop][SwiftToCxx] add experimental Swift::String -> NSString conversion operator 2022-08-25 15:09:30 -07:00
Alex Lorenz
a9f262e322 [interop][SwiftToCxx] add support for passing and returning class values to generic functions 2022-08-08 08:38:28 -07:00
Tongjie Wang
c2e8ec96eb Add variable name and indent parameter...
... to value witness table access sequence function
2022-07-18 18:28:58 -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
Alex Lorenz
88c55c1778 [interop][SwiftToCxx] add support for passing/returning value types from other modules 2022-07-15 17:14:35 +01:00
Alex Lorenz
5474d7e54d [interop][SwiftToCxx] Add support for emitting resilient struct bindings 2022-06-15 20:33:23 -07:00
Alex Lorenz
ff37c4e8bc [interop][SwiftToCxx] NFC, extract value witness extraction printing into shared printer 2022-06-13 15:52:10 -07:00
Alex Lorenz
9254c47b2c [interop][SwiftToCxx] emit swift type metadata access function declaration for structs 2022-06-13 09:16:17 -07:00
Alex Lorenz
f8b870aee2 [interop] refactor out the code to print C++ impl class names and C stub names 2022-06-10 06:57:39 -07:00
Alex Lorenz
132729906c [interop][SwiftToCxx] pass / return Swift struct values between C/C++ and Swift 2022-06-08 07:03:24 -07:00
Alex Lorenz
68fc606510 [interop] NFC, add a method to print out identifier to clang syntax printer 2022-03-24 21:54:44 -07:00
Alex Lorenz
e21abc140b [interop] NFC, extract out isClangKeyword into ClangSyntaxPrinter 2022-03-24 19:20:42 -07:00
Alex Lorenz
891d7b04ac [interop] NFC, refactor printNullability to ClangSyntaxPrinter
This way it can be reused from ClangFunctionPrinter
2022-03-24 10:12:11 -07:00
Alex Lorenz
9d56de1c0c [interop] NFC, create ClangSyntaxPrinter class 2022-03-24 09:07:09 -07:00