Skip to content

Commit 4c56c95

Browse files
committed
Define doesActionRequireInputs
1 parent fe7444f commit 4c56c95

File tree

4 files changed

+68
-13
lines changed

4 files changed

+68
-13
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ class FrontendOptions {
301301
/// loaded before it is run.
302302
static bool doesActionRequireSwiftStandardLibrary(ActionType);
303303

304+
/// \return true if the given action requires input files to be provided.
305+
static bool doesActionRequireInputs(ActionType action);
306+
304307
/// Return a hash code of any components from these options that should
305308
/// contribute to a Swift Bridging PCH hash.
306309
llvm::hash_code getPCHHashComponents() const {

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,7 @@ bool ArgsToFrontendOptionsConverter::setUpInputKindAndImmediateArgs() {
406406
if (Opts.InputsAndOutputs.verifyInputs(
407407
Diags, treatAsSIL,
408408
Opts.RequestedAction == FrontendOptions::ActionType::REPL,
409-
(Opts.RequestedAction == FrontendOptions::ActionType::NoneAction ||
410-
Opts.RequestedAction == FrontendOptions::ActionType::PrintVersion))){
409+
!FrontendOptions::doesActionRequireInputs(Opts.RequestedAction))) {
411410
return true;
412411
}
413412
if (Opts.RequestedAction == FrontendOptions::ActionType::Immediate) {

lib/Frontend/FrontendOptions.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,47 @@ bool FrontendOptions::doesActionRequireSwiftStandardLibrary(ActionType action) {
130130
llvm_unreachable("Unknown ActionType");
131131
}
132132

133+
bool FrontendOptions::doesActionRequireInputs(ActionType action) {
134+
switch (action) {
135+
case ActionType::NoneAction:
136+
case ActionType::PrintVersion:
137+
return false;
138+
case ActionType::REPL:
139+
case ActionType::Parse:
140+
case ActionType::DumpParse:
141+
case ActionType::EmitSyntax:
142+
case ActionType::DumpInterfaceHash:
143+
case ActionType::EmitImportedModules:
144+
case ActionType::ScanDependencies:
145+
case ActionType::ScanClangDependencies:
146+
case ActionType::EmitPCH:
147+
case ActionType::EmitPCM:
148+
case ActionType::DumpPCM:
149+
case ActionType::CompileModuleFromInterface:
150+
case ActionType::TypecheckModuleFromInterface:
151+
case ActionType::ResolveImports:
152+
case ActionType::Typecheck:
153+
case ActionType::DumpAST:
154+
case ActionType::PrintAST:
155+
case ActionType::DumpScopeMaps:
156+
case ActionType::DumpTypeRefinementContexts:
157+
case ActionType::EmitSILGen:
158+
case ActionType::EmitSIL:
159+
case ActionType::EmitModuleOnly:
160+
case ActionType::MergeModules:
161+
case ActionType::EmitSIBGen:
162+
case ActionType::EmitSIB:
163+
case ActionType::Immediate:
164+
case ActionType::EmitAssembly:
165+
case ActionType::EmitIR:
166+
case ActionType::EmitBC:
167+
case ActionType::EmitObject:
168+
case ActionType::DumpTypeInfo:
169+
return true;
170+
}
171+
llvm_unreachable("Unknown ActionType");
172+
}
173+
133174
void FrontendOptions::forAllOutputPaths(
134175
const InputFile &input, llvm::function_ref<void(StringRef)> fn) const {
135176
if (RequestedAction != FrontendOptions::ActionType::EmitModuleOnly &&

lib/FrontendTool/FrontendTool.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)