Commit Graph

67 Commits

Author SHA1 Message Date
Becca Royal-Gordon
c3b57f24eb Merge pull request #74597 from beccadax/order-to-chaos
[NFC] [PrintAsClang] Add tiebreaking rule to sort
2024-06-21 21:56:54 -07:00
Becca Royal-Gordon
bf92156364 [NFC] [PrintAsClang] Add tiebreaking rule to sort
Because the underlying API for fetching top-level decls returns them in an unspecified order, PrintAsClang sorts the decls before printing them to make the output order more stable. However, the rules currently implemented have at least one known defect (they compare only the unqualified name of a nested class, so two nested classes with the same Swift name sort in an arbitrary order), and there are likely many more.

Add a fallback rule which sorts declarations by their mangled name; this should at least distinguish all non-colliding ValueDecls from each other, albeit according to fairly opaque criteria. Additionally add a rule to help distinguish extensions with very similar content, and tweak other logic so that the comparison function is less likely to give up early rather than continuing to look for a usable difference.

Fixes rdar://129485103.
2024-06-20 16:17:07 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07: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
Gabor Horvath
353f0608f9 [cxx-interop] Fix unavailable generics triggering compilation error
In some cases, the reverse interop generated both a forward declaration and a
definition with unavailable attribute in the C++ header. Unfortunately, the
kinds of these symbol did not match. The forward declaration was templated
while the definition was not. The forward declaration has the correct kind,
so this patch extends the printing of unavailable definitions to include the
generic arguments.

