@@ -2045,6 +2045,48 @@ 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 to: " ;
2070
+ SmallVector<std::pair<TypeVariableType *, Constraint *>> adjacentVars (
2071
+ AdjacentVars.begin (), AdjacentVars.end ());
2072
+ llvm::sort (adjacentVars,
2073
+ [](auto lhs, auto rhs) {
2074
+ return lhs.first ->getID () < rhs.first ->getID ();
2075
+ });
2076
+ interleave (adjacentVars,
2077
+ [&](std::pair<TypeVariableType *, Constraint *> pair) {
2078
+ out << pair.first ->getString (PO);
2079
+ if (pair.first ->getImpl ().getFixedType (/* record=*/ nullptr ))
2080
+ out << " (fixed)" ;
2081
+ out << " via " ;
2082
+ pair.second ->print (out, &cs.getASTContext ().SourceMgr , indent,
2083
+ /* skipLocator=*/ true );
2084
+ },
2085
+ [&out]() { out << " , " ; });
2086
+ out << " ] " ;
2087
+ }
2088
+ }
2089
+
2048
2090
void BindingSet::forEachLiteralRequirement (
2049
2091
llvm::function_ref<void (KnownProtocolKind)> callback) const {
2050
2092
for (const auto &literal : Literals) {
@@ -2184,22 +2226,21 @@ void BindingSet::dump(llvm::raw_ostream &out, unsigned indent) const {
2184
2226
if (!attributes.empty ())
2185
2227
out << " ] " ;
2186
2228
2187
- if (involvesTypeVariables ()) {
2229
+ if (!AdjacentVars. empty ()) {
2188
2230
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) {
2231
+ SmallVector<TypeVariableType *> adjacentVars (AdjacentVars.begin (),
2232
+ AdjacentVars.end ());
2233
+ llvm::sort (adjacentVars,
2234
+ [](const TypeVariableType *lhs, const TypeVariableType *rhs) {
2196
2235
return lhs->getID () < rhs->getID ();
2197
- });
2198
- interleave (
2199
- adjacentVars,
2200
- [&](const auto *typeVar) { out << typeVar->getString (PO); },
2201
- [&out]() { out << " , " ; });
2202
- }
2236
+ });
2237
+ interleave (adjacentVars,
2238
+ [&](auto *typeVar) {
2239
+ out << typeVar->getString (PO);
2240
+ if (typeVar->getImpl ().getFixedType (/* record=*/ nullptr ))
2241
+ out << " (fixed)" ;
2242
+ },
2243
+ [&out]() { out << " , " ; });
2203
2244
out << " ] " ;
2204
2245
}
2205
2246
@@ -2212,24 +2253,25 @@ void BindingSet::dump(llvm::raw_ostream &out, unsigned indent) const {
2212
2253
enum class BindingKind { Exact, Subtypes, Supertypes, Literal };
2213
2254
BindingKind Kind;
2214
2255
Type BindingType;
2215
- PrintableBinding (BindingKind kind, Type bindingType)
2216
- : Kind(kind), BindingType(bindingType) {}
2256
+ bool Viable;
2257
+ PrintableBinding (BindingKind kind, Type bindingType, bool viable)
2258
+ : Kind(kind), BindingType(bindingType), Viable(viable) {}
2217
2259
2218
2260
public:
2219
2261
static PrintableBinding supertypesOf (Type binding) {
2220
- return PrintableBinding{BindingKind::Supertypes, binding};
2262
+ return PrintableBinding{BindingKind::Supertypes, binding, true };
2221
2263
}
2222
2264
2223
2265
static PrintableBinding subtypesOf (Type binding) {
2224
- return PrintableBinding{BindingKind::Subtypes, binding};
2266
+ return PrintableBinding{BindingKind::Subtypes, binding, true };
2225
2267
}
2226
2268
2227
2269
static PrintableBinding exact (Type binding) {
2228
- return PrintableBinding{BindingKind::Exact, binding};
2270
+ return PrintableBinding{BindingKind::Exact, binding, true };
2229
2271
}
2230
2272
2231
- static PrintableBinding literalDefaultType (Type binding) {
2232
- return PrintableBinding{BindingKind::Literal, binding};
2273
+ static PrintableBinding literalDefaultType (Type binding, bool viable ) {
2274
+ return PrintableBinding{BindingKind::Literal, binding, viable };
2233
2275
}
2234
2276
2235
2277
void print (llvm::raw_ostream &out, const PrintOptions &PO,
@@ -2247,7 +2289,10 @@ void BindingSet::dump(llvm::raw_ostream &out, unsigned indent) const {
2247
2289
out << " (default type of literal) " ;
2248
2290
break ;
2249
2291
}
2250
- BindingType.print (out, PO);
2292
+ if (BindingType)
2293
+ BindingType.print (out, PO);
2294
+ if (!Viable)
2295
+ out << " [literal not viable]" ;
2251
2296
}
2252
2297
};
2253
2298
@@ -2269,10 +2314,11 @@ void BindingSet::dump(llvm::raw_ostream &out, unsigned indent) const {
2269
2314
}
2270
2315
}
2271
2316
for (const auto &literal : Literals) {
2272
- if (literal.second .viableAsBinding ()) {
2273
- potentialBindings.push_back (PrintableBinding::literalDefaultType (
2274
- literal.second .getDefaultType ()));
2275
- }
2317
+ potentialBindings.push_back (PrintableBinding::literalDefaultType (
2318
+ literal.second .hasDefaultType ()
2319
+ ? literal.second .getDefaultType ()
2320
+ : Type (),
2321
+ literal.second .viableAsBinding ()));
2276
2322
}
2277
2323
if (potentialBindings.empty ()) {
2278
2324
out << " <none>" ;
0 commit comments