Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix lsl overflow detection #8865
This PR fixes the implementation to match the documentation
but makes Int.(lsl) not longer behave like
Should other implementations be fixed as well ?
No. It would be costly to make [Int64.shift_left x 64] defined and always equal to 0. On the other hand, [x lsl 63 = 0] (on a 64-bit platform) falls out of the natural implementation of left shift over tagged integers, and is occasionally useful. For example, you can safely normalize the shift amount by keeping only bits 0 to 5: [x lsl (n land 0x3f)]. This would be more complicated if [x lsl 63] was undefined.
Here I'm speaking of the non-optimized implementation of lsl over tagged integers, [((x - 1) << n) + 1]. The bug that this PR fixes is in an optimized implementation, [(x << n) - (1 << n) + 1].