Skip to content

Commit 58c9b45

Browse files
author
Greg Parker
committed
[runtime] Clean up symbols in StdlibUnittest and the internal leak checker.
* Export fewer symbols. * Prefix exported but not-public symbols with `_swift_`.
1 parent ac6e0bd commit 58c9b45

File tree

14 files changed

+71
-65
lines changed

14 files changed

+71
-65
lines changed

benchmark/utils/DriverUtils.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,9 @@ func internalMedian(_ inputs: [UInt64]) -> UInt64 {
312312

313313
#if SWIFT_RUNTIME_ENABLE_LEAK_CHECKER
314314

315-
@_silgen_name("swift_leaks_startTrackingObjects")
315+
@_silgen_name("_swift_leaks_startTrackingObjects")
316316
func startTrackingObjects(_: UnsafeMutableRawPointer) -> ()
317-
@_silgen_name("swift_leaks_stopTrackingObjects")
317+
@_silgen_name("_swift_leaks_stopTrackingObjects")
318318
func stopTrackingObjects(_: UnsafeMutableRawPointer) -> Int
319319

320320
#endif

stdlib/private/StdlibUnittest/GetOSVersion.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
#include "swift/Runtime/Config.h"
1717

18-
SWIFT_CC(swift)
19-
extern "C" const char *
20-
swift_stdlib_getSystemVersionPlistProperty(const char *PropertyName) {
18+
SWIFT_CC(swift) LLVM_LIBRARY_VISIBILITY extern "C"
19+
const char *
20+
getSystemVersionPlistProperty(const char *PropertyName) {
2121
// This function is implemented in Objective-C because Swift does not support
2222
// failing initializers.
2323
if (!PropertyName)

stdlib/private/StdlibUnittest/InspectValue.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515

1616
using namespace swift;
1717

18-
SWIFT_CC(swift)
19-
extern "C"
20-
uint32_t swift_StdlibUnittest_getMetadataKindOf(
18+
SWIFT_CC(swift) LLVM_LIBRARY_VISIBILITY extern "C"
19+
uint32_t getMetadataKindOf(
2120
OpaqueValue *value,
2221
const Metadata *type
2322
) {

stdlib/private/StdlibUnittest/InspectValue.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public enum SwiftRuntime {
3030
case errorObject = 128
3131
}
3232

33-
@_silgen_name("swift_StdlibUnittest_getMetadataKindOf")
34-
static func _metadataKindImpl<T>(of value: T) -> UInt32
33+
@_silgen_name("getMetadataKindOf")
34+
private static func _metadataKind<T>(of value: T) -> UInt32
3535

3636
public static func metadataKind<T>(of value: T) -> MetadataKind {
37-
return MetadataKind(rawValue: Int(_metadataKindImpl(of: value)))!
37+
return MetadataKind(rawValue: Int(_metadataKind(of: value)))!
3838
}
3939
}
4040

stdlib/private/StdlibUnittest/InterceptTraps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ static void CrashCatcher(int Sig) {
3333
_exit(0);
3434
}
3535

36-
SWIFT_CC(swift)
37-
extern "C" void swift_stdlib_installTrapInterceptor() {
36+
SWIFT_CC(swift) LLVM_LIBRARY_VISIBILITY extern "C"
37+
void installTrapInterceptor() {
3838
// Disable buffering on stdout so that everything is printed before crashing.
3939
setbuf(stdout, 0);
4040

stdlib/private/StdlibUnittest/OpaqueIdentityFunctions.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include "swift/Runtime/Config.h"
1414

15-
SWIFT_CC(swift)
16-
extern "C"
17-
void *swift_stdlib_getPointer(void *x) { return x; }
15+
SWIFT_CC(swift) LLVM_LIBRARY_VISIBILITY extern "C"
16+
void *getPointer(void *x) { return x; }
1817

stdlib/private/StdlibUnittest/OpaqueIdentityFunctions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
@_silgen_name("swift_stdlib_getPointer")
14-
func _stdlib_getPointer(_ x: OpaquePointer) -> OpaquePointer
13+
@_silgen_name("getPointer")
14+
func _getPointer(_ x: OpaquePointer) -> OpaquePointer
1515

1616
public func _opaqueIdentity<T>(_ x: T) -> T {
1717
let ptr = UnsafeMutablePointer<T>.allocate(capacity: 1)
1818
ptr.initialize(to: x)
1919
let result =
20-
UnsafeMutablePointer<T>(_stdlib_getPointer(OpaquePointer(ptr))).pointee
20+
UnsafeMutablePointer<T>(_getPointer(OpaquePointer(ptr))).pointee
2121
ptr.deinitialize()
2222
ptr.deallocate(capacity: 1)
2323
return result
2424
}
2525

2626
func _blackHolePtr<T>(_ x: UnsafePointer<T>) {
27-
_ = _stdlib_getPointer(OpaquePointer(x))
27+
_ = _getPointer(OpaquePointer(x))
2828
}
2929

3030
public func _blackHole<T>(_ x: T) {

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,8 @@ var _testSuiteNameToIndex: [String : Int] = [:]
617617
let _stdlibUnittestStreamPrefix = "__STDLIB_UNITTEST__"
618618
let _crashedPrefix = "CRASHED:"
619619

620-
@_silgen_name("swift_stdlib_installTrapInterceptor")
621-
func _stdlib_installTrapInterceptor()
620+
@_silgen_name("installTrapInterceptor")
621+
func _installTrapInterceptor()
622622

623623
#if _runtime(_ObjC)
624624
@objc protocol _StdlibUnittestNSException {
@@ -629,7 +629,7 @@ func _stdlib_installTrapInterceptor()
629629
// Avoid serializing references to objc_setUncaughtExceptionHandler in SIL.
630630
@inline(never)
631631
func _childProcess() {
632-
_stdlib_installTrapInterceptor()
632+
_installTrapInterceptor()
633633

634634
#if _runtime(_ObjC)
635635
objc_setUncaughtExceptionHandler {
@@ -1192,9 +1192,9 @@ public func runAllTests() {
11921192

11931193
#if SWIFT_RUNTIME_ENABLE_LEAK_CHECKER
11941194

1195-
@_silgen_name("swift_leaks_startTrackingObjects")
1195+
@_silgen_name("_swift_leaks_startTrackingObjects")
11961196
func startTrackingObjects(_: UnsafePointer<CChar>)
1197-
@_silgen_name("swift_leaks_stopTrackingObjects")
1197+
@_silgen_name("_swift_leaks_stopTrackingObjects")
11981198
func stopTrackingObjects(_: UnsafePointer<CChar>) -> Int
11991199

12001200
#endif
@@ -1408,12 +1408,12 @@ public final class TestSuite {
14081408
}
14091409

14101410
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
1411-
@_silgen_name("swift_stdlib_getSystemVersionPlistProperty")
1412-
func _stdlib_getSystemVersionPlistPropertyImpl(
1411+
@_silgen_name("getSystemVersionPlistProperty")
1412+
func _getSystemVersionPlistPropertyImpl(
14131413
_ propertyName: UnsafePointer<CChar>) -> UnsafePointer<CChar>?
14141414

1415-
func _stdlib_getSystemVersionPlistProperty(_ propertyName: String) -> String? {
1416-
let cs = _stdlib_getSystemVersionPlistPropertyImpl(propertyName)
1415+
func _getSystemVersionPlistProperty(_ propertyName: String) -> String? {
1416+
let cs = _getSystemVersionPlistPropertyImpl(propertyName)
14171417
return cs.map(String.init(cString:))
14181418
}
14191419
#endif
@@ -1509,7 +1509,7 @@ func _getOSVersion() -> OSVersion {
15091509
#elseif os(Haiku)
15101510
return .haiku
15111511
#else
1512-
let productVersion = _stdlib_getSystemVersionPlistProperty("ProductVersion")!
1512+
let productVersion = _getSystemVersionPlistProperty("ProductVersion")!
15131513
let (major, minor, bugFix) = _parseDottedVersionTriple(productVersion)
15141514
#if os(OSX)
15151515
return .osx(major: major, minor: minor, bugFix: bugFix)

stdlib/private/StdlibUnittest/TestHelpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class DummyClass {}
1414

1515
// Used by the weak.mm runtime tests. All that matters is that the returned
1616
// object is an instance of a pure Swift class.
17-
@_silgen_name("make_swift_object")
17+
@_silgen_name("_swift_StdlibUnittest_make_swift_object")
1818
public func make_swift_object() -> AnyObject {
1919
return DummyClass()
2020
}

stdlib/private/StdlibUnittestFoundationExtras/StdlibUnittestFoundationExtras.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public func autoreleasepoolIfUnoptimizedReturnAutoreleased(
8080
}
8181

8282
@_versioned
83-
@_silgen_name("swift_stdlib_NSArray_getObjects")
84-
internal func _stdlib_NSArray_getObjects(
83+
@_silgen_name("NSArray_getObjects")
84+
func NSArray_getObjects(
8585
nsArray: AnyObject,
8686
objects: AutoreleasingUnsafeMutablePointer<AnyObject?>?,
8787
rangeLocation: Int,
@@ -92,16 +92,16 @@ extension NSArray {
9292
public func available_getObjects(
9393
_ objects: AutoreleasingUnsafeMutablePointer<AnyObject?>?, range: NSRange
9494
) {
95-
return _stdlib_NSArray_getObjects(
95+
return NSArray_getObjects(
9696
nsArray: self,
9797
objects: objects,
9898
rangeLocation: range.location,
9999
rangeLength: range.length)
100100
}
101101
}
102102

103-
@_silgen_name("swift_stdlib_NSDictionary_getObjects")
104-
func _stdlib_NSDictionary_getObjects(
103+
@_silgen_name("NSDictionary_getObjects")
104+
func NSDictionary_getObjects(
105105
nsDictionary: NSDictionary,
106106
objects: AutoreleasingUnsafeMutablePointer<AnyObject?>?,
107107
andKeys keys: AutoreleasingUnsafeMutablePointer<AnyObject?>?
@@ -113,7 +113,7 @@ extension NSDictionary {
113113
_ objects: AutoreleasingUnsafeMutablePointer<AnyObject?>?,
114114
andKeys keys: AutoreleasingUnsafeMutablePointer<AnyObject?>?
115115
) {
116-
return _stdlib_NSDictionary_getObjects(
116+
return NSDictionary_getObjects(
117117
nsDictionary: self,
118118
objects: objects,
119119
andKeys: keys)

stdlib/private/StdlibUnittestFoundationExtras/UnavailableFoundationMethodThunks.mm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
#include <Foundation/Foundation.h>
1414
#include "swift/Runtime/Config.h"
1515

16-
SWIFT_CC(swift)
16+
SWIFT_CC(swift) LLVM_LIBRARY_VISIBILITY
1717
extern "C" void
18-
swift_stdlib_NSArray_getObjects(NSArray NS_RELEASES_ARGUMENT *_Nonnull nsArray,
19-
id *objects, NSUInteger rangeLocation,
20-
NSUInteger rangeLength) {
18+
NSArray_getObjects(NSArray NS_RELEASES_ARGUMENT *_Nonnull nsArray,
19+
id *objects, NSUInteger rangeLocation,
20+
NSUInteger rangeLength) {
2121
[nsArray getObjects:objects range:NSMakeRange(rangeLocation, rangeLength)];
2222
[nsArray release];
2323
}
2424

25-
SWIFT_CC(swift)
25+
SWIFT_CC(swift) LLVM_LIBRARY_VISIBILITY
2626
extern "C" void
27-
swift_stdlib_NSDictionary_getObjects(NSDictionary *_Nonnull nsDictionary,
28-
id *objects, id *keys) {
27+
NSDictionary_getObjects(NSDictionary *_Nonnull nsDictionary,
28+
id *objects, id *keys) {
2929
[nsDictionary getObjects:objects andKeys:keys];
3030
[nsDictionary release];
3131
}

stdlib/public/runtime/Leaks.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,26 @@ struct HeapObject;
3131
}
3232

3333
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
34-
void swift_leaks_startTrackingObjects(const char *);
34+
void _swift_leaks_startTrackingObjects(const char *);
3535
SWIFT_CC(swift) SWIFT_RUNTIME_EXPORT LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
36-
int swift_leaks_stopTrackingObjects(const char *);
36+
int _swift_leaks_stopTrackingObjects(const char *);
3737
SWIFT_RUNTIME_EXPORT LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
38-
void swift_leaks_startTrackingObject(swift::HeapObject *);
38+
void _swift_leaks_startTrackingObject(swift::HeapObject *);
3939
SWIFT_RUNTIME_EXPORT LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
40-
void swift_leaks_stopTrackingObject(swift::HeapObject *);
40+
void _swift_leaks_stopTrackingObject(swift::HeapObject *);
4141

4242
#define SWIFT_LEAKS_START_TRACKING_OBJECT(obj) \
43-
swift_leaks_startTrackingObject(obj)
43+
_swift_leaks_startTrackingObject(obj)
4444
#define SWIFT_LEAKS_STOP_TRACKING_OBJECT(obj) \
45-
swift_leaks_stopTrackingObject(obj)
45+
_swift_leaks_stopTrackingObject(obj)
46+
47+
// SWIFT_RUNTIME_ENABLE_LEAK_CHECKER
4648
#else
49+
// not SWIFT_RUNTIME_ENABLE_LEAK_CHECKER
50+
4751
#define SWIFT_LEAKS_START_TRACKING_OBJECT(obj)
4852
#define SWIFT_LEAKS_STOP_TRACKING_OBJECT(obj)
53+
4954
#endif
5055

5156
#endif

stdlib/public/runtime/Leaks.mm

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
// Extra Interfaces
3636
//===----------------------------------------------------------------------===//
3737

38-
void swift_leaks_stopTrackingObjCObject(id obj);
39-
void swift_leaks_startTrackingObjCObject(id obj);
38+
static void _swift_leaks_stopTrackingObjCObject(id obj);
39+
static void _swift_leaks_startTrackingObjCObject(id obj);
4040

4141
//===----------------------------------------------------------------------===//
4242
// State
@@ -64,24 +64,23 @@
6464
//===----------------------------------------------------------------------===//
6565

6666
static void __swift_leaks_dealloc(id self, SEL _cmd) {
67-
swift_leaks_stopTrackingObjCObject(self);
67+
_swift_leaks_stopTrackingObjCObject(self);
6868
((void (*)(id, SEL))old_dealloc_fun)(self, _cmd);
6969
}
7070

7171
static id __swift_leaks_alloc(id self, SEL _cmd) {
7272
id result = ((id (*)(id, SEL))old_alloc_fun)(self, _cmd);
73-
swift_leaks_startTrackingObjCObject(result);
73+
_swift_leaks_startTrackingObjCObject(result);
7474
return result;
7575
}
7676

7777
static id __swift_leaks_allocWithZone(id self, SEL _cmd, id zone) {
7878
id result = ((id (*)(id, SEL, id))old_allocWithZone_fun)(self, _cmd, zone);
79-
swift_leaks_startTrackingObjCObject(result);
79+
_swift_leaks_startTrackingObjCObject(result);
8080
return result;
8181
}
8282

83-
SWIFT_CC(swift)
84-
extern "C" void swift_leaks_startTrackingObjects(const char *name) {
83+
void _swift_leaks_startTrackingObjects(const char *name) {
8584
pthread_mutex_lock(&LeaksMutex);
8685

8786
// First clear our tracked objects set.
@@ -160,8 +159,7 @@ static void dumpObjCHeapObjects() {
160159
}
161160
}
162161

163-
SWIFT_CC(swift)
164-
extern "C" int swift_leaks_stopTrackingObjects(const char *name) {
162+
int _swift_leaks_stopTrackingObjects(const char *name) {
165163
pthread_mutex_lock(&LeaksMutex);
166164
unsigned Result = TrackedSwiftObjects->size() + TrackedObjCObjects->size();
167165

@@ -198,29 +196,29 @@ static void dumpObjCHeapObjects() {
198196
// Tracking Code
199197
//===----------------------------------------------------------------------===//
200198

201-
extern "C" void swift_leaks_startTrackingObject(HeapObject *Object) {
199+
void _swift_leaks_startTrackingObject(HeapObject *Object) {
202200
pthread_mutex_lock(&LeaksMutex);
203201
if (ShouldTrackObjects) {
204202
TrackedSwiftObjects->insert(Object);
205203
}
206204
pthread_mutex_unlock(&LeaksMutex);
207205
}
208206

209-
extern "C" void swift_leaks_stopTrackingObject(HeapObject *Object) {
207+
void _swift_leaks_stopTrackingObject(HeapObject *Object) {
210208
pthread_mutex_lock(&LeaksMutex);
211209
TrackedSwiftObjects->erase(Object);
212210
pthread_mutex_unlock(&LeaksMutex);
213211
}
214212

215-
void swift_leaks_startTrackingObjCObject(id Object) {
213+
static void _swift_leaks_startTrackingObjCObject(id Object) {
216214
pthread_mutex_lock(&LeaksMutex);
217215
if (ShouldTrackObjects) {
218216
TrackedObjCObjects->insert(Object);
219217
}
220218
pthread_mutex_unlock(&LeaksMutex);
221219
}
222220

223-
void swift_leaks_stopTrackingObjCObject(id Object) {
221+
static void _swift_leaks_stopTrackingObjCObject(id Object) {
224222
pthread_mutex_lock(&LeaksMutex);
225223
TrackedObjCObjects->erase(Object);
226224
pthread_mutex_unlock(&LeaksMutex);

unittests/runtime/weak.mm

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@ - (void) dealloc {
4242
}
4343

4444
// Make a Native Swift object by calling a Swift function.
45-
// make_swift_object is defined in TestHelpers.swift as part of StdlibUnittest.
46-
SWIFT_CC(swift) extern "C" HeapObject *make_swift_object();
45+
// _swift_StdlibUnittest_make_swift_object is implemented in StdlibUnittest.
46+
SWIFT_CC(swift) extern "C"
47+
HeapObject *_swift_StdlibUnittest_make_swift_object();
48+
49+
static HeapObject *make_swift_object() {
50+
return _swift_StdlibUnittest_make_swift_object();
51+
}
4752

4853
static unsigned getUnownedRetainCount(HeapObject *object) {
4954
return swift_unownedRetainCount(object) - 1;

0 commit comments

Comments
 (0)