Skip to content

Commit e95ff01

Browse files
committed
AST: Fix invariant violation in swift::validateGenericSignature()
This is a silly "extended" verification check that we only exercise in test/Generics/validate_stdlib_generic_signatures.swift. We were taking a requirement containing unbound dependent member types and applying a substitution map to it, which would result in an ErrorType, so the requirement was always considered unsatisfied here and the check was not as useful as it should have been. Instead, re-implement a version of isRequirementSatisfied() that only uses generic signature queries instead of substitution here.
1 parent cfc3012 commit e95ff01

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

lib/AST/GenericSignature.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,39 @@ void swift::validateGenericSignature(ASTContext &context,
11741174

11751175
// If the removed requirement is satisfied by the new generic signature,
11761176
// it is redundant. Complain.
1177-
if (newSig->isRequirementSatisfied(requirements[victimIndex])) {
1177+
auto satisfied = [&](Requirement victim) {
1178+
if (!newSig->isValidTypeParameter(victim.getFirstType()))
1179+
return false;
1180+
1181+
switch (victim.getKind()) {
1182+
case RequirementKind::SameShape:
1183+
return (newSig->isValidTypeParameter(victim.getSecondType()) &&
1184+
newSig->haveSameShape(victim.getFirstType(),
1185+
victim.getSecondType()));
1186+
case RequirementKind::Conformance:
1187+
return newSig->requiresProtocol(victim.getFirstType(),
1188+
victim.getProtocolDecl());
1189+
case RequirementKind::Superclass: {
1190+
auto superclass = newSig->getSuperclassBound(victim.getFirstType());
1191+
return (superclass && superclass->isEqual(victim.getSecondType()));
1192+
}
1193+
case RequirementKind::SameType:
1194+
if (!victim.getSecondType().findIf([&](Type t) -> bool {
1195+
return (!t->isTypeParameter() ||
1196+
newSig->isValidTypeParameter(t));
1197+
})) {
1198+
return false;
1199+
}
1200+
return newSig.getReducedType(victim.getFirstType())
1201+
->isEqual(newSig.getReducedType(victim.getSecondType()));
1202+
case RequirementKind::Layout: {
1203+
auto layout = newSig->getLayoutConstraint(victim.getFirstType());
1204+
return (layout && layout == victim.getLayoutConstraint());
1205+
}
1206+
}
1207+
};
1208+
1209+
if (satisfied(requirements[victimIndex])) {
11781210
SmallString<32> reqString;
11791211
{
11801212
llvm::raw_svector_ostream out(reqString);

0 commit comments

Comments
 (0)