Skip to content

Commit 9eee21a

Browse files
allevatoluispadron
authored andcommitted
Also detect -O flags being set via --swiftcopt when planning parallel compilation.
In the future, we should consider whether we should more strictly control where these flags can be applied, since they don't just control optimizations but also how the driver plans its work. Cherry-pick: ab55a12
1 parent 6a4c74f commit 9eee21a

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

swift/internal/compiling.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ load(
6464
"SWIFT_FEATURE_USE_EXPLICIT_SWIFT_MODULE_MAP",
6565
"SWIFT_FEATURE_VFSOVERLAY",
6666
"SWIFT_FEATURE__NUM_THREADS_0_IN_SWIFTCOPTS",
67+
"SWIFT_FEATURE__OPT_IN_SWIFTCOPTS",
6768
"SWIFT_FEATURE__WMO_IN_SWIFTCOPTS",
6869
)
6970
load(
@@ -823,6 +824,9 @@ def _should_plan_parallel_compilation(
823824
) and not is_feature_enabled(
824825
feature_configuration = feature_configuration,
825826
feature_name = SWIFT_FEATURE_OPT,
827+
) and not is_feature_enabled(
828+
feature_configuration = feature_configuration,
829+
feature_name = SWIFT_FEATURE__OPT_IN_SWIFTCOPTS,
826830
)
827831
)
828832

swift/internal/feature_names.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,11 @@ SWIFT_FEATURE_LLD_GC_WORKAROUND = "swift.lld_gc_workaround"
356356
# objects if you know that isn't required.
357357
SWIFT_FEATURE_OBJC_LINK_FLAGS = "swift.objc_link_flag"
358358

359+
# A private feature that is set by the toolchain if an optimization flag in the
360+
# `-O` flag group was passed on the command line using `--swiftcopt`. Users
361+
# should never manually enable, disable, or query this feature.
362+
SWIFT_FEATURE__OPT_IN_SWIFTCOPTS = "swift._opt_in_swiftcopts"
363+
359364
# If enabled, requests the `-enforce-exclusivity=checked` swiftc flag which
360365
# enables runtime checking of exclusive memory access on mutation.
361366
SWIFT_FEATURE_CHECKED_EXCLUSIVITY = "swift.checked_exclusivity"

swift/internal/optimization.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
load(
1818
":feature_names.bzl",
1919
"SWIFT_FEATURE__NUM_THREADS_0_IN_SWIFTCOPTS",
20+
"SWIFT_FEATURE__OPT_IN_SWIFTCOPTS",
2021
"SWIFT_FEATURE__WMO_IN_SWIFTCOPTS",
2122
)
2223

@@ -112,6 +113,8 @@ def optimization_features_from_swiftcopts(swiftcopts):
112113
requested_features = []
113114
unsupported_features = []
114115

116+
if is_optimization_manually_requested(user_compile_flags = swiftcopts):
117+
requested_features.append(SWIFT_FEATURE__OPT_IN_SWIFTCOPTS)
115118
if is_wmo_manually_requested(user_compile_flags = swiftcopts):
116119
requested_features.append(SWIFT_FEATURE__WMO_IN_SWIFTCOPTS)
117120
if find_num_threads_flag_value(user_compile_flags = swiftcopts) == 1:

test/parallel_compilation_tests.bzl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ opt_actions_create_test = make_actions_created_test_rule(
2929
},
3030
)
3131

32+
opt_via_swiftcopt_actions_create_test = make_actions_created_test_rule(
33+
config_settings = {
34+
"@build_bazel_rules_swift//swift:copt": ["-O"],
35+
},
36+
)
37+
3238
def parallel_compilation_test_suite(name, tags = []):
3339
"""Test suite for parallel compilation.
3440
@@ -87,6 +93,15 @@ def parallel_compilation_test_suite(name, tags = []):
8793
target_under_test = "@build_bazel_rules_swift//test/fixtures/parallel_compilation:no_opt_with_wmo",
8894
)
8995

96+
# Force `-O` using the `copt` flag on a non-optimized, with-WMO target and
97+
# make sure we don't plan parallel compilation there.
98+
opt_via_swiftcopt_actions_create_test(
99+
name = "{}_no_opt_with_wmo_but_swiftcopt_dash_O".format(name),
100+
mnemonics = ["-SwiftCompileModule", "-SwiftCompileCodegen", "SwiftCompile"],
101+
tags = all_tags,
102+
target_under_test = "@build_bazel_rules_swift//test/fixtures/parallel_compilation:no_opt_with_wmo",
103+
)
104+
90105
# Optimized, with-WMO can be compiled in parallel if library evolution is
91106
# enabled (which implicitly disables CMO).
92107
actions_created_test(

0 commit comments

Comments
 (0)