[m-rev.] diff: cleanup switch_detection.m

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Feb 20 12:58:10 AEDT 2004


compiler/switch_detection.m:
	Bring this module up to date with our current coding standards.
	Use predmode declarations, state variable syntax and field accesses
	as relevant. Reorder arguments where this allows the use of state
	variable syntax. There are no changes in algorithms.

compiler/hlds_goal.m:
	Add field names to unify_rhs, to allow simplification of code in
	switch_detection.m.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/hlds_goal.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/hlds_goal.m,v
retrieving revision 1.111
diff -u -r1.111 hlds_goal.m
--- compiler/hlds_goal.m	21 Dec 2003 05:04:33 -0000	1.111
+++ compiler/hlds_goal.m	19 Feb 2004 01:31:45 -0000
@@ -308,30 +308,33 @@
 :- type unify_rhs
 	--->	var(prog_var)
 	;	functor(
-			cons_id,
-			is_existential_construction,
+			rhs_functor	:: cons_id,
+			rhs_is_exist_constr :: is_existential_construction,
 					% The `is_existential_construction'
 					% field is only used after
 					% polymorphism.m strips off
 					% the `new ' prefix from
 					% existentially typed constructions.
 					
-			list(prog_var)
+			rhs_args	:: list(prog_var)
 		)
 	;	lambda_goal(
-			purity,
-			pred_or_func,
-			lambda_eval_method,
+			rhs_purity	:: purity,
+			rhs_p_or_f	:: pred_or_func,
+			rhs_eval_method	:: lambda_eval_method,
 					% should be `normal' except for
 					% closures executed by Aditi.
-			fix_aditi_state_modes,
-			list(prog_var),	% non-locals of the goal excluding
+			rhs_aditi	:: fix_aditi_state_modes,
+			rhs_nonlocals	:: list(prog_var),
+					% non-locals of the goal excluding
 					% the lambda quantified variables
-			list(prog_var),	% lambda quantified variables
-			list(mode),	% modes of the lambda
+			rhs_lambda_quant_vars :: list(prog_var),
+					% lambda quantified variables
+			rhs_lambda_modes :: list(mode),
+					% modes of the lambda
 					% quantified variables
-			determinism,
-			hlds_goal
+			rhs_detism	:: determinism,
+			rhs_lambda_goal	:: hlds_goal
 		).
 
 	% Was the constructor originally of the form 'new ctor'(...).
Index: compiler/switch_detection.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/switch_detection.m,v
retrieving revision 1.102
diff -u -r1.102 switch_detection.m
--- compiler/switch_detection.m	31 Oct 2003 03:27:29 -0000	1.102
+++ compiler/switch_detection.m	19 Feb 2004 01:31:45 -0000
@@ -70,24 +70,22 @@
 	% Traverse the module structure, calling `detect_switches_in_goal'
 	% for each procedure body.
 
-detect_switches(ModuleInfo0, ModuleInfo1) -->
-	{ module_info_predids(ModuleInfo0, PredIds) },
-	detect_switches_in_preds(PredIds, ModuleInfo0, ModuleInfo1).
-
-:- pred detect_switches_in_preds(list(pred_id), module_info, module_info,
-	io__state, io__state).
-:- mode detect_switches_in_preds(in, in, out, di, uo) is det.
-
-detect_switches_in_preds([], ModuleInfo, ModuleInfo) --> [].
-detect_switches_in_preds([PredId | PredIds], ModuleInfo0, ModuleInfo) -->
-	{ module_info_preds(ModuleInfo0, PredTable) },
-	{ map__lookup(PredTable, PredId, PredInfo) },
-	detect_switches_in_pred(PredId, PredInfo, ModuleInfo0, ModuleInfo1),
-	detect_switches_in_preds(PredIds, ModuleInfo1, ModuleInfo).
-
-:- pred detect_switches_in_pred(pred_id, pred_info, module_info, module_info,
-	io__state, io__state).
-:- mode detect_switches_in_pred(in, in, in, out, di, uo) is det.
+detect_switches(!ModuleInfo, !IO) :-
+	module_info_predids(!.ModuleInfo, PredIds),
+	detect_switches_in_preds(PredIds, !ModuleInfo, !IO).
+
+:- pred detect_switches_in_preds(list(pred_id)::in,
+	module_info::in, module_info::out, io::di, io::uo) is det.
+
+detect_switches_in_preds([], !ModuleInfo, !IO).
+detect_switches_in_preds([PredId | PredIds], !ModuleInfo, !IO) :-
+	module_info_preds(!.ModuleInfo, PredTable),
+	map__lookup(PredTable, PredId, PredInfo),
+	detect_switches_in_pred(PredId, PredInfo, !ModuleInfo, !IO),
+	detect_switches_in_preds(PredIds, !ModuleInfo, !IO).
+
+:- pred detect_switches_in_pred(pred_id::in, pred_info::in,
+	module_info::in, module_info::out, io::di, io::uo) is det.
 
 detect_switches_in_pred(PredId, PredInfo0, !ModuleInfo, !IO) :-
 	ProcIds = pred_info_non_imported_procids(PredInfo0),
@@ -99,14 +97,13 @@
 	),
 	detect_switches_in_procs(ProcIds, PredId, !ModuleInfo).
 
