diff --git a/src/compile.ml b/src/compile.ml index 6e5383b2779..c21763a1fc5 100644 --- a/src/compile.ml +++ b/src/compile.ml @@ -1467,7 +1467,7 @@ sig (* given a numeric object on the stack as skewed pointer, check whether it can be faithfully stored in N bits, including a leading sign bit leaves boolean result on the stack - N must be 2..63 + N must be 2..64 *) val fits_signed_bits : E.t -> int -> G.t (* given a numeric object on the stack as skewed pointer, check whether @@ -4651,8 +4651,13 @@ and compile_exp (env : E.t) ae exp = | "Int->Int64" -> SR.UnboxedWord64, + let (set_num, get_num) = new_local env "num" in compile_exp_vanilla env ae e ^^ - BigNum.truncate_to_word64 env (* FIXME: trap if it doesn't fit *) + set_num ^^ get_num ^^ + BigNum.fits_signed_bits env 64 ^^ + E.else_trap_with env "Losing precision" ^^ + get_num ^^ + BigNum.truncate_to_word64 env | "Int->Int32" | "Int->Int16" diff --git a/test/fail/ok/outrange-int64lower.diff-ir.ok b/test/fail/ok/outrange-int64lower.diff-ir.ok new file mode 100644 index 00000000000..9c3d9f5fb52 --- /dev/null +++ b/test/fail/ok/outrange-int64lower.diff-ir.ok @@ -0,0 +1,10 @@ +--- outrange-int64lower.run ++++ outrange-int64lower.run-ir +@@ -1,6 +1,7 @@ + prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed + + Last environment: ++$param/8 = -9_223_372_036_854_775_809 + @new_async = func + @text_of_Bool = func + @text_of_Int = func diff --git a/test/fail/ok/outrange-int64lower.diff-low.ok b/test/fail/ok/outrange-int64lower.diff-low.ok new file mode 100644 index 00000000000..34fae546f58 --- /dev/null +++ b/test/fail/ok/outrange-int64lower.diff-low.ok @@ -0,0 +1,10 @@ +--- outrange-int64lower.run ++++ outrange-int64lower.run-low +@@ -1,6 +1,7 @@ + prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed + + Last environment: ++$param/8 = -9_223_372_036_854_775_809 + @new_async = func + @text_of_Bool = func + @text_of_Int = func diff --git a/test/fail/ok/outrange-int64lower.run-ir.ok b/test/fail/ok/outrange-int64lower.run-ir.ok new file mode 100644 index 00000000000..0f8bc37b97b --- /dev/null +++ b/test/fail/ok/outrange-int64lower.run-ir.ok @@ -0,0 +1,94 @@ +prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed + +Last environment: +$param/8 = -9_223_372_036_854_775_809 +@new_async = func +@text_of_Bool = func +@text_of_Int = func +@text_of_Nat = func +@text_of_Text = func +@text_of_array = func +@text_of_array_mut = func +@text_of_option = func +@text_of_variant = func +Array_init = func +Array_tabulate = func +abs = func +btstWord16 = func +btstWord32 = func +btstWord64 = func +btstWord8 = func +charToText = func +charToWord32 = func +clzWord16 = func +clzWord32 = func +clzWord64 = func +clzWord8 = func +ctzWord16 = func +ctzWord32 = func +ctzWord64 = func +ctzWord8 = func +decodeUTF8 = func +hashInt = func +ignore = func +int16ToInt = func +int16ToWord16 = func +int32ToInt = func +int32ToWord32 = func +int64ToInt = func +int64ToWord64 = func +int8ToInt = func +int8ToWord8 = func +intToInt16 = func +intToInt32 = func +intToInt64 = func +intToInt8 = func +intToWord16 = func +intToWord32 = func +intToWord64 = func +intToWord8 = func +n = -9_223_372_036_854_775_809 +nat16ToNat = func +nat16ToWord16 = func +nat32ToNat = func +nat32ToWord32 = func +nat64ToNat = func +nat64ToWord64 = func +nat8ToNat = func +nat8ToWord8 = func +natToNat16 = func +natToNat32 = func +natToNat64 = func +natToNat8 = func +natToWord16 = func +natToWord32 = func +natToWord64 = func +natToWord8 = func +popcntWord16 = func +popcntWord32 = func +popcntWord64 = func +popcntWord8 = func +print = func +printChar = func +printInt = func +range = func +revrange = func +rts_version = func +word16ToInt = func +word16ToInt16 = func +word16ToNat = func +word16ToNat16 = func +word32ToChar = func +word32ToInt = func +word32ToInt32 = func +word32ToNat = func +word32ToNat32 = func +word64ToInt = func +word64ToInt64 = func +word64ToNat = func +word64ToNat64 = func +word8ToInt = func +word8ToInt8 = func +word8ToNat = func +word8ToNat8 = func + diff --git a/test/fail/ok/outrange-int64lower.run-low.ok b/test/fail/ok/outrange-int64lower.run-low.ok new file mode 100644 index 00000000000..0f8bc37b97b --- /dev/null +++ b/test/fail/ok/outrange-int64lower.run-low.ok @@ -0,0 +1,94 @@ +prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed + +Last environment: +$param/8 = -9_223_372_036_854_775_809 +@new_async = func +@text_of_Bool = func +@text_of_Int = func +@text_of_Nat = func +@text_of_Text = func +@text_of_array = func +@text_of_array_mut = func +@text_of_option = func +@text_of_variant = func +Array_init = func +Array_tabulate = func +abs = func +btstWord16 = func +btstWord32 = func +btstWord64 = func +btstWord8 = func +charToText = func +charToWord32 = func +clzWord16 = func +clzWord32 = func +clzWord64 = func +clzWord8 = func +ctzWord16 = func +ctzWord32 = func +ctzWord64 = func +ctzWord8 = func +decodeUTF8 = func +hashInt = func +ignore = func +int16ToInt = func +int16ToWord16 = func +int32ToInt = func +int32ToWord32 = func +int64ToInt = func +int64ToWord64 = func +int8ToInt = func +int8ToWord8 = func +intToInt16 = func +intToInt32 = func +intToInt64 = func +intToInt8 = func +intToWord16 = func +intToWord32 = func +intToWord64 = func +intToWord8 = func +n = -9_223_372_036_854_775_809 +nat16ToNat = func +nat16ToWord16 = func +nat32ToNat = func +nat32ToWord32 = func +nat64ToNat = func +nat64ToWord64 = func +nat8ToNat = func +nat8ToWord8 = func +natToNat16 = func +natToNat32 = func +natToNat64 = func +natToNat8 = func +natToWord16 = func +natToWord32 = func +natToWord64 = func +natToWord8 = func +popcntWord16 = func +popcntWord32 = func +popcntWord64 = func +popcntWord8 = func +print = func +printChar = func +printInt = func +range = func +revrange = func +rts_version = func +word16ToInt = func +word16ToInt16 = func +word16ToNat = func +word16ToNat16 = func +word32ToChar = func +word32ToInt = func +word32ToInt32 = func +word32ToNat = func +word32ToNat32 = func +word64ToInt = func +word64ToInt64 = func +word64ToNat = func +word64ToNat64 = func +word8ToInt = func +word8ToInt8 = func +word8ToNat = func +word8ToNat8 = func + diff --git a/test/fail/ok/outrange-int64lower.run.ok b/test/fail/ok/outrange-int64lower.run.ok new file mode 100644 index 00000000000..df1b2f5b212 --- /dev/null +++ b/test/fail/ok/outrange-int64lower.run.ok @@ -0,0 +1,93 @@ +prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed + +Last environment: +@new_async = func +@text_of_Bool = func +@text_of_Int = func +@text_of_Nat = func +@text_of_Text = func +@text_of_array = func +@text_of_array_mut = func +@text_of_option = func +@text_of_variant = func +Array_init = func +Array_tabulate = func +abs = func +btstWord16 = func +btstWord32 = func +btstWord64 = func +btstWord8 = func +charToText = func +charToWord32 = func +clzWord16 = func +clzWord32 = func +clzWord64 = func +clzWord8 = func +ctzWord16 = func +ctzWord32 = func +ctzWord64 = func +ctzWord8 = func +decodeUTF8 = func +hashInt = func +ignore = func +int16ToInt = func +int16ToWord16 = func +int32ToInt = func +int32ToWord32 = func +int64ToInt = func +int64ToWord64 = func +int8ToInt = func +int8ToWord8 = func +intToInt16 = func +intToInt32 = func +intToInt64 = func +intToInt8 = func +intToWord16 = func +intToWord32 = func +intToWord64 = func +intToWord8 = func +n = -9_223_372_036_854_775_809 +nat16ToNat = func +nat16ToWord16 = func +nat32ToNat = func +nat32ToWord32 = func +nat64ToNat = func +nat64ToWord64 = func +nat8ToNat = func +nat8ToWord8 = func +natToNat16 = func +natToNat32 = func +natToNat64 = func +natToNat8 = func +natToWord16 = func +natToWord32 = func +natToWord64 = func +natToWord8 = func +popcntWord16 = func +popcntWord32 = func +popcntWord64 = func +popcntWord8 = func +print = func +printChar = func +printInt = func +range = func +revrange = func +rts_version = func +word16ToInt = func +word16ToInt16 = func +word16ToNat = func +word16ToNat16 = func +word32ToChar = func +word32ToInt = func +word32ToInt32 = func +word32ToNat = func +word32ToNat32 = func +word64ToInt = func +word64ToInt64 = func +word64ToNat = func +word64ToNat64 = func +word8ToInt = func +word8ToInt8 = func +word8ToNat = func +word8ToNat8 = func + diff --git a/test/fail/ok/outrange-int64lower.wasm-run.ok b/test/fail/ok/outrange-int64lower.wasm-run.ok new file mode 100644 index 00000000000..a87edfdf573 --- /dev/null +++ b/test/fail/ok/outrange-int64lower.wasm-run.ok @@ -0,0 +1 @@ +_out/outrange-int64lower.wasm:0x___: runtime trap: unreachable executed diff --git a/test/fail/ok/outrange-int64upper.diff-ir.ok b/test/fail/ok/outrange-int64upper.diff-ir.ok new file mode 100644 index 00000000000..a6a8a9d85e2 --- /dev/null +++ b/test/fail/ok/outrange-int64upper.diff-ir.ok @@ -0,0 +1,10 @@ +--- outrange-int64upper.run ++++ outrange-int64upper.run-ir +@@ -1,6 +1,7 @@ + prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed + + Last environment: ++$param/8 = 9_223_372_036_854_775_808 + @new_async = func + @text_of_Bool = func + @text_of_Int = func diff --git a/test/fail/ok/outrange-int64upper.diff-low.ok b/test/fail/ok/outrange-int64upper.diff-low.ok new file mode 100644 index 00000000000..38ce0d812ca --- /dev/null +++ b/test/fail/ok/outrange-int64upper.diff-low.ok @@ -0,0 +1,10 @@ +--- outrange-int64upper.run ++++ outrange-int64upper.run-low +@@ -1,6 +1,7 @@ + prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed + + Last environment: ++$param/8 = 9_223_372_036_854_775_808 + @new_async = func + @text_of_Bool = func + @text_of_Int = func diff --git a/test/fail/ok/outrange-int64upper.run-ir.ok b/test/fail/ok/outrange-int64upper.run-ir.ok new file mode 100644 index 00000000000..872a69100f9 --- /dev/null +++ b/test/fail/ok/outrange-int64upper.run-ir.ok @@ -0,0 +1,94 @@ +prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed + +Last environment: +$param/8 = 9_223_372_036_854_775_808 +@new_async = func +@text_of_Bool = func +@text_of_Int = func +@text_of_Nat = func +@text_of_Text = func +@text_of_array = func +@text_of_array_mut = func +@text_of_option = func +@text_of_variant = func +Array_init = func +Array_tabulate = func +abs = func +btstWord16 = func +btstWord32 = func +btstWord64 = func +btstWord8 = func +charToText = func +charToWord32 = func +clzWord16 = func +clzWord32 = func +clzWord64 = func +clzWord8 = func +ctzWord16 = func +ctzWord32 = func +ctzWord64 = func +ctzWord8 = func +decodeUTF8 = func +hashInt = func +ignore = func +int16ToInt = func +int16ToWord16 = func +int32ToInt = func +int32ToWord32 = func +int64ToInt = func +int64ToWord64 = func +int8ToInt = func +int8ToWord8 = func +intToInt16 = func +intToInt32 = func +intToInt64 = func +intToInt8 = func +intToWord16 = func +intToWord32 = func +intToWord64 = func +intToWord8 = func +n = 9_223_372_036_854_775_808 +nat16ToNat = func +nat16ToWord16 = func +nat32ToNat = func +nat32ToWord32 = func +nat64ToNat = func +nat64ToWord64 = func +nat8ToNat = func +nat8ToWord8 = func +natToNat16 = func +natToNat32 = func +natToNat64 = func +natToNat8 = func +natToWord16 = func +natToWord32 = func +natToWord64 = func +natToWord8 = func +popcntWord16 = func +popcntWord32 = func +popcntWord64 = func +popcntWord8 = func +print = func +printChar = func +printInt = func +range = func +revrange = func +rts_version = func +word16ToInt = func +word16ToInt16 = func +word16ToNat = func +word16ToNat16 = func +word32ToChar = func +word32ToInt = func +word32ToInt32 = func +word32ToNat = func +word32ToNat32 = func +word64ToInt = func +word64ToInt64 = func +word64ToNat = func +word64ToNat64 = func +word8ToInt = func +word8ToInt8 = func +word8ToNat = func +word8ToNat8 = func + diff --git a/test/fail/ok/outrange-int64upper.run-low.ok b/test/fail/ok/outrange-int64upper.run-low.ok new file mode 100644 index 00000000000..872a69100f9 --- /dev/null +++ b/test/fail/ok/outrange-int64upper.run-low.ok @@ -0,0 +1,94 @@ +prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed + +Last environment: +$param/8 = 9_223_372_036_854_775_808 +@new_async = func +@text_of_Bool = func +@text_of_Int = func +@text_of_Nat = func +@text_of_Text = func +@text_of_array = func +@text_of_array_mut = func +@text_of_option = func +@text_of_variant = func +Array_init = func +Array_tabulate = func +abs = func +btstWord16 = func +btstWord32 = func +btstWord64 = func +btstWord8 = func +charToText = func +charToWord32 = func +clzWord16 = func +clzWord32 = func +clzWord64 = func +clzWord8 = func +ctzWord16 = func +ctzWord32 = func +ctzWord64 = func +ctzWord8 = func +decodeUTF8 = func +hashInt = func +ignore = func +int16ToInt = func +int16ToWord16 = func +int32ToInt = func +int32ToWord32 = func +int64ToInt = func +int64ToWord64 = func +int8ToInt = func +int8ToWord8 = func +intToInt16 = func +intToInt32 = func +intToInt64 = func +intToInt8 = func +intToWord16 = func +intToWord32 = func +intToWord64 = func +intToWord8 = func +n = 9_223_372_036_854_775_808 +nat16ToNat = func +nat16ToWord16 = func +nat32ToNat = func +nat32ToWord32 = func +nat64ToNat = func +nat64ToWord64 = func +nat8ToNat = func +nat8ToWord8 = func +natToNat16 = func +natToNat32 = func +natToNat64 = func +natToNat8 = func +natToWord16 = func +natToWord32 = func +natToWord64 = func +natToWord8 = func +popcntWord16 = func +popcntWord32 = func +popcntWord64 = func +popcntWord8 = func +print = func +printChar = func +printInt = func +range = func +revrange = func +rts_version = func +word16ToInt = func +word16ToInt16 = func +word16ToNat = func +word16ToNat16 = func +word32ToChar = func +word32ToInt = func +word32ToInt32 = func +word32ToNat = func +word32ToNat32 = func +word64ToInt = func +word64ToInt64 = func +word64ToNat = func +word64ToNat64 = func +word8ToInt = func +word8ToInt8 = func +word8ToNat = func +word8ToNat8 = func + diff --git a/test/fail/ok/outrange-int64upper.run.ok b/test/fail/ok/outrange-int64upper.run.ok new file mode 100644 index 00000000000..1434eca9dfe --- /dev/null +++ b/test/fail/ok/outrange-int64upper.run.ok @@ -0,0 +1,93 @@ +prelude:68.71-68.72: internal error, File "prelude.ml", line 407, characters 28-34: Assertion failed + +Last environment: +@new_async = func +@text_of_Bool = func +@text_of_Int = func +@text_of_Nat = func +@text_of_Text = func +@text_of_array = func +@text_of_array_mut = func +@text_of_option = func +@text_of_variant = func +Array_init = func +Array_tabulate = func +abs = func +btstWord16 = func +btstWord32 = func +btstWord64 = func +btstWord8 = func +charToText = func +charToWord32 = func +clzWord16 = func +clzWord32 = func +clzWord64 = func +clzWord8 = func +ctzWord16 = func +ctzWord32 = func +ctzWord64 = func +ctzWord8 = func +decodeUTF8 = func +hashInt = func +ignore = func +int16ToInt = func +int16ToWord16 = func +int32ToInt = func +int32ToWord32 = func +int64ToInt = func +int64ToWord64 = func +int8ToInt = func +int8ToWord8 = func +intToInt16 = func +intToInt32 = func +intToInt64 = func +intToInt8 = func +intToWord16 = func +intToWord32 = func +intToWord64 = func +intToWord8 = func +n = 9_223_372_036_854_775_808 +nat16ToNat = func +nat16ToWord16 = func +nat32ToNat = func +nat32ToWord32 = func +nat64ToNat = func +nat64ToWord64 = func +nat8ToNat = func +nat8ToWord8 = func +natToNat16 = func +natToNat32 = func +natToNat64 = func +natToNat8 = func +natToWord16 = func +natToWord32 = func +natToWord64 = func +natToWord8 = func +popcntWord16 = func +popcntWord32 = func +popcntWord64 = func +popcntWord8 = func +print = func +printChar = func +printInt = func +range = func +revrange = func +rts_version = func +word16ToInt = func +word16ToInt16 = func +word16ToNat = func +word16ToNat16 = func +word32ToChar = func +word32ToInt = func +word32ToInt32 = func +word32ToNat = func +word32ToNat32 = func +word64ToInt = func +word64ToInt64 = func +word64ToNat = func +word64ToNat64 = func +word8ToInt = func +word8ToInt8 = func +word8ToNat = func +word8ToNat8 = func + diff --git a/test/fail/ok/outrange-int64upper.wasm-run.ok b/test/fail/ok/outrange-int64upper.wasm-run.ok new file mode 100644 index 00000000000..6ec234a4e85 --- /dev/null +++ b/test/fail/ok/outrange-int64upper.wasm-run.ok @@ -0,0 +1 @@ +_out/outrange-int64upper.wasm:0x___: runtime trap: unreachable executed diff --git a/test/fail/outrange-int64lower.as b/test/fail/outrange-int64lower.as new file mode 100644 index 00000000000..a9a6a6625e8 --- /dev/null +++ b/test/fail/outrange-int64lower.as @@ -0,0 +1 @@ +let _ = intToInt64 (- 2 ** 63 - 1); diff --git a/test/fail/outrange-int64upper.as b/test/fail/outrange-int64upper.as new file mode 100644 index 00000000000..1c87d142031 --- /dev/null +++ b/test/fail/outrange-int64upper.as @@ -0,0 +1 @@ +let _ = intToInt64 (2 ** 63);