4141#include " swift/AST/PropertyWrappers.h"
4242#include " swift/AST/ProtocolConformance.h"
4343#include " swift/AST/RawComment.h"
44+ #include " swift/AST/SearchPathOptions.h"
4445#include " swift/AST/SILLayout.h"
4546#include " swift/AST/SemanticAttrs.h"
4647#include " swift/AST/SourceFile.h"
@@ -1573,29 +1574,32 @@ Optional<ModuleDependencies> ASTContext::getModuleDependencies(
15731574 bool cacheOnly) {
15741575 // Retrieve the dependencies for this module.
15751576 if (cacheOnly) {
1577+ auto searchPathSet = getAllModuleSearchPathsSet ();
15761578 // Check whether we've cached this result.
15771579 if (!isUnderlyingClangModule) {
1578- if (auto found = cache.findDependencies (moduleName,
1579- ModuleDependenciesKind::SwiftTextual))
1580+ if (auto found = cache.findDependencies (
1581+ moduleName,
1582+ {ModuleDependenciesKind::SwiftTextual, searchPathSet}))
15801583 return found;
1581- if (auto found = cache.findDependencies (moduleName,
1582- ModuleDependenciesKind::SwiftTextual ))
1584+ if (auto found = cache.findDependencies (
1585+ moduleName, { ModuleDependenciesKind::SwiftBinary, searchPathSet} ))
15831586 return found;
1584- if (auto found = cache.findDependencies (moduleName,
1585- ModuleDependenciesKind::SwiftPlaceholder))
1587+ if (auto found = cache.findDependencies (
1588+ moduleName,
1589+ {ModuleDependenciesKind::SwiftPlaceholder, searchPathSet}))
15861590 return found;
15871591 }
1588- if (auto found = cache.findDependencies (moduleName,
1589- ModuleDependenciesKind::Clang))
1592+ if (auto found = cache.findDependencies (
1593+ moduleName, { ModuleDependenciesKind::Clang, searchPathSet} ))
15901594 return found;
15911595 } else {
15921596 for (auto &loader : getImpl ().ModuleLoaders ) {
15931597 if (isUnderlyingClangModule &&
15941598 loader.get () != getImpl ().TheClangModuleLoader )
15951599 continue ;
15961600
1597- if (auto dependencies = loader-> getModuleDependencies (moduleName, cache,
1598- delegate))
1601+ if (auto dependencies =
1602+ loader-> getModuleDependencies (moduleName, cache, delegate))
15991603 return dependencies;
16001604 }
16011605 }
@@ -1618,6 +1622,65 @@ ASTContext::getSwiftModuleDependencies(StringRef moduleName,
16181622 return None;
16191623}
16201624
1625+ namespace {
1626+ static StringRef
1627+ pathStringFromFrameworkSearchPath (const SearchPathOptions::FrameworkSearchPath &next) {
1628+ return next.Path ;
1629+ };
1630+ }
1631+
1632+ std::vector<std::string> ASTContext::getDarwinImplicitFrameworkSearchPaths ()
1633+ const {
1634+ assert (LangOpts.Target .isOSDarwin ());
1635+ SmallString<128 > systemFrameworksScratch;
1636+ systemFrameworksScratch = SearchPathOpts.SDKPath ;
1637+ llvm::sys::path::append (systemFrameworksScratch, " System" , " Library" , " Frameworks" );
1638+
1639+ SmallString<128 > frameworksScratch;
1640+ frameworksScratch = SearchPathOpts.SDKPath ;
1641+ llvm::sys::path::append (frameworksScratch, " Library" , " Frameworks" );
1642+ return {systemFrameworksScratch.str ().str (), frameworksScratch.str ().str ()};
1643+ }
1644+
1645+ llvm::StringSet<> ASTContext::getAllModuleSearchPathsSet ()
1646+ const {
1647+ llvm::StringSet<> result;
1648+ result.insert (SearchPathOpts.ImportSearchPaths .begin (),
1649+ SearchPathOpts.ImportSearchPaths .end ());
1650+
1651+ // Framework paths are "special", they contain more than path strings,
1652+ // but path strings are all we care about here.
1653+ using FrameworkPathView = ArrayRefView<SearchPathOptions::FrameworkSearchPath,
1654+ StringRef,
1655+ pathStringFromFrameworkSearchPath>;
1656+ FrameworkPathView frameworkPathsOnly{SearchPathOpts.FrameworkSearchPaths };
1657+ result.insert (frameworkPathsOnly.begin (), frameworkPathsOnly.end ());
1658+
1659+ if (LangOpts.Target .isOSDarwin ()) {
1660+ auto implicitFrameworkSearchPaths = getDarwinImplicitFrameworkSearchPaths ();
1661+ result.insert (implicitFrameworkSearchPaths.begin (),
1662+ implicitFrameworkSearchPaths.end ());
1663+ }
1664+ result.insert (SearchPathOpts.RuntimeLibraryImportPaths .begin (),
1665+ SearchPathOpts.RuntimeLibraryImportPaths .end ());
1666+
1667+ // ClangImporter special-cases the path for SwiftShims, so do the same here
1668+ // If there are no shims in the resource dir, add a search path in the SDK.
1669+ SmallString<128 > shimsPath (SearchPathOpts.RuntimeResourcePath );
1670+ llvm::sys::path::append (shimsPath, " shims" );
1671+ if (!llvm::sys::fs::exists (shimsPath)) {
1672+ shimsPath = SearchPathOpts.SDKPath ;
1673+ llvm::sys::path::append (shimsPath, " usr" , " lib" , " swift" , " shims" );
1674+ }
1675+ result.insert (shimsPath.str ());
1676+
1677+ // Clang system modules are found in the SDK root
1678+ SmallString<128 > clangSysRootPath (SearchPathOpts.SDKPath );
1679+ llvm::sys::path::append (clangSysRootPath, " usr" , " include" );
1680+ result.insert (clangSysRootPath.str ());
1681+ return result;
1682+ }
1683+
16211684void ASTContext::loadExtensions (NominalTypeDecl *nominal,
16221685 unsigned previousGeneration) {
16231686 PrettyStackTraceDecl stackTrace (" loading extensions for" , nominal);
0 commit comments