Skip to content

[6.2 🍒][Dependency Scanning] Fix search path context hashing hole and avoid serializing unnecessary field #81255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1094,9 +1094,6 @@ class ASTContext final {
/// $SDKROOT/System/Library/Frameworks/ and $SDKROOT/Library/Frameworks/.
std::vector<std::string> getDarwinImplicitFrameworkSearchPaths() const;

/// Return a set of all possible filesystem locations where modules can be found.
llvm::StringSet<> getAllModuleSearchPathsSet() const;

/// Load extensions to the given nominal type from the external
/// module loaders.
///
Expand Down
5 changes: 0 additions & 5 deletions include/swift/AST/ModuleDependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -787,11 +787,6 @@ class ModuleDependencyInfo {
return storage->auxiliaryFiles;
}

void
setAuxiliaryFiles(const ArrayRef<std::string> auxiliaryFiles) {
storage->auxiliaryFiles.assign(auxiliaryFiles.begin(), auxiliaryFiles.end());
}

bool isStaticLibrary() const {
if (auto *detail = getAsSwiftInterfaceModule())
return detail->isStatic;
Expand Down
23 changes: 7 additions & 16 deletions include/swift/AST/SearchPathOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ class SearchPathOptions {
friend bool operator!=(const SearchPath &LHS, const SearchPath &RHS) {
return !(LHS == RHS);
}
friend llvm::hash_code
hash_value(const SearchPath &searchPath) {
return llvm::hash_combine(searchPath.Path, searchPath.IsSystem);
}
};

private:
Expand Down Expand Up @@ -599,30 +603,17 @@ class SearchPathOptions {
makeOverlayFileSystem(
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS) const;

private:
static StringRef pathStringFromSearchPath(const SearchPath &next) {
return next.Path;
};

public:
/// Return a hash code of any components from these options that should
/// contribute to a Swift Bridging PCH hash.
llvm::hash_code getPCHHashComponents() const {
using llvm::hash_combine;
using llvm::hash_combine_range;

using SearchPathView =
ArrayRefView<SearchPath, StringRef, pathStringFromSearchPath>;
SearchPathView importPathsOnly{ImportSearchPaths};
SearchPathView frameworkPathsOnly{FrameworkSearchPaths};

return hash_combine(SDKPath,
// FIXME: Should we include the system-ness of
// search paths too?
hash_combine_range(importPathsOnly.begin(), importPathsOnly.end()),
hash_combine_range(ImportSearchPaths.begin(), ImportSearchPaths.end()),
hash_combine_range(VFSOverlayFiles.begin(), VFSOverlayFiles.end()),
hash_combine_range(frameworkPathsOnly.begin(),
frameworkPathsOnly.end()),
hash_combine_range(FrameworkSearchPaths.begin(),
FrameworkSearchPaths.end()),
hash_combine_range(LibrarySearchPaths.begin(),
LibrarySearchPaths.end()),
RuntimeResourcePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ using llvm::BCVBR;
const unsigned char MODULE_DEPENDENCY_CACHE_FORMAT_SIGNATURE[] = {'I', 'M', 'D','C'};
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MAJOR = 9;
/// Increment this on every change.
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 1;
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 2;

/// Various identifiers in this format will rely on having their strings mapped
/// using this ID.
Expand Down Expand Up @@ -80,7 +80,6 @@ using LinkLibrariesArrayIDField = IdentifierIDField;
using MacroDependenciesArrayIDField = IdentifierIDField;
using FlagIDArrayIDField = IdentifierIDField;
using DependencyIDArrayIDField = IdentifierIDField;
using AuxiliaryFilesArrayIDField = IdentifierIDField;
using SourceLocationIDArrayIDField = IdentifierIDField;

/// The ID of the top-level block containing the dependency graph
Expand Down Expand Up @@ -204,8 +203,7 @@ using ModuleInfoLayout =
DependencyIDArrayIDField, // importedClangModules
DependencyIDArrayIDField, // crossImportOverlayModules
DependencyIDArrayIDField, // swiftOverlayDependencies
ModuleCacheKeyIDField, // moduleCacheKey
AuxiliaryFilesArrayIDField // auxiliaryFiles
ModuleCacheKeyIDField // moduleCacheKey
>;

using SwiftInterfaceModuleDetailsLayout =
Expand Down
40 changes: 0 additions & 40 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2212,46 +2212,6 @@ const {
return SearchPathOpts.getDarwinImplicitFrameworkSearchPaths();
}

llvm::StringSet<> ASTContext::getAllModuleSearchPathsSet()
const {
llvm::StringSet<> result;

// Import and framework paths are "special", they contain more than path
// strings, but path strings are all we care about here.
using SearchPathView = ArrayRefView<SearchPathOptions::SearchPath, StringRef,
pathStringFromSearchPath>;

SearchPathView importPathsOnly{SearchPathOpts.getImportSearchPaths()};
result.insert(importPathsOnly.begin(), importPathsOnly.end());

SearchPathView frameworkPathsOnly{SearchPathOpts.getFrameworkSearchPaths()};
result.insert(frameworkPathsOnly.begin(), frameworkPathsOnly.end());

if (LangOpts.Target.isOSDarwin()) {
auto implicitFrameworkSearchPaths = getDarwinImplicitFrameworkSearchPaths();
result.insert(implicitFrameworkSearchPaths.begin(),
implicitFrameworkSearchPaths.end());
}
result.insert(SearchPathOpts.RuntimeLibraryImportPaths.begin(),
SearchPathOpts.RuntimeLibraryImportPaths.end());

// ClangImporter special-cases the path for SwiftShims, so do the same here
// If there are no shims in the resource dir, add a search path in the SDK.
SmallString<128> shimsPath(SearchPathOpts.RuntimeResourcePath);
llvm::sys::path::append(shimsPath, "shims");
if (!llvm::sys::fs::exists(shimsPath)) {
shimsPath = SearchPathOpts.getSDKPath();
llvm::sys::path::append(shimsPath, "usr", "lib", "swift", "shims");
}
result.insert(shimsPath.str());

// Clang system modules are found in the SDK root
SmallString<128> clangSysRootPath(SearchPathOpts.getSDKPath());
llvm::sys::path::append(clangSysRootPath, "usr", "include");
result.insert(clangSysRootPath.str());
return result;
}

void ASTContext::loadExtensions(NominalTypeDecl *nominal,
unsigned previousGeneration) {
PrettyStackTraceDecl stackTrace("loading extensions for", nominal);
Expand Down
Loading