Skip to content

[SE-0163] Migrate from deprecated Unicode APIs (part 3) #33175

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
Aug 6, 2020
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
15 changes: 1 addition & 14 deletions stdlib/public/core/StaticString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,7 @@ public struct StaticString {
return body(UnsafeBufferPointer(
start: utf8Start, count: utf8CodeUnitCount))
} else {
var buffer: UInt64 = 0
var i = 0
let sink: (UInt8) -> Void = {
#if _endian(little)
buffer = buffer | (UInt64($0) << (UInt64(i) * 8))
#else
buffer = buffer | (UInt64($0) << (UInt64(7-i) * 8))
#endif
i += 1
}
UTF8.encode(unicodeScalar, into: sink)
return body(UnsafeBufferPointer(
start: UnsafePointer(Builtin.addressof(&buffer)),
count: i))
return unicodeScalar.withUTF8CodeUnits { body($0) }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is using the internal Unicode.Scalar.withUTF8CodeUnits(_:) method, which has been ABI-public since Swift 5.0 — I assume it will also be available in the bundled stdlib (e.g. when targeting macOS 10.9).

Copy link
Member

Choose a reason for hiding this comment

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

Yep, those were built from the same sources!

(It's unfortunate that this non-public entry point is missing its leading underscore.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(There was also a fix in Swift 5.1 for big-endian platforms.)

}
}

Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/objc_super.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,5 @@ class GenericRuncer<T> : Gizmo {
}

// CHECK: define internal swiftcc void [[PARTIAL_FORWARDING_THUNK]](%swift.refcounted* swiftself %0) {{.*}} {
// CHECK: @"$ss12StaticStringV14withUTF8BufferyxxSRys5UInt8VGXElFyAEcfU_"
// CHECK: @"$ss12StaticStringV14withUTF8BufferyxxSRys5UInt8VGXElFxAFXEfU_"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test now has a different closure #1 type in its mangled name.

  • Old swift-demangle result:

    $ss12StaticStringV14withUTF8BufferyxxSRys5UInt8VGXElFyAEcfU_ ---> 
    closure #1 (Swift.UInt8) -> () in 
    Swift.StaticString.withUTF8Buffer<A>((Swift.UnsafeBufferPointer<Swift.UInt8>) -> A) -> A
    
  • New swift-demangle result:

    $ss12StaticStringV14withUTF8BufferyxxSRys5UInt8VGXElFxAFXEfU_ ---> 
    closure #1 (Swift.UnsafeBufferPointer<Swift.UInt8>) -> A in 
    Swift.StaticString.withUTF8Buffer<A>((Swift.UnsafeBufferPointer<Swift.UInt8>) -> A) -> A
    

// CHECK: }