SIL: Split off reclaimUnresolvedLocalArchetypeDefinitions()

Just to be extra safe, I'm only going to call this when captured local archetypes
are present.
This commit is contained in:
Slava Pestov
2024-05-17 13:01:00 -04:00
parent 237e393dba
commit e8714e7e5a
2 changed files with 12 additions and 2 deletions

View File

@@ -687,13 +687,16 @@ SILValue SILModule::getRootLocalArchetypeDef(CanLocalArchetypeType archetype,
return def;
}
bool SILModule::hasUnresolvedLocalArchetypeDefinitions() {
// Garbage collect dead placeholders first.
void SILModule::reclaimUnresolvedLocalArchetypeDefinitions() {
llvm::DenseMap<LocalArchetypeKey, SILValue> newLocalArchetypeDefs;
for (auto pair : RootLocalArchetypeDefs) {
if (auto *placeholder = dyn_cast<PlaceholderValue>(pair.second)) {
// If a placeholder has no uses, the instruction that introduced it
// was deleted before the local archetype was resolved. Reclaim the
// placeholder so that we don't complain.
if (placeholder->use_empty()) {
assert(numUnresolvedLocalArchetypes > 0);
--numUnresolvedLocalArchetypes;
::delete placeholder;
continue;
@@ -704,7 +707,9 @@ bool SILModule::hasUnresolvedLocalArchetypeDefinitions() {
}
std::swap(newLocalArchetypeDefs, RootLocalArchetypeDefs);
}
bool SILModule::hasUnresolvedLocalArchetypeDefinitions() {
return numUnresolvedLocalArchetypes != 0;
}