Commit Graph

2428 Commits

Author SHA1 Message Date
Egor Zhdan
6ecaaa41c5 Merge pull request #70304 from apple/egorzhdan/conforms-to-derived-class
[cxx-interop] Propagate `CONFORMS_TO` attribute to derived classes
2023-12-07 22:00:44 +01:00
Egor Zhdan
45b22542d5 [cxx-interop] Propagate CONFORMS_TO attribute to derived classes
If `struct Base` is a public base class of `struct Derived`, and `Base` is annotated with `__attribute__((swift_attr("conforms_to:MyModule.MyProto")))`, `Derived` will now also get a conformance to `MyProto`.

rdar://113971944
2023-12-07 18:11:37 +00:00
Alex Lorenz
c7345d08cf Merge pull request #69790 from hyp/eng/move-only-is-back
[cxx-interop] enable support for move-only types
2023-12-06 09:43:43 -08:00
Alex Lorenz
623d3d2032 [cxx-interop] review fixes for non-copyable patch, ensure we only enable this in upcoming Swift 2023-12-05 14:16:30 -08:00
Egor Zhdan
8c049fda1e Merge pull request #69991 from apple/egorzhdan/using-arithmetic-op
[cxx-interop] Import using decls that refer to member operators of a base class
2023-12-05 12:38:44 +01:00
Puyan Lotfi
ebe83a4ac2 [cxx-interop] WA: skip virtual function import when symbolic import enabled
This is a simple work around to avoid importing virtual functions when symbolic
imports are turned on. Test cases that were failing before this WA are in
test/Interop/Cxx/symbolic-imports.

Thanks to Alex Lorenz for providing this WA to me (@hyp).
2023-12-04 01:57:13 -05:00
Puyan Lotfi
128064f31d [cxx-interop] Enable virtual function calling from Swift to C++
This is a forward-interop feature that wires up existing functionality for
synthesizing base class function calling to enable virtual function calling.
The general idea is to sythesize the pattern:

```
// C++ class:
struct S { virtual auto f() -> int { return 42; } };

// Swift User:
var s = S()
print("42: \(s.f())")

// Synthetized Swift Code:
extension S { func f() -> CInt { __synthesizedVirtualCall_f() } }

// Synthetized C/C++ Code:
auto __cxxVirtualCall_f(S *s) -> int { return s->f(); }
```

The idea here is to allow for the synthetized C++ bits from the Clang side to
handle the complexity of virtual function calling.
2023-12-04 01:55:30 -05:00
Alex Lorenz
c029ed68d6 [cxx-interop] try to workaround the linux libstdc++ move-only failure 2023-12-01 15:25:24 -08:00
Egor Zhdan
c497bab6c4 [cxx-interop] Fix assertion failure when emitting a module interface
```
Assertion failed: (LHS.isValid() && RHS.isValid() && "Passed invalid source location!"), function isBeforeInTranslationUnit, file SourceManager.cpp, line 1991.
```

rdar://118572078
2023-11-20 20:15:15 +00:00
Egor Zhdan
ece33a4d15 [cxx-interop] Import using decls that refer to member operators of a base class
This is required for proper support for `std::vector::iterator` on Windows.

rdar://118657936 / resolves https://github.com/apple/swift/issues/69990
2023-11-20 18:57:12 +00:00
Egor Zhdan
0b69eb5254 [cxx-interop] Refactor: add member operator instantiations to the lookup table elsewhere
NFC intended
2023-11-17 18:03:03 +00:00
Alex Lorenz
86e5556e91 [cxx-interop] add support for 'address' pointee for non-copyable C++ types 2023-11-16 10:08:30 -08:00
zoecarver
a78a7ec4aa [cxx-interop] Cleanup: remove debug printing, enable more tests. 2023-11-16 10:08:27 -08:00
zoecarver
c79eace683 no merge: add some debugging for linux. 2023-11-16 10:08:26 -08:00
zoecarver
e738bdfdc8 [cxx-interop] Import move only types even when -enable-experimental-move-only isn't added. 2023-11-16 10:08:22 -08:00
Egor Zhdan
efc008a2ca [cxx-interop] Import using decls that expose methods from private base classes
If a C++ type `Derived` inherits from `Base` privately, the public methods from `Base` should not be callable on an instance of `Derived`. However, C++ supports exposing such methods via a using declaration: `using MyPrivateBase::myPublicMethod;`.

