[m-rev.] for review: test cases for clause mode annotations

Fergus Henderson fjh at cs.mu.OZ.AU
Thu May 17 01:17:42 AEST 2001


This addresses Simon Taylor's review comment on my earlier change,
namely the lack of test cases.

Estimated hours taken: 2
Branches: main

tests/hard_coded/Mmakefile:
tests/hard_coded/multimode.m:
tests/hard_coded/multimode.exp:
tests/invalid/Mmakefile:
tests/invalid/multimode_missing_impure.m:
tests/invalid/multimode_missing_impure.err_exp:
tests/invalid/multimode_dcg.m:
tests/invalid/multimode_dcg.err_exp:
tests/invalid/multimode_syntax.m:
tests/invalid/multimode_syntax.err_exp:
	Add some test cases for my recent change to add support
	using different clauses for different modes.

Workspace: /home/mars/fjh/ws1/mercury
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.115
diff -u -d -r1.115 Mmakefile
--- tests/hard_coded/Mmakefile	2001/05/15 07:12:04	1.115
+++ tests/hard_coded/Mmakefile	2001/05/16 13:41:54
@@ -73,6 +73,7 @@
 	merge_and_remove_dups \
 	minint_bug \
 	mode_choice \
+	multimode \
 	myset_test \
 	name_mangling \
 	no_fully_strict \
Index: tests/hard_coded/multimode.exp
===================================================================
RCS file: multimode.exp
diff -N multimode.exp
--- /dev/null	Wed Apr 11 00:52:25 2001
+++ multimode.exp	Wed May 16 23:41:23 2001
@@ -0,0 +1,13 @@
+func0 = out
+func1(in) = out
+func1(out) = 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/multimode.m
===================================================================
RCS file: multimode.m
diff -N multimode.m
--- /dev/null	Wed Apr 11 00:52:25 2001
+++ multimode.m	Wed May 16 23:42:41 2001
@@ -0,0 +1,85 @@
+:- module multimode.
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+:- pragma promise_pure(main/2).
+main -->
+	{ In = 42 },
+
+	% test pure functions
+	print(func0), nl,
+	print(func1(In)), nl,
+	print(func1(_Out0)), nl,
+	%print(func2(In, In)), 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) }.
+
+:- func func0 = string.
+:- mode func0 = out is det.
+func0 = ("func0 = out" :: out).
+	
+:- pragma promise_pure(func1/1). % XXX technically this is a lie
+:- func func1(int) = string.
+:- mode func1(in) = out is det.
+:- mode func1(out) = out is det.
+func1(_::in) = ("func1(in) = out"::out).
+func1(0::out) = ("func1(out) = out"::out).
+
+:- pragma promise_pure(func2/2). % XXX technically this is a lie
+:- 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.
+%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".
+
+:- impure pred test0.
+:- mode test0 is det.
+test0 :-
+	impure puts("test0").
+	
+:- impure pred test1(int).
+:- mode test1(in) is det.
+:- mode test1(out) is det.
+test1(_::in) :-
+	impure puts("test1(in)").
+test1(0::out) :-
+	impure puts("test1(out)").
+
+:- 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.
+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)").
+
+:- impure pred puts(string::in) is det.
+:- pragma c_code(puts(S::in), [will_not_call_mercury], "puts(S)").
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.84
diff -u -d -r1.84 Mmakefile
--- tests/invalid/Mmakefile	2001/05/07 06:11:47	1.84
+++ tests/invalid/Mmakefile	2001/05/16 13:55:19
@@ -59,6 +59,9 @@
 	modes_erroneous.m \
 	mostly_uniq1.m \
 	mostly_uniq2.m \
+	multimode_missing_impure.m \
+	multimode_dcg.m \
+	multimode_syntax.m \
 	multisoln_func.m \
 	nested_impl_in_int.m \
 	no_exports.m \
