Skip to content

Commit da87b83

Browse files
authored
Merge pull request #12116 from rudkx/move-add-potential-binding
[Constraint system] Move addPotentialBinding implementation back to CSBdinings.cpp.
2 parents 6b0595d + e46d2a7 commit da87b83

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,40 @@ static bool shouldBindToValueType(Constraint *constraint) {
123123
llvm_unreachable("Unhandled ConstraintKind in switch.");
124124
}
125125

126+
void ConstraintSystem::PotentialBindings::addPotentialBinding(
127+
PotentialBinding binding, bool allowJoinMeet) {
128+
assert(!binding.BindingType->is<ErrorType>());
129+
130+
// If this is a non-defaulted supertype binding,
131+
// check whether we can combine it with another
132+
// supertype binding by computing the 'join' of the types.
133+
if (binding.Kind == AllowedBindingKind::Supertypes &&
134+
!binding.BindingType->hasTypeVariable() && !binding.DefaultedProtocol &&
135+
!binding.isDefaultableBinding() && allowJoinMeet) {
136+
if (lastSupertypeIndex) {
137+
// Can we compute a join?
138+
auto &lastBinding = Bindings[*lastSupertypeIndex];
139+
auto lastType = lastBinding.BindingType->getWithoutSpecifierType();
140+
auto bindingType = binding.BindingType->getWithoutSpecifierType();
141+
auto join = Type::join(lastType, bindingType);
142+
if (join) {
143+
auto anyType = join->getASTContext().TheAnyType;
144+
if (!join->isEqual(anyType) || lastType->isEqual(anyType) ||
145+
bindingType->isEqual(anyType)) {
146+
// Replace the last supertype binding with the join. We're done.
147+
lastBinding.BindingType = join;
148+
return;
149+
}
150+
}
151+
}
152+
153+
// Record this as the most recent supertype index.
154+
lastSupertypeIndex = Bindings.size();
155+
}
156+
157+
Bindings.push_back(std::move(binding));
158+
}
159+
126160
/// \brief Retrieve the set of potential type bindings for the given
127161
/// representative type variable, along with flags indicating whether
128162
/// those types should be opened.

lib/Sema/ConstraintSystem.h

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,39 +2629,7 @@ class ConstraintSystem {
26292629
/// \brief Add a potential binding to the list of bindings,
26302630
/// coalescing supertype bounds when we are able to compute the meet.
26312631
void addPotentialBinding(PotentialBinding binding,
2632-
bool allowJoinMeet = true) {
2633-
assert(!binding.BindingType->is<ErrorType>());
2634-
2635-
// If this is a non-defaulted supertype binding,
2636-
// check whether we can combine it with another
2637-
// supertype binding by computing the 'join' of the types.
2638-
if (binding.Kind == AllowedBindingKind::Supertypes &&
2639-
!binding.BindingType->hasTypeVariable() &&
2640-
!binding.DefaultedProtocol && !binding.isDefaultableBinding() &&
2641-
allowJoinMeet) {
2642-
if (lastSupertypeIndex) {
2643-
// Can we compute a join?
2644-
auto &lastBinding = Bindings[*lastSupertypeIndex];
2645-
auto lastType = lastBinding.BindingType->getWithoutSpecifierType();
2646-
auto bindingType = binding.BindingType->getWithoutSpecifierType();
2647-
auto join = Type::join(lastType, bindingType);
2648-
if (join) {
2649-
auto anyType = join->getASTContext().TheAnyType;
2650-
if (!join->isEqual(anyType) || lastType->isEqual(anyType) ||
2651-
bindingType->isEqual(anyType)) {
2652-
// Replace the last supertype binding with the join. We're done.
2653-
lastBinding.BindingType = join;
2654-
return;
2655-
}
2656-
}
2657-
}
2658-
2659-
// Record this as the most recent supertype index.
2660-
lastSupertypeIndex = Bindings.size();
2661-
}
2662-
2663-
Bindings.push_back(std::move(binding));
2664-
}
2632+
bool allowJoinMeet = true);
26652633

26662634
void dump(llvm::raw_ostream &out,
26672635
unsigned indent = 0) const LLVM_ATTRIBUTE_USED {

0 commit comments

Comments
 (0)