diff: mode & type interation limits

Fergus Henderson fjh at hydra.cs.mu.oz.au
Thu Nov 13 17:26:03 AEDT 1997


Hi,

I think I may have already posted the mode-inference iteration limit changes,
but the type-inference iteration limit changes are new.

Estimated hours taken: 2

compiler/options.m:
	Add new options `--mode-inference-iteration-limit'
	and `--type-inference-iteration-limit'.

compiler/typecheck.m:
	Only perform a finite number of iterations of type inference,
	to work around infinite loops for preds such as `p(p)'.

compiler/modes.m:
	Use the new option rather than a hard-coded limit.

doc/user_guide.texi:
	Document the new options.

cvs diff compiler/modes.m compiler/options.m compiler/typecheck.m doc/user_guide.texi
Index: compiler/modes.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/modes.m,v
retrieving revision 1.205
diff -u -r1.205 modes.m
--- modes.m	1997/09/15 21:12:24	1.205
+++ modes.m	1997/11/02 17:17:52
@@ -303,7 +303,8 @@
 
 check_pred_modes(ModuleInfo0, ModuleInfo, UnsafeToContinue) -->
 	{ module_info_predids(ModuleInfo0, PredIds) },
-	{ MaxIterations = 30 }, % XXX FIXME should be command-line option
+	globals__io_lookup_int_option(mode_inference_iteration_limit,
+		MaxIterations),
 	modecheck_to_fixpoint(PredIds, MaxIterations, ModuleInfo0,
 					ModuleInfo1, UnsafeToContinue),
 	write_mode_inference_messages(PredIds, ModuleInfo1),
@@ -349,8 +350,15 @@
 
 report_max_iterations_exceeded -->
 	io__set_exit_status(1),
-	io__write_string("Mode analysis iteration limit exceeded.\n").
-	% XXX FIXME add verbose_errors message
+	io__write_strings([
+	   "Mode analysis iteration limit exceeded.\n",
+	   "You may need to declare the modes explicitly, or use the\n",
+	   "`--mode-inference-iteration-limit' option to increase the limit.\n"
+	]),
+	globals__io_lookup_int_option(mode_inference_iteration_limit,
+		MaxIterations),
+	io__format("(The current limit is %d iterations.)\n",
+		[i(MaxIterations)]).
 
 :- pred modecheck_pred_modes_2(list(pred_id), module_info, module_info,
 			bool, bool, int, int, io__state, io__state).
Index: compiler/options.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/options.m,v
retrieving revision 1.208
diff -u -r1.208 options.m
--- options.m	1997/10/14 09:07:42	1.208
+++ options.m	1997/11/13 05:31:52
@@ -100,6 +100,8 @@
 		;	infer_modes
 		;	infer_det
 		;	infer_all
+		;	type_inference_iteration_limit
+		;	mode_inference_iteration_limit
 	% Compilation Model options
 		;	grade
 		;	gcc_non_local_gotos
@@ -333,7 +335,9 @@
 	infer_types		-	bool(no),
 	infer_modes		-	bool(no),
 	infer_det		-	bool(yes),
