Skip to content

Commit 7824dc1

Browse files
committed
[Frontend] Move parse-only module load assert
Move into `performEndOfPipelineActions`, and move the call up a bit in `performCompile` to make sure it gets called even for a parse-only invocation. Unfortunately this requires carving out an exception for `-emit-imported-modules`, which can load modules.
1 parent ff170df commit 7824dc1

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,6 @@ void CompilerInstance::performParseOnly() {
784784
(void)Kind;
785785

786786
performSemaUpTo(SourceFile::Unprocessed);
787-
assert(Context->LoadedModules.size() == 1 &&
788-
"Loaded a module during parse-only");
789787
}
790788

791789
void CompilerInstance::performParseAndResolveImportsOnly() {

lib/FrontendTool/FrontendTool.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,9 +1226,20 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
12261226
/// before or after LLVM depending on when the ASTContext gets freed.
12271227
static void performEndOfPipelineActions(CompilerInstance &Instance) {
12281228
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+
}
12291240

12301241
// Verify the AST for all the modules we've loaded.
1231-
Instance.getASTContext().verifyAllLoadedModules();
1242+
ctx.verifyAllLoadedModules();
12321243

12331244
// Emit dependencies and index data.
12341245
emitReferenceDependenciesForAllPrimaryInputsIfNeeded(Instance);
@@ -1273,6 +1284,13 @@ static bool performCompile(CompilerInstance &Instance,
12731284
return true;
12741285
}
12751286

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+
12761294
if (FrontendOptions::shouldActionOnlyParse(Action)) {
12771295
Instance.performParseOnly();
12781296
} else if (Action == FrontendOptions::ActionType::ResolveImports) {
@@ -1330,13 +1348,6 @@ static bool performCompile(CompilerInstance &Instance,
13301348
emitSwiftRangesForAllPrimaryInputsIfNeeded(Instance);
13311349
emitCompiledSourceForAllPrimaryInputsIfNeeded(Instance);
13321350

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-
13401351
if (Context.hadError())
13411352
return true;
13421353

0 commit comments

Comments
 (0)