Commit Graph

572 Commits

Author SHA1 Message Date
swift-ci
61d5b48a52 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-02 08:15:55 -07:00
Egor Zhdan
7f597c63ae Merge pull request #76726 from swiftlang/egorzhdan/char8_t
[cxx-interop] Support `char8_t` C++20 type
2024-10-02 16:10:17 +01:00
swift-ci
f00e29868e Merge remote-tracking branch 'origin/main' into rebranch 2024-09-28 08:15:47 -07:00
Allan Shortlidge
07b84fccfb AST: Introduce ModuleDecl::isClangHeaderImportModule() convenience. 2024-09-27 12:00:03 -07:00
Egor Zhdan
fcb590690e [cxx-interop] Support char8_t C++20 type
https://en.cppreference.com/w/cpp/keyword/char8_t

This is based on a patch from Varun Gandhi: https://github.com/swiftlang/swift/pull/26153

rdar://39988329 / resolves https://github.com/swiftlang/swift/issues/68726
2024-09-27 13:56:03 +01:00
swift-ci
5e0b892e9e Merge remote-tracking branch 'origin/main' into rebranch 2024-09-20 13:09:36 -07:00
Slava Pestov
0bd6f257b9 PrintAsClang: More idiomatic conformance lookup 2024-09-19 14:18:33 -04:00
Ben Barham
a7b50f357f Merge remote-tracking branch 'origin/main' into manual-main-merge
Conflicts:
  - `lib/Driver/ToolChains.cpp` conflicting with the `addAllArgs` rename
    for multiple options
2024-09-16 13:53:18 -07:00
Becca Royal-Gordon
5d6ca1c10a Partially revert “Support @objc(CustomName) on extensions”
Revert portions of 07b9fe9ce6 to temporarily avoid applying `@objc(CustomName) extension`s to generated header category names.

Fixes rdar://135924149.
2024-09-12 23:15:26 -07:00
Doug Gregor
b272a05ea9 Merge pull request #76363 from DmT021/wp/print-diagnostic-groups
[Diagnostics] Add -print-diagnostic-groups flag
2024-09-11 13:04:07 -07:00
Dmitrii Galimzianov
a8b71ea97f Add -print-diagnostic-groups flag
This change adds the `-print-diagnostic-groups` flag as described by SE-0443.
2024-09-11 13:34:42 +02: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
swift-ci
f1877410ef Merge remote-tracking branch 'origin/main' into rebranch 2024-09-03 02:53:13 -07:00
Gabor Horvath
1842867de2 [cxx-interop][NFC] Fix some clang-tidy warnings
Mostly remove redundant includes, adding missing namespace end comments
and using isa_and_nonnull.
2024-09-02 15:24:47 +01:00
swift-ci
f8bfda0159 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-30 14:34:38 -07:00
Gabor Horvath
131a354436 [cxx-interop] Do not attempt to export read accessors to C++
This triggers a crash. Unfortunately, adding support is not that
straightforward so skipping these accessors for now.

rdar://134425834
2024-08-30 16:16:04 +01:00
Ben Barham
467e528200 Merge remote-tracking branch 'origin/main' into manual-rebranch-merge
Conflicts:
  - `lib/Serialization/ModuleFormat.h` bumped version to account for
    differences between main and rebranch.
2024-08-09 15:22:39 -07:00
Egor Zhdan
c3e067bb34 Merge pull request #75804 from swiftlang/egorzhdan/static-inline
[cxx-interop] Print `inline` instead of `static inline` for template specializations
2024-08-09 22:37:36 +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
57e00e4ecf [cxx-interop] Support operator[] with multiple parameters
C++ only support multiparameter operator[] in C++23 and up. Change the
code to protect such overloaded operators with a C++ language mode
check.

