@@ -811,79 +811,41 @@ void writeAttrInformation(llvm::json::OStream &JSON,
811811 });
812812}
813813
814- void writeParameterizedProtocolSameTypeRequirements (
815- llvm::json::OStream &JSON,
816- const ParameterizedProtocolType &ParameterizedProtoTy) {
817- auto Protocol = ParameterizedProtoTy.getProtocol ();
818- auto ProtocolTy = ParameterizedProtoTy.getBaseType ();
819- auto Requirements = Protocol->getProtocolRequirements ();
820- auto ParameterTypeNames = Protocol->getPrimaryAssociatedTypeNames ();
821- auto ProtocolArguments = ParameterizedProtoTy.getArgs ();
822- llvm::dbgs () << Requirements.size () << " \n " ;
823- assert (ProtocolArguments.size () >= ParameterTypeNames.size ());
824-
825- for (size_t i = 0 ; i < ProtocolArguments.size (); ++i) {
826- auto ProtocolArgumentTy = ProtocolArguments[i];
827- std::string ArgumentName = ParameterTypeNames.size () > i
828- ? ParameterTypeNames[i].first .str ().str ()
829- : " unknown" ;
830-
831- JSON.object ([&] {
832- auto QualifiedTypeAliasName = toFullyQualifiedProtocolNameString (
833- *ParameterizedProtoTy.getProtocol ()) +
834- " ." + ArgumentName;
835- JSON.attribute (" typeAliasName" , QualifiedTypeAliasName);
836- JSON.attribute (" substitutedTypeName" ,
837- toFullyQualifiedTypeNameString (ProtocolArgumentTy));
838- JSON.attribute (" substitutedMangledTypeName" ,
839- toMangledTypeNameString (ProtocolArgumentTy));
840- });
841- }
842- }
843-
844- void writeOpaqueTypeProtocolCompositionSameTypeRequirements (
845- llvm::json::OStream &JSON,
846- const ProtocolCompositionType &ProtocolCompositionTy) {
847- for (auto CompositionMemberProto : ProtocolCompositionTy.getMembers ()) {
848- if (auto ParameterizedProtoTy =
849- CompositionMemberProto->getAs <ParameterizedProtocolType>()) {
850- writeParameterizedProtocolSameTypeRequirements (JSON,
851- *ParameterizedProtoTy);
852- }
853- }
854- }
855-
856814void writeSubstitutedOpaqueTypeAliasDetails (
857815 llvm::json::OStream &JSON, const OpaqueTypeArchetypeType &OpaqueTy) {
816+ auto Signature = OpaqueTy.getDecl ()->getOpaqueInterfaceGenericSignature ();
817+
858818 JSON.attributeArray (" opaqueTypeProtocolRequirements" , [&] {
859- auto ConformsToProtocols = OpaqueTy.getConformsTo ();
860- for (auto Proto : ConformsToProtocols) {
861- JSON.value (toFullyQualifiedProtocolNameString (*Proto));
819+ for (const auto Requirement : Signature.getRequirements ()) {
820+ // Ignore requirements whose subject type is that of the owner decl
821+ if (!Requirement.getFirstType ()->isEqual (OpaqueTy.getInterfaceType ()))
822+ continue ;
823+ if (Requirement.getKind () == RequirementKind::Conformance)
824+ JSON.value (
825+ toFullyQualifiedProtocolNameString (*Requirement.getProtocolDecl ()));
862826 }
863827 });
828+
864829 JSON.attributeArray (" opaqueTypeSameTypeRequirements" , [&] {
865- auto GenericSig = OpaqueTy.getDecl ()
866- ->getNamingDecl ()
867- ->getInnermostDeclContext ()
868- ->getGenericSignatureOfContext ();
869- auto ConstraintTy = OpaqueTy.getExistentialType ();
870- if (auto existential = ConstraintTy->getAs <ExistentialType>())
871- ConstraintTy = existential->getConstraintType ();
872-
873- // Opaque archetype substitutions are always canonical, so
874- // re-sugar the constraint type using the owning
875- // declaration's generic parameter names.
876- if (GenericSig)
877- ConstraintTy = GenericSig->getSugaredType (ConstraintTy);
878-
879- if (auto ParameterizedProtoTy =
880- ConstraintTy->getAs <ParameterizedProtocolType>()) {
881- writeParameterizedProtocolSameTypeRequirements (JSON,
882- *ParameterizedProtoTy);
883- } else if (auto ProtocolCompositionTy =
884- ConstraintTy->getAs <ProtocolCompositionType>()) {
885- writeOpaqueTypeProtocolCompositionSameTypeRequirements (
886- JSON, *ProtocolCompositionTy);
830+ for (const auto Requirement : Signature.getRequirements ()) {
831+ if (Requirement.getKind () == RequirementKind::SameType) {
832+ auto TypeAliasType = Requirement.getFirstType ();
833+ auto TypeWitness = Requirement.getSecondType ();
834+ JSON.object ([&] {
835+ auto TypeAliasName = toFullyQualifiedTypeNameString (TypeAliasType);
836+ if (auto DependentMemberTy =
837+ TypeAliasType->getAs <DependentMemberType>())
838+ if (const auto *Assoc = DependentMemberTy->getAssocType ())
839+ TypeAliasName =
840+ toFullyQualifiedProtocolNameString (*Assoc->getProtocol ()) +
841+ " ." + DependentMemberTy->getName ().str ().str ();
842+ JSON.attribute (" typeAliasName" , TypeAliasName);
843+ JSON.attribute (" substitutedTypeName" ,
844+ toFullyQualifiedTypeNameString (TypeWitness));
845+ JSON.attribute (" substitutedMangledTypeName" ,
846+ toMangledTypeNameString (TypeWitness));
847+ });
848+ }
887849 }
888850 });
889851}
0 commit comments