-	infer_all		-	bool_special
+	infer_all		-	bool_special,
+	type_inference_iteration_limit	-	int(60),
+	mode_inference_iteration_limit	-	int(30)
 ]).
 option_defaults_2(compilation_model_option, [
 		% Compilation model options (ones that affect binary
@@ -626,6 +630,10 @@
 long_option("infer-modes",		infer_modes).
 long_option("infer-determinism",	infer_det).
 long_option("infer-det",		infer_det).
+long_option("type-inference-iteration-limit",
+					type_inference_iteration_limit).
+long_option("mode-inference-iteration-limit",
+					mode_inference_iteration_limit).
 
 % compilation model options
 long_option("grade",			grade).
@@ -1238,7 +1246,12 @@
 
 	io__write_string("\t--no-infer-det, --no-infer-determinism\n"),
 	io__write_string("\t\tIf there is no determinism declaration for a procedure,\n"),
-	io__write_string("\t\tdon't try to infer the determinism, just report an error.\n").
+	io__write_string("\t\tdon't try to infer the determinism, just report an error.\n"),
+	io__write_string("\t--type-inference-iteration-limit <n>\n"),
+	io__write_string("\t\tPerform at most <n> passes of type inference (default: 60).\n"),
+	io__write_string("\t--mode-inference-iteration-limit <n>\n"),
+	io__write_string("\t\tPerform at most <n> passes of mode inference (default: 30).\n").
+
 
 :- pred options_help_compilation_model(io__state::di, io__state::uo) is det.
 
Index: compiler/typecheck.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/typecheck.m,v
retrieving revision 1.217
diff -u -r1.217 typecheck.m
--- typecheck.m	1997/10/14 09:18:50	1.217
+++ typecheck.m	1997/11/13 06:22:14
@@ -194,17 +194,21 @@
 
 check_pred_types(Module0, Module, ModeError, FoundError) -->
 	{ module_info_predids(Module0, PredIds) },
-	typecheck_to_fixpoint(PredIds, Module0, Module, ModeError, FoundError),
+	globals__io_lookup_int_option(type_inference_iteration_limit,
+		MaxIterations),
+	typecheck_to_fixpoint(MaxIterations, PredIds, Module0,
+		Module, ModeError, FoundError),
 	write_inference_messages(PredIds, Module).
 
 	% Repeatedly typecheck the code for a group of predicates
 	% until a fixpoint is reached, or until some errors are detected.
 
-:- pred typecheck_to_fixpoint(list(pred_id), module_info, module_info, 
+:- pred typecheck_to_fixpoint(int, list(pred_id), module_info, module_info, 
 		bool, bool, io__state, io__state).
-:- mode typecheck_to_fixpoint(in, in, out, in, out, di, uo) is det.
+:- mode typecheck_to_fixpoint(in, in, in, out, in, out, di, uo) is det.
 
-typecheck_to_fixpoint(PredIds, Module0, Module, ModeError, FoundError) -->
+typecheck_to_fixpoint(NumIterations, PredIds, Module0, Module, ModeError,
+		FoundError) -->
 	typecheck_pred_types_2(PredIds, Module0, Module1,
 		ModeError, no, FoundError1, no, Changed),
 	( { Changed = no ; FoundError1 = yes } ->
@@ -217,9 +221,32 @@
 		;
 			[]
 		),
-		typecheck_to_fixpoint(PredIds, Module1, Module,
-			ModeError, FoundError)
+		{ NumIterations1 = NumIterations - 1 },
+		( { NumIterations1 > 0 } ->
+			typecheck_to_fixpoint(NumIterations1, PredIds, Module1,
+				Module, ModeError, FoundError)
+		;
+			typecheck_report_max_iterations_exceeded,
+			{ Module = Module1 },
+			{ FoundError = yes }
+		)
 	).
+
+:- pred typecheck_report_max_iterations_exceeded(io__state, io__state).
+:- mode typecheck_report_max_iterations_exceeded(di, uo) is det.
+
+typecheck_report_max_iterations_exceeded -->
+	io__set_exit_status(1),
+	io__write_strings([
+	   "Type inference iteration limit exceeded.\n",
+	   "This probably indicates that your program has a type error.\n",
+	   "You should declare the types explicitly.\n"
+	]),
+	globals__io_lookup_int_option(type_inference_iteration_limit,
+		MaxIterations),
+	io__format("(The current limit is %d iterations.  You can use the\n",
+		[i(MaxIterations)]),
+	io__write_string("`--type-inference-iteration-limit' option to increase the limit).\n").
 
 %-----------------------------------------------------------------------------%
 
Index: doc/user_guide.texi
===================================================================
RCS file: /home/staff/zs/imp/mercury/doc/user_guide.texi,v
retrieving revision 1.101
diff -u -r1.101 user_guide.texi
--- user_guide.texi	1997/10/14 09:34:56	1.101
+++ user_guide.texi	1997/11/13 06:16:38
@@ -1485,6 +1485,13 @@
 If there is no determinism declaration for a procedure,
 don't try to infer the determinism, just report an error.
 
+ at sp 1
+ at item --type-inference-iteration-limit @var{n}
+Perform at most @var{n} passes of mode inference (default: 60).
+
+ at sp 1
+ at item --mode-inference-iteration-limit @var{n}
+Perform at most @var{n} passes of mode inference (default: 30).
 @end table
 
 @node Compilation model options

-- 
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.



More information about the developers mailing list