Skip to content

Commit 685dbad

Browse files
authored
Merge pull request #41052 from slavapestov/rqm-autodiff-workaround
AutoDiff: Explicitly filter out invalid requirements
2 parents ed5974d + bc663bb commit 685dbad

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)