Skip to content

Commit e41f023

Browse files
author
Dave Abrahams
authored
Merge pull request #4538 from apple/stdlib-warning-suppression
[stdlib] Suppress noisy warnings
2 parents 6678ab2 + 5c13e35 commit e41f023

22 files changed

+102
-54
lines changed

docs/Literals.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,6 @@ literal type is always Dictionary.
138138

139139
String interpolations are a bit different: they try to individually convert
140140
each element of the interpolation to the type that adopts
141-
ExpressibleByStringInterpolation, then calls the variadic
141+
_ExpressibleByStringInterpolation, then calls the variadic
142142
``convertFromStringInterpolation`` to put them all together. The default type
143143
for an interpolated literal without context is also ``StringLiteralType``.

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,10 +2107,10 @@ ERROR(optional_used_as_boolean,none,
21072107
"test for '!= nil' instead", (Type))
21082108

21092109
ERROR(interpolation_missing_proto,none,
2110-
"string interpolation requires the protocol 'ExpressibleByStringInterpolation' to be defined",
2110+
"string interpolation requires the protocol '_ExpressibleByStringInterpolation' to be defined",
21112111
())
21122112
ERROR(interpolation_broken_proto,none,
2113-
"protocol 'ExpressibleByStringInterpolation' is broken",
2113+
"protocol '_ExpressibleByStringInterpolation' is broken",
21142114
())
21152115

21162116
ERROR(object_literal_broken_proto,none,

include/swift/AST/KnownProtocols.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByDictionaryLiteral)
7171
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByExtendedGraphemeClusterLiteral)
7272
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByFloatLiteral)
7373
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByIntegerLiteral)
74-
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByStringInterpolation)
74+
EXPRESSIBLE_BY_LITERAL_PROTOCOL_(ExpressibleByStringInterpolation)
7575
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByStringLiteral)
7676
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByNilLiteral)
7777
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByUnicodeScalarLiteral)

stdlib/private/StdlibCollectionUnittest/CheckCollectionInstance.swift.gyb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public struct CollectionMisuseResiliencyChecks {
4040
}
4141

4242
% for inc, protocol, direction, end in (
43-
% ('inc', 'Indexable', 'after', 'end'),
44-
% ('dec', 'BidirectionalIndexable', 'before', 'start')):
43+
% ('inc', '_Indexable', 'after', 'end'),
44+
% ('dec', '_BidirectionalIndexable', 'before', 'start')):
4545

4646
/// Test that the elements of `instances` satisfy
4747
/// ${'some of ' if inc == 'dec' else ''}the semantic
@@ -91,7 +91,7 @@ internal func _checkIncrementalAdvance<Instances, BaseCollection>(
9191
${TRACE}
9292
) where
9393
Instances : Collection,
94-
BaseCollection : Indexable,
94+
BaseCollection : _Indexable,
9595
Instances.Iterator.Element == BaseCollection.Index,
9696
// FIXME(compiler limitation): these constraints should be applied to
9797
// associated types of Collection.
@@ -128,7 +128,7 @@ public func checkForwardIndex<Instances, BaseCollection>(
128128
endIndex: Instances.Iterator.Element, ${TRACE}
129129
) where
130130
Instances : Collection,
131-
BaseCollection : Indexable,
131+
BaseCollection : _Indexable,
132132
Instances.Iterator.Element == BaseCollection.Index,
133133
// FIXME(compiler limitation): these constraints should be applied to
134134
// associated types of Collection.
@@ -158,7 +158,7 @@ public func checkBidirectionalIndex<Instances, BaseCollection>(
158158
${TRACE}
159159
) where
160160
Instances: Collection,
161-
BaseCollection : BidirectionalIndexable,
161+
BaseCollection : _BidirectionalIndexable,
162162
Instances.Iterator.Element == BaseCollection.Index,
163163
// FIXME(compiler limitation): these constraints should be applied to
164164
// associated types of Collection.
@@ -197,7 +197,7 @@ public func checkRandomAccessIndex<Instances, Distances, BaseCollection>(
197197
) where
198198
Instances : Collection,
199199
Distances : Collection,
200-
BaseCollection : RandomAccessIndexable,
200+
BaseCollection : _RandomAccessIndexable,
201201
Instances.Iterator.Element == BaseCollection.Index,
202202
Distances.Iterator.Element == BaseCollection.IndexDistance,
203203
// FIXME(compiler limitation): these constraints should be applied to
@@ -230,7 +230,7 @@ public func checkAdvancesAndDistances<Instances, Distances, BaseCollection>(
230230
) where
231231
Instances : Collection,
232232
Distances : Collection,
233-
BaseCollection : Indexable,
233+
BaseCollection : _Indexable,
234234
Instances.Iterator.Element == BaseCollection.Index,
235235
Distances.Iterator.Element == BaseCollection.IndexDistance,
236236
// FIXME(compiler limitation): these constraints should be applied to

