[m-rev.] for review: support different clauses for different modes

Fergus Henderson fjh at cs.mu.OZ.AU
Thu May 17 04:18:38 AEST 2001


On 16-May-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> I'd also like to see a test case in tests/hard_coded where a predicate
> which uses different clauses for different modes is written to a `.opt' file
> then inlined in an importing module. The code in intermod.m to write
> clauses currently doesn't handle this feature.

Good point.  I've written such a test case, and you're quite right,
it doesn't pass if intermodule optmization is enabled.

I think the right place to fix it is in hlds_out__write_clause (which
is called from intermod__write_clause).  But I don't have a fix yet.

Here's a diff for adding the test case.
I'll try to finish this off (by fixing hlds_out.m) tomorrow.

----------

Estimated hours taken: 1
Branches: main

tests/hard_coded/Mmakefile:
tests/hard_coded/intermod_multimode.m:
tests/hard_coded/intermod_multimode_main.m:
tests/hard_coded/intermod_multimode_main.exp:
	Add a multi-module test case for using different clauses
	for different modes.  XXX Currently we don't pass it!

compiler/hlds_out.m:
	Change hlds_out__write_clause so that it outputs the
	mode annotations, if needed.
	XXX FIXME this is not yet done!

Workspace: /mnt/hg/home/hg/fjh/mercury
Index: compiler/hlds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_out.m,v
retrieving revision 1.258
diff -u -d -r1.258 hlds_out.m
--- compiler/hlds_out.m	2001/04/07 14:04:40	1.258
+++ compiler/hlds_out.m	2001/05/16 18:06:53
@@ -955,6 +955,7 @@
 	;
 		[]
 	),
+	% XXX FIXME add mode annotation if needed
 	hlds_out__write_clause_head(ModuleInfo, PredId, VarSet, AppendVarnums,
 		HeadTerms, PredOrFunc),
 	( { Goal = conj([]) - _GoalInfo } ->
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.116
diff -u -d -r1.116 Mmakefile
--- tests/hard_coded/Mmakefile	2001/05/16 17:28:40	1.116
+++ tests/hard_coded/Mmakefile	2001/05/16 17:59:46
@@ -70,6 +70,7 @@
 	impure_prune \
 	integer_test \
 	intermod_c_code \
+	intermod_multimode_main \
 	merge_and_remove_dups \
 	minint_bug \
 	mode_choice \
@@ -124,7 +125,15 @@
 	write_reg1 \
 	write_reg2
 
+# We do not pass the following tests at all:
+#
+# XXX var_not_found -- mode error in automatically generated unification
+#		predicate.  This test uses partially instantiated modes,
+#		which are not yet fully supported.
+#
 # XXX csharp_test doesn't work yet (not even in il* grades)
+
+# The following tests are passed only in some grades:
 #
 # XXX copy_pred does not work in the hl* grades (e.g. hlc.gc),
 # because the MLDS back-end doesn't generate the closure layout
@@ -162,11 +171,6 @@
 else
 SPLIT_PROGS =
 endif
-
-# we do not pass the following tests
-#	var_not_found -- mode error in automatically generated unification
-#		predicate.  This test uses partially instantiated modes,
-#		which are not yet fully support.
 
 #-----------------------------------------------------------------------------#
 
Index: tests/hard_coded/intermod_multimode.m
===================================================================
RCS file: intermod_multimode.m
diff -N intermod_multimode.m
--- /dev/null	Wed Apr 11 00:52:25 2001
+++ intermod_multimode.m	Thu May 17 03:52:24 2001
@@ -0,0 +1,67 @@
+:- module intermod_multimode.
+:- interface.
+
+:- func func0 = string.
+:- mode func0 = out is det.
+	
+:- func func1(int) = string.
+:- mode func1(in) = out is det.
+:- mode func1(out) = out is det.
+
+:- func func2(int, int) = string.
+:- mode func2(in, in) = out is det.
+:- mode func2(in, out) = out is det.
+:- mode func2(out, in) = out is det.
+:- mode func2(out, out) = out is det.
+
+:- impure pred test0.
+:- mode test0 is det.
+
+:- impure pred test1(int).
+:- mode test1(in) is det.
+:- mode test1(out) is det.
+
+:- impure pred test2(int, int).
+:- mode test2(in, in) is det.
+:- mode test2(in, out) is det.
+:- mode test2(out, in) is det.
+:- mode test2(out, out) is det.
+
+:- impure pred puts(string::in) is det.
+
+:- implementation.
+
+func0 = ("func0 = out" :: out).
+
+:- pragma promise_pure(func1/1). % XXX technically this is a lie
+func1(_::in) = ("func1(in) = out"::out).
+func1(0::out) = ("func1(out) = out"::out).
+
+:- pragma promise_pure(func2/2). % XXX technically this is a lie
+func2(_::in, _::in) = (R::out) :-
+	R = "func2(in, in) = out".
+func2(_::in, 0::out) = (R::out) :-
+	R = "func2(in, out) = out".
+func2(0::out, _::in) = (R::out) :-
+	R = "func2(out, in) = out".
+func2(0::out, 0::out) = (R::out) :-
+	R = "func2(out, out) = out".
+
+test0 :-
+	impure puts("test0").
+	
+test1(_::in) :-
+	impure puts("test1(in)").
+test1(0::out) :-
+	impure puts("test1(out)").
+
+test2(_::in, _::in) :-
+	impure puts("test2(in, in)").
+test2(_::in, 0::out) :-
+	impure puts("test2(in, out)").
+test2(0::out, _::in) :-
+	impure puts("test2(out, in)").
+test2(0::out, 0::out) :-
+	impure puts("test2(out, out)").
+
+:- pragma c_code(puts(S::in), [will_not_call_mercury], "puts(S)").
Index: tests/hard_coded/intermod_multimode_main.exp
===================================================================
RCS file: intermod_multimode_main.exp
diff -N intermod_multimode_main.exp
--- /dev/null	Wed Apr 11 00:52:25 2001
+++ intermod_multimode_main.exp	Thu May 17 03:55:32 2001
@@ -0,0 +1,14 @@
+func0 = out
+func1(in) = out
+func1(out) = out
+func2(in, in) = out
+func2(in, out) = out
+func2(out, in) = out
+func2(out, out) = out
+test0
+test1(in)
+test1(out)
+test2(in, in)
+test2(in, out)
+test2(out, in)
+test2(out, out)
Index: tests/hard_coded/intermod_multimode_main.m
===================================================================
RCS file: intermod_multimode_main.m
diff -N intermod_multimode_main.m
--- /dev/null	Wed Apr 11 00:52:25 2001
+++ intermod_multimode_main.m	Thu May 17 03:52:58 2001
@@ -0,0 +1,35 @@
+:- module intermod_multimode_main.
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+:- import_module intermod_multimode.
+
+:- pragma promise_pure(main/2).
+main -->
+	{ In = 42 },
+	{ In2 = In },		% this line (and the use of `In2' below,
+				% rather than `In') is needed to avoid
+				% triggering an unrelated bug -- see
+				% tests/valid/mode_selection.m.
+
+	% test pure functions
+	print(func0), nl,
+	print(func1(In)), nl,
+	print(func1(_Out0)), nl,
+	print(func2(In, In2)), nl,
+	print(func2(In, _Out1)), nl,
+	print(func2(_Out2, In)), nl,
+	print(func2(_Out3, _Out4)), nl,
+
+	% test impure predicates
+	{ impure test0 },
+	{ impure test1(In) },
+	{ impure test1(_Out10) },
+	{ impure test2(In, In) },
+	{ impure test2(In, _Out11) },
+	{ impure test2(_Out12, In) },
+	{ impure test2(_Out13, _Out14) }.
+

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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