@@ -77,7 +77,7 @@ public class AnyKeyPath: _AppendKeyPath {
77
77
}
78
78
79
79
#if _pointerBitWidth(_64)
80
- _kvcKeyPathStringPtr = unsafe UnsafePointer< CChar > ( bitPattern: - offset - 1 )
80
+ unsafe _kvcKeyPathStringPtr = UnsafePointer < CChar > ( bitPattern: - offset - 1 )
81
81
#elseif _pointerBitWidth(_32)
82
82
if offset <= maximumOffsetOn32BitArchitecture {
83
83
_kvcKeyPathStringPtr = UnsafePointer < CChar > ( bitPattern: ( offset + 1 ) )
@@ -96,7 +96,7 @@ public class AnyKeyPath: _AppendKeyPath {
96
96
}
97
97
98
98
#if _pointerBitWidth(_64)
99
- let offset = ( 0 &- Int ( bitPattern: _kvcKeyPathStringPtr) ) &- 1
99
+ let offset = unsafe ( 0 &- Int ( bitPattern: _kvcKeyPathStringPtr) ) &- 1
100
100
guard _fastPath ( offset >= 0 ) else {
101
101
// This happens to be an actual _kvcKeyPathStringPtr, not an offset, if
102
102
// we get here.
@@ -126,7 +126,7 @@ public class AnyKeyPath: _AppendKeyPath {
126
126
guard self . getOffsetFromStorage ( ) == nil else {
127
127
return nil
128
128
}
129
- guard let ptr = _kvcKeyPathStringPtr else { return nil }
129
+ guard let ptr = unsafe _kvcKeyPathStringPtr else { return nil }
130
130
131
131
return unsafe String( validatingCString: ptr)
132
132
}
@@ -155,7 +155,7 @@ public class AnyKeyPath: _AppendKeyPath {
155
155
" capacity must be multiple of 4 bytes " )
156
156
let result = Builtin . allocWithTailElems_1 ( self , ( bytes/ 4 ) . _builtinWordValue,
157
157
Int32 . self)
158
- result. _kvcKeyPathStringPtr = nil
158
+ unsafe result. _kvcKeyPathStringPtr = nil
159
159
let base = UnsafeMutableRawPointer ( Builtin . projectTailElems ( result,
160
160
Int32 . self) )
161
161
unsafe body( UnsafeMutableRawBufferPointer ( start: base, count: bytes) )
@@ -173,7 +173,7 @@ public class AnyKeyPath: _AppendKeyPath {
173
173
@usableFromInline // Exposed as public API by MemoryLayout<Root>.offset(of:)
174
174
internal var _storedInlineOffset : Int ? {
175
175
#if !$Embedded
176
- return withBuffer {
176
+ return unsafe withBuffer {
177
177
var buffer = unsafe $0
178
178
179
179
// The identity key path is effectively a stored keypath of type Self
@@ -219,7 +219,7 @@ extension AnyKeyPath: Hashable {
219
219
@_effects ( releasenone)
220
220
final public func hash( into hasher: inout Hasher ) {
221
221
ObjectIdentifier ( type ( of: self ) ) . hash ( into: & hasher)
222
- return withBuffer {
222
+ return unsafe withBuffer {
223
223
var buffer = unsafe $0
224
224
if unsafe buffer. data . isEmpty { return }
225
225
while true {
@@ -243,9 +243,9 @@ extension AnyKeyPath: Hashable {
243
243
if type ( of: a) != type ( of: b) {
244
244
return false
245
245
}
246
- return a. withBuffer {
246
+ return unsafe a. withBuffer {
247
247
var aBuffer = unsafe $0
248
- return b. withBuffer {
248
+ return unsafe b. withBuffer {
249
249
var bBuffer = unsafe $0
250
250
251
251
// Two equivalent key paths should have the same reference prefix
@@ -344,7 +344,7 @@ public class KeyPath<Root, Value>: PartialKeyPath<Root> {
344
344
}
345
345
}
346
346
347
- return withBuffer {
347
+ return unsafe withBuffer {
348
348
var buffer = unsafe $0
349
349
350
350
if unsafe _slowPath( buffer. data. isEmpty) {
@@ -441,7 +441,7 @@ public class KeyPath<Root, Value>: PartialKeyPath<Root> {
441
441
442
442
deinit {
443
443
#if !$Embedded
444
- withBuffer { unsafe $0. destroy ( ) }
444
+ unsafe withBuffer { unsafe $0. destroy ( ) }
445
445
#else
446
446
fatalError ( ) // unreachable, keypaths in embedded Swift are compile-time
447
447
#endif
@@ -475,7 +475,7 @@ public class WritableKeyPath<Root, Value>: KeyPath<Root, Value> {
475
475
var type : Any . Type = Root . self
476
476
var keepAlive : AnyObject ?
477
477
478
- return withBuffer {
478
+ return unsafe withBuffer {
479
479
var buffer = unsafe $0
480
480
481
481
unsafe _internalInvariant ( !buffer. hasReferencePrefix,
@@ -531,7 +531,7 @@ public class ReferenceWritableKeyPath<
531
531
internal final func _projectMutableAddress( from origBase: Root )
532
532
-> ( pointer: UnsafeMutablePointer < Value > , owner: AnyObject ? ) {
533
533
var keepAlive : AnyObject ?
534
- let address : UnsafeMutablePointer < Value > = withBuffer {
534
+ let address : UnsafeMutablePointer < Value > = unsafe withBuffer {
535
535
var buffer = unsafe $0
536
536
537
537
// Project out the reference prefix.
@@ -2619,9 +2619,9 @@ internal func _appendingKeyPaths<
2619
2619
leaf: KeyPath < Value , AppendedValue >
2620
2620
) -> Result {
2621
2621
let resultTy = type ( of: root) . appendedType ( with: type ( of: leaf) )
2622
- var returnValue : AnyKeyPath = root. withBuffer {
2622
+ var returnValue : AnyKeyPath = unsafe root. withBuffer {
2623
2623
var rootBuffer = unsafe $0
2624
- return leaf. withBuffer {
2624
+ return unsafe leaf. withBuffer {
2625
2625
var leafBuffer = unsafe $0
2626
2626
2627
2627
// If either operand is the identity key path, then we should return
@@ -2638,8 +2638,8 @@ internal func _appendingKeyPaths<
2638
2638
let appendedKVCLength : Int , rootKVCLength : Int , leafKVCLength : Int
2639
2639
2640
2640
if root. getOffsetFromStorage ( ) == nil , leaf. getOffsetFromStorage ( ) == nil ,
2641
- let rootPtr = root. _kvcKeyPathStringPtr,
2642
- let leafPtr = leaf. _kvcKeyPathStringPtr {
2641
+ let rootPtr = unsafe root. _kvcKeyPathStringPtr,
2642
+ let leafPtr = unsafe leaf. _kvcKeyPathStringPtr {
2643
2643
rootKVCLength = unsafe Int( _swift_stdlib_strlen ( rootPtr) )
2644
2644
leafKVCLength = unsafe Int( _swift_stdlib_strlen ( leafPtr) )
2645
2645
// root + "." + leaf
@@ -2673,7 +2673,7 @@ internal func _appendingKeyPaths<
2673
2673
2674
2674
var kvcStringBuffer : UnsafeMutableRawPointer ? = nil
2675
2675
2676
- let result = resultTy. _create ( capacityInBytes: totalResultSize) {
2676
+ let result = unsafe resultTy. _create ( capacityInBytes: totalResultSize) {
2677
2677
var destBuffer = unsafe $0
2678
2678
2679
2679
// Remember where the tail-allocated KVC string buffer begins.
@@ -2771,7 +2771,7 @@ internal func _appendingKeyPaths<
2771
2771
dest: kvcStringBuffer. advanced ( by: rootKVCLength + 1 ) ,
2772
2772
src: leafPtr,
2773
2773
size: UInt ( leafKVCLength) )
2774
- result. _kvcKeyPathStringPtr =
2774
+ unsafe result. _kvcKeyPathStringPtr =
2775
2775
unsafe UnsafePointer( kvcStringBuffer. assumingMemoryBound ( to: CChar . self) )
2776
2776
unsafe kvcStringBuffer. advanced ( by: rootKVCLength + leafKVCLength + 1 )
2777
2777
. storeBytes ( of: 0 /* '\0' */, as: CChar . self)
@@ -2874,7 +2874,7 @@ public func _swift_getKeyPath(pattern: UnsafeMutableRawPointer,
2874
2874
var pureStructOffset : UInt32 ? = nil
2875
2875
2876
2876
// Allocate the instance.
2877
- let instance = keyPathClass. _create (
2877
+ let instance = unsafe keyPathClass. _create (
2878
2878
capacityInBytes: sizeWithMaxSize
2879
2879
) { instanceData in
2880
2880
// Instantiate the pattern into the instance.
@@ -2893,11 +2893,11 @@ public func _swift_getKeyPath(pattern: UnsafeMutableRawPointer,
2893
2893
2894
2894
if kvcStringOffset == 0 {
2895
2895
// Null pointer.
2896
- instance. _kvcKeyPathStringPtr = nil
2896
+ unsafe instance. _kvcKeyPathStringPtr = nil
2897
2897
} else {
2898
2898
let kvcStringPtr = unsafe _resolveRelativeAddress( kvcStringBase, kvcStringOffset)
2899
- instance. _kvcKeyPathStringPtr =
2900
- unsafe kvcStringPtr. assumingMemoryBound ( to: CChar . self)
2899
+ unsafe instance. _kvcKeyPathStringPtr =
2900
+ kvcStringPtr. assumingMemoryBound ( to: CChar . self)
2901
2901
}
2902
2902
if unsafe instance. _kvcKeyPathStringPtr == nil , let offset = pureStructOffset {
2903
2903
instance. assignOffsetToStorage ( offset: Int ( offset) )
@@ -4222,7 +4222,7 @@ public func _createOffsetBasedKeyPath(
4222
4222
// The buffer header is 32 bits, but components must start on a word
4223
4223
// boundary.
4224
4224
let kpBufferSize = MemoryLayout < Int > . size + MemoryLayout < Int32 > . size
4225
- let kp = kpTy. _create ( capacityInBytes: kpBufferSize) {
4225
+ let kp = unsafe kpTy. _create ( capacityInBytes: kpBufferSize) {
4226
4226
var builder = unsafe KeyPathBuffer. Builder ( $0)
4227
4227
let header = unsafe KeyPathBuffer. Header (
4228
4228
size: kpBufferSize - MemoryLayout< Int> . size,
@@ -4265,7 +4265,7 @@ public func _rerootKeyPath<NewRoot>(
4265
4265
hasReferencePrefix,
4266
4266
isSingleComponent,
4267
4267
componentSize
4268
- ) = existingKp. withBuffer {
4268
+ ) = unsafe existingKp . withBuffer {
4269
4269
unsafe ( $0. trivial, $0. hasReferencePrefix, $0. isSingleComponent, $0. data. count)
4270
4270
}
4271
4271
@@ -4297,7 +4297,7 @@ public func _rerootKeyPath<NewRoot>(
4297
4297
capacity = MemoryLayout< Int> . _roundingUpToAlignment( capacity)
4298
4298
capacity += MemoryLayout< Int> . size
4299
4299
4300
- return newKpTy. _create (
4300
+ return unsafe newKpTy. _create (
4301
4301
capacityInBytes: capacity
4302
4302
) {
4303
4303
var builder = unsafe KeyPathBuffer. Builder ( $0)
@@ -4310,7 +4310,7 @@ public func _rerootKeyPath<NewRoot>(
4310
4310
4311
4311
unsafe builder. pushHeader ( header)
4312
4312
4313
- existingKp. withBuffer {
4313
+ unsafe existingKp . withBuffer {
4314
4314
var existingBuffer = unsafe $0
4315
4315
4316
4316
while true {
@@ -4382,7 +4382,7 @@ extension AnyKeyPath: CustomDebugStringConvertible {
4382
4382
@available ( SwiftStdlib 5 . 8 , * )
4383
4383
public var debugDescription : String {
4384
4384
var description = " \\ \( String ( describing: Self . rootType) ) "
4385
- return withBuffer {
4385
+ return unsafe withBuffer {
4386
4386
var buffer = unsafe $0
4387
4387
if unsafe buffer. data . isEmpty {
4388
4388
description. append ( " .self " )
0 commit comments