SIL: Replace SILFunction::ContextGenericParams with a GenericEnvironment

This patch is rather large, since it was hard to make this change
incrementally, but most of the changes are mechanical.

Now that we have a lighter-weight data structure in the AST for mapping
interface types to archetypes and vice versa, use that in SIL instead of
a GenericParamList.

This means that when serializing a SILFunction body, we no longer need to
serialize references to archetypes from other modules.

Several methods used for forming substitutions can now be moved from
GenericParamList to GenericEnvironment.

Also, GenericParamList::cloneWithOuterParameters() and
GenericParamList::getEmpty() can now go away, since they were only used
when SILGen-ing witness thunks.

Finally, when printing generic parameters with identical names, the
SIL printer used to number them from highest depth to lowest, by
walking generic parameter lists starting with the innermost one.
Now, ambiguous generic parameters are numbered from lowest depth
to highest, by walking the generic signature, which means test
output in one of the SILGen tests has changed.
This commit is contained in:
Slava Pestov
2016-08-25 22:42:33 -07:00
parent b9b296b32a
commit ca0b548584
50 changed files with 422 additions and 450 deletions

View File

@@ -19,6 +19,7 @@
#include "swift/AST/ASTPrinter.h"
#include "swift/AST/ASTWalker.h"
#include "swift/AST/DiagnosticsSema.h"
#include "swift/AST/GenericEnvironment.h"
#include "swift/AST/LazyResolver.h"
#include "swift/AST/LinkLibrary.h"
#include "swift/AST/ModuleLoader.h"
@@ -587,16 +588,15 @@ TypeBase::gatherAllSubstitutions(Module *module,
auto *parentDC = gpContext;
while (parent) {
if (auto boundGeneric = dyn_cast<BoundGenericType>(parent)) {
auto genericParams = parentDC->getGenericParamsOfContext();
auto genericSig = parentDC->getGenericSignatureOfContext();
unsigned index = 0;
assert(boundGeneric->getGenericArgs().size() ==
genericParams->getParams().size());
genericSig->getInnermostGenericParams().size());
for (Type arg : boundGeneric->getGenericArgs()) {
auto gp = genericParams->getParams()[index++];
substitutions[gp->getDeclaredType()->getCanonicalType()
.getPointer()] = arg;
auto paramTy = genericSig->getInnermostGenericParams()[index++];
substitutions[paramTy->getCanonicalType().getPointer()] = arg;
}
parent = CanType(boundGeneric->getParent());
@@ -615,8 +615,11 @@ TypeBase::gatherAllSubstitutions(Module *module,
// Add forwarding substitutions from the outer context if we have
// a type nested inside a generic function.
if (auto *outerParams = parentDC->getGenericParamsOfContext())
outerParams->getForwardingSubstitutionMap(substitutions);
if (auto *outerEnv = parentDC->getGenericEnvironmentOfContext())
for (auto pair : outerEnv->getInterfaceToArchetypeMap()) {
auto result = substitutions.insert(pair);
assert(result.second);
}
auto lookupConformanceFn =
[&](Type replacement, ProtocolType *protoType)