[m-dev.] diff: mode inference & functions

Fergus Henderson fjh at cs.mu.oz.au
Sun Jan 4 17:01:52 AEDT 1998


On 04-Jan-1998, Fergus Henderson <fjh at cs.mu.oz.au> wrote:
> 
> Make functions with no mode declaration always use the default mode,
> rather than doing mode inference for them.  
> 
> The reason for this change is that mode inference for functions doesn't
> work properly, because make_hlds.m flattens things in the wrong order.
> In the long run it might be better to fix make_hlds.m to flatten
> things in the right order, but that would cause severe efficiency
> problems for the current type checker.  We would need to modify the
> type checker to use a different algorithm (e.g. the one suggested
> by Peter Stuckey <pjs at cs.mu.oz.au>).
> 
> compiler/make_hlds.m:
> 	When adding clauses for functions with no modes,
> 	add the default function mode (in, in, ...) = out
> 	rather than setting the `infer_modes' marker.

Oops, the version I posted previously was buggy.
Let me try that again.

Index: make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.248
diff -u -u -r1.248 make_hlds.m
--- make_hlds.m	1997/12/22 09:55:55	1.248
+++ make_hlds.m	1998/01/04 06:00:41
@@ -1831,31 +1831,32 @@
 	;
 		{
 		pred_info_clauses_info(PredInfo1, Clauses0),
-		pred_info_procedures(PredInfo1, Procs),
 		pred_info_typevarset(PredInfo1, TVarSet0),
+		maybe_add_default_mode(PredInfo1, PredInfo2),
+		pred_info_procedures(PredInfo2, Procs),
 		map__keys(Procs, ModeIds)
 		},
 		clauses_info_add_clause(Clauses0, PredId, ModeIds,
 			ClauseVarSet, TVarSet0, Args, Body, Context, Goal,
 			VarSet, TVarSet, Clauses, Warnings, Info0, Info),
 		{
-		pred_info_set_clauses_info(PredInfo1, Clauses, PredInfo2),
-		pred_info_set_goal_type(PredInfo2, clauses, PredInfo3),
-		pred_info_set_typevarset(PredInfo3, TVarSet, PredInfo4),
-		pred_info_arg_types(PredInfo4, _ArgTVarSet, ArgTypes),
-		pred_info_set_arg_types(PredInfo4, TVarSet,
-					ArgTypes, PredInfo5),
+		pred_info_set_clauses_info(PredInfo2, Clauses, PredInfo3),
+		pred_info_set_goal_type(PredInfo3, clauses, PredInfo4),
+		pred_info_set_typevarset(PredInfo4, TVarSet, PredInfo5),
+		pred_info_arg_types(PredInfo5, _ArgTVarSet, ArgTypes),
+		pred_info_set_arg_types(PredInfo5, TVarSet,
+					ArgTypes, PredInfo6),
 
 		%
-		% check if there are no modes for the predicate,
+		% check if there are still no modes for the predicate,
 		% and if so, set the `infer_modes' flag for that predicate
 		%
 		( ModeIds = [] ->
-			pred_info_get_markers(PredInfo5, Markers0),
+			pred_info_get_markers(PredInfo6, Markers0),
 			add_marker(Markers0, infer_modes, Markers),
-			pred_info_set_markers(PredInfo5, Markers, PredInfo)
+			pred_info_set_markers(PredInfo6, Markers, PredInfo)
 		;
-			PredInfo = PredInfo5
+			PredInfo = PredInfo6
 		),
 		map__det_update(Preds0, PredId, PredInfo, Preds),
 		predicate_table_set_preds(PredicateTable1, Preds,
-- 
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