Skip to content

Commit b8bac2a

Browse files
committed
[stdlib] UnsafePointer: Resolve most of the symbol mismatches
1 parent b07c4b8 commit b8bac2a

File tree

2 files changed

+113
-20
lines changed

2 files changed

+113
-20
lines changed

stdlib/public/core/UnsafePointer.swift

Lines changed: 111 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,30 @@ extension UnsafePointer: _Pointer where Pointee: ~Copyable {
227227
public typealias Distance = Int
228228
}
229229

230-
extension UnsafePointer {
231-
// Note: This explicit `hashValue` applies @_preInverseGenerics to the
230+
@_preInverseGenerics
231+
extension UnsafePointer: Equatable where Pointee: ~Copyable {}
232+
@_preInverseGenerics
233+
extension UnsafePointer: Hashable where Pointee: ~Copyable {
234+
// Note: This explicit `hashValue` applies @_preInverseGenerics to emulate the
232235
// original (pre-6.0) compiler-synthesized version.
233236
@_preInverseGenerics
234237
public var hashValue: Int {
235238
_hashValue(for: self)
236239
}
237240
}
241+
@_preInverseGenerics
242+
extension UnsafePointer: Comparable where Pointee: ~Copyable {}
243+
@_preInverseGenerics
244+
extension UnsafePointer: Strideable where Pointee: ~Copyable {}
245+
#if !$Embedded
246+
@_preInverseGenerics
247+
extension UnsafePointer: CustomDebugStringConvertible
248+
where Pointee: ~Copyable {}
249+
#endif
250+
#if SWIFT_ENABLE_REFLECTION
251+
@_preInverseGenerics
252+
extension UnsafePointer: CustomReflectable where Pointee: ~Copyable {}
253+
#endif
238254

239255
extension UnsafePointer where Pointee: ~Copyable {
240256
/// Deallocates the memory block previously allocated at this pointer.
@@ -258,15 +274,27 @@ extension UnsafePointer where Pointee: ~Copyable {
258274
///
259275
/// When reading from the `pointee` property, the instance referenced by
260276
/// this pointer must already be initialized.
261-
@inlinable
262-
@_preInverseGenerics
277+
@_alwaysEmitIntoClient
263278
public var pointee: Pointee {
264279
@_transparent unsafeAddress {
265280
return self
266281
}
267282
}
268283
}
269284

285+
extension UnsafePointer {
286+
// This preserves the ABI of the original (pre-6.0) `pointee` property that
287+
// used to export a getter. The current one above would export a read
288+
// accessor, if it wasn't @_alwaysEmitIntoClient.
289+
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 2)
290+
@usableFromInline
291+
internal var pointee: Pointee {
292+
@_transparent unsafeAddress {
293+
return self
294+
}
295+
}
296+
}
297+
270298
extension UnsafePointer where Pointee: ~Copyable {
271299
/// Accesses the pointee at the specified offset from this pointer.
272300
///
@@ -275,8 +303,7 @@ extension UnsafePointer where Pointee: ~Copyable {
275303
///
276304
/// - Parameter i: The offset from this pointer at which to access an
277305
/// instance, measured in strides of the pointer's `Pointee` type.
278-
@inlinable
279-
@_preInverseGenerics
306+
@_alwaysEmitIntoClient
280307
public subscript(i: Int) -> Pointee {
281308
@_transparent
282309
unsafeAddress {
@@ -285,6 +312,20 @@ extension UnsafePointer where Pointee: ~Copyable {
285312
}
286313
}
287314

315+
extension UnsafePointer {
316+
// This preserves the ABI of the original (pre-6.0) subscript that used to
317+
// export a getter. The current one above would export a read accessor, if it
318+
// wasn't @_alwaysEmitIntoClient.
319+
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 2)
320+
@usableFromInline
321+
internal subscript(i: Int) -> Pointee {
322+
@_transparent
323+
unsafeAddress {
324+
return self + i
325+
}
326+
}
327+
}
328+
288329
extension UnsafePointer where Pointee: ~Copyable {
289330
/// Executes the given closure while temporarily binding memory to
290331
/// the specified number of instances of type `T`.
@@ -631,6 +672,31 @@ extension UnsafeMutablePointer: _Pointer where Pointee: ~Copyable {
631672
public typealias Distance = Int
632673
}
633674

675+
@_preInverseGenerics
676+
extension UnsafeMutablePointer: Equatable where Pointee: ~Copyable {}
677+
@_preInverseGenerics
678+
extension UnsafeMutablePointer: Hashable where Pointee: ~Copyable {
679+
// Note: This explicit `hashValue` applies @_preInverseGenerics to emulate the
680+
// original (pre-6.0) compiler-synthesized version.
681+
@_preInverseGenerics
682+
public var hashValue: Int {
683+
_hashValue(for: self)
684+
}
685+
}
686+
@_preInverseGenerics
687+
extension UnsafeMutablePointer: Comparable where Pointee: ~Copyable {}
688+
@_preInverseGenerics
689+
extension UnsafeMutablePointer: Strideable where Pointee: ~Copyable {}
690+
#if !$Embedded
691+
@_preInverseGenerics
692+
extension UnsafeMutablePointer: CustomDebugStringConvertible
693+
where Pointee: ~Copyable {}
694+
#endif
695+
#if SWIFT_ENABLE_REFLECTION
696+
@_preInverseGenerics
697+
extension UnsafeMutablePointer: CustomReflectable where Pointee: ~Copyable {}
698+
#endif
699+
634700
extension UnsafeMutablePointer where Pointee: ~Copyable {
635701
/// Creates a mutable typed pointer referencing the same memory as the given
636702
/// immutable pointer.
@@ -677,15 +743,6 @@ extension UnsafeMutablePointer where Pointee: ~Copyable {
677743
}
678744
}
679745

680-
extension UnsafeMutablePointer {
681-
// Note: This explicit `hashValue` applies @_preInverseGenerics to the
682-
// original (pre-6.0) compiler-synthesized version.
683-
@_preInverseGenerics
684-
public var hashValue: Int {
685-
_hashValue(for: self)
686-
}
687-
}
688-
689746
extension UnsafeMutablePointer where Pointee: ~Copyable {
690747
/// Allocates uninitialized memory for the specified number of instances of
691748
/// type `Pointee`.
@@ -765,8 +822,7 @@ extension UnsafeMutablePointer where Pointee: ~Copyable {
765822
/// Uninitialized memory cannot be initialized to a nontrivial type
766823
/// using `pointee`. Instead, use an initializing method, such as
767824
/// `initialize(to:)`.
768-
@inlinable // unsafe-performance
769-
@_preInverseGenerics
825+
@_alwaysEmitIntoClient
770826
public var pointee: Pointee {
771827
@_transparent unsafeAddress {
772828
return UnsafePointer(self)
@@ -777,6 +833,23 @@ extension UnsafeMutablePointer where Pointee: ~Copyable {
777833
}
778834
}
779835

836+
extension UnsafeMutablePointer {
837+
// This preserves the ABI of the original (pre-6.0) `pointee` property that
838+
// used to export a getter. The current one above would export a read
839+
// accessor, if it wasn't @_alwaysEmitIntoClient.
840+
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 2)
841+
@usableFromInline
842+
internal var pointee: Pointee {
843+
@_transparent unsafeAddress {
844+
return UnsafePointer(self)
845+
}
846+
@_transparent nonmutating unsafeMutableAddress {
847+
return self
848+
}
849+
}
850+
}
851+
852+
780853
extension UnsafeMutablePointer {
781854
/// Initializes this pointer's memory with the specified number of
782855
/// consecutive copies of the given value.
@@ -952,7 +1025,7 @@ extension UnsafeMutablePointer where Pointee: ~Copyable {
9521025
/// referenced by `source` and this pointer may overlap.
9531026
/// - count: The number of instances to move from `source` to this
9541027
/// pointer's memory. `count` must not be negative.
955-
@_alwaysEmitIntoClient
1028+
@inlinable
9561029
@_preInverseGenerics
9571030
public func moveInitialize(
9581031
@_nonEphemeral from source: UnsafeMutablePointer, count: Int
@@ -1036,6 +1109,7 @@ extension UnsafeMutablePointer where Pointee: ~Copyable {
10361109
/// - count: The number of instances to move from `source` to this
10371110
/// pointer's memory. `count` must not be negative.
10381111
@inlinable
1112+
@_silgen_name("$sSp10moveAssign4from5countySpyxG_SitF")
10391113
@_preInverseGenerics
10401114
public func moveUpdate(
10411115
@_nonEphemeral from source: UnsafeMutablePointer, count: Int
@@ -1203,8 +1277,7 @@ extension UnsafeMutablePointer where Pointee: ~Copyable {
12031277
///
12041278
/// - Parameter i: The offset from this pointer at which to access an
12051279
/// instance, measured in strides of the pointer's `Pointee` type.
1206-
@inlinable
1207-
@_preInverseGenerics
1280+
@_alwaysEmitIntoClient
12081281
public subscript(i: Int) -> Pointee {
12091282
@_transparent
12101283
unsafeAddress {
@@ -1217,6 +1290,24 @@ extension UnsafeMutablePointer where Pointee: ~Copyable {
12171290
}
12181291
}
12191292

1293+
extension UnsafeMutablePointer {
1294+
// This preserves the ABI of the original (pre-6.0) subscript that used to
1295+
// export a getter. The current one above would export a read accessor, if it
1296+
// wasn't @_alwaysEmitIntoClient.
1297+
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 2)
1298+
@usableFromInline
1299+
internal subscript(i: Int) -> Pointee {
1300+
@_transparent
1301+
unsafeAddress {
1302+
return UnsafePointer(self + i)
1303+
}
1304+
@_transparent
1305+
nonmutating unsafeMutableAddress {
1306+
return self + i
1307+
}
1308+
}
1309+
}
1310+
12201311
extension UnsafeMutablePointer {
12211312
/// Obtain a pointer to the stored property referred to by a key path.
12221313
///

stdlib/public/core/VarArgs.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ extension OpaquePointer: CVarArg {
350350
}
351351
}
352352

353+
@_preInverseGenerics
353354
extension UnsafePointer: CVarArg where Pointee: ~Copyable {
354355
/// Transform `self` into a series of machine words that can be
355356
/// appropriately interpreted by C varargs.
@@ -360,6 +361,7 @@ extension UnsafePointer: CVarArg where Pointee: ~Copyable {
360361
}
361362
}
362363

364+
@_preInverseGenerics
363365
extension UnsafeMutablePointer: CVarArg where Pointee: ~Copyable {
364366
/// Transform `self` into a series of machine words that can be
365367
/// appropriately interpreted by C varargs.

0 commit comments

Comments
 (0)