Skip to content

Commit 0dd725a

Browse files
committed
RequirementMachine: Fix potential 'pollution' from installing an invalid requirement machine
If the substitution terms of a concrete type symbol contain unresolved name symbols, we have an invalid requirement that is dropped from the minimized signature. In this case, the rewrite system used for minimization cannot be installed as the official rewrite system for this generic signature, because building a rewrite system from the signature will produce a different result. This might be the cause of the crash in rdar://114111159.
1 parent 5ba4ce5 commit 0dd725a

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

lib/AST/RequirementMachine/HomotopyReduction.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,10 @@ void RewriteSystem::minimizeRewriteSystem(const PropertyMap &map) {
646646
}
647647

648648
/// Returns flags indicating if the rewrite system has unresolved or
649-
/// conflicting rules in our minimization domain.
649+
/// conflicting rules in our minimization domain. If these flags are
650+
/// set, we do not install this rewrite system in the rewrite context
651+
/// after minimization. Instead, we will rebuild a new rewrite system
652+
/// from the minimized requirements.
650653
GenericSignatureErrors RewriteSystem::getErrors() const {
651654
assert(Complete);
652655
assert(Minimized);
@@ -668,10 +671,19 @@ GenericSignatureErrors RewriteSystem::getErrors() const {
668671
if (rule.isConflicting() || rule.isRecursive())
669672
result |= GenericSignatureErrorFlags::HasInvalidRequirements;
670673

671-
if (!rule.isRedundant())
672-
if (auto property = rule.isPropertyRule())
674+
if (!rule.isRedundant()) {
675+
if (auto property = rule.isPropertyRule()) {
673676
if (property->getKind() == Symbol::Kind::ConcreteConformance)
674677
result |= GenericSignatureErrorFlags::HasConcreteConformances;
678+
679+
if (property->hasSubstitutions()) {
680+
for (auto t : property->getSubstitutions()) {
681+
if (t.containsUnresolvedSymbols())
682+
result |= GenericSignatureErrorFlags::HasInvalidRequirements;
683+
}
684+
}
685+
}
686+
}
675687
}
676688

677689
return result;

test/Generics/rdar113943346.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
struct G<T, U, V> {}
4+
5+
struct Foo<T> {}
6+
7+
extension G where T == Foo<V.Bar>, U == Foo<Int> {}
8+
// expected-error@-1 {{'Bar' is not a member type of type 'V'}}
9+
10+
extension G where U == Foo<Int> {
11+
func f() {
12+
print(T.self)
13+
print(U.self)
14+
}
15+
}

0 commit comments

Comments
 (0)