Open ezyang opened 6 years ago
It was originally called eraseFromParent
, from LLVM. Maybe it had that weird name in LLVM for a reason.
Another possibility is to make destroy take an iterator reference. Then if the iterator points at the thing you want to destroy, it will instead fix the iterator. I saw myself writing this:
JIT_ASSERT(rhs->uses().size() == 1);
// TODO: This is awful! See https://github.com/ezyang/pytorch/issues/254
if (*it == rhs_select) {
it.destroyCurrent();
} else {
rhs_select->destroy();
}
if (*it == rhs) {
it.destroyCurrent();
} else {
rhs->destroy();
}
It is far too easy to accidentally invalidate an iterator this way. Let's name it something longer so you remember.