Skip to content

Commit 3790bd3

Browse files
authored
Merge pull request swiftlang#813 from swiftwasm/master
[pull] swiftwasm from master
2 parents 1c63a78 + d7b5de9 commit 3790bd3

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

docs/Literals.rst

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,30 @@ The ExpressibleByStringLiteral Protocol
3636
Here is the ExpressibleByStringLiteral protocol as defined in the standard
3737
library's CompilerProtocols.swift::
3838

39-
// NOTE: the compiler has builtin knowledge of this protocol
40-
// Conforming types can be initialized with arbitrary string literals.
39+
/// A type that can be initialized with a string literal.
40+
///
41+
/// The `String` and `StaticString` types conform to the
42+
/// `ExpressibleByStringLiteral` protocol. You can initialize a variable or
43+
/// constant of either of these types using a string literal of any length.
44+
///
45+
/// let picnicGuest = "Deserving porcupine"
46+
///
47+
/// Conforming to ExpressibleByStringLiteral
48+
/// ========================================
49+
///
50+
/// To add `ExpressibleByStringLiteral` conformance to your custom type,
51+
/// implement the required initializer.
4152
public protocol ExpressibleByStringLiteral
4253
: ExpressibleByExtendedGraphemeClusterLiteral {
4354

44-
typealias StringLiteralType : _ExpressibleByBuiltinStringLiteral
45-
// Create an instance initialized to `value`.
55+
/// A type that represents a string literal.
56+
///
57+
/// Valid types for `StringLiteralType` are `String` and `StaticString`.
58+
associatedtype StringLiteralType: _ExpressibleByBuiltinStringLiteral
59+
60+
/// Creates an instance initialized to the given string value.
61+
///
62+
/// - Parameter value: The value of the new instance.
4663
init(stringLiteral value: StringLiteralType)
4764
}
4865

