Skip to content

Commit d07d390

Browse files
author
Amritpan Kaur
committed
[ConstraintSystem] Move getScoreKindName to ConstraintSystem for use across CS and create new function for printing non-zero ScoreKinds.
You are currently editing a commit while rebasing branch 'improve-solution-printing' on '538ee30efb5'.
1 parent d6b3e47 commit d07d390

File tree

2 files changed

+90
-67
lines changed

2 files changed

+90
-67
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
940944
struct 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.

lib/Sema/CSRanking.cpp

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -32,70 +32,6 @@ using namespace constraints;
3232
#define DEBUG_TYPE "Constraint solver overall"
3333
STATISTIC(NumDiscardedSolutions, "Number of solutions discarded");
3434

35-
static StringRef getScoreKindName(ScoreKind kind) {
36-
switch (kind) {
37-
case SK_Hole:
38-
return "hole in the constraint system";
39-
40-
case SK_Unavailable:
41-
return "use of an unavailable declaration";
42-
43-
case SK_AsyncInSyncMismatch:
44-
return "async-in-synchronous mismatch";
45-
46-
case SK_SyncInAsync:
47-
return "sync-in-asynchronous";
48-
49-
case SK_ForwardTrailingClosure:
50-
return "forward scan when matching a trailing closure";
51-
52-
case SK_Fix:
53-
return "attempting to fix the source";
54-
55-
case SK_DisfavoredOverload:
56-
return "disfavored overload";
57-
58-
case SK_UnresolvedMemberViaOptional:
59-
return "unwrapping optional at unresolved member base";
60-
61-
case SK_ForceUnchecked:
62-
return "force of an implicitly unwrapped optional";
63-
64-
case SK_UserConversion:
65-
return "user conversion";
66-
67-
case SK_FunctionConversion:
68-
return "function conversion";
69-
70-
case SK_NonDefaultLiteral:
71-
return "non-default literal";
72-
73-
case SK_CollectionUpcastConversion:
74-
return "collection upcast conversion";
75-
76-
case SK_ValueToOptional:
77-
return "value to optional";
78-
79-
case SK_EmptyExistentialConversion:
80-
return "empty-existential conversion";
81-
82-
case SK_KeyPathSubscript:
83-
return "key path subscript";
84-
85-
case SK_ValueToPointerConversion:
86-
return "value-to-pointer conversion";
87-
88-
case SK_FunctionToAutoClosureConversion:
89-
return "function to autoclosure parameter";
90-
91-
case SK_ImplicitValueConversion:
92-
return "value-to-value conversion";
93-
94-
case SK_UnappliedFunction:
95-
return "overloaded unapplied function";
96-
}
97-
}
98-
9935
void ConstraintSystem::increaseScore(ScoreKind kind, unsigned value) {
10036
if (isForCodeCompletion()) {
10137
switch (kind) {

0 commit comments

Comments
 (0)