Commit Graph

568 Commits

Author SHA1 Message Date
Gábor Horváth
c0c28c4c3c Merge pull request #74384 from apple/gaborh/print-decl-order
[cxx-interop] Fix generated declaration order
2024-06-13 19:19:50 +01: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
Gábor Horváth
de9aefc842 Merge pull request #74330 from apple/gaborh/core-foundation-types
[cxx-interop] Fix extra indirection when exporting CFData arguments
2024-06-13 08:29:34 +01:00
Gabor Horvath
ae1f8042c0 [cxx-interop] Fix extra indirection when exporting CFData arguments/return values
The clang nodes associated with Swift's Core Foundation types can already be
represented by a pointer. The interop code does not need to add an extra
layer of indirection in those cases.

rdar://119840281
2024-06-12 16:39:20 +01: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
Gábor Horváth
c2d6039992 Merge pull request #74287 from apple/gaborh/unavailable-generics
[cxx-interop] Fix unavailable generics triggering compilation error
2024-06-11 17:26:22 +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
Gabor Horvath
064a7dd9a0 Address review comments. 2024-06-10 14:18:54 +01:00
Gabor Horvath
53861a4e00 [cxx-interop] Avoid emitting methods that cause name clash
In Swift, we can have enum elements and methods with the same name, they are overloaded.
Unfortunately, this feature is not supported by C++ interop at the moment. This patch
avoids emitting the methods with name collisions to make sure the resulting header
can be compiler. A proper fix should follow in a later PR.

rdar://128162252
2024-06-10 12:35:44 +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
Becca Royal-Gordon
07b9fe9ce6 Support @objc(CustomName) on extensions
This now specifies a category name that’s used in TBDGen, IRGen, and PrintAsClang. There are also now category name conflict diagnostics; these subsume some @implementation diagnostics.

(It turns out there was already a check for @objc(CustomName) to make sure it wasn’t a selector!)
2024-05-16 13:40:13 -07:00
Artem Chikin
1f14158a1d Introduce VisionOS Platform
This change introduces a new compilation target platform to the Swift compiler - visionOS.

- Changes to the compiler build infrastrucuture to support building compiler-adjacent artifacts and test suites for the new target.
- Addition of the new platform kind definition.
- Support for the new platform in language constructs such as compile-time availability annotations or runtime OS version queries.
- Utilities to read out Darwin platform SDK info containing platform mapping data.
- Utilities to support re-mapping availability annotations from iOS to visionOS (e.g. 'updateIntroducedPlatformForFallback', 'updateDeprecatedPlatformForFallback', 'updateObsoletedPlatformForFallback').
- Additional tests exercising platform-specific availability handling and availability re-mapping fallback code-path.
- Changes to existing test suite to accomodate the new platform.
2024-04-10 09:38:02 -07:00
Ben Barham
1fdda023b3 Rename StringRef::endswith references to StringRef::ends_with
Missed this when doing the `startswith` renaming. `endswith` has also
been deprecated upstream (and presumably soon to be removed).
2024-04-01 10:59:16 -07:00
Becca Royal-Gordon
a02698ba06 [PrintAsClang] Fix thunks for throwing Never funcs
Extend the previous commit’s support for functions that return Never to also properly generate code for *throwing* Never functions. This is a little subtle because:

• At the SWIFT_CALL level, throwing Never functions are *not* noreturn
• At the thunk level, throwing Never functions are noreturn *only* if you’re using exceptions; if you’re using swift::Expected, they should throw
• In either case, the compiler cannot statically prove that thunks are noreturn except on the error path, so we need to add an abort() call on the success path
2024-03-29 22:12:20 -07:00
Becca Royal-Gordon
80f38be3b8 [PrintAsClang] Fix thunks for Never funcs
Swift-to-C++ thunk printing for functions didn’t really take into account Swift’s `Never` type. This type maps to `SWIFT_NORETURN`, but it also requires other tweaks to code generation, such as omitting the `return` keyword. (Removing that requires minor changes to many tests.)

Fixes rdar://124137073.
2024-03-29 22:12:19 -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
Becca Royal-Gordon
eff456ffc3 Merge pull request #72203 from beccadax/does-this-sign-conform-to-the-protocol
[PrintAsObjC] Use NSUInteger if protocol requires
2024-03-11 19:14:22 -07:00
Becca Royal-Gordon
0ef9b7952a [PrintAsObjC] Use NSUInteger if protocol requires
When printing an ObjC member into a header with an `Int` parameter or result, PrintAsClang would look up any imported Objective-C member it overrode to see if ClangImporter imported `NSUInteger` as `Int`, and if so, would print `NSUInteger` instead of `NSInteger`. However, it did not do the same for protocol requirements the member witnessed. Correct this oversight.

