Skip to content

Commit 2e2fe68

Browse files
authored
[clang][DependencyScanning] Use ArrayRef in function signatures over const std::vector& (NFC) (#170941)
This updates the dependency-scanning tooling to consistently use `ArrayRef<std::string>` rather than `const std::vector<std::string>&` in function signatures. This is done to help break PR #169964 into smaller, more manageable pieces.
1 parent 7ba7101 commit 2e2fe68

File tree

5 files changed

+32
-32
lines changed

5 files changed

+32
-32
lines changed

clang/include/clang/DependencyScanning/DependencyScanningWorker.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class DependencyScanningWorker {
100100
/// \returns false if clang errors occurred (with diagnostics reported to
101101
/// \c DiagConsumer), true otherwise.
102102
bool computeDependencies(
103-
StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
103+
StringRef WorkingDirectory, ArrayRef<std::string> CommandLine,
104104
DependencyConsumer &DepConsumer, DependencyActionController &Controller,
105105
DiagnosticConsumer &DiagConsumer,
106106
std::optional<llvm::MemoryBufferRef> TUBuffer = std::nullopt);
@@ -111,7 +111,7 @@ class DependencyScanningWorker {
111111
/// \returns A \c StringError with the diagnostic output if clang errors
112112
/// occurred, success otherwise.
113113
llvm::Error computeDependencies(
114-
StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
114+
StringRef WorkingDirectory, ArrayRef<std::string> CommandLine,
115115
DependencyConsumer &Consumer, DependencyActionController &Controller,
116116
std::optional<llvm::MemoryBufferRef> TUBuffer = std::nullopt);
117117

@@ -125,7 +125,7 @@ class DependencyScanningWorker {
125125
/// @param CommandLine The commandline used for the scan.
126126
/// @return Error if the initializaiton fails.
127127
llvm::Error initializeCompilerInstanceWithContextOrError(
128-
StringRef CWD, const std::vector<std::string> &CommandLine);
128+
StringRef CWD, ArrayRef<std::string> CommandLine);
129129

130130
/// @brief Performaces dependency scanning for the module whose name is
131131
/// specified.
@@ -147,9 +147,9 @@ class DependencyScanningWorker {
147147
/// three methods return a flag to indicate if the call is successful.
148148
/// The initialization function asks the client for a DiagnosticsConsumer
149149
/// that it direct the diagnostics to.
150-
bool initializeCompilerInstanceWithContext(
151-
StringRef CWD, const std::vector<std::string> &CommandLine,
152-
DiagnosticConsumer *DC = nullptr);
150+
bool initializeCompilerInstanceWithContext(StringRef CWD,
151+
ArrayRef<std::string> CommandLine,
152+
DiagnosticConsumer *DC = nullptr);
153153
bool
154154
computeDependenciesByNameWithContext(StringRef ModuleName,
155155
DependencyConsumer &Consumer,
@@ -172,7 +172,7 @@ class DependencyScanningWorker {
172172
/// Actually carries out the scan. If \c OverlayFS is provided, it must be
173173
/// based on top of DepFS.
174174
bool scanDependencies(
175-
StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
175+
StringRef WorkingDirectory, ArrayRef<std::string> CommandLine,
176176
DependencyConsumer &Consumer, DependencyActionController &Controller,
177177
DiagnosticConsumer &DC,
178178
IntrusiveRefCntPtr<llvm::vfs::FileSystem> OverlayFS = nullptr);

clang/include/clang/Tooling/DependencyScanningTool.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class DependencyScanningTool {
4747
/// \returns A \c StringError with the diagnostic output if clang errors
4848
/// occurred, dependency file contents otherwise.
4949
llvm::Expected<std::string>
50-
getDependencyFile(const std::vector<std::string> &CommandLine, StringRef CWD);
50+
getDependencyFile(ArrayRef<std::string> CommandLine, StringRef CWD);
5151

5252
/// Collect the module dependency in P1689 format for C++20 named modules.
5353
///
@@ -92,7 +92,7 @@ class DependencyScanningTool {
9292
/// occurred, \c TranslationUnitDeps otherwise.
9393
llvm::Expected<dependencies::TranslationUnitDeps>
9494
getTranslationUnitDependencies(
95-
const std::vector<std::string> &CommandLine, StringRef CWD,
95+
ArrayRef<std::string> CommandLine, StringRef CWD,
9696
const llvm::DenseSet<dependencies::ModuleID> &AlreadySeen,
9797
dependencies::LookupModuleOutputCallback LookupModuleOutput,
9898
std::optional<llvm::MemoryBufferRef> TUBuffer = std::nullopt);
@@ -104,8 +104,8 @@ class DependencyScanningTool {
104104
/// CompilerInstanceWithContext. We are keeping it here so that it is easier
105105
/// to coordinate with Swift and C-API changes.
106106
llvm::Expected<dependencies::TranslationUnitDeps> getModuleDependencies(
107-
StringRef ModuleName, const std::vector<std::string> &CommandLine,
108-
StringRef CWD, const llvm::DenseSet<dependencies::ModuleID> &AlreadySeen,
107+
StringRef ModuleName, ArrayRef<std::string> CommandLine, StringRef CWD,
108+
const llvm::DenseSet<dependencies::ModuleID> &AlreadySeen,
109109
dependencies::LookupModuleOutputCallback LookupModuleOutput);
110110

111111
/// The following three methods provide a new interface to perform
@@ -119,8 +119,9 @@ class DependencyScanningTool {
119119
/// @param CWD The current working directory used during the scan.
120120
/// @param CommandLine The commandline used for the scan.
121121
/// @return Error if the initializaiton fails.
122-
llvm::Error initializeCompilerInstanceWithContext(
123-
StringRef CWD, const std::vector<std::string> &CommandLine);
122+
llvm::Error
123+
initializeCompilerInstanceWithContext(StringRef CWD,
124+
ArrayRef<std::string> CommandLine);
124125

125126
/// @brief Computes the dependeny for the module named ModuleName.
126127
/// @param ModuleName The name of the module for which this method computes

clang/lib/DependencyScanning/DependencyScannerImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ bool CompilerInstanceWithContext::computeDependencies(
815815
// file. In this case, we call BeginSourceFile to initialize.
816816
std::unique_ptr<FrontendAction> Action =
817817
std::make_unique<PreprocessOnlyAction>();
818-
auto InputFile = CI.getFrontendOpts().Inputs.begin();
818+
auto *InputFile = CI.getFrontendOpts().Inputs.begin();
819819
bool ActionBeginSucceeded = Action->BeginSourceFile(CI, *InputFile);
820820
assert(ActionBeginSucceeded && "Action BeginSourceFile must succeed");
821821
(void)ActionBeginSucceeded;

clang/lib/DependencyScanning/DependencyScanningWorker.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ DependencyScanningWorker::~DependencyScanningWorker() = default;
3838
DependencyActionController::~DependencyActionController() = default;
3939

4040
llvm::Error DependencyScanningWorker::computeDependencies(
41-
StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
41+
StringRef WorkingDirectory, ArrayRef<std::string> CommandLine,
4242
DependencyConsumer &Consumer, DependencyActionController &Controller,
4343
std::optional<llvm::MemoryBufferRef> TUBuffer) {
4444
// Capture the emitted diagnostics and report them to the client
@@ -71,8 +71,7 @@ static bool forEachDriverJob(
7171
}
7272

7373
static bool createAndRunToolInvocation(
74-
const std::vector<std::string> &CommandLine,
75-
DependencyScanningAction &Action,
74+
ArrayRef<std::string> CommandLine, DependencyScanningAction &Action,
7675
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
7776
std::shared_ptr<clang::PCHContainerOperations> &PCHContainerOps,
7877
DiagnosticsEngine &Diags) {
@@ -86,7 +85,7 @@ static bool createAndRunToolInvocation(
8685
}
8786

8887
bool DependencyScanningWorker::scanDependencies(
89-
StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
88+
StringRef WorkingDirectory, ArrayRef<std::string> CommandLine,
9089
DependencyConsumer &Consumer, DependencyActionController &Controller,
9190
DiagnosticConsumer &DC,
9291
IntrusiveRefCntPtr<llvm::vfs::FileSystem> OverlayFS) {
@@ -151,24 +150,24 @@ bool DependencyScanningWorker::scanDependencies(
151150
}
152151

153152
bool DependencyScanningWorker::computeDependencies(
154-
StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
153+
StringRef WorkingDirectory, ArrayRef<std::string> CommandLine,
155154
DependencyConsumer &Consumer, DependencyActionController &Controller,
156155
DiagnosticConsumer &DC, std::optional<llvm::MemoryBufferRef> TUBuffer) {
157156
if (TUBuffer) {
158157
auto [FinalFS, FinalCommandLine] = initVFSForTUBufferScanning(
159158
DepFS, CommandLine, WorkingDirectory, *TUBuffer);
160159
return scanDependencies(WorkingDirectory, FinalCommandLine, Consumer,
161160
Controller, DC, FinalFS);
162-
} else {
163-
DepFS->setCurrentWorkingDirectory(WorkingDirectory);
164-
return scanDependencies(WorkingDirectory, CommandLine, Consumer, Controller,
165-
DC);
166161
}
162+
163+
DepFS->setCurrentWorkingDirectory(WorkingDirectory);
164+
return scanDependencies(WorkingDirectory, CommandLine, Consumer, Controller,
165+
DC);
167166
}
168167

169168
llvm::Error
170169
DependencyScanningWorker::initializeCompilerInstanceWithContextOrError(
171-
StringRef CWD, const std::vector<std::string> &CommandLine) {
170+
StringRef CWD, ArrayRef<std::string> CommandLine) {
172171
bool Success = initializeCompilerInstanceWithContext(CWD, CommandLine);
173172
return CIWithContext->handleReturnStatus(Success);
174173
}
@@ -189,8 +188,7 @@ DependencyScanningWorker::finalizeCompilerInstanceWithContextOrError() {
189188
}
190189

191190
bool DependencyScanningWorker::initializeCompilerInstanceWithContext(
192-
StringRef CWD, const std::vector<std::string> &CommandLine,
193-
DiagnosticConsumer *DC) {
191+
StringRef CWD, ArrayRef<std::string> CommandLine, DiagnosticConsumer *DC) {
194192
CIWithContext =
195193
std::make_unique<CompilerInstanceWithContext>(*this, CWD, CommandLine);
196194
return CIWithContext->initialize(DC);

clang/lib/Tooling/DependencyScanningTool.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ class MakeDependencyPrinterConsumer : public DependencyConsumer {
7171
};
7272
} // anonymous namespace
7373

74-
llvm::Expected<std::string> DependencyScanningTool::getDependencyFile(
75-
const std::vector<std::string> &CommandLine, StringRef CWD) {
74+
llvm::Expected<std::string>
75+
DependencyScanningTool::getDependencyFile(ArrayRef<std::string> CommandLine,
76+
StringRef CWD) {
7677
MakeDependencyPrinterConsumer Consumer;
7778
CallbackActionController Controller(nullptr);
7879
auto Result =
@@ -141,7 +142,7 @@ llvm::Expected<P1689Rule> DependencyScanningTool::getP1689ModuleDependencyFile(
141142

142143
llvm::Expected<TranslationUnitDeps>
143144
DependencyScanningTool::getTranslationUnitDependencies(
144-
const std::vector<std::string> &CommandLine, StringRef CWD,
145+
ArrayRef<std::string> CommandLine, StringRef CWD,
145146
const llvm::DenseSet<ModuleID> &AlreadySeen,
146147
LookupModuleOutputCallback LookupModuleOutput,
147148
std::optional<llvm::MemoryBufferRef> TUBuffer) {
@@ -157,8 +158,8 @@ DependencyScanningTool::getTranslationUnitDependencies(
157158

158159
llvm::Expected<TranslationUnitDeps>
159160
DependencyScanningTool::getModuleDependencies(
160-
StringRef ModuleName, const std::vector<std::string> &CommandLine,
161-
StringRef CWD, const llvm::DenseSet<ModuleID> &AlreadySeen,
161+
StringRef ModuleName, ArrayRef<std::string> CommandLine, StringRef CWD,
162+
const llvm::DenseSet<ModuleID> &AlreadySeen,
162163
LookupModuleOutputCallback LookupModuleOutput) {
163164
FullDependencyConsumer Consumer(AlreadySeen);
164165
CallbackActionController Controller(LookupModuleOutput);
@@ -179,7 +180,7 @@ DependencyScanningTool::getModuleDependencies(
179180
}
180181

181182
llvm::Error DependencyScanningTool::initializeCompilerInstanceWithContext(
182-
StringRef CWD, const std::vector<std::string> &CommandLine) {
183+
StringRef CWD, ArrayRef<std::string> CommandLine) {
183184
return Worker.initializeCompilerInstanceWithContextOrError(CWD, CommandLine);
184185
}
185186

0 commit comments

Comments
 (0)