Skip to content

Commit 7e585d1

Browse files
Address review feedback
1 parent 560b687 commit 7e585d1

File tree

6 files changed

+137
-168
lines changed

6 files changed

+137
-168
lines changed

include/swift-c/DependencyScan/DependencyScan.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/// SWIFTSCAN_VERSION_MINOR should increase when there are API additions.
2626
/// SWIFTSCAN_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
2727
#define SWIFTSCAN_VERSION_MAJOR 0
28-
#define SWIFTSCAN_VERSION_MINOR 3
28+
#define SWIFTSCAN_VERSION_MINOR 4
2929

3030
SWIFTSCAN_BEGIN_DECLS
3131

include/swift/AST/ModuleDependencies.h

+55-99
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ class ModuleDependencyInfoStorageBase {
106106
const ModuleDependencyKind dependencyKind;
107107

108108
ModuleDependencyInfoStorageBase(ModuleDependencyKind dependencyKind,
109+
StringRef moduleCacheKey = "",
109110
bool resolved = false)
110-
: dependencyKind(dependencyKind), resolved(resolved) { }
111+
: dependencyKind(dependencyKind), moduleCacheKey(moduleCacheKey.str()),
112+
resolved(resolved) {}
111113

112114
virtual ModuleDependencyInfoStorageBase *clone() const = 0;
113115

@@ -124,18 +126,18 @@ class ModuleDependencyInfoStorageBase {
124126
/// The set of modules on which this module depends, resolved
125127
/// to Module IDs, qualified by module kind: Swift, Clang, etc.
126128
std::vector<ModuleDependencyID> resolvedModuleDependencies;
129+
130+
/// The cache key for the produced module.
131+
std::string moduleCacheKey;
132+
127133
bool resolved;
128134
};
129135

130136
struct CommonSwiftTextualModuleDependencyDetails {
131137
CommonSwiftTextualModuleDependencyDetails(
132138
ArrayRef<StringRef> extraPCMArgs, ArrayRef<StringRef> buildCommandLine,
133-
ArrayRef<StringRef> bridgingHeaderBuildCommandLine,
134139
const std::string &CASFileSystemRootID)
135140
: extraPCMArgs(extraPCMArgs.begin(), extraPCMArgs.end()),
136-
buildCommandLine(buildCommandLine.begin(), buildCommandLine.end()),
137-
bridgingHeaderBuildCommandLine(bridgingHeaderBuildCommandLine.begin(),
138-
bridgingHeaderBuildCommandLine.end()),
139141
CASFileSystemRootID(CASFileSystemRootID) {}
140142

141143
/// To build a PCM to be used by this Swift module, we need to append these
@@ -160,14 +162,11 @@ struct CommonSwiftTextualModuleDependencyDetails {
160162
/// interface.
161163
std::vector<std::string> buildCommandLine;
162164

163-
/// The Swift frontend invocation arguments to build bridging header.
164-
std::vector<std::string> bridgingHeaderBuildCommandLine;
165-
166165
/// CASID for the Root of CASFS. Empty if CAS is not used.
167166
std::string CASFileSystemRootID;
168167

169168
/// CASID for the Root of bridgingHeaderClangIncludeTree. Empty if not used.
170-
std::string bridgingHeaderIncludeTreeRoot;
169+
std::string CASBridgingHeaderIncludeTreeRootID;
171170
};
172171

173172
/// Describes the dependencies of a Swift module described by an Swift interface file.
@@ -194,28 +193,21 @@ class SwiftInterfaceModuleDependenciesStorage :
194193
/// Details common to Swift textual (interface or source) modules
195194
CommonSwiftTextualModuleDependencyDetails textualModuleDetails;
196195

197-
/// The cache key for the produced module.
198-
std::string moduleCacheKey;
199-
200196
SwiftInterfaceModuleDependenciesStorage(
201197
const std::string &moduleOutputPath,
202198
const std::string &swiftInterfaceFile,
203199
ArrayRef<std::string> compiledModuleCandidates,
204-
ArrayRef<StringRef> buildCommandLine,
205-
ArrayRef<StringRef> extraPCMArgs,
206-
StringRef contextHash,
207-
bool isFramework,
208-
const std::string &RootID,
209-
const std::string &ModuleCacheKey
210-
) : ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftInterface),
211-
moduleOutputPath(moduleOutputPath),
212-
swiftInterfaceFile(swiftInterfaceFile),
213-
compiledModuleCandidates(compiledModuleCandidates.begin(),
214-
compiledModuleCandidates.end()),
215-
contextHash(contextHash), isFramework(isFramework),
216-
textualModuleDetails(extraPCMArgs, buildCommandLine, {}, RootID),
217-
moduleCacheKey(ModuleCacheKey)
218-
{}
200+
ArrayRef<StringRef> buildCommandLine, ArrayRef<StringRef> extraPCMArgs,
201+
StringRef contextHash, bool isFramework, const std::string &RootID,
202+
const std::string &moduleCacheKey)
203+
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftInterface,
204+
moduleCacheKey),
205+
moduleOutputPath(moduleOutputPath),
206+
swiftInterfaceFile(swiftInterfaceFile),
207+
compiledModuleCandidates(compiledModuleCandidates.begin(),
208+
compiledModuleCandidates.end()),
209+
contextHash(contextHash), isFramework(isFramework),
210+
textualModuleDetails(extraPCMArgs, buildCommandLine, RootID) {}
219211

