@@ -2240,6 +2240,138 @@ ASTMangler::appendProtocolConformance(const ProtocolConformance *conformance) {
2240
2240
}
2241
2241
}
2242
2242
2243
+ void ASTMangler::appendProtocolConformanceRef (
2244
+ const NormalProtocolConformance *conformance) {
2245
+ // FIXME: Symbolic reference to the protocol conformance descriptor.
2246
+ appendProtocolName (conformance->getProtocol ());
2247
+
2248
+ // For retroactive conformances, add a reference to the module in which the
2249
+ // conformance resides. For @objc protocols, there is no point: conformances
2250
+ // are global anyway.
2251
+ if (conformance->isRetroactive () && !conformance->isSynthesizedNonUnique () &&
2252
+ !conformance->getProtocol ()->isObjC ())
2253
+ appendModule (conformance->getDeclContext ()->getParentModule ());
2254
+ }
2255
+
2256
+ // / Retrieve the index of the conformance requirement indicated by the
2257
+ // / conformance access path entry within the given set of requirements.
2258
+ static unsigned conformanceRequirementIndex (
2259
+ const ConformanceAccessPath::Entry &entry,
2260
+ ArrayRef<Requirement> requirements) {
2261
+ unsigned result = 0 ;
2262
+ for (const auto &req : requirements) {
2263
+ if (req.getKind () != RequirementKind::Conformance)
2264
+ continue ;
2265
+
2266
+ if (req.getFirstType ()->isEqual (entry.first ) &&
2267
+ req.getSecondType ()->castTo <ProtocolType>()->getDecl () == entry.second )
2268
+ return result;
2269
+
2270
+ ++result;
2271
+ }
2272
+
2273
+ llvm_unreachable (" Conformance access path step is missing from requirements" );
2274
+ }
2275
+
2276
+ void ASTMangler::appendDependentProtocolConformance (
2277
+ const ConformanceAccessPath &path) {
2278
+ ProtocolDecl *currentProtocol = nullptr ;
2279
+ for (const auto &entry : path) {
2280
+ // After each step, update the current protocol to refer to where we
2281
+ // are.
2282
+ SWIFT_DEFER {
2283
+ currentProtocol = entry.second ;
2284
+ };
2285
+
2286
+ // The first entry is the "root". Find this requirement in the generic
2287
+ // signature.
2288
+ if (!currentProtocol) {
2289
+ appendType (entry.first );
2290
+ appendProtocolName (entry.second );
2291
+ auto index =
2292
+ conformanceRequirementIndex (entry,
2293
+ CurGenericSignature->getRequirements ());
2294
+ appendOperator (" HD" , index + 1 );
2295
+ continue ;
2296
+ }
2297
+
2298
+ // Conformances are relative to the current protocol's requirement
2299
+ // signature.
2300
+ auto index =
2301
+ conformanceRequirementIndex (entry,
2302
+ currentProtocol->getRequirementSignature ());
2303
+
2304
+ // Inherited conformance.
2305
+ bool isInheritedConformance =
2306
+ entry.first ->isEqual (currentProtocol->getProtocolSelfType ());
2307
+ if (isInheritedConformance) {
2308
+ appendProtocolName (entry.second );
2309
+ appendOperator (" HI" , index + 1 );
2310
+ continue ;
2311
+ }
2312
+
2313
+ // Associated conformance.
2314
+ // FIXME: Symbolic reference.
2315
+ appendType (entry.first );
2316
+ appendProtocolName (entry.second );
2317
+
2318
+ // For non-resilient protocols, encode the index.
2319
+ bool isResilient =
2320
+ currentProtocol->isResilient (Mod, ResilienceExpansion::Maximal);
2321
+ appendOperator (" HA" , isResilient ? 0 : index + 1 );
2322
+ }
2323
+ }
2324
+
2325
+ void ASTMangler::appendConcreteProtocolConformance (
2326
+ const ProtocolConformance *conformance) {
2327
+ auto module = conformance->getDeclContext ()->getParentModule ();
2328
+
2329
+ // Conforming type.
2330
+ Type conformingType = conformance->getType ();
2331
+ if (conformingType->hasArchetype ())
2332
+ conformingType = conformingType->mapTypeOutOfContext ();
2333
+ appendType (conformingType->getCanonicalType ());
2334
+
2335
+ // Protocol conformance reference.
2336
+ appendProtocolConformanceRef (conformance->getRootNormalConformance ());
2337
+
2338
+ // Conditional conformance requirements.
2339
+ bool firstRequirement = true ;
2340
+ for (const auto &conditionalReq : conformance->getConditionalRequirements ()) {
2341
+ switch (conditionalReq.getKind ()) {
2342
+ case RequirementKind::Layout:
2343
+ case RequirementKind::SameType:
2344
+ case RequirementKind::Superclass:
2345
+ continue ;
2346
+
2347
+ case RequirementKind::Conformance: {
2348
+ auto type = conditionalReq.getFirstType ();
2349
+ if (type->hasArchetype ())
2350
+ type = type->mapTypeOutOfContext ();
2351
+ CanType canType = type->getCanonicalType (CurGenericSignature);
2352
+ auto proto =
2353
+ conditionalReq.getSecondType ()->castTo <ProtocolType>()->getDecl ();
2354
+ if (canType->isTypeParameter ()) {
2355
+ assert (CurGenericSignature &&
2356
+ " Need a generic signature to resolve conformance" );
2357
+ auto conformanceAccessPath =
2358
+ CurGenericSignature->getConformanceAccessPath (type, proto);
2359
+ appendDependentProtocolConformance (conformanceAccessPath);
2360
+ } else {
2361
+ auto conditionalConf = module ->lookupConformance (canType, proto);
2362
+ appendConcreteProtocolConformance (conditionalConf->getConcrete ());
2363
+ }
2364
+ appendListSeparator (firstRequirement);
2365
+ break ;
2366
+ }
2367
+ }
2368
+ }
2369
+ if (firstRequirement)
2370
+ appendOperator (" y" );
2371
+
2372
+ appendOperator (" HC" );
2373
+ }
2374
+
2243
2375
void ASTMangler::appendOpParamForLayoutConstraint (LayoutConstraint layout) {
2244
2376
assert (layout);
2245
2377
switch (layout->getKind ()) {
0 commit comments