Skip to content

Commit 6c8da76

Browse files
authored
Merge pull request #83439 from xedin/allow-debugging-of-decl-specialization-comparison
[CSRanking] Pass down a flag to enable debug output in `CompareDeclSp…
2 parents 3524025 + 5899eb2 commit 6c8da76

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

include/swift/AST/TypeCheckRequests.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,7 +2883,7 @@ class SynthesizeDefaultInitRequest
28832883
class CompareDeclSpecializationRequest
28842884
: public SimpleRequest<CompareDeclSpecializationRequest,
28852885
bool(DeclContext *, ValueDecl *, ValueDecl *, bool,
2886-
bool),
2886+
bool, bool),
28872887
RequestFlags::Cached> {
28882888
public:
28892889
using SimpleRequest::SimpleRequest;
@@ -2893,8 +2893,8 @@ class CompareDeclSpecializationRequest
28932893

28942894
// Evaluation.
28952895
bool evaluate(Evaluator &evaluator, DeclContext *DC, ValueDecl *VD1,
2896-
ValueDecl *VD2, bool dynamic,
2897-
bool allowMissingConformances) const;
2896+
ValueDecl *VD2, bool dynamic, bool allowMissingConformances,
2897+
bool debugMode) const;
28982898

28992899
public:
29002900
// Caching.

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ SWIFT_REQUEST(TypeChecker, CheckRedeclarationRequest,
5252
SWIFT_REQUEST(TypeChecker, ClassAncestryFlagsRequest,
5353
AncestryFlags(ClassDecl *), Cached, NoLocationInfo)
5454
SWIFT_REQUEST(TypeChecker, CompareDeclSpecializationRequest,
55-
bool (DeclContext *, ValueDecl *, ValueDecl *, bool, bool),
55+
bool (DeclContext *, ValueDecl *, ValueDecl *, bool, bool, bool),
5656
Cached, NoLocationInfo)
5757
SWIFT_REQUEST(TypeChecker, ConditionalRequirementsRequest,
5858
ArrayRef<Requirement> (NormalProtocolConformance *),

lib/Sema/CSRanking.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -465,20 +465,25 @@ static bool paramIsIUO(const ValueDecl *decl, int paramNum) {
465465
static bool isDeclAsSpecializedAs(DeclContext *dc, ValueDecl *decl1,
466466
ValueDecl *decl2,
467467
bool isDynamicOverloadComparison = false,
468-
bool allowMissingConformances = true) {
468+
bool allowMissingConformances = true,
469+
bool debugMode = false) {
469470
return evaluateOrDefault(decl1->getASTContext().evaluator,
470471
CompareDeclSpecializationRequest{
471472
dc, decl1, decl2, isDynamicOverloadComparison,
472-
allowMissingConformances},
473+
allowMissingConformances, debugMode},
473474
false);
474475
}
475476

476477
bool CompareDeclSpecializationRequest::evaluate(
477478
Evaluator &eval, DeclContext *dc, ValueDecl *decl1, ValueDecl *decl2,
478-
bool isDynamicOverloadComparison, bool allowMissingConformances) const {
479+
bool isDynamicOverloadComparison, bool allowMissingConformances,
480+
bool debugMode) const {
479481
auto &C = decl1->getASTContext();
482+
ConstraintSystemOptions options;
483+
if (debugMode)
484+
options |= ConstraintSystemFlags::DebugConstraints;
480485
// Construct a constraint system to compare the two declarations.
481-
ConstraintSystem cs(dc, ConstraintSystemOptions());
486+
ConstraintSystem cs(dc, options);
482487
if (cs.isDebugMode()) {
483488
llvm::errs() << "Comparing declarations\n";
484489
decl1->print(llvm::errs());
@@ -1174,15 +1179,15 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
11741179
// Determine whether one declaration is more specialized than the other.
11751180
bool firstAsSpecializedAs = false;
11761181
bool secondAsSpecializedAs = false;
1177-
if (isDeclAsSpecializedAs(cs.DC, decl1, decl2,
1178-
isDynamicOverloadComparison,
1179-
/*allowMissingConformances=*/false)) {
1182+
if (isDeclAsSpecializedAs(cs.DC, decl1, decl2, isDynamicOverloadComparison,
1183+
/*allowMissingConformances=*/false,
1184+
cs.isDebugMode())) {
11801185
score1 += weight;
11811186
firstAsSpecializedAs = true;
11821187
}
1183-
if (isDeclAsSpecializedAs(cs.DC, decl2, decl1,
1184-
isDynamicOverloadComparison,
1185-
/*allowMissingConformances=*/false)) {
1188+
if (isDeclAsSpecializedAs(cs.DC, decl2, decl1, isDynamicOverloadComparison,
1189+
/*allowMissingConformances=*/false,
1190+
cs.isDebugMode())) {
11861191
score2 += weight;
11871192
secondAsSpecializedAs = true;
11881193
}

0 commit comments

Comments
 (0)