@@ -2184,10 +2184,6 @@ class SolutionApplicationTarget {
2184
2184
using RewriteTargetFn = std::function<
2185
2185
Optional<SolutionApplicationTarget> (SolutionApplicationTarget)>;
2186
2186
2187
- // / Represents a conversion restriction between two types.
2188
- using ConversionRestriction =
2189
- std::tuple<TypeBase *, TypeBase *, ConversionRestrictionKind>;
2190
-
2191
2187
enum class ConstraintSystemPhase {
2192
2188
ConstraintGeneration,
2193
2189
Solving,
@@ -2377,15 +2373,15 @@ class ConstraintSystem {
2377
2373
// / there are multiple ways in which one type could convert to another, e.g.,
2378
2374
// / given class types A and B, the solver might choose either a superclass
2379
2375
// / conversion or a user-defined conversion.
2380
- std::vector<ConversionRestriction> ConstraintRestrictions;
2376
+ llvm::MapVector<std::pair<TypeBase *, TypeBase *>, ConversionRestrictionKind>
2377
+ ConstraintRestrictions;
2381
2378
2382
2379
// / The set of fixes applied to make the solution work.
2383
- llvm::SmallVector <ConstraintFix *, 4 > Fixes;
2380
+ llvm::SmallSetVector <ConstraintFix *, 4 > Fixes;
2384
2381
2385
2382
// / The set of remembered disjunction choices used to reach
2386
2383
// / the current constraint system.
2387
- std::vector<std::pair<ConstraintLocator*, unsigned >>
2388
- DisjunctionChoices;
2384
+ llvm::MapVector<ConstraintLocator *, unsigned > DisjunctionChoices;
2389
2385
2390
2386
// / A map from applied disjunction constraints to the corresponding
2391
2387
// / argument function type.
@@ -2394,12 +2390,12 @@ class ConstraintSystem {
2394
2390
2395
2391
// / For locators associated with call expressions, the trailing closure
2396
2392
// / matching rule and parameter bindings that were applied.
2397
- std::vector<std::pair< ConstraintLocator *, MatchCallArgumentResult> >
2393
+ llvm::MapVector< ConstraintLocator *, MatchCallArgumentResult>
2398
2394
argumentMatchingChoices;
2399
2395
2400
2396
// / The set of implicit value conversions performed by the solver on
2401
2397
// / a current path to reach a solution.
2402
- SmallVector<std::pair <ConstraintLocator *, ConversionRestrictionKind> , 2 >
2398
+ llvm::SmallMapVector <ConstraintLocator *, ConversionRestrictionKind, 2 >
2403
2399
ImplicitValueConversions;
2404
2400
2405
2401
// / The worklist of "active" constraints that should be revisited
@@ -2415,8 +2411,8 @@ class ConstraintSystem {
2415
2411
2416
2412
// / A mapping from constraint locators to the set of opened types associated
2417
2413
// / with that locator.
2418
- SmallVector<std::pair <ConstraintLocator *, ArrayRef<OpenedType> >, 4 >
2419
- OpenedTypes;
2414
+ llvm::SmallMapVector <ConstraintLocator *, ArrayRef<OpenedType>, 4 >
2415
+ OpenedTypes;
2420
2416
2421
2417
// / The list of all generic requirements fixed along the current
2422
2418
// / solver path.
@@ -2430,11 +2426,11 @@ class ConstraintSystem {
2430
2426
2431
2427
// / A mapping from constraint locators to the opened existential archetype
2432
2428
// / used for the 'self' of an existential type.
2433
- SmallVector<std::pair <ConstraintLocator *, OpenedArchetypeType *> , 4 >
2434
- OpenedExistentialTypes;
2429
+ llvm::SmallMapVector <ConstraintLocator *, OpenedArchetypeType *, 4 >
2430
+ OpenedExistentialTypes;
2435
2431
2436
2432
// / The set of functions that have been transformed by a result builder.
2437
- std::vector<std::pair< AnyFunctionRef, AppliedBuilderTransform> >
2433
+ llvm::MapVector< AnyFunctionRef, AppliedBuilderTransform>
2438
2434
resultBuilderTransformed;
2439
2435
2440
2436
// / Cache of the effects any closures visited.
@@ -2450,7 +2446,7 @@ class ConstraintSystem {
2450
2446
llvm::SmallMapVector<ASTNode, SmallVector<AppliedPropertyWrapper, 2 >, 4 > appliedPropertyWrappers;
2451
2447
2452
2448
// / The locators of \c Defaultable constraints whose defaults were used.
2453
- std::vector <ConstraintLocator *> DefaultedConstraints;
2449
+ llvm::SetVector <ConstraintLocator *> DefaultedConstraints;
2454
2450
2455
2451
// / A cache that stores the @dynamicCallable required methods implemented by
2456
2452
// / types.
@@ -3424,7 +3420,7 @@ class ConstraintSystem {
3424
3420
return !solverState || solverState->recordFixes ;
3425
3421
}
3426
3422
3427
- ArrayRef<ConstraintFix *> getFixes () const { return Fixes; }
3423
+ ArrayRef<ConstraintFix *> getFixes () const { return Fixes. getArrayRef () ; }
3428
3424
3429
3425
bool shouldSuppressDiagnostics () const {
3430
3426
return Options.contains (ConstraintSystemFlags::SuppressDiagnostics);
@@ -3473,6 +3469,16 @@ class ConstraintSystem {
3473
3469
});
3474
3470
}
3475
3471
3472
+ bool
3473
+ hasConversionRestriction (Type type1, Type type2,
3474
+ ConversionRestrictionKind restrictionKind) const {
3475
+ auto restriction =
3476
+ ConstraintRestrictions.find ({type1.getPointer (), type2.getPointer ()});
3477
+ return restriction == ConstraintRestrictions.end ()
3478
+ ? false
3479
+ : restriction->second == restrictionKind;
3480
+ }
3481
+
3476
3482
// / If an UnresolvedDotExpr, SubscriptMember, etc has been resolved by the
3477
3483
// / constraint system, return the decl that it references.
3478
3484
ValueDecl *findResolvedMemberRef (ConstraintLocator *locator);
@@ -4172,10 +4178,12 @@ class ConstraintSystem {
4172
4178
OpenedTypeMap *replacements = nullptr );
4173
4179
4174
4180
// / Retrieve a list of generic parameter types solver has "opened" (replaced
4175
- // / with a type variable) along the current path.
4176
- ArrayRef<std::pair<ConstraintLocator *, ArrayRef<OpenedType>>>
4177
- getOpenedTypes () const {
4178
- return OpenedTypes;
4181
+ // / with a type variable) at the given location.
4182
+ ArrayRef<OpenedType> getOpenedTypes (ConstraintLocator *locator) const {
4183
+ auto substitutions = OpenedTypes.find (locator);
4184
+ if (substitutions == OpenedTypes.end ())
4185
+ return {};
4186
+ return substitutions->second ;
4179
4187
}
4180
4188
4181
4189
private:
@@ -4901,7 +4909,10 @@ class ConstraintSystem {
4901
4909
// / Record a particular disjunction choice of
4902
4910
void recordDisjunctionChoice (ConstraintLocator *disjunctionLocator,
4903
4911
unsigned index) {
4904
- DisjunctionChoices.push_back ({disjunctionLocator, index});
4912
+ // We shouldn't ever register disjunction choices multiple times.
4913
+ assert (!DisjunctionChoices.count (disjunctionLocator) ||
4914
+ DisjunctionChoices[disjunctionLocator] == index);
4915
+ DisjunctionChoices.insert ({disjunctionLocator, index});
4905
4916
}
4906
4917
4907
4918
// / Filter the set of disjunction terms, keeping only those where the
0 commit comments