[m-rev.] For review: Preparations for mode inference

Julien Fischer juliensf at cs.mu.OZ.AU
Fri Feb 10 01:21:53 AEDT 2006


On Wed, 8 Feb 2006, Richard Fothergill wrote:

> For review by anyone.
>
> Estimated hours taken: 5
>
> Chiefly isolating nondeterministic behaviour in constraints based
> mode ordering, so that when mode analysis for a single predicate
> fails it is dealt with instead of being backtracked out of.

How is it dealt with?

> Make preparations for mode inference.

I suggest rewording that something like the following:

	Isolate the nondeterminism in constraint based mode ordering
	so that when the analysis of a single predicate fails ...

	Further work towards constraint based mode inference.


> compiler/abstract_mode_constraints.m:
> 	Pred IDs for called preds that will need to be mode inferred
> 	for the call mode are now stored along with constraints
> 	for predicate calls.

compiler/abstract_mode_constraints.m:
compiler/build_mode_constraints.m:
	Store PredIds for called predicates that require mode inference
	with the constraints for the predicate calls.


If the same log message applies to multiple files just group them
together as above.

...

> compiler/mode_constraints.m:
> 	No longer need to deal with nondeterministic behaviour of
> 	mode reordering here.


Or as it would be more commonly expressed in log messages:

	Minor changes to conform to the above.


> compiler/ordering_mode_constraints.m:
> 	Much nondeterministic and committed choice behaviour moved.
> 	A simple data structure documenting any failure in mode
> 	analysis introduced. Variables renamed to conform with
> 	current conventions (s/PredID/PredId/)


	Conform to the above changes.

	Add a data structure to record reasons for mode analysis
	failures.

	s/PredID/PredId/

...

> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/abstract_mode_constraints.m,v
> retrieving revision 1.6
> diff -u -r1.6 abstract_mode_constraints.m
> --- compiler/abstract_mode_constraints.m	6 Feb 2006 02:36:50 -0000	1.6
> +++ compiler/abstract_mode_constraints.m	8 Feb 2006 05:04:35 -0000
> @@ -27,6 +27,7 @@
>  :- import_module list.
>  :- import_module map.
>  :- import_module multi_map.
> +:- import_module set.
>  :- import_module std_util.
>  :- import_module term.
>  :- import_module varset.
> @@ -126,10 +127,14 @@
>                                  % Stores procedure specific constraints
>                                  % such as mode declaration constraints.
>          pred_constraints    ::  assoc_list(constraint_formula,
> -                                    constraint_annotation)
> +                                    constraint_annotation),
>                                  % Stores constraints that apply to all
>                                  % procedures of the predicate -
>                                  % typically generated from its clauses.


What do you mean by "typically"?  Is there some atypical way of generating
the constraints?

> +        mode_infer_callees  ::  set(pred_id)
> +                                % Collection of predicates with no
> +                                % declared modes that are called by
> +                                % this predicate.
>      ).


>
>  %-----------------------------------------------------------------------------%
> @@ -169,6 +174,13 @@
>  :- pred add_constraint(prog_context::in, proc_id::in, constraint_formula::in,
>      pred_p_c_constraints::in, pred_p_c_constraints::out) is det.
>
> +    % add_mode_infer_callee(PredId, !PredConstraints) records in
> +    % PredConstraints that predicate PredId is called and needs
> +    % to have modes infered for it to be called in.

s/infered/inferred/


Perhaps, something like:

	% Add PredId to the set of predicates that requires mode inference.

...

> Index: compiler/ordering_mode_constraints.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/ordering_mode_constraints.m,v
> retrieving revision 1.2
> diff -u -r1.2 ordering_mode_constraints.m
> --- compiler/ordering_mode_constraints.m	6 Feb 2006 02:36:51 -0000	1.2
> +++ compiler/ordering_mode_constraints.m	8 Feb 2006 05:04:44 -0000

...

> @@ -120,6 +120,36 @@
>
>  %-----------------------------------------------------------------------------%
>
> +    % A way of returning the manner of mode analysis failure.
> +    %
> +:- type mode_analysis_failures == list(mode_analysis_failure).
> +
> +    % A way of returning the manner of mode analysis failure.
> +    %

