From 01bb403e55e0760fccdb183b28dc2addbbb414ca Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 28 Nov 2016 01:01:01 -0800 Subject: [PATCH] AST: Prohibit archetypes in setInterfaceType() --- lib/AST/Decl.cpp | 7 +++++++ lib/Sema/TypeCheckConstraints.cpp | 3 ++- lib/Sema/TypeCheckPattern.cpp | 2 +- lib/Sema/TypeCheckStmt.cpp | 3 ++- lib/Serialization/Serialization.cpp | 15 +++++++++------ 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index b1cbd68b575..d174cca64fa 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1705,6 +1705,13 @@ Type ValueDecl::getInterfaceType() const { void ValueDecl::setInterfaceType(Type type) { assert((type.isNull() || !type->hasTypeVariable()) && "Type variable in interface type"); + + // lldb creates global typealiases with archetypes in them. + // FIXME: Add an isDebugAlias() flag, like isDebugVar(). + if (!isa(this)) { + assert((type.isNull() || !type->hasArchetype()) && + "Archetype in interface type"); + } InterfaceTy = type; } diff --git a/lib/Sema/TypeCheckConstraints.cpp b/lib/Sema/TypeCheckConstraints.cpp index e52703df7e8..d61d37e3d9b 100644 --- a/lib/Sema/TypeCheckConstraints.cpp +++ b/lib/Sema/TypeCheckConstraints.cpp @@ -2283,7 +2283,8 @@ bool TypeChecker::typeCheckExprPattern(ExprPattern *EP, DeclContext *DC, Context.getIdentifier("$match"), rhsType, DC); - matchVar->setInterfaceType(rhsType); + matchVar->setInterfaceType(ArchetypeBuilder::mapTypeOutOfContext( + DC, rhsType)); matchVar->setImplicit(); EP->setMatchVar(matchVar); diff --git a/lib/Sema/TypeCheckPattern.cpp b/lib/Sema/TypeCheckPattern.cpp index b37ace4dffa..93563e57e43 100644 --- a/lib/Sema/TypeCheckPattern.cpp +++ b/lib/Sema/TypeCheckPattern.cpp @@ -971,7 +971,7 @@ static bool coercePatternViaConditionalDowncast(TypeChecker &tc, pattern->getLoc(), tc.Context.getIdentifier("$match"), type, dc); - matchVar->setInterfaceType(type); + matchVar->setInterfaceType(ArchetypeBuilder::mapTypeOutOfContext(dc, type)); matchVar->setHasNonPatternBindingInit(); // Form the cast $match as? T, which produces an optional. diff --git a/lib/Sema/TypeCheckStmt.cpp b/lib/Sema/TypeCheckStmt.cpp index f155440058e..db95dabecc6 100644 --- a/lib/Sema/TypeCheckStmt.cpp +++ b/lib/Sema/TypeCheckStmt.cpp @@ -664,7 +664,8 @@ public: generator = new (TC.Context) VarDecl(/*static*/ false, /*IsLet*/ false, S->getInLoc(), TC.Context.getIdentifier(name), generatorTy, DC); - generator->setInterfaceType(generatorTy); + generator->setInterfaceType(ArchetypeBuilder::mapTypeOutOfContext( + DC, generatorTy)); generator->setImplicit(); // Create a pattern binding to initialize the generator. diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index 1a67a3494cd..f23472ed932 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -2521,12 +2521,15 @@ void Serializer::writeDecl(const Decl *D) { verifyAttrSerializable(param); auto contextID = addDeclContextRef(param->getDeclContext()); - Type type = (param->hasType() - ? param->getType() - : Type()); - Type interfaceType = (param->hasInterfaceType() - ? param->getInterfaceType() - : Type()); + Type type, interfaceType; + + if (param->hasType()) { + type = param->getType(); + interfaceType = param->getInterfaceType(); + // FIXME: Interface types for ParamDecls + if (interfaceType->hasArchetype()) + interfaceType = Type(); + } unsigned abbrCode = DeclTypeAbbrCodes[ParamLayout::Code]; ParamLayout::emitRecord(Out, ScratchRecord, abbrCode,