[m-dev.] for review: mode declarations for zero arity predicates

Simon Taylor stayl at cs.mu.OZ.AU
Mon Sep 20 12:34:35 AEST 1999


Estimated hours taken: 1.5

Implement Fergus' suggestion for deciding when to add
modes for predicates with no arguments.

The following declarations result in a mode being added:
:- pred foo is semidet.

:- pred foo.
:- mode foo.

:- pred foo.
:- mode foo is semidet.

This declaration doesn't:
:- pred foo.

compiler/make_hlds.m:
	Remove code to add a default mode for a zero arity predicate
	with only a pred declaration with no determinism.

tests/invalid/bigtest.err_exp:
	Add a `no modes for predicate ...' error.

tests/invalid/missing_det_decls.m:
tests/invalid/missing_det_decls.err_exp:
	Add missing mode declarations.

tests/valid/Mmakefile:
	Pass --infer-modes to mmc when compiling zero_arity.m.

tests/valid/zero_arity.m:
	Add tests for each of the declaration combinations listed above.

tests/valid/det_inference.m:
	Add missing mode declarations.


Index: compiler/make_hlds.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/make_hlds.m,v
retrieving revision 1.305
diff -u -u -r1.305 make_hlds.m
--- make_hlds.m	1999/09/17 17:18:58	1.305
+++ make_hlds.m	1999/09/19 01:31:26
@@ -527,33 +527,8 @@
 		--> [].
 add_item_decl_pass_2(mode_defn(_, _, _), _, Status, Module, Status, Module)
 		--> [].
-add_item_decl_pass_2(pred(_, _, _, PredName, TypesAndModes, MaybeDet, _, _, _),
-		_, Status, Module0, Status, Module) -->
-	%
-	% Add a mode for a predicate with no arguments
-	% for which the determinism is not declared.
-	%
-	( { TypesAndModes = [], MaybeDet = no } ->
-		{ module_info_get_predicate_table(Module0, PredTable0) },
-		(
-			{ predicate_table_search_pred_sym_arity(PredTable0,
-				PredName, 0, [PredId]) }
-		->
-			{ module_info_pred_info(Module0, PredId, PredInfo0) },
-			maybe_add_default_zero_arity_pred_mode(PredInfo0,
-				PredInfo, MaybeProcId),
-			{ MaybeProcId = yes(_) ->
-				module_info_set_pred_info(Module0, PredId,
-					PredInfo, Module)
-			;
-				Module = Module0
-			}
-		;
-			{ error("make_hlds.m: can't find pred declaration") }
-		)
-	;
-		{ Module = Module0 }
-	).
+add_item_decl_pass_2(pred(_, _, _, _, _, _, _, _, _),
+		_, Status, Module, Status, Module) --> [].
 
 add_item_decl_pass_2(pred_mode(_, _, _, _, _), _, Status, Module, Status,
 		Module) --> [].
@@ -2035,9 +2010,8 @@
 		{ MaybeModes = yes(Modes) },
 
 		% For predicates with no arguments, if the determinism
-		% is not declared a mode is not added. If there is no separate
-		% mode declaration for the predicate, one will be added by
-		% add_item_list_decls_pass_2.
+		% is not declared a mode is not added. The determinism
+		% can be specified by a separate mode declaration.
 		\+ {
 			Modes = [],
 			MaybeDet = no
@@ -2242,9 +2216,6 @@
 
 	% Go through the list of class methods, looking for functions without
 	% mode declarations.
-	% 
-	% Default modes are not added for zero arity class method predicates
-	% because the determinism must be specified for class methods.
 :- pred add_default_class_method_func_modes(class_interface, 
 	list(maybe(pair(pred_id, proc_id))), 
 	list(maybe(pair(pred_id, proc_id))), module_info, module_info).
@@ -2827,27 +2798,6 @@
 	list__length(List, ModeInt),
 	proc_id_to_int(ModeId, ModeInt).
 
-:- pred maybe_add_default_zero_arity_pred_mode(pred_info, pred_info,
-		maybe(proc_id), io__state, io__state).
-:- mode maybe_add_default_zero_arity_pred_mode(in, out, out, di, uo) is det.
-
-maybe_add_default_zero_arity_pred_mode(PredInfo0, PredInfo, MaybeProcId) -->
-	(
-		{ pred_info_arity(PredInfo0, 0) },
-		{ pred_info_procedures(PredInfo0, Procs0) },
-		{ map__is_empty(Procs0) }
-	->
-		{ Modes = [] },
-		{ MaybeDet = no },
-		{ pred_info_context(PredInfo0, MContext) },
-		module_do_add_mode(PredInfo0, 0, Modes, MaybeDet, MContext,
-			PredInfo, ProcId), 
-		{ MaybeProcId = yes(ProcId) }
-	;
-		{ PredInfo = PredInfo0 },
-		{ MaybeProcId = no }
-	).
-
 %-----------------------------------------------------------------------------%
 
 :- pred module_add_pred_clause(module_info, prog_varset, sym_name,
@@ -2988,9 +2938,7 @@
 	;
 		{ pred_info_clauses_info(PredInfo1, Clauses0) },
 		{ pred_info_typevarset(PredInfo1, TVarSet0) },
-		{ maybe_add_default_func_mode(PredInfo1, PredInfo2a, _) },
-		maybe_add_default_zero_arity_pred_mode(PredInfo2a,
-			PredInfo2, _),
+		{ maybe_add_default_func_mode(PredInfo1, PredInfo2, _) },
 		{ pred_info_procedures(PredInfo2, Procs) },
 		{ map__keys(Procs, ModeIds) },
 		clauses_info_add_clause(Clauses0, PredId, ModeIds,
Index: tests/invalid/bigtest.err_exp
===================================================================
RCS file: /home/staff/zs/imp/tests/invalid/bigtest.err_exp,v
retrieving revision 1.4
diff -u -u -r1.4 bigtest.err_exp
--- bigtest.err_exp	1999/08/31 05:25:58	1.4
+++ bigtest.err_exp	1999/09/19 06:39:18
@@ -11,4 +11,5 @@
 bigtest.m:005:   without preceding `pred' declaration.
 bigtest.m:005: Inferred :- pred fact.
 bigtest.m:010: Error: no mode declaration for predicate `bigtest:p/1'.
+bigtest.m:005: Error: no mode declaration for predicate `bigtest:fact/0'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/missing_det_decls.err_exp
===================================================================
RCS file: /home/staff/zs/imp/tests/invalid/missing_det_decls.err_exp,v
retrieving revision 1.2
diff -u -u -r1.2 missing_det_decls.err_exp
--- missing_det_decls.err_exp	1999/08/31 05:26:00	1.2
+++ missing_det_decls.err_exp	1999/09/20 01:56:15
@@ -1,13 +1,13 @@
-missing_det_decls.m:007: Error: no determinism declaration for exported
-missing_det_decls.m:007:   predicate `missing_det_decls:exp2/1'.
-missing_det_decls.m:014: Error: no determinism declaration for local
-missing_det_decls.m:014:   predicate `missing_det_decls:loc2/1'.
-missing_det_decls.m:004: Error: no determinism declaration for exported
-missing_det_decls.m:004:   predicate `missing_det_decls:exp1/0'.
-missing_det_decls.m:011: Error: no determinism declaration for local
-missing_det_decls.m:011:   predicate `missing_det_decls:loc1/0'.
+missing_det_decls.m:005: Error: no determinism declaration for exported
+missing_det_decls.m:005:   predicate `missing_det_decls:exp1/0'.
+missing_det_decls.m:008: Error: no determinism declaration for exported
+missing_det_decls.m:008:   predicate `missing_det_decls:exp2/1'.
+missing_det_decls.m:013: Error: no determinism declaration for local
+missing_det_decls.m:013:   predicate `missing_det_decls:loc1/0'.
+missing_det_decls.m:016: Error: no determinism declaration for local
+missing_det_decls.m:016:   predicate `missing_det_decls:loc2/1'.
 missing_det_decls.m:004: Error: no clauses for predicate `missing_det_decls:exp1/0'
-missing_det_decls.m:006: Error: no clauses for predicate `missing_det_decls:exp2/1'
-missing_det_decls.m:011: Error: no clauses for predicate `missing_det_decls:loc1/0'
-missing_det_decls.m:013: Error: no clauses for predicate `missing_det_decls:loc2/1'
+missing_det_decls.m:007: Error: no clauses for predicate `missing_det_decls:exp2/1'
+missing_det_decls.m:012: Error: no clauses for predicate `missing_det_decls:loc1/0'
+missing_det_decls.m:015: Error: no clauses for predicate `missing_det_decls:loc2/1'
 For more information, try recompiling with `-E'.
