Skip to content

Commit cf47e9f

Browse files
committed
[Serialization] Don't try to complete the redeclaration chain in
ASTReader after we start writing This is intended to mitigate #61447. Before the patch, it takes 5s to compile test.cppm in the above reproducer. After the patch it takes 3s to compile it. Although this patch didn't solve the problem completely, it should mitigate the problem for sure. Noted that the behavior of the patch is consistent with the comment of the originally empty function ASTReader::finalizeForWriting. So the change should be consistent with the original design.
1 parent 5becf54 commit cf47e9f

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

clang/include/clang/Serialization/ASTReader.h

+3
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,9 @@ class ASTReader
988988
///Whether we are currently processing update records.
989989
bool ProcessingUpdateRecords = false;
990990

991+
/// Whether we are going to write modules.
992+
bool FinalizedForWriting = false;
993+
991994
using SwitchCaseMapTy = llvm::DenseMap<unsigned, SwitchCase *>;
992995

993996
/// Mapping from switch-case IDs in the chain to switch-case statements

clang/lib/Serialization/ASTReader.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -5089,7 +5089,8 @@ void ASTReader::InitializeContext() {
50895089
}
50905090

50915091
void ASTReader::finalizeForWriting() {
5092-
// Nothing to do for now.
5092+
assert(!NumCurrentElementsDeserializing && "deserializing when reading");
5093+
FinalizedForWriting = true;
50935094
}
50945095

50955096
/// Reads and return the signature record from \p PCH's control block, or
@@ -7328,6 +7329,12 @@ Decl *ASTReader::GetExternalDecl(uint32_t ID) {
73287329
}
73297330

73307331
void ASTReader::CompleteRedeclChain(const Decl *D) {
7332+
// We don't need to complete declaration chain after we start writing.
7333+
// We loses more chances to find ODR violation in the writing place and
7334+
// we get more efficient writing process.
7335+
if (FinalizedForWriting)
7336+
return;
7337+
73317338
if (NumCurrentElementsDeserializing) {
73327339
// We arrange to not care about the complete redeclaration chain while we're
73337340
// deserializing. Just remember that the AST has marked this one as complete

clang/test/Modules/polluted-operator.cppm

+13
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,20 @@ module;
5151
export module b;
5252
import a;
5353

54+
void b() {
55+
std::variant<int, double> v;
56+
}
57+
5458
// expected-error@* {{has different definitions in different modules; first difference is defined here found data member '_S_copy_ctor' with an initializer}}
5559
// expected-note@* {{but in 'a.<global>' found data member '_S_copy_ctor' with a different initializer}}
5660
// expected-error@* {{from module 'a.<global>' is not present in definition of 'variant<_Types...>' provided earlier}}
5761
// expected-note@* {{declaration of 'swap' does not match}}
62+
63+
//--- c.cppm
64+
module;
65+
#include "bar.h"
66+
export module c;
67+
import a;
68+
69+
// expected-error@* {{has different definitions in different modules; first difference is defined here found data member '_S_copy_ctor' with an initializer}}
70+
// expected-note@* {{but in 'a.<global>' found data member '_S_copy_ctor' with a different initializer}}

0 commit comments

Comments
 (0)