File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -2141,6 +2141,11 @@ class ConstraintSystem {
2141
2141
// / explored.
2142
2142
size_t MaxMemory = 0 ;
2143
2143
2144
+ // / Flag to indicate to the solver that the system is in invalid
2145
+ // / state and it shouldn't proceed but instead produce a fallback
2146
+ // / diagnostic.
2147
+ bool InvalidState = false ;
2148
+
2144
2149
// / Cached member lookups.
2145
2150
llvm::DenseMap<std::pair<Type, DeclNameRef>, Optional<LookupResult>>
2146
2151
MemberLookups;
@@ -2640,6 +2645,11 @@ class ConstraintSystem {
2640
2645
Phase = newPhase;
2641
2646
}
2642
2647
2648
+ // / Check whether constraint system is in valid state e.g.
2649
+ // / has left-over active/inactive constraints which should
2650
+ // / have been simplified.
2651
+ bool inInvalidState () const { return InvalidState; }
2652
+
2643
2653
// / Cache the types of the given expression and all subexpressions.
2644
2654
void cacheExprTypes (Expr *expr) {
2645
2655
bool excludeRoot = false ;
Original file line number Diff line number Diff line change @@ -1384,6 +1384,13 @@ void ConstraintSystem::solveImpl(SmallVectorImpl<Solution> &solutions) {
1384
1384
if (failedConstraint)
1385
1385
return ;
1386
1386
1387
+ // Attempt to solve a constraint system already in an invalid
1388
+ // state should be immediately aborted.
1389
+ if (inInvalidState ()) {
1390
+ solutions.clear ();
1391
+ return ;
1392
+ }
1393
+
1387
1394
// Allocate new solver scope, so constraint system
1388
1395
// could be restored to its original state afterwards.
1389
1396
// Otherwise there is a risk that some of the constraints
@@ -1426,6 +1433,14 @@ void ConstraintSystem::solveImpl(SmallVectorImpl<Solution> &solutions) {
1426
1433
// or error, which means that current path is inconsistent.
1427
1434
{
1428
1435
auto result = advance (step.get (), prevFailed);
1436
+
1437
+ // If execution of this step let constraint system in an
1438
+ // invalid state, let's drop all of the solutions and abort.
1439
+ if (inInvalidState ()) {
1440
+ solutions.clear ();
1441
+ return ;
1442
+ }
1443
+
1429
1444
switch (result.getKind ()) {
1430
1445
// It was impossible to solve this step, let's note that
1431
1446
// for followup steps, to propogate the error.
Original file line number Diff line number Diff line change @@ -384,6 +384,7 @@ StepResult ComponentStep::take(bool prevFailed) {
384
384
getDebugLogger () << " )\n " ;
385
385
}
386
386
387
+ CS.InvalidState = true ;
387
388
return finalize (/* isSuccess=*/ false );
388
389
#endif
389
390
}
@@ -400,6 +401,7 @@ StepResult ComponentStep::take(bool prevFailed) {
400
401
getDebugLogger () << " )\n " ;
401
402
}
402
403
404
+ CS.InvalidState = true ;
403
405
return finalize (/* isSuccess=*/ false );
404
406
#endif
405
407
}
You can’t perform that action at this time.
0 commit comments