[m-dev.] for review: improve unification error messages

Simon Taylor stayl at cs.mu.OZ.AU
Tue Jun 15 16:26:55 AEST 1999



Estimated hours taken: 1

compiler/hlds_goal.m:
	Added `set_goal_contexts', which sets all the contexts
	of the goal_infos of the sub-goals of a goal.

compiler/unify_proc.m:
	Use `set_goal_contexts' to ensure that error messages
	for automatically generated procedures have a useful context.

tests/invalid/partial_implied_mode.err_exp:
	Update the expected output.



Index: compiler/hlds_goal.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_goal.m,v
retrieving revision 1.59
diff -u -u -r1.59 hlds_goal.m
--- hlds_goal.m	1999/04/23 01:02:41	1.59
+++ hlds_goal.m	1999/06/07 04:21:35
@@ -715,6 +715,13 @@
 :- pred goal_list_determinism(list(hlds_goal), determinism).
 :- mode goal_list_determinism(in, out) is det.
 
+	% Change the contexts of the goal_infos of all the sub-goals
+	% of the given goal. This is used to ensure that error messages
+	% for automatically generated unification procedures have a useful
+	% context.
+:- pred set_goal_contexts(prog_context, hlds_goal, hlds_goal).
+:- mode set_goal_contexts(in, in, out) is det.
+
 	%
 	% Produce a goal to construct a given constant.
 	% These predicates all fill in the non-locals, instmap_delta
@@ -1099,6 +1106,47 @@
                        det_conjunction_detism(Det0, Det1, Det)
                )),
        list__foldl(ComputeDeterminism, Goals, det, Determinism).
+
+%-----------------------------------------------------------------------------%
+
+set_goal_contexts(Context, Goal0 - GoalInfo0, Goal - GoalInfo) :-
+	goal_info_set_context(GoalInfo0, Context, GoalInfo),
+	set_goal_contexts_2(Context, Goal0, Goal).
+
+:- pred set_goal_contexts_2(prog_context, hlds_goal_expr, hlds_goal_expr).
+:- mode set_goal_contexts_2(in, in, out) is det.
+
+set_goal_contexts_2(Context, conj(Goals0), conj(Goals)) :-
+	list__map(set_goal_contexts(Context), Goals0, Goals).
+set_goal_contexts_2(Context, disj(Goals0, SM), disj(Goals, SM)) :-
+	list__map(set_goal_contexts(Context), Goals0, Goals).
+set_goal_contexts_2(Context, par_conj(Goals0, SM), par_conj(Goals, SM)) :-
+	list__map(set_goal_contexts(Context), Goals0, Goals).
+set_goal_contexts_2(Context, if_then_else(Vars, Cond0, Then0, Else0, SM),
+		if_then_else(Vars, Cond, Then, Else, SM)) :-
+	set_goal_contexts(Context, Cond0, Cond),
+	set_goal_contexts(Context, Then0, Then),
+	set_goal_contexts(Context, Else0, Else).
+set_goal_contexts_2(Context, switch(Var, CanFail, Cases0, SM),
+		switch(Var, CanFail, Cases, SM)) :-
+	list__map(
+	    (pred(case(ConsId, Goal0)::in, case(ConsId, Goal)::out) is det :-
+		set_goal_contexts(Context, Goal0, Goal)
+	    ), Cases0, Cases).
+set_goal_contexts_2(Context, some(Vars, Goal0), some(Vars, Goal)) :-
+	set_goal_contexts(Context, Goal0, Goal).	
+set_goal_contexts_2(Context, not(Goal0), not(Goal)) :-
+	set_goal_contexts(Context, Goal0, Goal).	
+set_goal_contexts_2(_, Goal, Goal) :-
+	Goal = call(_, _, _, _, _, _).
+set_goal_contexts_2(_, Goal, Goal) :-
+	Goal = higher_order_call(_, _, _, _, _, _).
+set_goal_contexts_2(_, Goal, Goal) :-
+	Goal = class_method_call(_, _, _, _, _, _).
+set_goal_contexts_2(_, Goal, Goal) :-
+	Goal = unify(_, _, _, _, _).
+set_goal_contexts_2(_, Goal, Goal) :-
+	Goal = pragma_c_code(_, _, _, _, _, _, _).
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/unify_proc.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/unify_proc.m,v
retrieving revision 1.75
diff -u -u -r1.75 unify_proc.m
--- unify_proc.m	1999/06/01 09:44:17	1.75
+++ unify_proc.m	1999/06/07 05:19:38
@@ -282,7 +282,11 @@
 	proc_info_set_can_process(ProcInfo0, no, ProcInfo1),
 
 	copy_clauses_to_proc(ProcId, ClausesInfo, ProcInfo1, ProcInfo2),
