@@ -339,19 +339,22 @@ class DependentComponentSplitterStep final : public SolverStep {
339
339
class ComponentStep final : public SolverStep {
340
340
class Scope {
341
341
ConstraintSystem &CS;
342
- ConstraintSystem::SolverScope * SolverScope;
342
+ std::optional< ConstraintSystem::SolverScope> SolverScope;
343
343
344
344
SetVector<TypeVariableType *> TypeVars;
345
345
unsigned prevPartialSolutionFixes = 0 ;
346
346
347
347
// The component this scope is associated with.
348
348
ComponentStep &Component;
349
349
350
+ Scope (const Scope &) = delete ;
351
+ Scope &operator =(const Scope &) = delete ;
352
+
350
353
public:
351
- Scope (ComponentStep &component);
354
+ explicit Scope (ComponentStep &component);
352
355
353
356
~Scope () {
354
- delete SolverScope; // rewind back all of the changes.
357
+ SolverScope. reset () ; // rewind back all of the changes.
355
358
CS.solverState ->numPartialSolutionFixes = prevPartialSolutionFixes;
356
359
357
360
// return all of the saved type variables back to the system.
@@ -383,7 +386,7 @@ class ComponentStep final : public SolverStep {
383
386
384
387
// / If this step depends on other smaller steps to be solved first
385
388
// / we need to keep active scope until all of the work is done.
386
- std::unique_ptr <Scope> ComponentScope = nullptr ;
389
+ std::optional <Scope> ComponentScope;
387
390
388
391
// / Type variables and constraints "in scope" of this step.
389
392
TinyPtrVector<TypeVariableType *> TypeVars;
@@ -474,7 +477,7 @@ class ComponentStep final : public SolverStep {
474
477
log << " (solving component #" << Index << ' \n ' ;
475
478
}
476
479
477
- ComponentScope = std::make_unique<Scope> (*this );
480
+ ComponentScope. emplace (*this );
478
481
479
482
if (CS.isDebugMode ()) {
480
483
auto &log = getDebugLogger ();
@@ -834,7 +837,7 @@ class ConjunctionStep : public BindingStep<ConjunctionElementProducer> {
834
837
// / this scope would be initialized once all of the
835
838
// / elements are successfully solved to continue solving
836
839
// / along the current path as-if there was no conjunction.
837
- std::unique_ptr <Scope> IsolationScope = nullptr ;
840
+ std::optional <Scope> IsolationScope;
838
841
839
842
public:
840
843
SolverSnapshot (ConstraintSystem &cs, Constraint *conjunction)
@@ -862,7 +865,7 @@ class ConjunctionStep : public BindingStep<ConjunctionElementProducer> {
862
865
863
866
// Establish isolation scope so that conjunction solution
864
867
// and follow-up steps could be rolled back.
865
- IsolationScope = std::make_unique<Scope> (CS);
868
+ IsolationScope. emplace (CS);
866
869
867
870
// Apply solution inferred for the conjunction.
868
871
replaySolution (solution);
0 commit comments