220212
ModuleDependencyInfoStorageBase *clone() const override {
221213
return new SwiftInterfaceModuleDependenciesStorage(*this);
@@ -228,10 +220,6 @@ class SwiftInterfaceModuleDependenciesStorage :
228220
void updateCommandLine(const std::vector<std::string> &newCommandLine) {
229221
textualModuleDetails.buildCommandLine = newCommandLine;
230222
}
231-
232-
void updateModuleCacheKey(const std::string &Key) {
233-
moduleCacheKey = Key;
234-
}
235223
};
236224

237225
/// Describes the dependencies of a Swift module
@@ -250,14 +238,18 @@ class SwiftSourceModuleDependenciesStorage :
250238
/// Collection of module imports that were detected to be `@Testable`
251239
llvm::StringSet<> testableImports;
252240

241+
/// The Swift frontend invocation arguments to build bridging header.
242+
std::vector<std::string> bridgingHeaderBuildCommandLine;
243+
253244
SwiftSourceModuleDependenciesStorage(
254245
const std::string &RootID, ArrayRef<StringRef> buildCommandLine,
255246
ArrayRef<StringRef> bridgingHeaderBuildCommandLine,
256247
ArrayRef<StringRef> extraPCMArgs)
257248
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftSource),
258-
textualModuleDetails(extraPCMArgs, buildCommandLine,
259-
bridgingHeaderBuildCommandLine, RootID),
260-
testableImports(llvm::StringSet<>()) {}
249+
textualModuleDetails(extraPCMArgs, buildCommandLine, RootID),
250+
testableImports(llvm::StringSet<>()),
251+
bridgingHeaderBuildCommandLine(bridgingHeaderBuildCommandLine.begin(),
252+
bridgingHeaderBuildCommandLine.end()) {}
261253

262254
ModuleDependencyInfoStorageBase *clone() const override {
263255
return new SwiftSourceModuleDependenciesStorage(*this);
@@ -273,7 +265,7 @@ class SwiftSourceModuleDependenciesStorage :
273265

274266
void updateBridgingHeaderCommandLine(
275267
const std::vector<std::string> &newCommandLine) {
276-
textualModuleDetails.bridgingHeaderBuildCommandLine = newCommandLine;
268+
bridgingHeaderBuildCommandLine = newCommandLine;
277269
}
278270

279271
void addTestableImport(ImportPath::Module module) {
@@ -290,11 +282,11 @@ class SwiftBinaryModuleDependencyStorage : public ModuleDependencyInfoStorageBas
290282
const std::string &moduleDocPath,
291283
const std::string &sourceInfoPath,
292284
const bool isFramework,
293-
const std::string ModuleCacheKey)
294-
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftBinary),
285+
const std::string &moduleCacheKey)
286+
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftBinary,
287+
moduleCacheKey),
295288
compiledModulePath(compiledModulePath), moduleDocPath(moduleDocPath),
296-
sourceInfoPath(sourceInfoPath), isFramework(isFramework),
297-
moduleCacheKey(ModuleCacheKey) {}
289+
sourceInfoPath(sourceInfoPath), isFramework(isFramework) {}
298290

299291
ModuleDependencyInfoStorageBase *clone() const override {
300292
return new SwiftBinaryModuleDependencyStorage(*this);
@@ -312,16 +304,9 @@ class SwiftBinaryModuleDependencyStorage : public ModuleDependencyInfoStorageBas
312304
/// A flag that indicates this dependency is a framework
313305
const bool isFramework;
314306

315-
/// The cache key for the produced module.
316-
std::string moduleCacheKey;
317-
318307
static bool classof(const ModuleDependencyInfoStorageBase *base) {
319308
return base->dependencyKind == ModuleDependencyKind::SwiftBinary;
320309
}
321-
322-
void updateModuleCacheKey(const std::string &Key) {
323-
moduleCacheKey = Key;
324-
}
325310
};
326311