-:- pred detect_switches_in_procs(list(proc_id), pred_id,
-	module_info, module_info).
-:- mode detect_switches_in_procs(in, in, in, out) is det.
-
-detect_switches_in_procs([], _PredId, ModuleInfo, ModuleInfo).
-detect_switches_in_procs([ProcId | ProcIds], PredId, ModuleInfo0, ModuleInfo) :-
-	detect_switches_in_proc(ProcId, PredId, ModuleInfo0, ModuleInfo1),
-	detect_switches_in_procs(ProcIds, PredId, ModuleInfo1, ModuleInfo).
+:- pred detect_switches_in_procs(list(proc_id)::in, pred_id::in,
+	module_info::in, module_info::out) is det.
+
+detect_switches_in_procs([], _PredId, !ModuleInfo).
+detect_switches_in_procs([ProcId | ProcIds], PredId, !ModuleInfo) :-
+	detect_switches_in_proc(ProcId, PredId, !ModuleInfo),
+	detect_switches_in_procs(ProcIds, PredId, !ModuleInfo).
 
 detect_switches_in_proc(ProcId, PredId, !ModuleInfo) :-
 	module_info_preds(!.ModuleInfo, PredTable0),
@@ -120,7 +117,7 @@
 	proc_info_goal(ProcInfo0, Goal0),
 	proc_info_vartypes(ProcInfo0, VarTypes),
 	proc_info_get_initial_instmap(ProcInfo0, !.ModuleInfo, InstMap0),
-	detect_switches_in_goal(Goal0, InstMap0, VarTypes, !.ModuleInfo, Goal),
+	detect_switches_in_goal(!.ModuleInfo, VarTypes, InstMap0, Goal0, Goal),
 
 	proc_info_set_goal(Goal, ProcInfo0, ProcInfo),
 	map__det_update(ProcTable0, ProcId, ProcInfo, ProcTable),
@@ -133,37 +130,34 @@
 	% Given a goal, and the instmap on entry to that goal,
 	% replace disjunctions with switches whereever possible.
 
-:- pred detect_switches_in_goal(hlds_goal, instmap, map(prog_var, type),
-	module_info, hlds_goal).
-:- mode detect_switches_in_goal(in, in, in, in, out) is det.
-
-detect_switches_in_goal(Goal0, InstMap0, VarTypes, ModuleInfo, Goal) :-
-	detect_switches_in_goal_1(Goal0, InstMap0, VarTypes, ModuleInfo,
-		Goal, _InstMap).
+:- pred detect_switches_in_goal(module_info::in, vartypes::in,
+	instmap::in, hlds_goal::in, hlds_goal::out) is det.
+
+detect_switches_in_goal(ModuleInfo, VarTypes, InstMap0, !Goal) :-
+	detect_switches_in_goal_1(ModuleInfo, VarTypes, InstMap0, _InstMap,
+		!Goal).
 
 	% This version is the same as the above except that it returns
 	% the resulting instmap on exit from the goal, which is
 	% computed by applying the instmap delta specified in the
 	% goal's goalinfo.
 
