[JIT] failures with nested with blocks + loop continuation
Labels: oncall: jit

### 🐛 Describe the bug

loop continuation + single `with` was fixed in #79749, but nested `with` blocks are still failing:

Add this to `test/jit/test_with.py` to repro:

```python
    def test_with_and_continue_nested(self) -> int:
        def fn(a: int):
            ans = 0
            ans2 = 0
            for i in range(100):
                with torch.no_grad():
                    v1 = i * 2
                    if (a + i) % 6 == 0:
                        continue
                    with torch.no_grad():
                        if (a + i) % 2 == 0:
                            continue
                        v2 = i * i
                    v3 = i * 3 + 4
                    if (a + i + 1) % 7 == 0:
                        continue
                    v4 = i * i * i
                    ans += v2 + v3 + v1 + v4
                ans2 += v1 + v2 + v3 + v4
            return ans, ans2

        fn_s = torch.jit.script(fn)

        self.assertEqual(fn(0), fn_s(0))
        self.assertEqual(fn(1), fn_s(1))
        self.assertEqual(fn(2), fn_s(2))
```

Stacktrace:
```
#1  0x00007fffc93ec27b in c10::detail::torchCheckFail (func=0x7fffccb18b80 <torch::jit::Node::eraseOutput(unsigned long)::__func__> "eraseOutput",
    file=0x7fffccb14074 "../torch/csrc/jit/ir/ir.cpp", line=1315,
    msg=0x7fffccb16378 "outputs_[i]->uses().empty() INTERNAL ASSERT FAILED at \"../torch/csrc/jit/ir/ir.cpp\":1315, please report a bug to PyTorch. ")
    at ../c10/util/Exception.cpp:94
#2  0x00007fffe131d3f4 in c10::detail::torchInternalAssertFail (func=0x7fffccb18b80 <torch::jit::Node::eraseOutput(unsigned long)::__func__> "eraseOutput",
    file=0x7fffccb14074 "../torch/csrc/jit/ir/ir.cpp", line=1315,
    condMsg=0x7fffccb16378 "outputs_[i]->uses().empty() INTERNAL ASSERT FAILED at \"../torch/csrc/jit/ir/ir.cpp\":1315, please report a bug to PyTorch. ")
    at ../c10/util/Exception.h:437
#3  0x00007fffd55079cd in torch::jit::Node::eraseOutput (this=0x55555b29f5f0, i=4) at ../torch/csrc/jit/ir/ir.cpp:1315
#4  0x00007fffd5507d26 in torch::jit::Node::destroy (this=0x55555b29f5f0) at ../torch/csrc/jit/ir/ir.cpp:1341
#5  0x00007fffd5514202 in torch::jit::generic_graph_node_list_iterator<torch::jit::Node>::destroyCurrent (this=0x7fffffff8ba0)
    at ../torch/csrc/jit/ir/graph_node_list.h:103
#6  0x00007fffd5504763 in torch::jit::Block::destroy (this=0x55555b2a1d30) at ../torch/csrc/jit/ir/ir.cpp:750
#7  0x00007fffd5507cb6 in torch::jit::Node::eraseBlock (this=0x55555b291720, i=0) at ../torch/csrc/jit/ir/ir.cpp:1336
#8  0x00007fffd5507d82 in torch::jit::Node::destroy (this=0x55555b291720) at ../torch/csrc/jit/ir/ir.cpp:1344
#9  0x00007fffd5514202 in torch::jit::generic_graph_node_list_iterator<torch::jit::Node>::destroyCurrent (this=0x7fffffff8d20)
    at ../torch/csrc/jit/ir/graph_node_list.h:103
#10 0x00007fffd5504763 in torch::jit::Block::destroy (this=0x55555addb360) at ../torch/csrc/jit/ir/ir.cpp:750
#11 0x00007fffd5507cb6 in torch::jit::Node::eraseBlock (this=0x55555b293b10, i=1) at ../torch/csrc/jit/ir/ir.cpp:1336
#12 0x00007fffd5507d82 in torch::jit::Node::destroy (this=0x55555b293b10) at ../torch/csrc/jit/ir/ir.cpp:1344
#13 0x00007fffd5401987 in torch::jit::inlineConsecutiveIfs (node=0x55555b296ff0) at ../torch/csrc/jit/frontend/exit_transforms.cpp:593
#14 0x00007fffd5401b06 in torch::jit::inlineConsecutiveIfs (block=0x55555b296c60) at ../torch/csrc/jit/frontend/exit_transforms.cpp:617
#15 0x00007fffd5401aeb in torch::jit::inlineConsecutiveIfs (block=0x55555ac5c620) at ../torch/csrc/jit/frontend/exit_transforms.cpp:613
#16 0x00007fffd5401aeb in torch::jit::inlineConsecutiveIfs (block=0x55555b281cb0) at ../torch/csrc/jit/frontend/exit_transforms.cpp:613
#17 0x00007fffd54028fc in torch::jit::TransformExits (graph=...) at ../torch/csrc/jit/frontend/exit_transforms.cpp:881
#18 0x00007fffd53f943f in torch::jit::ConvertToSSA (graph=...) at ../torch/csrc/jit/frontend/convert_to_ssa.cpp:345
#19 0x00007fffd541cb1f in torch::jit::to_ir::to_ir (this=0x7fffffff96f0, def=..., resolver_=..., self=0x0, method=...) at ../torch/csrc/jit/frontend/ir_emitter.cpp:676
```

Possibly caused by a check in exit_transforms.cpp which checks if the parent is a loop continuation (but not if the parent of the prim::With is a loop continuation..) https://github.com/pytorch/pytorch/blob/f9656817df2a745420dbfa015a1f3fd75b3e1b44/torch/csrc/jit/frontend/exit_transforms.cpp#L399-L402

### Versions

based on #79749