[m-rev.] fix --no-infer-modes bug

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Jun 18 17:47:13 AEST 2003


Estimated hours taken: 1
Branches: main

Fix a bug where we were in some cases failing to report errors for
procedures with no declared modes, even though --infer-modes was not
enabled.

compiler/modes.m:
	Fix a bug where the check for procedures with no modes was not
	working as intended, because it was counting inferred modes.
	Instead, check for procedures with no *declared* modes.

tests/general/accumulator/Mercury.options:
	Compile ite.m with --infer-modes, since it was relying on that.

tests/invalid/Mmakefile:
tests/invalid/Mercury.options
tests/invalid/undeclared_mode.m:
tests/invalid/undeclared_mode.err_exp:
	Add a (renamed) copy of tests/general/accumulator/ite.m,
	compiled with --no-infer-modes, as a regression test.

Workspace: /home/ceres/fjh/mercury
Index: compiler/modes.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modes.m,v
retrieving revision 1.270
diff -u -d -r1.270 modes.m
--- compiler/modes.m	2 Jun 2003 06:55:23 -0000	1.270
+++ compiler/modes.m	18 Jun 2003 07:27:05 -0000
@@ -646,23 +646,31 @@
 
 modecheck_pred_mode_2(PredId, PredInfo0, WhatToCheck, MayChangeCalledProc,
 		ModuleInfo0, ModuleInfo, Changed0, Changed, NumErrors) -->
-	% Note that we use pred_info_procids rather than
-	% pred_info_all_procids here, which means that we
-	% don't process modes that have already been inferred
-	% as invalid.
-	{ pred_info_procids(PredInfo0, ProcIds) },
 	( { WhatToCheck = check_modes } ->
+		{ pred_info_procedures(PredInfo0, ProcTable) },
 		(
-			{ ProcIds = [] }
+			some [ProcInfo] {
+				map__member(ProcTable, _ProcId, ProcInfo),
+				proc_info_maybe_declared_argmodes(ProcInfo,
+					yes(_))
+			}
 		->
+			% there was at least one declared modes for this
+			% procedure
+			[]
+		;
+			% there were no declared modes for this procedure
 			maybe_report_error_no_modes(PredId, PredInfo0,
 					ModuleInfo0)
-		;
-			[]
 		)
 	;
 		[]
 	),
+	% Note that we use pred_info_procids rather than
+	% pred_info_all_procids here, which means that we
+	% don't process modes that have already been inferred
+	% as invalid.
+	{ pred_info_procids(PredInfo0, ProcIds) },
 	modecheck_procs(ProcIds, PredId, WhatToCheck, MayChangeCalledProc,
 				ModuleInfo0, Changed0, 0,
 				ModuleInfo, Changed, NumErrors).
Index: tests/general/accumulator/Mercury.options
===================================================================
RCS file: /home/mercury1/repository/tests/general/accumulator/Mercury.options,v
retrieving revision 1.1
diff -u -d -r1.1 Mercury.options
--- tests/general/accumulator/Mercury.options	17 Aug 2002 13:52:07 -0000	1.1
+++ tests/general/accumulator/Mercury.options	18 Jun 2003 07:33:43 -0000
@@ -0,0 +1 @@
+MCFLAGS-ite = --infer-modes
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.137
diff -u -d -r1.137 Mmakefile
--- tests/invalid/Mmakefile	2 Jun 2003 04:56:30 -0000	1.137
+++ tests/invalid/Mmakefile	18 Jun 2003 07:38:26 -0000
@@ -139,6 +139,7 @@
 	types	\
 	type_spec \
 	unbound_type_vars \
+	undeclared_mode \
 	undef_lambda_mode \
 	undef_inst \
 	undef_mode \
Index: tests/invalid/undeclared_mode.err_exp
===================================================================
RCS file: tests/invalid/undeclared_mode.err_exp
diff -N tests/invalid/undeclared_mode.err_exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/undeclared_mode.err_exp	18 Jun 2003 07:40:25 -0000
@@ -0,0 +1,3 @@
+undeclared_mode.m:032: Error: no mode declaration for predicate `undeclared_mode.sort_of_factorial/2'.
+undeclared_mode.m:032: Inferred :- mode sort_of_factorial(di, uo).
+For more information, try recompiling with `-E'.
Index: tests/invalid/undeclared_mode.m
===================================================================
RCS file: tests/invalid/undeclared_mode.m
diff -N tests/invalid/undeclared_mode.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/undeclared_mode.m	18 Jun 2003 07:36:02 -0000
@@ -0,0 +1,45 @@
+	% Test that we report an error for procedures with no mode
+	% declarations.  This is a regression test; Mercury versions
+	% prior to 18 Jun 2003 failed this test.
+
+:- module undeclared_mode.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+:- import_module int.
+
+main -->
+	io__write_string("factorial: "),
+	{ Factorial = factorial(7) },
+	io__write(Factorial),
+	io__nl,
+	io__write_string("sort_of_factorial: "),
+	{ sort_of_factorial(3, Factorial2) },
+	io__write(Factorial2),
+	io__nl.
+
+:- func factorial(int) = int.
+
+factorial(Num)
+	= ( Num = 0 -> 1 ; Num * factorial(Num - 1)).
+
+:- pred sort_of_factorial(int, int).
+% ERROR: no mode declaration for sort_of_factorial/2
+
+	% Here we bind a value in the If goals and use it in the Then
+	% goals, in an attempt to confuse the compiler.
+sort_of_factorial(Num, Fac) :-
+	( 
+		(Num \= 0, X = 2)
+	->
+		sort_of_factorial(Num - 1, Fac0),
+		Fac = X * Num * Fac0
+	;
+		Fac = 1
+	).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list