Skip to content

Commit 63b723f

Browse files
Address review feedback
1 parent 72f32d7 commit 63b723f

File tree

9 files changed

+217
-181
lines changed

9 files changed

+217
-181
lines changed

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 1 addition & 1 deletion
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

Lines changed: 55 additions & 98 deletions
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,19 @@ 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()),
136141
buildCommandLine(buildCommandLine.begin(), buildCommandLine.end()),
137-
bridgingHeaderBuildCommandLine(bridgingHeaderBuildCommandLine.begin(),
138-
bridgingHeaderBuildCommandLine.end()),
139142
CASFileSystemRootID(CASFileSystemRootID) {}
140143

141144
/// To build a PCM to be used by this Swift module, we need to append these
@@ -160,14 +163,11 @@ struct CommonSwiftTextualModuleDependencyDetails {
160163
/// interface.
161164
std::vector<std::string> buildCommandLine;
162165

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

169169
/// CASID for the Root of bridgingHeaderClangIncludeTree. Empty if not used.
170-
std::string bridgingHeaderIncludeTreeRoot;
170+
std::string CASBridgingHeaderIncludeTreeRootID;
171171
};
172172

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

197-
/// The cache key for the produced module.
198-
std::string moduleCacheKey;
199-
200197
SwiftInterfaceModuleDependenciesStorage(
201198
const std::string &moduleOutputPath,
202199
const std::string &swiftInterfaceFile,
203200
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-
{}
201+
ArrayRef<StringRef> buildCommandLine, ArrayRef<StringRef> extraPCMArgs,
202+
StringRef contextHash, bool isFramework, const std::string &RootID,
203+
const std::string &moduleCacheKey)
204+
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftInterface,
205+
moduleCacheKey),
206+
moduleOutputPath(moduleOutputPath),
207+
swiftInterfaceFile(swiftInterfaceFile),
208+
compiledModuleCandidates(compiledModuleCandidates.begin(),
209+
compiledModuleCandidates.end()),
210+
contextHash(contextHash), isFramework(isFramework),
211+
textualModuleDetails(extraPCMArgs, buildCommandLine, RootID) {}
219212

220213
ModuleDependencyInfoStorageBase *clone() const override {
221214
return new SwiftInterfaceModuleDependenciesStorage(*this);
@@ -228,10 +221,6 @@ class SwiftInterfaceModuleDependenciesStorage :
228221
void updateCommandLine(const std::vector<std::string> &newCommandLine) {
229222
textualModuleDetails.buildCommandLine = newCommandLine;
230223
}
231-
232-
void updateModuleCacheKey(const std::string &Key) {
233-
moduleCacheKey = Key;
234-
}
235224
};
236225

237226
/// Describes the dependencies of a Swift module
@@ -250,14 +239,18 @@ class SwiftSourceModuleDependenciesStorage :
250239
/// Collection of module imports that were detected to be `@Testable`
251240
llvm::StringSet<> testableImports;
252241

242+
/// The Swift frontend invocation arguments to build bridging header.
243+
std::vector<std::string> bridgingHeaderBuildCommandLine;
244+
253245
SwiftSourceModuleDependenciesStorage(
254246
const std::string &RootID, ArrayRef<StringRef> buildCommandLine,
255247
ArrayRef<StringRef> bridgingHeaderBuildCommandLine,
256248
ArrayRef<StringRef> extraPCMArgs)
257249
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftSource),
258-
textualModuleDetails(extraPCMArgs, buildCommandLine,
259-
bridgingHeaderBuildCommandLine, RootID),
260-
testableImports(llvm::StringSet<>()) {}
250+
textualModuleDetails(extraPCMArgs, buildCommandLine, RootID),
251+
testableImports(llvm::StringSet<>()),
252+
bridgingHeaderBuildCommandLine(bridgingHeaderBuildCommandLine.begin(),
253+
bridgingHeaderBuildCommandLine.end()) {}
261254

