[m-dev.] diff: fix bug in mode inference messages

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Oct 26 17:39:09 AEST 1999


Estimated hours taken: 0.5

compiler/mode_errors.m:
	When printing out mode inference messages,
	make sure to remove the modes for the extra
	type_info and type_class_info arguments inserted
	by polymorphism.m.

tests/warnings/Mmakefile:
tests/warnings/inference_test.m:
tests/warnings/inference_test.exp:
	Add a test case to check the type/mode/determinism
	inference messages.

Workspace: /d-drive/home/hg/fjh/mercury
Index: compiler/mode_errors.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_errors.m,v
retrieving revision 1.65
diff -u -d -r1.65 mode_errors.m
--- compiler/mode_errors.m	1999/07/13 08:53:13	1.65
+++ compiler/mode_errors.m	1999/10/26 07:23:25
@@ -979,7 +979,20 @@
 	{ pred_info_name(PredInfo, PredName) },
 	{ Name = unqualified(PredName) },
 	{ pred_info_context(PredInfo, Context) },
-	{ proc_info_argmodes(ProcInfo, Modes0) },
+	{ pred_info_arity(PredInfo, PredArity) },
+	{ proc_info_argmodes(ProcInfo, ArgModes0) },
+
+	% We need to strip off the extra type_info arguments inserted at the
+	% front by polymorphism.m - we only want the last `PredArity' of them.
+	%
+	{ list__length(ArgModes0, NumArgModes) },
+	{ NumToDrop is NumArgModes - PredArity },
+	( { list__drop(NumToDrop, ArgModes0, ArgModes1) } ->
+		{ ArgModes2 = ArgModes1 }
+	;
+		{ error("report_pred_proc_id: list__drop failed") }
+	),
+
 	{ varset__init(VarSet) },
 	{ pred_info_get_is_pred_or_func(PredInfo, PredOrFunc) },
 	( { OutputDetism = yes } ->
@@ -989,13 +1002,13 @@
 		{ MaybeDet = no }
 	),
 	prog_out__write_context(Context),
-	{ strip_builtin_qualifiers_from_mode_list(Modes0, Modes) },
+	{ strip_builtin_qualifiers_from_mode_list(ArgModes2, ArgModes3) },
 	io__write_string("Inferred "),
 	(	{ PredOrFunc = predicate },
-		mercury_output_pred_mode_decl(VarSet, Name, Modes,
+		mercury_output_pred_mode_decl(VarSet, Name, ArgModes3,
 				MaybeDet, Context)
 	;	{ PredOrFunc = function },
-		{ pred_args_to_func_args(Modes, ArgModes, RetMode) },
+		{ pred_args_to_func_args(ArgModes3, ArgModes, RetMode) },
 		mercury_output_func_mode_decl(VarSet, Name, ArgModes, RetMode,
 				MaybeDet, Context)
 	).
Index: tests/warnings/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/warnings/Mmakefile,v
retrieving revision 1.6
diff -u -d -r1.6 Mmakefile
--- tests/warnings/Mmakefile	1999/07/14 17:04:41	1.6
+++ tests/warnings/Mmakefile	1999/10/26 07:29:10
@@ -10,6 +10,7 @@
 	duplicate_call \
 	inf_recursion_lambda \
 	infinite_recursion \
+	inference_test \
 	missing_if \
 	pragma_source_file \
 	simple_code \
@@ -24,6 +25,7 @@
 MCFLAGS-duplicate_call		= --warn-duplicate-calls
 MCFLAGS-unused_args_test	= --warn-unused-args
 MCFLAGS-unused_import		= --warn-interface-imports
+MCFLAGS-inference_test		= --infer-all
 
 #-----------------------------------------------------------------------------#
 
cvs diff: tests/warnings/inference_test.exp is a new entry, no comparison available
cvs diff: tests/warnings/inference_test.m is a new entry, no comparison available
==============================
tests/warnings/inference_test.exp
==============================
inference_test.m:016: Inferred :- func len_func((list:list(T))) = int.
inference_test.m:019: Inferred :- pred len((list:list(T)), int).
inference_test.m:030: Inferred :- func int_zero = int.
inference_test.m:032: Inferred :- pred unused_pred((list:list(T)), (list:list(T))) <= (inference_test:null(T)).
inference_test.m:019: Inferred :- mode len(in, out) is det.
==============================
tests/warnings/inference_test.m
==============================
% This test case isn't really testing warnings,
% it is actually testing that the compiler
% prints out the right type/mode inference message.

:- module inference_test.
:- interface.
:- import_module io.

:- pred main(io__state::di, io__state::uo) is det.

:- implementation.
:- import_module int, list.

main --> print(len_func([42])), nl.

len_func(List) = Len :-
	len(List, Len).

len([], zero).
len([_|Xs], N) :- len(Xs, N - 1).

:- typeclass null(T) where [
	func zero = T
].

:- instance null(int) where [
	func(zero/0) is int_zero
].

int_zero = 0.

unused_pred([X], [_]) :-
	X = zero.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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