Correct discrepancies in the package interface file lookup.

Add a check for the client side flag which explcitly opts in to loading the package interface,
besides whether package-name is empty or in the same package.

rdar://131393508
This commit is contained in:
Ellie Shin
2024-07-10 18:23:12 -07:00
parent bbc02a5544
commit 255a0940de

View File

@@ -618,9 +618,6 @@ std::string SerializedModuleBaseName::getName(file_types::ID fileTy) const {
std::optional<std::string>
SerializedModuleBaseName::getPackageInterfacePathIfInSamePackage(
llvm::vfs::FileSystem &fs, ASTContext &ctx) const {
if (!ctx.LangOpts.EnablePackageInterfaceLoad)
return std::nullopt;
std::string packagePath{
getName(file_types::TY_PackageSwiftModuleInterfaceFile)};
@@ -667,8 +664,12 @@ SerializedModuleBaseName::findInterfacePath(llvm::vfs::FileSystem &fs,
if (!fs.exists(interfacePath))
return std::nullopt;
// If there is a package name, try look for the package interface.
if (!ctx.LangOpts.PackageName.empty()) {
// If there is a package name, try to look for the package interface,
// which can only be loaded if -experimental-package-interface-load
// is passed to the client, so fall back to private/public interface
// if not.
if (!ctx.LangOpts.PackageName.empty() &&
ctx.LangOpts.EnablePackageInterfaceLoad) {
if (auto maybePackageInterface =
getPackageInterfacePathIfInSamePackage(fs, ctx))
return *maybePackageInterface;