Skip to content

Commit f092d83

Browse files
committed
[ABI] Eliminate witness table accessors.
Witness table accessors return a witness table for a given type's conformance to a protocol. They are called directly from IRGen (when we need the witness table instance) and from runtime conformance checking (swift_conformsToProtocol digs the access function out of the protocol conformance record). They have two interesting functions: 1) For witness tables requiring instantiation, they call swift_instantiateWitnessTable directly. 2) For synthesized witness tables that might not be unique, they call swift_getForeignWitnessTable. Extend swift_instantiateWitnessTable() to handle both runtime uniquing (for #2) as well as handling witness tables that don't have a "generic table", i.e., don't need any actual instantiation. Use it as the universal entry point for "get a witness table given a specific conformance descriptor and type", eliminating witness table accessors entirely. Make a few related simplifications: * Drop the "pattern" from the generic witness table. Instead, store the pattern in the main part of the conformance descriptor, always. * Drop the "conformance kind" from the protocol conformance descriptor, since it was only there to distinguish between witness table (pattern) vs. witness table accessor. * Internalize swift_getForeignWitnessTable(); IRGen no longer needs to call it. Reduces the code size of the standard library (+assertions build) by ~149k. Addresses rdar://problem/45489388.
1 parent 079036a commit f092d83

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

Darwin/Foundation-swiftoverlay/NSError.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ namespace swift {
2727
/// The items that ErrorObject.mm needs for bridging. The
2828
/// ERROR_BRIDGING_SYMBOL_NAME symbol will contain an instance of this struct.
2929
struct ErrorBridgingInfo {
30-
const SWIFT_CC(swift) WitnessTable *(*GetCFErrorErrorConformance)();
31-
32-
const SWIFT_CC(swift) hashable_support::HashableWitnessTable *
33-
(*GetNSObjectHashableConformance)();
34-
30+
const ProtocolConformanceDescriptor *CFErrorErrorConformance;
31+
const ProtocolConformanceDescriptor *NSObjectHashableConformance;
32+
3533
SWIFT_CC(swift) NSDictionary *(*GetErrorDefaultUserInfo)(const OpaqueValue *error,
3634
const Metadata *T,
3735
const WitnessTable *Error);

Darwin/Foundation-swiftoverlay/NSError.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
using namespace swift;
1818

1919
// Declare the mangled Swift symbols that we'll be putting in the bridging info.
20-
extern "C" const SWIFT_CC(swift) WitnessTable *
21-
MANGLE_SYM(So10CFErrorRefas5Error10FoundationWa)();
20+
extern "C" const ProtocolConformanceDescriptor
21+
MANGLE_SYM(So10CFErrorRefas5Error10FoundationMc);
2222

23-
extern "C" const SWIFT_CC(swift) hashable_support::HashableWitnessTable *
24-
MANGLE_SYM(So8NSObjectCSH10ObjectiveCWa)();
23+
extern "C" const ProtocolConformanceDescriptor
24+
MANGLE_SYM(So8NSObjectCSH10ObjectiveCMc);
2525

2626
extern "C" SWIFT_CC(swift)
2727
NSDictionary *MANGLE_SYM(10Foundation24_getErrorDefaultUserInfoyyXlSgxs0C0RzlF)(
@@ -36,8 +36,8 @@
3636

3737
// Define the bridging info struct.
3838
extern "C" ErrorBridgingInfo ERROR_BRIDGING_SYMBOL_NAME = {
39-
MANGLE_SYM(So10CFErrorRefas5Error10FoundationWa),
40-
MANGLE_SYM(So8NSObjectCSH10ObjectiveCWa),
39+
&MANGLE_SYM(So10CFErrorRefas5Error10FoundationMc),
40+
&MANGLE_SYM(So8NSObjectCSH10ObjectiveCMc),
4141
MANGLE_SYM(10Foundation24_getErrorDefaultUserInfoyyXlSgxs0C0RzlF),
4242
MANGLE_SYM(10Foundation21_bridgeNSErrorToError_3outSbSo0C0C_SpyxGtAA021_ObjectiveCBridgeableE0RzlF),
4343
&MANGLE_SYM(10Foundation26_ObjectiveCBridgeableErrorMp)

0 commit comments

Comments
 (0)