Skip to content

Commit 15c4822

Browse files
authored
Merge pull request #68055 from slavapestov/rdar113943346
RequirementMachine: Fix potential 'pollution' from installing an invalid requirement machine
2 parents 8501e1d + 595a7a5 commit 15c4822

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
struct G<T, U, V> {}
4+
5+
struct Foo<T> {}
6+
7+
// The first extension has the same generic signature as the
8+
// second extension, because we drop the invalid requirement.
9+
//
10+
// But the rewrite system used for minimization with the first
11+
// extension should not be installed in the rewrite context,
12+
// because of this invalid requirement.
13+
14+
extension G where T == Foo<V.Bar>, U == Foo<Int> {}
15+
// expected-error@-1 {{'Bar' is not a member type of type 'V'}}
16+
17+
extension G where U == Foo<Int> {
18+
func f() {
19+
print(T.self)
20+
print(U.self)
21+
}
22+
}

0 commit comments

Comments
 (0)