tarides / hackocaml

OCaml hacking ideas, small and large.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Detect and throw Integer_overflow with OCaml

nikochiko opened this issue · comments

Notes from talking to KC:

  • OCaml has 31 and 63-bit signed integers - one bit (LSB) is always 1 to mark it as an integer (otherwise, it is considered to be a pointer by the GC)
  • OCaml also has int32 and int64 - boxed ints that are not cleared by the GC
  • We should want to do it without making an expensive external C call

Ideally, the compiler should spit out code to check the overflow flag (or whatever the condition would be - with calculations on the 31/63-bit ints), and throw an exception in that case.
It would get pipelined and not cause a performance hit.