[m-rev.] for review: Use uints to represent bit vectors.

Julien Fischer jfischer at opturion.com
Mon Apr 16 12:15:50 AEST 2018


On Mon, 16 Apr 2018, Peter Wang wrote:

> On Sun, 15 Apr 2018 21:12:08 -0400 (EDT), Julien Fischer <jfischer at opturion.com> wrote:
>>
>> The csharp grade is also broken.
>>
>> Mercury/css/sparse_bitset.cs(718,27): error CS0031: Constant value
>> `18446744073709551615' cannot be converted to a `uint'
>
> This
>
>    main(!IO) :-
> 	write_uint(\0u, !IO).
>
> produces this
>
>    io.write_uint_3_p_0(18446744073709551615U);
>
> const_prop.m should be more careful with `\' I think.

Indeed!  The following ought to fix it:

diff --git a/compiler/const_prop.m b/compiler/const_prop.m
index 87eaa41..500a96c 100644
--- a/compiler/const_prop.m
+++ b/compiler/const_prop.m
@@ -251,6 +251,9 @@ evaluate_det_call_int_2(Globals, ProcName, ModeNum, X, Y,
          ProcName = "\\",
          ModeNum = 0,
          X ^ arg_inst = bound(_, _, [bound_functor(int_const(XVal), [])]),
+        globals.lookup_bool_option(Globals, pregenerated_dist, no),
+        target_bits_per_int(Globals, TargetBitsPerInt),
+        TargetBitsPerInt = bits_per_int(int.bits_per_int),
          OutputArg = Y,
          OutputArgVal = \ XVal
      ;
@@ -292,12 +295,15 @@ evaluate_det_call_int_2(Globals, ProcName, ModeNum, X, Y,
      arg_hlds_info::in, arg_hlds_info::in, arg_hlds_info::out, cons_id::out)
      is semidet.

-evaluate_det_call_uint_2(_Globals, ProcName, ModeNum, X, Y,
+evaluate_det_call_uint_2(Globals, ProcName, ModeNum, X, Y,
          OutputArg, uint_const(OutputArgVal)) :-
      (
          ProcName = "\\",
          ModeNum = 0,
          X ^ arg_inst = bound(_, _, [bound_functor(uint_const(XVal), [])]),
+        globals.lookup_bool_option(Globals, pregenerated_dist, no),
+        target_bits_per_uint(Globals, TargetBitsPerUInt),
+        TargetBitsPerUInt = bits_per_uint(uint.bits_per_uint),
          OutputArg = Y,
          OutputArgVal = \ XVal
      ).


Note that we've been somewhat lucky that the compiler doesn't contain
bitwise negation of constants other than bits_per_int, since otherwise
the pregen grades would have been broken long ago.

Julien.


More information about the reviews mailing list