@@ -811,78 +811,41 @@ void writeAttrInformation(llvm::json::OStream &JSON,
811
811
});
812
812
}
813
813
814
- void writeParameterizedProtocolSameTypeRequirements (
815
- llvm::json::OStream &JSON,
816
- const ParameterizedProtocolType &ParameterizedProtoTy) {
817
- auto Protocol = ParameterizedProtoTy.getProtocol ();
818
- auto Requirements = Protocol->getProtocolRequirements ();
819
- auto ParameterTypeNames = Protocol->getPrimaryAssociatedTypeNames ();
820
- auto ProtocolArguments = ParameterizedProtoTy.getArgs ();
821
- llvm::dbgs () << Requirements.size () << " \n " ;
822
- assert (ProtocolArguments.size () >= ParameterTypeNames.size ());
823
-
824
- for (size_t i = 0 ; i < ProtocolArguments.size (); ++i) {
825
- auto ProtocolArgumentTy = ProtocolArguments[i];
826
- std::string ArgumentName = ParameterTypeNames.size () > i
827
- ? ParameterTypeNames[i].first .str ().str ()
828
- : " unknown" ;
829
-
830
- JSON.object ([&] {
831
- auto QualifiedTypeAliasName = toFullyQualifiedProtocolNameString (
832
- *ParameterizedProtoTy.getProtocol ()) +
833
- " ." + ArgumentName;
834
- JSON.attribute (" typeAliasName" , QualifiedTypeAliasName);
835
- JSON.attribute (" substitutedTypeName" ,
836
- toFullyQualifiedTypeNameString (ProtocolArgumentTy));
837
- JSON.attribute (" substitutedMangledTypeName" ,
838
- toMangledTypeNameString (ProtocolArgumentTy));
839
- });
840
- }
841
- }
842
-
843
- void writeOpaqueTypeProtocolCompositionSameTypeRequirements (
844
- llvm::json::OStream &JSON,
845
- const ProtocolCompositionType &ProtocolCompositionTy) {
846
- for (auto CompositionMemberProto : ProtocolCompositionTy.getMembers ()) {
847
- if (auto ParameterizedProtoTy =
848
- CompositionMemberProto->getAs <ParameterizedProtocolType>()) {
849
- writeParameterizedProtocolSameTypeRequirements (JSON,
850
- *ParameterizedProtoTy);
851
- }
852
- }
853
- }
854
-
855
814
void writeSubstitutedOpaqueTypeAliasDetails (
856
815
llvm::json::OStream &JSON, const OpaqueTypeArchetypeType &OpaqueTy) {
816
+ auto Signature = OpaqueTy.getDecl ()->getOpaqueInterfaceGenericSignature ();
817
+
857
818
JSON.attributeArray (" opaqueTypeProtocolRequirements" , [&] {
858
- auto ConformsToProtocols = OpaqueTy.getConformsTo ();
859
- for (auto Proto : ConformsToProtocols) {
860
- 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 ()));
861
826
}
862
827
});
828
+
863
829
JSON.attributeArray (" opaqueTypeSameTypeRequirements" , [&] {
864
- auto GenericSig = OpaqueTy.getDecl ()
865
- ->getNamingDecl ()
866
- ->getInnermostDeclContext ()
867
- ->getGenericSignatureOfContext ();
868
- auto ConstraintTy = OpaqueTy.getExistentialType ();
869
- if (auto existential = ConstraintTy->getAs <ExistentialType>())
870
- ConstraintTy = existential->getConstraintType ();
871
-
872
- // Opaque archetype substitutions are always canonical, so
873
- // re-sugar the constraint type using the owning
874
- // declaration's generic parameter names.
875
- if (GenericSig)
876
- ConstraintTy = GenericSig->getSugaredType (ConstraintTy);
877
-
878
- if (auto ParameterizedProtoTy =
879
- ConstraintTy->getAs <ParameterizedProtocolType>()) {
880
- writeParameterizedProtocolSameTypeRequirements (JSON,
881
- *ParameterizedProtoTy);
882
- } else if (auto ProtocolCompositionTy =
883
- ConstraintTy->getAs <ProtocolCompositionType>()) {
884
- writeOpaqueTypeProtocolCompositionSameTypeRequirements (
885
- 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
+ }
886
849
}
887
850
});
888
851
}
0 commit comments