Skip to content

Commit ffe180f

Browse files
authored
Merge pull request #28385 from apple/revert-28353-error-bridge-to-nsobject
Revert "[Runtime] Handle dynamic casting to NSObject via error bridging."
2 parents 5f2dde4 + bc5d59e commit ffe180f

File tree

4 files changed

+3
-44
lines changed

4 files changed

+3
-44
lines changed

stdlib/public/runtime/Casting.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include "llvm/Support/Compiler.h"
3838
#if SWIFT_OBJC_INTEROP
3939
#include "swift/Runtime/ObjCBridge.h"
40-
#include "SwiftObject.h"
4140
#include "SwiftValue.h"
4241
#endif
4342

@@ -2331,10 +2330,9 @@ static bool swift_dynamicCastImpl(OpaqueValue *dest, OpaqueValue *src,
23312330
case MetadataKind::Class:
23322331
case MetadataKind::ObjCClassWrapper:
23332332
#if SWIFT_OBJC_INTEROP
2334-
// If the destination type is an NSError or NSObject, and the source type
2335-
// is an Error, then the cast can succeed by NSError bridging.
2336-
if (targetType == getNSErrorMetadata() ||
2337-
targetType == getNSObjectMetadata()) {
2333+
// If the destination type is an NSError, and the source type is an
2334+
// Error, then the cast can succeed by NSError bridging.
2335+
if (targetType == getNSErrorMetadata()) {
23382336
// Don't rebridge if the source is already some kind of NSError.
23392337
if (srcType->isAnyClass()
23402338
&& swift_dynamicCastObjCClass(*reinterpret_cast<id*>(src),

stdlib/public/runtime/SwiftObject.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030

3131
#if SWIFT_OBJC_INTEROP
32-
#if __OBJC__
3332

3433
// Source code: "SwiftObject"
3534
// Real class name: mangled "Swift._SwiftObject"
@@ -84,13 +83,5 @@ id getDescription(OpaqueValue *value, const Metadata *type);
8483
}
8584

8685
#endif
87-
#endif
88-
89-
namespace swift {
90-
91-
/// Get the NSObject metadata.
92-
const Metadata *getNSObjectMetadata();
93-
94-
}
9586

9687
#endif

stdlib/public/runtime/SwiftObject.mm

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,11 +1552,6 @@ void swift_objc_swift3ImplicitObjCEntrypoint(id self, SEL selector,
15521552
free(nullTerminatedFilename);
15531553
}
15541554

1555-
const Metadata *swift::getNSObjectMetadata() {
1556-
return SWIFT_LAZY_CONSTANT(
1557-
swift_getObjCClassMetadata((const ClassMetadata *)[NSObject class]));
1558-
}
1559-
15601555
#endif
15611556

15621557
const ClassMetadata *swift::getRootSuperclass() {

test/stdlib/ErrorBridged.swift

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -767,29 +767,4 @@ ErrorBridgingTests.test("@objc error domains for nested types") {
767767
String(reflecting: NonPrintAsObjCError.self))
768768
}
769769

770-
@inline(never)
771-
@_optimize(none)
772-
func anyToAny<T, U>(_ a: T, _ : U.Type) -> U {
773-
return a as! U
774-
}
775-
776-
ErrorBridgingTests.test("error-to-NSObject casts") {
777-
let error = MyCustomizedError(code: 12345)
778-
779-
// Unconditional cast
780-
let nsErrorAsObject1 = unconditionalCast(error, to: NSObject.self)
781-
let nsError1 = unconditionalCast(nsErrorAsObject1, to: NSError.self)
782-
expectEqual("custom", nsError1.domain)
783-
expectEqual(12345, nsError1.code)
784-
785-
// Conditional cast
786-
let nsErrorAsObject2 = conditionalCast(error, to: NSObject.self)!
787-
let nsError2 = unconditionalCast(nsErrorAsObject2, to: NSError.self)
788-
expectEqual("custom", nsError2.domain)
789-
expectEqual(12345, nsError2.code)
790-
791-
// "is" check
792-
expectTrue(error is NSObject)
793-
}
794-
795770
runAllTests()

0 commit comments

Comments
 (0)