From fc0aca026de7688b0c1d539cc712202b40af282f Mon Sep 17 00:00:00 2001 From: Brentley Jones Date: Thu, 14 Oct 2021 09:23:35 -0500 Subject: [PATCH] Use newer split module flag with Swift 5.4 Uses the newer `-experimental-skip-non-inlinable-function-bodies-without-types` which was introduced here: https://github.com/apple/swift/pull/34612. This should improve LLDB usage in some cases. When using WMO, it has two downsides in Swift 5.5, both introduced by https://github.com/apple/swift/pull/38939: - The swiftmodules will have swiftdeps info embedded in them, which is only needed for incremental compilation - Interface hashing is enabled, which again is only needed for incremental compilation This is because the swift compiler only expects `-experimental-skip-non-inlinable-function-bodies-without-types` to be used with the new `emit-module-separately` incremental build. --- swift/internal/compiling.bzl | 11 +++++++++++ swift/internal/feature_names.bzl | 7 ++++++- swift/internal/swift_autoconfiguration.bzl | 11 +++++++++++ swift/internal/xcode_swift_toolchain.bzl | 2 ++ test/split_derived_files_tests.bzl | 4 +++- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/swift/internal/compiling.bzl b/swift/internal/compiling.bzl index 115af509f..201a3444a 100644 --- a/swift/internal/compiling.bzl +++ b/swift/internal/compiling.bzl @@ -42,6 +42,7 @@ load( "SWIFT_FEATURE_ENABLE_BATCH_MODE", "SWIFT_FEATURE_ENABLE_LIBRARY_EVOLUTION", "SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES", + "SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES_WITHOUT_TYPES", "SWIFT_FEATURE_ENABLE_TESTING", "SWIFT_FEATURE_FASTBUILD", "SWIFT_FEATURE_FULL_DEBUG_INFO", @@ -849,6 +850,16 @@ def compile_action_configs( ), ], features = [SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES], + not_features = [SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES_WITHOUT_TYPES], + ), + swift_toolchain_config.action_config( + actions = [swift_action_names.DERIVE_FILES], + configurators = [ + swift_toolchain_config.add_arg( + "-experimental-skip-non-inlinable-function-bodies-without-types", + ), + ], + features = [SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES_WITHOUT_TYPES], ), swift_toolchain_config.action_config( actions = [swift_action_names.COMPILE], diff --git a/swift/internal/feature_names.bzl b/swift/internal/feature_names.bzl index f0f62dfda..f362cc1b7 100644 --- a/swift/internal/feature_names.bzl +++ b/swift/internal/feature_names.bzl @@ -254,9 +254,14 @@ SWIFT_FEATURE_GENERATE_FROM_RAW_PROTO_FILES = "swift.generate_from_raw_proto_fil SWIFT_FEATURE_SPLIT_DERIVED_FILES_GENERATION = "swift.split_derived_files_generation" # If enabled the skip function bodies frontend flag is passed when using derived -# files generation. This requires Swift 5.2 +# files generation. This requires Swift 5.2. SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES = "swift.skip_function_bodies_for_derived_files" +# If enabled the skip function bodies without types frontend flag is passed when +# using derived files generation. This takes precedence over +# swift.skip_function_bodies_for_derived_files. This requires Swift 5.4. +SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES_WITHOUT_TYPES = "swift.skip_function_bodies_without_types_for_derived_files" + # If enabled remap the absolute path to Xcode in debug info. When used with # swift.coverage_prefix_map also remap the path in coverage data. SWIFT_FEATURE_REMAP_XCODE_PATH = "swift.remap_xcode_path" diff --git a/swift/internal/swift_autoconfiguration.bzl b/swift/internal/swift_autoconfiguration.bzl index 8df438d15..6fb63a22d 100644 --- a/swift/internal/swift_autoconfiguration.bzl +++ b/swift/internal/swift_autoconfiguration.bzl @@ -29,6 +29,7 @@ load( "SWIFT_FEATURE_DEBUG_PREFIX_MAP", "SWIFT_FEATURE_ENABLE_BATCH_MODE", "SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES", + "SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES_WITHOUT_TYPES", "SWIFT_FEATURE_MODULE_MAP_NO_PRIVATE_HEADERS", "SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS", "SWIFT_FEATURE_USE_RESPONSE_FILES", @@ -84,6 +85,15 @@ def _check_skip_function_bodies(repository_ctx, swiftc_path, temp_dir): "-experimental-skip-non-inlinable-function-bodies", ) +def _check_skip_function_bodies_without_types(repository_ctx, swiftc_path, temp_dir): + """Returns True if `swiftc` supports skip function bodies.""" + return _swift_succeeds( + repository_ctx, + swiftc_path, + "-version", + "-experimental-skip-non-inlinable-function-bodies-without-types", + ) + def _check_debug_prefix_map(repository_ctx, swiftc_path, temp_dir): """Returns True if `swiftc` supports debug prefix mapping.""" return _swift_succeeds( @@ -197,6 +207,7 @@ _FEATURE_CHECKS = { SWIFT_FEATURE_DEBUG_PREFIX_MAP: _check_debug_prefix_map, SWIFT_FEATURE_ENABLE_BATCH_MODE: _check_enable_batch_mode, SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES: _check_skip_function_bodies, + SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES_WITHOUT_TYPES: _check_skip_function_bodies_without_types, SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS: _check_supports_private_deps, SWIFT_FEATURE_USE_RESPONSE_FILES: _check_use_response_files, } diff --git a/swift/internal/xcode_swift_toolchain.bzl b/swift/internal/xcode_swift_toolchain.bzl index 043d29245..279593801 100644 --- a/swift/internal/xcode_swift_toolchain.bzl +++ b/swift/internal/xcode_swift_toolchain.bzl @@ -36,6 +36,7 @@ load( "SWIFT_FEATURE_DEBUG_PREFIX_MAP", "SWIFT_FEATURE_ENABLE_BATCH_MODE", "SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES", + "SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES_WITHOUT_TYPES", "SWIFT_FEATURE_MODULE_MAP_HOME_IS_CWD", "SWIFT_FEATURE_MODULE_MAP_NO_PRIVATE_HEADERS", "SWIFT_FEATURE_REMAP_XCODE_PATH", @@ -711,6 +712,7 @@ def _xcode_swift_toolchain_impl(ctx): # Xcode 12.5 implies Swift 5.4. if _is_xcode_at_least_version(xcode_config, "12.5"): + requested_features.append(SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES_WITHOUT_TYPES) requested_features.append(SWIFT_FEATURE_SUPPORTS_SYSTEM_MODULE_FLAG) env = _xcode_env(platform = platform, xcode_config = xcode_config) diff --git a/test/split_derived_files_tests.bzl b/test/split_derived_files_tests.bzl index 1bbe6961b..0855ffbf9 100644 --- a/test/split_derived_files_tests.bzl +++ b/test/split_derived_files_tests.bzl @@ -278,6 +278,7 @@ def split_derived_files_test_suite(name = "split_derived_files"): mnemonic = "SwiftCompile", not_expected_argv = [ "-experimental-skip-non-inlinable-function-bodies", + "-experimental-skip-non-inlinable-function-bodies-without-types", ], tags = [name], target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple", @@ -286,11 +287,12 @@ def split_derived_files_test_suite(name = "split_derived_files"): split_swiftmodule_skip_function_bodies_test( name = "{}_skip_function_bodies".format(name), expected_argv = [ - "-experimental-skip-non-inlinable-function-bodies", + "-experimental-skip-non-inlinable-function-bodies-without-types", ], mnemonic = "SwiftDeriveFiles", not_expected_argv = [ "-emit-object", + "-experimental-skip-non-inlinable-function-bodies", ], tags = [name], target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",