Skip to content

Commit a0fc6a2

Browse files
author
Amritpan Kaur
committed
[CSStep] Print changed type variables or constraints with a Changes heading. This prints type variables that changed because they involve other type variables and so may have new bindings due to this relationship. It also prints any new or changed constraints that occured as a result of acquiring these new bindings.
1 parent 590e5ef commit a0fc6a2

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ Optional<BindingSet> ConstraintSystem::determineBestBindings() {
798798
continue;
799799

800800
if (isDebugMode()) {
801-
bindings.dump(typeVar, llvm::errs(), solverState->depth * 2);
801+
bindings.dump(typeVar, llvm::errs(), solverState->depth * 2 + 2);
802802
}
803803

804804
// If these are the first bindings, or they are better than what
@@ -1983,6 +1983,10 @@ TypeVariableBinding::fixForHole(ConstraintSystem &cs) const {
19831983
}
19841984

19851985
bool TypeVariableBinding::attempt(ConstraintSystem &cs) const {
1986+
// Get bindings for TypeVar in scope before this attempt
1987+
// adds new constraints or bindings, for use in debug printing.
1988+
auto bindings = cs.getBindingsFor(TypeVar);
1989+
19861990
auto type = Binding.BindingType;
19871991
auto *srcLocator = Binding.getLocator();
19881992
auto *dstLocator = TypeVar->getImpl().getLocator();
@@ -2070,6 +2074,25 @@ bool TypeVariableBinding::attempt(ConstraintSystem &cs) const {
20702074

20712075
if (cs.simplify())
20722076
return false;
2077+
2078+
if (cs.isDebugMode() && bindings.involvesTypeVariables()) {
2079+
auto &log = llvm::errs();
2080+
log.indent(cs.solverState->depth * 2);
2081+
log << "Changes: \n";
2082+
log.indent(cs.solverState->depth * 2 + 2);
2083+
log << "Constraints: \n";
2084+
auto gatheringKind = ConstraintGraph::GatheringKind::AllMentions;
2085+
auto &CG = cs.getConstraintGraph();
2086+
for (auto *constraint : CG.gatherConstraints(TypeVar, gatheringKind)) {
2087+
log.indent(cs.solverState->depth * 2 + 4);
2088+
log << "- ";
2089+
constraint->print(log, &cs.getASTContext().SourceMgr);
2090+
log << '\n';
2091+
}
2092+
log.indent(cs.solverState->depth * 2 + 2);
2093+
log << "Type Variables: \n";
2094+
}
2095+
20732096

20742097
// If all of the re-activated constraints where simplified,
20752098
// let's notify binding inference about the fact that type

lib/Sema/CSStep.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,6 @@ bool TypeVariableStep::attempt(const TypeVariableBinding &choice) {
508508
if (choice.hasDefaultedProtocol())
509509
SawFirstLiteralConstraint = true;
510510

511-
// Try to solve the system with typeVar := type
512511
return choice.attempt(CS);
513512
}
514513

0 commit comments

Comments
 (0)