Skip to content

Commit 1985b6c

Browse files
committed
[NFC] Add SerializationOptions to ASTContext
1 parent 51090e4 commit 1985b6c

18 files changed

+73
-44
lines changed

include/swift/AST/ASTContext.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
#include "swift/AST/Type.h"
2828
#include "swift/AST/TypeAlignments.h"
2929
#include "swift/AST/Types.h"
30+
#include "swift/Basic/BlockList.h"
3031
#include "swift/Basic/CASOptions.h"
3132
#include "swift/Basic/LangOptions.h"
3233
#include "swift/Basic/Located.h"
3334
#include "swift/Basic/Malloc.h"
34-
#include "swift/Basic/BlockList.h"
35+
#include "swift/Serialization/SerializationOptions.h"
3536
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
3637
#include "clang/AST/DeclTemplate.h"
3738
#include "clang/Basic/DarwinSDKInfo.h"
@@ -266,7 +267,8 @@ class ASTContext final {
266267
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
267268
ClangImporterOptions &ClangImporterOpts,
268269
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, CASOptions &casOpts,
269-
SourceManager &SourceMgr, DiagnosticEngine &Diags,
270+
SerializationOptions &serializationOpts, SourceManager &SourceMgr,
271+
DiagnosticEngine &Diags,
270272
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend = nullptr);
271273

272274
public:
@@ -283,7 +285,8 @@ class ASTContext final {
283285
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
284286
ClangImporterOptions &ClangImporterOpts,
285287
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, CASOptions &casOpts,
286-
SourceManager &SourceMgr, DiagnosticEngine &Diags,
288+
SerializationOptions &serializationOpts, SourceManager &SourceMgr,
289+
DiagnosticEngine &Diags,
287290
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend = nullptr);
288291
~ASTContext();
289292

@@ -314,6 +317,9 @@ class ASTContext final {
314317
/// The CAS options used by this AST context.
315318
const CASOptions &CASOpts;
316319

320+
/// Options for Serialization
321+
const SerializationOptions &SerializationOpts;
322+
317323
/// The source manager object.
318324
SourceManager &SourceMgr;
319325

include/swift/Frontend/Frontend.h

+6
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class CompilerInvocation {
104104
TBDGenOptions TBDGenOpts;
105105
ModuleInterfaceOptions ModuleInterfaceOpts;
106106
CASOptions CASOpts;
107+
SerializationOptions SerializationOpts;
107108
llvm::MemoryBuffer *IDEInspectionTargetBuffer = nullptr;
108109

109110
/// The offset that IDEInspection wants to further examine in offset of bytes
@@ -327,6 +328,11 @@ class CompilerInvocation {
327328
IRGenOptions &getIRGenOptions() { return IRGenOpts; }
328329
const IRGenOptions &getIRGenOptions() const { return IRGenOpts; }
329330

331+
SerializationOptions &getSerializationOptions() { return SerializationOpts; }
332+
const SerializationOptions &getSerializationOptions() const {
333+
return SerializationOpts;
334+
}
335+
330336
void setParseStdlib() {
331337
FrontendOpts.ParseStdlib = true;
332338
}

include/swift/Serialization/SerializationOptions.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@
2525
namespace swift {
2626

2727
class SerializationOptions {
28-
SerializationOptions(const SerializationOptions &) = delete;
29-
void operator=(const SerializationOptions &) = delete;
30-
3128
public:
3229
SerializationOptions() = default;
3330
SerializationOptions(SerializationOptions &&) = default;
3431
SerializationOptions &operator=(SerializationOptions &&) = default;
32+
SerializationOptions(const SerializationOptions &) = default;
33+
SerializationOptions &operator=(const SerializationOptions &) = default;
3534
~SerializationOptions() = default;
3635

3736
StringRef OutputPath;

lib/AST/ASTContext.cpp

+17-14
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,8 @@ ASTContext *ASTContext::get(
757757
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
758758
ClangImporterOptions &ClangImporterOpts,
759759
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, CASOptions &casOpts,
760-
SourceManager &SourceMgr, DiagnosticEngine &Diags,
760+
SerializationOptions &serializationOpts, SourceManager &SourceMgr,
761+
DiagnosticEngine &Diags,
761762
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutputBackend) {
762763
// If more than two data structures are concatentated, then the aggregate
763764
// size math needs to become more complicated due to per-struct alignment
@@ -771,26 +772,28 @@ ASTContext *ASTContext::get(
771772
new (impl) Implementation();
772773
return new (mem)
773774
ASTContext(langOpts, typecheckOpts, silOpts, SearchPathOpts,
774-
ClangImporterOpts, SymbolGraphOpts, casOpts, SourceMgr, Diags,
775-
std::move(OutputBackend));
775+
ClangImporterOpts, SymbolGraphOpts, casOpts, serializationOpts,
776+
SourceMgr, Diags, std::move(OutputBackend));
776777
}
777778

778779
ASTContext::ASTContext(
779780
LangOptions &langOpts, TypeCheckerOptions &typecheckOpts,
780781
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
781782
ClangImporterOptions &ClangImporterOpts,
782783
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, CASOptions &casOpts,
783-
SourceManager &SourceMgr, DiagnosticEngine &Diags,
784+
SerializationOptions &SerializationOpts, SourceManager &SourceMgr,
785+
DiagnosticEngine &Diags,
784786
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend)
785787
: LangOpts(langOpts), TypeCheckerOpts(typecheckOpts), SILOpts(silOpts),
786788
SearchPathOpts(SearchPathOpts), ClangImporterOpts(ClangImporterOpts),
787-
SymbolGraphOpts(SymbolGraphOpts), CASOpts(casOpts), SourceMgr(SourceMgr),
788-
Diags(Diags), OutputBackend(std::move(OutBackend)),
789-
evaluator(Diags, langOpts), TheBuiltinModule(createBuiltinModule(*this)),
789+
SymbolGraphOpts(SymbolGraphOpts), CASOpts(casOpts),
790+
SerializationOpts(SerializationOpts), SourceMgr(SourceMgr), Diags(Diags),
791+
OutputBackend(std::move(OutBackend)), evaluator(Diags, langOpts),
792+
TheBuiltinModule(createBuiltinModule(*this)),
790793
StdlibModuleName(getIdentifier(STDLIB_NAME)),
791794
SwiftShimsModuleName(getIdentifier(SWIFT_SHIMS_NAME)),
792795
blockListConfig(SourceMgr),
793-
TheErrorType(new (*this, AllocationArena::Permanent) ErrorType(
796+
TheErrorType(new(*this, AllocationArena::Permanent) ErrorType(
794797
*this, Type(), RecursiveTypeProperties::HasError)),
795798
TheUnresolvedType(new(*this, AllocationArena::Permanent)
796799
UnresolvedType(*this)),
@@ -801,17 +804,17 @@ ASTContext::ASTContext(
801804
The##SHORT_ID##Type(new (*this, AllocationArena::Permanent) \
802805
ID##Type(*this)),
803806
#include "swift/AST/TypeNodes.def"
804-
TheIEEE32Type(new (*this, AllocationArena::Permanent)
807+
TheIEEE32Type(new(*this, AllocationArena::Permanent)
805808
BuiltinFloatType(BuiltinFloatType::IEEE32, *this)),
806-
TheIEEE64Type(new (*this, AllocationArena::Permanent)
809+
TheIEEE64Type(new(*this, AllocationArena::Permanent)
807810
BuiltinFloatType(BuiltinFloatType::IEEE64, *this)),
808-
TheIEEE16Type(new (*this, AllocationArena::Permanent)
811+
TheIEEE16Type(new(*this, AllocationArena::Permanent)
809812
BuiltinFloatType(BuiltinFloatType::IEEE16, *this)),
810-
TheIEEE80Type(new (*this, AllocationArena::Permanent)
813+
TheIEEE80Type(new(*this, AllocationArena::Permanent)
811814
BuiltinFloatType(BuiltinFloatType::IEEE80, *this)),
812-
TheIEEE128Type(new (*this, AllocationArena::Permanent)
815+
TheIEEE128Type(new(*this, AllocationArena::Permanent)
813816
BuiltinFloatType(BuiltinFloatType::IEEE128, *this)),
814-
ThePPC128Type(new (*this, AllocationArena::Permanent)
817+
ThePPC128Type(new(*this, AllocationArena::Permanent)
815818
BuiltinFloatType(BuiltinFloatType::PPC128, *this)) {
816819

817820
// Initialize all of the known identifiers.

lib/DependencyScan/ModuleDependencyScanner.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ ModuleDependencyScanningWorker::ModuleDependencyScanningWorker(
180180
workerCompilerInvocation->getClangImporterOptions(),
181181
workerCompilerInvocation->getSymbolGraphOptions(),
182182
workerCompilerInvocation->getCASOptions(),
183+
workerCompilerInvocation->getSerializationOptions(),
183184
ScanASTContext.SourceMgr, Diagnostics));
184185
auto loader = std::make_unique<PluginLoader>(
185186
*workerASTContext, /*DepTracker=*/nullptr,

lib/DriverTool/modulewrap_main.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,12 @@ int modulewrap_main(ArrayRef<const char *> Args, const char *Argv0,
188188
ClangImporterOptions ClangImporterOpts;
189189
symbolgraphgen::SymbolGraphOptions SymbolGraphOpts;
190190
CASOptions CASOpts;
191+
SerializationOptions SerializationOpts;
191192
LangOpts.Target = Invocation.getTargetTriple();
192193
LangOpts.EnableObjCInterop = Invocation.enableObjCInterop();
193194
ASTContext &ASTCtx = *ASTContext::get(
194195
LangOpts, TypeCheckOpts, SILOpts, SearchPathOpts, ClangImporterOpts,
195-
SymbolGraphOpts, CASOpts, SrcMgr, Instance.getDiags(),
196+
SymbolGraphOpts, CASOpts, SerializationOpts, SrcMgr, Instance.getDiags(),
196197
llvm::makeIntrusiveRefCnt<llvm::vfs::OnDiskOutputBackend>());
197198
registerParseRequestFunctions(ASTCtx.evaluator);
198199
registerTypeCheckerRequestFunctions(ASTCtx.evaluator);

lib/DriverTool/swift_parse_test_main.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ struct LibParseExecutor {
8282
ClangImporterOptions clangOpts;
8383
symbolgraphgen::SymbolGraphOptions symbolOpts;
8484
CASOptions casOpts;
85-
std::unique_ptr<ASTContext> ctx(
86-
ASTContext::get(langOpts, typeckOpts, silOpts, searchPathOpts,
87-
clangOpts, symbolOpts, casOpts, SM, diagEngine));
85+
SerializationOptions serializationOpts;
86+
std::unique_ptr<ASTContext> ctx(ASTContext::get(
87+
langOpts, typeckOpts, silOpts, searchPathOpts, clangOpts, symbolOpts,
88+
casOpts, serializationOpts, SM, diagEngine));
8889

8990
SourceFile::ParsingOptions parseOpts;
9091
parseOpts |= SourceFile::ParsingFlags::DisablePoundIfEvaluation;
@@ -153,13 +154,14 @@ struct ASTGenExecutor {
153154
ClangImporterOptions clangOpts;
154155
CASOptions casOpts;
155156
symbolgraphgen::SymbolGraphOptions symbolOpts;
157+
SerializationOptions serializationOpts;
156158

157159
// Enable ASTGen.
158160
langOpts.enableFeature(Feature::ParserASTGen);
159161

160-
std::unique_ptr<ASTContext> ctx(
161-
ASTContext::get(langOpts, typeckOpts, silOpts, searchPathOpts,
162-
clangOpts, symbolOpts, casOpts, SM, diagEngine));
162+
std::unique_ptr<ASTContext> ctx(ASTContext::get(
163+
langOpts, typeckOpts, silOpts, searchPathOpts, clangOpts, symbolOpts,
164+
casOpts, serializationOpts, SM, diagEngine));
163165
registerParseRequestFunctions(ctx->evaluator);
164166
registerTypeCheckerRequestFunctions(ctx->evaluator);
165167

lib/Frontend/Frontend.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ bool CompilerInstance::setUpASTContextIfNeeded() {
302302
Invocation.getLangOptions(), Invocation.getTypeCheckerOptions(),
303303
Invocation.getSILOptions(), Invocation.getSearchPathOptions(),
304304
Invocation.getClangImporterOptions(), Invocation.getSymbolGraphOptions(),
305-
Invocation.getCASOptions(), SourceMgr, Diagnostics, OutputBackend));
305+
Invocation.getCASOptions(), Invocation.getSerializationOptions(),
306+
SourceMgr, Diagnostics, OutputBackend));
306307
if (!Invocation.getFrontendOptions().ModuleAliasMap.empty())
307308
Context->setModuleAliases(Invocation.getFrontendOptions().ModuleAliasMap);
308309

lib/IDETool/CompileInstance.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,12 @@ getModifiedFunctionDeclList(const SourceFile &SF, SourceManager &tmpSM,
128128
SILOptions silOpts = ctx.SILOpts;
129129
CASOptions casOpts = ctx.CASOpts;
130130
symbolgraphgen::SymbolGraphOptions symbolOpts = ctx.SymbolGraphOpts;
131+
SerializationOptions serializationOpts = ctx.SerializationOpts;
131132

132133
DiagnosticEngine tmpDiags(tmpSM);
133134
auto &tmpCtx =
134135
*ASTContext::get(langOpts, typeckOpts, silOpts, searchPathOpts, clangOpts,
135-
symbolOpts, casOpts, tmpSM, tmpDiags);
136+
symbolOpts, casOpts, serializationOpts, tmpSM, tmpDiags);
136137
registerParseRequestFunctions(tmpCtx.evaluator);
137138
registerTypeCheckerRequestFunctions(tmpCtx.evaluator);
138139

lib/IDETool/IDEInspectionInstance.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,11 @@ bool IDEInspectionInstance::performCachedOperationIfPossible(
241241
ClangImporterOptions clangOpts;
242242
symbolgraphgen::SymbolGraphOptions symbolOpts;
243243
CASOptions casOpts;
244+
SerializationOptions serializationOpts =
245+
CachedCI->getASTContext().SerializationOpts;
244246
std::unique_ptr<ASTContext> tmpCtx(
245247
ASTContext::get(langOpts, typeckOpts, silOpts, searchPathOpts, clangOpts,
246-
symbolOpts, casOpts, tmpSM, tmpDiags));
248+
symbolOpts, casOpts, serializationOpts, tmpSM, tmpDiags));
247249
tmpCtx->CancellationFlag = CancellationFlag;
248250
registerParseRequestFunctions(tmpCtx->evaluator);
249251
registerIDERequestFunctions(tmpCtx->evaluator);

lib/IDETool/SyntacticMacroExpansion.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ bool SyntacticMacroExpansionInstance::setup(
6363
invocation.getLangOptions(), invocation.getTypeCheckerOptions(),
6464
invocation.getSILOptions(), invocation.getSearchPathOptions(),
6565
invocation.getClangImporterOptions(), invocation.getSymbolGraphOptions(),
66-
invocation.getCASOptions(), SourceMgr, Diags));
66+
invocation.getCASOptions(), invocation.getSerializationOptions(),
67+
SourceMgr, Diags));
6768
registerParseRequestFunctions(Ctx->evaluator);
6869
registerTypeCheckerRequestFunctions(Ctx->evaluator);
6970

lib/Parse/Parser.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,7 @@ struct ParserUnit::Implementation {
11261126
ClangImporterOptions clangImporterOpts;
11271127
symbolgraphgen::SymbolGraphOptions symbolGraphOpts;
11281128
CASOptions CASOpts;
1129+
SerializationOptions SerializationOpts;
11291130
DiagnosticEngine Diags;
11301131
ASTContext &Ctx;
11311132
SourceFile *SF;
@@ -1136,8 +1137,8 @@ struct ParserUnit::Implementation {
11361137
const SILOptions &silOpts, StringRef ModuleName)
11371138
: LangOpts(Opts), TypeCheckerOpts(TyOpts), SILOpts(silOpts), Diags(SM),
11381139
Ctx(*ASTContext::get(LangOpts, TypeCheckerOpts, SILOpts, SearchPathOpts,
1139-
clangImporterOpts, symbolGraphOpts, CASOpts, SM,
1140-
Diags)) {
1140+
clangImporterOpts, symbolGraphOpts, CASOpts,
1141+
SerializationOpts, SM, Diags)) {
11411142
registerParseRequestFunctions(Ctx.evaluator);
11421143

11431144
auto parsingOpts = SourceFile::getDefaultParsingOptions(LangOpts);

unittests/AST/TestContext.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static Decl *createOptionalType(ASTContext &ctx, SourceFile *fileForLookups,
3636
TestContext::TestContext(ShouldDeclareOptionalTypes optionals)
3737
: Ctx(*ASTContext::get(LangOpts, TypeCheckerOpts, SILOpts, SearchPathOpts,
3838
ClangImporterOpts, SymbolGraphOpts, CASOpts,
39-
SourceMgr, Diags)) {
39+
SerializationOpts, SourceMgr, Diags)) {
4040
registerParseRequestFunctions(Ctx.evaluator);
4141
registerTypeCheckerRequestFunctions(Ctx.evaluator);
4242
registerClangImporterRequestFunctions(Ctx.evaluator);

unittests/AST/TestContext.h

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class TestContextBase {
3636
ClangImporterOptions ClangImporterOpts;
3737
symbolgraphgen::SymbolGraphOptions SymbolGraphOpts;
3838
CASOptions CASOpts;
39+
SerializationOptions SerializationOpts;
3940
SourceManager SourceMgr;
4041
DiagnosticEngine Diags;
4142

unittests/ClangImporter/ClangImporterTests.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ TEST(ClangImporterTest, emitPCHInMemory) {
8080
swift::SearchPathOptions searchPathOpts;
8181
swift::symbolgraphgen::SymbolGraphOptions symbolGraphOpts;
8282
swift::CASOptions casOpts;
83+
swift::SerializationOptions serializationOpts;
8384
swift::SourceManager sourceMgr;
8485
swift::DiagnosticEngine diags(sourceMgr);
85-
std::unique_ptr<ASTContext> context(
86-
ASTContext::get(langOpts, typecheckOpts, silOpts, searchPathOpts, options,
87-
symbolGraphOpts, casOpts, sourceMgr, diags));
86+
std::unique_ptr<ASTContext> context(ASTContext::get(
87+
langOpts, typecheckOpts, silOpts, searchPathOpts, options,
88+
symbolGraphOpts, casOpts, serializationOpts, sourceMgr, diags));
8889
auto importer = ClangImporter::create(*context);
8990

9091
std::string PCH = createFilename(cache, "bridging.h.pch");
@@ -197,14 +198,15 @@ TEST(ClangImporterTest, libStdCxxInjectionTest) {
197198
swift::DiagnosticEngine diags(sourceMgr);
198199
ClangImporterOptions options;
199200
CASOptions casOpts;
201+
SerializationOptions serializationOpts;
200202
options.clangPath = "/usr/bin/clang";
201203
options.ExtraArgs.push_back(
202204
(llvm::Twine("--gcc-toolchain=") + "/opt/rh/devtoolset-9/root/usr")
203205
.str());
204206
options.ExtraArgs.push_back("--gcc-toolchain");
205-
std::unique_ptr<ASTContext> context(
206-
ASTContext::get(langOpts, typecheckOpts, silOpts, searchPathOpts, options,
207-
symbolGraphOpts, casOpts, sourceMgr, diags));
207+
std::unique_ptr<ASTContext> context(ASTContext::get(
208+
langOpts, typecheckOpts, silOpts, searchPathOpts, options,
209+
symbolGraphOpts, casOpts, serializationOpts, sourceMgr, diags));
208210

209211
{
210212
LibStdCxxInjectionVFS vfs;

unittests/FrontendTool/ModuleLoadingTests.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ class ModuleInterfaceLoaderTest : public testing::Test {
104104
symbolgraphgen::SymbolGraphOptions symbolGraphOpts;
105105
SILOptions silOpts;
106106
CASOptions casOpts;
107+
SerializationOptions serializationOpts;
107108
auto ctx = ASTContext::get(langOpts, typecheckOpts, silOpts, searchPathOpts,
108109
clangImpOpts, symbolGraphOpts, casOpts,
109-
sourceMgr, diags);
110+
serializationOpts, sourceMgr, diags);
110111

111112
ctx->addModuleInterfaceChecker(
112113
std::make_unique<ModuleInterfaceCheckerImpl>(*ctx, cacheDir,

unittests/Sema/SemaFixture.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ using namespace swift::unittest;
2929
using namespace swift::constraints::inference;
3030

3131
SemaTest::SemaTest()
32-
: Context(*ASTContext::get(LangOpts, TypeCheckerOpts, SILOpts,
33-
SearchPathOpts, ClangImporterOpts,
34-
SymbolGraphOpts, CASOpts, SourceMgr, Diags)) {
32+
: Context(*ASTContext::get(
33+
LangOpts, TypeCheckerOpts, SILOpts, SearchPathOpts, ClangImporterOpts,
34+
SymbolGraphOpts, CASOpts, SerializationOpts, SourceMgr, Diags)) {
3535
INITIALIZE_LLVM();
3636

3737
registerParseRequestFunctions(Context.evaluator);

unittests/Sema/SemaFixture.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class SemaTestBase : public ::testing::Test {
4343
ClangImporterOptions ClangImporterOpts;
4444
symbolgraphgen::SymbolGraphOptions SymbolGraphOpts;
4545
CASOptions CASOpts;
46+
SerializationOptions SerializationOpts;
4647
SourceManager SourceMgr;
4748
DiagnosticEngine Diags;
4849

0 commit comments

Comments
 (0)