Skip to content

Commit 4c3c335

Browse files
authored
Merge pull request #28685 from lorentey/i-heard-you-like-runtime-so-i-put-a-runtime-in-your-foundation-overlay-so-you-can-run-while-you-found
[Foundation][runtime] Remove swift_errorBridgingInfo
2 parents 7543a89 + c34389c commit 4c3c335

File tree

4 files changed

+29
-114
lines changed

4 files changed

+29
-114
lines changed

stdlib/public/Darwin/Foundation/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ add_swift_target_library(swiftFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES
3232
NSCoder.swift
3333
NSDate.swift
3434
NSDictionary.swift
35-
NSError.mm
3635
NSError.swift
3736
NSExpression.swift
3837
NSFastEnumeration.swift

stdlib/public/Darwin/Foundation/NSError.h

Lines changed: 0 additions & 45 deletions
This file was deleted.

stdlib/public/Darwin/Foundation/NSError.mm

Lines changed: 0 additions & 49 deletions
This file was deleted.

stdlib/public/runtime/ErrorObject.mm

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include <objc/message.h>
3838
#include <objc/objc.h>
3939
#include <Foundation/Foundation.h>
40-
#include "../Darwin/Foundation/NSError.h"
4140

4241
using namespace swift;
4342
using namespace swift::hashable_support;
@@ -260,19 +259,6 @@ static id getEmptyNSDictionary() {
260259
object_dispose((id)error);
261260
}
262261

263-
/// Get the error bridging info from the Foundation overlay. If it can't
264-
/// be loaded, return all NULLs.
265-
static ErrorBridgingInfo getErrorBridgingInfo() {
266-
auto *info = SWIFT_LAZY_CONSTANT(
267-
reinterpret_cast<ErrorBridgingInfo *>(
268-
dlsym(RTLD_DEFAULT, ERROR_BRIDGING_SYMBOL_NAME_STRING)));
269-
if (!info) {
270-
ErrorBridgingInfo nulls = {};
271-
return nulls;
272-
}
273-
return *info;
274-
}
275-
276262
static const WitnessTable *getNSErrorConformanceToError() {
277263
// CFError and NSError are toll-free-bridged, so we can use either type's
278264
// witness table interchangeably. CFError's is potentially slightly more
@@ -281,7 +267,10 @@ static ErrorBridgingInfo getErrorBridgingInfo() {
281267
// safe to assume that that's been linked in if a user is using NSError in
282268
// their Swift source.
283269

284-
auto conformance = getErrorBridgingInfo().CFErrorErrorConformance;
270+
auto *conformance = SWIFT_LAZY_CONSTANT(
271+
reinterpret_cast<const ProtocolConformanceDescriptor *>(
272+
dlsym(RTLD_DEFAULT,
273+
MANGLE_AS_STRING(MANGLE_SYM(So10CFErrorRefas5Error10FoundationMc)))));
285274
assert(conformance &&
286275
"Foundation overlay not loaded, or 'CFError : Error' conformance "
287276
"not available");
@@ -291,7 +280,10 @@ static ErrorBridgingInfo getErrorBridgingInfo() {
291280
}
292281

293282
static const HashableWitnessTable *getNSErrorConformanceToHashable() {
294-
auto conformance = getErrorBridgingInfo().NSObjectHashableConformance;
283+
auto *conformance = SWIFT_LAZY_CONSTANT(
284+
reinterpret_cast<const ProtocolConformanceDescriptor *>(
285+
dlsym(RTLD_DEFAULT,
286+
MANGLE_AS_STRING(MANGLE_SYM(So8NSObjectCSH10ObjectiveCMc)))));
295287
assert(conformance &&
296288
"ObjectiveC overlay not loaded, or 'NSObject : Hashable' conformance "
297289
"not available");
@@ -427,7 +419,15 @@ id _swift_stdlib_getErrorDefaultUserInfo(OpaqueValue *error,
427419
const WitnessTable *Error) {
428420
// public func Foundation._getErrorDefaultUserInfo<T: Error>(_ error: T)
429421
// -> AnyObject?
430-
auto foundationGetDefaultUserInfo = getErrorBridgingInfo().GetErrorDefaultUserInfo;
422+
typedef SWIFT_CC(swift) NSDictionary *(*GetErrorDefaultUserInfoFunction)(
423+
const OpaqueValue *error,
424+
const Metadata *T,
425+
const WitnessTable *Error);
426+
auto foundationGetDefaultUserInfo = SWIFT_LAZY_CONSTANT(
427+
reinterpret_cast<GetErrorDefaultUserInfoFunction>(
428+
dlsym(RTLD_DEFAULT,
429+
MANGLE_AS_STRING(MANGLE_SYM(10Foundation24_getErrorDefaultUserInfoyyXlSgxs0C0RzlF)))));
430+
431431
if (!foundationGetDefaultUserInfo) {
432432
return nullptr;
433433
}
@@ -533,9 +533,19 @@ ProtocolDescriptorRef theErrorProtocol(&PROTOCOL_DESCR_SYM(s5Error),
533533
// public func Foundation._bridgeNSErrorToError<
534534
// T : _ObjectiveCBridgeableError
535535
// >(error: NSError, out: UnsafeMutablePointer<T>) -> Bool {
536-
auto bridgeNSErrorToError = getErrorBridgingInfo().BridgeErrorToNSError;
536+
typedef SWIFT_CC(swift) bool (*BridgeErrorToNSErrorFunction)(
537+
NSError *, OpaqueValue*, const Metadata *,
538+
const WitnessTable *);
539+
auto bridgeNSErrorToError = SWIFT_LAZY_CONSTANT(
540+
reinterpret_cast<BridgeErrorToNSErrorFunction>(
541+
dlsym(RTLD_DEFAULT,
542+
MANGLE_AS_STRING(MANGLE_SYM(10Foundation21_bridgeNSErrorToError_3outSbSo0C0C_SpyxGtAA021_ObjectiveCBridgeableE0RzlF)))));
543+
537544
// protocol _ObjectiveCBridgeableError
538-
auto TheObjectiveCBridgeableError = getErrorBridgingInfo().ObjectiveCBridgeableError;
545+
auto TheObjectiveCBridgeableError = SWIFT_LAZY_CONSTANT(
546+
reinterpret_cast<ProtocolDescriptor *>(
547+
dlsym(RTLD_DEFAULT,
548+
MANGLE_AS_STRING(MANGLE_SYM(10Foundation26_ObjectiveCBridgeableErrorMp)))));
539549

540550
// If the Foundation overlay isn't loaded, then arbitrary NSErrors can't be
541551
// bridged.

0 commit comments

Comments
 (0)