[clang] 5922f23 - Revert "[clang-repl] Implement partial translation units and error recovery."
Vassil Vassilev via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 11 07:43:05 PDT 2021
Author: Vassil Vassilev
Date: 2021-07-11T14:40:10Z
New Revision: 5922f234c8c95f61534160a31db15dfc10da9b60
URL: https://github.com/llvm/llvm-project/commit/5922f234c8c95f61534160a31db15dfc10da9b60
DIFF: https://github.com/llvm/llvm-project/commit/5922f234c8c95f61534160a31db15dfc10da9b60.diff
LOG: Revert "[clang-repl] Implement partial translation units and error recovery."
This reverts commit 6775fc6ffa3ca1c36b20c25fa4e7f48f81213cf2.
It also reverts "[lldb] Fix compilation by adjusting to the new ASTContext signature."
This reverts commit 03a3f86071c10a1f6cbbf7375aa6fe9d94168972.
We see some failures on the lldb infrastructure, these changes might play a role
in it. Let's revert it now and see if the bots will become green.
Ref: https://reviews.llvm.org/D104918
Added:
clang/include/clang/Interpreter/Transaction.h
Modified:
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Decl.h
clang/include/clang/AST/Redeclarable.h
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Interpreter/Interpreter.h
clang/include/clang/Lex/Preprocessor.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclBase.cpp
clang/lib/Frontend/ASTUnit.cpp
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Interpreter/IncrementalParser.cpp
clang/lib/Interpreter/IncrementalParser.h
clang/lib/Interpreter/Interpreter.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Serialization/ASTReader.cpp
clang/tools/clang-import-test/clang-import-test.cpp
clang/unittests/AST/ASTVectorTest.cpp
clang/unittests/Interpreter/IncrementalProcessingTest.cpp
clang/unittests/Interpreter/InterpreterTest.cpp
clang/unittests/Lex/PPCallbacksTest.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Removed:
clang/include/clang/Interpreter/PartialTranslationUnit.h
################################################################################
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index 34299581d89d4..5032f3194a9b7 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -459,7 +459,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
friend class ASTWriter;
template <class> friend class serialization::AbstractTypeReader;
friend class CXXRecordDecl;
- friend class IncrementalParser;
/// A mapping to contain the template or declaration that
/// a variable declaration describes or was instantiated from,
@@ -568,7 +567,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
ImportDecl *FirstLocalImport = nullptr;
ImportDecl *LastLocalImport = nullptr;
- TranslationUnitDecl *TUDecl = nullptr;
+ TranslationUnitDecl *TUDecl;
mutable ExternCContextDecl *ExternCContext = nullptr;
mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
@@ -625,7 +624,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
IdentifierTable &Idents;
SelectorTable &Selectors;
Builtin::Context &BuiltinInfo;
- const TranslationUnitKind TUKind;
mutable DeclarationNameTable DeclarationNames;
IntrusiveRefCntPtr<ExternalASTSource> ExternalSource;
ASTMutationListener *Listener = nullptr;
@@ -1024,18 +1022,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// Get the initializations to perform when importing a module, if any.
ArrayRef<Decl*> getModuleInitializers(Module *M);
- TranslationUnitDecl *getTranslationUnitDecl() const {
- return TUDecl->getMostRecentDecl();
- }
- void addTranslationUnitDecl() {
- assert(!TUDecl || TUKind == TU_Incremental);
- TranslationUnitDecl *NewTUDecl = TranslationUnitDecl::Create(*this);
- if (TraversalScope.empty() || TraversalScope.back() == TUDecl)
- TraversalScope = {NewTUDecl};
- if (TUDecl)
- NewTUDecl->setPreviousDecl(TUDecl);
- TUDecl = NewTUDecl;
- }
+ TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
ExternCContextDecl *getExternCContextDecl() const;
BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
@@ -1112,8 +1099,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
llvm::DenseSet<const VarDecl *> CUDADeviceVarODRUsedByHost;
ASTContext(LangOptions &LOpts, SourceManager &SM, IdentifierTable &idents,
- SelectorTable &sels, Builtin::Context &builtins,
- TranslationUnitKind TUKind);
+ SelectorTable &sels, Builtin::Context &builtins);
ASTContext(const ASTContext &) = delete;
ASTContext &operator=(const ASTContext &) = delete;
~ASTContext();
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 510bf89789851..d22594ae8442a 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -79,23 +79,7 @@ class UnresolvedSetImpl;
class VarTemplateDecl;
/// The top declaration context.
-class TranslationUnitDecl : public Decl,
- public DeclContext,
- public Redeclarable<TranslationUnitDecl> {
- using redeclarable_base = Redeclarable<TranslationUnitDecl>;
-
- TranslationUnitDecl *getNextRedeclarationImpl() override {
- return getNextRedeclaration();
- }
-
- TranslationUnitDecl *getPreviousDeclImpl() override {
- return getPreviousDecl();
- }
-
- TranslationUnitDecl *getMostRecentDeclImpl() override {
- return getMostRecentDecl();
- }
-
+class TranslationUnitDecl : public Decl, public DeclContext {
ASTContext &Ctx;
/// The (most recently entered) anonymous namespace for this
@@ -107,16 +91,6 @@ class TranslationUnitDecl : public Decl,
virtual void anchor();
public:
- using redecl_range = redeclarable_base::redecl_range;
- using redecl_iterator = redeclarable_base::redecl_iterator;
-
- using redeclarable_base::getMostRecentDecl;
- using redeclarable_base::getPreviousDecl;
- using redeclarable_base::isFirstDecl;
- using redeclarable_base::redecls;
- using redeclarable_base::redecls_begin;
- using redeclarable_base::redecls_end;
-
ASTContext &getASTContext() const { return Ctx; }
NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; }
diff --git a/clang/include/clang/AST/Redeclarable.h b/clang/include/clang/AST/Redeclarable.h
index 77b827c52bfb3..87252337a0f4b 100644
--- a/clang/include/clang/AST/Redeclarable.h
+++ b/clang/include/clang/AST/Redeclarable.h
@@ -193,7 +193,6 @@ class Redeclarable {
public:
friend class ASTDeclReader;
friend class ASTDeclWriter;
- friend class IncrementalParser;
Redeclarable(const ASTContext &Ctx)
: RedeclLink(LatestDeclLink(Ctx)),
diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h
index 71cf0c65e6924..d04ce52a550ef 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -697,11 +697,7 @@ enum TranslationUnitKind {
TU_Prefix,
/// The translation unit is a module.
- TU_Module,
-
- /// The translation unit is a is a complete translation unit that we might
- /// incrementally extend later.
- TU_Incremental
+ TU_Module
};
} // namespace clang
diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h
index 020cbe2db3d06..d4dd8731da184 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -14,7 +14,7 @@
#ifndef LLVM_CLANG_INTERPRETER_INTERPRETER_H
#define LLVM_CLANG_INTERPRETER_INTERPRETER_H
-#include "clang/Interpreter/PartialTranslationUnit.h"
+#include "clang/Interpreter/Transaction.h"
#include "llvm/Support/Error.h"
@@ -55,14 +55,14 @@ class Interpreter {
static llvm::Expected<std::unique_ptr<Interpreter>>
create(std::unique_ptr<CompilerInstance> CI);
const CompilerInstance *getCompilerInstance() const;
- llvm::Expected<PartialTranslationUnit &> Parse(llvm::StringRef Code);
- llvm::Error Execute(PartialTranslationUnit &T);
+ llvm::Expected<Transaction &> Parse(llvm::StringRef Code);
+ llvm::Error Execute(Transaction &T);
llvm::Error ParseAndExecute(llvm::StringRef Code) {
- auto PTU = Parse(Code);
- if (!PTU)
- return PTU.takeError();
- if (PTU->TheModule)
- return Execute(*PTU);
+ auto ErrOrTransaction = Parse(Code);
+ if (auto Err = ErrOrTransaction.takeError())
+ return Err;
+ if (ErrOrTransaction->TheModule)
+ return Execute(*ErrOrTransaction);
return llvm::Error::success();
}
};
diff --git a/clang/include/clang/Interpreter/PartialTranslationUnit.h b/clang/include/clang/Interpreter/Transaction.h
similarity index 74%
rename from clang/include/clang/Interpreter/PartialTranslationUnit.h
rename to clang/include/clang/Interpreter/Transaction.h
index bf91d559452b8..15639d4af0f98 100644
--- a/clang/include/clang/Interpreter/PartialTranslationUnit.h
+++ b/clang/include/clang/Interpreter/Transaction.h
@@ -11,10 +11,11 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_INTERPRETER_PARTIALTRANSLATIONUNIT_H
-#define LLVM_CLANG_INTERPRETER_PARTIALTRANSLATIONUNIT_H
+#ifndef LLVM_CLANG_INTERPRETER_TRANSACTION_H
+#define LLVM_CLANG_INTERPRETER_TRANSACTION_H
#include <memory>
+#include <vector>
namespace llvm {
class Module;
@@ -22,16 +23,17 @@ class Module;
namespace clang {
-class TranslationUnitDecl;
+class DeclGroupRef;
/// The class keeps track of various objects created as part of processing
/// incremental inputs.
-struct PartialTranslationUnit {
- TranslationUnitDecl *TUPart = nullptr;
+struct Transaction {
+ /// The decls created for the input.
+ std::vector<clang::DeclGroupRef> Decls;
/// The llvm IR produced for the input.
std::unique_ptr<llvm::Module> TheModule;
};
} // namespace clang
-#endif // LLVM_CLANG_INTERPRETER_PARTIALTRANSLATIONUNIT_H
+#endif // LLVM_CLANG_INTERPRETER_TRANSACTION_H
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index be345d4f5b4ea..2d6335471383c 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -264,11 +264,9 @@ class Preprocessor {
/// avoid tearing the Lexer and etc. down).
bool IncrementalProcessing = false;
-public:
/// The kind of translation unit we are processing.
- const TranslationUnitKind TUKind;
+ TranslationUnitKind TUKind;
-private:
/// The code-completion handler.
CodeCompletionHandler *CodeComplete = nullptr;
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index bb038a4479a6c..ad987dffac03a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1377,7 +1377,7 @@ class Sema final {
/// initializers for tentative definitions in C) once parsing has
/// completed. Modules and precompiled headers perform
diff erent kinds of
/// checks.
- const TranslationUnitKind TUKind;
+ TranslationUnitKind TUKind;
llvm::BumpPtrAllocator BumpAlloc;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 3d83c73ec6b79..47f30f5ff9a41 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -966,7 +966,7 @@ static bool isAddrSpaceMapManglingEnabled(const TargetInfo &TI,
ASTContext::ASTContext(LangOptions &LOpts, SourceManager &SM,
IdentifierTable &idents, SelectorTable &sels,
- Builtin::Context &builtins, TranslationUnitKind TUKind)
+ Builtin::Context &builtins)
: ConstantArrayTypes(this_()), FunctionProtoTypes(this_()),
TemplateSpecializationTypes(this_()),
DependentTemplateSpecializationTypes(this_()), AutoTypes(this_()),
@@ -978,10 +978,11 @@ ASTContext::ASTContext(LangOptions &LOpts, SourceManager &SM,
LangOpts.XRayAttrListFiles, SM)),
ProfList(new ProfileList(LangOpts.ProfileListFiles, SM)),
PrintingPolicy(LOpts), Idents(idents), Selectors(sels),
- BuiltinInfo(builtins), TUKind(TUKind), DeclarationNames(*this),
- Comments(SM), CommentCommandTraits(BumpAlloc, LOpts.CommentOpts),
+ BuiltinInfo(builtins), DeclarationNames(*this), Comments(SM),
+ CommentCommandTraits(BumpAlloc, LOpts.CommentOpts),
CompCategories(this_()), LastSDM(nullptr, 0) {
- addTranslationUnitDecl();
+ TUDecl = TranslationUnitDecl::Create(*this);
+ TraversalScope = {TUDecl};
}
ASTContext::~ASTContext() {
@@ -1195,10 +1196,9 @@ ExternCContextDecl *ASTContext::getExternCContextDecl() const {
BuiltinTemplateDecl *
ASTContext::buildBuiltinTemplateDecl(BuiltinTemplateKind BTK,
const IdentifierInfo *II) const {
- auto *BuiltinTemplate =
- BuiltinTemplateDecl::Create(*this, getTranslationUnitDecl(), II, BTK);
+ auto *BuiltinTemplate = BuiltinTemplateDecl::Create(*this, TUDecl, II, BTK);
BuiltinTemplate->setImplicit();
- getTranslationUnitDecl()->addDecl(BuiltinTemplate);
+ TUDecl->addDecl(BuiltinTemplate);
return BuiltinTemplate;
}
@@ -1485,7 +1485,7 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
// MSVC predeclares struct _GUID, and we need it to create MSGuidDecls.
if (LangOpts.MicrosoftExt || LangOpts.Borland) {
MSGuidTagDecl = buildImplicitRecord("_GUID");
- getTranslationUnitDecl()->addDecl(MSGuidTagDecl);
+ TUDecl->addDecl(MSGuidTagDecl);
}
}
@@ -6622,7 +6622,7 @@ QualType ASTContext::getCFConstantStringType() const {
QualType ASTContext::getObjCSuperType() const {
if (ObjCSuperType.isNull()) {
RecordDecl *ObjCSuperTypeDecl = buildImplicitRecord("objc_super");
- getTranslationUnitDecl()->addDecl(ObjCSuperTypeDecl);
+ TUDecl->addDecl(ObjCSuperTypeDecl);
ObjCSuperType = getTagDeclType(ObjCSuperTypeDecl);
}
return ObjCSuperType;
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 8f2ecb7bcf2a4..5dcfca45a54b6 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -102,7 +102,7 @@ bool Decl::isOutOfLine() const {
TranslationUnitDecl::TranslationUnitDecl(ASTContext &ctx)
: Decl(TranslationUnit, nullptr, SourceLocation()),
- DeclContext(TranslationUnit), redeclarable_base(ctx), Ctx(ctx) {}
+ DeclContext(TranslationUnit), Ctx(ctx) {}
//===----------------------------------------------------------------------===//
// NamedDecl Implementation
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 3467da2b549e2..80b591e2a81a2 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1219,6 +1219,7 @@ bool DeclContext::Encloses(const DeclContext *DC) const {
DeclContext *DeclContext::getPrimaryContext() {
switch (getDeclKind()) {
+ case Decl::TranslationUnit:
case Decl::ExternCContext:
case Decl::LinkageSpec:
case Decl::Export:
@@ -1230,8 +1231,6 @@ DeclContext *DeclContext::getPrimaryContext() {
// There is only one DeclContext for these entities.
return this;
- case Decl::TranslationUnit:
- return static_cast<TranslationUnitDecl *>(this)->getFirstDecl();
case Decl::Namespace:
// The original namespace is our primary context.
return static_cast<NamespaceDecl *>(this)->getOriginalNamespace();
@@ -1286,25 +1285,21 @@ DeclContext *DeclContext::getPrimaryContext() {
}
}
-template <typename T>
-void collectAllContextsImpl(T *Self, SmallVectorImpl<DeclContext *> &Contexts) {
- for (T *D = Self->getMostRecentDecl(); D; D = D->getPreviousDecl())
- Contexts.push_back(D);
-
- std::reverse(Contexts.begin(), Contexts.end());
-}
-
-void DeclContext::collectAllContexts(SmallVectorImpl<DeclContext *> &Contexts) {
+void
+DeclContext::collectAllContexts(SmallVectorImpl<DeclContext *> &Contexts){
Contexts.clear();
- Decl::Kind Kind = getDeclKind();
-
- if (Kind == Decl::TranslationUnit)
- collectAllContextsImpl(static_cast<TranslationUnitDecl *>(this), Contexts);
- else if (Kind == Decl::Namespace)
- collectAllContextsImpl(static_cast<NamespaceDecl *>(this), Contexts);
- else
+ if (getDeclKind() != Decl::Namespace) {
Contexts.push_back(this);
+ return;
+ }
+
+ auto *Self = static_cast<NamespaceDecl *>(this);
+ for (NamespaceDecl *N = Self->getMostRecentDecl(); N;
+ N = N->getPreviousDecl())
+ Contexts.push_back(N);
+
+ std::reverse(Contexts.begin(), Contexts.end());
}
std::pair<Decl *, Decl *>
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 996783aa9cf4b..4f92833e4229c 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -807,8 +807,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
if (ToLoad >= LoadASTOnly)
AST->Ctx = new ASTContext(*AST->LangOpts, AST->getSourceManager(),
PP.getIdentifierTable(), PP.getSelectorTable(),
- PP.getBuiltinInfo(),
- AST->getTranslationUnitKind());
+ PP.getBuiltinInfo());
DisableValidationForModuleKind disableValid =
DisableValidationForModuleKind::None;
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index a6e2329c8864a..2ae3be6814dec 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -551,7 +551,7 @@ void CompilerInstance::createASTContext() {
Preprocessor &PP = getPreprocessor();
auto *Context = new ASTContext(getLangOpts(), PP.getSourceManager(),
PP.getIdentifierTable(), PP.getSelectorTable(),
- PP.getBuiltinInfo(), PP.TUKind);
+ PP.getBuiltinInfo());
Context->InitBuiltinTypes(getTarget(), getAuxTarget());
setASTContext(Context);
}
diff --git a/clang/lib/Interpreter/IncrementalParser.cpp b/clang/lib/Interpreter/IncrementalParser.cpp
index 897e2cd1aaed8..84b4d779d43c5 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -12,7 +12,6 @@
#include "IncrementalParser.h"
-#include "clang/AST/DeclContextInternals.h"
#include "clang/CodeGen/BackendUtil.h"
#include "clang/CodeGen/CodeGenAction.h"
#include "clang/CodeGen/ModuleBuilder.h"
@@ -76,9 +75,6 @@ class IncrementalAction : public WrapperFrontendAction {
return Act;
}()) {}
FrontendAction *getWrapped() const { return WrappedAction.get(); }
- TranslationUnitKind getTranslationUnitKind() override {
- return TU_Incremental;
- }
void ExecuteAction() override {
CompilerInstance &CI = getCompilerInstance();
assert(CI.hasPreprocessor() && "No PP!");
@@ -134,32 +130,26 @@ IncrementalParser::IncrementalParser(std::unique_ptr<CompilerInstance> Instance,
IncrementalParser::~IncrementalParser() { Act->FinalizeAction(); }
-llvm::Expected<PartialTranslationUnit &>
-IncrementalParser::ParseOrWrapTopLevelDecl() {
+llvm::Expected<Transaction &> IncrementalParser::ParseOrWrapTopLevelDecl() {
+ DiagnosticsEngine &Diags = getCI()->getDiagnostics();
+
+ if (Diags.hasErrorOccurred())
+ llvm::report_fatal_error("Previous input had errors, "
+ "recovery not yet supported",
+ /*GenCrashDiag=*/false);
+
// Recover resources if we crash before exiting this method.
Sema &S = CI->getSema();
llvm::CrashRecoveryContextCleanupRegistrar<Sema> CleanupSema(&S);
Sema::GlobalEagerInstantiationScope GlobalInstantiations(S, /*Enabled=*/true);
Sema::LocalEagerInstantiationScope LocalInstantiations(S);
- PTUs.emplace_back(PartialTranslationUnit());
- PartialTranslationUnit &LastPTU = PTUs.back();
- // Add a new PTU.
- ASTContext &C = S.getASTContext();
- C.addTranslationUnitDecl();
- LastPTU.TUPart = C.getTranslationUnitDecl();
-
// Skip previous eof due to last incremental input.
- if (P->getCurToken().is(tok::eof)) {
+ if (P->getCurToken().is(tok::eof))
P->ConsumeToken();
- // FIXME: Clang does not call ExitScope on finalizing the regular TU, we
- // might want to do that around HandleEndOfTranslationUnit.
- P->ExitScope();
- S.CurContext = nullptr;
- // Start a new PTU.
- P->EnterScope(Scope::DeclScope);
- S.ActOnTranslationUnitScope(P->getCurScope());
- }
+
+ Transactions.emplace_back(Transaction());
+ Transaction &LastTransaction = Transactions.back();
Parser::DeclGroupPtrTy ADecl;
for (bool AtEOF = P->ParseFirstTopLevelDecl(ADecl); !AtEOF;
@@ -171,50 +161,26 @@ IncrementalParser::ParseOrWrapTopLevelDecl() {
return llvm::make_error<llvm::StringError>("Parsing failed. "
"The consumer rejected a decl",
std::error_code());
- }
-
- DiagnosticsEngine &Diags = getCI()->getDiagnostics();
- if (Diags.hasErrorOccurred()) {
- TranslationUnitDecl *MostRecentTU = C.getTranslationUnitDecl();
- TranslationUnitDecl *PreviousTU = MostRecentTU->getPreviousDecl();
- assert(PreviousTU && "Must have a TU from the ASTContext initialization!");
- TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl();
- assert(FirstTU);
- FirstTU->RedeclLink.setLatest(PreviousTU);
- C.TUDecl = PreviousTU;
- S.TUScope->setEntity(PreviousTU);
-
- // Clean up the lookup table
- if (StoredDeclsMap *Map = PreviousTU->getLookupPtr()) {
- for (auto I = Map->begin(); I != Map->end(); ++I) {
- StoredDeclsList &List = I->second;
- DeclContextLookupResult R = List.getLookupResult();
- for (NamedDecl *D : R)
- if (D->getTranslationUnitDecl() == MostRecentTU)
- List.remove(D);
- if (List.isNull())
- Map->erase(I);
- }
- }
-
- // FIXME: Do not reset the pragma handlers.
- Diags.Reset();
- return llvm::make_error<llvm::StringError>("Parsing failed.",
- std::error_code());
+ LastTransaction.Decls.push_back(ADecl.get());
}
// Process any TopLevelDecls generated by #pragma weak.
for (Decl *D : S.WeakTopLevelDecls()) {
DeclGroupRef DGR(D);
+ LastTransaction.Decls.push_back(DGR);
Consumer->HandleTopLevelDecl(DGR);
}
LocalInstantiations.perform();
GlobalInstantiations.perform();
- Consumer->HandleTranslationUnit(C);
+ Consumer->HandleTranslationUnit(S.getASTContext());
+
+ if (Diags.hasErrorOccurred())
+ return llvm::make_error<llvm::StringError>("Parsing failed.",
+ std::error_code());
- return LastPTU;
+ return LastTransaction;
}
static CodeGenerator *getCodeGen(FrontendAction *Act) {
@@ -225,8 +191,7 @@ static CodeGenerator *getCodeGen(FrontendAction *Act) {
return static_cast<CodeGenAction *>(WrappedAct)->getCodeGenerator();
}
-llvm::Expected<PartialTranslationUnit &>
-IncrementalParser::Parse(llvm::StringRef input) {
+llvm::Expected<Transaction &> IncrementalParser::Parse(llvm::StringRef input) {
Preprocessor &PP = CI->getPreprocessor();
assert(PP.isIncrementalProcessingEnabled() && "Not in incremental mode!?");
@@ -259,9 +224,9 @@ IncrementalParser::Parse(llvm::StringRef input) {
"Cannot enter source file.",
std::error_code());
- auto PTU = ParseOrWrapTopLevelDecl();
- if (!PTU)
- return PTU.takeError();
+ auto ErrOrTransaction = ParseOrWrapTopLevelDecl();
+ if (auto Err = ErrOrTransaction.takeError())
+ return std::move(Err);
if (PP.getLangOpts().DelayedTemplateParsing) {
// Microsoft-specific:
@@ -281,12 +246,12 @@ IncrementalParser::Parse(llvm::StringRef input) {
if (CodeGenerator *CG = getCodeGen(Act.get())) {
std::unique_ptr<llvm::Module> M(CG->ReleaseModule());
- CG->StartModule("incr_module_" + std::to_string(PTUs.size()),
+ CG->StartModule("incr_module_" + std::to_string(Transactions.size()),
M->getContext());
- PTU->TheModule = std::move(M);
+ ErrOrTransaction->TheModule = std::move(M);
}
- return PTU;
+ return ErrOrTransaction;
}
} // end namespace clang
diff --git a/clang/lib/Interpreter/IncrementalParser.h b/clang/lib/Interpreter/IncrementalParser.h
index aa8142cbe4939..2ebc64e5930e5 100644
--- a/clang/lib/Interpreter/IncrementalParser.h
+++ b/clang/lib/Interpreter/IncrementalParser.h
@@ -13,7 +13,7 @@
#ifndef LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H
#define LLVM_CLANG_LIB_INTERPRETER_INCREMENTALPARSER_H
-#include "clang/Interpreter/PartialTranslationUnit.h"
+#include "clang/Interpreter/Transaction.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
@@ -55,7 +55,7 @@ class IncrementalParser {
/// List containing every information about every incrementally parsed piece
/// of code.
- std::list<PartialTranslationUnit> PTUs;
+ std::list<Transaction> Transactions;
public:
IncrementalParser(std::unique_ptr<CompilerInstance> Instance,
@@ -65,12 +65,12 @@ class IncrementalParser {
const CompilerInstance *getCI() const { return CI.get(); }
/// Parses incremental input by creating an in-memory file.
- ///\returns a \c PartialTranslationUnit which holds information about the
- /// \c TranslationUnitDecl and \c llvm::Module corresponding to the input.
- llvm::Expected<PartialTranslationUnit &> Parse(llvm::StringRef Input);
+ ///\returns a \c Transaction which holds information about the \c Decls and
+ /// \c llvm::Module corresponding to the input.
+ llvm::Expected<Transaction &> Parse(llvm::StringRef Input);
private:
- llvm::Expected<PartialTranslationUnit &> ParseOrWrapTopLevelDecl();
+ llvm::Expected<Transaction &> ParseOrWrapTopLevelDecl();
};
} // end namespace clang
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 937504f34739f..768847f9f0352 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -198,12 +198,11 @@ const CompilerInstance *Interpreter::getCompilerInstance() const {
return IncrParser->getCI();
}
-llvm::Expected<PartialTranslationUnit &>
-Interpreter::Parse(llvm::StringRef Code) {
+llvm::Expected<Transaction &> Interpreter::Parse(llvm::StringRef Code) {
return IncrParser->Parse(Code);
}
-llvm::Error Interpreter::Execute(PartialTranslationUnit &T) {
+llvm::Error Interpreter::Execute(Transaction &T) {
assert(T.TheModule);
if (!IncrExecutor) {
const llvm::Triple &Triple =
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 704b631f94003..e2d46e3bf9383 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -183,7 +183,6 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
DisableTypoCorrection(false), TyposCorrected(0), AnalysisWarnings(*this),
ThreadSafetyDeclCache(nullptr), VarDataSharingAttributesStack(nullptr),
CurScope(nullptr), Ident_super(nullptr), Ident___float128(nullptr) {
- assert(pp.TUKind == TUKind);
TUScope = nullptr;
isConstantEvaluatedOverride = false;
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 98972af5957ec..80ee56a9b7df8 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -7176,11 +7176,6 @@ void ASTReader::CompleteRedeclChain(const Decl *D) {
return;
}
- if (!D->getDeclContext()) {
- assert(isa<TranslationUnitDecl>(D) && "Not a TU?");
- return;
- }
-
const DeclContext *DC = D->getDeclContext()->getRedeclContext();
// If this is a named declaration, complete it by looking it up
diff --git a/clang/tools/clang-import-test/clang-import-test.cpp b/clang/tools/clang-import-test/clang-import-test.cpp
index a5206319bbb6e..fa5d7a54f53b4 100644
--- a/clang/tools/clang-import-test/clang-import-test.cpp
+++ b/clang/tools/clang-import-test/clang-import-test.cpp
@@ -218,10 +218,9 @@ std::unique_ptr<CompilerInstance> BuildCompilerInstance() {
std::unique_ptr<ASTContext>
BuildASTContext(CompilerInstance &CI, SelectorTable &ST, Builtin::Context &BC) {
- auto &PP = CI.getPreprocessor();
auto AST = std::make_unique<ASTContext>(
CI.getLangOpts(), CI.getSourceManager(),
- PP.getIdentifierTable(), ST, BC, PP.TUKind);
+ CI.getPreprocessor().getIdentifierTable(), ST, BC);
AST->InitBuiltinTypes(CI.getTarget());
return AST;
}
diff --git a/clang/unittests/AST/ASTVectorTest.cpp b/clang/unittests/AST/ASTVectorTest.cpp
index 1c17eb9210ac3..7953acb1b4db2 100644
--- a/clang/unittests/AST/ASTVectorTest.cpp
+++ b/clang/unittests/AST/ASTVectorTest.cpp
@@ -29,7 +29,7 @@ class ASTVectorTest : public ::testing::Test {
: FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
SourceMgr(Diags, FileMgr), Idents(LangOpts, nullptr),
- Ctxt(LangOpts, SourceMgr, Idents, Sels, Builtins, TU_Complete) {}
+ Ctxt(LangOpts, SourceMgr, Idents, Sels, Builtins) {}
FileSystemOptions FileMgrOpts;
FileManager FileMgr;
diff --git a/clang/unittests/Interpreter/IncrementalProcessingTest.cpp b/clang/unittests/Interpreter/IncrementalProcessingTest.cpp
index b7ad468e14c7a..7d58d9837b8f6 100644
--- a/clang/unittests/Interpreter/IncrementalProcessingTest.cpp
+++ b/clang/unittests/Interpreter/IncrementalProcessingTest.cpp
@@ -55,23 +55,23 @@ TEST(IncrementalProcessing, EmitCXXGlobalInitFunc) {
auto CI = llvm::cantFail(IncrementalCompilerBuilder::create(ClangArgv));
auto Interp = llvm::cantFail(Interpreter::create(std::move(CI)));
- std::array<clang::PartialTranslationUnit *, 2> PTUs;
+ std::array<clang::Transaction *, 2> Transactions;
- PTUs[0] = &llvm::cantFail(Interp->Parse(TestProgram1));
- ASSERT_TRUE(PTUs[0]->TheModule);
- ASSERT_TRUE(PTUs[0]->TheModule->getFunction("funcForProg1"));
+ Transactions[0] = &llvm::cantFail(Interp->Parse(TestProgram1));
+ ASSERT_TRUE(Transactions[0]->TheModule);
+ ASSERT_TRUE(Transactions[0]->TheModule->getFunction("funcForProg1"));
- PTUs[1] = &llvm::cantFail(Interp->Parse(TestProgram2));
- ASSERT_TRUE(PTUs[1]->TheModule);
- ASSERT_TRUE(PTUs[1]->TheModule->getFunction("funcForProg2"));
+ Transactions[1] = &llvm::cantFail(Interp->Parse(TestProgram2));
+ ASSERT_TRUE(Transactions[1]->TheModule);
+ ASSERT_TRUE(Transactions[1]->TheModule->getFunction("funcForProg2"));
// First code should not end up in second module:
- ASSERT_FALSE(PTUs[1]->TheModule->getFunction("funcForProg1"));
+ ASSERT_FALSE(Transactions[1]->TheModule->getFunction("funcForProg1"));
// Make sure global inits exist and are unique:
- const Function *GlobalInit1 = getGlobalInit(PTUs[0]->TheModule.get());
+ const Function *GlobalInit1 = getGlobalInit(Transactions[0]->TheModule.get());
ASSERT_TRUE(GlobalInit1);
- const Function *GlobalInit2 = getGlobalInit(PTUs[1]->TheModule.get());
+ const Function *GlobalInit2 = getGlobalInit(Transactions[1]->TheModule.get());
ASSERT_TRUE(GlobalInit2);
ASSERT_FALSE(GlobalInit1->getName() == GlobalInit2->getName());
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp
index 6ce43748ae049..984255c0a2290 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -37,41 +37,34 @@ createInterpreter(const Args &ExtraArgs = {},
return cantFail(clang::Interpreter::create(std::move(CI)));
}
-static size_t DeclsSize(TranslationUnitDecl *PTUDecl) {
- return std::distance(PTUDecl->decls().begin(), PTUDecl->decls().end());
-}
-
TEST(InterpreterTest, Sanity) {
std::unique_ptr<Interpreter> Interp = createInterpreter();
+ Transaction &R1(cantFail(Interp->Parse("void g(); void g() {}")));
+ EXPECT_EQ(2U, R1.Decls.size());
- using PTU = PartialTranslationUnit;
-
- PTU &R1(cantFail(Interp->Parse("void g(); void g() {}")));
- EXPECT_EQ(2U, DeclsSize(R1.TUPart));
-
- PTU &R2(cantFail(Interp->Parse("int i;")));
- EXPECT_EQ(1U, DeclsSize(R2.TUPart));
+ Transaction &R2(cantFail(Interp->Parse("int i;")));
+ EXPECT_EQ(1U, R2.Decls.size());
}
-static std::string DeclToString(Decl *D) {
- return llvm::cast<NamedDecl>(D)->getQualifiedNameAsString();
+static std::string DeclToString(DeclGroupRef DGR) {
+ return llvm::cast<NamedDecl>(DGR.getSingleDecl())->getQualifiedNameAsString();
}
TEST(InterpreterTest, IncrementalInputTopLevelDecls) {
std::unique_ptr<Interpreter> Interp = createInterpreter();
- auto R1 = Interp->Parse("int var1 = 42; int f() { return var1; }");
+ auto R1OrErr = Interp->Parse("int var1 = 42; int f() { return var1; }");
// gtest doesn't expand into explicit bool conversions.
- EXPECT_TRUE(!!R1);
- auto R1DeclRange = R1->TUPart->decls();
- EXPECT_EQ(2U, DeclsSize(R1->TUPart));
- EXPECT_EQ("var1", DeclToString(*R1DeclRange.begin()));
- EXPECT_EQ("f", DeclToString(*(++R1DeclRange.begin())));
-
- auto R2 = Interp->Parse("int var2 = f();");
- EXPECT_TRUE(!!R2);
- auto R2DeclRange = R2->TUPart->decls();
- EXPECT_EQ(1U, DeclsSize(R2->TUPart));
- EXPECT_EQ("var2", DeclToString(*R2DeclRange.begin()));
+ EXPECT_TRUE(!!R1OrErr);
+ auto R1 = R1OrErr->Decls;
+ EXPECT_EQ(2U, R1.size());
+ EXPECT_EQ("var1", DeclToString(R1[0]));
+ EXPECT_EQ("f", DeclToString(R1[1]));
+
+ auto R2OrErr = Interp->Parse("int var2 = f();");
+ EXPECT_TRUE(!!R2OrErr);
+ auto R2 = R2OrErr->Decls;
+ EXPECT_EQ(1U, R2.size());
+ EXPECT_EQ("var2", DeclToString(R2[0]));
}
TEST(InterpreterTest, Errors) {
@@ -90,8 +83,9 @@ TEST(InterpreterTest, Errors) {
HasSubstr("error: unknown type name 'intentional_error'"));
EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
- auto RecoverErr = Interp->Parse("int var1 = 42;");
- EXPECT_TRUE(!!RecoverErr);
+#ifdef GTEST_HAS_DEATH_TEST
+ EXPECT_DEATH((void)Interp->Parse("int var1 = 42;"), "");
+#endif
}
// Here we test whether the user can mix declarations and statements. The
@@ -107,21 +101,21 @@ TEST(InterpreterTest, DeclsAndStatements) {
DiagnosticsOS, new DiagnosticOptions());
auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
- auto R1 = Interp->Parse(
+ auto R1OrErr = Interp->Parse(
"int var1 = 42; extern \"C\" int printf(const char*, ...);");
// gtest doesn't expand into explicit bool conversions.
- EXPECT_TRUE(!!R1);
+ EXPECT_TRUE(!!R1OrErr);
- auto *PTU1 = R1->TUPart;
- EXPECT_EQ(2U, DeclsSize(PTU1));
+ auto R1 = R1OrErr->Decls;
+ EXPECT_EQ(2U, R1.size());
// FIXME: Add support for wrapping and running statements.
- auto R2 = Interp->Parse("var1++; printf(\"var1 value %d\\n\", var1);");
- EXPECT_FALSE(!!R2);
+ auto R2OrErr = Interp->Parse("var1++; printf(\"var1 value %d\\n\", var1);");
+ EXPECT_FALSE(!!R2OrErr);
using ::testing::HasSubstr;
EXPECT_THAT(DiagnosticsOS.str(),
HasSubstr("error: unknown type name 'var1'"));
- auto Err = R2.takeError();
+ auto Err = R2OrErr.takeError();
EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
}
diff --git a/clang/unittests/Lex/PPCallbacksTest.cpp b/clang/unittests/Lex/PPCallbacksTest.cpp
index bb4098a1f98bd..f92587af8dc5e 100644
--- a/clang/unittests/Lex/PPCallbacksTest.cpp
+++ b/clang/unittests/Lex/PPCallbacksTest.cpp
@@ -323,7 +323,7 @@ class PPCallbacksTest : public ::testing::Test {
// according to LangOptions, so we init Parser to register opencl
// pragma handlers
ASTContext Context(OpenCLLangOpts, SourceMgr, PP.getIdentifierTable(),
- PP.getSelectorTable(), PP.getBuiltinInfo(), PP.TUKind);
+ PP.getSelectorTable(), PP.getBuiltinInfo());
Context.InitBuiltinTypes(*Target);
ASTConsumer Consumer;
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 137cba40e1d65..306573e06250e 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -746,7 +746,7 @@ void TypeSystemClang::CreateASTContext() {
*m_diagnostics_engine_up, *m_file_manager_up);
m_ast_up = std::make_unique<ASTContext>(
*m_language_options_up, *m_source_manager_up, *m_identifier_table_up,
- *m_selector_table_up, *m_builtins_up, TU_Complete);
+ *m_selector_table_up, *m_builtins_up);
m_diagnostic_consumer_up = std::make_unique<NullDiagnosticConsumer>();
m_ast_up->getDiagnostics().setClient(m_diagnostic_consumer_up.get(), false);
More information about the cfe-commits
mailing list