[m-rev.] for review: insert extra arguments in reused objects

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Jan 15 15:58:14 AEDT 2008


On Tue, 15 Jan 2008, Peter Wang wrote:

> Branches: main
>
> compiler/ml_unify_gen.m:
> 	ml_gen_new_object may be passed extra arguments to be inserted at the
> 	start of the object to be constructed, e.g. secondary tags.  This was
> 	not respected when reusing dead cells.  Fix that (for low-level data
> 	only).
>
> 	Add a cast when assigning one variable to another when reusing cells.
> 	This was causing C compiler warnings.
>
> Index: compiler/ml_unify_gen.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_unify_gen.m,v
> retrieving revision 1.119
> diff -u -r1.119 ml_unify_gen.m
> --- compiler/ml_unify_gen.m	30 Dec 2007 08:23:49 -0000	1.119
> +++ compiler/ml_unify_gen.m	15 Jan 2008 04:41:28 -0000
> @@ -764,9 +764,9 @@
>             MaybeConsId = no,
>             unexpected(this_file, "ml_gen_new_object: unknown cons id")
>         ),
> +        ml_variable_type(!.Info, ReuseVar, ReuseType),
>         list.map(
>             (pred(ReuseConsId::in, ReusePrimTag::out) is det :-
> -                ml_variable_type(!.Info, ReuseVar, ReuseType),
>                 ml_cons_id_to_tag(!.Info, ReuseConsId,
>                     ReuseType, ReuseConsIdTag),
>                 ml_tag_offset_and_argnum(ReuseConsIdTag, ReusePrimTag,
> @@ -799,18 +799,21 @@
>                 unop(std_unop(strip_tag), lval(Var2Lval)))
>         ),
>
> -        Statement = ml_gen_assign(Var1Lval, Var2Rval, Context),
> +        ml_gen_type(!.Info, Type, MLDS_DestType),
> +        CastVar2Rval = unop(cast(MLDS_DestType), Var2Rval),
> +        Statement = ml_gen_assign(Var1Lval, CastVar2Rval, Context),
>
>         % For each field in the construction unification we need to generate
> -        % an rval.
> +        % an rval.  ExtraRvals need to be inserted at the start of the object.
> +        ml_gen_extra_arg_assign(ExtraRvals, ExtraTypes, Type, VarLval,
> +            0, ConsIdTag, Context, ExtraRvalStatements, !Info),
>         % XXX we do more work than we need to here, as some of the cells
>         % may already contain the correct values.
> -        %
>         ml_gen_unify_args(ConsId, ArgVars, ArgModes, ArgTypes, Fields, Type,
>             VarLval, OffSet, ArgNum, ConsIdTag, Context, Statements0, !Info),
>
>         Decls = [],
> -        Statements = [Statement | Statements0]
> +        Statements = [Statement | ExtraRvalStatements] ++ Statements0
>     ;
>         HowToConstruct = construct_in_region(_RegVar),
>         sorry(this_file, "ml_gen_new_object: " ++
> @@ -1303,6 +1306,43 @@
>             MLDS_Types, TakeAddrInfos, !MayUseAtomic, !Info)
>     ).
>
> +    % Generate assignment statements for each of ExtraRvals into the object at
> +    % VarLval, beginning at Offset.
> +    %
> +:- pred ml_gen_extra_arg_assign(list(mlds_rval)::in,
> +    list(mlds_type)::in, mer_type::in, mlds_lval::in, int::in, cons_tag::in,
> +    prog_context::in, statements::out, ml_gen_info::in, ml_gen_info::out)
> +    is det.
> +
> +ml_gen_extra_arg_assign([], [], _, _, _, _, _, [], !Info).
> +ml_gen_extra_arg_assign([ExtraRval | ExtraRvals], [ExtraType | ExtraTypes],
> +        VarType, VarLval, Offset, ConsIdTag, Context,
> +        [Statement | Statements], !Info) :-
> +    ml_gen_info_get_module_info(!.Info, ModuleInfo),
> +    module_info_get_globals(ModuleInfo, Globals),
> +    globals.lookup_bool_option(Globals, highlevel_data, HighLevelData),
> +    (
> +        HighLevelData = no
> +    ;
> +        HighLevelData = yes,
> +        sorry(this_file, "ml_gen_extra_arg_assign: high-level data")
> +    ),
> +
> +    ml_gen_type(!.Info, VarType, MLDS_VarType),
> +    FieldId = offset(const(mlconst_int(Offset))),
> +    MaybePrimaryTag = get_primary_tag(ConsIdTag),
> +    FieldLval = field(MaybePrimaryTag, lval(VarLval), FieldId,
> +        ExtraType, MLDS_VarType),
> +    Statement = ml_gen_assign(FieldLval, ExtraRval, Context),
> +
> +    ml_gen_extra_arg_assign(ExtraRvals, ExtraTypes, VarType, VarLval,
> +        Offset + 1, ConsIdTag, Context, Statements, !Info).
> +
> +ml_gen_extra_arg_assign([_ | _], [], _, _, _, _, _, _, !Info) :-
> +    unexpected(this_file, "ml_gen_extra_arg_assign: length mismatch").
> +ml_gen_extra_arg_assign([], [_ | _], _, _, _, _, _, _, !Info) :-
> +    unexpected(this_file, "ml_gen_extra_arg_assign: length mismatch").
> +
> %-----------------------------------------------------------------------------%

That looks fine.

Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list