[m-rev.] for review: fix tests/hard_coded/ho_and_type_spec

Julien Fischer juliensf at csse.unimelb.edu.au
Wed May 2 14:55:15 AEST 2007


On Tue, 1 May 2007, Simon Taylor wrote:

> Estimated hours taken: 10
> Branches: main
>
> Fix a compiler abort on tests/hard_coded/ho_and_type_spec.

s/hard_coded/valid/.

> This also fixes problems compiling compiler/mode_robdd.tfeirn.m
> and compiler/mode_robdd.implications.m, but the flags to reduce
> optimization for those files can't be removed until this change
> is installed.
>
> The sequence of events leading to the abort was:
> 1. higher_order.construct_higher_order_terms builds a construction
> unification for a type-info which isn't yet used.
> 2. quantification works out that the type-info isn't used and
> removes it from the instmap_delta.
> 3. further specialization makes the type-info become used.
> 4. recompute_instmap_delta doesn't put it back in the instmap_delta.
> 5. crash.

It seems to me that the real problem here is that during higher_order
the HLDS gets into an inconsistent state.  Is this something that could
be changed?

> compiler/mode_util.m:
> 	Make recompute_instmap_delta recompute the instmap_deltas
> 	for goals which construct terms of builtin types where
> 	the constructed variable occurs in the nonlocals but
> 	not the instmap_delta.
>
> compiler/Mercury.options:
> 	Document that the workaround for this bug can be removed
> 	once this change is installed everywhere.
>
>
> Index: compiler/mode_util.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/mode_util.m,v
> retrieving revision 1.197
> diff -u -u -r1.197 mode_util.m
> --- compiler/mode_util.m	19 Jan 2007 07:04:22 -0000	1.197
> +++ compiler/mode_util.m	28 Apr 2007 02:16:37 -0000
> @@ -202,6 +202,7 @@
>
> :- import_module int.
> :- import_module map.
> +:- import_module maybe.
> :- import_module pair.
> :- import_module set.
> :- import_module term.
> @@ -1322,6 +1323,9 @@
>         InstMap, InstMapDelta, RI) :-
>     % Deconstructions are the only types of unifications that can require
>     % updating of the instmap_delta after simplify.m has been run.
> +    % Type specialization may require constructions of type-infos,
> +    % typeclass-infos or predicate constants to be added to the
> +    % instmap_delta.
>     ModuleInfo = RI ^ module_info,
>     (
>         Uni = deconstruct(Var, _ConsId, Vars, UniModes, _, _CanCGC)
> @@ -1354,10 +1358,62 @@
>             ModuleInfo, InstMapDelta),
>         UniMode = UniMode0
>     ;
> +        Uni = construct(Var, ConsId, Args, _, _, _, _),
> +        goal_info_get_nonlocals(GoalInfo, NonLocals),
> +        set.member(Var, NonLocals),
> +        goal_info_get_instmap_delta(GoalInfo, OldInstMapDelta),
> +        \+ instmap_delta_search_var(OldInstMapDelta, Var, _),
> +        MaybeInst = cons_id_to_shared_inst(ModuleInfo, ConsId, length(Args)),
> +        MaybeInst = yes(Inst)
> +    ->
> +        UniMode = UniMode0,
> +        instmap_delta_init_reachable(InstMapDelta0),
> +        instmap_delta_set(Var, Inst, InstMapDelta0, InstMapDelta)
> +    ;
>         goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
>         UniMode = UniMode0
>     ).
>
> +    % For a builtin constructor, return the inst of the constructed term.
> +    % Handling user-defined constructors properly would require running
> +    % mode analysis again.
> +    %
> +:- func cons_id_to_shared_inst(module_info, cons_id, int) = maybe(mer_inst).
> +
> +cons_id_to_shared_inst(_, cons(_, _), _) = no.
> +cons_id_to_shared_inst(_, ConsId @ int_const(_), _) =
> +            yes(bound(shared, [bound_functor(ConsId, [])])).
> +cons_id_to_shared_inst(_, ConsId @ float_const(_), _) =
> +            yes(bound(shared, [bound_functor(ConsId, [])])).
> +cons_id_to_shared_inst(_, ConsId @ string_const(_), _) =
> +            yes(bound(shared, [bound_functor(ConsId, [])])).

Is there a reason that constructions of builtins other than type-info
related ones and predicate constants are being added to the instmap
delta?  (It appears that is what this code would do.)

> +cons_id_to_shared_inst(ModuleInfo, pred_const(PredProcId, _), NumArgs) =
> +        yes(ground(shared, higher_order(pred_inst_info(PorF, Modes, Det)))) :-
> +    module_info_pred_proc_info(ModuleInfo, unshroud_pred_proc_id(PredProcId),
> +        PredInfo, ProcInfo),
> +    PorF = pred_info_is_pred_or_func(PredInfo),
> +    proc_info_interface_determinism(ProcInfo, Det),
> +    proc_info_get_argmodes(ProcInfo, ProcArgModes),
> +    ( list.drop(NumArgs, ProcArgModes, Modes0) ->
> +        Modes = Modes0
> +    ;
> +        unexpected(this_file, "list.drop failed in cons_id_to_shared_inst")
> +    ).

That looks fine otherwise.

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