Commit Graph

51 Commits

Author SHA1 Message Date
Gabor Horvath
0e03d342fe [cxx-interop] Support ObjC protocols in C++ interop
This patch introduces handling of ObjC protocols similar to how ObjC
classes work. Since this only works in ObjC++, all declarations
containing ObjC protocols will be protected by the __OBJC__ macro.

This patch results in some `_bridgeObjC` methods being exposed, we might
end up hiding those in the future, but there is no harm having them in
the interop header for the interim period.

rdar://136757913
2024-10-16 18:51:35 +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
cee81a4c48 [cxx-interop] Make function signature printing transactional
The function responsible for printing signatures can return in the middle
of the printing process whenever it discovers an unsupported scenario.
To avoid creating a header that cannot be compiler, this function should
be transactional. It either has to succeed and write the signature to the
stream, or in case it failed, the stream should be untouched. This patch
introduces a temporary buffer that is flushed to the stream as the last
step for a successful execution. This should make the user experience
better whenever the user stumbles upon something that is unsupported.
2024-06-12 16:26: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
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07: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
7efae9a74c [interop][SwiftToCxx] add additional type representation emission check for associated enum element types
This ensures that we do not try to emit enums whose associated values come from dependent modules that don't have a C++ representation
2023-04-24 12:31:30 -07:00
Alex Lorenz
f8c3895f32 [interop][SwiftToCxx] print availability attributes for Swift decls in C++ 2023-02-27 12:07:36 -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
b7007cb748 [interop][SwiftToCxx] dispatch Swift class methods correctly using the vtable 2023-02-09 20:20:53 -08:00
Alex Lorenz
8305c7d5de [interop][SwiftToCxx] add C++ bindings for static methods 2023-02-08 10:25:17 -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
1d7c0ee7a5 [interop][SwiftToCxx] NFC, make 'noexcept' a function signature modifier 2023-01-11 11:47:09 -08:00
Slava Pestov
65d2d4d621 IRGen: Encapsulate fields of GenericRequirement better 2022-12-11 22:14:37 -05: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
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
6f9b683617 [interop][SwiftToCxx] add support for bridging static properties 2022-09-26 12:50:13 -07:00
Alex Lorenz
773a0436cf [interop][SwiftToCxx] extract generic associated value from enum 2022-09-14 12:21:18 -07:00
Alex Lorenz
8c48d268d5 [interop][SwiftToCxx] expose subscript getter for Array's operator [] 2022-09-12 21:13:44 -07:00
Alex Lorenz
661ae6bd1a [interop][SwiftToCxx] cleanup the function signature stuff 2022-09-07 14:06:28 -07:00
Alex Lorenz
f4de75ae2c [interop][SwiftToCxx] 'self' param should be handled by type param visitor 2022-09-07 12:45:38 -07:00
Alex Lorenz
0592894e33 [interop][SwiftToCxx] move generic additional type parameters into lowered function signature 2022-09-07 12:22:04 -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
d9f4c072cc [interop][SwiftToCxx] correctly invoke property accessors in generic structs 2022-09-01 06:57:49 -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
942523f3df [interop][SwiftToCxx] NFC, refactor full _impl type printer into a function 2022-08-31 14:02:17 -07:00
Alex Lorenz
8214b85f6b Merge pull request #60842 from WANGJIEKE/cxx-interop-enum-creation
[Interop][SwiftToCxx] Support enum creation from Cxx
2022-08-31 14:00:50 -07:00
Tongjie Wang
cbc23cbafc [Interop][SwiftToCxx] Support enum creation from Cxx 2022-08-29 20:16:52 -07:00
Alex Lorenz
a89d4f3ced [interop][SwiftToCxx] add support for generic methods 2022-08-29 14:11:33 -07:00
Alex Lorenz
288e4cb566 [interop][SwiftToCxx] do not emit functions/methods that use unexposed types 2022-08-25 15:09:26 -07:00
Alex Lorenz
d4a7f86e3d [interop][SwiftToCxx] do not emit unsupported function signatures yet 2022-08-16 14:39:22 -07:00
Alex Lorenz
32723f7e67 [interop][SwiftToCxx] initial generic function support: pass generic parameters
Only primitive types are supported at the moment from C++ as the type traits aren't emitted for all types yet
2022-07-28 22:52:21 +01: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
Alex Lorenz
760d59e8e1 [interop][SwiftToCxx] NFC, use FunctionSignatureModifiers to print 'static' 2022-07-26 14:20:30 +01:00
Alex Lorenz
5aafe4599c [interop][SwiftToCxx] NFC, use FunctionSignatureModifiers to print 'inline' 2022-07-26 14:08:09 +01:00
Alex Lorenz
6f86d60e54 [interop][SwiftToCxx] NFC, use FunctionSignatureModifiers to print 'const' 2022-07-26 14:04:23 +01:00
Alex Lorenz
a170eaf0fc [interop][SwiftToCxx] NFC, init FunctionSignatureModifiers values inline 2022-07-26 13:57:25 +01: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
42b2cd2dd4 NFC, PrintAsClang: remove superfluous include 2022-07-15 17:14:35 +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
Roberto Rosmaninho
ff222acebc Setting hardcode SWIFT_NOEXCEPT and noexcept flags only to
non-throwing functions.
Activating swift-functions-errors tests
Inserting macros and additional parameters in C and C++ functions following the pattern to lowering to LLVM IR.
2022-07-14 12:34:53 -03:00
Tongjie Wang
00598e8019 [interop][SwiftToCxx] add initial support for passing/returning enums 2022-06-20 00:45:07 -07:00
Alex Lorenz
71065e94d3 [interop][SwiftToCxx] emit struct initializers
They're emtited as static init methods in the C++ class
2022-06-17 16:00:23 -07:00
Alex Lorenz
b47bb5b66e [interop][SwiftToCxx] support mutating struct methods in C++ 2022-06-17 07:58:19 -07:00
Alex Lorenz
f2b4a43c06 [interop][SwiftToCxx] emit non-mutating instance methods for structs 2022-06-15 07:35:13 -07:00
Alex Lorenz
d7fd1233a9 [interop][SwiftToCxx] emit instance property getters for structs 2022-06-14 17:20:37 -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
d76c45d104 [interop] NFC, refactor clang function printer to share code between C and C++ signature printer 2022-03-29 15:09:12 -07:00
Alex Lorenz
f7902a6095 [cxx-interop] Emit C++ inline function thunks that with correct primitive types 2022-03-29 13:37:01 -07:00