diff: unify_proc.m: bug fix for queued procs

Fergus Henderson fjh at cs.mu.oz.au
Tue Jan 13 00:28:12 AEDT 1998


Estimated hours taken: 2

compiler/unify_proc.m:
	Fix a bug which caused an internal error when compiling
	tests/invalid/types.m: when modechecking queued procedures,
	we must first check that they are type-correct,
	i.e. that they have not been removed from the list of
	valid pred_ids.

cvs diff  compiler/unify_proc.m
Index: compiler/unify_proc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unify_proc.m,v
retrieving revision 1.63
diff -u -r1.63 unify_proc.m
--- unify_proc.m	1998/01/05 07:26:21	1.63
+++ unify_proc.m	1998/01/12 13:01:37
@@ -300,37 +300,62 @@
 			Requests1) },
 		{ module_info_set_proc_requests(ModuleInfo0, Requests1,
 			ModuleInfo1) },
-		globals__io_lookup_bool_option(very_verbose, VeryVerbose),
-		( { VeryVerbose = yes } ->
-			( { HowToCheckGoal = check_unique_modes } ->
-				io__write_string(
-	"% Mode-checking, determinism-checking, and unique-mode-checking\n% ")
-			;
-				io__write_string("% Mode-checking ")
-			),
-			{ PredProcId = proc(PredId, ProcId) },
-			hlds_out__write_pred_proc_id(ModuleInfo1,
-				PredId, ProcId),
-			io__write_string("\n")
-			/*****
-			{ mode_list_get_initial_insts(Modes, ModuleInfo1,
-				InitialInsts) },
-			io__write_string("% Initial insts: `"),
-			{ varset__init(InstVarSet) },
-			mercury_output_inst_list(InitialInsts, InstVarSet),
-			io__write_string("'\n")
-			*****/
+		%
+		% Check that the procedure is valid (i.e. type-correct),
+		% before we attempt to do mode analysis on it.
+		% This check is necessary to avoid internal errors
+		% caused by doing mode analysis on type-incorrect code.
+		% XXX inefficient! This is O(N*M).
+		%
+		{ PredProcId = proc(PredId, _ProcId) },
+		{ module_info_predids(ModuleInfo1, ValidPredIds) },
+		( { list__member(PredId, ValidPredIds) } ->
+			queued_proc_progress_message(PredProcId,
+				HowToCheckGoal, ModuleInfo1),
+			modecheck_queued_proc(HowToCheckGoal, PredProcId,
+				ModuleInfo1, ModuleInfo2, Changed1)
 		;
-			[]
+			{ ModuleInfo2 = ModuleInfo1 },
+			{ Changed1 = no }
 		),
-		modecheck_queued_proc(HowToCheckGoal, PredProcId,
-			ModuleInfo1, ModuleInfo2, Changed1),
 		modecheck_queued_procs(HowToCheckGoal, ModuleInfo2, ModuleInfo,
 			Changed2),
 		{ bool__or(Changed1, Changed2, Changed) }
 	;
 		{ ModuleInfo = ModuleInfo0 },
 		{ Changed = no }
+	).
+
+:- pred queued_proc_progress_message(pred_proc_id, how_to_check_goal,
+			module_info, io__state, io__state).
+:- mode queued_proc_progress_message(in, in, in, di, uo) is det.
+
+queued_proc_progress_message(PredProcId, HowToCheckGoal, ModuleInfo) -->
+	globals__io_lookup_bool_option(very_verbose,
+		VeryVerbose),
+	( { VeryVerbose = yes } ->
+		%
+		% print progress message
+		%
+		( { HowToCheckGoal = check_unique_modes } ->
+			io__write_string(
+		    "% Analyzing modes, determinism, and unique-modes for\n% ")
+		;
+			io__write_string("% Mode-analyzing ")
+		),
+		{ PredProcId = proc(PredId, ProcId) },
+		hlds_out__write_pred_proc_id(ModuleInfo, PredId, ProcId),
+		io__write_string("\n")
+		/*****
+		{ mode_list_get_initial_insts(Modes, ModuleInfo1,
+			InitialInsts) },
+		io__write_string("% Initial insts: `"),
+		{ varset__init(InstVarSet) },
+		mercury_output_inst_list(InitialInsts, InstVarSet),
+		io__write_string("'\n")
+		*****/
+	;
+		[]
 	).
 
 :- pred modecheck_queued_proc(how_to_check_goal, pred_proc_id,


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