-:- pred detect_switches_in_goal_1(hlds_goal, instmap, map(prog_var, type),
-	module_info, hlds_goal, instmap).
-:- mode detect_switches_in_goal_1(in, in, in, in, out, out) is det.
-
-detect_switches_in_goal_1(Goal0 - GoalInfo, InstMap0, VarTypes, ModuleInfo,
-		Goal - GoalInfo, InstMap) :-
-	detect_switches_in_goal_2(Goal0, GoalInfo, InstMap0,
-		VarTypes, ModuleInfo, Goal),
+:- pred detect_switches_in_goal_1(module_info::in, vartypes::in,
+	instmap::in, instmap::out, hlds_goal::in, hlds_goal::out) is det.
+
+detect_switches_in_goal_1(ModuleInfo, VarTypes, InstMap0, InstMap,
+		Goal0 - GoalInfo, Goal - GoalInfo) :-
+	detect_switches_in_goal_2(ModuleInfo, VarTypes, InstMap0, GoalInfo,
+		Goal0, Goal),
 	update_instmap(Goal0 - GoalInfo, InstMap0, InstMap).
 
 	% Here we process each of the different sorts of goals.
 
-:- pred detect_switches_in_goal_2(hlds_goal_expr, hlds_goal_info, instmap,
-		map(prog_var, type), module_info, hlds_goal_expr).
-:- mode detect_switches_in_goal_2(in, in, in, in, in, out) is det.
+:- pred detect_switches_in_goal_2(module_info::in, vartypes::in, instmap::in, 
+	hlds_goal_info::in, hlds_goal_expr::in, hlds_goal_expr::out) is det.
 
-detect_switches_in_goal_2(disj(Goals0), GoalInfo, InstMap0,
-		VarTypes, ModuleInfo, Goal) :-
+detect_switches_in_goal_2(ModuleInfo, VarTypes, InstMap0, GoalInfo,
+		disj(Goals0), Goal) :-
 	( Goals0 = [] ->
 		Goal = disj([])
 	;
@@ -174,62 +168,58 @@
 			[], Goal)
 	).
 
-detect_switches_in_goal_2(conj(Goals0), _GoalInfo, InstMap0,
-		VarTypes, ModuleInfo, conj(Goals)) :-
-	detect_switches_in_conj(Goals0, InstMap0, VarTypes, ModuleInfo, Goals).
-
-detect_switches_in_goal_2(par_conj(Goals0), _GoalInfo, InstMap0,
-		VarTypes, ModuleInfo, par_conj(Goals)) :-
-	detect_switches_in_par_conj(Goals0, InstMap0, VarTypes,
-		ModuleInfo, Goals).
-
-detect_switches_in_goal_2(not(Goal0), _GoalInfo, InstMap0,
-		VarTypes, ModuleInfo, not(Goal)) :-
-	detect_switches_in_goal(Goal0, InstMap0, VarTypes, ModuleInfo, Goal).
+detect_switches_in_goal_2(ModuleInfo, VarTypes, InstMap0, _GoalInfo,
+		conj(Goals0), conj(Goals)) :-
+	detect_switches_in_conj(ModuleInfo, VarTypes, InstMap0, Goals0, Goals).
+
+detect_switches_in_goal_2(ModuleInfo, VarTypes, InstMap0,
+		_GoalInfo, par_conj(Goals0), par_conj(Goals)) :-
+	detect_switches_in_par_conj(ModuleInfo, VarTypes, InstMap0,
+		Goals0, Goals).
+
+detect_switches_in_goal_2(ModuleInfo, VarTypes, InstMap0, _GoalInfo,
+		not(Goal0), not(Goal)) :-
+	detect_switches_in_goal(ModuleInfo, VarTypes, InstMap0, Goal0, Goal).
 
