[m-rev.] [reuse] diff: within_n_cells_difference bootstrap fixes

Peter Ross peter.ross at miscrit.be
Thu Mar 15 01:47:49 AEDT 2001


Hi,


===================================================================


Estimated hours taken: 8
Branches: reuse

compiler/sr_choice.m:
compiler/sr_dead.m:
    No longer use the arity of the cons_id of a type as an indicator of
    the size of the cell.  Instead count the number of arguments to the
    construction and deconstruction.

compiler/sr_dead.m:
    Avoid a problem where we try and reuse a cell to store a pred_const.
    The solution of using cons_id_maybe_arity is probably not optimal,
    and will need to be revisited later.


Index: sr_choice.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_choice.m,v
retrieving revision 1.1.2.16
diff -u -r1.1.2.16 sr_choice.m
--- sr_choice.m	2001/03/13 16:06:56	1.1.2.16
+++ sr_choice.m	2001/03/14 14:37:09
@@ -70,7 +70,8 @@
 
 :- type constraint_info
 	--->	constraint_info(
-			map	:: multi_map(prog_var, cons_id)
+			map	:: multi_map(prog_var,
+					pair(cons_id, prog_vars))
 		).
 
 :- pred constraint_info_init(constraint_info::out) is det.
@@ -184,7 +185,7 @@
 		constraint_info::in, constraint_info::out) is det.
 
 apply_constraint_unification(Constraint, Unif, GoalInfo0, GoalInfo) -->
-	{ Unif = construct(_Var, ConsId, _Vars, _Ms, _HTC, _IsUniq, _Aditi) },
+	{ Unif = construct(_Var, ConsId, Vars, _Ms, _HTC, _IsUniq, _Aditi) },
 	{ goal_info_get_reuse(GoalInfo0, ReuseInfo) },
 	{ ReuseInfo = choice(construct(Pairs)) ->
 		PossibleCandidates = set__to_sorted_list(Pairs)
@@ -199,30 +200,30 @@
 		{ P = (pred(Candidate::out) is nondet :- 
 			list__member(Candidate0, PossibleCandidates),
 			CandidateVar = Candidate0 ^ var,
-			multi_map__search(Map, CandidateVar, ConsIds),
+			multi_map__search(Map, CandidateVar, CandidateData),
+			list__map(fst, CandidateData, ConsIds),
 			list__remove_dups(ConsIds, [ConsId]),
 			Candidate = Candidate0 ^ cons_ids := yes([ConsId])
 		)}
 	;
 		{ Constraint = within_n_cells_difference(Difference) },
 
-			% XXX Are two cells with the same arity the same
-			% contain existentially typed compenents which
-			% require storage of the corresponding type
-			% infos.
+			% XXX recode this more efficiently at some stage.
 		{ P = (pred(Candidate::out) is nondet :- 
 			list__member(Candidate0, PossibleCandidates),
 			CandidateVar = Candidate0 ^ var,
-			multi_map__search(Map, CandidateVar, ConsIds0),
-			list__remove_dups(ConsIds0, ConsIds),
-			cons_id_arity(ConsId, Arity),
-			all [ReuseConsId] (
-				list__member(ReuseConsId, ConsIds)
+			multi_map__search(Map, CandidateVar, CandidateData),
+			ConsIds = list__remove_dups(
+					list__map(fst, CandidateData)),
+			ReuseSizes = list__map(
+					(func(Data) = list__length(snd(Data))),
+					CandidateData),
+			Size = list__length(Vars),
+			all [ReuseSize] (
+				list__member(ReuseSize, ReuseSizes)
 			=>
 				(
-					cons_id_arity(ReuseConsId, ReuseArity),
-					ReuseArity - Arity =< Difference
+					ReuseSize - Size =< Difference
 				)
 			),
 			Candidate = Candidate0 ^ cons_ids := yes(ConsIds)
@@ -234,7 +235,7 @@
 			GoalInfo) }.
 
 apply_constraint_unification(_Constraint, Unif, GoalInfo0, GoalInfo) -->
-	{ Unif = deconstruct(Var, ConsId, _Vars, _Modes, _CanFail, _CanCGC) },
+	{ Unif = deconstruct(Var, ConsId, Vars, _Modes, _CanFail, _CanCGC) },
 
 	{ goal_info_get_reuse(GoalInfo0, ReuseInfo) },
 	{ ReuseInfo = choice(deconstruct(MaybeDies)) ->
@@ -252,7 +253,7 @@
 	},
 
 	Map0 =^ map,
-	{ multi_map__set(Map0, Var, ConsId, Map) },
+	{ multi_map__set(Map0, Var, ConsId - Vars, Map) },
 	^ map := Map.
 apply_constraint_unification(_Constraint, Unif, GoalInfo, GoalInfo) -->
 	{ Unif = assign(_, _) }.
Index: sr_dead.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_dead.m,v
retrieving revision 1.1.2.13
diff -u -r1.1.2.13 sr_dead.m
--- sr_dead.m	2001/03/14 10:32:53	1.1.2.13
+++ sr_dead.m	2001/03/14 14:37:09
@@ -216,7 +216,7 @@
 unification_verify_reuse(ModuleInfo, ProcInfo, Unification, Alias0,
 		Pool0, Pool, Info0, Info) :- 
 	(
-		Unification = deconstruct(Var, ConsId, _, _, _, _)
+		Unification = deconstruct(Var, _ConsId, Vars, _, _, _)
 	->
 		goal_info_get_lfu(Info0, LFU), 
 		goal_info_get_lbu(Info0, LBU),
@@ -237,7 +237,7 @@
 			Pool = Pool0
 		;
 			add_dead_cell(ModuleInfo, ProcInfo, 
-					Var, ConsId, 
+					Var, list__length(Vars), 
 					LFU, LBU,
 					Alias0, Pool0, Pool, 
 					ReuseCondition),
@@ -246,9 +246,18 @@
 					yes(ReuseCondition))), Info) 
 		)
 	;
