Skip to content

Commit 85179e0

Browse files
committed
[AST] Make sure that InheritedProtocols::evaluate is never called on a deserialized protocol
The result should always be pre-cached by the deserialization.
1 parent 1d76a1f commit 85179e0

File tree

1 file changed

+32
-45
lines changed

1 file changed

+32
-45
lines changed

lib/AST/NameLookup.cpp

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3257,55 +3257,42 @@ InheritedProtocolsRequest::evaluate(Evaluator &evaluator,
32573257

32583258
llvm::SmallSetVector<ProtocolDecl *, 2> inherited;
32593259

3260-
if (PD->wasDeserialized()) {
3261-
auto protoSelfTy = PD->getSelfInterfaceType();
3262-
for (auto req : PD->getRequirementSignature().getRequirements()) {
3263-
// Dig out a conformance requirement...
3264-
if (req.getKind() != RequirementKind::Conformance)
3265-
continue;
3266-
3267-
// constraining Self.
3268-
if (!req.getFirstType()->isEqual(protoSelfTy))
3269-
continue;
3260+
assert(!PD->wasDeserialized());
32703261

3271-
inherited.insert(req.getProtocolDecl());
3272-
}
3273-
} else {
3274-
InvertibleProtocolSet inverses;
3275-
bool anyObject = false;
3276-
for (const auto &found : getDirectlyInheritedNominalTypeDecls(
3277-
PD, inverses, anyObject)) {
3278-
auto proto = dyn_cast<ProtocolDecl>(found.Item);
3279-
if (proto && proto != PD)
3280-
inherited.insert(proto);
3281-
}
3282-
3283-
// Apply inverses.
3284-
if (ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
3285-
bool skipInverses = false;
3286-
3287-
// ... except for these protocols, so that Copyable does not have to
3288-
// inherit ~Copyable, etc.
3289-
if (auto kp = PD->getKnownProtocolKind()) {
3290-
switch (*kp) {
3291-
case KnownProtocolKind::Sendable:
3292-
case KnownProtocolKind::Copyable:
3293-
case KnownProtocolKind::Escapable:
3294-
skipInverses = true;
3295-
break;
3262+
InvertibleProtocolSet inverses;
3263+
bool anyObject = false;
3264+
for (const auto &found :
3265+
getDirectlyInheritedNominalTypeDecls(PD, inverses, anyObject)) {
3266+
auto proto = dyn_cast<ProtocolDecl>(found.Item);
3267+
if (proto && proto != PD)
3268+
inherited.insert(proto);
3269+
}
3270+
3271+
// Apply inverses.
3272+
if (ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
3273+
bool skipInverses = false;
3274+
3275+
// ... except for these protocols, so that Copyable does not have to
3276+
// inherit ~Copyable, etc.
3277+
if (auto kp = PD->getKnownProtocolKind()) {
3278+
switch (*kp) {
3279+
case KnownProtocolKind::Sendable:
3280+
case KnownProtocolKind::Copyable:
3281+
case KnownProtocolKind::Escapable:
3282+
skipInverses = true;
3283+
break;
32963284

3297-
default:
3298-
break;
3299-
}
3285+
default:
3286+
break;
33003287
}
3288+
}
33013289

3302-
if (!skipInverses) {
3303-
for (auto ip : InvertibleProtocolSet::full()) {
3304-
// Unless the user wrote ~P in the syntactic inheritance clause, the
3305-
// semantic inherited list includes P.
3306-
if (!inverses.contains(ip))
3307-
inherited.insert(ctx.getProtocol(getKnownProtocolKind(ip)));
3308-
}
3290+
if (!skipInverses) {
3291+
for (auto ip : InvertibleProtocolSet::full()) {
3292+
// Unless the user wrote ~P in the syntactic inheritance clause, the
3293+
// semantic inherited list includes P.
3294+
if (!inverses.contains(ip))
3295+
inherited.insert(ctx.getProtocol(getKnownProtocolKind(ip)));
33093296
}
33103297
}
33113298
}

0 commit comments

Comments
 (0)