@@ -3345,89 +3345,34 @@ void simplifyLocator(Expr *&anchor,
3345
3345
// / null otherwise.
3346
3346
Expr *simplifyLocatorToAnchor (ConstraintSystem &cs, ConstraintLocator *locator);
3347
3347
3348
- enum class TypeBindingFlag {
3349
- // / The constraint represented by this choice has been
3350
- // / marked as disabled by the solver.
3351
- Disabled = 0x01 ,
3352
- // / The declaration behind this binding is marked as `@unavailable`
3353
- Unavailable = 0x02 ,
3354
- // / This binding comes from the "defaults to" constraint.
3355
- Defaultable = 0x04 ,
3356
- // / This binding comes from the "defaults to" constraint
3357
- // / which has associated protocol.
3358
- HasDefaultedProtocol = 0x08 ,
3359
- // / Type of the binding comes from generic operator declaration.
3360
- GenericOperator = 0x10 ,
3361
- // / Type of the binding comes from symmetric operator declaration.
3362
- SymmetricOperator = 0x20 ,
3363
- };
3364
-
3365
- using TypeBindingFlags = OptionSet<TypeBindingFlag>;
3366
-
3367
- // / Common interface to encapsulate attempting choices of
3368
- // / different entities, such as type variables (types)
3369
- // / or disjunctions (their choices).
3370
- class TypeBinding {
3348
+ class DisjunctionChoice {
3371
3349
unsigned Index;
3372
- TypeBindingFlags Flags;
3350
+ Constraint *Choice;
3351
+ bool ExplicitConversion;
3373
3352
3374
3353
public:
3375
- TypeBinding (unsigned index, TypeBindingFlags flags)
3376
- : Index(index), Flags(flags) {}
3377
-
3378
- virtual ~TypeBinding () {}
3379
-
3380
- // / Attempt given binding in the constraint system, this is going to
3381
- // / introduce some new constraints (potentially "bind" constraints)
3382
- // / to try and associate some type variables with new types.
3383
- // /
3384
- // / \returns true if attempt has been accepted by the constraint system,
3385
- // / which means that new constraints have been successfully solved.
3386
- virtual bool attempt (ConstraintSystem &cs) const = 0;
3354
+ DisjunctionChoice (unsigned index, Constraint *choice, bool explicitConversion)
3355
+ : Index(index), Choice(choice), ExplicitConversion(explicitConversion) {}
3387
3356
3388
- // / Position of this binding in the chain.
3389
3357
unsigned getIndex () const { return Index; }
3390
3358
3391
- bool isDisabled () const { return Flags.contains (TypeBindingFlag::Disabled); }
3392
-
3393
- bool isUnavailable () const {
3394
- return Flags.contains (TypeBindingFlag::Unavailable);
3395
- }
3359
+ bool attempt (ConstraintSystem &cs) const ;
3396
3360
3397
- bool isDefaultable () const {
3398
- return Flags.contains (TypeBindingFlag::Defaultable);
3399
- }
3361
+ bool isDisabled () const { return Choice->isDisabled (); }
3400
3362
3401
- bool hasDefaultedProtocol () const {
3402
- return Flags.contains (TypeBindingFlag::HasDefaultedProtocol);
3363
+ bool isUnavailable () const {
3364
+ if (auto *decl = getDecl (Choice))
3365
+ return decl->getAttrs ().isUnavailable (decl->getASTContext ());
3366
+ return false ;
3403
3367
}
3404
3368
3405
3369
// FIXME: Both of the accessors below are required to support
3406
3370
// performance optimization hacks in constraint solver.
3407
3371
3408
- bool isGenericOperator () const {
3409
- return Flags.contains (TypeBindingFlag::GenericOperator);
3410
- }
3411
-
3412
- bool isSymmetricOperator () const {
3413
- return Flags.contains (TypeBindingFlag::SymmetricOperator);
3414
- }
3415
-
3416
- virtual void print (llvm::raw_ostream &Out, SourceManager *SM) const = 0;
3417
- };
3418
-
3419
- class DisjunctionChoice : public TypeBinding {
3420
- Constraint *Choice;
3421
- bool ExplicitConversion;
3422
-
3423
- public:
3424
- DisjunctionChoice (unsigned index, Constraint *choice, bool explicitConversion)
3425
- : TypeBinding(index, computeFlags(choice)), Choice(choice),
3426
- ExplicitConversion (explicitConversion) {}
3427
-
3428
- bool attempt (ConstraintSystem &cs) const override ;
3372
+ bool isGenericOperator () const ;
3373
+ bool isSymmetricOperator () const ;
3429
3374
3430
- void print (llvm::raw_ostream &Out, SourceManager *SM) const override {
3375
+ void print (llvm::raw_ostream &Out, SourceManager *SM) const {
3431
3376
Choice->print (Out, SM);
3432
3377
}
3433
3378
@@ -3439,15 +3384,6 @@ class DisjunctionChoice : public TypeBinding {
3439
3384
// / let's try to propagate its type early to prune search space.
3440
3385
void propagateConversionInfo (ConstraintSystem &cs) const ;
3441
3386
3442
- static bool unavailable (Constraint *choice) {
3443
- if (auto *decl = getDecl (choice))
3444
- return decl->getAttrs ().isUnavailable (decl->getASTContext ());
3445
- return false ;
3446
- }
3447
-
3448
- static bool isGenericOp (Constraint *choice);
3449
- static bool isSymmetricOp (Constraint *choice);
3450
-
3451
3387
static ValueDecl *getOperatorDecl (Constraint *choice) {
3452
3388
auto *decl = getDecl (choice);
3453
3389
if (!decl)
@@ -3466,46 +3402,25 @@ class DisjunctionChoice : public TypeBinding {
3466
3402
3467
3403
return choice.getDecl ();
3468
3404
}
3469
-
3470
- static TypeBindingFlags computeFlags (Constraint *choice) {
3471
- TypeBindingFlags flags;
3472
- if (choice->isDisabled ())
3473
- flags |= TypeBindingFlag::Disabled;
3474
- if (unavailable (choice))
3475
- flags |= TypeBindingFlag::Unavailable;
3476
- if (isGenericOp (choice))
3477
- flags |= TypeBindingFlag::GenericOperator;
3478
- if (isSymmetricOp (choice))
3479
- flags |= TypeBindingFlag::SymmetricOperator;
3480
- return flags;
3481
- }
3482
3405
};
3483
3406
3484
- class TypeVariableBinding : public TypeBinding {
3407
+ class TypeVariableBinding {
3485
3408
TypeVariableType *TypeVar;
3486
3409
ConstraintSystem::PotentialBinding Binding;
3487
3410
3488
3411
public:
3489
- TypeVariableBinding (unsigned index, TypeVariableType *typeVar,
3412
+ TypeVariableBinding (TypeVariableType *typeVar,
3490
3413
ConstraintSystem::PotentialBinding &binding)
3491
- : TypeBinding(index, computeFlags(binding)), TypeVar(typeVar),
3492
- Binding (binding) {}
3414
+ : TypeVar(typeVar), Binding(binding) {}
3493
3415
3494
- bool attempt (ConstraintSystem &cs ) const override ;
3416
+ bool isDefaultable ( ) const { return Binding. isDefaultableBinding (); }
3495
3417
3496
- void print (llvm::raw_ostream &Out, SourceManager *) const override {
3497
- Out << TypeVar->getString () << " := " << Binding.BindingType ->getString ();
3498
- }
3418
+ bool hasDefaultedProtocol () const { return Binding.DefaultedProtocol ; }
3499
3419
3500
- private:
3501
- static TypeBindingFlags
3502
- computeFlags (ConstraintSystem::PotentialBinding &binding) {
3503
- TypeBindingFlags flags;
3504
- if (binding.isDefaultableBinding ())
3505
- flags |= TypeBindingFlag::Defaultable;
3506
- if (binding.DefaultedProtocol )
3507
- flags |= TypeBindingFlag::HasDefaultedProtocol;
3508
- return flags;
3420
+ bool attempt (ConstraintSystem &cs) const ;
3421
+
3422
+ void print (llvm::raw_ostream &Out, SourceManager *) const {
3423
+ Out << TypeVar->getString () << " := " << Binding.BindingType ->getString ();
3509
3424
}
3510
3425
};
3511
3426
@@ -3564,8 +3479,7 @@ class TypeVarBindingProducer : public BindingProducer<TypeVariableBinding> {
3564
3479
if (needsToComputeNext () && !computeNext ())
3565
3480
return None;
3566
3481
3567
- unsigned currIndex = Index++;
3568
- return TypeVariableBinding (currIndex, TypeVar, Bindings[currIndex]);
3482
+ return TypeVariableBinding (TypeVar, Bindings[Index++]);
3569
3483
}
3570
3484
3571
3485
bool needsToComputeNext () const override { return Index >= Bindings.size (); }
0 commit comments