[m-rev.] for review: encode invariants in types when creating constant structures

Peter Wang novalazy at gmail.com
Wed Mar 14 11:48:36 AEDT 2018


On Tue, 13 Mar 2018 05:22:50 +1100 (AEDT), "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> For review by anyone.
> 
> The main thing requiring review is the abort in the packing code
> when it finds a double-word argument.
> 
> This cannot be triggered on 64 bit machines, which have no double word
> primitive data types.
> 
> It cannot be triggered in hlc.pregen.gc, which boxes both floats
> and int64/uint64 arguments.
> 
> I don't think it can be triggered for int64/uint64 fields on 32 bit machines,
> since those are boxed there as well even when the grade is not pregen.
> 
> I think it can be triggered only on 32 bit machines in non-pregen grades
> for float fields. However, I believe the existing code in ml_unify_gen.m
> generated incorrect code for such fields already, because it treated them
> as if their width was a single word. I haven't heard any reports of
> such problems. Has anyone else?

Hi Zoltan,

For

    :- type data
	--->    data(int, float, float, int).

    Data = data(1, 2.2, 3.3, 4),

we currently generate in hlc grades:

    #ifdef MR_MSVC
    #pragma pack(push, MR_BYTES_PER_WORD)
    #endif
    struct constdata_scalar_cell_group_1 {
      MR_Box f1;
      MR_Float_Aligned f2;
      MR_Float_Aligned f3;
      MR_Box f4;
    };
    #ifdef MR_MSVC
    #pragma pack(pop)
    #endif

    static /* final */ const struct constdata_scalar_cell_group_1 constdata_scalar_common_1[1] = {
      /* row 0 */
      {
	((MR_Box) ((MR_Integer) 1)),
	(MR_Float) 2.2000000000000002,
	(MR_Float) 3.2999999999999998,
	((MR_Box) ((MR_Integer) 4))
      },
    };

This diff would and does cause the compiler to abort instead.

Peter


More information about the reviews mailing list