[NFC] Add SerializationOptions to ASTContext

This commit is contained in:
Meghana Gupta
2024-10-31 13:35:18 -07:00
parent 51090e4bc4
commit 1985b6cceb
18 changed files with 73 additions and 44 deletions

View File

@@ -27,11 +27,12 @@
#include "swift/AST/Type.h"
#include "swift/AST/TypeAlignments.h"
#include "swift/AST/Types.h"
#include "swift/Basic/BlockList.h"
#include "swift/Basic/CASOptions.h"
#include "swift/Basic/LangOptions.h"
#include "swift/Basic/Located.h"
#include "swift/Basic/Malloc.h"
#include "swift/Basic/BlockList.h"
#include "swift/Serialization/SerializationOptions.h"
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/Basic/DarwinSDKInfo.h"
@@ -266,7 +267,8 @@ class ASTContext final {
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
ClangImporterOptions &ClangImporterOpts,
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, CASOptions &casOpts,
SourceManager &SourceMgr, DiagnosticEngine &Diags,
SerializationOptions &serializationOpts, SourceManager &SourceMgr,
DiagnosticEngine &Diags,
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend = nullptr);
public:
@@ -283,7 +285,8 @@ public:
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
ClangImporterOptions &ClangImporterOpts,
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, CASOptions &casOpts,
SourceManager &SourceMgr, DiagnosticEngine &Diags,
SerializationOptions &serializationOpts, SourceManager &SourceMgr,
DiagnosticEngine &Diags,
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend = nullptr);
~ASTContext();
@@ -314,6 +317,9 @@ public:
/// The CAS options used by this AST context.
const CASOptions &CASOpts;
/// Options for Serialization
const SerializationOptions &SerializationOpts;
/// The source manager object.
SourceManager &SourceMgr;

View File