Index: tests/invalid/multimode_dcg.err_exp
===================================================================
RCS file: multimode_dcg.err_exp
diff -N multimode_dcg.err_exp
--- /dev/null	Wed Apr 11 00:52:25 2001
+++ multimode_dcg.err_exp	Wed May 16 23:50:56 2001
@@ -0,0 +1,26 @@
+multimode_dcg.m:027: In clause for predicate `multimode_dcg:test1/3':
+multimode_dcg.m:027:   syntax error: some but not all arguments have mode annotations.
+multimode_dcg.m:029: In clause for predicate `multimode_dcg:test1/3':
+multimode_dcg.m:029:   syntax error: some but not all arguments have mode annotations.
+multimode_dcg.m:037: In clause for predicate `multimode_dcg:test2/4':
+multimode_dcg.m:037:   syntax error: some but not all arguments have mode annotations.
+multimode_dcg.m:039: In clause for predicate `multimode_dcg:test2/4':
+multimode_dcg.m:039:   syntax error: some but not all arguments have mode annotations.
+multimode_dcg.m:041: In clause for predicate `multimode_dcg:test2/4':
+multimode_dcg.m:041:   syntax error: some but not all arguments have mode annotations.
+multimode_dcg.m:043: In clause for predicate `multimode_dcg:test2/4':
+multimode_dcg.m:043:   syntax error: some but not all arguments have mode annotations.
+multimode_dcg.m:029: In clause for `test1(out, di, uo)':
+multimode_dcg.m:029:   mode mismatch in disjunction.
+multimode_dcg.m:029:   `HeadVar__1' :: free, unique(0).
+multimode_dcg.m:043: In clause for `test2(in, out, di, uo)':
+multimode_dcg.m:043:   mode mismatch in disjunction.
+multimode_dcg.m:043:   `HeadVar__2' :: free, unique(0), free, unique(0).
+multimode_dcg.m:043: In clause for `test2(out, in, di, uo)':
+multimode_dcg.m:043:   mode mismatch in disjunction.
+multimode_dcg.m:043:   `HeadVar__1' :: free, free, unique(0), unique(0).
+multimode_dcg.m:043: In clause for `test2(out, out, di, uo)':
+multimode_dcg.m:043:   mode mismatch in disjunction.
+multimode_dcg.m:043:   `HeadVar__1' :: free, free, unique(0), unique(0).
+multimode_dcg.m:043:   `HeadVar__2' :: free, unique(0), free, unique(0).
+For more information, try recompiling with `-E'.
Index: tests/invalid/multimode_dcg.m
===================================================================
RCS file: multimode_dcg.m
diff -N multimode_dcg.m
--- /dev/null	Wed Apr 11 00:52:25 2001
+++ multimode_dcg.m	Wed May 16 23:48:05 2001
@@ -0,0 +1,48 @@
+:- module multimode_dcg.
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+main -->
+	{ In = 42 },
+	test0,
+	test1(In),
+	test1(_Out0),
+	test2(In, In),
+	test2(In, _Out1),
+	test2(_Out2, In),
+	test2(_Out3, _Out4).
+
+:- pred test0(io__state, io__state).
+:- mode test0(di, uo) is det.
+test0 -->
+	puts("test0").
+	
+:- pred test1(int, io__state, io__state).
+:- mode test1(in, di, uo) is det.
+:- mode test1(out, di, uo) is det.
+test1(_::in) -->
+	puts("test1(in)").
+test1(0::out) -->
+	puts("test1(out)").
+
+:- pred test2(int, int, io__state, io__state).
+:- mode test2(in, in, di, uo) is det.
+:- mode test2(in, out, di, uo) is det.
+:- mode test2(out, in, di, uo) is det.
+:- mode test2(out, out, di, uo) is det.
+test2(_::in, _::in) -->
+	puts("test2(in, in)").
+test2(_::in, 0::out) -->
+	puts("test2(in, out)").
+test2(0::out, _::in) -->
+	puts("test2(out, in)").
+test2(0::out, 0::out) -->
+	puts("test2(out, out)").
+
+:- pred puts(string::in, io__state::di, io__state::uo) is det.
+puts(S) -->
+	io__write_string(S), nl.
Index: tests/invalid/multimode_missing_impure.err_exp
===================================================================
RCS file: multimode_missing_impure.err_exp
diff -N multimode_missing_impure.err_exp
--- /dev/null	Wed Apr 11 00:52:25 2001
+++ multimode_missing_impure.err_exp	Wed May 16 23:46:24 2001
@@ -0,0 +1,7 @@
+multimode_missing_impure.m:025: In predicate `multimode_missing_impure:test1/1':
+multimode_missing_impure.m:025:   purity error: predicate is impure.
+multimode_missing_impure.m:025:   It must be declared `impure' or promised pure.
+multimode_missing_impure.m:034: In predicate `multimode_missing_impure:test2/2':
+multimode_missing_impure.m:034:   purity error: predicate is impure.
+multimode_missing_impure.m:034:   It must be declared `impure' or promised pure.
+For more information, try recompiling with `-E'.
Index: tests/invalid/multimode_missing_impure.m
===================================================================
RCS file: multimode_missing_impure.m
diff -N multimode_missing_impure.m
--- /dev/null	Wed Apr 11 00:52:25 2001
+++ multimode_missing_impure.m	Wed May 16 23:45:26 2001
@@ -0,0 +1,49 @@
+:- module multimode_missing_impure.
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+main -->
+	{ In = 42 },
+	{ test0 },
+	{ test1(In) },
+	{ test1(_Out0) },
+	{ test2(In, In) },
+	{ test2(In, _Out1) },
+	{ test2(_Out2, In) },
+	{ test2(_Out3, _Out4) }.
+
+:- pred test0.
+:- mode test0 is det.
+test0 :-
+	puts("test0").
+	
+% This should be declared impure, or promise pure
+:- pred test1(int).
+:- mode test1(in) is det.
+:- mode test1(out) is det.
+test1(_::in) :-
+	puts("test1(in)").
+test1(0::out) :-
+	puts("test1(out)").
+
+% This should be declared impure, or promise pure
+:- 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.
+test2(_::in, _::in) :-
+	puts("test2(in, in)").
+test2(_::in, 0::out) :-
+	puts("test2(in, out)").
+test2(0::out, _::in) :-
+	puts("test2(out, in)").
+test2(0::out, 0::out) :-
+	puts("test2(out, out)").
+
+:- pred puts(string::in) is det.
+:- pragma c_code(puts(S::in), [will_not_call_mercury], "puts(S)").
Index: tests/invalid/multimode_syntax.err_exp
===================================================================
RCS file: multimode_syntax.err_exp
diff -N multimode_syntax.err_exp
--- /dev/null	Wed Apr 11 00:52:25 2001
+++ multimode_syntax.err_exp	Thu May 17 01:14:24 2001
@@ -0,0 +1,41 @@
+multimode_syntax.m:013: Error: clause for predicate `multimode_syntax:::/2'
+multimode_syntax.m:013:   without preceding `pred' declaration.
+multimode_syntax.m:018: In clause for function `multimode_syntax:func1/1':
+multimode_syntax.m:018:   syntax error: some but not all arguments have mode annotations.
+multimode_syntax.m:019: In clause for function `multimode_syntax:func1/1':
+multimode_syntax.m:019:   syntax error: some but not all arguments have mode annotations.
+multimode_syntax.m:025: In clause for function `multimode_syntax:func2/2':
+multimode_syntax.m:025:   error: mode annotation specifies undeclared mode
+multimode_syntax.m:025:   `func2(in, out) = out'
+multimode_syntax.m:025:   of function `multimode_syntax:func2/2'.
+multimode_syntax.m:027: In clause for function `multimode_syntax:func2/2':
+multimode_syntax.m:027:   error: mode annotation specifies undeclared mode
+multimode_syntax.m:027:   `func2(out, in) = out'
+multimode_syntax.m:027:   of function `multimode_syntax:func2/2'.
+multimode_syntax.m:029: In clause for function `multimode_syntax:func2/2':
+multimode_syntax.m:029:   error: mode annotation specifies undeclared mode
+multimode_syntax.m:029:   `func2(out, out) = out'
+multimode_syntax.m:029:   of function `multimode_syntax:func2/2'.
+multimode_syntax.m:033: In clause for function `multimode_syntax:func2b/2':
+multimode_syntax.m:033:   error: mode annotation specifies undeclared mode
+multimode_syntax.m:033:   `func2b(in, out) = out'
+multimode_syntax.m:033:   of function `multimode_syntax:func2b/2'.
+multimode_syntax.m:037: In clause for predicate `multimode_syntax:pred2b/2':
+multimode_syntax.m:037:   error: mode annotation specifies undeclared mode
+multimode_syntax.m:037:   `pred2b(in, out)'
+multimode_syntax.m:037:   of predicate `multimode_syntax:pred2b/2'.
+multimode_syntax.m:037:   (There are no declared modes for this predicate.)
+multimode_syntax.m:045: In clause for predicate `multimode_syntax:test2/2':
+multimode_syntax.m:045:   syntax error: some but not all arguments have mode annotations.
+multimode_syntax.m:047: In clause for predicate `multimode_syntax:test2/2':
+multimode_syntax.m:047:   syntax error: some but not all arguments have mode annotations.
+multimode_syntax.m:011: Error: no clauses for
+multimode_syntax.m:011:   function `multimode_syntax:func0/0'.
+multimode_syntax.m:013: In clause for predicate `multimode_syntax:::/2':
+multimode_syntax.m:013:   in argument 1 of clause head:
+multimode_syntax.m:013:   error: the language construct =/2 should be
+multimode_syntax.m:013:   used as a goal, not as an expression.
+multimode_syntax.m:013: In clause for predicate `multimode_syntax:::/2':
+multimode_syntax.m:013:   in argument 2 of clause head:
+multimode_syntax.m:013:   error: undefined symbol `out/0'.
+For more information, try recompiling with `-E'.
Index: tests/invalid/multimode_syntax.m
===================================================================
RCS file: multimode_syntax.m
diff -N multimode_syntax.m
--- /dev/null	Wed Apr 11 00:52:25 2001
+++ multimode_syntax.m	Thu May 17 01:14:16 2001
@@ -0,0 +1,55 @@
+:- module multimode_syntax.
+:- interface.
+:- import_module io.
+
+:- pred main(state::di, state::uo) is det.
+
+:- implementation.
+
+main --> [].
+
+:- func func0 = string.
+:- mode func0 = out is det.
+func0 = "func0 = out" :: out. % missing parentheses
+	
+:- func func1(int) = string.
+:- mode func1(in) = out is det.
+:- mode func1(out) = out is det.
+func1(_::in) = "func1(in) = out".  % missing mode annotation on return value
+func1(0) = ("func1(out) = out" :: out). % missing mode annotation on argument
+
+:- func func2(int, int) = string.
+:- mode func2(in, in) = out is det.
+func2(_::in, _::in) = (R::out) :-
+	R = "func2(in, in) = out".
+func2(_::in, 0::out) = (R::out) :-	% reference to undeclared mode
+	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".
+
+:- func func2b(int, int) = string.
+func2b(_::in, _::out) = (R::out) :-	% another reference to undeclared mode
+	R = "func3(in, out) = out".
+
+:- impure pred pred2b(int, int).
+pred2b(_::in, 0::out) :-		% another reference to undeclared mode
+	impure puts("func3(in, out) = out").
+
+:- 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.
+test2(_::in, _) :-			% missing mode annotation on 2nd arg
+	impure puts("test2(in, in)").
+test2(_, 0::out) :-			% missing mode annotation on 1st arg
+	impure puts("test2(in, out)").
+test2(0::out, _::in) :-
+	impure puts("test2(out, in)").
+test2(0::out, 0::out) :-
+	impure puts("test2(out, out)").
+
+:- impure pred puts(string::in) is det.
+:- pragma c_code(puts(S::in), [will_not_call_mercury], "puts(S)").

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