262255
ModuleDependencyInfoStorageBase *clone() const override {
263256
return new SwiftSourceModuleDependenciesStorage(*this);
@@ -273,7 +266,7 @@ class SwiftSourceModuleDependenciesStorage :
273266

274267
void updateBridgingHeaderCommandLine(
275268
const std::vector<std::string> &newCommandLine) {
276-
textualModuleDetails.bridgingHeaderBuildCommandLine = newCommandLine;
269+
bridgingHeaderBuildCommandLine = newCommandLine;
277270
}
278271

279272
void addTestableImport(ImportPath::Module module) {
@@ -290,11 +283,11 @@ class SwiftBinaryModuleDependencyStorage : public ModuleDependencyInfoStorageBas
290283
const std::string &moduleDocPath,
291284
const std::string &sourceInfoPath,
292285
const bool isFramework,
293-
const std::string ModuleCacheKey)
294-
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftBinary),
286+
const std::string &moduleCacheKey)
287+
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftBinary,
288+
moduleCacheKey),
295289
compiledModulePath(compiledModulePath), moduleDocPath(moduleDocPath),
296-
sourceInfoPath(sourceInfoPath), isFramework(isFramework),
297-
moduleCacheKey(ModuleCacheKey) {}
290+
sourceInfoPath(sourceInfoPath), isFramework(isFramework) {}
298291

299292
ModuleDependencyInfoStorageBase *clone() const override {
300293
return new SwiftBinaryModuleDependencyStorage(*this);
@@ -312,16 +305,9 @@ class SwiftBinaryModuleDependencyStorage : public ModuleDependencyInfoStorageBas
312305
/// A flag that indicates this dependency is a framework
313306
const bool isFramework;
314307

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

327313
/// Describes the dependencies of a Clang module.
@@ -339,7 +325,7 @@ class ClangModuleDependencyStorage : public ModuleDependencyInfoStorageBase {
339325
const std::string contextHash;
340326

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

344330
/// The file dependencies
345331
const std::vector<std::string> fileDependencies;
@@ -352,31 +338,24 @@ class ClangModuleDependencyStorage : public ModuleDependencyInfoStorageBase {
352338
std::string CASFileSystemRootID;
353339

354340
/// 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) {}
341+
std::string CASClangIncludeTreeRootID;
342+
343+
ClangModuleDependencyStorage(const std::string &pcmOutputPath,
344+
const std::string &moduleMapFile,
345+
const std::string &contextHash,
346+
const std::vector<std::string> &buildCommandLine,
347+
const std::vector<std::string> &fileDependencies,
348+
const std::vector<std::string> &capturedPCMArgs,
349+
const std::string &CASFileSystemRootID,
350+
const std::string &clangIncludeTreeRoot,
351+
const std::string &moduleCacheKey)
352+
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::Clang,
353+
moduleCacheKey),
354+
pcmOutputPath(pcmOutputPath), moduleMapFile(moduleMapFile),
355+
contextHash(contextHash), buildCommandLine(buildCommandLine),
356+
fileDependencies(fileDependencies), capturedPCMArgs(capturedPCMArgs),
357+
CASFileSystemRootID(CASFileSystemRootID),
358+
CASClangIncludeTreeRootID(clangIncludeTreeRoot) {}
380359

381360
ModuleDependencyInfoStorageBase *clone() const override {
382361
return new ClangModuleDependencyStorage(*this);
@@ -387,12 +366,7 @@ class ClangModuleDependencyStorage : public ModuleDependencyInfoStorageBase {
387366
}
388367

389368
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;
369+
buildCommandLine = newCommandLine;
396370
}
397371
};
398372

@@ -543,28 +517,11 @@ class ModuleDependencyInfo {
543517

544518
std::string getModuleCacheKey() const {
545519
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");
520+
return storage->moduleCacheKey;
554521
}
555522

556523
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");
524+
storage->moduleCacheKey = key;
568525
}
569526

570527
/// Resolve a dependency's set of `imports` with qualified Module IDs
@@ -590,7 +547,7 @@ class ModuleDependencyInfo {
590547

591548
std::vector<std::string> getCommandline() const {
592549
if (auto *detail = getAsClangModule())
593-
return detail->nonPathCommandLine;
550+
return detail->buildCommandLine;
594551
else if (auto *detail = getAsSwiftInterfaceModule())
595552
return detail->textualModuleDetails.buildCommandLine;
596553
else if (auto *detail = getAsSwiftSourceModule())
@@ -613,7 +570,7 @@ class ModuleDependencyInfo {
613570

614571
std::vector<std::string> getBridgingHeaderCommandline() const {
615572
if (auto *detail = getAsSwiftSourceModule())
616-
return detail->textualModuleDetails.bridgingHeaderBuildCommandLine;
573+
return detail->bridgingHeaderBuildCommandLine;
617574
return {};
618575
}
619576

lib/AST/ModuleDependencies.cpp

Lines changed: 17 additions & 16 deletions
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)