[Type checker] Keep the type checker alive as long as the ASTContext is.

It is possible for the SIL optimizers, IRGen, etc. to request information
from the AST that only the type checker can provide, but the type checker
is typically torn down after the “type checking” phase. This can lead to
various crashes late in the compilation cycle.

Keep the type checker instance around as long as the ASTContext is alive
or until someone asks for it to be destroyed.

Fixes SR-285 / rdar://problem/23677338.
This commit is contained in:
Doug Gregor
2018-10-10 16:44:42 -07:00
parent 4f4167bcac
commit 599e07e5d9
16 changed files with 142 additions and 168 deletions

View File

@@ -960,8 +960,7 @@ static bool reportModuleDocInfo(CompilerInvocation Invocation,
return true;
ASTContext &Ctx = CI.getASTContext();
// Setup a typechecker for protocol conformance resolving.
OwnedResolver TypeResolver = createLazyResolver(Ctx);
(void)createTypeChecker(Ctx);
SourceTextInfo IFaceInfo;
if (getModuleInterfaceInfo(Ctx, ModuleName, IFaceInfo))
@@ -1089,7 +1088,7 @@ static bool reportSourceDocInfo(CompilerInvocation Invocation,
CI.performSema();
// Setup a typechecker for protocol conformance resolving.
OwnedResolver TypeResolver = createLazyResolver(Ctx);
(void)createTypeChecker(Ctx);
SourceTextInfo SourceInfo;
if (getSourceTextInfo(CI, SourceInfo))
@@ -1447,7 +1446,8 @@ findModuleGroups(StringRef ModuleName, ArrayRef<const char *> Args,
ASTContext &Ctx = CI.getASTContext();
// Setup a typechecker for protocol conformance resolving.
OwnedResolver TypeResolver = createLazyResolver(Ctx);
(void)createTypeChecker(Ctx);
// Load standard library so that Clang importer can use it.
auto *Stdlib = getModuleByFullName(Ctx, Ctx.StdlibModuleName);
if (!Stdlib) {