Skip to content

[Batch Mode] Move supplementary output paths into a dedicated structure in FrontendInputsAndOutputs (3) #14402

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
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
3 changes: 3 additions & 0 deletions include/swift/AST/DiagnosticsFrontend.def
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ ERROR(error_index_failed_status_check,none,
ERROR(error_index_inputs_more_than_outputs,none,
"index output filenames do not match input source files", ())

ERROR(error_wrong_number_of_arguments,none,
"wrong number of '%0' arguments (expected %1, got %2)", (StringRef, int, int))

ERROR(error_formatting_multiple_file_ranges,none,
"file ranges don't support multiple input files", ())

Expand Down
4 changes: 2 additions & 2 deletions include/swift/Frontend/ArgsToFrontendOptionsConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ArgsToFrontendOptionsConverter {
void computeDebugTimeOptions();
bool computeFallbackModuleName();
bool computeModuleName();
bool computeOutputFilenames();
bool computeMainAndSupplementaryOutputFilenames();
void computeDumpScopeMapLocations();
void computeHelpOptions();
void computeImplicitImportModuleNames();
Expand All @@ -52,7 +52,7 @@ class ArgsToFrontendOptionsConverter {

bool setUpForSILOrLLVM();

void determineSupplementaryOutputFilenames();
bool checkUnusedSupplementaryOutputPaths() const;

/// \returns the output filenames on the command line or in the output
/// filelist, or an empty vector if there were neither -o's nor an output
Expand Down
64 changes: 63 additions & 1 deletion include/swift/Frontend/ArgsToFrontendOutputsConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "swift/AST/DiagnosticEngine.h"
#include "swift/Basic/LLVM.h"
#include "swift/Frontend/FrontendOptions.h"
#include "swift/Frontend/SupplementaryOutputPaths.h"
#include "swift/Option/Options.h"
#include "llvm/Option/ArgList.h"

Expand All @@ -41,7 +42,8 @@ class ArgsToFrontendOutputsConverter {
: Args(args), ModuleName(moduleName), InputsAndOutputs(inputsAndOutputs),
Diags(diags) {}

Optional<std::vector<std::string>> convert();
bool convert(std::vector<std::string> &mainOutputs,
SupplementaryOutputPaths &supplementaryOutputs);

/// Try to read an output file list file.
/// \returns `None` if it could not open the filelist.
Expand Down Expand Up @@ -108,6 +110,66 @@ class OutputFilesComputer {
std::string deriveOutputFileFromParts(StringRef dir, StringRef base) const;
};

class SupplementaryOutputPathsComputer {
const llvm::opt::ArgList &Args;
DiagnosticEngine &Diags;
const FrontendInputsAndOutputs &InputsAndOutputs;
ArrayRef<std::string> OutputFiles;
StringRef ModuleName;

const FrontendOptions::ActionType RequestedAction;

public:
SupplementaryOutputPathsComputer(
const llvm::opt::ArgList &args, DiagnosticEngine &diags,
const FrontendInputsAndOutputs &inputsAndOutputs,
ArrayRef<std::string> outputFiles, StringRef moduleName);
Optional<std::vector<SupplementaryOutputPaths>> computeOutputPaths() const;

private:
/// \Return a set of supplementary output paths for each input that might
/// produce supplementary outputs, or None to signal an error.
/// \note
/// At present, only one input can produce supplementary outputs, but
/// in the future, batch-mode will support multiple primary inputs and thus,
/// multiple sets of supplementary outputs. This function is written with that
/// future in mind.
/// \par
/// The paths are derived from arguments
/// such as -emit-module-path. These are not the final computed paths,
/// merely the ones passed in via the command line.
/// \note
/// In the future, these will also include those passed in via whatever
/// filelist scheme gets implemented to handle cases where the command line
/// arguments become burdensome.
Optional<std::vector<SupplementaryOutputPaths>>
getSupplementaryOutputPathsFromArguments() const;

/// Given an ID corresponding to supplementary output argument
/// (e.g. -emit-module-path), collect all such paths, and ensure
/// there are the right number of them.
Optional<std::vector<std::string>>
getSupplementaryFilenamesFromArguments(options::ID pathID) const;

Optional<SupplementaryOutputPaths> computeOutputPathsForOneInput(
StringRef outputFilename,
const SupplementaryOutputPaths &pathsFromFilelists,
const InputFile &) const;

StringRef deriveDefaultSupplementaryOutputPathExcludingExtension(
StringRef outputFilename, const InputFile &) const;

/// \return empty string if no output file.
std::string determineSupplementaryOutputFilename(
options::ID emitOpt, std::string pathFromArgumentsOrFilelists,
StringRef extension, StringRef mainOutputIfUsable,
StringRef defaultSupplementaryOutputPathExcludingExtension) const;

void deriveModulePathParameters(options::ID &emitOption,
std::string &extension,
std::string &mainOutputIfUsable) const;
};

} // namespace swift

#endif /* SWIFT_FRONTEND_ARGSTOFRONTENDOUTPUTSCONVERTER_H */
6 changes: 4 additions & 2 deletions include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,12 @@ class CompilerInvocation {
}

void setSerializedDiagnosticsPath(StringRef Path) {
FrontendOpts.SerializedDiagnosticsPath = Path;
FrontendOpts.InputsAndOutputs.supplementaryOutputs()
.SerializedDiagnosticsPath = Path;
}
StringRef getSerializedDiagnosticsPath() const {
return FrontendOpts.SerializedDiagnosticsPath;
return FrontendOpts.InputsAndOutputs.supplementaryOutputs()
.SerializedDiagnosticsPath;
}

LangOptions &getLangOptions() {
Expand Down
26 changes: 25 additions & 1 deletion include/swift/Frontend/FrontendInputsAndOutputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "swift/AST/Module.h"
#include "swift/Frontend/InputFile.h"
#include "swift/Frontend/SupplementaryOutputPaths.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/MapVector.h"

Expand Down Expand Up @@ -43,10 +44,19 @@ class FrontendInputsAndOutputs {
/// Punt where needed to enable batch mode experiments.
bool AreBatchModeChecksBypassed = false;

SupplementaryOutputPaths SupplementaryOutputs;

public:
bool areBatchModeChecksBypassed() const { return AreBatchModeChecksBypassed; }
void setBypassBatchModeChecks(bool bbc) { AreBatchModeChecksBypassed = bbc; }

const SupplementaryOutputPaths &supplementaryOutputs() const {
return SupplementaryOutputs;
}
SupplementaryOutputPaths &supplementaryOutputs() {
return SupplementaryOutputs;
}

FrontendInputsAndOutputs() = default;
FrontendInputsAndOutputs(const FrontendInputsAndOutputs &other);
FrontendInputsAndOutputs &operator=(const FrontendInputsAndOutputs &other);
Expand Down Expand Up @@ -164,7 +174,9 @@ class FrontendInputsAndOutputs {
private:
friend class ArgsToFrontendOptionsConverter;

void setMainOutputs(ArrayRef<std::string> outputFiles);
void
setMainAndSupplementaryOutputs(ArrayRef<std::string> outputFiles,
SupplementaryOutputPaths supplementaryOutputs);

public:
unsigned countOfInputsProducingMainOutputs() const;
Expand Down Expand Up @@ -193,8 +205,20 @@ class FrontendInputsAndOutputs {

// Supplementary outputs

unsigned countOfFilesProducingSupplementaryOutput() const;

void forEachInputProducingSupplementaryOutput(
llvm::function_ref<void(const InputFile &)> fn) const;

bool hasDependenciesPath() const;
bool hasReferenceDependenciesPath() const;
bool hasObjCHeaderOutputPath() const;
bool hasLoadedModuleTracePath() const;
bool hasModuleOutputPath() const;
bool hasModuleDocOutputPath() const;
bool hasTBDPath() const;

bool hasDependencyTrackerPath() const;
};

} // namespace swift
Expand Down
32 changes: 1 addition & 31 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,37 +52,12 @@ class FrontendOptions {
/// The name of the module which the frontend is building.
std::string ModuleName;

/// The path to which we should emit a serialized module.
std::string ModuleOutputPath;

/// The path to which we should emit a module documentation file.
std::string ModuleDocOutputPath;

/// The name of the library to link against when using this module.
std::string ModuleLinkName;

/// The path to which we should emit an Objective-C header for the module.
std::string ObjCHeaderOutputPath;

/// Path to a file which should contain serialized diagnostics for this
/// frontend invocation.
std::string SerializedDiagnosticsPath;

/// The path to which we should output a Make-style dependencies file.
std::string DependenciesFilePath;

/// The path to which we should output a Swift reference dependencies file.
std::string ReferenceDependenciesFilePath;

/// The path to which we should output fixits as source edits.
std::string FixitsOutputPath;

/// The path to which we should output a loaded module trace file.
std::string LoadedModuleTracePath;

/// The path to which we should output a TBD file.
std::string TBDPath;

/// Arguments which should be passed in immediate mode.
std::vector<std::string> ImmediateArgv;

Expand Down Expand Up @@ -301,15 +276,10 @@ class FrontendOptions {
}

private:
bool hasUnusedDependenciesFilePath() const;
static bool canActionEmitDependencies(ActionType);
bool hasUnusedObjCHeaderOutputPath() const;
static bool canActionEmitHeader(ActionType);
bool hasUnusedLoadedModuleTracePath() const;
static bool canActionEmitObjCHeader(ActionType);
static bool canActionEmitLoadedModuleTrace(ActionType);
bool hasUnusedModuleOutputPath() const;
static bool canActionEmitModule(ActionType);
bool hasUnusedModuleDocOutputPath() const;
static bool canActionEmitModuleDoc(ActionType);

public:
Expand Down
53 changes: 53 additions & 0 deletions include/swift/Frontend/SupplementaryOutputPaths.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//===--- SupplementaryOutputPaths.h ----------------------------*- C++ -*-===*//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#ifndef SWIFT_FRONTEND_SUPPLEMENTARYOUTPUTPATHS_H
#define SWIFT_FRONTEND_SUPPLEMENTARYOUTPUTPATHS_H

#include "swift/Basic/LLVM.h"
#include "llvm/ADT/Optional.h"

#include <string>

namespace swift {
struct SupplementaryOutputPaths {
/// The path to which we should emit an Objective-C header for the module.
std::string ObjCHeaderOutputPath;

/// The path to which we should emit a serialized module.
std::string ModuleOutputPath;

/// The path to which we should emit a module documentation file.
std::string ModuleDocOutputPath;

/// The path to which we should output a Make-style dependencies file.
std::string DependenciesFilePath;

/// The path to which we should output a Swift reference dependencies file.
std::string ReferenceDependenciesFilePath;

/// Path to a file which should contain serialized diagnostics for this
/// frontend invocation.
std::string SerializedDiagnosticsPath;

/// The path to which we should output a loaded module trace file.
std::string LoadedModuleTracePath;

/// The path to which we should output a TBD file.
std::string TBDPath;

SupplementaryOutputPaths() = default;
SupplementaryOutputPaths(const SupplementaryOutputPaths &) = default;
};
} // namespace swift

#endif /* SWIFT_FRONTEND_SUPPLEMENTARYOUTPUTPATHS_H */
Loading