Skip to content

Commit 6460469

Browse files
committed
AST: Directly implement InheritedProtocolsRequest for deserialized protocols
1 parent 21313d4 commit 6460469

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

lib/AST/NameLookup.cpp

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3263,19 +3263,37 @@ SuperclassDeclRequest::evaluate(Evaluator &evaluator,
32633263
ArrayRef<ProtocolDecl *>
32643264
InheritedProtocolsRequest::evaluate(Evaluator &evaluator,
32653265
ProtocolDecl *PD) const {
3266+
auto &ctx = PD->getASTContext();
3267+
32663268
llvm::SmallSetVector<ProtocolDecl *, 2> inherited;
3267-
InvertibleProtocolSet inverses;
3268-
bool anyObject = false;
3269-
for (const auto &found : getDirectlyInheritedNominalTypeDecls(
3270-
PD, inverses, anyObject)) {
3271-
auto proto = dyn_cast<ProtocolDecl>(found.Item);
3272-
if (proto && proto != PD)
3273-
inherited.insert(proto);
3274-
}
32753269

3276-
// FIXME: Apply inverses
3270+
if (PD->wasDeserialized()) {
3271+
auto protoSelfTy = PD->getSelfInterfaceType();
3272+
for (auto req : PD->getRequirementSignature().getRequirements()) {
3273+
// Dig out a conformance requirement...
3274+
if (req.getKind() != RequirementKind::Conformance)
3275+
continue;
3276+
3277+
// constraining Self.
3278+
if (!req.getFirstType()->isEqual(protoSelfTy))
3279+
continue;
3280+
3281+
inherited.insert(req.getProtocolDecl());
3282+
}
3283+
} else {
3284+
InvertibleProtocolSet inverses;
3285+
bool anyObject = false;
3286+
for (const auto &found : getDirectlyInheritedNominalTypeDecls(
3287+
PD, inverses, anyObject)) {
3288+
auto proto = dyn_cast<ProtocolDecl>(found.Item);
3289+
if (proto && proto != PD)
3290+
inherited.insert(proto);
3291+
}
3292+
3293+
// FIXME: Apply inverses
3294+
}
32773295

3278-
return PD->getASTContext().AllocateCopy(inherited.getArrayRef());
3296+
return ctx.AllocateCopy(inherited.getArrayRef());
32793297
}
32803298

32813299
ArrayRef<ValueDecl *>

0 commit comments

Comments
 (0)