Skip to content

Commit 56dd5ea

Browse files
authored
Merge pull request #3644 from swiftix/stdlib-cleanups
Remove unsafeAddress(of:) as per SE-0127
2 parents 1d4a970 + 880be3b commit 56dd5ea

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

stdlib/private/SwiftReflectionTest/SwiftReflectionTest.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ internal func sendBytes<T>(from address: UnsafePointer<T>, count: Int) {
156156
internal func sendAddress(of instance: AnyObject) {
157157
debugLog("BEGIN \(#function)")
158158
defer { debugLog("END \(#function)") }
159-
var address = unsafeAddress(of: instance)
159+
var address = Unmanaged.passUnretained(instance).toOpaque()
160160
sendBytes(from: &address, count: sizeof(UInt.self))
161161
}
162162

@@ -296,8 +296,9 @@ internal func reflect(instanceAddress: UInt, kind: InstanceKind) {
296296
/// This reflects the stored properties of the immediate class.
297297
/// The superclass is not (yet?) visited.
298298
public func reflect(object: AnyObject) {
299-
let address = unsafeAddress(of: object)
300-
let addressValue = unsafeBitCast(address, to: UInt.self)
299+
defer { _fixLifetime(object) }
300+
var address = Unmanaged.passUnretained(object).toOpaque()
301+
let addressValue = UInt(bitPattern: address)
301302
reflect(instanceAddress: addressValue, kind: .Object)
302303
}
303304

stdlib/public/SwiftShims/RuntimeShims.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ typedef struct Metadata Metadata;
3737
#define bool _Bool
3838
#endif
3939

40-
SWIFT_RUNTIME_EXPORT
41-
bool swift_objc_class_usesNativeSwiftReferenceCounting(const void *);
42-
4340
/// Return an NSString to be used as the Mirror summary of the object
4441
SWIFT_RUNTIME_STDLIB_INTERFACE
4542
void *_swift_objCMirrorSummary(const void * nsObject);

stdlib/public/core/ArrayBuffer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ extension _ArrayBuffer {
437437
return _native.identity
438438
}
439439
else {
440-
return unsafeAddress(of: _nonNative)
440+
return UnsafeRawPointer(Unmanaged.passUnretained(_nonNative).toOpaque())
441441
}
442442
}
443443

stdlib/public/core/Builtin.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,13 @@ internal func _isClassOrObjCExistential<T>(_ x: T.Type) -> Bool {
206206
/// Returns an `UnsafePointer` to the storage used for `object`. There's
207207
/// not much you can do with this other than use it to identify the
208208
/// object.
209-
@_transparent
210-
public func unsafeAddress(of object: AnyObject) -> UnsafeRawPointer {
211-
return UnsafeRawPointer(Builtin.bridgeToRawPointer(object))
209+
@available(*, unavailable, message: "Removed in Swift 3. Use Unmanaged.passUnretained(x).toOpaque() instead.")
210+
public func unsafeAddress(of object: AnyObject) -> UnsafePointer<Void> {
211+
Builtin.unreachable()
212212
}
213213

214-
@available(*, unavailable, renamed: "unsafeAddress(of:)")
215-
public func unsafeAddressOf(_ object: AnyObject) -> UnsafeRawPointer {
214+
@available(*, unavailable, message: "Removed in Swift 3. Use Unmanaged.passUnretained(x).toOpaque() instead.")
215+
public func unsafeAddressOf(_ object: AnyObject) -> UnsafePointer<Void> {
216216
Builtin.unreachable()
217217
}
218218

@@ -293,17 +293,19 @@ public func _onFastPath() {
293293

294294
/// Returns `true` iff the class indicated by `theClass` uses native
295295
/// Swift reference-counting.
296-
@_versioned
297-
@inline(__always)
298-
internal func _usesNativeSwiftReferenceCounting(_ theClass: AnyClass) -> Bool {
299296
#if _runtime(_ObjC)
300-
return swift_objc_class_usesNativeSwiftReferenceCounting(
301-
unsafeAddress(of: theClass)
302-
)
297+
// Declare it here instead of RuntimeShims.h, because we need to specify
298+
// the type of argument to be AnyClass. This is currently not possible
299+
// when using RuntimeShims.h
300+
@_silgen_name("swift_objc_class_usesNativeSwiftReferenceCounting")
301+
func _usesNativeSwiftReferenceCounting(_ theClass: AnyClass) -> Bool
303302
#else
303+
@_versioned
304+
@inline(__always)
305+
func _usesNativeSwiftReferenceCounting(_ theClass: AnyClass) -> Bool {
304306
return true
305-
#endif
306307
}
308+
#endif
307309

308310
@_silgen_name("swift_class_getInstanceExtents")
309311
func swift_class_getInstanceExtents(_ theClass: AnyClass)

stdlib/public/runtime/SwiftObject.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,10 @@ - (BOOL)isNSValue__ { return NO; }
385385
}
386386

387387
// version for SwiftShims
388+
SWIFT_RUNTIME_EXPORT
389+
extern "C"
388390
bool
389-
swift::swift_objc_class_usesNativeSwiftReferenceCounting(const void *theClass) {
391+
swift_objc_class_usesNativeSwiftReferenceCounting(const void *theClass) {
390392
#if SWIFT_OBJC_INTEROP
391393
return usesNativeSwiftReferenceCounting((const ClassMetadata *)theClass);
392394
#else

test/1_stdlib/Renames.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ func _Arrays<T>(e: T) {
3131
}
3232

3333
func _Builtin(o: AnyObject, oo: AnyObject?) {
34-
_ = unsafeAddressOf(o) // expected-error {{'unsafeAddressOf' has been renamed to 'unsafeAddress(of:)'}} {{7-22=unsafeAddress}} {{23-23=of: }} {{none}}
34+
_ = unsafeAddressOf(o) // expected-error {{Removed in Swift 3. Use Unmanaged.passUnretained(x).toOpaque() instead.}} {{none}}
35+
_ = unsafeAddress(of: o) // expected-error {{Removed in Swift 3. Use Unmanaged.passUnretained(x).toOpaque() instead.}} {{none}}
3536
_ = unsafeUnwrap(oo) // expected-error {{Removed in Swift 3. Please use Optional.unsafelyUnwrapped instead.}} {{none}}
3637
}
3738

0 commit comments

Comments
 (0)