Commit Graph

217 Commits

Author SHA1 Message Date
Egor Zhdan
242fe5cfac Merge pull request #77677 from swiftlang/egorzhdan/cxxstdlib-builtin-float
[cxx-interop] Declare CxxStdlib dependency on _Builtin_float
2024-11-19 12:57:53 +00:00
Allan Shortlidge
c9c36732be stdlib: Enable upcoming MemberImportVisibility feature.
It was already supposed to be enabled, but I forgot to update the CMake when I
renamed the feature from ExtensionImportVisibility to MemberImportVisibility.

However, leave it disabled on the CxxStdlib module since the C++ standard
library's modularization varies a lot by platform, making it difficult to add
the right conditional imports.
2024-11-18 10:27:14 -08:00
Egor Zhdan
72425fa750 [cxx-interop] Declare CxxStdlib dependency on _Builtin_float
This fixes incremental builds of the overlay.

The CxxStdlib overlay re-exports the entire C++ standard library, which has headers that transitively include Clang builtin headers, bringing in the _Builtin_float module.

rdar://140036608
2024-11-18 13:01:31 +00:00
Egor Zhdan
f88b29bfdc Merge pull request #77445 from CrazyFanFan/feature_cxxset_remove
[cxx-interop] Allow removing elements from `std::set`.
2024-11-14 13:09:21 +00:00
Crazy凡
aeaa8ecadd [cxx-interop] Allow removing elements from std::set. 2024-11-13 23:16:45 +08:00
Egor Zhdan
703e479135 [cxx-interop] Make Cxx and CxxStdlib libraries resilient
This enables library evolution for the two libraries that form the Swift overlay for the C++ standard library.

rdar://129169673
2024-11-12 17:22:03 +00:00
Egor Zhdan
cb486c6599 [cxx-interop] Allow creating a String from std::string_view
This adds overlay support for initializing a Swift String from C++ `std::string_view`, `std::u16string_view`, `std::u32string_view`.

rdar://138417835
2024-10-24 13:11:09 +01: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
Egor Zhdan
535a9412df [cxx-interop] Conform std::map to ExpressibleByDictionaryLiteral
This adds an automatic conformance for `std::map` and `std::unordered_map` to Swift's `ExpressibleByDictionaryLiteral` protocol.

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

rdar://137126474
2024-10-03 13:33:40 +01: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
Egor Zhdan
0a14f04fe5 Merge pull request #76260 from swiftlang/egorzhdan/cxxshim-maccatalyst
[cxx-interop] Install CxxShim library for macCatalyst
2024-09-06 13:09:21 +01:00
Egor Zhdan
0d19a7763c [cxx-interop] Install CxxShim library for macCatalyst
This is a follow-up after the change that enabled Cxx and CxxStdlib overlays on macCatalyst: https://github.com/swiftlang/swift/pull/74994.

The compiler relies on the presence of these shim libraries in the toolchain.

rdar://135275773
2024-09-04 19:09:46 +01:00
Shreyans Pathak
49d9067d3e feat: add comparable conformance for C++ strings 2024-09-03 13:47:27 -04:00
Egor Zhdan
39b8b3c67e Merge pull request #76106 from swiftlang/egorzhdan/cxx-mutable-rac
[cxx-interop] Add `CxxMutableRandomAccessCollection` protocol
2024-09-02 11:35:43 +01: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
Alex Lorenz
c8fa166e58 [cxx][windows] fix the CxxStdlib build for recent MSVC versions after recent regression
The build regressed after cbaef38968 as newer versions of MSVC that aren't used in the OSS CI yet fail to build CxxStdlib now
2024-08-19 10:55:22 -07:00
Egor Zhdan
28078d65be Merge pull request #75608 from CrazyFanFan/crazy_fan/75110
[c++-interop] Improve performance of creating a C++ `std::string` from a contiguous UTF-8 `Swift.String`
2024-08-19 15:40:43 +01:00
Egor Zhdan
8e2f0e2d50 Merge pull request #75877 from swiftlang/egorzhdan/std-map-init
[cxx-interop] Allow initializing `std::map` from Swift Dictionary
2024-08-14 21:49:56 +01:00
Egor Zhdan
9fe13ece49 [cxx-interop] Allow initializing std::map from Swift Dictionary
This adds initializers for `std::map` and `std::unordered_map` that take a Swift dictionary as a single parameter.

