From 48384757f6ca1b86ca2b9e6ba177a27deffd5778 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Thu, 9 Sep 2021 15:41:01 -0700 Subject: [PATCH] Remove metadata section functions from the stdlib add aliases in test suite --- .../SwiftReflectionTest.swift | 21 +++++++++++++++++++ stdlib/public/core/Misc.swift | 14 ------------- .../public/runtime/ImageInspectionCommon.cpp | 15 +++++-------- .../stability-stdlib-abi-without-asserts.test | 5 ----- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/stdlib/private/SwiftReflectionTest/SwiftReflectionTest.swift b/stdlib/private/SwiftReflectionTest/SwiftReflectionTest.swift index 7904d43015b19..db1919bb81be5 100644 --- a/stdlib/private/SwiftReflectionTest/SwiftReflectionTest.swift +++ b/stdlib/private/SwiftReflectionTest/SwiftReflectionTest.swift @@ -131,6 +131,19 @@ import Glibc let rtldDefault: UnsafeMutableRawPointer? = nil +#if INTERNAL_CHECKS_ENABLED +@_silgen_name("swift_getMetadataSection") +internal func _getMetadataSection(_ index: UInt) -> UnsafeRawPointer? + +@_silgen_name("swift_getMetadataSectionCount") +internal func _getMetadataSectionCount() -> UInt + +@_silgen_name("swift_getMetadataSectionName") +internal func _getMetadataSectionName( + _ metadata_section: UnsafeRawPointer +) -> UnsafePointer +#endif + extension Section { init(range: MetadataSectionRange) { self.startAddress = UnsafeRawPointer(bitPattern: range.start)! @@ -139,6 +152,7 @@ extension Section { } internal func getReflectionInfoForImage(atIndex i: UInt32) -> ReflectionInfo? { +#if INTERNAL_CHECKS_ENABLED return _getMetadataSection(UInt(i)).map { rawPointer in let name = _getMetadataSectionName(rawPointer) let metadataSection = rawPointer.bindMemory(to: MetadataSections.self, capacity: 1).pointee @@ -150,10 +164,17 @@ internal func getReflectionInfoForImage(atIndex i: UInt32) -> ReflectionInfo? { typeref: Section(range: metadataSection.swift5_typeref), reflstr: Section(range: metadataSection.swift5_reflstr)) } +#else + return nil +#endif } internal func getImageCount() -> UInt32 { +#if INTERNAL_CHECKS_ENABLED return UInt32(_getMetadataSectionCount()) +#else + return 0 +#endif } internal func sendImages() { diff --git a/stdlib/public/core/Misc.swift b/stdlib/public/core/Misc.swift index 2b63a7f69c93c..469ac429b8ee8 100644 --- a/stdlib/public/core/Misc.swift +++ b/stdlib/public/core/Misc.swift @@ -118,17 +118,3 @@ public func _getTypeByMangledNameInContext( genericContext: UnsafeRawPointer?, genericArguments: UnsafeRawPointer?) -> Any.Type? - -@_silgen_name("swift_getMetadataSection") -public func _getMetadataSection( - _ index: UInt) - -> UnsafeRawPointer? - -@_silgen_name("swift_getMetadataSectionCount") -public func _getMetadataSectionCount() - -> UInt - -@_silgen_name("swift_getMetadataSectionName") -public func _getMetadataSectionName( - _ metadata_section: UnsafeRawPointer) - -> UnsafePointer diff --git a/stdlib/public/runtime/ImageInspectionCommon.cpp b/stdlib/public/runtime/ImageInspectionCommon.cpp index fa2d58a311fe5..c70e886c06806 100644 --- a/stdlib/public/runtime/ImageInspectionCommon.cpp +++ b/stdlib/public/runtime/ImageInspectionCommon.cpp @@ -131,9 +131,10 @@ void swift::initializeTypeMetadataRecordLookup() { void swift::initializeDynamicReplacementLookup() { } +#ifndef NDEBUG + SWIFT_RUNTIME_EXPORT const swift::MetadataSections *swift_getMetadataSection(size_t index) { - #ifndef NDEBUG if (swift::registered == nullptr) { return nullptr; } @@ -147,27 +148,21 @@ const swift::MetadataSections *swift_getMetadataSection(size_t index) { --index; } return selected; - #else // NDEBUG - return nullptr; - #endif // else NDEBUG } SWIFT_RUNTIME_EXPORT const char *swift_getMetadataSectionName(void *metadata_section) { - #ifndef NDEBUG swift::SymbolInfo info; if (lookupSymbol(metadata_section, &info)) { if (info.fileName) { return info.fileName; } } - #endif // NDEBUG return ""; } SWIFT_RUNTIME_EXPORT size_t swift_getMetadataSectionCount() { - #ifndef NDEBUG if (swift::registered == nullptr) return 0; @@ -176,10 +171,10 @@ size_t swift_getMetadataSectionCount() { current != swift::registered; current = current->next, ++count); return count; - #else // NDEBUG - return 0; - #endif // else NDEBUG } + +#endif // NDEBUG + #endif // !defined(__MACH__) #endif // SWIFT_RUNTIME_IMAGEINSPECTIONCOMMON_H \ No newline at end of file diff --git a/test/api-digester/stability-stdlib-abi-without-asserts.test b/test/api-digester/stability-stdlib-abi-without-asserts.test index 4006a88b676d9..9b731bbf42fb1 100644 --- a/test/api-digester/stability-stdlib-abi-without-asserts.test +++ b/test/api-digester/stability-stdlib-abi-without-asserts.test @@ -50,11 +50,6 @@ Func _prespecialize() is a new API without @available attribute Func _stdlib_isOSVersionAtLeastOrVariantVersionAtLeast(_:_:_:_:_:_:) is a new API without @available attribute -// These reflection APIs are exposed to facilitate building SwiftReflectionTest.swift when testing Release builds. -Func _getMetadataSection(_:) is a new API without @available attribute -Func _getMetadataSectionCount() is a new API without @available attribute -Func _getMetadataSectionName(_:) is a new API without @available attribute - Func Collection.removingSubranges(_:) has been removed Func Collection.subranges(of:) has been removed Func Collection.subranges(where:) has been removed