@@ -5460,6 +5460,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
54605460 } else if (auto archetype = dyn_cast<ArchetypeType>(T.getPointer ())) {
54615461 if (archetype->isParameterPack () && Options.PrintExplicitEach )
54625462 return false ;
5463+ if (Options.PrintForSIL && isa<LocalArchetypeType>(archetype))
5464+ return false ;
54635465 }
54645466 return T->hasSimpleTypeRepr ();
54655467 }
@@ -6621,12 +6623,58 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
66216623 }
66226624 }
66236625
6626+ static Type findPackForElementArchetype (ElementArchetypeType *T) {
6627+ // The type in @pack_element is looked up in the generic params
6628+ // of the identified open_pack_element instruction. The param list
6629+ // is long gone, but the sugar survives in the type parameters of
6630+ // the generic signature of the contextual substitution map in the
6631+ // opened element environment.
6632+ auto env = T->getGenericEnvironment ();
6633+ auto subs = env->getPackElementContextSubstitutions ();
6634+ auto sig = subs.getGenericSignature ();
6635+ auto params = sig.getGenericParams ();
6636+
6637+ auto elementShapeClass =
6638+ env->getOpenedElementShapeClass ()->mapTypeOutOfContext ();
6639+
6640+ // The element archetypes are at a depth one past the max depth
6641+ // of the base signature.
6642+ unsigned elementDepth = params.back ()->getDepth () + 1 ;
6643+
6644+ // Transform the archetype's interface type to be based on the
6645+ // corresponding non-canonical type parameter.
6646+ auto interfaceType = T->getInterfaceType ();
6647+ return interfaceType.subst ([&](SubstitutableType *type) -> Type {
6648+ // Don't transform types that aren't element type parameters.
6649+ auto *elementParam = type->getAs <GenericTypeParamType>();
6650+ if (!elementParam || elementParam->getDepth () != elementDepth)
6651+ return Type ();
6652+
6653+ // Loop through the type parameters looking for the type parameter
6654+ // pack at the appropriate index. We only expect to actually do
6655+ // this once for each type, so it's fine to do it in the callback.
6656+ unsigned nextIndex = 0 ;
6657+ for (auto *genericParam : params) {
6658+ if (!genericParam->isParameterPack ())
6659+ continue ;
6660+
6661+ if (!sig->haveSameShape (genericParam, elementShapeClass))
6662+ continue ;
6663+
6664+ if (nextIndex == elementParam->getIndex ())
6665+ return genericParam;
6666+ nextIndex++;
6667+ }
6668+ llvm_unreachable (" ran out of type parameters" );
6669+ return Type ();
6670+ }, LookUpConformanceInSignature (sig.getPointer ()));
6671+ }
6672+
66246673 void visitElementArchetypeType (ElementArchetypeType *T) {
66256674 if (Options.PrintForSIL ) {
6626- Printer << " @element(\" " << T->getOpenedElementID () << " ) " ;
6627-
6628- auto interfaceTy = T->getInterfaceType ();
6629- visit (interfaceTy);
6675+ Printer << " @pack_element(\" " << T->getOpenedElementID () << " \" ) " ;
6676+ auto packTy = findPackForElementArchetype (T);
6677+ visit (packTy);
66306678 } else {
66316679 visit (T->getInterfaceType ());
66326680 }
0 commit comments