Commit Graph

72 Commits

Author SHA1 Message Date
Egor Zhdan
2db0e8aea8 Merge pull request #85439 from egorzhdan/egorzhdan/endif-objc
[cxx-interop] Emit `#endif // defined(__OBJC__)` with the comment consistently
2025-11-13 03:59:17 +00:00
Egor Zhdan
8cafef09c3 [cxx-interop] Emit #endif // defined(__OBJC__) with the comment consistently
This makes sure that whenever we emit `#if defined(__OBJC__)`, the matching `#endif` has a comment `// defined(__OBJC__)`.

This makes both testing and reading the header file easier.
2025-11-12 11:51:10 +00:00
Alexis Laferrière
94113f4a83 SE-496: Remove references to features CDecl and CImplementation 2025-10-29 17:31:20 -07:00
Gabor Horvath
adca01b1e5 [cxx-interop] Add flag to set minimum access level for reverse interop
rdar://159211965
2025-10-20 10:27:50 -07:00
Alexis Laferrière
9ec824c20b Parser: Rename the experimental attribute @cdecl to @c
There's no users of `@cdecl` yet so we can do a direct rename. The
legacy `@_cdecl` remains unaffected.
2025-09-19 11:55:07 -07:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
Alexis Laferrière
c0889d57c3 PrintAsClang: Print #include for headers used from @cdecl functions
Start printing `#include` for headers referenced from `@cdecl` function
signatures. This adds on top of the existing tiered imports. We already
print each module referenced from decls printed in the compatibility
header. Previously we printed mostly `@import` with an option to
fallback on a `#import`. This change adds a third fallback to `#include`
when the module is referenced from a `@cdecl` function signature. The
bridging header can also be imported in a similar way.
2025-05-14 16:04:37 -07:00
Alexis Laferrière
20e1ac687a PrintAsClang: Ignore nullability attributes for C clients
In C mode we still print nullability attributes. Don't let clang warn on
them and ignore the attribute if the C compiler doesn't know them.
2025-04-18 15:27:19 -07:00
Alexis Laferrière
02933b5b28 PrintAsClang: Print @cdecl in their own block in compatibility headers
Add a block for C clients in the compatibility header. This block
contains only the `@cdecl` functions that are printed using only C
types.

This C block is printed above the Objective-C and C++ blocks as if we
add support for `@cdecl` types other languages should be able to
reference them in function signatures. Other languages block don't
duplicate printing the `@cdecl` functions either as they are already
accessible to them.
2025-04-18 15:23:23 -07:00
Becca Royal-Gordon
60f6afb76c Correct newline emission in generated headers
Eliminates extraneous newlines between top-level Objective-C declarations in `-emit-objc-header` headers. Specifically, there should now always be exactly one—no more, no less—empty line between `@end` and whatever follows it.

Besides being more aesthetically pleasing, this eliminates ordering-dependent behavior where PrintAsClang would print an extra newline when visiting an empty extension, which meant that the order in which empty and non-empty extensions were visited during printing could result in whitespace differences in the compiler output. Printing the blank line is now conditional on whether `tell()` indicates that characters were actually written to the output.

