@@ -81,13 +81,22 @@ namespace {
81
81
class ExplicitModuleDependencyResolver {
82
82
public:
83
83
ExplicitModuleDependencyResolver (
84
- ModuleDependencyID moduleID, ModuleDependenciesCache &cache,
84
+ const ModuleDependencyID & moduleID, ModuleDependenciesCache &cache,
85
85
CompilerInstance &instance, std::optional<SwiftDependencyTracker> tracker)
86
86
: moduleID(moduleID), cache(cache), instance(instance),
87
87
resolvingDepInfo (cache.findKnownDependency(moduleID)),
88
88
tracker(std::move(tracker)) {
89
89
// Copy commandline.
90
90
commandline = resolvingDepInfo.getCommandline ();
91
+
92
+ if (resolvingDepInfo.isSwiftInterfaceModule ()) {
93
+ auto swiftTextualDeps = resolvingDepInfo.getAsSwiftInterfaceModule ();
94
+ auto &interfacePath = swiftTextualDeps->swiftInterfaceFile ;
95
+ auto SDKPath = instance.getASTContext ().SearchPathOpts .getSDKPath ();
96
+ nameExpander = std::make_unique<InterfaceModuleNameExpander>(
97
+ moduleID.ModuleName , interfacePath, SDKPath,
98
+ instance.getInvocation ());
99
+ }
91
100
}
92
101
93
102
llvm::Error
@@ -171,6 +180,9 @@ class ExplicitModuleDependencyResolver {
171
180
172
181
pruneUnusedVFSOverlay ();
173
182
183
+ if (resolvingDepInfo.isSwiftInterfaceModule ())
184
+ updateSwiftInterfaceCommandLine ();
185
+
174
186
// Update the dependency in the cache with the modified command-line.
175
187
if (resolvingDepInfo.isSwiftInterfaceModule () ||
176
188
resolvingDepInfo.isClangModule ()) {
@@ -221,6 +233,12 @@ class ExplicitModuleDependencyResolver {
221
233
return err;
222
234
}
223
235
236
+ if (nameExpander) {
237
+ auto expandedName = nameExpander->getExpandedName ();
238
+ depInfo.updateModuleOutputPath (expandedName.outputPath .c_str ());
239
+ depInfo.updateContextHash (expandedName.hash .str ());
240
+ }
241
+
224
242
return llvm::Error::success ();
225
243
}
226
244
@@ -402,9 +420,62 @@ class ExplicitModuleDependencyResolver {
402
420
}
403
421
resolvedCommandLine.push_back (*it);
404
422
}
423
+
424
+ // Filter the extra args that we use to calculate the hash of the module.
425
+ // The key assumption is that these args are clang importer args, so we
426
+ // do not need to check for -Xcc.
427
+ auto extraArgsFilter = [&](InterfaceModuleNameExpander::ArgListTy &args) {
428
+ bool skip = false ;
429
+ InterfaceModuleNameExpander::ArgListTy newArgs;
430
+ for (auto it = args.begin (), end = args.end (); it != end; it++) {
431
+ if (skip) {
432
+ skip = false ;
433
+ continue ;
434
+ }
435
+
436
+ if ((it + 1 ) != end && isVFSOverlayFlag (*it)) {
437
+ if (!usedVFSOverlayPaths.contains (*(it + 1 ))) {
438
+ skip = true ;
439
+ continue ;
440
+ }
441
+ }
442
+
443
+ newArgs.push_back (*it);
444
+ }
445
+ args = newArgs;
446
+ return ;
447
+ };
448
+
449
+ if (nameExpander)
450
+ nameExpander->pruneExtraArgs (extraArgsFilter);
451
+
405
452
commandline = std::move (resolvedCommandLine);
406
453
}
407
454
455
+ void updateSwiftInterfaceCommandLine () {
456
+ // The command line needs upadte once we prune the unused VFS overlays.
457
+ // The update consists of two steps.
458
+ // 1. Recompute the output path, which includes the module hash.
459
+ // 2. Update `-o `'s value on the command line with the new output path.
460
+
461
+ assert (nameExpander && " Can only update if we hae a nameExpander." );
462
+ auto expandedName = nameExpander->getExpandedName ();
463
+
464
+ StringRef outputName = expandedName.outputPath .str ();
465
+
466
+ bool isOutputPath = false ;
467
+ for (auto &A : commandline) {
468
+ if (isOutputPath) {
469
+ A = outputName.str ();
470
+ break ;
471
+ } else if (A == " -o" ) {
472
+ isOutputPath = true ;
473
+ }
474
+ }
475
+
476
+ return ;
477
+ }
478
+
408
479
llvm::Error collectCASDependencies (ModuleDependencyInfo &dependencyInfoCopy) {
409
480
if (!instance.getInvocation ().getCASOptions ().EnableCaching )
410
481
return llvm::Error::success ();
@@ -524,10 +595,11 @@ class ExplicitModuleDependencyResolver {
524
595
}
525
596
526
597
private:
527
- ModuleDependencyID moduleID;
598
+ const ModuleDependencyID & moduleID;
528
599
ModuleDependenciesCache &cache;
529
600
CompilerInstance &instance;
530
601
const ModuleDependencyInfo &resolvingDepInfo;
602
+ std::unique_ptr<InterfaceModuleNameExpander> nameExpander;
531
603
532
604
std::optional<SwiftDependencyTracker> tracker;
533
605
std::vector<std::string> rootIDs;
@@ -540,7 +612,7 @@ class ExplicitModuleDependencyResolver {
540
612
};
541
613
542
614
static llvm::Error resolveExplicitModuleInputs (
543
- ModuleDependencyID moduleID,
615
+ const ModuleDependencyID & moduleID,
544
616
const std::set<ModuleDependencyID> &dependencies,
545
617
ModuleDependenciesCache &cache, CompilerInstance &instance,
546
618
std::optional<std::set<ModuleDependencyID>> bridgingHeaderDeps,
0 commit comments