Skip to content

Commit 6fa2ae0

Browse files
committed
[stdlib] Move the public API of AutoreleasingUnsafeMutablePointer to the ObjectiveC overlay from StdlibCore.
1 parent 558f2b8 commit 6fa2ae0

File tree

9 files changed

+44
-18
lines changed

9 files changed

+44
-18
lines changed

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ NominalTypeDecl *ASTContext::getUnsafePointerDecl() const {
753753
NominalTypeDecl *ASTContext::getAutoreleasingUnsafeMutablePointerDecl() const {
754754
if (!Impl.AutoreleasingUnsafeMutablePointerDecl)
755755
Impl.AutoreleasingUnsafeMutablePointerDecl
756-
= findStdlibType(*this, "AutoreleasingUnsafeMutablePointer", 1);
756+
= findStdlibType(*this, "_AutoreleasingUnsafeMutablePointer", 1);
757757

758758
return Impl.AutoreleasingUnsafeMutablePointerDecl;
759759
}

lib/ClangImporter/ImportType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ namespace {
351351
quals.getObjCLifetime() == clang::Qualifiers::OCL_ExplicitNone) {
352352
return {
353353
Impl.getNamedSwiftTypeSpecialization(
354-
Impl.getStdlibModule(), "AutoreleasingUnsafeMutablePointer",
354+
Impl.getStdlibModule(), "_AutoreleasingUnsafeMutablePointer",
355355
pointeeType),
356356
ImportHint::OtherPointer};
357357
}
@@ -1179,7 +1179,7 @@ static Type adjustTypeForConcreteImport(ClangImporter::Implementation &impl,
11791179
if (importKind == ImportTypeKind::CFRetainedOutParameter)
11801180
pointerName = "UnsafeMutablePointer";
11811181
else
1182-
pointerName = "AutoreleasingUnsafeMutablePointer";
1182+
pointerName = "_AutoreleasingUnsafeMutablePointer";
11831183

11841184
resultTy = impl.getNamedSwiftTypeSpecialization(impl.getStdlibModule(),
11851185
pointerName,

lib/IRGen/GenClangType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ GenClangType::visitBoundGenericType(CanBoundGenericType type) {
442442
.Case("UnsafeMutablePointer", StructKind::UnsafeMutablePointer)
443443
.Case("UnsafePointer", StructKind::UnsafePointer)
444444
.Case(
445-
"AutoreleasingUnsafeMutablePointer",
445+
"_AutoreleasingUnsafeMutablePointer",
446446
StructKind::AutoreleasingUnsafeMutablePointer)
447447
.Case("Unmanaged", StructKind::Unmanaged)
448448
.Case("CFunctionPointer", StructKind::CFunctionPointer)

stdlib/public/SDK/ObjectiveC/ObjectiveC.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,29 @@ extension NSObject : CVarArg {
243243
}
244244
}
245245

246+
//===----------------------------------------------------------------------===//
247+
// AutoreleasingUnsafeMutablePointer
248+
//===----------------------------------------------------------------------===//
249+
250+
/// A mutable pointer-to-ObjC-pointer argument.
251+
///
252+
/// This type has implicit conversions to allow passing any of the following
253+
/// to a C or ObjC API:
254+
///
255+
/// - `nil`, which gets passed as a null pointer,
256+
/// - an inout argument of the referenced type, which gets passed as a pointer
257+
/// to a writeback temporary with autoreleasing ownership semantics,
258+
/// - an `UnsafeMutablePointer<Pointee>`, which is passed as-is.
259+
///
260+
/// Passing pointers to mutable arrays of ObjC class pointers is not
261+
/// directly supported. Unlike `UnsafeMutablePointer<Pointee>`,
262+
/// `AutoreleasingUnsafeMutablePointer<Pointee>` must reference storage that
263+
/// does not own a reference count to the referenced
264+
/// value. UnsafeMutablePointer's operations, by contrast, assume that
265+
/// the referenced storage owns values loaded from or stored to it.
266+
///
267+
/// This type does not carry an owner pointer unlike the other C*Pointer types
268+
/// because it only needs to reference the results of inout conversions, which
269+
/// already have writeback-scoped lifetime.
270+
public typealias AutoreleasingUnsafeMutablePointer<Pointee> =
271+
_AutoreleasingUnsafeMutablePointer<Pointee>

stdlib/public/core/BridgeObjectiveC.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ internal var _nilNativeObject: AnyObject? {
369369
///
370370
/// Passing pointers to mutable arrays of ObjC class pointers is not
371371
/// directly supported. Unlike `UnsafeMutablePointer<Pointee>`,
372-
/// `AutoreleasingUnsafeMutablePointer<Pointee>` must reference storage that
372+
/// `_AutoreleasingUnsafeMutablePointer<Pointee>` must reference storage that
373373
/// does not own a reference count to the referenced
374374
/// value. UnsafeMutablePointer's operations, by contrast, assume that
375375
/// the referenced storage owns values loaded from or stored to it.
@@ -378,7 +378,7 @@ internal var _nilNativeObject: AnyObject? {
378378
/// because it only needs to reference the results of inout conversions, which
379379
/// already have writeback-scoped lifetime.
380380
@_fixed_layout
381-
public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
381+
public struct _AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
382382
: Equatable, _Pointer {
383383

384384
public let _rawValue: Builtin.RawPointer
@@ -401,7 +401,7 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
401401
}
402402
/// Set the value the pointer points to, copying over the previous value.
403403
///
404-
/// AutoreleasingUnsafeMutablePointers are assumed to reference a
404+
/// _AutoreleasingUnsafeMutablePointers are assumed to reference a
405405
/// value with __autoreleasing ownership semantics, like 'NSFoo**'
406406
/// in ARC. This autoreleases the argument before trivially
407407
/// storing it to the referenced memory.
@@ -436,7 +436,7 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
436436
///
437437
/// This is inherently unsafe; UnsafeMutablePointer assumes the
438438
/// referenced memory has +1 strong ownership semantics, whereas
439-
/// AutoreleasingUnsafeMutablePointer implies +0 semantics.
439+
/// _AutoreleasingUnsafeMutablePointer implies +0 semantics.
440440
@_transparent public
441441
init<U>(_ from: UnsafeMutablePointer<U>) {
442442
self._rawValue = from._rawValue
@@ -448,7 +448,7 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
448448
///
449449
/// This is inherently unsafe; UnsafeMutablePointer assumes the
450450
/// referenced memory has +1 strong ownership semantics, whereas
451-
/// AutoreleasingUnsafeMutablePointer implies +0 semantics.
451+
/// _AutoreleasingUnsafeMutablePointer implies +0 semantics.
452452
@_transparent public
453453
init?<U>(_ from: UnsafeMutablePointer<U>?) {
454454
guard let unwrapped = from else { return nil }
@@ -477,7 +477,7 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
477477
}
478478
}
479479

480-
extension AutoreleasingUnsafeMutablePointer : CustomDebugStringConvertible {
480+
extension _AutoreleasingUnsafeMutablePointer : CustomDebugStringConvertible {
481481
/// A textual representation of `self`, suitable for debugging.
482482
public var debugDescription: String {
483483
return _rawPointerToString(_rawValue)
@@ -486,8 +486,8 @@ extension AutoreleasingUnsafeMutablePointer : CustomDebugStringConvertible {
486486

487487
@_transparent
488488
public func == <Pointee>(
489-
lhs: AutoreleasingUnsafeMutablePointer<Pointee>,
490-
rhs: AutoreleasingUnsafeMutablePointer<Pointee>
489+
lhs: _AutoreleasingUnsafeMutablePointer<Pointee>,
490+
rhs: _AutoreleasingUnsafeMutablePointer<Pointee>
491491
) -> Bool {
492492
return Bool(Builtin.cmp_eq_RawPointer(lhs._rawValue, rhs._rawValue))
493493
}
@@ -540,7 +540,7 @@ internal struct _CocoaFastEnumerationStackBuf {
540540
}
541541
}
542542

543-
extension AutoreleasingUnsafeMutablePointer {
543+
extension _AutoreleasingUnsafeMutablePointer {
544544
@available(*, unavailable, renamed: "Pointee")
545545
public typealias Memory = Pointee
546546

stdlib/public/core/HashedCollections.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,7 +3215,7 @@ final internal class _Native${Self}StorageKeyNSEnumerator<
32153215
var theState = state.pointee
32163216
if theState.state == 0 {
32173217
theState.state = 1 // Arbitrary non-zero value.
3218-
theState.itemsPtr = AutoreleasingUnsafeMutablePointer(objects)
3218+
theState.itemsPtr = _AutoreleasingUnsafeMutablePointer(objects)
32193219
theState.mutationsPtr = _fastEnumerationStorageMutationsPtr
32203220
}
32213221

@@ -3548,7 +3548,7 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
35483548
var theState = state.pointee
35493549
if theState.state == 0 {
35503550
theState.state = 1 // Arbitrary non-zero value.
3551-
theState.itemsPtr = AutoreleasingUnsafeMutablePointer(objects)
3551+
theState.itemsPtr = _AutoreleasingUnsafeMutablePointer(objects)
35523552
theState.mutationsPtr = _fastEnumerationStorageMutationsPtr
35533553
theState.extra.0 = CUnsignedLong(nativeStorage.startIndex.offset)
35543554
}

stdlib/public/core/Pointer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
/// A stdlib-internal protocol modeled by the intrinsic pointer types,
1414
/// UnsafeMutablePointer, UnsafePointer, and
15-
/// AutoreleasingUnsafeMutablePointer.
15+
/// _AutoreleasingUnsafeMutablePointer.
1616
public protocol _Pointer {
1717
/// The underlying raw pointer value.
1818
var _rawValue: Builtin.RawPointer { get }

stdlib/public/core/SwiftNativeNSArray.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ extension _SwiftNativeNSArrayWithContiguousStorage : _NSArrayCore {
105105
objects in
106106
enumerationState.mutationsPtr = _fastEnumerationStorageMutationsPtr
107107
enumerationState.itemsPtr =
108-
AutoreleasingUnsafeMutablePointer(objects.baseAddress)
108+
_AutoreleasingUnsafeMutablePointer(objects.baseAddress)
109109
enumerationState.state = 1
110110
state.pointee = enumerationState
111111
return objects.count

stdlib/public/core/VarArgs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ extension UnsafeMutablePointer : CVarArg {
245245
}
246246

247247
#if _runtime(_ObjC)
248-
extension AutoreleasingUnsafeMutablePointer : CVarArg {
248+
extension _AutoreleasingUnsafeMutablePointer : CVarArg {
249249
/// Transform `self` into a series of machine words that can be
250250
/// appropriately interpreted by C varargs.
251251
public var _cVarArgEncoding: [Int] {

0 commit comments

Comments
 (0)