diff --git a/stdlib/public/core/Collection.swift b/stdlib/public/core/Collection.swift index 1775f7a9e48..a12c9357e2d 100644 --- a/stdlib/public/core/Collection.swift +++ b/stdlib/public/core/Collection.swift @@ -216,7 +216,7 @@ extension CollectionType { } // A fast implementation for when you are backed by a contiguous array. -public func ~> >( +public func ~> >( source: T, ptr: (_InitializeTo, UnsafeMutablePointer)) { let s = source._baseAddressIfContiguous if s != nil { @@ -232,12 +232,10 @@ public func ~> >( } } -// Default implementation of `preprocessingPass` for *collections*. Do not -// use this operator directly; call `_preprocessingPass(s)` instead. -public func ~> ( - s: T, args: (_PreprocessingPass, ( (T)->R )) -) -> R? { - return args.1(s) +extension CollectionType { + final public func _preprocessingPass(preprocess: (Self)->R) -> R? { + return preprocess(self) + } } /// Returns `true` iff `x` is empty. diff --git a/stdlib/public/core/ContiguousArrayBuffer.swift b/stdlib/public/core/ContiguousArrayBuffer.swift index fe47445ea32..5d6041e73a0 100644 --- a/stdlib/public/core/ContiguousArrayBuffer.swift +++ b/stdlib/public/core/ContiguousArrayBuffer.swift @@ -548,7 +548,7 @@ extension _ContiguousArrayBuffer : CollectionType { } public func ~> < - S : _Sequence_Type + S : SequenceType >( source: S, _: (_CopyToNativeArrayBuffer,()) ) -> _ContiguousArrayBuffer diff --git a/stdlib/public/core/Join.swift b/stdlib/public/core/Join.swift index ebecd5f47e0..56a99feb9cf 100644 --- a/stdlib/public/core/Join.swift +++ b/stdlib/public/core/Join.swift @@ -156,7 +156,7 @@ public func join< let separatorSize = separator.count // FIXME: include separator - let reservation = elements~>_preprocessingPass { + let reservation = elements._preprocessingPass { (s: S) -> C.Index.Distance in let r: C.Index.Distance = s.reduce(0) { $0 + separatorSize + $1.count } return r - separatorSize diff --git a/stdlib/public/core/Sequence.swift b/stdlib/public/core/Sequence.swift index f37c3b4c911..f3cdb1a7abd 100644 --- a/stdlib/public/core/Sequence.swift +++ b/stdlib/public/core/Sequence.swift @@ -37,20 +37,18 @@ public protocol GeneratorType { mutating func next() -> Element? } -/// This protocol is an implementation detail of `SequenceType`; do -/// not use it directly. +/// A type that can be iterated with a `for`...`in` loop. /// -/// Its requirements are inherited by `SequenceType` and thus must -/// be satisfied by types conforming to that protocol. -public protocol _Sequence_Type { - - /// A type whose instances can produce the elements of this - /// sequence, in order. +/// `SequenceType` makes no requirement on conforming types regarding +/// whether they will be destructively "consumed" by iteration. To +/// ensure non-destructive iteration, constrain your *sequence* to +/// `CollectionType`. +public protocol SequenceType { + /// A type that provides the *sequence*'s iteration interface and + /// encapsulates its iteration state. typealias Generator : GeneratorType - /// Return a *generator* over the elements of this *sequence*. The - /// *generator*'s next element is the first element of the - /// sequence. + /// Return a *generator* over the elements of this *sequence*. /// /// - Complexity: O(1). func generate() -> Generator @@ -78,27 +76,11 @@ public protocol _Sequence_Type { func _customContainsEquatableElement( element: Generator.Element ) -> Bool? -} - -/// A type that can be iterated with a `for`...`in` loop. -/// -/// `SequenceType` makes no requirement on conforming types regarding -/// whether they will be destructively "consumed" by iteration. To -/// ensure non-destructive iteration, constrain your *sequence* to -/// `CollectionType`. -public protocol SequenceType : _Sequence_Type { - /// A type that provides the *sequence*'s iteration interface and - /// encapsulates its iteration state. - typealias Generator : GeneratorType - - /// Return a *generator* over the elements of this *sequence*. - /// - /// - Complexity: O(1). - func generate() -> Generator - - /// If `self` is multi-pass (i.e., a `CollectionType`), invoke the function - /// on `self` and return its result. Otherwise, return `nil`. - func ~> (_: Self, _: (_PreprocessingPass, ((Self)->R))) -> R? + + /// If `self` is multi-pass (i.e., a `CollectionType`), invoke + /// `preprocess` on `self` and return its result. Otherwise, return + /// `nil`. + func _preprocessingPass(preprocess: (Self)->R) -> R? /// Create a native array buffer containing the elements of `self`, /// in the same order. @@ -118,6 +100,10 @@ extension SequenceType { final public func underestimateCount() -> Int { return 0 } + + final public func _preprocessingPass(preprocess: (Self)->R) -> R? { + return nil + } } extension SequenceType { @@ -177,7 +163,7 @@ internal func _initializeTo(a: Args) -> (_InitializeTo, Args) { return (_InitializeTo(), a) } -public func ~> ( +public func ~> ( source: T, ptr: (_InitializeTo, UnsafeMutablePointer)) { var p = UnsafeMutablePointer(ptr.1) for x in GeneratorSequence(source.generate()) { @@ -185,24 +171,6 @@ public func ~> ( } } -// Operation tags for preprocessingPass. See Index.swift for an -// explanation of operation tags. -public struct _PreprocessingPass {} - -// Default implementation of `_preprocessingPass` for Sequences. Do not -// use this operator directly; call `_preprocessingPass(s)` instead -public func ~> < - T : _Sequence_Type, R ->(s: T, _: (_PreprocessingPass, ( (T)->R ))) -> R? { - return nil -} - -internal func _preprocessingPass(args: Args) - -> (_PreprocessingPass, Args) -{ - return (_PreprocessingPass(), args) -} - // Pending and , // pass a GeneratorType through GeneratorSequence to give it "SequenceType-ness" /// A sequence built around a generator of type `G`. diff --git a/stdlib/public/core/StringCore.swift b/stdlib/public/core/StringCore.swift index b087a945f8b..401271cb746 100644 --- a/stdlib/public/core/StringCore.swift +++ b/stdlib/public/core/StringCore.swift @@ -596,7 +596,7 @@ extension _StringCore : ExtensibleCollectionType { >(s: S) { var width = elementWidth if width == 1 { - if let hasNonAscii = s~>_preprocessingPass({ + if let hasNonAscii = s._preprocessingPass({ s in s.contains { $0 > 0x7f } }) { width = hasNonAscii ? 2 : 1 diff --git a/test/Constraints/generic_protocol_witness.swift b/test/Constraints/generic_protocol_witness.swift index 4ab2807e258..cc3010861c9 100644 --- a/test/Constraints/generic_protocol_witness.swift +++ b/test/Constraints/generic_protocol_witness.swift @@ -56,7 +56,7 @@ func usesAGenericMethod(x: U) { x.method(5) } -struct L: SequenceType {} // expected-error {{type 'L' does not conform to protocol '_Sequence_Type'}} expected-error {{type 'L' does not conform to protocol 'SequenceType'}} +struct L: SequenceType {} // expected-error {{type 'L' does not conform to protocol 'SequenceType'}} func z(x: L) { for xx in x {} // expected-error{{'L' does not have a member named 'Generator'}} diff --git a/test/SILGen/witness_same_type.swift b/test/SILGen/witness_same_type.swift index b89200de382..99829ab949f 100644 --- a/test/SILGen/witness_same_type.swift +++ b/test/SILGen/witness_same_type.swift @@ -18,7 +18,7 @@ struct Foo: Fooable { } // rdar://problem/19049566 -// CHECK-LABEL: sil [transparent] [thunk] @_TTWu0_Rq_Ss12SequenceTypezq0_qqq_S_9GeneratorSs13GeneratorType7Element_GV17witness_same_type14LazySequenceOfq_q0__Ss14_Sequence_TypeS1_FS3_8generateuRq_S3__fq_FT_qq_S3_9Generator +// CHECK-LABEL: sil [transparent] [thunk] @_TTWu0_Rq_Ss12SequenceTypezq0_qqq_S_9GeneratorSs13GeneratorType7Element_GV17witness_same_type14LazySequenceOfq_q0__S_S1_FS_8generateuRq_S__fq_FT_qq_S_9Generator public struct LazySequenceOf : SequenceType { public func generate() -> AnyGenerator { var opt: AnyGenerator? diff --git a/test/stmt/foreach.swift b/test/stmt/foreach.swift index e8244b5ea43..4de83d1f578 100644 --- a/test/stmt/foreach.swift +++ b/test/stmt/foreach.swift @@ -8,7 +8,7 @@ func bad_containers_1(bc: BadContainer1) { for e in bc { } // expected-error{{type 'BadContainer1' does not conform to protocol 'SequenceType'}} } -struct BadContainer2 : SequenceType { // expected-error{{type 'BadContainer2' does not conform to protocol '_Sequence_Type'}} expected-error{{type 'BadContainer2' does not conform to protocol 'SequenceType'}} +struct BadContainer2 : SequenceType { // expected-error{{type 'BadContainer2' does not conform to protocol 'SequenceType'}} var generate : Int } @@ -16,7 +16,7 @@ func bad_containers_2(bc: BadContainer2) { for e in bc { } // expected-error{{'BadContainer2' does not have a member named 'Generator'}} } -struct BadContainer3 : SequenceType { // expected-error{{type 'BadContainer3' does not conform to protocol '_Sequence_Type'}} expected-error{{type 'BadContainer3' does not conform to protocol 'SequenceType'}} +struct BadContainer3 : SequenceType { // expected-error{{type 'BadContainer3' does not conform to protocol 'SequenceType'}} func generate() { } // expected-note{{inferred type '()' (by matching requirement 'generate()') is invalid: does not conform to 'GeneratorType'}} } @@ -28,8 +28,8 @@ struct BadGeneratorType1 { } -struct BadContainer4 : SequenceType { // expected-error{{type 'BadContainer4' does not conform to protocol 'SequenceType'}} expected-error{{type 'BadContainer4' does not conform to protocol '_Sequence_Type'}} - typealias Generator = BadGeneratorType1 // expected-note{{possibly intended match 'Generator' does not conform to 'GeneratorType'}} expected-note{{possibly intended match 'Generator' does not conform to 'GeneratorType'}} +struct BadContainer4 : SequenceType { // expected-error{{type 'BadContainer4' does not conform to protocol 'SequenceType'}} + typealias Generator = BadGeneratorType1 // expected-note{{possibly intended match 'Generator' does not conform to 'GeneratorType'}} func generate() -> BadGeneratorType1 { } }