Skip to content

Commit 2613b73

Browse files
authored
Merge pull request #4297 from rintaro/swift3-se-0118-unavailable
[swift-3.0-branch] stdlib: Add unavailable declarations for APIs renamed in SE-0118
2 parents 12f3d46 + fe6aec3 commit 2613b73

File tree

8 files changed

+129
-11
lines changed

8 files changed

+129
-11
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,18 +1369,18 @@ void swift::fixItAvailableAttrRename(TypeChecker &TC,
13691369
if (parsed.isMember()) {
13701370
diag.fixItReplace(call->getFn()->getSourceRange(), parsed.ContextName);
13711371

1372-
} else {
1373-
auto *dotCall = dyn_cast<DotSyntaxCallExpr>(call->getFn());
1374-
if (!dotCall)
1375-
return;
1376-
1372+
} else if (auto *dotCall = dyn_cast<DotSyntaxCallExpr>(call->getFn())) {
13771373
SourceLoc removeLoc = dotCall->getDotLoc();
13781374
if (removeLoc.isInvalid())
13791375
return;
13801376

13811377
diag.fixItRemove(SourceRange(removeLoc, dotCall->getFn()->getEndLoc()));
1378+
} else if (!isa<ConstructorRefCallExpr>(call->getFn())) {
1379+
return;
13821380
}
13831381

1382+
// Continue on to diagnose any constructor argument label renames.
1383+
13841384
} else {
13851385
// Just replace the base name.
13861386
SmallString<64> baseReplace;

stdlib/public/core/CollectionAlgorithms.swift.gyb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,22 @@ extension MutableCollection
597597
}
598598
}
599599

