@@ -1958,37 +1958,50 @@ class DecodedMetadataBuilder {
1958
1958
return BuiltType ();
1959
1959
#endif
1960
1960
1961
- // FIXME: variadic-generics
1962
-
1963
1961
auto swiftProtocol = protocol.getSwiftProtocol ();
1964
- auto witnessTable = swift_conformsToProtocol (base.getMetadata (), swiftProtocol);
1965
- if (!witnessTable)
1966
- return BuiltType ();
1967
1962
1968
1963
// Look for the named associated type within the protocol.
1969
1964
auto assocType = findAssociatedTypeByName (swiftProtocol, name);
1970
1965
if (!assocType) return BuiltType ();
1971
1966
1972
- // Call the associated type access function.
1973
- #if SWIFT_STDLIB_USE_RELATIVE_PROTOCOL_WITNESS_TABLES
1974
- auto tbl = reinterpret_cast <RelativeWitnessTable *>(
1975
- const_cast <WitnessTable *>(witnessTable));
1976
- return BuiltType (
1977
- swift_getAssociatedTypeWitnessRelative (
1978
- MetadataState::Abstract,
1979
- tbl,
1980
- base.getMetadata (),
1981
- swiftProtocol->getRequirementBaseDescriptor (),
1982
- *assocType));
1983
- #else
1984
- return BuiltType (
1985
- swift_getAssociatedTypeWitness (
1986
- MetadataState::Abstract,
1987
- const_cast <WitnessTable *>(witnessTable),
1988
- base.getMetadata (),
1989
- swiftProtocol->getRequirementBaseDescriptor (),
1990
- *assocType));
1991
- #endif
1967
+ auto projectDependentMemberType = [&](const Metadata *baseMetadata) -> const Metadata * {
1968
+ auto witnessTable = swift_conformsToProtocol (baseMetadata, swiftProtocol);
1969
+ if (!witnessTable)
1970
+ return nullptr ;
1971
+
1972
+ // Call the associated type access function.
1973
+ #if SWIFT_STDLIB_USE_RELATIVE_PROTOCOL_WITNESS_TABLES
1974
+ auto tbl = reinterpret_cast <RelativeWitnessTable *>(
1975
+ const_cast <WitnessTable *>(witnessTable));
1976
+ return swift_getAssociatedTypeWitnessRelative (
1977
+ MetadataState::Abstract,
1978
+ tbl,
1979
+ baseMetadata,
1980
+ swiftProtocol->getRequirementBaseDescriptor (),
1981
+ *assocType).Value ;
1982
+ #else
1983
+ return swift_getAssociatedTypeWitness (
1984
+ MetadataState::Abstract,
1985
+ const_cast <WitnessTable *>(witnessTable),
1986
+ baseMetadata,
1987
+ swiftProtocol->getRequirementBaseDescriptor (),
1988
+ *assocType).Value ;
1989
+ #endif
1990
+ };
1991
+
1992
+ if (base.isMetadata ()) {
1993
+ return BuiltType (projectDependentMemberType (base.getMetadata ()));
1994
+ } else {
1995
+ MetadataPackPointer basePack = base.getMetadataPack ();
1996
+
1997
+ llvm::SmallVector<const Metadata *, 4 > packElts;
1998
+ for (size_t i = 0 , e = basePack.getNumElements (); i < e; ++i) {
1999
+ auto *projectedElt = projectDependentMemberType (basePack.getElements ()[i]);
2000
+ packElts.push_back (projectedElt);
2001
+ }
2002
+
2003
+ return BuiltType (swift_allocateMetadataPack (packElts.data (), packElts.size ()));
2004
+ }
1992
2005
}
1993
2006
1994
2007
#define REF_STORAGE (Name, ...) \
0 commit comments