Skip to content

[Caching] Use subInvocation to verify interface #71497

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 2 commits into from
Feb 13, 2024
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
14 changes: 8 additions & 6 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<llvm::vfs::OutputBackend> OutBackend = nullptr
);
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend = nullptr);

public:
// Members that should only be used by ASTContext.cpp.
Expand All @@ -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<llvm::vfs::OutputBackend> OutBackend = nullptr
);
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend = nullptr);
~ASTContext();

/// Optional table of counters to report, nullptr when not collecting.
Expand All @@ -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;

Expand Down
65 changes: 65 additions & 0 deletions include/swift/Basic/CASOptions.h
Original file line number Diff line number Diff line change
@@ -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<std::string> CASFSRootIDs;

/// Clang Include Trees.
std::vector<std::string> 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<void(llvm::StringRef)> 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
6 changes: 0 additions & 6 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<clang::CASOptions> CASOpts;

/// Cache key for imported bridging header.
std::string BridgingHeaderPCHCacheKey;

/// Disable validating the persistent PCH.
bool PCHDisableValidation = false;

Expand Down
7 changes: 6 additions & 1 deletion include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -166,7 +168,7 @@ class CompilerInvocation {
}

bool requiresCAS() const {
return FrontendOpts.EnableCaching || FrontendOpts.UseCASBackend;
return CASOpts.EnableCaching || IRGenOpts.UseCASBackend;
}

void setClangModuleCachePath(StringRef Path) {
Expand Down Expand Up @@ -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; }

Expand Down
27 changes: 0 additions & 27 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> CASFSRootIDs;

/// Clang Include Trees.
std::vector<std::string> 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;

Expand Down
18 changes: 9 additions & 9 deletions include/swift/Frontend/ModuleInterfaceLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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<typename ...ArgTypes>
Expand Down
15 changes: 7 additions & 8 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<llvm::vfs::OutputBackend> OutputBackend) {
// If more than two data structures are concatentated, then the aggregate
Expand All @@ -692,23 +692,22 @@ 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));
}

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<llvm::vfs::OutputBackend> OutBackend
)
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> 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(
Expand Down
8 changes: 4 additions & 4 deletions lib/AST/ModuleDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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);

Expand Down
39 changes: 39 additions & 0 deletions lib/Basic/CASOptions.cpp
Original file line number Diff line number Diff line change
@@ -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<void(llvm::StringRef)> 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());
}
}
}
}
1 change: 1 addition & 0 deletions lib/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ add_swift_host_library(swiftBasic STATIC
BasicBridging.cpp
BasicSourceInfo.cpp
Cache.cpp
CASOptions.cpp
ClusteredBitVector.cpp
DiverseStack.cpp
Edit.cpp
Expand Down
13 changes: 7 additions & 6 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading