Skip to content

Commit 7e0eaf7

Browse files
authored
Remove metadata section functions from the stdlib (#39236)
add aliases in test suite
1 parent ec37074 commit 7e0eaf7

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

stdlib/private/SwiftReflectionTest/SwiftReflectionTest.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ import Glibc
131131

132132
let rtldDefault: UnsafeMutableRawPointer? = nil
133133

134+
#if INTERNAL_CHECKS_ENABLED
135+
@_silgen_name("swift_getMetadataSection")
136+
internal func _getMetadataSection(_ index: UInt) -> UnsafeRawPointer?
137+
138+
@_silgen_name("swift_getMetadataSectionCount")
139+
internal func _getMetadataSectionCount() -> UInt
140+
141+
@_silgen_name("swift_getMetadataSectionName")
142+
internal func _getMetadataSectionName(
143+
_ metadata_section: UnsafeRawPointer
144+
) -> UnsafePointer<CChar>
145+
#endif
146+
134147
extension Section {
135148
init(range: MetadataSectionRange) {
136149
self.startAddress = UnsafeRawPointer(bitPattern: range.start)!
@@ -139,6 +152,7 @@ extension Section {
139152
}
140153

141154
internal func getReflectionInfoForImage(atIndex i: UInt32) -> ReflectionInfo? {
155+
#if INTERNAL_CHECKS_ENABLED
142156
return _getMetadataSection(UInt(i)).map { rawPointer in
143157
let name = _getMetadataSectionName(rawPointer)
144158
let metadataSection = rawPointer.bindMemory(to: MetadataSections.self, capacity: 1).pointee
@@ -150,10 +164,17 @@ internal func getReflectionInfoForImage(atIndex i: UInt32) -> ReflectionInfo? {
150164
typeref: Section(range: metadataSection.swift5_typeref),
151165
reflstr: Section(range: metadataSection.swift5_reflstr))
152166
}
167+
#else
168+
return nil
169+
#endif
153170
}
154171

155172
internal func getImageCount() -> UInt32 {
173+
#if INTERNAL_CHECKS_ENABLED
156174
return UInt32(_getMetadataSectionCount())
175+
#else
176+
return 0
177+
#endif
157178
}
158179

159180
internal func sendImages() {

stdlib/public/core/Misc.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,3 @@ public func _getTypeByMangledNameInContext(
118118
genericContext: UnsafeRawPointer?,
119119
genericArguments: UnsafeRawPointer?)
120120
-> Any.Type?
121-
122-
@_silgen_name("swift_getMetadataSection")
123-
public func _getMetadataSection(
124-
_ index: UInt)
125-
-> UnsafeRawPointer?
126-
127-
@_silgen_name("swift_getMetadataSectionCount")
128-
public func _getMetadataSectionCount()
129-
-> UInt
130-
131-
@_silgen_name("swift_getMetadataSectionName")
132-
public func _getMetadataSectionName(
133-
_ metadata_section: UnsafeRawPointer)
134-
-> UnsafePointer<CChar>

stdlib/public/runtime/ImageInspectionCommon.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,10 @@ void swift::initializeTypeMetadataRecordLookup() {
131131
void swift::initializeDynamicReplacementLookup() {
132132
}
133133

134+
#ifndef NDEBUG
135+
134136
SWIFT_RUNTIME_EXPORT
135137
const swift::MetadataSections *swift_getMetadataSection(size_t index) {
136-
#ifndef NDEBUG
137138
if (swift::registered == nullptr) {
138139
return nullptr;
139140
}
@@ -147,27 +148,21 @@ const swift::MetadataSections *swift_getMetadataSection(size_t index) {
147148
--index;
148149
}
149150
return selected;
150-
#else // NDEBUG
151-
return nullptr;
152-
#endif // else NDEBUG
153151
}
154152

155153
SWIFT_RUNTIME_EXPORT
156154
const char *swift_getMetadataSectionName(void *metadata_section) {
157-
#ifndef NDEBUG
158155
swift::SymbolInfo info;
159156
if (lookupSymbol(metadata_section, &info)) {
160157
if (info.fileName) {
161158
return info.fileName;
162159
}
163160
}
164-
#endif // NDEBUG
165161
return "";
166162
}
167163

168164
SWIFT_RUNTIME_EXPORT
169165
size_t swift_getMetadataSectionCount() {
170-
#ifndef NDEBUG
171166
if (swift::registered == nullptr)
172167
return 0;
173168

@@ -176,10 +171,10 @@ size_t swift_getMetadataSectionCount() {
176171
current != swift::registered; current = current->next, ++count);
177172

178173
return count;
179-
#else // NDEBUG
180-
return 0;
181-
#endif // else NDEBUG
182174
}
175+
176+
#endif // NDEBUG
177+
183178
#endif // !defined(__MACH__)
184179

185180
#endif // SWIFT_RUNTIME_IMAGEINSPECTIONCOMMON_H

test/api-digester/stability-stdlib-abi-without-asserts.test

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@
5050
Func _prespecialize() is a new API without @available attribute
5151
Func _stdlib_isOSVersionAtLeastOrVariantVersionAtLeast(_:_:_:_:_:_:) is a new API without @available attribute
5252

53-
// These reflection APIs are exposed to facilitate building SwiftReflectionTest.swift when testing Release builds.
54-
Func _getMetadataSection(_:) is a new API without @available attribute
55-
Func _getMetadataSectionCount() is a new API without @available attribute
56-
Func _getMetadataSectionName(_:) is a new API without @available attribute
57-
5853
Func Collection.removingSubranges(_:) has been removed
5954
Func Collection.subranges(of:) has been removed
6055
Func Collection.subranges(where:) has been removed

0 commit comments

Comments
 (0)