Skip to content

Commit 5a2d162

Browse files
committed
[KeyPath] Restrict push and pop to BitwiseCopyable
Promotes the runtime isPOD check to a compile time constraint.
1 parent 134fc4d commit 5a2d162

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

stdlib/public/core/KeyPath.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,15 +1814,14 @@ internal struct RawKeyPathComponent {
18141814
}
18151815
}
18161816

1817-
internal func _pop<T>(from: inout UnsafeRawBufferPointer,
1817+
internal func _pop<T : _BitwiseCopyable>(from: inout UnsafeRawBufferPointer,
18181818
as type: T.Type) -> T {
18191819
let buffer = _pop(from: &from, as: type, count: 1)
18201820
return buffer.baseAddress.unsafelyUnwrapped.pointee
18211821
}
1822-
internal func _pop<T>(from: inout UnsafeRawBufferPointer,
1822+
internal func _pop<T : _BitwiseCopyable>(from: inout UnsafeRawBufferPointer,
18231823
as: T.Type,
18241824
count: Int) -> UnsafeBufferPointer<T> {
1825-
_internalInvariant(_isPOD(T.self), "should be POD")
18261825
from = MemoryLayout<T>._roundingUpBaseToAlignment(from)
18271826
let byteCount = MemoryLayout<T>.stride * count
18281827
let result = UnsafeBufferPointer(
@@ -3414,8 +3413,7 @@ internal struct InstantiateKeyPathBuffer: KeyPathPatternVisitor {
34143413
}
34153414
return (baseAddress, misalign)
34163415
}
3417-
mutating func pushDest<T>(_ value: T) {
3418-
_internalInvariant(_isPOD(T.self))
3416+
mutating func pushDest<T : _BitwiseCopyable>(_ value: T) {
34193417
let size = MemoryLayout<T>.size
34203418
let (baseAddress, misalign) = adjustDestForAlignment(of: T.self)
34213419
_withUnprotectedUnsafeBytes(of: value) {

0 commit comments

Comments
 (0)