rdar://133539699
2024-08-09 15:33:47 +01:00
Ben Barham
db5fd1d087 [cxx-interop] Print inline instead of static inline for template specializations
This was fixed in 14413d9d90 but then lost
when a05b3051fa was merged in. Bring it
back.
2024-08-08 11:41:36 -07:00
swift-ci
2bf8a521eb Merge remote-tracking branch 'origin/main' into rebranch 2024-08-07 09:53:42 -07:00
Gábor Horváth
4c3c612b92 Merge pull request #75692 from swiftlang/gaborh/reverse-interop-c-structs
[cxx-interop] Support reexposing C structs from Swift to C++
2024-08-07 17:44:43 +01:00
Gábor Horváth
e867c08644 Merge pull request #75708 from swiftlang/gaborh/embedded-comment
[cxx-interop] Document Embedded Swift limitations in a comment
2024-08-07 17:44:00 +01:00
swift-ci
13a412eeb3 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-07 02:17:43 -07:00
Ben Barham
7bdf1e117e Merge remote-tracking branch 'origin/main' into manually-merge-main-to-rebranch
Conflicts:
  - `lib/PrintAsClang/PrintSwiftToClangCoreScaffold.cpp` not positive
    what the cause here was, just took main.
2024-08-06 13:44:27 -07:00
Gabor Horvath
0276d46718 [cxx-interop] Fix reverse interop crash when using raw modules
Some fields in the AST are cached values that are populated lazily. We
should not use those values directly as in case they are not yet
computed we get back null pointers. Use ASTContext instead which can
call the slow path if the cache is not yet populated.

rdar://132746445
2024-08-06 17:42:52 +01:00
Gabor Horvath
b49a3e5ab9 [cxx-interop] Document Embedded Swift limitations in a comment 2024-08-06 12:03:02 +01:00
Gabor Horvath
c4649edc2c [cxx-interop] Support reexposing C structs from Swift to C++
Previously, when a Swift API referenced a C struct (that is not a C++
struct), we did not expose said API to C++. The reason was that we do
not have support yet for non-trivial structs (structs with ARC fields).
This patch introduces logic to determine if a C struct is trivial and
lets us expose trivial C structs from Swift to C++.

rdar://111812577
2024-08-05 17:44:00 +01:00
Gabor Horvath
a05b3051fa [cxx-interop] Fix crash with reverse interop in Embedded Swift
Embedded Swift has a minimal runtime, some type metadata is not
available. This patch works around a crash that tries to emit C++
briding to this non-existent Swift metadata. It is very likely that
there will be more fallout in reverse interop, but this patch should fix
the most glaring issue, crashing on an empty Embedded Swift project.

rdar://129030521
2024-08-05 10:47:09 +01:00
Becca Royal-Gordon
893a30ebbb Update availability attribute printing
The new clang implements “P2361 Unevaluated string literals”, which means it rejects numeric escapes in string literals in attributes (most notably for Swift, availability attributes). Update PrintAsClang to follow these new rules when it prints availability attributes. In the case of control characters which cannot be otherwise represented, this means Swift will print a hex code for the user to read.

Fixes rdar://127263671.
2024-07-24 13:40:39 -07:00
Egor Zhdan
14413d9d90 [cxx-interop][rebranch] 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-07-24 13:01:46 +01:00
Gábor Horváth
536a88971f Merge pull request #75396 from swiftlang/gaborh/value-type-trait
[cxx-interop] Support generic types with isValueType trait
2024-07-24 12:11:24 +02:00
Gabor Horvath
48ebed6760 [cxx-interop] Support generic types with isValueType trait
In some circumstances the missing trait resulted in picking the wrong
branch of some compile time conditionals resulting in code that would
not compile.

rdar://126709253
2024-07-23 09:48:49 +02: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
Gábor Horváth
439cbe6221 Merge pull request #75100 from swiftlang/gaborh/support-optional-generic-in-enum
[cxx-interop] Support optional generic cases in enums
2024-07-18 15:14:02 -07:00
Gabor Horvath
e6c3cb3db1 [cxx-interop] Forward declare classes
The code already forward declared strutcs and enums. This patch extends
the logic to also forward declare classes. Unfortunately, there was some
fallout because some traits ended up defined multiple times for some
classes, so the code is now extended to only conditionally emit these
traits if no forward declaration was emitted for the type yet.

