Commit Graph

5139 Commits

Author SHA1 Message Date
Egor Zhdan
46f86f0870 [cxx-interop] Import custom NS_OPTIONS correctly
This changes the heuristic that we use to detect `CF_OPTIONS`/`NS_OPTIONS` instantiations in C++ language mode.

Since libraries sometimes declare custom option types that break the assumptions about the names of such types, this lifts the requirements on the type name.

rdar://113524090
rdar://113279214
2023-08-18 15:41:50 +01: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
fbfeb4fbfc Merge pull request #67750 from artemcm/SeparateClangScannerCachePath
[Dependency Scanning] Separate module output path from Clang scanner's module cache
2023-08-10 16:41:15 -07:00
Egor Zhdan
3723ff1401 [cxx-interop] Add UnsafeCxxMutableRandomAccessIterator protocol
This will be used to provide a safe overload of `std::vector::erase` in Swift.

`std::vector::erase` is not currently imported into Swift because it returns a C++ iterator.

rdar://113704853
2023-08-10 19:58:51 +01:00
Artem Chikin
6ef79c4ba0 [Dependency Scanning] Specify Explicit Module output path to the scanner explicitly
Instead of the code querying the compiler's built-in Clang instance, refactor the
dependency scanner to explicitly keep track of module output path. It is still
set according to '-module-cache-path' as it has been prior to this change, but
now the scanner can use a different module cache for scanning PCMs, as specified
with '-clang-scanner-module-cache-path', without affecting module output path.

Resolves rdar://113222853
2023-08-10 11:11:05 -07:00
Artem Chikin
8501f99cb2 [Dependency Scanning] Add option to specify a separate Clang Dependency scanner module cache.
Clang dependency scanning produces scanner PCMs which we may want to live in a
different filesystem location than the main build module cache.

Resolves rdar://113222853
2023-08-10 11:10:18 -07:00
Artem Chikin
f905b28a24 Merge pull request #67577 from artemcm/ConfigureClangScanDepsWithAlreadySeen
[Dependency Scanning] Add Clang modules from scan-deps queries to theset of "already seen" modules, to pass down to subsequent queries.
2023-08-10 10:09:55 -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
Artem Chikin
0c6f212cd5 [Dependency Scanning] Add Clang modules from scan-deps queries to the set of
"already seen" modules, to pass down to subsequent queries.
2023-08-09 09:16:46 -07:00
Egor Zhdan
aecc10e90b Merge pull request #67775 from apple/egorzhdan/clang-stmt-iterator
[cxx-interop] Fix SwiftCompilerSources hosttools build
2023-08-08 14:11:15 +01:00
Egor Zhdan
c621d13711 [cxx-interop] Fix SwiftCompilerSources hosttools build
This fixes a compiler error when building SwiftCompilerSources in hosttools mode with a recent Xcode.

```
<unknown>:0: error: calling a private constructor of class 'clang::StmtIterator'
swift/llvm-project/clang/include/clang/AST/StmtIterator.h:137:3: note: declared private here
  StmtIterator(const StmtIteratorBase &RHS)
  ^
```

rdar://113514872
2023-08-07 20:11:29 +01: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
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
Saleem Abdulrasool
a4c5b9de8a Merge pull request #67718 from compnerd/architectures-for-none
ClangImporter: correct a duplicated path component
2023-08-04 17:31:13 -07:00
Alex Lorenz
dd658bd716 Merge pull request #67728 from hyp/eng/symbolic-stronger-together
[cxx-interop][symbolic interface] add a fallback for unknown generic …
2023-08-04 15:19:43 -07:00
Alex Lorenz
4fcaddb4d8 Merge pull request #67726 from hyp/eng/friends-no-more
[cxx-interop] do not add friend decls as a member of Swift type that …
2023-08-04 15:19:35 -07:00
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
Alex Lorenz
ac3866aaa7 [cxx-interop][symbolic interface] add a fallback for unknown generic type to be Any 2023-08-03 17:36:26 -07:00
Alex Lorenz
f8dbc01dc6 [cxx-interop] do not add friend decls as a member of Swift type that represents a C++ class 2023-08-03 14:03:45 -07:00
Saleem Abdulrasool
eee9331d97 ClangImporter: correct a duplicated path component
When computing the path for a non-architecture specific resource, we
would append the architecture unconditionally if `-sdk` is used.  This
would result in the path being miscomputed with the architecture or the
architecture duplicated if it was architecture specific.

