[Serialization] Drop extensions whose requirements are missing types (#17488)

If, for whatever reason, a type used in an extension's generic
requirements is missing, just drop the whole extension. This isn't
wonderful recovery, but in practice nothing should be able to use the
extension anyway, since the relevant type in question is missing.

...Okay, that's not quite true; there could, for example, be inlinable
code that references one of these methods. However, that (1) isn't
worse than the behavior for any other inlinable code (which doesn't
yet attempt to recover from missing declarations), and (2) is still a
strict improvement over the current situation, where we will eagerly
abort the compiler trying to load the extension in the first place.

rdar://problem/40956460
This commit is contained in:
Jordan Rose
2018-06-25 19:17:11 -07:00
committed by GitHub
parent 55fb2e313c
commit 7f33f47ab3
2 changed files with 18 additions and 4 deletions

View File

@@ -2698,10 +2698,12 @@ void Serializer::writeDecl(const Decl *D) {
inheritedAndDependencyTypes.push_back(addTypeRef(inherited.getType()));
size_t numInherited = inheritedAndDependencyTypes.size();
// FIXME: Figure out what to do with requirements and such, which the
// extension also depends on. Right now just do what is safe to drop, which
// is the base declaration.
auto dependencies = collectDependenciesFromType(baseTy);
llvm::SmallSetVector<Type, 4> dependencies;
collectDependenciesFromType(dependencies, baseTy, /*excluding*/nullptr);
for (Requirement req : extension->getGenericRequirements()) {
collectDependenciesFromRequirement(dependencies, req,
/*excluding*/nullptr);
}
for (auto dependencyTy : dependencies)
inheritedAndDependencyTypes.push_back(addTypeRef(dependencyTy));