ezyang / pytorch-unattached

Tensors and Dynamic neural networks in Python with strong GPU acceleration
http://pytorch.org
Other
20 stars 8 forks source link

Rename Node->destroy #254

Open ezyang opened 6 years ago

ezyang commented 6 years ago

It is far too easy to accidentally invalidate an iterator this way. Let's name it something longer so you remember.

zdevito commented 6 years ago

It was originally called eraseFromParent, from LLVM. Maybe it had that weird name in LLVM for a reason.

ezyang commented 6 years ago

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();
      }