@@ -104,6 +104,7 @@ class CompilerInvocation {
TBDGenOptions TBDGenOpts;
ModuleInterfaceOptions ModuleInterfaceOpts;
CASOptions CASOpts;
SerializationOptions SerializationOpts;
llvm::MemoryBuffer *IDEInspectionTargetBuffer = nullptr;
/// The offset that IDEInspection wants to further examine in offset of bytes
@@ -327,6 +328,11 @@ public:
IRGenOptions &getIRGenOptions() { return IRGenOpts; }
const IRGenOptions &getIRGenOptions() const { return IRGenOpts; }
SerializationOptions &getSerializationOptions() { return SerializationOpts; }
const SerializationOptions &getSerializationOptions() const {
return SerializationOpts;
}
void setParseStdlib() {
FrontendOpts.ParseStdlib = true;
}

View File

@@ -25,13 +25,12 @@
namespace swift {
class SerializationOptions {
SerializationOptions(const SerializationOptions &) = delete;
void operator=(const SerializationOptions &) = delete;
public:
SerializationOptions() = default;
SerializationOptions(SerializationOptions &&) = default;
SerializationOptions &operator=(SerializationOptions &&) = default;
SerializationOptions(const SerializationOptions &) = default;
SerializationOptions &operator=(const SerializationOptions &) = default;
~SerializationOptions() = default;
StringRef OutputPath;

View File

@@ -757,7 +757,8 @@ ASTContext *ASTContext::get(
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
ClangImporterOptions &ClangImporterOpts,
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, CASOptions &casOpts,
SourceManager &SourceMgr, DiagnosticEngine &Diags,
SerializationOptions &serializationOpts, SourceManager &SourceMgr,
DiagnosticEngine &Diags,
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutputBackend) {
// If more than two data structures are concatentated, then the aggregate
// size math needs to become more complicated due to per-struct alignment
@@ -771,8 +772,8 @@ ASTContext *ASTContext::get(
new (impl) Implementation();
return new (mem)
ASTContext(langOpts, typecheckOpts, silOpts, SearchPathOpts,
ClangImporterOpts, SymbolGraphOpts, casOpts, SourceMgr, Diags,
std::move(OutputBackend));
ClangImporterOpts, SymbolGraphOpts, casOpts, serializationOpts,
SourceMgr, Diags, std::move(OutputBackend));
}
ASTContext::ASTContext(
@@ -780,17 +781,19 @@ ASTContext::ASTContext(
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
ClangImporterOptions &ClangImporterOpts,
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, CASOptions &casOpts,
SourceManager &SourceMgr, DiagnosticEngine &Diags,
SerializationOptions &SerializationOpts, SourceManager &SourceMgr,
DiagnosticEngine &Diags,
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend)
: LangOpts(langOpts), TypeCheckerOpts(typecheckOpts), SILOpts(silOpts),
SearchPathOpts(SearchPathOpts), ClangImporterOpts(ClangImporterOpts),
SymbolGraphOpts(SymbolGraphOpts), CASOpts(casOpts), SourceMgr(SourceMgr),
Diags(Diags), OutputBackend(std::move(OutBackend)),
evaluator(Diags, langOpts), TheBuiltinModule(createBuiltinModule(*this)),
SymbolGraphOpts(SymbolGraphOpts), CASOpts(casOpts),
SerializationOpts(SerializationOpts), SourceMgr(SourceMgr), Diags(Diags),
OutputBackend(std::move(OutBackend)), evaluator(Diags, langOpts),
TheBuiltinModule(createBuiltinModule(*this)),
StdlibModuleName(getIdentifier(STDLIB_NAME)),
SwiftShimsModuleName(getIdentifier(SWIFT_SHIMS_NAME)),
blockListConfig(SourceMgr),
TheErrorType(new (*this, AllocationArena::Permanent) ErrorType(
TheErrorType(new(*this, AllocationArena::Permanent) ErrorType(
*this, Type(), RecursiveTypeProperties::HasError)),
TheUnresolvedType(new(*this, AllocationArena::Permanent)
UnresolvedType(*this)),
@@ -801,17 +804,17 @@ ASTContext::ASTContext(
The##SHORT_ID##Type(new (*this, AllocationArena::Permanent) \
ID##Type(*this)),
#include "swift/AST/TypeNodes.def"
TheIEEE32Type(new (*this, AllocationArena::Permanent)
TheIEEE32Type(new(*this, AllocationArena::Permanent)
BuiltinFloatType(BuiltinFloatType::IEEE32, *this)),
TheIEEE64Type(new (*this, AllocationArena::Permanent)
TheIEEE64Type(new(*this, AllocationArena::Permanent)
BuiltinFloatType(BuiltinFloatType::IEEE64, *this)),
TheIEEE16Type(new (*this, AllocationArena::Permanent)
TheIEEE16Type(new(*this, AllocationArena::Permanent)
BuiltinFloatType(BuiltinFloatType::IEEE16, *this)),
TheIEEE80Type(new (*this, AllocationArena::Permanent)
TheIEEE80Type(new(*this, AllocationArena::Permanent)
BuiltinFloatType(BuiltinFloatType::IEEE80, *this)),
TheIEEE128Type(new (*this, AllocationArena::Permanent)
TheIEEE128Type(new(*this, AllocationArena::Permanent)
BuiltinFloatType(BuiltinFloatType::IEEE128, *this)),
ThePPC128Type(new (*this, AllocationArena::Permanent)
ThePPC128Type(new(*this, AllocationArena::Permanent)
BuiltinFloatType(BuiltinFloatType::PPC128, *this)) {
// Initialize all of the known identifiers.

View File

@@ -180,6 +180,7 @@ ModuleDependencyScanningWorker::ModuleDependencyScanningWorker(
workerCompilerInvocation->getClangImporterOptions(),
workerCompilerInvocation->getSymbolGraphOptions(),
workerCompilerInvocation->getCASOptions(),
workerCompilerInvocation->getSerializationOptions(),
ScanASTContext.SourceMgr, Diagnostics));
auto loader = std::make_unique<PluginLoader>(
*workerASTContext, /*DepTracker=*/nullptr,

View File

@@ -188,11 +188,12 @@ int modulewrap_main(ArrayRef<const char *> Args, const char *Argv0,
ClangImporterOptions ClangImporterOpts;
symbolgraphgen::SymbolGraphOptions SymbolGraphOpts;
CASOptions CASOpts;
SerializationOptions SerializationOpts;
LangOpts.Target = Invocation.getTargetTriple();
LangOpts.EnableObjCInterop = Invocation.enableObjCInterop();
ASTContext &ASTCtx = *ASTContext::get(
LangOpts, TypeCheckOpts, SILOpts, SearchPathOpts, ClangImporterOpts,
SymbolGraphOpts, CASOpts, SrcMgr, Instance.getDiags(),
SymbolGraphOpts, CASOpts, SerializationOpts, SrcMgr, Instance.getDiags(),
llvm::makeIntrusiveRefCnt<llvm::vfs::OnDiskOutputBackend>());
registerParseRequestFunctions(ASTCtx.evaluator);
registerTypeCheckerRequestFunctions(ASTCtx.evaluator);

View File

@@ -82,9 +82,10 @@ struct LibParseExecutor {
ClangImporterOptions clangOpts;
symbolgraphgen::SymbolGraphOptions symbolOpts;
CASOptions casOpts;
std::unique_ptr<ASTContext> ctx(
ASTContext::get(langOpts, typeckOpts, silOpts, searchPathOpts,
clangOpts, symbolOpts, casOpts, SM, diagEngine));
SerializationOptions serializationOpts;
std::unique_ptr<ASTContext> ctx(ASTContext::get(
langOpts, typeckOpts, silOpts, searchPathOpts, clangOpts, symbolOpts,
casOpts, serializationOpts, SM, diagEngine));
SourceFile::ParsingOptions parseOpts;
parseOpts |= SourceFile::ParsingFlags::DisablePoundIfEvaluation;
@@ -153,13 +154,14 @@ struct ASTGenExecutor {
ClangImporterOptions clangOpts;
CASOptions casOpts;
symbolgraphgen::SymbolGraphOptions symbolOpts;
SerializationOptions serializationOpts;
// Enable ASTGen.
langOpts.enableFeature(Feature::ParserASTGen);
std::unique_ptr<ASTContext> ctx(
ASTContext::get(langOpts, typeckOpts, silOpts, searchPathOpts,
clangOpts, symbolOpts, casOpts, SM, diagEngine));
std::unique_ptr<ASTContext> ctx(ASTContext::get(
langOpts, typeckOpts, silOpts, searchPathOpts, clangOpts, symbolOpts,
casOpts, serializationOpts, SM, diagEngine));
registerParseRequestFunctions(ctx->evaluator);
registerTypeCheckerRequestFunctions(ctx->evaluator);

View File

@@ -302,7 +302,8 @@ bool CompilerInstance::setUpASTContextIfNeeded() {
Invocation.getLangOptions(), Invocation.getTypeCheckerOptions(),
Invocation.getSILOptions(), Invocation.getSearchPathOptions(),
Invocation.getClangImporterOptions(), Invocation.getSymbolGraphOptions(),
Invocation.getCASOptions(), SourceMgr, Diagnostics, OutputBackend));
Invocation.getCASOptions(), Invocation.getSerializationOptions(),
SourceMgr, Diagnostics, OutputBackend));
if (!Invocation.getFrontendOptions().ModuleAliasMap.empty())
Context->setModuleAliases(Invocation.getFrontendOptions().ModuleAliasMap);

View File

@@ -128,11 +128,12 @@ getModifiedFunctionDeclList(const SourceFile &SF, SourceManager &tmpSM,
SILOptions silOpts = ctx.SILOpts;
CASOptions casOpts = ctx.CASOpts;
symbolgraphgen::SymbolGraphOptions symbolOpts = ctx.SymbolGraphOpts;
SerializationOptions serializationOpts = ctx.SerializationOpts;
DiagnosticEngine tmpDiags(tmpSM);
auto &tmpCtx =
*ASTContext::get(langOpts, typeckOpts, silOpts, searchPathOpts, clangOpts,
symbolOpts, casOpts, tmpSM, tmpDiags);
symbolOpts, casOpts, serializationOpts, tmpSM, tmpDiags);
registerParseRequestFunctions(tmpCtx.evaluator);
registerTypeCheckerRequestFunctions(tmpCtx.evaluator);

View File

@@ -241,9 +241,11 @@ bool IDEInspectionInstance::performCachedOperationIfPossible(
ClangImporterOptions clangOpts;
symbolgraphgen::SymbolGraphOptions symbolOpts;
CASOptions casOpts;
SerializationOptions serializationOpts =
CachedCI->getASTContext().SerializationOpts;
std::unique_ptr<ASTContext> tmpCtx(
ASTContext::get(langOpts, typeckOpts, silOpts, searchPathOpts, clangOpts,
symbolOpts, casOpts, tmpSM, tmpDiags));
symbolOpts, casOpts, serializationOpts, tmpSM, tmpDiags));
tmpCtx->CancellationFlag = CancellationFlag;
registerParseRequestFunctions(tmpCtx->evaluator);
registerIDERequestFunctions(tmpCtx->evaluator);

View File

@@ -63,7 +63,8 @@ bool SyntacticMacroExpansionInstance::setup(
invocation.getLangOptions(), invocation.getTypeCheckerOptions(),
invocation.getSILOptions(), invocation.getSearchPathOptions(),
invocation.getClangImporterOptions(), invocation.getSymbolGraphOptions(),
invocation.getCASOptions(), SourceMgr, Diags));
invocation.getCASOptions(), invocation.getSerializationOptions(),
SourceMgr, Diags));
registerParseRequestFunctions(Ctx->evaluator);
registerTypeCheckerRequestFunctions(Ctx->evaluator);

View File

@@ -1126,6 +1126,7 @@ struct ParserUnit::Implementation {
ClangImporterOptions clangImporterOpts;
symbolgraphgen::SymbolGraphOptions symbolGraphOpts;
CASOptions CASOpts;
SerializationOptions SerializationOpts;
DiagnosticEngine Diags;
ASTContext &Ctx;
SourceFile *SF;
@@ -1136,8 +1137,8 @@ struct ParserUnit::Implementation {
const SILOptions &silOpts, StringRef ModuleName)
: LangOpts(Opts), TypeCheckerOpts(TyOpts), SILOpts(silOpts), Diags(SM),
Ctx(*ASTContext::get(LangOpts, TypeCheckerOpts, SILOpts, SearchPathOpts,
clangImporterOpts, symbolGraphOpts, CASOpts, SM,
Diags)) {
clangImporterOpts, symbolGraphOpts, CASOpts,
SerializationOpts, SM, Diags)) {
registerParseRequestFunctions(Ctx.evaluator);
auto parsingOpts = SourceFile::getDefaultParsingOptions(LangOpts);

View File

@@ -36,7 +36,7 @@ static Decl *createOptionalType(ASTContext &ctx, SourceFile *fileForLookups,
TestContext::TestContext(ShouldDeclareOptionalTypes optionals)
: Ctx(*ASTContext::get(LangOpts, TypeCheckerOpts, SILOpts, SearchPathOpts,
ClangImporterOpts, SymbolGraphOpts, CASOpts,
SourceMgr, Diags)) {
SerializationOpts, SourceMgr, Diags)) {
registerParseRequestFunctions(Ctx.evaluator);
registerTypeCheckerRequestFunctions(Ctx.evaluator);
registerClangImporterRequestFunctions(Ctx.evaluator);

View File

@@ -36,6 +36,7 @@ public:
ClangImporterOptions ClangImporterOpts;
symbolgraphgen::SymbolGraphOptions SymbolGraphOpts;
CASOptions CASOpts;
SerializationOptions SerializationOpts;
SourceManager SourceMgr;
DiagnosticEngine Diags;

View File

@@ -80,11 +80,12 @@ TEST(ClangImporterTest, emitPCHInMemory) {
swift::SearchPathOptions searchPathOpts;
swift::symbolgraphgen::SymbolGraphOptions symbolGraphOpts;
swift::CASOptions casOpts;
swift::SerializationOptions serializationOpts;
swift::SourceManager sourceMgr;
swift::DiagnosticEngine diags(sourceMgr);
std::unique_ptr<ASTContext> context(
ASTContext::get(langOpts, typecheckOpts, silOpts, searchPathOpts, options,
symbolGraphOpts, casOpts, sourceMgr, diags));
std::unique_ptr<ASTContext> context(ASTContext::get(
langOpts, typecheckOpts, silOpts, searchPathOpts, options,
symbolGraphOpts, casOpts, serializationOpts, sourceMgr, diags));
auto importer = ClangImporter::create(*context);
std::string PCH = createFilename(cache, "bridging.h.pch");
@@ -197,14 +198,15 @@ TEST(ClangImporterTest, libStdCxxInjectionTest) {
swift::DiagnosticEngine diags(sourceMgr);
ClangImporterOptions options;
CASOptions casOpts;
SerializationOptions serializationOpts;
options.clangPath = "/usr/bin/clang";
options.ExtraArgs.push_back(
(llvm::Twine("--gcc-toolchain=") + "/opt/rh/devtoolset-9/root/usr")
.str());
options.ExtraArgs.push_back("--gcc-toolchain");
std::unique_ptr<ASTContext> context(
ASTContext::get(langOpts, typecheckOpts, silOpts, searchPathOpts, options,
symbolGraphOpts, casOpts, sourceMgr, diags));
std::unique_ptr<ASTContext> context(ASTContext::get(
langOpts, typecheckOpts, silOpts, searchPathOpts, options,
symbolGraphOpts, casOpts, serializationOpts, sourceMgr, diags));
{
LibStdCxxInjectionVFS vfs;

View File

@@ -104,9 +104,10 @@ protected:
symbolgraphgen::SymbolGraphOptions symbolGraphOpts;
SILOptions silOpts;
CASOptions casOpts;
SerializationOptions serializationOpts;
auto ctx = ASTContext::get(langOpts, typecheckOpts, silOpts, searchPathOpts,
clangImpOpts, symbolGraphOpts, casOpts,
sourceMgr, diags);
serializationOpts, sourceMgr, diags);
ctx->addModuleInterfaceChecker(
std::make_unique<ModuleInterfaceCheckerImpl>(*ctx, cacheDir,

View File

@@ -29,9 +29,9 @@ using namespace swift::unittest;
using namespace swift::constraints::inference;
SemaTest::SemaTest()
: Context(*ASTContext::get(LangOpts, TypeCheckerOpts, SILOpts,
SearchPathOpts, ClangImporterOpts,
SymbolGraphOpts, CASOpts, SourceMgr, Diags)) {
: Context(*ASTContext::get(
LangOpts, TypeCheckerOpts, SILOpts, SearchPathOpts, ClangImporterOpts,
SymbolGraphOpts, CASOpts, SerializationOpts, SourceMgr, Diags)) {
INITIALIZE_LLVM();
registerParseRequestFunctions(Context.evaluator);

View File

@@ -43,6 +43,7 @@ public:
ClangImporterOptions ClangImporterOpts;
symbolgraphgen::SymbolGraphOptions SymbolGraphOpts;
CASOptions CASOpts;
SerializationOptions SerializationOpts;
SourceManager SourceMgr;
DiagnosticEngine Diags;