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

Commit 52b9ffa

Browse files
thomasvlswiple-rules-gardener
authored andcommitted
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
1 parent 5383052 commit 52b9ffa

File tree

2 files changed

+16
-40
lines changed

2 files changed

+16
-40
lines changed

swift/internal/compiling.bzl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
load("@bazel_skylib//lib:collections.bzl", "collections")
1818
load("@bazel_skylib//lib:partial.bzl", "partial")
1919
load("@bazel_skylib//lib:paths.bzl", "paths")
20+
load("@bazel_skylib//lib:sets.bzl", "sets")
2021
load("@bazel_skylib//lib:types.bzl", "types")
2122
load(
2223
":actions.bzl",
@@ -1016,7 +1017,6 @@ def _conditional_compilation_flag_configurator(prerequisites, args):
10161017
all_defines = depset(
10171018
prerequisites.defines,
10181019
transitive = [
1019-
prerequisites.transitive_defines,
10201020
# Take any Swift-compatible defines from Objective-C dependencies
10211021
# and define them for Swift.
10221022
prerequisites.cc_info.compilation_context.defines,
@@ -1212,15 +1212,22 @@ def compile(
12121212
merged_providers.swift_info.transitive_modules.to_list()
12131213
)
12141214

1215+
transitive_swiftmodules = []
1216+
defines_set = sets.make(defines)
1217+
for module in transitive_modules:
1218+
swift_module = module.swift
1219+
if not swift_module:
1220+
continue
1221+
transitive_swiftmodules.append(swift_module.swiftmodule)
1222+
if swift_module.defines:
1223+
defines_set = sets.union(
1224+
defines_set,
1225+
sets.make(swift_module.defines),
1226+
)
1227+
12151228
# We need this when generating the VFS overlay file and also when
12161229
# configuring inputs for the compile action, so it's best to precompute it
12171230
# here.
1218-
transitive_swiftmodules = [
1219-
module.swift.swiftmodule
1220-
for module in transitive_modules
1221-
if module.swift
1222-
]
1223-
12241231
if is_feature_enabled(
12251232
feature_configuration = feature_configuration,
12261233
feature_name = SWIFT_FEATURE_VFSOVERLAY,
@@ -1242,7 +1249,7 @@ def compile(
12421249
additional_inputs = additional_inputs,
12431250
bin_dir = bin_dir,
12441251
cc_info = merged_providers.cc_info,
1245-
defines = defines,
1252+
defines = sets.to_list(defines_set),
12461253
genfiles_dir = genfiles_dir,
12471254
is_swift = True,
12481255
module_name = module_name,
@@ -1251,7 +1258,6 @@ def compile(
12511258
),
12521259
objc_info = merged_providers.objc_info,
12531260
source_files = srcs,
1254-
transitive_defines = merged_providers.swift_info.transitive_defines,
12551261
transitive_modules = transitive_modules,
12561262
transitive_swiftmodules = transitive_swiftmodules,
12571263
user_compile_flags = copts + swift_toolchain.command_line_copts,

swift/internal/providers.bzl

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
"""Defines Starlark providers that propagated by the Swift BUILD rules."""
1616

17-
load("@bazel_skylib//lib:sets.bzl", "sets")
18-
1917
SwiftInfo = provider(
2018
doc = """\
2119
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
2624
has reasonable defaults for any fields not explicitly set.
2725
""",
2826
fields = {
29-
"direct_defines": """\
30-
`List` of `string`s. The values specified by the `defines` attribute of the
31-
library that directly propagated this provider.
32-
""",
3327
"direct_modules": """\
3428
`List` of values returned from `swift_common.create_module`. The modules (both
3529
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.
4135
4236
This field is deprecated; the Swift version should be obtained by inspecting the
4337
arguments passed to specific compilation actions.
44-
""",
45-
"transitive_defines": """\
46-
`Depset` of `string`s. The transitive `defines` specified for the library that
47-
propagated this provider and all of its dependencies.
4838
""",
4939
"transitive_modules": """\
5040
`Depset` of values returned from `swift_common.create_module`. The transitive
@@ -316,30 +306,10 @@ def create_swift_info(
316306
A new `SwiftInfo` provider with the given values.
317307
"""
318308

319-
defines_set = sets.make()
320-
for module in modules:
321-
swift_module = module.swift
322-
if not swift_module:
323-
continue
324-
325-
if swift_module.defines:
326-
defines_set = sets.union(
327-
defines_set,
328-
sets.make(swift_module.defines),
329-
)
330-
331-
defines = sets.to_list(defines_set)
332-
333-
transitive_defines = []
334-
transitive_modules = []
335-
for swift_info in swift_infos:
336-
transitive_defines.append(swift_info.transitive_defines)
337-
transitive_modules.append(swift_info.transitive_modules)
309+
transitive_modules = [x.transitive_modules for x in swift_infos]
338310

339311
return SwiftInfo(
340-
direct_defines = defines,
341312
direct_modules = modules,
342313
swift_version = swift_version,
343-
transitive_defines = depset(defines, transitive = transitive_defines),
344314
transitive_modules = depset(modules, transitive = transitive_modules),
345315
)

0 commit comments

Comments
 (0)