Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Stop computing/tracking defines.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thomasvl authored and swiple-rules-gardener committed Jan 13, 2021
1 parent 5383052 commit 52b9ffa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 40 deletions.
24 changes: 15 additions & 9 deletions swift/internal/compiling.bzl
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
32 changes: 1 addition & 31 deletions swift/internal/providers.bzl
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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),
)

0 comments on commit 52b9ffa

Please sign in to comment.