2020#include " swift/AST/FileSystem.h"
2121#include " swift/AST/Module.h"
2222#include " swift/Basic/Platform.h"
23+ #include " swift/Basic/StringExtras.h"
2324#include " swift/Frontend/CachingUtils.h"
2425#include " swift/Frontend/Frontend.h"
2526#include " swift/Frontend/ModuleInterfaceSupport.h"
@@ -233,6 +234,7 @@ struct ModuleRebuildInfo {
233234 NotIgnored,
234235 PublicFramework,
235236 InterfacePreferred,
237+ CompilerHostModule,
236238 };
237239 struct CandidateModule {
238240 std::string path;
@@ -704,7 +706,28 @@ class ModuleInterfaceLoaderImpl {
704706 bool isInResourceDir (StringRef path) {
705707 StringRef resourceDir = ctx.SearchPathOpts .RuntimeResourcePath ;
706708 if (resourceDir.empty ()) return false ;
707- return path.startswith (resourceDir);
709+ return pathStartsWith (resourceDir, path);
710+ }
711+
712+ bool isInResourceHostDir (StringRef path) {
713+ StringRef resourceDir = ctx.SearchPathOpts .RuntimeResourcePath ;
714+ if (resourceDir.empty ()) return false ;
715+
716+ SmallString<128 > hostPath;
717+ llvm::sys::path::append (hostPath,
718+ resourceDir, " host" );
719+ return pathStartsWith (hostPath, path);
720+ }
721+
722+ bool isInSystemFrameworks (StringRef path) {
723+ StringRef sdkPath = ctx.SearchPathOpts .getSDKPath ();
724+ if (sdkPath.empty ()) return false ;
725+
726+ SmallString<128 > publicFrameworksPath;
727+ llvm::sys::path::append (publicFrameworksPath,
728+ sdkPath, " System" , " Library" , " Frameworks" );
729+
730+ return pathStartsWith (publicFrameworksPath, path);
708731 }
709732
710733 std::pair<std::string, std::string> getCompiledModuleCandidates () {
@@ -719,10 +742,12 @@ class ModuleInterfaceLoaderImpl {
719742 llvm::sys::path::append (publicFrameworksPath,
720743 ctx.SearchPathOpts .getSDKPath (),
721744 " System" , " Library" , " Frameworks" );
722- if (!ctx.SearchPathOpts .getSDKPath ().empty () &&
723- modulePath.startswith (publicFrameworksPath)) {
745+ if (isInSystemFrameworks (modulePath)) {
724746 shouldLoadAdjacentModule = false ;
725747 rebuildInfo.addIgnoredModule (modulePath, ReasonIgnored::PublicFramework);
748+ } else if (isInResourceHostDir (modulePath)) {
749+ shouldLoadAdjacentModule = false ;
750+ rebuildInfo.addIgnoredModule (modulePath, ReasonIgnored::CompilerHostModule);
726751 }
727752
728753 switch (loadMode) {
0 commit comments