Skip to content

Commit f213671

Browse files
jckartergottesmm
authored andcommitted
Runtime: Handle getDescription correctly in +0 mode.
This can eventually be made more efficient by avoiding copies in all the callees, but this is the minimal fix. Remove an unnecessary bit of reverse-dependency on the Foundation overlay while we're here. rdar://34222540
1 parent a9cc598 commit f213671

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

stdlib/public/SDK/Foundation/NSString.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ public class NSSimpleCString {}
2222
@available(*, unavailable, message: "Please use String or NSString")
2323
public class NSConstantString {}
2424

25-
// Called by the SwiftObject implementation.
26-
public func _getDescription<T>(_ x: T) -> NSString {
27-
return String(reflecting: x)._bridgeToObjectiveC()
28-
}
29-
3025
extension NSString : ExpressibleByStringLiteral {
3126
/// Create an instance initialized to `value`.
3227
public required convenience init(stringLiteral value: StaticString) {

stdlib/public/core/StringBridge.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,14 @@ extension String {
368368
}
369369
}
370370

371+
// Called by the SwiftObject implementation to get the description of a value
372+
// as an NSString.
373+
@_silgen_name("swift_stdlib_getDescription")
374+
public func _getDescription<T>(_ x: T) -> AnyObject {
375+
return String(reflecting: x)._bridgeToObjectiveCImpl()
376+
}
377+
378+
371379
#else // !_runtime(_ObjC)
372380

373381
@_fixed_layout // FIXME(sil-serialize-all)

stdlib/public/runtime/SwiftObject.mm

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,14 @@ static Class _swift_getObjCClassOfAllocated(const void *object) {
147147
class_getInstanceSize(cls), mask));
148148
}
149149

150-
NSString *swift::getDescription(OpaqueValue *value, const Metadata *type) {
151-
typedef SWIFT_CC(swift) NSString *GetDescriptionFn(OpaqueValue*, const Metadata*);
152-
auto getDescription = SWIFT_LAZY_CONSTANT(
153-
reinterpret_cast<GetDescriptionFn*>(dlsym(RTLD_DEFAULT,
154-
MANGLE_AS_STRING(MANGLE_SYM(10Foundation15_getDescriptionySo8NSStringCxlF)))));
155-
156-
// If Foundation hasn't loaded yet, fall back to returning the static string
157-
// "Swift._SwiftObject". The likelihood of someone invoking -description without
158-
// ObjC interop is low.
159-
if (!getDescription) {
160-
return @"Swift._SwiftObject";
161-
}
150+
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERFACE
151+
NSString *swift_stdlib_getDescription(OpaqueValue *value,
152+
const Metadata *type);
162153

163-
return [getDescription(value, type) autorelease];
154+
NSString *swift::getDescription(OpaqueValue *value, const Metadata *type) {
155+
auto result = swift_stdlib_getDescription(value, type);
156+
SWIFT_CC_PLUSZERO_GUARD(type->vw_destroy(value));
157+
return [result autorelease];
164158
}
165159

166160
static NSString *_getObjectDescription(SwiftObject *obj) {

0 commit comments

Comments
 (0)