alias branch bug fixes

David Matthew Overton dmo at cs.mu.OZ.AU
Fri Oct 30 09:58:44 AEDT 1998


Hi,

I've just committed the following bug fixes to tha alias branch.

David

Estimated hours taken: 5

Fix some bugs with deforestation in the alias branch.  Deforestation
is still not completely working.  E.g. it creates predicates with
infinite loops in them when deforesting library/relation.m.

compiler/deforest.m:
	Call recompute_instmap_delta on newly-created call goals to
	ensure they have the correct instmap_delta.

compiler/pd_util.m:
	Call recompute_instmap_delta before re-running unique mode
	checking.  This is necessary to ensure that the inst_keys in
	the inst_key_sub within the instmap_deltas are correct ---
	they will be wrong if the goal has been inlined from another
	predicate.

compiler/pd_info.m:
compiler/deforest.m:
compiler/pd_debug.m:
compiler/pd_util.m:
	Use the inst_table from the proc_info instead of storing an
	extra copy in the pd_info.  This ensures that the inst_table
	is always updated correctly.

Index: deforest.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/deforest.m,v
retrieving revision 1.3.2.5
retrieving revision 1.3.2.6
diff -u -r1.3.2.5 -r1.3.2.6
--- 1.3.2.5	1998/09/25 01:07:07
+++ 1.3.2.6	1998/10/29 22:33:48
@@ -65,8 +65,7 @@
 	hlds_dependency_info_get_dependency_ordering(DepInfo, DepOrdering),
 	list__condense(DepOrdering, DepList),
 
-	inst_table_init(InstTable),
-	pd_info_init(ModuleInfo2, ProcArgInfo, InstTable, IO1, PdInfo0),
+	pd_info_init(ModuleInfo2, ProcArgInfo, IO1, PdInfo0),
 	pd_info_foldl(deforest__proc, DepList, PdInfo0, PdInfo1),
 	pd_info_get_module_info(ModuleInfo3, PdInfo1, PdInfo),
 	module_info_clobber_dependency_info(ModuleInfo3, ModuleInfo),
@@ -111,13 +110,9 @@
 		PredInfo0, ProcInfo0) },
 	pd_info_init_unfold_info(proc(PredId, ProcId), PredInfo0, ProcInfo0),
 	{ proc_info_goal(ProcInfo0, Goal0) },
-	{ proc_info_inst_table(ProcInfo0, InstTable0) },
-	pd_info_set_inst_table(InstTable0),
 	deforest__goal(Goal0, Goal1),
 	pd_info_get_proc_info(ProcInfo1),
