Skip to content

Commit 4f6951c

Browse files
committed
Change a cycle condition
Not having the generic signature is the real culprit here.
1 parent 6b7fbc9 commit 4f6951c

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

include/swift/AST/TypeCheckRequests.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ class RequirementRequest :
434434
// Source location
435435
SourceLoc getNearestLoc() const;
436436

437+
// Cycle handling.
438+
void noteCycleStep(DiagnosticEngine &diags) const;
439+
437440
// Separate caching.
438441
bool isCached() const;
439442
Optional<Requirement> getCachedResult() const;
@@ -1120,6 +1123,9 @@ class InferredGenericSignatureRequest :
11201123
SourceLoc getNearestLoc() const {
11211124
return SourceLoc();
11221125
}
1126+
1127+
// Cycle handling.
1128+
void noteCycleStep(DiagnosticEngine &diags) const;
11231129
};
11241130

11251131
void simple_display(llvm::raw_ostream &out, const TypeLoc source);
@@ -1174,7 +1180,7 @@ class GenericSignatureRequest :
11741180
llvm::Expected<GenericSignature *>
11751181
evaluate(Evaluator &evaluator, GenericContext *value) const;
11761182

1177-
public:
1183+
public:
11781184
// Separate caching.
11791185
bool isCached() const { return true; }
11801186
Optional<GenericSignature *> getCachedResult() const;

lib/AST/TypeCheckRequests.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,14 @@ SourceLoc RequirementRequest::getNearestLoc() const {
364364
return owner.getLoc();
365365
}
366366

367+
void RequirementRequest::noteCycleStep(DiagnosticEngine &diags) const {
368+
// For now, the GSB does a better job of describing the exact structure of
369+
// the cycle.
370+
//
371+
// FIXME: We should consider merging the circularity handling the GSB does
372+
// into this request. See rdar://55263708
373+
}
374+
367375
MutableArrayRef<RequirementRepr> WhereClauseOwner::getRequirements() const {
368376
if (auto genericParams = source.dyn_cast<GenericParamList *>()) {
369377
return genericParams->getRequirements();
@@ -823,6 +831,18 @@ void GenericSignatureRequest::cacheResult(GenericSignature *value) const {
823831
GC->GenericSigAndBit.setPointerAndInt(value, true);
824832
}
825833

834+
//----------------------------------------------------------------------------//
835+
// GenericSignatureRequest computation.
836+
//----------------------------------------------------------------------------//
837+
838+
void InferredGenericSignatureRequest::noteCycleStep(DiagnosticEngine &d) const {
839+
// For now, the GSB does a better job of describing the exact structure of
840+
// the cycle.
841+
//
842+
// FIXME: We should consider merging the circularity handling the GSB does
843+
// into this request. See rdar://55263708
844+
}
845+
826846
//----------------------------------------------------------------------------//
827847
// IsImplicitlyUnwrappedOptionalRequest computation.
828848
//----------------------------------------------------------------------------//

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ Type TypeChecker::applyGenericArguments(Type type,
768768
}
769769

770770
// FIXME: More principled handling of circularity.
771-
if (!genericDecl->hasValidSignature()) {
771+
if (!genericDecl->getGenericSignature()) {
772772
diags.diagnose(loc, diag::recursive_decl_reference,
773773
genericDecl->getDescriptiveKind(), genericDecl->getName());
774774
genericDecl->diagnose(diag::kind_declared_here, DescriptiveDeclKind::Type);

test/Generics/generic_types.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ class Top {}
230230
class Bottom<T : Bottom<Top>> {}
231231
// expected-error@-1 {{generic class 'Bottom' references itself}}
232232
// expected-note@-2 {{type declared here}}
233+
// expected-error@-3 {{circular reference}}
234+
// expected-note@-4 {{through reference here}}
233235

234236
// Invalid inheritance clause
235237

test/decl/protocol/req/recursion.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public protocol P {
4343
associatedtype T
4444
}
4545

46-
public struct S<A: P> where A.T == S<A> {
46+
public struct S<A: P> where A.T == S<A> { // expected-error {{circular reference}}
4747
// expected-note@-1 {{type declared here}}
4848
// expected-error@-2 {{generic struct 'S' references itself}}
4949
func f(a: A.T) {
@@ -71,7 +71,7 @@ protocol PI {
7171
associatedtype T : I
7272
}
7373

74-
struct SI<A: PI> : I where A : I, A.T == SI<A> {
74+
struct SI<A: PI> : I where A : I, A.T == SI<A> { // expected-error {{circular reference}}
7575
// expected-note@-1 {{type declared here}}
7676
// expected-error@-2 {{generic struct 'SI' references itself}}
7777
func ggg<T : I>(t: T.Type) -> T {

0 commit comments

Comments
 (0)