Fixes rdar://143533893.
2025-01-24 16:26:33 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Jan Svoboda
89048bab2f Drop -index-header-map, adopt new Module::Headers API (#77376) 2024-11-06 14:20:01 -08: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
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
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
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
Ben Barham
9779c18da3 Rename startswith to starts_with
LLVM is presumably moving towards `std::string_view` -
`StringRef::startswith` is deprecated on tip. `SmallString::startswith`
was just renamed there (maybe with some small deprecation inbetween, but
if so, we've missed it).

The `SmallString::startswith` references were moved to
`.str().starts_with()`, rather than adding the `starts_with` on
`stable/20230725` as we only had a few of them. Open to switching that
over if anyone feels strongly though.
2024-03-13 22:25:47 -07: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
Alex Lorenz
d8a938883b Merge pull request #69441 from hyp/eng/pssst-ptrauth-why-u-mad
[interop][SwiftToCxx] disable -Wnon-modular-include-in-framework-modu…
2023-10-27 08:00:04 -07:00
Alex Lorenz
e367131053 [interop][SwiftToCxx] disable -Wnon-modular-include-in-framework-module diagnostic before including ptrauth 2023-10-26 13:12:33 -07:00
Allan Shortlidge
d0a4f2633c NFC: Fix unused variable warnings. 2023-10-25 09:42:21 -07:00
Alex Lorenz
2579d1b6ad [rebranch][cxx-interop][SwiftToCxx] supress the -Wunsafe-buffer-usage warnings in the generated header 2023-08-09 15:47:55 -07:00
Evan Wilde
a6fbe439bb Update PrintAsClang clang::Module File API usage
The clang file entry APIs have changed a bit. This patch updates the
code to get the directories and files with the updated APIs.
2023-07-25 12:28:28 -07:00
Alex Lorenz
42bd9d0e64 Merge pull request #65680 from hyp/eng/cxx-warning-nomore-in-stdlib-from-gen-hdr
[interop][SwiftToCxx] avoid importing C++ stdlib in C++ section of ge…
2023-05-05 14:22:23 -07:00
Alex Lorenz
f4f6f7a408 [interop][SwiftToCxx] avoid importing C++ stdlib in C++ section of generated header inside of 'pragma clang attribute' block 2023-05-04 17:01:39 -07:00
Alex Lorenz
228078f074 [interop][SwiftToCxx] remove extraneous semicolon when emitting 'pragma clang module import'
The semicolon actually causes a compiler error in that case
2023-05-04 14:56:55 -07:00
Alex Lorenz
a854550fa2 [interop] fix test failure after c4cc9e8e42
rdar://107445101
2023-03-30 16:34:50 -07:00
Alex Lorenz
c4cc9e8e42 [interop][SwiftToCxx] do not error out on -Wnon-modular-include-in-framework-module clang diagnostic when importing the generated header as part of a framework back into C++ via a Clang module 2023-03-30 08:40:40 -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
2dcbeb0bc9 [interop][SwiftToCxx] do not require @_expose when generating C++ interface for a Swift module
Instead, we emit API bindings for all supported public APIs, when -enable-experimental-cxx-interop is enabled
2023-03-02 14:06:47 -08:00
Alex Lorenz
4c24669c66 [interop][SwiftToCxx] add 'has-expose-attr-or-stdlib' mode to -clang-header-expose-decls flag
This mode allows the user to fallback to the old behavior that required @expose annotations, while still having standard library interfaces emitted in one header
2023-03-02 13:58:23 -08:00
Alex Lorenz
65a467420e Revert "[interop][SwiftToCxx] add -enable-experimental-cxx-interop-in-clang-header flag that lets you enable reverse interop only"
This reverts commit c193a63fd4.
2023-03-02 13:19:34 -08:00
QuietMisdreavus
8d548efbb9 install a list of symbols generated by the PrintAsClang header (#59072)
rdar://93504690
2022-12-09 16:38:02 -07:00
Nuri Amari
cd4b9a6416 Add support for textual imports to -emit-objc-header
Currently headers produced with `-emit-objc-header` /
`-emit-objc-header-path` produce headers that include modular imports.
If the consumer wishes to operate without modules enabled, these headers
cannot be used. This patch introduces a new flag
(`-emit-clang-header-nonmodular-includes`) that when enabled
attempts to argument each modular import included in such a header with
a set of equivalent textual imports.
2022-12-03 13:07:39 -08:00
Evan Wilde
7c0c89546f Revert "Add support for textual imports to -emit-objc-header" 2022-12-02 15:02:19 -08:00
Nuri Amari
91fd5f80e0 Merge pull request #60971 from NuriAmari/textual-imports 2022-11-29 18:24:19 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Nuri Amari
89a01dddfb Add support for textual imports to -emit-objc-header
Currently headers produced with `-emit-objc-header` /
`-emit-objc-header-path` produce headers that include modular imports.
If the consumer wishes to operate without modules enabled, these headers
cannot be used. This patch introduces a new flag
(`-emit-clang-header-nonmodular-includes`) that when enabled
attempts to argument each modular import included in such a header with
a set of equivalent textual imports.
2022-11-19 12:05:09 -08:00
Alex Lorenz
de1e67d054 [interop][SwiftToCxx] include the swiftToCxx shim header only when actually needed for reverse interop 2022-10-17 13:12:20 -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
a24ebeaa51 [interop][SwiftToCxx] install _SwiftCxxInteroperability.h header as part of compiler build, not stdlib
The _SwiftCxxInteroperability.h is too tightly coupled to the compiler right now and should not be shipped with the standard library. In the future it could be moved back to the standard library.
2022-09-28 16:14:33 -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
c193a63fd4 [interop][SwiftToCxx] add -enable-experimental-cxx-interop-in-clang-header flag that lets you enable reverse interop only 2022-09-27 11:26:21 -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
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
a9f262e322 [interop][SwiftToCxx] add support for passing and returning class values to generic functions 2022-08-08 08:38:28 -07:00
Alex Lorenz
aab5c45c01 [interop][SwiftToCxx] include _SwiftCxxInteroperability.h in the toolchain, relative to clang's resource dir 2022-08-03 18:31:53 +01:00
Alex Lorenz
51f907675f [interop][SwiftToCxx] NFC, move swift::Int&UInt declarations into shims headers 2022-08-01 10:38:05 +01:00