Fixes rdar://124300674.
2024-03-08 16:26:10 -08: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
Doug Gregor
943e7f1d28 Merge pull request #72099 from DougGregor/clang-import-loosen-inverted
[Clang printing] Loosen assertion on noncopyable & nonescaping requirements
2024-03-05 19:44:06 -08:00
Becca Royal-Gordon
617e85107c Merge pull request #72094 from beccadax/objcimpl-generated-header-override 2024-03-05 18:59:14 -08:00
Doug Gregor
19c08ee569 [Clang printing] Loosen assertion on noncopyable & nonescaping requirements
Noncopyable and nonescaping APIs in Swift can be expressed in C++ with
some downsides. Teach the AST printer to be more lenient, allowing
Swift APIs involving noncopyable and nonescapable types to be printed.
2024-03-05 14:01:21 -08:00
Becca Royal-Gordon
bcdbeb4640 [PrintAsClang] Don’t print any objcImpl overrides
Previously we only excluded implicitly-created overrides, but it turns out explicit overrides are just as problematic and just as unnecessary.

Fixes rdar://123633538.
2024-03-05 11:32:18 -08:00
Alex Hoppen
aa955655ab Merge pull request #72048 from Jamezzzb/#56350
#56350 - Give Identifier a hasUnderscoredNaming() helper
2024-03-04 20:13:01 -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
Slava Pestov
558ed7b246 Merge pull request #71887 from slavapestov/cxx-assert
C++Interop: Relax some noncopyable generics assertions
2024-02-27 06:55:24 -05:00
Slava Pestov
6cc4738506 C++Interop: Relax some noncopyable generics assertions 2024-02-26 13:08:11 -05:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Akira Hatanaka
fe88a00c81 [interop][SwiftToCxx] Skip emitting an accessor method if its name collides with an accessor method of another property
Resolves rdar://119835520 and rdar://119835571.
2024-02-21 17:29:14 -08: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
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
Slava Pestov
57b768db8c ClangImporter: Missed a few more places where they check for requirements 2024-02-01 17:17:43 -05:00
Slava Pestov
bbbfc62e6d ClangImporter: Fixes for non-copyable generics 2024-01-31 21:56:45 -05: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
Allan Shortlidge
e5c6bb649c Remove support for Swift 3 @objc inference.
Obsolete the `-enable-swift3-objc-inference` option and related options by
removing support for inferring `@objc` attributes using Swift 3 rules.
Automated migration from Swift 3 has not been supported by the compiler for
many years.
2024-01-11 15:40:04 -08:00
Slava Pestov
29b7ce2d5d PrintAsClang: Change a couple of isAny() checks into isMarkerExistential() 2023-12-15 14:29:23 -05:00
Becca Royal-Gordon
6591d4ea82 [NFC] Add accessor for @_cdecl name
It also reads the C name out of imported C functions, which will be convenient for @cdecl @implementation.
2023-12-13 11:09:50 -08:00
Becca Royal-Gordon
8651af4325 Make @objcImpl work with @_cdecl
No real diagnostics yet, but we’re emitting mostly correct code.
2023-12-13 11:09:49 -08:00
Alex Lorenz
bcdfb8da28 [interop][SwiftToCxx] dispatch 'class' methods directly to avoid broken header generation
rdar://102393950
2023-11-07 14:33:54 -08:00
Alex Lorenz
ea38d57485 Merge pull request #69519 from hyp/eng/get-type-metadata-helper-inline
[interop][SwiftToCxx] Use 'SWIFT_INLINE_PRIVATE_HELPER' for getTypeMetadata helper to avoid emitting a reference to it when 'DEBUG' macro is set
2023-11-01 10:26:36 -07:00
Alex Lorenz
b1d63d0938 [interop][SwiftToCxx] Use 'SWIFT_INLINE_PRIVATE_HELPER' for getTypeMetadata helper to avoid emitting a reference to it when 'DEBUG' macro is set
This is needed as the metadata for C++ types might not be actually emitted and thus we can't always reference it

Fixes https://github.com/apple/swift/issues/69234

rdar://117089662
2023-10-31 09:21:01 -07:00
Alex Lorenz
70a968a111 Merge pull request #69515 from hyp/eng/generic-generic-generic-generic
[interop][SwiftToCxx] ensure Swift generic types can be used as template parameters to other Swift generic types in C++
2023-10-30 17:30:36 -07:00
Alex Lorenz
bd372c2d68 Merge pull request #69473 from hyp/eng/consuming-params
[interop][SwiftToCxx] consuming parameters should be passed using an …
2023-10-30 15:19:28 -07:00
Alex Lorenz
ca95860530 [interop][SwiftToCxx] ensure Swift generic types can be used as template parameters to other Swift generic types in C++
rdar://117015962
2023-10-30 12:17:29 -07:00
Alex Lorenz
645073de55 [interop][SwiftToCxx] do not expose Swift APIs with shared FRTs as their ownership is not yet managed at the language boundary 2023-10-30 10:54:25 -07:00
Pavel Yaskevich
1b521a5c69 [PrintAsClang] Don't attempt forward declare marker protocols 2023-10-30 10:21:04 -07:00
Alex Lorenz
ab948f4897 [interop][SwiftToCxx] ensure that buffers for heap allocated Swift values are released after parameter copy is consumed 2023-10-29 17:08:02 -07:00
Alex Lorenz
4e519a8d8b [interop][SwiftToCxx] consuming parameters should be passed using an additional copy
Fixes https://github.com/apple/swift/issues/69372
2023-10-27 17:29:52 -07: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