Skip to content

When building stdlib, pass -prespecialize-generic-metadata from CMake, and respect the flag in IRGenModule::shouldPrespecializeGenericMetadata #38946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/IRGen/IRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
12 changes: 12 additions & 0 deletions stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down Expand Up @@ -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.")
Expand Down
4 changes: 4 additions & 0 deletions stdlib/cmake/modules/AddSwiftStdlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion utils/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down