Skip to content

Commit 53e0d78

Browse files
authored
Merge pull request #4307 from jckarter/swiftvalue-swifttypename-method
Runtime: Add a convenient `-[_SwiftValue _swiftTypeName]` method for debugging.
2 parents 4f53564 + f998c62 commit 53e0d78

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

include/swift/Runtime/HeapObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,11 @@ static inline void swift_unknownUnownedTakeAssign(UnownedReference *dest,
11551155

11561156
#endif /* SWIFT_OBJC_INTEROP */
11571157

1158+
/// Return the name of a Swift type represented by a metadata object.
1159+
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT
1160+
extern "C"
1161+
TwoWordPair<const char *, uintptr_t>::Return
1162+
swift_getTypeName(const Metadata *type, bool qualified);
11581163

11591164
} // end namespace swift
11601165

stdlib/public/runtime/Casting.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,8 @@ std::string swift::nameForMetadata(const Metadata *type,
316316
}
317317

318318
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT
319-
extern "C"
320319
TwoWordPair<const char *, uintptr_t>::Return
321-
swift_getTypeName(const Metadata *type, bool qualified) {
320+
swift::swift_getTypeName(const Metadata *type, bool qualified) {
322321
using Pair = TwoWordPair<const char *, uintptr_t>;
323322
using Key = llvm::PointerIntPair<const Metadata *, 1, bool>;
324323

stdlib/public/runtime/SwiftValue.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ - (NSString *)debugDescription {
326326
- (const Metadata *)_swiftTypeMetadata {
327327
return getSwiftValueTypeMetadata(self);
328328
}
329+
- (NSString *)_swiftTypeName {
330+
TwoWordPair<const char *, uintptr_t> typeName
331+
= swift_getTypeName(getSwiftValueTypeMetadata(self), true);
332+
333+
return [NSString stringWithUTF8String: typeName.first];
334+
}
329335
- (const OpaqueValue *)_swiftValue {
330336
return getValueFromSwiftValue(self).second;
331337
}

0 commit comments

Comments
 (0)