Commit Graph

57 Commits

Author SHA1 Message Date
Egor Zhdan
f42609b7bd [cxx-interop][SwiftToCxx] Do not crash while trying to expose a macro to C++
This fixes a compiler crash that happened when emitting a Clang header for a Swift module that declares multiple macros with the same base name and different argument names.

Swift macros are not currently designed to be exposed to C++. This teaches the compiler to explicitly mark them as unavailable in C++.

rdar://117969472 / resolves https://github.com/apple/swift/issues/69656
2024-05-08 16:08:02 +01: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
Slava Pestov
6cc4738506 C++Interop: Relax some noncopyable generics assertions 2024-02-26 13:08:11 -05: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
Slava Pestov
bbbfc62e6d ClangImporter: Fixes for non-copyable generics 2024-01-31 21:56:45 -05:00
Kavon Farvardin
b4985f7fde [NFC] replace canBeNoncopyable
First, "can have an absence of Copyable" is a rather confusing notion,
so the query is flipped to "can be Copyable". Next, it's more robust to
ask if a conformance exists for the TypeDecl to answer that question,
rather than trying to replicate what happens within that conformance
lookup.

Also renames `TypeDecl::isEscapable` to match.
2024-01-23 22:42:38 -08: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
Kavon Farvardin
a9c64baaa3 [Sema] refactor TypeDecl::isNoncopyable
In preparation for reporting whether the inverse marking on a TypeDecl
was inferred instead of explicit.
2023-11-06 15:40:12 -08:00
Kavon Farvardin
148897ac1a [nfc] refactor ValueDecl::isMoveOnly
I've renamed the method to `TypeDecl::isNoncopyable`, because the query
doesn't make sense for many other kinds of `ValueDecl`'s beyond the
`TypeDecl`'s. In fact, it looks like no one was relying on that anyway.

Thus, we now have a distinction where in Sema, you ask whether
a `Type` or `TypeDecl` is "Noncopyable". But within SIL, we still
preserve the notion of "move-only" since there is additionally the
move-only type wrapper for types that otherwise support copying.
2023-10-18 13:45:50 -07:00
Yuta Saito
ac440c336a [wasm] Accept multiple @_expose on a single function decl
But multiple @_expose with the same exposure kind are still invalid.
2023-09-26 14:13:43 +00:00
Yuta Saito
6d378a3ec3 [wasm] add @_expose(wasm) attribute support
This attribute instructs the compiler that this function declaration
should be "export"ed from this .wasm module. It's equivalent of Clang's
`__attribute__((export_name("name")))`
2023-09-26 14:13:33 +00:00
Egor Zhdan
926653d9fa [cxx-interop][SwiftToCxx] Print operator keyword when mapping Swift operator to C++
Previously we emitted this:
```
SWIFT_INLINE_THUNK bool ==(const IntBox& lhs, const IntBox& rhs)
```
which is not valid in C++.

Now we'll emit this:
```
SWIFT_INLINE_THUNK bool operator==(const IntBox& lhs, const IntBox& rhs)
```

rdar://114772296
2023-09-01 20:06:41 +01:00
Alex Lorenz
97c25ae854 [interop][SwiftToCxx] nested types are not yet supported so do not emit references to them 2023-08-02 13:03:05 -07:00
Becca Royal-Gordon
1318bf5bf5 [NFC] Begin adopting new diagnostics features 2023-07-19 13:06:51 -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
74e87a9ae6 [interop][SwiftToCxx] do not expose move-only Swift types
Swift's consume semantics are not yet supported in C++
2023-05-06 07:12:46 -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
bf35e3f55a [interop][SwiftToCxx] provide a clear unavailable message for protocol decls in C++ 2023-05-05 17:03:28 -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
20704ec0f3 [interop][SwiftToCxx] do not expose enums with a protocol type associated value 2023-04-21 12:06:43 -07:00
Alex Lorenz
71ef7e8d3d [interop][SwiftToCxx] do not expose unsupported enums yet
This includes indirect enums, enums with multiple associated values, or enums whose associated value is a type we don't yet support
2023-04-20 18:05:00 -07:00
Alex Lorenz
f405fb0fa8 [interop][SwiftToCxx] do not expose @alwaysEmitIntoClient properties to C++ 2023-03-15 10:01:37 -07:00
Alex Lorenz
9f86ff9072 [interop][SwiftToCxx] explicitly tell the user that @objc decls can't be yet exposed to C++ 2023-03-13 18:16:36 -07:00
Alex Lorenz
3b7c92073b Merge pull request #64265 from hyp/eng/swift-stdlib-is-swift-whoda-thunk-it
[interop][SwiftToCxx] emit Swift's stdlib inside of 'swift' namespace
2023-03-10 06:40:11 -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
617ead4a9d [interop][SwiftToCxx] do not emit _Concurrency APIs in the C++ section of the generated header
Fixes an issue where actors exposed its unownedExecutor property with unsupported type.
2023-03-09 10:51:22 -08:00
Alex Lorenz
3adf16eb28 Merge pull request #64083 from hyp/eng/api-stdlib-arg-labels
[interop][SwiftToCxx] incorporate argument labels into Stdlib API nam…
2023-03-03 21:37:40 -08:00
Alex Lorenz
13a63f4b05 [interop][SwiftToCxx] incorporate argument labels into Stdlib API names in C++
This allows easier use and more wider API exposure from the Swift stdlib

