Merge pull request #40282 from hborla/existential-any

[SE-0335] Introduce existential `any`
This commit is contained in:
Holly Borla
2021-12-10 08:56:03 -08:00
committed by GitHub
51 changed files with 1035 additions and 24 deletions

View File

@@ -408,6 +408,7 @@ struct ASTContext::Implementation {
llvm::DenseMap<std::pair<StructDecl*, Type>, StructType*> StructTypes;
llvm::DenseMap<std::pair<ClassDecl*, Type>, ClassType*> ClassTypes;
llvm::DenseMap<std::pair<ProtocolDecl*, Type>, ProtocolType*> ProtocolTypes;
llvm::DenseMap<Type, ExistentialType *> ExistentialTypes;
llvm::FoldingSet<UnboundGenericType> UnboundGenericTypes;
llvm::FoldingSet<BoundGenericType> BoundGenericTypes;
llvm::FoldingSet<ProtocolCompositionType> ProtocolCompositionTypes;
@@ -4113,6 +4114,21 @@ ProtocolType::ProtocolType(ProtocolDecl *TheDecl, Type Parent,
RecursiveTypeProperties properties)
: NominalType(TypeKind::Protocol, &Ctx, TheDecl, Parent, properties) { }
ExistentialType *ExistentialType::get(Type constraint) {
auto properties = constraint->getRecursiveProperties();
auto arena = getArena(properties);
auto &C = constraint->getASTContext();
auto &entry = C.getImpl().getArena(arena).ExistentialTypes[constraint];
if (entry)
return entry;
const ASTContext *canonicalContext = constraint->isCanonical() ? &C : nullptr;
return entry = new (C, arena) ExistentialType(constraint,
canonicalContext,
properties);
}
LValueType *LValueType::get(Type objectTy) {
assert(!objectTy->is<LValueType>() && !objectTy->is<InOutType>() &&
"cannot have 'inout' or @lvalue wrapped inside an @lvalue");