@@ -936,6 +936,10 @@ struct AppliedBuilderTransform {
936936 Expr *returnExpr = nullptr ;
937937};
938938
939+ struct Score ;
940+ // / Display a score.
941+ llvm::raw_ostream &operator <<(llvm::raw_ostream &out, const Score &score);
942+
939943// / Describes the fixed score of a solution to the constraint system.
940944struct Score {
941945 unsigned Data[NumScoreKinds] = {};
@@ -1006,11 +1010,94 @@ struct Score {
10061010 friend bool operator >=(const Score &x, const Score &y) {
10071011 return !(x < y);
10081012 }
1013+
1014+ // / Return ScoreKind descriptions for printing alongside non-zero ScoreKinds
1015+ // / in debug output.
1016+ static std::string getNameFor (ScoreKind kind) {
1017+ switch (kind) {
1018+ case SK_Hole:
1019+ return " hole in the constraint system" ;
10091020
1010- };
1021+ case SK_Unavailable:
1022+ return " use of an unavailable declaration" ;
10111023
1012- // / Display a score.
1013- llvm::raw_ostream &operator <<(llvm::raw_ostream &out, const Score &score);
1024+ case SK_AsyncInSyncMismatch:
1025+ return " async-in-synchronous mismatch" ;
1026+
1027+ case SK_SyncInAsync:
1028+ return " sync-in-asynchronous" ;
1029+
1030+ case SK_ForwardTrailingClosure:
1031+ return " forward scan when matching a trailing closure" ;
1032+
1033+ case SK_Fix:
1034+ return " attempting to fix the source" ;
1035+
1036+ case SK_DisfavoredOverload:
1037+ return " disfavored overload" ;
1038+
1039+ case SK_UnresolvedMemberViaOptional:
1040+ return " unwrapping optional at unresolved member base" ;
1041+
1042+ case SK_ForceUnchecked:
1043+ return " force of an implicitly unwrapped optional" ;
1044+
1045+ case SK_UserConversion:
1046+ return " user conversion" ;
1047+
1048+ case SK_FunctionConversion:
1049+ return " function conversion" ;
1050+
1051+ case SK_NonDefaultLiteral:
1052+ return " non-default literal" ;
1053+
1054+ case SK_CollectionUpcastConversion:
1055+ return " collection upcast conversion" ;
1056+
1057+ case SK_ValueToOptional:
1058+ return " value to optional" ;
1059+
1060+ case SK_EmptyExistentialConversion:
1061+ return " empty-existential conversion" ;
1062+
1063+ case SK_KeyPathSubscript:
1064+ return " key path subscript" ;
1065+
1066+ case SK_ValueToPointerConversion:
1067+ return " value-to-pointer conversion" ;
1068+
1069+ case SK_FunctionToAutoClosureConversion:
1070+ return " function to autoclosure parameter" ;
1071+
1072+ case SK_ImplicitValueConversion:
1073+ return " value-to-value conversion" ;
1074+
1075+ case SK_UnappliedFunction:
1076+ return " overloaded unapplied function" ;
1077+ }
1078+ }
1079+
1080+ // / Print Score list a with brief description of any non-zero ScoreKinds.
1081+ void print (llvm::raw_ostream &out) const {
1082+ bool hasNonDefault = false ;
1083+ for (unsigned int i = 0 ; i < NumScoreKinds; ++i) {
1084+ if (Data[i] != 0 ) {
1085+ out << " [" ;
1086+ out << getNameFor (ScoreKind (i));
1087+ out << " (s) = " ;
1088+ out << std::to_string (Data[i]);
1089+ out << " ]" ;
1090+ hasNonDefault = true ;
1091+ }
1092+ }
1093+
1094+ if (!hasNonDefault) {
1095+ out << " <default " ;
1096+ out << *this ;
1097+ out << " >" ;
1098+ }
1099+ }
1100+ };
10141101
10151102// / Describes a dependent type that has been opened to a particular type
10161103// / variable.
0 commit comments