rdar://124022242
2024-07-18 15:27:50 +01:00
Gabor Horvath
fe1a4b5961 [cxx-interop] Export accessors of static properties to C++
The code wants to avoid exporting certain synthesized operators but it
inadvertently also prevented exporting accessors to static properties.

rdar://115564118
2024-07-12 16:33:35 +01:00
Gabor Horvath
b5384bc8a6 [cxx-interop] Support optional generic cases in enums
This PR implements proper support for optional generic associated values
in enum cases. Most of the code changes are supporting generic types in
more contexts in the printer, the rest are making sure we handle the
null pointer case when we try to get the declaration from the type that
represents a generic parameter.

rdar://131112273
2024-07-09 16:08:27 +01:00
Gabor Horvath
c56cca1d3b [cxx-interop] Do not expose enums with optional generic cases
Unfortunately, we cannot generate the C++ code for them just yet. There
will be a follow-up PR to actually fix the underlying issue and expose
such enums correctly.

rdar://129250756
2024-07-04 15:42:50 +01:00
Gábor Horváth
3ee8272c42 Merge pull request #74942 from swiftlang/gaborh/emit-implicit-std-dependencies-all-public
[cxx-interop] Emit Swift StdLib dependencies when all public decls emitted
2024-07-04 11:24:02 +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
Daniel Rodríguez Troitiño
00e866ae53 [cxx-interop] noexcept specifier before function attributes (#74780)
In #74516 the `SWIFT_NOEXCEPT` specifier is added to the imported Swift
functions in C++ mode, but it is added after the function attributes. It seems
that the tests only do `-fsyntax-only`, which seems not to catch an error like
"expected function body after function declarator" when the header is
used without that flag.

Flip the attributes and the specifier around in the printer, and flip
them in all the tests.

The tests were using `%check-in-clang`, but it only checks importing as
an objective-c-header. Add a parallel `%check-in-clang-cxx` to test also
in C++. It uses C++17 because of some details in the imported headers and
disables a warning about variadic macros that was promoted to an error
and was blocking passing the tests. The clang-importer-sdk gets the
minimal set of files to compile the two modified tests as C++. The files
are mostly empty, except `cstddef` that imports the equivalent C header.
Some modifications were needed in `ctypes.h` because the header was
using features only available in C and not C++.
2024-06-27 22:49:03 -07:00
Gábor Horváth
78b0fd75bf Merge pull request #74654 from swiftlang/gaborh/reenable-exposing-frts
[cxx-interop] Reenable exporting Foreign Reference Types to C++
2024-06-26 13:38:53 +01:00
Becca Royal-Gordon
9f18481dc8 Merge pull request #74637 from beccadax/enum-my
[PrintAsCxx] Fix printing of C++ enum args
2024-06-24 13:51:58 -07:00
Gabor Horvath
7b72e8f6d7 [cxx-interop] Reenable exporting Foreign Reference Types to C++
This feature worked prior 5.10 but the semantics was undefined. This PR
restores the behavior with the old semantics, and a separate PR will
update the documentation to describe the behavior.
2024-06-24 17:59:49 +01:00
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
7fa35d4d6a [PrintAsCxx] Fix printing of C++ enum args
Because imported enums are @objc, they were treated as unsupported in C++ and therefore ineligible to be printed in a C++ generated header. Narrow this logic so that only @objc *classes* are excluded, and update related printing logic to support enums correctly.

Fixes rdar://124262637.
2024-06-21 16:01:55 -07:00
Gábor Horváth
5fbf42a76f Merge pull request #74516 from swiftlang/gaborh/objcpp-fix
[cxx-interop] Fix exporting cdecl Swift functions to Obj-C++
2024-06-21 06:58:54 +01: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