@@ -347,46 +347,19 @@ GenericSignature ProtocolConformance::getGenericSignature() const {
347
347
}
348
348
349
349
SubstitutionMap ProtocolConformance::getSubstitutions (ModuleDecl *M) const {
350
- // Walk down to the base NormalProtocolConformance.
351
- SubstitutionMap subMap;
352
- const ProtocolConformance *parent = this ;
353
- while (!isa<RootProtocolConformance>(parent)) {
354
- switch (parent->getKind ()) {
355
- case ProtocolConformanceKind::Normal:
356
- case ProtocolConformanceKind::Self:
357
- case ProtocolConformanceKind::Builtin:
358
- llvm_unreachable (" should have exited the loop?!" );
359
- case ProtocolConformanceKind::Inherited:
360
- parent =
361
- cast<InheritedProtocolConformance>(parent)->getInheritedConformance ();
362
- break ;
363
- case ProtocolConformanceKind::Specialized: {
364
- auto SC = cast<SpecializedProtocolConformance>(parent);
365
- parent = SC->getGenericConformance ();
366
- assert (subMap.empty () && " multiple conformance specializations?!" );
367
- subMap = SC->getSubstitutionMap ();
368
- break ;
369
- }
370
- }
371
- }
350
+ const ProtocolConformance *conformance = this ;
372
351
373
- // Found something; we're done!
374
- if (!subMap.empty ())
375
- return subMap;
352
+ if (auto *inheritedC = dyn_cast<InheritedProtocolConformance>(conformance))
353
+ conformance = inheritedC->getInheritedConformance ();
376
354
377
- // If the normal conformance is for a generic type, and we didn't hit a
378
- // specialized conformance, collect the substitutions from the generic type.
379
- // FIXME: The AST should do this for us.
380
- const NormalProtocolConformance *normalC =
381
- dyn_cast<NormalProtocolConformance>(parent);
382
- if (!normalC)
383
- return SubstitutionMap ();
355
+ if (auto *specializedC = dyn_cast<SpecializedProtocolConformance>(conformance))
356
+ return specializedC->getSubstitutionMap ();
384
357
385
- if (!normalC->getType ()->isSpecialized ())
386
- return SubstitutionMap ();
358
+ auto *rootC = cast<RootProtocolConformance>(conformance);
359
+ if (auto genericSig = rootC->getGenericSignature ())
360
+ return genericSig->getIdentitySubstitutionMap ();
387
361
388
- auto *DC = normalC->getDeclContext ();
389
- return normalC->getType ()->getContextSubstitutionMap (M, DC);
362
+ return SubstitutionMap ();
390
363
}
391
364
392
365
bool RootProtocolConformance::isInvalid () const {
0 commit comments