Skip to content

[ConstraintSystem] NFC: Extract PotentialBinding(s) and auxiliary types/logic into separate header and namespace #35453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
540 changes: 540 additions & 0 deletions include/swift/Sema/CSBindings.h

Large diffs are not rendered by default.

608 changes: 9 additions & 599 deletions include/swift/Sema/ConstraintSystem.h

Large diffs are not rendered by default.

305 changes: 197 additions & 108 deletions lib/Sema/CSBindings.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/Sema/CSStep.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@ template <typename P> class BindingStep : public SolverStep {
};

class TypeVariableStep final : public BindingStep<TypeVarBindingProducer> {
using BindingContainer = ConstraintSystem::PotentialBindings;
using Binding = ConstraintSystem::PotentialBinding;
using BindingContainer = inference::PotentialBindings;
using Binding = inference::PotentialBinding;

TypeVariableType *TypeVar;

Expand Down
6 changes: 3 additions & 3 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

using namespace swift;
using namespace constraints;
using namespace inference;

#define DEBUG_TYPE "ConstraintSystem"

Expand Down Expand Up @@ -5295,8 +5296,7 @@ bool ConstraintSystem::isReadOnlyKeyPathComponent(
return false;
}

TypeVarBindingProducer::TypeVarBindingProducer(
ConstraintSystem::PotentialBindings &bindings)
TypeVarBindingProducer::TypeVarBindingProducer(PotentialBindings &bindings)
: BindingProducer(bindings.CS, bindings.TypeVar->getImpl().getLocator()),
TypeVar(bindings.TypeVar), CanBeNil(bindings.canBeNil()) {
if (bindings.isDirectHole()) {
Expand Down Expand Up @@ -5406,7 +5406,7 @@ bool TypeVarBindingProducer::requiresOptionalAdjustment(
return false;
}

ConstraintSystem::PotentialBinding
PotentialBinding
TypeVarBindingProducer::getDefaultBinding(Constraint *constraint) const {
assert(constraint->getKind() == ConstraintKind::Defaultable ||
constraint->getKind() == ConstraintKind::DefaultClosureType);
Expand Down
4 changes: 2 additions & 2 deletions unittests/Sema/BindingInferenceTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using namespace swift;
using namespace swift::unittest;
using namespace swift::constraints;
using namespace swift::constraints::inference;

TEST_F(SemaTest, TestIntLiteralBindingInference) {
ConstraintSystemOptions options;
Expand Down Expand Up @@ -124,8 +125,7 @@ TEST_F(SemaTest, TestIntLiteralBindingInference) {
ASSERT_EQ(bindings.Bindings.size(), (unsigned)0);
ASSERT_EQ(bindings.Literals.size(), (unsigned)0);

llvm::SmallDenseMap<TypeVariableType *, ConstraintSystem::PotentialBindings>
env;
llvm::SmallDenseMap<TypeVariableType *, PotentialBindings> env;
env.insert({floatLiteralTy, cs.inferBindingsFor(floatLiteralTy)});

bindings.finalize(env);
Expand Down
8 changes: 4 additions & 4 deletions unittests/Sema/SemaFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

using namespace swift;
using namespace swift::unittest;
using namespace swift::constraints::inference;

SemaTest::SemaTest()
: Context(*ASTContext::get(LangOpts, TypeCheckerOpts, SearchPathOpts,
Expand Down Expand Up @@ -120,10 +121,9 @@ ProtocolType *SemaTest::createProtocol(llvm::StringRef protocolName,
return ProtocolType::get(PD, parent, Context);
}

ConstraintSystem::PotentialBindings
SemaTest::inferBindings(ConstraintSystem &cs, TypeVariableType *typeVar) {
llvm::SmallDenseMap<TypeVariableType *, ConstraintSystem::PotentialBindings>
cache;
PotentialBindings SemaTest::inferBindings(ConstraintSystem &cs,
TypeVariableType *typeVar) {
llvm::SmallDenseMap<TypeVariableType *, PotentialBindings> cache;

for (auto *typeVar : cs.getTypeVariables()) {
if (!typeVar->getImpl().hasRepresentativeOrFixed())
Expand Down
5 changes: 3 additions & 2 deletions unittests/Sema/SemaFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <string>

using namespace swift::constraints;
using namespace swift::constraints::inference;

namespace swift {
namespace unittest {
Expand Down Expand Up @@ -75,8 +76,8 @@ class SemaTest : public SemaTestBase {
ProtocolType *createProtocol(llvm::StringRef protocolName,
Type parent = Type());

static ConstraintSystem::PotentialBindings
inferBindings(ConstraintSystem &cs, TypeVariableType *typeVar);
static PotentialBindings inferBindings(ConstraintSystem &cs,
TypeVariableType *typeVar);
};

} // end namespace unittest
Expand Down