Index: tests/invalid/missing_det_decls.m
===================================================================
RCS file: /home/staff/zs/imp/tests/invalid/missing_det_decls.m,v
retrieving revision 1.1
diff -u -u -r1.1 missing_det_decls.m
--- missing_det_decls.m	1995/07/11 13:12:03	1.1
+++ missing_det_decls.m	1999/09/20 01:55:08
@@ -2,6 +2,7 @@
 :- interface.
 
 :- pred exp1.
+:- mode exp1.
 
 :- pred exp2(int).
 :- mode exp2(out).
@@ -9,6 +10,7 @@
 :- implementation.
 
 :- pred loc1.
+:- mode loc1.
 
 :- pred loc2(int).
 :- mode loc2(out).
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/valid/Mmakefile,v
retrieving revision 1.41
diff -u -u -r1.41 Mmakefile
--- Mmakefile	1999/08/31 05:26:06	1.41
+++ Mmakefile	1999/09/20 01:33:54
@@ -193,6 +193,7 @@
 MCFLAGS-type_inf_ambig_test	= --infer-all
 MCFLAGS-uniq_mode_inf_bug	= --infer-all
 MCFLAGS-vn_float		= -O5
+MCFLAGS-zero_arity		= --infer-modes
 
 check:	objs aditi_update.err
 