327312
/// Describes the dependencies of a Clang module.
@@ -339,7 +324,7 @@ class ClangModuleDependencyStorage : public ModuleDependencyInfoStorageBase {
339324
const std::string contextHash;
340325

341326
/// Partial (Clang) command line that can be used to build this module.
342-
std::vector<std::string> nonPathCommandLine;
327+
std::vector<std::string> buildCommandLine;
343328

344329
/// The file dependencies
345330
const std::vector<std::string> fileDependencies;
@@ -352,31 +337,24 @@ class ClangModuleDependencyStorage : public ModuleDependencyInfoStorageBase {
352337
std::string CASFileSystemRootID;
353338

354339
/// CASID for the Root of ClangIncludeTree. Empty if not used.
355-
std::string clangIncludeTreeRoot;
356-
357-
/// The cache key for the produced module.
358-
std::string moduleCacheKey;
359-
360-
ClangModuleDependencyStorage(
361-
const std::string &pcmOutputPath,
362-
const std::string &moduleMapFile,
363-
const std::string &contextHash,
364-
const std::vector<std::string> &nonPathCommandLine,
365-
const std::vector<std::string> &fileDependencies,
366-
const std::vector<std::string> &capturedPCMArgs,
367-
const std::string &CASFileSystemRootID,
368-
const std::string &clangIncludeTreeRoot,
369-
const std::string &ModuleCacheKey
370-
) : ModuleDependencyInfoStorageBase(ModuleDependencyKind::Clang),
371-
pcmOutputPath(pcmOutputPath),
372-
moduleMapFile(moduleMapFile),
373-
contextHash(contextHash),
374-
nonPathCommandLine(nonPathCommandLine),
375-
fileDependencies(fileDependencies),
376-
capturedPCMArgs(capturedPCMArgs),
377-
CASFileSystemRootID(CASFileSystemRootID),
378-
clangIncludeTreeRoot(clangIncludeTreeRoot),
379-
moduleCacheKey(ModuleCacheKey) {}
340+
std::string CASClangIncludeTreeRootID;
341+
342+
ClangModuleDependencyStorage(const std::string &pcmOutputPath,
343+
const std::string &moduleMapFile,
344+
const std::string &contextHash,
345+
const std::vector<std::string> &buildCommandLine,
346+
const std::vector<std::string> &fileDependencies,
347+
const std::vector<std::string> &capturedPCMArgs,
348+
const std::string &CASFileSystemRootID,
349+
const std::string &clangIncludeTreeRoot,
350+
const std::string &moduleCacheKey)
351+
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::Clang,
352+
moduleCacheKey),
353+
pcmOutputPath(pcmOutputPath), moduleMapFile(moduleMapFile),
354+
contextHash(contextHash), buildCommandLine(buildCommandLine),
355+
fileDependencies(fileDependencies), capturedPCMArgs(capturedPCMArgs),
356+
CASFileSystemRootID(CASFileSystemRootID),
357+
CASClangIncludeTreeRootID(clangIncludeTreeRoot) {}
380358

381359
ModuleDependencyInfoStorageBase *clone() const override {
382360
return new ClangModuleDependencyStorage(*this);
@@ -387,12 +365,7 @@ class ClangModuleDependencyStorage : public ModuleDependencyInfoStorageBase {
387365
}
388366

389367
void updateCommandLine(const std::vector<std::string> &newCommandLine) {
390-
nonPathCommandLine = newCommandLine;
391-
}
392-
393-
void updateModuleCacheKey(const std::string &Key) {
394-
assert(moduleCacheKey.empty());
395-
moduleCacheKey = Key;
368+
buildCommandLine = newCommandLine;
396369
}
397370
};
398371

@@ -543,28 +516,11 @@ class ModuleDependencyInfo {
543516

544517
std::string getModuleCacheKey() const {
545518
assert(storage->resolved);
546-
if (auto *dep = getAsSwiftInterfaceModule())
547-
return dep->moduleCacheKey;
548-
else if (auto *dep = getAsSwiftBinaryModule())
549-
return dep->moduleCacheKey;
550-
else if (auto *dep = getAsClangModule())
551-
return dep->moduleCacheKey;
552-
553-
llvm_unreachable("Unexpected type");
519+
return storage->moduleCacheKey;
554520
}
555521

556522
void updateModuleCacheKey(const std::string &key) {
557-
if (isSwiftInterfaceModule())
558-
return cast<SwiftInterfaceModuleDependenciesStorage>(storage.get())
559-
->updateModuleCacheKey(key);
560-
else if (isSwiftBinaryModule())
561-
return cast<SwiftBinaryModuleDependencyStorage>(storage.get())
562-
->updateModuleCacheKey(key);
563-
else if (isClangModule())
564-
return cast<ClangModuleDependencyStorage>(storage.get())
565-
->updateModuleCacheKey(key);
566-
567-
llvm_unreachable("Unexpected type");
523+
storage->moduleCacheKey = key;
568524
}
569525

570526
/// Resolve a dependency's set of `imports` with qualified Module IDs
@@ -590,7 +546,7 @@ class ModuleDependencyInfo {
590546

591547
std::vector<std::string> getCommandline() const {
592548
if (auto *detail = getAsClangModule())
593-
return detail->nonPathCommandLine;
549+
return detail->buildCommandLine;
594550
else if (auto *detail = getAsSwiftInterfaceModule())
595551
return detail->textualModuleDetails.buildCommandLine;
596552
else if (auto *detail = getAsSwiftSourceModule())
@@ -613,7 +569,7 @@ class ModuleDependencyInfo {
613569

614570
std::vector<std::string> getBridgingHeaderCommandline() const {
615571
if (auto *detail = getAsSwiftSourceModule())
616-
return detail->textualModuleDetails.bridgingHeaderBuildCommandLine;
572+
return detail->bridgingHeaderBuildCommandLine;
617573
return {};
618574
}
619575

lib/AST/ModuleDependencies.cpp

+17-16
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ Optional<std::string> ModuleDependencyInfo::getClangIncludeTree() const {
215215
switch (getKind()) {
216216
case swift::ModuleDependencyKind::Clang: {
217217
auto clangModuleStorage = cast<ClangModuleDependencyStorage>(storage.get());
218-
Root = clangModuleStorage->clangIncludeTreeRoot;
218+
Root = clangModuleStorage->CASClangIncludeTreeRootID;
219219
break;
220220
}
221221
default:
@@ -235,14 +235,14 @@ ModuleDependencyInfo::getBridgingHeaderIncludeTree() const {
235235
auto swiftInterfaceStorage =
236236
cast<SwiftInterfaceModuleDependenciesStorage>(storage.get());
237237
Root = swiftInterfaceStorage->textualModuleDetails
238-
.bridgingHeaderIncludeTreeRoot;
238+
.CASBridgingHeaderIncludeTreeRootID;
239239
break;
240240
}
241241
case swift::ModuleDependencyKind::SwiftSource: {
242242
auto swiftSourceStorage =
243243
cast<SwiftSourceModuleDependenciesStorage>(storage.get());
244-
Root =
245-
swiftSourceStorage->textualModuleDetails.bridgingHeaderIncludeTreeRoot;
244+
Root = swiftSourceStorage->textualModuleDetails
245+
.CASBridgingHeaderIncludeTreeRootID;
246246
break;
247247
}
248248
default:
@@ -330,15 +330,15 @@ void ModuleDependencyInfo::addBridgingHeaderIncludeTree(StringRef ID) {
330330
case swift::ModuleDependencyKind::SwiftInterface: {
331331
auto swiftInterfaceStorage =
332332
cast<SwiftInterfaceModuleDependenciesStorage>(storage.get());
333-
swiftInterfaceStorage->textualModuleDetails.bridgingHeaderIncludeTreeRoot =
334-
ID.str();
333+
swiftInterfaceStorage->textualModuleDetails
334+
.CASBridgingHeaderIncludeTreeRootID = ID.str();
335335
break;
336336
}
337337
case swift::ModuleDependencyKind::SwiftSource: {
338338
auto swiftSourceStorage =
339339
cast<SwiftSourceModuleDependenciesStorage>(storage.get());
340-
swiftSourceStorage->textualModuleDetails.bridgingHeaderIncludeTreeRoot =
341-
ID.str();
340+
swiftSourceStorage->textualModuleDetails
341+
.CASBridgingHeaderIncludeTreeRootID = ID.str();
342342
break;
343343
}
344344
default:
@@ -435,14 +435,15 @@ void SwiftDependencyScanningService::setupCachingDependencyScanningService(
435435
SDKSettingPath.size());
436436

437437
// Add Legacy layout file (maybe just hard code instead of searching).
438-
StringRef RuntimeLibPath =
439-
Instance.getInvocation().getSearchPathOptions().RuntimeLibraryPaths[0];
440-
auto &FS = Instance.getFileSystem();
441-
std::error_code EC;
442-
for (auto F = FS.dir_begin(RuntimeLibPath, EC);
443-
!EC && F != llvm::vfs::directory_iterator(); F.increment(EC)) {
444-
if (F->path().endswith(".yaml"))
445-
CommonDependencyFiles.emplace_back(F->path().str());
438+
for (auto RuntimeLibPath :
439+
Instance.getInvocation().getSearchPathOptions().RuntimeLibraryPaths) {
440+
auto &FS = Instance.getFileSystem();
441+
std::error_code EC;
442+
for (auto F = FS.dir_begin(RuntimeLibPath, EC);
443+
!EC && F != llvm::vfs::directory_iterator(); F.increment(EC)) {
444+
if (F->path().endswith(".yaml"))
445+
CommonDependencyFiles.emplace_back(F->path().str());
446+
}
446447
}
447448

448449
auto CachingFS =

0 commit comments

Comments
 (0)