-detect_switches_in_goal_2(if_then_else(Vars, Cond0, Then0, Else0),
-		_GoalInfo, InstMap0, VarTypes, ModuleInfo,
+detect_switches_in_goal_2(ModuleInfo, VarTypes, InstMap0, _GoalInfo,
+		if_then_else(Vars, Cond0, Then0, Else0),
 		if_then_else(Vars, Cond, Then, Else)) :-
-	detect_switches_in_goal_1(Cond0, InstMap0, VarTypes, ModuleInfo, Cond,
-		InstMap1),
-	detect_switches_in_goal(Then0, InstMap1, VarTypes, ModuleInfo, Then),
-	detect_switches_in_goal(Else0, InstMap0, VarTypes, ModuleInfo, Else).
-
-detect_switches_in_goal_2(some(Vars, CanRemove, Goal0), _GoalInfo, InstMap0,
-		VarTypes, ModuleInfo, some(Vars, CanRemove, Goal)) :-
-	detect_switches_in_goal(Goal0, InstMap0, VarTypes, ModuleInfo, Goal).
-
-detect_switches_in_goal_2(generic_call(A,B,C,D), _, _, _, _,
-		generic_call(A,B,C,D)).
-
-detect_switches_in_goal_2(call(A,B,C,D,E,F), _, _, _, _,
-		call(A,B,C,D,E,F)).
-
-detect_switches_in_goal_2(unify(A,RHS0,C,D,E), __GoalInfo, InstMap0,
-		VarTypes, ModuleInfo, unify(A,RHS,C,D,E)) :-
-	(
-		RHS0 = lambda_goal(Purity, PredOrFunc, EvalMethod, FixModes,
-			NonLocals, Vars, Modes, Det, Goal0)
-	->
+	detect_switches_in_goal_1(ModuleInfo, VarTypes, InstMap0, InstMap1,
+		Cond0, Cond),
+	detect_switches_in_goal(ModuleInfo, VarTypes, InstMap1, Then0, Then),
+	detect_switches_in_goal(ModuleInfo, VarTypes, InstMap0, Else0, Else).
+
+detect_switches_in_goal_2(ModuleInfo, VarTypes, InstMap0, _GoalInfo,
+		some(Vars, CanRemove, Goal0), some(Vars, CanRemove, Goal)) :-
+	detect_switches_in_goal(ModuleInfo, VarTypes, InstMap0, Goal0, Goal).
+
+detect_switches_in_goal_2(_, _, _, _, Goal @ generic_call(_, _, _, _), Goal).
+
+detect_switches_in_goal_2(_, _, _, _, Goal @ call(_, _, _, _, _, _), Goal).
+
+detect_switches_in_goal_2(ModuleInfo, VarTypes, InstMap0, _GoalInfo,
+		Goal0, Goal) :-
+	Goal0 = unify(_, RHS0, _, _, _),
+	( RHS0 = lambda_goal(_, _, _, _, _, Vars, Modes, _, LambdaGoal0) ->
 		% we need to insert the initial insts for the lambda
 		% variables in the instmap before processing the lambda goal
-		instmap__pre_lambda_update(ModuleInfo, 
-			Vars, Modes, InstMap0, InstMap1),
-		detect_switches_in_goal(Goal0, InstMap1, VarTypes, ModuleInfo,
-			Goal),
-		RHS = lambda_goal(Purity, PredOrFunc, EvalMethod, FixModes,
-			NonLocals, Vars, Modes, Det, Goal)
+		instmap__pre_lambda_update(ModuleInfo, Vars, Modes,
+			InstMap0, InstMap1),
+		detect_switches_in_goal(ModuleInfo, VarTypes, InstMap1,
+			LambdaGoal0, LambdaGoal),
+		RHS = RHS0 ^ rhs_lambda_goal := LambdaGoal,
+		Goal = Goal0 ^ unify_rhs := RHS
 	;
-		RHS = RHS0
+		Goal = Goal0
 	).
 
-detect_switches_in_goal_2(switch(Var, CanFail, Cases0), _, InstMap,
-		VarTypes, ModuleInfo, switch(Var, CanFail, Cases)) :-
-	detect_switches_in_cases(Cases0, InstMap, VarTypes, ModuleInfo, Cases).
-
-detect_switches_in_goal_2(foreign_proc(A,B,C,D,E,F,G), _, _, _, _,
-		foreign_proc(A,B,C,D,E,F,G)).
-detect_switches_in_goal_2(shorthand(_), _, _, _, _, _) :-
+detect_switches_in_goal_2(ModuleInfo, VarTypes, InstMap, _,
+		switch(Var, CanFail, Cases0), switch(Var, CanFail, Cases)) :-
+	detect_switches_in_cases(ModuleInfo, VarTypes, InstMap, Cases0, Cases).
+
+detect_switches_in_goal_2(_, _, _, _, Goal @ foreign_proc(_, _, _, _, _, _, _),
+		Goal).
+detect_switches_in_goal_2(_, _, _, _, shorthand(_), _) :-
 	% these should have been expanded out by now
 	error("detect_switches_in_goal_2: unexpected shorthand").
 
@@ -250,10 +240,10 @@
 
 :- type again ---> again(prog_var, list(hlds_goal), sorted_case_list).
 
-:- pred detect_switches_in_disj(list(prog_var), list(hlds_goal), hlds_goal_info,
-	instmap, map(prog_var, type), list(prog_var), module_info,
-	list(again), hlds_goal_expr).
-:- mode detect_switches_in_disj(in, in, in, in, in, in, in, in, out) is det.
+:- pred detect_switches_in_disj(list(prog_var)::in, list(hlds_goal)::in,
+	hlds_goal_info::in, instmap::in, vartypes::in,
+	list(prog_var)::in, module_info::in, list(again)::in,
+	hlds_goal_expr::out) is det.
 
 detect_switches_in_disj([Var | Vars], Goals0, GoalInfo, InstMap,
 		VarTypes, AllVars, ModuleInfo, Again0, Goal) :-
@@ -284,8 +274,8 @@
 					GoalInfo, InstMap, ModuleInfo,
 					Goal)
 			;
-				detect_sub_switches_in_disj(Goals0, InstMap,
-					VarTypes, ModuleInfo, Goals),
+				detect_sub_switches_in_disj(ModuleInfo,
+					VarTypes, InstMap, Goals0, Goals),
 				Goal = disj(Goals)
 			)
 		;
