Skip to content

Make String(unsafeUninitializedCapacity:initializingUTF8With:) public #30106

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 1 commit into from
Mar 3, 2020

Conversation

Catfish-Man
Copy link
Contributor

No description provided.

@Catfish-Man Catfish-Man requested a review from milseman February 27, 2020 22:29
@Catfish-Man Catfish-Man self-assigned this Feb 27, 2020
@Catfish-Man
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 9daaa16475d66ef24babb2c4c3a385add9ec2300

@Catfish-Man
Copy link
Contributor Author

@swift-ci please test and merge

1 similar comment
@Catfish-Man
Copy link
Contributor Author

@swift-ci please test and merge

@benrimmington
Copy link
Contributor

benrimmington commented Feb 28, 2020

Should the public initializer include the unsafe label from the review?

@Catfish-Man
Copy link
Contributor Author

Oh did I get that backwards? For some reason I thought we'd ended up removing it. Thanks for catching that!

Also what is swift-ci doing :(

@benrimmington

This comment has been minimized.

@@ -476,7 +476,8 @@ extension String {
/// - buffer: A buffer covering uninitialized memory with room for the
/// specified number of UTF-8 code units.
@inline(__always)
internal init(
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
public init(
Copy link
Member

@milseman milseman Feb 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the proposal:

  public init(
    unsafeUninitializedCapacity capacity: Int,
    initializingUTF8With initializer: (
      _ buffer: UnsafeMutableBufferPointer<UInt8>,
    ) throws -> Int
  ) rethrows

@Catfish-Man
Copy link
Contributor Author

@swift-ci please test and merge

@Catfish-Man
Copy link
Contributor Author

@swift-ci please smoke test and merge

@benrimmington
Copy link
Contributor

The unsafeUninitializedCapacity: label also needs to be used in existing callers:

@xwu xwu changed the title Make String(uninitializedCapacity:,initializingUTF8With:) public Make String(unsafeUninitializedCapacity:initializingUTF8With:) public Feb 29, 2020
@Catfish-Man
Copy link
Contributor Author

Huh when did lowercased() and friends start using this, that's neat

@Catfish-Man
Copy link
Contributor Author

Also I have to work around availability >.<

@Catfish-Man
Copy link
Contributor Author

@swift-ci please test and merge

@benrimmington
Copy link
Contributor

The public and internal initializers are @inline(__always) but not @inlinable. Does that mean they are inlined within stdlib, but not inlined into other modules?

And if the callers I listed above (lowercased(), etc.) are also not inlined into other modules, then shouldn't you be able to use the public initializer everywhere, and remove the internal initializer completely?

The "test and merge" failed.

https://ci.swift.org/job/swift-PR-merge/2268/
ERROR: Couldn't find any revision to build.

You could try a "test" only, and merge manually if that works.

@Catfish-Man
Copy link
Contributor Author

Yes, inline always but not inlinable was intentional here. I want to try taking that off at some point, but getting the SmallString part inlined as much as possible is important (originally I wanted to make it inlinable, but SmallString isn't ABI).

I tried using the public initializer in lowercased() and friends but it still got upset about availability :(

test only is a good idea, let's try that

@Catfish-Man
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Mar 2, 2020

Build failed
Swift Test Linux Platform
Git Sha - bf1ce1e54c9ca0f36e59ff5e9e9d9397bccb221c

@swift-ci
Copy link
Contributor

swift-ci commented Mar 2, 2020

Build failed
Swift Test OS X Platform
Git Sha - bf1ce1e54c9ca0f36e59ff5e9e9d9397bccb221c

@benrimmington
Copy link
Contributor

All checks have passed!

@Catfish-Man Catfish-Man merged commit eb74e71 into swiftlang:master Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants