@@ -1653,6 +1653,7 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
16531653 // it's -emit-imported-modules, which can load modules.
16541654 auto action = opts.RequestedAction ;
16551655 if (FrontendOptions::shouldActionOnlyParse (action) &&
1656+ !ctx.getLoadedModules ().empty () &&
16561657 action != FrontendOptions::ActionType::EmitImportedModules) {
16571658 assert (ctx.getNumLoadedModules () == 1 &&
16581659 " Loaded a module during parse-only" );
@@ -1689,9 +1690,15 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
16891690 }
16901691 }
16911692
1692- // Emit dependencies and index data.
1693+ // FIXME: This predicate matches the status quo, but there's no reason
1694+ // indexing cannot run for actions that do not require stdlib e.g. to better
1695+ // facilitate tests.
1696+ if (FrontendOptions::doesActionRequireSwiftStandardLibrary (action)) {
1697+ emitIndexData (Instance);
1698+ }
1699+
1700+ // Emit dependencies.
16931701 emitReferenceDependenciesForAllPrimaryInputsIfNeeded (Instance);
1694- emitIndexData (Instance);
16951702 emitMakeDependenciesIfNeeded (Instance.getDiags (),
16961703 Instance.getDependencyTracker (), opts);
16971704
@@ -1791,13 +1798,16 @@ static bool performAction(CompilerInstance &Instance,
17911798 return buildModuleFromInterface (Instance);
17921799
17931800 // MARK: Actions that Dump
1794- case FrontendOptions::ActionType::DumpParse: {
1801+ case FrontendOptions::ActionType::DumpParse:
1802+ return dumpAST (Instance);
1803+ case FrontendOptions::ActionType::DumpAST: {
1804+ // FIXME: -dump-ast expects to be able to write output even if type checking
1805+ // fails which does not cleanly fit the model \c withSemanticAnalysis is
1806+ // trying to impose. Once there is a request for the "semantic AST", this
1807+ // point is moot.
1808+ Instance.performSema ();
17951809 return dumpAST (Instance);
17961810 }
1797- case FrontendOptions::ActionType::DumpAST:
1798- return withSemanticAnalysis (
1799- Instance, observer,
1800- [](CompilerInstance &Instance) { return dumpAST (Instance); });
18011811 case FrontendOptions::ActionType::PrintAST:
18021812 return withSemanticAnalysis (
18031813 Instance, observer, [](CompilerInstance &Instance) {
@@ -1860,9 +1870,6 @@ static bool performAction(CompilerInstance &Instance,
18601870 Instance, observer, [&](CompilerInstance &Instance) {
18611871 assert (FrontendOptions::doesActionGenerateSIL (opts.RequestedAction ) &&
18621872 " All actions not requiring SILGen must have been handled!" );
1863- if (Instance.getInvocation ().getInputKind () == InputFileKind::LLVM)
1864- return compileLLVMIR (Instance);
1865-
18661873 return performCompileStepsPostSema (Instance, ReturnValue, observer);
18671874 });
18681875 }
@@ -1882,6 +1889,10 @@ static bool performCompile(CompilerInstance &Instance,
18821889 const auto &opts = Invocation.getFrontendOptions ();
18831890 const FrontendOptions::ActionType Action = opts.RequestedAction ;
18841891
1892+ // To compile LLVM IR, just pass it off unmodified.
1893+ if (Instance.getInvocation ().getInputKind () == InputFileKind::LLVM)
1894+ return compileLLVMIR (Instance);
1895+
18851896 // If we aren't in a parse-only context and expect an implicit stdlib import,
18861897 // load in the standard library. If we either fail to find it or encounter an
18871898 // error while loading it, bail early. Continuing the compilation will at best
@@ -1909,7 +1920,8 @@ static bool performCompile(CompilerInstance &Instance,
19091920
19101921 // We might have freed the ASTContext already, but in that case we would
19111922 // have already performed these actions.
1912- if (Instance.hasASTContext ()) {
1923+ if (Instance.hasASTContext () &&
1924+ FrontendOptions::doesActionRequireInputs (Action)) {
19131925 performEndOfPipelineActions (Instance);
19141926 hadError |= Instance.getASTContext ().hadError ();
19151927 }
0 commit comments