diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index 920990158cdc3..6f2ac630d2f15 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -1702,7 +1702,7 @@ bool IRGenModule::shouldPrespecializeGenericMetadata() { (Triple.isOSDarwin() || (Triple.isOSLinux() && !(Triple.isARM() && Triple.isArch32Bit()))); if (canPrespecializeTarget && isStandardLibrary()) { - return true; + return IRGen.Opts.PrespecializeGenericMetadata; } auto &context = getSwiftModule()->getASTContext(); auto deploymentAvailability = diff --git a/stdlib/CMakeLists.txt b/stdlib/CMakeLists.txt index 409d06ed7afa8..12c7ec15264f3 100644 --- a/stdlib/CMakeLists.txt +++ b/stdlib/CMakeLists.txt @@ -44,6 +44,14 @@ else() set(SWIFT_BUILD_TEST_SUPPORT_MODULES_default FALSE) endif() +if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)") + set(SWIFT_STDLIB_ENABLE_PRESPECIALIZATION_default TRUE) +elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "LINUX") + set(SWIFT_STDLIB_ENABLE_PRESPECIALIZATION_default TRUE) +else() + set(SWIFT_STDLIB_ENABLE_PRESPECIALIZATION_default FALSE) +endif() + # # User-configurable options for the standard library. # @@ -82,6 +90,10 @@ option(SWIFT_BUILD_TEST_SUPPORT_MODULES option(SWIFT_FREESTANDING_FLAVOR "When building the FREESTANDING stdlib, which build style to use (options: apple, linux)") +option(SWIFT_STDLIB_ENABLE_PRESPECIALIZATION + "Should stdlib be built with generic metadata prespecialization enabled. Defaults to On on Darwin and on " + "${SWIFT_STDLIB_ENABLE_PRESPECIALIZATION_default}") + 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.") diff --git a/stdlib/cmake/modules/AddSwiftStdlib.cmake b/stdlib/cmake/modules/AddSwiftStdlib.cmake index c3517d0b8cb2a..14207f95e9195 100644 --- a/stdlib/cmake/modules/AddSwiftStdlib.cmake +++ b/stdlib/cmake/modules/AddSwiftStdlib.cmake @@ -1673,6 +1673,10 @@ function(add_swift_target_library name) "-Xfrontend;-disable-implicit-distributed-module-import") endif() + if(SWIFTLIB_IS_STDLIB AND SWIFT_STDLIB_ENABLE_PRESPECIALIZATION) + list(APPEND SWIFTLIB_SWIFT_COMPILE_FLAGS "-Xfrontend;-prespecialize-generic-metadata") + endif() + # If we are building this library for targets, loop through the various # SDKs building the variants of this library. list_intersect( diff --git a/utils/build-presets.ini b/utils/build-presets.ini index e6be532cedb41..c6990572c0b9d 100644 --- a/utils/build-presets.ini +++ b/utils/build-presets.ini @@ -2433,7 +2433,10 @@ swift-enable-compatibility-overrides=0 swift-runtime-macho-no-dyld=1 swift-stdlib-single-threaded-runtime=1 swift-stdlib-os-versioning=0 -extra-cmake-options=-DSWIFT_ENABLE_DISPATCH:BOOL=FALSE -DSWIFT_IMPLICIT_CONCURRENCY_IMPORT:BOOL=FALSE +extra-cmake-options= + -DSWIFT_ENABLE_DISPATCH:BOOL=FALSE + -DSWIFT_IMPLICIT_CONCURRENCY_IMPORT:BOOL=FALSE + -DSWIFT_STDLIB_ENABLE_PRESPECIALIZATION:BOOL=FALSE [preset: stdlib_S_standalone_minimal_macho_x86_64,build] mixin-preset=