Skip to content

Commit 1ec03e1

Browse files
authored
Merge pull request swiftlang#74017 from Azoy/pointer-transparent
[stdlib] Mark some UnsafePointer APIs as transparent
2 parents c3d8251 + 47c584f commit 1ec03e1

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

stdlib/public/core/UnsafePointer.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ extension UnsafePointer where Pointee: ~Copyable {
262262
/// This pointer must be a pointer to the start of a previously allocated
263263
/// memory block. The memory must not be initialized or `Pointee` must be a
264264
/// trivial type.
265-
@inlinable
266265
@_preInverseGenerics
266+
@_transparent
267267
public func deallocate() {
268268
// Passing zero alignment to the runtime forces "aligned
269269
// deallocation". Since allocation via `UnsafeMutable[Raw][Buffer]Pointer`
@@ -777,8 +777,8 @@ extension UnsafeMutablePointer where Pointee: ~Copyable {
777777
///
778778
/// - Parameter count: The amount of memory to allocate, counted in instances
779779
/// of `Pointee`.
780-
@inlinable
781780
@_preInverseGenerics
781+
@_transparent
782782
public static func allocate(
783783
capacity count: Int
784784
) -> UnsafeMutablePointer<Pointee> {
@@ -810,8 +810,8 @@ extension UnsafeMutablePointer where Pointee: ~Copyable {
810810
/// This pointer must be a pointer to the start of a previously allocated
811811
/// memory block. The memory must not be initialized or `Pointee` must be a
812812
/// trivial type.
813-
@inlinable
814813
@_preInverseGenerics
814+
@_transparent
815815
public func deallocate() {
816816
// Passing zero alignment to the runtime forces "aligned
817817
// deallocation". Since allocation via `UnsafeMutable[Raw][Buffer]Pointer`
@@ -898,6 +898,7 @@ extension UnsafeMutablePointer where Pointee: ~Copyable {
898898
/// - Parameters:
899899
/// - value: The instance to initialize this pointer's pointee to.
900900
@_alwaysEmitIntoClient
901+
@_transparent
901902
public func initialize(to value: consuming Pointee) {
902903
Builtin.initialize(value, self._rawValue)
903904
}
@@ -928,8 +929,8 @@ extension UnsafeMutablePointer where Pointee: ~Copyable {
928929
/// `move()`, the memory is uninitialized.
929930
///
930931
/// - Returns: The instance referenced by this pointer.
931-
@inlinable
932932
@_preInverseGenerics
933+
@_transparent
933934
public func move() -> Pointee {
934935
return Builtin.take(_rawValue)
935936
}
@@ -1162,9 +1163,9 @@ extension UnsafeMutablePointer where Pointee: ~Copyable {
11621163
/// not be negative.
11631164
/// - Returns: A raw pointer to the same address as this pointer. The memory
11641165
/// referenced by the returned raw pointer is still bound to `Pointee`.
1165-
@inlinable
1166-
@_preInverseGenerics
11671166
@discardableResult
1167+
@_preInverseGenerics
1168+
@_transparent
11681169
public func deinitialize(count: Int) -> UnsafeMutableRawPointer {
11691170
_debugPrecondition(count >= 0, "UnsafeMutablePointer.deinitialize with negative count")
11701171
// Note: When count is statically known to be 1 the compiler will optimize

test/SILOptimizer/stdlib/Cell.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ public struct Cell<T: ~Copyable>: ~Copyable {
2020
// CHECK: bb0({{%.*}} : $*Cell<T>, [[VALUE:%.*]] : $*T, {{%.*}} : $@thin Cell<T>.Type):
2121
// CHECK: {{%.*}} = builtin "zeroInitializer"<Cell<T>>([[SELF:%.*]] : $*Cell<T>) : $()
2222
// CHECK-NEXT: [[RAW_LAYOUT_ADDR:%.*]] = builtin "addressOfRawLayout"<Cell<T>>([[SELF]] : $*Cell<T>) : $Builtin.RawPointer
23-
// CHECK-NEXT: [[POINTER:%.*]] = struct $UnsafeMutablePointer<T> ([[RAW_LAYOUT_ADDR]] : $Builtin.RawPointer)
24-
// Calling 'UnsafeMutablePointer<T>.initialize(to:)'
25-
// CHECK: {{%.*}} = apply {{%.*}}<T>([[VALUE]], [[POINTER]])
2623
// CHECK-LABEL: } // end sil function '$s4CellAAVAARi_zrlEyAByxGxcfC'
2724
@_transparent
2825
public init(_ value: consuming T) {

0 commit comments

Comments
 (0)