rdar://133691563
2024-08-14 13:32:30 +01:00
Crazy凡
cbaef38968 [c++-interop] Improve performance of creating a C++ std::string from a contiguous UTF-8 Swift.String 2024-08-13 13:58:56 +08:00
Andrew Kaster
65cd7e4ea3 fix centos7 build (hopefully) 2024-08-05 09:06:39 -06:00
Andrew Kaster
fd41d2601f [cxx-interop] Disable c++ execution header with libstdcxx versions >= 11
Workaround for https://github.com/swiftlang/swift/issues/75661
2024-08-02 17:04:20 -06: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
smonteiro2
15e1749594 Add precondition to prevent access out of bounds
The subscript function from CxxRandomAccessCollection did not perform any bounds-checks.
This means that C++ containers that don't provide the operator[] (or C++ containers used in generic contexts) didn't have bounds-checks.

Fixes rdar://126570011
2024-07-18 15:30:11 +01:00
Egor Zhdan
b0a3bb10f0 [cxx-interop] Build Cxx and CxxStdlib modules for macCatalyst
This enables building the C++ stdlib overlays (`Cxx.swiftmodule` and `CxxStdlib.swiftmodule`) for the Mac Catalyst target.

rdar://126938813
2024-07-05 19:35:29 +01: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
Alex Lorenz
273edcf2a2 build CxxStdlib for Android too 2024-06-04 15:46:39 -07:00
Alastair Houghton
0fa5e65bb2 [Stdlib][Build] Fix the standard library build for fully static Linux.
Mostly this just means adding `Musl` as a module dependency of various
things and making sure that we build things for `swift_static` even
if `SWIFT_BUILD_STATIC_STDLIB` isn't enabled.

There's also a slight difference in the declaration of `memcmp()`;
musl's declaration is more like the one we have on Darwin.

rdar://123508245
2024-05-07 16:56:20 +01:00
Egor Zhdan
4513ca2447 [cxx-interop] Faster std::string initialization from String
Instead of appending characters one-by-one, which resizes the resulting string multiple times, let's reserve the required number of bytes beforehand.

rdar://127423949
2024-05-02 14:07:07 +01:00
Artem Chikin
1f14158a1d Introduce VisionOS Platform
This change introduces a new compilation target platform to the Swift compiler - visionOS.

- Changes to the compiler build infrastrucuture to support building compiler-adjacent artifacts and test suites for the new target.
- Addition of the new platform kind definition.
- Support for the new platform in language constructs such as compile-time availability annotations or runtime OS version queries.
- Utilities to read out Darwin platform SDK info containing platform mapping data.
- Utilities to support re-mapping availability annotations from iOS to visionOS (e.g. 'updateIntroducedPlatformForFallback', 'updateDeprecatedPlatformForFallback', 'updateObsoletedPlatformForFallback').
- Additional tests exercising platform-specific availability handling and availability re-mapping fallback code-path.
- Changes to existing test suite to accomodate the new platform.
2024-04-10 09:38:02 -07:00
Karoy Lorentey
621bd47c86 [cxx-interop] Back out ~Copyable changes for now
Keep the `@_borrowed` attributes on UnsafeCxx[Mutable]Iterator — it appears to be required with the new pointer types. (That’ll need some separate investigation.)

rdar://125146418
2024-03-22 17:58:56 -07:00
Guillaume Lessard
3b09ecec74 [gardening] update copyright notice
[gardening] update copyright notice

[gardening] update copyright notice

[gardening] update copyright notice

[gardening] update copyright notice
2024-03-18 11:08:32 -07:00
Karoy Lorentey
d0b39ac8db [stdlib] Unsafe[Mutable]Pointer: Add support for non-copyable Pointee types
[stdlib] Pull back @_aeic on pointer → integer conversions

