mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Serialization] Load non-public transitive dependencies on @testable imports
A @testable import allows a client to call internal decls which may refer to non-public dependencies. To support such a use case, load non-public transitive dependencies of a module when it's imported @testable from the main module. This replaces the previous behavior where we loaded those dependencies for any modules built for testing. This was risky as we would load more module for any debug build, opening the door to a different behavior between debug and release builds. In contrast, applying this logic to @testable clients will only change the behavior of test targets. rdar://107329303
This commit is contained in:
@@ -430,7 +430,8 @@ llvm::ErrorOr<ModuleDependencyInfo> SerializedModuleLoaderBase::scanModuleFile(
|
||||
loadedModuleFile->getTransitiveLoadingBehavior(dependency,
|
||||
/*debuggerMode*/false,
|
||||
/*isPartialModule*/false,
|
||||
/*package*/Ctx.LangOpts.PackageName);
|
||||
/*package*/Ctx.LangOpts.PackageName,
|
||||
loadedModuleFile->isTestable());
|
||||
if (transitiveBehavior != ModuleLoadingBehavior::Required)
|
||||
continue;
|
||||
|
||||
@@ -1039,11 +1040,12 @@ void swift::serialization::diagnoseSerializedASTLoadFailureTransitive(
|
||||
std::copy_if(
|
||||
loadedModuleFile->getDependencies().begin(),
|
||||
loadedModuleFile->getDependencies().end(), std::back_inserter(missing),
|
||||
[&duplicates, &loadedModuleFile](
|
||||
[&duplicates, &loadedModuleFile, forTestable](
|
||||
const ModuleFile::Dependency &dependency) -> bool {
|
||||
if (dependency.isLoaded() || dependency.isHeader() ||
|
||||
loadedModuleFile->getTransitiveLoadingBehavior(dependency) !=
|
||||
ModuleLoadingBehavior::Required) {
|
||||
loadedModuleFile->getTransitiveLoadingBehavior(dependency,
|
||||
forTestable)
|
||||
!= ModuleLoadingBehavior::Required) {
|
||||
return false;
|
||||
}
|
||||
return duplicates.insert(dependency.Core.RawPath).second;
|
||||
@@ -1472,6 +1474,18 @@ void SerializedASTFile::collectLinkLibraries(
|
||||
}
|
||||
}
|
||||
|
||||
void SerializedASTFile::loadDependenciesForTestable(SourceLoc diagLoc) const {
|
||||
serialization::Status status =
|
||||
File.loadDependenciesForFileContext(this, diagLoc, /*forTestable=*/true);
|
||||
|
||||
if (status != serialization::Status::Valid) {
|
||||
if (diagLoc)
|
||||
serialization::diagnoseSerializedASTLoadFailureTransitive(
|
||||
getASTContext(), diagLoc, status, &File,
|
||||
getParentModule()->getName(), /*forTestable*/true);
|
||||
}
|
||||
}
|
||||
|
||||
bool SerializedASTFile::isSIB() const {
|
||||
return File.isSIB();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user