@@ -530,6 +530,7 @@ struct ASTContext::Implementation {
530
530
531
531
llvm::DenseMap<Type, ErrorType *> ErrorTypesWithOriginal;
532
532
llvm::FoldingSet<TypeAliasType> TypeAliasTypes;
533
+ llvm::FoldingSet<LocatableType> LocatableTypes;
533
534
llvm::FoldingSet<TupleType> TupleTypes;
534
535
llvm::FoldingSet<PackType> PackTypes;
535
536
llvm::FoldingSet<PackExpansionType> PackExpansionTypes;
@@ -3272,6 +3273,7 @@ void ASTContext::Implementation::Arena::dump(llvm::raw_ostream &os) const {
3272
3273
3273
3274
SIZE_AND_BYTES (ErrorTypesWithOriginal);
3274
3275
SIZE (TypeAliasTypes);
3276
+ SIZE (LocatableTypes);
3275
3277
SIZE (TupleTypes);
3276
3278
SIZE (PackTypes);
3277
3279
SIZE (PackExpansionTypes);
@@ -3454,6 +3456,45 @@ void TypeAliasType::Profile(
3454
3456
id.AddPointer (underlying.getPointer ());
3455
3457
}
3456
3458
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
+
3457
3498
// Simple accessors.
3458
3499
Type ErrorType::get (const ASTContext &C) { return C.TheErrorType ; }
3459
3500
0 commit comments