stdlib/public/core/UnsafePointer.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@
108108
/// `load(fromByteOffset:as:)` method to read values.
109109
///
110110
/// let rawPointer = UnsafeRawPointer(uint64Pointer)
111-
/// fullInteger = rawPointer.load(as: UInt64.self) // OK
112-
/// firstByte = rawPointer.load(as: UInt8.self) // OK
111+
/// let fullInteger = rawPointer.load(as: UInt64.self) // OK
112+
/// let firstByte = rawPointer.load(as: UInt8.self) // OK
113113
///
114114
/// Performing Typed Pointer Arithmetic
115115
/// ===================================
@@ -260,7 +260,7 @@ public struct UnsafePointer<Pointee>: _Pointer {
260260
/// pointer to `Int64`, then accesses a property on the signed integer.
261261
///
262262
/// let uint64Pointer: UnsafePointer<UInt64> = fetchValue()
263-
/// let isNegative = uint64Pointer.withMemoryRebound(to: Int64.self) { ptr in
263+
/// let isNegative = uint64Pointer.withMemoryRebound(to: Int64.self, capacity: 1) { ptr in
264264
/// return ptr.pointee < 0
265265
/// }
266266
///
@@ -430,8 +430,8 @@ public struct UnsafePointer<Pointee>: _Pointer {
430430
/// to read and write values.
431431
///
432432
/// let rawPointer = UnsafeMutableRawPointer(uint64Pointer)
433-
/// fullInteger = rawPointer.load(as: UInt64.self) // OK
434-
/// firstByte = rawPointer.load(as: UInt8.self) // OK
433+
/// let fullInteger = rawPointer.load(as: UInt64.self) // OK
434+
/// let firstByte = rawPointer.load(as: UInt8.self) // OK
435435
///
436436
/// Performing Typed Pointer Arithmetic
437437
/// ===================================
@@ -911,7 +911,7 @@ public struct UnsafeMutablePointer<Pointee>: _Pointer {
911911
/// pointer to `Int64`, then accesses a property on the signed integer.
912912
///
913913
/// let uint64Pointer: UnsafeMutablePointer<UInt64> = fetchValue()
914-
/// let isNegative = uint64Pointer.withMemoryRebound(to: Int64.self) { ptr in
914+
/// let isNegative = uint64Pointer.withMemoryRebound(to: Int64.self, capacity: 1) { ptr in
915915
/// return ptr.pointee < 0
916916
/// }
917917
///

stdlib/public/core/UnsafeRawPointer.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ public struct UnsafeRawPointer: _Pointer {
288288
///
289289
/// let count = 4
290290
/// let bytesPointer = UnsafeMutableRawPointer.allocate(
291-
/// bytes: 100,
292-
/// alignedTo: MemoryLayout<Int8>.alignment)
291+
/// byteCount: 100,
292+
/// alignment: MemoryLayout<Int8>.alignment)
293293
/// let int8Pointer = bytesPointer.bindMemory(to: Int8.self, capacity: count)
294294
///
295295
/// After calling `bindMemory(to:capacity:)`, the first four bytes of the
@@ -653,8 +653,8 @@ public struct UnsafeMutableRawPointer: _Pointer {
653653
///
654654
/// let count = 4
655655
/// let bytesPointer = UnsafeMutableRawPointer.allocate(
656-
/// bytes: 100,
657-
/// alignedTo: MemoryLayout<Int8>.alignment)
656+
/// byteCount: 100,
657+
/// alignment: MemoryLayout<Int8>.alignment)
658658
/// let int8Pointer = bytesPointer.bindMemory(to: Int8.self, capacity: count)
659659
///
660660
/// After calling `bindMemory(to:capacity:)`, the first four bytes of the
@@ -716,7 +716,7 @@ public struct UnsafeMutableRawPointer: _Pointer {
716716
/// let bytesPointer = UnsafeMutableRawPointer.allocate(
717717
/// byteCount: count * MemoryLayout<Int8>.stride,
718718
/// alignment: MemoryLayout<Int8>.alignment)
719-
/// let int8Pointer = myBytes.initializeMemory(
719+
/// let int8Pointer = bytesPointer.initializeMemory(
720720
/// as: Int8.self, repeating: 0, count: count)
721721
///
722722
/// // After using 'int8Pointer':
@@ -764,8 +764,8 @@ public struct UnsafeMutableRawPointer: _Pointer {
764764
///
765765
/// let count = 4
766766
/// let bytesPointer = UnsafeMutableRawPointer.allocate(
767-
/// bytes: count * MemoryLayout<Int8>.stride,
768-
/// alignedTo: MemoryLayout<Int8>.alignment)
767+
/// byteCount: count * MemoryLayout<Int8>.stride,
768+
/// alignment: MemoryLayout<Int8>.alignment)
769769
/// let values: [Int8] = [1, 2, 3, 4]
770770
/// let int8Pointer = values.withUnsafeBufferPointer { buffer in
771771
/// return bytesPointer.initializeMemory(as: Int8.self,
@@ -776,7 +776,7 @@ public struct UnsafeMutableRawPointer: _Pointer {
776776
/// // (int8Pointer + 3).pointee == 4
777777
///
778778
/// // After using 'int8Pointer':
779-
/// int8Pointer.deallocate(count)
779+
/// int8Pointer.deallocate()
780780
///
781781
/// After calling this method on a raw pointer `p`, the region starting at
782782
/// `p` and continuing up to `p + count * MemoryLayout<T>.stride` is bound
@@ -933,7 +933,7 @@ public struct UnsafeMutableRawPointer: _Pointer {
933933
///
934934
/// let typedPointer = p.bindMemory(to: U.self, capacity: 1)
935935
/// typedPointer.deinitialize(count: 1)
936-
/// p.initializeMemory(as: T.self, to: newValue)
936+
/// p.initializeMemory(as: T.self, repeating: newValue, count: 1)
937937
///
938938
/// - Parameters:
939939
/// - value: The value to store as raw bytes.

0 commit comments

Comments
 (0)