Skip to content

Commit 8b46a57

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 e1906b8 commit 8b46a57

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
@@ -592,5 +592,8 @@ ERROR(experimental_not_supported_in_production,none,
592592
ERROR(zlib_not_supported,none,
593593
"this compiler was not built with zlib compression support enabled", ())
594594

595+
ERROR(ast_format_requires_dump_ast,none,
596+
"structured AST formats are only supported when using -dump-ast", ())
597+
595598
#define UNDEFINE_DIAGNOSTIC_MACROS
596599
#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)