- Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathMigrationSupport.swift
707 lines (642 loc) · 35.3 KB
/
MigrationSupport.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// This file contains only support for types deprecated from previous versions
// of Swift
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"BidirectionalCollection")
publictypealiasBidirectionalIndexable=BidirectionalCollection
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"Collection")
publictypealiasIndexableBase=Collection
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"Collection")
publictypealiasIndexable=Collection
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"MutableCollection")
publictypealiasMutableIndexable=MutableCollection
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"RandomAccessCollection")
publictypealiasRandomAccessIndexable=RandomAccessCollection
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"RangeReplaceableIndexable")
publictypealiasRangeReplaceableIndexable=RangeReplaceableCollection
@available(swift, deprecated:4.2, renamed:"EnumeratedSequence.Iterator")
publictypealiasEnumeratedIterator<T:Sequence>=EnumeratedSequence<T>.Iterator
@available(swift,deprecated:4.2, obsoleted:5.0, renamed:"CollectionOfOne.Iterator")
publictypealiasIteratorOverOne<T>=CollectionOfOne<T>.Iterator
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"EmptyCollection.Iterator")
publictypealiasEmptyIterator<T>=EmptyCollection<T>.Iterator
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"LazyFilterSequence.Iterator")
publictypealiasLazyFilterIterator<T:Sequence>=LazyFilterSequence<T>.Iterator
@available(swift, deprecated:3.1, obsoleted:5.0, message:"Use Base.Index")
publictypealiasLazyFilterIndex<Base:Collection>=Base.Index
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"LazyDropWhileSequence.Iterator")
publictypealiasLazyDropWhileIterator<T>=LazyDropWhileSequence<T>.Iterator where T: Sequence
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"LazyDropWhileCollection.Index")
publictypealiasLazyDropWhileIndex<T>=LazyDropWhileCollection<T>.Index where T: Collection
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"LazyDropWhileCollection")
publictypealiasLazyDropWhileBidirectionalCollection<T>=LazyDropWhileCollection<T> where T: BidirectionalCollection
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"LazyFilterCollection")
publictypealiasLazyFilterBidirectionalCollection<T>=LazyFilterCollection<T> where T: BidirectionalCollection
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"LazyMapSequence.Iterator")
publictypealiasLazyMapIterator<T, E>=LazyMapSequence<T,E>.Iterator where T: Sequence
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"LazyMapCollection")
publictypealiasLazyMapBidirectionalCollection<T, E>=LazyMapCollection<T,E> where T: BidirectionalCollection
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"LazyMapCollection")
publictypealiasLazyMapRandomAccessCollection<T, E>=LazyMapCollection<T,E> where T: RandomAccessCollection
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"LazyCollection")
publictypealiasLazyBidirectionalCollection<T>=LazyCollection<T> where T: BidirectionalCollection
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"LazyCollection")
publictypealiasLazyRandomAccessCollection<T>=LazyCollection<T> where T: RandomAccessCollection
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"FlattenCollection.Index")
publictypealiasFlattenCollectionIndex<T>=FlattenCollection<T>.Index where T: Collection, T.Element: Collection
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"FlattenCollection.Index")
publictypealiasFlattenBidirectionalCollectionIndex<T>=FlattenCollection<T>.Index where T: BidirectionalCollection, T.Element: BidirectionalCollection
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"FlattenCollection")
publictypealiasFlattenBidirectionalCollection<T>=FlattenCollection<T> where T: BidirectionalCollection, T.Element: BidirectionalCollection
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"JoinedSequence.Iterator")
publictypealiasJoinedIterator<T:Sequence>=JoinedSequence<T>.Iterator where T.Element: Sequence
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"Zip2Sequence.Iterator")
publictypealiasZip2Iterator<T, U>=Zip2Sequence<T,U>.Iterator where T: Sequence, U: Sequence
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"LazyPrefixWhileSequence.Iterator")
publictypealiasLazyPrefixWhileIterator<T>=LazyPrefixWhileSequence<T>.Iterator where T: Sequence
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"LazyPrefixWhileCollection.Index")
publictypealiasLazyPrefixWhileIndex<T>=LazyPrefixWhileCollection<T>.Index where T: Collection
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"LazyPrefixWhileCollection")
publictypealiasLazyPrefixWhileBidirectionalCollection<T>=LazyPrefixWhileCollection<T> where T: BidirectionalCollection
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"ReversedCollection")
publictypealiasReversedRandomAccessCollection<T:RandomAccessCollection>=ReversedCollection<T>
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"ReversedCollection.Index")
publictypealiasReversedIndex<T:BidirectionalCollection>=ReversedCollection<T>.Index
@available(swift, deprecated:4.0, obsoleted:5.0, renamed:"Slice")
publictypealiasBidirectionalSlice<T>=Slice<T> where T: BidirectionalCollection
@available(swift, deprecated:4.0, obsoleted:5.0, renamed:"Slice")
publictypealiasRandomAccessSlice<T>=Slice<T> where T: RandomAccessCollection
@available(swift, deprecated:4.0, obsoleted:5.0, renamed:"Slice")
publictypealiasRangeReplaceableSlice<T>=Slice<T> where T: RangeReplaceableCollection
@available(swift, deprecated:4.0, obsoleted:5.0, renamed:"Slice")
publictypealiasRangeReplaceableBidirectionalSlice<T>=Slice<T> where T: RangeReplaceableCollection &BidirectionalCollection
@available(swift, deprecated:4.0, obsoleted:5.0, renamed:"Slice")
publictypealiasRangeReplaceableRandomAccessSlice<T>=Slice<T> where T: RangeReplaceableCollection &RandomAccessCollection
@available(swift, deprecated:4.0, obsoleted:5.0, renamed:"Slice")
publictypealiasMutableSlice<T>=Slice<T> where T: MutableCollection
@available(swift, deprecated:4.0, obsoleted:5.0, renamed:"Slice")
publictypealiasMutableBidirectionalSlice<T>=Slice<T> where T: MutableCollection &BidirectionalCollection
@available(swift, deprecated:4.0, obsoleted:5.0, renamed:"Slice")
publictypealiasMutableRandomAccessSlice<T>=Slice<T> where T: MutableCollection &RandomAccessCollection
@available(swift, deprecated:4.0, obsoleted:5.0, renamed:"Slice")
publictypealiasMutableRangeReplaceableSlice<T>=Slice<T> where T: MutableCollection &RangeReplaceableCollection
@available(swift, deprecated:4.0, obsoleted:5.0, renamed:"Slice")
publictypealiasMutableRangeReplaceableBidirectionalSlice<T>=Slice<T> where T: MutableCollection &RangeReplaceableCollection&BidirectionalCollection
@available(swift, deprecated:4.0, obsoleted:5.0, renamed:"Slice")
publictypealiasMutableRangeReplaceableRandomAccessSlice<T>=Slice<T> where T: MutableCollection &RangeReplaceableCollection&RandomAccessCollection
@available(swift, deprecated:4.0, obsoleted:5.0, renamed:"DefaultIndices")
publictypealiasDefaultBidirectionalIndices<T>=DefaultIndices<T> where T: BidirectionalCollection
@available(swift, deprecated:4.0, obsoleted:5.0, renamed:"DefaultIndices")
publictypealiasDefaultRandomAccessIndices<T>=DefaultIndices<T> where T: RandomAccessCollection
// Deprecated by SE-0115.
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"ExpressibleByNilLiteral")
publictypealiasNilLiteralConvertible=ExpressibleByNilLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"_ExpressibleByBuiltinIntegerLiteral")
publictypealias_BuiltinIntegerLiteralConvertible=_ExpressibleByBuiltinIntegerLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"ExpressibleByIntegerLiteral")
publictypealiasIntegerLiteralConvertible=ExpressibleByIntegerLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"_ExpressibleByBuiltinFloatLiteral")
publictypealias_BuiltinFloatLiteralConvertible=_ExpressibleByBuiltinFloatLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"ExpressibleByFloatLiteral")
publictypealiasFloatLiteralConvertible=ExpressibleByFloatLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"_ExpressibleByBuiltinBooleanLiteral")
publictypealias_BuiltinBooleanLiteralConvertible=_ExpressibleByBuiltinBooleanLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"ExpressibleByBooleanLiteral")
publictypealiasBooleanLiteralConvertible=ExpressibleByBooleanLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"_ExpressibleByBuiltinUnicodeScalarLiteral")
publictypealias_BuiltinUnicodeScalarLiteralConvertible=_ExpressibleByBuiltinUnicodeScalarLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"ExpressibleByUnicodeScalarLiteral")
publictypealiasUnicodeScalarLiteralConvertible=ExpressibleByUnicodeScalarLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"_ExpressibleByBuiltinExtendedGraphemeClusterLiteral")
publictypealias_BuiltinExtendedGraphemeClusterLiteralConvertible=_ExpressibleByBuiltinExtendedGraphemeClusterLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"ExpressibleByExtendedGraphemeClusterLiteral")
publictypealiasExtendedGraphemeClusterLiteralConvertible=ExpressibleByExtendedGraphemeClusterLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"_ExpressibleByBuiltinStringLiteral")
publictypealias_BuiltinStringLiteralConvertible=_ExpressibleByBuiltinStringLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"ExpressibleByStringLiteral")
publictypealiasStringLiteralConvertible=ExpressibleByStringLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"ExpressibleByArrayLiteral")
publictypealiasArrayLiteralConvertible=ExpressibleByArrayLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"ExpressibleByDictionaryLiteral")
publictypealiasDictionaryLiteralConvertible=ExpressibleByDictionaryLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"ExpressibleByStringInterpolation")
publictypealiasStringInterpolationConvertible=ExpressibleByStringInterpolation
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"_ExpressibleByColorLiteral")
publictypealias_ColorLiteralConvertible=_ExpressibleByColorLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"_ExpressibleByImageLiteral")
publictypealias_ImageLiteralConvertible=_ExpressibleByImageLiteral
@available(swift, deprecated:3.0, obsoleted:5.0, renamed:"_ExpressibleByFileReferenceLiteral")
publictypealias_FileReferenceLiteralConvertible=_ExpressibleByFileReferenceLiteral
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"ClosedRange.Index")
publictypealiasClosedRangeIndex<T>=ClosedRange<T>.Index where T: Strideable, T.Stride: SignedInteger
/// An optional type that allows implicit member access.
///
/// The `ImplicitlyUnwrappedOptional` type is deprecated. To create an optional
/// value that is implicitly unwrapped, place an exclamation mark (`!`) after
/// the type that you want to denote as optional.
///
/// // An implicitly unwrapped optional integer
/// let guaranteedNumber: Int! = 6
///
/// // An optional integer
/// let possibleNumber: Int? = 5
@available(*, unavailable, renamed:"Optional")
publictypealiasImplicitlyUnwrappedOptional<Wrapped>=Optional<Wrapped>
extensionRangewhere Bound:Strideable, Bound.Stride:SignedInteger{
/// Now that Range is conditionally a collection when Bound: Strideable,
/// CountableRange is no longer needed. This is a deprecated initializer
/// for any remaining uses of Range(countableRange).
@available(swift, deprecated:4.2, obsoleted:5.0, message:"CountableRange is now a Range. No need to convert any more.")
publicinit(_ other:Range<Bound>){
self= other
}
}
extensionClosedRangewhere Bound:Strideable, Bound.Stride:SignedInteger{
/// Now that Range is conditionally a collection when Bound: Strideable,
/// CountableRange is no longer needed. This is a deprecated initializer
/// for any remaining uses of Range(countableRange).
@available(swift, deprecated:4.2, obsoleted:5.0, message:"CountableClosedRange is now a ClosedRange. No need to convert any more.")
publicinit(_ other:ClosedRange<Bound>){
self= other
}
}
@available(swift, deprecated:5.0, renamed:"KeyValuePairs")
publictypealiasDictionaryLiteral<Key, Value>=KeyValuePairs<Key,Value>
extensionLazySequenceProtocol{
/// Returns the non-`nil` results of mapping the given transformation over
/// this sequence.
///
/// Use this method to receive a sequence of non-optional values when your
/// transformation produces an optional value.
///
/// - Parameter transform: A closure that accepts an element of this sequence
/// as its argument and returns an optional value.
///
/// - Complexity: O(1)
@available(swift, deprecated:4.1, renamed:"compactMap(_:)", message:"Please use compactMap(_:) for the case where closure returns an optional value")
publicfunc flatMap<ElementOfResult>(
_ transform:@escaping(Elements.Element)->ElementOfResult?
)->LazyMapSequence<
LazyFilterSequence<
LazyMapSequence<Elements,ElementOfResult?>>,
ElementOfResult
>{
returnself.compactMap(transform)
}
}
extensionString{
/// A view of a string's contents as a collection of characters.
///
/// Previous versions of Swift provided this view since String
/// itself was not a collection. String is now a collection of
/// characters, so this type is now just an alias for String.
@available(swift, deprecated:3.2, obsoleted:5.0, message:"Please use String directly")
publictypealiasCharacterView=String
/// A view of the string's contents as a collection of characters.
///
/// Previous versions of Swift provided this view since String
/// itself was not a collection. String is now a collection of
/// characters, so this type is now just an alias for String.
@available(swift, deprecated:3.2, obsoleted:5.0, message:"Please use String directly")
publicvarcharacters:String{
get{returnself}
set{self= newValue }
}
/// Applies the given closure to a mutable view of the string's characters.
///
/// Previous versions of Swift provided this view since String
/// itself was not a collection. String is now a collection of
/// characters, so this type is now just an alias for String.
@available(swift, deprecated:3.2, obsoleted:5.0, message:"Please mutate the String directly")
publicmutatingfunc withMutableCharacters<R>(
_ body:(inoutString)->R
)->R{
returnbody(&self)
}
}
extensionString.UnicodeScalarView:_CustomPlaygroundQuickLookable{
@available(swift, deprecated:4.2/*, obsoleted: 5.0*/, message:"UnicodeScalarView.customPlaygroundQuickLook will be removed in Swift 5.0")
publicvarcustomPlaygroundQuickLook:_PlaygroundQuickLook{
return.text(description)
}
}
//===--- Slicing Support --------------------------------------------------===//
// @available(swift,deprecated: 5.0, renamed: "Unicode.UTF8")
publictypealiasUTF8=Unicode.UTF8
// @available(swift, deprecated: 5.0, renamed: "Unicode.UTF16")
publictypealiasUTF16=Unicode.UTF16
// @available(swift, deprecated: 5.0, renamed: "Unicode.UTF32")
publictypealiasUTF32=Unicode.UTF32
// @available(swift, deprecated: 5.0, renamed: "Unicode.Scalar")
publictypealiasUnicodeScalar=Unicode.Scalar
extensionString.UTF16View:_CustomPlaygroundQuickLookable{
@available(swift, deprecated:4.2/*, obsoleted: 5.0*/, message:"UTF16View.customPlaygroundQuickLook will be removed in Swift 5.0")
publicvarcustomPlaygroundQuickLook:_PlaygroundQuickLook{
return.text(description)
}
}
extensionString.UTF8View:_CustomPlaygroundQuickLookable{
@available(swift, deprecated:4.2/*, obsoleted: 5.0*/, message:"UTF8View.customPlaygroundQuickLook will be removed in Swift 5.0")
publicvarcustomPlaygroundQuickLook:_PlaygroundQuickLook{
return.text(description)
}
}
extensionSubstring{
/// A view of a string's contents as a collection of characters.
///
/// Previous versions of Swift provided this view since String
/// itself was not a collection. String is now a collection of
/// characters, so this type is now just an alias for String.
@available(swift, deprecated:3.2, obsoleted:5.0, message:"Please use Substring directly")
publictypealiasCharacterView=Substring
/// A view of the string's contents as a collection of characters.
@available(swift, deprecated:3.2, obsoleted:5.0, message:"Please use Substring directly")
publicvarcharacters:Substring{
get{
returnself
}
set{
self= newValue
}
}
/// Applies the given closure to a mutable view of the string's characters.
///
/// Previous versions of Swift provided this view since String
/// itself was not a collection. String is now a collection of
/// characters, so this type is now just an alias for String.
@available(swift, deprecated:3.2, obsoleted:5.0, message:"Please mutate the Substring directly")
publicmutatingfunc withMutableCharacters<R>(
_ body:(inoutSubstring)->R
)->R{
returnbody(&self)
}
privatefunc _boundsCheck(_ range:Range<Index>){
_precondition(range.lowerBound >= startIndex,
"String index range is out of bounds")
_precondition(range.upperBound <= endIndex,
"String index range is out of bounds")
}
}
extensionSubstring:_CustomPlaygroundQuickLookable{
@available(swift, deprecated:4.2/*, obsoleted: 5.0*/, message:"Substring.customPlaygroundQuickLook will be removed in Swift 5.0")
publicvarcustomPlaygroundQuickLook:_PlaygroundQuickLook{
returnString(self).customPlaygroundQuickLook
}
}
extensionCollection{
// FIXME: <rdar://problem/34142121>
// This typealias should be removed as it predates the source compatibility
// guarantees of Swift 3, but it cannot due to a bug.
@available(*, unavailable, renamed:"Iterator")
publictypealiasGenerator=Iterator
@available(swift, deprecated:3.2, obsoleted:5.0, renamed:"Element")
publictypealias_Element=Element
@available(swift, deprecated:4.0, obsoleted:5.0, message:"all index distances are now of type Int")
publicfunc index<T:BinaryInteger>(_ i:Index, offsetBy n:T)->Index{
returnindex(i, offsetBy:Int(n))
}
@available(swift, deprecated:4.0, obsoleted:5.0, message:"all index distances are now of type Int")
publicfunc formIndex<T:BinaryInteger>(_ i:inoutIndex, offsetBy n:T){
returnformIndex(&i, offsetBy:Int(n))
}
@available(swift, deprecated:4.0, obsoleted:5.0, message:"all index distances are now of type Int")
publicfunc index<T:BinaryInteger>(_ i:Index, offsetBy n:T, limitedBy limit:Index)->Index?{
returnindex(i, offsetBy:Int(n), limitedBy: limit)
}
@available(swift, deprecated:4.0, obsoleted:5.0, message:"all index distances are now of type Int")
publicfunc formIndex<T:BinaryInteger>(_ i:inoutIndex, offsetBy n:T, limitedBy limit:Index)->Bool{
returnformIndex(&i, offsetBy:Int(n), limitedBy: limit)
}
@available(swift, deprecated:4.0, obsoleted:5.0, message:"all index distances are now of type Int")
publicfunc distance<T:BinaryInteger>(from start:Index, to end:Index)->T{
returnnumericCast(distance(from: start, to: end)asInt)
}
}
extensionUnsafeMutablePointer{
@available(swift, deprecated:4.1, obsoleted:5.0, renamed:"initialize(repeating:count:)")
publicfunc initialize(to newValue:Pointee, count:Int=1){
initialize(repeating: newValue, count: count)
}
@available(swift, deprecated:4.1, obsoleted:5.0, message:"the default argument to deinitialize(count:) has been removed, please specify the count explicitly")
@discardableResult
publicfunc deinitialize()->UnsafeMutableRawPointer{
returndeinitialize(count:1)
}
@available(swift, deprecated:4.1, obsoleted:5.0, message:"Swift currently only supports freeing entire heap blocks, use deallocate() instead")
publicfunc deallocate(capacity _:Int){
self.deallocate()
}
/// Initializes memory starting at this pointer's address with the elements
/// of the given collection.
///
/// The region of memory starting at this pointer and covering `source.count`
/// instances of the pointer's `Pointee` type must be uninitialized or
/// `Pointee` must be a trivial type. After calling `initialize(from:)`, the
/// region is initialized.
///
/// - Parameter source: A collection of elements of the pointer's `Pointee`
/// type.
// This is fundamentally unsafe since collections can underreport their count.
@available(swift, deprecated:4.2, obsoleted:5.0, message:"it will be removed in Swift 5.0. Please use 'UnsafeMutableBufferPointer.initialize(from:)' instead")
publicfunc initialize<C:Collection>(from source:C)
where C.Element ==Pointee{
letbuf=UnsafeMutableBufferPointer(start:self, count:numericCast(source.count))
var(remainders,writtenUpTo)= source._copyContents(initializing: buf)
// ensure that exactly rhs.count elements were written
_precondition(remainders.next()==nil,"rhs underreported its count")
_precondition(writtenUpTo == buf.endIndex,"rhs overreported its count")
}
}
extensionUnsafeMutableRawPointer{
@available(*, unavailable, renamed:"init(mutating:)")
publicinit(@_nonEphemeral _ from:UnsafeRawPointer){Builtin.unreachable()}
@available(*, unavailable, renamed:"init(mutating:)")
publicinit?(@_nonEphemeral _ from:UnsafeRawPointer?){Builtin.unreachable()}
@available(*, unavailable, renamed:"init(mutating:)")
publicinit<T>(@_nonEphemeral _ from:UnsafePointer<T>){Builtin.unreachable()}
@available(*, unavailable, renamed:"init(mutating:)")
publicinit?<T>(@_nonEphemeral _ from:UnsafePointer<T>?){Builtin.unreachable()}
}
extensionUnsafeRawPointer:_CustomPlaygroundQuickLookable{
internalvarsummary:String{
letptrValue=UInt64(
bitPattern:Int64(Int(Builtin.ptrtoint_Word(_rawValue))))
return ptrValue ==0
?"UnsafeRawPointer(nil)"
:"UnsafeRawPointer(0x\(_uint64ToString(ptrValue, radix:16, uppercase:true)))"
}
@available(swift, deprecated:4.2/*, obsoleted: 5.0*/, message:"UnsafeRawPointer.customPlaygroundQuickLook will be removed in a future Swift version")
publicvarcustomPlaygroundQuickLook:_PlaygroundQuickLook{
return.text(summary)
}
}
extensionUnsafeMutableRawPointer:_CustomPlaygroundQuickLookable{
privatevarsummary:String{
letptrValue=UInt64(
bitPattern:Int64(Int(Builtin.ptrtoint_Word(_rawValue))))
return ptrValue ==0
?"UnsafeMutableRawPointer(nil)"
:"UnsafeMutableRawPointer(0x\(_uint64ToString(ptrValue, radix:16, uppercase:true)))"
}
@available(swift, deprecated:4.2/*, obsoleted: 5.0*/, message:"UnsafeMutableRawPointer.customPlaygroundQuickLook will be removed in a future Swift version")
publicvarcustomPlaygroundQuickLook:_PlaygroundQuickLook{
return.text(summary)
}
}
extensionUnsafePointer:_CustomPlaygroundQuickLookable{
privatevarsummary:String{
letptrValue=UInt64(bitPattern:Int64(Int(Builtin.ptrtoint_Word(_rawValue))))
return ptrValue ==0
?"UnsafePointer(nil)"
:"UnsafePointer(0x\(_uint64ToString(ptrValue, radix:16, uppercase:true)))"
}
@available(swift, deprecated:4.2/*, obsoleted: 5.0*/, message:"UnsafePointer.customPlaygroundQuickLook will be removed in a future Swift version")
publicvarcustomPlaygroundQuickLook:PlaygroundQuickLook{
return.text(summary)
}
}
extensionUnsafeMutablePointer:_CustomPlaygroundQuickLookable{
privatevarsummary:String{
letptrValue=UInt64(bitPattern:Int64(Int(Builtin.ptrtoint_Word(_rawValue))))
return ptrValue ==0
?"UnsafeMutablePointer(nil)"
:"UnsafeMutablePointer(0x\(_uint64ToString(ptrValue, radix:16, uppercase:true)))"
}
@available(swift, deprecated:4.2/*, obsoleted: 5.0*/, message:"UnsafeMutablePointer.customPlaygroundQuickLook will be removed in a future Swift version")
publicvarcustomPlaygroundQuickLook:PlaygroundQuickLook{
return.text(summary)
}
}
@available(swift, deprecated:4.1, obsoleted:5.0, renamed:"UnsafeBufferPointer.Iterator")
publictypealiasUnsafeBufferPointerIterator<T>=UnsafeBufferPointer<T>.Iterator
@available(swift, deprecated:4.1, obsoleted:5.0, renamed:"UnsafeRawBufferPointer.Iterator")
publictypealiasUnsafeRawBufferPointerIterator<T>=UnsafeBufferPointer<T>.Iterator
@available(swift, deprecated:4.1, obsoleted:5.0, renamed:"UnsafeRawBufferPointer.Iterator")
publictypealiasUnsafeMutableRawBufferPointerIterator<T>=UnsafeBufferPointer<T>.Iterator
extensionUnsafeMutableRawPointer{
@available(swift, deprecated:4.1, obsoleted:5.0, renamed:"allocate(byteCount:alignment:)")
publicstaticfunc allocate(
bytes size:Int, alignedTo alignment:Int
)->UnsafeMutableRawPointer{
returnUnsafeMutableRawPointer.allocate(byteCount: size, alignment: alignment)
}
@available(swift, deprecated:4.1, obsoleted:5.0, renamed:"deallocate()", message:"Swift currently only supports freeing entire heap blocks, use deallocate() instead")
publicfunc deallocate(bytes _:Int, alignedTo _:Int){
self.deallocate()
}
@available(swift, deprecated:4.1, obsoleted:5.0, renamed:"copyMemory(from:byteCount:)")
publicfunc copyBytes(from source:UnsafeRawPointer, count:Int){
copyMemory(from: source, byteCount: count)
}
@available(swift, deprecated:4.1, obsoleted:5.0, renamed:"initializeMemory(as:repeating:count:)")
@discardableResult
publicfunc initializeMemory<T>(
as type:T.Type, at offset:Int=0, count:Int=1, to repeatedValue:T
)->UnsafeMutablePointer<T>{
return(self+ offset *MemoryLayout<T>.stride).initializeMemory(
as: type, repeating: repeatedValue, count: count)
}
@available(swift, deprecated:4.1, obsoleted:5.0, message:"it will be removed in Swift 5.0. Please use 'UnsafeMutableRawBufferPointer.initialize(from:)' instead")
@discardableResult
publicfunc initializeMemory<C:Collection>(
as type:C.Element.Type, from source:C
)->UnsafeMutablePointer<C.Element>{
// TODO: Optimize where `C` is a `ContiguousArrayBuffer`.
// Initialize and bind each element of the container.
varptr=self
forelementin source {
ptr.initializeMemory(as:C.Element.self, repeating: element, count:1)
ptr += MemoryLayout<C.Element>.stride
}
returnUnsafeMutablePointer(_rawValue)
}
}
extensionUnsafeMutableRawBufferPointer{
@available(swift, deprecated:4.1, obsoleted:5.0, renamed:"allocate(byteCount:alignment:)")
publicstaticfunc allocate(count:Int)->UnsafeMutableRawBufferPointer{
returnUnsafeMutableRawBufferPointer.allocate(
byteCount: count, alignment: MemoryLayout<UInt>.alignment)
}
@available(swift, deprecated:4.1, obsoleted:5.0, renamed:"copyMemory(from:)")
publicfunc copyBytes(from source:UnsafeRawBufferPointer){
copyMemory(from: source)
}
}
//===----------------------------------------------------------------------===//
// The following overloads of flatMap are carefully crafted to allow the code
// like the following:
// ["hello"].flatMap { $0 }
// return an array of strings without any type context in Swift 3 mode, at the
// same time allowing the following code snippet to compile:
// [0, 1].flatMap { x in
// if String(x) == "foo" { return "bar" } else { return nil }
// }
// Note that the second overload is declared on a more specific protocol.
// See: test/stdlib/StringFlatMap.swift for tests.
extensionSequence{
@available(swift, deprecated:4.1/*, obsoleted: 5.1 */, renamed:"compactMap(_:)",
message:"Please use compactMap(_:) for the case where closure returns an optional value")
publicfunc flatMap<ElementOfResult>(
_ transform:(Element)throws->ElementOfResult?
)rethrows->[ElementOfResult]{
returntry_compactMap(transform)
}
}
extensionCollection{
@available(swift, deprecated:4.1, obsoleted:5.0, renamed:"compactMap(_:)",
message:"Please use compactMap(_:) for the case where closure returns an optional value")
publicfunc flatMap(
_ transform:(Element)throws->String?
)rethrows->[String]{
returntry_compactMap(transform)
}
}
extensionCollection{
/// Returns the first index in which an element of the collection satisfies
/// the given predicate.
@available(swift, deprecated:5.0, renamed:"firstIndex(where:)")
@inlinable
publicfunc index(
where _predicate:(Element)throws->Bool
)rethrows->Index?{
returntryfirstIndex(where: _predicate)
}
}
extensionCollectionwhere Element:Equatable{
/// Returns the first index where the specified value appears in the
/// collection.
@available(swift, deprecated:5.0, renamed:"firstIndex(of:)")
@inlinable
publicfunc index(of element:Element)->Index?{
returnfirstIndex(of: element)
}
}
extensionZip2Sequence{
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"Sequence1.Iterator")
publictypealiasStream1=Sequence1.Iterator
@available(swift, deprecated:4.2, obsoleted:5.0, renamed:"Sequence2.Iterator")
publictypealiasStream2=Sequence2.Iterator
}
//===--- QuickLooks -------------------------------------------------------===//
/// The sum of types that can be used as a Quick Look representation.
///
/// The `PlaygroundQuickLook` protocol is deprecated, and will be removed from
/// the standard library in a future Swift release. To customize the logging of
/// your type in a playground, conform to the
/// `CustomPlaygroundDisplayConvertible` protocol, which does not use the
/// `PlaygroundQuickLook` enum.
///
/// If you need to provide a customized playground representation in Swift 4.0
/// or Swift 3.2 or earlier, use a conditional compilation block:
///
/// #if swift(>=4.1) || (swift(>=3.3) && !swift(>=4.0))
/// // With Swift 4.1 and later (including Swift 3.3 and later), use
/// // the CustomPlaygroundDisplayConvertible protocol.
/// #else
/// // With Swift 4.0 and Swift 3.2 and earlier, use PlaygroundQuickLook
/// // and the CustomPlaygroundQuickLookable protocol.
/// #endif
@available(swift, deprecated:4.2, message:"PlaygroundQuickLook will be removed in a future Swift version. For customizing how types are presented in playgrounds, use CustomPlaygroundDisplayConvertible instead.")
publictypealiasPlaygroundQuickLook=_PlaygroundQuickLook
@frozen // rdar://problem/38719739 - needed by LLDB
publicenum_PlaygroundQuickLook{
case text(String)
case int(Int64)
case uInt(UInt64)
case float(Float32)
case double(Float64)
case image(Any)
case sound(Any)
case color(Any)
case bezierPath(Any)
case attributedString(Any)
case rectangle(Float64,Float64,Float64,Float64)
case point(Float64,Float64)
case size(Float64,Float64)
case bool(Bool)
case range(Int64,Int64)
case view(Any)
case sprite(Any)
case url(String)
case _raw([UInt8],String)
}
extension_PlaygroundQuickLook{
/// Creates a new Quick Look for the given instance.
///
/// If the dynamic type of `subject` conforms to
/// `CustomPlaygroundQuickLookable`, the result is found by calling its
/// `customPlaygroundQuickLook` property. Otherwise, the result is
/// synthesized by the language. In some cases, the synthesized result may
/// be `.text(String(reflecting: subject))`.
///
/// - Note: If the dynamic type of `subject` has value semantics, subsequent
/// mutations of `subject` will not observable in the Quick Look. In
/// general, though, the observability of such mutations is unspecified.
///
/// - Parameter subject: The instance to represent with the resulting Quick
/// Look.
@available(swift, deprecated:4.2, obsoleted:5.0, message:"PlaygroundQuickLook will be removed in a future Swift version.")
publicinit(reflecting subject:Any){
iflet customized = subject as?_CustomPlaygroundQuickLookable{
self= customized.customPlaygroundQuickLook
}
elseiflet customized = subject as?__DefaultCustomPlaygroundQuickLookable{
self= customized._defaultCustomPlaygroundQuickLook
}
else{
iflet q =Mirror.quickLookObject(subject){
self= q
}
else{
self=.text(String(reflecting: subject))
}
}
}
}
/// A type that explicitly supplies its own playground Quick Look.
///
/// The `CustomPlaygroundQuickLookable` protocol is deprecated, and will be
/// removed from the standard library in a future Swift release. To customize
/// the logging of your type in a playground, conform to the
/// `CustomPlaygroundDisplayConvertible` protocol.
///
/// If you need to provide a customized playground representation in Swift 4.0
/// or Swift 3.2 or earlier, use a conditional compilation block:
///
/// #if swift(>=4.1) || (swift(>=3.3) && !swift(>=4.0))
/// // With Swift 4.1 and later (including Swift 3.3 and later),
/// // conform to CustomPlaygroundDisplayConvertible.
/// extension MyType: CustomPlaygroundDisplayConvertible { /*...*/ }
/// #else
/// // Otherwise, on Swift 4.0 and Swift 3.2 and earlier,
/// // conform to CustomPlaygroundQuickLookable.
/// extension MyType: CustomPlaygroundQuickLookable { /*...*/ }
/// #endif
@available(swift, deprecated:4.2, obsoleted:5.0, message:"CustomPlaygroundQuickLookable will be removed in a future Swift version. For customizing how types are presented in playgrounds, use CustomPlaygroundDisplayConvertible instead.")
publictypealiasCustomPlaygroundQuickLookable=_CustomPlaygroundQuickLookable
//@available(swift, obsoleted: 5.0)
publicprotocol_CustomPlaygroundQuickLookable{
/// A custom playground Quick Look for this instance.
///
/// If this type has value semantics, the `PlaygroundQuickLook` instance
/// should be unaffected by subsequent mutations.
varcustomPlaygroundQuickLook:_PlaygroundQuickLook{get}
}
// Double-underscored real version allows us to keep using this in AppKit while
// warning for non-SDK use. This is probably overkill but it doesn't cost
// anything.
@available(swift, deprecated:4.2, obsoleted:5.0, message:"_DefaultCustomPlaygroundQuickLookable will be removed in a future Swift version. For customizing how types are presented in playgrounds, use CustomPlaygroundDisplayConvertible instead.")
publictypealias_DefaultCustomPlaygroundQuickLookable=__DefaultCustomPlaygroundQuickLookable
// @available(swift, obsoleted: 5.0)
publicprotocol__DefaultCustomPlaygroundQuickLookable{
var_defaultCustomPlaygroundQuickLook:_PlaygroundQuickLook{get}
}