Skip to content

Commit 157fdd3

Browse files
authored
Merge pull request #82342 from compnerd/unsafe
stdlib: handle `unsafe` annotations in additional places
2 parents 6db11b6 + c17e67e commit 157fdd3

File tree

7 files changed

+21
-20
lines changed

7 files changed

+21
-20
lines changed

stdlib/public/Distributed/LocalTestingDistributedActorSystem.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ fileprivate class _Lock {
255255
unsafe self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
256256
unsafe self.underlying.initialize(to: os_unfair_lock())
257257
#elseif os(Windows)
258-
self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
259-
InitializeSRWLock(self.underlying)
258+
unsafe self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
259+
unsafe InitializeSRWLock(self.underlying)
260260
#elseif os(WASI)
261261
// WASI environment has only a single thread
262262
#else
@@ -292,7 +292,7 @@ fileprivate class _Lock {
292292
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) || os(visionOS)
293293
unsafe os_unfair_lock_lock(self.underlying)
294294
#elseif os(Windows)
295-
AcquireSRWLockExclusive(self.underlying)
295+
unsafe AcquireSRWLockExclusive(self.underlying)
296296
#elseif os(WASI)
297297
// WASI environment has only a single thread
298298
#else
@@ -305,7 +305,7 @@ fileprivate class _Lock {
305305
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) || os(visionOS)
306306
unsafe os_unfair_lock_unlock(self.underlying)
307307
#elseif os(Windows)
308-
ReleaseSRWLockExclusive(self.underlying)
308+
unsafe ReleaseSRWLockExclusive(self.underlying)
309309
#elseif os(WASI)
310310
// WASI environment has only a single thread
311311
#else

stdlib/public/core/BridgeObjectiveC.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,19 +716,19 @@ public func swift_unboxFromSwiftValueWithType<T>(
716716

717717
if source === _nullPlaceholder {
718718
if let unpacked = Optional<Any>.none as? T {
719-
result.initialize(to: unpacked)
719+
unsafe result.initialize(to: unpacked)
720720
return true
721721
}
722722
}
723723

724724
if let box = source as? __SwiftValue {
725725
if let value = box.value as? T {
726-
result.initialize(to: value)
726+
unsafe result.initialize(to: value)
727727
return true
728728
}
729729
} else if let box = source as? _NSSwiftValue {
730730
if let value = box.value as? T {
731-
result.initialize(to: value)
731+
unsafe result.initialize(to: value)
732732
return true
733733
}
734734
}
@@ -819,7 +819,7 @@ public func _bridgeAnythingToObjectiveC<T>(_ x: T) -> AnyObject {
819819

820820
if !done {
821821
if type(of: source) as? AnyClass != nil {
822-
result = unsafeBitCast(x, to: AnyObject.self)
822+
result = unsafe unsafeBitCast(x, to: AnyObject.self)
823823
} else if let object = _bridgeToObjectiveCUsingProtocolIfPossible(source) {
824824
result = object
825825
} else {

stdlib/public/core/Int128.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public struct Int128: Sendable {
7676
public var _value: Builtin.Int128 {
7777
@_transparent
7878
get {
79-
unsafeBitCast(self, to: Builtin.Int128.self)
79+
unsafe unsafeBitCast(self, to: Builtin.Int128.self)
8080
}
8181

8282
@_transparent
@@ -88,7 +88,7 @@ public struct Int128: Sendable {
8888
@available(SwiftStdlib 6.0, *)
8989
@_transparent
9090
public init(_ _value: Builtin.Int128) {
91-
self = unsafeBitCast(_value, to: Self.self)
91+
self = unsafe unsafeBitCast(_value, to: Self.self)
9292
}
9393
#endif
9494

stdlib/public/core/KeyPath.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ public class AnyKeyPath: _AppendKeyPath {
8080
unsafe _kvcKeyPathStringPtr = UnsafePointer<CChar>(bitPattern: -offset - 1)
8181
#elseif _pointerBitWidth(_32)
8282
if offset <= maximumOffsetOn32BitArchitecture {
83-
_kvcKeyPathStringPtr = UnsafePointer<CChar>(bitPattern: (offset + 1))
83+
unsafe _kvcKeyPathStringPtr =
84+
UnsafePointer<CChar>(bitPattern: (offset + 1))
8485
} else {
85-
_kvcKeyPathStringPtr = nil
86+
unsafe _kvcKeyPathStringPtr = nil
8687
}
8788
#else
8889
// Don't assign anything.
@@ -104,7 +105,7 @@ public class AnyKeyPath: _AppendKeyPath {
104105
}
105106
return offset
106107
#elseif _pointerBitWidth(_32)
107-
let offset = Int(bitPattern: _kvcKeyPathStringPtr) &- 1
108+
let offset = unsafe Int(bitPattern: _kvcKeyPathStringPtr) &- 1
108109
// Pointers above 0x7fffffff will come in as negative numbers which are
109110
// less than maximumOffsetOn32BitArchitecture, be sure to reject them.
110111
if offset >= 0, offset <= maximumOffsetOn32BitArchitecture {
@@ -4152,7 +4153,7 @@ internal func _instantiateKeyPathBuffer(
41524153
var walker = unsafe ValidatingInstantiateKeyPathBuffer(sizeVisitor: sizeWalker,
41534154
instantiateVisitor: instantiateWalker)
41544155
#else
4155-
var walker = InstantiateKeyPathBuffer(
4156+
var walker = unsafe InstantiateKeyPathBuffer(
41564157
destData: destData,
41574158
patternArgs: arguments,
41584159
root: rootType)
@@ -4165,8 +4166,8 @@ internal func _instantiateKeyPathBuffer(
41654166
let endOfReferencePrefixComponent =
41664167
unsafe walker.instantiateVisitor.endOfReferencePrefixComponent
41674168
#else
4168-
let isTrivial = walker.isTrivial
4169-
let endOfReferencePrefixComponent = walker.endOfReferencePrefixComponent
4169+
let isTrivial = unsafe walker.isTrivial
4170+
let endOfReferencePrefixComponent = unsafe walker.endOfReferencePrefixComponent
41704171
#endif
41714172

41724173
// Write out the header.

stdlib/public/core/StringObject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ extension _StringObject {
12451245
countAndFlags: countAndFlags)
12461246
#elseif _pointerBitWidth(_32) || _pointerBitWidth(_16)
12471247
self.init(
1248-
variant: .immortal(start: bufPtr.baseAddress._unsafelyUnwrappedUnchecked),
1248+
variant: unsafe .immortal(start: bufPtr.baseAddress._unsafelyUnwrappedUnchecked),
12491249
discriminator: Nibbles.largeImmortal(),
12501250
countAndFlags: countAndFlags)
12511251
#else

stdlib/public/core/UInt128.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public struct UInt128: Sendable {
7676
public var _value: Builtin.Int128 {
7777
@_transparent
7878
get {
79-
unsafeBitCast(self, to: Builtin.Int128.self)
79+
unsafe unsafeBitCast(self, to: Builtin.Int128.self)
8080
}
8181

8282
@_transparent
@@ -88,7 +88,7 @@ public struct UInt128: Sendable {
8888
@available(SwiftStdlib 6.0, *)
8989
@_transparent
9090
public init(_ _value: Builtin.Int128) {
91-
self = unsafeBitCast(_value, to: Self.self)
91+
self = unsafe unsafeBitCast(_value, to: Self.self)
9292
}
9393
#endif
9494

stdlib/public/core/VarArgs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ final internal class __VaListBuilder {
609609
// We may need to retain an object that provides a pointer value.
610610
if let obj = arg as? _CVarArgObject {
611611
arg = obj._cVarArgObject
612-
retainer.append(arg)
612+
unsafe retainer.append(arg)
613613
}
614614
#endif
615615

0 commit comments

Comments
 (0)