Skip to content

Commit 437da8c

Browse files
committed
Avoid verifying un-parented GenericTypeParamDecls
When deserializing, we delay parenting GenericTypeParamDecls until we install the GenericParamList on the parent declaration, using a dummy parent of the ModuleDecl until this happens. However when deserializing GenericTypeParamTypes, we don't necessarily get the opportunity to deserialize the parent, leaving them with the dummy parent. We should probably consider not deserializing GenericTypeParamDecls at all, we currently only do it to preserve the sugar of the name, this could be serialized on the type instead. For now though, adjust the dummy parent to be the SerializedASTFile, and tell the ASTVerifier to skip verification for such generic params.
1 parent 21b733b commit 437da8c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/AST/ASTVerifier.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2732,7 +2732,18 @@ class Verifier : public ASTWalker {
27322732
PrettyStackTraceDecl debugStack("verifying GenericTypeParamDecl", GTPD);
27332733

27342734
const DeclContext *DC = GTPD->getDeclContext();
2735-
if (!GTPD->getDeclContext()->isInnermostContextGeneric()) {
2735+
2736+
// Skip verification of deserialized generic param decls that have the
2737+
// the file set as their parent. This happens when they have not yet had
2738+
// their correct parent set.
2739+
// FIXME: This is a hack to workaround the fact that we don't necessarily
2740+
// parent a GenericTypeParamDecl if we just deserialize its type.
2741+
if (auto *fileDC = dyn_cast<FileUnit>(DC)) {
2742+
if (fileDC->getKind() == FileUnitKind::SerializedAST)
2743+
return;
2744+
}
2745+
2746+
if (!DC->isInnermostContextGeneric()) {
27362747
Out << "DeclContext of GenericTypeParamDecl does not have "
27372748
"generic params\n";
27382749
abort();

lib/Serialization/Deserialization.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,9 +2487,9 @@ class DeclDeserializer {
24872487
depth,
24882488
index);
24892489

2490-
// Always create GenericTypeParamDecls in the associated module;
2491-
// the real context will reparent them.
2492-
auto DC = MF.getAssociatedModule();
2490+
// Always create GenericTypeParamDecls in the associated file; the real
2491+
// context will reparent them.
2492+
auto *DC = MF.getFile();
24932493
auto genericParam = MF.createDecl<GenericTypeParamDecl>(
24942494
DC, MF.getIdentifier(nameID), SourceLoc(), depth, index);
24952495
declOrOffset = genericParam;

0 commit comments

Comments
 (0)