@@ -310,8 +300,8 @@
 		VarTypes, AllVars, ModuleInfo, AgainList0, disj(Goals)) :-
 	(
 		AgainList0 = [],
-		detect_sub_switches_in_disj(Goals0, InstMap, VarTypes,
-			ModuleInfo, Goals)
+		detect_sub_switches_in_disj(ModuleInfo, VarTypes, InstMap,
+			Goals0, Goals)
 	;
 		AgainList0 = [Again | AgainList1],
 		select_best_switch(AgainList1, Again, BestAgain),
@@ -324,8 +314,7 @@
 		Goals = [SwitchGoal - GoalInfo | LeftList]
 	).
 
-:- pred select_best_switch(list(again), again, again).
-:- mode select_best_switch(in, in, out) is det.
+:- pred select_best_switch(list(again)::in, again::in, again::out) is det.
 
 select_best_switch([], BestAgain, BestAgain).
 select_best_switch([Again | AgainList], BestAgain0, BestAgain) :-
@@ -342,50 +331,46 @@
 	),
 	select_best_switch(AgainList, BestAgain1, BestAgain).
 
-:- pred detect_sub_switches_in_disj(list(hlds_goal), instmap,
-		map(prog_var, type), module_info, list(hlds_goal)).
-:- mode detect_sub_switches_in_disj(in, in, in, in, out) is det.
-
-detect_sub_switches_in_disj([], _InstMap, _VarTypes, _ModuleInfo, []).
-detect_sub_switches_in_disj([Goal0 | Goals0], InstMap, VarTypes, ModuleInfo,
-		[Goal | Goals]) :-
-	detect_switches_in_goal(Goal0, InstMap, VarTypes, ModuleInfo, Goal),
-	detect_sub_switches_in_disj(Goals0, InstMap, VarTypes, ModuleInfo,
-		Goals).
-
-:- pred detect_switches_in_cases(list(case), instmap, map(prog_var, type),
-		module_info, list(case)).
-:- mode detect_switches_in_cases(in, in, in, in, out) is det.
-
-detect_switches_in_cases([], _InstMap, _VarTypes, _ModuleInfo, []).
-detect_switches_in_cases([Case0 | Cases0], InstMap, VarTypes, ModuleInfo,
-		[Case | Cases]) :-
+:- pred detect_sub_switches_in_disj(module_info::in, vartypes::in, instmap::in,
+	list(hlds_goal)::in, list(hlds_goal)::out) is det.
+
+detect_sub_switches_in_disj(_ModuleInfo, _VarTypes, _InstMap, [], []).
+detect_sub_switches_in_disj(ModuleInfo, VarTypes, InstMap,
+		[Goal0 | Goals0], [Goal | Goals]) :-
+	detect_switches_in_goal(ModuleInfo, VarTypes, InstMap, Goal0, Goal),
+	detect_sub_switches_in_disj(ModuleInfo, VarTypes, InstMap,
+		Goals0, Goals).
+
+:- pred detect_switches_in_cases(module_info::in, vartypes::in, instmap::in,
+	list(case)::in, list(case)::out) is det.
+
+detect_switches_in_cases(_ModuleInfo, _VarTypes, _InstMap, [], []).
+detect_switches_in_cases(ModuleInfo, VarTypes, InstMap,
+		[Case0 | Cases0], [Case | Cases]) :-
 	Case0 = case(Functor, Goal0),
