Mess with the way we do canonicalization for ProtocolCompositionTypes in a way

that doesn't violate canonical type invariants.  It's still a little messy,
but it's consistent.  Fixes <rdar://problem/11886926>.



Swift SVN r2368
This commit is contained in:
Eli Friedman
2012-07-18 01:31:40 +00:00
parent 29b3994cca
commit 6a4098b102
6 changed files with 65 additions and 58 deletions

View File

@@ -991,23 +991,18 @@ private:
/// protocol, then the canonical type is that protocol type. Otherwise, it is
/// a composition of the protocols in that list.
class ProtocolCompositionType : public TypeBase, public llvm::FoldingSetNode {
ASTContext &Ctx; // Note: Needed for canonicalization of the empty case.
SourceLoc FirstLoc; // FIXME: Egregious hack due to lack of TypeLocs
ArrayRef<Type> Protocols;
public:
/// \brief Retrieve an instance of a protocol composition type with the
/// given set of protocols.
static ProtocolCompositionType *
get(ASTContext &C, SourceLoc FirstLoc, ArrayRef<Type> Protocols);
static Type get(ASTContext &C, SourceLoc FirstLoc, ArrayRef<Type> Protocols);
/// \brief Retrieve the source location where this type was first uttered.
/// FIXME: This is a hackaround for the lack of TypeLocs.
SourceLoc getFirstLoc() const { return FirstLoc; }
/// \brief Retrieve the AST context of this type.
ASTContext &getASTContext() const { return Ctx; }
/// \brief Retrieve the set of protocols composed to create this type.
ArrayRef<Type> getProtocols() const { return Protocols; }
@@ -1025,11 +1020,14 @@ public:
}
private:
ProtocolCompositionType(ASTContext &Ctx, SourceLoc FirstLoc,
static ProtocolCompositionType *build(ASTContext &C, SourceLoc FirstLoc,
ArrayRef<Type> Protocols);
ProtocolCompositionType(ASTContext *Ctx, SourceLoc FirstLoc,
ArrayRef<Type> Protocols)
: TypeBase(TypeKind::ProtocolComposition, /*Context=*/nullptr,
: TypeBase(TypeKind::ProtocolComposition, /*Context=*/Ctx,
/*Unresolved=*/false),
Ctx(Ctx), FirstLoc(FirstLoc), Protocols(Protocols) { }
FirstLoc(FirstLoc), Protocols(Protocols) { }
};
/// LValueType - An l-value is a handle to a physical object. The