From 52b9ffae47f39df35826448ecfabc04c4cccb8c1 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Wed, 13 Jan 2021 08:09:15 -0800 Subject: [PATCH] Stop computing/tracking defines. They are already exposed in the modules, so use them directly from there instead. This also means they union doesn't have to keep being computed going up the build graph, which will save some cycles. RELNOTES: None PiperOrigin-RevId: 351588940 --- swift/internal/compiling.bzl | 24 +++++++++++++++--------- swift/internal/providers.bzl | 32 +------------------------------- 2 files changed, 16 insertions(+), 40 deletions(-) diff --git a/swift/internal/compiling.bzl b/swift/internal/compiling.bzl index eb9f937fb..223b37d68 100644 --- a/swift/internal/compiling.bzl +++ b/swift/internal/compiling.bzl @@ -17,6 +17,7 @@ load("@bazel_skylib//lib:collections.bzl", "collections") load("@bazel_skylib//lib:partial.bzl", "partial") load("@bazel_skylib//lib:paths.bzl", "paths") +load("@bazel_skylib//lib:sets.bzl", "sets") load("@bazel_skylib//lib:types.bzl", "types") load( ":actions.bzl", @@ -1016,7 +1017,6 @@ def _conditional_compilation_flag_configurator(prerequisites, args): all_defines = depset( prerequisites.defines, transitive = [ - prerequisites.transitive_defines, # Take any Swift-compatible defines from Objective-C dependencies # and define them for Swift. prerequisites.cc_info.compilation_context.defines, @@ -1212,15 +1212,22 @@ def compile( merged_providers.swift_info.transitive_modules.to_list() ) + transitive_swiftmodules = [] + defines_set = sets.make(defines) + for module in transitive_modules: + swift_module = module.swift + if not swift_module: + continue + transitive_swiftmodules.append(swift_module.swiftmodule) + if swift_module.defines: + defines_set = sets.union( + defines_set, + sets.make(swift_module.defines), + ) + # We need this when generating the VFS overlay file and also when # configuring inputs for the compile action, so it's best to precompute it # here. - transitive_swiftmodules = [ - module.swift.swiftmodule - for module in transitive_modules - if module.swift - ] - if is_feature_enabled( feature_configuration = feature_configuration, feature_name = SWIFT_FEATURE_VFSOVERLAY, @@ -1242,7 +1249,7 @@ def compile( additional_inputs = additional_inputs, bin_dir = bin_dir, cc_info = merged_providers.cc_info, - defines = defines, + defines = sets.to_list(defines_set), genfiles_dir = genfiles_dir, is_swift = True, module_name = module_name, @@ -1251,7 +1258,6 @@ def compile( ), objc_info = merged_providers.objc_info, source_files = srcs, - transitive_defines = merged_providers.swift_info.transitive_defines, transitive_modules = transitive_modules, transitive_swiftmodules = transitive_swiftmodules, user_compile_flags = copts + swift_toolchain.command_line_copts, diff --git a/swift/internal/providers.bzl b/swift/internal/providers.bzl index 4cb7095f3..07c5b310e 100644 --- a/swift/internal/providers.bzl +++ b/swift/internal/providers.bzl @@ -14,8 +14,6 @@ """Defines Starlark providers that propagated by the Swift BUILD rules.""" -load("@bazel_skylib//lib:sets.bzl", "sets") - SwiftInfo = provider( doc = """\ Contains information about the compiled artifacts of a Swift module. @@ -26,10 +24,6 @@ directly, consider using the `swift_common.create_swift_info` function, which has reasonable defaults for any fields not explicitly set. """, fields = { - "direct_defines": """\ -`List` of `string`s. The values specified by the `defines` attribute of the -library that directly propagated this provider. -""", "direct_modules": """\ `List` of values returned from `swift_common.create_module`. The modules (both Swift and C/Objective-C) emitted by the library that propagated this provider. @@ -41,10 +35,6 @@ flag. This will be `None` if the flag was not set. This field is deprecated; the Swift version should be obtained by inspecting the arguments passed to specific compilation actions. -""", - "transitive_defines": """\ -`Depset` of `string`s. The transitive `defines` specified for the library that -propagated this provider and all of its dependencies. """, "transitive_modules": """\ `Depset` of values returned from `swift_common.create_module`. The transitive @@ -316,30 +306,10 @@ def create_swift_info( A new `SwiftInfo` provider with the given values. """ - defines_set = sets.make() - for module in modules: - swift_module = module.swift - if not swift_module: - continue - - if swift_module.defines: - defines_set = sets.union( - defines_set, - sets.make(swift_module.defines), - ) - - defines = sets.to_list(defines_set) - - transitive_defines = [] - transitive_modules = [] - for swift_info in swift_infos: - transitive_defines.append(swift_info.transitive_defines) - transitive_modules.append(swift_info.transitive_modules) + transitive_modules = [x.transitive_modules for x in swift_infos] return SwiftInfo( - direct_defines = defines, direct_modules = modules, swift_version = swift_version, - transitive_defines = depset(defines, transitive = transitive_defines), transitive_modules = depset(modules, transitive = transitive_modules), )