mila-iqia/myia

Support the raise statement

Closed this issue · 1 comments

I do not believe we should support try/except in Myia, at least not in the foreseeable future, but support for raise would be useful. raise would basically abort the whole program with an informative message.

My idea to implement this is to add the raise_ and Exception primitives.

  • Exception(message, *args) would have some special type like AbstractException, which for now might not support any operations on it.
  • raise_(x) would be produced by the parser when it sees raise x. It would have the type AbstractBottom. "bottom" in type theory is the type that has no values, so it's the type of infinite loops and errors. amerge(AbstractBottom, x) and amerge(x, AbstractBottom) should succeed and return x (because it either returns x or brings down the whole program). That way, raise can be put in a branch of a conditional and the inferrer will not complain.

Done in #222