Found by inspection.
2023-08-03 10:58:39 -07:00
Egor Zhdan
42cbacfd15 Merge pull request #67653 from apple/egorzhdan/stream-delegate
[cxx-interop] Import `NSStreamDelegate.stream` correctly
2023-08-02 20:45:29 +01:00
Egor Zhdan
6edde292f1 [cxx-interop] Import NSStreamDelegate.stream correctly
This Objective-C method
```
- (void)stream:(NSStream *)aStream
   handleEvent:(NSStreamEvent)eventCode;
```
should be imported as
```
optional func stream(
    _ aStream: Stream,
    handle eventCode: Stream.Event)
```
and not
```
optional func stream(
    _ aStream: Stream,
    handleEvent eventCode: Stream.Event)
```
in order to stay compatible with Objective-C interop mode.

rdar://113208675
2023-08-02 17:54:58 +01:00
Egor Zhdan
6caaa77efc [cxx-interop] Allow mutating std::map from Swift
This adds a setter to the `CxxDictionary` subscript which makes it possible to mutate `std::map` and `std::unordered_map` from Swift.

rdar://105399019
2023-08-02 16:44:30 +01:00
Egor Zhdan
5f624d18fd Merge pull request #67618 from apple/egorzhdan/std-pair-init
[cxx-interop] Force creating a memberwise init for `std::pair`
2023-08-02 13:04:27 +01:00
Egor Zhdan
6902041e34 [cxx-interop] Force creating a memberwise init for std::pair
In libc++, `pair()` and `pair(_T1 const& __t1, _T2 const& __t2)` are templated with `enable_if`, so these initializers are not imported into Swift.

There should be a way to call `std.pair.init` from Swift, so this change makes sure Swift synthesizes a memberwise initializer for `std.pair`.

rdar://113135110
2023-08-01 18:59:41 +01:00
Alex Lorenz
0eed1a944c [cxx-interop] correctly add and lookup enumerators added to enums that correspond to namespaces
Fixes https://github.com/apple/swift/issues/67604
2023-07-31 18:57:50 -07:00
Egor Zhdan
9e35a83341 Merge pull request #67598 from apple/egorzhdan/memberwise-init
[cxx-interop] Memberwise init is not synthesized for C++ type with templated using decl
2023-07-28 23:55:23 +01:00
Egor Zhdan
9c22a7a530 [cxx-interop] Memberwise init is not synthesized for C++ type with templated using decl
When Swift fails to import a member of a struct, it checks to see if this member could affect the memory layout of the struct, and if it can, Swift doesn't synthesize the memberwise initializer for this struct. This logic was overly restrictive and treated templated using-decls as potentially affecting the memory layout of the struct.

rdar://113044949
2023-07-28 19:53:59 +01:00
Alex Lorenz
a219cfa632 Merge pull request #67557 from hyp/eng/64457
[cxx-interop][linux] modularize the bits part of libstdc++
2023-07-27 20:48:11 -07:00
Alex Lorenz
c215abdd8c [cxx-interop][linux] modularize the bits part of libstdc++
Fixes https://github.com/apple/swift/issues/64457
2023-07-27 10:20:28 -07:00
Egor Zhdan
b860fddd52 [cxx-interop] Fix assertion failure in IRGen with mutable dereference operators
I discovered this when experimenting with `std::map::iterator`, which has a const overload of `operator*` that returns a non-const reference, and does not have a const overload of `operator*`.

rdar://112471779
2023-07-27 15:54:09 +01:00
Egor Zhdan
8d7d0efe13 [cxx-interop] Add UnsafeCxxMutableInputIterator protocol
This is an inheritor of the existing `UnsafeCxxInputIterator` protocol, with the only difference being the ability to mutate `var pointee` via a non-const `operator*()`.

This is needed to support mutable subscripts for `std::map` via `CxxDictionary`.

