Skip to content

Commit bc663bb

Browse files
committed
AutoDiff: Explicitly filter out invalid requirements
The GenericSignatureBuilder drops requirements rooted in a non-existent generic parameter, whereas the RequirementMachine now asserts. Filter them out to preserve the old behavior when building the _Differentiation module with -requirement-machine-abstract-signatures=verify.
1 parent d9b9afe commit bc663bb

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,23 @@ static CanGenericSignature buildDifferentiableGenericSignature(CanGenericSignatu
394394
if (origTypeOfAbstraction) {
395395
(void) origTypeOfAbstraction.findIf([&](Type t) -> bool {
396396
if (auto *at = t->getAs<ArchetypeType>()) {
397-
types.insert(at->getInterfaceType()->getCanonicalType());
398-
for (auto *proto : at->getConformsTo()) {
399-
reqs.push_back(Requirement(RequirementKind::Conformance,
400-
at->getInterfaceType(),
401-
proto->getDeclaredInterfaceType()));
397+
auto interfaceTy = at->getInterfaceType();
398+
auto genericParams = sig.getGenericParams();
399+
400+
// The GSB used to drop requirements which reference non-existent
401+
// generic parameters, whereas the RequirementMachine asserts now.
402+
// Filter thes requirements out explicitly to preserve the old
403+
// behavior.
404+
if (std::find_if(genericParams.begin(), genericParams.end(),
405+
[interfaceTy](CanGenericTypeParamType t) -> bool {
406+
return t->isEqual(interfaceTy->getRootGenericParam());
407+
}) != genericParams.end()) {
408+
types.insert(interfaceTy->getCanonicalType());
409+
for (auto *proto : at->getConformsTo()) {
410+
reqs.push_back(Requirement(RequirementKind::Conformance,
411+
interfaceTy,
412+
proto->getDeclaredInterfaceType()));
413+
}
402414
}
403415
}
404416
return false;

0 commit comments

Comments
 (0)