600+
extension Sequence {
601+
@available(*, unavailable, renamed: "sorted(by:)")
602+
public func sort(
603+
_ isOrderedBefore: (${IElement}, ${IElement}) -> Bool
604+
) -> [${IElement}] {
605+
Builtin.unreachable()
606+
}
607+
}
608+
609+
extension Sequence where ${IElement} : Comparable {
610+
@available(*, unavailable, renamed: "sorted()")
611+
public func sort() -> [${IElement}] {
612+
Builtin.unreachable()
613+
}
614+
}
615+
600616
extension MutableCollection
601617
where
602618
Self : RandomAccessCollection,
@@ -611,7 +627,7 @@ extension MutableCollection
611627
extension MutableCollection where Self : RandomAccessCollection {
612628
@available(*, unavailable, renamed: "sort(by:)")
613629
public mutating func sortInPlace(
614-
_ isOrderedBefore: (Iterator.Element, Iterator.Element) -> Bool
630+
_ isOrderedBefore: (${IElement}, ${IElement}) -> Bool
615631
) {
616632
Builtin.unreachable()
617633
}

stdlib/public/core/ManagedBuffer.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,31 @@ public func isKnownUniquelyReferenced<T : AnyObject>(
514514
return _isUnique(&object)
515515
}
516516

517+
518+
@available(*, unavailable, renamed: "ManagedBuffer")
519+
public typealias ManagedProtoBuffer<Header, Element> =
520+
ManagedBuffer<Header, Element>
521+
522+
extension ManagedBuffer {
523+
@available(*, unavailable, renamed: "create(minimumCapacity:makingHeaderWith:)")
524+
public final class func create(
525+
_ minimumCapacity: Int,
526+
initialValue: (ManagedBuffer<Header, Element>) -> Header
527+
) -> ManagedBuffer<Header, Element> {
528+
Builtin.unreachable()
529+
}
530+
}
531+
517532
extension ManagedBufferPointer {
533+
@available(*, unavailable, renamed: "init(bufferClass:minimumCapacity:makingHeaderWith:)")
534+
public init(
535+
bufferClass: AnyClass,
536+
minimumCapacity: Int,
537+
initialValue: (_ buffer: AnyObject, _ allocatedCount: (AnyObject) -> Int) -> Header
538+
) {
539+
Builtin.unreachable()
540+
}
541+
518542
@available(*, unavailable, renamed: "capacity")
519543
public var allocatedElementCount: Int {
520544
Builtin.unreachable()

stdlib/public/core/Sequence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ extension Sequence {
12621262
Builtin.unreachable()
12631263
}
12641264

1265-
@available(*, unavailable, message: "call 'split(maxSplits:omittingEmptySubsequences:isSeparator:)' and invert the 'allowEmptySlices' argument")
1265+
@available(*, unavailable, message: "call 'split(maxSplits:omittingEmptySubsequences:whereSeparator:)' and invert the 'allowEmptySlices' argument")
12661266
public func split(_ maxSplit: Int, allowEmptySlices: Bool,
12671267
isSeparator: (Iterator.Element) throws -> Bool
12681268
) rethrows -> [SubSequence] {

stdlib/public/core/SequenceAlgorithms.swift.gyb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,17 @@ extension Sequence {
745745
Builtin.unreachable()
746746
}
747747

748+
@available(*, unavailable, renamed: "elementsEqual(_:by:)")
749+
public func elementsEqual<OtherSequence>(
750+
_ other: OtherSequence,
751+
isEquivalent isEquivalent: (${GElement}, ${GElement}) throws -> Bool
752+
) rethrows -> Bool
753+
where
754+
OtherSequence: Sequence,
755+
OtherSequence.${GElement} == ${GElement} {
756+
Builtin.unreachable()
757+
}
758+
748759
@available(*, unavailable, renamed: "lexicographicallyPrecedes(_:by:)")
749760
public func lexicographicalCompare<
750761
OtherSequence
@@ -757,6 +768,21 @@ extension Sequence {
757768
OtherSequence.${GElement} == ${GElement} {
758769
Builtin.unreachable()
759770
}
771+
772+
@available(*, unavailable, renamed: "contains(where:)")
773+
public func contains(
774+
_ predicate: (${GElement}) throws -> Bool
775+
) rethrows -> Bool {
776+
Builtin.unreachable()
777+
}
778+
779+
@available(*, unavailable, renamed: "reduce(_:_:)")
780+
public func reduce<Result>(
781+
_ initial: Result,
782+
combine combine: (_ partialResult: Result, ${GElement}) throws -> Result
783+
) rethrows -> Result {
784+
Builtin.unreachable()
785+
}
760786
}
761787

762788
extension Sequence where Iterator.Element : Comparable {

stdlib/public/core/Unicode.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,16 @@ extension UnicodeCodec {
11381138
@available(*, unavailable, renamed: "UnicodeCodec")
11391139
public typealias UnicodeCodecType = UnicodeCodec
11401140

1141+
extension UnicodeCodec {
1142+
@available(*, unavailable, renamed: "encode(_:into:)")
1143+
public static func encode(
1144+
_ input: UnicodeScalar,
1145+
output put: (CodeUnit) -> Void
1146+
) {
1147+
Builtin.unreachable()
1148+
}
1149+
}
1150+
11411151
@available(*, unavailable, message: "use 'transcode(_:from:to:stoppingOnError:into:)'")
11421152
public func transcode<Input, InputEncoding, OutputEncoding>(
11431153
_ inputEncoding: InputEncoding.Type, _ outputEncoding: OutputEncoding.Type,

test/1_stdlib/Renames.swift

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,30 @@ func _CollectionAlgorithms<C : Collection>(c: C) {
9191
_ = c.indexOf { _ in true } // expected-error {{'indexOf' has been renamed to 'index(where:)'}} {{9-16=index}} {{none}}
9292
}
9393

94+
func _CollectionAlgorithms<C : Sequence>(c: C) {
95+
_ = c.sort { _, _ in true } // expected-error {{'sort' has been renamed to 'sorted(by:)'}} {{9-13=sorted}} {{none}}
96+
_ = c.sort({ _, _ in true }) // expected-error {{'sort' has been renamed to 'sorted(by:)'}} {{9-13=sorted}} {{14-14=by: }} {{none}}
97+
}
98+
func _CollectionAlgorithms<C : Sequence>(c: C) where C.Iterator.Element : Comparable {
99+
_ = c.sort() // expected-error {{'sort()' has been renamed to 'sorted()'}} {{9-13=sorted}} {{none}}
100+
}
101+
102+
func _CollectionAlgorithms<C : MutableCollection>(c: C) {
103+
_ = c.sort { _, _ in true } // expected-error {{'sort' has been renamed to 'sorted(by:)'}} {{9-13=sorted}} {{none}}
104+
_ = c.sort({ _, _ in true }) // expected-error {{'sort' has been renamed to 'sorted(by:)'}} {{9-13=sorted}} {{14-14=by: }} {{none}}
105+
}
106+
func _CollectionAlgorithms<C : MutableCollection>(c: C) where C.Iterator.Element : Comparable {
107+
_ = c.sort() // expected-error {{'sort()' has been renamed to 'sorted()'}} {{9-13=sorted}} {{none}}
108+
109+
var a: [Int] = [1,2,3]
110+
var _: [Int] = a.sort() // expected-error {{'sort()' has been renamed to 'sorted()'}} {{20-24=sorted}} {{none}}
111+
var _: [Int] = a.sort { _, _ in true } // expected-error {{'sort' has been renamed to 'sorted(by:)'}} {{20-24=sorted}} {{none}}
112+
var _: [Int] = a.sort({ _, _ in true }) // expected-error {{'sort' has been renamed to 'sorted(by:)'}} {{20-24=sorted}} {{25-25=by: }} {{none}}
113+
114+
_ = a.sort() // OK, in `Void`able context, `sort()` is a renamed `sortInPlace()`.
115+
_ = a.sort { _, _ in true } // OK, `Void`able context, `sort(by:)` is a renamed `sortInPlace(_:)`.
116+
}
117+
94118
func _CollectionOfOne<T>(i: IteratorOverOne<T>) {
95119
func fn(_: GeneratorOfOne<T>) {} // expected-error {{'GeneratorOfOne' has been renamed to 'IteratorOverOne'}} {{14-28=IteratorOverOne}} {{none}}
96120
_ = i.generate() // expected-error {{'generate()' has been renamed to 'makeIterator()'}} {{9-17=makeIterator}} {{none}}
@@ -281,8 +305,14 @@ func _LifetimeManager<T>(x: T) {
281305
_ = withUnsafePointers(&x, &x, &x) { _, _, _ in } // expected-error {{'withUnsafePointers' is unavailable: use nested withUnsafePointer(to:_:) instead}} {{none}}
282306
}
283307

284-
func _ManagedBuffer<V, E>(x: ManagedBufferPointer<V, E>) {
308+
func _ManagedBuffer<H, E>(x: ManagedBufferPointer<H, E>, h: H, bc: AnyClass) {
285309
_ = x.allocatedElementCount // expected-error {{'allocatedElementCount' has been renamed to 'capacity'}} {{9-30=capacity}} {{none}}
310+
_ = ManagedBuffer<H, E>.create(1) { _ in h } // expected-error {{'create(_:initialValue:)' has been renamed to 'create(minimumCapacity:makingHeaderWith:)'}} {{27-33=create}} {{34-34=minimumCapacity: }} {{none}}
311+
_ = ManagedBuffer<H, E>.create(1, initialValue: { _ in h }) // expected-error {{'create(_:initialValue:)' has been renamed to 'create(minimumCapacity:makingHeaderWith:)'}} {{27-33=create}} {{34-34=minimumCapacity: }} {{37-49=makingHeaderWith}} {{none}}
312+
_ = ManagedBufferPointer<H, E>(bufferClass: bc, minimumCapacity: 1, initialValue: { _, _ in h }) // expected-error {{'init(bufferClass:minimumCapacity:initialValue:)' has been renamed to 'init(bufferClass:minimumCapacity:makingHeaderWith:)'}} {{71-83=makingHeaderWith}} {{none}}
313+
_ = ManagedBufferPointer<H, E>(bufferClass: bc, minimumCapacity: 1) { _, _ in h } // OK
314+
315+
func fn(_: ManagedProtoBuffer<H, E>) {} // expected-error {{'ManagedProtoBuffer' has been renamed to 'ManagedBuffer'}} {{14-32=ManagedBuffer}} {{none}}
286316
}
287317

288318
func _Map() {
@@ -422,7 +452,7 @@ func _Sequence() {
422452
func _Sequence<S : Sequence>(s: S) {
423453
_ = s.generate() // expected-error {{'generate()' has been renamed to 'makeIterator()'}} {{9-17=makeIterator}} {{none}}
424454
_ = s.underestimateCount() // expected-error {{'underestimateCount()' has been replaced by 'underestimatedCount'}} {{9-27=underestimatedCount}} {{27-29=}} {{none}}
425-
_ = s.split(1, allowEmptySlices: true) { _ in true } // expected-error {{'split(_:allowEmptySlices:isSeparator:)' is unavailable: call 'split(maxSplits:omittingEmptySubsequences:isSeparator:)' and invert the 'allowEmptySlices' argument}} {{none}}
455+
_ = s.split(1, allowEmptySlices: true) { _ in true } // expected-error {{'split(_:allowEmptySlices:isSeparator:)' is unavailable: call 'split(maxSplits:omittingEmptySubsequences:whereSeparator:)' and invert the 'allowEmptySlices' argument}} {{none}}
426456
}
427457
func _Sequence<S : Sequence>(s: S, e: S.Iterator.Element) where S.Iterator.Element : Equatable {
428458
_ = s.split(e, maxSplit: 1, allowEmptySlices: true) // expected-error {{'split(_:maxSplit:allowEmptySlices:)' is unavailable: call 'split(separator:maxSplits:omittingEmptySubsequences:)' and invert the 'allowEmptySlices' argument}} {{none}}
@@ -434,7 +464,13 @@ func _SequenceAlgorithms<S : Sequence>(x: S) {
434464
_ = x.maxElement { _, _ in true } // expected-error {{'maxElement' has been renamed to 'max(by:)'}} {{9-19=max}} {{none}}
435465
_ = x.reverse() // expected-error {{'reverse()' has been renamed to 'reversed()'}} {{9-16=reversed}} {{none}}
436466
_ = x.startsWith([]) { _ in true } // expected-error {{'startsWith(_:isEquivalent:)' has been renamed to 'starts(with:by:)'}} {{9-19=starts}} {{20-20=with: }} {{none}}
467+
_ = x.elementsEqual([], isEquivalent: { _, _ in true }) // expected-error {{'elementsEqual(_:isEquivalent:)' has been renamed to 'elementsEqual(_:by:)'}} {{9-22=elementsEqual}} {{27-39=by}} {{none}}
468+
_ = x.elementsEqual([]) { _, _ in true } // OK
437469
_ = x.lexicographicalCompare([]) { _, _ in true } // expected-error {{'lexicographicalCompare(_:isOrderedBefore:)' has been renamed to 'lexicographicallyPrecedes(_:by:)'}} {{9-31=lexicographicallyPrecedes}}{{none}}
470+
_ = x.contains({ _ in true }) // expected-error {{'contains' has been renamed to 'contains(where:)'}} {{9-17=contains}} {{18-18=where: }} {{none}}
471+
_ = x.contains { _ in true } // OK
472+
_ = x.reduce(1, combine: { _, _ in 1 }) // expected-error {{'reduce(_:combine:)' has been renamed to 'reduce(_:_:)'}} {{9-15=reduce}} {{19-28=}} {{none}}
473+
_ = x.reduce(1) { _, _ in 1 } // OK
438474
}
439475
func _SequenceAlgorithms<S : Sequence>(x: S) where S.Iterator.Element : Comparable {
440476
_ = x.minElement() // expected-error {{'minElement()' has been renamed to 'min()'}} {{9-19=min}} {{none}}
@@ -509,9 +545,15 @@ func _StringLegacy(c: Character, u: UnicodeScalar) {
509545
_ = String(repeating: u, count: 1) // expected-error {{'init(repeating:count:)' is unavailable: Replaced by init(repeating: String, count: Int)}} {{none}}
510546
}
511547

512-
func _Unicode() {
548+
func _Unicode<C : UnicodeCodec>(s: UnicodeScalar, c: C.Type, out: (C.CodeUnit) -> Void) {
513549
func fn<T : UnicodeCodecType>(_: T) {} // expected-error {{'UnicodeCodecType' has been renamed to 'UnicodeCodec'}} {{15-31=UnicodeCodec}} {{none}}
550+
c.encode(s, output: out) // expected-error {{encode(_:output:)' has been renamed to 'encode(_:into:)}} {{5-11=encode}} {{15-21=into}} {{none}}
551+
c.encode(s) { _ in } // OK
552+
UTF8.encode(s, output: { _ in }) // expected-error {{'encode(_:output:)' has been renamed to 'encode(_:into:)'}} {{8-14=encode}} {{18-24=into}} {{none}}
553+
UTF16.encode(s, output: { _ in }) // expected-error {{'encode(_:output:)' has been renamed to 'encode(_:into:)'}} {{9-15=encode}} {{19-25=into}} {{none}}
554+
UTF32.encode(s, output: { _ in }) // expected-error {{'encode(_:output:)' has been renamed to 'encode(_:into:)'}} {{9-15=encode}} {{19-25=into}} {{none}}
514555
}
556+
515557
func _Unicode<I : IteratorProtocol, E : UnicodeCodec>(i: I, e: E.Type) where I.Element == E.CodeUnit {
516558
_ = transcode(e, e, i, { _ in }, stopOnError: true) // expected-error {{'transcode(_:_:_:_:stopOnError:)' is unavailable: use 'transcode(_:from:to:stoppingOnError:into:)'}} {{none}}
517559
_ = UTF16.measure(e, input: i, repairIllFormedSequences: true) // expected-error {{'measure(_:input:repairIllFormedSequences:)' is unavailable: use 'transcodedLength(of:decodedAs:repairingIllFormedSequences:)'}} {{none}}

test/1_stdlib/StringDiagnostics_without_Foundation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ func testStringCollectionTypes(s: String) {
2727
struct NotLosslessStringConvertible {}
2828

2929
func testStringInitT() {
30-
_ = String(NotLosslessStringConvertible()) // expected-error{{'init' has been renamed to 'init(describing:)}}
30+
_ = String(NotLosslessStringConvertible()) // expected-error{{'init' has been renamed to 'init(describing:)}}{{14-14=describing: }}
3131
}

0 commit comments

Comments
 (0)