rdar://105399019
2023-07-26 18:20:49 +01:00
Alex Lorenz
d7b62b3c40 [cxx-interop] add 'upcoming-swift' compat version
This version will be used to gate new source breaking changes for C++ interoperability
2023-07-25 16:19:58 -07:00
Egor Zhdan
be34674915 Merge pull request #67375 from apple/egorzhdan/mutable-var-pointee
[cxx-interop] Import mutating dereference operators
2023-07-25 16:20:19 +01:00
Egor Zhdan
43e6e97c1a Merge pull request #67482 from apple/egorzhdan/vector-of-string
[cxx-interop] Import iterator types that are not typedef-ed
2023-07-24 17:29:26 +01:00
Egor Zhdan
af014c02b3 [cxx-interop] Import iterator types that are not typedef-ed
This prevented `std::vector<std::string>` from being auto-conformed to `CxxRandomAccessCollection`.

If an iterator type is templated, and does not have an explicit instantiation via a typedef or a using-decl, its specialization will not have an owning Clang module. Make sure we treat it as a part of the Clang module that owns the template decl.

rdar://112762768 / resolves https://github.com/apple/swift/issues/67410
2023-07-24 11:25:15 +01:00
Alex Lorenz
15a0345857 Merge pull request #67268 from hyp/eng/windows-method-oh-no
[cxx-interop] windows methods fixes
2023-07-21 06:57:01 -07:00
Alex Lorenz
96806f4d44 [cxx-interop] Windows: unify address-only logic and mark non-trivial loadable C++ types as unavailable
Windows logic for determining address-only type layout for a C++ type is now unified with other platforms.
However, this means that on Windows, a C++ type with a custom destructor, but a default copy constructor
is now loadable, even though it's non-trivial. Since Swift does not support such type operations at the
moment (it can't be yet destroyed), mark such type as unavailable in Swift instead, when building for
the Windows target.

This fixes the Windows miscompilation related to such types when they were passed indirectly to C++
functions even though they're actually passed directly.
2023-07-20 14:58:02 -07:00
Egor Zhdan
64401aeeea [ClangImporter] NFC: Remove unused definitions 2023-07-20 19:37:58 +01:00
Egor Zhdan
8832d27e98 [cxx-interop] Import mutating dereference operators
C++ `T& operator*()` is mapped to a Swift computed property `var pointee: T`.

Previously `var pointee` only had a getter, after this change it will also have a setter if the C++ type declares an overload of `operator*` that returns a mutable reference.

rdar://112471779
2023-07-19 16:12:55 +01:00
zoecarver
806956d80f [cxx-interop] always mark begin and end methods as unsafe (to help automatic rac conformance); update tests accordingly. 2023-07-18 17:42:56 -07:00
zoecarver
fd7b39e736 [cxx-interop] Mark *all* iterators as unsafe; update tests accordingly; fix a few remaining tests that use raw pointers. 2023-07-18 17:42:56 -07:00
zoecarver
782641af68 [cxx-interop] ExpirementalFeature -> LanguageFeature. 2023-07-18 17:42:35 -07:00
zoecarver
8677fab6a8 [cxx-interop] Add legacy implementation of is-safe-use-of-cxx-method. 2023-07-18 17:42:35 -07:00
zoecarver
7db669ce5b [cxx-interop] Fix a bug with explicit, nested, self-contained types (and add a test). 2023-07-18 17:42:05 -07:00
zoecarver
474a7cd834 [cxx-interop] Only mark projections of self-contained types as unsafe.
Projections of trivial types and view types aren't unsafe. This matches what was described in the vision document.
2023-07-18 17:42:05 -07:00
Egor Zhdan
bc56ddc2bb [cxx-interop] Handle inherited templated operators during auto-conformance
This fixes the automatic `std::unordered_map` conformance to CxxDictionary on Linux. Previously `std::unordered_map::const_iterator` was not auto-conformed to UnsafeCxxInputIterator because its `operator==` is defined on a templated base class of `const_iterator`.

rdar://105220600
2023-07-17 21:10:32 +01:00
Egor Zhdan
9edb752ac5 Merge pull request #67301 from apple/egorzhdan/foundation-linker-errors
[cxx-interop] Import CF_OPTIONS types such as `Foundation.NSTextCheckingType` correctly
2023-07-14 20:32:16 +01:00