Skip to content

Commit 6af690a

Browse files
committed
Eliminate HasCircularInheritanceRequest.
This is now reliably detected by SuperclassDeclRequest.
1 parent 4ddf6e5 commit 6af690a

File tree

9 files changed

+9
-110
lines changed

9 files changed

+9
-110
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3920,9 +3920,6 @@ class ClassDecl final : public NominalTypeDecl {
39203920
/// Set the superclass of this class.
39213921
void setSuperclass(Type superclass);
39223922

3923-
/// Whether this class has a circular reference in its inheritance hierarchy.
3924-
bool hasCircularInheritance() const;
3925-
39263923
/// Walk this class and all of the superclasses of this class, transitively,
39273924
/// invoking the callback function for each class.
39283925
///

include/swift/AST/TypeCheckRequests.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,29 +1986,6 @@ class PreCheckFunctionBuilderRequest
19861986
bool isCached() const { return true; }
19871987
};
19881988

1989-
/// Computes whether a class has a circular reference in its inheritance
1990-
/// hierarchy.
1991-
class HasCircularInheritanceRequest
1992-
: public SimpleRequest<HasCircularInheritanceRequest, bool(ClassDecl *),
1993-
RequestFlags::Cached> {
1994-
public:
1995-
using SimpleRequest::SimpleRequest;
1996-
1997-
private:
1998-
friend SimpleRequest;
1999-
2000-
// Evaluation.
2001-
bool evaluate(Evaluator &evaluator, ClassDecl *decl) const;
2002-
2003-
public:
2004-
// Cycle handling.
2005-
void diagnoseCycle(DiagnosticEngine &diags) const;
2006-
void noteCycleStep(DiagnosticEngine &diags) const;
2007-
2008-
// Cached.
2009-
bool isCached() const { return true; }
2010-
};
2011-
20121989
/// Computes whether a protocol has a circular reference in its list of
20131990
/// inherited protocols.
20141991
class HasCircularInheritedProtocolsRequest

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ SWIFT_REQUEST(TypeChecker, FunctionOperatorRequest, OperatorDecl *(FuncDecl *),
9595
SWIFT_REQUEST(NameLookup, GenericSignatureRequest,
9696
GenericSignature (GenericContext *),
9797
SeparatelyCached, NoLocationInfo)
98-
SWIFT_REQUEST(TypeChecker, HasCircularInheritanceRequest,
99-
bool(ClassDecl *), Cached, NoLocationInfo)
10098
SWIFT_REQUEST(TypeChecker, HasCircularInheritedProtocolsRequest,
10199
bool(ProtocolDecl *), Cached, NoLocationInfo)
102100
SWIFT_REQUEST(TypeChecker, HasCircularRawValueRequest,

lib/AST/Decl.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4148,13 +4148,6 @@ void NominalTypeDecl::synthesizeSemanticMembersIfNeeded(DeclName member) {
41484148
}
41494149
}
41504150

4151-
bool ClassDecl::hasCircularInheritance() const {
4152-
auto &ctx = getASTContext();
4153-
auto *mutableThis = const_cast<ClassDecl *>(this);
4154-
return evaluateOrDefault(ctx.evaluator,
4155-
HasCircularInheritanceRequest{mutableThis}, true);
4156-
}
4157-
41584151
ClassDecl::ClassDecl(SourceLoc ClassLoc, Identifier Name, SourceLoc NameLoc,
41594152
MutableArrayRef<TypeLoc> Inherited,
41604153
GenericParamList *GenericParams, DeclContext *Parent)

lib/AST/TypeCheckRequests.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,23 +1136,6 @@ void swift::simple_display(llvm::raw_ostream &out,
11361136
}
11371137
}
11381138