In the future, all functions and method should incorporate argument labels, but it's not yet clear how
2023-03-03 14:15:48 -08:00
Alex Lorenz
1d3797308d [interop][SwiftToCxx] do not expose functions / properties that throw without the experimental feature 2023-03-02 15:22:36 -08:00
Alex Lorenz
8bce678200 [interop][SwiftToCxx] diagnose when certain generic decls can not yet be exposed to C++ 2023-02-28 09:17:31 -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
Alex Lorenz
d0e5372fc0 [interop][SwiftToCxx] give explicit error for @alwaysEmitIntoClient exposed functions 2022-12-06 11:44:29 -08:00
Alex Lorenz
bd6367986e [interop][SwiftToCxx] report an error for attempts to explicitly expose 'async' functions to C++
also fixup distributed actor example in interop test
2022-11-03 13:46:52 -07:00
Alex Lorenz
0d754e1d3f [interop][SwiftToCxx] add support for exposing non-isolated actor declarations 2022-11-02 12:17:55 -07:00
Alex Lorenz
a949ca987e [interop][SwiftToCxx] do not expose actor classes in the generated header 2022-10-04 21:32:00 -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
fcdcb2a9f1 [interop][SwiftToC++] print C++ interface for top-level Swift functions 2022-03-09 14:53:12 -08:00
Alex Lorenz
e106551028 [NFC][interop] rename the PrintAsObjC library to PrintAsClang
We're starting to support emission of C++ header interfaces, so a language-agnostic name makes more sense
2022-01-20 11:31:58 -08:00
Anthony Latsis
c63b737e92 Collapse all indirect equivalents to ValueDecl::getBaseIdentifier 2020-03-29 00:36:01 +03:00
Anthony Latsis
d0ae3ee580 [AST] Replace FuncDecl::getName & EnumElementDecl::getName with ValueDecl::getBaseIdentifier 2020-03-29 00:35:51 +03:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Jordan Rose
171ff440fc Remove swift::reversed in favor of llvm::reverse (#27610)
The former predates the latter, but we don't need it anymore! The
latter has more features anyway.

No functionality change.
2019-10-10 17:16:09 -07:00
Slava Pestov
0c5d52d860 AST: Introduce AbstractStorageDecl::get{Parsed,Opaque}Accessor()
Also, change visitOpaqueAccessors() to call getOpaqueAccessor() instead of
asserting if the expected accessor does not exist.
2019-08-02 19:34:43 -04:00
Slava Pestov
64c32c695b AST: Remove a few utility methods from AbstractStorageDecl
Since the return value of getAccessor() depends on mutable state, it
does not make sense in the request evaluator world. Let's begin by
removing some utility methods derived from getAccessor(), replacing
calls to them with calls to getAccessor().
2019-08-01 18:31:58 -04:00
Brent Royal-Gordon
1875783734 Use more robust Swift type names for error domains
getErrorDomainStringForObjC() now includes the parent types in the error domain string. Its implementation does not support generic types or private discriminators, but those types can’t be PrintAsObjC’d anyway, so we should never see them.
2018-12-21 15:45:23 -08:00
Brent Royal-Gordon
1a6ca82d6b [NFC] Extract helper for making NSError domains
Avoids having to coordinate changes in two different parts of the compiler.
2018-12-21 15:30:35 -08:00
Slava Pestov
840c97d794 AST: Remove hasAccess() checks 2018-09-05 16:45:31 -07:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Slava Pestov
615d068d63 Sema: Replace some uses of getBaseIdentifier() with userFacingName() 2018-03-14 22:26:58 -07:00
Stephan Tolksdorf
79cef77ce0 [AST] Remove unused LazyResolver parameter from ObjC-selector-related Decl methods 2018-02-27 01:11:35 +01:00