Commit Graph

84 Commits

Author SHA1 Message Date
Egor Zhdan
c06951e3af Merge pull request #74146 from swiftlang/egorzhdan/std-optional-init-value
[cxx-interop] Instantiate `std::optional` value constructors
2025-07-04 16:33:28 +01:00
Egor Zhdan
dcc3842535 [cxx-interop] Instantiate std::optional value constructors
This improves support for initializing instances of `std::optional` from Swift. Previously only a null optional could be initialized directly from Swift. Now instantiations of `std::optional` will get a Swift initializer that takes the wrapped value as a parameter.

rdar://118026392
2025-07-03 14:00:27 +01:00
Michael Spencer
75ac27dc3d [ClangImporter] Fix dangling reference.
LookupOverloadedBinOp stores `Args` for later use, so store the
backing array on the stack instead of using a temporary.

This fixes a crash that appeared under some build configurations.

Related to rdar://154291418
2025-07-01 17:49:14 -07:00
John Hui
50f5221962 [NFC] promote getOperatorName() to a non-static function (#80466) 2025-04-03 10:42:37 -04:00
Anthony Latsis
631a04e56c Merge pull request #80159 from AnthonyLatsis/danaus-plexippus-5
Sema: Extend adoption mode for `AsyncCallerExecution` to storage declarations
2025-03-26 04:40:58 +00:00
Gabor Horvath
3d6c714cd6 [cxx-interop] Add span property to std::vector
rdar://146944876
2025-03-20 16:15:06 +00:00
Anthony Latsis
182bfc6c79 [NFC] ClangImporter: Remove some redundant hasParameterList calls 2025-03-19 18:49:15 +00:00
Allan Shortlidge
70a2363b97 AST: Introduce new conveniences for synthesizing AvailabilityAttrs.
This makes intent clearer at the call site and removes a lot of explicit uses
of PlatformAgnosticAvailabilityKind, which is going away.
2025-01-08 19:59:47 -08:00
Crazy凡
aeaa8ecadd [cxx-interop] Allow removing elements from std::set. 2024-11-13 23:16:45 +08:00
swift-ci
f70c740512 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-17 04:56:35 -07:00
Egor Zhdan
34f6cd3f1a [cxx-interop] Conform to UnsafeCxxContiguousIterator based on iterator_concept nested type
3a200dee has a logic bug where we tried to conform C++ iterator types to `UnsafeCxxContiguousIterator` protocol based on their nested type called `iterator_category`. The C++20 standard says we should rely on `iterator_concept` instead.

https://en.cppreference.com/w/cpp/iterator/iterator_tags#Iterator_concept

Despite what the name suggests, we are not actually using C++ concepts in this change.

rdar://137877849
2024-10-16 19:47:46 +01:00
swift-ci
4ac1f2887f Merge remote-tracking branch 'origin/main' into rebranch 2024-10-15 10:16:56 -07:00
Egor Zhdan
3a200deee9 [cxx-interop] Add UnsafeCxxContiguousIterator & UnsafeCxxMutableContiguousIterator protocols
This adds a pair of Swift protocols that represents C++ iterator types conforming to `std::contiguous_iterator_tag` requirements. These are random access iterators that guarantee that the values are stored in consequent memory addresses.

This will be used to optimize usage of C++ containers such as `std::vector` from Swift, for instance, by providing an overload of `withContiguousStorageIfAvailable` for contiguous containers.

rdar://137877849
2024-10-15 14:30:09 +01:00
swift-ci
cd956f3b28 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-03 04:53:49 -07:00
Egor Zhdan
f37f42fc7e [cxx-interop] Conform std::set to ExpressibleByArrayLiteral
Swift's own `Set` conforms to `ExpressibleByArrayLiteral`. This change conforms instantiations of C++ `std::set` to `ExpressibleByArrayLiteral` as well.

This makes it possible to pass an array literal as an argument to a function that takes a `std::set` as parameter.

rdar://137126325
2024-10-02 19:27:51 +01:00
swift-ci
e984fa4cbf Merge remote-tracking branch 'origin/main' into rebranch 2024-09-02 03:54:41 -07:00
Egor Zhdan
0ab681514b [cxx-interop] Add CxxMutableRandomAccessCollection protocol
This conforms mutable C++ container types, such as `std::vector`, to `MutableCollection` via a new overlay protocol `CxxMutableRandomAccessCollection`.

rdar://134531554
2024-08-28 12:43:42 +01:00
Ben Barham
467e528200 Merge remote-tracking branch 'origin/main' into manual-rebranch-merge
Conflicts:
  - `lib/Serialization/ModuleFormat.h` bumped version to account for
    differences between main and rebranch.
2024-08-09 15:22:39 -07:00
Slava Pestov
b41f32dae6 ClangImporter: Nuke isConcreteAndValid() 2024-08-08 23:35:58 -04:00
Slava Pestov
375363a473 AST: Move global conformance lookup entry points to ConformanceLookup.h 2024-08-08 23:35:58 -04:00
swift-ci
e72f3e3e6c Merge remote-tracking branch 'origin/main' into rebranch 2024-07-25 06:55:45 -07:00
smonteiro2
0ef50125a3 [cxx-interop] Constructor Span(baseAddress, count) is deprecated
This constructor is unsafe, as it allows creating a `std::span` with a count higher than the size of the sequence of objects it refers to. Therefore, when hardening is enabled, an out-of-bounds access won't trap.
We make it deprecated to discourage its use.
2024-07-25 11:48:50 +01:00
swift-ci
9448b5ad08 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-19 06:14:52 -07:00
smonteiro2
684e9ebf0c [cxx-interop] Implements CxxMutableSpan, created from an UnsafeMutableBufferPointer
* Added tests for generic functions
* Add some tests for mutable spans
* Initialize ConstSpan from UnsafeMutableBufferPointer
* Change hardening flag
2024-07-19 10:38:52 +01:00
swift-ci
b7921a8232 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-06 14:34:09 -07:00
Slava Pestov
86d567f95a AST: ModuleDecl::lookupConformance() is a static method 2024-07-06 12:05:47 -04:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 2024-07-06 12:05:46 -04:00
swift-ci
287d711d03 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-01 11:14:00 -07:00
susmonteiro
e86099c26d [cxx-interop] Implements constructor for std::span from UnsafeBufferPointer
Tests: init span from UnsafeBufferPointer, for loop, map, filter, init Array from span, span of strings
2024-07-01 16:07:28 +01:00
swift-ci
ee72f594fb Merge remote-tracking branch 'origin/main' into rebranch 2024-06-25 08:55:18 -07:00
Alex Lorenz
0c7621d282 Merge pull request #74541 from hyp/eng/lookup-imported-member-operator-cxx
[cxx-interop][serialization] resolve x-refs to instantiated/synthesiz…
2024-06-25 08:45:02 -07:00
swift-ci
8179c1c4a2 Merge remote-tracking branch 'origin/main' into rebranch 2024-06-21 12:55:46 -07:00
Egor Zhdan
d07e8ce424 Merge pull request #74619 from swiftlang/egorzhdan/std-function-inout
[cxx-interop] Instantiate the `std::function` constructor with a const pointer argument
2024-06-21 20:39:25 +01:00
Egor Zhdan
d38067c2ba [cxx-interop] Instantiate the std::function constructor with a const pointer argument
We were trying to instantiate a constructor for `std::function` from a C function pointer with a non-const function pointer type. That worked well on most platforms, where `std::function` defines a single constructor for const and non-const function pointers, but failed on UBI 9.

This fixes a test (`Interop/Cxx/stdlib/use-std-function.swift`) on UBI Linux.

rdar://118026392
2024-06-21 14:22:11 +01:00
Xi Ge
736ccef626 Merge remote-tracking branch 'apple/main' into rebranch 2024-06-20 15:16:55 -07:00
Alex Lorenz
983fb8025a [cxx-interop][serialization] resolve x-refs to instantiated/synthesized C++ iterator conformance operators
These x-refs might not be resolvable using regular lookup from the 'std' module as they could be instantiated/synthesized
by the clang importer. Augment the lookup logic in that case to try clang importer lookup logic that is used during
the conformance to the C++ iterator protocol.
2024-06-20 14:51:34 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
swift-ci
0bbe4a8055 Merge remote-tracking branch 'origin/main' into rebranch 2024-06-17 10:14:25 -07:00
Egor Zhdan
3243228897 [cxx-interop] Allow initializing std::function from Swift closures
This adds a Swift initializer to instantiations of `std::function` that accepts a Swift closure with `@convention(c)`.

rdar://103979602
2024-06-14 19:05:45 +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
Ben Barham
0c0c4ea7c3 [ClangImporter] Use new CXXThisExpr::Create function
The constructor takes a new arg which `Create` now handles. Use it
instead.
2024-04-08 08:58:58 -07:00
Egor Zhdan
3ca0d56675 [cxx-interop] Discard duplicating IteratorTy::iterator_category decls
libc++ recently split the `std` module into many top-level modules: 571178a21a

This broke the logic that conforms C++ iterator types to `UnsafeCxxInputIterator`/`UnsafeCxxRandomAccessIterator`. To determine if a C++ type is an iterator type, we look for its inner type called `iterator_category`. After module std was split, Clang instantiates `std::string::const_iterator::iterator_category` twice and doing a Clang lookup within the `const_iterator` type returns two identical `TypedefDecl`s. Clang itself has logic to merge them, but Swift doesn't.

rdar://119270491
2023-12-14 17:37:01 +00: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
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
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
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
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
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