Skip to content

Commit d37e93d

Browse files
committed
[QoI] While merging equivalence classes don't forget to merge fixed types (if any)
Otherwise merging of the representative equivalence classes leaves constraint system and graph disconnected, which might leave to incorrect solutions.
1 parent 474096b commit d37e93d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/Sema/CSGen.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ static bool mergeRepresentativeEquivalenceClasses(ConstraintSystem &CS,
7171
auto rep2 = CS.getRepresentative(tyvar2);
7272

7373
if (rep1 != rep2) {
74+
auto fixedType2 = CS.getFixedType(rep2);
75+
76+
// If the there exists fixed type associated with the second
77+
// type variable, and we simply merge two types together it would
78+
// mean that portion of the constraint graph previously associated
79+
// with that (second) variable is going to be disconnected from its
80+
// new equivalence class, which is going to lead to incorrect solutions,
81+
// so we need to make sure to re-bind fixed to the new representative.
82+
if (fixedType2) {
83+
CS.addConstraint(ConstraintKind::Bind, fixedType2, rep1,
84+
rep1->getImpl().getLocator());
85+
}
86+
7487
CS.mergeEquivalenceClasses(rep1, rep2, /*updateWorkList*/ false);
7588
return true;
7689
}

validation-test/compiler_crashers/28588-unreachable-executed-at-swift-lib-sema-csapply-cpp-5770.swift renamed to validation-test/compiler_crashers_fixed/28588-unreachable-executed-at-swift-lib-sema-csapply-cpp-5770.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
// See https://swift.org/LICENSE.txt for license information
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -emit-ir
8+
// RUN: not %target-swift-frontend %s -emit-ir
99
{$0=($0={

0 commit comments

Comments
 (0)