[m-dev.] for review: inference of mostly_unique modes

Fergus Henderson fjh at cs.mu.oz.au
Mon Jan 5 18:23:26 AEDT 1998


On 05-Jan-1998, Andrew Bromage <bromage at cs.mu.oz.au> wrote:

> I'm unhappy about overloading the unify_requests structure in this way.
> You probably should rename it to reflect its new role.

OK, I'll rename it as the `proc_requests' structure.
See the diff below.

> > +	%
> > +	% create the new procedure, set its "can-process" flag to `no',
> > +	% and insert it into the queue of requested procedures.
> > +	%
> > +	unify_proc__request_proc(PredId, Modes, yes(ArgLives), MaybeDet,
> > +		Context, ModuleInfo0, ProcId, ModuleInfo),
> 
> Where's the "can-process" flag, and where is the "no"?

I've inserted "call unify_proc__request_proc, which will"...
at the start of the comment.

Here's diffs for the new changes in response to your suggestions.
I've also implemented all your other suggestions, so I'll go ahead
and commit it all now. 

--------------------

compiler/hlds_module.m:
	Fix a mistake in a comment: s/unify_info.m/unify_proc.m/

--------------------

Handle inference of mostly-unique (not just unique) modes.
...
compiler/unify_proc.m:
	Generalize the existing "unify request queue" so that
	it can handle requests for any kind of predicate, not
	just for unification predicates, and hence rename the
	`unify_request' table which contains it as the `proc_request' table.

compiler/hlds_module.m:
	Rename the `unify_request' table as the `proc_request' table.
...

--------------------

Index: hlds_module.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_module.m,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -u -r1.28 -r1.29
--- hlds_module.m	1997/12/23 08:29:22	1.28
+++ hlds_module.m	1998/01/05 05:57:54	1.29
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1996-1997 The University of Melbourne.
+% Copyright (C) 1996-1998 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -100,7 +100,7 @@
 :- mode module_info_set_predicate_table(in, in, out) is det.
 
 	% For an explanation of the unify_requests structure,
-	% see unify_info.m.
+	% see unify_proc.m.
 :- pred module_info_get_unify_requests(module_info, unify_requests).
 :- mode module_info_get_unify_requests(in, out) is det.
 
Index: hlds_module.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_module.m,v
retrieving revision 1.29
diff -u -u -r1.29 hlds_module.m
--- hlds_module.m	1998/01/05 05:57:54	1.29
+++ hlds_module.m	1998/01/05 07:10:46
@@ -99,10 +99,10 @@
 	module_info).
 :- mode module_info_set_predicate_table(in, in, out) is det.
 
-	% For an explanation of the unify_requests structure,
+	% For an explanation of the proc_requests structure,
 	% see unify_proc.m.
-:- pred module_info_get_unify_requests(module_info, unify_requests).
-:- mode module_info_get_unify_requests(in, out) is det.
+:- pred module_info_get_proc_requests(module_info, proc_requests).
+:- mode module_info_get_proc_requests(in, out) is det.
 
 :- pred module_info_get_special_pred_map(module_info, special_pred_map).
 :- mode module_info_get_special_pred_map(in, out) is det.
@@ -192,9 +192,9 @@
 :- pred module_info_unused_arg_info(module_info, unused_arg_info).
 :- mode module_info_unused_arg_info(in, out) is det.
 
