Skip to content

Commit 5be7e2d

Browse files
committed
[Serialization] Load indirect package dependencies from the current package
When loading a swiftmodule A, read its package information to tell if the current client should load A's dependencies imports by a package import. Only clients belonging to the same package as A should load those dependencies, clients outside of the package likely don't have access to those dependencies. This is specific to swiftmodules as swiftinterfaces never display a package-only import. Clients are unaware of package dependencies when building against a swiftinterface. rdar://106164813
1 parent 6980cf2 commit 5be7e2d

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

lib/Serialization/ModuleFile.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
209209
continue;
210210
}
211211

212+
if (dependency.isPackageOnly() &&
213+
ctx.LangOpts.PackageName != this->getModulePackageName())
214+
continue;
215+
212216
ImportPath::Builder builder(ctx, dependency.Core.RawPath,
213217
/*separator=*/'\0');
214218
for (const auto &elem : builder) {

lib/Serialization/ModuleFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ class ModuleFile
107107
bool isImplementationOnly() const {
108108
return Core.isImplementationOnly();
109109
}
110+
bool isPackageOnly() const {
111+
return Core.isPackageOnly();
112+
}
110113

111114
bool isHeader() const { return Core.isHeader(); }
112115
bool isScoped() const { return Core.isScoped(); }

lib/Serialization/ModuleFileSharedCore.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ class ModuleFileSharedCore {
150150
bool isImplementationOnly() const {
151151
return getImportControl() == ImportFilterKind::ImplementationOnly;
152152
}
153+
bool isPackageOnly() const {
154+
return getImportControl() == ImportFilterKind::PackageOnly;
155+
}
153156

154157
bool isHeader() const { return IsHeader; }
155158
bool isScoped() const { return IsScoped; }
@@ -557,6 +560,10 @@ class ModuleFileSharedCore {
557560
return Name;
558561
}
559562

563+
StringRef getModulePackageName() const {
564+
return ModulePackageName;
565+
}
566+
560567
/// Returns the list of modules this module depends on.
561568
ArrayRef<Dependency> getDependencies() const {
562569
return Dependencies;

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ llvm::ErrorOr<ModuleDependencyInfo> SerializedModuleLoaderBase::scanModuleFile(
426426
if (dependency.isImplementationOnly())
427427
continue;
428428

429+
if (dependency.isPackageOnly() &&
430+
Ctx.LangOpts.PackageName != loadedModuleFile->getModulePackageName())
431+
continue;
432+
429433
// Find the top-level module name.
430434
auto modulePathStr = dependency.getPrettyPrintedPath();
431435
StringRef moduleName = modulePathStr;

0 commit comments

Comments
 (0)