Skip to content

[NFC] Clean Up FrontendTool #33672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ class CompilerInstance {
///
/// This is similar to a parse-only invocation, but module imports will also
/// be processed.
void performParseAndResolveImportsOnly();
bool performParseAndResolveImportsOnly();

/// Performs mandatory, diagnostic, and optimization passes over the SIL.
/// \param silModule The SIL module that was generated during SILGen.
Expand Down
9 changes: 8 additions & 1 deletion include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,16 @@ class FrontendOptions {
/// '.../lib/swift', otherwise '.../lib/swift_static'.
bool UseSharedResourceFolder = true;

/// \return true if action only parses without doing other compilation steps.
/// \return true if the given action only parses without doing other compilation steps.
static bool shouldActionOnlyParse(ActionType);

/// \return true if the given action requires the standard library to be
/// loaded before it is run.
static bool doesActionRequireSwiftStandardLibrary(ActionType);

/// \return true if the given action requires input files to be provided.
static bool doesActionRequireInputs(ActionType action);

/// Return a hash code of any components from these options that should
/// contribute to a Swift Bridging PCH hash.
llvm::hash_code getPCHHashComponents() const {
Expand Down
3 changes: 1 addition & 2 deletions lib/Frontend/ArgsToFrontendOptionsConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,7 @@ bool ArgsToFrontendOptionsConverter::setUpInputKindAndImmediateArgs() {
if (Opts.InputsAndOutputs.verifyInputs(
Diags, treatAsSIL,
Opts.RequestedAction == FrontendOptions::ActionType::REPL,
(Opts.RequestedAction == FrontendOptions::ActionType::NoneAction ||
Opts.RequestedAction == FrontendOptions::ActionType::PrintVersion))){
!FrontendOptions::doesActionRequireInputs(Opts.RequestedAction))) {
return true;
}
if (Opts.RequestedAction == FrontendOptions::ActionType::Immediate) {
Expand Down
3 changes: 2 additions & 1 deletion lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ void CompilerInstance::setMainModule(ModuleDecl *newMod) {
Context->addLoadedModule(newMod);
}

void CompilerInstance::performParseAndResolveImportsOnly() {
bool CompilerInstance::performParseAndResolveImportsOnly() {
FrontendStatsTracer tracer(getStatsReporter(), "parse-and-resolve-imports");

// Resolve imports for all the source files.
Expand All @@ -867,6 +867,7 @@ void CompilerInstance::performParseAndResolveImportsOnly() {
mainModule->setHasResolvedImports();

bindExtensions(*mainModule);
return Context->hadError();
}

void CompilerInstance::performSema() {
Expand Down
100 changes: 92 additions & 8 deletions lib/Frontend/FrontendOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,104 @@ bool FrontendOptions::needsProperModuleName(ActionType action) {

bool FrontendOptions::shouldActionOnlyParse(ActionType action) {
switch (action) {
case FrontendOptions::ActionType::Parse:
case FrontendOptions::ActionType::DumpParse:
case FrontendOptions::ActionType::EmitSyntax:
case FrontendOptions::ActionType::DumpInterfaceHash:
case FrontendOptions::ActionType::EmitImportedModules:
case FrontendOptions::ActionType::ScanDependencies:
case FrontendOptions::ActionType::ScanClangDependencies:
case FrontendOptions::ActionType::PrintVersion:
case ActionType::Parse:
case ActionType::DumpParse:
case ActionType::EmitSyntax:
case ActionType::DumpInterfaceHash:
case ActionType::EmitImportedModules:
case ActionType::ScanDependencies:
case ActionType::ScanClangDependencies:
case ActionType::PrintVersion:
return true;
default:
return false;
}
}

bool FrontendOptions::doesActionRequireSwiftStandardLibrary(ActionType action) {
switch (action) {
case ActionType::NoneAction:
case ActionType::Parse:
case ActionType::DumpParse:
case ActionType::EmitSyntax:
case ActionType::DumpInterfaceHash:
case ActionType::EmitImportedModules:
case ActionType::ScanDependencies:
case ActionType::ScanClangDependencies:
case ActionType::PrintVersion:
case ActionType::EmitPCH:
case ActionType::EmitPCM:
case ActionType::DumpPCM:
case ActionType::CompileModuleFromInterface:
case ActionType::TypecheckModuleFromInterface:
return false;
case ActionType::ResolveImports:
case ActionType::Typecheck:
case ActionType::DumpAST:
case ActionType::PrintAST:
case ActionType::DumpScopeMaps:
case ActionType::DumpTypeRefinementContexts:
case ActionType::EmitSILGen:
case ActionType::EmitSIL:
case ActionType::EmitModuleOnly:
case ActionType::MergeModules:
case ActionType::EmitSIBGen:
case ActionType::EmitSIB:
case ActionType::Immediate:
case ActionType::REPL:
case ActionType::EmitAssembly:
case ActionType::EmitIR:
case ActionType::EmitBC:
case ActionType::EmitObject:
case ActionType::DumpTypeInfo:
assert(!FrontendOptions::shouldActionOnlyParse(action) &&
"Parse-only actions should not load modules!");
return true;
}
llvm_unreachable("Unknown ActionType");
}

bool FrontendOptions::doesActionRequireInputs(ActionType action) {
switch (action) {
case ActionType::NoneAction:
case ActionType::PrintVersion:
return false;
case ActionType::REPL:
case ActionType::Parse:
case ActionType::DumpParse:
case ActionType::EmitSyntax:
case ActionType::DumpInterfaceHash:
case ActionType::EmitImportedModules:
case ActionType::ScanDependencies:
case ActionType::ScanClangDependencies:
case ActionType::EmitPCH:
case ActionType::EmitPCM:
case ActionType::DumpPCM:
case ActionType::CompileModuleFromInterface:
case ActionType::TypecheckModuleFromInterface:
case ActionType::ResolveImports:
case ActionType::Typecheck:
case ActionType::DumpAST:
case ActionType::PrintAST:
case ActionType::DumpScopeMaps:
case ActionType::DumpTypeRefinementContexts:
case ActionType::EmitSILGen:
case ActionType::EmitSIL:
case ActionType::EmitModuleOnly:
case ActionType::MergeModules:
case ActionType::EmitSIBGen:
case ActionType::EmitSIB:
case ActionType::Immediate:
case ActionType::EmitAssembly:
case ActionType::EmitIR:
case ActionType::EmitBC:
case ActionType::EmitObject:
case ActionType::DumpTypeInfo:
return true;
}
llvm_unreachable("Unknown ActionType");
}

void FrontendOptions::forAllOutputPaths(
const InputFile &input, llvm::function_ref<void(StringRef)> fn) const {
if (RequestedAction != FrontendOptions::ActionType::EmitModuleOnly &&
Expand Down
Loading