-	{ proc_info_set_goal(ProcInfo1, Goal1, ProcInfo2) },
-	pd_info_get_inst_table(InstTable1),
-	{ proc_info_set_inst_table(ProcInfo2, InstTable1, ProcInfo3) },
+	{ proc_info_set_goal(ProcInfo1, Goal1, ProcInfo3) },
 	pd_info_get_changed(Changed),
 
 	( { Changed = yes } ->
@@ -975,7 +970,7 @@
 
 		% Compute a goal_info.
 	% { proc_info_argmodes(CalledProcInfo, argument_modes(_, ArgModes)) },
-	{ instmap_delta_init_reachable(InstMapDelta) },	% YYY
+	{ instmap_delta_init_reachable(InstMapDelta) },
 	{ proc_info_interface_determinism(ProcInfo, Detism) },
 	{ set__list_to_set(Args, NonLocals) },
 	{ goal_info_init(NonLocals, InstMapDelta, Detism, GoalInfo) },
@@ -982,8 +977,9 @@
 
 	{ pred_info_module(CalledPredInfo, PredModule) },
 	{ pred_info_name(CalledPredInfo, PredName) },
-	{ Goal = call(PredId, ProcId, Args, not_builtin, no, 
-			qualified(PredModule, PredName)) - GoalInfo }.
+	{ Goal0 = call(PredId, ProcId, Args, not_builtin, no, 
+			qualified(PredModule, PredName)) - GoalInfo },
+	pd_util__recompute_instmap_delta(Goal0, Goal).
 	
 :- pred deforest__create_deforest_call_args(list(var)::in, list(type)::in,
 	map(var, var)::in, substitution::in, list(var)::out, varset::in,
Index: pd_debug.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/pd_debug.m,v
retrieving revision 1.1.6.2
retrieving revision 1.1.6.3
diff -u -r1.1.6.2 -r1.1.6.3
--- 1.1.6.2	1998/07/27 05:31:19
+++ 1.1.6.3	1998/10/29 22:33:49
@@ -152,8 +152,8 @@
 
 pd_debug__write_instmap -->
 	pd_info_get_instmap(InstMap),
-	pd_info_get_inst_table(InstTable),
 	pd_info_get_proc_info(ProcInfo),
+	{ proc_info_inst_table(ProcInfo, InstTable) },
 	{ proc_info_varset(ProcInfo, VarSet) },
 	pd_debug__do_io(hlds_out__write_instmap(InstMap, VarSet, yes, 1,
 		InstTable)).
@@ -183,7 +183,7 @@
 		pd_info_get_instmap(InstMap),
 		pd_info_get_io_state(IO0),
 		pd_info_get_module_info(ModuleInfo),
-		pd_info_get_inst_table(InstTable),
+		{ proc_info_inst_table(ProcInfo, InstTable) },
 		{
 		io__write_string(Msg, IO0, IO1),
 		goal_util__goal_vars(Goal - GoalInfo, Vars),
Index: pd_info.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/pd_info.m,v
retrieving revision 1.1.6.3
retrieving revision 1.1.6.4
diff -u -r1.1.6.3 -r1.1.6.4
--- 1.1.6.3	1998/09/25 01:08:37
+++ 1.1.6.4	1998/10/29 22:33:50
@@ -33,7 +33,7 @@
 		set(pair(pred_proc_id)),% pairs of procedures which when
 					% paired for deforestation produce
 					% little improvement
-		inst_table,
+		unit,
 		unit
 	).
 
@@ -53,8 +53,8 @@
 :- inst pd_info_no_io = ground.
 :- mode pd_info_set_io :: pd_info_no_io -> dead.
 
-:- pred pd_info_init(module_info, pd_arg_info, inst_table, io__state, pd_info).
-:- mode pd_info_init(in, in, in, di, pd_info_uo) is det.
+:- pred pd_info_init(module_info, pd_arg_info, io__state, pd_info).
+:- mode pd_info_init(in, in, di, pd_info_uo) is det.
 
 :- pred pd_info_init_unfold_info(pred_proc_id, 
 		pred_info, proc_info, pd_info, pd_info).
@@ -96,9 +96,6 @@
 :- pred pd_info_get_useless_versions(set(pair(pred_proc_id)), pd_info, pd_info).
 :- mode pd_info_get_useless_versions(out, pd_info_di, pd_info_uo) is det.
 
-:- pred pd_info_get_inst_table(inst_table, pd_info, pd_info).
-:- mode pd_info_get_inst_table(out, pd_info_di, pd_info_uo) is det.
-
 :- pred pd_info_set_io_state(io__state, pd_info, pd_info).
 :- mode pd_info_set_io_state(di, pd_info_set_io, pd_info_uo) is det.
 
@@ -135,9 +132,6 @@
 :- pred pd_info_set_useless_versions(set(pair(pred_proc_id)), pd_info, pd_info).
 :- mode pd_info_set_useless_versions(in, pd_info_di, pd_info_uo) is det.
 
-:- pred pd_info_set_inst_table(inst_table, pd_info, pd_info).
-:- mode pd_info_set_inst_table(in, pd_info_di, pd_info_uo) is det.
-
 :- pred pd_info_update_goal(hlds_goal, pd_info, pd_info).
 :- mode pd_info_update_goal(in, pd_info_di, pd_info_uo) is det.
 
@@ -170,7 +164,7 @@
 :- import_module inst_match, hlds_goal, prog_util, hlds_data.
 :- import_module assoc_list, bool, int, require, string.
 
-pd_info_init(ModuleInfo, ProcArgInfos, InstTable, IO, PdInfo) :-
+pd_info_init(ModuleInfo, ProcArgInfos, IO, PdInfo) :-
 	map__init(GoalVersionIndex),
 	map__init(Versions),
 	set__init(ParentVersions),
@@ -179,7 +173,7 @@
 	set__init(UselessVersions),
 	PdInfo = pd_info(IO, ModuleInfo, no, GoalVersionIndex, Versions, 
 		ProcArgInfos, 0, GlobalInfo, ParentVersions, 0, 
-		CreatedVersions, UselessVersions, InstTable, unit).
+		CreatedVersions, UselessVersions, unit, unit).
 
 pd_info_init_unfold_info(PredProcId, PredInfo, ProcInfo) -->
 	pd_info_get_module_info(ModuleInfo),
@@ -224,9 +218,6 @@
 	PdInfo = pd_info(_,_,_,_,_,_,_,_,_,_,Versions,_,_,_).
 pd_info_get_useless_versions(Versions, PdInfo, PdInfo) :-
 	PdInfo = pd_info(_,_,_,_,_,_,_,_,_,_,_,Versions,_,_).
-pd_info_get_inst_table(InstTable, PdInfo, PdInfo) :-
-	PdInfo = pd_info(_,_,_,_,_,_,_,_,_,_,_,_,InstTable,_).
-
 pd_info_set_io_state(IO0, pd_info(_, B,C,D,E,F,G,H,I,J,K,L,M,N), 
 		pd_info(IO, B,C,D,E,F,G,H,I,J,K,L,M,N)) :-
 	unsafe_promise_unique(IO0, IO).
@@ -254,8 +245,6 @@
 		pd_info(A,B,C,D,E,F,G,H,I,J,Versions,L,M,N)).
 pd_info_set_useless_versions(Versions, pd_info(A,B,C,D,E,F,G,H,I,J,K,_,M,N),
 		pd_info(A,B,C,D,E,F,G,H,I,J,K,Versions,M,N)).
