@@ -1118,7 +1118,8 @@ static bool printSwiftFeature(CompilerInstance &instance) {
1118
1118
1119
1119
static bool
1120
1120
withSemanticAnalysis (CompilerInstance &Instance, FrontendObserver *observer,
1121
- llvm::function_ref<bool (CompilerInstance &)> cont) {
1121
+ llvm::function_ref<bool (CompilerInstance &)> cont,
1122
+ bool runDespiteErrors = false) {
1122
1123
const auto &Invocation = Instance.getInvocation ();
1123
1124
const auto &opts = Invocation.getFrontendOptions ();
1124
1125
assert (!FrontendOptions::shouldActionOnlyParse (opts.RequestedAction ) &&
@@ -1141,11 +1142,12 @@ withSemanticAnalysis(CompilerInstance &Instance, FrontendObserver *observer,
1141
1142
1142
1143
(void )migrator::updateCodeAndEmitRemapIfNeeded (&Instance);
1143
1144
1144
- if (Instance.getASTContext ().hadError () &&
1145
- !opts.AllowModuleWithCompilerErrors )
1145
+ bool hadError = Instance.getASTContext ().hadError ()
1146
+ && !opts.AllowModuleWithCompilerErrors ;
1147
+ if (hadError && !runDespiteErrors)
1146
1148
return true ;
1147
1149
1148
- return cont (Instance);
1150
+ return cont (Instance) || hadError ;
1149
1151
}
1150
1152
1151
1153
static bool performScanDependencies (CompilerInstance &Instance) {
@@ -1207,14 +1209,11 @@ static bool performAction(CompilerInstance &Instance,
1207
1209
// MARK: Actions that Dump
1208
1210
case FrontendOptions::ActionType::DumpParse:
1209
1211
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 );
1218
1217
case FrontendOptions::ActionType::PrintAST:
1219
1218
return withSemanticAnalysis (
1220
1219
Instance, observer, [](CompilerInstance &Instance) {
@@ -1234,14 +1233,14 @@ static bool performAction(CompilerInstance &Instance,
1234
1233
Instance, observer, [](CompilerInstance &Instance) {
1235
1234
return dumpAndPrintScopeMap (Instance,
1236
1235
getPrimaryOrMainSourceFile (Instance));
1237
- });
1236
+ }, /* runDespiteErrors= */ true );
1238
1237
case FrontendOptions::ActionType::DumpTypeRefinementContexts:
1239
1238
return withSemanticAnalysis (
1240
1239
Instance, observer, [](CompilerInstance &Instance) {
1241
1240
getPrimaryOrMainSourceFile (Instance).getTypeRefinementContext ()->dump (
1242
1241
llvm::errs (), Instance.getASTContext ().SourceMgr );
1243
1242
return Instance.getASTContext ().hadError ();
1244
- });
1243
+ }, /* runDespiteErrors= */ true );
1245
1244
case FrontendOptions::ActionType::DumpInterfaceHash:
1246
1245
getPrimaryOrMainSourceFile (Instance).dumpInterfaceHash (llvm::errs ());
1247
1246
return Context.hadError ();
0 commit comments