[sil-deserialization] Implement cache invalidation for all serialized SIL entities and use it to properly invalidate global variables/witness tables when we delete them.

Otherwise, one runs into memory corruption. I ran into this while enabling ossa
on the stdlib for non-Darwin platforms.

Hopefully we do not regress on this again when someone adds more optzns that
eliminate these since I added a big NOTE to warn people to do it and implemented
support even for the entities we do not support deleting at the SIL
level... yet.
This commit is contained in:
Michael Gottesman
2021-02-17 13:15:57 -08:00
parent 8b563d24e3
commit 891bd00f66
5 changed files with 267 additions and 26 deletions

View File

@@ -144,14 +144,58 @@ SerializedSILLoader::lookupDifferentiabilityWitness(
return dw;
}
void SerializedSILLoader::invalidateCaches() {
for (auto &Des : LoadedSILSections)
Des->invalidateFunctionCache();
void SerializedSILLoader::invalidateAllCaches() {
for (auto &des : LoadedSILSections)
des->invalidateAllCaches();
}
bool SerializedSILLoader::invalidateFunction(SILFunction *F) {
for (auto &Des : LoadedSILSections)
if (Des->invalidateFunction(F))
bool SerializedSILLoader::invalidateFunction(SILFunction *fn) {
for (auto &des : LoadedSILSections)
if (des->invalidateFunction(fn))
return true;
return false;
}
bool SerializedSILLoader::invalidateGlobalVariable(SILGlobalVariable *gv) {
for (auto &des : LoadedSILSections)
if (des->invalidateGlobalVariable(gv))
return true;
return false;
}
bool SerializedSILLoader::invalidateVTable(SILVTable *vt) {
for (auto &des : LoadedSILSections)
if (des->invalidateVTable(vt))
return true;
return false;
}
bool SerializedSILLoader::invalidateWitnessTable(SILWitnessTable *wt) {
for (auto &des : LoadedSILSections)
if (des->invalidateWitnessTable(wt))
return true;
return false;
}
bool SerializedSILLoader::invalidateDefaultWitnessTable(
SILDefaultWitnessTable *wt) {
for (auto &des : LoadedSILSections)
if (des->invalidateDefaultWitnessTable(wt))
return true;
return false;
}
bool SerializedSILLoader::invalidateProperty(SILProperty *p) {
for (auto &des : LoadedSILSections)
if (des->invalidateProperty(p))
return true;
return false;
}
bool SerializedSILLoader::invalidateDifferentiabilityWitness(
SILDifferentiabilityWitness *w) {
for (auto &des : LoadedSILSections)
if (des->invalidateDifferentiabilityWitness(w))
return true;
return false;
}