diff --git a/stdlib/CMakeLists.txt b/stdlib/CMakeLists.txt index a2e5f71c3da43..3fa2f27217573 100644 --- a/stdlib/CMakeLists.txt +++ b/stdlib/CMakeLists.txt @@ -102,6 +102,10 @@ set(SWIFT_STDLIB_ENABLE_LTO OFF CACHE STRING "Build Swift stdlib with LTO. One must specify the form of LTO by setting this to one of: 'full', 'thin'. This option only affects the standard library and runtime, not tools.") +option(SWIFT_ENABLE_REFLECTION + "Build stdlib with support for runtime reflection and mirrors." + TRUE) + # # End of user-configurable options. # diff --git a/stdlib/cmake/modules/AddSwiftStdlib.cmake b/stdlib/cmake/modules/AddSwiftStdlib.cmake index 4d8a588a5d4e6..492c9864f0dc7 100644 --- a/stdlib/cmake/modules/AddSwiftStdlib.cmake +++ b/stdlib/cmake/modules/AddSwiftStdlib.cmake @@ -315,6 +315,10 @@ function(_add_target_variant_c_compile_flags) list(APPEND result "-DSWIFT_RUNTIME_NO_COMPATIBILITY_OVERRIDES") endif() + if(SWIFT_ENABLE_REFLECTION) + list(APPEND result "-DSWIFT_ENABLE_REFLECTION") + endif() + if(SWIFT_RUNTIME_MACHO_NO_DYLD) list(APPEND result "-DSWIFT_RUNTIME_MACHO_NO_DYLD") endif() diff --git a/stdlib/cmake/modules/SwiftSource.cmake b/stdlib/cmake/modules/SwiftSource.cmake index 9ca753c1ac909..c21a99c10307d 100644 --- a/stdlib/cmake/modules/SwiftSource.cmake +++ b/stdlib/cmake/modules/SwiftSource.cmake @@ -432,6 +432,12 @@ function(_compile_swift_files list(APPEND swift_flags "-Xfrontend" "-emit-sorted-sil") endif() + if(NOT SWIFT_ENABLE_REFLECTION) + list(APPEND swift_flags "-Xfrontend" "-disable-reflection-metadata") + else() + list(APPEND swift_flags "-D" "SWIFT_ENABLE_REFLECTION") + endif() + # FIXME: Cleaner way to do this? if(SWIFTFILE_IS_STDLIB_CORE) list(APPEND swift_flags diff --git a/stdlib/public/core/AnyHashable.swift b/stdlib/public/core/AnyHashable.swift index 21ee82f4dc481..3225dc5f2e1d3 100644 --- a/stdlib/public/core/AnyHashable.swift +++ b/stdlib/public/core/AnyHashable.swift @@ -252,6 +252,7 @@ extension AnyHashable: CustomDebugStringConvertible { } } +#if SWIFT_ENABLE_REFLECTION extension AnyHashable: CustomReflectable { public var customMirror: Mirror { return Mirror( @@ -259,6 +260,7 @@ extension AnyHashable: CustomReflectable { children: ["value": base]) } } +#endif @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) extension AnyHashable: _HasCustomAnyHashableRepresentation { diff --git a/stdlib/public/core/Array.swift b/stdlib/public/core/Array.swift index 5fb18d7ea6d75..5ad228816394e 100644 --- a/stdlib/public/core/Array.swift +++ b/stdlib/public/core/Array.swift @@ -1414,6 +1414,7 @@ extension Array { } } +#if SWIFT_ENABLE_REFLECTION extension Array: CustomReflectable { /// A mirror that reflects the array. public var customMirror: Mirror { @@ -1423,6 +1424,7 @@ extension Array: CustomReflectable { displayStyle: .collection) } } +#endif extension Array: CustomStringConvertible, CustomDebugStringConvertible { /// A textual representation of the array and its elements. diff --git a/stdlib/public/core/ArraySlice.swift b/stdlib/public/core/ArraySlice.swift index d797b0223a505..07e8a0f6b7c45 100644 --- a/stdlib/public/core/ArraySlice.swift +++ b/stdlib/public/core/ArraySlice.swift @@ -1118,6 +1118,7 @@ extension ArraySlice: RangeReplaceableCollection { } } +#if SWIFT_ENABLE_REFLECTION extension ArraySlice: CustomReflectable { /// A mirror that reflects the array. public var customMirror: Mirror { @@ -1127,6 +1128,7 @@ extension ArraySlice: CustomReflectable { displayStyle: .collection) } } +#endif extension ArraySlice: CustomStringConvertible, CustomDebugStringConvertible { /// A textual representation of the array and its elements. diff --git a/stdlib/public/core/ClosedRange.swift b/stdlib/public/core/ClosedRange.swift index 0ff48522689c6..079ae8fad6386 100644 --- a/stdlib/public/core/ClosedRange.swift +++ b/stdlib/public/core/ClosedRange.swift @@ -396,12 +396,14 @@ extension ClosedRange: CustomDebugStringConvertible { } } +#if SWIFT_ENABLE_REFLECTION extension ClosedRange: CustomReflectable { public var customMirror: Mirror { return Mirror( self, children: ["lowerBound": lowerBound, "upperBound": upperBound]) } } +#endif extension ClosedRange { /// Returns a copy of this range clamped to the given limiting range. diff --git a/stdlib/public/core/CollectionOfOne.swift b/stdlib/public/core/CollectionOfOne.swift index 7bdd41928a1c8..04e2c3c2a9fef 100644 --- a/stdlib/public/core/CollectionOfOne.swift +++ b/stdlib/public/core/CollectionOfOne.swift @@ -165,11 +165,13 @@ extension CollectionOfOne: CustomDebugStringConvertible { } } +#if SWIFT_ENABLE_REFLECTION extension CollectionOfOne: CustomReflectable { public var customMirror: Mirror { return Mirror(self, children: ["element": _element]) } } +#endif extension CollectionOfOne: Sendable where Element: Sendable { } extension CollectionOfOne.Iterator: Sendable where Element: Sendable { } diff --git a/stdlib/public/core/ContiguousArray.swift b/stdlib/public/core/ContiguousArray.swift index 89dcec8c804f6..e3daceaf36244 100644 --- a/stdlib/public/core/ContiguousArray.swift +++ b/stdlib/public/core/ContiguousArray.swift @@ -1019,6 +1019,7 @@ extension ContiguousArray: RangeReplaceableCollection { } } +#if SWIFT_ENABLE_REFLECTION extension ContiguousArray: CustomReflectable { /// A mirror that reflects the array. public var customMirror: Mirror { @@ -1028,6 +1029,7 @@ extension ContiguousArray: CustomReflectable { displayStyle: .collection) } } +#endif extension ContiguousArray: CustomStringConvertible, CustomDebugStringConvertible { /// A textual representation of the array and its elements. diff --git a/stdlib/public/core/DebuggerSupport.swift b/stdlib/public/core/DebuggerSupport.swift index af1e130935184..ef9eafeab81f7 100644 --- a/stdlib/public/core/DebuggerSupport.swift +++ b/stdlib/public/core/DebuggerSupport.swift @@ -12,6 +12,8 @@ import SwiftShims +#if SWIFT_ENABLE_REFLECTION + @frozen // namespace public enum _DebuggerSupport { private enum CollectionStatus { @@ -262,6 +264,8 @@ public func _stringForPrintObject(_ value: Any) -> String { return _DebuggerSupport.stringForPrintObject(value) } +#endif // SWIFT_ENABLE_REFLECTION + public func _debuggerTestingCheckExpect(_: String, _: String) { } // Utilities to get refcount(s) of class objects. diff --git a/stdlib/public/core/Dictionary.swift b/stdlib/public/core/Dictionary.swift index 914e35b43f8fa..dcebf90dc72bf 100644 --- a/stdlib/public/core/Dictionary.swift +++ b/stdlib/public/core/Dictionary.swift @@ -2033,6 +2033,7 @@ extension Dictionary.Iterator: IteratorProtocol { } } +#if SWIFT_ENABLE_REFLECTION extension Dictionary.Iterator: CustomReflectable { /// A mirror that reflects the iterator. public var customMirror: Mirror { @@ -2049,6 +2050,7 @@ extension Dictionary: CustomReflectable { return Mirror(self, unlabeledChildren: self, displayStyle: style) } } +#endif extension Dictionary { /// Removes and returns the first key-value pair of the dictionary if the diff --git a/stdlib/public/core/Dump.swift b/stdlib/public/core/Dump.swift index 24651aad32936..4f33668a88626 100644 --- a/stdlib/public/core/Dump.swift +++ b/stdlib/public/core/Dump.swift @@ -10,6 +10,8 @@ // //===----------------------------------------------------------------------===// +#if SWIFT_ENABLE_REFLECTION + /// Dumps the given object's contents using its mirror to the specified output /// stream. /// @@ -247,3 +249,4 @@ internal func _dumpSuperclass_unlocked( } } +#endif // SWIFT_ENABLE_REFLECTION diff --git a/stdlib/public/core/MigrationSupport.swift b/stdlib/public/core/MigrationSupport.swift index c4dbf718825d4..9d934144440a4 100644 --- a/stdlib/public/core/MigrationSupport.swift +++ b/stdlib/public/core/MigrationSupport.swift @@ -309,12 +309,14 @@ extension Substring { } } +#if SWIFT_ENABLE_REFLECTION extension Substring: _CustomPlaygroundQuickLookable { @available(swift, deprecated: 4.2/*, obsoleted: 5.0*/, message: "Substring.customPlaygroundQuickLook will be removed in a future Swift version") public var customPlaygroundQuickLook: _PlaygroundQuickLook { return String(self).customPlaygroundQuickLook } } +#endif extension Collection { // FIXME: @@ -630,6 +632,7 @@ public enum _PlaygroundQuickLook { case _raw([UInt8], String) } +#if SWIFT_ENABLE_REFLECTION extension _PlaygroundQuickLook { /// Creates a new Quick Look for the given instance. /// @@ -663,6 +666,7 @@ extension _PlaygroundQuickLook { } } } +#endif /// A type that explicitly supplies its own playground Quick Look. /// diff --git a/stdlib/public/core/Mirror.swift b/stdlib/public/core/Mirror.swift index f900aab4986ac..3a953e12e7c5b 100644 --- a/stdlib/public/core/Mirror.swift +++ b/stdlib/public/core/Mirror.swift @@ -12,6 +12,8 @@ // FIXME: ExistentialCollection needs to be supported before this will work // without the ObjC Runtime. +#if SWIFT_ENABLE_REFLECTION + /// A representation of the substructure and display style of an instance of /// any type. /// @@ -456,6 +458,70 @@ extension Mirror { } } +#else // SWIFT_ENABLE_REFLECTION + +@available(*, unavailable) +public struct Mirror { + public enum AncestorRepresentation { + case generated + case customized(() -> Mirror) + case suppressed + } + public init(reflecting subject: Any) { Builtin.unreachable() } + public typealias Child = (label: String?, value: Any) + public typealias Children = AnyCollection + public enum DisplayStyle: Sendable { + case `struct`, `class`, `enum`, tuple, optional, collection + case dictionary, `set` + } + public init( + _ subject: Subject, + children: C, + displayStyle: DisplayStyle? = nil, + ancestorRepresentation: AncestorRepresentation = .generated + ) where C.Element == Child { Builtin.unreachable() } + public init( + _ subject: Subject, + unlabeledChildren: C, + displayStyle: DisplayStyle? = nil, + ancestorRepresentation: AncestorRepresentation = .generated + ) { Builtin.unreachable() } + public init( + _ subject: Subject, + children: KeyValuePairs, + displayStyle: DisplayStyle? = nil, + ancestorRepresentation: AncestorRepresentation = .generated + ) { Builtin.unreachable() } + public let subjectType: Any.Type + public let children: Children + public let displayStyle: DisplayStyle? + public var superclassMirror: Mirror? { Builtin.unreachable() } +} + +@available(*, unavailable) +public protocol CustomReflectable { + var customMirror: Mirror { get } +} + +@available(*, unavailable) +public protocol CustomLeafReflectable: CustomReflectable {} + +@available(*, unavailable) +public protocol MirrorPath {} +@available(*, unavailable) +extension Int: MirrorPath {} +@available(*, unavailable) +extension String: MirrorPath {} + +@available(*, unavailable) +extension Mirror { + public func descendant(_ first: MirrorPath, _ rest: MirrorPath...) -> Any? { + Builtin.unreachable() + } +} + +#endif // SWIFT_ENABLE_REFLECTION + //===--- General Utilities ------------------------------------------------===// extension String { @@ -693,6 +759,8 @@ extension String { } } +#if SWIFT_ENABLE_REFLECTION + /// Reflection for `Mirror` itself. extension Mirror: CustomStringConvertible { public var description: String { @@ -705,3 +773,5 @@ extension Mirror: CustomReflectable { return Mirror(self, children: [:]) } } + +#endif // SWIFT_ENABLE_REFLECTION diff --git a/stdlib/public/core/Mirrors.swift b/stdlib/public/core/Mirrors.swift index 171adc99673f6..fd682555e494e 100644 --- a/stdlib/public/core/Mirrors.swift +++ b/stdlib/public/core/Mirrors.swift @@ -10,6 +10,8 @@ // //===----------------------------------------------------------------------===// +#if SWIFT_ENABLE_REFLECTION + extension Float: CustomReflectable { /// A mirror that reflects the `Float` instance. public var customMirror: Mirror { @@ -258,3 +260,5 @@ extension Float80: CustomReflectable { } } #endif + +#endif diff --git a/stdlib/public/core/Optional.swift b/stdlib/public/core/Optional.swift index bea036409826f..35dca316dc24b 100644 --- a/stdlib/public/core/Optional.swift +++ b/stdlib/public/core/Optional.swift @@ -279,6 +279,7 @@ extension Optional: CustomDebugStringConvertible { } } +#if SWIFT_ENABLE_REFLECTION extension Optional: CustomReflectable { public var customMirror: Mirror { switch self { @@ -292,6 +293,7 @@ extension Optional: CustomReflectable { } } } +#endif @_transparent public // COMPILER_INTRINSIC diff --git a/stdlib/public/core/OutputStream.swift b/stdlib/public/core/OutputStream.swift index 5ede1f939ea20..c5d357f8c6488 100644 --- a/stdlib/public/core/OutputStream.swift +++ b/stdlib/public/core/OutputStream.swift @@ -296,6 +296,7 @@ internal func _fallbackEnumRawValue(_ value: T) -> Int64? { } } +#if SWIFT_ENABLE_REFLECTION /// Do our best to print a value that cannot be printed directly. @_semantics("optimize.sil.specialize.generic.never") internal func _adHocPrint_unlocked( @@ -396,6 +397,7 @@ internal func _adHocPrint_unlocked( } } } +#endif @usableFromInline @_semantics("optimize.sil.specialize.generic.never") @@ -435,8 +437,12 @@ internal func _print_unlocked( return } +#if SWIFT_ENABLE_REFLECTION let mirror = Mirror(reflecting: value) _adHocPrint_unlocked(value, mirror, &target, isDebugPrint: false) +#else + target.write("(value cannot be printed without reflection)") +#endif } //===----------------------------------------------------------------------===// @@ -463,10 +469,15 @@ public func _debugPrint_unlocked( return } +#if SWIFT_ENABLE_REFLECTION let mirror = Mirror(reflecting: value) _adHocPrint_unlocked(value, mirror, &target, isDebugPrint: true) +#else + target.write("(value cannot be printed without reflection)") +#endif } +#if SWIFT_ENABLE_REFLECTION @_semantics("optimize.sil.specialize.generic.never") internal func _dumpPrint_unlocked( _ value: T, _ mirror: Mirror, _ target: inout TargetStream @@ -533,6 +544,7 @@ internal func _dumpPrint_unlocked( _adHocPrint_unlocked(value, mirror, &target, isDebugPrint: true) } +#endif //===----------------------------------------------------------------------===// // OutputStreams diff --git a/stdlib/public/core/Pointer.swift b/stdlib/public/core/Pointer.swift index f248b4799a9cd..6b59eb16ba4d6 100644 --- a/stdlib/public/core/Pointer.swift +++ b/stdlib/public/core/Pointer.swift @@ -10,11 +10,17 @@ // //===----------------------------------------------------------------------===// +#if SWIFT_ENABLE_REFLECTION +public typealias _CustomReflectableOrNone = CustomReflectable +#else +public typealias _CustomReflectableOrNone = Any +#endif + /// A stdlib-internal protocol modeled by the intrinsic pointer types, /// UnsafeMutablePointer, UnsafePointer, UnsafeRawPointer, /// UnsafeMutableRawPointer, and AutoreleasingUnsafeMutablePointer. public protocol _Pointer -: Hashable, Strideable, CustomDebugStringConvertible, CustomReflectable { +: Hashable, Strideable, CustomDebugStringConvertible, _CustomReflectableOrNone { /// A type that represents the distance between two pointers. typealias Distance = Int @@ -220,6 +226,7 @@ extension _Pointer /*: CustomDebugStringConvertible */ { } } +#if SWIFT_ENABLE_REFLECTION extension _Pointer /*: CustomReflectable */ { public var customMirror: Mirror { let ptrValue = UInt64( @@ -227,6 +234,7 @@ extension _Pointer /*: CustomReflectable */ { return Mirror(self, children: ["pointerValue": ptrValue]) } } +#endif extension Int { /// Creates a new value with the bit pattern of the given pointer. diff --git a/stdlib/public/core/Prespecialize.swift b/stdlib/public/core/Prespecialize.swift index b4dd39d553a68..f8e2f735f1390 100644 --- a/stdlib/public/core/Prespecialize.swift +++ b/stdlib/public/core/Prespecialize.swift @@ -83,7 +83,9 @@ internal func _prespecialize() { consume(Optional.self) consume(Optional.self) consume(Optional.self) +#if SWIFT_ENABLE_REFLECTION consume(Optional.self) +#endif consume(Optional.self) consume(Optional>.self) consume(Optional>.self) @@ -93,7 +95,9 @@ internal func _prespecialize() { consume(Optional.self) consume(Optional.self) consume(Optional.self) +#if SWIFT_ENABLE_REFLECTION consume(Optional.self) +#endif consume(Optional>.self) consume(Optional>.self) consume(Optional>.self) diff --git a/stdlib/public/core/Range.swift b/stdlib/public/core/Range.swift index fde006d0037b1..2c09a510c2779 100644 --- a/stdlib/public/core/Range.swift +++ b/stdlib/public/core/Range.swift @@ -388,12 +388,14 @@ extension Range: CustomDebugStringConvertible { } } +#if SWIFT_ENABLE_REFLECTION extension Range: CustomReflectable { public var customMirror: Mirror { return Mirror( self, children: ["lowerBound": lowerBound, "upperBound": upperBound]) } } +#endif extension Range: Equatable { /// Returns a Boolean value indicating whether two ranges are equal. diff --git a/stdlib/public/core/ReflectionMirror.swift b/stdlib/public/core/ReflectionMirror.swift index 2f68b9078aa21..91cf84b1f8170 100644 --- a/stdlib/public/core/ReflectionMirror.swift +++ b/stdlib/public/core/ReflectionMirror.swift @@ -10,6 +10,8 @@ // //===----------------------------------------------------------------------===// +#if SWIFT_ENABLE_REFLECTION + import SwiftShims @_silgen_name("swift_isClassType") @@ -365,3 +367,5 @@ public func _forEachFieldWithKeyPath( return true } + +#endif diff --git a/stdlib/public/core/Set.swift b/stdlib/public/core/Set.swift index 91a67b3d15f2e..f4fb463fe24db 100644 --- a/stdlib/public/core/Set.swift +++ b/stdlib/public/core/Set.swift @@ -1572,6 +1572,7 @@ extension Set.Iterator: IteratorProtocol { } } +#if SWIFT_ENABLE_REFLECTION extension Set.Iterator: CustomReflectable { /// A mirror that reflects the iterator. public var customMirror: Mirror { @@ -1588,6 +1589,7 @@ extension Set: CustomReflectable { return Mirror(self, unlabeledChildren: self, displayStyle: style) } } +#endif extension Set { /// Removes and returns the first element of the set. diff --git a/stdlib/public/core/StaticString.swift b/stdlib/public/core/StaticString.swift index 086c6b3c86085..ac114c755a26f 100644 --- a/stdlib/public/core/StaticString.swift +++ b/stdlib/public/core/StaticString.swift @@ -308,9 +308,11 @@ extension StaticString: CustomDebugStringConvertible { } } +#if SWIFT_ENABLE_REFLECTION extension StaticString: CustomReflectable { public var customMirror: Mirror { return Mirror(reflecting: description) } } +#endif diff --git a/stdlib/public/core/Stride.swift b/stdlib/public/core/Stride.swift index e9a43bbb4fb3f..d17fbf4239dfc 100644 --- a/stdlib/public/core/Stride.swift +++ b/stdlib/public/core/Stride.swift @@ -386,11 +386,13 @@ extension StrideTo: Sequence { } } +#if SWIFT_ENABLE_REFLECTION extension StrideTo: CustomReflectable { public var customMirror: Mirror { return Mirror(self, children: ["from": _start, "to": _end, "by": _stride]) } } +#endif // FIXME(conditional-conformances): This does not yet compile (SR-6474). #if false @@ -597,12 +599,14 @@ extension StrideThrough: Sequence { } } +#if SWIFT_ENABLE_REFLECTION extension StrideThrough: CustomReflectable { public var customMirror: Mirror { return Mirror(self, children: ["from": _start, "through": _end, "by": _stride]) } } +#endif // FIXME(conditional-conformances): This does not yet compile (SR-6474). #if false diff --git a/stdlib/public/core/StringUTF16View.swift b/stdlib/public/core/StringUTF16View.swift index 555137789d452..5f19b2823a40a 100644 --- a/stdlib/public/core/StringUTF16View.swift +++ b/stdlib/public/core/StringUTF16View.swift @@ -405,6 +405,7 @@ extension String.UTF16View.Index { } } +#if SWIFT_ENABLE_REFLECTION // Reflection extension String.UTF16View: CustomReflectable { /// Returns a mirror that reflects the UTF-16 view of a string. @@ -412,6 +413,7 @@ extension String.UTF16View: CustomReflectable { return Mirror(self, unlabeledChildren: self) } } +#endif // Slicing extension String.UTF16View { diff --git a/stdlib/public/core/StringUTF8View.swift b/stdlib/public/core/StringUTF8View.swift index b0d8f7c1170ad..3883db5f8491e 100644 --- a/stdlib/public/core/StringUTF8View.swift +++ b/stdlib/public/core/StringUTF8View.swift @@ -346,6 +346,7 @@ extension String.UTF8View.Index { } } +#if SWIFT_ENABLE_REFLECTION // Reflection extension String.UTF8View: CustomReflectable { /// Returns a mirror that reflects the UTF-8 view of a string. @@ -353,6 +354,7 @@ extension String.UTF8View: CustomReflectable { return Mirror(self, unlabeledChildren: self) } } +#endif //===--- Slicing Support --------------------------------------------------===// /// In Swift 3.2, in the absence of type context, diff --git a/stdlib/public/core/StringUnicodeScalarView.swift b/stdlib/public/core/StringUnicodeScalarView.swift index 8a0ae258371fe..6c6a0c8fa3d8c 100644 --- a/stdlib/public/core/StringUnicodeScalarView.swift +++ b/stdlib/public/core/StringUnicodeScalarView.swift @@ -382,6 +382,7 @@ extension String.UnicodeScalarIndex { } } +#if SWIFT_ENABLE_REFLECTION // Reflection extension String.UnicodeScalarView: CustomReflectable { /// Returns a mirror that reflects the Unicode scalars view of a string. @@ -389,7 +390,7 @@ extension String.UnicodeScalarView: CustomReflectable { return Mirror(self, unlabeledChildren: self) } } - +#endif //===--- Slicing Support --------------------------------------------------===// /// In Swift 3.2, in the absence of type context, diff --git a/stdlib/public/core/Substring.swift b/stdlib/public/core/Substring.swift index 1b414b2d9710d..d0ae836ffea88 100644 --- a/stdlib/public/core/Substring.swift +++ b/stdlib/public/core/Substring.swift @@ -307,9 +307,11 @@ extension Substring: StringProtocol { } } +#if SWIFT_ENABLE_REFLECTION extension Substring: CustomReflectable { public var customMirror: Mirror { return String(self).customMirror } } +#endif extension Substring: CustomStringConvertible { @inlinable @inline(__always) diff --git a/stdlib/public/runtime/ReflectionMirror.cpp b/stdlib/public/runtime/ReflectionMirror.cpp index 141da5ff01dec..5158894ffd54a 100644 --- a/stdlib/public/runtime/ReflectionMirror.cpp +++ b/stdlib/public/runtime/ReflectionMirror.cpp @@ -10,6 +10,8 @@ // //===----------------------------------------------------------------------===// +#ifdef SWIFT_ENABLE_REFLECTION + #include "swift/Basic/Lazy.h" #include "swift/Runtime/Reflection.h" #include "swift/Runtime/Casting.h" @@ -1106,3 +1108,5 @@ id swift_reflectionMirror_quickLookObject(OpaqueValue *value, const Metadata *T) return call(value, T, nullptr, [](ReflectionMirrorImpl *impl) { return impl->quickLookObject(); }); } #endif + +#endif // SWIFT_ENABLE_REFLECTION diff --git a/stdlib/public/runtime/ReflectionMirrorObjC.mm b/stdlib/public/runtime/ReflectionMirrorObjC.mm index a9efbe107b35d..52d15d6771d53 100644 --- a/stdlib/public/runtime/ReflectionMirrorObjC.mm +++ b/stdlib/public/runtime/ReflectionMirrorObjC.mm @@ -12,7 +12,7 @@ #include "swift/Runtime/Config.h" -#if SWIFT_OBJC_INTEROP +#if SWIFT_OBJC_INTEROP && defined(SWIFT_ENABLE_REFLECTION) #include "Private.h" #include diff --git a/utils/build-presets.ini b/utils/build-presets.ini index 529f771da99d7..fbe67d4b691a1 100644 --- a/utils/build-presets.ini +++ b/utils/build-presets.ini @@ -2451,6 +2451,7 @@ build-swift-dynamic-stdlib=0 build-swift-static-stdlib=1 swift-objc-interop=0 swift-enable-compatibility-overrides=0 +swift-enable-reflection=1 swift-runtime-macho-no-dyld=1 swift-stdlib-has-darwin-libmalloc=0 swift-stdlib-single-threaded-runtime=1 diff --git a/utils/build-script-impl b/utils/build-script-impl index 70e7375fccccd..8f72fba02e8c0 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -204,6 +204,7 @@ KNOWN_SETTINGS=( stdlib-deployment-targets "" "space-separated list of targets to configure the Swift standard library to be compiled or cross-compiled for" swift-objc-interop "" "whether to enable interoperability with Objective-C, default is 1 on Apple platfors, 0 otherwise" swift-enable-compatibility-overrides "1" "whether to support back-deploying compatibility fixes for newer apps running on older runtimes" + swift-enable-reflection "1" "whether to support reflection and mirrors" swift-runtime-macho-no-dyld "0" "whether to build stdlib assuming the runtime environment does not support dynamic modules" swift-stdlib-single-threaded-runtime "0" "whether to build stdlib as a single-threaded runtime only" swift-stdlib-os-versioning "1" "whether to build stdlib with availability based on OS versions (Darwin only)" @@ -2053,6 +2054,13 @@ for host in "${ALL_HOSTS[@]}"; do ) fi + if [[ "${SWIFT_ENABLE_REFLECTION}" == "0" ]] ; then + cmake_options=( + "${cmake_options[@]}" + -DSWIFT_ENABLE_REFLECTION:BOOL=FALSE + ) + fi + if [[ "${SWIFT_PRIMARY_VARIANT_SDK}" ]] ; then cmake_options=( "${cmake_options[@]}"