Skip to content

Commit 69bd40c

Browse files
committed
Replace the cycle breaker for pattern bindings
1 parent 198601d commit 69bd40c

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,6 +2226,9 @@ class PatternBindingDecl final : public Decl,
22262226
/// \returns the way 'static'/'class' should be spelled for this declaration.
22272227
StaticSpellingKind getCorrectStaticSpelling() const;
22282228

2229+
/// Is the pattern binding entry for this variable currently being computed?
2230+
bool isComputingPatternBindingEntry(const VarDecl *vd) const;
2231+
22292232
static bool classof(const Decl *D) {
22302233
return D->getKind() == DeclKind::PatternBinding;
22312234
}

lib/AST/Decl.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,13 @@ bool PatternBindingDecl::isDefaultInitializable(unsigned i) const {
17351735
return false;
17361736
}
17371737

1738+
bool PatternBindingDecl::isComputingPatternBindingEntry(
1739+
const VarDecl *vd) const {
1740+
unsigned i = getPatternEntryIndexForVarDecl(vd);
1741+
return getASTContext().evaluator.hasActiveRequest(
1742+
PatternBindingEntryRequest{const_cast<PatternBindingDecl *>(this), i});
1743+
}
1744+
17381745
SourceLoc TopLevelCodeDecl::getStartLoc() const {
17391746
return Body->getStartLoc();
17401747
}
@@ -2761,7 +2768,7 @@ bool ValueDecl::isRecursiveValidation() const {
27612768

27622769
if (auto *vd = dyn_cast<VarDecl>(this))
27632770
if (auto *pbd = vd->getParentPatternBinding())
2764-
if (pbd->isBeingValidated())
2771+
if (pbd->isComputingPatternBindingEntry(vd))
27652772
return true;
27662773

27672774
auto *dc = getDeclContext();

test/decl/overload.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,27 @@ enum SR_10084_E_16 {
610610
case Z // expected-error {{invalid redeclaration of 'Z'}}
611611
}
612612

613-
// N.B. Validating the pattern binding initializer for `raw` used to cause
613+
// N.B. Validating the pattern binding initializer for `pickMe` used to cause
614614
// recursive validation of the VarDecl. Check that we don't regress now that
615615
// this isn't the case.
616616
public struct Cyclic {
617617
static func pickMe(please: Bool) -> Int { return 42 }
618618
public static let pickMe = Cyclic.pickMe(please: true)
619619
}
620+
621+
struct Node {}
622+
struct Parameterized<Value, Format> {
623+
func please<NewValue>(_ transform: @escaping (_ otherValue: NewValue) -> Value) -> Parameterized<NewValue, Format> {
624+
fatalError()
625+
}
626+
}
627+
628+
extension Parameterized where Value == [Node], Format == String {
629+
static var pickMe: Parameterized {
630+
fatalError()
631+
}
632+
}
633+
634+
extension Parameterized where Value == Node, Format == String {
635+
static let pickMe = Parameterized<[Node], String>.pickMe.please { [$0] }
636+
}

test/decl/protocol/conforms/circular_validation.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
// not crash.
55

66
protocol P {
7-
var x: Int { get set }
7+
var x: Int { get set } // expected-note {{protocol requires property 'x' with type 'Int'; do you want to add a stub?}}
88
}
99

10-
struct S : P {
11-
static var x = 0
12-
var x = S.x // expected-error {{circular reference}}
13-
// expected-note@-1 {{through reference here}}
10+
struct S : P { // expected-error {{type 'S' does not conform to protocol 'P'}}
11+
static var x = 0 // expected-note {{candidate operates on a type, not an instance as required}}
12+
var x = S.x // expected-note {{candidate references itself}}
1413
}
1514

1615
// FIXME: Lousy diagnostics on this case.

test/decl/protocol/req/associated_type_inference.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ struct XCollectionLikeP0a<T> : CollectionLikeP0 {
185185
struct XCollectionLikeP0b : CollectionLikeP0 {
186186
// expected-error@-1 {{type 'XCollectionLikeP0b' does not conform to protocol 'CollectionLikeP0'}}
187187
var startIndex: XCollectionLikeP0b.Index
188-
// expected-error@-1{{circular reference}}
189-
// expected-note@-2{{through reference here}}
188+
// There was an error @-1 ("'startIndex' used within its own type"),
189+
// but it disappeared and doesn't seem like much of a loss.
190190
var startElement: XCollectionLikeP0b.Element
191191
}
192192

0 commit comments

Comments
 (0)