Skip to content

Commit 5ebbd8e

Browse files
authored
Merge pull request swiftlang#8 from lorentey/string_guts
Update some tests; fix some bugs
2 parents d3fcf6b + 7b1b141 commit 5ebbd8e

File tree

10 files changed

+192
-117
lines changed

10 files changed

+192
-117
lines changed

stdlib/public/core/StringGuts.swift

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ extension _StringGuts {
178178
}
179179
}
180180

181-
@_versioned
181+
public // @testable
182182
var byteWidth: Int {
183183
@inline(__always) get { return isSingleByte ? 1 : 2 }
184184
}
@@ -522,8 +522,8 @@ extension _StringGuts {
522522
}
523523

524524
@_inlineable
525-
@_versioned
526-
internal var _unmanagedRawStart: UnsafeRawPointer {
525+
public // @testable
526+
var _unmanagedRawStart: UnsafeRawPointer {
527527
@inline(__always) get {
528528
_sanityCheck(_isUnmanaged)
529529
return UnsafeRawPointer(
@@ -697,8 +697,7 @@ extension _StringGuts {
697697
}
698698

699699
extension _StringGuts {
700-
@_versioned
701-
internal
700+
public // @testable
702701
var _underlyingCocoaString: _CocoaString? {
703702
if _isNative {
704703
return _nativeRawStorage
@@ -974,8 +973,8 @@ extension _StringGuts {
974973
return storage
975974
}
976975

977-
@_versioned
978-
internal
976+
@_inlineable
977+
public // @testable
979978
func _extractSlice(_ range: Range<Int>) -> _StringGuts {
980979
if range == 0..<count { return self }
981980
switch (isASCII, _isUnmanaged) {
@@ -993,7 +992,7 @@ extension _StringGuts {
993992

994993
@_inlineable
995994
@inline(__always)
996-
public // TODO(StringGuts): for testing only
995+
public // @testable
997996
mutating func isUniqueNative() -> Bool {
998997
guard _isNative else { return false }
999998
// Note that the isUnique test must be in a separate statement;
@@ -1104,9 +1103,9 @@ extension _StringGuts {
11041103
@inline(__always) get { return count }
11051104
}
11061105

1107-
@_versioned
11081106
@_inlineable
1109-
internal var count: Int {
1107+
public // @testable
1108+
var count: Int {
11101109
if _slowPath(_isSmallCocoa) {
11111110
return _taggedCocoaCount
11121111
} else if _slowPath(_isNonTaggedCocoa) {
@@ -1126,9 +1125,9 @@ extension _StringGuts {
11261125
}
11271126

11281127
/// Get the UTF-16 code unit stored at the specified position in this string.
1129-
@_versioned
11301128
@_inlineable // FIXME(sil-serialize-all)
1131-
internal subscript(position: Int) -> UTF16.CodeUnit {
1129+
public // @testable
1130+
subscript(position: Int) -> UTF16.CodeUnit {
11321131
if isASCII {
11331132
return _unmanagedASCIIView[position]
11341133
} else if _slowPath(_isOpaque) {
@@ -1212,6 +1211,23 @@ extension _StringGuts {
12121211
}
12131212
}
12141213

1214+
@_inlineable
1215+
public // TODO(StringGuts): for testing only
1216+
mutating func append(_ other: _StringGuts) {
1217+
if _isEmptyLiteral {
1218+
self = other
1219+
return
1220+
}
1221+
if other.isASCII {
1222+
self.append(other._unmanagedASCIIView)
1223+
} else if _slowPath(other._isOpaque) {
1224+
self.append(other._asOpaque())
1225+
} else {
1226+
self.append(other._unmanagedUTF16View)
1227+
}
1228+
_fixLifetime(other)
1229+
}
1230+
12151231
@_inlineable
12161232
public // TODO(StringGuts): for testing only
12171233
mutating func append(_ other: _StringGuts, range: Range<Int>) {
@@ -1273,14 +1289,18 @@ extension _StringGuts {
12731289
var dst = storage.start + bounds.lowerBound
12741290
if deltaCount != 0 && tailCount > 0 {
12751291
// Move tail to make space for new data
1276-
(dst + newCount).moveAssign(from: dst + bounds.count, count: tailCount)
1292+
(dst + newCount).moveInitialize(
1293+
from: dst + bounds.count,
1294+
count: tailCount)
12771295
}
12781296
// Copy new elements in place
12791297
let (_, end) = UnsafeMutableBufferPointer(
12801298
start: dst,
12811299
count: newCount).initialize(from: newElements)
12821300
_precondition(end == newCount, "Collection misreported its count")
12831301
storage.count += deltaCount
1302+
_nativeCount += deltaCount
1303+
_invariantCheck()
12841304
_fixLifetime(self)
12851305
return
12861306
}
@@ -1313,6 +1333,7 @@ extension _StringGuts {
13131333
into: UnsafeMutableBufferPointer(start: dst, count: suffixRange.count))
13141334
_sanityCheck(dst + suffixRange.count == storage.end)
13151335
self = _StringGuts(storage)
1336+
_invariantCheck()
13161337
}
13171338
}
13181339

stdlib/public/core/StringUTF8.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,12 @@ extension String.UTF8View.Iterator : IteratorProtocol {
507507
self._guts = guts
508508
self._sourceIndex = 0
509509
self._buffer = 0
510-
self._endIndex = self._guts.count
511-
if _fastPath(self._guts._isContiguous && self._guts.isASCII) {
512-
self._asciiPointer = self._guts._unmanagedASCIIView.start
510+
if _fastPath(guts._isContiguous && guts.isASCII) {
511+
let ascii = guts._unmanagedASCIIView
512+
self._endIndex = ascii.count
513+
self._asciiPointer = ascii.start
513514
} else {
515+
self._endIndex = self._guts.count
514516
self._asciiPointer = nil
515517
}
516518
}

test/stdlib/NewString.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func repr(_ x: _StringGuts) -> String {
2828
return "Cocoa("
2929
+ "owner: \(hexAddrVal(x._owner)), "
3030
+ "count: \(x.count))"
31-
} else if x._isTaggedCocoa {
31+
} else if x._isSmallCocoa {
3232
return "Cocoa("
3333
+ "owner: <tagged>, "
3434
+ "count: \(x.count))"
@@ -165,13 +165,13 @@ print("--- Literals ---")
165165
// CHECK-NEXT: true
166166
let asciiLiteral: String = "foobar"
167167
print(" \(repr(asciiLiteral))")
168-
print(" \(asciiLiteral._core.isASCII)")
168+
print(" \(asciiLiteral._guts.isASCII)")
169169

170170
// CHECK-NEXT: String(Unmanaged(count: 11)) = "🏂☃❅❆❄︎⛄️❄️"
171171
// CHECK-NEXT: false
172172
let nonASCIILiteral: String = "🏂☃❅❆❄︎⛄️❄️"
173173
print(" \(repr(nonASCIILiteral))")
174-
print(" \(!asciiLiteral._core.isASCII)")
174+
print(" \(!asciiLiteral._guts.isASCII)")
175175

176176
// ===------- Appending -------===
177177

test/stdlib/NewStringAppending.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func repr(_ x: _StringGuts) -> String {
4545
return "Cocoa("
4646
+ "owner: \(hexAddrVal(x._owner)), "
4747
+ "count: \(x.count))"
48-
} else if x._isTaggedCocoa {
48+
} else if x._isSmallCocoa {
4949
return "Cocoa("
5050
+ "owner: <tagged>, "
5151
+ "count: \(x.count))"

validation-test/Reflection/reflect_Character.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ reflect(object: obj)
3333
// CHECK-64-NEXT: (field name=smallUTF16 offset=0
3434
// CHECK-64-NEXT: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647))
3535
// CHECK-64-NEXT: (field name=large offset=0
36-
// CHECK-64-NEXT: (struct size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647
37-
// CHECK-64-NEXT: (field name=_nativeBuffer offset=0
38-
// CHECK-64-NEXT: (reference kind=strong refcounting=native)))))))))
36+
// CHECK-64-NEXT: (reference kind=strong refcounting=native)))))))
3937

4038
// CHECK-32: Reflecting an object.
4139
// CHECK-32: Type reference:
@@ -50,9 +48,7 @@ reflect(object: obj)
5048
// CHECK-32-NEXT: (field name=smallUTF16 offset=0
5149
// CHECK-32-NEXT: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647))
5250
// CHECK-32-NEXT: (field name=large offset=0
53-
// CHECK-32-NEXT: (struct size=4 alignment=4 stride=4 num_extra_inhabitants=4096
54-
// CHECK-32-NEXT: (field name=_nativeBuffer offset=0
55-
// CHECK-32-NEXT: (reference kind=strong refcounting=native)))))))))
51+
// CHECK-32-NEXT: (reference kind=strong refcounting=native)))))))
5652

5753
doneReflecting()
5854

validation-test/Reflection/reflect_String.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ reflect(object: obj)
2323
// CHECK-64: (class reflect_String.TestClass)
2424

2525
// CHECK-64: Type info:
26-
// CHECK-64-NEXT: (class_instance size=40 alignment=8 stride=40
26+
// CHECK-64-NEXT: (class_instance size=32 alignment=8 stride=32
2727
// CHECK-64-NEXT: (field name=t offset=16
28-
// CHECK-64-NEXT: (struct size=24 alignment=8 stride=24 num_extra_inhabitants=0
28+
// CHECK-64-NEXT: (struct size=16 alignment=8 stride=16 num_extra_inhabitants=1
2929
// (unstable implementation details omitted)
3030

3131
// CHECK-32: Reflecting an object.
@@ -34,9 +34,9 @@ reflect(object: obj)
3434
// CHECK-32: (class reflect_String.TestClass)
3535

3636
// CHECK-32: Type info:
37-
// CHECK-32-NEXT: (class_instance size=20 alignment=4 stride=20
37+
// CHECK-32-NEXT: (class_instance size=32 alignment=4 stride=32
3838
// CHECK-32-NEXT: (field name=t offset=8
39-
// CHECK-32-NEXT: (struct size=12 alignment=4 stride=12 num_extra_inhabitants=0
39+
// CHECK-32-NEXT: (struct size=16 alignment=4 stride=16 num_extra_inhabitants=1
4040
// (unstable implementation details omitted)
4141

4242
doneReflecting()

validation-test/Reflection/reflect_multiple_types.swift

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ reflect(object: obj)
115115
// CHECK-64: (class reflect_multiple_types.TestClass)
116116

117117
// CHECK-64: Type info:
118-
// CHECK-64-NEXT: (class_instance size=185 alignment=8 stride=192 num_extra_inhabitants=0
118+
// CHECK-64-NEXT: (class_instance size=177 alignment=8 stride=184 num_extra_inhabitants=0
119119
// CHECK-64-NEXT: (field name=t00 offset=16
120120
// CHECK-64-NEXT: (struct size=8 alignment=8 stride=8 num_extra_inhabitants=1
121121
// (unstable implementation details omitted)
@@ -130,9 +130,7 @@ reflect(object: obj)
130130
// CHECK-64-NEXT: (field name=smallUTF16 offset=0
131131
// CHECK-64-NEXT: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647))
132132
// CHECK-64-NEXT: (field name=large offset=0
133-
// CHECK-64-NEXT: (struct size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647
134-
// CHECK-64-NEXT: (field name=_nativeBuffer offset=0
135-
// CHECK-64-NEXT: (reference kind=strong refcounting=native))))
133+
// CHECK-64-NEXT: (reference kind=strong refcounting=native))))))
136134
// CHECK-64-NEXT: (field name=t03 offset=40
137135
// CHECK-64-NEXT: (struct size=8 alignment=8 stride=8 num_extra_inhabitants=0
138136
// (unstable implementation details omitted)
@@ -176,25 +174,25 @@ reflect(object: obj)
176174
// CHECK-64-NEXT: (struct size=8 alignment=8 stride=8 num_extra_inhabitants=0
177175
// (unstable implementation details omitted)
178176
// CHECK-64: (field name=t16 offset=136
179-
// CHECK-64-NEXT: (struct size=24 alignment=8 stride=24 num_extra_inhabitants=0
177+
// CHECK-64-NEXT: (struct size=16 alignment=8 stride=16 num_extra_inhabitants=1
180178
// (unstable implementation details omitted)
181-
// CHECK-64: (field name=t17 offset=160
179+
// CHECK-64: (field name=t17 offset=152
182180
// CHECK-64-NEXT: (struct size=8 alignment=8 stride=8 num_extra_inhabitants=0
183181
// CHECK-64-NEXT: (field name=_value offset=0
184182
// CHECK-64-NEXT: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=0))))
185-
// CHECK-64-NEXT: (field name=t18 offset=168
183+
// CHECK-64-NEXT: (field name=t18 offset=160
186184
// CHECK-64-NEXT: (struct size=2 alignment=2 stride=2 num_extra_inhabitants=0
187185
// CHECK-64-NEXT: (field name=_value offset=0
188186
// CHECK-64-NEXT: (builtin size=2 alignment=2 stride=2 num_extra_inhabitants=0))))
189-
// CHECK-64-NEXT: (field name=t19 offset=172
187+
// CHECK-64-NEXT: (field name=t19 offset=164
190188
// CHECK-64-NEXT: (struct size=4 alignment=4 stride=4 num_extra_inhabitants=0
191189
// CHECK-64-NEXT: (field name=_value offset=0
192190
// CHECK-64-NEXT: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=0))))
193-
// CHECK-64-NEXT: (field name=t20 offset=176
191+
// CHECK-64-NEXT: (field name=t20 offset=168
194192
// CHECK-64-NEXT: (struct size=8 alignment=8 stride=8 num_extra_inhabitants=0
195193
// CHECK-64-NEXT: (field name=_value offset=0
196194
// CHECK-64-NEXT: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=0))))
197-
// CHECK-64-NEXT: (field name=t21 offset=184
195+
// CHECK-64-NEXT: (field name=t21 offset=176
198196
// CHECK-64-NEXT: (struct size=1 alignment=1 stride=1 num_extra_inhabitants=0
199197
// CHECK-64-NEXT: (field name=_value offset=0
200198
// CHECK-64-NEXT: (builtin size=1 alignment=1 stride=1 num_extra_inhabitants=0)))))
@@ -220,9 +218,7 @@ reflect(object: obj)
220218
// CHECK-32-NEXT: (field name=smallUTF16 offset=0
221219
// CHECK-32-NEXT: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647))
222220
// CHECK-32-NEXT: (field name=large offset=0
223-
// CHECK-32-NEXT: (struct size=4 alignment=4 stride=4 num_extra_inhabitants=4096
224-
// CHECK-32-NEXT: (field name=_nativeBuffer offset=0
225-
// CHECK-32-NEXT: (reference kind=strong refcounting=native))))))
221+
// CHECK-32-NEXT: (reference kind=strong refcounting=native))))))
226222
// CHECK-32-NEXT: (field name=t03 offset=24
227223
// CHECK-32-NEXT: (struct size=4 alignment=4 stride=4 num_extra_inhabitants=0
228224
// (unstable implementation details omitted)
@@ -266,25 +262,25 @@ reflect(object: obj)
266262
// CHECK-32-NEXT: (struct size=4 alignment=4 stride=4 num_extra_inhabitants=0
267263
// (unstable implementation details omitted)
268264
// CHECK-32: (field name=t16 offset=88
269-
// CHECK-32-NEXT: (struct size=12 alignment=4 stride=12 num_extra_inhabitants=0
265+
// CHECK-32-NEXT: (struct size=16 alignment=4 stride=16 num_extra_inhabitants=1
270266
// (unstable implementation details omitted)
271-
// CHECK-32: (field name=t17 offset=100
267+
// CHECK-32: (field name=t17 offset=104
272268
// CHECK-32-NEXT: (struct size=4 alignment=4 stride=4 num_extra_inhabitants=0
273269
// CHECK-32-NEXT: (field name=_value offset=0
274270
// CHECK-32-NEXT: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=0))))
275-
// CHECK-32-NEXT: (field name=t18 offset=104
271+
// CHECK-32-NEXT: (field name=t18 offset=108
276272
// CHECK-32-NEXT: (struct size=2 alignment=2 stride=2 num_extra_inhabitants=0
277273
// CHECK-32-NEXT: (field name=_value offset=0
278274
// CHECK-32-NEXT: (builtin size=2 alignment=2 stride=2 num_extra_inhabitants=0))))
279-
// CHECK-32-NEXT: (field name=t19 offset=108
275+
// CHECK-32-NEXT: (field name=t19 offset=112
280276
// CHECK-32-NEXT: (struct size=4 alignment=4 stride=4 num_extra_inhabitants=0
281277
// CHECK-32-NEXT: (field name=_value offset=0
282278
// CHECK-32-NEXT: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=0))))
283-
// CHECK-32-NEXT: (field name=t20 offset=112
279+
// CHECK-32-NEXT: (field name=t20 offset=116
284280
// CHECK-32-NEXT: (struct size=8 alignment=8 stride=8 num_extra_inhabitants=0
285281
// CHECK-32-NEXT: (field name=_value offset=0
286282
// CHECK-32-NEXT: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=0))))
287-
// CHECK-32-NEXT: (field name=t21 offset=120
283+
// CHECK-32-NEXT: (field name=t21 offset=124
288284
// CHECK-32-NEXT: (struct size=1 alignment=1 stride=1 num_extra_inhabitants=0
289285
// CHECK-32-NEXT: (field name=_value offset=0
290286
// CHECK-32-NEXT: (builtin size=1 alignment=1 stride=1 num_extra_inhabitants=0)))))

0 commit comments

Comments
 (0)