Skip to content

Commit bde6a46

Browse files
committed
[AST] Fix circular reference with implicit some
getPotentiallyOpaqueGenericParams has a redundant call to check if declarations contain any opaque type representations. We don't need to check this here. Instead we can simply collect the result type representaions without the additional checks.
1 parent b6637e4 commit bde6a46

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,6 +2767,9 @@ class ValueDecl : public Decl {
27672767
/// some Q), or we might have a `NamedOpaqueReturnTypeRepr`.
27682768
TypeRepr *getOpaqueResultTypeRepr() const;
27692769

2770+
/// Get the representative for this value's result type, if it has one.
2771+
TypeRepr *getResultTypeRepr() const;
2772+
27702773
/// Retrieve the attribute associating this declaration with a
27712774
/// result builder, if there is one.
27722775
CustomAttr *getAttachedResultBuilder() const;

lib/AST/ASTScopeCreation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ namespace {
893893
/// Retrieve the opaque generic parameter list if present, otherwise the normal generic parameter list.
894894
template<typename T>
895895
GenericParamList *getPotentiallyOpaqueGenericParams(T *decl) {
896-
if (auto opaqueRepr = decl->getOpaqueResultTypeRepr()) {
896+
if (auto opaqueRepr = decl->getResultTypeRepr()) {
897897
if (auto namedOpaque = dyn_cast<NamedOpaqueReturnTypeRepr>(opaqueRepr)) {
898898
return namedOpaque->getGenericParams();
899899
}

lib/AST/Decl.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3058,7 +3058,8 @@ void ValueDecl::setOverriddenDecls(ArrayRef<ValueDecl *> overridden) {
30583058
request.cacheResult(overriddenVec);
30593059
}
30603060

3061-
TypeRepr *ValueDecl::getOpaqueResultTypeRepr() const {
3061+
// To-Do: Replce calls to getOpaqueResultTypeRepr with getResultTypeRepr()
3062+
TypeRepr *ValueDecl::getResultTypeRepr() const {
30623063
TypeRepr *returnRepr = nullptr;
30633064
if (auto *VD = dyn_cast<VarDecl>(this)) {
30643065
if (auto *P = VD->getParentPattern()) {
@@ -3069,7 +3070,7 @@ TypeRepr *ValueDecl::getOpaqueResultTypeRepr() const {
30693070
P = P->getSemanticsProvidingPattern();
30703071
if (auto *NP = dyn_cast<NamedPattern>(P)) {
30713072
assert(NP->getDecl() == VD);
3072-
(void) NP;
3073+
(void)NP;
30733074

30743075
returnRepr = TP->getTypeRepr();
30753076
}
@@ -3083,6 +3084,14 @@ TypeRepr *ValueDecl::getOpaqueResultTypeRepr() const {
30833084
returnRepr = SD->getElementTypeRepr();
30843085
}
30853086

3087+
return returnRepr;
3088+
}
3089+
3090+
TypeRepr *ValueDecl::getOpaqueResultTypeRepr() const {
3091+
TypeRepr *returnRepr = nullptr;
3092+
3093+
returnRepr = this->getResultTypeRepr();
3094+
30863095
auto *dc = getDeclContext();
30873096
auto &ctx = dc->getASTContext();
30883097

0 commit comments

Comments
 (0)