Skip to content
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

[SR-13863] String.init(describing:) in addition to current four overloads, should add three more #56261

Closed
mattyoung opened this issue Nov 16, 2020 · 2 comments
Labels
feature A feature request or implementation standard library Area: Standard library umbrella String Area → standard library: The `String` type will not do Resolution: Will not be worked on

Comments

@mattyoung
Copy link

mattyoung commented Nov 16, 2020

Previous ID SR-13863
Radar rdar://problem/71492268
Original Reporter @mattyoung
Type New Feature
Status Closed
Resolution Won't Do
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels New Feature
Assignee None
Priority Medium

md5: 14b8acdeba460c8d67aaaa8f59f10bf3

Issue Description:

Four overload currently:

init<Subject>(describing instance: Subject) where Subject : TextOutputStreamable  
init<Subject>(describing instance: Subject) where Subject : CustomStringConvertible  
init<Subject>(describing instance: Subject) where Subject : CustomStringConvertible, Subject : TextOutputStreamable  
@_disfavoredOverload // need this if the new overload are added  
init<Subject>(describing instance: Subject)

First three are fast, last one slow and should be avoided if possible, but the fourth is called even when type is known:

String(describing: x as CustomStringConvertible)

this end up calling the last one which is slow. So to avoid calling this slow one, add these three for fast:

@_disfavoredOverload  
init(describing instance: TextOutputStreamable) { ... }  
@_disfavoredOverload  
init(describing instance: CustomStringConvertible) { ... }  
@_disfavoredOverload  
init(describing instance: CustomStringConvertible & TextOutputStreamable) { ... }

See:
https://forums.swift.org/t/question-re-string-init-describing-overloads-why-there-are-four/41172
https://forums.swift.org/t/init-subject-customstringconvertible-xxx-instance-subject-vs-init-xxx-instance-customstringconvertible/41219/12

@typesanitizer
Copy link

@swift-ci create

@lorentey
Copy link
Member

I don't see any practical need for these overloads. The only way I expect people would call these is immediately after converting a value to a protocol existential, in which case the right thing to do is to directly call the corresponding protocol requirement. (As in, just call `x.description` instead of `String(describing: x)`.) This also matches what the stdlib is doing in the implementation _print_unlocked.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added feature A feature request or implementation String Area → standard library: The `String` type will not do Resolution: Will not be worked on and removed new feature labels Feb 27, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request or implementation standard library Area: Standard library umbrella String Area → standard library: The `String` type will not do Resolution: Will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants