@@ -76,10 +76,7 @@ using namespace llvm::support;
76
76
using swift::version::Version;
77
77
using llvm::BCBlockRAII;
78
78
79
-
80
- ASTContext &SerializerBase::getASTContext () {
81
- return M->getASTContext ();
82
- }
79
+ ASTContext &SerializerBase::getASTContext () const { return M->getASTContext (); }
83
80
84
81
// / Used for static_assert.
85
82
static constexpr bool declIDFitsIn32Bits () {
@@ -644,8 +641,9 @@ serialization::TypeID Serializer::addTypeRef(Type ty) {
644
641
645
642
#ifndef NDEBUG
646
643
PrettyStackTraceType trace (M->getASTContext (), " serializing" , typeToSerialize);
647
- assert (M->getASTContext ().LangOpts .AllowModuleWithCompilerErrors ||
648
- !typeToSerialize || !typeToSerialize->hasError () && " serializing type with an error" );
644
+ assert ((allowCompilerErrors () || !typeToSerialize ||
645
+ !typeToSerialize->hasError ()) &&
646
+ " serializing type with an error" );
649
647
#endif
650
648
651
649
return TypesToSerialize.addRef (typeToSerialize);
@@ -1015,7 +1013,7 @@ void Serializer::writeHeader(const SerializationOptions &options) {
1015
1013
Strategy.emit (ScratchRecord, unsigned (M->getResilienceStrategy ()));
1016
1014
}
1017
1015
1018
- if (getASTContext (). LangOpts . AllowModuleWithCompilerErrors ) {
1016
+ if (allowCompilerErrors () ) {
1019
1017
options_block::IsAllowModuleWithCompilerErrorsEnabledLayout
1020
1018
AllowErrors (Out);
1021
1019
AllowErrors.emit (ScratchRecord);
@@ -1439,8 +1437,7 @@ void Serializer::writeASTBlockEntity(
1439
1437
using namespace decls_block ;
1440
1438
1441
1439
// The conformance must be complete, or we can't serialize it.
1442
- assert (conformance->isComplete () ||
1443
- getASTContext ().LangOpts .AllowModuleWithCompilerErrors );
1440
+ assert (conformance->isComplete () || allowCompilerErrors ());
1444
1441
assert (NormalConformancesToSerialize.hasRef (conformance));
1445
1442
1446
1443
auto protocol = conformance->getProtocol ();
@@ -2853,7 +2850,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
2853
2850
// Retrieve the type of the pattern.
2854
2851
auto getPatternType = [&] {
2855
2852
if (!pattern->hasType ()) {
2856
- if (S.getASTContext (). LangOpts . AllowModuleWithCompilerErrors )
2853
+ if (S.allowCompilerErrors () )
2857
2854
return ErrorType::get (S.getASTContext ());
2858
2855
llvm_unreachable (" all nodes should have types" );
2859
2856
}
@@ -3617,8 +3614,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
3617
3614
getRawStableDefaultArgumentKind (argKind),
3618
3615
defaultArgumentText);
3619
3616
3620
- if (interfaceType->hasError () &&
3621
- !S.getASTContext ().LangOpts .AllowModuleWithCompilerErrors ) {
3617
+ if (interfaceType->hasError () && !S.allowCompilerErrors ()) {
3622
3618
param->getDeclContext ()->printContext (llvm::errs ());
3623
3619
interfaceType->dump (llvm::errs ());
3624
3620
llvm_unreachable (" error in interface type of parameter" );
@@ -3985,8 +3981,8 @@ void Serializer::writeASTBlockEntity(const Decl *D) {
3985
3981
}
3986
3982
};
3987
3983
3988
- assert (getASTContext (). LangOpts . AllowModuleWithCompilerErrors ||
3989
- !D-> isInvalid () && " cannot create a module with an invalid decl" );
3984
+ assert (( allowCompilerErrors () || !D-> isInvalid ()) &&
3985
+ " cannot create a module with an invalid decl" );
3990
3986
if (isDeclXRef (D)) {
3991
3987
writeCrossReference (D);
3992
3988
return ;
@@ -4148,7 +4144,7 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
4148
4144
void visitType (const TypeBase *) = delete;
4149
4145
4150
4146
void visitErrorType (const ErrorType *ty) {
4151
- if (S.getASTContext (). LangOpts . AllowModuleWithCompilerErrors ) {
4147
+ if (S.allowCompilerErrors () ) {
4152
4148
using namespace decls_block ;
4153
4149
unsigned abbrCode = S.DeclTypeAbbrCodes [ErrorTypeLayout::Code];
4154
4150
ErrorTypeLayout::emitRecord (S.Out , S.ScratchRecord , abbrCode,
@@ -5244,8 +5240,7 @@ static void collectInterestingNestedDeclarations(
5244
5240
if (!nominalParent) {
5245
5241
const DeclContext *DC = member->getDeclContext ();
5246
5242
nominalParent = DC->getSelfNominalTypeDecl ();
5247
- assert (nominalParent ||
5248
- nestedType->getASTContext ().LangOpts .AllowModuleWithCompilerErrors &&
5243
+ assert ((nominalParent || S.allowCompilerErrors ()) &&
5249
5244
" parent context is not a type or extension" );
5250
5245
}
5251
5246
nestedTypeDecls[nestedType->getName ()].push_back ({
@@ -5531,6 +5526,10 @@ void Serializer::writeToStream(
5531
5526
S.writeToStream (os);
5532
5527
}
5533
5528
5529
+ bool Serializer::allowCompilerErrors () const {
5530
+ return getASTContext ().LangOpts .AllowModuleWithCompilerErrors ;
5531
+ }
5532
+
5534
5533
void swift::serializeToBuffers (
5535
5534
ModuleOrSourceFile DC, const SerializationOptions &options,
5536
5535
std::unique_ptr<llvm::MemoryBuffer> *moduleBuffer,
0 commit comments