[m-rev.] diff: purity warnings test case
Fergus Henderson
fjh at cs.mu.OZ.AU
Wed Jan 22 23:45:43 AEDT 2003
Estimated hours taken: 1
Branches: main
tests/warnings/Mmakefile:
tests/warnings/purity_warnings.m:
tests/warnings/purity_warnings.exp:
Add a test case to test purity warnings.
Workspace: /home/ceres/fjh/ws-ceres2/mercury
Index: tests/warnings/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/warnings/Mmakefile,v
retrieving revision 1.27
diff -u -d -r1.27 Mmakefile
--- tests/warnings/Mmakefile 2 Jan 2003 06:54:01 -0000 1.27
+++ tests/warnings/Mmakefile 22 Jan 2003 12:30:05 -0000
@@ -17,6 +17,7 @@
inference_test \
missing_if \
pragma_source_file \
+ purity_warnings \
simple_code \
singleton_test \
state_vars_test \
@@ -43,8 +44,8 @@
$(ERRORCHECK_PROGS:%=%.runtest): %.runtest: %.res_error ;
- # Build the `.analysis' file for unused_args_analysis2
- # before building unused_args_analysis.c.
+# Build the `.analysis' file for unused_args_analysis2
+# before building unused_args_analysis.c.
$(cs_subdir)unused_args_analysis.c: $(cs_subdir)unused_args_analysis2.c
unused_args_analysis.err: $(cs_subdir)unused_args_analysis2.c
Index: tests/warnings/purity_warnings.exp
===================================================================
RCS file: tests/warnings/purity_warnings.exp
diff -N tests/warnings/purity_warnings.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/warnings/purity_warnings.exp 22 Jan 2003 12:44:10 -0000
@@ -0,0 +1,27 @@
+purity_warnings.m:021: In call to predicate `io.write_string/3':
+purity_warnings.m:021: warning: unnecessary `semipure' indicator.
+purity_warnings.m:021: No purity indicator is necessary.
+purity_warnings.m:022: In call to predicate `io.print/3':
+purity_warnings.m:022: warning: unnecessary `impure' indicator.
+purity_warnings.m:022: No purity indicator is necessary.
+purity_warnings.m:024: In predicate `purity_warnings.impure_pred1/2':
+purity_warnings.m:024: warning: declared `impure' but actually pure.
+purity_warnings.m:028: In predicate `purity_warnings.impure_pred2/2':
+purity_warnings.m:028: warning: declared `impure' but actually semipure.
+purity_warnings.m:036: In call to predicate `io.write_string/3':
+purity_warnings.m:036: warning: unnecessary `semipure' indicator.
+purity_warnings.m:036: No purity indicator is necessary.
+purity_warnings.m:034: In predicate `purity_warnings.semipure_pred/2':
+purity_warnings.m:034: warning: declared `semipure' but actually pure.
+purity_warnings.m:063: In call to predicate `io.print/3':
+purity_warnings.m:063: warning: unnecessary `impure' indicator.
+purity_warnings.m:063: No purity indicator is necessary.
+purity_warnings.m:058: In predicate `purity_warnings.impure_method1a_impl/2':
+purity_warnings.m:058: warning: declared `impure' but actually pure.
+purity_warnings.m:059: In predicate `purity_warnings.impure_method2a_impl/2':
+purity_warnings.m:059: warning: declared `impure' but actually semipure.
+purity_warnings.m:069: In call to predicate `io.print/3':
+purity_warnings.m:069: warning: unnecessary `semipure' indicator.
+purity_warnings.m:069: No purity indicator is necessary.
+purity_warnings.m:060: In predicate `purity_warnings.semipure_method_a_impl/2':
+purity_warnings.m:060: warning: declared `semipure' but actually pure.
Index: tests/warnings/purity_warnings.m
===================================================================
RCS file: tests/warnings/purity_warnings.m
diff -N tests/warnings/purity_warnings.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/warnings/purity_warnings.m 22 Jan 2003 12:42:46 -0000
@@ -0,0 +1,88 @@
+% Various checks that impurity declarations are treated properly.
+
+:- module purity_warnings.
+:- interface.
+:- import_module io.
+:- impure pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+:- import_module int, list, string.
+
+main -->
+ impure impure_pred1,
+ impure impure_pred2,
+ semipure semipure_pred,
+ impure impure_method1a,
+ impure impure_method2a,
+ semipure semipure_method_a,
+ impure impure_method1b,
+ impure impure_method2b,
+ semipure semipure_method_b,
+ semipure io__write_string("main 1\n"),
+ impure io__print("main 2\n").
+
+:- impure pred impure_pred1(io__state::di, io__state::uo) is det.
+impure_pred1 -->
+ io__write_string("impure_pred1\n").
+
+:- impure pred impure_pred2(io__state::di, io__state::uo) is det.
+impure_pred2 -->
+ io__write_string("impure_pred2\n"),
+ { semipure get_x(X) },
+ print("X = "), print(X), nl.
+
+:- semipure pred semipure_pred(io__state::di, io__state::uo) is det.
+semipure_pred -->
+ semipure io__write_string("semipure_pred1\n").
+
+:- typeclass foo(IO) where [
+ (impure pred impure_method1a(IO::di, IO::uo) is det),
+ (impure pred impure_method1b(IO::di, IO::uo) is det),
+ (impure pred impure_method2a(IO::di, IO::uo) is det),
+ (impure pred impure_method2b(IO::di, IO::uo) is det),
+ (semipure pred semipure_method_a(IO::di, IO::uo) is det),
+ (semipure pred semipure_method_b(IO::di, IO::uo) is det)
+].
+:- instance foo(io) where [
+ pred(impure_method1a/2) is impure_method1a_impl,
+ pred(impure_method2a/2 )is impure_method2a_impl,
+ pred(semipure_method_a/2 )is semipure_method_a_impl,
+ (impure_method1b --> print("impure_method1b\n")),
+ (impure_method2b -->
+ io__write_string("impure_method2b\n"),
+ { semipure get_x(X) },
+ print("X = "), print(X), nl),
+ (semipure_method_b --> print("semipure_method_b\n"))
+].
+
+:- impure pred impure_method1a_impl(io::di, io::uo) is det.
+:- impure pred impure_method2a_impl(io::di, io::uo) is det.
+:- semipure pred semipure_method_a_impl(io::di, io::uo) is det.
+
+impure_method1a_impl -->
+ impure print("impure_method1a_impl\n").
+impure_method2a_impl -->
+ io__write_string("impure_method2a_impl\n"),
+ { semipure get_x(X) },
+ print("X = "), print(X), nl.
+semipure_method_a_impl -->
+ semipure print("semipure_method_a_impl\n").
+
+:- pragma c_header_code("extern int x;").
+:- pragma c_code("int x = 0;").
+:- pragma foreign_code("C#", "
+static int x = 0;
+").
+
+:- impure pred set_x(int::in) is det.
+:- pragma c_code(set_x(X::in), will_not_call_mercury, "x=X;" ).
+:- pragma foreign_proc("C#", set_x(X::in), will_not_call_mercury, "x=X;" ).
+
+:- impure pred incr_x is det.
+:- pragma c_code(incr_x, will_not_call_mercury, "++x;" ).
+:- pragma foreign_proc("C#", incr_x, will_not_call_mercury, "++x;" ).
+
+:- semipure pred get_x(int::out) is det.
+:- pragma promise_semipure(get_x/1).
+:- pragma c_code(get_x(X::out), will_not_call_mercury, "X=x;").
+:- pragma foreign_proc("C#", get_x(X::out), will_not_call_mercury, "X=x;").
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | 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