Skip to content

Commit 2aea662

Browse files
committed
AST: Introduce a new LookUpConformanceInSignature functor
For now, it "cheats" and performs the lookup in the module declaring the protocol. This will change shortly.
1 parent 1e46f13 commit 2aea662

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

include/swift/AST/Type.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ class MakeAbstractConformanceForGenericType {
125125
ProtocolType *conformedProtocol) const;
126126
};
127127

128+
/// Functor class suitable for use as a \c LookupConformanceFn that fetches
129+
/// conformances from a generic signature.
130+
class LookUpConformanceInSignature {
131+
const GenericSignature &Sig;
132+
public:
133+
LookUpConformanceInSignature(const GenericSignature &Sig)
134+
: Sig(Sig) {}
135+
136+
Optional<ProtocolConformanceRef>
137+
operator()(CanType dependentType,
138+
Type conformingReplacementType,
139+
ProtocolType *conformedProtocol) const;
140+
};
141+
128142
/// Flags that can be passed when substituting into a type.
129143
enum class SubstFlags {
130144
/// If a type cannot be produced because some member type is

lib/AST/Type.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,8 +2961,8 @@ LookUpConformanceInModule::operator()(CanType dependentType,
29612961
return ProtocolConformanceRef(conformedProtocol->getDecl());
29622962

29632963
return M->lookupConformance(conformingReplacementType,
2964-
conformedProtocol->getDecl(),
2965-
conformingReplacementType->getASTContext().getLazyResolver());
2964+
conformedProtocol->getDecl(),
2965+
M->getASTContext().getLazyResolver());
29662966
}
29672967

29682968
Optional<ProtocolConformanceRef>
@@ -2982,6 +2982,21 @@ MakeAbstractConformanceForGenericType::operator()(CanType dependentType,
29822982
return ProtocolConformanceRef(conformedProtocol->getDecl());
29832983
}
29842984

2985+
Optional<ProtocolConformanceRef>
2986+
LookUpConformanceInSignature::operator()(CanType dependentType,
2987+
Type conformingReplacementType,
2988+
ProtocolType *conformedProtocol) const {
2989+
// FIXME: Actually implement this properly.
2990+
auto *M = conformedProtocol->getDecl()->getParentModule();
2991+
2992+
if (conformingReplacementType->isTypeParameter())
2993+
return ProtocolConformanceRef(conformedProtocol->getDecl());
2994+
2995+
return M->lookupConformance(conformingReplacementType,
2996+
conformedProtocol->getDecl(),
2997+
M->getASTContext().getLazyResolver());
2998+
}
2999+
29853000
Type DependentMemberType::substBaseType(ModuleDecl *module,
29863001
Type substBase,
29873002
LazyResolver *resolver) {

0 commit comments

Comments
 (0)