Skip to content

Commit 6d3c6f2

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 37c3d70 commit 6d3c6f2

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
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

0 commit comments

Comments
 (0)