Skip to content

Commit 415b36d

Browse files
author
Greg Parker
authored
[runtime] Clean up symbol exports in casting and class introspection. (#13005)
1 parent a5d9ace commit 415b36d

File tree

7 files changed

+88
-96
lines changed

7 files changed

+88
-96
lines changed

include/swift/Runtime/HeapObject.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,9 @@ static inline bool swift_unknownUnownedIsEqual(UnownedReference *ref,
12431243
#endif /* SWIFT_OBJC_INTEROP */
12441244

12451245
/// Return the name of a Swift type represented by a metadata object.
1246-
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT
1246+
/// func _getTypeName(_ type: Any.Type, qualified: Bool)
1247+
/// -> (UnsafePointer<UInt8>, Int)
1248+
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_API
12471249
TwoWordPair<const char *, uintptr_t>::Return
12481250
swift_getTypeName(const Metadata *type, bool qualified);
12491251

stdlib/public/core/BridgeObjectiveC.swift

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ public func _bridgeAnythingToObjectiveC<T>(_ x: T) -> AnyObject {
170170
return _bridgeAnythingNonVerbatimToObjectiveC(x)
171171
}
172172

173-
/// COMPILER_INTRINSIC
174-
@_inlineable // FIXME(sil-serialize-all)
175-
@_silgen_name("_swift_bridgeAnythingNonVerbatimToObjectiveC")
173+
@_silgen_name("")
176174
public func _bridgeAnythingNonVerbatimToObjectiveC<T>(_ x: T) -> AnyObject
177175

178176
/// Convert a purportedly-nonnull `id` value from Objective-C into an Any.
@@ -214,8 +212,8 @@ public func _forceBridgeFromObjectiveC<T>(_ x: AnyObject, _: T.Type) -> T {
214212

215213
/// Convert `x` from its Objective-C representation to its Swift
216214
/// representation.
215+
/// COMPILER_INTRINSIC
217216
@_inlineable // FIXME(sil-serialize-all)
218-
@_silgen_name("_forceBridgeFromObjectiveC_bridgeable")
219217
public func _forceBridgeFromObjectiveC_bridgeable<T:_ObjectiveCBridgeable> (
220218
_ x: T._ObjectiveCType,
221219
_: T.Type
@@ -253,8 +251,8 @@ public func _conditionallyBridgeFromObjectiveC<T>(
253251

254252
/// Attempt to convert `x` from its Objective-C representation to its Swift
255253
/// representation.
254+
/// COMPILER_INTRINSIC
256255
@_inlineable // FIXME(sil-serialize-all)
257-
@_silgen_name("_conditionallyBridgeFromObjectiveC_bridgeable")
258256
public func _conditionallyBridgeFromObjectiveC_bridgeable<T:_ObjectiveCBridgeable>(
259257
_ x: T._ObjectiveCType,
260258
_: T.Type
@@ -264,32 +262,26 @@ public func _conditionallyBridgeFromObjectiveC_bridgeable<T:_ObjectiveCBridgeabl
264262
return result
265263
}
266264

267-
@_inlineable // FIXME(sil-serialize-all)
268-
@_versioned // FIXME(sil-serialize-all)
269-
@_silgen_name("_swift_bridgeNonVerbatimFromObjectiveC")
270-
internal func _bridgeNonVerbatimFromObjectiveC<T>(
265+
@_silgen_name("")
266+
public func _bridgeNonVerbatimFromObjectiveC<T>(
271267
_ x: AnyObject,
272268
_ nativeType: T.Type,
273269
_ result: inout T?
274270
)
275271

276272
/// Helper stub to upcast to Any and store the result to an inout Any?
277273
/// on the C++ runtime's behalf.
278-
// COMPILER_INTRINSIC
279-
@_inlineable // FIXME(sil-serialize-all)
280-
@_silgen_name("_swift_bridgeNonVerbatimFromObjectiveCToAny")
281-
public func _bridgeNonVerbatimFromObjectiveCToAny(
274+
@_silgen_name("_bridgeNonVerbatimFromObjectiveCToAny")
275+
internal func _bridgeNonVerbatimFromObjectiveCToAny(
282276
_ x: AnyObject,
283277
_ result: inout Any?
284278
) {
285279
result = x as Any
286280
}
287281

288282
/// Helper stub to upcast to Optional on the C++ runtime's behalf.
289-
// COMPILER_INTRINSIC
290-
@_inlineable // FIXME(sil-serialize-all)
291-
@_silgen_name("_swift_bridgeNonVerbatimBoxedValue")
292-
public func _bridgeNonVerbatimBoxedValue<NativeType>(
283+
@_silgen_name("_bridgeNonVerbatimBoxedValue")
284+
internal func _bridgeNonVerbatimBoxedValue<NativeType>(
293285
_ x: UnsafePointer<NativeType>,
294286
_ result: inout NativeType?
295287
) {
@@ -303,10 +295,8 @@ public func _bridgeNonVerbatimBoxedValue<NativeType>(
303295
/// unchanged otherwise.
304296
///
305297
/// - Returns: `true` to indicate success, `false` to indicate failure.
306-
@_inlineable // FIXME(sil-serialize-all)
307-
@_versioned // FIXME(sil-serialize-all)
308-
@_silgen_name("_swift_bridgeNonVerbatimFromObjectiveCConditional")
309-
internal func _bridgeNonVerbatimFromObjectiveCConditional<T>(
298+
@_silgen_name("")
299+
public func _bridgeNonVerbatimFromObjectiveCConditional<T>(
310300
_ x: AnyObject,
311301
_ nativeType: T.Type,
312302
_ result: inout T?
@@ -325,10 +315,8 @@ public func _isBridgedToObjectiveC<T>(_: T.Type) -> Bool {
325315
return _isBridgedNonVerbatimToObjectiveC(T.self)
326316
}
327317

328-
@_inlineable // FIXME(sil-serialize-all)
329-
@_versioned // FIXME(sil-serialize-all)
330-
@_silgen_name("_swift_isBridgedNonVerbatimToObjectiveC")
331-
internal func _isBridgedNonVerbatimToObjectiveC<T>(_: T.Type) -> Bool
318+
@_silgen_name("")
319+
public func _isBridgedNonVerbatimToObjectiveC<T>(_: T.Type) -> Bool
332320

333321
/// A type that's bridged "verbatim" does not conform to
334322
/// `_ObjectiveCBridgeable`, and can have its bits reinterpreted as an
@@ -348,10 +336,8 @@ public func _getBridgedObjectiveCType<T>(_: T.Type) -> Any.Type? {
348336
return _getBridgedNonVerbatimObjectiveCType(T.self)
349337
}
350338

351-
@_inlineable // FIXME(sil-serialize-all)
352-
@_versioned // FIXME(sil-serialize-all)
353-
@_silgen_name("_swift_getBridgedNonVerbatimObjectiveCType")
354-
internal func _getBridgedNonVerbatimObjectiveCType<T>(_: T.Type) -> Any.Type?
339+
@_silgen_name("")
340+
public func _getBridgedNonVerbatimObjectiveCType<T>(_: T.Type) -> Any.Type?
355341

356342
// -- Pointer argument bridging
357343

stdlib/public/core/Builtin.swift

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public func _onFastPath() {
322322
// when using RuntimeShims.h
323323
@_inlineable // FIXME(sil-serialize-all)
324324
@_versioned
325-
@_silgen_name("swift_objc_class_usesNativeSwiftReferenceCounting")
325+
@_silgen_name("_objcClassUsesNativeSwiftReferenceCounting")
326326
internal func _usesNativeSwiftReferenceCounting(_ theClass: AnyClass) -> Bool
327327
#else
328328
@_inlineable // FIXME(sil-serialize-all)
@@ -335,24 +335,24 @@ internal func _usesNativeSwiftReferenceCounting(_ theClass: AnyClass) -> Bool {
335335

336336
@_inlineable // FIXME(sil-serialize-all)
337337
@_versioned // FIXME(sil-serialize-all)
338-
@_silgen_name("swift_class_getInstanceExtents")
339-
internal func swift_class_getInstanceExtents(_ theClass: AnyClass)
338+
@_silgen_name("_getSwiftClassInstanceExtents")
339+
internal func getSwiftClassInstanceExtents(_ theClass: AnyClass)
340340
-> (negative: UInt, positive: UInt)
341341

342342
@_inlineable // FIXME(sil-serialize-all)
343343
@_versioned // FIXME(sil-serialize-all)
344-
@_silgen_name("swift_objc_class_unknownGetInstanceExtents")
345-
internal func swift_objc_class_unknownGetInstanceExtents(_ theClass: AnyClass)
344+
@_silgen_name("_getObjCClassInstanceExtents")
345+
internal func getObjCClassInstanceExtents(_ theClass: AnyClass)
346346
-> (negative: UInt, positive: UInt)
347347

348348
@_inlineable // FIXME(sil-serialize-all)
349349
@_versioned // FIXME(sil-serialize-all)
350350
@inline(__always)
351351
internal func _class_getInstancePositiveExtentSize(_ theClass: AnyClass) -> Int {
352352
#if _runtime(_ObjC)
353-
return Int(swift_objc_class_unknownGetInstanceExtents(theClass).positive)
353+
return Int(getObjCClassInstanceExtents(theClass).positive)
354354
#else
355-
return Int(swift_class_getInstanceExtents(theClass).positive)
355+
return Int(getSwiftClassInstanceExtents(theClass).positive)
356356
#endif
357357
}
358358

@@ -488,16 +488,12 @@ internal func _makeBridgeObject(
488488
)
489489
}
490490

491-
@_inlineable // FIXME(sil-serialize-all)
492-
@_versioned
493491
@_silgen_name("_swift_class_getSuperclass")
494492
internal func _swift_class_getSuperclass(_ t: AnyClass) -> AnyClass?
495493

496494
/// Returns the superclass of `t`, if any. The result is `nil` if `t` is
497495
/// a root class or class protocol.
498-
@_inlineable // FIXME(sil-serialize-all)
499-
@inline(__always)
500-
public // @testable
496+
public
501497
func _getSuperclass(_ t: AnyClass) -> AnyClass? {
502498
return _swift_class_getSuperclass(t)
503499
}

stdlib/public/core/Misc.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,14 @@ func _typeName(_ type: Any.Type, qualified: Bool = true) -> String {
9292
input: UnsafeBufferPointer(start: stringPtr, count: count))
9393
}
9494

95-
@_inlineable // FIXME(sil-serialize-all)
96-
@_versioned // FIXME(sil-serialize-all)
97-
@_silgen_name("swift_getTypeByName")
95+
@_silgen_name("")
9896
internal func _getTypeByName(
9997
_ name: UnsafePointer<UInt8>,
10098
_ nameLength: UInt)
10199
-> Any.Type?
102100

103101
/// Lookup a class given a name. Until the demangled encoding of type
104102
/// names is stabilized, this is limited to top-level class names (Foo.bar).
105-
@_inlineable // FIXME(sil-serialize-all)
106103
public // SPI(Foundation)
107104
func _typeByName(_ name: String) -> Any.Type? {
108105
let nameUTF8 = Array(name.utf8)

stdlib/public/runtime/Casting.cpp

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ std::string swift::nameForMetadata(const Metadata *type,
113113
return result;
114114
}
115115

116-
SWIFT_CC(swift)
117116
TwoWordPair<const char *, uintptr_t>::Return
118117
swift::swift_getTypeName(const Metadata *type, bool qualified) {
119118
using Pair = TwoWordPair<const char *, uintptr_t>;
@@ -2972,9 +2971,13 @@ static id bridgeAnythingNonVerbatimToObjectiveC(OpaqueValue *src,
29722971
return (id)bridgeAnythingToSwiftValueObject(src, srcType, consume);
29732972
}
29742973

2975-
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERFACE
2976-
id _swift_bridgeAnythingNonVerbatimToObjectiveC(OpaqueValue *src,
2977-
const Metadata *srcType) {
2974+
/// public func _bridgeAnythingNonVerbatimToObjectiveC<T>(_ x: T) -> AnyObject
2975+
/// Called by inlined stdlib code.
2976+
#define _bridgeAnythingNonVerbatimToObjectiveC \
2977+
MANGLE_SYM(s38_bridgeAnythingNonVerbatimToObjectiveCyXlxlF)
2978+
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_API
2979+
id _bridgeAnythingNonVerbatimToObjectiveC(OpaqueValue *src,
2980+
const Metadata *srcType) {
29782981
return bridgeAnythingNonVerbatimToObjectiveC(src, srcType, /*consume*/ true);
29792982
}
29802983

@@ -3031,8 +3034,12 @@ findBridgeWitness(const Metadata *T) {
30313034
return nullptr;
30323035
}
30333036

3034-
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERFACE
3035-
const Metadata *_swift_getBridgedNonVerbatimObjectiveCType(
3037+
// public func _getBridgedNonVerbatimObjectiveCType<T>(_: T.Type) -> Any.Type?
3038+
// Called by inlined stdlib code.
3039+
#define _getBridgedNonVerbatimObjectiveCType \
3040+
MANGLE_SYM(s36_getBridgedNonVerbatimObjectiveCTypeypXpSgxmlF)
3041+
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_API
3042+
const Metadata *_getBridgedNonVerbatimObjectiveCType(
30363043
const Metadata *value, const Metadata *T
30373044
) {
30383045
// Classes and Objective-C existentials bridge verbatim.
@@ -3047,26 +3054,26 @@ const Metadata *_swift_getBridgedNonVerbatimObjectiveCType(
30473054
return nullptr;
30483055
}
30493056

3050-
// @_silgen_name("_swift_bridgeNonVerbatimFromObjectiveCToAny")
3057+
// @_silgen_name("_bridgeNonVerbatimFromObjectiveCToAny")
30513058
// func _bridgeNonVerbatimFromObjectiveCToAny(
30523059
// x: AnyObject,
30533060
// inout result: Any?
30543061
// )
3055-
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERFACE
3062+
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL
30563063
void
3057-
_swift_bridgeNonVerbatimFromObjectiveCToAny(HeapObject *sourceValue,
3058-
OpaqueValue *destValue);
3064+
_bridgeNonVerbatimFromObjectiveCToAny(HeapObject *sourceValue,
3065+
OpaqueValue *destValue);
30593066

3060-
// @_silgen_name("_swift_bridgeNonVerbatimBoxedValue")
3067+
// @_silgen_name("_bridgeNonVerbatimBoxedValue")
30613068
// func _bridgeNonVerbatimBoxedValue<NativeType>(
30623069
// x: UnsafePointer<NativeType>,
30633070
// inout result: NativeType?
30643071
// )
3065-
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERFACE
3072+
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL
30663073
void
3067-
_swift_bridgeNonVerbatimBoxedValue(const OpaqueValue *sourceValue,
3068-
OpaqueValue *destValue,
3069-
const Metadata *nativeType);
3074+
_bridgeNonVerbatimBoxedValue(const OpaqueValue *sourceValue,
3075+
OpaqueValue *destValue,
3076+
const Metadata *nativeType);
30703077

30713078
// Try bridging by conversion to Any or boxing if applicable.
30723079
static bool tryBridgeNonVerbatimFromObjectiveCUniversal(
@@ -3079,8 +3086,7 @@ static bool tryBridgeNonVerbatimFromObjectiveCUniversal(
30793086
if (auto nativeExistential = dyn_cast<ExistentialTypeMetadata>(nativeType)) {
30803087
if (nativeExistential->Protocols.NumProtocols == 0 &&
30813088
!nativeExistential->isClassBounded()) {
3082-
_swift_bridgeNonVerbatimFromObjectiveCToAny(sourceValue,
3083-
destValue);
3089+
_bridgeNonVerbatimFromObjectiveCToAny(sourceValue, destValue);
30843090
return true;
30853091
}
30863092
}
@@ -3092,25 +3098,25 @@ static bool tryBridgeNonVerbatimFromObjectiveCUniversal(
30923098

30933099
std::tie(sourceType, sourceBoxedValue) = getValueFromSwiftValue(srcBox);
30943100
if (sourceType == nativeType) {
3095-
_swift_bridgeNonVerbatimBoxedValue(sourceBoxedValue,
3096-
destValue,
3097-
nativeType);
3101+
_bridgeNonVerbatimBoxedValue(sourceBoxedValue, destValue, nativeType);
30983102
return true;
30993103
}
31003104
}
31013105

31023106
return false;
31033107
}
31043108

3105-
// @_silgen_name("_swift_bridgeNonVerbatimFromObjectiveC")
31063109
// func _bridgeNonVerbatimFromObjectiveC<NativeType>(
31073110
// x: AnyObject,
31083111
// nativeType: NativeType.Type
31093112
// inout result: T?
31103113
// )
3111-
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERFACE
3114+
// Called by inlined stdlib code.
3115+
#define _bridgeNonVerbatimFromObjectiveC \
3116+
MANGLE_SYM(s32_bridgeNonVerbatimFromObjectiveCyyXl_xmxSgztlF)
3117+
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_API
31123118
void
3113-
_swift_bridgeNonVerbatimFromObjectiveC(
3119+
_bridgeNonVerbatimFromObjectiveC(
31143120
HeapObject *sourceValue,
31153121
const Metadata *nativeType,
31163122
OpaqueValue *destValue,
@@ -3145,15 +3151,14 @@ _swift_bridgeNonVerbatimFromObjectiveC(
31453151
swift::crash("value type is not bridged to Objective-C");
31463152
}
31473153

3148-
// @_silgen_name("_swift_bridgeNonVerbatimFromObjectiveCConditional")
3149-
// func _bridgeNonVerbatimFromObjectiveCConditional<NativeType>(
3150-
// x: AnyObject,
3151-
// nativeType: T.Type,
3152-
// inout result: T?
3153-
// ) -> Bool
3154-
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERFACE
3154+
/// func _bridgeNonVerbatimFromObjectiveCConditional<NativeType>(
3155+
/// x: AnyObject, nativeType: T.Type, inout result: T?) -> Bool
3156+
/// Called by inlined stdlib code.
3157+
#define _bridgeNonVerbatimFromObjectiveCConditional \
3158+
MANGLE_SYM(s43_bridgeNonVerbatimFromObjectiveCConditionalSbyXl_xmxSgztlF)
3159+
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_API
31553160
bool
3156-
_swift_bridgeNonVerbatimFromObjectiveCConditional(
3161+
_bridgeNonVerbatimFromObjectiveCConditional(
31573162
HeapObject *sourceValue,
31583163
const Metadata *nativeType,
31593164
OpaqueValue *destValue,
@@ -3195,10 +3200,12 @@ _swift_bridgeNonVerbatimFromObjectiveCConditional(
31953200
}
31963201

31973202
// func _isBridgedNonVerbatimToObjectiveC<T>(x: T.Type) -> Bool
3198-
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERFACE
3199-
bool _swift_isBridgedNonVerbatimToObjectiveC(
3200-
const Metadata *value, const Metadata *T
3201-
) {
3203+
// Called by inlined stdlib code.
3204+
#define _isBridgedNonVerbatimToObjectiveC \
3205+
MANGLE_SYM(s33_isBridgedNonVerbatimToObjectiveCSbxmlF)
3206+
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_API
3207+
bool _isBridgedNonVerbatimToObjectiveC(const Metadata *value,
3208+
const Metadata *T) {
32023209
assert(!swift_isClassOrObjCExistentialTypeImpl(T));
32033210

32043211
auto bridgeWitness = findBridgeWitness(T);
@@ -3213,20 +3220,22 @@ bool _swift_isClassOrObjCExistentialType(const Metadata *value,
32133220
return swift_isClassOrObjCExistentialTypeImpl(T);
32143221
}
32153222

3216-
SWIFT_CC(swift)
3223+
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL
32173224
const Metadata *swift::_swift_class_getSuperclass(const Metadata *theClass) {
32183225
if (const ClassMetadata *classType = theClass->getClassObject())
32193226
if (classHasSuperclass(classType))
32203227
return getMetadataForClass(classType->SuperClass);
32213228
return nullptr;
32223229
}
32233230

3224-
SWIFT_CC(c) SWIFT_RUNTIME_EXPORT
3231+
// Called by compiler-generated cast code.
3232+
SWIFT_CC(c) SWIFT_RUNTIME_STDLIB_API
32253233
bool swift_isClassType(const Metadata *type) {
32263234
return Metadata::isAnyKindOfClass(type->getKind());
32273235
}
32283236

3229-
SWIFT_CC(c) SWIFT_RUNTIME_EXPORT
3237+
// Called by compiler-generated code.
3238+
SWIFT_CC(c) SWIFT_RUNTIME_STDLIB_API
32303239
bool swift_isOptionalType(const Metadata *type) {
32313240
return type->getKind() == MetadataKind::Optional;
32323241
}

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,14 @@ _classByName(const llvm::StringRef typeName) {
258258

259259
/// \param typeName The name of a class in the form: <module>.<class>
260260
/// \return Returns the metadata of the type, if found.
261-
SWIFT_CC(swift)
262-
SWIFT_RUNTIME_EXPORT
261+
262+
/// internal func _getTypeByName(_ name: UnsafePointer<UInt8>,
263+
/// _ nameLength: UInt) -> Any.Type?
264+
#define _getTypeByName \
265+
MANGLE_SYM(s14_getTypeByNameypXpSgSPys5UInt8VG_SutF)
266+
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL
263267
const Metadata *
264-
swift_getTypeByName(const char *typeName, size_t typeNameLength) {
268+
_getTypeByName(const char *typeName, size_t typeNameLength) {
265269
llvm::StringRef name(typeName, typeNameLength);
266270
return _classByName(name);
267271
}

0 commit comments

Comments
 (0)