Skip to content
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
9 changes: 9 additions & 0 deletions include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,12 @@ class CompilerInstance {
}
}

SourceFile &getPrimaryOrMainSourceFile() const {
if (SourceFile *SF = getPrimarySourceFile())
return *SF;
return getMainModule()->getMainSourceFile();
}

/// Returns true if there was an error during setup.
bool setup(const CompilerInvocation &Invocation, std::string &Error,
ArrayRef<const char *> Args = {});
Expand Down Expand Up @@ -792,6 +798,9 @@ class CompilerInstance {
/// \returns true if any errors occurred.
bool performSILProcessing(SILModule *silModule);

/// Dumps any debugging output for the compilation, if requested.
void emitEndOfPipelineDebuggingOutput();

private:
/// Creates a new source file for the main module.
SourceFile *createSourceFileForMainModule(ModuleDecl *mod,
Expand Down
29 changes: 18 additions & 11 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ namespace llvm {
namespace swift {
enum class IntermoduleDepTrackingMode;

/// Options for debugging the behavior of the frontend.
struct CompilerDebuggingOptions {
/// Indicates whether or not the Clang importer should print statistics upon
/// termination.
bool PrintClangStats = false;

/// Indicates whether or not the availability scope trees built during
/// compilation should be dumped upon termination.
bool DumpAvailabilityScopes = false;

/// Indicates whether or not the Clang importer should dump lookup tables
/// upon termination.
bool DumpClangLookupTables = false;
};

/// Options for controlling the behavior of the frontend.
class FrontendOptions {
friend class ArgsToFrontendOptionsConverter;
Expand Down Expand Up @@ -124,6 +139,9 @@ class FrontendOptions {
/// A set of modules allowed to import this module.
std::set<std::string> AllowableClients;

/// Options for debugging the compiler.
CompilerDebuggingOptions CompilerDebuggingOpts;

/// Emit index data for imported serialized swift system modules.
bool IndexSystemModules = false;

Expand Down Expand Up @@ -167,9 +185,6 @@ class FrontendOptions {
/// Parse and dump scope map.
DumpScopeMaps,

/// Parse, type-check, and dump availability scopes
DumpAvailabilityScopes,

EmitImportedModules, ///< Emit the modules that this one imports
EmitPCH, ///< Emit PCH of imported bridging header

Expand Down Expand Up @@ -305,14 +320,6 @@ class FrontendOptions {
/// termination.
bool PrintStats = false;

/// Indicates whether or not the Clang importer should print statistics upon
/// termination.
bool PrintClangStats = false;

/// Indicates whether or not the Clang importer should dump lookup tables
/// upon termination.
bool DumpClangLookupTables = false;

/// Indicates whether standard help should be shown.
bool PrintHelp = false;

Expand Down
28 changes: 6 additions & 22 deletions include/swift/Frontend/ModuleInterfaceLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ class ExplicitModuleMapParser {
llvm::StringSaver Saver;
};

struct ModuleInterfaceLoaderOptions {
class ModuleInterfaceLoaderOptions {
public:
FrontendOptions::ActionType requestedAction =
FrontendOptions::ActionType::EmitModuleOnly;
bool remarkOnRebuildFromInterface = false;
Expand All @@ -464,28 +465,11 @@ struct ModuleInterfaceLoaderOptions {
bool disableBuildingInterface = false;
bool downgradeInterfaceVerificationError = false;
bool strictImplicitModuleContext = false;
CompilerDebuggingOptions compilerDebuggingOptions;
std::string mainExecutablePath;
ModuleInterfaceLoaderOptions(const FrontendOptions &Opts):
remarkOnRebuildFromInterface(Opts.RemarkOnRebuildFromModuleInterface),
disableInterfaceLock(Opts.DisableInterfaceFileLock),
disableImplicitSwiftModule(Opts.DisableImplicitModules),
disableBuildingInterface(Opts.DisableBuildingInterface),
downgradeInterfaceVerificationError(Opts.DowngradeInterfaceVerificationError),
strictImplicitModuleContext(Opts.StrictImplicitModuleContext),
mainExecutablePath(Opts.MainExecutablePath)
{
switch (Opts.RequestedAction) {
case FrontendOptions::ActionType::TypecheckModuleFromInterface:
requestedAction = FrontendOptions::ActionType::Typecheck;
break;
case FrontendOptions::ActionType::ScanDependencies:
requestedAction = Opts.RequestedAction;
break;
default:
requestedAction = FrontendOptions::ActionType::EmitModuleOnly;
break;
}
}

ModuleInterfaceLoaderOptions(const FrontendOptions &Opts,
bool inheritDebuggingOpts = false);
ModuleInterfaceLoaderOptions() = default;
};

Expand Down
3 changes: 3 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,9 @@ def dump_clang_lookup_tables : Flag<["-"], "dump-clang-lookup-tables">,
HelpText<"Dump the importer's Swift-name-to-Clang-name lookup tables to "
"stderr">;

def dump_availability_scopes : Flag<["-"], "dump-availability-scopes">,
HelpText<"Dump availability scopes to stderr">;

def disable_modules_validate_system_headers : Flag<["-"], "disable-modules-validate-system-headers">,
HelpText<"Disable validating system headers in the Clang importer">;

Expand Down
6 changes: 1 addition & 5 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1435,11 +1435,7 @@ def dump_scope_maps : Separate<["-"], "dump-scope-maps">,
MetaVarName<"<expanded-or-list-of-line:column>">,
ModeOpt,
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>;
def dump_availability_scopes :
Flag<["-"], "dump-availability-scopes">,
HelpText<"Type-check input file(s) and dump availability scopes">,
ModeOpt,
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>;

def dump_type_info : Flag<["-"], "dump-type-info">,
HelpText<"Output YAML dump of fixed-size types from all imported modules">,
ModeOpt,
Expand Down
11 changes: 7 additions & 4 deletions lib/Frontend/ArgsToFrontendOptionsConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ bool ArgsToFrontendOptionsConverter::convert(
computeDebugTimeOptions();
computeTBDOptions();

Opts.DumpClangLookupTables |= Args.hasArg(OPT_dump_clang_lookup_tables);
Opts.CompilerDebuggingOpts.DumpAvailabilityScopes |=
Args.hasArg(OPT_dump_availability_scopes);

Opts.CompilerDebuggingOpts.DumpClangLookupTables |=
Args.hasArg(OPT_dump_clang_lookup_tables);

Opts.CheckOnoneSupportCompleteness = Args.hasArg(OPT_check_onone_completeness);

Expand Down Expand Up @@ -471,7 +475,8 @@ void ArgsToFrontendOptionsConverter::handleDebugCrashGroupArguments() {
void ArgsToFrontendOptionsConverter::computePrintStatsOptions() {
using namespace options;
Opts.PrintStats |= Args.hasArg(OPT_print_stats);
Opts.PrintClangStats |= Args.hasArg(OPT_print_clang_stats);
Opts.CompilerDebuggingOpts.PrintClangStats |=
Args.hasArg(OPT_print_clang_stats);
Opts.PrintZeroStats |= Args.hasArg(OPT_print_zero_stats);
#if defined(NDEBUG) && !LLVM_ENABLE_STATS
if (Opts.PrintStats || Opts.PrintClangStats)
Expand Down Expand Up @@ -665,8 +670,6 @@ ArgsToFrontendOptionsConverter::determineRequestedAction(const ArgList &args) {
return FrontendOptions::ActionType::MergeModules;
if (Opt.matches(OPT_dump_scope_maps))
return FrontendOptions::ActionType::DumpScopeMaps;
if (Opt.matches(OPT_dump_availability_scopes))
return FrontendOptions::ActionType::DumpAvailabilityScopes;
if (Opt.matches(OPT_dump_interface_hash))
return FrontendOptions::ActionType::DumpInterfaceHash;
if (Opt.matches(OPT_dump_type_info))
Expand Down
1 change: 0 additions & 1 deletion lib/Frontend/ArgsToFrontendOutputsConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ static bool shouldEmitFineModuleTrace(FrontendOptions::ActionType action) {
case swift::FrontendOptions::ActionType::PrintAST:
case swift::FrontendOptions::ActionType::PrintASTDecl:
case swift::FrontendOptions::ActionType::DumpScopeMaps:
case swift::FrontendOptions::ActionType::DumpAvailabilityScopes:
case swift::FrontendOptions::ActionType::EmitImportedModules:
case swift::FrontendOptions::ActionType::EmitPCH:
case swift::FrontendOptions::ActionType::EmitModuleOnly:
Expand Down
18 changes: 18 additions & 0 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "swift/Frontend/Frontend.h"
#include "swift/AST/ASTContext.h"
#include "swift/AST/AvailabilityDomain.h"
#include "swift/AST/AvailabilityScope.h"
#include "swift/AST/DiagnosticsFrontend.h"
#include "swift/AST/DiagnosticsSema.h"
#include "swift/AST/FileSystem.h"
Expand Down Expand Up @@ -1867,6 +1868,23 @@ bool CompilerInstance::performSILProcessing(SILModule *silModule) {
return false;
}

void CompilerInstance::emitEndOfPipelineDebuggingOutput() {
assert(hasASTContext());
auto &ctx = getASTContext();
const auto &Invocation = getInvocation();
const auto &opts = Invocation.getFrontendOptions().CompilerDebuggingOpts;

if (opts.PrintClangStats && ctx.getClangModuleLoader())
ctx.getClangModuleLoader()->printStatistics();

if (opts.DumpAvailabilityScopes)
getPrimaryOrMainSourceFile().getAvailabilityScope()->dump(llvm::errs(),
ctx.SourceMgr);

if (opts.DumpClangLookupTables && ctx.getClangModuleLoader())
ctx.getClangModuleLoader()->dumpSwiftLookupTables();
}

bool CompilerInstance::isCancellationRequested() const {
auto flag = getASTContext().CancellationFlag;
return flag && flag->load(std::memory_order_relaxed);
Expand Down
21 changes: 0 additions & 21 deletions lib/Frontend/FrontendOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ bool FrontendOptions::needsProperModuleName(ActionType action) {
case ActionType::PrintAST:
case ActionType::PrintASTDecl:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::DumpPCM:
case ActionType::EmitPCH:
return false;
Expand Down Expand Up @@ -111,7 +110,6 @@ bool FrontendOptions::doesActionRequireSwiftStandardLibrary(ActionType action) {
case ActionType::PrintAST:
case ActionType::PrintASTDecl:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::EmitSILGen:
case ActionType::EmitSIL:
case ActionType::EmitLoweredSIL:
Expand Down Expand Up @@ -157,7 +155,6 @@ bool FrontendOptions::doesActionRequireInputs(ActionType action) {
case ActionType::PrintAST:
case ActionType::PrintASTDecl:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::EmitSILGen:
case ActionType::EmitSIL:
case ActionType::EmitLoweredSIL:
Expand Down Expand Up @@ -200,7 +197,6 @@ bool FrontendOptions::doesActionPerformEndOfPipelineActions(ActionType action) {
case ActionType::PrintAST:
case ActionType::PrintASTDecl:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::EmitSILGen:
case ActionType::EmitSIL:
case ActionType::EmitLoweredSIL:
Expand Down Expand Up @@ -239,7 +235,6 @@ bool FrontendOptions::supportCompilationCaching(ActionType action) {
case ActionType::PrintAST:
case ActionType::PrintASTDecl:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::MergeModules:
case ActionType::Immediate:
case ActionType::DumpTypeInfo:
Expand Down Expand Up @@ -305,7 +300,6 @@ FrontendOptions::formatForPrincipalOutputFileForAction(ActionType action) {
case ActionType::PrintAST:
case ActionType::PrintASTDecl:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::DumpTypeInfo:
case ActionType::DumpPCM:
case ActionType::PrintVersion:
Expand Down Expand Up @@ -378,7 +372,6 @@ bool FrontendOptions::canActionEmitDependencies(ActionType action) {
case ActionType::PrintAST:
case ActionType::PrintASTDecl:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::DumpTypeInfo:
case ActionType::CompileModuleFromInterface:
case ActionType::TypecheckModuleFromInterface:
Expand Down Expand Up @@ -422,7 +415,6 @@ bool FrontendOptions::canActionEmitReferenceDependencies(ActionType action) {
case ActionType::PrintAST:
case ActionType::PrintASTDecl:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::DumpTypeInfo:
case ActionType::CompileModuleFromInterface:
case ActionType::TypecheckModuleFromInterface:
Expand Down Expand Up @@ -467,7 +459,6 @@ bool FrontendOptions::canActionEmitModuleSummary(ActionType action) {
case ActionType::EmitImportedModules:
case ActionType::EmitPCH:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::DumpTypeInfo:
case ActionType::EmitSILGen:
case ActionType::EmitSIBGen:
Expand Down Expand Up @@ -509,7 +500,6 @@ bool FrontendOptions::canActionEmitClangHeader(ActionType action) {
case ActionType::PrintASTDecl:
case ActionType::EmitPCH:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::DumpTypeInfo:
case ActionType::CompileModuleFromInterface:
case ActionType::TypecheckModuleFromInterface:
Expand Down Expand Up @@ -550,7 +540,6 @@ bool FrontendOptions::canActionEmitLoadedModuleTrace(ActionType action) {
case ActionType::PrintAST:
case ActionType::PrintASTDecl:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::DumpTypeInfo:
case ActionType::CompileModuleFromInterface:
case ActionType::TypecheckModuleFromInterface:
Expand Down Expand Up @@ -600,7 +589,6 @@ bool FrontendOptions::canActionEmitModuleSemanticInfo(ActionType action) {
case ActionType::PrintASTDecl:
case ActionType::EmitPCH:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::DumpTypeInfo:
case ActionType::EmitSILGen:
case ActionType::TypecheckModuleFromInterface:
Expand Down Expand Up @@ -643,7 +631,6 @@ bool FrontendOptions::canActionEmitConstValues(ActionType action) {
case ActionType::PrintAST:
case ActionType::PrintASTDecl:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::DumpTypeInfo:
case ActionType::CompileModuleFromInterface:
case ActionType::TypecheckModuleFromInterface:
Expand Down Expand Up @@ -687,7 +674,6 @@ bool FrontendOptions::canActionEmitModule(ActionType action) {
case ActionType::PrintASTDecl:
case ActionType::EmitPCH:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::DumpTypeInfo:
case ActionType::EmitSILGen:
case ActionType::CompileModuleFromInterface:
Expand Down Expand Up @@ -733,7 +719,6 @@ bool FrontendOptions::canActionEmitInterface(ActionType action) {
case ActionType::EmitImportedModules:
case ActionType::EmitPCH:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::DumpTypeInfo:
case ActionType::EmitSILGen:
case ActionType::EmitSIBGen:
Expand Down Expand Up @@ -776,7 +761,6 @@ bool FrontendOptions::canActionEmitAPIDescriptor(ActionType action) {
case ActionType::EmitImportedModules:
case ActionType::EmitPCH:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::DumpTypeInfo:
case ActionType::EmitSILGen:
case ActionType::EmitSIBGen:
Expand Down Expand Up @@ -818,7 +802,6 @@ bool FrontendOptions::doesActionProduceOutput(ActionType action) {
case ActionType::PrintAST:
case ActionType::PrintASTDecl:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::EmitPCH:
case ActionType::EmitSILGen:
case ActionType::EmitSIL:
Expand Down Expand Up @@ -877,7 +860,6 @@ bool FrontendOptions::doesActionProduceTextualOutput(ActionType action) {
case ActionType::PrintAST:
case ActionType::PrintASTDecl:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::EmitImportedModules:
case ActionType::EmitSILGen:
case ActionType::EmitSIL:
Expand Down Expand Up @@ -907,7 +889,6 @@ bool FrontendOptions::doesActionGenerateSIL(ActionType action) {
case ActionType::PrintAST:
case ActionType::PrintASTDecl:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::EmitImportedModules:
case ActionType::EmitPCH:
case ActionType::CompileModuleFromInterface:
Expand Down Expand Up @@ -948,7 +929,6 @@ bool FrontendOptions::doesActionGenerateIR(ActionType action) {
case ActionType::PrintAST:
case ActionType::PrintASTDecl:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::DumpTypeInfo:
case ActionType::CompileModuleFromInterface:
case ActionType::TypecheckModuleFromInterface:
Expand Down Expand Up @@ -994,7 +974,6 @@ bool FrontendOptions::doesActionBuildModuleFromInterface(ActionType action) {
case ActionType::PrintAST:
case ActionType::PrintASTDecl:
case ActionType::DumpScopeMaps:
case ActionType::DumpAvailabilityScopes:
case ActionType::DumpTypeInfo:
case ActionType::Typecheck:
case ActionType::ResolveImports:
Expand Down
Loading