Skip to content

Commit 881c4f7

Browse files
committed
Sema: Ignore inactive type variables in addTypeVariableConstraintsToWorkList()
Fixes a regression from commit 0c128e5. The old depthFirstSearch() walked all adjacencies via the constraint graph, and thus it would visit type variables that are currently inactive because we're solving a conjunction element. This was inconsistent with the new union-find which only formed the connected components from the currently active type variables; adjacencies involving inactive type variables are no longer considered. Fix the inconsistency by changing gatherConstraints(), which used from addTypeVariableConstraintsToWorkList(), to also skip inactive type variables. Fixes rdar://problem/143340082.
1 parent 9966e01 commit 881c4f7

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,17 @@ bool ConjunctionElement::attempt(ConstraintSystem &cs) const {
19461946
llvm::SmallPtrSet<TypeVariableType *, 4> referencedVars;
19471947
findReferencedVariables(cs, referencedVars);
19481948

1949+
if (cs.isDebugMode()) {
1950+
auto indent = cs.solverState->getCurrentIndent();
1951+
auto &log = llvm::errs().indent(indent);
1952+
log << "(Element type variables in scope: ";
1953+
interleave(
1954+
referencedVars,
1955+
[&](TypeVariableType *typeVar) { log << "$T" << typeVar->getID(); },
1956+
[&] { log << ", "; });
1957+
log << ")\n";
1958+
}
1959+
19491960
for (auto *typeVar : referencedVars)
19501961
cs.addTypeVariable(typeVar);
19511962
}

lib/Sema/ConstraintGraph.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,11 @@ static void depthFirstSearch(
565565
llvm::function_ref<void(Constraint *)> visitConstraint,
566566
llvm::SmallPtrSet<TypeVariableType *, 4> &typeVars,
567567
llvm::SmallPtrSet<Constraint *, 8> &visitedConstraints) {
568+
// If we're not looking at this type variable right now because we're
569+
// solving a conjunction element, don't consider its adjacencies.
570+
if (!cg.getConstraintSystem().isActiveTypeVariable(typeVar))
571+
return;
572+
568573
// Visit this node. If we've already seen it, bail out.
569574
if (!typeVars.insert(typeVar).second)
570575
return;

test/Constraints/rdar143340082.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
struct Test {
4+
var v: String
5+
var i: Int
6+
}
7+
8+
do {
9+
let _ = Array(1 ... 20).map { i in
10+
_ = 0
11+
return Test(v: "\(i * 1000)", i: 1)
12+
}
13+
}

0 commit comments

Comments
 (0)