Skip to content

Commit e8714e7

Browse files
committed
SIL: Split off reclaimUnresolvedLocalArchetypeDefinitions()
Just to be extra safe, I'm only going to call this when captured local archetypes are present.
1 parent 237e393 commit e8714e7

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

include/swift/SIL/SILModule.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,11 @@ class SILModule {
477477
/// This should only be the case during parsing or deserialization.
478478
bool hasUnresolvedLocalArchetypeDefinitions();
479479

480+
/// If we added any instructions that reference unresolved local archetypes
481+
/// and then deleted those instructions without resolving those archetypes,
482+
/// we must reclaim those unresolved local archetypes.
483+
void reclaimUnresolvedLocalArchetypeDefinitions();
484+
480485
/// Get a unique index for a struct or class field in layout order.
481486
///
482487
/// Precondition: \p decl must be a non-resilient struct or class.

lib/SIL/IR/SILModule.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,13 +687,16 @@ SILValue SILModule::getRootLocalArchetypeDef(CanLocalArchetypeType archetype,
687687
return def;
688688
}
689689

690-
bool SILModule::hasUnresolvedLocalArchetypeDefinitions() {
691-
// Garbage collect dead placeholders first.
690+
void SILModule::reclaimUnresolvedLocalArchetypeDefinitions() {
692691
llvm::DenseMap<LocalArchetypeKey, SILValue> newLocalArchetypeDefs;
693692

694693
for (auto pair : RootLocalArchetypeDefs) {
695694
if (auto *placeholder = dyn_cast<PlaceholderValue>(pair.second)) {
695+
// If a placeholder has no uses, the instruction that introduced it
696+
// was deleted before the local archetype was resolved. Reclaim the
697+
// placeholder so that we don't complain.
696698
if (placeholder->use_empty()) {
699+
assert(numUnresolvedLocalArchetypes > 0);
697700
--numUnresolvedLocalArchetypes;
698701
::delete placeholder;
699702
continue;
@@ -704,7 +707,9 @@ bool SILModule::hasUnresolvedLocalArchetypeDefinitions() {
704707
}
705708

706709
std::swap(newLocalArchetypeDefs, RootLocalArchetypeDefs);
710+
}
707711

712+
bool SILModule::hasUnresolvedLocalArchetypeDefinitions() {
708713
return numUnresolvedLocalArchetypes != 0;
709714
}
710715

0 commit comments

Comments
 (0)