kpd
kpd copied to clipboard
handle integer overflow
Maybe perform range analysis on the various numeric types and hopefully compact them to an appropriate size? Then in type check you can make sure they are in their min/max constraints? This could be added as a simple optimization pass
@s0cks not sure if im following right: is your suggestion to not handle overflow as an error and try and store it in an appropriately sized variable?
my idea was that all integer constants are stored in a token as a "BigInt", so I could probably just check if they are greater than int32_max or int64_max, etc or < 0 and throw an error accordingly.
this would be a semantic pass and would handle simple overflows... then maybe later on these could be handled on some simple constant expressions in constant propagation or after or something
Yes, the range analysis can be performed before constant propagation after type resolution. This should help maximize efficiency in memory usage so it doesn't eat memory when you load say 1000 numeric types
This pass should encompass the lifespan of the object so generally you can opt this in for small blocks of code or temp values. In the future you may get away with this for all edge cases though
Interesting, though I feel it tackles a different issue and is more of an optimisation for memory footprint/safety
I'd say we would do what I do and just have some simple bounds checks, then range analysis can probably be performed later on in the compiler during SSA or something. Would probably be easier/less complex to do on an SSA conforming piece of code