How about:

	This type stores information about a mode analysis failure.
	This information is used when producing error messages ....


> +:- type mode_analysis_failure
> +   --->     no_producer_consumer_sols(
> +                failing_predicate   ::  pred_proc_id
> +                                    % The predicate for which the
> +                                    % producer/consumer analysis
> +                                    % failed to be solved
> +            )
> +
> +    ;
> +            mode_inference_failed(
> +                caller              ::  pred_id,
> +                                    % The predicate calling the
> +                                    % predicate for which mode
> +                                    % inference has failed.
> +
> +                scc                 :: list(pred_id)
> +                                    % The SCC of predicates to be
> +                                    % mode infered for which

s/infered/inferred/

> +                                    % the mode inference failed.
> +            )
> +
> +    ;
> +            conjunct_ordering_failed(pred_proc_id).
> +

...

> +        PredConstraints = map.lookup(PredConstraintsMap, PredId),
> +        ProcIds = pred_info_all_procids(PredInfo1),
> +        list.foldl2(proc_reordering(PredConstraints, VarMap, PredId), ProcIds,
> +            [], Errors, PredInfo1, PredInfo),
> +
> +        (
> +            Errors = [],
> +            module_info_set_pred_info(PredId, PredInfo, !ModuleInfo)
> +        ;
> +            Errors = [_ | _],
> +            % XXX Deal with mode errors here!
> +            sorry(this_file, "mode checking failure")
> +        )

Even at this stage it would be useful if some sort of error message were
printed out.

...

> +    % solve_proc_reordering is cc_multi because each of its solutions
> +    % is equivalent in the sense that they all contain the same goals
> +    % and conjunctions are ordered according to some legitimate
> +    % solution to the producing and consuming goals of program
> +    % variables.
> +    Errors0 = !.Errors,
> +    promise_equivalent_solutions [Errors1, Goal] (
> +        solve_proc_reordering(VarMap, PredId, ProcId, SolverConstraints,
> +            Errors0, Errors1, Goal0, Goal)
> +    ),
> +    !:Errors = Errors1,
>
>      proc_info_set_goal(Goal, ProcInfo0, ProcInfo),
> -    pred_info_set_proc_info(ProcID, ProcInfo, !PredInfo).
> +    pred_info_set_proc_info(ProcId, ProcInfo, !PredInfo).
> +
> +    % solve_proc_reordering(VarMap, PredId, ProcId, SolverConstraints,
> +    %   !Errors, !Goal)
> +    %
> +    % Performs the nondeterministic constraint solving for proc_reordering
> +    % - using the constraints in SolverConstraints to order the goals
> +    % in Goal (from procedure ProcId in predicate PredId). Any failure
> +    % is stored in Errors, and the predicate still proceeds.
> +    % VarMap should contain any constraint variables refering to Goal

s/refering/referring/

> +    % and the program variables in it.
> +    %
> +    % solve_proc_reordering is cc_multi because each of its solutions
> +    % is equivalent in the sense that they all contain the same goals
> +    % and conjunctions are ordered according to some legitimate
> +    % solution to the producing and consuming goals of program

I suggest just: producer/consumer

> +    % variables.
> +    %
> +:- pred solve_proc_reordering(mc_var_map::in, pred_id::in, proc_id::in,
> +    solver_cstrts::in, mode_analysis_failures::in, mode_analysis_failures::out,
> +    hlds_goal::in, hlds_goal::out) is cc_multi.
> +
> +solve_proc_reordering(VarMap, PredId, ProcId, SolverConstraints,
> +        !Errors, !Goal) :-
> +    ( mcsolver.solve(SolverConstraints, Bindings) ->
> +        ( goal_reordering(PredId, VarMap, Bindings, !Goal) ->
> +            true
> +        ;
> +            list.cons(conjunct_ordering_failed(proc(PredId, ProcId)), !Errors)
> +        )
> +    ;
> +        list.cons(no_producer_consumer_sols(proc(PredId, ProcId)), !Errors)
> +    ).

That's okay otherwise.

Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list