[AST] Create ParameterTypeFlags and put them on function params

Long term, we want to refactor the AST to reflect the current
programming model in Swift. This would include refactoring
FunctionType to take a list of ParameterTypeElt, or something with a
better name, that can contain both the type and flags/bits that are
only specific to types in parameter position, such as @autoclosure and
@escaping. At the same time, noescape-by-default has severely hurt our
ability to print types without significant context, as we either have
to choose to too aggressively print @escaping or not print it in every
situation it occurs, or both.

As a gentle step towards the final solution, without uprooting our
overall AST structure, and as a way towards fixing the @escaping
printing ails, put these bits on the TupleTypeElt and ParenType, which
will serve as a model for what ParameterTypeElt will be like in the
future. Re-use these flags on CallArgParam, to leverage shared
knowledge in the type system. It is a little painful to tack onto
these types, but it's minor and will be overhauled soon, which will
eventually result in size savings and less complexity overall.

This includes all the constraint system adjustments to make these
types work and influence type equality and overload resolution as
desired. They are encoded in the module format. Additional tests
added.
This commit is contained in:
Michael Ilseman
2016-09-21 13:31:52 -07:00
parent 81b0aa7339
commit ed2522b384
13 changed files with 229 additions and 91 deletions

View File

@@ -3446,8 +3446,10 @@ Type ModuleFile::getType(TypeID TID) {
case decls_block::PAREN_TYPE: {
TypeID underlyingID;
decls_block::ParenTypeLayout::readRecord(scratch, underlyingID);
typeOrOffset = ParenType::get(ctx, getType(underlyingID));
uint8_t flagsValue;
decls_block::ParenTypeLayout::readRecord(scratch, underlyingID, flagsValue);
typeOrOffset = ParenType::get(ctx, getType(underlyingID),
ParameterTypeFlags(flagsValue));
break;
}
@@ -3467,11 +3469,12 @@ Type ModuleFile::getType(TypeID TID) {
IdentifierID nameID;
TypeID typeID;
bool isVararg;
uint8_t flagsValue;
decls_block::TupleTypeEltLayout::readRecord(scratch, nameID, typeID,
isVararg);
flagsValue);
elements.push_back({getType(typeID), getIdentifier(nameID), isVararg});
elements.emplace_back(getType(typeID), getIdentifier(nameID),
ParameterTypeFlags(flagsValue));
}
typeOrOffset = TupleType::get(elements, ctx);