Exemplo n.º 1
0
static IRGenFunction::ArchetypeAccessPath
findAccessPathDeclaringConformance(IRGenFunction &IGF,
                                   CanArchetypeType archetype,
                                   ProtocolDecl *protocol) {
  // Consider all the associated type relationships we know about.

  // Use the archetype's parent relationship first if possible.
  if (!archetype->isPrimary()) {
    auto parent = archetype.getParent();
    auto association =
      findConformanceDeclaration(parent->getConformsTo(),
                                 archetype->getAssocType(), protocol);
    if (association) return { parent, association };
  }

  for (auto accessPath : IGF.getArchetypeAccessPaths(archetype)) {
    auto association =
      findConformanceDeclaration(accessPath.BaseType->getConformsTo(),
                                 accessPath.Association, protocol);
    if (association) return { accessPath.BaseType, association };
  }

  llvm_unreachable("no relation found that declares conformance to target");
}