[stdlib] UnsafeMutablePointer.allocate: Fix thinko

[stdlib] Disable support for noncopyable pointees on some pointer operations

We have to temporarily pull back support for noncopyable pointees for UnsafeMutablePointer.initialize(to:), .moveInitialize, .moveUpdate, as the builtins they’re calling are no longer accepting such types.

These will return following a builtin audit.

[stdlib] Remove workarounds for certain builtins not supporting noncopyable use

https://github.com/apple/swift/pull/71733 fixed this!

[stdlib] Update FIXME

[stdlib] UnsafePointer: Update Swift version numbers

[stdlib] UnsafePointer: Actually hide legacy ABI

[stdlib] Remove workaround for U[M]BP.withMemoryRebound
2024-03-18 11:03:49 -07:00
Egor Zhdan
53fb6531f2 [cxx-interop] Add conversions between std::chrono::duration and Swift.Duration
rdar://123696734
2024-03-01 13:15:05 +00:00
Egor Zhdan
c39c8da4db [cxx-interop] Use APINotes to apply import_owned attr to std::string and std::vector
This removes a special case in the compiler for these types, and applies the `import_owned` attribute to all instantiations of `vector` and `basic_string` via API Notes.
2023-12-04 19:54:17 +00:00
Egor Zhdan
e144f607d7 [cxx-interop] Migrate to overlay the new compiler flag
`-enable-experimental-cxx-interop` is deprecated, the new flag for enabling C++ interop is `-cxx-interoperability-mode=enabled`.

NFC intended.
2023-11-28 20:30:12 +00:00
Egor Zhdan
00cdb66d01 [cxx-interop] Lower macOS deployment target version for the Cxx module
The Cxx module does not rely on any modern OS features. It can be deployed to older macOS versions.

rdar://117699474
2023-10-30 19:22:02 +00:00
Ian Anderson
4dbc58723a [CMake] [Darwin] Don't add the Darwin overlay as a dependency if the overlays aren't being built
Allow for the overlays to not be built in Darwin by respecting SWIFT_BUILD_SDK_OVERLAY.
2023-10-17 11:03:57 -07:00
Crazy凡
02a9259dda [cxx-interop] Provide similar support for std::u32string as std::string and std::u16string. 2023-10-10 16:01:15 +08:00
mohanadkandil
d58943a508 Add filter method for ordered and unordered map (#67501)
Co-authored-by: mkandil <mkandil@synapse-analytics.io>
2023-10-05 19:13:34 +01: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
Rintaro Ishizaki
064cb34015 [CMake] Use add_custom_command_target for copying std.apinotes
`COMMAND` for `add_custom_target` are "always considered out of date"
and executed everytime. Because of that, targets depends on that were
alway marked "dirty". Use `add_custom_command_target` instead.
2023-09-14 16:52:43 -07:00
Egor Zhdan
b40b1db7ff Merge pull request #68118 from apple/egorzhdan/cxxstdlib-apinotes
[cxx-interop] Introduce APINotes file for C++ stdlib
2023-08-30 16:34:45 +01: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
Saleem Abdulrasool
ba9174df18 Cxx: build Cxx module statically on all platforms
This adjusts Cxx to be built statically on all platforms including
Windows.  The static library support is sufficient to support this
module linking statically on Windows.
2023-08-28 09:27:34 -07:00
Saleem Abdulrasool
dff40e9399 Cxx: mark as fragile
This library is still fragile as C++ Interop is in preview. Mark it as
fragile to match cxxStdlib.
2023-08-25 11:31:36 -07:00
Egor Zhdan
c167f4045b [cxx-interop] Conform std::optional to ExpressibleByNilLiteral
This will allow passing `nil` as a parameter to a C++ function that takes a `std::optional<T>`.

rdar://114194600
2023-08-21 19:21:40 +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
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
Saleem Abdulrasool
2124c01e74 stdlib: enable CxxStdlib module on Windows
Enable this module on Windows for enabling C++ Interop.
2023-08-04 21:19:35 -07:00