Commit Graph

2550 Commits

Author SHA1 Message Date
Pavel Yaskevich
6cdab78028 Merge pull request #70867 from xedin/dynamic-enforcement-of-witness-isolation-with-preconcurrency
[TypeChecker/SILGen] Dynamic enforcement of witness/objc isolation with @preconcurrency attribute
2024-01-17 10:01:37 -08:00
Egor Zhdan
206164013b Merge pull request #70772 from apple/egorzhdan/std-function-initial-tests
[cxx-interop] Initial tests for `std::function` usage
2024-01-17 13:25:02 +00:00
Pavel Yaskevich
e8b7a26eac [AST] Add a flag to indicate that the conformance is @preconcurrency 2024-01-16 11:51:42 -08:00
Pavel Yaskevich
233d279a5c [AST] Support @preconcurrency attribute on test/extension inheritance entries 2024-01-16 10:30:58 -08:00
Pavel Yaskevich
8f8e856ea6 [ClangImporter] Account for Sendable attributes on generic parameter requirements 2024-01-12 11:32:06 -08:00
Egor Zhdan
4ca4b9a290 [cxx-interop] Check for type completeness consistently
`clangSema.isCompleteType` checks for decl visibility according to the module visibility rules, which we don't actually need. What we need to check is whether the record has a definition – this is the check we already use elsewhere in ClangImporter.

This makes sure that we can import `std::function` on Windows.

rdar://103979602
2024-01-11 20:53:45 +00:00
Anthony Latsis
bd2f48d9d2 [NFC] AST: Introduce and use Identifier::isConstructor 2023-12-25 21:09:17 +03:00
Egor Zhdan
233b80e431 Merge pull request #70503 from apple/egorzhdan/no-abstract-ctors
[cxx-interop] Do not import constructors of abstract C++ classes
2023-12-18 17:24:00 +00:00
Egor Zhdan
325868808b [cxx-interop] Do not import constructors of abstract C++ classes
Clang rejects code that tries to call a constructor of an abstract C++ class with an error: "Variable type 'Base' is an abstract class". Swift should reject this as well.

rdar://119689243
2023-12-18 14:52:32 +00:00
Alex Lorenz
9261fa765d Merge pull request #70420 from hyp/eng/virtual-methods++
[cxx-interop] virtual method fixes
2023-12-16 06:37:44 -08:00
Egor Zhdan
65eaafe7da [cxx-interop] Keep pulling in the entire libc++
libc++ recently split the `std` module into many top-level modules: 571178a21a

Previously if a C++ module had `#include <iosfwd>`, importing that module in Swift would make the entire C++ stdlib visible from Swift, since it was a single top-level Clang module. After libc++ got split it doesn't automatically do so, but we need to preserve the current behavior for Swift users.

rdar://119270491
2023-12-14 15:58:15 +00:00
Egor Zhdan
06f9c012c0 Merge pull request #70411 from apple/egorzhdan/libcxx-requires-cplusplus
[cxx-interop] Adjust detection of C++ modules after changes in libc++
2023-12-13 17:02:21 +01:00
Egor Zhdan
01670cdb62 Merge pull request #70325 from apple/egorzhdan/friend-operator-lookup
[cxx-interop] Add friend operators to the lookup table properly
2023-12-13 14:24:58 +01:00
Egor Zhdan
24b0d6e91e [cxx-interop] Adjust detection of C++ modules after changes in libc++
libc++ recently split the `std` module into many top-level modules: 571178a21a

This prevented the conformances to `CxxSet`, `CxxVector`, etc. from being synthesized with a fresh libc++ version.

rdar://119270491
2023-12-13 13:15:31 +00:00
Doug Gregor
2ca67e0e0a Merge pull request #70414 from DougGregor/clang-importer-special-names
[Clang importer] Map imported names via the user-facing name
2023-12-13 00:31:06 -08:00
Alex Lorenz
c19ea96809 [interop] allow virtual methods only for the 'upcoming-swift' release 2023-12-12 17:20:53 -08:00
Doug Gregor
7e30d54deb [Clang importer] Map imported names via the user-facing name
Swift names provided via C attributes or API notes can be parsed as
special names, such as `init` or `subscript`. However, doing so would
cause the Clang importer to crash, because it assumes that these names
are always identifiers. In these places, we actually want to treat
them as identifiers, where special names are mapped back to their
keywords. Introduce a function to do that, and use it consistently.
2023-12-12 14:22:02 -08:00
Egor Zhdan
4a77ae849c [cxx-interop] Fix incorrect diagnostic for non-imported functions
If a C++ function cannot be imported into Swift, we try to emit a diagnostic that explains why. This diagnostic wasn't always correct: for functions that return a C++ struct, we emitted a note saying "function uses foreign reference type in a return type which breaks 'swift_shared_reference' contract" even if the return type is a trivial struct without any attributes. This was emitted unless there was another diagnostic that we also provided for the same function.
2023-12-12 17:05:42 +00:00
Holly Borla
e4436bac7e Merge pull request #70348 from hborla/cxx-generic-subscript
[cxx-interop] Allow imported subscript to have generic parameters.
2023-12-10 13:51:25 -08:00
Holly Borla
450e59c797 [cxx-interop] Allow imported subscript to have generic parameters. 2023-12-08 21:26:11 -08:00
Egor Zhdan
c8017e7d9f [cxx-interop] Add friend operators to the lookup table properly
Previously, `friend` operators declared in C++ classes were added to the lookup table when the class is being imported.

The operators were added to the wrong lookup table if the class is declared in a C++ namespace. Since a namespace can span across multiple Clang modules, its contents should be added to a translation unit level lookup table, not to a module level lookup table.

This change makes sure we add `friend` operators to the lookup table earlier, when we are actually building the lookup table. Note that this is not possible for class template instantiations, because those are instantiated later, so for templates we still handle `friend` operators when importing the instantiation.

rdar://116349899
2023-12-08 18:48:58 +00:00
Hamish Knight
5e7854f46b [AST] Remove static loc and spelling kind from AccessorDecl
The spelling kind was only ever set to
`StaticSpellingKind::None`, and the static location
was never used for anything (and should be queried
on the storage anyway). This doesn't affect the
computation of `isStatic` since `IsStaticRequest`
already takes the static-ness from the storage for
accessors.
2023-12-08 17:59:44 +00:00
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