Commit Graph

204 Commits

Author SHA1 Message Date
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
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
dd2648b827 [cxx-interop] Conform Swift pointers to UnsafeCxxMutableInputIterator
This is currently a no-op since we don't auto-conform custom types to any kind of `MutableCollection` protocols: `UnsafeCxxMutableInputIterator` is only used for `std::map` conformance to `CxxDictionary` in the overlay. However, this will be useful in the future if we start conforming mutable C++ containers to certain Swift protocols: that way containers that use raw non-const pointers as iterators would be treated as mutable in Swift.
2023-08-01 15:31:22 +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
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
Evan Wilde
669285fd17 Merge pull request #65534 from stephank/fix/cmake-3.25
build: fix accidental cmake expansions
2023-07-24 09:44:14 -07:00
Egor Zhdan
390beb9315 Merge pull request #67398 from apple/egorzhdan/cxx-pair-mutable
[cxx-interop] Make CxxPair's fields mutable
2023-07-19 18:34:03 +01:00
Alex Lorenz
3748b0ff1c Merge pull request #65129 from hyp/eng/no-evo-cxx
[interop] Prohibit use of C++ APIs in public interfaces that opt-in i…
2023-07-19 08:10:23 -07:00
Egor Zhdan
4ca1eeb141 [cxx-interop] Make CxxPair's fields mutable
This will be needed to support mutable C++ iterators, e.g. `std::map::iterator`.
2023-07-19 16:05:28 +01:00
Stéphan Kochen
7b460ce495 build: fix accidental cmake expansions
As of CMake 3.25, there are now global variables `LINUX=1`, `ANDROID=1`,
etc. These conflict with expressions that used these names as unquoted
strings in positions where CMake accepts 'variable|string', for example:

- `if(sdk STREQUAL LINUX)` would fail, because `LINUX` is now defined and
  expands to 1, where it would previously coerce to a string.

- `if(${sdk} STREQUAL "LINUX")` would fail if `sdk=LINUX`, because the
  left-hand side expands twice.

In this patch, I looked for a number of patterns to fix up, sometimes a
little defensively:

- Quoted right-hand side of `STREQUAL` where I was confident it was
  intended to be a string literal.

- Removed manual variable expansion on left-hand side of `STREQUAL`,
  `MATCHES` and `IN_LIST` where I was confident it was unintended.

Fixes #65028.
2023-07-17 21:50:50 +02:00
Egor Zhdan
7ca1b5c5eb [cxx-interop] NFC: Add doc comments for overlay protocols 2023-07-12 19:10:23 +01:00
Egor Zhdan
12f01ce23a Merge pull request #66855 from apple/egorzhdan/libstdcxx-arch-independent
[cxx-interop] Make libstdc++ header and modulemap arch-independent
2023-06-23 12:10:17 +01:00
Egor Zhdan
3e28a7c525 [cxx-interop] Make libstdc++ header and modulemap arch-independent
This moves `libstdcxx.modulemap` and `libstdcxx.h` from `*.xctoolchain/usr/lib/swift/macosx/arm64e` to `*.xctoolchain/usr/lib/swift/macosx` to simplify distribution.

rdar://110788977
2023-06-22 22:03:57 +01:00