@@ -234,11 +234,15 @@ std::string typeUSR(Type type) {
234
234
return " " ;
235
235
236
236
if (type->hasArchetype ()) {
237
- // We can't generate USRs for types that contain archetypes. Replace them
238
- // with their interface types.
237
+ type = type->mapTypeOutOfContext ();
238
+ }
239
+ if (type->hasLocalArchetype ()) {
240
+ // If we have local archetypes, we can't mangle those. Replace them with
241
+ // their existential upper bounds, which loses information but is probably
242
+ // close enough for most purposes.
239
243
type = type.transformRec ([&](TypeBase *t) -> std::optional<Type> {
240
- if (auto AT = dyn_cast<ArchetypeType >(t)) {
241
- return AT-> getInterfaceType ();
244
+ if (auto LAT = dyn_cast<LocalArchetypeType >(t)) {
245
+ return LAT-> getExistentialType ();
242
246
}
243
247
return std::nullopt;
244
248
});
@@ -1270,11 +1274,25 @@ namespace {
1270
1274
1271
1275
printField (requirement.getKind (), Label::optional (" kind" ));
1272
1276
1273
- if (requirement.getKind () != RequirementKind::Layout
1274
- && requirement.getSecondType ())
1275
- printTypeField (requirement.getSecondType (),
1276
- Label::optional (" second_type" ), opts);
1277
- else if (requirement.getLayoutConstraint ())
1277
+ if (requirement.getKind () != RequirementKind::Layout &&
1278
+ requirement.getSecondType ()) {
1279
+ if (Writer.isParsable ()) {
1280
+ // If this is a conformance requirement, print the USR of the protocol
1281
+ // decl instead of the type. The type USR for a protocol is based on
1282
+ // the equivalent expanded existential, which drops suppressed
1283
+ // protocols.
1284
+ if (requirement.getKind () == RequirementKind::Conformance) {
1285
+ printReferencedDeclField (requirement.getProtocolDecl (),
1286
+ Label::optional (" protocol" ));
1287
+ } else {
1288
+ printTypeField (requirement.getSecondType (),
1289
+ Label::optional (" second_type" ), opts);
1290
+ }
1291
+ } else {
1292
+ printTypeField (requirement.getSecondType (),
1293
+ Label::optional (" second_type" ), opts);
1294
+ }
1295
+ } else if (requirement.getLayoutConstraint ())
1278
1296
printFieldQuoted (requirement.getLayoutConstraint (),
1279
1297
Label::optional (" layout" ));
1280
1298
@@ -1925,6 +1943,62 @@ namespace {
1925
1943
}
1926
1944
}
1927
1945
1946
+ void printInheritance (const IterableDeclContext *DC) {
1947
+ if (!(Writer.isParsable () && isTypeChecked ())) {
1948
+ // If the output is not parsable or we're not type-checked, just print
1949
+ // the inheritance list as written.
1950
+ switch (DC->getIterableContextKind ()) {
1951
+ case IterableDeclContextKind::NominalTypeDecl:
1952
+ printInherited (cast<NominalTypeDecl>(DC)->getInherited ());
1953
+ break ;
1954
+ case IterableDeclContextKind::ExtensionDecl:
1955
+ printInherited (cast<ExtensionDecl>(DC)->getInherited ());
1956
+ break ;
1957
+ }
1958
+ return ;
1959
+ }
1960
+
1961
+ // For parsable, type-checked output, print a more structured
1962
+ // representation of the data.
1963
+ printRecArbitrary (
1964
+ [&](Label label) {
1965
+ printHead (" inheritance" , FieldLabelColor, label);
1966
+
1967
+ SmallPtrSet<const ProtocolConformance *, 4 > dumped;
1968
+ printList (
1969
+ DC->getLocalConformances (),
1970
+ [&](auto conformance, Label label) {
1971
+ printRec (conformance, dumped, label);
1972
+ },
1973
+ Label::always (" conformances" ));
1974
+
1975
+ if (auto CD = dyn_cast<ClassDecl>(DC); CD && CD->hasSuperclass ()) {
1976
+ printReferencedDeclField (CD->getSuperclassDecl (),
1977
+ Label::always (" superclass_decl_usr" ));
1978
+ }
1979
+
1980
+ if (auto ED = dyn_cast<EnumDecl>(DC); ED && ED->hasRawType ()) {
1981
+ printTypeField (ED->getRawType (), Label::always (" raw_type" ));
1982
+ }
1983
+
1984
+ if (auto PD = dyn_cast<ProtocolDecl>(DC)) {
1985
+ printList (
1986
+ PD->getAllInheritedProtocols (),
1987
+ [&](auto inherited, Label label) {
1988
+ printReferencedDeclField (inherited, label);
1989
+ },
1990
+ Label::always (" protocols" ));
1991
+ if (PD->hasSuperclass ()) {
1992
+ printReferencedDeclField (PD->getSuperclassDecl (),
1993
+ Label::always (" superclass_decl_usr" ));
1994
+ }
1995
+ }
1996
+
1997
+ printFoot ();
1998
+ },
1999
+ Label::always (" inherits" ));
2000
+ }
2001
+
1928
2002
void printInherited (InheritedTypes Inherited) {
1929
2003
if (Writer.isParsable ()) {
1930
2004
printList (
@@ -2260,13 +2334,13 @@ namespace {
2260
2334
switch (IDC->getIterableContextKind ()) {
2261
2335
case IterableDeclContextKind::NominalTypeDecl: {
2262
2336
const auto NTD = cast<NominalTypeDecl>(IDC);
2263
- printInherited (NTD-> getInherited () );
2337
+ printInheritance (NTD);
2264
2338
printWhereRequirements (NTD);
2265
2339
break ;
2266
2340
}
2267
2341
case IterableDeclContextKind::ExtensionDecl:
2268
2342
const auto ED = cast<ExtensionDecl>(IDC);
2269
- printInherited (ED-> getInherited () );
2343
+ printInheritance (ED);
2270
2344
printWhereRequirements (ED);
2271
2345
break ;
2272
2346
}
@@ -5765,27 +5839,33 @@ class PrintConformance : public PrintBase {
5765
5839
5766
5840
void PrintBase::printRec (SubstitutionMap map, VisitedConformances &visited,
5767
5841
Label label) {
5768
- printRecArbitrary ([&](Label label) {
5769
- PrintConformance (Writer)
5770
- .visitSubstitutionMap (map, SubstitutionMap::DumpStyle::Full, visited,
5771
- label);
5772
- }, label);
5842
+ printRecArbitrary (
5843
+ [&](Label label) {
5844
+ PrintConformance (Writer, MemberLoading)
5845
+ .visitSubstitutionMap (map, SubstitutionMap::DumpStyle::Full,
5846
+ visited, label);
5847
+ },
5848
+ label);
5773
5849
}
5774
5850
5775
5851
void PrintBase::printRec (const ProtocolConformanceRef &ref,
5776
5852
VisitedConformances &visited, Label label) {
5777
- printRecArbitrary ([&](Label label) {
5778
- PrintConformance (Writer)
5779
- .visitProtocolConformanceRef (ref, visited, label);
5780
- }, label);
5853
+ printRecArbitrary (
5854
+ [&](Label label) {
5855
+ PrintConformance (Writer, MemberLoading)
5856
+ .visitProtocolConformanceRef (ref, visited, label);
5857
+ },
5858
+ label);
5781
5859
}
5782
5860
5783
5861
void PrintBase::printRec (const ProtocolConformance *conformance,
5784
5862
VisitedConformances &visited, Label label) {
5785
- printRecArbitrary ([&](Label label) {
5786
- PrintConformance (Writer)
5787
- .visitProtocolConformance (conformance, visited, label);
5788
- }, label);
5863
+ printRecArbitrary (
5864
+ [&](Label label) {
5865
+ PrintConformance (Writer, MemberLoading)
5866
+ .visitProtocolConformance (conformance, visited, label);
5867
+ },
5868
+ label);
5789
5869
}
5790
5870
5791
5871
} // end anonymous namespace
0 commit comments