@@ -2045,6 +2045,42 @@ void PotentialBindings::reset() {
2045
2045
AssociatedCodeCompletionToken = ASTNode ();
2046
2046
}
2047
2047
2048
+ void PotentialBindings::dump (ConstraintSystem &cs,
2049
+ TypeVariableType *typeVar,
2050
+ llvm::raw_ostream &out,
2051
+ unsigned indent) const {
2052
+ PrintOptions PO;
2053
+ PO.PrintTypesForDebugging = true ;
2054
+
2055
+ out << " Potential bindings for " ;
2056
+ typeVar->getImpl ().print (out);
2057
+ out << " \n " ;
2058
+
2059
+ out << " [constraints: " ;
2060
+ interleave (Constraints,
2061
+ [&](Constraint *constraint) {
2062
+ constraint->print (out, &cs.getASTContext ().SourceMgr , indent,
2063
+ /* skipLocator=*/ true );
2064
+ },
2065
+ [&out]() { out << " , " ; });
2066
+ out << " ] " ;
2067
+
2068
+ if (!AdjacentVars.empty ()) {
2069
+ out << " [adjacent_vars: " ;
2070
+ interleave (AdjacentVars,
2071
+ [&](std::pair<TypeVariableType *, Constraint *> pair) {
2072
+ out << pair.first ->getString (PO);
2073
+ if (pair.first ->getImpl ().getFixedType (/* record=*/ nullptr ))
2074
+ out << " (fixed)" ;
2075
+ out << " via " ;
2076
+ pair.second ->print (out, &cs.getASTContext ().SourceMgr , indent,
2077
+ /* skipLocator=*/ true );
2078
+ },
2079
+ [&out]() { out << " , " ; });
2080
+ out << " ] " ;
2081
+ }
2082
+ }
2083
+
2048
2084
void BindingSet::forEachLiteralRequirement (
2049
2085
llvm::function_ref<void (KnownProtocolKind)> callback) const {
2050
2086
for (const auto &literal : Literals) {
@@ -2184,22 +2220,15 @@ void BindingSet::dump(llvm::raw_ostream &out, unsigned indent) const {
2184
2220
if (!attributes.empty ())
2185
2221
out << " ] " ;
2186
2222
2187
- if (involvesTypeVariables ()) {
2188
- out << " [adjacent to: " ;
2189
- if (AdjacentVars.empty ()) {
2190
- out << " <none>" ;
2191
- } else {
2192
- SmallVector<TypeVariableType *> adjacentVars (AdjacentVars.begin (),
2193
- AdjacentVars.end ());
2194
- llvm::sort (adjacentVars,
2195
- [](const TypeVariableType *lhs, const TypeVariableType *rhs) {
2196
- return lhs->getID () < rhs->getID ();
2197
- });
2198
- interleave (
2199
- adjacentVars,
2200
- [&](const auto *typeVar) { out << typeVar->getString (PO); },
2201
- [&out]() { out << " , " ; });
2202
- }
2223
+ if (!AdjacentVars.empty ()) {
2224
+ out << " [adjacent_vars: " ;
2225
+ interleave (AdjacentVars,
2226
+ [&](auto *typeVar) {
2227
+ out << typeVar->getString (PO);
2228
+ if (typeVar->getImpl ().getFixedType (/* record=*/ nullptr ))
2229
+ out << " (fixed)" ;
2230
+ },
2231
+ [&out]() { out << " , " ; });
2203
2232
out << " ] " ;
2204
2233
}
2205
2234
@@ -2212,24 +2241,25 @@ void BindingSet::dump(llvm::raw_ostream &out, unsigned indent) const {
2212
2241
enum class BindingKind { Exact, Subtypes, Supertypes, Literal };
2213
2242
BindingKind Kind;
2214
2243
Type BindingType;
2215
- PrintableBinding (BindingKind kind, Type bindingType)
2216
- : Kind(kind), BindingType(bindingType) {}
2244
+ bool Viable;
2245
+ PrintableBinding (BindingKind kind, Type bindingType, bool viable)
2246
+ : Kind(kind), BindingType(bindingType), Viable(viable) {}
2217
2247
2218
2248
public:
2219
2249
static PrintableBinding supertypesOf (Type binding) {
2220
- return PrintableBinding{BindingKind::Supertypes, binding};
2250
+ return PrintableBinding{BindingKind::Supertypes, binding, true };
2221
2251
}
2222
2252
2223
2253
static PrintableBinding subtypesOf (Type binding) {
2224
- return PrintableBinding{BindingKind::Subtypes, binding};
2254
+ return PrintableBinding{BindingKind::Subtypes, binding, true };
2225
2255
}
2226
2256
2227
2257
static PrintableBinding exact (Type binding) {
2228
- return PrintableBinding{BindingKind::Exact, binding};
2258
+ return PrintableBinding{BindingKind::Exact, binding, true };
2229
2259
}
2230
2260
2231
- static PrintableBinding literalDefaultType (Type binding) {
2232
- return PrintableBinding{BindingKind::Literal, binding};
2261
+ static PrintableBinding literalDefaultType (Type binding, bool viable ) {
2262
+ return PrintableBinding{BindingKind::Literal, binding, viable };
2233
2263
}
2234
2264
2235
2265
void print (llvm::raw_ostream &out, const PrintOptions &PO,
@@ -2247,7 +2277,10 @@ void BindingSet::dump(llvm::raw_ostream &out, unsigned indent) const {
2247
2277
out << " (default type of literal) " ;
2248
2278
break ;
2249
2279
}
2250
- BindingType.print (out, PO);
2280
+ if (BindingType)
2281
+ BindingType.print (out, PO);
2282
+ if (!Viable)
2283
+ out << " [literal not viable]" ;
2251
2284
}
2252
2285
};
2253
2286
@@ -2269,10 +2302,11 @@ void BindingSet::dump(llvm::raw_ostream &out, unsigned indent) const {
2269
2302
}
2270
2303
}
2271
2304
for (const auto &literal : Literals) {
2272
- if (literal.second .viableAsBinding ()) {
2273
- potentialBindings.push_back (PrintableBinding::literalDefaultType (
2274
- literal.second .getDefaultType ()));
2275
- }
2305
+ potentialBindings.push_back (PrintableBinding::literalDefaultType (
2306
+ literal.second .hasDefaultType ()
2307
+ ? literal.second .getDefaultType ()
2308
+ : Type (),
2309
+ literal.second .viableAsBinding ()));
2276
2310
}
2277
2311
if (potentialBindings.empty ()) {
2278
2312
out << " <none>" ;
0 commit comments