-		Unification = construct(_, ConsId, _, _, _, _, _)
+		Unification = construct(_, ConsId, Vars, _, _, _, _)
 	->
-		dead_cell_pool_try_to_reuse(ConsId, Pool0, ReuseVarsConds),
+			% XXX to avoid trying to reuse cells such as
+			% pred_const, which don't have a valid cons_id
+			% passed to them in ml_gen_new_object. ie
+			% pred_const's
+		( cons_id_maybe_arity(ConsId, no) ->
+			set__init(ReuseVarsConds)
+		;
+			dead_cell_pool_try_to_reuse(list__length(Vars),
+					Pool0, ReuseVarsConds)
+		),
 		goal_info_set_reuse(Info0, choice(construct(ReuseVarsConds)),
 				Info),
 		Pool = Pool0
@@ -276,10 +285,11 @@
 	% who would be interested in reusing the dead cell. 
 :- type dead_extra_info --->
 		extra(
-			arity, 		% instead of keeping the cons, 
-					% just keep it's size as a way to
-					% compare cons'es and their
-					% mutual reusability.
+			int, 		% the number of variables in the
+					% cell, note that is different
+					% to the arity of the cell.
+					% ie type_info's, existentially
+					% typed data constructors
 			reuse_condition, 
 			list(prog_var) 	% XXX for the moment always kept
 					% empty
@@ -290,14 +300,14 @@
 	% test if empty
 :- pred dead_cell_pool_is_empty(dead_cell_pool::in) is semidet.
 
-:- pred add_dead_cell(module_info, proc_info, prog_var, cons_id, set(prog_var), 
+:- pred add_dead_cell(module_info, proc_info, prog_var, int, set(prog_var), 
 			set(prog_var), alias_as, 
 			dead_cell_pool, dead_cell_pool, 
 			reuse_condition).
 :- mode add_dead_cell(in, in, in, in, in, in, in, in, out, out) is det.
 
 	% given its reuse_condition, add the dead cell to dr_info.
-:- pred add_dead_cell(prog_var, cons_id, reuse_condition, 
+:- pred add_dead_cell(prog_var, int, reuse_condition, 
 			dead_cell_pool, dead_cell_pool) is det.
 :- mode add_dead_cell(in, in, in, in, out) is det.
 
@@ -318,7 +328,7 @@
 					dead_cell_pool).
 :- mode dead_cell_pool_leave_scope(in, in, out) is det.
 
-:- pred dead_cell_pool_try_to_reuse(cons_id, dead_cell_pool, 
+:- pred dead_cell_pool_try_to_reuse(int, dead_cell_pool, 
 		set(reuse_var)).
 :- mode dead_cell_pool_try_to_reuse(in, in, out) is det.
 
@@ -328,32 +338,34 @@
 dead_cell_pool_is_empty(pool(_, Pool)):- 
 	map__is_empty(Pool).
 
-add_dead_cell(ModuleInfo, ProcInfo, Var, Cons, LFU, LBU, 
+add_dead_cell(ModuleInfo, ProcInfo, Var, Size, LFU, LBU, 
 			Alias0, Pool0, Pool, Condition) :- 
 	Pool0 = pool(HVS, _Map0), 
 	reuse_condition_init(ModuleInfo, ProcInfo, Var, LFU, LBU, 
 			Alias0, HVS, Condition),
-	add_dead_cell(Var, Cons, Condition, Pool0, Pool).
 
+		% XXX This needs to be investigated more, but cells of
+		% size 0 are things like characters and integers and so
+		% forth which aren't represented on the heap, so we
+		% don't want to reuse their storage, I think.
+	( Size > 0 ->
+		add_dead_cell(Var, Size, Condition, Pool0, Pool)
+	;
+		Pool = Pool0
+	).
 
-add_dead_cell(Var, Cons, ReuseCond, pool(HVS, Pool0), 
+
+add_dead_cell(Var, Size, ReuseCond, pool(HVS, Pool0), 
 				     pool(HVS, Pool)) :- 
 		% XXX Candidates are always zero. For the
 		% moment we will not try to track this ! 
-	cons_id_maybe_arity(Cons, MaybeArity), 
+	Extra = extra(Size, ReuseCond, []),
 	(
-		MaybeArity = yes(Arity)
+		map__insert(Pool0, Var, Extra, Pool1)
 	->
-		Extra = extra(Arity, ReuseCond, []),
-		(
-			map__insert(Pool0, Var, Extra, Pool1)
-		->
-			Pool = Pool1
-		;
-			require__error("(sr_direct) add_dead_cell: trying to add dead variable whilst already being marked as dead?")
-		)
+		Pool = Pool1
 	;
-		Pool = Pool0
+		error("(sr_dead) add_dead_cell: trying to add dead variable whilst already being marked as dead?")
 	).
 
 
@@ -428,32 +440,20 @@
 	map__from_assoc_list(AssocList, Pool),
 	P = pool(HVS, Pool).
 	
-dead_cell_pool_try_to_reuse(Cons, Pool, Set) :-
+dead_cell_pool_try_to_reuse(Size, Pool, Set) :-
 	Pool = pool(_HVS, Map), 
-	cons_id_maybe_arity(Cons, MaybeArity), 
-	(
-		MaybeArity = yes(Arity)
-	->
-		map__to_assoc_list(Map, AssocList),
-		list__filter(
-			cons_can_reuse(Arity), 
-			AssocList, 
-			CellsThatCanBeReused),
-		list__map(
-			to_pair_var_condition, 
-			CellsThatCanBeReused,
-			VarConditionPairs),
-		set__list_to_set(VarConditionPairs, Set)
-	;
-		set__init(Set)
-	).
+	map__to_assoc_list(Map, AssocList),
+	list__filter(cons_can_reuse(Size), AssocList, CellsThatCanBeReused),
+	list__map(to_pair_var_condition, 
+			CellsThatCanBeReused, VarConditionPairs),
+	set__list_to_set(VarConditionPairs, Set).
 
-:- pred cons_can_reuse(arity, pair(prog_var, dead_extra_info)).
+:- pred cons_can_reuse(int, pair(prog_var, dead_extra_info)).
 :- mode cons_can_reuse(in, in) is semidet.
 
-cons_can_reuse(Arity, _Var - Extra) :- 
-	Extra = extra(DeadArity, _, _), 
-	Arity =< DeadArity.
+cons_can_reuse(Size, _Var - Extra) :- 
+	Extra = extra(DeadSize, _, _), 
+	Size =< DeadSize.
 
 :- pred to_pair_var_condition(pair(prog_var, dead_extra_info), reuse_var).
 :- mode to_pair_var_condition(in, out) is det.

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