@@ -422,6 +422,11 @@ ConstraintSystem::SolverState::~SolverState() {
422
422
" Expected constraint system to have this solver state!" );
423
423
CS.solverState = nullptr ;
424
424
425
+ // If constraint system ended up being in an invalid state
426
+ // let's just drop the state without attempting to rollback.
427
+ if (CS.inInvalidState ())
428
+ return ;
429
+
425
430
// Make sure that all of the retired constraints have been returned
426
431
// to constraint system.
427
432
assert (!hasRetiredConstraints ());
@@ -513,6 +518,10 @@ ConstraintSystem::SolverScope::SolverScope(ConstraintSystem &cs)
513
518
}
514
519
515
520
ConstraintSystem::SolverScope::~SolverScope () {
521
+ // Don't attempt to rollback from an incorrect state.
522
+ if (cs.inInvalidState ())
523
+ return ;
524
+
516
525
// Erase the end of various lists.
517
526
while (cs.TypeVariables .size () > numTypeVariables)
518
527
cs.TypeVariables .pop_back ();
@@ -1384,6 +1393,13 @@ void ConstraintSystem::solveImpl(SmallVectorImpl<Solution> &solutions) {
1384
1393
if (failedConstraint)
1385
1394
return ;
1386
1395
1396
+ // Attempt to solve a constraint system already in an invalid
1397
+ // state should be immediately aborted.
1398
+ if (inInvalidState ()) {
1399
+ solutions.clear ();
1400
+ return ;
1401
+ }
1402
+
1387
1403
// Allocate new solver scope, so constraint system
1388
1404
// could be restored to its original state afterwards.
1389
1405
// Otherwise there is a risk that some of the constraints
@@ -1426,6 +1442,14 @@ void ConstraintSystem::solveImpl(SmallVectorImpl<Solution> &solutions) {
1426
1442
// or error, which means that current path is inconsistent.
1427
1443
{
1428
1444
auto result = advance (step.get (), prevFailed);
1445
+
1446
+ // If execution of this step let constraint system in an
1447
+ // invalid state, let's drop all of the solutions and abort.
1448
+ if (inInvalidState ()) {
1449
+ solutions.clear ();
1450
+ return ;
1451
+ }
1452
+
1429
1453
switch (result.getKind ()) {
1430
1454
// It was impossible to solve this step, let's note that
1431
1455
// for followup steps, to propogate the error.
0 commit comments