Skip to content

[swift-3.0-branch] Renaming Streamable (part of SE-0137) #4391

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 3 commits into from
Aug 19, 2016
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
4 changes: 2 additions & 2 deletions stdlib/public/core/Mirror.swift
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ extension String {
/// string representation of `instance` in one of the following ways,
/// depending on its protocol conformance:
///
/// - If `instance` conforms to the `Streamable` protocol, the result is
/// - If `instance` conforms to the `TextOutputStreamable` protocol, the result is
/// obtained by calling `instance.write(to: s)` on an empty string `s`.
/// - If `instance` conforms to the `CustomStringConvertible` protocol, the
/// result is `instance.description`.
Expand Down Expand Up @@ -888,7 +888,7 @@ extension String {
/// the result is `subject.debugDescription`.
/// - If `subject` conforms to the `CustomStringConvertible` protocol, the
/// result is `subject.description`.
/// - If `subject` conforms to the `Streamable` protocol, the result is
/// - If `subject` conforms to the `TextOutputStreamable` protocol, the result is
/// obtained by calling `subject.write(to: s)` on an empty string `s`.
/// - An unspecified result is supplied automatically by the Swift standard
/// library.
Expand Down
41 changes: 23 additions & 18 deletions stdlib/public/core/OutputStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,27 @@ extension TextOutputStream {

/// A source of text-streaming operations.
///
/// Instances of types that conform to the `Streamable` protocol can write
/// their value to instances of any type that conforms to the `TextOutputStream`
/// protocol. The Swift standard library's text-related types, `String`,
/// `Character`, and `UnicodeScalar`, all conform to `Streamable`.
/// Instances of types that conform to the `TextOutputStreamable` protocol can
/// write their value to instances of any type that conforms to the
/// `TextOutputStream` protocol. The Swift standard library's text-related
/// types, `String`, `Character`, and `UnicodeScalar`, all conform to
/// `TextOutputStreamable`.
///
/// Conforming to the Streamable Protocol
/// Conforming to the TextOutputStreamable Protocol
/// =====================================
///
/// To add `Streamable` conformance to a custom type, implement the required
/// `write(to:)` method. Call the given output stream's `write(_:)` method in
/// your implementation.
public protocol Streamable {
/// To add `TextOutputStreamable` conformance to a custom type, implement the
/// required `write(to:)` method. Call the given output stream's `write(_:)`
/// method in your implementation.
public protocol TextOutputStreamable {
/// Writes a textual representation of this instance into the given output
/// stream.
func write<Target : TextOutputStream>(to target: inout Target)
}

// @available(*, unavailable, renamed: "TextOutputStreamable")
public typealias Streamable = TextOutputStreamable

/// A type with a customized textual representation.
///
/// Types that conform to the `CustomStringConvertible` protocol can provide
Expand Down Expand Up @@ -346,7 +350,7 @@ internal func _print_unlocked<T, TargetStream : TextOutputStream>(
debugPrintable.debugDescription.write(to: &target)
return
}
if case let streamableObject as Streamable = value {
if case let streamableObject as TextOutputStreamable = value {
streamableObject.write(to: &target)
return
}
Expand All @@ -373,7 +377,7 @@ internal func _print_unlocked<T, TargetStream : TextOutputStream>(
/// This function is forbidden from being inlined because when building the
/// standard library inlining makes us drop the special semantics.
@inline(never) @effects(readonly)
func _toStringReadOnlyStreamable<T : Streamable>(_ x: T) -> String {
func _toStringReadOnlyStreamable<T : TextOutputStreamable>(_ x: T) -> String {
var result = ""
x.write(to: &result)
return result
Expand Down Expand Up @@ -402,7 +406,7 @@ public func _debugPrint_unlocked<T, TargetStream : TextOutputStream>(
return
}

if let streamableObject = value as? Streamable {
if let streamableObject = value as? TextOutputStreamable {
streamableObject.write(to: &target)
return
}
Expand All @@ -415,7 +419,8 @@ internal func _dumpPrint_unlocked<T, TargetStream : TextOutputStream>(
_ value: T, _ mirror: Mirror, _ target: inout TargetStream
) {
if let displayStyle = mirror.displayStyle {
// Containers and tuples are always displayed in terms of their element count
// Containers and tuples are always displayed in terms of their element
// count
switch displayStyle {
case .tuple:
let count = mirror.children.count
Expand Down Expand Up @@ -448,7 +453,7 @@ internal func _dumpPrint_unlocked<T, TargetStream : TextOutputStream>(
return
}

if let streamableObject = value as? Streamable {
if let streamableObject = value as? TextOutputStreamable {
streamableObject.write(to: &target)
return
}
Expand Down Expand Up @@ -519,7 +524,7 @@ extension String : TextOutputStream {
// Streamables
//===----------------------------------------------------------------------===//

extension String : Streamable {
extension String : TextOutputStreamable {
/// Writes the string into the given output stream.
///
/// - Parameter target: An output stream.
Expand All @@ -528,7 +533,7 @@ extension String : Streamable {
}
}

extension Character : Streamable {
extension Character : TextOutputStreamable {
/// Writes the character into the given output stream.
///
/// - Parameter target: An output stream.
Expand All @@ -537,7 +542,7 @@ extension Character : Streamable {
}
}

extension UnicodeScalar : Streamable {
extension UnicodeScalar : TextOutputStreamable {
/// Writes the textual representation of the Unicode scalar into the given
/// output stream.
///
Expand Down Expand Up @@ -568,7 +573,7 @@ internal struct _TeeStream<
@available(*, unavailable, renamed: "TextOutputStream")
public typealias OutputStreamType = TextOutputStream

extension Streamable {
extension TextOutputStreamable {
@available(*, unavailable, renamed: "write(to:)")
public func writeTo<Target : TextOutputStream>(_ target: inout Target) {
Builtin.unreachable()
Expand Down
8 changes: 4 additions & 4 deletions stdlib/public/core/Print.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
/// - terminator: The string to print after all items have been printed. The
/// default is a newline (`"\n"`).
///
/// - SeeAlso: `debugPrint(_:separator:terminator:)`, `Streamable`,
/// - SeeAlso: `debugPrint(_:separator:terminator:)`, `TextOutputStreamable`,
/// `CustomStringConvertible`, `CustomDebugStringConvertible`
@inline(never)
@_semantics("stdlib_binary_only")
Expand Down Expand Up @@ -113,7 +113,7 @@ public func print(
/// - terminator: The string to print after all items have been printed. The
/// default is a newline (`"\n"`).
///
/// - SeeAlso: `print(_:separator:terminator:)`, `Streamable`,
/// - SeeAlso: `print(_:separator:terminator:)`, `TextOutputStreamable`,
/// `CustomStringConvertible`, `CustomDebugStringConvertible`
@inline(never)
@_semantics("stdlib_binary_only")
Expand Down Expand Up @@ -174,7 +174,7 @@ public func debugPrint(
///
/// - SeeAlso: `print(_:separator:terminator:)`,
/// `debugPrint(_:separator:terminator:to:)`, `TextOutputStream`,
/// `Streamable`, `CustomStringConvertible`, `CustomDebugStringConvertible`
/// `TextOutputStreamable`, `CustomStringConvertible`, `CustomDebugStringConvertible`
@inline(__always)
public func print<Target : TextOutputStream>(
_ items: Any...,
Expand Down Expand Up @@ -225,7 +225,7 @@ public func print<Target : TextOutputStream>(
/// item.
///
/// - SeeAlso: `debugPrint(_:separator:terminator:)`,
/// `print(_:separator:terminator:to:)`, `TextOutputStream`, `Streamable`,
/// `print(_:separator:terminator:to:)`, `TextOutputStream`, `TextOutputStreamable`,
/// `CustomStringConvertible`, `CustomDebugStringConvertible`
@inline(__always)
public func debugPrint<Target : TextOutputStream>(
Expand Down
10 changes: 5 additions & 5 deletions test/1_stdlib/Optional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class TestString : CustomStringConvertible, CustomDebugStringConvertible {
return "XString"
}
}
class TestStream : Streamable {
class TestStream : TextOutputStreamable {
func write<Target : TextOutputStream>(to target: inout Target) {
target.write("AStream")
}
Expand All @@ -371,8 +371,8 @@ OptionalTests.test("Optional TextOutputStream") {
let optNoString: TestNoString? = TestNoString()
expectFalse(optNoString is CustomStringConvertible)
expectFalse(canGenericCast(optNoString, CustomStringConvertible.self))
expectFalse(optNoString is Streamable)
expectFalse(canGenericCast(optNoString, Streamable.self))
expectFalse(optNoString is TextOutputStreamable)
expectFalse(canGenericCast(optNoString, TextOutputStreamable.self))
expectTrue(optNoString is CustomDebugStringConvertible)
expectTrue(canGenericCast(optNoString, CustomDebugStringConvertible.self))
expectEqual(String(describing: optNoString), "Optional(main.TestNoString)")
Expand All @@ -388,8 +388,8 @@ OptionalTests.test("Optional TextOutputStream") {
expectEqual(debugPrintStr(optString), "Optional(XString)")

let optStream: TestStream? = TestStream()
expectTrue(optStream is Streamable)
expectTrue(canGenericCast(optStream, Streamable.self))
expectTrue(optStream is TextOutputStreamable)
expectTrue(canGenericCast(optStream, TextOutputStreamable.self))
expectTrue(optStream is CustomDebugStringConvertible)
expectTrue(canGenericCast(optStream, CustomDebugStringConvertible.self))
expectEqual(String(describing: TestStream()), "AStream")
Expand Down
2 changes: 1 addition & 1 deletion test/1_stdlib/Renames.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func _Optional<T>(x: T) {
func _TextOutputStream() {
func fn<S : OutputStreamType>(_: S) {} // expected-error {{'OutputStreamType' has been renamed to 'TextOutputStream'}} {{15-31=TextOutputStream}} {{none}}
}
func _TextOutputStream<S : Streamable, O : TextOutputStream>(s: S, o: O) {
func _TextOutputStream<S : TextOutputStreamable, O : TextOutputStream>(s: S, o: O) {
var o = o
s.writeTo(&o) // expected-error {{'writeTo' has been renamed to 'write(to:)'}} {{5-12=write}} {{13-13=to: }} {{none}}
}
Expand Down