Force generic parameter types declared in module context to belong to

the current SIL module, unless the AST sees them first.

This turns out to be important when we deserialize generic
reabstraction thunks, which have shared linkage so get serialized
again in the current SIL module.

There are some fundamental inconsistencies in the way parameter type
decls are handled, but we need a quick workaround to unblock progress
on the stdlib.

Fixes
<rdar://problem/16807985> Building Foundation overlay crashes in stdlib deserialization in r17377

Swift SVN r18173
This commit is contained in:
Andrew Trick
2014-05-16 04:27:09 +00:00
parent c1db20d178
commit fa898f5562
3 changed files with 23 additions and 2 deletions

View File

@@ -787,6 +787,20 @@ GenericParamList *ModuleFile::maybeReadGenericParams(DeclContext *DC,
DeclID paramDeclID;
GenericParamLayout::readRecord(scratch, paramDeclID);
auto genericParam = cast<GenericTypeParamDecl>(getDecl(paramDeclID, DC));
// FIXME: There are unfortunate inconsistencies in the treatment of
// generic param decls. Currently the first request for context wins
// because we don't want to change context on-the-fly.
// Here are typical scenarios:
// (1) AST reads decl, get's scope.
// Later, readSILFunction tries to force module scope.
// (2) readSILFunction forces module scope.
// Later, readVTable requests an enclosing scope.
// ...other combinations are possible, but as long as AST lookups
// precede SIL linkage, we should be ok.
assert((genericParam->getDeclContext()->isModuleScopeContext() ||
DC->isModuleScopeContext() ||
genericParam->getDeclContext() == DC) &&
"Mismatched decl context for generic types.");
params.push_back(GenericParam(genericParam));
break;
}