[m-rev.] For post commit review: fix a problem with error_util.print_anything

Ralph Becket rafe at csse.unimelb.edu.au
Tue Jul 31 13:55:12 AEST 2007


I've already committed this one because it's been preventing me from
working.  The change is sufficiently small that it should not affect
anyone else, although people may wish to comment on the change itself.


Estimated hours taken: 4
Branches: main

Fix a problem in compiler/error_util.m where the compiler would throw an
exception when attempting to eliminate duplicate error messages for output.
The problem was that error_util defined a data constructor (print_anything)
with a higher order argument; higher order terms cannot be compared.

compiler/error_util.m:
	Replace the higher order argument of the print_anything data
	constructor argument with an existentially quantified constrained type.

	Define the print_anything/1 type class.

compiler/mode_errors.m:
	Use the new definition for print_anything.

Index: compiler/error_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/error_util.m,v
retrieving revision 1.63
diff -u -r1.63 error_util.m
--- compiler/error_util.m	28 May 2007 01:06:17 -0000	1.63
+++ compiler/error_util.m	31 Jul 2007 03:07:13 -0000
@@ -169,13 +169,19 @@
             % and set the flag that triggers the printing of the message
             % reminding the user about --verbose-errors.
 
-    ;       print_anything(pred(io, io)).
+    ;       some [T] ( print_anything(T) => print_anything(T) ).
             % This alternative allows the caller to specify an arbitrary thing
             % to be printed at any point in the sequence. Since things printed
             % this way aren't formatted as error messages should be (context
             % at start etc), this capability is intended only for messages
             % that help debug the compiler itself.
 
+:- typeclass print_anything(T) where [
+
+    pred print_anything(T::in, io::di, io::uo) is det
+
+].
+
 %-----------------------------------------------------------------------------%
 
     % Return the worst of two actual severities.
@@ -784,8 +790,7 @@
         !:PrintedSome = yes
     ;
         Component = print_anything(Anything),
-        unsafe_cast_to_io_pred(Anything, Pred),
-        Pred(!IO),
+        print_anything(Anything, !IO),
         !:First = no,
         !:PrintedSome = yes
     ),
Index: compiler/mode_errors.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_errors.m,v
retrieving revision 1.116
diff -u -r1.116 mode_errors.m
--- compiler/mode_errors.m	28 May 2007 01:06:18 -0000	1.116
+++ compiler/mode_errors.m	31 Jul 2007 03:16:37 -0000
@@ -469,10 +469,11 @@
     Msg1 = simple_msg(Context,
         [option_is_set(debug_modes, yes, [always(Pieces1)])]),
     mode_info_get_module_info(!.ModeInfo, ModuleInfo),
-    Closure = write_indented_goal(Goal, ModuleInfo, VarSet),
     Msg2 = error_msg(no, no, 0,
         [option_is_set(very_verbose, yes,
-            [always([nl]), print_anything(Closure)])]),
+            [always([nl]),
+             'new print_anything'(
+                write_indented_goal(Goal, ModuleInfo, VarSet))])]),
     Error = mode_error_info(_, ModeError, ErrorContext, ModeContext),
     mode_info_set_context(ErrorContext, !ModeInfo),
     mode_info_set_mode_context(ModeContext, !ModeInfo),
@@ -480,12 +481,17 @@
     SubSpec = error_spec(_, _, SubMsgs),
     Msgs = [Msg1, Msg2] ++ SubMsgs.
 
-:- pred write_indented_goal(hlds_goal::in, module_info::in, prog_varset::in,
-    io::di, io::uo) is det.
+:- type write_indented_goal
+    --->    write_indented_goal(hlds_goal, module_info, prog_varset).
 
-write_indented_goal(Goal, ModuleInfo, VarSet, !IO) :-
-    io.write_string("\t\t", !IO),
-    hlds_out.write_goal(Goal, ModuleInfo, VarSet, no, 2, ".\n", !IO).
+:- instance error_util.print_anything(write_indented_goal) where [
+
+    ( print_anything(write_indented_goal(Goal, ModuleInfo, VarSet), !IO) :-
+        io.write_string("\t\t", !IO),
+        hlds_out.write_goal(Goal, ModuleInfo, VarSet, no, 2, ".\n", !IO)
+    )
+
+].
 
 %-----------------------------------------------------------------------------%
 
--------------------------------------------------------------------------
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