# In TorchScript, why does prim::Exit have return a tensor?

**URL:** <https://discuss.pytorch.org/t/in-torchscript-why-does-prim-exit-have-return-a-tensor/120987>\
**Category:** jit\
**Created:** [May 12, 2021, 12:46am UTC](https://discuss.pytorch.org/t/in-torchscript-why-does-prim-exit-have-return-a-tensor/120987 "2021-05-12T00:46:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![garymm](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/garymm/32/38178_2.png) [@garymm](https://discuss.pytorch.org/u/garymm)\
**Post date:** [May 12, 2021, 12:46am UTC](https://discuss.pytorch.org/t/in-torchscript-why-does-prim-exit-have-return-a-tensor/120987/1 "2021-05-12T00:46:31Z")

</div>

Hi,  
I’m trying to understand how the compiler works and have been reading the documentation.

In the section on the [with statement](https://github.com/pytorch/pytorch/blob/75651e3cc4a7683970075c40334896927e4beaff/torch/csrc/jit/OVERVIEW.md#with), I see that `prim::Exit` returns a Tensor in TorchScript graphs.

Why does `prim::Exit` have a return value at all?  
I could be wrong, but it seems impossible for any other code to actually do anything with the return value.

CC @SplitInfinity who I think was involved in implementing the with statement.

---

<div class="post-metadata">

**Author:** ![SplitInfinity](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/5e9695/32.png) [@SplitInfinity](https://discuss.pytorch.org/u/SplitInfinity)\
**Post date:** [May 12, 2021, 1:50am UTC](https://discuss.pytorch.org/t/in-torchscript-why-does-prim-exit-have-return-a-tensor/120987/2 "2021-05-12T01:50:45Z")

</div>

See [this section of the Python language reference for more information](https://docs.python.org/3/reference/compound_stmts.html#the-with-statement). `prim::Exit` corresponds to ` __exit__ ` on the class being used as a context manager and is allowed to return a boolean value.

---

<div class="post-metadata">

**Author:** ![garymm](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/garymm/32/38178_2.png) [@garymm](https://discuss.pytorch.org/u/garymm)\
**Post date:** [May 12, 2021, 4:48pm UTC](https://discuss.pytorch.org/t/in-torchscript-why-does-prim-exit-have-return-a-tensor/120987/3 "2021-05-12T16:48:21Z")

</div>

Thanks. Why does it return a Tensor instead of a bool?

---

<div class="post-metadata">

**Author:** ![SplitInfinity](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/5e9695/32.png) [@SplitInfinity](https://discuss.pytorch.org/u/SplitInfinity)\
**Post date:** [May 14, 2021, 5:18pm UTC](https://discuss.pytorch.org/t/in-torchscript-why-does-prim-exit-have-return-a-tensor/120987/4 "2021-05-14T17:18:12Z")

</div>

My earlier statement was not completely accurate. ` __exit__ ` is allowed to return anything that can be interpreted as a boolean, which includes certain kinds of Tensors.
