@@ -1226,9 +1226,20 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
1226
1226
// / before or after LLVM depending on when the ASTContext gets freed.
1227
1227
static void performEndOfPipelineActions (CompilerInstance &Instance) {
1228
1228
assert (Instance.hasASTContext ());
1229
+ auto &ctx = Instance.getASTContext ();
1230
+
1231
+ // Make sure we didn't load a module during a parse-only invocation, unless
1232
+ // it's -emit-imported-modules, which can load modules.
1233
+ auto action = Instance.getInvocation ().getFrontendOptions ().RequestedAction ;
1234
+ if (FrontendOptions::shouldActionOnlyParse (action) &&
1235
+ action != FrontendOptions::ActionType::EmitImportedModules) {
1236
+ assert (ctx.LoadedModules .size () == 1 &&
1237
+ " Loaded a module during parse-only" );
1238
+ assert (ctx.LoadedModules .front ().second == Instance.getMainModule ());
1239
+ }
1229
1240
1230
1241
// Verify the AST for all the modules we've loaded.
1231
- Instance. getASTContext () .verifyAllLoadedModules ();
1242
+ ctx .verifyAllLoadedModules ();
1232
1243
1233
1244
// Emit dependencies and index data.
1234
1245
emitReferenceDependenciesForAllPrimaryInputsIfNeeded (Instance);
@@ -1273,6 +1284,13 @@ static bool performCompile(CompilerInstance &Instance,
1273
1284
return true ;
1274
1285
}
1275
1286
1287
+ SWIFT_DEFER {
1288
+ // We might have freed the ASTContext already, but in that case we would
1289
+ // have already performed these actions.
1290
+ if (Instance.hasASTContext ())
1291
+ performEndOfPipelineActions (Instance);
1292
+ };
1293
+
1276
1294
if (FrontendOptions::shouldActionOnlyParse (Action)) {
1277
1295
Instance.performParseOnly ();
1278
1296
} else if (Action == FrontendOptions::ActionType::ResolveImports) {
@@ -1330,13 +1348,6 @@ static bool performCompile(CompilerInstance &Instance,
1330
1348
emitSwiftRangesForAllPrimaryInputsIfNeeded (Instance);
1331
1349
emitCompiledSourceForAllPrimaryInputsIfNeeded (Instance);
1332
1350
1333
- SWIFT_DEFER {
1334
- // We might have freed the ASTContext already, but in that case we would
1335
- // have already performed these actions.
1336
- if (Instance.hasASTContext ())
1337
- performEndOfPipelineActions (Instance);
1338
- };
1339
-
1340
1351
if (Context.hadError ())
1341
1352
return true ;
1342
1353
0 commit comments