Skip to content

Commit 2723946

Browse files
committed
[GSB] Mark conformances used by the GenericSignatureBuilder as “used”.
Prior to the removal of the “lookup conformance function”, whenever the type checker created a GenericSignatureBuilder, its lookup conformance function would mark any referenced conformance as “used”. Do so now via a LazyResolver callback, which fixes a regression in multi-file type checking scenarios.
1 parent a92d8d5 commit 2723946

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

include/swift/AST/LazyResolver.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef SWIFT_AST_LAZYRESOLVER_H
1818
#define SWIFT_AST_LAZYRESOLVER_H
1919

20+
#include "swift/AST/ProtocolConformanceRef.h"
2021
#include "swift/AST/TypeLoc.h"
2122
#include "llvm/ADT/PointerEmbeddedInt.h"
2223

@@ -102,6 +103,10 @@ class LazyResolver {
102103
/// is usable for the given type.
103104
virtual bool isProtocolExtensionUsable(DeclContext *dc, Type type,
104105
ExtensionDecl *protocolExtension) = 0;
106+
107+
/// Mark the given conformance as "used" from the given declaration context.
108+
virtual void markConformanceUsed(ProtocolConformanceRef conformance,
109+
DeclContext *dc) = 0;
105110
};
106111

107112
/// An implementation of LazyResolver that delegates to another.
@@ -171,6 +176,11 @@ class DelegatingLazyResolver : public LazyResolver {
171176
ExtensionDecl *protocolExtension) override {
172177
return Principal.isProtocolExtensionUsable(dc, type, protocolExtension);
173178
}
179+
180+
void markConformanceUsed(ProtocolConformanceRef conformance,
181+
DeclContext *dc) override {
182+
return Principal.markConformanceUsed(conformance, dc);
183+
}
174184
};
175185

176186
class LazyMemberLoader;

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,8 +2919,12 @@ GenericSignatureBuilder::lookupConformance(CanType dependentType,
29192919
// FIXME: When lookupConformance() starts respecting modules, we'll need
29202920
// to do some filtering here.
29212921
ModuleDecl *searchModule = conformedProtocol->getDecl()->getParentModule();
2922-
return searchModule->lookupConformance(conformingReplacementType,
2923-
conformedProtocol->getDecl());
2922+
auto result = searchModule->lookupConformance(conformingReplacementType,
2923+
conformedProtocol->getDecl());
2924+
if (result && getLazyResolver())
2925+
getLazyResolver()->markConformanceUsed(*result, searchModule);
2926+
2927+
return result;
29242928
}
29252929

29262930
LazyResolver *GenericSignatureBuilder::getLazyResolver() const {

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,7 @@ class TypeChecker final : public LazyResolver {
19611961
/// Mark the given protocol conformance as "used" from the given declaration
19621962
/// context.
19631963
void markConformanceUsed(ProtocolConformanceRef conformance,
1964-
DeclContext *dc);
1964+
DeclContext *dc) override final;
19651965

19661966
/// Functor class suitable for use as a \c LookupConformanceFn to look up a
19671967
/// conformance through a particular declaration context using the given

0 commit comments

Comments
 (0)