[m-rev.] for review: make the I/O globals field non-unique
Julien Fischer
juliensf at csse.unimelb.edu.au
Fri Feb 9 17:33:22 AEDT 2007
(This will probably conflict with Peter's change for parallel mmc --make.)
Estimated hours taken: 0.5
Branches: main
Make the globals field in the I/O state non-unique. There is an obvious
flaw in the unique version in that you can obtain multiple references
to a unique object just by calling the get_globals/3 predicate multiple
times. Also, the uniqueness aspect is rarely ever useful; most code that
uses globals field just ends up call unsafe_promise_unique/2.
library/io.m:
Make the globals field in the I/O state non-unique.
NEWS:
Mention this change and also the addition of io.update_globals/3.
compiler/globals.m:
extras/graphics/samples/maze/globals.m:
tests/hard_coded/io_globals_deadlock.m:
Conform to the above change.
Julien.
Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.442
diff -u -r1.442 NEWS
--- NEWS 5 Feb 2007 03:12:50 -0000 1.442
+++ NEWS 9 Feb 2007 06:26:09 -0000
@@ -19,6 +19,12 @@
Changes to the Mercury standard library:
+* The globals field in the I/O state is no longer unique. The modes of
+ the access predicates, io.set_globals/3, io.get_global have been changed
+ accordingly. We have also added a new predicate, io.update_globals/3
+ that allows for atomic updates of the globals field in grades that
+ support concurrent execution.
+
* We have moved some of the concurrency primitives out of the extras
distribution and into a new standard library module called `thread',
and its submodules `thread.channel', `thread.mvar', and `thread.semaphore'.
Index: compiler/globals.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/globals.m,v
retrieving revision 1.79
diff -u -r1.79 globals.m
--- compiler/globals.m 8 Jan 2007 03:03:09 -0000 1.79
+++ compiler/globals.m 9 Feb 2007 06:26:09 -0000
@@ -233,7 +233,7 @@
:- pred io_get_globals(globals::out, io::di, io::uo) is det.
-:- pred io_set_globals(globals::di, io::di, io::uo) is det.
+:- pred io_set_globals(globals::in, io::di, io::uo) is det.
:- pred io_set_option(option::in, option_data::in, io::di, io::uo) is det.
@@ -591,34 +591,22 @@
io_get_globals(Globals0, !IO),
get_options(Globals0, OptionTable0),
map.set(OptionTable0, Option, OptionData, OptionTable),
- set_options(OptionTable, Globals0, Globals1),
- % XXX there is a bit of a design flaw with regard to
- % uniqueness and io.set_globals
- unsafe_promise_unique(Globals1, Globals),
+ set_options(OptionTable, Globals0, Globals),
io_set_globals(Globals, !IO).
io_set_gc_method(GC_Method, !IO) :-
io_get_globals(Globals0, !IO),
- set_gc_method(GC_Method, Globals0, Globals1),
- unsafe_promise_unique(Globals1, Globals),
- % XXX there is a bit of a design flaw with regard to
- % uniqueness and io.set_globals
+ set_gc_method(GC_Method, Globals0, Globals),
io_set_globals(Globals, !IO).
io_set_tags_method(Tags_Method, !IO) :-
io_get_globals(Globals0, !IO),
- set_tags_method(Tags_Method, Globals0, Globals1),
- unsafe_promise_unique(Globals1, Globals),
- % XXX there is a bit of a design flaw with regard to
- % uniqueness and io.set_globals
+ set_tags_method(Tags_Method, Globals0, Globals),
io_set_globals(Globals, !IO).
io_set_trace_level(TraceLevel, !IO) :-
io_get_globals(Globals0, !IO),
- set_trace_level(TraceLevel, Globals0, Globals1),
- unsafe_promise_unique(Globals1, Globals),
- % XXX there is a bit of a design flaw with regard to
- % uniqueness and io.set_globals
+ set_trace_level(TraceLevel, Globals0, Globals),
io_set_globals(Globals, !IO).
io_set_extra_error_info(ExtraErrorInfo, !IO) :-
@@ -669,10 +657,7 @@
io_printing_usage(AlreadyPrinted, !IO) :-
io_get_globals(Globals0, !IO),
AlreadyPrinted = Globals0 ^ have_printed_usage,
- Globals1 = Globals0 ^ have_printed_usage := yes,
- unsafe_promise_unique(Globals1, Globals),
- % XXX there is a bit of a design flaw with regard to
- % uniqueness and io.set_globals
+ Globals = Globals0 ^ have_printed_usage := yes,
io_set_globals(Globals, !IO).
%-----------------------------------------------------------------------------%
Index: extras/graphics/samples/maze/globals.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/graphics/samples/maze/globals.m,v
retrieving revision 1.6
diff -u -r1.6 globals.m
--- extras/graphics/samples/maze/globals.m 30 Mar 2006 02:52:45 -0000 1.6
+++ extras/graphics/samples/maze/globals.m 9 Feb 2007 06:26:09 -0000
@@ -62,8 +62,7 @@
then
type_to_univ(Value, UValue),
map.set(Map0, Name, UValue, Map),
- type_to_univ(Map, UMap1),
- unsafe_promise_unique(UMap1, UMap),
+ type_to_univ(Map, UMap),
io.set_globals(UMap, !IO)
else
error("globals.set/4: global store corrupt.")
Index: library/io.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.368
diff -u -r1.368 io.m
--- library/io.m 18 Jan 2007 07:33:03 -0000 1.368
+++ library/io.m 9 Feb 2007 06:26:09 -0000
@@ -1130,8 +1130,8 @@
%
% Does not modify the I/O state.
%
-:- pred io.get_globals(univ::uo, io::di, io::uo) is det.
-:- pred io.set_globals(univ::di, io::di, io::uo) is det.
+:- pred io.get_globals(univ::out, io::di, io::uo) is det.
+:- pred io.set_globals(univ::in, io::di, io::uo) is det.
% io.update_globals(UpdatePred, !IO).
% Update the `globals' field in the I/O state based upon its current
@@ -1145,7 +1145,7 @@
% If `UpdatePred' throws an exception then the `globals' field is
% left unchanged.
%
-:- pred io.update_globals(pred(univ, univ)::in(pred(di, uo) is det),
+:- pred io.update_globals(pred(univ, univ)::in(pred(in, out) is det),
io::di, io::uo) is det.
% The following predicates provide an interface to the environment list.
@@ -4413,12 +4413,11 @@
io.unsafe_get_globals(Globals0, !IO),
promise_equivalent_solutions [!:IO] (
Update = (pred(G::out) is det :-
- UpdatePred(unsafe_promise_unique(Globals0), G)
+ UpdatePred(Globals0, G)
),
try(Update, UpdateResult),
(
- UpdateResult = succeeded(Globals1),
- Globals = unsafe_promise_unique(Globals1),
+ UpdateResult = succeeded(Globals),
io.unsafe_set_globals(Globals, !IO),
io.unlock_globals(!IO)
;
@@ -4484,9 +4483,9 @@
% predicates should be surrounded by calls to io.{lock, unlock}_globals/2
% this is safe.
%
-:- pred io.unsafe_get_globals(univ::uo, io::di, io::uo) is det.
+:- pred io.unsafe_get_globals(univ::out, io::di, io::uo) is det.
:- pragma foreign_proc("C",
- io.unsafe_get_globals(Globals::uo, IO0::di, IO::uo),
+ io.unsafe_get_globals(Globals::out, IO0::di, IO::uo),
[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe,
does_not_affect_liveness],
"
@@ -4494,9 +4493,9 @@
MR_update_io(IO0, IO);
").
-:- pred io.unsafe_set_globals(univ::di, io::di, io::uo) is det.
+:- pred io.unsafe_set_globals(univ::in, io::di, io::uo) is det.
:- pragma foreign_proc("C",
- io.unsafe_set_globals(Globals::di, IO0::di, IO::uo),
+ io.unsafe_set_globals(Globals::in, IO0::di, IO::uo),
[will_not_call_mercury, promise_pure, tabled_for_io, thread_safe,
does_not_affect_liveness],
"
@@ -4506,28 +4505,28 @@
").
:- pragma foreign_proc("C#",
- io.unsafe_get_globals(Globals::uo, _IOState0::di, _IOState::uo),
+ io.unsafe_get_globals(Globals::out, _IOState0::di, _IOState::uo),
[will_not_call_mercury, promise_pure, tabled_for_io],
"
Globals = ML_io_user_globals;
").
:- pragma foreign_proc("C#",
- io.unsafe_set_globals(Globals::di, _IOState0::di, _IOState::uo),
+ io.unsafe_set_globals(Globals::in, _IOState0::di, _IOState::uo),
[will_not_call_mercury, promise_pure, tabled_for_io],
"
ML_io_user_globals = Globals;
").
:- pragma foreign_proc("Java",
- io.unsafe_get_globals(Globals::uo, _IOState0::di, _IOState::uo),
+ io.unsafe_get_globals(Globals::out, _IOState0::di, _IOState::uo),
[will_not_call_mercury, promise_pure, tabled_for_io],
"
Globals = ML_io_user_globals;
").
:- pragma foreign_proc("Java",
- io.unsafe_set_globals(Globals::di, _IOState0::di, _IOState::uo),
+ io.unsafe_set_globals(Globals::in, _IOState0::di, _IOState::uo),
[will_not_call_mercury, promise_pure, tabled_for_io],
"
ML_io_user_globals = Globals;
Index: tests/hard_coded/io_globals_deadlock.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/io_globals_deadlock.m,v
retrieving revision 1.1
diff -u -r1.1 io_globals_deadlock.m
--- tests/hard_coded/io_globals_deadlock.m 31 Aug 2006 04:12:21 -0000 1.1
+++ tests/hard_coded/io_globals_deadlock.m 9 Feb 2007 06:26:09 -0000
@@ -46,7 +46,7 @@
update_pred_1(unit, !IO) :-
io.update_globals(update_1, !IO).
-:- pred update_1(univ::di, univ::uo) is det.
+:- pred update_1(univ::in, univ::out) is det.
update_1(!Univ) :-
( univ_to_type(!.Univ, N) ->
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list