@@ -200,28 +200,6 @@ enum class TrailingClosureMatching {
200
200
Backward,
201
201
};
202
202
203
- // / A handle that holds the saved state of a type variable, which
204
- // / can be restored.
205
- class SavedTypeVariableBinding {
206
- // / The type variable that we saved the state of.
207
- TypeVariableType *TypeVar;
208
-
209
- // / The saved type variable options.
210
- unsigned Options;
211
-
212
- // / The parent or fixed type.
213
- llvm::PointerUnion<TypeVariableType *, TypeBase *> ParentOrFixed;
214
-
215
- public:
216
- explicit SavedTypeVariableBinding (TypeVariableType *typeVar);
217
-
218
- // / Restore the state of the type variable to the saved state.
219
- void restore ();
220
- };
221
-
222
- // / A set of saved type variable bindings.
223
- using SavedTypeVariableBindings = SmallVector<SavedTypeVariableBinding, 16 >;
224
-
225
203
class ConstraintLocator ;
226
204
227
205
// / Describes a conversion restriction or a fix.
@@ -369,7 +347,7 @@ class TypeVariableType::Implementation {
369
347
// / constraint graph.
370
348
unsigned GraphIndex;
371
349
372
- friend class constraints ::SavedTypeVariableBinding ;
350
+ friend class constraints ::SolverTrail ;
373
351
374
352
public:
375
353
// / Retrieve the type variable associated with this implementation.
@@ -457,8 +435,9 @@ class TypeVariableType::Implementation {
457
435
}
458
436
459
437
// / Record the current type-variable binding.
460
- void recordBinding (constraints::SavedTypeVariableBindings &record) {
461
- record.push_back (constraints::SavedTypeVariableBinding (getTypeVariable ()));
438
+ void recordBinding (constraints::SolverTrail &trail) {
439
+ trail.recordChange (constraints::SolverTrail::Change::updatedTypeVariable (
440
+ getTypeVariable (), ParentOrFixed, getRawOptions ()));
462
441
}
463
442
464
443
// / Retrieve the locator describing where this type variable was
@@ -525,11 +504,11 @@ class TypeVariableType::Implementation {
525
504
// / Retrieve the representative of the equivalence class to which this
526
505
// / type variable belongs.
527
506
// /
528
- // / \param record The record of changes made by retrieving the representative,
507
+ // / \param trail The record of changes made by retrieving the representative,
529
508
// / which can happen due to path compression. If null, path compression is
530
509
// / not performed.
531
510
TypeVariableType *
532
- getRepresentative (constraints::SavedTypeVariableBindings *record ) {
511
+ getRepresentative (constraints::SolverTrail *trail ) {
533
512
// Find the representative type variable.
534
513
auto result = getTypeVariable ();
535
514
Implementation *impl = this ;
@@ -543,7 +522,7 @@ class TypeVariableType::Implementation {
543
522
impl = &nextTV->getImpl ();
544
523
}
545
524
546
- if (impl == this || !record )
525
+ if (impl == this || !trail )
547
526
return result;
548
527
549
528
// Perform path compression.
@@ -555,7 +534,7 @@ class TypeVariableType::Implementation {
555
534
break ;
556
535
557
536
// Record the state change.
558
- impl->recordBinding (*record );
537
+ impl->recordBinding (*trail );
559
538
560
539
impl->ParentOrFixed = result;
561
540
impl = &nextTV->getImpl ();
@@ -569,36 +548,36 @@ class TypeVariableType::Implementation {
569
548
// /
570
549
// / \param other The type variable to merge with.
571
550
// /
572
- // / \param record The record of state changes.
551
+ // / \param trail The record of state changes.
573
552
void mergeEquivalenceClasses (TypeVariableType *other,
574
- constraints::SavedTypeVariableBindings *record ) {
553
+ constraints::SolverTrail *trail ) {
575
554
// Merge the equivalence classes corresponding to these two type
576
555
// variables. Always merge 'up' the constraint stack, because it is simpler.
577
556
if (getID () > other->getImpl ().getID ()) {
578
- other->getImpl ().mergeEquivalenceClasses (getTypeVariable (), record );
557
+ other->getImpl ().mergeEquivalenceClasses (getTypeVariable (), trail );
579
558
return ;
580
559
}
581
560
582
- auto otherRep = other->getImpl ().getRepresentative (record );
583
- if (record )
584
- otherRep->getImpl ().recordBinding (*record );
561
+ auto otherRep = other->getImpl ().getRepresentative (trail );
562
+ if (trail )
563
+ otherRep->getImpl ().recordBinding (*trail );
585
564
otherRep->getImpl ().ParentOrFixed = getTypeVariable ();
586
565
587
566
if (canBindToLValue () && !otherRep->getImpl ().canBindToLValue ()) {
588
- if (record )
589
- recordBinding (*record );
567
+ if (trail )
568
+ recordBinding (*trail );
590
569
getTypeVariable ()->Bits .TypeVariableType .Options &= ~TVO_CanBindToLValue;
591
570
}
592
571
593
572
if (canBindToInOut () && !otherRep->getImpl ().canBindToInOut ()) {
594
- if (record )
595
- recordBinding (*record );
573
+ if (trail )
574
+ recordBinding (*trail );
596
575
getTypeVariable ()->Bits .TypeVariableType .Options &= ~TVO_CanBindToInOut;
597
576
}
598
577
599
578
if (canBindToNoEscape () && !otherRep->getImpl ().canBindToNoEscape ()) {
600
- if (record )
601
- recordBinding (*record );
579
+ if (trail )
580
+ recordBinding (*trail );
602
581
getTypeVariable ()->Bits .TypeVariableType .Options &= ~TVO_CanBindToNoEscape;
603
582
}
604
583
}
@@ -609,12 +588,12 @@ class TypeVariableType::Implementation {
609
588
// / \returns the fixed type associated with this type variable, or a null
610
589
// / type if there is no fixed type.
611
590
// /
612
- // / \param record The record of changes made by retrieving the representative,
591
+ // / \param trail The record of changes made by retrieving the representative,
613
592
// / which can happen due to path compression. If null, path compression is
614
593
// / not performed.
615
- Type getFixedType (constraints::SavedTypeVariableBindings *record ) {
594
+ Type getFixedType (constraints::SolverTrail *trail ) {
616
595
// Find the representative type variable.
617
- auto rep = getRepresentative (record );
596
+ auto rep = getRepresentative (trail );
618
597
Implementation &repImpl = rep->getImpl ();
619
598
620
599
// Return the bound type if there is one, otherwise, null.
@@ -623,20 +602,21 @@ class TypeVariableType::Implementation {
623
602
624
603
// / Assign a fixed type to this equivalence class.
625
604
void assignFixedType (Type type,
626
- constraints::SavedTypeVariableBindings *record) {
627
- assert ((!getFixedType (0 ) || getFixedType (0 )->isEqual (type)) &&
605
+ constraints::SolverTrail *trail) {
606
+ assert ((!getFixedType (nullptr ) ||
607
+ getFixedType (nullptr )->isEqual (type)) &&
628
608
" Already has a fixed type!" );
629
- auto rep = getRepresentative (record );
630
- if (record )
631
- rep->getImpl ().recordBinding (*record );
609
+ auto rep = getRepresentative (trail );
610
+ if (trail )
611
+ rep->getImpl ().recordBinding (*trail );
632
612
rep->getImpl ().ParentOrFixed = type.getPointer ();
633
613
}
634
614
635
- void setCanBindToLValue (constraints::SavedTypeVariableBindings *record ,
615
+ void setCanBindToLValue (constraints::SolverTrail *trail ,
636
616
bool enabled) {
637
- auto &impl = getRepresentative (record )->getImpl ();
638
- if (record )
639
- impl.recordBinding (*record );
617
+ auto &impl = getRepresentative (trail )->getImpl ();
618
+ if (trail )
619
+ impl.recordBinding (*trail );
640
620
641
621
if (enabled)
642
622
impl.getTypeVariable ()->Bits .TypeVariableType .Options |=
@@ -646,11 +626,11 @@ class TypeVariableType::Implementation {
646
626
~TVO_CanBindToLValue;
647
627
}
648
628
649
- void setCanBindToNoEscape (constraints::SavedTypeVariableBindings *record ,
629
+ void setCanBindToNoEscape (constraints::SolverTrail *trail ,
650
630
bool enabled) {
651
- auto &impl = getRepresentative (record )->getImpl ();
652
- if (record )
653
- impl.recordBinding (*record );
631
+ auto &impl = getRepresentative (trail )->getImpl ();
632
+ if (trail )
633
+ impl.recordBinding (*trail );
654
634
655
635
if (enabled)
656
636
impl.getTypeVariable ()->Bits .TypeVariableType .Options |=
@@ -660,10 +640,10 @@ class TypeVariableType::Implementation {
660
640
~TVO_CanBindToNoEscape;
661
641
}
662
642
663
- void enableCanBindToHole (constraints::SavedTypeVariableBindings *record ) {
664
- auto &impl = getRepresentative (record )->getImpl ();
665
- if (record )
666
- impl.recordBinding (*record );
643
+ void enableCanBindToHole (constraints::SolverTrail *trail ) {
644
+ auto &impl = getRepresentative (trail )->getImpl ();
645
+ if (trail )
646
+ impl.recordBinding (*trail );
667
647
668
648
impl.getTypeVariable ()->Bits .TypeVariableType .Options |= TVO_CanBindToHole;
669
649
}
@@ -2528,10 +2508,6 @@ class ConstraintSystem {
2528
2508
// / Whether to record failures or not.
2529
2509
bool recordFixes = false ;
2530
2510
2531
- // / The set of type variable bindings that have changed while
2532
- // / processing this constraint system.
2533
- SavedTypeVariableBindings savedBindings;
2534
-
2535
2511
// / A log of changes to the constraint system, representing the
2536
2512
// / current path being explored in the solution space.
2537
2513
SolverTrail Trail;
@@ -3072,18 +3048,11 @@ class ConstraintSystem {
3072
3048
}
3073
3049
}
3074
3050
3075
- // / Restore the type variable bindings to what they were before
3076
- // / we attempted to solve this constraint system.
3077
- // /
3078
- // / \param numBindings The number of bindings to restore, from the end of
3079
- // / the saved-binding stack.
3080
- void restoreTypeVariableBindings (unsigned numBindings);
3081
-
3082
3051
// / Retrieve the set of saved type variable bindings, if available.
3083
3052
// /
3084
3053
// / \returns null when we aren't currently solving the system.
3085
- SavedTypeVariableBindings * getSavedBindings () const {
3086
- return solverState ? &solverState->savedBindings : nullptr ;
3054
+ SolverTrail * getTrail () const {
3055
+ return solverState ? &solverState->Trail : nullptr ;
3087
3056
}
3088
3057
3089
3058
// / Add a new type variable that was already created.
@@ -4090,7 +4059,7 @@ class ConstraintSystem {
4090
4059
// / Retrieve the representative of the equivalence class containing
4091
4060
// / this type variable.
4092
4061
TypeVariableType *getRepresentative (TypeVariableType *typeVar) const {
4093
- return typeVar->getImpl ().getRepresentative (getSavedBindings ());
4062
+ return typeVar->getImpl ().getRepresentative (getTrail ());
4094
4063
}
4095
4064
4096
4065
// / Find if the given type variable is representative for a type
@@ -4153,7 +4122,7 @@ class ConstraintSystem {
4153
4122
// / Retrieve the fixed type corresponding to the given type variable,
4154
4123
// / or a null type if there is no fixed type.
4155
4124
Type getFixedType (TypeVariableType *typeVar) const {
4156
- return typeVar->getImpl ().getFixedType (getSavedBindings ());
4125
+ return typeVar->getImpl ().getFixedType (getTrail ());
4157
4126
}
4158
4127
4159
4128
// / Retrieve the fixed type corresponding to a given type variable,
0 commit comments