@@ -1318,35 +1318,10 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
1318
1318
llvm_unreachable (" Cannot mangle free-standing archetypes" );
1319
1319
1320
1320
case TypeKind::OpaqueTypeArchetype: {
1321
- // If this is the opaque return type of the declaration currently being
1322
- // mangled, use a short mangling to represent it.
1323
1321
auto opaqueType = cast<OpaqueTypeArchetypeType>(tybase);
1324
1322
auto opaqueDecl = opaqueType->getDecl ();
1325
- if (opaqueDecl->getNamingDecl () == forDecl) {
1326
- assert (opaqueType->getSubstitutions ().isIdentity ());
1327
- if (opaqueType->getOrdinal () == 0 )
1328
- return appendOperator (" Qr" );
1329
-
1330
- return appendOperator (" QR" , Index (opaqueType->getOrdinal () - 1 ));
1331
- }
1332
-
1333
- // Otherwise, try to substitute it.
1334
- if (tryMangleTypeSubstitution (type, sig))
1335
- return ;
1336
-
1337
- // Use the fully elaborated explicit mangling.
1338
- appendOpaqueDeclName (opaqueDecl);
1339
- bool isFirstArgList = true ;
1340
- appendBoundGenericArgs (opaqueDecl, sig,
1341
- opaqueType->getSubstitutions (),
1342
- isFirstArgList, forDecl);
1343
- appendRetroactiveConformances (opaqueType->getSubstitutions (), sig,
1344
- opaqueDecl->getParentModule ());
1345
-
1346
- appendOperator (" Qo" , Index (opaqueType->getOrdinal ()));
1347
-
1348
- addTypeSubstitution (type, sig);
1349
- return ;
1323
+ return appendOpaqueTypeArchetype (
1324
+ opaqueType, opaqueDecl, opaqueType->getSubstitutions (), sig, forDecl);
1350
1325
}
1351
1326
1352
1327
case TypeKind::NestedArchetype: {
@@ -1356,16 +1331,9 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
1356
1331
// types, so that they can be accurately demangled at runtime.
1357
1332
if (auto opaque =
1358
1333
dyn_cast<OpaqueTypeArchetypeType>(nestedType->getRoot ())) {
1359
- if (tryMangleTypeSubstitution (nestedType, sig))
1360
- return ;
1361
-
1362
- appendType (opaque, sig, forDecl);
1363
- bool isAssocTypeAtDepth = false ;
1364
- appendAssocType (nestedType->getInterfaceType (),
1365
- sig, isAssocTypeAtDepth);
1366
- appendOperator (isAssocTypeAtDepth ? " QX" : " Qx" );
1367
- addTypeSubstitution (nestedType, sig);
1368
- return ;
1334
+ return appendOpaqueTypeArchetype (
1335
+ nestedType, opaque->getDecl (), opaque->getSubstitutions (), sig,
1336
+ forDecl);
1369
1337
}
1370
1338
1371
1339
// FIXME: Never actually used.
@@ -1958,6 +1926,51 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn,
1958
1926
appendOperator (" I" , StringRef (OpArgs.data (), OpArgs.size ()));
1959
1927
}
1960
1928
1929
+ void ASTMangler::appendOpaqueTypeArchetype (ArchetypeType *archetype,
1930
+ OpaqueTypeDecl *opaqueDecl,
1931
+ SubstitutionMap subs,
1932
+ GenericSignature sig,
1933
+ const ValueDecl *forDecl) {
1934
+ Type interfaceType = archetype->getInterfaceType ();
1935
+ auto genericParam = interfaceType->getAs <GenericTypeParamType>();
1936
+
1937
+ // If this is the opaque return type of the declaration currently being
1938
+ // mangled, use a short mangling to represent it.
1939
+ if (genericParam && opaqueDecl->getNamingDecl () == forDecl) {
1940
+ assert (subs.isIdentity ());
1941
+ if (genericParam->getIndex () == 0 )
1942
+ return appendOperator (" Qr" );
1943
+
1944
+ return appendOperator (" QR" , Index (genericParam->getIndex () - 1 ));
1945
+ }
1946
+
1947
+ // Otherwise, try to substitute it.
1948
+ if (tryMangleTypeSubstitution (Type (archetype), sig))
1949
+ return ;
1950
+
1951
+ // Mangling at the root, described by a generic parameter.
1952
+ if (genericParam) {
1953
+ // Use the fully elaborated explicit mangling.
1954
+ appendOpaqueDeclName (opaqueDecl);
1955
+ bool isFirstArgList = true ;
1956
+ appendBoundGenericArgs (opaqueDecl, sig, subs, isFirstArgList, forDecl);
1957
+ appendRetroactiveConformances (subs, sig, opaqueDecl->getParentModule ());
1958
+
1959
+ appendOperator (" Qo" , Index (genericParam->getIndex ()));
1960
+ } else {
1961
+ // Mangle associated types of opaque archetypes like dependent member
1962
+ // types, so that they can be accurately demangled at runtime.
1963
+ appendType (Type (archetype->getRoot ()), sig, forDecl);
1964
+ bool isAssocTypeAtDepth = false ;
1965
+ appendAssocType (
1966
+ archetype->getInterfaceType ()->castTo <DependentMemberType>(),
1967
+ sig, isAssocTypeAtDepth);
1968
+ appendOperator (isAssocTypeAtDepth ? " QX" : " Qx" );
1969
+ }
1970
+
1971
+ addTypeSubstitution (Type (archetype), sig);
1972
+ }
1973
+
1961
1974
Optional<ASTMangler::SpecialContext>
1962
1975
ASTMangler::getSpecialManglingContext (const ValueDecl *decl,
1963
1976
bool useObjCProtocolNames) {
0 commit comments