diff --git a/include/swift/AST/ASTContext.h b/include/swift/AST/ASTContext.h index 70c60b0122d12..80156adc89cf2 100644 --- a/include/swift/AST/ASTContext.h +++ b/include/swift/AST/ASTContext.h @@ -27,6 +27,7 @@ #include "swift/AST/Type.h" #include "swift/AST/TypeAlignments.h" #include "swift/AST/Types.h" +#include "swift/Basic/CASOptions.h" #include "swift/Basic/LangOptions.h" #include "swift/Basic/Located.h" #include "swift/Basic/Malloc.h" @@ -239,10 +240,9 @@ class ASTContext final { LangOptions &langOpts, TypeCheckerOptions &typecheckOpts, SILOptions &silOpts, SearchPathOptions &SearchPathOpts, ClangImporterOptions &ClangImporterOpts, - symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, + symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, CASOptions &casOpts, SourceManager &SourceMgr, DiagnosticEngine &Diags, - llvm::IntrusiveRefCntPtr OutBackend = nullptr - ); + llvm::IntrusiveRefCntPtr OutBackend = nullptr); public: // Members that should only be used by ASTContext.cpp. @@ -257,10 +257,9 @@ class ASTContext final { get(LangOptions &langOpts, TypeCheckerOptions &typecheckOpts, SILOptions &silOpts, SearchPathOptions &SearchPathOpts, ClangImporterOptions &ClangImporterOpts, - symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, + symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, CASOptions &casOpts, SourceManager &SourceMgr, DiagnosticEngine &Diags, - llvm::IntrusiveRefCntPtr OutBackend = nullptr - ); + llvm::IntrusiveRefCntPtr OutBackend = nullptr); ~ASTContext(); /// Optional table of counters to report, nullptr when not collecting. @@ -287,6 +286,9 @@ class ASTContext final { /// The symbol graph generation options used by this AST context. symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts; + /// The CAS options used by this AST context. + const CASOptions &CASOpts; + /// The source manager object. SourceManager &SourceMgr; diff --git a/include/swift/Basic/CASOptions.h b/include/swift/Basic/CASOptions.h new file mode 100644 index 0000000000000..f6a094eddd8ea --- /dev/null +++ b/include/swift/Basic/CASOptions.h @@ -0,0 +1,65 @@ +//===--- CASOptions.h - CAS & caching options -------------------*- C++ -*-===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// +// +// This file defines the CASOptions class, which provides various +// CAS and caching flags. +// +//===----------------------------------------------------------------------===// + +#ifndef SWIFT_BASIC_CASOPTIONS_H +#define SWIFT_BASIC_CASOPTIONS_H + +#include "clang/CAS/CASOptions.h" + +namespace swift { + +class CASOptions final { +public: + /// Enable compiler caching. + bool EnableCaching = false; + + /// Enable compiler caching remarks. + bool EnableCachingRemarks = false; + + /// Skip replaying outputs from cache. + bool CacheSkipReplay = false; + + /// CASOptions + clang::CASOptions CASOpts; + + /// CASFS Root. + std::vector CASFSRootIDs; + + /// Clang Include Trees. + std::vector ClangIncludeTrees; + + /// CacheKey for input file. + std::string InputFileKey; + + /// Cache key for imported bridging header. + std::string BridgingHeaderPCHCacheKey; + + /// Get the CAS configuration flags. + void enumerateCASConfigurationFlags( + llvm::function_ref Callback) const; + + /// Check to see if a CASFileSystem is required. + bool requireCASFS() const { + return EnableCaching && + (!CASFSRootIDs.empty() || !ClangIncludeTrees.empty() || + !InputFileKey.empty() || !BridgingHeaderPCHCacheKey.empty()); + } +}; + +} // namespace swift + +#endif // SWIFT_BASIC_CASOPTIONS_H diff --git a/include/swift/Basic/LangOptions.h b/include/swift/Basic/LangOptions.h index 2d2eb6ad36aaf..38cb02bc3712c 100644 --- a/include/swift/Basic/LangOptions.h +++ b/include/swift/Basic/LangOptions.h @@ -884,12 +884,6 @@ namespace swift { /// import, but it can affect Clang's IR generation of static functions. std::string Optimization; - /// clang CASOptions. - llvm::Optional CASOpts; - - /// Cache key for imported bridging header. - std::string BridgingHeaderPCHCacheKey; - /// Disable validating the persistent PCH. bool PCHDisableValidation = false; diff --git a/include/swift/Frontend/Frontend.h b/include/swift/Frontend/Frontend.h index 14fc54f66dd04..58f76a9a06b30 100644 --- a/include/swift/Frontend/Frontend.h +++ b/include/swift/Frontend/Frontend.h @@ -26,6 +26,7 @@ #include "swift/AST/SILOptions.h" #include "swift/AST/SearchPathOptions.h" #include "swift/AST/SourceFile.h" +#include "swift/Basic/CASOptions.h" #include "swift/Basic/DiagnosticOptions.h" #include "swift/Basic/LangOptions.h" #include "swift/Basic/SourceManager.h" @@ -102,6 +103,7 @@ class CompilerInvocation { IRGenOptions IRGenOpts; TBDGenOptions TBDGenOpts; ModuleInterfaceOptions ModuleInterfaceOpts; + CASOptions CASOpts; llvm::MemoryBuffer *IDEInspectionTargetBuffer = nullptr; /// The offset that IDEInspection wants to further examine in offset of bytes @@ -166,7 +168,7 @@ class CompilerInvocation { } bool requiresCAS() const { - return FrontendOpts.EnableCaching || FrontendOpts.UseCASBackend; + return CASOpts.EnableCaching || IRGenOpts.UseCASBackend; } void setClangModuleCachePath(StringRef Path) { @@ -274,6 +276,9 @@ class CompilerInvocation { FrontendOptions &getFrontendOptions() { return FrontendOpts; } const FrontendOptions &getFrontendOptions() const { return FrontendOpts; } + CASOptions &getCASOptions() { return CASOpts; } + const CASOptions &getCASOptions() const { return CASOpts; } + TBDGenOptions &getTBDGenOptions() { return TBDGenOpts; } const TBDGenOptions &getTBDGenOptions() const { return TBDGenOpts; } diff --git a/include/swift/Frontend/FrontendOptions.h b/include/swift/Frontend/FrontendOptions.h index 25eb37d970676..29500c7f56cd2 100644 --- a/include/swift/Frontend/FrontendOptions.h +++ b/include/swift/Frontend/FrontendOptions.h @@ -129,33 +129,6 @@ class FrontendOptions { /// The module for which we should verify all of the generic signatures. std::string VerifyGenericSignaturesInModule; - /// Enable compiler caching. - bool EnableCaching = false; - - /// Enable compiler caching remarks. - bool EnableCachingRemarks = false; - - /// Skip replaying outputs from cache. - bool CacheSkipReplay = false; - - /// CASOptions - clang::CASOptions CASOpts; - - /// CASFS Root. - std::vector CASFSRootIDs; - - /// Clang Include Trees. - std::vector ClangIncludeTrees; - - /// CacheKey for input file. - std::string InputFileKey; - - /// Enable using the LLVM MCCAS backend for object file output. - bool UseCASBackend = false; - - /// The output mode for the CAS Backend. - llvm::CASBackendMode CASObjMode; - /// Emit a .casid file next to the object file if CAS Backend is used. bool EmitCASIDFile = false; diff --git a/include/swift/Frontend/ModuleInterfaceLoader.h b/include/swift/Frontend/ModuleInterfaceLoader.h index e3bda47b0c833..4e6b96ad16287 100644 --- a/include/swift/Frontend/ModuleInterfaceLoader.h +++ b/include/swift/Frontend/ModuleInterfaceLoader.h @@ -596,12 +596,12 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase { static bool buildSwiftModuleFromSwiftInterface( SourceManager &SourceMgr, DiagnosticEngine &Diags, const SearchPathOptions &SearchPathOpts, const LangOptions &LangOpts, - const ClangImporterOptions &ClangOpts, StringRef CacheDir, - StringRef PrebuiltCacheDir, StringRef BackupInterfaceDir, - StringRef ModuleName, StringRef InPath, + const ClangImporterOptions &ClangOpts, const CASOptions &CASOpts, + StringRef CacheDir, StringRef PrebuiltCacheDir, + StringRef BackupInterfaceDir, StringRef ModuleName, StringRef InPath, StringRef OutPath, StringRef ABIOutputPath, - bool SerializeDependencyHashes, - bool TrackSystemDependencies, ModuleInterfaceLoaderOptions Opts, + bool SerializeDependencyHashes, bool TrackSystemDependencies, + ModuleInterfaceLoaderOptions Opts, RequireOSSAModules_t RequireOSSAModules, RequireNoncopyableGenerics_t RequireNCGenerics, bool silenceInterfaceDiagnostics); @@ -657,6 +657,7 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate { inheritOptionsForBuildingInterface(const SearchPathOptions &SearchPathOpts, const LangOptions &LangOpts, const ClangImporterOptions &clangImporterOpts, + const CASOptions &casOpts, bool suppressRemarks, RequireOSSAModules_t requireOSSAModules, RequireNoncopyableGenerics_t requireNCGenerics); @@ -668,12 +669,11 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate { InterfaceSubContextDelegateImpl( SourceManager &SM, DiagnosticEngine *Diags, const SearchPathOptions &searchPathOpts, const LangOptions &langOpts, - const ClangImporterOptions &clangImporterOpts, + const ClangImporterOptions &clangImporterOpts, const CASOptions &casOpts, ModuleInterfaceLoaderOptions LoaderOpts, bool buildModuleCacheDirIfAbsent, StringRef moduleCachePath, StringRef prebuiltCachePath, - StringRef backupModuleInterfaceDir, - bool serializeDependencyHashes, bool trackSystemDependencies, - RequireOSSAModules_t requireOSSAModules, + StringRef backupModuleInterfaceDir, bool serializeDependencyHashes, + bool trackSystemDependencies, RequireOSSAModules_t requireOSSAModules, RequireNoncopyableGenerics_t requireNCGenerics); template diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index f137245ae9c98..ce4297331bf30 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -677,7 +677,7 @@ ASTContext *ASTContext::get( LangOptions &langOpts, TypeCheckerOptions &typecheckOpts, SILOptions &silOpts, SearchPathOptions &SearchPathOpts, ClangImporterOptions &ClangImporterOpts, - symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, + symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, CASOptions &casOpts, SourceManager &SourceMgr, DiagnosticEngine &Diags, llvm::IntrusiveRefCntPtr OutputBackend) { // If more than two data structures are concatentated, then the aggregate @@ -692,7 +692,7 @@ ASTContext *ASTContext::get( new (impl) Implementation(); return new (mem) ASTContext(langOpts, typecheckOpts, silOpts, SearchPathOpts, - ClangImporterOpts, SymbolGraphOpts, SourceMgr, Diags, + ClangImporterOpts, SymbolGraphOpts, casOpts, SourceMgr, Diags, std::move(OutputBackend)); } @@ -700,15 +700,14 @@ ASTContext::ASTContext( LangOptions &langOpts, TypeCheckerOptions &typecheckOpts, SILOptions &silOpts, SearchPathOptions &SearchPathOpts, ClangImporterOptions &ClangImporterOpts, - symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, + symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, CASOptions &casOpts, SourceManager &SourceMgr, DiagnosticEngine &Diags, - llvm::IntrusiveRefCntPtr OutBackend - ) + llvm::IntrusiveRefCntPtr OutBackend) : LangOpts(langOpts), TypeCheckerOpts(typecheckOpts), SILOpts(silOpts), SearchPathOpts(SearchPathOpts), ClangImporterOpts(ClangImporterOpts), - SymbolGraphOpts(SymbolGraphOpts), SourceMgr(SourceMgr), Diags(Diags), - OutputBackend(std::move(OutBackend)), evaluator(Diags, langOpts), - TheBuiltinModule(createBuiltinModule(*this)), + SymbolGraphOpts(SymbolGraphOpts), CASOpts(casOpts), SourceMgr(SourceMgr), + Diags(Diags), OutputBackend(std::move(OutBackend)), + evaluator(Diags, langOpts), TheBuiltinModule(createBuiltinModule(*this)), StdlibModuleName(getIdentifier(STDLIB_NAME)), SwiftShimsModuleName(getIdentifier(SWIFT_SHIMS_NAME)), TheErrorType(new (*this, AllocationArena::Permanent) ErrorType( diff --git a/lib/AST/ModuleDependencies.cpp b/lib/AST/ModuleDependencies.cpp index 338ede4ec313d..6126a040fbd56 100644 --- a/lib/AST/ModuleDependencies.cpp +++ b/lib/AST/ModuleDependencies.cpp @@ -480,12 +480,12 @@ SwiftDependencyTracker::createTreeFromDependencies() { bool SwiftDependencyScanningService::setupCachingDependencyScanningService( CompilerInstance &Instance) { - if (!Instance.getInvocation().getFrontendOptions().EnableCaching) + if (!Instance.getInvocation().getCASOptions().EnableCaching) return false; if (CASOpts) { // If CASOption matches, the service is initialized already. - if (*CASOpts == Instance.getInvocation().getFrontendOptions().CASOpts) + if (*CASOpts == Instance.getInvocation().getCASOptions().CASOpts) return false; // CASOption mismatch, return error. @@ -496,7 +496,7 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService( } // Setup CAS. - CASOpts = Instance.getInvocation().getFrontendOptions().CASOpts; + CASOpts = Instance.getInvocation().getCASOptions().CASOpts; CAS = Instance.getSharedCASInstance(); // Add SDKSetting file. @@ -552,7 +552,7 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService( ClangScanningService.emplace( clang::tooling::dependencies::ScanningMode::DependencyDirectivesScan, ClangScanningFormat, - Instance.getInvocation().getFrontendOptions().CASOpts, + Instance.getInvocation().getCASOptions().CASOpts, Instance.getSharedCASInstance(), Instance.getSharedCacheInstance(), UseClangIncludeTree ? nullptr : CacheFS); diff --git a/lib/Basic/CASOptions.cpp b/lib/Basic/CASOptions.cpp new file mode 100644 index 0000000000000..f7e5119f9aa07 --- /dev/null +++ b/lib/Basic/CASOptions.cpp @@ -0,0 +1,39 @@ +//===--- CASOptions.cpp - CAS & caching options ---------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// +// +// This file defines the CASOptions class, which provides various +// CAS and caching flags. +// +//===----------------------------------------------------------------------===// + +#include "swift/Basic/CASOptions.h" + +using namespace swift; + +void CASOptions::enumerateCASConfigurationFlags( + llvm::function_ref Callback) const { + if (EnableCaching) { + Callback("-cache-compile-job"); + if (!CASOpts.CASPath.empty()) { + Callback("-cas-path"); + Callback(CASOpts.CASPath); + } + if (!CASOpts.PluginPath.empty()) { + Callback("-cas-plugin-path"); + Callback(CASOpts.PluginPath); + for (auto Opt : CASOpts.PluginOptions) { + Callback("-cas-plugin-option"); + Callback((llvm::Twine(Opt.first) + "=" + Opt.second).str()); + } + } + } +} diff --git a/lib/Basic/CMakeLists.txt b/lib/Basic/CMakeLists.txt index 067ea5717bb7a..9ba79b0b07f59 100644 --- a/lib/Basic/CMakeLists.txt +++ b/lib/Basic/CMakeLists.txt @@ -45,6 +45,7 @@ add_swift_host_library(swiftBasic STATIC BasicBridging.cpp BasicSourceInfo.cpp Cache.cpp + CASOptions.cpp ClusteredBitVector.cpp DiverseStack.cpp Edit.cpp diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 3c84bb95180f0..f431d3815638d 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -716,21 +716,22 @@ importer::getNormalInvocationArguments( llvm::sys::path::get_separator() + "apinotes").str()); - if (importerOpts.CASOpts) { + auto CASOpts = ctx.CASOpts; + if (CASOpts.EnableCaching) { invocationArgStrs.push_back("-Xclang"); invocationArgStrs.push_back("-fno-pch-timestamp"); - if (!importerOpts.CASOpts->CASPath.empty()) { + if (!CASOpts.CASOpts.CASPath.empty()) { invocationArgStrs.push_back("-Xclang"); invocationArgStrs.push_back("-fcas-path"); invocationArgStrs.push_back("-Xclang"); - invocationArgStrs.push_back(importerOpts.CASOpts->CASPath); + invocationArgStrs.push_back(CASOpts.CASOpts.CASPath); } - if (!importerOpts.CASOpts->PluginPath.empty()) { + if (!CASOpts.CASOpts.PluginPath.empty()) { invocationArgStrs.push_back("-Xclang"); invocationArgStrs.push_back("-fcas-plugin-path"); invocationArgStrs.push_back("-Xclang"); - invocationArgStrs.push_back(importerOpts.CASOpts->PluginPath); - for (auto Opt : importerOpts.CASOpts->PluginOptions) { + invocationArgStrs.push_back(CASOpts.CASOpts.PluginPath); + for (auto Opt : CASOpts.CASOpts.PluginOptions) { invocationArgStrs.push_back("-Xclang"); invocationArgStrs.push_back("-fcas-plugin-option"); invocationArgStrs.push_back("-Xclang"); diff --git a/lib/ClangImporter/ClangModuleDependencyScanner.cpp b/lib/ClangImporter/ClangModuleDependencyScanner.cpp index b4516bfd0032b..41adf1236b2e5 100644 --- a/lib/ClangImporter/ClangModuleDependencyScanner.cpp +++ b/lib/ClangImporter/ClangModuleDependencyScanner.cpp @@ -237,22 +237,8 @@ ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies( std::string IncludeTree = clangModuleDep.IncludeTreeID ? *clangModuleDep.IncludeTreeID : ""; - if (ctx.ClangImporterOpts.CASOpts) { - swiftArgs.push_back("-cache-compile-job"); - if (!ctx.ClangImporterOpts.CASOpts->CASPath.empty()) { - swiftArgs.push_back("-cas-path"); - swiftArgs.push_back(ctx.ClangImporterOpts.CASOpts->CASPath); - } - if (!ctx.ClangImporterOpts.CASOpts->PluginPath.empty()) { - swiftArgs.push_back("-cas-plugin-path"); - swiftArgs.push_back(ctx.ClangImporterOpts.CASOpts->PluginPath); - for (auto Opt : ctx.ClangImporterOpts.CASOpts->PluginOptions) { - swiftArgs.push_back("-cas-plugin-option"); - swiftArgs.push_back( - (llvm::Twine(Opt.first) + "=" + Opt.second).str()); - } - } - } + ctx.CASOpts.enumerateCASConfigurationFlags( + [&](StringRef Arg) { swiftArgs.push_back(Arg.str()); }); if (!RootID.empty()) { swiftArgs.push_back("-no-clang-include-tree"); @@ -343,21 +329,8 @@ void ClangImporter::recordBridgingHeaderOptions( llvm::for_each(clangArgs, addClangArg); - if (ctx.ClangImporterOpts.CASOpts) { - swiftArgs.push_back("-cache-compile-job"); - if (!ctx.ClangImporterOpts.CASOpts->CASPath.empty()) { - swiftArgs.push_back("-cas-path"); - swiftArgs.push_back(ctx.ClangImporterOpts.CASOpts->CASPath); - } - if (!ctx.ClangImporterOpts.CASOpts->PluginPath.empty()) { - swiftArgs.push_back("-cas-plugin-path"); - swiftArgs.push_back(ctx.ClangImporterOpts.CASOpts->PluginPath); - for (auto Opt : ctx.ClangImporterOpts.CASOpts->PluginOptions) { - swiftArgs.push_back("-cas-plugin-option"); - swiftArgs.push_back((llvm::Twine(Opt.first) + "=" + Opt.second).str()); - } - } - } + ctx.CASOpts.enumerateCASConfigurationFlags( + [&](StringRef Arg) { swiftArgs.push_back(Arg.str()); }); if (auto Tree = deps.IncludeTreeID) { swiftArgs.push_back("-clang-include-tree-root"); diff --git a/lib/DependencyScan/ModuleDependencyScanner.cpp b/lib/DependencyScan/ModuleDependencyScanner.cpp index bf6a9b573b890..39a8d16690144 100644 --- a/lib/DependencyScan/ModuleDependencyScanner.cpp +++ b/lib/DependencyScan/ModuleDependencyScanner.cpp @@ -157,7 +157,7 @@ ModuleDependencyScanningWorker::ModuleDependencyScanningWorker( ScanningASTDelegate = std::make_unique( ScanASTContext.SourceMgr, &ScanASTContext.Diags, ScanASTContext.SearchPathOpts, ScanASTContext.LangOpts, - ScanASTContext.ClangImporterOpts, LoaderOpts, + ScanASTContext.ClangImporterOpts, ScanASTContext.CASOpts, LoaderOpts, /*buildModuleCacheDirIfAbsent*/ false, ClangModuleCachePath, FEOpts.PrebuiltModuleCachePath, FEOpts.BackupModuleInterfaceDir, FEOpts.SerializeModuleInterfaceDependencyHashes, diff --git a/lib/DependencyScan/ScanDependencies.cpp b/lib/DependencyScan/ScanDependencies.cpp index c14a20b18568a..4e154bfad8b75 100644 --- a/lib/DependencyScan/ScanDependencies.cpp +++ b/lib/DependencyScan/ScanDependencies.cpp @@ -335,7 +335,7 @@ static llvm::Error resolveExplicitModuleInputs( } // Handle CAS options. - if (instance.getInvocation().getFrontendOptions().EnableCaching) { + if (instance.getInvocation().getCASOptions().EnableCaching) { // Merge CASFS from clang dependency. auto &CASFS = cache.getScanService().getSharedCachingFS(); auto &CAS = CASFS.getCAS(); diff --git a/lib/DriverTool/modulewrap_main.cpp b/lib/DriverTool/modulewrap_main.cpp index 676b78e720ae4..3bce40120d045 100644 --- a/lib/DriverTool/modulewrap_main.cpp +++ b/lib/DriverTool/modulewrap_main.cpp @@ -182,10 +182,11 @@ int modulewrap_main(ArrayRef Args, const char *Argv0, LangOptions LangOpts; ClangImporterOptions ClangImporterOpts; symbolgraphgen::SymbolGraphOptions SymbolGraphOpts; + CASOptions CASOpts; LangOpts.Target = Invocation.getTargetTriple(); ASTContext &ASTCtx = *ASTContext::get( LangOpts, TypeCheckOpts, SILOpts, SearchPathOpts, ClangImporterOpts, - SymbolGraphOpts, SrcMgr, Instance.getDiags(), + SymbolGraphOpts, CASOpts, SrcMgr, Instance.getDiags(), llvm::makeIntrusiveRefCnt()); registerParseRequestFunctions(ASTCtx.evaluator); registerTypeCheckerRequestFunctions(ASTCtx.evaluator); diff --git a/lib/DriverTool/swift_cache_tool_main.cpp b/lib/DriverTool/swift_cache_tool_main.cpp index 49ba407c4c6ee..54090e5dda662 100644 --- a/lib/DriverTool/swift_cache_tool_main.cpp +++ b/lib/DriverTool/swift_cache_tool_main.cpp @@ -220,7 +220,7 @@ class SwiftCacheToolInvocation { MainExecutablePath)) return true; - if (!Invocation.getFrontendOptions().EnableCaching) { + if (!Invocation.getCASOptions().EnableCaching) { llvm::errs() << "Requested command-line arguments do not enable CAS\n"; return true; } diff --git a/lib/DriverTool/swift_parse_test_main.cpp b/lib/DriverTool/swift_parse_test_main.cpp index 0bc892b31e04c..7526fca32f589 100644 --- a/lib/DriverTool/swift_parse_test_main.cpp +++ b/lib/DriverTool/swift_parse_test_main.cpp @@ -81,9 +81,10 @@ struct LibParseExecutor { SearchPathOptions searchPathOpts; ClangImporterOptions clangOpts; symbolgraphgen::SymbolGraphOptions symbolOpts; + CASOptions casOpts; std::unique_ptr ctx( ASTContext::get(langOpts, typeckOpts, silOpts, searchPathOpts, - clangOpts, symbolOpts, SM, diagEngine)); + clangOpts, symbolOpts, casOpts, SM, diagEngine)); SourceFile::ParsingOptions parseOpts; parseOpts |= SourceFile::ParsingFlags::DisablePoundIfEvaluation; @@ -150,6 +151,7 @@ struct ASTGenExecutor { SILOptions silOpts; SearchPathOptions searchPathOpts; ClangImporterOptions clangOpts; + CASOptions casOpts; symbolgraphgen::SymbolGraphOptions symbolOpts; // Enable ASTGen. @@ -157,7 +159,7 @@ struct ASTGenExecutor { std::unique_ptr ctx( ASTContext::get(langOpts, typeckOpts, silOpts, searchPathOpts, - clangOpts, symbolOpts, SM, diagEngine)); + clangOpts, symbolOpts, casOpts, SM, diagEngine)); registerParseRequestFunctions(ctx->evaluator); registerTypeCheckerRequestFunctions(ctx->evaluator); diff --git a/lib/Frontend/ArgsToFrontendOptionsConverter.cpp b/lib/Frontend/ArgsToFrontendOptionsConverter.cpp index 9a8a60ca3cc83..62b8aeb2ac4d4 100644 --- a/lib/Frontend/ArgsToFrontendOptionsConverter.cpp +++ b/lib/Frontend/ArgsToFrontendOptionsConverter.cpp @@ -253,32 +253,9 @@ bool ArgsToFrontendOptionsConverter::convert( if (checkBuildFromInterfaceOnlyOptions()) return true; - Opts.DeterministicCheck = Args.hasArg(OPT_enable_deterministic_check); - Opts.EnableCaching = Args.hasArg(OPT_cache_compile_job); - Opts.EnableCachingRemarks = Args.hasArg(OPT_cache_remarks); - Opts.CacheSkipReplay = Args.hasArg(OPT_cache_disable_replay); - Opts.CASOpts.CASPath = - Args.getLastArgValue(OPT_cas_path, llvm::cas::getDefaultOnDiskCASPath()); - Opts.CASOpts.PluginPath = Args.getLastArgValue(OPT_cas_plugin_path); - 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), - std::string(Value)); - } - - Opts.CASFSRootIDs = Args.getAllArgValues(OPT_cas_fs); - Opts.ClangIncludeTrees = Args.getAllArgValues(OPT_clang_include_tree_root); - Opts.InputFileKey = Args.getLastArgValue(OPT_input_file_key); + Opts.DeterministicCheck |= Args.hasArg(OPT_enable_deterministic_check); Opts.CacheReplayPrefixMap = Args.getAllArgValues(OPT_cache_replay_prefix_map); - if (Opts.EnableCaching && Opts.CASFSRootIDs.empty() && - Opts.ClangIncludeTrees.empty() && - FrontendOptions::supportCompilationCaching(Opts.RequestedAction)) { - Diags.diagnose(SourceLoc(), diag::error_caching_no_cas_fs); - return true; - } - if (FrontendOptions::doesActionGenerateIR(Opts.RequestedAction)) { if (Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) || Args.hasArg(OPT_experimental_skip_all_function_bodies) || @@ -402,17 +379,6 @@ bool ArgsToFrontendOptionsConverter::convert( Opts.BlocklistConfigFilePaths.push_back(A); } - if (Arg *A = Args.getLastArg(OPT_cas_backend_mode)) { - Opts.CASObjMode = llvm::StringSwitch(A->getValue()) - .Case("native", llvm::CASBackendMode::Native) - .Case("casid", llvm::CASBackendMode::CASID) - .Case("verify", llvm::CASBackendMode::Verify) - .Default(llvm::CASBackendMode::Native); - } - - Opts.UseCASBackend = Args.hasArg(OPT_cas_backend); - Opts.EmitCASIDFile = Args.hasArg(OPT_cas_emit_casid_file); - Opts.DisableSandbox = Args.hasArg(OPT_disable_sandbox); return false; diff --git a/lib/Frontend/CachedDiagnostics.cpp b/lib/Frontend/CachedDiagnostics.cpp index 5787cba7f6ddc..cdde300affbd8 100644 --- a/lib/Frontend/CachedDiagnostics.cpp +++ b/lib/Frontend/CachedDiagnostics.cpp @@ -752,7 +752,7 @@ CachingDiagnosticsProcessor::CachingDiagnosticsProcessor( : Impl(*new Implementation(Instance)) { Impl.serializedOutputCallback = [&](StringRef Output) { LLVM_DEBUG(llvm::dbgs() << Output << "\n";); - if (!Instance.getInvocation().getFrontendOptions().EnableCaching) + if (!Instance.getInvocation().getCASOptions().EnableCaching) return false; // compress the YAML file. diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 731de8b44ee51..19eae4a510c66 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -270,10 +270,6 @@ setIRGenOutputOptsFromFrontendOptions(IRGenOptions &IRGenOpts, } }(FrontendOpts.RequestedAction); - IRGenOpts.UseCASBackend = FrontendOpts.UseCASBackend; - IRGenOpts.CASObjMode = FrontendOpts.CASObjMode; - IRGenOpts.EmitCASIDFile = FrontendOpts.EmitCASIDFile; - // If we're in JIT mode, set the requisite flags. if (FrontendOpts.RequestedAction == FrontendOptions::ActionType::Immediate) { IRGenOpts.UseJIT = true; @@ -531,6 +527,50 @@ parseStrictConcurrency(StringRef value) { .Default(llvm::None); } +static bool ParseCASArgs(CASOptions &Opts, ArgList &Args, + DiagnosticEngine &Diags, + const FrontendOptions &FrontendOpts) { + using namespace options; + Opts.EnableCaching |= Args.hasArg(OPT_cache_compile_job); + 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(); + + if (const Arg *A = Args.getLastArg(OPT_cas_plugin_path)) + Opts.CASOpts.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), + std::string(Value)); + } + + for (const auto &A : Args.getAllArgValues(OPT_cas_fs)) + Opts.CASFSRootIDs.emplace_back(A); + for (const auto &A : Args.getAllArgValues(OPT_clang_include_tree_root)) + Opts.ClangIncludeTrees.emplace_back(A); + + if (const Arg *A = Args.getLastArg(OPT_input_file_key)) + Opts.InputFileKey = A->getValue(); + + if (const Arg*A = Args.getLastArg(OPT_bridging_header_pch_key)) + Opts.BridgingHeaderPCHCacheKey = A->getValue(); + + if (Opts.EnableCaching && Opts.CASFSRootIDs.empty() && + Opts.ClangIncludeTrees.empty() && + FrontendOptions::supportCompilationCaching( + FrontendOpts.RequestedAction)) { + Diags.diagnose(SourceLoc(), diag::error_caching_no_cas_fs); + return true; + } + + return false; +} + static bool ParseLangArgs(LangOptions &Opts, ArgList &Args, DiagnosticEngine &Diags, const FrontendOptions &FrontendOpts) { @@ -1565,7 +1605,8 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts, ArgList &Args, DiagnosticEngine &Diags, StringRef workingDirectory, const LangOptions &LangOpts, - const FrontendOptions &FrontendOpts) { + const FrontendOptions &FrontendOpts, + const CASOptions &CASOpts) { using namespace options; if (const Arg *a = Args.getLastArg(OPT_tools_directory)) { @@ -1633,8 +1674,8 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts, ArgList &Args, Opts.ExtraArgs.push_back("-ffile-compilation-dir=" + Val); } - if (FrontendOpts.CASFSRootIDs.empty() && - FrontendOpts.ClangIncludeTrees.empty()) { + if (CASOpts.CASFSRootIDs.empty() && + CASOpts.ClangIncludeTrees.empty()) { if (!workingDirectory.empty()) { // Provide a working directory to Clang as well if there are any -Xcc // options, in case some of them are search-related. But do it at the @@ -1661,8 +1702,6 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts, ArgList &Args, if (auto *A = Args.getLastArg(OPT_import_objc_header)) Opts.BridgingHeader = A->getValue(); - Opts.BridgingHeaderPCHCacheKey = - Args.getLastArgValue(OPT_bridging_header_pch_key); Opts.DisableSwiftBridgeAttr |= Args.hasArg(OPT_disable_swift_bridge_attr); Opts.DisableOverlayModules |= Args.hasArg(OPT_emit_imported_modules); @@ -1698,12 +1737,11 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts, ArgList &Args, // Forward the FrontendOptions to clang importer option so it can be // accessed when creating clang module compilation invocation. - if (FrontendOpts.EnableCaching) { - Opts.CASOpts = FrontendOpts.CASOpts; + if (CASOpts.EnableCaching) { // Only set UseClangIncludeTree when caching is enabled since it is not // useful in non-caching context. - Opts.UseClangIncludeTree = !Args.hasArg(OPT_no_clang_include_tree); - Opts.HasClangIncludeTreeRoot = Args.hasArg(OPT_clang_include_tree_root); + Opts.UseClangIncludeTree |= !Args.hasArg(OPT_no_clang_include_tree); + Opts.HasClangIncludeTreeRoot |= Args.hasArg(OPT_clang_include_tree_root); } return false; @@ -3026,6 +3064,17 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args, .Default(llvm::CallingConv::C); } + if (Arg *A = Args.getLastArg(OPT_cas_backend_mode)) { + Opts.CASObjMode = llvm::StringSwitch(A->getValue()) + .Case("native", llvm::CASBackendMode::Native) + .Case("casid", llvm::CASBackendMode::CASID) + .Case("verify", llvm::CASBackendMode::Verify) + .Default(llvm::CASBackendMode::Native); + } + + Opts.UseCASBackend |= Args.hasArg(OPT_cas_backend); + Opts.EmitCASIDFile |= Args.hasArg(OPT_cas_emit_casid_file); + return false; } @@ -3160,6 +3209,10 @@ bool CompilerInvocation::parseArgs( ParseModuleInterfaceArgs(ModuleInterfaceOpts, ParsedArgs); SaveModuleInterfaceArgs(ModuleInterfaceOpts, FrontendOpts, ParsedArgs, Diags); + if (ParseCASArgs(CASOpts, ParsedArgs, Diags, FrontendOpts)) { + return true; + } + if (ParseLangArgs(LangOpts, ParsedArgs, Diags, FrontendOpts)) { return true; } @@ -3169,7 +3222,8 @@ bool CompilerInvocation::parseArgs( } if (ParseClangImporterArgs(ClangImporterOpts, ParsedArgs, Diags, - workingDirectory, LangOpts, FrontendOpts)) { + workingDirectory, LangOpts, FrontendOpts, + CASOpts)) { return true; } diff --git a/lib/Frontend/Frontend.cpp b/lib/Frontend/Frontend.cpp index 55cfebeb86241..170e4ece325a0 100644 --- a/lib/Frontend/Frontend.cpp +++ b/lib/Frontend/Frontend.cpp @@ -290,7 +290,7 @@ bool CompilerInstance::setUpASTContextIfNeeded() { Invocation.getLangOptions(), Invocation.getTypeCheckerOptions(), Invocation.getSILOptions(), Invocation.getSearchPathOptions(), Invocation.getClangImporterOptions(), Invocation.getSymbolGraphOptions(), - SourceMgr, Diagnostics, OutputBackend)); + Invocation.getCASOptions(), SourceMgr, Diagnostics, OutputBackend)); if (!Invocation.getFrontendOptions().ModuleAliasMap.empty()) Context->setModuleAliases(Invocation.getFrontendOptions().ModuleAliasMap); @@ -434,10 +434,10 @@ void CompilerInstance::setupDependencyTrackerIfNeeded() { } bool CompilerInstance::setupCASIfNeeded(ArrayRef Args) { - const auto &Opts = getInvocation().getFrontendOptions(); if (!getInvocation().requiresCAS()) return false; + const auto &Opts = getInvocation().getCASOptions(); auto MaybeDB= Opts.CASOpts.getOrCreateDatabases(); if (!MaybeDB) { Diagnostics.diagnose(SourceLoc(), diag::error_cas, @@ -559,10 +559,9 @@ bool CompilerInstance::setup(const CompilerInvocation &Invoke, } bool CompilerInstance::setUpVirtualFileSystemOverlays() { - if (Invocation.getFrontendOptions().EnableCaching) { - const auto &Opts = getInvocation().getFrontendOptions(); - if (!Invocation.getFrontendOptions().CASFSRootIDs.empty() || - !Invocation.getFrontendOptions().ClangIncludeTrees.empty()) { + if (Invocation.getCASOptions().requireCASFS()) { + const auto &Opts = getInvocation().getCASOptions(); + if (!Opts.CASFSRootIDs.empty() || !Opts.ClangIncludeTrees.empty()) { // Set up CASFS as BaseFS. auto FS = createCASFileSystem(*CAS, Opts.CASFSRootIDs, Opts.ClangIncludeTrees); @@ -579,10 +578,10 @@ bool CompilerInstance::setUpVirtualFileSystemOverlays() { new llvm::vfs::InMemoryFileSystem(); const auto &ClangOpts = getInvocation().getClangImporterOptions(); - if (!ClangOpts.BridgingHeaderPCHCacheKey.empty()) { + if (!Opts.BridgingHeaderPCHCacheKey.empty()) { if (auto loadedBuffer = loadCachedCompileResultFromCacheKey( getObjectStore(), getActionCache(), Diagnostics, - ClangOpts.BridgingHeaderPCHCacheKey, file_types::ID::TY_PCH, + Opts.BridgingHeaderPCHCacheKey, file_types::ID::TY_PCH, ClangOpts.BridgingHeader)) MemFS->addFile(Invocation.getClangImporterOptions().BridgingHeader, 0, std::move(loadedBuffer)); @@ -592,11 +591,14 @@ bool CompilerInstance::setUpVirtualFileSystemOverlays() { Invocation.getClangImporterOptions().BridgingHeader); } if (!Opts.InputFileKey.empty()) { - if (Opts.InputsAndOutputs.getAllInputs().size() != 1) + if (Invocation.getFrontendOptions() + .InputsAndOutputs.getAllInputs() + .size() != 1) Diagnostics.diagnose(SourceLoc(), diag::error_wrong_input_num_for_input_file_key); else { - auto InputPath = Opts.InputsAndOutputs.getFilenameOfFirstInput(); + auto InputPath = Invocation.getFrontendOptions() + .InputsAndOutputs.getFilenameOfFirstInput(); auto Type = file_types::lookupTypeFromFilename( llvm::sys::path::filename(InputPath)); if (auto loadedBuffer = loadCachedCompileResultFromCacheKey( @@ -741,7 +743,7 @@ bool CompilerInstance::setUpModuleLoaders() { if (ExplicitModuleBuild || !Invocation.getSearchPathOptions().ExplicitSwiftModuleMap.empty() || !Invocation.getSearchPathOptions().ExplicitSwiftModuleInputs.empty()) { - if (Invocation.getFrontendOptions().EnableCaching) + if (Invocation.getCASOptions().EnableCaching) ESML = ExplicitCASModuleLoader::create( *Context, getObjectStore(), getActionCache(), getDependencyTracker(), MLM, Invocation.getSearchPathOptions().ExplicitSwiftModuleMap, @@ -812,7 +814,8 @@ bool CompilerInstance::setUpModuleLoaders() { ModuleInterfaceLoaderOptions LoaderOpts(FEOpts); InterfaceSubContextDelegateImpl ASTDelegate( Context->SourceMgr, &Context->Diags, Context->SearchPathOpts, - Context->LangOpts, Context->ClangImporterOpts, LoaderOpts, + Context->LangOpts, Context->ClangImporterOpts, Context->CASOpts, + LoaderOpts, /*buildModuleCacheDirIfAbsent*/ false, ClangModuleCachePath, FEOpts.PrebuiltModuleCachePath, FEOpts.BackupModuleInterfaceDir, FEOpts.SerializeModuleInterfaceDependencyHashes, @@ -1172,7 +1175,7 @@ bool CompilerInstance::canImportCxxShim() const { } bool CompilerInstance::supportCaching() const { - if (!Invocation.getFrontendOptions().EnableCaching) + if (!Invocation.getCASOptions().EnableCaching) return false; return FrontendOptions::supportCompilationCaching( diff --git a/lib/Frontend/ModuleInterfaceLoader.cpp b/lib/Frontend/ModuleInterfaceLoader.cpp index 277e66475ba0c..652873ce306bc 100644 --- a/lib/Frontend/ModuleInterfaceLoader.cpp +++ b/lib/Frontend/ModuleInterfaceLoader.cpp @@ -1053,7 +1053,7 @@ class ModuleInterfaceLoaderImpl { } InterfaceSubContextDelegateImpl astDelegate( ctx.SourceMgr, &ctx.Diags, ctx.SearchPathOpts, ctx.LangOpts, - ctx.ClangImporterOpts, Opts, + ctx.ClangImporterOpts, ctx.CASOpts, Opts, /*buildModuleCacheDirIfAbsent*/ true, cacheDir, prebuiltCacheDir, backupInterfaceDir, /*serializeDependencyHashes*/ false, trackSystemDependencies, @@ -1374,17 +1374,16 @@ bool ModuleInterfaceCheckerImpl::tryEmitForwardingModule( bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface( SourceManager &SourceMgr, DiagnosticEngine &Diags, const SearchPathOptions &SearchPathOpts, const LangOptions &LangOpts, - const ClangImporterOptions &ClangOpts, StringRef CacheDir, - StringRef PrebuiltCacheDir, StringRef BackupInterfaceDir, - StringRef ModuleName, StringRef InPath, - StringRef OutPath, StringRef ABIOutputPath, - bool SerializeDependencyHashes, + const ClangImporterOptions &ClangOpts, const CASOptions &CASOpts, + StringRef CacheDir, StringRef PrebuiltCacheDir, + StringRef BackupInterfaceDir, StringRef ModuleName, StringRef InPath, + StringRef OutPath, StringRef ABIOutputPath, bool SerializeDependencyHashes, bool TrackSystemDependencies, ModuleInterfaceLoaderOptions LoaderOpts, RequireOSSAModules_t RequireOSSAModules, RequireNoncopyableGenerics_t RequireNCGenerics, bool silenceInterfaceDiagnostics) { InterfaceSubContextDelegateImpl astDelegate( - SourceMgr, &Diags, SearchPathOpts, LangOpts, ClangOpts, LoaderOpts, + SourceMgr, &Diags, SearchPathOpts, LangOpts, ClangOpts, CASOpts, LoaderOpts, /*CreateCacheDirIfAbsent*/ true, CacheDir, PrebuiltCacheDir, BackupInterfaceDir, SerializeDependencyHashes, TrackSystemDependencies, @@ -1558,7 +1557,7 @@ void ModuleInterfaceLoader::collectVisibleTopLevelModuleNames( void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface( const SearchPathOptions &SearchPathOpts, const LangOptions &LangOpts, - const ClangImporterOptions &clangImporterOpts, + const ClangImporterOptions &clangImporterOpts, const CASOptions &casOpts, bool suppressRemarks, RequireOSSAModules_t RequireOSSAModules, RequireNoncopyableGenerics_t requireNCGenerics) { GenericArgs.push_back("-frontend"); @@ -1674,23 +1673,11 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface( GenericArgs.push_back(clangImporterOpts.BuildSessionFilePath); } - if (clangImporterOpts.CASOpts) { - genericSubInvocation.getClangImporterOptions().CASOpts = - clangImporterOpts.CASOpts; - GenericArgs.push_back("-cache-compile-job"); - if (!clangImporterOpts.CASOpts->CASPath.empty()) { - GenericArgs.push_back("-cas-path"); - GenericArgs.push_back(clangImporterOpts.CASOpts->CASPath); - } - if (!clangImporterOpts.CASOpts->PluginPath.empty()) { - GenericArgs.push_back("-cas-plugin-path"); - GenericArgs.push_back(clangImporterOpts.CASOpts->PluginPath); - for (auto Opt : clangImporterOpts.CASOpts->PluginOptions) { - GenericArgs.push_back("-cas-plugin-option"); - std::string pair = (llvm::Twine(Opt.first) + "=" + Opt.second).str(); - GenericArgs.push_back(ArgSaver.save(pair)); - } - } + if (casOpts.EnableCaching) { + genericSubInvocation.getCASOptions().EnableCaching = casOpts.EnableCaching; + genericSubInvocation.getCASOptions().CASOpts = casOpts.CASOpts; + casOpts.enumerateCASConfigurationFlags( + [&](StringRef Arg) { GenericArgs.push_back(ArgSaver.save(Arg)); }); } if (!clangImporterOpts.UseClangIncludeTree) { @@ -1726,7 +1713,7 @@ bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs( InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl( SourceManager &SM, DiagnosticEngine *Diags, const SearchPathOptions &searchPathOpts, const LangOptions &langOpts, - const ClangImporterOptions &clangImporterOpts, + const ClangImporterOptions &clangImporterOpts, const CASOptions &casOpts, ModuleInterfaceLoaderOptions LoaderOpts, bool buildModuleCacheDirIfAbsent, StringRef moduleCachePath, StringRef prebuiltCachePath, StringRef backupModuleInterfaceDir, @@ -1736,7 +1723,7 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl( : SM(SM), Diags(Diags), ArgSaver(Allocator) { genericSubInvocation.setMainExecutablePath(LoaderOpts.mainExecutablePath); inheritOptionsForBuildingInterface(searchPathOpts, langOpts, - clangImporterOpts, + clangImporterOpts, casOpts, Diags->getSuppressRemarks(), requireOSSAModules, requireNCGenerics); @@ -1793,7 +1780,6 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl( // required by sourcekitd. subClangImporterOpts.DetailedPreprocessingRecord = clangImporterOpts.DetailedPreprocessingRecord; - subClangImporterOpts.CASOpts = clangImporterOpts.CASOpts; std::vector inheritedParentContextClangArgs; if (LoaderOpts.requestedAction == diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index 0d5f93f986f0f..8e48881d43861 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -418,19 +418,18 @@ static bool buildModuleFromInterface(CompilerInstance &Instance) { // currently we need to ensure it still reads the flags written out // in the .swiftinterface file itself. Instead, creation of that // job should incorporate those flags. - if (FEOpts.ExplicitInterfaceBuild && - !(FEOpts.isTypeCheckAction() && !FEOpts.EnableCaching)) + if (FEOpts.ExplicitInterfaceBuild && !(FEOpts.isTypeCheckAction())) return ModuleInterfaceLoader::buildExplicitSwiftModuleFromSwiftInterface( Instance, Invocation.getClangModuleCachePath(), FEOpts.BackupModuleInterfaceDir, PrebuiltCachePath, ABIPath, InputPath, Invocation.getOutputFilename(), /* shouldSerializeDeps */ true, Invocation.getSearchPathOptions().CandidateCompiledModules); - else - return ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface( + + return ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface( Instance.getSourceMgr(), Instance.getDiags(), Invocation.getSearchPathOptions(), Invocation.getLangOptions(), - Invocation.getClangImporterOptions(), + Invocation.getClangImporterOptions(), Invocation.getCASOptions(), Invocation.getClangModuleCachePath(), PrebuiltCachePath, FEOpts.BackupModuleInterfaceDir, Invocation.getModuleName(), InputPath, Invocation.getOutputFilename(), ABIPath, @@ -1455,7 +1454,7 @@ static bool performAction(CompilerInstance &Instance, /// false and will not replay any output. static bool tryReplayCompilerResults(CompilerInstance &Instance) { if (!Instance.supportCaching() || - Instance.getInvocation().getFrontendOptions().CacheSkipReplay) + Instance.getInvocation().getCASOptions().CacheSkipReplay) return false; assert(Instance.getCompilerBaseKey() && @@ -1471,7 +1470,7 @@ static bool tryReplayCompilerResults(CompilerInstance &Instance) { Instance.getObjectStore(), Instance.getActionCache(), *Instance.getCompilerBaseKey(), Instance.getDiags(), Instance.getInvocation().getFrontendOptions().InputsAndOutputs, *CDP, - Instance.getInvocation().getFrontendOptions().EnableCachingRemarks); + Instance.getInvocation().getCASOptions().EnableCachingRemarks); // If we didn't replay successfully, re-start capture. if (!replayed) diff --git a/lib/IDETool/CompileInstance.cpp b/lib/IDETool/CompileInstance.cpp index 9ef977faa3168..9eefaae862d2f 100644 --- a/lib/IDETool/CompileInstance.cpp +++ b/lib/IDETool/CompileInstance.cpp @@ -125,11 +125,13 @@ getModifiedFunctionDeclList(const SourceFile &SF, SourceManager &tmpSM, SearchPathOptions searchPathOpts = ctx.SearchPathOpts; ClangImporterOptions clangOpts = ctx.ClangImporterOpts; SILOptions silOpts = ctx.SILOpts; + CASOptions casOpts = ctx.CASOpts; symbolgraphgen::SymbolGraphOptions symbolOpts = ctx.SymbolGraphOpts; DiagnosticEngine tmpDiags(tmpSM); - auto &tmpCtx = *ASTContext::get(langOpts, typeckOpts, silOpts, searchPathOpts, - clangOpts, symbolOpts, tmpSM, tmpDiags); + auto &tmpCtx = + *ASTContext::get(langOpts, typeckOpts, silOpts, searchPathOpts, clangOpts, + symbolOpts, casOpts, tmpSM, tmpDiags); registerParseRequestFunctions(tmpCtx.evaluator); registerTypeCheckerRequestFunctions(tmpCtx.evaluator); diff --git a/lib/IDETool/IDEInspectionInstance.cpp b/lib/IDETool/IDEInspectionInstance.cpp index 1785fc6b43d90..e49127a301c67 100644 --- a/lib/IDETool/IDEInspectionInstance.cpp +++ b/lib/IDETool/IDEInspectionInstance.cpp @@ -240,9 +240,10 @@ bool IDEInspectionInstance::performCachedOperationIfPossible( DiagnosticEngine tmpDiags(tmpSM); ClangImporterOptions clangOpts; symbolgraphgen::SymbolGraphOptions symbolOpts; + CASOptions casOpts; std::unique_ptr tmpCtx( ASTContext::get(langOpts, typeckOpts, silOpts, searchPathOpts, clangOpts, - symbolOpts, tmpSM, tmpDiags)); + symbolOpts, casOpts, tmpSM, tmpDiags)); tmpCtx->CancellationFlag = CancellationFlag; registerParseRequestFunctions(tmpCtx->evaluator); registerIDERequestFunctions(tmpCtx->evaluator); diff --git a/lib/IDETool/SyntacticMacroExpansion.cpp b/lib/IDETool/SyntacticMacroExpansion.cpp index 317064365dead..8372db317338e 100644 --- a/lib/IDETool/SyntacticMacroExpansion.cpp +++ b/lib/IDETool/SyntacticMacroExpansion.cpp @@ -62,7 +62,7 @@ bool SyntacticMacroExpansionInstance::setup( invocation.getLangOptions(), invocation.getTypeCheckerOptions(), invocation.getSILOptions(), invocation.getSearchPathOptions(), invocation.getClangImporterOptions(), invocation.getSymbolGraphOptions(), - SourceMgr, Diags)); + invocation.getCASOptions(), SourceMgr, Diags)); registerParseRequestFunctions(Ctx->evaluator); registerTypeCheckerRequestFunctions(Ctx->evaluator); diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 52288e0ea3f4a..ee4ec48d97032 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -1130,6 +1130,7 @@ struct ParserUnit::Implementation { SearchPathOptions SearchPathOpts; ClangImporterOptions clangImporterOpts; symbolgraphgen::SymbolGraphOptions symbolGraphOpts; + CASOptions CASOpts; DiagnosticEngine Diags; ASTContext &Ctx; SourceFile *SF; @@ -1138,10 +1139,10 @@ struct ParserUnit::Implementation { Implementation(SourceManager &SM, SourceFileKind SFKind, unsigned BufferID, const LangOptions &Opts, const TypeCheckerOptions &TyOpts, const SILOptions &silOpts, StringRef ModuleName) - : LangOpts(Opts), - TypeCheckerOpts(TyOpts), SILOpts(silOpts), Diags(SM), + : LangOpts(Opts), TypeCheckerOpts(TyOpts), SILOpts(silOpts), Diags(SM), Ctx(*ASTContext::get(LangOpts, TypeCheckerOpts, SILOpts, SearchPathOpts, - clangImporterOpts, symbolGraphOpts, SM, Diags)) { + clangImporterOpts, symbolGraphOpts, CASOpts, SM, + Diags)) { registerParseRequestFunctions(Ctx.evaluator); auto parsingOpts = SourceFile::getDefaultParsingOptions(LangOpts); diff --git a/lib/Serialization/SerializedModuleLoader.cpp b/lib/Serialization/SerializedModuleLoader.cpp index c23d8de88a223..f7089856023ec 100644 --- a/lib/Serialization/SerializedModuleLoader.cpp +++ b/lib/Serialization/SerializedModuleLoader.cpp @@ -486,7 +486,7 @@ SerializedModuleLoaderBase::scanModuleFile(Twine modulePath, bool isFramework) { // of binary module dependencies. In the meantime, in non-CAS mode // loading clients will consume the `.h` files encoded in the `.swiftmodules` // directly. - if (Ctx.ClangImporterOpts.CASOpts) { + if (Ctx.CASOpts.EnableCaching) { importedHeaders.reserve(importedHeaderSet.size()); llvm::transform(importedHeaderSet.keys(), std::back_inserter(importedHeaders), diff --git a/test/CAS/cas-explicit-module-map.swift b/test/CAS/cas-explicit-module-map.swift index 9c2d6535e1763..296ece70d5339 100644 --- a/test/CAS/cas-explicit-module-map.swift +++ b/test/CAS/cas-explicit-module-map.swift @@ -36,13 +36,13 @@ // RUN: -cache-compile-job -cas-path %t/cas -swift-version 5 -enable-library-evolution \ // RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \ // RUN: -explicit-interface-module-build -Rcache-compile-job @%t/MyApp.cmd -input-file-key @%t/key 2>&1 \ -// RUN: | %FileCheck %s --check-prefix=VERIFY-OUTPUT --check-prefix=CACHE-MISS +// RUN: | %FileCheck %s --check-prefix=CACHE-MISS // RUN: %target-swift-frontend -typecheck-module-from-interface %t/Foo.swiftinterface -disable-implicit-swift-modules \ // RUN: -module-cache-path %t.module-cache -explicit-swift-module-map-file @%t/map.casid \ // RUN: -cache-compile-job -cas-path %t/cas -swift-version 5 -enable-library-evolution \ // RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \ // RUN: -explicit-interface-module-build -Rcache-compile-job @%t/MyApp.cmd -input-file-key @%t/key 2>&1 \ -// RUN: | %FileCheck %s --check-prefix=VERIFY-OUTPUT --check-prefix=CACHE-HIT +// RUN: | %FileCheck %s --check-prefix=CACHE-HIT // CACHE-MISS: remark: cache miss for input // VERIFY-OUTPUT: warning: module 'B' was not compiled with library evolution support diff --git a/tools/libSwiftScan/SwiftCaching.cpp b/tools/libSwiftScan/SwiftCaching.cpp index 21d93206d90d8..430927c8bc9c8 100644 --- a/tools/libSwiftScan/SwiftCaching.cpp +++ b/tools/libSwiftScan/SwiftCaching.cpp @@ -835,7 +835,7 @@ swiftscan_cache_replay_instance_create(int argc, const char **argv, return nullptr; } - if (!Instance->Invocation.getFrontendOptions().EnableCaching) { + if (!Instance->Invocation.getCASOptions().EnableCaching) { delete Instance; *error = swift::c_string_utils::create_clone( "caching is not enabled from command-line"); @@ -955,7 +955,7 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance, Outputs.try_emplace(file_types::TY_CachedDiagnostics, ""); // Load all the output buffer. - bool Remarks = Instance.Invocation.getFrontendOptions().EnableCachingRemarks; + bool Remarks = Instance.Invocation.getCASOptions().EnableCachingRemarks; struct OutputEntry { std::string Path; llvm::cas::ObjectProxy Proxy; diff --git a/unittests/AST/TestContext.cpp b/unittests/AST/TestContext.cpp index 0439efa2e2f18..c971b625f5ddd 100644 --- a/unittests/AST/TestContext.cpp +++ b/unittests/AST/TestContext.cpp @@ -35,8 +35,8 @@ static Decl *createOptionalType(ASTContext &ctx, SourceFile *fileForLookups, TestContext::TestContext(ShouldDeclareOptionalTypes optionals) : Ctx(*ASTContext::get(LangOpts, TypeCheckerOpts, SILOpts, SearchPathOpts, - ClangImporterOpts, SymbolGraphOpts, SourceMgr, - Diags)) { + ClangImporterOpts, SymbolGraphOpts, CASOpts, + SourceMgr, Diags)) { registerParseRequestFunctions(Ctx.evaluator); registerTypeCheckerRequestFunctions(Ctx.evaluator); registerClangImporterRequestFunctions(Ctx.evaluator); diff --git a/unittests/AST/TestContext.h b/unittests/AST/TestContext.h index 02d1101f5d5d0..3025a38fdd714 100644 --- a/unittests/AST/TestContext.h +++ b/unittests/AST/TestContext.h @@ -35,6 +35,7 @@ class TestContextBase { SearchPathOptions SearchPathOpts; ClangImporterOptions ClangImporterOpts; symbolgraphgen::SymbolGraphOptions SymbolGraphOpts; + CASOptions CASOpts; SourceManager SourceMgr; DiagnosticEngine Diags; diff --git a/unittests/ClangImporter/ClangImporterTests.cpp b/unittests/ClangImporter/ClangImporterTests.cpp index 53627d8dd7a2a..e761efa22dd8e 100644 --- a/unittests/ClangImporter/ClangImporterTests.cpp +++ b/unittests/ClangImporter/ClangImporterTests.cpp @@ -1,6 +1,7 @@ #include "swift/AST/ASTContext.h" #include "swift/AST/DiagnosticEngine.h" #include "swift/AST/SearchPathOptions.h" +#include "swift/Basic/CASOptions.h" #include "swift/Basic/Defer.h" #include "swift/Basic/LLVMInitialize.h" #include "swift/Basic/LangOptions.h" @@ -78,11 +79,12 @@ TEST(ClangImporterTest, emitPCHInMemory) { INITIALIZE_LLVM(); swift::SearchPathOptions searchPathOpts; swift::symbolgraphgen::SymbolGraphOptions symbolGraphOpts; + swift::CASOptions casOpts; swift::SourceManager sourceMgr; swift::DiagnosticEngine diags(sourceMgr); std::unique_ptr context( ASTContext::get(langOpts, typecheckOpts, silOpts, searchPathOpts, options, - symbolGraphOpts, sourceMgr, diags)); + symbolGraphOpts, casOpts, sourceMgr, diags)); auto importer = ClangImporter::create(*context); std::string PCH = createFilename(cache, "bridging.h.pch"); @@ -192,6 +194,7 @@ TEST(ClangImporterTest, libStdCxxInjectionTest) { swift::SourceManager sourceMgr; swift::DiagnosticEngine diags(sourceMgr); ClangImporterOptions options; + CASOptions casOpts; options.clangPath = "/usr/bin/clang"; options.ExtraArgs.push_back( (llvm::Twine("--gcc-toolchain=") + "/opt/rh/devtoolset-9/root/usr") @@ -199,7 +202,7 @@ TEST(ClangImporterTest, libStdCxxInjectionTest) { options.ExtraArgs.push_back("--gcc-toolchain"); std::unique_ptr context( ASTContext::get(langOpts, typecheckOpts, silOpts, searchPathOpts, options, - symbolGraphOpts, sourceMgr, diags)); + symbolGraphOpts, casOpts, sourceMgr, diags)); { LibStdCxxInjectionVFS vfs; diff --git a/unittests/FrontendTool/ModuleLoadingTests.cpp b/unittests/FrontendTool/ModuleLoadingTests.cpp index 3b2fb59cc59fc..fca45e0298f22 100644 --- a/unittests/FrontendTool/ModuleLoadingTests.cpp +++ b/unittests/FrontendTool/ModuleLoadingTests.cpp @@ -103,8 +103,10 @@ class ModuleInterfaceLoaderTest : public testing::Test { ClangImporterOptions clangImpOpts; symbolgraphgen::SymbolGraphOptions symbolGraphOpts; SILOptions silOpts; + CASOptions casOpts; auto ctx = ASTContext::get(langOpts, typecheckOpts, silOpts, searchPathOpts, - clangImpOpts, symbolGraphOpts, sourceMgr, diags); + clangImpOpts, symbolGraphOpts, casOpts, + sourceMgr, diags); ctx->addModuleInterfaceChecker( std::make_unique(*ctx, cacheDir, diff --git a/unittests/Sema/SemaFixture.cpp b/unittests/Sema/SemaFixture.cpp index fc555f1364269..252e1178a401c 100644 --- a/unittests/Sema/SemaFixture.cpp +++ b/unittests/Sema/SemaFixture.cpp @@ -31,7 +31,7 @@ using namespace swift::constraints::inference; SemaTest::SemaTest() : Context(*ASTContext::get(LangOpts, TypeCheckerOpts, SILOpts, SearchPathOpts, ClangImporterOpts, - SymbolGraphOpts, SourceMgr, Diags)) { + SymbolGraphOpts, CASOpts, SourceMgr, Diags)) { INITIALIZE_LLVM(); registerParseRequestFunctions(Context.evaluator); diff --git a/unittests/Sema/SemaFixture.h b/unittests/Sema/SemaFixture.h index a1add414dd38b..6658ad01b2d8a 100644 --- a/unittests/Sema/SemaFixture.h +++ b/unittests/Sema/SemaFixture.h @@ -42,6 +42,7 @@ class SemaTestBase : public ::testing::Test { SearchPathOptions SearchPathOpts; ClangImporterOptions ClangImporterOpts; symbolgraphgen::SymbolGraphOptions SymbolGraphOpts; + CASOptions CASOpts; SourceManager SourceMgr; DiagnosticEngine Diags;