diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index dd67c5d0410f8..4e43b650285a4 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -4063,19 +4063,6 @@ inline void operator delete[](void *Ptr, const clang::ASTContext &C, size_t) { C.Deallocate(Ptr); } -/// Create the representation of a LazyGenerationalUpdatePtr. -template -typename clang::LazyGenerationalUpdatePtr::ValueType - clang::LazyGenerationalUpdatePtr::makeValue( - const clang::ASTContext &Ctx, T Value) { - // Note, this is implemented here so that ExternalASTSource.h doesn't need to - // include ASTContext.h. We explicitly instantiate it for all relevant types - // in ASTContext.cpp. - if (auto *Source = Ctx.getExternalSource()) - return new (Ctx) LazyData(Source, Value); - return Value; -} template <> struct llvm::DenseMapInfo { static unsigned getHashValue(const FoldingSetNodeID &Val) { return Val.ComputeHash(); diff --git a/clang/include/clang/AST/ExternalASTSource.h b/clang/include/clang/AST/ExternalASTSource.h index be88309969715..b277ce5812cdc 100644 --- a/clang/include/clang/AST/ExternalASTSource.h +++ b/clang/include/clang/AST/ExternalASTSource.h @@ -439,46 +439,38 @@ struct LazyOffsetPtr { } }; -/// A lazy value (of type T) that is within an AST node of type Owner, -/// where the value might change in later generations of the external AST -/// source. -template -struct LazyGenerationalUpdatePtr { +/// A lazy Decl value where the value might change in later generations of the +/// external AST source. +struct LazyGenerationalDeclPtr { /// A cache of the value of this pointer, in the most recent generation in /// which we queried it. struct LazyData { ExternalASTSource *ExternalSource; uint32_t LastGeneration = 0; - T LastValue; + Decl *LastValue; - LazyData(ExternalASTSource *Source, T Value) + LazyData(ExternalASTSource *Source, Decl *Value) : ExternalSource(Source), LastValue(Value) {} }; - // Our value is represented as simply T if there is no external AST source. - using ValueType = llvm::PointerUnion; + // Our value is represented as simply a Decl pointer if there is no external + // AST source. + using ValueType = llvm::PointerUnion; ValueType Value; - LazyGenerationalUpdatePtr(ValueType V) : Value(V) {} + LazyGenerationalDeclPtr(ValueType V) : Value(V) {} - // Defined in ASTContext.h - static ValueType makeValue(const ASTContext &Ctx, T Value); + static ValueType makeValue(const ASTContext &Ctx, Decl *Value); public: - explicit LazyGenerationalUpdatePtr(const ASTContext &Ctx, T Value = T()) + explicit LazyGenerationalDeclPtr(const ASTContext &Ctx, Decl *Value = nullptr) : Value(makeValue(Ctx, Value)) {} - /// Create a pointer that is not potentially updated by later generations of - /// the external AST source. - enum NotUpdatedTag { NotUpdated }; - LazyGenerationalUpdatePtr(NotUpdatedTag, T Value = T()) - : Value(Value) {} - /// Forcibly set this pointer (which must be lazy) as needing updates. void markIncomplete() { cast(Value)->LastGeneration = 0; } /// Set the value of this pointer, in the current generation. - void set(T NewValue) { + void set(Decl *NewValue) { if (auto *LazyVal = Value.template dyn_cast()) { LazyVal->LastValue = NewValue; return; @@ -486,31 +478,28 @@ struct LazyGenerationalUpdatePtr { Value = NewValue; } - /// Set the value of this pointer, for this and all future generations. - void setNotUpdated(T NewValue) { Value = NewValue; } - /// Get the value of this pointer, updating its owner if necessary. - T get(Owner O) { + Decl *get(const Decl *O) { if (auto *LazyVal = Value.template dyn_cast()) { if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) { LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration(); - (LazyVal->ExternalSource->*Update)(O); + LazyVal->ExternalSource->CompleteRedeclChain(O); } return LazyVal->LastValue; } - return cast(Value); + return cast(Value); } /// Get the most recently computed value of this pointer without updating it. - T getNotUpdated() const { + Decl *getNotUpdated() const { if (auto *LazyVal = Value.template dyn_cast()) return LazyVal->LastValue; - return cast(Value); + return cast(Value); } void *getOpaqueValue() { return Value.getOpaqueValue(); } - static LazyGenerationalUpdatePtr getFromOpaqueValue(void *Ptr) { - return LazyGenerationalUpdatePtr(ValueType::getFromOpaqueValue(Ptr)); + static LazyGenerationalDeclPtr getFromOpaqueValue(void *Ptr) { + return LazyGenerationalDeclPtr(ValueType::getFromOpaqueValue(Ptr)); } }; @@ -518,13 +507,10 @@ struct LazyGenerationalUpdatePtr { namespace llvm { -/// Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be +/// Specialize PointerLikeTypeTraits to allow LazyGenerationalDeclPtr to be /// placed into a PointerUnion. -template -struct PointerLikeTypeTraits< - clang::LazyGenerationalUpdatePtr> { - using Ptr = clang::LazyGenerationalUpdatePtr; +template <> struct PointerLikeTypeTraits { + using Ptr = clang::LazyGenerationalDeclPtr; static void *getAsVoidPointer(Ptr P) { return P.getOpaqueValue(); } static Ptr getFromVoidPointer(void *P) { return Ptr::getFromOpaqueValue(P); } diff --git a/clang/include/clang/AST/Redeclarable.h b/clang/include/clang/AST/Redeclarable.h index 28fff4f43823c..35911ee2f7d16 100644 --- a/clang/include/clang/AST/Redeclarable.h +++ b/clang/include/clang/AST/Redeclarable.h @@ -86,9 +86,7 @@ class Redeclarable { class DeclLink { /// A pointer to a known latest declaration, either statically known or /// generationally updated as decls are added by an external source. - using KnownLatest = - LazyGenerationalUpdatePtr; + using KnownLatest = LazyGenerationalDeclPtr; /// We store a pointer to the ASTContext in the UninitializedLatest /// pointer, but to avoid circular type dependencies when we steal the low diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index b502c4436de49..4123c2d204920 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -15171,15 +15171,6 @@ LangAS ASTContext::getLangASForBuiltinAddressSpace(unsigned AS) const { return getLangASFromTargetAS(AS); } -// Explicitly instantiate this in case a Redeclarable is used from a TU that -// doesn't include ASTContext.h -template -clang::LazyGenerationalUpdatePtr< - const Decl *, Decl *, &ExternalASTSource::CompleteRedeclChain>::ValueType -clang::LazyGenerationalUpdatePtr< - const Decl *, Decl *, &ExternalASTSource::CompleteRedeclChain>::makeValue( - const clang::ASTContext &Ctx, Decl *Value); - unsigned char ASTContext::getFixedPointScale(QualType Ty) const { assert(Ty->isFixedPointType()); diff --git a/clang/lib/AST/ExternalASTSource.cpp b/clang/lib/AST/ExternalASTSource.cpp index e8c1004089713..118f6fd67d3a4 100644 --- a/clang/lib/AST/ExternalASTSource.cpp +++ b/clang/lib/AST/ExternalASTSource.cpp @@ -134,3 +134,10 @@ uint32_t ExternalASTSource::incrementGeneration(ASTContext &C) { return OldGeneration; } + +LazyGenerationalDeclPtr::ValueType +LazyGenerationalDeclPtr::makeValue(const ASTContext &Ctx, Decl *Value) { + if (auto *Source = Ctx.getExternalSource()) + return new (Ctx) LazyData(Source, Value); + return Value; +} diff --git a/llvm/unittests/ADT/PointerUnionTest.cpp b/llvm/unittests/ADT/PointerUnionTest.cpp index 258e4050984e8..2c85c24526320 100644 --- a/llvm/unittests/ADT/PointerUnionTest.cpp +++ b/llvm/unittests/ADT/PointerUnionTest.cpp @@ -310,7 +310,7 @@ struct alignas(4) LowAlign { }; // Wrapper around a PointerUnion that over-claims NumLowBitsAvailable, -// mimicking LazyGenerationalUpdatePtr's PLTT on 32-bit. +// mimicking LazyGenerationalDeclPtr's PLTT on 32-bit. struct OverClaimWrapper { PointerUnion Value;