-	map__det_update(Procs1, ProcId, ProcInfo2, Procs2),
+
+	proc_info_goal(ProcInfo2, Goal0),
+	set_goal_contexts(Context, Goal0, Goal),
+	proc_info_set_goal(ProcInfo2, Goal, ProcInfo),
+	map__det_update(Procs1, ProcId, ProcInfo, Procs2),
 	pred_info_set_procedures(PredInfo1, Procs2, PredInfo2),
 	map__det_update(Preds0, PredId, PredInfo2, Preds2),
 	module_info_set_preds(ModuleInfo0, Preds2, ModuleInfo2),
Index: tests/invalid/partial_implied_mode.err_exp
===================================================================
RCS file: /home/staff/zs/imp/tests/invalid/partial_implied_mode.err_exp,v
retrieving revision 1.2
diff -u -u -r1.2 partial_implied_mode.err_exp
--- partial_implied_mode.err_exp	1999/05/19 04:19:25	1.2
+++ partial_implied_mode.err_exp	1999/06/07 04:19:31
@@ -1,6 +1,6 @@
-partial_implied_mode2.int:008: In clause for `'__Unify__'((unique(partial_implied_mode2:physic_quantity(ground, free, unique(partial_implied_mode2:absol(free, free)))) -> bound(partial_implied_mode2:physic_quantity(ground, ground, bound(partial_implied_mode2:absol(ground, ground))))), (ground -> bound(partial_implied_mode2:physic_quantity(ground, ground, bound(partial_implied_mode2:absol(ground, ground))))))':
-partial_implied_mode2.int:008:   mode error in unification of `V_1' and `partial_implied_mode2:physic_quantity(V_9, V_4, V_10)'.
-partial_implied_mode2.int:008:   Variable `V_1' has instantiatedness `unique(partial_implied_mode2:physic_quantity(ground, free, unique(partial_implied_mode2:absol(free, free))))',
-partial_implied_mode2.int:008:   term `partial_implied_mode2:physic_quantity(V_9, V_4, V_10)'
-partial_implied_mode2.int:008:   has instantiatedness `partial_implied_mode2:physic_quantity(free, ground, free)'.
+partial_implied_mode.m:033: In clause for `'__Unify__'((unique(partial_implied_mode2:physic_quantity(ground, free, unique(partial_implied_mode2:absol(free, free)))) -> bound(partial_implied_mode2:physic_quantity(ground, ground, bound(partial_implied_mode2:absol(ground, ground))))), (ground -> bound(partial_implied_mode2:physic_quantity(ground, ground, bound(partial_implied_mode2:absol(ground, ground))))))':
+partial_implied_mode.m:033:   mode error in unification of `V_1' and `partial_implied_mode2:physic_quantity(V_9, V_4, V_10)'.
+partial_implied_mode.m:033:   Variable `V_1' has instantiatedness `unique(partial_implied_mode2:physic_quantity(ground, free, unique(partial_implied_mode2:absol(free, free))))',
+partial_implied_mode.m:033:   term `partial_implied_mode2:physic_quantity(V_9, V_4, V_10)'
+partial_implied_mode.m:033:   has instantiatedness `partial_implied_mode2:physic_quantity(free, ground, free)'.
 For more information, try recompiling with `-E'.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list