Skip to content

Commit fa553ab

Browse files
committed
[CSBindings] Record conformance requirements associated with type variable
Include direct conformnace requirements as well as transitive ones.
1 parent 40d7da4 commit fa553ab

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ void ConstraintSystem::inferTransitiveSupertypeBindings(
8181
bindings.addPotentialBinding(
8282
binding.withSameSource(type, AllowedBindingKind::Supertypes));
8383
}
84+
85+
// Infer transitive protocol requirements.
86+
for (auto *protocol : relatedBindings->getSecond().Protocols) {
87+
bindings.Protocols.push_back(protocol);
88+
}
8489
}
8590
}
8691

@@ -628,6 +633,10 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) const {
628633
LLVM_FALLTHROUGH;
629634

630635
case ConstraintKind::LiteralConformsTo: {
636+
// Record constraint where protocol requirement originated
637+
// this is useful to use for the binding later.
638+
result.Protocols.push_back(constraint);
639+
631640
// If there is a 'nil' literal constraint, we might need optional
632641
// supertype bindings.
633642
if (constraint->getProtocol()->isSpecificProtocol(

lib/Sema/ConstraintSystem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4420,6 +4420,9 @@ class ConstraintSystem {
44204420
/// The set of potential bindings.
44214421
SmallVector<PotentialBinding, 4> Bindings;
44224422

4423+
/// The set of protocol requirements placed on this type variable.
4424+
llvm::TinyPtrVector<Constraint *> Protocols;
4425+
44234426
/// Whether these bindings should be delayed until the rest of the
44244427
/// constraint system is considered "fully bound".
44254428
bool FullyBound = false;

0 commit comments

Comments
 (0)