@@ -2184,10 +2184,6 @@ class SolutionApplicationTarget {
21842184using RewriteTargetFn = std::function<
21852185 Optional<SolutionApplicationTarget> (SolutionApplicationTarget)>;
21862186
2187- // / Represents a conversion restriction between two types.
2188- using ConversionRestriction =
2189- std::tuple<TypeBase *, TypeBase *, ConversionRestrictionKind>;
2190-
21912187enum class ConstraintSystemPhase {
21922188 ConstraintGeneration,
21932189 Solving,
@@ -2377,15 +2373,15 @@ class ConstraintSystem {
23772373 // / there are multiple ways in which one type could convert to another, e.g.,
23782374 // / given class types A and B, the solver might choose either a superclass
23792375 // / conversion or a user-defined conversion.
2380- std::vector<ConversionRestriction> ConstraintRestrictions;
2376+ llvm::MapVector<std::pair<TypeBase *, TypeBase *>, ConversionRestrictionKind>
2377+ ConstraintRestrictions;
23812378
23822379 // / The set of fixes applied to make the solution work.
2383- llvm::SmallVector <ConstraintFix *, 4 > Fixes;
2380+ llvm::SmallSetVector <ConstraintFix *, 4 > Fixes;
23842381
23852382 // / The set of remembered disjunction choices used to reach
23862383 // / the current constraint system.
2387- std::vector<std::pair<ConstraintLocator*, unsigned >>
2388- DisjunctionChoices;
2384+ llvm::MapVector<ConstraintLocator *, unsigned > DisjunctionChoices;
23892385
23902386 // / A map from applied disjunction constraints to the corresponding
23912387 // / argument function type.
@@ -2394,12 +2390,12 @@ class ConstraintSystem {
23942390
23952391 // / For locators associated with call expressions, the trailing closure
23962392 // / matching rule and parameter bindings that were applied.
2397- std::vector<std::pair< ConstraintLocator *, MatchCallArgumentResult> >
2393+ llvm::MapVector< ConstraintLocator *, MatchCallArgumentResult>
23982394 argumentMatchingChoices;
23992395
24002396 // / The set of implicit value conversions performed by the solver on
24012397 // / a current path to reach a solution.
2402- SmallVector<std::pair <ConstraintLocator *, ConversionRestrictionKind> , 2 >
2398+ llvm::SmallMapVector <ConstraintLocator *, ConversionRestrictionKind, 2 >
24032399 ImplicitValueConversions;
24042400
24052401 // / The worklist of "active" constraints that should be revisited
@@ -2415,8 +2411,8 @@ class ConstraintSystem {
24152411
24162412 // / A mapping from constraint locators to the set of opened types associated
24172413 // / with that locator.
2418- SmallVector<std::pair <ConstraintLocator *, ArrayRef<OpenedType> >, 4 >
2419- OpenedTypes;
2414+ llvm::SmallMapVector <ConstraintLocator *, ArrayRef<OpenedType>, 4 >
2415+ OpenedTypes;
24202416
24212417 // / The list of all generic requirements fixed along the current
24222418 // / solver path.
@@ -2430,11 +2426,11 @@ class ConstraintSystem {
24302426
24312427 // / A mapping from constraint locators to the opened existential archetype
24322428 // / 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;
24352431
24362432 // / The set of functions that have been transformed by a result builder.
2437- std::vector<std::pair< AnyFunctionRef, AppliedBuilderTransform> >
2433+ llvm::MapVector< AnyFunctionRef, AppliedBuilderTransform>
24382434 resultBuilderTransformed;
24392435
24402436 // / Cache of the effects any closures visited.
@@ -2450,7 +2446,7 @@ class ConstraintSystem {
24502446 llvm::SmallMapVector<ASTNode, SmallVector<AppliedPropertyWrapper, 2 >, 4 > appliedPropertyWrappers;
24512447
24522448 // / The locators of \c Defaultable constraints whose defaults were used.
2453- std::vector <ConstraintLocator *> DefaultedConstraints;
2449+ llvm::SetVector <ConstraintLocator *> DefaultedConstraints;
24542450
24552451 // / A cache that stores the @dynamicCallable required methods implemented by
24562452 // / types.
@@ -3424,7 +3420,7 @@ class ConstraintSystem {
34243420 return !solverState || solverState->recordFixes ;
34253421 }
34263422
3427- ArrayRef<ConstraintFix *> getFixes () const { return Fixes; }
3423+ ArrayRef<ConstraintFix *> getFixes () const { return Fixes. getArrayRef () ; }
34283424
34293425 bool shouldSuppressDiagnostics () const {
34303426 return Options.contains (ConstraintSystemFlags::SuppressDiagnostics);
@@ -3473,6 +3469,16 @@ class ConstraintSystem {
34733469 });
34743470 }
34753471
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+
34763482 // / If an UnresolvedDotExpr, SubscriptMember, etc has been resolved by the
34773483 // / constraint system, return the decl that it references.
34783484 ValueDecl *findResolvedMemberRef (ConstraintLocator *locator);
@@ -4172,10 +4178,12 @@ class ConstraintSystem {
41724178 OpenedTypeMap *replacements = nullptr );
41734179
41744180 // / 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 ;
41794187 }
41804188
41814189private:
@@ -4901,7 +4909,10 @@ class ConstraintSystem {
49014909 // / Record a particular disjunction choice of
49024910 void recordDisjunctionChoice (ConstraintLocator *disjunctionLocator,
49034911 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});
49054916 }
49064917
49074918 // / Filter the set of disjunction terms, keeping only those where the
0 commit comments