Skip to content

Commit f690933

Browse files
committed
Sema: Remove BindingSet::getConstraintSystem()
We shouldn't store a pointer to the ConstraintSystem inside every BindingSet, but there are some annoying things to untangle before we can do that. As a starting point toward that, remove the getConstraintSystem() getter so that at least we can't reach up to the ConstraintSystem from the outside.
1 parent c3b0a88 commit f690933

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

include/swift/Sema/CSBindings.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,6 @@ class BindingSet {
410410

411411
BindingSet(const BindingSet &other) = delete;
412412

413-
ConstraintSystem &getConstraintSystem() const { return CS; }
414-
415413
TypeVariableType *getTypeVariable() const { return TypeVar; }
416414

417415
/// Check whether this binding set belongs to a type variable

include/swift/Sema/ConstraintSystem.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6196,7 +6196,9 @@ class TypeVarBindingProducer : public BindingProducer<TypeVariableBinding> {
61966196
public:
61976197
using Element = TypeVariableBinding;
61986198

6199-
TypeVarBindingProducer(const BindingSet &bindings);
6199+
TypeVarBindingProducer(ConstraintSystem &cs,
6200+
TypeVariableType *typeVar,
6201+
const BindingSet &bindings);
62006202

62016203
/// Retrieve a set of bindings available in the current state.
62026204
ArrayRef<Binding> getCurrentBindings() const { return Bindings; }

lib/Sema/CSStep.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ StepResult ComponentStep::take(bool prevFailed) {
335335
switch (*step) {
336336
case StepKind::Binding:
337337
return suspend(
338-
std::make_unique<TypeVariableStep>(*bestBindings, Solutions));
338+
std::make_unique<TypeVariableStep>(CS, bestBindings->getTypeVariable(),
339+
*bestBindings, Solutions));
339340
case StepKind::Disjunction: {
340341
CS.retireConstraint(disjunction->first);
341342
return suspend(

lib/Sema/CSStep.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,12 @@ class TypeVariableStep final : public BindingStep<TypeVarBindingProducer> {
540540
bool SawFirstLiteralConstraint = false;
541541

542542
public:
543-
TypeVariableStep(const BindingContainer &bindings,
543+
TypeVariableStep(ConstraintSystem &cs,
544+
TypeVariableType *typeVar,
545+
const BindingContainer &bindings,
544546
SmallVectorImpl<Solution> &solutions)
545-
: BindingStep(bindings.getConstraintSystem(), {bindings}, solutions),
546-
TypeVar(bindings.getTypeVariable()) {}
547+
: BindingStep(cs, {cs, typeVar, bindings}, solutions),
548+
TypeVar(typeVar) {}
547549

548550
void setup() override;
549551

lib/Sema/ConstraintSystem.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5323,10 +5323,12 @@ ConstraintSystem::inferKeyPathLiteralCapability(KeyPathExpr *keyPath) {
53235323
return success(mutability, isSendable);
53245324
}
53255325

5326-
TypeVarBindingProducer::TypeVarBindingProducer(const BindingSet &bindings)
5327-
: BindingProducer(bindings.getConstraintSystem(),
5328-
bindings.getTypeVariable()->getImpl().getLocator()),
5329-
TypeVar(bindings.getTypeVariable()), CanBeNil(bindings.canBeNil()) {
5326+
TypeVarBindingProducer::TypeVarBindingProducer(
5327+
ConstraintSystem &cs,
5328+
TypeVariableType *typeVar,
5329+
const BindingSet &bindings)
5330+
: BindingProducer(cs, typeVar->getImpl().getLocator()),
5331+
TypeVar(typeVar), CanBeNil(bindings.canBeNil()) {
53305332
if (bindings.isDirectHole()) {
53315333
auto *locator = getLocator();
53325334
// If this type variable is associated with a code completion token

unittests/Sema/BindingInferenceTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ TEST_F(SemaTest, TestNoDoubleVoidClosureResultInference) {
352352

353353
auto verifyInference = [&](TypeVariableType *typeVar, unsigned numExpected) {
354354
auto bindings = cs.getBindingsFor(typeVar);
355-
TypeVarBindingProducer producer(bindings);
355+
TypeVarBindingProducer producer(cs, typeVar, bindings);
356356

357357
llvm::SmallPtrSet<Type, 2> inferredTypes;
358358

@@ -425,7 +425,7 @@ TEST_F(SemaTest, TestSupertypeInferenceWithDefaults) {
425425
cs.getConstraintLocator({}));
426426

427427
auto bindings = cs.getBindingsFor(genericArg);
428-
TypeVarBindingProducer producer(bindings);
428+
TypeVarBindingProducer producer(cs, genericArg, bindings);
429429

430430
llvm::SmallVector<Type, 4> inferredTypes;
431431
while (auto binding = producer()) {

0 commit comments

Comments
 (0)