Skip to content

Commit 95f70f7

Browse files
author
David Ungar
authored
Merge pull request #14402 from davidungar/PR-18-5a-SupplementaryOutputs
[Batch Mode] Move supplementary output paths into a dedicated structure in FrontendInputsAndOutputs (3)
2 parents 63bda7b + ef02d0b commit 95f70f7

15 files changed

+558
-203
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ ERROR(error_index_failed_status_check,none,
190190
ERROR(error_index_inputs_more_than_outputs,none,
191191
"index output filenames do not match input source files", ())
192192

193+
ERROR(error_wrong_number_of_arguments,none,
194+
"wrong number of '%0' arguments (expected %1, got %2)", (StringRef, int, int))
195+
193196
ERROR(error_formatting_multiple_file_ranges,none,
194197
"file ranges don't support multiple input files", ())
195198

include/swift/Frontend/ArgsToFrontendOptionsConverter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ArgsToFrontendOptionsConverter {
3737
void computeDebugTimeOptions();
3838
bool computeFallbackModuleName();
3939
bool computeModuleName();
40-
bool computeOutputFilenames();
40+
bool computeMainAndSupplementaryOutputFilenames();
4141
void computeDumpScopeMapLocations();
4242
void computeHelpOptions();
4343
void computeImplicitImportModuleNames();
@@ -52,7 +52,7 @@ class ArgsToFrontendOptionsConverter {
5252

5353
bool setUpForSILOrLLVM();
5454

55-
void determineSupplementaryOutputFilenames();
55+
bool checkUnusedSupplementaryOutputPaths() const;
5656

5757
/// \returns the output filenames on the command line or in the output
5858
/// filelist, or an empty vector if there were neither -o's nor an output

include/swift/Frontend/ArgsToFrontendOutputsConverter.h

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/AST/DiagnosticEngine.h"
1818
#include "swift/Basic/LLVM.h"
1919
#include "swift/Frontend/FrontendOptions.h"
20+
#include "swift/Frontend/SupplementaryOutputPaths.h"
2021
#include "swift/Option/Options.h"
2122
#include "llvm/Option/ArgList.h"
2223

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

44-
Optional<std::vector<std::string>> convert();
45+
bool convert(std::vector<std::string> &mainOutputs,
46+
SupplementaryOutputPaths &supplementaryOutputs);
4547

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

113+
class SupplementaryOutputPathsComputer {
114+
const llvm::opt::ArgList &Args;
115+
DiagnosticEngine &Diags;
116+
const FrontendInputsAndOutputs &InputsAndOutputs;
117+
ArrayRef<std::string> OutputFiles;
118+
StringRef ModuleName;
119+
120+
const FrontendOptions::ActionType RequestedAction;
121+
122+
public:
123+
SupplementaryOutputPathsComputer(
124+
const llvm::opt::ArgList &args, DiagnosticEngine &diags,
125+
const FrontendInputsAndOutputs &inputsAndOutputs,
126+
ArrayRef<std::string> outputFiles, StringRef moduleName);
127+
Optional<std::vector<SupplementaryOutputPaths>> computeOutputPaths() const;
128+
129+
private:
130+
/// \Return a set of supplementary output paths for each input that might
131+
/// produce supplementary outputs, or None to signal an error.
132+
/// \note
133+
/// At present, only one input can produce supplementary outputs, but
134+
/// in the future, batch-mode will support multiple primary inputs and thus,
135+
/// multiple sets of supplementary outputs. This function is written with that
136+
/// future in mind.
137+
/// \par
138+
/// The paths are derived from arguments
139+
/// such as -emit-module-path. These are not the final computed paths,
140+
/// merely the ones passed in via the command line.
141+
/// \note
142+
/// In the future, these will also include those passed in via whatever
143+
/// filelist scheme gets implemented to handle cases where the command line
144+
/// arguments become burdensome.
145+
Optional<std::vector<SupplementaryOutputPaths>>
146+
getSupplementaryOutputPathsFromArguments() const;
147+
148+
/// Given an ID corresponding to supplementary output argument
149+
/// (e.g. -emit-module-path), collect all such paths, and ensure
150+
/// there are the right number of them.
151+
Optional<std::vector<std::string>>
152+
getSupplementaryFilenamesFromArguments(options::ID pathID) const;
153+
154+
Optional<SupplementaryOutputPaths> computeOutputPathsForOneInput(
155+
StringRef outputFilename,
156+
const SupplementaryOutputPaths &pathsFromFilelists,
157+
const InputFile &) const;
158+
159+
StringRef deriveDefaultSupplementaryOutputPathExcludingExtension(
160+
StringRef outputFilename, const InputFile &) const;
161+
162+
/// \return empty string if no output file.
163+
std::string determineSupplementaryOutputFilename(
164+
options::ID emitOpt, std::string pathFromArgumentsOrFilelists,
165+
StringRef extension, StringRef mainOutputIfUsable,
166+
StringRef defaultSupplementaryOutputPathExcludingExtension) const;
167+
168+
void deriveModulePathParameters(options::ID &emitOption,
169+
std::string &extension,
170+
std::string &mainOutputIfUsable) const;
171+
};
172+
111173
} // namespace swift
112174

113175
#endif /* SWIFT_FRONTEND_ARGSTOFRONTENDOUTPUTSCONVERTER_H */

include/swift/Frontend/Frontend.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,12 @@ class CompilerInvocation {
175175
}
176176

177177
void setSerializedDiagnosticsPath(StringRef Path) {
178-
FrontendOpts.SerializedDiagnosticsPath = Path;
178+
FrontendOpts.InputsAndOutputs.supplementaryOutputs()
179+
.SerializedDiagnosticsPath = Path;
179180
}
180181
StringRef getSerializedDiagnosticsPath() const {
181-
return FrontendOpts.SerializedDiagnosticsPath;
182+
return FrontendOpts.InputsAndOutputs.supplementaryOutputs()
183+
.SerializedDiagnosticsPath;
182184
}
183185

184186
LangOptions &getLangOptions() {

include/swift/Frontend/FrontendInputsAndOutputs.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "swift/AST/Module.h"
1717
#include "swift/Frontend/InputFile.h"
18+
#include "swift/Frontend/SupplementaryOutputPaths.h"
1819
#include "llvm/ADT/Hashing.h"
1920
#include "llvm/ADT/MapVector.h"
2021

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

47+
SupplementaryOutputPaths SupplementaryOutputs;
48+
4649
public:
4750
bool areBatchModeChecksBypassed() const { return AreBatchModeChecksBypassed; }
4851
void setBypassBatchModeChecks(bool bbc) { AreBatchModeChecksBypassed = bbc; }
4952

53+
const SupplementaryOutputPaths &supplementaryOutputs() const {
54+
return SupplementaryOutputs;
55+
}
56+
SupplementaryOutputPaths &supplementaryOutputs() {
57+
return SupplementaryOutputs;
58+
}
59+
5060
FrontendInputsAndOutputs() = default;
5161
FrontendInputsAndOutputs(const FrontendInputsAndOutputs &other);
5262
FrontendInputsAndOutputs &operator=(const FrontendInputsAndOutputs &other);
@@ -164,7 +174,9 @@ class FrontendInputsAndOutputs {
164174
private:
165175
friend class ArgsToFrontendOptionsConverter;
166176

167-
void setMainOutputs(ArrayRef<std::string> outputFiles);
177+
void
178+
setMainAndSupplementaryOutputs(ArrayRef<std::string> outputFiles,
179+
SupplementaryOutputPaths supplementaryOutputs);
168180

169181
public:
170182
unsigned countOfInputsProducingMainOutputs() const;
@@ -193,8 +205,20 @@ class FrontendInputsAndOutputs {
193205

194206
// Supplementary outputs
195207

208+
unsigned countOfFilesProducingSupplementaryOutput() const;
209+
196210
void forEachInputProducingSupplementaryOutput(
197211
llvm::function_ref<void(const InputFile &)> fn) const;
212+
213+
bool hasDependenciesPath() const;
214+
bool hasReferenceDependenciesPath() const;
215+
bool hasObjCHeaderOutputPath() const;
216+
bool hasLoadedModuleTracePath() const;
217+
bool hasModuleOutputPath() const;
218+
bool hasModuleDocOutputPath() const;
219+
bool hasTBDPath() const;
220+
221+
bool hasDependencyTrackerPath() const;
198222
};
199223

200224
} // namespace swift

include/swift/Frontend/FrontendOptions.h

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,37 +52,12 @@ class FrontendOptions {
5252
/// The name of the module which the frontend is building.
5353
std::string ModuleName;
5454

55-
/// The path to which we should emit a serialized module.
56-
std::string ModuleOutputPath;
57-
58-
/// The path to which we should emit a module documentation file.
59-
std::string ModuleDocOutputPath;
60-
6155
/// The name of the library to link against when using this module.
6256
std::string ModuleLinkName;
6357

64-
/// The path to which we should emit an Objective-C header for the module.
65-
std::string ObjCHeaderOutputPath;
66-
67-
/// Path to a file which should contain serialized diagnostics for this
68-
/// frontend invocation.
69-
std::string SerializedDiagnosticsPath;
70-
71-
/// The path to which we should output a Make-style dependencies file.
72-
std::string DependenciesFilePath;
73-
74-
/// The path to which we should output a Swift reference dependencies file.
75-
std::string ReferenceDependenciesFilePath;
76-
7758
/// The path to which we should output fixits as source edits.
7859
std::string FixitsOutputPath;
7960

80-
/// The path to which we should output a loaded module trace file.
81-
std::string LoadedModuleTracePath;
82-
83-
/// The path to which we should output a TBD file.
84-
std::string TBDPath;
85-
8661
/// Arguments which should be passed in immediate mode.
8762
std::vector<std::string> ImmediateArgv;
8863

@@ -301,15 +276,10 @@ class FrontendOptions {
301276
}
302277

303278
private:
304-
bool hasUnusedDependenciesFilePath() const;
305279
static bool canActionEmitDependencies(ActionType);
306-
bool hasUnusedObjCHeaderOutputPath() const;
307-
static bool canActionEmitHeader(ActionType);
308-
bool hasUnusedLoadedModuleTracePath() const;
280+
static bool canActionEmitObjCHeader(ActionType);
309281
static bool canActionEmitLoadedModuleTrace(ActionType);
310-
bool hasUnusedModuleOutputPath() const;
311282
static bool canActionEmitModule(ActionType);
312-
bool hasUnusedModuleDocOutputPath() const;
313283
static bool canActionEmitModuleDoc(ActionType);
314284

315285
public:
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//===--- SupplementaryOutputPaths.h ----------------------------*- C++ -*-===*//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_FRONTEND_SUPPLEMENTARYOUTPUTPATHS_H
14+
#define SWIFT_FRONTEND_SUPPLEMENTARYOUTPUTPATHS_H
15+
16+
#include "swift/Basic/LLVM.h"
17+
#include "llvm/ADT/Optional.h"
18+
19+
#include <string>
20+
21+
namespace swift {
22+
struct SupplementaryOutputPaths {
23+
/// The path to which we should emit an Objective-C header for the module.
24+
std::string ObjCHeaderOutputPath;
25+
26+
/// The path to which we should emit a serialized module.
27+
std::string ModuleOutputPath;
28+
29+
/// The path to which we should emit a module documentation file.
30+
std::string ModuleDocOutputPath;
31+
32+
/// The path to which we should output a Make-style dependencies file.
33+
std::string DependenciesFilePath;
34+
35+
/// The path to which we should output a Swift reference dependencies file.
36+
std::string ReferenceDependenciesFilePath;
37+
38+
/// Path to a file which should contain serialized diagnostics for this
39+
/// frontend invocation.
40+
std::string SerializedDiagnosticsPath;
41+
42+
/// The path to which we should output a loaded module trace file.
43+
std::string LoadedModuleTracePath;
44+
45+
/// The path to which we should output a TBD file.
46+
std::string TBDPath;
47+
48+
SupplementaryOutputPaths() = default;
49+
SupplementaryOutputPaths(const SupplementaryOutputPaths &) = default;
50+
};
51+
} // namespace swift
52+
53+
#endif /* SWIFT_FRONTEND_SUPPLEMENTARYOUTPUTPATHS_H */

0 commit comments

Comments
 (0)