-	detect_switches_in_goal(Goal0, InstMap, VarTypes, ModuleInfo, Goal),
+	detect_switches_in_goal(ModuleInfo, VarTypes, InstMap, Goal0, Goal),
 	Case = case(Functor, Goal),
-	detect_switches_in_cases(Cases0, InstMap, VarTypes, ModuleInfo, Cases).
+	detect_switches_in_cases(ModuleInfo, VarTypes, InstMap, Cases0, Cases).
+
+:- pred detect_switches_in_par_conj(module_info::in, vartypes::in, instmap::in,
+	list(hlds_goal)::in, list(hlds_goal)::out) is det.
 
-:- pred detect_switches_in_par_conj(list(hlds_goal), instmap,
-		map(prog_var, type), module_info, list(hlds_goal)).
-:- mode detect_switches_in_par_conj(in, in, in, in, out) is det.
-
-detect_switches_in_par_conj([], _InstMap, _VarTypes, _ModuleInfo, []).
-detect_switches_in_par_conj([Goal0 | Goals0], InstMap, VarTypes, ModuleInfo,
-		[Goal | Goals]) :-
-	detect_switches_in_goal(Goal0, InstMap, VarTypes, ModuleInfo, Goal),
-	detect_switches_in_par_conj(Goals0, InstMap, VarTypes,
-		ModuleInfo, Goals).
-
-:- pred detect_switches_in_conj(list(hlds_goal), instmap, map(prog_var, type),
-	module_info, list(hlds_goal)).
-:- mode detect_switches_in_conj(in, in, in, in, out) is det.
-
-detect_switches_in_conj([], _InstMap, _VarTypes, _ModuleInfo, []).
-detect_switches_in_conj([Goal0 | Goals0], InstMap0, VarTypes, ModuleInfo,
-		[Goal | Goals]) :-
-	detect_switches_in_goal_1(Goal0, InstMap0, VarTypes, ModuleInfo, Goal,
-		InstMap1),
-	detect_switches_in_conj(Goals0, InstMap1, VarTypes, ModuleInfo, Goals).
+detect_switches_in_par_conj(_ModuleInfo, _VarTypes, _InstMap, [], []).
+detect_switches_in_par_conj(ModuleInfo, VarTypes, InstMap,
+		[Goal0 | Goals0], [Goal | Goals]) :-
+	detect_switches_in_goal(ModuleInfo, VarTypes, InstMap, Goal0, Goal),
+	detect_switches_in_par_conj(ModuleInfo, VarTypes, InstMap,
+		Goals0, Goals).
+
+:- pred detect_switches_in_conj(module_info::in, vartypes::in, instmap::in,
+	list(hlds_goal)::in, list(hlds_goal)::out) is det.
+
+detect_switches_in_conj(_ModuleInfo, _VarTypes, _InstMap, [], []).
+detect_switches_in_conj(ModuleInfo, VarTypes, InstMap0,
+		[Goal0 | Goals0], [Goal | Goals]) :-
+	detect_switches_in_goal_1(ModuleInfo, VarTypes, InstMap0, InstMap1,
+		Goal0, Goal),
+	detect_switches_in_conj(ModuleInfo, VarTypes, InstMap1, Goals0, Goals).
 
 %-----------------------------------------------------------------------------%
 
@@ -402,9 +387,8 @@
 	% We partition the goals by abstractly interpreting the unifications
 	% at the start of each disjunction, to build up a substitution.
 
-:- pred partition_disj(list(hlds_goal), prog_var, hlds_goal_info,
-		list(hlds_goal), sorted_case_list).
-:- mode partition_disj(in, in, in, out, out) is semidet.
+:- pred partition_disj(list(hlds_goal)::in, prog_var::in, hlds_goal_info::in,
+	list(hlds_goal)::out, sorted_case_list::out) is semidet.
 
 partition_disj(Goals0, Var, GoalInfo, Left, CasesList) :-
 	map__init(Cases0),
@@ -413,57 +397,56 @@
 	CasesAssocList \= [], % there must be at least one case
 	fix_case_list(CasesAssocList, GoalInfo, CasesList).
 