MSVC started using this feature for `std::optional` which means Swift doesn't correctly import `var pointee: Pointee` for instantiations of `std::optional` on Windows. This prevents the automatic conformance to `CxxOptional` from being synthesized.

 rdar://114282353 / resolves https://github.com/apple/swift/issues/68068
2023-11-14 00:30:54 +00:00
Alex Lorenz
1d53ecedfd [cxx-interop] make sure a const operator [] is imported as a mutable setter 2023-11-10 14:21:03 -08:00
Sophia Poirier
4c9a726183 nonisolated(unsafe) to opt out of strict concurrency static checking for global variables 2023-10-26 16:22:28 -07:00
Doug Gregor
5ad39c84e0 [Typed throws] Record thrown error types and conversions in the AST
For any operation that can throw an error, such as calls, property
accesses, and non-exhaustive do..catch statements, record the thrown
error type along with the conversion from that thrown error to the
error type expected in context, as appropriate. This will prevent
later stages from having to re-compute the conversion sequences.
2023-10-24 12:40:22 -07:00
Mishal Shah
aa6a588f45 Merge pull request #69163 from apple/rebranch
Merge `rebranch` into `main` to support `stable/20230725` llvm-project branch
2023-10-23 09:26:37 -07:00
Egor Zhdan
879b04f2e7 Merge pull request #69327 from apple/egorzhdan/circular-requests
[cxx-interop] Avoid circular reference errors when importing C++ structs
2023-10-23 14:35:02 +01:00
Egor Zhdan
4632d894e6 [cxx-interop] Avoid circular reference errors when importing C++ structs
When importing a C++ struct, if its owning module requires cplusplus, Swift tried to auto-conform it to certain protocols from the Cxx module. This triggers name lookup in the clang struct, specifically for `__beginUnsafe()` and `__endUnsafe` methods, which imports all of the base structs including their methods.

This moves the import of base structs out of the name lookup request, preventing cycles.

