Diff for review: bug fix in modecheck_unify

Andrew Bromage bromage at cs.mu.oz.au
Mon Apr 28 21:24:13 AEST 1997


G'day.

Fergus or Simon, could you review this one please?

There is no regression test as apparently no later pass of the compiler
which depended on the cons_id in a unify_rhs field being module qualified.
The bug was found by the new recompute_instmap_delta (coming RSN).

Cheers,
Andrew Bromage
--------8<---CUT HERE---8<--------
Approximate hours taken: 0.5

Bug fix in modecheck_unify.m.

The modecheck pass should module qualify cons_ids where possible,
however it did not module qualify cons_ids which appear in the
unify_rhs field of var-functor unifications.  This fixes the problem.

compiler/modecheck_unify.m:
	Changes detailed above.

Index: modecheck_unify.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/modecheck_unify.m,v
retrieving revision 1.13
diff -u -r1.13 modecheck_unify.m
--- modecheck_unify.m	1997/04/08 02:26:29	1.13
+++ modecheck_unify.m	1997/04/28 07:37:21
@@ -97,7 +97,7 @@
 		Unify = unify(X, var(Y), Modes, Unification, UnifyContext)
 	).
 
-modecheck_unification(X0, functor(ConsId, ArgVars0), Unification0,
+modecheck_unification(X0, functor(ConsId0, ArgVars0), Unification0,
 			UnifyContext, GoalInfo0, HowToCheckGoal,
 			Goal, ModeInfo0, ModeInfo) :-
 	mode_info_get_module_info(ModeInfo0, ModuleInfo0),
@@ -116,7 +116,7 @@
 		% been expanded.)
 		%
 		HowToCheckGoal \= check_unique_modes,
-		ConsId = cons(unqualified(ApplyName), _),
+		ConsId0 = cons(unqualified(ApplyName), _),
 		( ApplyName = "apply" ; ApplyName = "" ),
 		Arity >= 2,
 		ArgVars0 = [FuncVar | FuncArgVars]
@@ -143,7 +143,7 @@
 
 		% Find the set of candidate predicates which have the
 		% specified name and arity (and module, if module-qualified)
-		ConsId = cons(PredName, _),
+		ConsId0 = cons(PredName, _),
 		module_info_pred_info(ModuleInfo0, ThisPredId, PredInfo),
 
 		%
@@ -190,7 +190,7 @@
 		invalid_proc_id(ProcId),
 		list__append(ArgVars0, [X0], ArgVars),
 		FuncCallUnifyContext = call_unify_context(X0,
-			functor(ConsId, ArgVars0), UnifyContext),
+			functor(ConsId0, ArgVars0), UnifyContext),
 		FuncCall = call(PredId, ProcId, ArgVars, not_builtin,
 			yes(FuncCallUnifyContext), QualifiedFuncName),
 		%
@@ -224,7 +224,7 @@
 
 		% check if variable has a higher-order type
 		type_is_higher_order(TypeOfX, PredOrFunc, PredArgTypes),
-		ConsId = cons(PName, _),
+		ConsId0 = cons(PName, _),
 		% but in case we are redoing mode analysis, make sure
 		% we don't mess with the address constants for type_info
 		% fields created by polymorphism.m
@@ -260,7 +260,7 @@
 		QualifiedPName = qualified(PredModule, UnqualPName),
 
 		CallUnifyContext = call_unify_context(X0,
-				functor(ConsId, ArgVars0), UnifyContext),
+				functor(ConsId0, ArgVars0), UnifyContext),
 		LambdaGoalExpr = call(PredId, ProcId, Args, not_builtin,
 				yes(CallUnifyContext), QualifiedPName),
 
@@ -309,9 +309,9 @@
 		% call modecheck_unify_functor to do the ordinary thing.
 		%
 		mode_info_get_instmap(ModeInfo0, InstMap0),
-		modecheck_unify_functor(X0, TypeOfX, ConsId, ArgVars0, 
+		modecheck_unify_functor(X0, TypeOfX, ConsId0, ArgVars0, 
 				Unification0, ExtraGoals, Mode, ArgVars,
-				Unification, ModeInfo0, ModeInfo),
+				Unification, ConsId, ModeInfo0, ModeInfo),
 		%
 		% Optimize away construction of unused terms by
 		% replacing the unification with `true'.
@@ -488,13 +488,13 @@
 
 :- pred modecheck_unify_functor(var, (type), cons_id, list(var), unification,
 			pair(list(hlds_goal)), pair(mode), list(var),
-			unification,
+			unification, cons_id,
 			mode_info, mode_info).
-:- mode modecheck_unify_functor(in, in, in, in, in, out, out, out, out,
+:- mode modecheck_unify_functor(in, in, in, in, in, out, out, out, out, out,
 			mode_info_di, mode_info_uo) is det.
 
 modecheck_unify_functor(X, TypeOfX, ConsId0, ArgVars0, Unification0,
-			ExtraGoals, Mode, ArgVars, Unification,
+			ExtraGoals, Mode, ArgVars, Unification, ConsId,
 			ModeInfo0, ModeInfo) :-
 	mode_info_get_module_info(ModeInfo0, ModuleInfo0),
 	list__length(ArgVars0, Arity),



More information about the developers mailing list