2323#include < tsolvers/RDLTHandler.h>
2424#include < unsatcores/UnsatCoreBuilder.h>
2525
26+ #include < type_traits>
27+
2628namespace opensmt {
2729
2830MainSolver::MainSolver (Logic & logic, SMTConfig & conf, std::string name)
@@ -60,6 +62,7 @@ void MainSolver::initialize() {
6062 frames.push ();
6163 frameTerms.push (logic.getTerm_true ());
6264 preprocessor.initialize ();
65+ preprocessedAssertionsCountPerFrame.push_back (0 );
6366 smt_solver->initialize ();
6467 pair<CRef, CRef> iorefs{CRef_Undef, CRef_Undef};
6568 smt_solver->addOriginalSMTClause ({term_mapper->getOrCreateLit (logic.getTerm_true ())}, iorefs);
@@ -74,6 +77,7 @@ void MainSolver::push() {
7477 frames.push ();
7578 preprocessor.push ();
7679 frameTerms.push (newFrameTerm (frames.last ().getId ()));
80+ preprocessedAssertionsCountPerFrame.push_back (0 );
7781 termNames.pushScope ();
7882 if (alreadyUnsat) { rememberLastFrameUnsat (); }
7983}
@@ -92,7 +96,9 @@ bool MainSolver::pop() {
9296 }
9397 frames.pop ();
9498 preprocessor.pop ();
99+ preprocessedAssertionsCountPerFrame.pop_back ();
95100 termNames.popScope ();
101+ // goes back to frames.frameCount()-1 only if a formula is added via addAssertion
96102 firstNotPreprocessedFrame = std::min (firstNotPreprocessedFrame, frames.frameCount ());
97103 if (not isLastFrameUnsat ()) { getSMTSolver ().restoreOK (); }
98104 return true ;
@@ -158,9 +164,14 @@ sstat MainSolver::simplifyFormulas() {
158164bool MainSolver::tryPreprocessFormulasOfFrame (std::size_t i) {
159165 auto & frame = frames[i];
160166 FrameId const frameId = frame.getId ();
161- PreprocessingContext context{.frameCount = i, .perPartition = trackPartitions ()};
167+ auto & preprocessedFrameAssertionsCount = preprocessedAssertionsCountPerFrame[i];
168+ assert (frame.formulas .size () == 0 or std::size_t (frame.formulas .size ()) > preprocessedFrameAssertionsCount);
169+ PreprocessingContext context{.frameCount = i,
170+ .preprocessedFrameAssertionsCount = preprocessedFrameAssertionsCount,
171+ .perPartition = trackPartitions ()};
162172 preprocessor.prepareForProcessingFrame (i);
163173 firstNotPreprocessedFrame = i + 1 ;
174+ preprocessedFrameAssertionsCount = frame.formulas .size ();
164175
165176 assert (status != s_False);
166177
@@ -185,6 +196,7 @@ PTRef MainSolver::preprocessFormulasDefault(vec<PTRef> const & frameFormulas, Pr
185196
186197 if (frameFormulas.size () == 0 ) { return logic.getTerm_true (); }
187198
199+ // Include even already preprocessed formulas which can still benefit from the new ones
188200 PTRef frameFormula = logic.mkAnd (frameFormulas);
189201 return preprocessFormula (frameFormula, context);
190202}
@@ -193,16 +205,21 @@ vec<PTRef> MainSolver::preprocessFormulasPerPartition(vec<PTRef> const & frameFo
193205 PreprocessingContext const & context) {
194206 assert (context.perPartition );
195207
196- if (frameFormulas.size () == 0 ) { return {}; }
208+ std::size_t const frameFormulasCount = frameFormulas.size ();
209+ static_assert (std::is_unsigned_v<decltype (context.preprocessedFrameAssertionsCount )>);
210+ assert (context.preprocessedFrameAssertionsCount <= frameFormulasCount);
211+ std::size_t const formulasCountToProcess = frameFormulasCount - context.preprocessedFrameAssertionsCount ;
212+ if (formulasCountToProcess == 0 ) { return {}; }
197213
198214 vec<PTRef> processedFormulas;
199- for (PTRef fla : frameFormulas) {
215+ for (std::size_t i = context.preprocessedFrameAssertionsCount ; i < frameFormulasCount; ++i) {
216+ PTRef fla = frameFormulas[i];
200217 PTRef processed = preprocessFormulaBeforeFinalTheoryPreprocessing (fla, context);
201218 processedFormulas.push (processed);
202219 }
203220
204- assert (processedFormulas.size () == frameFormulas. size () );
205- assert (processedFormulas.size () > 0 );
221+ assert (std::size_t ( processedFormulas.size ()) == formulasCountToProcess );
222+ assert (std::size_t ( processedFormulas.size () ) > 0 );
206223 if (std::all_of (processedFormulas.begin (), processedFormulas.end (),
207224 [&](PTRef fla) { return fla == logic.getTerm_true (); })) {
208225 return {};
0 commit comments