-pd_info_set_inst_table(InstTable, pd_info(A,B,C,D,E,F,G,H,I,J,K,L,_,N),
-		pd_info(A,B,C,D,E,F,G,H,I,J,K,L,InstTable,N)).
 
 pd_info_update_goal(_ - GoalInfo) -->
 	{ goal_info_get_instmap_delta(GoalInfo, Delta) },
@@ -568,7 +557,7 @@
 	pd_info_get_module_info(ModuleInfo),
 	pd_info_get_proc_info(ProcInfo),
 	pd_info_get_instmap(InstMap),
-	pd_info_get_inst_table(InstTable),
+	{ proc_info_inst_table(ProcInfo, InstTable) },
 	{ proc_info_vartypes(ProcInfo, VarTypes) },
 	(
 		{ map__search(GoalVersionIndex, CalledPreds, VersionIds) },
Index: pd_util.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/pd_util.m,v
retrieving revision 1.1.6.4
retrieving revision 1.1.6.5
diff -u -r1.1.6.4 -r1.1.6.5
--- 1.1.6.4	1998/07/27 05:31:24
+++ 1.1.6.5	1998/10/29 22:33:51
@@ -188,6 +188,11 @@
 
 pd_util__unique_modecheck_goal(LiveVars, Goal0, Goal, Errors) -->
 
+	% First make sure the inst_subs in the instmap deltas are correct.
+	% (They may have the wrong inst keys if the goal has been inlined
+	% from another predicate.)
+	pd_util__recompute_instmap_delta(Goal0, Goal1),
+
 	% 
 	% Construct a mode_info.
 	%
@@ -210,7 +215,7 @@
 	{ mode_info_init(IO0, ModuleInfo1, InstTable0, PredId, ProcId, Context,
 		LiveVars, InstMap0, HowToCheck, ModeInfo0) },
 
-	{ unique_modes__check_goal(Goal0, Goal, ModeInfo0, ModeInfo1) },
+	{ unique_modes__check_goal(Goal1, Goal, ModeInfo0, ModeInfo1) },
 	pd_info_lookup_bool_option(debug_pd, Debug),
 	{ Debug = yes ->
 		report_mode_errors(ModeInfo1, ModeInfo)
@@ -246,7 +251,8 @@
 	pd_info_get_module_info(ModuleInfo),
 	{ goal_info_get_instmap_delta(GoalInfo, InstMapDelta) },
 	pd_info_get_instmap(InstMapBefore),
-	pd_info_get_inst_table(InstTable),
+	pd_info_get_proc_info(ProcInfo),
+	{ proc_info_inst_table(ProcInfo, InstTable) },
 	{ goal_info_get_nonlocals(GoalInfo, NonLocals) },
 	{ set__to_sorted_list(NonLocals, NonLocalsList) },
 	{ set__init(Vars0) },
@@ -734,7 +740,7 @@
 inst_MSG_2(bound(_, ListA), InstMapA, bound(UniqB, ListB), InstMapB,
 		InstTable, ModuleInfo, Inst) :-
 	bound_inst_list_MSG(ListA, InstMapA, ListB, InstMapB, InstTable,
-		ModuleInfo, UniqB, ListB, Inst).
+		ModuleInfo, UniqB, ListB, InstMapB, Inst).
 inst_MSG_2(bound(_, _), _, ground(UniqB, InfoB), _, _, _,
 		ground(UniqB, InfoB)).
 
@@ -772,11 +778,11 @@
 
 :- pred bound_inst_list_MSG(list(bound_inst), instmap, list(bound_inst),
 		instmap, inst_table, module_info, uniqueness,
-		list(bound_inst), inst).
-:- mode bound_inst_list_MSG(in, in, in, in, in, in, in, in, out) is semidet.
+		list(bound_inst), instmap, inst).
+:- mode bound_inst_list_MSG(in, in, in, in, in, in, in, in, in, out) is semidet.
 
 bound_inst_list_MSG(Xs, InstMapX, Ys, InstMapY, InstTable, ModuleInfo,
-		Uniq, List, Inst) :-
+		Uniq, List, InstMap, Inst) :-
 	(
 		Xs = [],
 		Ys = []
@@ -792,7 +798,7 @@
 				ModuleInfo, Args),
 		Z = functor(ConsId, Args),
 		bound_inst_list_MSG(Xs1, InstMapX, Ys1, InstMapY,
-			InstTable, ModuleInfo, Uniq, List, Inst1),
+			InstTable, ModuleInfo, Uniq, List, InstMap, Inst1),
 		( Inst1 = bound(Uniq, Zs) ->
 			Inst = bound(Uniq, [Z | Zs])
 		;
@@ -800,17 +806,16 @@
 		)
 	;
 		% Check that it's OK to round off the uniqueness information.
-		instmap__init_reachable(EmptyInstMap),	% YYY
 		( 
 			Uniq = shared,
 			inst_is_ground(bound(shared, List),
-				EmptyInstMap, InstTable, ModuleInfo),
+				InstMap, InstTable, ModuleInfo),
 			inst_is_not_partly_unique(bound(shared, List),
-				EmptyInstMap, InstTable, ModuleInfo)
+				InstMap, InstTable, ModuleInfo)
 		;
 			Uniq = unique,
 			inst_is_unique(bound(unique, List),
-				EmptyInstMap, InstTable, ModuleInfo)
+				InstMap, InstTable, ModuleInfo)
 		),		
 		Inst = ground(Uniq, no)
 	).
-- 
David Overton
MEngSc Student                       Email: dmo at cs.mu.oz.au     
Department of Computer Science       Web: http://www.cs.mu.oz.au/~dmo
The University of Melbourne          Phone: +61 3 9344 9159



More information about the developers mailing list