@@ -3304,6 +3304,63 @@ SequenceArchetypeType::SequenceArchetypeType(
33043304 assert (cast<GenericTypeParamType>(InterfaceType.getPointer ())->isTypeSequence ());
33053305}
33063306
3307+ namespace {
3308+
3309+ // / Substitute the outer generic parameters from a substitution map, ignoring
3310+ // / innter generic parameters with a given depth.
3311+ struct SubstituteOuterFromSubstitutionMap {
3312+ SubstitutionMap subs;
3313+ unsigned depth;
3314+
3315+ // / Whether this is a type parameter that should not be substituted.
3316+ bool isUnsubstitutedTypeParameter (Type type) const {
3317+ if (!type->isTypeParameter ())
3318+ return false ;
3319+
3320+ if (auto depMemTy = type->getAs <DependentMemberType>())
3321+ return isUnsubstitutedTypeParameter (depMemTy->getBase ());
3322+
3323+ if (auto genericParam = type->getAs <GenericTypeParamType>())
3324+ return genericParam->getDepth () >= depth;
3325+
3326+ return false ;
3327+ }
3328+
3329+ Type operator ()(SubstitutableType *type) const {
3330+ if (isUnsubstitutedTypeParameter (type))
3331+ return Type (type);
3332+
3333+ return QuerySubstitutionMap{subs}(type);
3334+ }
3335+
3336+ ProtocolConformanceRef operator ()(CanType dependentType,
3337+ Type conformingReplacementType,
3338+ ProtocolDecl *conformedProtocol) const {
3339+ if (isUnsubstitutedTypeParameter (dependentType))
3340+ return ProtocolConformanceRef (conformedProtocol);
3341+
3342+ return LookUpConformanceInSubstitutionMap (subs)(
3343+ dependentType, conformingReplacementType, conformedProtocol);
3344+ }
3345+ };
3346+
3347+ }
3348+
3349+ CanType OpaqueTypeArchetypeType::getCanonicalInterfaceType (Type interfaceType) {
3350+ // Compute the canonical type within the generic signature of the opaque
3351+ // type declaration.
3352+ auto sig = getDecl ()->getOpaqueInterfaceGenericSignature ();
3353+ CanType canonicalType = interfaceType->getCanonicalType (sig);
3354+ if (!interfaceType->hasTypeParameter ())
3355+ return canonicalType;
3356+
3357+ // Substitute outer generic parameters only.
3358+ unsigned opaqueDepth =
3359+ getDecl ()->getOpaqueGenericParams ().front ()->getDepth ();
3360+ SubstituteOuterFromSubstitutionMap replacer{Substitutions, opaqueDepth};
3361+ return canonicalType.subst (replacer, replacer)->getCanonicalType ();
3362+ }
3363+
33073364GenericEnvironment *OpaqueTypeArchetypeType::getGenericEnvironment () const {
33083365 if (Environment)
33093366 return Environment;
0 commit comments