AST: Assign interface types to ParamDecls

First, ensure all ParamDecls that are synthesized from scratch are given
both a contextual type and an interface type.

For ParamDecls written in source, add a new recordParamType() method to
GenericTypeResolver. This calls setType() or setInterfaceType() as
appropriate.

Interestingly enough a handful of diagnostics in the test suite have
improved. I'm not sure why, but I'll take it.

The ParamDecl::createUnboundSelf() method is now only used in the parser,
and no longer sets the type of the self parameter to the unbound generic
type. This was wrong anyway, since the type was always being overwritten.
This allows us to remove DeclContext::getSelfTypeOfContext().

Also, ensure that FuncDecl::getBodyResultTypeLoc() always has an interface
type for synthesized declarations, eliminating a mapTypeOutOfContext()
call when computing the function interface type in configureInterfaceType().

Finally, clean up the logic for resolving the DynamicSelfType. We now
get the interface or contextual type of 'Self' via the resolver, instead
of always getting the contextual type and patching it up inside
configureInterfaceType().
This commit is contained in:
Slava Pestov
2016-12-03 18:57:14 -08:00
parent 3e883682aa
commit 1a991da16d
37 changed files with 367 additions and 405 deletions

View File

@@ -201,7 +201,7 @@ public:
ArrayRef<Substitution> witnessSubs) {
auto *dc = witness->getDeclContext();
Type selfInterfaceType = dc->getSelfInterfaceType();
Type selfType = witness->computeSelfType()->getRValueInstanceType();
Type selfType = witness->mapTypeIntoContext(selfInterfaceType);
SILDeclRef constant(witness);
auto constantInfo = SGM.Types.getConstantInfo(constant);
@@ -305,7 +305,7 @@ public:
}
CanType witnessSelfType =
Witness->computeInterfaceSelfType(false)->getCanonicalType();
Witness->computeInterfaceSelfType()->getCanonicalType();
witnessSelfType = getSubstWitnessInterfaceType(witnessSelfType);
if (auto selfTuple = dyn_cast<TupleType>(witnessSelfType)) {
assert(selfTuple->getNumElements() == 1);