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

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

In the section on the with statement, 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.

See this section of the Python language reference for more information. prim::Exit corresponds to __exit__ on the class being used as a context manager and is allowed to return a boolean value.

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

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.