-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] Round out ~Copyable generalizations in stdlib primitives #73045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[stdlib] Round out ~Copyable generalizations in stdlib primitives #73045
Conversation
There'll be some api-digester failures (at least); I'll fix those later. |
- `Optional.map`, `.flatMap`: Allow noncopyable results. Implement typed throws. - `Result.map`, `.flatMap`: Allow noncopyable types for the new success. - `Result.flatMapError`: Generalize for noncopyable Success. - `Unsafe[Mutable][Buffer]Pointer.withMemoryRebound`: Alllow typed throws. - `Unsafe[Mutable]BufferPointer: Generalize CustomDebugStringConvertible conformance for noncopyable `Element`s. - `OpaquePointer.init(_: UnsafeMutablePointer)`, `.init(_: UnsafeMutablePointer?)`: Allow noncopyable pointee types. - `ManagedBuffer.withUnsafeMutablePointerToHeader`, `.withUnsafeMutablePointerToElements`, `.withUnsafeMutablePointers`: Generalize for typed throws and noncopyable return types. Avoid `@_preInverseGenerics`. - `ManagedBufferPointer`: Ditto. - `withExtendedLifetime`: Use typed throws. Stop using `@_preInverseGenerics`. rdar://117753275
We can’t do typed throws here yet. (They involve implicit stack allocations that interfere with the explicit stack allocation builtins.)
2a1417a
to
fab25dc
Compare
@swift-ci test |
@swift-ci test source compatibility |
Source compat failures: GRDB:
The obvious workaround is to revert to untyped rethrows for AsyncNinja:
This is the same issue as triggered the original revert in #72477. |
swiftlang#73045 has uncovered a compiler crash with existing code of this form: try withExtendedLifetime(statement) { // 💥silgen crash do { try dbPool.close() XCTFail("Expected Error") } catch DatabaseError.SQLITE_BUSY { } } This patterns can happen with any of the newly typed throwing entry points, but the source compat suite only seems to have caught this with `withExtendedLifetime`; let’s see if we can get away with only rolling back this one.
…ound a shadowing issue The new ~Copyable generalizations have changed the function signature enough that alternative definitions of `map`/`flatMap` in existing code that used to be considered to shadow the originals no longer do so. This leads to use sites becoming ambiguous — a source break. While we consider approaches to resolve this on the compiler side, let’s try slapping a `@_disfavoredOverload` on these and see if that helps.
@swift-ci test |
@swift-ci test source compatibility |
@swift-ci build toolchain macOS platform |
Hmm, this source compat issue in swift-distributed-actors is a preexisting regression on main. (It actually showed up in the earlier run, too.) It is unrelated to this PR; I'm ignoring it.
|
macOS failure is in the stability-stdlib-source check. I'm very tempted to delete that test entirely, as it keeps getting in the way and it has so limited understanding of recent Swift changes that it no longer provides much value. But for now, I'll add another patch to its exception list. |
@swift-ci test |
swiftlang#73045 has uncovered a compiler crash with existing code of this form: try withExtendedLifetime(statement) { // 💥silgen crash do { try dbPool.close() XCTFail("Expected Error") } catch DatabaseError.SQLITE_BUSY { } } This patterns can happen with any of the newly typed throwing entry points, but the source compat suite only seems to have caught this with `withExtendedLifetime`; let’s see if we can get away with only rolling back this one. (cherry picked from commit 153c001)
@swift-ci please test Windows platform |
Joe's fix for the typed throw issue is up at #73092. I'll submit a separate PR to re-generalize |
This is a followup to #71688, completing the generalization of pointer types,
Optional
,Result
andManagedBuffer
, as well as the temporary allocation facility.Optional.map
,.flatMap
: Allow noncopyable results. Implement typed throws.Result.map
,.flatMap
: Allow noncopyable types for the new success. (This reapplies the changes that got temporarily reverted in [stdlib] Undo the generalization ofResult.map
&.flatMap
for now #72477.)Result.flatMapError
: Generalize for noncopyable Success.Unsafe[Mutable]BufferPointer: Generalize CustomDebugStringConvertible conformance for noncopyable
Element`s.Unsafe[Mutable][Buffer]Pointer.withMemoryRebound
: Convert to typed throws.OpaquePointer.init(_: UnsafeMutablePointer)
,.init(_: UnsafeMutablePointer?)
: Allow noncopyable pointee types.ManagedBuffer.withUnsafeMutablePointerToHeader
,.withUnsafeMutablePointerToElements
,.withUnsafeMutablePointers
: Generalize for noncopyable return types and typed throw . Avoid@_preInverseGenerics
.ManagedBufferPointer
: Ditto.withUnsafeTemporaryAllocation
: Generalize for noncopyable result types. (Not typed throws though -- they involve stack allocations that don't mix with explicitwithExtendedLifetime
:Use typed throws. Stop using@_preInverseGenerics
.rdar://117753275