[m-rev.] For Review: Bug fixes in constraints based mode analysis.

Richard Fothergill fothergill at gmail.com
Sun Mar 26 18:46:27 AEDT 2006


On 2/17/06, Zoltan Somogyi <zs at cs.mu.oz.au> wrote:
> On 17-Feb-2006, Richard Fothergill <fothergill at gmail.com> wrote:
> > Bugfixes for constraints based mode analysis (propagation solver).
>
> Thanks, Richard.
>
> > +        % Preprocess to accomdate implied modes.
>
> s/accomdate/accommodate/
>

Thanks.

> > -    % The keys of RepvarMap are the program variables nonlocal
> > -    % to Goals. Each is mapped to the mc_rep_var representation
> > -    % of the proposition that it is produced at a Goal for every
> > -    % Goal it is nonlocal to in Goals.
> > +    % The keys of RepvarMap are the program variables nonlocal to Goals that
> > +    % appear in goals. Each is mapped to the mc_rep_var representation of the
> > +    % proposition that it is produced at a Goal for every Goal it is nonlocal
> > +    % to in Goals.
>
> I don't understand "to in Goals".
>

The comment now reads:

    %             ... Each is mapped to the mc_rep_var representation of the
    % proposition that it is produced at a Goal in Goals, for every Goal in
    % Goals it is nonlocal to.

Which is slightly better, but I always find describing what these
constraint variables mean a little awkward.

> >  make_conjunct_nonlocal_repvars(PredId, Goal, !RepvarMap) :-
> >      GoalInfo = snd(Goal),
> > -    goal_info_get_nonlocals(GoalInfo, NonLocals),
> > +    goal_info_get_nonlocals(GoalInfo, Nonlocals),
> >      goal_info_get_goal_path(GoalInfo, GoalPath),
> > +    goal_util.goal_vars(Goal, VarsInGoal),
> > +    set.intersect(Nonlocals, VarsInGoal, NonlocalsInGoal),
>
> If Goal includes other goals, those will be traversed twice; if the goal
> structure is deep, that can lead to lots of wasted work.
>
> The right solution to the problem of the nonlocal set being too conservative
> is to run the quantification pass just before this pass; that will set the
> nonlocals to the exactly right sets (no approximations).
>

I ran the quantification pass like this. It seemed a little heavy
handed, but I wanted to be sure it was done before the main processing
had started.


    % correct_nonlocals_in_pred(PredId, !ModuleInfo) requantifies
    % the clause_body of PredId. This is to ensure that no variable
    % appears in the nonlocal set of a goal that doesn't also appear
    % in that goal.
    %
:- pred correct_nonlocals_in_pred(pred_id::in, module_info::in,
    module_info::out) is det.

correct_nonlocals_in_pred(PredId, !ModuleInfo) :-
    module_info_pred_info(!.ModuleInfo, PredId, PredInfo0),
    some [!ClausesInfo, !Varset, !Vartypes, !Clauses, !Goals] (
        pred_info_clauses_info(PredInfo0, !:ClausesInfo),
        clauses_info_clauses_only(!.ClausesInfo, !:Clauses),
        clauses_info_headvars(!.ClausesInfo, Headvars),
        clauses_info_varset(!.ClausesInfo, !:Varset),
        clauses_info_vartypes(!.ClausesInfo, !:Vartypes),
        !:Goals = list.map(func(X) = clause_body(X), !.Clauses),
        list.map_foldl2(correct_nonlocals_in_clause_body(Headvars), !Goals,
            !Varset, !Vartypes),
        !:Clauses = list.map_corresponding(
            func(Clause, Goal) = 'clause_body :='(Clause, Goal),
            !.Clauses, !.Goals),
        clauses_info_set_clauses(!.Clauses, !ClausesInfo),
        clauses_info_set_varset(!.Varset, !ClausesInfo),
        clauses_info_set_vartypes(!.Vartypes, !ClausesInfo),
        pred_info_set_clauses_info(!.ClausesInfo, PredInfo0, PredInfo)
    ),
    module_info_set_pred_info(PredId, PredInfo, !ModuleInfo).

    % correct_nonlocals_in_clause_body(Headvars, !Goals, !Varset, !Vartypes)
    % requantifies the clause body Goal. This is to ensure that no variable
    % appears in the nonlocal set of a goal that doesn't also appear
    % in that goal.
    %
:- pred correct_nonlocals_in_clause_body(list(prog_var)::in,
    hlds_goal::in, hlds_goal::out, prog_varset::in, prog_varset::out,
    vartypes::in, vartypes::out) is det.

correct_nonlocals_in_clause_body(Headvars, !Goals, !Varset, !Vartypes) :-
        implicitly_quantify_clause_body(Headvars, Warnings, !Goals, !Varset,
            !Vartypes),
    (   Warnings = []
    ;
        Warnings = [_|_],
        unexpected(this_file, "Quantification error during constraints" ++
            " based mode analysis")
    ).



> Otherwise, the diff is fine.
>

Thanks. Sorry for making you wait so long for the changes - I let uni
stuff sweep me away.

-Richard

--------------------------------------------------------------------------
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