@@ -2007,29 +2007,7 @@ namespace {
20072007 // /
20082008 // / When it does, returns the protocol.
20092009 ProtocolDecl *requiresWitnessTable (const Requirement &req) const {
2010- // We only care about conformance requirements.
2011- if (req.getKind () != RequirementKind::Conformance)
2012- return nullptr ;
2013-
2014- // The protocol must require a witness table.
2015- auto proto = req.getProtocolDecl ();
2016- if (!Lowering::TypeConverter::protocolRequiresWitnessTable (proto))
2017- return nullptr ;
2018-
2019- // The type itself must be anchored on one of the generic parameters of
2020- // the opaque type (not an outer context).
2021- Type subject = req.getFirstType ();
2022- while (auto depMember = subject->getAs <DependentMemberType>()) {
2023- subject = depMember->getBase ();
2024- }
2025-
2026- if (auto genericParam = subject->getAs <GenericTypeParamType>()) {
2027- unsigned opaqueDepth = O->getOpaqueGenericParams ().front ()->getDepth ();
2028- if (genericParam->getDepth () == opaqueDepth)
2029- return proto;
2030- }
2031-
2032- return nullptr ;
2010+ return opaqueTypeRequiresWitnessTable (O, req);
20332011 }
20342012
20352013 public:
@@ -2155,6 +2133,33 @@ namespace {
21552133 };
21562134} // end anonymous namespace
21572135
2136+ ProtocolDecl *irgen::opaqueTypeRequiresWitnessTable (
2137+ OpaqueTypeDecl *opaque, const Requirement &req) {
2138+ // We only care about conformance requirements.
2139+ if (req.getKind () != RequirementKind::Conformance)
2140+ return nullptr ;
2141+
2142+ // The protocol must require a witness table.
2143+ auto proto = req.getProtocolDecl ();
2144+ if (!Lowering::TypeConverter::protocolRequiresWitnessTable (proto))
2145+ return nullptr ;
2146+
2147+ // The type itself must be anchored on one of the generic parameters of
2148+ // the opaque type (not an outer context).
2149+ Type subject = req.getFirstType ();
2150+ while (auto depMember = subject->getAs <DependentMemberType>()) {
2151+ subject = depMember->getBase ();
2152+ }
2153+
2154+ if (auto genericParam = subject->getAs <GenericTypeParamType>()) {
2155+ unsigned opaqueDepth = opaque->getOpaqueGenericParams ().front ()->getDepth ();
2156+ if (genericParam->getDepth () == opaqueDepth)
2157+ return proto;
2158+ }
2159+
2160+ return nullptr ;
2161+ }
2162+
21582163static void eraseExistingTypeContextDescriptor (IRGenModule &IGM,
21592164 NominalTypeDecl *type) {
21602165 // We may have emitted a partial type context descriptor with some empty
0 commit comments