Skip to content

Commit 1d80980

Browse files
committed
AST: Add ValueDecl::isRecursiveValidation()
This will be used as a transitional aid in refactoring getInterfaceType() to always return a valid type, instead of silently returning Type() when there is circularity.
1 parent 7baf6a2 commit 1d80980

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,6 +2608,9 @@ class ValueDecl : public Decl {
26082608
/// if the base declaration is \c open, the override might have to be too.
26092609
bool hasOpenAccess(const DeclContext *useDC) const;
26102610

2611+
/// FIXME: This is deprecated.
2612+
bool isRecursiveValidation() const;
2613+
26112614
/// Retrieve the "interface" type of this value, which uses
26122615
/// GenericTypeParamType if the declaration is generic. For a generic
26132616
/// function, this will have a GenericFunctionType with a

lib/AST/Decl.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,27 @@ bool ValueDecl::hasInterfaceType() const {
27052705
return !TypeAndAccess.getPointer().isNull();
27062706
}
27072707

2708+
bool ValueDecl::isRecursiveValidation() const {
2709+
if (hasValidationStarted() || !hasInterfaceType())
2710+
return true;
2711+
2712+
if (auto *vd = dyn_cast<VarDecl>(this))
2713+
if (auto *pbd = vd->getParentPatternBinding())
2714+
if (pbd->isBeingValidated())
2715+
return true;
2716+
2717+
auto *dc = getDeclContext();
2718+
while (isa<NominalTypeDecl>(dc))
2719+
dc = dc->getParent();
2720+
2721+
if (auto *ext = dyn_cast<ExtensionDecl>(dc)) {
2722+
if (ext->isComputingGenericSignature())
2723+
return true;
2724+
}
2725+
2726+
return false;
2727+
}
2728+
27082729
Type ValueDecl::getInterfaceType() const {
27092730
if (!hasInterfaceType()) {
27102731
// Our clients that don't register the lazy resolver are relying on the

0 commit comments

Comments
 (0)