Skip to content

Commit 62dc8ce

Browse files
authored
Merge pull request #35453 from xedin/extract-potential-bindings-into-header
[ConstraintSystem] NFC: Extract `PotentialBinding(s)` and auxiliary types/logic into separate header and namespace
2 parents 0059864 + 48afd65 commit 62dc8ce

File tree

8 files changed

+760
-720
lines changed

8 files changed

+760
-720
lines changed

include/swift/Sema/CSBindings.h

Lines changed: 540 additions & 0 deletions
Large diffs are not rendered by default.

include/swift/Sema/ConstraintSystem.h

Lines changed: 9 additions & 599 deletions
Large diffs are not rendered by default.

lib/Sema/CSBindings.cpp

Lines changed: 197 additions & 108 deletions
Large diffs are not rendered by default.

lib/Sema/CSStep.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@ template <typename P> class BindingStep : public SolverStep {
565565
};
566566

567567
class TypeVariableStep final : public BindingStep<TypeVarBindingProducer> {
568-
using BindingContainer = ConstraintSystem::PotentialBindings;
569-
using Binding = ConstraintSystem::PotentialBinding;
568+
using BindingContainer = inference::PotentialBindings;
569+
using Binding = inference::PotentialBinding;
570570

571571
TypeVariableType *TypeVar;
572572

lib/Sema/ConstraintSystem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
using namespace swift;
4040
using namespace constraints;
41+
using namespace inference;
4142

4243
#define DEBUG_TYPE "ConstraintSystem"
4344

@@ -5295,8 +5296,7 @@ bool ConstraintSystem::isReadOnlyKeyPathComponent(
52955296
return false;
52965297
}
52975298

5298-
TypeVarBindingProducer::TypeVarBindingProducer(
5299-
ConstraintSystem::PotentialBindings &bindings)
5299+
TypeVarBindingProducer::TypeVarBindingProducer(PotentialBindings &bindings)
53005300
: BindingProducer(bindings.CS, bindings.TypeVar->getImpl().getLocator()),
53015301
TypeVar(bindings.TypeVar), CanBeNil(bindings.canBeNil()) {
53025302
if (bindings.isDirectHole()) {
@@ -5406,7 +5406,7 @@ bool TypeVarBindingProducer::requiresOptionalAdjustment(
54065406
return false;
54075407
}
54085408

5409-
ConstraintSystem::PotentialBinding
5409+
PotentialBinding
54105410
TypeVarBindingProducer::getDefaultBinding(Constraint *constraint) const {
54115411
assert(constraint->getKind() == ConstraintKind::Defaultable ||
54125412
constraint->getKind() == ConstraintKind::DefaultClosureType);

unittests/Sema/BindingInferenceTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using namespace swift;
2020
using namespace swift::unittest;
2121
using namespace swift::constraints;
22+
using namespace swift::constraints::inference;
2223

2324
TEST_F(SemaTest, TestIntLiteralBindingInference) {
2425
ConstraintSystemOptions options;
@@ -124,8 +125,7 @@ TEST_F(SemaTest, TestIntLiteralBindingInference) {
124125
ASSERT_EQ(bindings.Bindings.size(), (unsigned)0);
125126
ASSERT_EQ(bindings.Literals.size(), (unsigned)0);
126127

127-
llvm::SmallDenseMap<TypeVariableType *, ConstraintSystem::PotentialBindings>
128-
env;
128+
llvm::SmallDenseMap<TypeVariableType *, PotentialBindings> env;
129129
env.insert({floatLiteralTy, cs.inferBindingsFor(floatLiteralTy)});
130130

131131
bindings.finalize(env);

unittests/Sema/SemaFixture.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
using namespace swift;
2828
using namespace swift::unittest;
29+
using namespace swift::constraints::inference;
2930

3031
SemaTest::SemaTest()
3132
: Context(*ASTContext::get(LangOpts, TypeCheckerOpts, SearchPathOpts,
@@ -120,10 +121,9 @@ ProtocolType *SemaTest::createProtocol(llvm::StringRef protocolName,
120121
return ProtocolType::get(PD, parent, Context);
121122
}
122123

123-
ConstraintSystem::PotentialBindings
124-
SemaTest::inferBindings(ConstraintSystem &cs, TypeVariableType *typeVar) {
125-
llvm::SmallDenseMap<TypeVariableType *, ConstraintSystem::PotentialBindings>
126-
cache;
124+
PotentialBindings SemaTest::inferBindings(ConstraintSystem &cs,
125+
TypeVariableType *typeVar) {
126+
llvm::SmallDenseMap<TypeVariableType *, PotentialBindings> cache;
127127

128128
for (auto *typeVar : cs.getTypeVariables()) {
129129
if (!typeVar->getImpl().hasRepresentativeOrFixed())

unittests/Sema/SemaFixture.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <string>
2929

3030
using namespace swift::constraints;
31+
using namespace swift::constraints::inference;
3132

3233
namespace swift {
3334
namespace unittest {
@@ -75,8 +76,8 @@ class SemaTest : public SemaTestBase {
7576
ProtocolType *createProtocol(llvm::StringRef protocolName,
7677
Type parent = Type());
7778

78-
static ConstraintSystem::PotentialBindings
79-
inferBindings(ConstraintSystem &cs, TypeVariableType *typeVar);
79+
static PotentialBindings inferBindings(ConstraintSystem &cs,
80+
TypeVariableType *typeVar);
8081
};
8182

8283
} // end namespace unittest

0 commit comments

Comments
 (0)