[m-rev.] for preliminary review: bug 493 & 532 alterative fix

Peter Wang novalazy at gmail.com
Mon May 17 14:17:33 AEST 2021


On Sat, 15 May 2021 13:41:10 +1000 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> 
> 2021-05-15 12:47 GMT+10:00 "Peter Wang" <novalazy at gmail.com>:
> >> >     --- a/a/stage2/compiler/hlds.make_hlds.state_var.c
> >> >     +++ b/b/stage2/compiler/hlds.make_hlds.state_var.c
> >> >     ...
> >> >     @@ -1263,12 +1263,6 @@ static /* final */ const MR_Box hlds__make_hlds__state_var_scalar_common_2[6][3]
> >> > 	 ((MR_Box) ((MR_Unsigned) 0U)),
> >> > 	 ((MR_Box) ((MR_Unsigned) 0U))
> >> >        },
> >> >     -  /* row 5 */
> >> >     -  {
> >> >     -    ((MR_Box) (((MR_Box) ((MR_Integer) 1)))),
> >> >     -    ((MR_Box) ((MR_Unsigned) 0U)),
> >> >     -    ((MR_Box) ((MR_Unsigned) 0U))
> >> >     -  },
> >> >      };
> >> 
> >> What options did you use to generate the code in this diff?
> > 
> > % cat Mmake.stage.params
> > GRADE=hlc.gc
> > EXTRA_MCFLAGS=-O5 --intermod-opt
> 
> When I do that, I get hlds__make_hlds__state_var_scalar_common_2
> ending after row 4; no row 5 at all. Row 4 does have the same content
> as above.

The duplicate row occurred in the workspace where I had made my
tentative change (the subject of this thread).

It is possible to reproduce the duplicate row without that change
by DISABLING loop invariant hoisting, e.g. -O5 --no-loop-invariants,
so that mark_static_terms is not run before common.m.

What happens is that row 4 and row 5 have identical constants that are
cast to different types, which makes no difference in the C output.

This is the call to cord.snoc in ml_gen_scalar_static_defn:

mdb> p
snoc(nonempty_cord(branch_node(branch_node(branch_node(branch_node(unit_node(
init_array([
init_obj(ml_box(mercury_nb_type(defined_type(qualified(unqualified("private_builtin"),
"type_info"), [], kind_star), ctor_cat_system(cat_system_type_info)),
ml_cast(mercury_nb_type(defined_type(qualified(unqualified("private_builtin"),
"type_info"), [], kind_star), ctor_cat_system(cat_system_type_info)),
ml_const(mlconst_data_addr_rtti(mlds_module_name(qualified(unqualified("mercury"),
"pair"), qualified(unqualified("mercury"), "pair")),
ctor_rtti_id(rtti_type_ctor(unqualified("pair"), "pair", 2u16),
type_ctor_type_ctor_info)))))), ...])), unit_node/1), unit_node/1),
unit_node/1), unit_node/1)), init_array/1) = _

mdb> pp 1/1/2/1
       C (arg 1)/1/2/1
init_array(
  [init_obj(
     ml_box(
       mercury_nb_type(
         defined_type(qualified(unqualified("counter"), "counter"), [],
           kind_star), ctor_cat_user(cat_user_notag)),
       ml_cast(
         mercury_nb_type(
           defined_type(qualified(unqualified("counter"), "counter"), [],
             kind_star), ctor_cat_user(cat_user_notag)),
         ml_box(mlds_builtin_type_int(int_type_int),
           ml_const(mlconst_int(1)))))),
   init_obj(
     ml_box(
       mercury_nb_type(
         defined_type(qualified(unqualified("tree234"), "tree234"),
           [defined_type(qualified(unqualified("term"), "var"),
              [defined_type(
                 qualified(qualified(unqualified("parse_tree"), "prog_data"),
                   "prog_var_type"), [], kind_star)], kind_star),
            defined_type(
              qualified(
                qualified(qualified(unqualified("hlds"), "make_hlds"),
                  "state_var"), "svar_status"), [], kind_star)], kind_star),
         ctor_cat_user(cat_user_general)),
       ml_cast(
         mercury_nb_type(
           defined_type(qualified(unqualified("tree234"), "tree234"),
             [defined_type(qualified(unqualified("term"), "var"),
                [defined_type(
                   qualified(qualified(unqualified("parse_tree"), "prog_data"),
                     "prog_var_type"), [], kind_star)], kind_star),
              defined_type(
                qualified(
                  qualified(qualified(unqualified("hlds"), "make_hlds"),
                    "state_var"), "svar_status"), [], kind_star)], kind_star),
           ctor_cat_user(cat_user_general)), ml_const(mlconst_uint(0))))),
   init_obj(
     ml_box(
       mercury_nb_type(
         defined_type(qualified(unqualified("list"), "list"),
           [defined_type(
              qualified(qualified(unqualified("parse_tree"), "error_util"),
                "error_spec"), [], kind_star)], kind_star),
         ctor_cat_user(cat_user_general)),
       ml_cast(
         mercury_nb_type(
           defined_type(qualified(unqualified("list"), "list"),
             [defined_type(
                qualified(qualified(unqualified("parse_tree"), "error_util"),
                  "error_spec"), [], kind_star)], kind_star),
           ctor_cat_user(cat_user_general)), ml_const(mlconst_uint(0)))))])

