@@ -356,19 +356,6 @@ class swift::ParseableInterfaceBuilder {
356
356
return false ;
357
357
}
358
358
359
- // / Determines if the dependency with the provided path is a swiftmodule in
360
- // / either the module cache or prebuilt module cache
361
- bool isCachedModule (StringRef DepName) const {
362
- auto Ext = llvm::sys::path::extension (DepName);
363
- auto Ty = file_types::lookupTypeForExtension (Ext);
364
-
365
- if (Ty != file_types::TY_SwiftModuleFile)
366
- return false ;
367
- if (!moduleCachePath.empty () && DepName.startswith (moduleCachePath))
368
- return true ;
369
- return !prebuiltCachePath.empty () && DepName.startswith (prebuiltCachePath);
370
- }
371
-
372
359
// / Populate the provided \p Deps with \c FileDependency entries for all
373
360
// / dependencies \p SubInstance's DependencyTracker recorded while compiling
374
361
// / the module, excepting .swiftmodules in \p moduleCachePath or
@@ -379,12 +366,31 @@ class swift::ParseableInterfaceBuilder {
379
366
SmallVectorImpl<FileDependency> &Deps,
380
367
bool IsHashBased) {
381
368
StringRef SDKPath = SubInstance.getASTContext ().SearchPathOpts .SDKPath ;
369
+ StringRef ResourcePath =
370
+ SubInstance.getASTContext ().SearchPathOpts .RuntimeResourcePath ;
382
371
auto DTDeps = SubInstance.getDependencyTracker ()->getDependencies ();
383
372
SmallVector<StringRef, 16 > InitialDepNames (DTDeps.begin (), DTDeps.end ());
384
373
InitialDepNames.push_back (interfacePath);
385
374
llvm::StringSet<> AllDepNames;
386
375
387
376
for (auto const &DepName : InitialDepNames) {
377
+ assert (moduleCachePath.empty () || !DepName.startswith (moduleCachePath));
378
+ assert (prebuiltCachePath.empty () || !DepName.startswith (prebuiltCachePath));
379
+
380
+ // / Lazily load the dependency buffer if we need it. If we're not
381
+ // / dealing with a hash-based dependencies, and if the dependency is
382
+ // / not a .swiftmodule, we can avoid opening the buffer.
383
+ std::unique_ptr<llvm::MemoryBuffer> DepBuf = nullptr ;
384
+ auto getDepBuf = [&]() -> llvm::MemoryBuffer * {
385
+ if (DepBuf) return DepBuf.get ();
386
+ if (auto Buf = getBufferOfDependency (fs, DepName, interfacePath,
387
+ diags, diagnosticLoc)) {
388
+ DepBuf = std::move (Buf);
389
+ return DepBuf.get ();
390
+ }
391
+ return nullptr ;
392
+ };
393
+
388
394
// Adjust the paths of dependences in the SDK to be relative to it
389
395
bool IsSDKRelative = false ;
390
396
StringRef DepNameToStore = DepName;
@@ -410,48 +416,10 @@ class swift::ParseableInterfaceBuilder {
410
416
dependencyTracker->addDependency (DepName, /* isSystem*/ IsSDKRelative);
411
417
}
412
418
413
- // / Lazily load the dependency buffer if we need it. If we're not
414
- // / dealing with a hash-based dependencies, and if the dependency is
415
- // / not a .swiftmodule, we can avoid opening the buffer.
416
- std::unique_ptr<llvm::MemoryBuffer> DepBuf = nullptr ;
417
- auto getDepBuf = [&]() -> llvm::MemoryBuffer * {
418
- if (DepBuf) return DepBuf.get ();
419
- if (auto Buf = getBufferOfDependency (fs, DepName, interfacePath,
420
- diags, diagnosticLoc)) {
421
- DepBuf = std::move (Buf);
422
- return DepBuf.get ();
423
- }
424
- return nullptr ;
425
- };
426
-
427
- // If Dep is itself a cached .swiftmodule, pull out its deps and include
428
- // them in our own, so we have a single-file view of transitive deps:
429
- // removes redundancies, makes the cache more relocatable, and avoids
430
- // opening and reading multiple swiftmodules during future loads.
431
- if (isCachedModule (DepName)) {
432
- auto buf = getDepBuf ();
433
- if (!buf) return true ;
434
- SmallVector<FileDependency, 16 > SubDeps;
435
- auto VI = serialization::validateSerializedAST (buf->getBuffer (),
436
- /* ExtendedValidationInfo=*/ nullptr , &SubDeps);
437
- if (VI.status != serialization::Status::Valid) {
438
- diags.diagnose (diagnosticLoc,
439
- diag::error_extracting_dependencies_from_cached_module,
440
- DepName);
441
- return true ;
442
- }
443
- for (auto const &SubDep : SubDeps) {
444
- if (AllDepNames.insert (SubDep.getPath ()).second ) {
445
- Deps.push_back (SubDep);
446
- if (dependencyTracker)
447
- dependencyTracker->addDependency (
448
- SubDep.getPath (), /* IsSystem=*/ SubDep.isSDKRelative ());
449
- }
450
- }
419
+ // Don't serialize compiler-relative deps so the cache is relocatable.
420
+ if (DepName.startswith (ResourcePath))
451
421
continue ;
452
- }
453
422
454
- // Otherwise, include this dependency directly
455
423
auto Status = getStatusOfDependency (fs, DepName, interfacePath,
456
424
diags, diagnosticLoc);
457
425
if (!Status)
@@ -761,11 +729,11 @@ class ParseableInterfaceModuleLoaderImpl {
761
729
if (dependencyTracker)
762
730
dependencyTracker->addDependency (fullPath, /* isSystem*/ in.isSDKRelative ());
763
731
if (!dependencyIsUpToDate (in, fullPath)) {
764
- LLVM_DEBUG (llvm::dbgs () << " Dep " << in. getPath ()
732
+ LLVM_DEBUG (llvm::dbgs () << " Dep " << fullPath
765
733
<< " is directly out of date\n " );
766
734
return false ;
767
735
}
768
- LLVM_DEBUG (llvm::dbgs () << " Dep " << in. getPath () << " is up to date\n " );
736
+ LLVM_DEBUG (llvm::dbgs () << " Dep " << fullPath << " is up to date\n " );
769
737
}
770
738
return true ;
771
739
}
@@ -1047,6 +1015,12 @@ class ParseableInterfaceModuleLoaderImpl {
1047
1015
1048
1016
} // end anonymous namespace
1049
1017
1018
+ bool ParseableInterfaceModuleLoader::isCached (StringRef DepPath) {
1019
+ if (!CacheDir.empty () && DepPath.startswith (CacheDir))
1020
+ return true ;
1021
+ return !PrebuiltCacheDir.empty () && DepPath.startswith (PrebuiltCacheDir);
1022
+ }
1023
+
1050
1024
// / Load a .swiftmodule associated with a .swiftinterface either from a
1051
1025
// / cache or by converting it in a subordinate \c CompilerInstance, caching
1052
1026
// / the results.
0 commit comments