diff: mode inference & functions

Fergus Henderson fjh at cs.mu.oz.au
Sun Jan 4 16:12:40 AEDT 1998


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.

cvs diff  compiler/make_hlds.m
Index: compiler/make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.248
diff -u -r1.248 make_hlds.m
--- make_hlds.m	1997/12/22 09:55:55	1.248
+++ make_hlds.m	1998/01/04 05:04:09
@@ -1829,12 +1829,8 @@
 		io__write_string("  with `:- pragma c_code' declaration preceding.\n"),
 		{ Info = Info0 }
 	;
-		{
-		pred_info_clauses_info(PredInfo1, Clauses0),
-		pred_info_procedures(PredInfo1, Procs),
-		pred_info_typevarset(PredInfo1, TVarSet0),
-		map__keys(Procs, ModeIds)
-		},
+		{ pred_info_clauses_info(PredInfo1, Clauses0) },
+		{ pred_info_typevarset(PredInfo1, TVarSet0) },
 		clauses_info_add_clause(Clauses0, PredId, ModeIds,
 			ClauseVarSet, TVarSet0, Args, Body, Context, Goal,
 			VarSet, TVarSet, Clauses, Warnings, Info0, Info),
@@ -1847,15 +1843,20 @@
 					ArgTypes, PredInfo5),
 
 		%
-		% check if there are no modes for the predicate,
-		% and if so, set the `infer_modes' flag for that predicate
+		% If it is a function, add the default mode.
+		% Then check if there are still no modes for
+		% the predicate, and if so, set the `infer_modes'
+		% flag for that predicate.
 		%
+		maybe_add_default_mode(PredInfo5, PredInfo6),
+		pred_info_procedures(PredInfo6, Procs),
+		map__keys(Procs, ModeIds),
 		( 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