diff: fix var.m mode errors (`any' inst in higher-order term)
Fergus Henderson
fjh at cs.mu.OZ.AU
Sun Feb 15 02:05:50 AEDT 1998
extras/trailed_update/var.m:
Avoid mode errors in debug_freeze/{3,4} which were caused by the use
of a variable of inst `any' as the curried argument in a higher-order
term. The fix was to replace `unsafe_perform_io(dump_var(Var))'
with `unsafe_dump_var(Var)' where unsafe_dump_var/1 is a new impure
version of dump_var/3.
(The mode errors were detected as a result of Andrew Bromage's
recent change to fix mode checking for lambda expressions.
In this particular case, as it happens, there is no genuine error,
becaused dump_var/1 does not instantiate its argument.
However, there's no way for the mode checker to know that,
so it is correct to report an error.)
Index: var.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/trailed_update/var.m,v
retrieving revision 1.9
diff -u -u -r1.9 var.m
--- var.m 1997/12/11 21:23:27 1.9
+++ var.m 1998/02/14 14:56:01
@@ -97,6 +97,9 @@
% dump_var prints out a representation of a variable.
:- pred dump_var(var(T)::in(any), io__state::di, io__state::uo) is cc_multi.
+ % unsafe_dump_var/1: an impure version of dump_var/3.
+:- impure pred unsafe_dump_var(var(T)::in(any)) is det.
+
% var__is_ground/2 can be used to test if a variable is ground.
%
% Declaratively, is_ground(Var, Result) is true iff
@@ -922,7 +925,7 @@
impure unsafe_perform_io(print("freezing: ")),
impure unsafe_perform_io(print(Msg)),
impure unsafe_perform_io(print(": ")),
- impure unsafe_perform_io(dump_var(Var)),
+ impure unsafe_dump_var(Var),
impure unsafe_perform_io(nl),
freeze(Var, debug_pred(Msg, Pred)),
@@ -930,13 +933,13 @@
impure unsafe_perform_io(print("frozen: ")),
impure unsafe_perform_io(print(Msg)),
impure unsafe_perform_io(print(": ")),
- impure unsafe_perform_io(dump_var(Var)),
+ impure unsafe_dump_var(Var),
impure unsafe_perform_io(nl)
;
impure unsafe_perform_io(print("freeze failed: ")),
impure unsafe_perform_io(print(Msg)),
impure unsafe_perform_io(print(": ")),
- impure unsafe_perform_io(dump_var(Var)),
+ impure unsafe_dump_var(Var),
impure unsafe_perform_io(nl),
fail
).
@@ -949,7 +952,7 @@
impure unsafe_perform_io(print("freezing: ")),
impure unsafe_perform_io(print(Msg)),
impure unsafe_perform_io(print(": ")),
- impure unsafe_perform_io(dump_var(X)),
+ impure unsafe_dump_var(X),
impure unsafe_perform_io(nl),
freeze(X, debug_pred2(Msg, Pred), Y),
@@ -957,13 +960,13 @@
impure unsafe_perform_io(print("frozen: ")),
impure unsafe_perform_io(print(Msg)),
impure unsafe_perform_io(print(": ")),
- impure unsafe_perform_io(dump_var(X)),
+ impure unsafe_dump_var(X),
impure unsafe_perform_io(nl)
;
impure unsafe_perform_io(print("freeze failed: ")),
impure unsafe_perform_io(print(Msg)),
impure unsafe_perform_io(print(": ")),
- impure unsafe_perform_io(dump_var(X)),
+ impure unsafe_dump_var(X),
impure unsafe_perform_io(nl),
fail
).
@@ -1021,6 +1024,10 @@
:- pragma c_code(dump_var(Var::in(any), IO0::di, IO::uo), may_call_mercury, "
ML_var_print(TypeInfo_for_T, Var);
IO = IO0;
+").
+
+:- pragma c_code(unsafe_dump_var(Var::in(any)), may_call_mercury, "
+ ML_var_print(TypeInfo_for_T, Var);
").
:- pred dump_var_rep(var_rep(T)::in(var_rep_any),
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list