stdlib/public/SDK/Foundation/Data.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,10 +735,10 @@ extension Data : CustomStringConvertible, CustomDebugStringConvertible, CustomRe
735735

736736
extension Data {
737737
@available(*, unavailable, renamed: "copyBytes(to:count:)")
738-
public func getBytes(_ buffer: UnsafeMutablePointer<Swift.Void>, length: Int) { }
738+
public func getBytes<UnsafeMutablePointerVoid: _Pointer>(_ buffer: UnsafeMutablePointerVoid, length: Int) { }
739739

740740
@available(*, unavailable, renamed: "copyBytes(to:from:)")
741-
public func getBytes(_ buffer: UnsafeMutablePointer<Swift.Void>, range: NSRange) { }
741+
public func getBytes<UnsafeMutablePointerVoid: _Pointer>(_ buffer: UnsafeMutablePointerVoid, range: NSRange) { }
742742
}
743743

744744
/// Provides bridging functionality for struct Data to class NSData and vice-versa.

stdlib/public/core/BidirectionalCollection.swift

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
/// `BidirectionalCollection` protocol instead, because it has a more complete
1818
/// interface.
1919
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'BidirectionalCollection' instead")
20-
public protocol BidirectionalIndexable : Indexable {
20+
public typealias BidirectionalIndexable = _BidirectionalIndexable
21+
public protocol _BidirectionalIndexable : _Indexable {
2122
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
2223
// to exist apart from missing compiler features that we emulate with it.
2324
// rdar://problem/20531108
@@ -65,7 +66,7 @@ public protocol BidirectionalIndexable : Indexable {
6566
/// - If `i > c.startIndex && i <= c.endIndex`
6667
/// `c.index(after: c.index(before: i)) == i`.
6768
public protocol BidirectionalCollection
68-
: BidirectionalIndexable, Collection {
69+
: _BidirectionalIndexable, Collection {
6970

7071
// TODO: swift-3-indexing-model - replaces functionality in BidirectionalIndex
7172
/// Returns the position immediately before the given index.
@@ -83,18 +84,37 @@ public protocol BidirectionalCollection
8384

8485
/// A sequence that can represent a contiguous subrange of the collection's
8586
/// elements.
86-
associatedtype SubSequence : BidirectionalIndexable, Collection
87+
associatedtype SubSequence : _BidirectionalIndexable, Collection
8788
= BidirectionalSlice<Self>
8889
// FIXME(compiler limitation):
8990
// associatedtype SubSequence : BidirectionalCollection
9091

9192
/// A type that can represent the indices that are valid for subscripting the
9293
/// collection, in ascending order.
93-
associatedtype Indices : BidirectionalIndexable, Collection
94+
associatedtype Indices : _BidirectionalIndexable, Collection
9495
= DefaultBidirectionalIndices<Self>
9596
// FIXME(compiler limitation):
9697
// associatedtype Indices : BidirectionalCollection
9798

99+
/// The indices that are valid for subscripting the collection, in ascending
100+
/// order.
101+
///
102+
/// A collection's `indices` property can hold a strong reference to the
103+
/// collection itself, causing the collection to be non-uniquely referenced.
104+
/// If you mutate the collection while iterating over its indices, a strong
105+
/// reference can cause an unexpected copy of the collection. To avoid the
106+
/// unexpected copy, use the `index(after:)` method starting with
107+
/// `startIndex` to produce indices instead.
108+
///
109+
/// var c = MyFancyCollection([10, 20, 30, 40, 50])
110+
/// var i = c.startIndex
111+
/// while i != c.endIndex {
112+
/// c[i] /= 5
113+
/// i = c.index(after: i)
114+
/// }
115+
/// // c == MyFancyCollection([2, 4, 6, 8, 10])
116+
var indices: Indices { get }
117+
98118
// TODO: swift-3-indexing-model: tests.
99119
/// The last element of the collection.
100120
///
@@ -111,7 +131,7 @@ public protocol BidirectionalCollection
111131
}
112132

113133
/// Default implementation for bidirectional collections.
114-
extension BidirectionalIndexable {
134+
extension _BidirectionalIndexable {
115135

116136
@inline(__always)
117137
public func formIndex(before i: inout Index) {

stdlib/public/core/Builtin.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ internal func _isClassOrObjCExistential<T>(_ x: T.Type) -> Bool {
193193
/// not much you can do with this other than use it to identify the
194194
/// object.
195195
@available(*, unavailable, message: "Removed in Swift 3. Use Unmanaged.passUnretained(x).toOpaque() instead.")
196-
public func unsafeAddress(of object: AnyObject) -> UnsafePointer<Void> {
196+
public func unsafeAddress(of object: AnyObject) -> UnsafeRawPointer {
197197
Builtin.unreachable()
198198
}
199199

200200
@available(*, unavailable, message: "Removed in Swift 3. Use Unmanaged.passUnretained(x).toOpaque() instead.")
201-
public func unsafeAddressOf(_ object: AnyObject) -> UnsafePointer<Void> {
201+
public func unsafeAddressOf(_ object: AnyObject) -> UnsafeRawPointer {
202202
Builtin.unreachable()
203203
}
204204

stdlib/public/core/Collection.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
/// In most cases, it's best to ignore this protocol and use the `Collection`
1717
/// protocol instead, because it has a more complete interface.
1818
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'Collection' instead")
19-
public protocol IndexableBase {
19+
public typealias IndexableBase = _IndexableBase
20+
public protocol _IndexableBase {
2021
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
2122
// to exist apart from missing compiler features that we emulate with it.
2223
// rdar://problem/20531108
@@ -159,7 +160,8 @@ public protocol IndexableBase {
159160
/// In most cases, it's best to ignore this protocol and use the `Collection`
160161
/// protocol instead, because it has a more complete interface.
161162
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'Collection' instead")
162-
public protocol Indexable : IndexableBase {
163+
public typealias Indexable = _Indexable
164+
public protocol _Indexable : _IndexableBase {
163165
/// A type used to represent the number of steps between two indices, where
164166
/// one value is reachable from the other.
165167
///
@@ -354,7 +356,7 @@ public protocol Indexable : IndexableBase {
354356
/// // Prints "15.0"
355357
/// // Prints "20.0"
356358
public struct IndexingIterator<
357-
Elements : IndexableBase
359+
Elements : _IndexableBase
358360
// FIXME(compiler limitation):
359361
// Elements : Collection
360362
> : IteratorProtocol, Sequence {
@@ -530,7 +532,7 @@ public struct IndexingIterator<
530532
/// forward or bidirectional collection must traverse the entire collection to
531533
/// count the number of contained elements, accessing its `count` property is
532534
/// an O(*n*) operation.
533-
public protocol Collection : Indexable, Sequence {
535+
public protocol Collection : _Indexable, Sequence {
534536
/// A type that can represent the number of steps between a pair of
535537
/// indices.
536538
associatedtype IndexDistance : SignedInteger = Int
@@ -555,7 +557,7 @@ public protocol Collection : Indexable, Sequence {
555557
/// This associated type appears as a requirement in the `Sequence`
556558
/// protocol, but it is restated here with stricter constraints. In a
557559
/// collection, the subsequence should also conform to `Collection`.
558-
associatedtype SubSequence : IndexableBase, Sequence = Slice<Self>
560+
associatedtype SubSequence : _IndexableBase, Sequence = Slice<Self>
559561
// FIXME(compiler limitation):
560562
// associatedtype SubSequence : Collection
561563
// where
@@ -614,7 +616,7 @@ public protocol Collection : Indexable, Sequence {
614616

615617
/// A type that can represent the indices that are valid for subscripting the
616618
/// collection, in ascending order.
617-
associatedtype Indices : IndexableBase, Sequence = DefaultIndices<Self>
619+
associatedtype Indices : _Indexable, Sequence = DefaultIndices<Self>
618620

619621
// FIXME(compiler limitation):
620622
// associatedtype Indices : Collection
@@ -859,7 +861,7 @@ public protocol Collection : Indexable, Sequence {
859861
}
860862

861863
/// Default implementation for forward collections.
862-
extension Indexable {
864+
extension _Indexable {
863865
/// Replaces the given index with its successor.
864866
///
865867
/// - Parameter i: A valid index of the collection. `i` must be less than
@@ -1702,7 +1704,7 @@ extension Collection {
17021704
public enum Bit {}
17031705

17041706
@available(*, unavailable, renamed: "IndexingIterator")
1705-
public struct IndexingGenerator<Elements : IndexableBase> {}
1707+
public struct IndexingGenerator<Elements : _IndexableBase> {}
17061708

17071709
@available(*, unavailable, renamed: "Collection")
17081710
public typealias CollectionType = Collection

stdlib/public/core/CollectionAlgorithms.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ ${orderingExplanation}
469469
}
470470
}
471471

472-
% for Self in 'Indexable', 'MutableIndexable':
472+
% for Self in '_Indexable', '_MutableIndexable':
473473
%{
474474

475475
subscriptCommentPre = """\

stdlib/public/core/CompilerProtocols.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@ public protocol ExpressibleByDictionaryLiteral {
614614
/// String(stringInterpolationSegment: price * number),
615615
/// String(stringInterpolationSegment: "."))
616616
@available(*, deprecated, message: "it will be replaced or redesigned in Swift 4.0. Instead of conforming to 'ExpressibleByStringInterpolation', consider adding an 'init(_:String)'")
617-
public protocol ExpressibleByStringInterpolation {
617+
public typealias ExpressibleByStringInterpolation = _ExpressibleByStringInterpolation
618+
public protocol _ExpressibleByStringInterpolation {
618619
/// Creates an instance by concatenating the given values.
619620
///
620621
/// Do not call this initializer directly. It is used by the compiler when

stdlib/public/core/ExistentialCollection.swift.gyb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,9 @@ protocol _AnyCollectionProtocol : Collection {
799799
public struct ${Self}<Element>
800800
: _AnyCollectionProtocol, ${SelfProtocol} {
801801

802+
// public typealias Indices
803+
// = Default${Traversal.replace('Forward', '')}Indices<${Self}>
804+
802805
internal init(_box: _${Self}Box<Element>) {
803806
self._box = _box
804807
}

stdlib/public/core/HashedCollections.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,7 @@ public func _dictionaryUpCast<DerivedKey, DerivedValue, BaseKey, BaseValue>(
22112211
var result = Dictionary<BaseKey, BaseValue>(minimumCapacity: source.count)
22122212

22132213
for (k, v) in source {
2214-
result[k as! BaseKey] = v as! BaseValue
2214+
result[k as! BaseKey] = (v as! BaseValue)
22152215
}
22162216
return result
22172217
}

stdlib/public/core/Indices.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ from gyb_stdlib_support import (
3030

3131
/// A collection of indices for an arbitrary ${collection}.
3232
public struct ${Self}<
33-
Elements : ${collectionForTraversal(Traversal).replace('Collection', 'Indexable')}
33+
Elements : _${collectionForTraversal(Traversal).replace('Collection', 'Indexable')}
3434
// FIXME(ABI)(compiler limitation):
3535
// Elements : Collection
3636
// rdar://problem/20531108

stdlib/public/core/MutableCollection.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
/// `MutableCollection` protocol instead, because it has a more complete
1717
/// interface.
1818
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'MutableCollection' instead")
19-
public protocol MutableIndexable : Indexable {
19+
public typealias MutableIndexable = _MutableIndexable
20+
public protocol _MutableIndexable : _Indexable {
2021
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
2122
// to exist apart from missing compiler features that we emulate with it.
2223
// rdar://problem/20531108
@@ -216,7 +217,7 @@ public protocol MutableIndexable : Indexable {
216217
/// // Must be equivalent to:
217218
/// a[i] = x
218219
/// let y = x
219-
public protocol MutableCollection : MutableIndexable, Collection {
220+
public protocol MutableCollection : _MutableIndexable, Collection {
220221
// FIXME: should be constrained to MutableCollection
221222
// (<rdar://problem/20715009> Implement recursive protocol
222223
// constraints)

stdlib/public/core/RandomAccessCollection.swift

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
/// `RandomAccessCollection` protocol instead, because it has a more complete
1717
/// interface.
1818
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'RandomAccessCollection' instead")
19-
public protocol RandomAccessIndexable : BidirectionalIndexable {
19+
public typealias RandomAccessIndexable = _RandomAccessIndexable
20+
public protocol _RandomAccessIndexable : _BidirectionalIndexable {
2021
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
2122
// to exist apart from missing compiler features that we emulate with it.
2223
// rdar://problem/20531108
@@ -46,21 +47,40 @@ public protocol RandomAccessIndexable : BidirectionalIndexable {
4647
/// `Strideable` protocol or you must implement the `index(_:offsetBy:)` and
4748
/// `distance(from:to:)` methods with O(1) efficiency.
4849
public protocol RandomAccessCollection :
49-
RandomAccessIndexable, BidirectionalCollection
50+
_RandomAccessIndexable, BidirectionalCollection
5051
{
5152
/// A collection that represents a contiguous subrange of the collection's
5253
/// elements.
53-
associatedtype SubSequence : RandomAccessIndexable, BidirectionalCollection
54+
associatedtype SubSequence : _RandomAccessIndexable, BidirectionalCollection
5455
= RandomAccessSlice<Self>
5556
// FIXME(compiler limitation):
5657
// associatedtype SubSequence : RandomAccessCollection
5758

5859
/// A type that can represent the indices that are valid for subscripting the
5960
/// collection, in ascending order.
60-
associatedtype Indices : RandomAccessIndexable, BidirectionalCollection
61+
associatedtype Indices : _RandomAccessIndexable, BidirectionalCollection
6162
= DefaultRandomAccessIndices<Self>
6263
// FIXME(compiler limitation):
6364
// associatedtype Indices : RandomAccessCollection
65+
66+
/// The indices that are valid for subscripting the collection, in ascending
67+
/// order.
68+
///
69+
/// A collection's `indices` property can hold a strong reference to the
70+
/// collection itself, causing the collection to be non-uniquely referenced.
71+
/// If you mutate the collection while iterating over its indices, a strong
72+
/// reference can cause an unexpected copy of the collection. To avoid the
73+
/// unexpected copy, use the `index(after:)` method starting with
74+
/// `startIndex` to produce indices instead.
75+
///
76+
/// var c = MyFancyCollection([10, 20, 30, 40, 50])
77+
/// var i = c.startIndex
78+
/// while i != c.endIndex {
79+
/// c[i] /= 5
80+
/// i = c.index(after: i)
81+
/// }
82+
/// // c == MyFancyCollection([2, 4, 6, 8, 10])
83+
var indices: Indices { get }
6484
}
6585

6686
/// Supply the default "slicing" `subscript` for `RandomAccessCollection`
@@ -103,7 +123,7 @@ extension RandomAccessCollection where SubSequence == RandomAccessSlice<Self> {
103123
// wrong complexity.
104124

105125
/// Default implementation for random access collections.
106-
extension RandomAccessIndexable {
126+
extension _RandomAccessIndexable {
107127
/// Returns an index that is the specified distance from the given index,
108128
/// unless that distance is beyond a given limiting index.
109129
///

0 commit comments

Comments
 (0)