Skip to content

Commit d6b3e47

Browse files
author
Amritpan Kaur
committed
[OverloadChoice] Refactor overload choice printing to its function.
1 parent 2786f24 commit d6b3e47

File tree

2 files changed

+41
-32
lines changed

2 files changed

+41
-32
lines changed

include/swift/Sema/OverloadChoice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ class OverloadChoice {
310310
assert(isDecl() && "only makes sense for declaration choices");
311311
return TheFunctionRefKind;
312312
}
313+
314+
/// Print selected overload choice kind found for Solution in debug output.
315+
void dump(Type adjustedOpenedType, SourceManager *sm, raw_ostream &out) const;
313316
};
314317

315318
} // end namespace constraints

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,43 @@ TypeChecker::coerceToRValue(ASTContext &Context, Expr *expr,
12281228
//===----------------------------------------------------------------------===//
12291229
#pragma mark Debugging
12301230

1231+
void OverloadChoice::dump(Type adjustedOpenedType, SourceManager *sm,
1232+
raw_ostream &out) const {
1233+
PrintOptions PO;
1234+
PO.PrintTypesForDebugging = true;
1235+
out << " with ";
1236+
1237+
switch (getKind()) {
1238+
case OverloadChoiceKind::Decl:
1239+
case OverloadChoiceKind::DeclViaDynamic:
1240+
case OverloadChoiceKind::DeclViaBridge:
1241+
case OverloadChoiceKind::DeclViaUnwrappedOptional:
1242+
getDecl()->dumpRef(out);
1243+
out << " as ";
1244+
if (getBaseType())
1245+
out << getBaseType()->getString(PO) << ".";
1246+
1247+
out << getDecl()->getBaseName() << ": "
1248+
<< adjustedOpenedType->getString(PO);
1249+
break;
1250+
1251+
case OverloadChoiceKind::KeyPathApplication:
1252+
out << "key path application root " << getBaseType()->getString(PO);
1253+
break;
1254+
1255+
case OverloadChoiceKind::DynamicMemberLookup:
1256+
case OverloadChoiceKind::KeyPathDynamicMemberLookup:
1257+
out << "dynamic member lookup root " << getBaseType()->getString(PO)
1258+
<< " name='" << getName();
1259+
break;
1260+
1261+
case OverloadChoiceKind::TupleIndex:
1262+
out << "tuple " << getBaseType()->getString(PO) << " index "
1263+
<< getTupleIndex();
1264+
break;
1265+
}
1266+
}
1267+
12311268
void Solution::dump() const {
12321269
dump(llvm::errs());
12331270
}
@@ -1268,40 +1305,9 @@ void Solution::dump(raw_ostream &out) const {
12681305
out << "\n";
12691306
ovl.first->dump(sm, out);
12701307
}
1271-
out << " with ";
12721308

12731309
auto choice = ovl.second.choice;
1274-
switch (choice.getKind()) {
1275-
case OverloadChoiceKind::Decl:
1276-
case OverloadChoiceKind::DeclViaDynamic:
1277-
case OverloadChoiceKind::DeclViaBridge:
1278-
case OverloadChoiceKind::DeclViaUnwrappedOptional:
1279-
choice.getDecl()->dumpRef(out);
1280-
out << " as ";
1281-
if (choice.getBaseType())
1282-
out << choice.getBaseType()->getString(PO) << ".";
1283-
1284-
out << choice.getDecl()->getBaseName() << ": "
1285-
<< ovl.second.adjustedOpenedType->getString(PO);
1286-
break;
1287-
1288-
case OverloadChoiceKind::KeyPathApplication:
1289-
out << "key path application root "
1290-
<< choice.getBaseType()->getString(PO);
1291-
break;
1292-
1293-
case OverloadChoiceKind::DynamicMemberLookup:
1294-
case OverloadChoiceKind::KeyPathDynamicMemberLookup:
1295-
out << "dynamic member lookup root "
1296-
<< choice.getBaseType()->getString(PO)
1297-
<< " name='" << choice.getName();
1298-
break;
1299-
1300-
case OverloadChoiceKind::TupleIndex:
1301-
out << "tuple " << choice.getBaseType()->getString(PO) << " index "
1302-
<< choice.getTupleIndex();
1303-
break;
1304-
}
1310+
choice.dump(ovl.second.adjustedOpenedType, sm, out);
13051311
}
13061312
out << "\n";
13071313
}

0 commit comments

Comments
 (0)