-:- pred partition_disj_trial(list(hlds_goal), prog_var,
-	list(hlds_goal), list(hlds_goal), cases, cases).
-:- mode partition_disj_trial(in, in, in, out, in, out) is det.
+:- pred partition_disj_trial(list(hlds_goal)::in, prog_var::in,
+	list(hlds_goal)::in, list(hlds_goal)::out, cases::in, cases::out)
+	is det.
 
-partition_disj_trial([], _Var, Left, Left, Cases, Cases).
-partition_disj_trial([Goal0 | Goals], Var, Left0, Left, Cases0, Cases) :-
+partition_disj_trial([], _Var, !Left, !Cases).
+partition_disj_trial([Goal0 | Goals], Var, !Left, !Cases) :-
 	find_bind_var(Var, find_bind_var_for_switch_in_deconstruct,
 		Goal0, Goal, no, MaybeFunctor, unit, _, _),
 	(
 		MaybeFunctor = yes(Functor),
-		Left1 = Left0,
-		( map__search(Cases0, Functor, DisjList0) ->
-			DisjList1 = [Goal | DisjList0],
-			map__det_update(Cases0, Functor, DisjList1, Cases1)
+		( map__search(!.Cases, Functor, DisjList0) ->
+			DisjList = [Goal | DisjList0],
+			map__det_update(!.Cases, Functor, DisjList, !:Cases)
 		;
-			DisjList1 = [Goal],
-			map__det_insert(Cases0, Functor, DisjList1, Cases1)
+			DisjList = [Goal],
+			map__det_insert(!.Cases, Functor, DisjList, !:Cases)
 		)
 	;
 		MaybeFunctor = no,
-		Left1 = [Goal0 | Left0],
-		Cases1 = Cases0
+		!:Left = [Goal0 | !.Left]
 	),
-	partition_disj_trial(Goals, Var, Left1, Left, Cases1, Cases).
+	partition_disj_trial(Goals, Var, !Left, !Cases).
 
-:- pred find_bind_var_for_switch_in_deconstruct(prog_var, hlds_goal,
-		list(hlds_goal), maybe(cons_id), maybe(cons_id), unit, unit).
-:- mode find_bind_var_for_switch_in_deconstruct(in, in, out,
-		in, out, in, out) is det.
+:- pred find_bind_var_for_switch_in_deconstruct(prog_var::in, hlds_goal::in,
+	list(hlds_goal)::out, maybe(cons_id)::in, maybe(cons_id)::out,
+	unit::in, unit::out) is det.
 
 find_bind_var_for_switch_in_deconstruct(_UnifyVar, Goal0, Goals, 
 		_Result0, Result, _, unit) :-
 	(
-		Goal0 = unify(A, B, C, UnifyInfo0, E) - GoalInfo,
-		UnifyInfo0 = deconstruct(A, Functor, F, G, _, I)
+		Goal0 = GoalExpr0 - GoalInfo,
+		UnifyInfo0 = GoalExpr0 ^ unify_kind,
+		UnifyInfo0 = deconstruct(_, Functor, _, _, _, _)
 	->
 		Result = yes(Functor),
 			% The deconstruction unification now becomes
 			% deterministic, since the test will get
 			% carried out in the switch.
-		UnifyInfo = deconstruct(A, Functor, F, G,
-			cannot_fail, I),
-		Goals = [unify(A, B, C, UnifyInfo, E) - GoalInfo]
+		UnifyInfo = UnifyInfo0 ^ deconstruct_can_fail := cannot_fail,
+		GoalExpr = GoalExpr0 ^ unify_kind := UnifyInfo,
+		Goal = GoalExpr - GoalInfo,
+		Goals = [Goal]
 	;
 		error("find_bind_var_for_switch_in_deconstruct")
 	).
 
 %-----------------------------------------------------------------------------%
 
-find_bind_var(Var, ProcessUnify, Goal0, Goal,
-		Result0, Result, Info0, Info, FoundDeconstruct) :-
+find_bind_var(Var, ProcessUnify, Goal0, Goal, Result0, Result, Info0, Info,
+		FoundDeconstruct) :-
 	map__init(Substitution),
 	find_bind_var(Var, ProcessUnify, Goal0, Goal, Substitution,
 		_, Result0, Result, Info0, Info, DeconstructSearch),
@@ -547,31 +530,25 @@
 	prog_substitution::in, prog_substitution::out, Result::in, Result::out,
 	Info::in, Info::out, deconstruct_search::out) is det.
 
