@@ -530,6 +530,7 @@ struct ASTContext::Implementation {
530530
531531 llvm::DenseMap<Type, ErrorType *> ErrorTypesWithOriginal;
532532 llvm::FoldingSet<TypeAliasType> TypeAliasTypes;
533+ llvm::FoldingSet<LocatableType> LocatableTypes;
533534 llvm::FoldingSet<TupleType> TupleTypes;
534535 llvm::FoldingSet<PackType> PackTypes;
535536 llvm::FoldingSet<PackExpansionType> PackExpansionTypes;
@@ -3272,6 +3273,7 @@ void ASTContext::Implementation::Arena::dump(llvm::raw_ostream &os) const {
32723273
32733274 SIZE_AND_BYTES (ErrorTypesWithOriginal);
32743275 SIZE (TypeAliasTypes);
3276+ SIZE (LocatableTypes);
32753277 SIZE (TupleTypes);
32763278 SIZE (PackTypes);
32773279 SIZE (PackExpansionTypes);
@@ -3454,6 +3456,45 @@ void TypeAliasType::Profile(
34543456 id.AddPointer (underlying.getPointer ());
34553457}
34563458
3459+ LocatableType::LocatableType (SourceLoc loc, Type underlying,
3460+ RecursiveTypeProperties properties)
3461+ : SugarType(TypeKind::Locatable, underlying, properties), Loc(loc) {
3462+ ASSERT (loc.isValid ());
3463+ }
3464+
3465+ LocatableType *LocatableType::get (SourceLoc loc, Type underlying) {
3466+ auto properties = underlying->getRecursiveProperties ();
3467+
3468+ // Figure out which arena this type will go into.
3469+ auto &ctx = underlying->getASTContext ();
3470+ auto arena = getArena (properties);
3471+
3472+ // Profile the type.
3473+ llvm::FoldingSetNodeID id;
3474+ LocatableType::Profile (id, loc, underlying);
3475+
3476+ // Did we already record this type?
3477+ void *insertPos;
3478+ auto &types = ctx.getImpl ().getArena (arena).LocatableTypes ;
3479+ if (auto result = types.FindNodeOrInsertPos (id, insertPos))
3480+ return result;
3481+
3482+ // Build a new type.
3483+ auto result = new (ctx, arena) LocatableType (loc, underlying, properties);
3484+ types.InsertNode (result, insertPos);
3485+ return result;
3486+ }
3487+
3488+ void LocatableType::Profile (llvm::FoldingSetNodeID &id) const {
3489+ Profile (id, Loc, Type (getSinglyDesugaredType ()));
3490+ }
3491+
3492+ void LocatableType::Profile (llvm::FoldingSetNodeID &id, SourceLoc loc,
3493+ Type underlying) {
3494+ id.AddPointer (loc.getOpaquePointerValue ());
3495+ id.AddPointer (underlying.getPointer ());
3496+ }
3497+
34573498// Simple accessors.
34583499Type ErrorType::get (const ASTContext &C) { return C.TheErrorType ; }
34593500
0 commit comments