Skip to content
Open
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
140 changes: 140 additions & 0 deletions stdlib/public/core/Mirror.swift
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,9 @@ extension String {
// also preserve source compatibility for clients which accidentally
// used init(stringInterpolationSegment:) through constructs like
// myArray.map(String.init).
//
// Unfortunately they create ambiguity by being parallel to each
// other, so many overloads are required.

/// Creates a string representing the given value.
///
Expand Down Expand Up @@ -631,10 +634,100 @@ extension String {
/// print(String(describing: p))
/// // Prints "(21, 30)"
@inlinable
@_alwaysEmitIntoClient
public init<Subject: CustomStringConvertible & ~Copyable>(describing instance: borrowing Subject) {
self = instance.description
}

/// Creates a string representing the given value.
///
/// Use this initializer to convert an instance of any type to its preferred
/// representation as a `String` instance. The initializer creates the
/// string representation of `instance` in one of the following ways,
/// depending on its protocol conformance:
///
/// - 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`.
/// - If `instance` conforms to the `CustomDebugStringConvertible` protocol,
/// the result is `instance.debugDescription`.
/// - An unspecified result is supplied automatically by the Swift standard
/// library.
///
/// For example, this custom `Point` struct uses the default representation
/// supplied by the standard library.
///
/// struct Point {
/// let x: Int, y: Int
/// }
///
/// let p = Point(x: 21, y: 30)
/// print(String(describing: p))
/// // Prints "Point(x: 21, y: 30)"
///
/// After adding `CustomStringConvertible` conformance by implementing the
/// `description` property, `Point` provides its own custom representation.
///
/// extension Point: CustomStringConvertible {
/// var description: String {
/// return "(\(x), \(y))"
/// }
/// }
///
/// print(String(describing: p))
/// // Prints "(21, 30)"
public init<Subject: CustomStringConvertible>(describing instance: Subject) {
self = instance.description
}

/// Creates a string representing the given value.
///
/// Use this initializer to convert an instance of any type to its preferred
/// representation as a `String` instance. The initializer creates the
/// string representation of `instance` in one of the following ways,
/// depending on its protocol conformance:
///
/// - 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`.
/// - If `instance` conforms to the `CustomDebugStringConvertible` protocol,
/// the result is `instance.debugDescription`.
/// - An unspecified result is supplied automatically by the Swift standard
/// library.
///
/// For example, this custom `Point` struct uses the default representation
/// supplied by the standard library.
///
/// struct Point {
/// let x: Int, y: Int
/// }
///
/// let p = Point(x: 21, y: 30)
/// print(String(describing: p))
/// // Prints "Point(x: 21, y: 30)"
///
/// After adding `CustomStringConvertible` conformance by implementing the
/// `description` property, `Point` provides its own custom representation.
///
/// extension Point: CustomStringConvertible {
/// var description: String {
/// return "(\(x), \(y))"
/// }
/// }
///
/// print(String(describing: p))
/// // Prints "(21, 30)"
@inlinable
@_alwaysEmitIntoClient
public init<Subject: TextOutputStreamable & ~Copyable>(describing instance: borrowing Subject) {
self.init()
instance.write(to: &self)
}

/// Creates a string representing the given value.
///
/// Use this initializer to convert an instance of any type to its preferred
Expand Down Expand Up @@ -680,6 +773,53 @@ extension String {
instance.write(to: &self)
}

/// Creates a string representing the given value.
///
/// Use this initializer to convert an instance of any type to its preferred
/// representation as a `String` instance. The initializer creates the
/// string representation of `instance` in one of the following ways,
/// depending on its protocol conformance:
///
/// - 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`.
/// - If `instance` conforms to the `CustomDebugStringConvertible` protocol,
/// the result is `instance.debugDescription`.
/// - An unspecified result is supplied automatically by the Swift standard
/// library.
///
/// For example, this custom `Point` struct uses the default representation
/// supplied by the standard library.
///
/// struct Point {
/// let x: Int, y: Int
/// }
///
/// let p = Point(x: 21, y: 30)
/// print(String(describing: p))
/// // Prints "Point(x: 21, y: 30)"
///
/// After adding `CustomStringConvertible` conformance by implementing the
/// `description` property, `Point` provides its own custom representation.
///
/// extension Point: CustomStringConvertible {
/// var description: String {
/// return "(\(x), \(y))"
/// }
/// }
///
/// print(String(describing: p))
/// // Prints "(21, 30)"
@inlinable
@_alwaysEmitIntoClient
public init<Subject>(describing instance: borrowing Subject)
where Subject: CustomStringConvertible & TextOutputStreamable & ~Copyable
{
self = instance.description
}

/// Creates a string representing the given value.
///
/// Use this initializer to convert an instance of any type to its preferred
Expand Down
8 changes: 4 additions & 4 deletions stdlib/public/core/OutputStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ extension TextOutputStream {
/// 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 {
public protocol TextOutputStreamable: ~Copyable {
/// Writes a textual representation of this instance into the given output
/// stream.
func write<Target: TextOutputStream>(to target: inout Target)
Expand Down Expand Up @@ -147,7 +147,7 @@ public protocol TextOutputStreamable {
///
/// print(p)
/// // Prints "(21, 30)"
public protocol CustomStringConvertible {
public protocol CustomStringConvertible: ~Copyable {
/// A textual representation of this instance.
///
/// Calling this property directly is discouraged. Instead, convert an
Expand Down Expand Up @@ -182,7 +182,7 @@ public protocol CustomStringConvertible {
/// The description property of a conforming type must be a value-preserving
/// representation of the original value. As such, it should be possible to
/// re-create an instance from its string representation.
public protocol LosslessStringConvertible: CustomStringConvertible {
public protocol LosslessStringConvertible: CustomStringConvertible, ~Copyable {
/// Instantiates an instance of the conforming type from a string
/// representation.
init?(_ description: String)
Expand Down Expand Up @@ -239,7 +239,7 @@ public protocol LosslessStringConvertible: CustomStringConvertible {
///
/// print(String(reflecting: p))
/// // Prints "(21, 30)"
public protocol CustomDebugStringConvertible {
public protocol CustomDebugStringConvertible: ~Copyable {
/// A textual representation of this instance, suitable for debugging.
///
/// Calling this property directly is discouraged. Instead, convert an
Expand Down
52 changes: 31 additions & 21 deletions stdlib/public/core/StringInterpolation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol, Sendable
/// print(message)
/// // Prints "If one cookie costs 2 dollars, 3 cookies cost 6 dollars."
@inlinable
public mutating func appendInterpolation<T>(_ value: T)
where T: TextOutputStreamable, T: CustomStringConvertible
@_preInverseGenerics
public mutating func appendInterpolation<T>(_ value: borrowing T)
where T: TextOutputStreamable, T: CustomStringConvertible, T: ~Copyable
{
value.write(to: &self)
}
Expand All @@ -127,8 +128,9 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol, Sendable
/// print(message)
/// // Prints "If one cookie costs 2 dollars, 3 cookies cost 6 dollars."
@inlinable
public mutating func appendInterpolation<T>(_ value: T)
where T: TextOutputStreamable
@_preInverseGenerics
public mutating func appendInterpolation<T>(_ value: borrowing T)
where T: TextOutputStreamable & ~Copyable
{
value.write(to: &self)
}
Expand All @@ -151,8 +153,9 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol, Sendable
/// print(message)
/// // Prints "If one cookie costs 2 dollars, 3 cookies cost 6 dollars."
@inlinable
public mutating func appendInterpolation<T>(_ value: T)
where T: CustomStringConvertible
@_preInverseGenerics
public mutating func appendInterpolation<T>(_ value: borrowing T)
where T: CustomStringConvertible, T: ~Copyable
{
value.description.write(to: &self)
}
Expand All @@ -175,7 +178,7 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol, Sendable
/// print(message)
/// // Prints "If one cookie costs 2 dollars, 3 cookies cost 6 dollars."
@inlinable
public mutating func appendInterpolation<T>(_ value: T) {
public mutating func appendInterpolation<T>(_ value: borrowing T) {
#if !$Embedded
_print_unlocked(value, &self)
#else
Expand Down Expand Up @@ -217,13 +220,15 @@ extension DefaultStringInterpolation {
/// - value: The value to include in a string interpolation, if non-`nil`.
/// - default: The string to include if `value` is `nil`.
@_alwaysEmitIntoClient
@_preInverseGenerics
public mutating func appendInterpolation<T>(
_ value: T?,
_ value: borrowing T?,
default: @autoclosure () -> some StringProtocol
) where T: TextOutputStreamable, T: CustomStringConvertible {
if let value {
) where T: TextOutputStreamable, T: CustomStringConvertible, T: ~Copyable {
switch value {
case let value?:
self.appendInterpolation(value)
} else {
case nil:
self.appendInterpolation(`default`())
}
}
Expand All @@ -247,13 +252,15 @@ extension DefaultStringInterpolation {
/// - value: The value to include in a string interpolation, if non-`nil`.
/// - default: The string to include if `value` is `nil`.
@_alwaysEmitIntoClient
@_preInverseGenerics
public mutating func appendInterpolation<T>(
_ value: T?,
_ value: borrowing T?,
default: @autoclosure () -> some StringProtocol
) where T: TextOutputStreamable {
if let value {
) where T: TextOutputStreamable & ~Copyable {
switch value {
case let value?:
self.appendInterpolation(value)
} else {
case nil:
self.appendInterpolation(`default`())
}
}
Expand All @@ -277,13 +284,15 @@ extension DefaultStringInterpolation {
/// - value: The value to include in a string interpolation, if non-`nil`.
/// - default: The string to include if `value` is `nil`.
@_alwaysEmitIntoClient
@_preInverseGenerics
public mutating func appendInterpolation<T>(
_ value: T?,
_ value: borrowing T?,
default: @autoclosure () -> some StringProtocol
) where T: CustomStringConvertible {
if let value {
) where T: CustomStringConvertible, T: ~Copyable {
switch value {
case let value?:
self.appendInterpolation(value)
} else {
case nil:
self.appendInterpolation(`default`())
}
}
Expand Down Expand Up @@ -311,9 +320,10 @@ extension DefaultStringInterpolation {
_ value: T?,
default: @autoclosure () -> some StringProtocol
) {
if let value {
switch value {
case let value?:
self.appendInterpolation(value)
} else {
case nil:
self.appendInterpolation(`default`())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Constructor ContiguousArray.init(unsafeUninitializedCapacity:initializingWith:)
Constructor ContiguousArray.init(unsafeUninitializedCapacity:initializingWith:) has parameter 1 type change from (inout Swift.UnsafeMutableBufferPointer<Element>, inout Swift.Int) throws -> Swift.Void to (inout Swift.UnsafeMutableBufferPointer<Element>, inout Swift.Int) throws(E) -> Swift.Void
Constructor ContiguousArray.init(unsafeUninitializedCapacity:initializingWith:) is now without rethrows

Protocol LosslessStringConvertible has generic signature change from <Self : Swift.CustomStringConvertible> to <Self : Swift.CustomStringConvertible, Self : ~Copyable>
Protocol SIMDScalar has generic signature change from <Self == Self.SIMD16Storage.Scalar, Self.SIMD16Storage : Swift.SIMDStorage, Self.SIMD2Storage : Swift.SIMDStorage, Self.SIMD32Storage : Swift.SIMDStorage, Self.SIMD4Storage : Swift.SIMDStorage, Self.SIMD64Storage : Swift.SIMDStorage, Self.SIMD8Storage : Swift.SIMDStorage, Self.SIMDMaskScalar : Swift.FixedWidthInteger, Self.SIMDMaskScalar : Swift.SIMDScalar, Self.SIMDMaskScalar : Swift.SignedInteger, Self.SIMD16Storage.Scalar == Self.SIMD2Storage.Scalar, Self.SIMD2Storage.Scalar == Self.SIMD32Storage.Scalar, Self.SIMD32Storage.Scalar == Self.SIMD4Storage.Scalar, Self.SIMD4Storage.Scalar == Self.SIMD64Storage.Scalar, Self.SIMD64Storage.Scalar == Self.SIMD8Storage.Scalar> to <Self : Swift.BitwiseCopyable, Self == Self.SIMD16Storage.Scalar, Self.SIMD16Storage : Swift.SIMDStorage, Self.SIMD2Storage : Swift.SIMDStorage, Self.SIMD32Storage : Swift.SIMDStorage, Self.SIMD4Storage : Swift.SIMDStorage, Self.SIMD64Storage : Swift.SIMDStorage, Self.SIMD8Storage : Swift.SIMDStorage, Self.SIMDMaskScalar : Swift.FixedWidthInteger, Self.SIMDMaskScalar : Swift.SIMDScalar, Self.SIMDMaskScalar : Swift.SignedInteger, Self.SIMDMaskScalar == Self.SIMDMaskScalar.SIMDMaskScalar, Self.SIMD16Storage.Scalar == Self.SIMD2Storage.Scalar, Self.SIMD2Storage.Scalar == Self.SIMD32Storage.Scalar, Self.SIMD32Storage.Scalar == Self.SIMD4Storage.Scalar, Self.SIMD4Storage.Scalar == Self.SIMD64Storage.Scalar, Self.SIMD64Storage.Scalar == Self.SIMD8Storage.Scalar>

Protocol AdditiveArithmetic has added inherited protocol Copyable
Expand All @@ -72,15 +73,13 @@ Protocol CodingKey has added inherited protocol Escapable
Protocol Collection has added inherited protocol Copyable
Protocol Collection has added inherited protocol Escapable
Protocol Comparable has added inherited protocol Escapable
Protocol CustomDebugStringConvertible has added inherited protocol Copyable
Protocol CustomDebugStringConvertible has added inherited protocol Escapable
Protocol CustomLeafReflectable has added inherited protocol Copyable
Protocol CustomLeafReflectable has added inherited protocol Escapable
Protocol CustomPlaygroundDisplayConvertible has added inherited protocol Copyable
Protocol CustomPlaygroundDisplayConvertible has added inherited protocol Escapable
Protocol CustomReflectable has added inherited protocol Copyable
Protocol CustomReflectable has added inherited protocol Escapable
Protocol CustomStringConvertible has added inherited protocol Copyable
Protocol CustomStringConvertible has added inherited protocol Escapable
Protocol Decodable has added inherited protocol Copyable
Protocol Decodable has added inherited protocol Escapable
Expand Down Expand Up @@ -129,7 +128,6 @@ Protocol LazyCollectionProtocol has added inherited protocol Copyable
Protocol LazyCollectionProtocol has added inherited protocol Escapable
Protocol LazySequenceProtocol has added inherited protocol Copyable
Protocol LazySequenceProtocol has added inherited protocol Escapable
Protocol LosslessStringConvertible has added inherited protocol Copyable
Protocol LosslessStringConvertible has added inherited protocol Escapable
Protocol MirrorPath has added inherited protocol Copyable
Protocol MirrorPath has added inherited protocol Escapable
Expand Down Expand Up @@ -176,7 +174,6 @@ Protocol StringProtocol has added inherited protocol Copyable
Protocol StringProtocol has added inherited protocol Escapable
Protocol TextOutputStream has added inherited protocol Copyable
Protocol TextOutputStream has added inherited protocol Escapable
Protocol TextOutputStreamable has added inherited protocol Copyable
Protocol TextOutputStreamable has added inherited protocol Escapable
Protocol UnicodeCodec has added inherited protocol Copyable
Protocol UnicodeCodec has added inherited protocol Escapable
Expand Down Expand Up @@ -401,3 +398,12 @@ Func Comparable.>=(_:_:) has generic signature change from <Self where Self : Sw
Func Comparable.>=(_:_:) has parameter 0 changing from Default to Shared
Func Comparable.>=(_:_:) has parameter 1 changing from Default to Shared

// CustomStringConvertible etc: ~Copyable
Accessor CustomDebugStringConvertible.debugDescription.Get() has generic signature change from <Self where Self : Swift.CustomDebugStringConvertible> to <Self where Self : Swift.CustomDebugStringConvertible, Self : ~Copyable>
Accessor CustomStringConvertible.description.Get() has generic signature change from <Self where Self : Swift.CustomStringConvertible> to <Self where Self : Swift.CustomStringConvertible, Self : ~Copyable>
Constructor LosslessStringConvertible.init(_:) has generic signature change from <Self where Self : Swift.LosslessStringConvertible> to <Self where Self : Swift.LosslessStringConvertible, Self : ~Copyable>
Func DefaultStringInterpolation.appendInterpolation(_:) has generic signature change from <T where T : Swift.CustomStringConvertible, T : Swift.TextOutputStreamable> to <T where T : Swift.CustomStringConvertible, T : Swift.TextOutputStreamable, T : ~Copyable>
Func DefaultStringInterpolation.appendInterpolation(_:) has generic signature change from <T where T : Swift.CustomStringConvertible> to <T where T : Swift.CustomStringConvertible, T : ~Copyable>
Func DefaultStringInterpolation.appendInterpolation(_:) has generic signature change from <T where T : Swift.TextOutputStreamable> to <T where T : Swift.TextOutputStreamable, T : ~Copyable>
Func DefaultStringInterpolation.appendInterpolation(_:) has parameter 0 changing from Default to Shared
Func TextOutputStreamable.write(to:) has generic signature change from <Self, Target where Self : Swift.TextOutputStreamable, Target : Swift.TextOutputStream> to <Self, Target where Self : Swift.TextOutputStreamable, Target : Swift.TextOutputStream, Self : ~Copyable>
Loading