[m-rev.] for post-commit review: determinism error messages

Paul Bone paul at bone.id.au
Fri May 13 09:44:25 AEST 2016


On Fri, May 13, 2016 at 05:48:32AM +1000, Zoltan Somogyi wrote:
> For review by anyone.
> 
> Zoltan.


> diff --git a/compiler/switch_detection.m b/compiler/switch_detection.m
> index 04cb50f..28c96eb 100644
> --- a/compiler/switch_detection.m
> +++ b/compiler/switch_detection.m
> @@ -567,6 +569,31 @@ project_single_arm_goal(single_cons_id_arm(_, Goal)) = Goal.
>  project_single_arm_goal(multi_cons_id_arm(_, _, _)) = _ :-
>      unexpected($module, $pred, "multi arm").
>  
> +:- pred use_context_of_first_disjunct(list(hlds_goal)::in,
> +    hlds_goal_info::in, hlds_goal_info::out) is det.
> +
> +use_context_of_first_disjunct(Disjuncts, GoalInfo0, GoalInfo) :-
> +    gather_contexts_of_goals(Disjuncts, set_tree234.init, Contexts),
> +    % In the common case that all the contexts have the same filename,
> +    % this selects the smallest line number. If Contexts contains more than
> +    % one filename, we have no way to choose the least surprising context
> +    % to use, so may as well use LeastContext.
> +    ( if set_tree234.remove_least(LeastContext, Contexts, _OtherContexts) then
> +        goal_info_set_context(LeastContext, GoalInfo0, GoalInfo)
> +    else
> +        GoalInfo = GoalInfo0
> +    ).
> +
> +:- pred gather_contexts_of_goals(list(hlds_goal)::in,
> +    set_tree234(term.context)::in, set_tree234(term.context)::out) is det.
> +
> +gather_contexts_of_goals([], !Contexts).
> +gather_contexts_of_goals([Goal | Goals], !Contexts) :-
> +    Goal = hlds_goal(_GoalExpr, GoalInfo),
> +    Context = goal_info_get_context(GoalInfo),
> +    set_tree234.insert(Context, !Contexts),
> +    gather_contexts_of_goals(Goals, !Contexts).
> +

There is an opportunity for optimisation here.  Rather than building up a
set of contexts you only need to track the smallest context seen so far.

The code is correct how it is and already committed, so I wouldn't worry
about it unless we wanted, for some reason, to improve the performance of an
error handling routine (rarely executed).

The rest of the change looks fine.


-- 
Paul Bone


More information about the reviews mailing list