mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
AST: Change TypeAliasDecls to store an interface type as their underlying type
- TypeAliasDecl::getAliasType() is gone. Now, getDeclaredInterfaceType() always returns the NameAliasType. - NameAliasTypes now always desugar to the underlying type as an interface type. - The NameAliasType of a generic type alias no longer desugars to an UnboundGenericType; call TypeAliasDecl::getUnboundGenericType() if you want that. - The "lazy mapTypeOutOfContext()" hack for deserialized TypeAliasDecls is gone. - The process of constructing a synthesized TypeAliasDecl is much simpler now; instead of calling computeType(), setInterfaceType() and then setting the recursive properties in the right order, just call setUnderlyingType(), passing it either an interface type or a contextual type. In particular, many places weren't setting the recursive properties, such as the ClangImporter and deserialization. This meant that queries such as hasArchetype() or hasTypeParameter() would return incorrect results on NameAliasTypes, which caused various subtle problems. - Finally, add some more tests for generic typealiases, most of which fail because they're still pretty broken.
This commit is contained in:
@@ -307,10 +307,9 @@ void IterativeTypeChecker::processResolveTypeDecl(
|
||||
TypeDecl *typeDecl,
|
||||
UnsatisfiedDependency unsatisfiedDependency) {
|
||||
if (auto typeAliasDecl = dyn_cast<TypeAliasDecl>(typeDecl)) {
|
||||
if (typeAliasDecl->getDeclContext()->isModuleScopeContext()) {
|
||||
// FIXME: This is silly.
|
||||
if (!typeAliasDecl->getAliasType())
|
||||
typeAliasDecl->computeType();
|
||||
if (typeAliasDecl->getDeclContext()->isModuleScopeContext() &&
|
||||
typeAliasDecl->getGenericParams() == nullptr) {
|
||||
typeAliasDecl->setHasCompletedValidation();
|
||||
|
||||
TypeResolutionOptions options;
|
||||
if (typeAliasDecl->getFormalAccess() <= Accessibility::FilePrivate)
|
||||
@@ -322,30 +321,12 @@ void IterativeTypeChecker::processResolveTypeDecl(
|
||||
if (TC.validateType(typeAliasDecl->getUnderlyingTypeLoc(), typeAliasDecl,
|
||||
options, &resolver, &unsatisfiedDependency)) {
|
||||
typeAliasDecl->setInvalid();
|
||||
typeAliasDecl->setInterfaceType(ErrorType::get(getASTContext()));
|
||||
typeAliasDecl->getUnderlyingTypeLoc().setInvalidType(getASTContext());
|
||||
}
|
||||
|
||||
if (typeAliasDecl->getUnderlyingTypeLoc().wasValidated()) {
|
||||
// We create TypeAliasTypes with invalid underlying types, so we
|
||||
// need to propagate recursive properties now.
|
||||
typeAliasDecl->getAliasType()->setRecursiveProperties(
|
||||
typeAliasDecl->getUnderlyingType()->getRecursiveProperties());
|
||||
|
||||
// Map the alias type out of context; if it is not dependent,
|
||||
// we'll keep the sugar.
|
||||
Type interfaceTy = typeAliasDecl->getAliasType();
|
||||
|
||||
// lldb creates global typealiases containing archetypes
|
||||
// sometimes...
|
||||
if (typeAliasDecl->getUnderlyingType()->hasArchetype() &&
|
||||
typeAliasDecl->isGenericContext()) {
|
||||
interfaceTy = typeAliasDecl->mapTypeOutOfContext(interfaceTy);
|
||||
}
|
||||
|
||||
typeAliasDecl->setInterfaceType(
|
||||
MetatypeType::get(interfaceTy,
|
||||
typeDecl->getASTContext()));
|
||||
typeAliasDecl->setUnderlyingType(
|
||||
typeAliasDecl->getUnderlyingTypeLoc().getType());
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user