Skip to content

Commit 324c48a

Browse files
authored
Merge pull request #617 from lorentey/rigidly-enforced-lifetime-requirements
Fix lifetime requirements rigidly enforced in the latest nightlies
2 parents 080a579 + 2417a00 commit 324c48a

6 files changed

Lines changed: 26 additions & 17 deletions

File tree

Sources/BasicContainers/RigidDictionary/RigidDictionary+Indices.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ where Key: ~Copyable, Value: ~Copyable
7070
@inlinable
7171
public var underestimatedCount_: Int { self._base.value.count }
7272

73-
@_lifetime(copy self)
73+
@_lifetime(borrow self) // FIXME: Should be @_lifetime(copy self)
7474
public func makeBorrowingIterator_() -> BorrowingIterator_ {
7575
let bit = self._base.value.makeBucketIterator()
7676
// FIXME: This override really should not be necessary. Check if the real `struct Borrow` fixes it.

Sources/BasicContainers/RigidSet/RigidSet+BorrowingSequence.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ extension RigidSet: BorrowingSequence_ where Element: ~Copyable {
4343
~Copyable,
4444
~Escapable
4545
{
46+
public typealias Element_ = Element
47+
4648
@_alwaysEmitIntoClient
4749
internal var _baseAddress: UnsafePointer<Element_>?
4850

@@ -68,7 +70,7 @@ extension RigidSet: BorrowingSequence_ where Element: ~Copyable {
6870
}
6971

7072
@_alwaysEmitIntoClient
71-
@_lifetime(copy self)
73+
@_lifetime(&self) // FIXME: This should be `@_lifetime(copy self)`
7274
public mutating func nextSpan_(maximumCount: Int) -> Span<Element_> {
7375
precondition(maximumCount > 0, "maximumCount must be positive")
7476
guard

Sources/ContainersPreview/Protocols/Container/Container+Filter.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ where Base.Element: ~Copyable
8787

8888
@available(SwiftStdlib 5.0, *)
8989
extension ContainerFilter: BorrowingIteratorProtocol_ where Element: ~Copyable {
90-
@_lifetime(copy self)
90+
public typealias Element_ = Base.Element
91+
92+
@_lifetime(&self) // FIXME: This should be `@_lifetime(copy self)`
9193
public mutating func nextSpan_(maximumCount: Int) -> Span<Element> {
9294
precondition(maximumCount > 0)
9395
while true {

Sources/ContainersPreview/Protocols/Container/ContainerIterator.swift

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,24 @@ where
5252
{
5353
public typealias Element_ = Base.Element
5454

55+
#if true
5556
@_unsafeNonescapableResult // FIXME: we cannot convert from a borrow to an inout dependence?!
5657
@_lifetime(&self)
5758
public mutating func nextSpan_(maximumCount: Int) -> Span<Base.Element> {
5859
_base.value.nextSpan(after: &self._position, maximumCount: maximumCount)
5960
}
60-
61-
// @_lifetime(copy self)
62-
// public mutating func nextSpan2(maximumCount: Int) -> Span<Base.Element> {
63-
// var i = self._position
64-
// let span = _base.value.nextSpan(
65-
// after: &i,
66-
// maximumCount: maximumCount)
67-
// _ = consume span
68-
// let result = _overrideLifetime(span, copying: self)
69-
// self._position = i
70-
// return .init()
71-
// }
61+
#else
62+
@_lifetime(copy self)
63+
public mutating func nextSpan(maximumCount: Int) -> Span<Base.Element> {
64+
var i = self._position
65+
let span = _base.value.nextSpan(
66+
after: &i,
67+
maximumCount: maximumCount)
68+
self._position = i
69+
let result = _overrideLifetime(span, copying: self)
70+
return result
71+
}
72+
#endif
7273

7374
@_lifetime(self: copy self)
7475
public mutating func skip_(by maximumOffset: Int) -> Int {

Sources/DequeModule/RigidDeque/RigidDeque+Container.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ extension RigidDeque where Element: ~Copyable {
2424
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
2525
@frozen
2626
public struct BorrowingIterator: ~Escapable, BorrowingIteratorProtocol_ {
27+
public typealias Element_ = Element
28+
2729
@usableFromInline
2830
internal var _currentSegment: Span<Element>
2931

@@ -44,7 +46,7 @@ extension RigidDeque where Element: ~Copyable {
4446
}
4547

4648
@_alwaysEmitIntoClient
47-
@_lifetime(copy self)
49+
@_lifetime(&self) // FIXME: This should be `@_lifetime(copy self)`
4850
@_lifetime(self: copy self)
4951
public mutating func nextSpan_(maximumCount: Int) -> Span<Element> {
5052
let result = _currentSegment._trim(first: maximumCount)

Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ package struct _StaccatoParameters {
7777

7878
@available(SwiftStdlib 5.0, *)
7979
public struct _StaccatoBorrowingIterator<Element: ~Copyable>: BorrowingIteratorProtocol_, ~Escapable {
80+
public typealias Element_ = Element
81+
8082
internal let _contents: Span<Element>
8183
internal let _params: _StaccatoParameters
8284
internal var _offset: Int
@@ -88,7 +90,7 @@ public struct _StaccatoBorrowingIterator<Element: ~Copyable>: BorrowingIteratorP
8890
self._offset = 0
8991
}
9092

91-
@_lifetime(copy self)
93+
@_lifetime(&self) // FIXME: Should be `@_lifetime(copy self)`
9294
public mutating func nextSpan_(maximumCount: Int) -> Span<Element> {
9395
let endOffset = _params.endOffset(fromOffset: _offset, maximumCount: maximumCount)
9496
let startOffset = _offset

0 commit comments

Comments
 (0)