@@ -76,10 +76,7 @@ using namespace llvm::support;
7676using swift::version::Version;
7777using llvm::BCBlockRAII;
7878
79-
80- ASTContext &SerializerBase::getASTContext () {
81- return M->getASTContext ();
82- }
79+ ASTContext &SerializerBase::getASTContext () const { return M->getASTContext (); }
8380
8481// / Used for static_assert.
8582static constexpr bool declIDFitsIn32Bits () {
@@ -644,8 +641,9 @@ serialization::TypeID Serializer::addTypeRef(Type ty) {
644641
645642#ifndef NDEBUG
646643 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" );
649647#endif
650648
651649 return TypesToSerialize.addRef (typeToSerialize);
@@ -1015,7 +1013,7 @@ void Serializer::writeHeader(const SerializationOptions &options) {
10151013 Strategy.emit (ScratchRecord, unsigned (M->getResilienceStrategy ()));
10161014 }
10171015
1018- if (getASTContext (). LangOpts . AllowModuleWithCompilerErrors ) {
1016+ if (allowCompilerErrors () ) {
10191017 options_block::IsAllowModuleWithCompilerErrorsEnabledLayout
10201018 AllowErrors (Out);
10211019 AllowErrors.emit (ScratchRecord);
@@ -1439,8 +1437,7 @@ void Serializer::writeASTBlockEntity(
14391437 using namespace decls_block ;
14401438
14411439 // The conformance must be complete, or we can't serialize it.
1442- assert (conformance->isComplete () ||
1443- getASTContext ().LangOpts .AllowModuleWithCompilerErrors );
1440+ assert (conformance->isComplete () || allowCompilerErrors ());
14441441 assert (NormalConformancesToSerialize.hasRef (conformance));
14451442
14461443 auto protocol = conformance->getProtocol ();
@@ -2861,7 +2858,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
28612858 // Retrieve the type of the pattern.
28622859 auto getPatternType = [&] {
28632860 if (!pattern->hasType ()) {
2864- if (S.getASTContext (). LangOpts . AllowModuleWithCompilerErrors )
2861+ if (S.allowCompilerErrors () )
28652862 return ErrorType::get (S.getASTContext ());
28662863 llvm_unreachable (" all nodes should have types" );
28672864 }
@@ -3625,8 +3622,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
36253622 getRawStableDefaultArgumentKind (argKind),
36263623 defaultArgumentText);
36273624
3628- if (interfaceType->hasError () &&
3629- !S.getASTContext ().LangOpts .AllowModuleWithCompilerErrors ) {
3625+ if (interfaceType->hasError () && !S.allowCompilerErrors ()) {
36303626 param->getDeclContext ()->printContext (llvm::errs ());
36313627 interfaceType->dump (llvm::errs ());
36323628 llvm_unreachable (" error in interface type of parameter" );
@@ -3993,8 +3989,8 @@ void Serializer::writeASTBlockEntity(const Decl *D) {
39933989 }
39943990 };
39953991
3996- assert (getASTContext (). LangOpts . AllowModuleWithCompilerErrors ||
3997- !D-> isInvalid () && " cannot create a module with an invalid decl" );
3992+ assert (( allowCompilerErrors () || !D-> isInvalid ()) &&
3993+ " cannot create a module with an invalid decl" );
39983994 if (isDeclXRef (D)) {
39993995 writeCrossReference (D);
40003996 return ;
@@ -4156,7 +4152,7 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
41564152 void visitType (const TypeBase *) = delete;
41574153
41584154 void visitErrorType (const ErrorType *ty) {
4159- if (S.getASTContext (). LangOpts . AllowModuleWithCompilerErrors ) {
4155+ if (S.allowCompilerErrors () ) {
41604156 using namespace decls_block ;
41614157 unsigned abbrCode = S.DeclTypeAbbrCodes [ErrorTypeLayout::Code];
41624158 ErrorTypeLayout::emitRecord (S.Out , S.ScratchRecord , abbrCode,
@@ -5252,8 +5248,7 @@ static void collectInterestingNestedDeclarations(
52525248 if (!nominalParent) {
52535249 const DeclContext *DC = member->getDeclContext ();
52545250 nominalParent = DC->getSelfNominalTypeDecl ();
5255- assert (nominalParent ||
5256- nestedType->getASTContext ().LangOpts .AllowModuleWithCompilerErrors &&
5251+ assert ((nominalParent || S.allowCompilerErrors ()) &&
52575252 " parent context is not a type or extension" );
52585253 }
52595254 nestedTypeDecls[nestedType->getName ()].push_back ({
@@ -5539,6 +5534,10 @@ void Serializer::writeToStream(
55395534 S.writeToStream (os);
55405535}
55415536
5537+ bool Serializer::allowCompilerErrors () const {
5538+ return getASTContext ().LangOpts .AllowModuleWithCompilerErrors ;
5539+ }
5540+
55425541void swift::serializeToBuffers (
55435542 ModuleOrSourceFile DC, const SerializationOptions &options,
55445543 std::unique_ptr<llvm::MemoryBuffer> *moduleBuffer,
0 commit comments