Skip to content

Commit 8f2e53c

Browse files
committed
[AST] Make sure that hole types are always allocated in ConstraintSolver arena
Since `HoleType` directly as well as other types which could contain holes are bound to a lifetime of constraint system that created them, we need to make sure that such types are always allocated using `ConstraintSolver` arena instead of a permanent one.
1 parent b6c2f89 commit 8f2e53c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/AST/ASTContext.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,8 +1466,9 @@ bool ASTContext::hadError() const {
14661466
/// Retrieve the arena from which we should allocate storage for a type.
14671467
static AllocationArena getArena(RecursiveTypeProperties properties) {
14681468
bool hasTypeVariable = properties.hasTypeVariable();
1469-
return hasTypeVariable? AllocationArena::ConstraintSolver
1470-
: AllocationArena::Permanent;
1469+
bool hasHole = properties.hasTypeHole();
1470+
return hasTypeVariable || hasHole ? AllocationArena::ConstraintSolver
1471+
: AllocationArena::Permanent;
14711472
}
14721473

14731474
void ASTContext::addSearchPath(StringRef searchPath, bool isFramework,
@@ -2360,9 +2361,13 @@ Type ErrorType::get(Type originalType) {
23602361

23612362
Type HoleType::get(ASTContext &ctx, OriginatorType originator) {
23622363
assert(originator);
2363-
RecursiveTypeProperties properties = RecursiveTypeProperties::HasTypeHole;
2364+
auto properties = reinterpret_cast<TypeBase *>(originator.getOpaqueValue())
2365+
->getRecursiveProperties();
2366+
properties |= RecursiveTypeProperties::HasTypeHole;
2367+
23642368
auto arena = getArena(properties);
2365-
return new (ctx, arena) HoleType(ctx, originator, properties);
2369+
return new (ctx, arena)
2370+
HoleType(ctx, originator, RecursiveTypeProperties::HasTypeHole);
23662371
}
23672372

23682373
BuiltinIntegerType *BuiltinIntegerType::get(BuiltinIntegerWidth BitWidth,

0 commit comments

Comments
 (0)