Skip to content

Commit aebfb53

Browse files
vinivendraCodaFi
authored andcommitted
Ast dump ignore wmo (#20596)
* Ignore -wmo when passing -dump-ast * Cleanup on driver diagnostics * Remove the FIXME. * Add support for ignoring `-index-file` * Revert unrelated formatting changes * Revert back to only ignoring `-wmo` Ignoring both `-wmo` and `-index-file` will be harder than just `-wmo`. This is because when calling the compiler and passing `-index-file` after `-dump-ast`, the option gets un-ignored by `Driver::buildOutputInfo`. Therefore, we will just ignore `-wmo` for now. * Add tests, inspired by `Driver/batch_mode_with_WMO_or_index.swift`
1 parent 2630be1 commit aebfb53

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

include/swift/AST/DiagnosticsDriver.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ WARNING(warn_opt_remark_disabled, none,
166166
WARNING(warn_ignoring_batch_mode,none,
167167
"ignoring '-enable-batch-mode' because '%0' was also specified", (StringRef))
168168

169+
WARNING(warn_ignoring_wmo, none,
170+
"ignoring '-wmo' because '-dump-ast' was also specified", ())
171+
169172
WARNING(warn_ignoring_source_range_dependencies,none,
170173
"ignoring '-enable-source-range-dependencies' because '%0' was also specified", (StringRef))
171174

lib/Driver/Driver.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,17 @@ Driver::computeCompilerMode(const DerivedArgList &Args,
17641764
const Arg *ArgRequiringSinglePrimaryCompile =
17651765
Args.getLastArg(options::OPT_enable_source_range_dependencies);
17661766

1767+
// AST dump doesn't work with `-wmo`. Since it's not common to want to dump
1768+
// the AST, we assume that's the priority and ignore `-wmo`, but we warn the
1769+
// user about this decision.
1770+
// FIXME: AST dump also doesn't work with `-index-file`, but that fix is a bit
1771+
// more complicated than this.
1772+
if (Args.hasArg(options::OPT_whole_module_optimization) &&
1773+
Args.hasArg(options::OPT_dump_ast)) {
1774+
Diags.diagnose(SourceLoc(), diag::warn_ignoring_wmo);
1775+
return OutputInfo::Mode::StandardCompile;
1776+
}
1777+
17671778
// Override batch mode if given -wmo or -index-file.
17681779
if (ArgRequiringSingleCompile) {
17691780
if (BatchModeOut) {

lib/FrontendTool/FrontendTool.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -894,10 +894,6 @@ static SourceFile *getPrimaryOrMainSourceFile(CompilerInvocation &Invocation,
894894
/// files were specified, use them; otherwise, dump the AST to stdout.
895895
static void dumpAST(CompilerInvocation &Invocation,
896896
CompilerInstance &Instance) {
897-
// FIXME: WMO doesn't use the notion of primary files, so this doesn't do the
898-
// right thing. Perhaps it'd be best to ignore WMO when dumping the AST, just
899-
// like WMO ignores `-incremental`.
900-
901897
auto primaryFiles = Instance.getPrimarySourceFiles();
902898
if (!primaryFiles.empty()) {
903899
for (SourceFile *sourceFile: primaryFiles) {

test/Driver/ast_dump_with_WMO.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: %empty-directory(%t)
2+
3+
4+
// Check that -wmo is ignored when -dump-ast is present and that the AST gets
5+
// dumped to stdout, no matter the order of the options
6+
7+
// RUN: %swiftc_driver -whole-module-optimization -dump-ast -module-name=main %S/../Inputs/empty.swift -### 2>%t/stderr_WMO_dump | %FileCheck -check-prefix CHECK-STDOUT %s
8+
// RUN: %swiftc_driver -dump-ast -whole-module-optimization -module-name=main %S/../Inputs/empty.swift -### 2>%t/stderr_dump_WMO | %FileCheck -check-prefix CHECK-STDOUT %s
9+
// RUN: %FileCheck -check-prefix CHECK-WMO %s <%t/stderr_WMO_dump
10+
// RUN: %FileCheck -check-prefix CHECK-WMO %s <%t/stderr_dump_WMO
11+
12+
13+
// Check that ignoring -wmo doesn't affect the output file paths for the AST
14+
// dumps
15+
16+
// RUN: cd %t
17+
// RUN: echo ' ' > a.swift
18+
// RUN: echo ' ' > main.swift
19+
// RUN: echo '{ "a.swift": { "ast-dump": "a.ast" }, "main.swift": { "ast-dump": "main.ast" }}' > outputFileMap.json
20+
21+
// RUN: %swiftc_driver -whole-module-optimization -dump-ast -module-name=main -output-file-map=outputFileMap.json main.swift a.swift -### 2>%t/stderr_WMO_OFM | %FileCheck -check-prefix CHECK-OFM %s
22+
// RUN: %FileCheck -check-prefix CHECK-WMO %s <%t/stderr_WMO_OFM
23+
24+
25+
26+
// CHECK-WMO: warning: ignoring '-wmo' because '-dump-ast' was also specified
27+
28+
// CHECK-STDOUT-NOT: -whole-module-optimization
29+
// CHECK-STDOUT-NOT: -wmo
30+
// CHECK-STDOUT: -dump-ast
31+
// CHECK-STDOUT: -o -
32+
33+
// CHECK-OFM-NOT: -whole-module-optimization
34+
// CHECK-OFM-NOT: -wmo
35+
// CHECK-OFM: -dump-ast
36+
// CHECK-OFM-SAME: -o main.ast
37+
// CHECK-OFM-NEXT: -dump-ast
38+
// CHECK-OFM-SAME: -o a.ast

0 commit comments

Comments
 (0)