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"
@@ -1641,29 +1642,32 @@ Optional<ModuleDependencies> ASTContext::getModuleDependencies(
16411642 bool cacheOnly) {
16421643 // Retrieve the dependencies for this module.
16431644 if (cacheOnly) {
1645+ auto searchPathSet = getAllModuleSearchPathsSet ();
16441646 // Check whether we've cached this result.
16451647 if (!isUnderlyingClangModule) {
1646- if (auto found = cache.findDependencies (moduleName,
1647- ModuleDependenciesKind::SwiftTextual))
1648+ if (auto found = cache.findDependencies (
1649+ moduleName,
1650+ {ModuleDependenciesKind::SwiftTextual, searchPathSet}))
16481651 return found;
1649- if (auto found = cache.findDependencies (moduleName,
1650- ModuleDependenciesKind::SwiftTextual ))
1652+ if (auto found = cache.findDependencies (
1653+ moduleName, { ModuleDependenciesKind::SwiftBinary, searchPathSet} ))
16511654 return found;
1652- if (auto found = cache.findDependencies (moduleName,
1653- ModuleDependenciesKind::SwiftPlaceholder))
1655+ if (auto found = cache.findDependencies (
1656+ moduleName,
1657+ {ModuleDependenciesKind::SwiftPlaceholder, searchPathSet}))
16541658 return found;
16551659 }
1656- if (auto found = cache.findDependencies (moduleName,
1657- ModuleDependenciesKind::Clang))
1660+ if (auto found = cache.findDependencies (
1661+ moduleName, { ModuleDependenciesKind::Clang, searchPathSet} ))
16581662 return found;
16591663 } else {
16601664 for (auto &loader : getImpl ().ModuleLoaders ) {
16611665 if (isUnderlyingClangModule &&
16621666 loader.get () != getImpl ().TheClangModuleLoader )
16631667 continue ;
16641668
1665- if (auto dependencies = loader-> getModuleDependencies (moduleName, cache,
1666- delegate))
1669+ if (auto dependencies =
1670+ loader-> getModuleDependencies (moduleName, cache, delegate))
16671671 return dependencies;
16681672 }
16691673 }
@@ -1686,6 +1690,65 @@ ASTContext::getSwiftModuleDependencies(StringRef moduleName,
16861690 return None;
16871691}
16881692
1693+ namespace {
1694+ static StringRef
1695+ pathStringFromFrameworkSearchPath (const SearchPathOptions::FrameworkSearchPath &next) {
1696+ return next.Path ;
1697+ };
1698+ }
1699+
1700+ std::vector<std::string> ASTContext::getDarwinImplicitFrameworkSearchPaths ()
1701+ const {
1702+ assert (LangOpts.Target .isOSDarwin ());
1703+ SmallString<128 > systemFrameworksScratch;
1704+ systemFrameworksScratch = SearchPathOpts.SDKPath ;
1705+ llvm::sys::path::append (systemFrameworksScratch, " System" , " Library" , " Frameworks" );
1706+
1707+ SmallString<128 > frameworksScratch;
1708+ frameworksScratch = SearchPathOpts.SDKPath ;
1709+ llvm::sys::path::append (frameworksScratch, " Library" , " Frameworks" );
1710+ return {systemFrameworksScratch.str ().str (), frameworksScratch.str ().str ()};
1711+ }
1712+
1713+ llvm::StringSet<> ASTContext::getAllModuleSearchPathsSet ()
1714+ const {
1715+ llvm::StringSet<> result;
1716+ result.insert (SearchPathOpts.ImportSearchPaths .begin (),
1717+ SearchPathOpts.ImportSearchPaths .end ());
1718+
1719+ // Framework paths are "special", they contain more than path strings,
1720+ // but path strings are all we care about here.
1721+ using FrameworkPathView = ArrayRefView<SearchPathOptions::FrameworkSearchPath,
1722+ StringRef,
1723+ pathStringFromFrameworkSearchPath>;
1724+ FrameworkPathView frameworkPathsOnly{SearchPathOpts.FrameworkSearchPaths };
1725+ result.insert (frameworkPathsOnly.begin (), frameworkPathsOnly.end ());
1726+
1727+ if (LangOpts.Target .isOSDarwin ()) {
1728+ auto implicitFrameworkSearchPaths = getDarwinImplicitFrameworkSearchPaths ();
1729+ result.insert (implicitFrameworkSearchPaths.begin (),
1730+ implicitFrameworkSearchPaths.end ());
1731+ }
1732+ result.insert (SearchPathOpts.RuntimeLibraryImportPaths .begin (),
1733+ SearchPathOpts.RuntimeLibraryImportPaths .end ());
1734+
1735+ // ClangImporter special-cases the path for SwiftShims, so do the same here
1736+ // If there are no shims in the resource dir, add a search path in the SDK.
1737+ SmallString<128 > shimsPath (SearchPathOpts.RuntimeResourcePath );
1738+ llvm::sys::path::append (shimsPath, " shims" );
1739+ if (!llvm::sys::fs::exists (shimsPath)) {
1740+ shimsPath = SearchPathOpts.SDKPath ;
1741+ llvm::sys::path::append (shimsPath, " usr" , " lib" , " swift" , " shims" );
1742+ }
1743+ result.insert (shimsPath.str ());
1744+
1745+ // Clang system modules are found in the SDK root
1746+ SmallString<128 > clangSysRootPath (SearchPathOpts.SDKPath );
1747+ llvm::sys::path::append (clangSysRootPath, " usr" , " include" );
1748+ result.insert (clangSysRootPath.str ());
1749+ return result;
1750+ }
1751+
16891752void ASTContext::loadExtensions (NominalTypeDecl *nominal,
16901753 unsigned previousGeneration) {
16911754 PrettyStackTraceDecl stackTrace (" loading extensions for" , nominal);
0 commit comments