Skip to content

Commit f7de3d3

Browse files
committed
Revert "[cxxmodules] Refactor generation counter in LLVM"
This reverts commit 75e3a39.
1 parent e0e5723 commit f7de3d3

5 files changed

Lines changed: 28 additions & 40 deletions

File tree

‎interpreter/llvm-project/clang/include/clang/AST/ASTContext.h‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
314314
llvm::to_underlying(PredefinedSugarType::Kind::Last) + 1>
315315
PredefinedSugarTypes{};
316316

317-
/// Generation number for this external AST source. Must be increased
318-
/// whenever we might have added new redeclarations for existing decls.
319-
uint32_t CurrentGeneration = 0;
320-
321317
/// Internal storage for NestedNameSpecifiers.
322318
///
323319
/// This set is managed by the NestedNameSpecifier class.
@@ -844,15 +840,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
844840
/// use ParentMapContext::getParents() directly.
845841
template <typename NodeT> DynTypedNodeList getParents(const NodeT &Node);
846842

847-
uint32_t getGeneration() const { return CurrentGeneration; }
848-
uint32_t incrementGeneration() {
849-
uint32_t OldGeneration = CurrentGeneration;
850-
CurrentGeneration++;
851-
assert(CurrentGeneration > OldGeneration &&
852-
"Overflowed generation counter");
853-
return OldGeneration;
854-
}
855-
856843
const clang::PrintingPolicy &getPrintingPolicy() const {
857844
return PrintingPolicy;
858845
}
@@ -3933,7 +3920,7 @@ typename clang::LazyGenerationalUpdatePtr<Owner, T, Update>::ValueType
39333920
// include ASTContext.h. We explicitly instantiate it for all relevant types
39343921
// in ASTContext.cpp.
39353922
if (auto *Source = Ctx.getExternalSource())
3936-
return new (Ctx) LazyData(&Ctx, Source, Value);
3923+
return new (Ctx) LazyData(Source, Value);
39373924
return Value;
39383925
}
39393926
template <> struct llvm::DenseMapInfo<llvm::FoldingSetNodeID> {

‎interpreter/llvm-project/clang/include/clang/AST/ExternalASTSource.h‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class ExternalASTSource : public RefCountedBase<ExternalASTSource> {
9393
/// Get the current generation of this AST source. This number
9494
/// is incremented each time the AST source lazily extends an existing
9595
/// entity.
96-
uint32_t getGeneration(const ASTContext &C) const;
96+
uint32_t getGeneration() const { return CurrentGeneration; }
9797

9898
/// Resolve a declaration ID into a declaration, potentially
9999
/// building a new declaration.
@@ -447,14 +447,12 @@ struct LazyGenerationalUpdatePtr {
447447
/// A cache of the value of this pointer, in the most recent generation in
448448
/// which we queried it.
449449
struct LazyData {
450-
const ASTContext *Context;
451450
ExternalASTSource *ExternalSource;
452451
uint32_t LastGeneration = 0;
453452
T LastValue;
454453

455-
LazyData(const ASTContext *Context, ExternalASTSource *Source, T Value)
456-
: Context(Context), ExternalSource(Source), LastGeneration(0),
457-
LastValue(Value) {}
454+
LazyData(ExternalASTSource *Source, T Value)
455+
: ExternalSource(Source), LastValue(Value) {}
458456
};
459457

460458
// Our value is represented as simply T if there is no external AST source.
@@ -494,10 +492,8 @@ struct LazyGenerationalUpdatePtr {
494492
/// Get the value of this pointer, updating its owner if necessary.
495493
T get(Owner O) {
496494
if (auto *LazyVal = Value.template dyn_cast<LazyData *>()) {
497-
if (LazyVal->LastGeneration !=
498-
LazyVal->ExternalSource->getGeneration(*LazyVal->Context)) {
499-
LazyVal->LastGeneration =
500-
LazyVal->ExternalSource->getGeneration(*LazyVal->Context);
495+
if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) {
496+
LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration();
501497
(LazyVal->ExternalSource->*Update)(O);
502498
}
503499
return LazyVal->LastValue;

‎interpreter/llvm-project/clang/include/clang/Serialization/ASTReader.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,12 +1556,6 @@ class ASTReader
15561556
: Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) {}
15571557
};
15581558

1559-
uint32_t getGenerationOrNull() const {
1560-
if (ContextObj)
1561-
return getGeneration(*ContextObj);
1562-
return 0u;
1563-
}
1564-
15651559
ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type,
15661560
SourceLocation ImportLoc, ModuleFile *ImportedBy,
15671561
SmallVectorImpl<ImportedModule> &Loaded,

‎interpreter/llvm-project/clang/lib/AST/ExternalASTSource.cpp‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ char ExternalASTSource::ID;
2828

2929
ExternalASTSource::~ExternalASTSource() = default;
3030

31-
uint32_t ExternalASTSource::getGeneration(const ASTContext &C) const {
32-
return C.getGeneration();
33-
}
34-
3531
std::optional<ASTSourceDescriptor>
3632
ExternalASTSource::getSourceDescriptor(unsigned ID) {
3733
return std::nullopt;
@@ -122,5 +118,19 @@ void ExternalASTSource::FindExternalLexicalDecls(
122118
void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {}
123119

124120
uint32_t ExternalASTSource::incrementGeneration(ASTContext &C) {
125-
return C.incrementGeneration();
121+
uint32_t OldGeneration = CurrentGeneration;
122+
123+
// Make sure the generation of the topmost external source for the context is
124+
// incremented. That might not be us.
125+
auto *P = C.getExternalSource();
126+
if (P && P != this)
127+
CurrentGeneration = P->incrementGeneration(C);
128+
else {
129+
// FIXME: Only bump the generation counter if the current generation number
130+
// has been observed?
131+
if (!++CurrentGeneration)
132+
llvm::reportFatalUsageError("generation counter overflowed");
133+
}
134+
135+
return OldGeneration;
126136
}

‎interpreter/llvm-project/clang/lib/Serialization/ASTReader.cpp‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,7 +2568,7 @@ void ASTReader::markIdentifierUpToDate(const IdentifierInfo *II) {
25682568

25692569
// Update the generation for this identifier.
25702570
if (getContext().getLangOpts().Modules)
2571-
IdentifierGeneration[II] = getGenerationOrNull();
2571+
IdentifierGeneration[II] = getGeneration();
25722572
}
25732573

25742574
MacroID ASTReader::ReadMacroID(ModuleFile &F, const RecordDataImpl &Record,
@@ -5177,10 +5177,11 @@ ASTReader::ReadASTCore(StringRef FileName,
51775177
unsigned ClientLoadCapabilities) {
51785178
ModuleFile *M;
51795179
std::string ErrorStr;
5180-
ModuleManager::AddModuleResult AddResult =
5181-
ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy,
5182-
getGenerationOrNull(), ExpectedSize, ExpectedModTime,
5183-
ExpectedSignature, readASTFileSignature, M, ErrorStr);
5180+
ModuleManager::AddModuleResult AddResult
5181+
= ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy,
5182+
getGeneration(), ExpectedSize, ExpectedModTime,
5183+
ExpectedSignature, readASTFileSignature,
5184+
M, ErrorStr);
51845185

51855186
switch (AddResult) {
51865187
case ModuleManager::AlreadyLoaded:
@@ -9462,7 +9463,7 @@ void ASTReader::ReadMethodPool(Selector Sel) {
94629463
// Get the selector generation and update it to the current generation.
94639464
unsigned &Generation = SelectorGeneration[Sel];
94649465
unsigned PriorGeneration = Generation;
9465-
Generation = getGenerationOrNull();
9466+
Generation = getGeneration();
94669467
SelectorOutOfDate[Sel] = false;
94679468

94689469
// Search for methods defined with this selector.

0 commit comments

Comments
 (0)