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