@@ -659,6 +659,10 @@ Type GenericEnvironment::mapTypeIntoContext(GenericTypeParamType *type) const {
659
659
return result;
660
660
}
661
661
662
+ // / So this expects a type written with the archetypes of the original generic
663
+ // / environment, not 'this', the opened element environment, because it is the
664
+ // / original PackArchetypes that become ElementArchetypes. Also this function
665
+ // / does not apply outer substitutions, which might not be what you expect.
662
666
Type
663
667
GenericEnvironment::mapContextualPackTypeIntoElementContext (Type type) const {
664
668
assert (getKind () == Kind::OpenedElement);
@@ -689,41 +693,23 @@ GenericEnvironment::mapContextualPackTypeIntoElementContext(CanType type) const
689
693
return CanType (mapContextualPackTypeIntoElementContext (Type (type)));
690
694
}
691
695
696
+ // / Unlike mapContextualPackTypeIntoElementContext(), this also applies outer
697
+ // / substitutions, so it behaves like mapTypeIntoContext() in that respect.
692
698
Type
693
699
GenericEnvironment::mapPackTypeIntoElementContext (Type type) const {
694
700
assert (getKind () == Kind::OpenedElement);
695
701
assert (!type->hasArchetype ());
696
702
697
- auto sig = getGenericSignature ();
698
- auto shapeClass = getOpenedElementShapeClass ();
699
-
700
- FindElementArchetypeForOpenedPackParam
701
- findElementArchetype (this , getOpenedPackParams ());
702
-
703
- // Map the interface type to the element type by stripping
704
- // away the isParameterPack bit before mapping type parameters
705
- // to archetypes.
706
- return type.transformRec ([&](TypeBase *ty) -> llvm::Optional<Type> {
707
- // We're only directly substituting pack parameters.
708
- if (!ty->isTypeParameter ()) {
709
- // Don't recurse into nested pack expansions; just map it into
710
- // context.
711
- if (ty->is <PackExpansionType>())
712
- return mapTypeIntoContext (ty);
713
-
714
- // Recurse into any other type.
715
- return llvm::None;
716
- }
703
+ if (!type->hasTypeParameter ()) return type;
717
704
718
- // Just do normal mapping for types that are not rooted in
719
- // opened type parameters.
720
- auto rootParam = ty->getRootGenericParam ();
721
- if (!rootParam->isParameterPack () ||
722
- !sig->haveSameShape (rootParam, shapeClass))
723
- return mapTypeIntoContext (ty);
705
+ // Get a contextual type in the original generic environment, not the
706
+ // substituted one, which is what mapContextualPackTypeIntoElementContext()
707
+ // expects.
708
+ auto contextualType = getPackElementContextSubstitutions ()
709
+ .getGenericSignature ().getGenericEnvironment ()->mapTypeIntoContext (type);
724
710
725
- return Type ( findElementArchetype (ty) );
726
- } );
711
+ contextualType = mapContextualPackTypeIntoElementContext (contextualType );
712
+ return maybeApplyOuterContextSubstitutions (contextualType );
727
713
}
728
714
729
715
Type
0 commit comments