Skip to content

Commit 4643cbd

Browse files
committed
GSB: Remove another call to resolveDeclSignature()
The GSB should avoid triggering declaration validation where possible, to avoid problems resulting from circularity and as a general performance rule-of-thumb. This last call was there to catch self-recursive protocol typealiases. However, we can diagnose this problem elsewhere, which allows us to emit a more accurate diagnostic as well.
1 parent 14a20ee commit 4643cbd

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,13 +2057,6 @@ TypeDecl *EquivalenceClass::lookupNestedType(
20572057
!= proto->getParentModule())
20582058
continue;
20592059

2060-
// Resolve the signature of this type.
2061-
if (!type->hasInterfaceType()) {
2062-
type->getASTContext().getLazyResolver()->resolveDeclSignature(type);
2063-
if (!type->hasInterfaceType())
2064-
continue;
2065-
}
2066-
20672060
concreteDecls.push_back(type);
20682061
continue;
20692062
}

lib/Sema/TypeCheckType.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,13 @@ Type TypeResolution::resolveDependentMemberType(
228228
auto lazyResolver = ctx.getLazyResolver();
229229
if (lazyResolver)
230230
lazyResolver->resolveDeclSignature(concrete);
231-
if (!concrete->hasInterfaceType())
231+
if (!concrete->hasInterfaceType()) {
232+
ctx.Diags.diagnose(ref->getIdLoc(), diag::recursive_decl_reference,
233+
concrete->getDescriptiveKind(), concrete->getName());
234+
concrete->diagnose(diag::kind_declared_here,
235+
DescriptiveDeclKind::Type);
232236
return ErrorType::get(ctx);
237+
}
233238

234239
// Make sure that base type didn't get replaced along the way.
235240
assert(baseTy->isTypeParameter());

test/decl/typealias/protocol.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,15 @@ protocol P3 {
144144

145145
// Test for not crashing on recursive aliases
146146
protocol Circular {
147-
typealias Y = Self.Y // expected-error {{'Y' is not a member type of 'Self'}}
147+
typealias Y = Self.Y // expected-error {{type alias 'Y' references itself}}
148+
// expected-note@-1 {{type declared here}}
148149

149150
typealias Y2 = Y2 // expected-error {{type alias 'Y2' references itself}}
150151
// expected-note@-1 {{type declared here}}
151-
// expected-note@-2 {{did you mean 'Y2'?}}
152152

153153
typealias Y3 = Y4 // expected-note {{type declared here}}
154-
// expected-note@-1 {{did you mean 'Y3'?}}
155154

156155
typealias Y4 = Y3 // expected-error {{type alias 'Y3' references itself}}
157-
// expected-note@-1 {{did you mean 'Y4'?}}
158156
}
159157

160158
// Qualified and unqualified references to protocol typealiases from concrete type

0 commit comments

Comments
 (0)