rdar://119835933
2024-06-11 11:43:02 +01:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -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
James Brown
2c281208de 56350 - Give Identifier a hasUnderscoredNaming() helper and in the places currently using str().startsWith, change it to use the new helper. 2024-03-04 19:34:11 -05:00
Pavel Yaskevich
f7ce3e9983 [PrintObjC] Fix ReferencedTypeFinder::isConstrained to filter out invertible protocols
The checking should be as simple as checking for `isAny()` or `isAnyObject()`
on an existential type because all of the non-inverse protocol requirements
are going to form a protocol composition type.
2024-02-13 11:56:26 -08:00
Hamish Knight
05615fa0e4 NFC: Rename TypeWalker's SkipChildren to SkipNode
For consistency with ASTWalker.
2024-02-05 15:27:25 +00:00
Akira Hatanaka
daebcc3fdf [interop][SwiftToCxx] Ignore delayedMembers in C++ (#70939)
[interop][SwiftToCxx] Ignore delayedMembers in C++

This fixes a bug where an ObjC @interface declaration is emitted for a
class that has a member that isn't emitted.

Resolves rdar://119835836
2024-01-25 14:47:39 -08:00
Pavel Yaskevich
1b521a5c69 [PrintAsClang] Don't attempt forward declare marker protocols 2023-10-30 10:21:04 -07:00
Becca Royal-Gordon
1318bf5bf5 [NFC] Begin adopting new diagnostics features 2023-07-19 13:06:51 -07:00
Erik Eckstein
6b1697eb06 use new llvm::Optional APIs to fix deprecation warnings 2023-06-28 14:28:38 +02:00
Alex Lorenz
82ef9d35e7 [interop][SwiftToCxx] do not emit unavaialble stubs for internal/private decls
only emit them for public ones
2023-05-06 14:51:18 -07:00
Alex Lorenz
c7836e3a8e [interop][SwiftToCxx] avoid emitting ambiguous C++ overloads
Just do an arity check for now
2023-05-05 17:07:43 -07:00
Alex Lorenz
aff3568a12 [interop][SwiftToCxx] emit unavailable type stubs for top level types that could not be emitted in the C++ section of the generated header 2023-05-05 17:03:26 -07:00
Alex Lorenz
601802820e [interop][SwiftToCxx] do not assert when emitting a public var and function with the same C++ name 2023-04-24 14:03:46 -07:00
Alex Lorenz
4fda7f4a9a [interop][SwiftToCxx] do not expose APIs with imported declarations whose modules do not have a generated header as specified by the user
The frontend option '-clang-header-expose-module' allows the user to specify that APIs from an imported module have been exposed in another generated header, and thus APIs that depend on them can be safely exposed in the current generated header.
2023-03-10 12:34:02 -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
c2a93f0480 [interop][SwiftToCxx] allow emission of overloaded functions with the same name 2023-03-02 16:34:06 -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
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
2c83ff7643 Merge pull request #61823 from Robertorosmaninho/interop/ExpectedClassForErrorHandling
[Interop][SwiftToCxx] Introduces swift::Expected
2022-12-16 17:47:28 -08:00
Alex Lorenz
28af8bef55 [interop][SwiftToCxx] make it possible to convert Swift String to a std::string in C++
This is done by exposing nested Index and UTF8View type in String. Nested types aren't
supported yet, so we need to employ a number of hacks to emit them.
2022-12-14 16:22:41 -08:00
Roberto Rosmaninho
5fc55b6e4f Add <new> into every bridge header 2022-12-14 12:59:00 -03:00
Alex Lorenz
5c703b4f5c [interop][SwiftToCxx] support std::string -> Swift::String conversion in C++ 2022-12-13 13:13:05 -08:00
Alex Lorenz
7c2ee165cc [interop][SwiftToCxx] only emit metadata references for record types 2022-12-11 21:11:46 -08: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
Slava Pestov
0e4ccb21ed AST: Remove various references to AbstractTypeParamDecl 2022-11-01 19:13:46 -04:00
Alex Lorenz
fdc0632659 [interop][SwiftToCxx] do not emit domain ObjC error values in C++ mode 2022-10-21 12:47:18 -07:00
Alex Lorenz
f8b54e7ea7 [interop][SwiftToCxx] guard inline emitted Stdlib module 2022-10-03 11:31:06 -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
43848fdb14 Merge pull request #61342 from apple/eng/fwd-decl-no-bridge
[interop][SwiftToCxx] forward declare - do not use bridged types in C…
2022-09-28 21:57:59 -07:00
Alex Lorenz
3dfcb96ad5 [interop][SwiftToCxx] forward declare - do not use bridged types in C++ mode
This allows SDK's stdlib Array to correctly decl String forward declaration
2022-09-28 14:11:13 -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
88913c1d65 [interop][SwiftToCxx] expose generic type traits for C++ types in generated header before it's used first 2022-09-13 07:47:30 -07:00
Alex Lorenz
d5c531fefc [interop][SwiftToCxx] experimentally expose exposable Swift's Array members to C++ 2022-09-12 20:42:16 -07:00
Alex Lorenz
1a449f5904 [interop][SwiftToCxx] emit members in extensions for same-type 2022-09-12 20:38:21 -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
b4d7a0c208 [interop][SwiftToCxx] bridge returned C++ record types back to C++ from Swift 2022-09-11 18:42:41 -07:00
Tongjie Wang
cbc23cbafc [Interop][SwiftToCxx] Support enum creation from Cxx 2022-08-29 20:16:52 -07:00
Alex Lorenz
e9450cf80b [interop][SwiftToCxx] add a test to print out empty Swift stdlib module 2022-08-24 15:10:11 -07:00
Alex Lorenz
8de79390be [interop][SwiftToCxx] add @_expose(Cxx) attribute support
This attribute instructs the compiler that this declaration should be included in the generated C++ bindings
2022-08-24 10:14:07 -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
94f6496431 [interop][SwiftToCxx] NFC,do not require definition of protocols for classes in C++ generation mode 2022-08-16 10:44:18 -07:00
Alex Lorenz
26d55a2b83 [interop][SwiftToCxx] start emitting bindings for Swift class types
This includes release on destruction, and correctly returning class values from Swift to C++.
2022-08-02 09:25:35 +01: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