[m-dev.] for review: fix unify/2 mode error message

Simon Taylor stayl at cs.mu.OZ.AU
Mon Sep 20 14:02:13 AEST 1999


Estimated hours taken: 0.5

compiler/polymorphism.m:
	Don't specialize calls to unify/2, index/2 and compare/3 into
	type-specific versions here because it stuffs up the predicate
	names in mode error messages. The optimization is done in
	higher_order.m.

tests/invalid/Mmakefile:
tests/invalid/unify_mode_error.m:
tests/invalid/unify_mode_error.err_exp:
	Test case.

Index: compiler/polymorphism.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/polymorphism.m,v
retrieving revision 1.170
diff -u -u -r1.170 polymorphism.m
--- polymorphism.m	1999/09/12 04:26:48	1.170
+++ polymorphism.m	1999/09/15 03:00:14
@@ -1035,41 +1035,9 @@
 		{ Goal = GoalExpr0 - GoalInfo0 }
 	).
 
-polymorphism__process_goal_expr(call(PredId0, ProcId0, ArgVars0,
-		Builtin, UnifyContext, Name0), GoalInfo, Goal) -->
-	% Check for a call to a special predicate like compare/3
-	% for which the type is known at compile-time.
-	% Replace such calls with calls to the particular version
-	% for that type.
-	% (Note: higher_order.m also performs the same optimization.
-	% Is there really much advantage in doing it here too?)
-	(
-		{ Name0 = qualified(ModuleName, PredName0) },
-		{ mercury_public_builtin_module(ModuleName) },
-		{ list__length(ArgVars0, Arity) },
-		{ special_pred_name_arity(SpecialPredId, PredName0,
-						MangledPredName, Arity) },
-		=(Info0),
-		{ poly_info_get_var_types(Info0, VarTypes) },
-		{ special_pred_get_type(MangledPredName, ArgVars0, MainVar) },
-		{ map__lookup(VarTypes, MainVar, Type) },
-		{ Type \= term__variable(_) },
-
-		% don't try this for any special preds if they're not
-		% implemented
-
-		{ special_pred_list(SpecialPredIds) },
-		{ list__member(SpecialPredId, SpecialPredIds) }
-	->
-		{ poly_info_get_module_info(Info0, ModuleInfo) },
-		{ polymorphism__get_special_proc(Type, SpecialPredId,
-			ModuleInfo, Name, PredId, ProcId) }
-	;
-		{ PredId = PredId0 },
-		{ ProcId = ProcId0 },
-		{ Name = Name0 }
-	),
-
+polymorphism__process_goal_expr(Goal0, GoalInfo, Goal) -->
+	{ Goal0 = call(PredId, ProcId, ArgVars0, Builtin,
+			UnifyContext, Name) },
 	polymorphism__process_call(PredId, ArgVars0, GoalInfo,
 		ArgVars, _ExtraVars, CallGoalInfo, ExtraGoals),
 
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/invalid/Mmakefile,v
retrieving revision 1.47
diff -u -u -r1.47 Mmakefile
--- Mmakefile	1999/08/31 05:25:58	1.47
+++ Mmakefile	1999/09/20 03:40:56
@@ -67,6 +67,7 @@
 	undef_mode.m \
 	undef_symbol.m \
 	undef_type.m \
+	unify_mode_error.m \
 	uniq_modes.m \
 	uu_type.m \
 	vars_in_wrong_places.m

tests/invalid/unify_mode_error.m
===================================================================
% The compiler of 15/9/1999 reported the wrong predicate
% name in the mode error for this test case because polymorphism.m
% substituted private_builtin__builtin_unify_int/2 for builtin__unify/2.
% That optimization is now only done by higher_order.m after all errors
% have been reported.
:- module unify_mode_error.

:- interface.

:- pred foo(int::in, int::out) is det.

:- implementation.

foo(X, Y) :-
	builtin__unify(X, Y).

tests/invalid/unify_mode_error.err_exp
===================================================================
unify_mode_error.m:015: In clause for `foo(in, out)':
unify_mode_error.m:015:   in argument 2 of call to predicate `builtin:unify/2':
unify_mode_error.m:015:   mode error: variable `Y' has instantiatedness `free',
unify_mode_error.m:015:   expected instantiatedness was `ground'.
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