@@ -1315,11 +1315,20 @@ static bool performCompile(CompilerInstance &Instance,
1315
1315
return true ;
1316
1316
}
1317
1317
1318
+ bool didFinishPipeline = false ;
1318
1319
SWIFT_DEFER {
1320
+ assert (didFinishPipeline && " Returned without calling finishPipeline" );
1321
+ };
1322
+
1323
+ auto finishPipeline = [&](bool hadError) -> bool {
1319
1324
// We might have freed the ASTContext already, but in that case we would
1320
1325
// have already performed these actions.
1321
- if (Instance.hasASTContext ())
1326
+ if (Instance.hasASTContext ()) {
1322
1327
performEndOfPipelineActions (Instance);
1328
+ hadError |= Instance.getASTContext ().hadError ();
1329
+ }
1330
+ didFinishPipeline = true ;
1331
+ return hadError;
1323
1332
};
1324
1333
1325
1334
auto &Context = Instance.getASTContext ();
@@ -1334,7 +1343,7 @@ static bool performCompile(CompilerInstance &Instance,
1334
1343
(void )kind;
1335
1344
} else if (Action == FrontendOptions::ActionType::ResolveImports) {
1336
1345
Instance.performParseAndResolveImportsOnly ();
1337
- return Context.hadError ();
1346
+ return finishPipeline ( Context.hadError () );
1338
1347
} else {
1339
1348
Instance.performSema ();
1340
1349
}
@@ -1346,11 +1355,11 @@ static bool performCompile(CompilerInstance &Instance,
1346
1355
if (auto *SF = dyn_cast<SourceFile>(file))
1347
1356
(void )SF->getTopLevelDecls ();
1348
1357
}
1349
- return Context.hadError ();
1358
+ return finishPipeline ( Context.hadError () );
1350
1359
}
1351
1360
1352
1361
if (Action == FrontendOptions::ActionType::ScanDependencies)
1353
- return scanDependencies (Instance);
1362
+ return finishPipeline ( scanDependencies (Instance) );
1354
1363
1355
1364
if (observer)
1356
1365
observer->performedSemanticAnalysis (Instance);
@@ -1371,19 +1380,20 @@ static bool performCompile(CompilerInstance &Instance,
1371
1380
}
1372
1381
1373
1382
if (auto r = dumpASTIfNeeded (Instance))
1374
- return *r ;
1383
+ return finishPipeline (*r) ;
1375
1384
1376
1385
if (Context.hadError ())
1377
- return true ;
1386
+ return finishPipeline ( /* hadError */ true ) ;
1378
1387
1379
1388
// We've just been told to perform a typecheck, so we can return now.
1380
1389
if (Action == FrontendOptions::ActionType::Typecheck)
1381
- return false ;
1390
+ return finishPipeline ( /* hadError */ false ) ;
1382
1391
1383
1392
assert (FrontendOptions::doesActionGenerateSIL (Action) &&
1384
1393
" All actions not requiring SILGen must have been handled!" );
1385
1394
1386
- return performCompileStepsPostSema (Instance, ReturnValue, observer);
1395
+ return finishPipeline (
1396
+ performCompileStepsPostSema (Instance, ReturnValue, observer));
1387
1397
}
1388
1398
1389
1399
static bool serializeSIB (SILModule *SM, const PrimarySpecificPaths &PSPs,
0 commit comments