mdb> pp 2
       X (arg 2)
init_array(
  [init_obj(
     ml_box(
       mercury_nb_type(
         defined_type(qualified(unqualified("counter"), "counter"), [],
           kind_star), ctor_cat_user(cat_user_notag)),
       ml_cast(
         mercury_nb_type(
           defined_type(qualified(unqualified("counter"), "counter"), [],
             kind_star), ctor_cat_user(cat_user_notag)),
         ml_box(mlds_builtin_type_int(int_type_int),
           ml_const(mlconst_int(1)))))),
   init_obj(
     ml_box(
       mercury_nb_type(
         defined_type(qualified(unqualified("tree234"), "tree234"),
           [defined_type(
              qualified(qualified(unqualified("mdbcomp"), "goal_path"),
                "goal_id"), [], kind_star),
            defined_type(qualified(unqualified("list"), "list"),
              [defined_type(qualified(unqualified("pair"), "pair"),
                 [defined_type(qualified(unqualified("term"), "var"),
                    [defined_type(
                       qualified(
                         qualified(unqualified("parse_tree"), "prog_data"),
                         "prog_var_type"), [], kind_star)], kind_star),
                  defined_type(qualified(unqualified("term"), "var"),
                    [defined_type(
                       qualified(
                         qualified(unqualified("parse_tree"), "prog_data"),
                         "prog_var_type"), [], kind_star)], kind_star)],
                 kind_star)], kind_star)], kind_star),
         ctor_cat_user(cat_user_general)),
       ml_cast(
         mercury_nb_type(
           defined_type(qualified(unqualified("tree234"), "tree234"),
             [defined_type(
                qualified(qualified(unqualified("mdbcomp"), "goal_path"),
                  "goal_id"), [], kind_star),
              defined_type(qualified(unqualified("list"), "list"),
                [defined_type(qualified(unqualified("pair"), "pair"),
                   [defined_type(qualified(unqualified("term"), "var"),
                      [defined_type(
                         qualified(
                           qualified(unqualified("parse_tree"), "prog_data"),
                           "prog_var_type"), [], kind_star)], kind_star),
                    defined_type(qualified(unqualified("term"), "var"),
                      [defined_type(
                         qualified(
                           qualified(unqualified("parse_tree"), "prog_data"),
                           "prog_var_type"), [], kind_star)], kind_star)],
                   kind_star)], kind_star)], kind_star),
           ctor_cat_user(cat_user_general)), ml_const(mlconst_uint(0))))),
   init_obj(
     ml_box(
       mercury_nb_type(
         defined_type(qualified(unqualified("list"), "list"),
           [defined_type(
              qualified(qualified(unqualified("parse_tree"), "error_util"),
                "error_spec"), [], kind_star)], kind_star),
         ctor_cat_user(cat_user_general)),
       ml_cast(
         mercury_nb_type(
           defined_type(qualified(unqualified("list"), "list"),
             [defined_type(
                qualified(qualified(unqualified("parse_tree"), "error_util"),
                  "error_spec"), [], kind_star)], kind_star),
           ctor_cat_user(cat_user_general)), ml_const(mlconst_uint(0)))))])

Peter


More information about the reviews mailing list