From 97c5bafb2fc658d2a3dab5239fafd294cd300515 Mon Sep 17 00:00:00 2001 From: Axel Naumann Date: Sat, 25 Jun 2016 00:14:00 +0200 Subject: [PATCH] Merge transaction unlinking into deregisterTransaction; pass nullptr if Transaction gets unloaded. --- lib/Interpreter/IncrementalParser.cpp | 21 ++++++++++++++++----- lib/Interpreter/IncrementalParser.h | 2 +- lib/Interpreter/Interpreter.cpp | 8 +++++--- lib/Interpreter/TransactionUnloader.cpp | 8 -------- lib/Interpreter/TransactionUnloader.h | 1 - 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/Interpreter/IncrementalParser.cpp b/lib/Interpreter/IncrementalParser.cpp index 9aea2c82..2eab886c 100644 --- a/lib/Interpreter/IncrementalParser.cpp +++ b/lib/Interpreter/IncrementalParser.cpp @@ -352,7 +352,7 @@ namespace cling { return ParseResultTransaction(T, ParseResult); } - void IncrementalParser::commitTransaction(ParseResultTransaction PRT) { + void IncrementalParser::commitTransaction(ParseResultTransaction& PRT) { Transaction* T = PRT.getPointer(); if (!T) { if (PRT.getInt() != kSuccess) { @@ -392,6 +392,8 @@ namespace cling { Diags.Reset(/*soft=*/true); Diags.getClient()->clear(); + PRT.setPointer(nullptr); + PRT.setInt(kFailed); m_Interpreter->unload(*T); if (MustStartNewModule) { @@ -418,8 +420,10 @@ namespace cling { for (Transaction::const_nested_iterator I = T->nested_begin(), E = T->nested_end(); I != E; ++I) - if ((*I)->getState() != Transaction::kCommitted) - commitTransaction(ParseResultTransaction(*I, PR)); + if ((*I)->getState() != Transaction::kCommitted) { + ParseResultTransaction PRT(*I, PR); + commitTransaction(PRT); + } } // If there was an error coming from the transformers. @@ -515,6 +519,7 @@ namespace cling { // trigger emission of weak symbols by providing use. ParseResultTransaction PRT = endTransaction(deserT); commitTransaction(PRT); + deserT = PRT.getPointer(); // This llvm::Module is done; finalize it and pass it to the execution // engine. @@ -537,7 +542,9 @@ namespace cling { // Reset the module builder to clean up global initializers, c'tors, d'tors getCodeGenerator()->HandleTranslationUnit(Context); FileName = OldName; - commitTransaction(endTransaction(deserT)); + auto PRT = endTransaction(deserT); + commitTransaction(PRT); + deserT = PRT.getPointer(); std::unique_ptr M(getCodeGenerator()->ReleaseModule()); @@ -576,13 +583,17 @@ namespace cling { } void IncrementalParser::deregisterTransaction(Transaction& T) { - if (!T.getParent()) { + if (Transaction* Parent = T.getParent()) { + Parent->removeNestedTransaction(&T); + T.setParent(0); + } else { // Remove from the queue assert(&T == m_Transactions.back() && "Out of order transaction removal"); m_Transactions.pop_back(); if (!m_Transactions.empty()) m_Transactions.back()->setNext(0); } + m_TransactionPool->releaseTransaction(&T); } diff --git a/lib/Interpreter/IncrementalParser.h b/lib/Interpreter/IncrementalParser.h index d597b764..52c3a626 100644 --- a/lib/Interpreter/IncrementalParser.h +++ b/lib/Interpreter/IncrementalParser.h @@ -130,7 +130,7 @@ namespace cling { ///\param[in] PRT - the transaction (ParseResultTransaction, really) to be /// committed /// - void commitTransaction(ParseResultTransaction PRT); + void commitTransaction(ParseResultTransaction& PRT); ///\brief Runs the consumers (e.g. CodeGen) on a non-parsed transaction. /// diff --git a/lib/Interpreter/Interpreter.cpp b/lib/Interpreter/Interpreter.cpp index 0a0e0b75..eac68de3 100644 --- a/lib/Interpreter/Interpreter.cpp +++ b/lib/Interpreter/Interpreter.cpp @@ -693,10 +693,12 @@ namespace cling { m_IncrParser->addTransaction(T); m_IncrParser->markWholeTransactionAsUsed(T); T->setState(Transaction::kCollecting); - m_IncrParser->commitTransaction(m_IncrParser->endTransaction(T)); + auto PRT = m_IncrParser->endTransaction(T); + m_IncrParser->commitTransaction(PRT); - if (executeTransaction(*T)) - return Interpreter::kSuccess; + if ((T = PRT.getPointer())) + if (executeTransaction(*T)) + return Interpreter::kSuccess; return Interpreter::kFailure; } diff --git a/lib/Interpreter/TransactionUnloader.cpp b/lib/Interpreter/TransactionUnloader.cpp index 401e836b..4f0cf62f 100644 --- a/lib/Interpreter/TransactionUnloader.cpp +++ b/lib/Interpreter/TransactionUnloader.cpp @@ -1228,13 +1228,6 @@ namespace cling { } - void TransactionUnloader::unlinkTransactionFromParent(Transaction* T) { - if (Transaction* Parent = T->getParent()) { - Parent->removeNestedTransaction(T); - T->setParent(0); - } - } - bool TransactionUnloader::unloadDeclarations(Transaction* T, clang::DeclUnloader& DeclU) { bool Successful = true; @@ -1311,7 +1304,6 @@ namespace cling { bool TransactionUnloader::RevertTransaction(Transaction* T) { clang::DeclUnloader DeclU(m_Sema, m_CodeGen, T); - unlinkTransactionFromParent(T); bool Successful = unloadDeclarations(T, DeclU); Successful = unloadFromPreprocessor(T, DeclU) && Successful; Successful = unloadDeserializedDeclarations(T, DeclU) && Successful; diff --git a/lib/Interpreter/TransactionUnloader.h b/lib/Interpreter/TransactionUnloader.h index df3e959d..903e03e0 100644 --- a/lib/Interpreter/TransactionUnloader.h +++ b/lib/Interpreter/TransactionUnloader.h @@ -31,7 +31,6 @@ namespace cling { clang::CodeGenerator* m_CodeGen; cling::IncrementalExecutor* m_Exe; - void unlinkTransactionFromParent(Transaction* T); bool unloadDeclarations(Transaction* T, clang::DeclUnloader& DeclU); bool unloadDeserializedDeclarations(Transaction* T, clang::DeclUnloader& DeclU);