Skip to content

Commit 71b0a5f

Browse files
committed
Restrict JSON AST dumps to when -dump-ast is used.
Specifically, this means `-dump-ast-format json` is incompatible with `-dump-parse`. This is because the JSON format is meant to export more details about the AST that require type checking to have been performed. I'm open to lifting this restriction in the future.
1 parent 52c009a commit 71b0a5f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,5 +606,8 @@ GROUPED_WARNING(command_line_conflicts_with_strict_safety,Unsafe,none,
606606
ERROR(zlib_not_supported,none,
607607
"this compiler was not built with zlib compression support enabled", ())
608608

609+
ERROR(ast_format_requires_dump_ast,none,
610+
"structured AST formats are only supported when using -dump-ast", ())
611+
609612
#define UNDEFINE_DIAGNOSTIC_MACROS
610613
#include "DefineDiagnosticMacros.h"

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ bool ArgsToFrontendOptionsConverter::convert(
213213
.Case("json", FrontendOptions::ASTFormat::JSON)
214214
.Case("json-zlib", FrontendOptions::ASTFormat::JSONZlib)
215215
.Default(FrontendOptions::ASTFormat::Default);
216+
if (Opts.DumpASTFormat != FrontendOptions::ASTFormat::Default &&
217+
!Args.hasArg(OPT_dump_ast)) {
218+
Diags.diagnose(SourceLoc(), diag::ast_format_requires_dump_ast);
219+
return true;
220+
}
216221
if (Opts.DumpASTFormat == FrontendOptions::ASTFormat::JSONZlib &&
217222
!llvm::compression::zlib::isAvailable()) {
218223
Diags.diagnose(SourceLoc(), diag::zlib_not_supported);

0 commit comments

Comments
 (0)