Skip to content

Commit b853d07

Browse files
committed
---
yaml --- r: 344942 b: refs/heads/master c: 1813ecb h: refs/heads/master
1 parent 9b30281 commit b853d07

File tree

9 files changed

+196
-17
lines changed

9 files changed

+196
-17
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: ddd80761bdd846695f9e0b2851c3009384e5a766
2+
refs/heads/master: 1813ecb85e36a98b71e3c32fc07344a32455d764
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/stdlib/public/core/BidirectionalCollection.swift

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@
3737
/// `c.index(after: c.index(before: i)) == i`.
3838
public protocol BidirectionalCollection: Collection
3939
where SubSequence: BidirectionalCollection, Indices: BidirectionalCollection {
40+
// FIXME(ABI): Associated type inference requires this.
41+
associatedtype Element
42+
43+
// FIXME(ABI): Associated type inference requires this.
44+
associatedtype Index
45+
46+
// FIXME(ABI): Associated type inference requires this.
47+
associatedtype SubSequence
48+
4049
// FIXME(ABI): Associated type inference requires this.
4150
associatedtype Indices
4251

@@ -53,6 +62,23 @@ where SubSequence: BidirectionalCollection, Indices: BidirectionalCollection {
5362
/// `startIndex`.
5463
func formIndex(before i: inout Index)
5564

65+
/// Returns the position immediately after the given index.
66+
///
67+
/// The successor of an index must be well defined. For an index `i` into a
68+
/// collection `c`, calling `c.index(after: i)` returns the same index every
69+
/// time.
70+
///
71+
/// - Parameter i: A valid index of the collection. `i` must be less than
72+
/// `endIndex`.
73+
/// - Returns: The index value immediately after `i`.
74+
func index(after i: Index) -> Index
75+
76+
/// Replaces the given index with its successor.
77+
///
78+
/// - Parameter i: A valid index of the collection. `i` must be less than
79+
/// `endIndex`.
80+
func formIndex(after i: inout Index)
81+
5682
/// Returns an index that is the specified distance from the given index.
5783
///
5884
/// The following example obtains an index advanced four positions from a
@@ -146,6 +172,25 @@ where SubSequence: BidirectionalCollection, Indices: BidirectionalCollection {
146172
/// resulting distance.
147173
func distance(from start: Index, to end: Index) -> Int
148174

175+
/// The indices that are valid for subscripting the collection, in ascending
176+
/// order.
177+
///
178+
/// A collection's `indices` property can hold a strong reference to the
179+
/// collection itself, causing the collection to be non-uniquely referenced.
180+
/// If you mutate the collection while iterating over its indices, a strong
181+
/// reference can cause an unexpected copy of the collection. To avoid the
182+
/// unexpected copy, use the `index(after:)` method starting with
183+
/// `startIndex` to produce indices instead.
184+
///
185+
/// var c = MyFancyCollection([10, 20, 30, 40, 50])
186+
/// var i = c.startIndex
187+
/// while i != c.endIndex {
188+
/// c[i] /= 5
189+
/// i = c.index(after: i)
190+
/// }
191+
/// // c == MyFancyCollection([2, 4, 6, 8, 10])
192+
var indices: Indices { get }
193+
149194
// TODO: swift-3-indexing-model: tests.
150195
/// The last element of the collection.
151196
///
@@ -159,6 +204,40 @@ where SubSequence: BidirectionalCollection, Indices: BidirectionalCollection {
159204
///
160205
/// - Complexity: O(1)
161206
var last: Element? { get }
207+
208+
/// Accesses a contiguous subrange of the collection's elements.
209+
///
210+
/// The accessed slice uses the same indices for the same elements as the
211+
/// original collection uses. Always use the slice's `startIndex` property
212+
/// instead of assuming that its indices start at a particular value.
213+
///
214+
/// This example demonstrates getting a slice of an array of strings, finding
215+
/// the index of one of the strings in the slice, and then using that index
216+
/// in the original array.
217+
///
218+
/// let streets = ["Adams", "Bryant", "Channing", "Douglas", "Evarts"]
219+
/// let streetsSlice = streets[2 ..< streets.endIndex]
220+
/// print(streetsSlice)
221+
/// // Prints "["Channing", "Douglas", "Evarts"]"
222+
///
223+
/// let index = streetsSlice.firstIndex(of: "Evarts") // 4
224+
/// print(streets[index!])
225+
/// // Prints "Evarts"
226+
///
227+
/// - Parameter bounds: A range of the collection's indices. The bounds of
228+
/// the range must be valid indices of the collection.
229+
///
230+
/// - Complexity: O(1)
231+
subscript(bounds: Range<Index>) -> SubSequence { get }
232+
233+
// FIXME(ABI): Associated type inference requires this.
234+
subscript(position: Index) -> Element { get }
235+
236+
// FIXME(ABI): Associated type inference requires this.
237+
var startIndex: Index { get }
238+
239+
// FIXME(ABI): Associated type inference requires this.
240+
var endIndex: Index { get }
162241
}
163242

164243
/// Default implementation for bidirectional collections.

trunk/stdlib/public/core/MutableCollection.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,17 @@
5858
/// a[i] = x
5959
/// let y = x
6060
public protocol MutableCollection: Collection
61-
where SubSequence: MutableCollection {
61+
where SubSequence: MutableCollection
62+
{
63+
// FIXME(ABI): Associated type inference requires this.
64+
associatedtype Element
65+
66+
// FIXME(ABI): Associated type inference requires this.
67+
associatedtype Index
68+
69+
// FIXME(ABI): Associated type inference requires this.
70+
associatedtype SubSequence
71+
6272
/// Accesses the element at the specified position.
6373
///
6474
/// For example, you can replace an element of an array by using its

trunk/stdlib/public/core/RandomAccessCollection.swift

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,39 @@
3131
/// `Strideable` protocol or you must implement the `index(_:offsetBy:)` and
3232
/// `distance(from:to:)` methods with O(1) efficiency.
3333
public protocol RandomAccessCollection: BidirectionalCollection
34-
where SubSequence: RandomAccessCollection, Indices: RandomAccessCollection {
34+
where SubSequence: RandomAccessCollection, Indices: RandomAccessCollection
35+
{
36+
// FIXME(ABI): Associated type inference requires this.
37+
associatedtype Element
38+
39+
// FIXME(ABI): Associated type inference requires this.
40+
associatedtype Index
41+
42+
// FIXME(ABI): Associated type inference requires this.
43+
associatedtype SubSequence
44+
45+
// FIXME(ABI): Associated type inference requires this.
46+
associatedtype Indices
47+
48+
/// The indices that are valid for subscripting the collection, in ascending
49+
/// order.
50+
///
51+
/// A collection's `indices` property can hold a strong reference to the
52+
/// collection itself, causing the collection to be nonuniquely referenced.
53+
/// If you mutate the collection while iterating over its indices, a strong
54+
/// reference can result in an unexpected copy of the collection. To avoid
55+
/// the unexpected copy, use the `index(after:)` method starting with
56+
/// `startIndex` to produce indices instead.
57+
///
58+
/// var c = MyFancyCollection([10, 20, 30, 40, 50])
59+
/// var i = c.startIndex
60+
/// while i != c.endIndex {
61+
/// c[i] /= 5
62+
/// i = c.index(after: i)
63+
/// }
64+
/// // c == MyFancyCollection([2, 4, 6, 8, 10])
65+
var indices: Indices { get }
66+
3567
/// Accesses a contiguous subrange of the collection's elements.
3668
///
3769
/// The accessed slice uses the same indices for the same elements as the
@@ -57,6 +89,45 @@ where SubSequence: RandomAccessCollection, Indices: RandomAccessCollection {
5789
/// - Complexity: O(1)
5890
subscript(bounds: Range<Index>) -> SubSequence { get }
5991

92+
// FIXME(ABI): Associated type inference requires this.
93+
subscript(position: Index) -> Element { get }
94+
95+
// FIXME(ABI): Associated type inference requires this.
96+
var startIndex: Index { get }
97+
98+
// FIXME(ABI): Associated type inference requires this.
99+
var endIndex: Index { get }
100+
101+
/// Returns the position immediately before the given index.
102+
///
103+
/// - Parameter i: A valid index of the collection. `i` must be greater than
104+
/// `startIndex`.
105+
/// - Returns: The index value immediately before `i`.
106+
func index(before i: Index) -> Index
107+
108+
/// Replaces the given index with its predecessor.
109+
///
110+
/// - Parameter i: A valid index of the collection. `i` must be greater than
111+
/// `startIndex`.
112+
func formIndex(before i: inout Index)
113+
114+
/// Returns the position immediately after the given index.
115+
///
116+
/// The successor of an index must be well defined. For an index `i` into a
117+
/// collection `c`, calling `c.index(after: i)` returns the same index every
118+
/// time.
119+
///
120+
/// - Parameter i: A valid index of the collection. `i` must be less than
121+
/// `endIndex`.
122+
/// - Returns: The index value immediately after `i`.
123+
func index(after i: Index) -> Index
124+
125+
/// Replaces the given index with its successor.
126+
///
127+
/// - Parameter i: A valid index of the collection. `i` must be less than
128+
/// `endIndex`.
129+
func formIndex(after i: inout Index)
130+
60131
/// Returns an index that is the specified distance from the given index.
61132
///
62133
/// The following example obtains an index advanced four positions from a

trunk/stdlib/public/core/RangeReplaceableCollection.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@
6262
/// parameter. You can override any of the protocol's required methods to
6363
/// provide your own custom implementation.
6464
public protocol RangeReplaceableCollection : Collection
65-
where SubSequence : RangeReplaceableCollection {
65+
where SubSequence : RangeReplaceableCollection {
66+
// FIXME(ABI): Associated type inference requires this.
67+
associatedtype SubSequence
6668

6769
//===--- Fundamental Requirements ---------------------------------------===//
6870

@@ -145,7 +147,8 @@ where SubSequence : RangeReplaceableCollection {
145147
///
146148
/// - Parameter elements: The sequence of elements for the new collection.
147149
/// `elements` must be finite.
148-
init<S : Sequence>(_ elements: S) where S.Element == Element
150+
init<S : Sequence>(_ elements: S)
151+
where S.Element == Element
149152

150153
/// Adds an element to the end of the collection.
151154
///
@@ -358,6 +361,12 @@ where SubSequence : RangeReplaceableCollection {
358361
/// - Complexity: O(*n*), where *n* is the length of the collection.
359362
mutating func removeAll(
360363
where shouldBeRemoved: (Element) throws -> Bool) rethrows
364+
365+
// FIXME(ABI): Associated type inference requires this.
366+
subscript(bounds: Index) -> Element { get }
367+
368+
// FIXME(ABI): Associated type inference requires this.
369+
subscript(bounds: Range<Index>) -> SubSequence { get }
361370
}
362371

363372
//===----------------------------------------------------------------------===//
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@objc class ClassInOtherFile {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@class ClassInOtherFile;
2+
3+
@interface Base
4+
- (ClassInOtherFile *)getClassInstanceWithoutMentioningItsName;
5+
@end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend -emit-ir -primary-file %s %S/Inputs/forward-declarations-other.swift -import-objc-header %S/Inputs/forward-declarations.h -enable-objc-interop -disable-objc-attr-requires-foundation-module -module-name main | %FileCheck %s
2+
3+
class Sub: Base {
4+
// CHECK-LABEL: define{{.*}} void @"$S4main3SubC4testyyF"
5+
func test() {
6+
// CHECK: [[BASE_SELF:%.+]] = bitcast %T4main3SubC* %0 to %TSo4BaseC*
7+
// CHECK: [[SELECTOR:%.+]] = load i8*, i8** @"\01L_selector(getClassInstanceWithoutMentioningItsName)"
8+
// CHECK: [[OPAQUE_SELF:%.+]] = bitcast %TSo4BaseC* %2 to {{%.+}}*
9+
// CHECK: [[RESULT:%.+]] = call {{%.+}}* bitcast (void ()* @objc_msgSend to {{%.+}}* ({{%.+}}*, i8*)*)({{%.+}}* [[OPAQUE_SELF]], i8* [[SELECTOR]])
10+
// CHECK: [[OPAQUE_RESULT:%.+]] = bitcast {{%.+}}* [[RESULT]] to i8*
11+
// CHECK: call i8* @objc_retainAutoreleasedReturnValue(i8* [[OPAQUE_RESULT]])
12+
_ = self.getClassInstanceWithoutMentioningItsName()
13+
// CHECK: call void @swift_release(%swift.refcounted* {{%.+}})
14+
// CHECK: ret void
15+
}
16+
}

trunk/test/api-digester/source-stability.swift.expected

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ TypeAlias StringProtocol.UTF16Index has been removed (deprecated)
1414
TypeAlias StringProtocol.UTF8Index has been removed (deprecated)
1515
TypeAlias StringProtocol.UnicodeScalarIndex has been removed (deprecated)
1616
TypeAlias UIntMax has been removed
17-
Var BidirectionalCollection.endIndex has been removed
18-
Var BidirectionalCollection.indices has been removed
19-
Var BidirectionalCollection.startIndex has been removed
2017
Var FixedWidthInteger.allZeros has been removed (deprecated)
21-
Var RandomAccessCollection.endIndex has been removed
22-
Var RandomAccessCollection.indices has been removed
23-
Var RandomAccessCollection.startIndex has been removed
2418
Constructor Int.init(truncatingBitPattern:) has been removed
2519
Constructor Int16.init(truncatingBitPattern:) has been removed
2620
Constructor Int32.init(truncatingBitPattern:) has been removed
@@ -30,8 +24,6 @@ Constructor UInt.init(truncatingBitPattern:) has been removed
3024
Constructor UInt16.init(truncatingBitPattern:) has been removed
3125
Constructor UInt32.init(truncatingBitPattern:) has been removed
3226
Constructor UInt8.init(truncatingBitPattern:) has been removed
33-
Func BidirectionalCollection.formIndex(after:) has been removed
34-
Func BidirectionalCollection.index(after:) has been removed
3527
Func BinaryInteger.toIntMax() has been removed
3628
Func FixedWidthInteger.addWithOverflow(_:_:) has been removed
3729
Func FixedWidthInteger.divideWithOverflow(_:_:) has been removed
@@ -53,10 +45,6 @@ Func Int16.toUIntMax() has been removed
5345
Func Int32.toUIntMax() has been removed
5446
Func Int64.toUIntMax() has been removed
5547
Func Int8.toUIntMax() has been removed
56-
Func RandomAccessCollection.formIndex(after:) has been removed
57-
Func RandomAccessCollection.formIndex(before:) has been removed
58-
Func RandomAccessCollection.index(after:) has been removed
59-
Func RandomAccessCollection.index(before:) has been removed
6048
Func Sequence.flatMap(_:) has been removed
6149
Func SignedNumeric.abs(_:) has been removed
6250
Func String.UTF16View.distance(from:to:) has been removed

0 commit comments

Comments
 (0)