rdar://116426238
2023-10-23 12:19:05 +01:00
Harlan Haskins
4ac34a40ea @retroactive conformance syntax and checking (#36068) 2023-10-20 14:27:03 -07:00
swift-ci
bfc9d85449 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-11 18:14:16 -07:00
Slava Pestov
a3fa3bf110 Merge pull request #69038 from slavapestov/clean-up-associated-conformances
Preparation for lazily populating associated conformances
2023-10-11 20:58:27 -04:00
Slava Pestov
9562cfb841 ClangImporter: Remove call to finishSignatureConformances() 2023-10-11 15:04:09 -04:00
Evan Wilde
24d0db249b Merge remote-tracking branch 'main' into 'rebranch'
Conflicts:
  CMakeLists.txt
    Take new BRIDGING_MODE

  SwiftCompilerSources/Sources/SIL/GlobalVariable.swift
    Take new
2023-10-09 17:21:23 -07:00
Egor Zhdan
041005af7c [cxx-interop] Use more correct type names in C++ template parameters
When importing a C++ class template instantiation, Swift translates the template parameter type names from C++ into their Swift equivalent.

For instance, `basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>>` gets imported as `basic_string<Scalar, char_traits<Scalar>, allocator<Scalar>>`: `wchar_t` is imported as `CWideChar`, which is a typealias for `Scalar` on most platforms including Darwin. Notice that Swift goes through the `CWideChar` typealias on the specific platform. Another instantiation `basic_string<uint32_t, char_traits<uint32_t>, allocator<uint32_t>>` also gets imported as `basic_string<Scalar, char_traits<Scalar>, allocator<Scalar>>`: `uint32_t` is also imported as `Scalar`. This is problematic because we have two distinct C++ types that have the same name in Swift.

This change makes sure Swift doesn't go through typealiases when emitting names of template parameters, so `wchar_t` would now get printed as `CWideChar`, `int` would get printed as `CInt`, etc.

This also encourages clients to use the correct type (`CInt`, `CWideChar`, etc) instead of relying on platform-specific typealiases.

rdar://115673622
2023-10-09 14:57:10 +01:00
swift-ci
447482505a Merge remote-tracking branch 'origin/main' into rebranch 2023-10-05 08:05:25 -07:00
Egor Zhdan
0b2048d096 Merge pull request #68578 from apple/egorzhdan/cxx-convertible-to-bool
[cxx-interop] Add conversion to Bool for types that define `operator bool()`
2023-10-05 15:52:03 +01:00
swift-ci
06f9a8a703 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-30 11:33:40 -07:00
Doug Gregor
ef642098f2 [Typed throws] Parsing and AST representation for typed errors
Parse typed throw specifiers as `throws(X)` in every place where there
are effects specified, and record the resulting thrown error type in
the AST except the type system. This includes:
* `FunctionTypeRepr`, for the parsed representation of types
* `AbstractFunctionDecl`, for various function-like declarations
* `ClosureExpr`, for closures
* `ArrowExpr`, for parsing of types within expression context

This also introduces some serialization logic for the thrown error
type of function-like declarations, along with an API to extract the
thrown interface type from one of those declarations, although right
now it will either be `Error` or empty.
2023-09-29 10:51:51 -07:00
Egor Zhdan
f0be52accd [cxx-interop] Add conversion to Bool for types that define operator bool()
C++ `operator bool()` is currently imported into Swift as `__convertToBool()`, which shouldn't be used by clients directly.

This adds a new protocol into the C++ stdlib overlay: `CxxConvertibleToBool`, along with an intitializer for `Swift.Bool` taking an instance of `CxxConvertibleToBool`.

rdar://115074954
2023-09-18 14:54:45 +01:00
swift-ci
1b4375ff33 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-12 17:00:25 -07:00
Alex Lorenz
786c78a895 [interop] do not synthesize special members for C++ records with incomplete fields
The incomplete fields will trigger different assertions when clang is sythensizing constructors/destructors

rdar://109417079
2023-09-11 11:01:51 -07:00
swift-ci
0407c3d3b2 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-06 13:34:53 -07:00
Allan Shortlidge
0dd8f4c492 AST: Introduce abstraction for extension/type decl inheritance clauses.
Wrap the `InheritedEntry` array available on both `ExtensionDecl` and
`TypeDecl` in a new `InheritedTypes` class. This class will provide shared
conveniences for working with inherited type clauses. NFC.
2023-09-06 10:41:57 -07:00
swift-ci
632da182bd Merge remote-tracking branch 'origin/main' into rebranch 2023-08-30 08:36:11 -07:00
Egor Zhdan
9b7dbf2599 [cxx-interop] Introduce APINotes file for C++ stdlib
This adds an `std.apinotes` file that is installed into `lib/swift/apinotes` along with existing Darwin apinotes. This new file is installed on all platforms. It replaces a few special cases in the compiler for `cmath` and `cstring` functions.

This does not require the upcoming APINotes support for namespaces, however, this does require https://github.com/apple/llvm-project/pull/7309.

rdar://107572302
2023-08-29 23:34:36 +01:00
swift-ci
0a607cead8 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-14 13:16:19 -07:00
Egor Zhdan
41e4a50126 Merge pull request #67873 from apple/egorzhdan/pthread_mutexattr_t
[cxx-interop] Make sure to create empty initializers for C++ structs
2023-08-14 21:09:14 +01:00
Egor Zhdan
4eb9c3be37 [cxx-interop] Make sure to create empty initializers for C++ structs
The existing synthesis mechanism had a bug: `cxxRecordDecl->hasDefaultConstructor()` returns true for C++ types with an implicit default constructor, for instance, `pthread_mutexattr_t`.

rdar://113708880
2023-08-14 17:46:57 +01:00
swift-ci
b87613bace Merge remote-tracking branch 'origin/main' into rebranch 2023-08-10 04:34:00 -07:00
Slava Pestov
50afb006ee ClangImporter: Remove unnecessary setGenericSignature() call 2023-08-09 17:42:58 -04:00
Slava Pestov
7f9a71cd15 AST: Rename ASTContext::getConformance() to getNormalConformance() 2023-08-09 17:42:25 -04:00
swift-ci
01bb951b0e Merge remote-tracking branch 'origin/main' into rebranch 2023-08-07 11:33:36 -07:00
Egor Zhdan
4acf9c8cf4 [cxx-interop] Add CxxVector protocol
This makes it possible to initialize `std::vector` from a Swift Sequence. This also conforms C++ vectors to `ExpressibleByArrayLiteral`, making it possible, for instance, to pass a Swift array to a C++ function that takes a vector of strings as a parameter.

rdar://104826995
2023-08-07 17:12:12 +01:00
swift-ci
ae4b70bf28 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-04 18:59:37 -07:00
Slava Pestov
6ae2a1deee Merge pull request #67739 from slavapestov/var-decl-type-in-context
AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
2023-08-04 21:44:22 -04:00
swift-ci
3497832e24 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-04 16:39:50 -07:00