Index: tests/valid/det_inference.m
===================================================================
RCS file: /home/staff/zs/imp/tests/valid/det_inference.m,v
retrieving revision 1.1
diff -u -u -r1.1 det_inference.m
--- det_inference.m	1995/11/14 08:03:18	1.1
+++ det_inference.m	1999/09/20 01:31:36
@@ -1,10 +1,18 @@
 :- module det_inference.
 
 :- pred p1 is det.
+
 :- pred p2.
+:- mode p2.
+
 :- pred p3.
+:- mode p3.
+
 :- pred p4.
+:- mode p4.
+
 :- pred p5.
+:- mode p5.
 
 p1 :- p2.
 p2 :- p3.
Index: tests/valid/zero_arity.m
===================================================================
RCS file: /home/staff/zs/imp/tests/valid/zero_arity.m,v
retrieving revision 1.1
diff -u -u -r1.1 zero_arity.m
--- zero_arity.m	1999/08/31 05:26:10	1.1
+++ zero_arity.m	1999/09/17 05:42:16
@@ -6,18 +6,31 @@
 
 :- interface.
 
-:- pred use_asm_labels.
-:- mode use_asm_labels is semidet.
+% bar has one mode, with determinism semidet.
+:- pred bar is semidet.
 
+% baz has one mode, with determinism semidet.
+:- pred baz.
+:- mode baz is semidet.
+
 :- implementation.
+
+:- import_module std_util.
+
+bar :- semidet_fail.
+
+baz :- semidet_fail.
+
+% foo has no modes, or the modes for foo will be inferred.
+:- pred foo.
 
-:- pragma c_code(use_asm_labels, [will_not_call_mercury, thread_safe], "
+% The mode error here should not be detected because this predicate
+% has no modes and is not called, so no modes will be inferred.
+foo :- X = 1, unify(X, _).
 
-#ifdef USE_ASM_LABELS
-	SUCCESS_INDICATOR = TRUE;
-#else
-	SUCCESS_INDICATOR = FALSE;
-#endif
-").
+% quux has one mode, whose determinism will be inferred.
+:- pred quux.
+:- mode quux.
 
+quux :- semidet_fail.
 
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list