From: Andrew Reynolds Date: Mon, 8 Feb 2021 15:17:31 +0000 (-0600) Subject: Avoid spurious traversal of terms during preregistration (#5860) X-Git-Tag: cvc5-1.0.0~2312 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0745ca0490e04c4a5b10a50bd91193e41c45c415;p=cvc5.git Avoid spurious traversal of terms during preregistration (#5860) This simplifies a few places in the code which unecessarily traverse terms during preregistration (which already traverses terms). --- diff --git a/src/theory/arith/nl/nonlinear_extension.cpp b/src/theory/arith/nl/nonlinear_extension.cpp index 49385294c..57b2803d9 100644 --- a/src/theory/arith/nl/nonlinear_extension.cpp +++ b/src/theory/arith/nl/nonlinear_extension.cpp @@ -82,7 +82,7 @@ void NonlinearExtension::preRegisterTerm(TNode n) { // register terms with extended theory, to find extended terms that can be // eliminated by context-depedendent simplification. - d_extTheory.registerTermRec(n); + d_extTheory.registerTerm(n); } void NonlinearExtension::sendLemmas(const std::vector& out) diff --git a/src/theory/ext_theory.cpp b/src/theory/ext_theory.cpp index 7a6d5c9ab..7b4936a53 100644 --- a/src/theory/ext_theory.cpp +++ b/src/theory/ext_theory.cpp @@ -438,28 +438,6 @@ void ExtTheory::registerTerm(Node n) } } -void ExtTheory::registerTermRec(Node n) -{ - std::unordered_set visited; - std::vector visit; - TNode cur; - visit.push_back(n); - do - { - cur = visit.back(); - visit.pop_back(); - if (visited.find(cur) == visited.end()) - { - visited.insert(cur); - registerTerm(cur); - for (const Node& cc : cur) - { - visit.push_back(cc); - } - } - } while (!visit.empty()); -} - // mark reduced void ExtTheory::markReduced(Node n, bool satDep) { diff --git a/src/theory/ext_theory.h b/src/theory/ext_theory.h index 1577c8b6f..efe235432 100644 --- a/src/theory/ext_theory.h +++ b/src/theory/ext_theory.h @@ -144,8 +144,6 @@ class ExtTheory * that is, if addFunctionKind( n.getKind() ) was called. */ void registerTerm(Node n); - /** register all subterms of n with this class */ - void registerTermRec(Node n); /** set n as reduced/inactive * * If satDep = false, then n remains inactive in the duration of this diff --git a/src/theory/strings/extf_solver.cpp b/src/theory/strings/extf_solver.cpp index 352da5ac8..8db53c53e 100644 --- a/src/theory/strings/extf_solver.cpp +++ b/src/theory/strings/extf_solver.cpp @@ -73,8 +73,6 @@ ExtfSolver::ExtfSolver(SolverState& s, ExtfSolver::~ExtfSolver() {} -void ExtfSolver::addSharedTerm(TNode n) { d_extt.registerTermRec(n); } - bool ExtfSolver::doReduction(int effort, Node n) { Assert(d_extfInfoTmp.find(n) != d_extfInfoTmp.end()); diff --git a/src/theory/strings/extf_solver.h b/src/theory/strings/extf_solver.h index df0a7ccb5..7d7ecdbe4 100644 --- a/src/theory/strings/extf_solver.h +++ b/src/theory/strings/extf_solver.h @@ -92,12 +92,6 @@ class ExtfSolver ExtTheory& et, SequencesStatistics& statistics); ~ExtfSolver(); - - /** - * Called when a shared term is added to theory of strings, this registers - * n with the extended theory utility for context-depdendent simplification. - */ - void addSharedTerm(TNode n); /** check extended functions evaluation * * This applies "context-dependent simplification" for all active extended diff --git a/src/theory/strings/theory_strings.cpp b/src/theory/strings/theory_strings.cpp index eec59685a..f25f9e29c 100644 --- a/src/theory/strings/theory_strings.cpp +++ b/src/theory/strings/theory_strings.cpp @@ -164,17 +164,6 @@ bool TheoryStrings::areCareDisequal( TNode x, TNode y ) { return false; } -void TheoryStrings::notifySharedTerm(TNode t) -{ - Debug("strings") << "TheoryStrings::notifySharedTerm(): " << t << " " - << t.getType().isBoolean() << endl; - if (options::stringExp()) - { - d_esolver.addSharedTerm(t); - } - Debug("strings") << "TheoryStrings::notifySharedTerm() finished" << std::endl; -} - bool TheoryStrings::propagateLit(TNode literal) { Debug("strings-propagate") @@ -566,6 +555,10 @@ void TheoryStrings::preRegisterTerm(TNode n) Trace("strings-preregister") << "TheoryStrings::preRegisterTerm: " << n << std::endl; d_termReg.preRegisterTerm(n); + // Register the term with the extended theory. Notice we do not recurse on + // this term here since preRegisterTerm is already called recursively on all + // subterms in preregistered literals. + d_extTheory.registerTerm(n); } TrustNode TheoryStrings::expandDefinition(Node node) @@ -634,10 +627,6 @@ void TheoryStrings::notifyFact(TNode atom, return; } Trace("strings-pending-debug") << " Now collect terms" << std::endl; - // Collect extended function terms in the atom. Notice that we must register - // all extended functions occurring in assertions and shared terms. We - // make a similar call to registerTermRec in TheoryStrings::addSharedTerm. - d_extTheory.registerTermRec(atom); Trace("strings-pending-debug") << " Finished collect terms" << std::endl; } diff --git a/src/theory/strings/theory_strings.h b/src/theory/strings/theory_strings.h index ebded2aec..c150fb3df 100644 --- a/src/theory/strings/theory_strings.h +++ b/src/theory/strings/theory_strings.h @@ -91,8 +91,6 @@ class TheoryStrings : public Theory { void presolve() override; /** shutdown */ void shutdown() override {} - /** add shared term */ - void notifySharedTerm(TNode n) override; /** preregister term */ void preRegisterTerm(TNode n) override; /** Expand definition */