Skip to content

Commit bdbd849

Browse files
committed
Sema: Infer default witnesses before finishing conformance checking
Otherwise, we'll never get a chance to drain the TypeChecker's UsedConformances list. Fixes <https://bugs.swift.org/browse/SR-6565>, <rdar://problem/35949729>.
1 parent 1ee806f commit bdbd849

File tree

6 files changed

+23
-15
lines changed

6 files changed

+23
-15
lines changed

include/swift/Subsystems.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ namespace swift {
184184
unsigned WarnLongExpressionTypeChecking = 0,
185185
unsigned ExpressionTimeoutThreshold = 0);
186186

187-
/// Once type checking is complete, this walks protocol requirements
188-
/// to resolve default witnesses.
189-
void finishTypeCheckingFile(SourceFile &SF);
190-
191187
/// Now that we have type-checked an entire module, perform any type
192188
/// checking that requires the full module, e.g., Objective-C method
193189
/// override checking.

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,6 @@ void CompilerInstance::finishTypeChecking(
648648
performWholeModuleTypeChecking(SF);
649649
});
650650
}
651-
forEachFileToTypeCheck([&](SourceFile &SF) { finishTypeCheckingFile(SF); });
652651
}
653652

654653
void CompilerInstance::performParseOnly(bool EvaluateConditionals) {

lib/Sema/TypeCheckDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3969,6 +3969,10 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
39693969
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
39703970
TC.checkDeclCircularity(nominal);
39713971
}
3972+
if (auto protocol = dyn_cast<ProtocolDecl>(decl)) {
3973+
if (!protocol->hasFixedLayout())
3974+
TC.inferDefaultWitnesses(protocol);
3975+
}
39723976
}
39733977
}
39743978

lib/Sema/TypeChecker.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -672,16 +672,6 @@ void swift::performTypeChecking(SourceFile &SF, TopLevelContext &TLC,
672672
}
673673
}
674674

675-
void swift::finishTypeCheckingFile(SourceFile &SF) {
676-
auto &Ctx = SF.getASTContext();
677-
TypeChecker TC(Ctx);
678-
679-
for (auto D : SF.Decls)
680-
if (auto PD = dyn_cast<ProtocolDecl>(D))
681-
if (!PD->hasFixedLayout())
682-
TC.inferDefaultWitnesses(PD);
683-
}
684-
685675
void swift::performWholeModuleTypeChecking(SourceFile &SF) {
686676
SharedTimer("performWholeModuleTypeChecking");
687677
auto &Ctx = SF.getASTContext();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public protocol Node: Source { }
2+
3+
public protocol Source {
4+
associatedtype Output
5+
}
6+
7+
public final class GraphNode<U>: Node {
8+
public typealias Output = U
9+
}

test/multifile/default-witness.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-frontend -typecheck %S/Inputs/default-witness.swift -primary-file %s -enable-resilience
2+
3+
public protocol GraphType {
4+
func insert<U>(_: GraphNode<U>, _: GraphNode<U>)
5+
}
6+
7+
public extension GraphType {
8+
func insert<N: Node>(_: N, _: GraphNode<N.Output>) {}
9+
}
10+

0 commit comments

Comments
 (0)