From 1a0443040e233a8e41c547fb55b8d83ae0a75c61 Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Wed, 29 Nov 2017 07:32:02 -0800 Subject: [PATCH] Revert "Merge pull request #12952 from davidungar/move-in-to-next" This reverts commit 911140c7e1901ccf843b54ed40aa6c364ec3660d, reversing changes made to 5590a2ff91255a71358e75d77058e1f845b8ab6e. This broke the incremental bot. rdar://35746584 --- include/swift/Frontend/FrontendOptions.h | 65 +- lib/Frontend/CompilerInvocation.cpp | 1034 ++++++++--------- lib/Frontend/Frontend.cpp | 5 +- lib/Frontend/FrontendOptions.cpp | 372 ++---- lib/FrontendTool/FrontendTool.cpp | 4 +- .../lib/SwiftLang/SwiftASTManager.cpp | 4 +- .../lib/SwiftLang/SwiftCompletion.cpp | 2 +- .../SourceKit/lib/SwiftLang/SwiftIndexing.cpp | 2 +- tools/driver/modulewrap_main.cpp | 4 +- 9 files changed, 623 insertions(+), 869 deletions(-) diff --git a/include/swift/Frontend/FrontendOptions.h b/include/swift/Frontend/FrontendOptions.h index 07a433aa99e36..626e170478d55 100644 --- a/include/swift/Frontend/FrontendOptions.h +++ b/include/swift/Frontend/FrontendOptions.h @@ -21,6 +21,10 @@ namespace llvm { class MemoryBuffer; + namespace opt { + class ArgList; + class Arg; + } // namespace opt } namespace swift { @@ -84,17 +88,17 @@ class FrontendInputs { // Input filename readers ArrayRef getInputFilenames() const { return InputFilenames; } - bool hasInputFilenames() const { return !getInputFilenames().empty(); } + bool haveInputFilenames() const { return !getInputFilenames().empty(); } unsigned inputFilenameCount() const { return getInputFilenames().size(); } - bool hasUniqueInputFilename() const { return inputFilenameCount() == 1; } + bool haveUniqueInputFilename() const { return inputFilenameCount() == 1; } const std::string &getFilenameOfFirstInput() const { - assert(hasInputFilenames()); + assert(haveInputFilenames()); return getInputFilenames()[0]; } bool isReadingFromStdin() const { - return hasUniqueInputFilename() && getFilenameOfFirstInput() == "-"; + return haveUniqueInputFilename() && getFilenameOfFirstInput() == "-"; } // If we have exactly one input filename, and its extension is "bc" or "ll", @@ -123,32 +127,32 @@ class FrontendInputs { // Primary count readers: - bool hasUniquePrimaryInput() const { return primaryInputCount() == 1; } + bool haveUniquePrimaryInput() const { return primaryInputCount() == 1; } - bool hasPrimaryInputs() const { return primaryInputCount() > 0; } + bool havePrimaryInputs() const { return primaryInputCount() > 0; } - bool isWholeModule() const { return !hasPrimaryInputs(); } + bool isWholeModule() const { return !havePrimaryInputs(); } // Count-dependend readers: Optional getOptionalPrimaryInput() const { - return hasPrimaryInputs() ? Optional(getPrimaryInputs()[0]) - : Optional(); + return havePrimaryInputs() ? Optional(getPrimaryInputs()[0]) + : Optional(); } SelectedInput getRequiredUniquePrimaryInput() const { - assert(hasUniquePrimaryInput()); + assert(haveUniquePrimaryInput()); return getPrimaryInputs()[0]; } Optional getOptionalUniquePrimaryInput() const { - return hasUniquePrimaryInput() + return haveUniquePrimaryInput() ? Optional(getPrimaryInputs()[0]) : Optional(); } - bool hasAPrimaryInputFile() const { - return hasPrimaryInputs() && getOptionalPrimaryInput()->isFilename(); + bool haveAPrimaryInputFile() const { + return havePrimaryInputs() && getOptionalPrimaryInput()->isFilename(); } Optional getOptionalUniquePrimaryInputFilename() const { @@ -158,7 +162,7 @@ class FrontendInputs { : Optional(); } - bool isInputPrimary(unsigned i) const { + bool isPrimaryInputAFileAt(unsigned i) const { assertMustNotBeMoreThanOnePrimaryInput(); if (Optional primaryInput = getOptionalPrimaryInput()) return primaryInput->isFilename() && primaryInput->Index == i; @@ -166,7 +170,7 @@ class FrontendInputs { } Optional primaryInputFileIndex() const { - return hasAPrimaryInputFile() + return haveAPrimaryInputFile() ? Optional(getOptionalPrimaryInput()->Index) : None; } @@ -180,10 +184,13 @@ class FrontendInputs { public: // Multi-facet readers + StringRef baseNameOfOutput(const llvm::opt::ArgList &Args, + StringRef ModuleName) const; + bool shouldTreatAsSIL() const; /// Return true for error - bool verifyInputs(DiagnosticEngine &diags, bool treatAsSIL, + bool verifyInputs(DiagnosticEngine &Diags, bool TreatAsSIL, bool isREPLRequested, bool isNoneRequested) const; // Input filename writers @@ -243,8 +250,6 @@ class FrontendInputs { /// Options for controlling the behavior of the frontend. class FrontendOptions { - friend class FrontendArgsToOptionsConverter; - public: FrontendInputs Inputs; @@ -274,9 +279,12 @@ class FrontendOptions { return getSingleOutputFilename() == "-"; } bool isOutputFileDirectory() const; - bool hasNamedOutputFile() const { + bool isOutputFilePlainFile() const; + bool haveNamedOutputFile() const { return !OutputFilenames.empty() && !isOutputFilenameStdout(); } + void setOutputFileList(DiagnosticEngine &Diags, + const llvm::opt::ArgList &Args); /// A list of arbitrary modules to import and make implicitly visible. std::vector ImplicitImportModuleNames; @@ -532,25 +540,10 @@ class FrontendOptions { bool isCompilingExactlyOneSwiftFile() const { return InputKind == InputFileKind::IFK_Swift && - Inputs.hasUniqueInputFilename(); + Inputs.haveUniqueInputFilename(); } -private: - static const char *suffixForPrincipalOutputFileForAction(ActionType); - - bool hasUnusedDependenciesFilePath() const; - static bool canActionEmitDependencies(ActionType); - bool hasUnusedObjCHeaderOutputPath() const; - static bool canActionEmitHeader(ActionType); - bool hasUnusedLoadedModuleTracePath() const; - static bool canActionEmitLoadedModuleTrace(ActionType); - bool hasUnusedModuleOutputPath() const; - static bool canActionEmitModule(ActionType); - bool hasUnusedModuleDocOutputPath() const; - static bool canActionEmitModuleDoc(ActionType); - - static bool doesActionProduceOutput(ActionType); - static bool doesActionProduceTextualOutput(ActionType); + void setModuleName(DiagnosticEngine &Diags, const llvm::opt::ArgList &Args); }; } diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 1689a4800ca84..a51dc25818f63 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -79,18 +79,6 @@ SourceFileKind CompilerInvocation::getSourceFileKind() const { llvm_unreachable("Unhandled InputFileKind in switch."); } -// This is a separate function so that it shows up in stack traces. -LLVM_ATTRIBUTE_NOINLINE -static void debugFailWithAssertion() { - // This assertion should always fail, per the user's request, and should - // not be converted to llvm_unreachable. - assert(0 && "This is an assertion!"); -} - -// This is a separate function so that it shows up in stack traces. -LLVM_ATTRIBUTE_NOINLINE -static void debugFailWithCrash() { LLVM_BUILTIN_TRAP; } - namespace swift { /// Implement argument semantics in a way that will make it easier to have @@ -230,164 +218,25 @@ class ArgsToFrontendInputsConverter { return false; } }; -class FrontendArgsToOptionsConverter { -private: - DiagnosticEngine &Diags; - const llvm::opt::ArgList &Args; - FrontendOptions &Opts; - - Optional> - cachedOutputFilenamesFromCommandLineOrFilelist; - - void handleDebugCrashGroupArguments(); - - void computeDebugTimeOptions(); - bool computeFallbackModuleName(); - bool computeModuleName(); - bool computeOutputFilenames(); - void computeDumpScopeMapLocations(); - void computeHelpOptions(); - void computeImplicitImportModuleNames(); - void computeImportObjCHeaderOptions(); - void computeLLVMArgs(); - void computePlaygroundOptions(); - void computePrintStatsOptions(); - void computeTBDOptions(); - - void setUnsignedIntegerArgument(options::ID optionID, unsigned max, - unsigned &valueToSet); - - FrontendOptions::ActionType determineRequestedAction() const; - - bool setUpForSILOrLLVM(); - - /// Determine the correct output filename when none was specified. - /// - /// Such an absence should only occur when invoking the frontend - /// without the driver, - /// because the driver will always pass -o with an appropriate filename - /// if output is required for the requested action. - bool deriveOutputFilenameFromInputFile(); - - /// Determine the correct output filename when a directory was specified. - /// - /// Such a specification should only occur when invoking the frontend - /// directly, because the driver will always pass -o with an appropriate - /// filename if output is required for the requested action. - bool deriveOutputFilenameForDirectory(StringRef outputDir); - - std::string determineBaseNameOfOutput() const; - - void determineSupplementaryOutputFilenames(); - - /// Returns the output filenames on the command line or in the output - /// filelist. If there - /// were neither -o's nor an output filelist, returns an empty vector. - ArrayRef getOutputFilenamesFromCommandLineOrFilelist(); - - bool checkForUnusedOutputPaths() const; - - std::vector readOutputFileList(StringRef filelistPath) const; - -public: - FrontendArgsToOptionsConverter(DiagnosticEngine &Diags, - const llvm::opt::ArgList &Args, - FrontendOptions &Opts) - : Diags(Diags), Args(Args), Opts(Opts) {} - - bool convert(); -}; } // namespace swift -bool FrontendArgsToOptionsConverter::convert() { - using namespace options; - - handleDebugCrashGroupArguments(); - - if (const Arg *A = Args.getLastArg(OPT_dump_api_path)) { - Opts.DumpAPIPath = A->getValue(); - } - if (const Arg *A = Args.getLastArg(OPT_group_info_path)) { - Opts.GroupInfoPath = A->getValue(); - } - if (const Arg *A = Args.getLastArg(OPT_index_store_path)) { - Opts.IndexStorePath = A->getValue(); - } - Opts.IndexSystemModules |= Args.hasArg(OPT_index_system_modules); - - Opts.EmitVerboseSIL |= Args.hasArg(OPT_emit_verbose_sil); - Opts.EmitSortedSIL |= Args.hasArg(OPT_emit_sorted_sil); - - Opts.EnableTesting |= Args.hasArg(OPT_enable_testing); - Opts.EnableResilience |= Args.hasArg(OPT_enable_resilience); - - computePrintStatsOptions(); - computeDebugTimeOptions(); - computeTBDOptions(); - - setUnsignedIntegerArgument(OPT_warn_long_function_bodies, 10, - Opts.WarnLongFunctionBodies); - setUnsignedIntegerArgument(OPT_warn_long_expression_type_checking, 10, - Opts.WarnLongExpressionTypeChecking); - setUnsignedIntegerArgument(OPT_solver_expression_time_threshold_EQ, 10, - Opts.SolverExpressionTimeThreshold); - - computePlaygroundOptions(); - - // This can be enabled independently of the playground transform. - Opts.PCMacro |= Args.hasArg(OPT_pc_macro); - - computeHelpOptions(); - if (ArgsToFrontendInputsConverter(Diags, Args, Opts.Inputs).convert()) - return true; - - Opts.ParseStdlib |= Args.hasArg(OPT_parse_stdlib); - - if (const Arg *A = Args.getLastArg(OPT_verify_generic_signatures)) { - Opts.VerifyGenericSignaturesInModule = A->getValue(); - } - - computeDumpScopeMapLocations(); - Opts.RequestedAction = determineRequestedAction(); - - if (Opts.RequestedAction == FrontendOptions::ActionType::Immediate && - Opts.Inputs.hasPrimaryInputs()) { - Diags.diagnose(SourceLoc(), diag::error_immediate_mode_primary_file); - return true; - } - - if (setUpForSILOrLLVM()) - return true; - - if (computeModuleName()) - return true; - - if (computeOutputFilenames()) - return true; - determineSupplementaryOutputFilenames(); - - if (checkForUnusedOutputPaths()) - return true; - - if (const Arg *A = Args.getLastArg(OPT_module_link_name)) { - Opts.ModuleLinkName = A->getValue(); - } - - Opts.AlwaysSerializeDebuggingOptions |= - Args.hasArg(OPT_serialize_debugging_options); - Opts.EnableSourceImport |= Args.hasArg(OPT_enable_source_import); - Opts.ImportUnderlyingModule |= Args.hasArg(OPT_import_underlying_module); - Opts.EnableSerializationNestedTypeLookupTable &= - !Args.hasArg(OPT_disable_serialization_nested_type_lookup_table); - - computeImportObjCHeaderOptions(); - computeImplicitImportModuleNames(); - computeLLVMArgs(); +// This is a separate function so that it shows up in stack traces. +LLVM_ATTRIBUTE_NOINLINE +static void debugFailWithAssertion() { + // This assertion should always fail, per the user's request, and should + // not be converted to llvm_unreachable. + assert(0 && "This is an assertion!"); +} - return false; +// This is a separate function so that it shows up in stack traces. +LLVM_ATTRIBUTE_NOINLINE +static void debugFailWithCrash() { + LLVM_BUILTIN_TRAP; } -void FrontendArgsToOptionsConverter::handleDebugCrashGroupArguments() { + +static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, + DiagnosticEngine &Diags) { using namespace options; if (const Arg *A = Args.getLastArg(OPT_debug_crash_Group)) { @@ -406,23 +255,36 @@ void FrontendArgsToOptionsConverter::handleDebugCrashGroupArguments() { llvm_unreachable("Unknown debug_crash_Group option!"); } } -} -void FrontendArgsToOptionsConverter::computePrintStatsOptions() { - using namespace options; + if (const Arg *A = Args.getLastArg(OPT_dump_api_path)) { + Opts.DumpAPIPath = A->getValue(); + } + + if (const Arg *A = Args.getLastArg(OPT_group_info_path)) { + Opts.GroupInfoPath = A->getValue(); + } + + if (const Arg *A = Args.getLastArg(OPT_index_store_path)) { + Opts.IndexStorePath = A->getValue(); + } + Opts.IndexSystemModules |= Args.hasArg(OPT_index_system_modules); + + Opts.EmitVerboseSIL |= Args.hasArg(OPT_emit_verbose_sil); + Opts.EmitSortedSIL |= Args.hasArg(OPT_emit_sorted_sil); + + Opts.EnableTesting |= Args.hasArg(OPT_enable_testing); + Opts.EnableResilience |= Args.hasArg(OPT_enable_resilience); + Opts.PrintStats |= Args.hasArg(OPT_print_stats); Opts.PrintClangStats |= Args.hasArg(OPT_print_clang_stats); #if defined(NDEBUG) && !defined(LLVM_ENABLE_STATS) if (Opts.PrintStats || Opts.PrintClangStats) Diags.diagnose(SourceLoc(), diag::stats_disabled); #endif -} -void FrontendArgsToOptionsConverter::computeDebugTimeOptions() { - using namespace options; Opts.DebugTimeFunctionBodies |= Args.hasArg(OPT_debug_time_function_bodies); Opts.DebugTimeExpressionTypeChecking |= - Args.hasArg(OPT_debug_time_expression_type_checking); + Args.hasArg(OPT_debug_time_expression_type_checking); Opts.DebugTimeCompilation |= Args.hasArg(OPT_debug_time_compilation); if (const Arg *A = Args.getLastArg(OPT_stats_output_dir)) { Opts.StatsOutputDir = A->getValue(); @@ -430,10 +292,7 @@ void FrontendArgsToOptionsConverter::computeDebugTimeOptions() { Opts.TraceStats = true; } } -} -void FrontendArgsToOptionsConverter::computeTBDOptions() { - using namespace options; if (const Arg *A = Args.getLastArg(OPT_validate_tbd_against_ir_EQ)) { using Mode = FrontendOptions::TBDValidationMode; StringRef value = A->getValue(); @@ -448,35 +307,50 @@ void FrontendArgsToOptionsConverter::computeTBDOptions() { A->getOption().getPrefixedName(), value); } } + if (const Arg *A = Args.getLastArg(OPT_tbd_install_name)) { Opts.TBDInstallName = A->getValue(); } -} -void FrontendArgsToOptionsConverter::setUnsignedIntegerArgument( - options::ID optionID, unsigned max, unsigned &valueToSet) { - if (const Arg *A = Args.getLastArg(optionID)) { + if (const Arg *A = Args.getLastArg(OPT_warn_long_function_bodies)) { unsigned attempt; - if (StringRef(A->getValue()).getAsInteger(max, attempt)) { + if (StringRef(A->getValue()).getAsInteger(10, attempt)) { Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value, A->getAsString(Args), A->getValue()); } else { - valueToSet = attempt; + Opts.WarnLongFunctionBodies = attempt; + } + } + + if (const Arg *A = Args.getLastArg(OPT_warn_long_expression_type_checking)) { + unsigned attempt; + if (StringRef(A->getValue()).getAsInteger(10, attempt)) { + Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value, + A->getAsString(Args), A->getValue()); + } else { + Opts.WarnLongExpressionTypeChecking = attempt; + } + } + + if (const Arg *A = Args.getLastArg(OPT_solver_expression_time_threshold_EQ)) { + unsigned attempt; + if (StringRef(A->getValue()).getAsInteger(10, attempt)) { + Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value, + A->getAsString(Args), A->getValue()); + } else { + Opts.SolverExpressionTimeThreshold = attempt; } } -} -void FrontendArgsToOptionsConverter::computePlaygroundOptions() { - using namespace options; Opts.PlaygroundTransform |= Args.hasArg(OPT_playground); if (Args.hasArg(OPT_disable_playground_transform)) Opts.PlaygroundTransform = false; Opts.PlaygroundHighPerformance |= - Args.hasArg(OPT_playground_high_performance); -} + Args.hasArg(OPT_playground_high_performance); + + // This can be enabled independently of the playground transform. + Opts.PCMacro |= Args.hasArg(OPT_pc_macro); -void FrontendArgsToOptionsConverter::computeHelpOptions() { - using namespace options; if (const Arg *A = Args.getLastArg(OPT_help, OPT_help_hidden)) { if (A->getOption().matches(OPT_help)) { Opts.PrintHelp = true; @@ -486,117 +360,124 @@ void FrontendArgsToOptionsConverter::computeHelpOptions() { llvm_unreachable("Unknown help option parsed"); } } -} -void FrontendArgsToOptionsConverter::computeDumpScopeMapLocations() { - using namespace options; - const Arg *A = Args.getLastArg(OPT_modes_Group); - if (!A || !A->getOption().matches(OPT_dump_scope_maps)) - return; - StringRef value = A->getValue(); - if (value == "expanded") { - // Note: fully expanded the scope map. - return; - } - // Parse a comma-separated list of line:column for lookups to - // perform (and dump the result of). - SmallVector locations; - value.split(locations, ','); - - bool invalid = false; - for (auto location : locations) { - auto lineColumnStr = location.split(':'); - unsigned line, column; - if (lineColumnStr.first.getAsInteger(10, line) || - lineColumnStr.second.getAsInteger(10, column)) { - Diags.diagnose(SourceLoc(), diag::error_invalid_source_location_str, - location); - invalid = true; - continue; - } - Opts.DumpScopeMapLocations.push_back({line, column}); + if (ArgsToFrontendInputsConverter(Diags, Args, Opts.Inputs).convert()) + return true; + + Opts.ParseStdlib |= Args.hasArg(OPT_parse_stdlib); + + if (const Arg *A = Args.getLastArg(OPT_verify_generic_signatures)) { + Opts.VerifyGenericSignaturesInModule = A->getValue(); } - if (!invalid && Opts.DumpScopeMapLocations.empty()) - Diags.diagnose(SourceLoc(), diag::error_no_source_location_scope_map); -} + // Determine what the user has asked the frontend to do. + FrontendOptions::ActionType &Action = Opts.RequestedAction; + if (const Arg *A = Args.getLastArg(OPT_modes_Group)) { + Option Opt = A->getOption(); + if (Opt.matches(OPT_emit_object)) { + Action = FrontendOptions::ActionType::EmitObject; + } else if (Opt.matches(OPT_emit_assembly)) { + Action = FrontendOptions::ActionType::EmitAssembly; + } else if (Opt.matches(OPT_emit_ir)) { + Action = FrontendOptions::ActionType::EmitIR; + } else if (Opt.matches(OPT_emit_bc)) { + Action = FrontendOptions::ActionType::EmitBC; + } else if (Opt.matches(OPT_emit_sil)) { + Action = FrontendOptions::ActionType::EmitSIL; + } else if (Opt.matches(OPT_emit_silgen)) { + Action = FrontendOptions::ActionType::EmitSILGen; + } else if (Opt.matches(OPT_emit_sib)) { + Action = FrontendOptions::ActionType::EmitSIB; + } else if (Opt.matches(OPT_emit_sibgen)) { + Action = FrontendOptions::ActionType::EmitSIBGen; + } else if (Opt.matches(OPT_emit_pch)) { + Action = FrontendOptions::ActionType::EmitPCH; + } else if (Opt.matches(OPT_emit_imported_modules)) { + Action = FrontendOptions::ActionType::EmitImportedModules; + } else if (Opt.matches(OPT_parse)) { + Action = FrontendOptions::ActionType::Parse; + } else if (Opt.matches(OPT_typecheck)) { + Action = FrontendOptions::ActionType::Typecheck; + } else if (Opt.matches(OPT_dump_parse)) { + Action = FrontendOptions::ActionType::DumpParse; + } else if (Opt.matches(OPT_dump_ast)) { + Action = FrontendOptions::ActionType::DumpAST; + } else if (Opt.matches(OPT_emit_syntax)) { + Action = FrontendOptions::ActionType::EmitSyntax; + } else if (Opt.matches(OPT_merge_modules)) { + Action = FrontendOptions::ActionType::MergeModules; + } else if (Opt.matches(OPT_dump_scope_maps)) { + Action = FrontendOptions::ActionType::DumpScopeMaps; + + StringRef value = A->getValue(); + if (value == "expanded") { + // Note: fully expanded the scope map. + } else { + // Parse a comma-separated list of line:column for lookups to + // perform (and dump the result of). + SmallVector locations; + value.split(locations, ','); + + bool invalid = false; + for (auto location : locations) { + auto lineColumnStr = location.split(':'); + unsigned line, column; + if (lineColumnStr.first.getAsInteger(10, line) || + lineColumnStr.second.getAsInteger(10, column)) { + Diags.diagnose(SourceLoc(), diag::error_invalid_source_location_str, + location); + invalid = true; + continue; + } + + Opts.DumpScopeMapLocations.push_back({line, column}); + } -FrontendOptions::ActionType -FrontendArgsToOptionsConverter::determineRequestedAction() const { - using namespace options; - const Arg *A = Args.getLastArg(OPT_modes_Group); - if (!A) { + if (!invalid && Opts.DumpScopeMapLocations.empty()) + Diags.diagnose(SourceLoc(), diag::error_no_source_location_scope_map); + } + } else if (Opt.matches(OPT_dump_type_refinement_contexts)) { + Action = FrontendOptions::ActionType::DumpTypeRefinementContexts; + } else if (Opt.matches(OPT_dump_interface_hash)) { + Action = FrontendOptions::ActionType::DumpInterfaceHash; + } else if (Opt.matches(OPT_print_ast)) { + Action = FrontendOptions::ActionType::PrintAST; + } else if (Opt.matches(OPT_repl) || + Opt.matches(OPT_deprecated_integrated_repl)) { + Action = FrontendOptions::ActionType::REPL; + } else if (Opt.matches(OPT_interpret)) { + Action = FrontendOptions::ActionType::Immediate; + } else { + llvm_unreachable("Unhandled mode option"); + } + } else { // We don't have a mode, so determine a default. if (Args.hasArg(OPT_emit_module, OPT_emit_module_path)) { // We've been told to emit a module, but have no other mode indicators. // As a result, put the frontend into EmitModuleOnly mode. // (Setting up module output will be handled below.) - return FrontendOptions::ActionType::EmitModuleOnly; + Action = FrontendOptions::ActionType::EmitModuleOnly; } - return FrontendOptions::ActionType::NoneAction; - } - Option Opt = A->getOption(); - if (Opt.matches(OPT_emit_object)) - return FrontendOptions::ActionType::EmitObject; - if (Opt.matches(OPT_emit_assembly)) - return FrontendOptions::ActionType::EmitAssembly; - if (Opt.matches(OPT_emit_ir)) - return FrontendOptions::ActionType::EmitIR; - if (Opt.matches(OPT_emit_bc)) - return FrontendOptions::ActionType::EmitBC; - if (Opt.matches(OPT_emit_sil)) - return FrontendOptions::ActionType::EmitSIL; - if (Opt.matches(OPT_emit_silgen)) - return FrontendOptions::ActionType::EmitSILGen; - if (Opt.matches(OPT_emit_sib)) - return FrontendOptions::ActionType::EmitSIB; - if (Opt.matches(OPT_emit_sibgen)) - return FrontendOptions::ActionType::EmitSIBGen; - if (Opt.matches(OPT_emit_pch)) - return FrontendOptions::ActionType::EmitPCH; - if (Opt.matches(OPT_emit_imported_modules)) - return FrontendOptions::ActionType::EmitImportedModules; - if (Opt.matches(OPT_parse)) - return FrontendOptions::ActionType::Parse; - if (Opt.matches(OPT_typecheck)) - return FrontendOptions::ActionType::Typecheck; - if (Opt.matches(OPT_dump_parse)) - return FrontendOptions::ActionType::DumpParse; - if (Opt.matches(OPT_dump_ast)) - return FrontendOptions::ActionType::DumpAST; - if (Opt.matches(OPT_emit_syntax)) - return FrontendOptions::ActionType::EmitSyntax; - if (Opt.matches(OPT_merge_modules)) - return FrontendOptions::ActionType::MergeModules; - if (Opt.matches(OPT_dump_scope_maps)) - return FrontendOptions::ActionType::DumpScopeMaps; - if (Opt.matches(OPT_dump_type_refinement_contexts)) - return FrontendOptions::ActionType::DumpTypeRefinementContexts; - if (Opt.matches(OPT_dump_interface_hash)) - return FrontendOptions::ActionType::DumpInterfaceHash; - if (Opt.matches(OPT_print_ast)) - return FrontendOptions::ActionType::PrintAST; - - if (Opt.matches(OPT_repl) || Opt.matches(OPT_deprecated_integrated_repl)) - return FrontendOptions::ActionType::REPL; - if (Opt.matches(OPT_interpret)) - return FrontendOptions::ActionType::Immediate; - - llvm_unreachable("Unhandled mode option"); -} + } -bool FrontendArgsToOptionsConverter::setUpForSILOrLLVM() { - using namespace options; - bool treatAsSIL = + if (Opts.RequestedAction == FrontendOptions::ActionType::Immediate && + Opts.Inputs.havePrimaryInputs()) { + Diags.diagnose(SourceLoc(), diag::error_immediate_mode_primary_file); + return true; + } + + bool TreatAsSIL = Args.hasArg(OPT_parse_sil) || Opts.Inputs.shouldTreatAsSIL(); - bool treatAsLLVM = Opts.Inputs.shouldTreatAsLLVM(); + + bool TreatAsLLVM = Opts.Inputs.shouldTreatAsLLVM(); if (Opts.Inputs.verifyInputs( - Diags, treatAsSIL, + Diags, TreatAsSIL, Opts.RequestedAction == FrontendOptions::ActionType::REPL, Opts.RequestedAction == FrontendOptions::ActionType::NoneAction)) { return true; } + if (Opts.RequestedAction == FrontendOptions::ActionType::Immediate) { Opts.ImmediateArgv.push_back( Opts.Inputs.getFilenameOfFirstInput()); // argv[0] @@ -607,208 +488,190 @@ bool FrontendArgsToOptionsConverter::setUpForSILOrLLVM() { } } - if (treatAsSIL) + if (TreatAsSIL) Opts.InputKind = InputFileKind::IFK_SIL; - else if (treatAsLLVM) + else if (TreatAsLLVM) Opts.InputKind = InputFileKind::IFK_LLVM_IR; else if (Args.hasArg(OPT_parse_as_library)) Opts.InputKind = InputFileKind::IFK_Swift_Library; - else if (Opts.RequestedAction == FrontendOptions::ActionType::REPL) + else if (Action == FrontendOptions::ActionType::REPL) Opts.InputKind = InputFileKind::IFK_Swift_REPL; else Opts.InputKind = InputFileKind::IFK_Swift; - return false; -} + Opts.setOutputFileList(Diags, Args); -bool FrontendArgsToOptionsConverter::computeModuleName() { - const Arg *A = Args.getLastArg(options::OPT_module_name); - if (A) { - Opts.ModuleName = A->getValue(); - } else if (Opts.ModuleName.empty()) { - // The user did not specify a module name, so determine a default fallback - // based on other options. - - // Note: this code path will only be taken when running the frontend - // directly; the driver should always pass -module-name when invoking the - // frontend. - if (computeFallbackModuleName()) - return true; - } + Opts.setModuleName(Diags, Args); - if (Lexer::isIdentifier(Opts.ModuleName) && - (Opts.ModuleName != STDLIB_NAME || Opts.ParseStdlib)) { - return false; - } - if (!Opts.actionHasOutput() || Opts.isCompilingExactlyOneSwiftFile()) { - Opts.ModuleName = "main"; - return false; - } - auto DID = (Opts.ModuleName == STDLIB_NAME) ? diag::error_stdlib_module_name - : diag::error_bad_module_name; - Diags.diagnose(SourceLoc(), DID, Opts.ModuleName, A == nullptr); - Opts.ModuleName = "__bad__"; - return false; // FIXME: Must continue to run to pass the tests, but should not - // have to. -} + if (Opts.OutputFilenames.empty() || + llvm::sys::fs::is_directory(Opts.getSingleOutputFilename())) { + // No output filename was specified, or an output directory was specified. + // Determine the correct output filename. -bool FrontendArgsToOptionsConverter::computeFallbackModuleName() { - if (Opts.RequestedAction == FrontendOptions::ActionType::REPL) { - // Default to a module named "REPL" if we're in REPL mode. - Opts.ModuleName = "REPL"; - return false; - } - if (!Opts.Inputs.hasInputFilenames()) { - Opts.ModuleName = StringRef(); - // FIXME: This is a bug that should not happen, but does in tests. - // The current behavior is needed to pass the tests. - // The compiler should bail out earlier, where "no frontend action was - // selected". - return false; - } - ArrayRef outputFilenames = - getOutputFilenamesFromCommandLineOrFilelist(); + // Note: this should typically only be used when invoking the frontend + // directly, as the driver will always pass -o with an appropriate filename + // if output is required for the requested action. - bool isOutputAUniqueOrdinaryFile = - outputFilenames.size() == 1 && outputFilenames[0] != "-" && - !llvm::sys::fs::is_directory(outputFilenames[0]); - std::string nameToStem = isOutputAUniqueOrdinaryFile - ? outputFilenames[0] - : Opts.Inputs.getFilenameOfFirstInput(); - Opts.ModuleName = llvm::sys::path::stem(nameToStem); - return false; -} + StringRef Suffix; + switch (Opts.RequestedAction) { + case FrontendOptions::ActionType::NoneAction: + break; -bool FrontendArgsToOptionsConverter::computeOutputFilenames() { - assert( - FrontendOptions::doesActionProduceOutput(Opts.RequestedAction) || - !FrontendOptions::doesActionProduceTextualOutput(Opts.RequestedAction)); + case FrontendOptions::ActionType::Parse: + case FrontendOptions::ActionType::Typecheck: + case FrontendOptions::ActionType::DumpParse: + case FrontendOptions::ActionType::DumpInterfaceHash: + case FrontendOptions::ActionType::DumpAST: + case FrontendOptions::ActionType::EmitSyntax: + case FrontendOptions::ActionType::PrintAST: + case FrontendOptions::ActionType::DumpScopeMaps: + case FrontendOptions::ActionType::DumpTypeRefinementContexts: + // Textual modes. + Opts.setOutputFilenameToStdout(); + break; - ArrayRef outputFilenamesFromCommandLineOrFilelist = - getOutputFilenamesFromCommandLineOrFilelist(); + case FrontendOptions::ActionType::EmitPCH: + Suffix = PCH_EXTENSION; + break; - if (outputFilenamesFromCommandLineOrFilelist.size() > 1) { - // WMO, threaded with N files (also someday batch mode). - Opts.OutputFilenames = outputFilenamesFromCommandLineOrFilelist; - return false; - } + case FrontendOptions::ActionType::EmitSILGen: + case FrontendOptions::ActionType::EmitSIL: { + if (Opts.OutputFilenames.empty()) + Opts.setOutputFilenameToStdout(); + else + Suffix = SIL_EXTENSION; + break; + } - if (outputFilenamesFromCommandLineOrFilelist.empty()) { - // When the Frontend is invoked without going through the driver - // (e.g. for testing), it is convenient to derive output filenames from - // input. - return deriveOutputFilenameFromInputFile(); - } + case FrontendOptions::ActionType::EmitSIBGen: + case FrontendOptions::ActionType::EmitSIB: + Suffix = SIB_EXTENSION; + break; - StringRef outputFilename = outputFilenamesFromCommandLineOrFilelist[0]; - if (!llvm::sys::fs::is_directory(outputFilename)) { - // Could be -primary-file (1), or -wmo (non-threaded w/ N (input) files) - Opts.OutputFilenames = outputFilenamesFromCommandLineOrFilelist; - return false; - } - // Only used for testing & when invoking frontend directly. - return deriveOutputFilenameForDirectory(outputFilename); -} + case FrontendOptions::ActionType::MergeModules: + case FrontendOptions::ActionType::EmitModuleOnly: + Suffix = SERIALIZED_MODULE_EXTENSION; + break; -bool FrontendArgsToOptionsConverter::deriveOutputFilenameFromInputFile() { - if (Opts.Inputs.isReadingFromStdin() || - FrontendOptions::doesActionProduceTextualOutput(Opts.RequestedAction)) { - Opts.setOutputFilenameToStdout(); - return false; - } - std::string baseName = determineBaseNameOfOutput(); - if (baseName.empty()) { - if (Opts.RequestedAction != FrontendOptions::ActionType::REPL && - Opts.RequestedAction != FrontendOptions::ActionType::Immediate && - Opts.RequestedAction != FrontendOptions::ActionType::NoneAction) { - Diags.diagnose(SourceLoc(), diag::error_no_output_filename_specified); - return true; + case FrontendOptions::ActionType::Immediate: + case FrontendOptions::ActionType::REPL: + // These modes have no frontend-generated output. + Opts.OutputFilenames.clear(); + break; + + case FrontendOptions::ActionType::EmitAssembly: { + if (Opts.OutputFilenames.empty()) + Opts.setOutputFilenameToStdout(); + else + Suffix = "s"; + break; } - return false; - } - llvm::SmallString<128> path(baseName); - StringRef suffix = FrontendOptions::suffixForPrincipalOutputFileForAction( - Opts.RequestedAction); - llvm::sys::path::replace_extension(path, suffix); - Opts.OutputFilenames.push_back(path.str()); - return false; -} -bool FrontendArgsToOptionsConverter::deriveOutputFilenameForDirectory( - StringRef outputDir) { + case FrontendOptions::ActionType::EmitIR: { + if (Opts.OutputFilenames.empty()) + Opts.setOutputFilenameToStdout(); + else + Suffix = "ll"; + break; + } - std::string baseName = determineBaseNameOfOutput(); - if (baseName.empty()) { - Diags.diagnose(SourceLoc(), diag::error_implicit_output_file_is_directory, - outputDir); - return true; - } - llvm::SmallString<128> path(outputDir); - llvm::sys::path::append(path, baseName); - StringRef suffix = FrontendOptions::suffixForPrincipalOutputFileForAction( - Opts.RequestedAction); - llvm::sys::path::replace_extension(path, suffix); - Opts.OutputFilenames.push_back(path.str()); - return false; -} + case FrontendOptions::ActionType::EmitBC: { + Suffix = "bc"; + break; + } -std::string FrontendArgsToOptionsConverter::determineBaseNameOfOutput() const { - std::string nameToStem; - if (Opts.Inputs.hasAPrimaryInputFile()) { - assert(Opts.Inputs.hasUniquePrimaryInput() && - "Cannot handle multiple primaries yet"); - nameToStem = Opts.Inputs.primaryInputFilenameIfAny(); - } else if (auto UserSpecifiedModuleName = - Args.getLastArg(options::OPT_module_name)) { - nameToStem = UserSpecifiedModuleName->getValue(); - } else if (Opts.Inputs.inputFilenameCount() == 1) { - nameToStem = Opts.Inputs.getFilenameOfFirstInput(); - } else - nameToStem = ""; - - return llvm::sys::path::stem(nameToStem).str(); -} + case FrontendOptions::ActionType::EmitObject: + Suffix = "o"; + break; -void FrontendArgsToOptionsConverter::determineSupplementaryOutputFilenames() { - using namespace options; - auto determineOutputFilename = - [&](std::string &output, OptSpecifier optWithoutPath, - OptSpecifier optWithPath, const char *extension, bool useMainOutput) { - if (const Arg *A = Args.getLastArg(optWithPath)) { - Args.ClaimAllArgs(optWithoutPath); - output = A->getValue(); - return; - } + case FrontendOptions::ActionType::EmitImportedModules: + if (Opts.OutputFilenames.empty()) + Opts.setOutputFilenameToStdout(); + else + Suffix = "importedmodules"; + break; + } - if (!Args.hasArg(optWithoutPath)) - return; + if (!Suffix.empty()) { + // We need to deduce a file name. + + // First, if we're reading from stdin and we don't have a directory, + // output to stdout. + if (Opts.Inputs.isReadingFromStdin() && Opts.OutputFilenames.empty()) + Opts.setOutputFilenameToStdout(); + else { + // We have a suffix, so determine an appropriate name. + StringRef BaseName = + Opts.Inputs.baseNameOfOutput(Args, Opts.ModuleName); + llvm::SmallString<128> Path(Opts.getSingleOutputFilename()); + llvm::sys::path::append(Path, BaseName); + llvm::sys::path::replace_extension(Path, Suffix); + + Opts.setSingleOutputFilename(Path.str()); + } + } - if (useMainOutput && !Opts.OutputFilenames.empty()) { - output = Opts.getSingleOutputFilename(); - return; - } + if (Opts.OutputFilenames.empty()) { + if (Opts.RequestedAction != FrontendOptions::ActionType::REPL && + Opts.RequestedAction != FrontendOptions::ActionType::Immediate && + Opts.RequestedAction != FrontendOptions::ActionType::NoneAction) { + Diags.diagnose(SourceLoc(), diag::error_no_output_filename_specified); + return true; + } + } else if (Opts.isOutputFileDirectory()) { + Diags.diagnose(SourceLoc(), diag::error_implicit_output_file_is_directory, + Opts.getSingleOutputFilename()); + return true; + } + } - if (!output.empty()) - return; + auto determineOutputFilename = [&](std::string &output, + OptSpecifier optWithoutPath, + OptSpecifier optWithPath, + const char *extension, + bool useMainOutput) { + if (const Arg *A = Args.getLastArg(optWithPath)) { + Args.ClaimAllArgs(optWithoutPath); + output = A->getValue(); + return; + } + + if (!Args.hasArg(optWithoutPath)) + return; - llvm::SmallString<128> path(Opts.originalPath()); - llvm::sys::path::replace_extension(path, extension); - output = path.str(); - }; + if (useMainOutput && !Opts.OutputFilenames.empty()) { + output = Opts.getSingleOutputFilename(); + return; + } - determineOutputFilename(Opts.DependenciesFilePath, OPT_emit_dependencies, - OPT_emit_dependencies_path, "d", false); - determineOutputFilename( - Opts.ReferenceDependenciesFilePath, OPT_emit_reference_dependencies, - OPT_emit_reference_dependencies_path, "swiftdeps", false); + if (!output.empty()) + return; + + llvm::SmallString<128> Path(Opts.originalPath()); + llvm::sys::path::replace_extension(Path, extension); + output = Path.str(); + }; + + determineOutputFilename(Opts.DependenciesFilePath, + OPT_emit_dependencies, + OPT_emit_dependencies_path, + "d", false); + determineOutputFilename(Opts.ReferenceDependenciesFilePath, + OPT_emit_reference_dependencies, + OPT_emit_reference_dependencies_path, + "swiftdeps", false); determineOutputFilename(Opts.SerializedDiagnosticsPath, OPT_serialize_diagnostics, - OPT_serialize_diagnostics_path, "dia", false); - determineOutputFilename(Opts.ObjCHeaderOutputPath, OPT_emit_objc_header, - OPT_emit_objc_header_path, "h", false); - determineOutputFilename( - Opts.LoadedModuleTracePath, OPT_emit_loaded_module_trace, - OPT_emit_loaded_module_trace_path, "trace.json", false); + OPT_serialize_diagnostics_path, + "dia", false); + determineOutputFilename(Opts.ObjCHeaderOutputPath, + OPT_emit_objc_header, + OPT_emit_objc_header_path, + "h", false); + determineOutputFilename(Opts.LoadedModuleTracePath, + OPT_emit_loaded_module_trace, + OPT_emit_loaded_module_trace_path, + "trace.json", false); determineOutputFilename(Opts.TBDPath, OPT_emit_tbd, OPT_emit_tbd_path, "tbd", false); @@ -817,108 +680,187 @@ void FrontendArgsToOptionsConverter::determineSupplementaryOutputFilenames() { Opts.FixitsOutputPath = A->getValue(); } - bool isSIB = Opts.RequestedAction == FrontendOptions::ActionType::EmitSIB || + bool IsSIB = Opts.RequestedAction == FrontendOptions::ActionType::EmitSIB || Opts.RequestedAction == FrontendOptions::ActionType::EmitSIBGen; bool canUseMainOutputForModule = Opts.RequestedAction == FrontendOptions::ActionType::MergeModules || Opts.RequestedAction == FrontendOptions::ActionType::EmitModuleOnly || - isSIB; - auto ext = isSIB ? SIB_EXTENSION : SERIALIZED_MODULE_EXTENSION; + IsSIB; + auto ext = IsSIB ? SIB_EXTENSION : SERIALIZED_MODULE_EXTENSION; auto sibOpt = Opts.RequestedAction == FrontendOptions::ActionType::EmitSIB ? OPT_emit_sib : OPT_emit_sibgen; determineOutputFilename(Opts.ModuleOutputPath, - isSIB ? sibOpt : OPT_emit_module, - OPT_emit_module_path, ext, canUseMainOutputForModule); + IsSIB ? sibOpt : OPT_emit_module, + OPT_emit_module_path, + ext, + canUseMainOutputForModule); - determineOutputFilename(Opts.ModuleDocOutputPath, OPT_emit_module_doc, + determineOutputFilename(Opts.ModuleDocOutputPath, + OPT_emit_module_doc, OPT_emit_module_doc_path, - SERIALIZED_MODULE_DOC_EXTENSION, false); -} + SERIALIZED_MODULE_DOC_EXTENSION, + false); -bool FrontendArgsToOptionsConverter::checkForUnusedOutputPaths() const { - if (Opts.hasUnusedDependenciesFilePath()) { - Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_dependencies); - return true; + if (!Opts.DependenciesFilePath.empty()) { + switch (Opts.RequestedAction) { + case FrontendOptions::ActionType::NoneAction: + case FrontendOptions::ActionType::DumpParse: + case FrontendOptions::ActionType::DumpInterfaceHash: + case FrontendOptions::ActionType::DumpAST: + case FrontendOptions::ActionType::EmitSyntax: + case FrontendOptions::ActionType::PrintAST: + case FrontendOptions::ActionType::DumpScopeMaps: + case FrontendOptions::ActionType::DumpTypeRefinementContexts: + case FrontendOptions::ActionType::Immediate: + case FrontendOptions::ActionType::REPL: + Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_dependencies); + return true; + case FrontendOptions::ActionType::Parse: + case FrontendOptions::ActionType::Typecheck: + case FrontendOptions::ActionType::MergeModules: + case FrontendOptions::ActionType::EmitModuleOnly: + case FrontendOptions::ActionType::EmitPCH: + case FrontendOptions::ActionType::EmitSILGen: + case FrontendOptions::ActionType::EmitSIL: + case FrontendOptions::ActionType::EmitSIBGen: + case FrontendOptions::ActionType::EmitSIB: + case FrontendOptions::ActionType::EmitIR: + case FrontendOptions::ActionType::EmitBC: + case FrontendOptions::ActionType::EmitAssembly: + case FrontendOptions::ActionType::EmitObject: + case FrontendOptions::ActionType::EmitImportedModules: + break; + } } - if (Opts.hasUnusedObjCHeaderOutputPath()) { - Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_header); - return true; + + if (!Opts.ObjCHeaderOutputPath.empty()) { + switch (Opts.RequestedAction) { + case FrontendOptions::ActionType::NoneAction: + case FrontendOptions::ActionType::DumpParse: + case FrontendOptions::ActionType::DumpInterfaceHash: + case FrontendOptions::ActionType::DumpAST: + case FrontendOptions::ActionType::EmitSyntax: + case FrontendOptions::ActionType::PrintAST: + case FrontendOptions::ActionType::EmitPCH: + case FrontendOptions::ActionType::DumpScopeMaps: + case FrontendOptions::ActionType::DumpTypeRefinementContexts: + case FrontendOptions::ActionType::Immediate: + case FrontendOptions::ActionType::REPL: + Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_header); + return true; + case FrontendOptions::ActionType::Parse: + case FrontendOptions::ActionType::Typecheck: + case FrontendOptions::ActionType::MergeModules: + case FrontendOptions::ActionType::EmitModuleOnly: + case FrontendOptions::ActionType::EmitSILGen: + case FrontendOptions::ActionType::EmitSIL: + case FrontendOptions::ActionType::EmitSIBGen: + case FrontendOptions::ActionType::EmitSIB: + case FrontendOptions::ActionType::EmitIR: + case FrontendOptions::ActionType::EmitBC: + case FrontendOptions::ActionType::EmitAssembly: + case FrontendOptions::ActionType::EmitObject: + case FrontendOptions::ActionType::EmitImportedModules: + break; + } } - if (Opts.hasUnusedLoadedModuleTracePath()) { - Diags.diagnose(SourceLoc(), - diag::error_mode_cannot_emit_loaded_module_trace); - return true; + + if (!Opts.LoadedModuleTracePath.empty()) { + switch (Opts.RequestedAction) { + case FrontendOptions::ActionType::NoneAction: + case FrontendOptions::ActionType::Parse: + case FrontendOptions::ActionType::DumpParse: + case FrontendOptions::ActionType::DumpInterfaceHash: + case FrontendOptions::ActionType::DumpAST: + case FrontendOptions::ActionType::EmitSyntax: + case FrontendOptions::ActionType::PrintAST: + case FrontendOptions::ActionType::DumpScopeMaps: + case FrontendOptions::ActionType::DumpTypeRefinementContexts: + case FrontendOptions::ActionType::Immediate: + case FrontendOptions::ActionType::REPL: + Diags.diagnose(SourceLoc(), + diag::error_mode_cannot_emit_loaded_module_trace); + return true; + case FrontendOptions::ActionType::Typecheck: + case FrontendOptions::ActionType::MergeModules: + case FrontendOptions::ActionType::EmitModuleOnly: + case FrontendOptions::ActionType::EmitPCH: + case FrontendOptions::ActionType::EmitSILGen: + case FrontendOptions::ActionType::EmitSIL: + case FrontendOptions::ActionType::EmitSIBGen: + case FrontendOptions::ActionType::EmitSIB: + case FrontendOptions::ActionType::EmitIR: + case FrontendOptions::ActionType::EmitBC: + case FrontendOptions::ActionType::EmitAssembly: + case FrontendOptions::ActionType::EmitObject: + case FrontendOptions::ActionType::EmitImportedModules: + break; + } } - if (Opts.hasUnusedModuleOutputPath()) { - Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_module); - return true; + + if (!Opts.ModuleOutputPath.empty() || + !Opts.ModuleDocOutputPath.empty()) { + switch (Opts.RequestedAction) { + case FrontendOptions::ActionType::NoneAction: + case FrontendOptions::ActionType::Parse: + case FrontendOptions::ActionType::Typecheck: + case FrontendOptions::ActionType::DumpParse: + case FrontendOptions::ActionType::DumpInterfaceHash: + case FrontendOptions::ActionType::DumpAST: + case FrontendOptions::ActionType::EmitSyntax: + case FrontendOptions::ActionType::PrintAST: + case FrontendOptions::ActionType::EmitPCH: + case FrontendOptions::ActionType::DumpScopeMaps: + case FrontendOptions::ActionType::DumpTypeRefinementContexts: + case FrontendOptions::ActionType::EmitSILGen: + case FrontendOptions::ActionType::Immediate: + case FrontendOptions::ActionType::REPL: + if (!Opts.ModuleOutputPath.empty()) + Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_module); + else + Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_module_doc); + return true; + case FrontendOptions::ActionType::MergeModules: + case FrontendOptions::ActionType::EmitModuleOnly: + case FrontendOptions::ActionType::EmitSIL: + case FrontendOptions::ActionType::EmitSIBGen: + case FrontendOptions::ActionType::EmitSIB: + case FrontendOptions::ActionType::EmitIR: + case FrontendOptions::ActionType::EmitBC: + case FrontendOptions::ActionType::EmitAssembly: + case FrontendOptions::ActionType::EmitObject: + case FrontendOptions::ActionType::EmitImportedModules: + break; + } } - if (Opts.hasUnusedModuleDocOutputPath()) { - Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_module_doc); - return true; + + if (const Arg *A = Args.getLastArg(OPT_module_link_name)) { + Opts.ModuleLinkName = A->getValue(); } - return false; -} -void FrontendArgsToOptionsConverter::computeImportObjCHeaderOptions() { - using namespace options; + Opts.AlwaysSerializeDebuggingOptions |= + Args.hasArg(OPT_serialize_debugging_options); + Opts.EnableSourceImport |= Args.hasArg(OPT_enable_source_import); + Opts.ImportUnderlyingModule |= Args.hasArg(OPT_import_underlying_module); + Opts.EnableSerializationNestedTypeLookupTable &= + !Args.hasArg(OPT_disable_serialization_nested_type_lookup_table); + if (const Arg *A = Args.getLastArgNoClaim(OPT_import_objc_header)) { Opts.ImplicitObjCHeaderPath = A->getValue(); Opts.SerializeBridgingHeader |= - !Opts.Inputs.hasPrimaryInputs() && !Opts.ModuleOutputPath.empty(); + !Opts.Inputs.havePrimaryInputs() && !Opts.ModuleOutputPath.empty(); } -} -void FrontendArgsToOptionsConverter::computeImplicitImportModuleNames() { - using namespace options; + for (const Arg *A : Args.filtered(OPT_import_module)) { Opts.ImplicitImportModuleNames.push_back(A->getValue()); } -} -void FrontendArgsToOptionsConverter::computeLLVMArgs() { - using namespace options; + for (const Arg *A : Args.filtered(OPT_Xllvm)) { Opts.LLVMArgs.push_back(A->getValue()); } -} - -ArrayRef -FrontendArgsToOptionsConverter::getOutputFilenamesFromCommandLineOrFilelist() { - if (cachedOutputFilenamesFromCommandLineOrFilelist) { - return *cachedOutputFilenamesFromCommandLineOrFilelist; - } - if (const Arg *A = Args.getLastArg(options::OPT_output_filelist)) { - assert(!Args.hasArg(options::OPT_o) && - "don't use -o with -output-filelist"); - cachedOutputFilenamesFromCommandLineOrFilelist.emplace( - readOutputFileList(A->getValue())); - } else { - cachedOutputFilenamesFromCommandLineOrFilelist.emplace( - Args.getAllArgValues(options::OPT_o)); - } - return *cachedOutputFilenamesFromCommandLineOrFilelist; -} - -/// Try to read an output file list file. -std::vector FrontendArgsToOptionsConverter::readOutputFileList( - const StringRef filelistPath) const { - llvm::ErrorOr> buffer = - llvm::MemoryBuffer::getFile(filelistPath); - if (!buffer) { - Diags.diagnose(SourceLoc(), diag::cannot_open_file, filelistPath, - buffer.getError().message()); - } - std::vector outputFiles; - for (StringRef line : make_range(llvm::line_iterator(*buffer.get()), {})) { - outputFiles.push_back(line.str()); - } - return outputFiles; -} - -static bool ParseFrontendArgs(FrontendOptions &opts, ArgList &args, - DiagnosticEngine &diags) { - return FrontendArgsToOptionsConverter(diags, args, opts).convert(); + return false; } static void diagnoseSwiftVersion(Optional &vers, Arg *verArg, @@ -1650,7 +1592,7 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args, } else if (const Optional filename = FrontendOpts.Inputs.getOptionalUniquePrimaryInputFilename()) { Opts.MainInputFilename = filename.getValue(); - } else if (FrontendOpts.Inputs.hasUniqueInputFilename()) { + } else if (FrontendOpts.Inputs.haveUniqueInputFilename()) { Opts.MainInputFilename = FrontendOpts.Inputs.getFilenameOfFirstInput(); } Opts.OutputFilenames = FrontendOpts.OutputFilenames; @@ -1882,36 +1824,36 @@ CompilerInvocation::loadFromSerializedAST(StringRef data) { llvm::ErrorOr> CompilerInvocation::setUpInputForSILTool( - StringRef inputFilename, StringRef moduleNameArg, + StringRef InputFilename, StringRef ModuleNameArg, bool alwaysSetModuleToMain, serialization::ExtendedValidationInfo &extendedInfo) { // Load the input file. - llvm::ErrorOr> fileBufOrErr = - llvm::MemoryBuffer::getFileOrSTDIN(inputFilename); - if (!fileBufOrErr) { - return fileBufOrErr; + llvm::ErrorOr> FileBufOrErr = + llvm::MemoryBuffer::getFileOrSTDIN(InputFilename); + if (!FileBufOrErr) { + return FileBufOrErr; } // If it looks like we have an AST, set the source file kind to SIL and the // name of the module to the file's name. - addInputBuffer(fileBufOrErr.get().get()); + addInputBuffer(FileBufOrErr.get().get()); auto result = serialization::validateSerializedAST( - fileBufOrErr.get()->getBuffer(), &extendedInfo); - bool hasSerializedAST = result.status == serialization::Status::Valid; - - if (hasSerializedAST) { - const StringRef stem = !moduleNameArg.empty() - ? moduleNameArg - : llvm::sys::path::stem(inputFilename); - setModuleName(stem); + FileBufOrErr.get()->getBuffer(), &extendedInfo); + bool HasSerializedAST = result.status == serialization::Status::Valid; + + if (HasSerializedAST) { + const StringRef Stem = !ModuleNameArg.empty() + ? ModuleNameArg + : llvm::sys::path::stem(InputFilename); + setModuleName(Stem); setInputKind(InputFileKind::IFK_Swift_Library); } else { - const StringRef name = (alwaysSetModuleToMain || moduleNameArg.empty()) + const StringRef Name = (alwaysSetModuleToMain || ModuleNameArg.empty()) ? "main" - : moduleNameArg; - setModuleName(name); + : ModuleNameArg; + setModuleName(Name); setInputKind(InputFileKind::IFK_SIL); } - return fileBufOrErr; + return FileBufOrErr; } diff --git a/lib/Frontend/Frontend.cpp b/lib/Frontend/Frontend.cpp index 3857efa8d51ce..ac75c2ae6e633 100644 --- a/lib/Frontend/Frontend.cpp +++ b/lib/Frontend/Frontend.cpp @@ -272,7 +272,6 @@ void CompilerInstance::performSema() { Context->LoadedModules[MainModule->getName()] = getMainModule(); if (Invocation.getInputKind() == InputFileKind::IFK_SIL) { - assert(!InputSourceCodeBufferIDs.empty()); assert(InputSourceCodeBufferIDs.size() == 1); assert(MainBufferID != NO_SUCH_BUFFER); createSILModule(); @@ -741,7 +740,7 @@ bool CompilerInstance::setUpForFileAt(unsigned i) { if (SILMode || (MainMode && filename(File) == "main.swift")) MainBufferID = ExistingBufferID.getValue(); - if (Invocation.getFrontendOptions().Inputs.isInputPrimary(i)) + if (Invocation.getFrontendOptions().Inputs.isPrimaryInputAFileAt(i)) PrimaryBufferID = ExistingBufferID.getValue(); return false; // replaced by a memory buffer. @@ -783,7 +782,7 @@ bool CompilerInstance::setUpForFileAt(unsigned i) { if (SILMode || (MainMode && filename(File) == "main.swift")) MainBufferID = BufferID; - if (Invocation.getFrontendOptions().Inputs.isInputPrimary(i)) + if (Invocation.getFrontendOptions().Inputs.isPrimaryInputAFileAt(i)) PrimaryBufferID = BufferID; return false; diff --git a/lib/Frontend/FrontendOptions.cpp b/lib/Frontend/FrontendOptions.cpp index 25b9face0a325..8ef2d3d407c1f 100644 --- a/lib/Frontend/FrontendOptions.cpp +++ b/lib/Frontend/FrontendOptions.cpp @@ -28,7 +28,7 @@ using namespace swift; using namespace llvm::opt; bool FrontendInputs::shouldTreatAsLLVM() const { - if (hasUniqueInputFilename()) { + if (haveUniqueInputFilename()) { StringRef Input(getFilenameOfFirstInput()); return llvm::sys::path::extension(Input).endswith(LLVM_BC_EXTENSION) || llvm::sys::path::extension(Input).endswith(LLVM_IR_EXTENSION); @@ -36,8 +36,21 @@ bool FrontendInputs::shouldTreatAsLLVM() const { return false; } +StringRef FrontendInputs::baseNameOfOutput(const llvm::opt::ArgList &Args, + StringRef ModuleName) const { + StringRef pifn = primaryInputFilenameIfAny(); + if (!pifn.empty()) { + return llvm::sys::path::stem(pifn); + } + bool UserSpecifiedModuleName = Args.getLastArg(options::OPT_module_name); + if (!UserSpecifiedModuleName && haveUniqueInputFilename()) { + return llvm::sys::path::stem(getFilenameOfFirstInput()); + } + return ModuleName; +} + bool FrontendInputs::shouldTreatAsSIL() const { - if (hasUniqueInputFilename()) { + if (haveUniqueInputFilename()) { // If we have exactly one input filename, and its extension is "sil", // treat the input as SIL. StringRef Input(getFilenameOfFirstInput()); @@ -53,36 +66,36 @@ bool FrontendInputs::shouldTreatAsSIL() const { return false; } -bool FrontendInputs::verifyInputs(DiagnosticEngine &diags, bool treatAsSIL, +bool FrontendInputs::verifyInputs(DiagnosticEngine &Diags, bool TreatAsSIL, bool isREPLRequested, bool isNoneRequested) const { if (isREPLRequested) { - if (hasInputFilenames()) { - diags.diagnose(SourceLoc(), diag::error_repl_requires_no_input_files); + if (haveInputFilenames()) { + Diags.diagnose(SourceLoc(), diag::error_repl_requires_no_input_files); return true; } - } else if (treatAsSIL && hasPrimaryInputs()) { + } else if (TreatAsSIL && havePrimaryInputs()) { // If we have the SIL as our primary input, we can waive the one file // requirement as long as all the other inputs are SIBs. for (unsigned i = 0, e = inputFilenameCount(); i != e; ++i) { if (i == getOptionalUniquePrimaryInput()->Index) continue; - StringRef file(getInputFilenames()[i]); - if (!llvm::sys::path::extension(file).endswith(SIB_EXTENSION)) { - diags.diagnose(SourceLoc(), + StringRef File(getInputFilenames()[i]); + if (!llvm::sys::path::extension(File).endswith(SIB_EXTENSION)) { + Diags.diagnose(SourceLoc(), diag::error_mode_requires_one_sil_multi_sib); return true; } } - } else if (treatAsSIL) { - if (!hasUniqueInputFilename()) { - diags.diagnose(SourceLoc(), diag::error_mode_requires_one_input_file); + } else if (TreatAsSIL) { + if (!haveUniqueInputFilename()) { + Diags.diagnose(SourceLoc(), diag::error_mode_requires_one_input_file); return true; } } else if (!isNoneRequested) { - if (!hasInputFilenames()) { - diags.diagnose(SourceLoc(), diag::error_mode_requires_an_input_file); + if (!haveInputFilenames()) { + Diags.diagnose(SourceLoc(), diag::error_mode_requires_an_input_file); return true; } } @@ -182,9 +195,37 @@ void FrontendOptions::forAllOutputPaths( } } +void FrontendOptions::setModuleName(DiagnosticEngine &Diags, + const llvm::opt::ArgList &Args) { + const Arg *A = Args.getLastArg(options::OPT_module_name); + if (A) { + ModuleName = A->getValue(); + } else if (ModuleName.empty()) { + // The user did not specify a module name, so determine a default fallback + // based on other options. + + // Note: this code path will only be taken when running the frontend + // directly; the driver should always pass -module-name when invoking the + // frontend. + ModuleName = determineFallbackModuleName(); + } + + if (Lexer::isIdentifier(ModuleName) && + (ModuleName != STDLIB_NAME || ParseStdlib)) { + return; + } + if (!actionHasOutput() || isCompilingExactlyOneSwiftFile()) { + ModuleName = "main"; + return; + } + auto DID = (ModuleName == STDLIB_NAME) ? diag::error_stdlib_module_name + : diag::error_bad_module_name; + Diags.diagnose(SourceLoc(), DID, ModuleName, A == nullptr); + ModuleName = "__bad__"; +} StringRef FrontendOptions::originalPath() const { - if (hasNamedOutputFile()) + if (haveNamedOutputFile()) // Put the serialized diagnostics file next to the output file. return getSingleOutputFilename(); @@ -195,278 +236,57 @@ StringRef FrontendOptions::originalPath() const { return !fn.empty() ? llvm::sys::path::filename(fn) : StringRef(ModuleName); } -bool FrontendOptions::isOutputFileDirectory() const { - return hasNamedOutputFile() && - llvm::sys::fs::is_directory(getSingleOutputFilename()); -} - -const char * -FrontendOptions::suffixForPrincipalOutputFileForAction(ActionType action) { - switch (action) { - case ActionType::NoneAction: - return nullptr; - - case ActionType::Parse: - case ActionType::Typecheck: - case ActionType::DumpParse: - case ActionType::DumpInterfaceHash: - case ActionType::DumpAST: - case ActionType::EmitSyntax: - case ActionType::PrintAST: - case ActionType::DumpScopeMaps: - case ActionType::DumpTypeRefinementContexts: - return nullptr; - - case ActionType::EmitPCH: - return PCH_EXTENSION; - - case ActionType::EmitSILGen: - case ActionType::EmitSIL: - return SIL_EXTENSION; - - case ActionType::EmitSIBGen: - case ActionType::EmitSIB: - return SIB_EXTENSION; - - case ActionType::MergeModules: - case ActionType::EmitModuleOnly: - return SERIALIZED_MODULE_EXTENSION; - - case ActionType::Immediate: - case ActionType::REPL: - // These modes have no frontend-generated output. - return nullptr; - - case ActionType::EmitAssembly: - return "s"; - - case ActionType::EmitIR: - return "ll"; - - case ActionType::EmitBC: - return "bc"; - - case ActionType::EmitObject: - return "o"; - - case ActionType::EmitImportedModules: - return "importedmodules"; +StringRef FrontendOptions::determineFallbackModuleName() const { + // Note: this code path will only be taken when running the frontend + // directly; the driver should always pass -module-name when invoking the + // frontend. + if (RequestedAction == FrontendOptions::ActionType::REPL) { + // Default to a module named "REPL" if we're in REPL mode. + return "REPL"; } -} - -bool FrontendOptions::hasUnusedDependenciesFilePath() const { - return !DependenciesFilePath.empty() && - !canActionEmitDependencies(RequestedAction); -} - -bool FrontendOptions::canActionEmitDependencies(ActionType action) { - switch (action) { - case ActionType::NoneAction: - case ActionType::DumpParse: - case ActionType::DumpInterfaceHash: - case ActionType::DumpAST: - case ActionType::EmitSyntax: - case ActionType::PrintAST: - case ActionType::DumpScopeMaps: - case ActionType::DumpTypeRefinementContexts: - case ActionType::Immediate: - case ActionType::REPL: - return false; - case ActionType::Parse: - case ActionType::Typecheck: - case ActionType::MergeModules: - case ActionType::EmitModuleOnly: - case ActionType::EmitPCH: - case ActionType::EmitSILGen: - case ActionType::EmitSIL: - case ActionType::EmitSIBGen: - case ActionType::EmitSIB: - case ActionType::EmitIR: - case ActionType::EmitBC: - case ActionType::EmitAssembly: - case ActionType::EmitObject: - case ActionType::EmitImportedModules: - return true; + // In order to pass Driver/options.swift test must leave ModuleName empty + if (!Inputs.haveInputFilenames()) { + return StringRef(); } + StringRef OutputFilename = getSingleOutputFilename(); + bool useOutputFilename = isOutputFilePlainFile(); + return llvm::sys::path::stem( + useOutputFilename ? OutputFilename + : StringRef(Inputs.getFilenameOfFirstInput())); } -bool FrontendOptions::hasUnusedObjCHeaderOutputPath() const { - return !ObjCHeaderOutputPath.empty() && !canActionEmitHeader(RequestedAction); -} - -bool FrontendOptions::canActionEmitHeader(ActionType action) { - switch (action) { - case ActionType::NoneAction: - case ActionType::DumpParse: - case ActionType::DumpInterfaceHash: - case ActionType::DumpAST: - case ActionType::EmitSyntax: - case ActionType::PrintAST: - case ActionType::EmitPCH: - case ActionType::DumpScopeMaps: - case ActionType::DumpTypeRefinementContexts: - case ActionType::Immediate: - case ActionType::REPL: - return false; - case ActionType::Parse: - case ActionType::Typecheck: - case ActionType::MergeModules: - case ActionType::EmitModuleOnly: - case ActionType::EmitSILGen: - case ActionType::EmitSIL: - case ActionType::EmitSIBGen: - case ActionType::EmitSIB: - case ActionType::EmitIR: - case ActionType::EmitBC: - case ActionType::EmitAssembly: - case ActionType::EmitObject: - case ActionType::EmitImportedModules: - return true; +/// Try to read an output file list file. +static void readOutputFileList(DiagnosticEngine &diags, + std::vector &outputFiles, + const llvm::opt::Arg *filelistPath) { + llvm::ErrorOr> buffer = + llvm::MemoryBuffer::getFile(filelistPath->getValue()); + if (!buffer) { + diags.diagnose(SourceLoc(), diag::cannot_open_file, + filelistPath->getValue(), buffer.getError().message()); } -} - -bool FrontendOptions::hasUnusedLoadedModuleTracePath() const { - return !LoadedModuleTracePath.empty() && - !canActionEmitLoadedModuleTrace(RequestedAction); -} - -bool FrontendOptions::canActionEmitLoadedModuleTrace(ActionType action) { - switch (action) { - case ActionType::NoneAction: - case ActionType::Parse: - case ActionType::DumpParse: - case ActionType::DumpInterfaceHash: - case ActionType::DumpAST: - case ActionType::EmitSyntax: - case ActionType::PrintAST: - case ActionType::DumpScopeMaps: - case ActionType::DumpTypeRefinementContexts: - case ActionType::Immediate: - case ActionType::REPL: - return false; - case ActionType::Typecheck: - case ActionType::MergeModules: - case ActionType::EmitModuleOnly: - case ActionType::EmitPCH: - case ActionType::EmitSILGen: - case ActionType::EmitSIL: - case ActionType::EmitSIBGen: - case ActionType::EmitSIB: - case ActionType::EmitIR: - case ActionType::EmitBC: - case ActionType::EmitAssembly: - case ActionType::EmitObject: - case ActionType::EmitImportedModules: - return true; + for (StringRef line : make_range(llvm::line_iterator(*buffer.get()), {})) { + outputFiles.push_back(line); } } -bool FrontendOptions::hasUnusedModuleOutputPath() const { - return !ModuleOutputPath.empty() && !canActionEmitModule(RequestedAction); -} - -bool FrontendOptions::hasUnusedModuleDocOutputPath() const { - return !ModuleDocOutputPath.empty() && !canActionEmitModule(RequestedAction); -} - -bool FrontendOptions::canActionEmitModule(ActionType action) { - switch (action) { - case ActionType::NoneAction: - case ActionType::Parse: - case ActionType::Typecheck: - case ActionType::DumpParse: - case ActionType::DumpInterfaceHash: - case ActionType::DumpAST: - case ActionType::EmitSyntax: - case ActionType::PrintAST: - case ActionType::EmitPCH: - case ActionType::DumpScopeMaps: - case ActionType::DumpTypeRefinementContexts: - case ActionType::EmitSILGen: - case ActionType::Immediate: - case ActionType::REPL: - return false; - case ActionType::MergeModules: - case ActionType::EmitModuleOnly: - case ActionType::EmitSIL: - case ActionType::EmitSIBGen: - case ActionType::EmitSIB: - case ActionType::EmitIR: - case ActionType::EmitBC: - case ActionType::EmitAssembly: - case ActionType::EmitObject: - case ActionType::EmitImportedModules: - return true; +void FrontendOptions::setOutputFileList(swift::DiagnosticEngine &Diags, + const llvm::opt::ArgList &Args) { + if (const Arg *A = Args.getLastArg(options::OPT_output_filelist)) { + readOutputFileList(Diags, OutputFilenames, A); + assert(!Args.hasArg(options::OPT_o) && + "don't use -o with -output-filelist"); + } else { + OutputFilenames = Args.getAllArgValues(options::OPT_o); } } -bool FrontendOptions::canActionEmitModuleDoc(ActionType action) { - return canActionEmitModule(action); -} - -bool FrontendOptions::doesActionProduceOutput(ActionType action) { - switch (action) { - // FIXME: Some of these don't actually produce output - // but for now stay consistent with the status quo. - case ActionType::NoneAction: - case ActionType::EmitPCH: - case ActionType::EmitSIBGen: - case ActionType::EmitSIB: - case ActionType::MergeModules: - case ActionType::EmitModuleOnly: - case ActionType::EmitBC: - case ActionType::EmitObject: - case ActionType::Parse: - case ActionType::Typecheck: - case ActionType::DumpParse: - case ActionType::DumpInterfaceHash: - case ActionType::DumpAST: - case ActionType::EmitSyntax: - case ActionType::PrintAST: - case ActionType::DumpScopeMaps: - case ActionType::DumpTypeRefinementContexts: - case ActionType::EmitImportedModules: - case ActionType::EmitSILGen: - case ActionType::EmitSIL: - case ActionType::EmitAssembly: - case ActionType::EmitIR: - return true; - - case ActionType::Immediate: - case ActionType::REPL: - // These modes have no frontend-generated output. - return false; - } +bool FrontendOptions::isOutputFileDirectory() const { + return haveNamedOutputFile() && + llvm::sys::fs::is_directory(getSingleOutputFilename()); } -bool FrontendOptions::doesActionProduceTextualOutput(ActionType action) { - switch (action) { - case ActionType::NoneAction: - case ActionType::EmitPCH: - case ActionType::EmitSIBGen: - case ActionType::EmitSIB: - case ActionType::MergeModules: - case ActionType::EmitModuleOnly: - case ActionType::EmitBC: - case ActionType::EmitObject: - case ActionType::Immediate: - case ActionType::REPL: - return false; - - case ActionType::Parse: - case ActionType::Typecheck: - case ActionType::DumpParse: - case ActionType::DumpInterfaceHash: - case ActionType::DumpAST: - case ActionType::EmitSyntax: - case ActionType::PrintAST: - case ActionType::DumpScopeMaps: - case ActionType::DumpTypeRefinementContexts: - case ActionType::EmitImportedModules: - case ActionType::EmitSILGen: - case ActionType::EmitSIL: - case ActionType::EmitAssembly: - case ActionType::EmitIR: - return true; - } +bool FrontendOptions::isOutputFilePlainFile() const { + return haveNamedOutputFile() && + !llvm::sys::fs::is_directory(getSingleOutputFilename()); } diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index 1e7cf9de5081a..a042a3c9fdd42 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -542,7 +542,7 @@ static bool performCompile(CompilerInstance &Instance, auto &LLVMContext = getGlobalLLVMContext(); // Load in bitcode file. - assert(Invocation.getFrontendOptions().Inputs.hasUniqueInputFilename() && + assert(Invocation.getFrontendOptions().Inputs.haveUniqueInputFilename() && "We expect a single input for bitcode input!"); llvm::ErrorOr> FileBufOrErr = llvm::MemoryBuffer::getFileOrSTDIN( @@ -777,7 +777,7 @@ static bool performCompile(CompilerInstance &Instance, auto SASTF = dyn_cast(File); return SASTF && SASTF->isSIB(); }; - if (opts.Inputs.hasAPrimaryInputFile()) { + if (opts.Inputs.haveAPrimaryInputFile()) { FileUnit *PrimaryFile = PrimarySourceFile; if (!PrimaryFile) { auto Index = opts.Inputs.getRequiredUniquePrimaryInput().Index; diff --git a/tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp b/tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp index ab2283e0bc1f3..0d16d956bba56 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp @@ -83,7 +83,7 @@ struct InvocationOptions { // Assert invocation with a primary file. We want to avoid full typechecking // for all files. assert(!this->PrimaryFile.empty()); - assert(this->Invok.getFrontendOptions().Inputs.hasUniquePrimaryInput() && + assert(this->Invok.getFrontendOptions().Inputs.haveUniquePrimaryInput() && "Must have exactly one primary input for code completion, etc."); } @@ -355,7 +355,7 @@ static void setModuleName(CompilerInvocation &Invocation) { StringRef Filename = Invocation.getOutputFilename(); if (Filename.empty()) { - if (!Invocation.getFrontendOptions().Inputs.hasInputFilenames()) { + if (!Invocation.getFrontendOptions().Inputs.haveInputFilenames()) { Invocation.setModuleName("__main__"); return; } diff --git a/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp b/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp index 501641feafa4a..2b6795c29137e 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp @@ -144,7 +144,7 @@ static bool swiftCodeCompleteImpl(SwiftLangSupport &Lang, if (Failed) { return false; } - if (!Invocation.getFrontendOptions().Inputs.hasInputFilenames()) { + if (!Invocation.getFrontendOptions().Inputs.haveInputFilenames()) { Error = "no input filenames specified"; return false; } diff --git a/tools/SourceKit/lib/SwiftLang/SwiftIndexing.cpp b/tools/SourceKit/lib/SwiftLang/SwiftIndexing.cpp index 918bbf7922f03..a4018bd56b7a9 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftIndexing.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftIndexing.cpp @@ -279,7 +279,7 @@ void SwiftLangSupport::indexSource(StringRef InputFile, return; } - if (!Invocation.getFrontendOptions().Inputs.hasInputFilenames()) { + if (!Invocation.getFrontendOptions().Inputs.haveInputFilenames()) { IdxConsumer.failed("no input filenames specified"); return; } diff --git a/tools/driver/modulewrap_main.cpp b/tools/driver/modulewrap_main.cpp index 397a394c46f45..9742b2785682a 100644 --- a/tools/driver/modulewrap_main.cpp +++ b/tools/driver/modulewrap_main.cpp @@ -43,7 +43,7 @@ class ModuleWrapInvocation { std::vector InputFilenames; public: - bool hasUniqueInputFilename() const { return InputFilenames.size() == 1; } + bool haveUniqueInputFilename() const { return InputFilenames.size() == 1; } const std::string &getFilenameOfFirstInput() const { return InputFilenames[0]; } @@ -131,7 +131,7 @@ int modulewrap_main(ArrayRef Args, const char *Argv0, return 1; } - if (!Invocation.hasUniqueInputFilename()) { + if (!Invocation.haveUniqueInputFilename()) { Instance.getDiags().diagnose(SourceLoc(), diag::error_mode_requires_one_input_file); return 1;