Skip to content

[swift-3.0-branch] stdlib: Add unavailable declarations for APIs renamed in SE-0118 #4297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1369,18 +1369,18 @@ void swift::fixItAvailableAttrRename(TypeChecker &TC,
if (parsed.isMember()) {
diag.fixItReplace(call->getFn()->getSourceRange(), parsed.ContextName);

} else {
auto *dotCall = dyn_cast<DotSyntaxCallExpr>(call->getFn());
if (!dotCall)
return;

} else if (auto *dotCall = dyn_cast<DotSyntaxCallExpr>(call->getFn())) {
SourceLoc removeLoc = dotCall->getDotLoc();
if (removeLoc.isInvalid())
return;

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

// Continue on to diagnose any constructor argument label renames.

} else {
// Just replace the base name.
SmallString<64> baseReplace;
Expand Down
18 changes: 17 additions & 1 deletion stdlib/public/core/CollectionAlgorithms.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,22 @@ extension MutableCollection
}
}

extension Sequence {
@available(*, unavailable, renamed: "sorted(by:)")
public func sort(
_ isOrderedBefore: (${IElement}, ${IElement}) -> Bool
) -> [${IElement}] {
Builtin.unreachable()
}
}

extension Sequence where ${IElement} : Comparable {
@available(*, unavailable, renamed: "sorted()")
public func sort() -> [${IElement}] {
Builtin.unreachable()
}
}

