Skip to content

Commit 4e32132

Browse files
committed
[CSStep] Don't retain multiple copies of the same bindings just for printing
1 parent 579274b commit 4e32132

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5826,6 +5826,9 @@ class TypeVarBindingProducer : public BindingProducer<TypeVariableBinding> {
58265826
TypeVar(bindings.TypeVar),
58275827
Bindings(bindings.Bindings.begin(), bindings.Bindings.end()) {}
58285828

5829+
/// Retrieve a set of bindings available in the current state.
5830+
ArrayRef<Binding> getCurrentBindings() const { return Bindings; }
5831+
58295832
Optional<Element> operator()() override {
58305833
// Once we reach the end of the current bindings
58315834
// let's try to compute new ones, e.g. supertypes,

lib/Sema/CSStep.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,15 @@ void TypeVariableStep::setup() {
446446
PO.PrintTypesForDebugging = true;
447447
auto &log = getDebugLogger();
448448

449+
auto initialBindings = Producer.getCurrentBindings();
449450
log << "Initial bindings: ";
450-
interleave(InitialBindings.begin(), InitialBindings.end(),
451-
[&](const Binding &binding) {
452-
log << TypeVar->getString(PO)
453-
<< " := " << binding.BindingType->getString(PO);
454-
},
455-
[&log] { log << ", "; });
451+
interleave(
452+
initialBindings.begin(), initialBindings.end(),
453+
[&](const Binding &binding) {
454+
log << TypeVar->getString(PO)
455+
<< " := " << binding.BindingType->getString(PO);
456+
},
457+
[&log] { log << ", "; });
456458

457459
log << '\n';
458460
}

lib/Sema/CSStep.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,9 @@ class ComponentStep final : public SolverStep {
479479
template <typename P> class BindingStep : public SolverStep {
480480
using Scope = ConstraintSystem::SolverScope;
481481

482+
protected:
482483
P Producer;
483484

484-
protected:
485485
/// Indicates whether any of the attempted bindings
486486
/// produced a solution.
487487
bool AnySolved = false;
@@ -569,10 +569,6 @@ class TypeVariableStep final : public BindingStep<TypeVarBindingProducer> {
569569
using Binding = ConstraintSystem::PotentialBinding;
570570

571571
TypeVariableType *TypeVar;
572-
// A set of the initial bindings to consider, which is
573-
// also a source of follow-up "computed" bindings such
574-
// as supertypes, defaults etc.
575-
SmallVector<Binding, 4> InitialBindings;
576572

577573
/// Indicates whether source of one of the previously
578574
/// attempted bindings was a literal constraint. This
@@ -583,8 +579,7 @@ class TypeVariableStep final : public BindingStep<TypeVarBindingProducer> {
583579
public:
584580
TypeVariableStep(ConstraintSystem &cs, BindingContainer &bindings,
585581
SmallVectorImpl<Solution> &solutions)
586-
: BindingStep(cs, {cs, bindings}, solutions), TypeVar(bindings.TypeVar),
587-
InitialBindings(bindings.Bindings.begin(), bindings.Bindings.end()) {}
582+
: BindingStep(cs, {cs, bindings}, solutions), TypeVar(bindings.TypeVar) {}
588583

589584
void setup() override;
590585

@@ -593,8 +588,7 @@ class TypeVariableStep final : public BindingStep<TypeVarBindingProducer> {
593588
void print(llvm::raw_ostream &Out) override {
594589
PrintOptions PO;
595590
PO.PrintTypesForDebugging = true;
596-
Out << "TypeVariableStep for " << TypeVar->getString(PO) << " with #"
597-
<< InitialBindings.size() << " initial bindings\n";
591+
Out << "TypeVariableStep for " << TypeVar->getString(PO) << '\n';
598592
}
599593

600594
protected:

0 commit comments

Comments
 (0)