Skip to content

Commit 1081f56

Browse files
[PackageInterface] Reduce parsing interface file for package-name
Try best to avoid parsing interface file to extract package name during dependency discovery to improve scanning performance. rdar://124056756
1 parent 52ad460 commit 1081f56

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -652,12 +652,21 @@ SerializedModuleBaseName::findInterfacePath(llvm::vfs::FileSystem &fs,
652652
if (!fs.exists(interfacePath))
653653
return std::nullopt;
654654

655-
// If in the same package, try return the package interface path if not
656-
// preferring the interface file.
657-
if (!ctx.LangOpts.AllowNonPackageInterfaceImportFromSamePackage) {
658-
if (auto packageName = getPackageNameFromInterface(interfacePath, fs)) {
659-
if (*packageName == ctx.LangOpts.PackageName)
660-
return getPackageInterfacePathIfInSamePackage(fs, ctx);
655+
// If there is a package name, try look for the package interface.
656+
if (!ctx.LangOpts.PackageName.empty()) {
657+
if (auto maybePackageInterface =
658+
getPackageInterfacePathIfInSamePackage(fs, ctx))
659+
return *maybePackageInterface;
660+
661+
// If package interface is not found, check if we can load the
662+
// public/private interface file by checking:
663+
// * if AllowNonPackageInterfaceImportFromSamePackage is true
664+
// * if the package name is not equal so not in the same package.
665+
if (!ctx.LangOpts.AllowNonPackageInterfaceImportFromSamePackage) {
666+
if (auto packageName = getPackageNameFromInterface(interfacePath, fs)) {
667+
if (*packageName == ctx.LangOpts.PackageName)
668+
return std::nullopt;
669+
}
661670
}
662671
}
663672

0 commit comments

Comments
 (0)