-conj_find_bind_var(_Var, _, [], [], Substitution, Substitution,
-		Result, Result, Info, Info, before_deconstruct).
+conj_find_bind_var(_Var, _, [], [], !Substitution, !Result, !Info,
+		before_deconstruct).
 conj_find_bind_var(Var, ProcessUnify, [Goal0 | Goals0], [Goal | Goals],
-		Substitution0, Substitution, Result0, Result,
-		Info0, Info, FoundDeconstruct) :-
-	find_bind_var(Var, ProcessUnify, Goal0, Goal, Substitution0,
-		Substitution1, Result0, Result1,
-		Info0, Info1, FoundDeconstruct1),
+		!Substitution, !Result, !Info, FoundDeconstruct) :-
+	find_bind_var(Var, ProcessUnify, Goal0, Goal, !Substitution,
+		!Result, !Info, FoundDeconstruct1),
 	( FoundDeconstruct1 = before_deconstruct ->
 		conj_find_bind_var(Var, ProcessUnify, Goals0, Goals,
-			Substitution1, Substitution, Result1, Result,
-			Info1, Info, FoundDeconstruct)
+			!Substitution, !Result, !Info, FoundDeconstruct)
 	;
 		FoundDeconstruct = FoundDeconstruct1,
-		Goals = Goals0,
-		Substitution = Substitution1,
-		Result = Result1,
-		Info = Info1
+		Goals = Goals0
 	).
 
 %-----------------------------------------------------------------------------%
 
-:- pred cases_to_switch(sorted_case_list, prog_var, map(prog_var, type),
-		hlds_goal_info, instmap, module_info, hlds_goal_expr).
-:- mode cases_to_switch(in, in, in, in, in, in, out) is det.
+:- pred cases_to_switch(sorted_case_list::in, prog_var::in, vartypes::in,
+	hlds_goal_info::in, instmap::in, module_info::in, hlds_goal_expr::out)
+	is det.
 
 cases_to_switch(CasesList, Var, VarTypes, _GoalInfo, InstMap, ModuleInfo,
 		Goal) :-
@@ -588,14 +565,14 @@
 	;
 		map__lookup(VarTypes, Var, Type),
 		CasesList1 = CasesList,
-		( switch_covers_all_cases(CasesList1, Type, ModuleInfo) ->
+		( switch_covers_all_cases(ModuleInfo, Type, CasesList1) ->
 			CanFail = cannot_fail
 		;
 			CanFail = can_fail
 		)
 	),
-	detect_switches_in_cases(CasesList1, InstMap, VarTypes,
-		ModuleInfo, Cases),
+	detect_switches_in_cases(ModuleInfo, VarTypes, InstMap,
+		CasesList1, Cases),
 
 	% We turn switches with no arms into fail, since this avoids having
 	% the code generator flush the control variable of the switch.
@@ -614,10 +591,10 @@
 	% check whether a switch handles all the possible
 	% constants/functors for the type
 
-:- pred switch_covers_all_cases(sorted_case_list, type, module_info).
-:- mode switch_covers_all_cases(in, in, in) is semidet.
+:- pred switch_covers_all_cases(module_info::in, (type)::in,
+	sorted_case_list::in) is semidet.
 
-switch_covers_all_cases(CasesList, Type, ModuleInfo) :-
+switch_covers_all_cases(ModuleInfo, Type, CasesList) :-
 	type_util__switch_type_num_functors(ModuleInfo, Type, NumFunctors),
 	list__length(CasesList, NumCases),
 	NumCases = NumFunctors.
@@ -625,9 +602,8 @@
 	% convert the assoc_list(cons_id, list(hlds_goal) back into
 	% a plain list(case).
 
-:- pred fix_case_list(assoc_list(cons_id, list(hlds_goal)), hlds_goal_info,
-	list(case)).
-:- mode fix_case_list(in, in, out) is det.
+:- pred fix_case_list(assoc_list(cons_id, list(hlds_goal))::in,
+	hlds_goal_info::in, list(case)::out) is det.
 
 fix_case_list([], _, []).
 fix_case_list([Functor - DisjList0 | Cases0], GoalInfo,
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing java
cvs diff: Diffing java/library
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
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