Skip to content

Commit dff5401

Browse files
committed
[ConstraintSystem] Requestify isDeclSubstitutable from CSStep.cpp
1 parent 27b1394 commit dff5401

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

include/swift/AST/TypeCheckRequests.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,27 @@ class CompareDeclSpecializationRequest
18831883
bool isCached() const { return true; }
18841884
};
18851885

1886+
/// Checks whether substituting the first generic function decl with the
1887+
/// second generic function decl will satisfy all requirements and produce
1888+
/// the same function type.
1889+
class IsDeclSubstitutableRequest
1890+
: public SimpleRequest<IsDeclSubstitutableRequest,
1891+
bool(ValueDecl *, ValueDecl *),
1892+
RequestFlags::Cached> {
1893+
public:
1894+
using SimpleRequest::SimpleRequest;
1895+
1896+
private:
1897+
friend SimpleRequest;
1898+
1899+
// Evaluation.
1900+
bool evaluate(Evaluator &evaluator, ValueDecl *declA, ValueDecl *declB) const;
1901+
1902+
public:
1903+
// Caching.
1904+
bool isCached() const { return true; }
1905+
};
1906+
18861907
/// Checks whether this declaration inherits its superclass' designated and
18871908
/// convenience initializers.
18881909
class InheritsSuperclassInitializersRequest

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ SWIFT_REQUEST(TypeChecker, CodeCompletionFileRequest,
4141
SWIFT_REQUEST(TypeChecker, CompareDeclSpecializationRequest,
4242
bool (DeclContext *, ValueDecl *, ValueDecl *, bool), Cached,
4343
NoLocationInfo)
44+
SWIFT_REQUEST(TypeChecker, IsDeclSubstitutableRequest,
45+
bool (ValueDecl *, ValueDecl *),
46+
Cached, NoLocationInfo)
4447
SWIFT_REQUEST(TypeChecker, CustomAttrTypeRequest,
4548
Type(CustomAttr *, DeclContext *, CustomAttrTypeKind),
4649
SeparatelyCached, NoLocationInfo)

lib/Sema/CSStep.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "CSStep.h"
1919
#include "TypeChecker.h"
2020
#include "swift/AST/Types.h"
21+
#include "swift/AST/TypeCheckRequests.h"
2122
#include "swift/AST/GenericEnvironment.h"
2223
#include "swift/Sema/ConstraintSystem.h"
2324
#include "llvm/ADT/ArrayRef.h"
@@ -529,7 +530,9 @@ StepResult DisjunctionStep::resume(bool prevFailed) {
529530
return take(prevFailed);
530531
}
531532

532-
static bool isDeclSubstitutable(ValueDecl *declA, ValueDecl *declB) {
533+
bool IsDeclSubstitutableRequest::evaluate(Evaluator &evaluator,
534+
ValueDecl *declA,
535+
ValueDecl *declB) const {
533536
auto *typeA = declA->getInterfaceType()->getAs<GenericFunctionType>();
534537
auto *typeB = declB->getInterfaceType()->getAs<GenericFunctionType>();
535538

@@ -571,6 +574,12 @@ static bool isDeclSubstitutable(ValueDecl *declA, ValueDecl *declB) {
571574
return substTypeA->isEqual(substTypeB);
572575
}
573576

577+
static bool isDeclSubstitutable(ValueDecl *declA, ValueDecl *declB) {
578+
return evaluateOrDefault(declA->getASTContext().evaluator,
579+
IsDeclSubstitutableRequest{ declA, declB },
580+
false);
581+
}
582+
574583
static bool isGenericDisjunctionChoice(Constraint *constraint) {
575584
if (constraint->getKind() != ConstraintKind::BindOverload)
576585
return false;

0 commit comments

Comments
 (0)