Skip to content

Commit e4f0392

Browse files
beccadaxtshortli
authored andcommitted
[NFC] Make Sema -dump flags work when Sema fails
`-dump-scope-maps` and `-dump-type-refinement-contexts` now dump out the content they're designed to emit even when there's an error during semantic analysis that would previously have stopped them from running.
1 parent 2242dbd commit e4f0392

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,8 @@ static bool printSwiftFeature(CompilerInstance &instance) {
11181118

11191119
static bool
11201120
withSemanticAnalysis(CompilerInstance &Instance, FrontendObserver *observer,
1121-
llvm::function_ref<bool(CompilerInstance &)> cont) {
1121+
llvm::function_ref<bool(CompilerInstance &)> cont,
1122+
bool runDespiteErrors = false) {
11221123
const auto &Invocation = Instance.getInvocation();
11231124
const auto &opts = Invocation.getFrontendOptions();
11241125
assert(!FrontendOptions::shouldActionOnlyParse(opts.RequestedAction) &&
@@ -1141,11 +1142,12 @@ withSemanticAnalysis(CompilerInstance &Instance, FrontendObserver *observer,
11411142

11421143
(void)migrator::updateCodeAndEmitRemapIfNeeded(&Instance);
11431144

1144-
if (Instance.getASTContext().hadError() &&
1145-
!opts.AllowModuleWithCompilerErrors)
1145+
bool hadError = Instance.getASTContext().hadError()
1146+
&& !opts.AllowModuleWithCompilerErrors;
1147+
if (hadError && !runDespiteErrors)
11461148
return true;
11471149

1148-
return cont(Instance);
1150+
return cont(Instance) || hadError;
11491151
}
11501152

11511153
static bool performScanDependencies(CompilerInstance &Instance) {
@@ -1207,14 +1209,11 @@ static bool performAction(CompilerInstance &Instance,
12071209
// MARK: Actions that Dump
12081210
case FrontendOptions::ActionType::DumpParse:
12091211
return dumpAST(Instance);
1210-
case FrontendOptions::ActionType::DumpAST: {
1211-
// FIXME: -dump-ast expects to be able to write output even if type checking
1212-
// fails which does not cleanly fit the model \c withSemanticAnalysis is
1213-
// trying to impose. Once there is a request for the "semantic AST", this
1214-
// point is moot.
1215-
Instance.performSema();
1216-
return dumpAST(Instance);
1217-
}
1212+
case FrontendOptions::ActionType::DumpAST:
1213+
return withSemanticAnalysis(
1214+
Instance, observer, [](CompilerInstance &Instance) {
1215+
return dumpAST(Instance);
1216+
}, /*runDespiteErrors=*/true);
12181217
case FrontendOptions::ActionType::PrintAST:
12191218
return withSemanticAnalysis(
12201219
Instance, observer, [](CompilerInstance &Instance) {
@@ -1234,14 +1233,14 @@ static bool performAction(CompilerInstance &Instance,
12341233
Instance, observer, [](CompilerInstance &Instance) {
12351234
return dumpAndPrintScopeMap(Instance,
12361235
getPrimaryOrMainSourceFile(Instance));
1237-
});
1236+
}, /*runDespiteErrors=*/true);
12381237
case FrontendOptions::ActionType::DumpTypeRefinementContexts:
12391238
return withSemanticAnalysis(
12401239
Instance, observer, [](CompilerInstance &Instance) {
12411240
getPrimaryOrMainSourceFile(Instance).getTypeRefinementContext()->dump(
12421241
llvm::errs(), Instance.getASTContext().SourceMgr);
12431242
return Instance.getASTContext().hadError();
1244-
});
1243+
}, /*runDespiteErrors=*/true);
12451244
case FrontendOptions::ActionType::DumpInterfaceHash:
12461245
getPrimaryOrMainSourceFile(Instance).dumpInterfaceHash(llvm::errs());
12471246
return Context.hadError();

0 commit comments

Comments
 (0)