extension MutableCollection
where
Self : RandomAccessCollection,
Expand All @@ -611,7 +627,7 @@ extension MutableCollection
extension MutableCollection where Self : RandomAccessCollection {
@available(*, unavailable, renamed: "sort(by:)")
public mutating func sortInPlace(
_ isOrderedBefore: (Iterator.Element, Iterator.Element) -> Bool
_ isOrderedBefore: (${IElement}, ${IElement}) -> Bool
) {
Builtin.unreachable()
}
Expand Down
24 changes: 24 additions & 0 deletions stdlib/public/core/ManagedBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,31 @@ public func isKnownUniquelyReferenced<T : AnyObject>(
return _isUnique(&object)
}


@available(*, unavailable, renamed: "ManagedBuffer")
public typealias ManagedProtoBuffer<Header, Element> =
ManagedBuffer<Header, Element>

extension ManagedBuffer {
@available(*, unavailable, renamed: "create(minimumCapacity:makingHeaderWith:)")
public final class func create(
_ minimumCapacity: Int,
initialValue: (ManagedBuffer<Header, Element>) -> Header
) -> ManagedBuffer<Header, Element> {
Builtin.unreachable()
}
}

extension ManagedBufferPointer {
@available(*, unavailable, renamed: "init(bufferClass:minimumCapacity:makingHeaderWith:)")
public init(
bufferClass: AnyClass,
minimumCapacity: Int,
initialValue: (_ buffer: AnyObject, _ allocatedCount: (AnyObject) -> Int) -> Header
) {
Builtin.unreachable()
}

@available(*, unavailable, renamed: "capacity")
public var allocatedElementCount: Int {
Builtin.unreachable()
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Sequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ extension Sequence {
Builtin.unreachable()
}

@available(*, unavailable, message: "call 'split(maxSplits:omittingEmptySubsequences:isSeparator:)' and invert the 'allowEmptySlices' argument")
@available(*, unavailable, message: "call 'split(maxSplits:omittingEmptySubsequences:whereSeparator:)' and invert the 'allowEmptySlices' argument")
public func split(_ maxSplit: Int, allowEmptySlices: Bool,
isSeparator: (Iterator.Element) throws -> Bool
) rethrows -> [SubSequence] {
Expand Down
26 changes: 26 additions & 0 deletions stdlib/public/core/SequenceAlgorithms.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,17 @@ extension Sequence {
Builtin.unreachable()
}

@available(*, unavailable, renamed: "elementsEqual(_:by:)")
public func elementsEqual<OtherSequence>(
_ other: OtherSequence,
isEquivalent isEquivalent: (${GElement}, ${GElement}) throws -> Bool
) rethrows -> Bool
where
OtherSequence: Sequence,
OtherSequence.${GElement} == ${GElement} {
Builtin.unreachable()
}

@available(*, unavailable, renamed: "lexicographicallyPrecedes(_:by:)")
public func lexicographicalCompare<
OtherSequence
Expand All @@ -757,6 +768,21 @@ extension Sequence {
OtherSequence.${GElement} == ${GElement} {
Builtin.unreachable()
}

@available(*, unavailable, renamed: "contains(where:)")
public func contains(
_ predicate: (${GElement}) throws -> Bool
) rethrows -> Bool {
Builtin.unreachable()
}

@available(*, unavailable, renamed: "reduce(_:_:)")
public func reduce<Result>(
_ initial: Result,
combine combine: (_ partialResult: Result, ${GElement}) throws -> Result
) rethrows -> Result {
Builtin.unreachable()
}
}

extension Sequence where Iterator.Element : Comparable {
Expand Down
10 changes: 10 additions & 0 deletions stdlib/public/core/Unicode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,16 @@ extension UnicodeCodec {
@available(*, unavailable, renamed: "UnicodeCodec")
public typealias UnicodeCodecType = UnicodeCodec

extension UnicodeCodec {
@available(*, unavailable, renamed: "encode(_:into:)")
public static func encode(
_ input: UnicodeScalar,
output put: (CodeUnit) -> Void
) {
Builtin.unreachable()
}
}

@available(*, unavailable, message: "use 'transcode(_:from:to:stoppingOnError:into:)'")
public func transcode<Input, InputEncoding, OutputEncoding>(
_ inputEncoding: InputEncoding.Type, _ outputEncoding: OutputEncoding.Type,
Expand Down
48 changes: 45 additions & 3 deletions test/1_stdlib/Renames.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,30 @@ func _CollectionAlgorithms<C : Collection>(c: C) {
_ = c.indexOf { _ in true } // expected-error {{'indexOf' has been renamed to 'index(where:)'}} {{9-16=index}} {{none}}
}

func _CollectionAlgorithms<C : Sequence>(c: C) {
_ = c.sort { _, _ in true } // expected-error {{'sort' has been renamed to 'sorted(by:)'}} {{9-13=sorted}} {{none}}
_ = c.sort({ _, _ in true }) // expected-error {{'sort' has been renamed to 'sorted(by:)'}} {{9-13=sorted}} {{14-14=by: }} {{none}}
}
func _CollectionAlgorithms<C : Sequence>(c: C) where C.Iterator.Element : Comparable {
_ = c.sort() // expected-error {{'sort()' has been renamed to 'sorted()'}} {{9-13=sorted}} {{none}}
}

func _CollectionAlgorithms<C : MutableCollection>(c: C) {
_ = c.sort { _, _ in true } // expected-error {{'sort' has been renamed to 'sorted(by:)'}} {{9-13=sorted}} {{none}}
_ = c.sort({ _, _ in true }) // expected-error {{'sort' has been renamed to 'sorted(by:)'}} {{9-13=sorted}} {{14-14=by: }} {{none}}
}
func _CollectionAlgorithms<C : MutableCollection>(c: C) where C.Iterator.Element : Comparable {
_ = c.sort() // expected-error {{'sort()' has been renamed to 'sorted()'}} {{9-13=sorted}} {{none}}

var a: [Int] = [1,2,3]
var _: [Int] = a.sort() // expected-error {{'sort()' has been renamed to 'sorted()'}} {{20-24=sorted}} {{none}}
var _: [Int] = a.sort { _, _ in true } // expected-error {{'sort' has been renamed to 'sorted(by:)'}} {{20-24=sorted}} {{none}}
var _: [Int] = a.sort({ _, _ in true }) // expected-error {{'sort' has been renamed to 'sorted(by:)'}} {{20-24=sorted}} {{25-25=by: }} {{none}}

_ = a.sort() // OK, in `Void`able context, `sort()` is a renamed `sortInPlace()`.
_ = a.sort { _, _ in true } // OK, `Void`able context, `sort(by:)` is a renamed `sortInPlace(_:)`.
}

func _CollectionOfOne<T>(i: IteratorOverOne<T>) {
func fn(_: GeneratorOfOne<T>) {} // expected-error {{'GeneratorOfOne' has been renamed to 'IteratorOverOne'}} {{14-28=IteratorOverOne}} {{none}}
_ = i.generate() // expected-error {{'generate()' has been renamed to 'makeIterator()'}} {{9-17=makeIterator}} {{none}}
Expand Down Expand Up @@ -281,8 +305,14 @@ func _LifetimeManager<T>(x: T) {
_ = withUnsafePointers(&x, &x, &x) { _, _, _ in } // expected-error {{'withUnsafePointers' is unavailable: use nested withUnsafePointer(to:_:) instead}} {{none}}
}

func _ManagedBuffer<V, E>(x: ManagedBufferPointer<V, E>) {
func _ManagedBuffer<H, E>(x: ManagedBufferPointer<H, E>, h: H, bc: AnyClass) {
_ = x.allocatedElementCount // expected-error {{'allocatedElementCount' has been renamed to 'capacity'}} {{9-30=capacity}} {{none}}
_ = 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}}
_ = 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}}
_ = 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}}
_ = ManagedBufferPointer<H, E>(bufferClass: bc, minimumCapacity: 1) { _, _ in h } // OK

func fn(_: ManagedProtoBuffer<H, E>) {} // expected-error {{'ManagedProtoBuffer' has been renamed to 'ManagedBuffer'}} {{14-32=ManagedBuffer}} {{none}}
}

func _Map() {
Expand Down Expand Up @@ -422,7 +452,7 @@ func _Sequence() {
func _Sequence<S : Sequence>(s: S) {
_ = s.generate() // expected-error {{'generate()' has been renamed to 'makeIterator()'}} {{9-17=makeIterator}} {{none}}
_ = s.underestimateCount() // expected-error {{'underestimateCount()' has been replaced by 'underestimatedCount'}} {{9-27=underestimatedCount}} {{27-29=}} {{none}}
_ = 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}}
_ = 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}}
}
func _Sequence<S : Sequence>(s: S, e: S.Iterator.Element) where S.Iterator.Element : Equatable {
_ = 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}}
Expand All @@ -434,7 +464,13 @@ func _SequenceAlgorithms<S : Sequence>(x: S) {
_ = x.maxElement { _, _ in true } // expected-error {{'maxElement' has been renamed to 'max(by:)'}} {{9-19=max}} {{none}}
_ = x.reverse() // expected-error {{'reverse()' has been renamed to 'reversed()'}} {{9-16=reversed}} {{none}}
_ = x.startsWith([]) { _ in true } // expected-error {{'startsWith(_:isEquivalent:)' has been renamed to 'starts(with:by:)'}} {{9-19=starts}} {{20-20=with: }} {{none}}
_ = x.elementsEqual([], isEquivalent: { _, _ in true }) // expected-error {{'elementsEqual(_:isEquivalent:)' has been renamed to 'elementsEqual(_:by:)'}} {{9-22=elementsEqual}} {{27-39=by}} {{none}}
_ = x.elementsEqual([]) { _, _ in true } // OK
_ = x.lexicographicalCompare([]) { _, _ in true } // expected-error {{'lexicographicalCompare(_:isOrderedBefore:)' has been renamed to 'lexicographicallyPrecedes(_:by:)'}} {{9-31=lexicographicallyPrecedes}}{{none}}
_ = x.contains({ _ in true }) // expected-error {{'contains' has been renamed to 'contains(where:)'}} {{9-17=contains}} {{18-18=where: }} {{none}}
_ = x.contains { _ in true } // OK
_ = x.reduce(1, combine: { _, _ in 1 }) // expected-error {{'reduce(_:combine:)' has been renamed to 'reduce(_:_:)'}} {{9-15=reduce}} {{19-28=}} {{none}}
_ = x.reduce(1) { _, _ in 1 } // OK
}
func _SequenceAlgorithms<S : Sequence>(x: S) where S.Iterator.Element : Comparable {
_ = x.minElement() // expected-error {{'minElement()' has been renamed to 'min()'}} {{9-19=min}} {{none}}
Expand Down Expand Up @@ -509,9 +545,15 @@ func _StringLegacy(c: Character, u: UnicodeScalar) {
_ = String(repeating: u, count: 1) // expected-error {{'init(repeating:count:)' is unavailable: Replaced by init(repeating: String, count: Int)}} {{none}}
}

func _Unicode() {
func _Unicode<C : UnicodeCodec>(s: UnicodeScalar, c: C.Type, out: (C.CodeUnit) -> Void) {
func fn<T : UnicodeCodecType>(_: T) {} // expected-error {{'UnicodeCodecType' has been renamed to 'UnicodeCodec'}} {{15-31=UnicodeCodec}} {{none}}
c.encode(s, output: out) // expected-error {{encode(_:output:)' has been renamed to 'encode(_:into:)}} {{5-11=encode}} {{15-21=into}} {{none}}
c.encode(s) { _ in } // OK
UTF8.encode(s, output: { _ in }) // expected-error {{'encode(_:output:)' has been renamed to 'encode(_:into:)'}} {{8-14=encode}} {{18-24=into}} {{none}}
UTF16.encode(s, output: { _ in }) // expected-error {{'encode(_:output:)' has been renamed to 'encode(_:into:)'}} {{9-15=encode}} {{19-25=into}} {{none}}
UTF32.encode(s, output: { _ in }) // expected-error {{'encode(_:output:)' has been renamed to 'encode(_:into:)'}} {{9-15=encode}} {{19-25=into}} {{none}}
}

func _Unicode<I : IteratorProtocol, E : UnicodeCodec>(i: I, e: E.Type) where I.Element == E.CodeUnit {
_ = transcode(e, e, i, { _ in }, stopOnError: true) // expected-error {{'transcode(_:_:_:_:stopOnError:)' is unavailable: use 'transcode(_:from:to:stoppingOnError:into:)'}} {{none}}
_ = UTF16.measure(e, input: i, repairIllFormedSequences: true) // expected-error {{'measure(_:input:repairIllFormedSequences:)' is unavailable: use 'transcodedLength(of:decodedAs:repairingIllFormedSequences:)'}} {{none}}
Expand Down
2 changes: 1 addition & 1 deletion test/1_stdlib/StringDiagnostics_without_Foundation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ func testStringCollectionTypes(s: String) {
struct NotLosslessStringConvertible {}

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