@@ -1653,6 +1653,7 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
1653
1653
// it's -emit-imported-modules, which can load modules.
1654
1654
auto action = opts.RequestedAction ;
1655
1655
if (FrontendOptions::shouldActionOnlyParse (action) &&
1656
+ !ctx.getLoadedModules ().empty () &&
1656
1657
action != FrontendOptions::ActionType::EmitImportedModules) {
1657
1658
assert (ctx.getNumLoadedModules () == 1 &&
1658
1659
" Loaded a module during parse-only" );
@@ -1689,9 +1690,15 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
1689
1690
}
1690
1691
}
1691
1692
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.
1693
1701
emitReferenceDependenciesForAllPrimaryInputsIfNeeded (Instance);
1694
- emitIndexData (Instance);
1695
1702
emitMakeDependenciesIfNeeded (Instance.getDiags (),
1696
1703
Instance.getDependencyTracker (), opts);
1697
1704
@@ -1791,13 +1798,16 @@ static bool performAction(CompilerInstance &Instance,
1791
1798
return buildModuleFromInterface (Instance);
1792
1799
1793
1800
// 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 ();
1795
1809
return dumpAST (Instance);
1796
1810
}
1797
- case FrontendOptions::ActionType::DumpAST:
1798
- return withSemanticAnalysis (
1799
- Instance, observer,
1800
- [](CompilerInstance &Instance) { return dumpAST (Instance); });
1801
1811
case FrontendOptions::ActionType::PrintAST:
1802
1812
return withSemanticAnalysis (
1803
1813
Instance, observer, [](CompilerInstance &Instance) {
@@ -1860,9 +1870,6 @@ static bool performAction(CompilerInstance &Instance,
1860
1870
Instance, observer, [&](CompilerInstance &Instance) {
1861
1871
assert (FrontendOptions::doesActionGenerateSIL (opts.RequestedAction ) &&
1862
1872
" All actions not requiring SILGen must have been handled!" );
1863
- if (Instance.getInvocation ().getInputKind () == InputFileKind::LLVM)
1864
- return compileLLVMIR (Instance);
1865
-
1866
1873
return performCompileStepsPostSema (Instance, ReturnValue, observer);
1867
1874
});
1868
1875
}
@@ -1882,6 +1889,10 @@ static bool performCompile(CompilerInstance &Instance,
1882
1889
const auto &opts = Invocation.getFrontendOptions ();
1883
1890
const FrontendOptions::ActionType Action = opts.RequestedAction ;
1884
1891
1892
+ // To compile LLVM IR, just pass it off unmodified.
1893
+ if (Instance.getInvocation ().getInputKind () == InputFileKind::LLVM)
1894
+ return compileLLVMIR (Instance);
1895
+
1885
1896
// If we aren't in a parse-only context and expect an implicit stdlib import,
1886
1897
// load in the standard library. If we either fail to find it or encounter an
1887
1898
// error while loading it, bail early. Continuing the compilation will at best
@@ -1909,7 +1920,8 @@ static bool performCompile(CompilerInstance &Instance,
1909
1920
1910
1921
// We might have freed the ASTContext already, but in that case we would
1911
1922
// have already performed these actions.
1912
- if (Instance.hasASTContext ()) {
1923
+ if (Instance.hasASTContext () &&
1924
+ FrontendOptions::doesActionRequireInputs (Action)) {
1913
1925
performEndOfPipelineActions (Instance);
1914
1926
hadError |= Instance.getASTContext ().hadError ();
1915
1927
}
0 commit comments