1139-
//----------------------------------------------------------------------------//
1140-
// HasCircularInheritanceRequest computation.
1141-
//----------------------------------------------------------------------------//
1142-
1143-
void HasCircularInheritanceRequest::diagnoseCycle(
1144-
DiagnosticEngine &diags) const {
1145-
auto *decl = std::get<0>(getStorage());
1146-
diags.diagnose(decl, diag::circular_class_inheritance, decl->getName());
1147-
}
1148-
1149-
void HasCircularInheritanceRequest::noteCycleStep(
1150-
DiagnosticEngine &diags) const {
1151-
auto *decl = std::get<0>(getStorage());
1152-
diags.diagnose(decl, diag::kind_declname_declared_here,
1153-
decl->getDescriptiveKind(), decl->getName());
1154-
}
1155-
11561139
//----------------------------------------------------------------------------//
11571140
// HasCircularInheritedProtocolsRequest computation.
11581141
//----------------------------------------------------------------------------//

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ using namespace swift;
3030
/// Returns whether the type represented by the given ClassDecl inherits from a
3131
/// type which conforms to the given protocol.
3232
static bool superclassConformsTo(ClassDecl *target, KnownProtocolKind kpk) {
33-
if (!target || !target->getSuperclass() || target->hasCircularInheritance()) {
33+
if (!target) {
3434
return false;
3535
}
36-
return !target->getSuperclassDecl()
36+
37+
auto superclass = target->getSuperclassDecl();
38+
if (!superclass)
39+
return false;
40+
41+
return !superclass
3742
->getModuleContext()
3843
->lookupConformance(target->getSuperclass(),
3944
target->getASTContext().getProtocol(kpk))

lib/Sema/TypeCheckDecl.cpp

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -233,52 +233,6 @@ static bool canSkipCircularityCheck(NominalTypeDecl *decl) {
233233
return decl->hasClangNode() || decl->wasDeserialized();
234234
}
235235

236-
bool
237-
HasCircularInheritanceRequest::evaluate(Evaluator &evaluator,
238-
ClassDecl *decl) const {
239-
if (canSkipCircularityCheck(decl) || !decl->hasSuperclass())
240-
return false;
241-
242-
auto *superclass = decl->getSuperclassDecl();
243-
auto result = evaluator(HasCircularInheritanceRequest{superclass});
244-
245-
// If we have a cycle, handle it and return true.
246-
if (!result) {
247-
using Error = CyclicalRequestError<HasCircularInheritanceRequest>;
248-
llvm::handleAllErrors(result.takeError(), [](const Error &E) {});
249-
return true;
250-
}
251-
return result.get();
252-
}
253-
254-
bool
255-
HasCircularInheritedProtocolsRequest::evaluate(Evaluator &evaluator,
256-
ProtocolDecl *decl) const {
257-
if (canSkipCircularityCheck(decl))
258-
return false;
259-
260-
bool anyObject = false;
261-
auto inherited = getDirectlyInheritedNominalTypeDecls(decl, anyObject);
262-
for (auto &found : inherited) {
263-
auto *protoDecl = dyn_cast<ProtocolDecl>(found.Item);
264-
if (!protoDecl)
265-
continue;
266-
267-
// If we have a cycle, handle it and return true.
268-
auto result = evaluator(HasCircularInheritedProtocolsRequest{protoDecl});
269-
if (!result) {
270-
using Error = CyclicalRequestError<HasCircularInheritedProtocolsRequest>;
271-
llvm::handleAllErrors(result.takeError(), [](const Error &E) {});
272-
return true;
273-
}
274-
275-
// If the underlying request handled a cycle and returned true, bail.
276-
if (*result)
277-
return true;
278-
}
279-
return false;
280-
}
281-
282236
bool
283237
HasCircularRawValueRequest::evaluate(Evaluator &evaluator,
284238
EnumDecl *decl) const {

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
20112011
checkGenericParams(CD);
20122012

20132013
// Check for circular inheritance.
2014-
(void)CD->hasCircularInheritance();
2014+
(void)CD->getSuperclassDecl();
20152015

20162016
// Force lowering of stored properties.
20172017
(void) CD->getStoredProperties();

test/decl/class/circular_inheritance.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: mkdir -p %t/stats-dir
33
// RUN: %target-typecheck-verify-swift
44
// RUN: not %target-swift-frontend -typecheck -debug-cycles %s -build-request-dependency-graph -output-request-graphviz %t.dot -stats-output-dir %t/stats-dir 2> %t.cycles
5+
// RUN: %FileCheck -check-prefix CHECK-DOT %s < %t.dot
56

67
class Left // expected-error {{'Left' inherits from itself}} expected-note {{through reference here}}
78
: Right.Hand { // expected-note {{through reference here}}
@@ -40,14 +41,6 @@ class Outer3 // expected-error {{'Outer3' inherits from itself}} expected-note {
4041
class Inner<T> {}
4142
}
4243

43-
// CHECK: ===CYCLE DETECTED===
44-
// CHECK-LABEL: `--{{.*}}HasCircularInheritanceRequest(circular_inheritance.(file).Left@
45-
// CHECK-NEXT: `--{{.*}}SuperclassDeclRequest({{.*Left}}
46-
// CHECK: `--{{.*}}InheritedDeclsReferencedRequest(circular_inheritance.(file).Left@
47-
// CHECK: `--{{.*}}SuperclassDeclRequest
48-
// CHECK: `--{{.*}}InheritedDeclsReferencedRequest(circular_inheritance.(file).Right@
49-
// CHECK: `--{{.*}}SuperclassDeclRequest{{.*(cyclic dependency)}}
50-
5144
// CHECK-DOT: digraph Dependencies
5245
// CHECK-DOT: label="InheritedTypeRequest
5346

@@ -65,7 +58,6 @@ func crash() {
6558
_ = Circle()
6659
}
6760

68-
// FIXME: We shouldn't emit the redundant "circular reference" diagnostics here.
6961
class WithDesignatedInit : WithDesignatedInit {
7062
// expected-error@-1 {{'WithDesignatedInit' inherits from itself}}
7163

0 commit comments

Comments
 (0)