diff --git a/include/swift/AST/ModuleDependencies.h b/include/swift/AST/ModuleDependencies.h index 3739d7465eaf1..8f427a75e5205 100644 --- a/include/swift/AST/ModuleDependencies.h +++ b/include/swift/AST/ModuleDependencies.h @@ -31,6 +31,7 @@ #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/StringSet.h" +#include "llvm/CAS/CASConfiguration.h" #include "llvm/CAS/CachingOnDiskFileSystem.h" #include "llvm/Support/Mutex.h" #include @@ -967,7 +968,7 @@ using ModuleDependenciesKindMap = /// dependency scanner. class SwiftDependencyScanningService { /// The CASOption created the Scanning Service if used. - std::optional CASOpts; + std::optional CASConfig; /// The persistent Clang dependency scanner service std::optional diff --git a/include/swift/Basic/CASOptions.h b/include/swift/Basic/CASOptions.h index 567c34671fc49..a3ec5d603997c 100644 --- a/include/swift/Basic/CASOptions.h +++ b/include/swift/Basic/CASOptions.h @@ -20,6 +20,7 @@ #include "clang/CAS/CASOptions.h" #include "llvm/ADT/Hashing.h" +#include "llvm/CAS/CASConfiguration.h" namespace swift { @@ -37,8 +38,8 @@ class CASOptions final { /// Import modules from CAS. bool ImportModuleFromCAS = false; - /// CASOptions - clang::CASOptions CASOpts; + /// CAS Configuration. + llvm::cas::CASConfiguration Config; /// Clang Include Trees. std::string ClangIncludeTree; @@ -80,6 +81,15 @@ class CASOptions final { llvm::hash_code getModuleScanningHashComponents() const { return getPCHHashComponents(); } + + /// Return corresponding clang::CASOptions for swift CASOptions. + clang::CASOptions getClangCASOptions() const { + clang::CASOptions CASOpts; + CASOpts.CASPath = Config.CASPath; + CASOpts.PluginPath = Config.PluginPath; + CASOpts.PluginOptions = Config.PluginOptions; + return CASOpts; + } }; } // namespace swift diff --git a/lib/AST/ModuleDependencies.cpp b/lib/AST/ModuleDependencies.cpp index ae2ba45e722af..15ece7bd9498a 100644 --- a/lib/AST/ModuleDependencies.cpp +++ b/lib/AST/ModuleDependencies.cpp @@ -636,9 +636,9 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService( if (!Instance.getInvocation().getCASOptions().EnableCaching) return false; - if (CASOpts) { + if (CASConfig) { // If CASOption matches, the service is initialized already. - if (*CASOpts == Instance.getInvocation().getCASOptions().CASOpts) + if (*CASConfig == Instance.getInvocation().getCASOptions().Config) return false; // CASOption mismatch, return error. @@ -647,12 +647,12 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService( } // Setup CAS. - CASOpts = Instance.getInvocation().getCASOptions().CASOpts; + CASConfig = Instance.getInvocation().getCASOptions().Config; ClangScanningService.emplace( clang::tooling::dependencies::ScanningMode::DependencyDirectivesScan, clang::tooling::dependencies::ScanningOutputFormat::FullIncludeTree, - Instance.getInvocation().getCASOptions().CASOpts, + Instance.getInvocation().getCASOptions().getClangCASOptions(), Instance.getSharedCASInstance(), Instance.getSharedCacheInstance(), /*CachingOnDiskFileSystem=*/nullptr, // The current working directory optimization (off by default) diff --git a/lib/Basic/CASOptions.cpp b/lib/Basic/CASOptions.cpp index f7e5119f9aa07..8ba863a960754 100644 --- a/lib/Basic/CASOptions.cpp +++ b/lib/Basic/CASOptions.cpp @@ -23,14 +23,14 @@ void CASOptions::enumerateCASConfigurationFlags( llvm::function_ref Callback) const { if (EnableCaching) { Callback("-cache-compile-job"); - if (!CASOpts.CASPath.empty()) { + if (!Config.CASPath.empty()) { Callback("-cas-path"); - Callback(CASOpts.CASPath); + Callback(Config.CASPath); } - if (!CASOpts.PluginPath.empty()) { + if (!Config.PluginPath.empty()) { Callback("-cas-plugin-path"); - Callback(CASOpts.PluginPath); - for (auto Opt : CASOpts.PluginOptions) { + Callback(Config.PluginPath); + for (auto Opt : Config.PluginOptions) { Callback("-cas-plugin-option"); Callback((llvm::Twine(Opt.first) + "=" + Opt.second).str()); } diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 70664b4b7ba56..62ff26e7ebf5c 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -1184,7 +1184,7 @@ std::optional> ClangImporter::getClangCC1Arguments( // compiler can be more efficient to compute swift cache key without having // the knowledge about clang command-line options. if (ctx.CASOpts.EnableCaching || ctx.CASOpts.ImportModuleFromCAS) { - CI->getCASOpts() = ctx.CASOpts.CASOpts; + CI->getCASOpts() = ctx.CASOpts.getClangCASOptions(); // When clangImporter is used to compile (generate .pcm or .pch), need to // inherit the include tree from swift args (last one wins) and clear the // input file. diff --git a/lib/DependencyScan/ScanDependencies.cpp b/lib/DependencyScan/ScanDependencies.cpp index e78151de2eb71..2b004bd6b1a38 100644 --- a/lib/DependencyScan/ScanDependencies.cpp +++ b/lib/DependencyScan/ScanDependencies.cpp @@ -146,7 +146,8 @@ class ExplicitModuleDependencyResolver { bridgingHeaderBuildCmd.push_back("-Xcc"); bridgingHeaderBuildCmd.push_back("-fmodule-file-cache-key"); bridgingHeaderBuildCmd.push_back("-Xcc"); - bridgingHeaderBuildCmd.push_back(clangDep->mappedPCMPath); + bridgingHeaderBuildCmd.push_back( + llvm::sys::path::filename(clangDep->mappedPCMPath).str()); bridgingHeaderBuildCmd.push_back("-Xcc"); bridgingHeaderBuildCmd.push_back(clangDep->moduleCacheKey); } @@ -276,17 +277,19 @@ class ExplicitModuleDependencyResolver { bool handleClangModuleDependency( ModuleDependencyID depModuleID, const ClangModuleDependencyStorage &clangDepDetails) { + auto pcmPath = + llvm::sys::path::filename(clangDepDetails.mappedPCMPath).str(); if (!resolvingDepInfo.isSwiftSourceModule()) { if (!resolvingDepInfo.isClangModule()) { commandline.push_back("-Xcc"); commandline.push_back("-fmodule-file=" + depModuleID.ModuleName + "=" + - clangDepDetails.mappedPCMPath); + pcmPath); } if (!clangDepDetails.moduleCacheKey.empty()) { commandline.push_back("-Xcc"); commandline.push_back("-fmodule-file-cache-key"); commandline.push_back("-Xcc"); - commandline.push_back(clangDepDetails.mappedPCMPath); + commandline.push_back(pcmPath); commandline.push_back("-Xcc"); commandline.push_back(clangDepDetails.moduleCacheKey); } diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 130b614943174..fb20fd9964873 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -788,17 +788,17 @@ static bool ParseCASArgs(CASOptions &Opts, ArgList &Args, Opts.EnableCachingRemarks |= Args.hasArg(OPT_cache_remarks); Opts.CacheSkipReplay |= Args.hasArg(OPT_cache_disable_replay); if (const Arg *A = Args.getLastArg(OPT_cas_path)) - Opts.CASOpts.CASPath = A->getValue(); - else if (Opts.CASOpts.CASPath.empty()) - Opts.CASOpts.CASPath = llvm::cas::getDefaultOnDiskCASPath(); + Opts.Config.CASPath = A->getValue(); + else if (Opts.Config.CASPath.empty()) + Opts.Config.CASPath = llvm::cas::getDefaultOnDiskCASPath(); if (const Arg *A = Args.getLastArg(OPT_cas_plugin_path)) - Opts.CASOpts.PluginPath = A->getValue(); + Opts.Config.PluginPath = A->getValue(); for (StringRef Opt : Args.getAllArgValues(OPT_cas_plugin_option)) { StringRef Name, Value; std::tie(Name, Value) = Opt.split('='); - Opts.CASOpts.PluginOptions.emplace_back(std::string(Name), + Opts.Config.PluginOptions.emplace_back(std::string(Name), std::string(Value)); } diff --git a/lib/Frontend/Frontend.cpp b/lib/Frontend/Frontend.cpp index 5cadb6afe4fe1..21dbf4542d1c2 100644 --- a/lib/Frontend/Frontend.cpp +++ b/lib/Frontend/Frontend.cpp @@ -465,7 +465,7 @@ bool CompilerInstance::setupCASIfNeeded(ArrayRef Args) { return false; const auto &Opts = getInvocation().getCASOptions(); - auto MaybeDB = Opts.CASOpts.getOrCreateDatabases(); + auto MaybeDB = Opts.Config.createDatabases(); if (!MaybeDB) { Diagnostics.diagnose(SourceLoc(), diag::error_cas_initialization, toString(MaybeDB.takeError())); diff --git a/lib/Frontend/ModuleInterfaceLoader.cpp b/lib/Frontend/ModuleInterfaceLoader.cpp index 98184ffc0d8d0..0cd2ada3659ac 100644 --- a/lib/Frontend/ModuleInterfaceLoader.cpp +++ b/lib/Frontend/ModuleInterfaceLoader.cpp @@ -1805,7 +1805,7 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface( if (casOpts.EnableCaching) { genericSubInvocation.getCASOptions().EnableCaching = casOpts.EnableCaching; - genericSubInvocation.getCASOptions().CASOpts = casOpts.CASOpts; + genericSubInvocation.getCASOptions().Config = casOpts.Config; genericSubInvocation.getCASOptions().HasImmutableFileSystem = casOpts.HasImmutableFileSystem; casOpts.enumerateCASConfigurationFlags( diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index 4fd5ad88998e0..c2a5bcae58126 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -1440,8 +1440,8 @@ static bool generateReproducer(CompilerInstance &Instance, llvm::sys::path::append(casPath, "cas"); clang::CASOptions newCAS; newCAS.CASPath = casPath.str(); - newCAS.PluginPath = casOpts.CASOpts.PluginPath; - newCAS.PluginOptions = casOpts.CASOpts.PluginOptions; + newCAS.PluginPath = casOpts.Config.PluginPath; + newCAS.PluginOptions = casOpts.Config.PluginOptions; auto db = newCAS.getOrCreateDatabases(); if (!db) { diags.diagnose(SourceLoc(), diag::error_cas_initialization, diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index 3390f11f4b2f6..b093e74cc1174 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -913,10 +913,10 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { // Note: The implementation here assumes that all clang submodules // belong to the same PCM file. ASTSourceDescriptor ParentDescriptor(*ClangModule->Parent); - Parent = getOrCreateModule({ParentDescriptor.getModuleName(), - ParentDescriptor.getPath(), - Desc.getASTFile(), Desc.getSignature()}, - ClangModule->Parent); + Parent = getOrCreateModule( + {ParentDescriptor.getModuleName(), ParentDescriptor.getPath(), + Desc.getASTFile(), Desc.getSignature(), /*CASID=*/""}, + ClangModule->Parent); } return getOrCreateModule(ClangModule, Parent, Desc.getModuleName(), IncludePath, Signature, Desc.getASTFile()); @@ -2565,11 +2565,11 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { // Describe the submodule, but substitute the cached ASTFile from // the toplevel module. The ASTFile pointer in SubModule may be // dangling and cant be trusted. - Scope = getOrCreateModule({SubModuleDesc->getModuleName(), - SubModuleDesc->getPath(), - TopLevelModuleDesc->getASTFile(), - TopLevelModuleDesc->getSignature()}, - SubModuleDesc->getModuleOrNull()); + Scope = getOrCreateModule( + {SubModuleDesc->getModuleName(), SubModuleDesc->getPath(), + TopLevelModuleDesc->getASTFile(), + TopLevelModuleDesc->getSignature(), /*CASID=*/""}, + SubModuleDesc->getModuleOrNull()); else if (SubModuleDesc->getModuleOrNull() == nullptr) // This is (bridging header) PCH. Scope = getOrCreateModule(*SubModuleDesc, nullptr); diff --git a/test/CAS/bridging-header.swift b/test/CAS/bridging-header.swift index b0bdb8db75a2c..45e26a04f8066 100644 --- a/test/CAS/bridging-header.swift +++ b/test/CAS/bridging-header.swift @@ -18,13 +18,13 @@ // CHECK: "-dwarf-ext-refs" // CHECK: "-fmodule-file-cache-key", // CHECK-NEXT: "-Xcc", -// CHECK-NEXT: "{{.*}}{{/|\\}}A-{{.*}}.pcm", +// CHECK-NEXT: "A-{{.*}}.pcm", // CHECK-NEXT: "-Xcc", // CHECK-NEXT: "llvmcas://{{.*}}", // CHECK-NEXT: "-Xcc", // CHECK-NEXT: "-fmodule-file-cache-key", // CHECK-NEXT: "-Xcc", -// CHECK-NEXT: "{{.*}}{{/|\\}}B-{{.*}}.pcm", +// CHECK-NEXT: "B-{{.*}}.pcm", // CHECK-NEXT: "-Xcc", // CHECK-NEXT: "llvmcas://{{.*}}" diff --git a/test/CAS/debug_info_pcm.swift b/test/CAS/debug_info_pcm.swift new file mode 100644 index 0000000000000..02ce3aa2cd76c --- /dev/null +++ b/test/CAS/debug_info_pcm.swift @@ -0,0 +1,41 @@ +// RUN: %empty-directory(%t) +// RUN: split-file %s %t + +// RUN: %target-swift-frontend -scan-dependencies -module-name Test -module-cache-path %t/clang-module-cache -O \ +// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \ +// RUN: %t/test.swift -o %t/deps.json -cache-compile-job -cas-path %t/cas -I %t/include + +// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:SwiftShims > %t/shim.cmd +// RUN: %swift_frontend_plain @%t/shim.cmd +// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:B > %t/B.cmd +// RUN: %swift_frontend_plain @%t/B.cmd +// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:A > %t/A.cmd +// RUN: %swift_frontend_plain @%t/A.cmd +// RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps.json clang:A modulePath > %t/A.path + +// RUN: dwarfdump --debug-info @%t/A.path | %FileCheck %s + +// CHECK: DW_AT_GNU_dwo_name ("llvmcas://{{.*}}") + +//--- test.swift +import A + +//--- include/a.h +#include "b.h" +struct A { + int a; +}; + +//--- include/b.h +void b(void); + +//--- include/module.modulemap +module A { + header "a.h" + export * +} + +module B { + header "b.h" + export * +} diff --git a/test/CAS/module_path_remap.swift b/test/CAS/module_path_remap.swift index 40648b749d3b4..ddf82f32d06b4 100644 --- a/test/CAS/module_path_remap.swift +++ b/test/CAS/module_path_remap.swift @@ -14,7 +14,7 @@ // DEPS-FS: /^src/test/CAS/module_path_remap.swift // RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps.json deps bridgingHeader | %FileCheck %s -check-prefix DEPS-BRIDGING -// DEPS-BRIDGING: -fmodule-file=F=/^tmp/clang-module-cache/F-{{.*}}.pcm +// DEPS-BRIDGING: -fmodule-file=F=F-{{.*}}.pcm // RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps.json F casFSRootID > %t/F.fs.casid // RUN: %cache-tool -cas-path %t/cas -cache-tool-action print-include-tree-list @%t/F.fs.casid | %FileCheck %s -check-prefix F-FS @@ -22,7 +22,7 @@ // RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps.json F commandLine | %FileCheck %s -check-prefix F-CMD // F-CMD: /^src/test/CAS/../ScanDependencies/Inputs/Swift/F.swiftinterface -// F-CMD: -fmodule-file=SwiftShims=/^tmp/clang-module-cache/SwiftShims-{{.*}}.pcm +// F-CMD: -fmodule-file=SwiftShims=SwiftShims-{{.*}}.pcm // RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps.json clang:F clangIncludeTree > %t/tree.casid // RUN: clang-cas-test --cas %t/cas --print-include-tree @%t/tree.casid | %FileCheck %s -check-prefix TREE