[m-rev.] trivial diff: fix failure of hard_coded/sub-modules/mutable_parent

Julien Fischer juliensf at cs.mu.OZ.AU
Tue Feb 21 16:46:09 AEDT 2006


Estimated hours taken: 0.5
Branches: main

Fix the failure of tests/hard_coded/sub-modules/mutable_parent on hosts that
compile with --intermodule-optimization.  The problem is that the current
version of simplify now has enough information with --intermodule-optimization
to realise that it can optimize some of the promise_pure scopes containing
impure set predicates.  The solution is to attach all of the mutables to the
I/O state and thread that through all the calls to the access predicates.

tests/hard_coded/sub-modules/mutable_parent.m:
tests/hard_coded/sub-modules/mutable_child.m:
tests/hard_coded/sub-modules/mutable_grandchild.m:
	Attach the mutables to the I/O state and use the pure versions of the
	access predicates in order to prevent the compiler optimising away
	calls to the impure set predicates that occur inside promise_pure
	scopes.

Julien.

Index: mutable_child.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/sub-modules/mutable_child.m,v
retrieving revision 1.1
diff -u -r1.1 mutable_child.m
--- mutable_child.m	15 Sep 2005 07:38:46 -0000	1.1
+++ mutable_child.m	21 Feb 2006 05:37:28 -0000
@@ -8,17 +8,14 @@

 :- implementation.

-:- mutable(child_global, int, 200, ground, [untrailed, thread_safe]).
+:- mutable(child_global, int, 200, ground,
+	[untrailed, thread_safe, attach_to_io_state]).

 run_child(!IO) :-
 	io.write_string("In child ...\n", !IO),
-	promise_pure (
-		semipure get_parent_global(ParentGlobal),
-		semipure get_child_global(ChildGlobal)
-	),
+	get_parent_global(ParentGlobal, !IO),
+	get_child_global(ChildGlobal, !IO),
 	io.format("    parent_global = %d\n", [i(ParentGlobal)], !IO),
 	io.format("    child_global  = %d\n", [i(ChildGlobal)], !IO),
-	promise_pure (
-		impure set_parent_global(ParentGlobal + 1),
-		impure set_child_global(ChildGlobal + 1)
-	).
+	set_parent_global(ParentGlobal + 1, !IO),
+	set_child_global(ChildGlobal + 1, !IO).
Index: mutable_grandchild.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/sub-modules/mutable_grandchild.m,v
retrieving revision 1.1
diff -u -r1.1 mutable_grandchild.m
--- mutable_grandchild.m	15 Sep 2005 07:38:46 -0000	1.1
+++ mutable_grandchild.m	21 Feb 2006 05:37:39 -0000
@@ -6,18 +6,15 @@

 :- implementation.

-:- mutable(grandchild_global, int, 300, ground, [untrailed, thread_safe]).
+:- mutable(grandchild_global, int, 300, ground,
+	[untrailed, thread_safe, attach_to_io_state]).

 run_grandchild(!IO) :-
 	io.write_string("In grandchild ...\n", !IO),
-	promise_pure (
-		semipure get_parent_global(ParentGlobal),
-		semipure get_child_global(ChildGlobal),
-		semipure get_grandchild_global(GrandChildGlobal)
-	),
+	get_parent_global(ParentGlobal, !IO),
+	get_child_global(ChildGlobal, !IO),
+	get_grandchild_global(GrandChildGlobal, !IO),
 	io.format("    parent_global      = %d\n", [i(ParentGlobal)], !IO),
 	io.format("    child_global       = %d\n", [i(ChildGlobal)], !IO),
 	io.format("    grandchild_global  = %d\n", [i(GrandChildGlobal)], !IO),
-	promise_pure (
-		impure set_parent_global(ParentGlobal + 1)
-	).
+	set_parent_global(ParentGlobal + 1, !IO).
Index: mutable_parent.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/sub-modules/mutable_parent.m,v
retrieving revision 1.1
diff -u -r1.1 mutable_parent.m
--- mutable_parent.m	15 Sep 2005 07:38:46 -0000	1.1
+++ mutable_parent.m	21 Feb 2006 05:38:08 -0000
@@ -17,26 +17,21 @@
 :- import_module mutable_parent.mutable_child.
 :- import_module mutable_parent.mutable_child.mutable_grandchild.

-:- mutable(parent_global, int, 100, ground, [untrailed, thread_safe]).
+:- mutable(parent_global, int, 100, ground,
+	[untrailed, thread_safe, attach_to_io_state]).

 main(!IO) :-
 	mutable_parent.run_parent(!IO),
 	mutable_parent.mutable_child.run_child(!IO),
 	mutable_parent.mutable_child.mutable_grandchild.run_grandchild(!IO),
 	io.write_string("Back in parent ...\n", !IO),
-	promise_pure (
-		semipure get_parent_global(ParentGlobal)
-	),
+	get_parent_global(ParentGlobal, !IO),
 	io.format("    parent_global = %d\n", [i(ParentGlobal)], !IO).

 :- pred run_parent(io::di, io::uo) is det.

 run_parent(!IO) :-
 	io.write_string("In parent ...\n", !IO),
-	promise_pure (
-		semipure get_parent_global(X)
-	),
+	get_parent_global(X, !IO),
 	io.format("    parent_global = %d\n", [i(X)], !IO),
-	promise_pure (
-		impure set_parent_global(X + 1)
-	).
+	set_parent_global(X + 1, !IO).

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