2
2
// RUN: -disable-experimental-parser-round-trip \
3
3
// RUN: -enable-experimental-feature NonescapableTypes \
4
4
// RUN: -enable-experimental-feature NoncopyableGenerics \
5
- // RUN: -enable-experimental-lifetime-dependence-inference \
6
5
// RUN: -disable-lifetime-dependence-diagnostics
7
6
8
7
// REQUIRES: asserts
@@ -64,7 +63,7 @@ public struct BufferView<Element> : ~Escapable {
64
63
private var baseAddress : UnsafeRawPointer { start. _rawValue }
65
64
// TODO: Enable diagnostics once this initializer's store to temporary is handled
66
65
// CHECK: sil @$s31lifetime_dependence_scope_fixup10BufferViewV11baseAddress5count9dependsOnACyxGSVYls_Siqd__htclufC : $@convention(method) <Element><Owner> (UnsafeRawPointer, Int, @in_guaranteed Owner, @thin BufferView<Element>.Type) -> _scope(1) @owned BufferView<Element> {
67
- public init < Owner> (
66
+ public init < Owner: ~ Copyable & ~ Escapable > (
68
67
baseAddress: UnsafeRawPointer ,
69
68
count: Int ,
70
69
dependsOn owner: borrowing Owner
@@ -74,7 +73,7 @@ public struct BufferView<Element> : ~Escapable {
74
73
)
75
74
}
76
75
// CHECK: sil hidden @$s31lifetime_dependence_scope_fixup10BufferViewV5start5count9dependsOnACyxGAA0eF5IndexVyxGYls_Siqd__htclufC : $@convention(method) <Element><Owner> (BufferViewIndex<Element>, Int, @in_guaranteed Owner, @thin BufferView<Element>.Type) -> _scope(1) @owned BufferView<Element> {
77
- init < Owner> (
76
+ init < Owner: ~ Copyable & ~ Escapable > (
78
77
start index: BufferViewIndex < Element > ,
79
78
count: Int ,
80
79
dependsOn owner: borrowing Owner
@@ -110,6 +109,11 @@ extension BufferView {
110
109
111
110
public var startIndex : Index { start }
112
111
public var endIndex : Index { start. advanced ( by: count) }
112
+
113
+ @inlinable @inline ( __always)
114
+ public func distance( from start: Index , to end: Index ) -> Int {
115
+ start. distance ( to: end)
116
+ }
113
117
114
118
public subscript( position: Index ) -> Element {
115
119
get {
@@ -131,6 +135,23 @@ extension BufferView {
131
135
)
132
136
}
133
137
}
138
+
139
+ borrowing public func prefix( upTo index: BufferViewIndex < Element > ) -> _borrow( self ) Self {
140
+ index == startIndex
141
+ ? Self ( start: start, count: 0 , dependsOn: copy self)
142
+ : prefix ( through: index. advanced ( by: - 1 ) )
143
+ }
144
+
145
+ borrowing public func prefix( through index: Index ) -> _borrow( self ) Self {
146
+ let nc = distance ( from: startIndex, to: index) &+ 1
147
+ return Self ( start: start, count: nc, dependsOn: copy self)
148
+ }
149
+
150
+ consuming public func prefix( _ maxLength: Int ) -> _consume( self ) Self {
151
+ precondition ( maxLength >= 0 , " Can't have a prefix of negative length. " )
152
+ let nc = maxLength < count ? maxLength : count
153
+ return Self ( start: start, count: nc, dependsOn: self )
154
+ }
134
155
}
135
156
136
157
extension Array {
0 commit comments