-:- pred module_info_set_unify_requests(module_info, unify_requests,
+:- pred module_info_set_proc_requests(module_info, proc_requests,
 	module_info).
-:- mode module_info_set_unify_requests(in, in, out) is det.
+:- mode module_info_set_proc_requests(in, in, out) is det.
 
 :- pred module_info_set_unused_arg_info(module_info,
 		unused_arg_info, module_info).
@@ -435,7 +435,7 @@
 	--->	module(
 			module_sub_info,
 			predicate_table,
-			unify_requests,
+			proc_requests,
 			special_pred_map,
 			continuation_info,
 			type_table,
@@ -624,7 +624,7 @@
 %	--->	module(
 % A			module_sub_info,
 % B			predicate_table,
-% C			unify_requests,
+% C			proc_requests,
 % D			special_pred_map,
 % E			continuation_info,
 % F			type_table,
@@ -649,7 +649,7 @@
 module_info_get_predicate_table(MI0, B) :-
 	MI0 = module(_, B, _, _, _, _, _, _, _, _, _, _).
 
-module_info_get_unify_requests(MI0, C) :-
+module_info_get_proc_requests(MI0, C) :-
 	MI0 = module(_, _, C, _, _, _, _, _, _, _, _, _).
 
 module_info_get_special_pred_map(MI0, D) :-
@@ -691,7 +691,7 @@
 	MI0 = module(A, _, C, D, E, F, G, H, I, J, K, L),
 	MI  = module(A, B, C, D, E, F, G, H, I, J, K, L).
 
-module_info_set_unify_requests(MI0, C, MI) :-
+module_info_set_proc_requests(MI0, C, MI) :-
 	MI0 = module(A, B, _, D, E, F, G, H, I, J, K, L),
 	MI  = module(A, B, C, D, E, F, G, H, I, J, K, L).
 
Index: unify_proc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unify_proc.m,v
retrieving revision 1.62
diff -u -u -r1.62 unify_proc.m
--- unify_proc.m	1997/09/15 13:47:09	1.62
+++ unify_proc.m	1998/01/05 07:13:46
@@ -1,12 +1,12 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1994-1997 The University of Melbourne.
+% Copyright (C) 1994-1998 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
 %
 % unify_proc.m: 
 %
-%	This module encapsulates access to the unify_requests table,
+%	This module encapsulates access to the proc_requests table,
 %	and constructs the clauses for out-of-line complicated
 %	unification procedures.
 %	It also generates the code for other compiler-generated type-specific
@@ -14,7 +14,7 @@
 %
 % During mode analysis, we notice each different complicated unification
 % that occurs.  For each one we add a new mode to the out-of-line
-% unification predicate for that type, and we record in the `unify_requests'
+% unification predicate for that type, and we record in the `proc_requests'
 % table that we need to eventually modecheck that mode of the unification
 % procedure.
 %
@@ -22,9 +22,12 @@
 % do mode analysis for the out-of-line unification procedures.  Note that
 % unification procedures may call other unification procedures which have
 % not yet been encountered, causing new entries to be added to the
-% unify_requests table.  We store the entries in a queue and continue the
+% proc_requests table.  We store the entries in a queue and continue the
 % process until the queue is empty.
 %
+% The same queuing mechanism is also used for procedures created by
+% mode inference during mode analysis and unique mode analysis.
+%
 % Currently if the same complicated unification procedure is called by
 % different modules, each module will end up with a copy of the code for
 % that procedure.  In the long run it would be desireable to either delay
@@ -47,29 +50,40 @@
 :- import_module modes, prog_data, special_pred.
 :- import_module std_util, io.
 
-:- type unify_requests.
+:- type proc_requests.
 
 :- type unify_proc_id == pair(type_id, uni_mode).
 
-	% Initialize the unify_requests table.
+	% Initialize the proc_requests table.
 
-:- pred unify_proc__init_requests(unify_requests).
+:- pred unify_proc__init_requests(proc_requests).
 :- mode unify_proc__init_requests(out) is det.
 
-	% Add a new request to the unify_requests table.
+	% Add a new request for a unification procedure to the
+	% proc_requests table.
 
 :- pred unify_proc__request_unify(unify_proc_id, determinism, term__context,
 				module_info, module_info).
 :- mode unify_proc__request_unify(in, in, in, in, out) is det.
 
-	% Modecheck the unification procedures which have been
-	% requested.  If the first argument is `unique_mode_check',
+	% Add a new request for a procedure (not necessarily a unification)
+	% to the request queue.  Return the procedure's newly allocated
+	% proc_id.  (This is used by unique_modes.m.)
+
+:- pred unify_proc__request_proc(pred_id, list(mode), maybe(list(is_live)),
+				maybe(determinism), term__context,
+				module_info, proc_id, module_info).
+:- mode unify_proc__request_proc(in, in, in, in, in, in, out, out) is det.
+
+	% Do mode analysis of the queued procedures.
+	% If the first argument is `unique_mode_check',
 	% then also go on and do full determinism analysis and unique mode
-	% checking on them as well.
+	% analysis on them as well.
 
-:- pred modecheck_unify_procs(how_to_check_goal, module_info, module_info,
+:- pred modecheck_queued_procs(how_to_check_goal, module_info, module_info,
+				bool,
 				io__state, io__state).
-:- mode modecheck_unify_procs(in, in, out, di, uo) is det.
+:- mode modecheck_queued_procs(in, in, out, out, di, uo) is det.
 
 	% Given the type and mode of a unification, look up the
 	% mode number for the unification proc.
@@ -99,19 +113,19 @@
 :- import_module switch_detection, cse_detection, det_analysis, unique_modes.
 
 	% We keep track of all the complicated unification procs we need
-	% by storing them in the unify_requests structure.
+	% by storing them in the proc_requests structure.
 	% For each unify_proc_id (i.e. type & mode), we store the proc_id
 	% (mode number) of the unification procedure which corresponds to
 	% that mode.
 
-:- type req_map == map(unify_proc_id, proc_id).
+:- type unify_req_map == map(unify_proc_id, proc_id).
 
-:- type req_queue == queue(unify_proc_id).
+:- type req_queue == queue(pred_proc_id).
 
-:- type unify_requests --->
-		unify_requests(
-			req_map,		% the assignment of numbers
-						% to unify_proc_ids
+:- type proc_requests --->
+		proc_requests(
+			unify_req_map,		% the assignment of proc_id
+						% numbers to unify_proc_ids
 			req_queue		% queue of procs we still need
 						% to generate code for
 		).
@@ -119,35 +133,36 @@
 %-----------------------------------------------------------------------------%
 
 unify_proc__init_requests(Requests) :-
-	map__init(ReqMap),
+	map__init(UnifyReqMap),
 	queue__init(ReqQueue),
-	Requests = unify_requests(ReqMap, ReqQueue).
+	Requests = proc_requests(UnifyReqMap, ReqQueue).
 
 %-----------------------------------------------------------------------------%
 
 	% Boring access predicates
 
-:- pred unify_proc__get_req_map(unify_requests, req_map).
-:- mode unify_proc__get_req_map(in, out) is det.
+:- pred unify_proc__get_unify_req_map(proc_requests, unify_req_map).
+:- mode unify_proc__get_unify_req_map(in, out) is det.
 
-:- pred unify_proc__get_req_queue(unify_requests, req_queue).
+:- pred unify_proc__get_req_queue(proc_requests, req_queue).
 :- mode unify_proc__get_req_queue(in, out) is det.
 
-:- pred unify_proc__set_req_map(unify_requests, req_map, unify_requests).
-:- mode unify_proc__set_req_map(in, in, out) is det.
+:- pred unify_proc__set_unify_req_map(proc_requests, unify_req_map,
+					proc_requests).
+:- mode unify_proc__set_unify_req_map(in, in, out) is det.
 
-:- pred unify_proc__set_req_queue(unify_requests, req_queue, unify_requests).
+:- pred unify_proc__set_req_queue(proc_requests, req_queue, proc_requests).
 :- mode unify_proc__set_req_queue(in, in, out) is det.
 
-unify_proc__get_req_map(unify_requests(ReqMap, _), ReqMap).
+unify_proc__get_unify_req_map(proc_requests(UnifyReqMap, _), UnifyReqMap).
 
-unify_proc__get_req_queue(unify_requests(_, ReqQueue), ReqQueue).
+unify_proc__get_req_queue(proc_requests(_, ReqQueue), ReqQueue).
 
-unify_proc__set_req_map(unify_requests(_, B), ReqMap,
-			unify_requests(ReqMap, B)).
+unify_proc__set_unify_req_map(proc_requests(_, B), UnifyReqMap,
+			proc_requests(UnifyReqMap, B)).
 
-unify_proc__set_req_queue(unify_requests(A, _), ReqQueue,
-			unify_requests(A, ReqQueue)).
+unify_proc__set_req_queue(proc_requests(A, _), ReqQueue,
+			proc_requests(A, ReqQueue)).
 
 %-----------------------------------------------------------------------------%
 
@@ -187,9 +202,9 @@
 	->
 		hlds_pred__in_in_unification_proc_id(ProcId)
 	;
-		module_info_get_unify_requests(ModuleInfo, Requests),
-		unify_proc__get_req_map(Requests, ReqMap),
-		map__search(ReqMap, TypeId - UniMode, ProcId)
+		module_info_get_proc_requests(ModuleInfo, Requests),
+		unify_proc__get_unify_req_map(Requests, UnifyReqMap),
+		map__search(UnifyReqMap, TypeId - UniMode, ProcId)
 	).
 
 %-----------------------------------------------------------------------------%
...

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