mirror of
https://github.com/apple/swift.git
synced 2026-06-20 15:42:51 +02:00
[DependencyScan] Propagate module library level through dependency scanner for CAS builds
Compute and propagate the library level (api/spi/ipi) of each module dependency through the dependency scanner so that the compiler can correctly enforce private module import diagnostics in CAS mode, where path-based SPI detection fails because CAS abstracts file paths to content IDs. Swift modules: - Detect library level from the module interface path using libraryLevelFromPath() during scanning, for both textual (.swiftinterface) and binary (.swiftmodule) Swift modules. Clang modules: - Expose ModuleMapIsPrivate from clang::Module in ModuleDeps via the dependency scanning infrastructure. - Set library level for clang modules in bridgeClangModuleDependency() using ModuleMapIsPrivate (catches module.private.modulemap in any SDK location) and libraryLevelFromPath() on the module map file (catches modules under PrivateFrameworks directories). The library level is: - Stored in ModuleDependencyInfo and serialized in the module dependency cache (format version bumped to v8). - Exposed through the swiftscan C API via a new swiftscan_module_info_get_library_level() function (API minor version bumped to 3). - Emitted in the dependency scanner JSON output as "libraryLevel" for all module kinds (Swift textual, Swift binary, Clang, and main module). - Parsed from the explicit module map JSON by ExplicitModuleMapParser for both Swift (ExplicitSwiftModuleInputInfo) and Clang (ExplicitClangModuleInputInfo) modules. - Looked up in ModuleLibraryLevelRequest via ASTContext::getExplicitModuleLibraryLevel(name, isClang), which consults the appropriate map (Swift or Clang) based on module kind. rdar://172693314 Assisted-By: Claude
This commit is contained in:
@@ -232,10 +232,11 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
||||
|
||||
std::vector<ScannerImportStatementInfo> importStatements;
|
||||
std::vector<ScannerImportStatementInfo> optionalImportStatements;
|
||||
LibraryLevel currentLibraryLevel = LibraryLevel::Other;
|
||||
|
||||
auto addCommonDependencyInfo =
|
||||
[&importedClangDependenciesIDs, ¯oDependencies]
|
||||
(ModuleDependencyInfo &moduleDep) {
|
||||
[&importedClangDependenciesIDs, ¯oDependencies,
|
||||
¤tLibraryLevel](ModuleDependencyInfo &moduleDep) {
|
||||
// Add qualified dependencies of this module
|
||||
moduleDep.setImportedClangDependencies(importedClangDependenciesIDs);
|
||||
|
||||
@@ -244,6 +245,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
||||
moduleDep.addMacroDependency(md.first, md.second.LibraryPath,
|
||||
md.second.ExecutablePath);
|
||||
|
||||
moduleDep.setLibraryLevel(currentLibraryLevel);
|
||||
moduleDep.setIsFinalized(true);
|
||||
};
|
||||
|
||||
@@ -477,7 +479,8 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
||||
importedSwiftDependenciesIDsArrayID,
|
||||
importedClangDependenciesIDsArrayID,
|
||||
crossImportOverlayDependenciesIDsArrayID,
|
||||
swiftOverlayDependenciesIDsArrayID, moduleCacheKeyID;
|
||||
swiftOverlayDependenciesIDsArrayID, moduleCacheKeyID,
|
||||
libraryLevelValue;
|
||||
|
||||
ModuleInfoLayout::readRecord(Scratch, moduleNameID, moduleImportsArrayID,
|
||||
optionalImportsArrayID, linkLibraryArrayID,
|
||||
@@ -486,7 +489,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
||||
importedClangDependenciesIDsArrayID,
|
||||
crossImportOverlayDependenciesIDsArrayID,
|
||||
swiftOverlayDependenciesIDsArrayID,
|
||||
moduleCacheKeyID);
|
||||
moduleCacheKeyID, libraryLevelValue);
|
||||
auto moduleName = getIdentifier(moduleNameID);
|
||||
if (!moduleName)
|
||||
llvm::report_fatal_error("Bad module name");
|
||||
@@ -544,6 +547,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
||||
if (!optionalMacroDependencies)
|
||||
llvm::report_fatal_error("Bad Macro Dependencies info");
|
||||
macroDependencies = *optionalMacroDependencies;
|
||||
currentLibraryLevel = static_cast<LibraryLevel>(libraryLevelValue);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1598,7 +1602,8 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
|
||||
ModuleIdentifierArrayKind::CrossImportOverlayDependenciesIDs),
|
||||
getIdentifierArrayID(
|
||||
moduleID, ModuleIdentifierArrayKind::SwiftOverlayDependenciesIDs),
|
||||
getIdentifier(dependencyInfo.getModuleCacheKey()));
|
||||
getIdentifier(dependencyInfo.getModuleCacheKey()),
|
||||
static_cast<unsigned>(dependencyInfo.getLibraryLevel()));
|
||||
|
||||
switch (dependencyInfo.getKind()) {
|
||||
case swift::ModuleDependencyKind::SwiftInterface: {
|
||||
|
||||
Reference in New Issue
Block a user