[m-rev.] diff: improved mode error messages

Zoltan Somogyi zs at cs.mu.OZ.AU
Thu Aug 18 17:41:40 AEST 2005


compiler/mode_errors.m:
	Convert this module to four-space indentation to reduce the number
	of bad line breaks. Fix some departures from our coding standards.

	Convert most of this module to use error_util.m to format error
	messages instead just io__write_strings. (Converting the rest
	will require some changes in hlds_out.m.)

compiler/error_util.m:
	Provide the ability to add prefixes in front of following format
	components, and the ability to influence the indentation level
	when starting a new line. This is needed to support some of the new
	uses of error_util in mode_errors.m.

compiler/state_var.m:
	Remove a redundant format component that causes a minor test case
	discrepancy with the new code in error_util.m.

compiler/modes.m:
	Minor style fixes.

tests/invalid/*.err_exp:
	Expect better format in mode error messages.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/error_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/error_util.m,v
retrieving revision 1.40
diff -u -b -r1.40 error_util.m
--- compiler/error_util.m	8 Aug 2005 02:33:08 -0000	1.40
+++ compiler/error_util.m	17 Aug 2005 11:21:29 -0000
@@ -50,6 +50,11 @@
     --->    fixed(string)   % This string should appear in the output
                             % in one piece, as it is.
 
+    ;       prefix(string)  % This string should appear in the output
+                            % in one piece, as it is, inserted directly
+                            % before the next format_component, without
+                            % any intervening space.
+
     ;       suffix(string)  % This string should appear in the output
                             % in one piece, as it is, appended directly
                             % after the previous format_component, without
@@ -77,9 +82,14 @@
     ;       simple_call_id(simple_call_id)
                             % Output the identity of the given call.
 
-    ;       nl.             % Insert a line break if there has been text
+    ;       nl              % Insert a line break if there has been text
                             % output since the last line break.
 
+    ;       nl_indent_delta(int).
+                            % Act as nl, but also add the given integer
+                            % (which should be a small positive or negative
+                            % integer) to the current indent level.
+
 :- type format_components == list(format_component).
 
     % Convert a list of strings into a list of format_components
@@ -158,6 +168,10 @@
 :- func append_punctuation(list(format_component), char) =
     list(format_component).
 
+    % Put `' quotes around the given string.
+    %
+:- func add_quotes(string) = string.
+
     % report_error_num_args(MaybePredOrFunc, Arity, CorrectArities).
     %
     % Write "wrong number of arguments (<Arity>; should be <CorrectArities>)",
@@ -283,7 +297,7 @@
     io::di, io::uo) is det.
 
 write_error_pieces_maybe_with_context(IsFirst, MaybeContext,
-        Indent, Components, !IO) :-
+        FixedIndent, Components, !IO) :-
     (
             % The fixed characters at the start of the line are:
             % filename
@@ -309,51 +323,34 @@
             MaybeContext = no,
             ContextLength = 0
         ),
-        NotFirstIndent = (IsFirst = yes -> 0 ; 2),
-        Remain = 79 - (ContextLength + Indent + NotFirstIndent),
-        convert_components_to_word_list(Components, [], [], Words),
-        group_words(IsFirst, Words, Remain, Lines)
+        convert_components_to_paragraphs(Components, Paragraphs),
+        FirstIndent = (IsFirst = yes -> 0 ; 1),
+        Remain = 79 - (ContextLength + FixedIndent),
+        group_words(IsFirst, FirstIndent, Paragraphs, Remain, Lines)
     ),
-    (
-        IsFirst = yes,
-        write_lines(Lines, MaybeContext, Indent, !IO)
-    ;
-        IsFirst = no,
-        write_nonfirst_lines(Lines, MaybeContext, Indent + 2, !IO)
-    ).
+    write_lines(Lines, MaybeContext, FixedIndent, !IO).
 
-:- pred write_lines(list(list(string))::in, maybe(prog_context)::in, int::in,
-    io::di, io::uo) is det.
+:- func indent_increment = int.
 
-write_lines([], _, _, !IO).
-write_lines([Line | Lines], MaybeContext, Indent, !IO) :-
-    (
-        MaybeContext = yes(Context),
-        prog_out__write_context(Context, !IO)
-    ;
-        MaybeContext = no
-    ),
-    string__pad_left("", ' ', Indent, IndentStr),
-    io__write_string(IndentStr, !IO),
-    write_line(Line, !IO),
-    Indent2 = Indent + 2,
-    write_nonfirst_lines(Lines, MaybeContext, Indent2, !IO).
+indent_increment = 2.
 
-:- pred write_nonfirst_lines(list(list(string))::in, maybe(prog_context)::in,
-    int::in, io::di, io::uo) is det.
+:- pred write_lines(list(line)::in, maybe(prog_context)::in, int::in,
+    io::di, io::uo) is det.
 
-write_nonfirst_lines([], _, _, !IO).
-write_nonfirst_lines([Line | Lines], MaybeContext, Indent, !IO) :-
+write_lines([], _, _, !IO).
+write_lines([Line | Lines], MaybeContext, FixedIndent, !IO) :-
     (
         MaybeContext = yes(Context),
         prog_out__write_context(Context, !IO)
     ;
         MaybeContext = no
     ),
+    Line = line(LineIndent, LineWords),
+    Indent = FixedIndent + LineIndent * indent_increment,
     string__pad_left("", ' ', Indent, IndentStr),
     io__write_string(IndentStr, !IO),
-    write_line(Line, !IO),
-    write_nonfirst_lines(Lines, MaybeContext, Indent, !IO).
+    write_line(LineWords, !IO),
+    write_lines(Lines, MaybeContext, FixedIndent, !IO).
 
 :- pred write_line(list(string)::in, io::di, io::uo) is det.
 
@@ -376,66 +373,88 @@
     TailStr = error_pieces_to_string(Components),
     (
         Component = fixed(Word),
-        ( TailStr = "" ->
-            Str = Word
+        Str = join_string_and_tail(Word, Components, TailStr)
         ;
-            Str = Word ++ " " ++ TailStr
-        )
+        Component = prefix(Word),
+        Str = Word ++ TailStr
     ;
         Component = suffix(Word),
-        Str = Word ++ TailStr
+        Str = join_string_and_tail(Word, Components, TailStr)
     ;
         Component = words(Words),
-        ( TailStr = "" ->
-            Str = Words
-        ;
-            Str = Words ++ " " ++ TailStr
-        )
+        Str = join_string_and_tail(Words, Components, TailStr)
     ;
         Component = sym_name(SymName),
         Word = sym_name_to_word(SymName),
-        ( TailStr = "" ->
-            Str = Word
-        ;
-            Str = Word ++ " " ++ TailStr
-        )
+        Str = join_string_and_tail(Word, Components, TailStr)
     ;
         Component = sym_name_and_arity(SymNameAndArity),
         Word = sym_name_and_arity_to_word(SymNameAndArity),
-        ( TailStr = "" ->
-            Str = Word
-        ;
-            Str = Word ++ " " ++ TailStr
-        )
+        Str = join_string_and_tail(Word, Components, TailStr)
     ;
         Component = pred_or_func(PredOrFunc),
-        Str = pred_or_func_to_string(PredOrFunc)
+        Word = pred_or_func_to_string(PredOrFunc),
+        Str = join_string_and_tail(Word, Components, TailStr)
     ;
         Component = simple_call_id(SimpleCallId),
-        Str = simple_call_id_to_string(SimpleCallId)
+        Word = simple_call_id_to_string(SimpleCallId),
+        Str = join_string_and_tail(Word, Components, TailStr)
     ;
         Component = nl,
         Str = "\n" ++ TailStr
+    ;
+        Component = nl_indent_delta(_),
+        % There is nothing we can do about the indent delta.
+        Str = "\n" ++ TailStr
+    ).
+
+:- func join_string_and_tail(string, list(format_component), string) = string.
+
+join_string_and_tail(Word, Components, TailStr) = Str :-
+    ( TailStr = "" ->
+        Str = Word
+    ; Components = [suffix(_) | _] ->
+        Str = Word ++ TailStr
+    ;
+        Str = Word ++ " " ++ TailStr
     ).
 
 %----------------------------------------------------------------------------%
 
+:- type paragraph
+    --->    paragraph(
+                list(string),   % The list of words to print in the paragraph.
+                                % It should not be empty.
+                int             % The indent delta to apply for the next
+                                % paragraph.
+            ).
+
+:- pred convert_components_to_paragraphs(list(format_component)::in,
+    list(paragraph)::out) is det.
+
+convert_components_to_paragraphs(Components, Paras) :-
+    convert_components_to_paragraphs_acc(Components, [], [], Paras).
+
 :- type word
     --->    word(string)
+    ;       prefix_word(string)
     ;       suffix_word(string).
 
-:- pred convert_components_to_word_list(list(format_component)::in,
-    list(word)::in, list(list(string))::in, list(list(string))::out)
-    is det.
+:- pred convert_components_to_paragraphs_acc(list(format_component)::in,
+    list(word)::in, list(paragraph)::in, list(paragraph)::out) is det.
 
-convert_components_to_word_list([], RevWords0, !Paras) :-
+convert_components_to_paragraphs_acc([], RevWords0, !Paras) :-
     Strings = rev_words_to_strings(RevWords0),
-    list__reverse([Strings | !.Paras], !:Paras).
-convert_components_to_word_list([Component | Components], RevWords0, !Paras) :-
+    list__reverse([paragraph(Strings, 0) | !.Paras], !:Paras).
+convert_components_to_paragraphs_acc([Component | Components], RevWords0,
+        !Paras) :-
     (
         Component = fixed(Word),
         RevWords1 = [word(Word) | RevWords0]
     ;
+        Component = prefix(Word),
+        RevWords1 = [prefix_word(Word) | RevWords0]
+    ;
         Component = suffix(Word),
         RevWords1 = [suffix_word(Word) | RevWords0]
     ;
@@ -459,38 +478,79 @@
     ;
         Component = nl,
         Strings = rev_words_to_strings(RevWords0),
-        list.cons(Strings, !Paras),
+        list.cons(paragraph(Strings, 0), !Paras),
+        RevWords1 = []
+    ;
+        Component = nl_indent_delta(IndentDelta),
+        Strings = rev_words_to_strings(RevWords0),
+        list.cons(paragraph(Strings, IndentDelta), !Paras),
         RevWords1 = []
     ),
-    convert_components_to_word_list(Components, RevWords1, !Paras).
+    convert_components_to_paragraphs_acc(Components, RevWords1, !Paras).
+
+:- type plain_or_prefix
+    --->    plain(string)
+    ;       prefix(string).
 
 :- func rev_words_to_strings(list(word)) = list(string).
 
-rev_words_to_strings(RevWords) =
-    list__reverse(rev_words_to_rev_strings(RevWords)).
+rev_words_to_strings(RevWords) = Strings :-
+    PorPs = list__reverse(rev_words_to_rev_plain_or_prefix(RevWords)),
+    Strings = join_prefixes(PorPs).
 
-:- func rev_words_to_rev_strings(list(word)) = list(string).
+:- func rev_words_to_rev_plain_or_prefix(list(word)) = list(plain_or_prefix).
 
-rev_words_to_rev_strings([]) = [].
-rev_words_to_rev_strings([Word | Words]) = Strings :-
+rev_words_to_rev_plain_or_prefix([]) = [].
+rev_words_to_rev_plain_or_prefix([Word | Words]) = PorPs :-
     (
         Word = word(String),
-        Strings = [String | rev_words_to_rev_strings(Words)]
+        PorPs = [plain(String) | rev_words_to_rev_plain_or_prefix(Words)]
+    ;
+        Word = prefix_word(Prefix),
+        PorPs = [prefix(Prefix) | rev_words_to_rev_plain_or_prefix(Words)]
     ;
         Word = suffix_word(Suffix),
         (
             Words = [],
-            Strings = [Suffix]
+            PorPs = [plain(Suffix)]
         ;
             Words = [word(String) | Tail],
-            Strings = [String ++ Suffix | rev_words_to_rev_strings(Tail)]
+            PorPs = [plain(String ++ Suffix)
+                | rev_words_to_rev_plain_or_prefix(Tail)]
+        ;
+            Words = [prefix_word(Prefix) | Tail],
+            % Convert the prefix/suffix combination into a plain word.
+            % We could convert it into a prefix, but since prefix/suffix
+            % combinations shouldn't come up at all, what we do here probably
+            % doesn't matter.
+            PorPs = [plain(Prefix ++ Suffix)
+                | rev_words_to_rev_plain_or_prefix(Tail)]
         ;
             Words = [suffix_word(MoreSuffix) | Tail],
-            Strings = rev_words_to_rev_strings(
+            PorPs = rev_words_to_rev_plain_or_prefix(
                 [suffix_word(MoreSuffix ++ Suffix) | Tail])
         )
     ).
 
+:- func join_prefixes(list(plain_or_prefix)) = list(string).
+
+join_prefixes([]) = [].
+join_prefixes([Head | Tail]) = Strings :-
+    TailStrings = join_prefixes(Tail),
+    (
+        Head = plain(String),
+        Strings = [String | TailStrings]
+    ;
+        Head = prefix(Prefix),
+        (
+            TailStrings = [First | Later],
+            Strings = [Prefix ++ First | Later]
+        ;
+            TailStrings = [],
+            Strings = [Prefix | TailStrings]
+        )
+    ).
+
 :- func sym_name_to_word(sym_name) = string.
 
 sym_name_to_word(SymName) = "`" ++ SymStr ++ "'" :-
@@ -549,72 +609,89 @@
 
 %----------------------------------------------------------------------------%
 
+:- type line
+    --->    line(
+                int,            % Indent level; multiply by indent_increment
+                                % to get number of spaces of indentation.
+                list(string)    % The words on the line.
+            ).
+
     % Groups the given words into lines. The first line can have up to Max
     % characters on it; the later lines (if any) up to Max-2 characters.
-    % The given list of words must be nonempty, since we always return
+    % The given list of paragraphs must be nonempty, since we always return
     % at least one line.
     %
-:- pred group_words(bool::in, list(list(string))::in, int::in,
-    list(list(string))::out) is det.
+:- pred group_words(bool::in, int::in, list(paragraph)::in, int::in,
+    list(line)::out) is det.
 
-group_words(IsFirst, Paras, Max, Lines) :-
+group_words(IsFirst, CurIndent, Paras, Max, Lines) :-
     (
         Paras = [],
         Lines = []
     ;
         Paras = [FirstPara | LaterParas],
-        (
-            FirstPara = [],
-            group_words(IsFirst, LaterParas, Max, Lines)
-        ;
-            FirstPara = [FirstWord | LaterWords],
-            get_line_of_words(FirstWord, LaterWords, Max, Line, RestWords),
+        FirstPara = paragraph(FirstParaWords, FirstIndentDelta),
             (
                 IsFirst = yes,
-                Max2 = Max - 2
+            RestIndent = CurIndent + 1
             ;
                 IsFirst = no,
-                Max2 = Max
+            RestIndent = CurIndent
             ),
-            group_nonfirst_line_words(RestWords, Max2, RestLines1),
-            Lines1 = [Line | RestLines1],
-            group_words(no, LaterParas, Max2, RestLines),
-            list__append(Lines1, RestLines, Lines)
+        NextIndent = RestIndent + FirstIndentDelta,
+        (
+            FirstParaWords = [],
+            group_words(IsFirst, NextIndent, LaterParas, Max, Lines)
+        ;
+            FirstParaWords = [FirstWord | LaterWords],
+            get_line_of_words(FirstWord, LaterWords, CurIndent, Max,
+                LineWords, RestWords),
+            CurLine = line(CurIndent, LineWords),
+
+            group_nonfirst_line_words(RestWords, RestIndent, Max,
+                ParaRestLines),
+            ParaLines = [CurLine | ParaRestLines],
+
+            group_words(no, NextIndent, LaterParas, Max, RestLines),
+            Lines = ParaLines ++ RestLines
         )
     ).
 
-:- pred group_nonfirst_line_words(list(string)::in, int::in,
-    list(list(string))::out) is det.
+:- pred group_nonfirst_line_words(list(string)::in, int::in, int::in,
+    list(line)::out) is det.
 
-group_nonfirst_line_words(Words, Max, Lines) :-
+group_nonfirst_line_words(Words, Indent, Max, Lines) :-
     (
         Words = [],
         Lines = []
     ;
         Words = [FirstWord | LaterWords],
-        get_line_of_words(FirstWord, LaterWords, Max, Line, RestWords),
-        group_nonfirst_line_words(RestWords, Max, RestLines),
+        get_line_of_words(FirstWord, LaterWords, Indent, Max,
+            LineWords, RestWords),
+        Line = line(Indent, LineWords),
+        group_nonfirst_line_words(RestWords, Indent, Max, RestLines),
         Lines = [Line | RestLines]
     ).
 
-:- pred get_line_of_words(string::in, list(string)::in, int::in,
+:- pred get_line_of_words(string::in, list(string)::in, int::in, int::in,
     list(string)::out, list(string)::out) is det.
 
-get_line_of_words(FirstWord, LaterWords, MaxLen, Line, RestWords) :-
+get_line_of_words(FirstWord, LaterWords, Indent, Max, Line, RestWords) :-
     string__length(FirstWord, FirstWordLen),
-    get_later_words(LaterWords, FirstWordLen, MaxLen, [FirstWord],
+    Avail = Max - Indent * indent_increment,
+    get_later_words(LaterWords, FirstWordLen, Avail, [FirstWord],
         Line, RestWords).
 
 :- pred get_later_words(list(string)::in, int::in, int::in,
     list(string)::in, list(string)::out, list(string)::out) is det.
 
 get_later_words([], _, _, Line, Line, []).
-get_later_words([Word | Words], OldLen, MaxLen, Line0, Line, RestWords) :-
+get_later_words([Word | Words], OldLen, Avail, Line0, Line, RestWords) :-
     string__length(Word, WordLen),
     NewLen = OldLen + 1 + WordLen,
-    ( NewLen =< MaxLen ->
+    ( NewLen =< Avail ->
         list__append(Line0, [Word], Line1),
-        get_later_words(Words, NewLen, MaxLen, Line1, Line, RestWords)
+        get_later_words(Words, NewLen, Avail, Line1, Line, RestWords)
     ;
         Line = Line0,
         RestWords = [Word | Words]
@@ -644,6 +721,9 @@
         Piece0 = fixed(String),
         Piece = fixed(string__append(String, char_to_string(Punc)))
     ;
+        Piece0 = prefix(Prefix),
+        Piece = prefix(string__append(Prefix, char_to_string(Punc)))
+    ;
         Piece0 = suffix(Suffix),
         Piece = suffix(string__append(Suffix, char_to_string(Punc)))
     ;
@@ -664,11 +744,18 @@
         Piece = words(string__append(String, char_to_string(Punc)))
     ;
         Piece0 = nl,
-        error("append_punctutation: appending punctuation after newline")
+        unexpected(this_file,
+            "append_punctutation: appending punctuation after nl")
+    ;
+        Piece0 = nl_indent_delta(_),
+        unexpected(this_file,
+            "append_punctutation: appending punctuation after nl_indent_delta")
     ).
 append_punctuation([Piece1, Piece2 | Pieces], Punc) =
     [Piece1 | append_punctuation([Piece2 | Pieces], Punc)].
 
+add_quotes(Str) = "`" ++ Str ++ "'".
+
 %-----------------------------------------------------------------------------%
 
 report_error_num_args(MaybePredOrFunc, Arity0, Arities0, !IO) :-
@@ -740,3 +827,11 @@
 report_warning(Context, Indent, Components, !IO) :-
     record_warning(!IO),
     write_error_pieces(Context, Indent, Components, !IO).
+
+%-----------------------------------------------------------------------------%
+
+:- func this_file = string.
+
+this_file = "error_util.m".
+
+%-----------------------------------------------------------------------------%
Index: compiler/mode_errors.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mode_errors.m,v
retrieving revision 1.86
diff -u -b -r1.86 mode_errors.m
--- compiler/mode_errors.m	25 Apr 2005 08:47:35 -0000	1.86
+++ compiler/mode_errors.m	17 Aug 2005 11:25:27 -0000
@@ -1,4 +1,6 @@
 %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
 % Copyright (C) 1994-2005 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
@@ -7,8 +9,7 @@
 % File: mode_errors.m.
 % Main author: fjh.
 
-% This module contains all the error-reporting routines for the
-% mode-checker.
+% This module contains all the error-reporting routines for the mode-checker.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -24,11 +25,11 @@
 :- import_module parse_tree__prog_data.
 :- import_module check_hlds__mode_info.
 
-:- import_module assoc_list.
 :- import_module bool.
 :- import_module io.
 :- import_module list.
 :- import_module set.
+:- import_module std_util.
 
 %-----------------------------------------------------------------------------%
 
@@ -36,96 +37,107 @@
 	---> disj
 	;    if_then_else.
 
-:- type merge_errors == assoc_list(prog_var, list(inst)).
+:- type merge_error  == pair(prog_var, list(inst)).
+:- type merge_errors == list(merge_error).
 
 :- type delayed_goal
 	--->	delayed_goal(
-			set(prog_var),	% The vars it's waiting on
-			mode_error_info,% The reason it can't be scheduled
-			hlds_goal	% The goal itself
+                set(prog_var),      % The vars it's waiting on.
+                mode_error_info,    % The reason it can't be scheduled.
+                hlds_goal           % The goal itself.
 		).
 
 :- type mode_error
 	--->	mode_error_disj(merge_context, merge_errors)
-			% different arms of a disjunction result in
-			% different insts for some non-local variables
+            % Different arms of a disjunction result in different insts
+            % for some non-local variables.
+
 	;	mode_error_par_conj(merge_errors)
-			% different arms of a parallel conj result in
-			% mutually exclusive bindings - ie the process
-			% of unifying the instmaps from the end of each
-			% branch failed.
+            % Different arms of a parallel conj result in mutually exclusive
+            % bindings - ie the process of unifying the instmaps from the end
+            % of each branch failed.
+
 	;	mode_error_higher_order_pred_var(pred_or_func, prog_var, inst,
 				arity)
-			% the predicate variable in a higher-order predicate
-			% or function call didn't have a higher-order
-			% predicate or function inst of the appropriate arity
+            % The predicate variable in a higher-order predicate or function
+            % call didn't have a higher-order predicate or function inst
+            % of the appropriate arity.
+
 	;	mode_error_poly_unify(prog_var, inst)
 			% A variable in a polymorphic unification with unknown
 			% type has inst other than `ground' or `any'.
+
 	;	mode_error_var_is_live(prog_var)
-			% call to a predicate which will clobber its argument,
-			% but the argument is still live
+            % Call to a predicate which will clobber its argument,
+            % but the argument is still live.
+
 	;	mode_error_var_has_inst(prog_var, inst, inst)
-			% call to a predicate with an insufficiently
-			% instantiated variable (for preds with one mode)
+            % Call to a predicate with an insufficiently
+            % instantiated variable (for preds with one mode).
+
 	;	mode_error_unify_pred(prog_var, mode_error_unify_rhs, type,
 				pred_or_func)
-			% an attempt was made to unify two higher-order
+            % An attempt was made to unify two higher-order
 			% predicate or function variables.
+
 	;	mode_error_implied_mode(prog_var, inst, inst)
-			% a call to a predicate with an overly
-			% instantiated variable would use an implied
-			% mode of the predicate.  XXX This is temporary -
-			% once we've implemented implied modes we can
-			% get rid of it.
+            % A call to a predicate with an overly instantiated variable
+            % would use an implied mode of the predicate, but we can't
+            % introduce a simple unification after calling the predicate in a
+            % principal mode because the relevant variable has complex inst
+            % (such as any).
+
 	;	mode_error_no_mode_decl
-			% a call to a predicate for which there are
-			% no mode declarations (and mode inference is
-			% not enabled)
+            % A call to a predicate for which there are no mode declarations
+            % (and mode inference is not enabled).
+
 	;	mode_error_no_matching_mode(list(prog_var), list(inst))
-			% call to a predicate with an insufficiently
-			% instantiated variable (for preds with >1 mode)
+            % Call to a predicate with an insufficiently instantiated variable
+            % (for preds with >1 mode).
+
 	;	mode_error_in_callee(list(prog_var), list(inst),
 			pred_id, proc_id, list(mode_error_info))
-			% call to a predicate with initial argument insts
-			% for which mode inference gave a mode error
-			% in the callee
+            % Call to a predicate with initial argument insts for which mode
+            % inference gave a mode error in the callee.
+
 	;	mode_error_bind_var(var_lock_reason, prog_var, inst, inst)
-			% attempt to bind a non-local variable inside
-			% a negated context, or attempt to re-bind a variable
-			% in a parallel conjunct
+            % Attempt to bind a non-local variable inside a negated context,
+            % or attempt to re-bind a variable in a parallel conjunct.
+
 	;	mode_error_non_local_lambda_var(prog_var, inst)
-			% attempt to pass a live non-ground var as a
-			% non-local variable to a lambda goal
+            % Attempt to pass a live non-ground var as a non-local variable
+            % to a lambda goal.
+
 	;	mode_error_unify_var_var(prog_var, prog_var, inst, inst)
-			% attempt to unify two free variables
+            % Attempt to unify two free variables.
+
 	;	mode_error_unify_var_functor(prog_var, cons_id, list(prog_var),
 							inst, list(inst))
-			% attempt to unify a free var with a functor containing
-			% free arguments
+            % Attempt to unify a free var with a functor containing
+            % free arguments.
+
 	;	mode_error_unify_var_lambda(prog_var, inst, inst)
-			% some sort of error in
-			% attempt to unify a variable with lambda expression
+            % Some sort of error in attempt to unify a variable with lambda
+            % expression.
+
 	;	mode_error_conj(list(delayed_goal), schedule_culprit)
-			% a conjunction contains one or more unscheduleable
-			% goals; schedule_culprit gives the reason why
-			% they couldn't be scheduled.
-	;	mode_error_final_inst(int, prog_var, inst, inst,
-				final_inst_error)
-			% one of the head variables did not have the
-			% expected final inst on exit from the proc
-	.
+            % A conjunction contains one or more unscheduleable goals;
+            % schedule_culprit gives the reason why they couldn't be scheduled.
+
+    ;       mode_error_final_inst(int, prog_var, inst, inst, final_inst_error).
+            % One of the head variables did not have the expected final inst
+            % on exit from the proc.
 
 :- type schedule_culprit
 	--->	goal_itself_was_impure
 	;	goals_followed_by_impure_goal(hlds_goal)
-	;	conj_floundered. % we've reached the end of a conjunction
-				% and there were still delayed goals
+    ;       conj_floundered.        % We've reached the end of a conjunction
+                                    % and there were still delayed goals.
 
 :- type final_inst_error
 	--->	too_instantiated
 	;	not_instantiated_enough
-	;	wrongly_instantiated.	% a catchall for anything that doesn't
+    ;       wrongly_instantiated.   % A catchall for anything that doesn't
 					% fit into the above two categories.
 
 :- type mode_error_unify_rhs
@@ -135,13 +147,13 @@
 
 :- type mode_error_info
 	---> mode_error_info(
-		set(prog_var),	% the variables which caused the error
+                set(prog_var),      % The variables which caused the error
 				% (we will attempt to reschedule the goal
 				% if the one of these variables becomes
-				% more instantiated)
-		mode_error,	% the nature of the error
-		prog_context,	% where the error occurred
-		mode_context	% where the error occurred
+                                    % more instantiated).
+                mode_error,         % The nature of the error.
+                prog_context,       % Where the error occurred.
+                mode_context        % Where the error occurred.
 	).
 
 %-----------------------------------------------------------------------------%
@@ -152,36 +164,37 @@
 :- pred report_mode_errors(mode_info::in, mode_info::out,
 	io::di, io::uo) is det.
 
-	% print an error message describing a mode error
-
+    % Print an error message describing a mode error.
+    %
 :- pred report_mode_error(mode_error::in, mode_info::in,
 	io::di, io::uo) is det.
 
-	% report an error for a predicate with no mode declarations
+    % Report an error for a predicate with no mode declarations
 	% unless mode inference is enabled and the predicate is local.
-
+    %
 :- pred maybe_report_error_no_modes(pred_id::in, pred_info::in,
 	module_info::in, io::di, io::uo) is det.
 
-	% initialize the mode_context.
-
+    % Initialize the mode_context.
+    %
 :- pred mode_context_init(mode_context::out) is det.
 
 	% Write out the inferred `mode' declarations for a list of pred_ids.
 	% The bool indicates whether or not to write out determinism
 	% annotations on the modes (it should only be set to `yes' _after_
 	% determinism analysis).
-
+    %
 :- pred write_mode_inference_messages(list(pred_id)::in, bool::in,
 	module_info::in, io::di, io::uo) is det.
 
-	% report an error for the case when two mode declarations
-	% declare indistinguishable modes
-
+    % Report an error for the case when two mode declarations
+    % declare indistinguishable modes.
+    %
 :- pred report_indistinguishable_modes_error(proc_id::in, proc_id::in,
 	pred_id::in, pred_info::in, module_info::in, io::di, io::uo) is det.
 
 :- pred output_mode_decl(proc_id::in, pred_info::in, io::di, io::uo) is det.
+:- func mode_decl_to_string(proc_id, pred_info) = string.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -191,320 +204,323 @@
 :- import_module check_hlds__mode_info.
 :- import_module check_hlds__mode_util.
 :- import_module hlds__hlds_data.
+:- import_module hlds__hlds_error_util.
 :- import_module hlds__hlds_out.
 :- import_module libs__globals.
 :- import_module libs__options.
+:- import_module parse_tree__error_util.
 :- import_module parse_tree__mercury_to_mercury.
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
 
+:- import_module assoc_list.
 :- import_module int.
 :- import_module map.
 :- import_module require.
-:- import_module std_util.
 :- import_module string.
 :- import_module term.
 :- import_module term_io.
 :- import_module varset.
 
-	% just dispatch on the different sorts of mode errors
-
-report_mode_error(mode_error_disj(MergeContext, ErrorList), ModeInfo) -->
-	report_mode_error_disj(ModeInfo, MergeContext, ErrorList).
-report_mode_error(mode_error_par_conj(ErrorList), ModeInfo) -->
-	report_mode_error_par_conj(ModeInfo, ErrorList).
-report_mode_error(mode_error_higher_order_pred_var(PredOrFunc, Var, Inst,
-		Arity), ModeInfo) -->
+report_mode_error(ModeError, ModeInfo, !IO) :-
+    (
+        ModeError = mode_error_disj(MergeContext, ErrorList),
+        report_mode_error_disj(ModeInfo, MergeContext, ErrorList, !IO)
+    ;
+        ModeError = mode_error_par_conj(ErrorList),
+        report_mode_error_par_conj(ModeInfo, ErrorList, !IO)
+    ;
+        ModeError = mode_error_higher_order_pred_var(PredOrFunc, Var, Inst,
+            Arity),
 	report_mode_error_higher_order_pred_var(ModeInfo, PredOrFunc, Var,
-		Inst, Arity).
-report_mode_error(mode_error_poly_unify(Var, Inst), ModeInfo) -->
-	report_mode_error_poly_unify(ModeInfo, Var, Inst).
-report_mode_error(mode_error_var_is_live(Var), ModeInfo) -->
-	report_mode_error_var_is_live(ModeInfo, Var).
-report_mode_error(mode_error_var_has_inst(Var, InstA, InstB), ModeInfo) -->
-	report_mode_error_var_has_inst(ModeInfo, Var, InstA, InstB).
-report_mode_error(mode_error_unify_pred(Var, RHS, Type, PredOrFunc),
-		ModeInfo) -->
-	report_mode_error_unify_pred(ModeInfo, Var, RHS, Type, PredOrFunc).
-report_mode_error(mode_error_implied_mode(Var, InstA, InstB), ModeInfo) -->
-	report_mode_error_implied_mode(ModeInfo, Var, InstA, InstB).
-report_mode_error(mode_error_no_mode_decl, ModeInfo) -->
-	report_mode_error_no_mode_decl(ModeInfo).
-report_mode_error(mode_error_bind_var(Reason, Var, InstA, InstB), ModeInfo) -->
-	report_mode_error_bind_var(ModeInfo, Reason, Var, InstA, InstB).
-report_mode_error(mode_error_non_local_lambda_var(Var, Inst), ModeInfo) -->
-	report_mode_error_non_local_lambda_var(ModeInfo, Var, Inst).
-report_mode_error(mode_error_unify_var_var(VarA, VarB, InstA, InstB),
-		ModeInfo) -->
-	report_mode_error_unify_var_var(ModeInfo, VarA, VarB, InstA, InstB).
-report_mode_error(mode_error_unify_var_lambda(VarA, InstA, InstB),
-		ModeInfo) -->
-	report_mode_error_unify_var_lambda(ModeInfo, VarA, InstA, InstB).
-report_mode_error(mode_error_unify_var_functor(Var, Name, Args, Inst,
-			ArgInsts), ModeInfo) -->
+            Inst, Arity, !IO)
+    ;
+        ModeError = mode_error_poly_unify(Var, Inst),
+        report_mode_error_poly_unify(ModeInfo, Var, Inst, !IO)
+    ;
+        ModeError = mode_error_var_is_live(Var),
+        report_mode_error_var_is_live(ModeInfo, Var, !IO)
+    ;
+        ModeError = mode_error_var_has_inst(Var, InstA, InstB),
+        report_mode_error_var_has_inst(ModeInfo, Var, InstA, InstB, !IO)
+    ;
+        ModeError = mode_error_unify_pred(Var, RHS, Type, PredOrFunc),
+        report_mode_error_unify_pred(ModeInfo, Var, RHS, Type, PredOrFunc, !IO)
+    ;
+        ModeError = mode_error_implied_mode(Var, InstA, InstB),
+        report_mode_error_implied_mode(ModeInfo, Var, InstA, InstB, !IO)
+    ;
+        ModeError = mode_error_no_mode_decl,
+        report_mode_error_no_mode_decl(ModeInfo, !IO)
+    ;
+        ModeError = mode_error_bind_var(Reason, Var, InstA, InstB),
+        report_mode_error_bind_var(ModeInfo, Reason, Var, InstA, InstB, !IO)
+    ;
+        ModeError = mode_error_non_local_lambda_var(Var, Inst),
+        report_mode_error_non_local_lambda_var(ModeInfo, Var, Inst, !IO)
+    ;
+        ModeError = mode_error_unify_var_var(VarA, VarB, InstA, InstB),
+        report_mode_error_unify_var_var(ModeInfo, VarA, VarB, InstA, InstB,
+            !IO)
+    ;
+        ModeError = mode_error_unify_var_lambda(VarA, InstA, InstB),
+        report_mode_error_unify_var_lambda(ModeInfo, VarA, InstA, InstB, !IO)
+    ;
+        ModeError = mode_error_unify_var_functor(Var, Name, Args, Inst,
+            ArgInsts),
 	report_mode_error_unify_var_functor(ModeInfo, Var, Name, Args, Inst,
-			ArgInsts).
-report_mode_error(mode_error_conj(Errors, Culprit), ModeInfo) -->
-	report_mode_error_conj(ModeInfo, Errors, Culprit).
-report_mode_error(mode_error_no_matching_mode(Vars, Insts), ModeInfo) -->
-	report_mode_error_no_matching_mode(ModeInfo, Vars, Insts).
-report_mode_error(mode_error_in_callee(Vars, Insts,
-		CalleePredId, CalleeProcId, CalleeErrors), ModeInfo) -->
+            ArgInsts, !IO)
+    ;
+        ModeError = mode_error_conj(Errors, Culprit),
+        report_mode_error_conj(ModeInfo, Errors, Culprit, !IO)
+    ;
+        ModeError = mode_error_no_matching_mode(Vars, Insts),
+        report_mode_error_no_matching_mode(ModeInfo, Vars, Insts, !IO)
+    ;
+        ModeError = mode_error_in_callee(Vars, Insts,
+            CalleePredId, CalleeProcId, CalleeErrors),
 	report_mode_error_in_callee(ModeInfo, Vars, Insts,
-		CalleePredId, CalleeProcId, CalleeErrors).
-report_mode_error(mode_error_final_inst(ArgNum, Var, VarInst, Inst, Reason),
-		ModeInfo) -->
+            CalleePredId, CalleeProcId, CalleeErrors, !IO)
+    ;
+        ModeError = mode_error_final_inst(ArgNum, Var, VarInst, Inst, Reason),
 	report_mode_error_final_inst(ModeInfo, ArgNum, Var, VarInst, Inst,
-		Reason).
+            Reason, !IO)
+    ).
 
 %-----------------------------------------------------------------------------%
 
 :- pred report_mode_error_conj(mode_info::in, list(delayed_goal)::in,
 	schedule_culprit::in, io::di, io::uo) is det.
 
-report_mode_error_conj(ModeInfo, Errors, Culprit) -->
-	{ mode_info_get_context(ModeInfo, Context) },
-	{ mode_info_get_varset(ModeInfo, VarSet) },
-	{ find_important_errors(Errors, ImportantErrors, OtherErrors) },
-
-	% if there's more than one error, and we have verbose-errors
-	% enabled, report them all
-	globals__io_lookup_bool_option(verbose_errors, VerboseErrors),
-	( { VerboseErrors = yes, Errors = [_, _ | _] } ->
-		mode_info_write_context(ModeInfo),
-		prog_out__write_context(Context),
-		io__write_string("  mode error in conjunction. The next "),
-		{ list__length(Errors, NumErrors) },
-		io__write_int(NumErrors),
-		io__write_string(" error messages\n"),
-		prog_out__write_context(Context),
-		io__write_string("  indicate possible causes of this error.\n"),
-		report_mode_error_conj_2(ImportantErrors, VarSet, Context,
-			ModeInfo),
-		report_mode_error_conj_2(OtherErrors, VarSet, Context, ModeInfo)
+report_mode_error_conj(ModeInfo, Errors, Culprit, !IO) :-
+    mode_info_get_context(ModeInfo, Context),
+    mode_info_get_varset(ModeInfo, VarSet),
+    list__filter(is_error_important, Errors, ImportantErrors, OtherErrors),
+
+    % If there's more than one error, and we have verbose-errors enabled,
+    % report them all.
+    globals__io_lookup_bool_option(verbose_errors, VerboseErrors, !IO),
+    (
+        VerboseErrors = yes,
+        Errors = [_, _ | _]
+    ->
+        mode_info_write_context(ModeInfo, !IO),
+        PiecesA = [words("mode error in conjunction. The next"),
+            fixed(int_to_string(list__length(Errors))),
+            words("error messages indicate possible causes of this error.")],
+        write_error_pieces_not_first_line(Context, 0, PiecesA, !IO),
+        list__foldl(report_mode_error_conjunct(VarSet, Context, ModeInfo),
+            ImportantErrors ++ OtherErrors, !IO)
 	;
-		% in the normal case, only report the first error
-		{ ImportantErrors = [FirstImportantError | _] }
+        % In the normal case, only report the first error.
+        ImportantErrors = [FirstImportantError | _]
 	->
-		report_mode_error_conj_2([FirstImportantError], VarSet, Context,
-			ModeInfo)
+        report_mode_error_conjunct(VarSet, Context, ModeInfo,
+            FirstImportantError, !IO)
 	;
-		{ OtherErrors = [FirstOtherError | _] }
+        OtherErrors = [FirstOtherError | _]
 	->
-		report_mode_error_conj_2([FirstOtherError], VarSet, Context,
-			ModeInfo)
+        report_mode_error_conjunct(VarSet, Context, ModeInfo, FirstOtherError,
+            !IO)
 	;
 		% There wasn't any error to report!  This can't happen.
-		{ error("report_mode_error_conj") }
+        unexpected(this_file, "report_mode_error_conj")
 	),
 
-	% if the goal(s) couldn't be scheduled because we couldn't
-	% reorder things past an impure goal, then report that.
-	( { Culprit = conj_floundered },
-		{ true } % we've already reported everything we can
-	; { Culprit = goal_itself_was_impure },
-		prog_out__write_context(Context),
-		io__write_string(
-		"  The goal could not be reordered, because it was impure.\n")
-	; { Culprit = goals_followed_by_impure_goal(ImpureGoal) },
-		prog_out__write_context(Context),
-		io__write_string(
-			"  The goal could not be reordered, because\n"),
-		prog_out__write_context(Context),
-		io__write_string(
-			"  it was followed by an impure goal.\n"),
-		{ ImpureGoal = _ - ImpureGoalInfo },
-		{ goal_info_get_context(ImpureGoalInfo, ImpureGoalContext) },
-		prog_out__write_context(ImpureGoalContext),
-		io__write_string(
-			"  This is the location of the impure goal.\n")
+    % If the goal(s) couldn't be scheduled because we couldn't reorder things
+    % past an impure goal, then report that.
+    (
+        Culprit = conj_floundered
+        % We've already reported everything we can.
+    ;
+        Culprit = goal_itself_was_impure,
+        Pieces = [words("The goal could not be reordered,"),
+            words("because it was impure.")],
+        write_error_pieces_not_first_line(Context, 0, Pieces, !IO)
+    ;
+        Culprit = goals_followed_by_impure_goal(ImpureGoal),
+        Pieces1 = [words("The goal could not be reordered,"),
+            words("becaise it was followed by an impure goal.")],
+        write_error_pieces_not_first_line(Context, 0, Pieces1, !IO),
+        ImpureGoal = _ - ImpureGoalInfo,
+        goal_info_get_context(ImpureGoalInfo, ImpureGoalContext),
+        Pieces2 = [words("This is the location of the impure goal.")],
+        write_error_pieces_not_first_line(ImpureGoalContext, 0, Pieces2, !IO)
 	).
 
-:- pred find_important_errors(list(delayed_goal)::in,
-	list(delayed_goal)::out, list(delayed_goal)::out) is det.
+:- pred is_error_important(delayed_goal::in) is semidet.
 
-find_important_errors([], [], []).
-find_important_errors([Error | Errors], ImportantErrors, OtherErrors) :-
-	Error = delayed_goal(_, mode_error_info(_, ModeError, _, ModeContext),
-				_),
+is_error_important(Error) :-
+    Error = delayed_goal(_, mode_error_info(_, ModeError, _, ModeContext), _),
 	(
-		% an error is important unless it is a non-explicit unification,
-		% i.e. a head unification or a call argument unification
+        % An error is important unless it is a non-explicit unification,
+        % i.e. a head unification or a call argument unification.
 		ModeContext = unify(unify_context(UnifyContext, _), _),
 		UnifyContext \= explicit,
-		% except that errors in lambda goals are important even
-		% if the unification that creates the lambda goal is
-		% an implicit one
+
+        % Except that errors in lambda goals are important even if the
+        % unification that creates the lambda goal is an implicit one.
 		ModeError \= mode_error_non_local_lambda_var(_, _)
 	->
-		ImportantErrors1 = ImportantErrors,
-		OtherErrors = [Error | OtherErrors1]
+        fail
 	;
-		ImportantErrors = [Error | ImportantErrors1],
-		OtherErrors1 = OtherErrors
-	),
-	find_important_errors(Errors, ImportantErrors1, OtherErrors1).
+        true
+    ).
 
-:- pred report_mode_error_conj_2(list(delayed_goal)::in, prog_varset::in,
-	prog_context::in, mode_info::in, io::di, io::uo) is det.
-
-report_mode_error_conj_2([], _, _, _) --> [].
-report_mode_error_conj_2([delayed_goal(Vars, Error, Goal) | Rest],
-			VarSet, Context, ModeInfo) -->
-	globals__io_lookup_bool_option(debug_modes, Debug),
-	( { Debug = yes } ->
-		prog_out__write_context(Context),
-		io__write_string("Floundered goal, waiting on { "),
-		{ set__to_sorted_list(Vars, VarList) },
-		mercury_output_vars(VarList, VarSet, no),
-		io__write_string(" } :\n")
+:- pred report_mode_error_conjunct(prog_varset::in, prog_context::in,
+    mode_info::in, delayed_goal::in, io::di, io::uo) is det.
+
+report_mode_error_conjunct(VarSet, Context, !.ModeInfo,
+        delayed_goal(Vars, Error, Goal), !IO) :-
+    globals__io_lookup_bool_option(debug_modes, Debug, !IO),
+    (
+        Debug = yes,
+        prog_out__write_context(Context, !IO),
+        io__write_string("Floundered goal, waiting on { ", !IO),
+        set__to_sorted_list(Vars, VarList),
+        mercury_output_vars(VarList, VarSet, no, !IO),
+        io__write_string(" } :\n", !IO)
 	;
-		[]
+        Debug = no
 	),
-	globals__io_lookup_bool_option(very_verbose, VeryVerbose),
-	( { VeryVerbose = yes } ->
-		io__write_string("\t\t"),
-		{ mode_info_get_module_info(ModeInfo, ModuleInfo) },
-		hlds_out__write_goal(Goal, ModuleInfo, VarSet, no, 2, ".\n")
+    globals__io_lookup_bool_option(very_verbose, VeryVerbose, !IO),
+    (
+        VeryVerbose = yes,
+        mode_info_get_module_info(!.ModeInfo, ModuleInfo),
+        io__write_string("\t\t", !IO),
+        hlds_out__write_goal(Goal, ModuleInfo, VarSet, no, 2, ".\n", !IO)
 	;
-		[]
+        VeryVerbose = no
 	),
-	{ Error = mode_error_info(_, ModeError, ErrorContext, ModeContext) },
-	{ mode_info_set_context(ErrorContext, ModeInfo, ModeInfo1) },
-	{ mode_info_set_mode_context(ModeContext, ModeInfo1, ModeInfo2) },
-	report_mode_error(ModeError, ModeInfo2),
-	report_mode_error_conj_2(Rest, VarSet, Context, ModeInfo2).
+    Error = mode_error_info(_, ModeError, ErrorContext, ModeContext),
+    mode_info_set_context(ErrorContext, !ModeInfo),
+    mode_info_set_mode_context(ModeContext, !ModeInfo),
+    report_mode_error(ModeError, !.ModeInfo, !IO).
 
 %-----------------------------------------------------------------------------%
 
 :- pred report_mode_error_disj(mode_info::in, merge_context::in,
 	merge_errors::in, io::di, io::uo) is det.
 
-report_mode_error_disj(ModeInfo, MergeContext, ErrorList) -->
-	{ mode_info_get_context(ModeInfo, Context) },
-	mode_info_write_context(ModeInfo),
-	prog_out__write_context(Context),
-	io__write_string("  mode mismatch in "),
-	write_merge_context(MergeContext),
-	io__write_string(".\n"),
-	write_merge_error_list(ErrorList, ModeInfo).
+report_mode_error_disj(ModeInfo, MergeContext, ErrorList, !IO) :-
+    mode_info_write_context(ModeInfo, !IO),
+    Pieces = [words("mode mismatch in "),
+        words(merge_context_to_string(MergeContext)), suffix(".")],
+    mode_info_get_context(ModeInfo, Context),
+    write_error_pieces_not_first_line(Context, 0, Pieces, !IO),
+    io__write_list(ErrorList, "", write_merge_error(ModeInfo), !IO).
 
 :- pred report_mode_error_par_conj(mode_info::in, merge_errors::in,
 	io::di, io::uo) is det.
 
-report_mode_error_par_conj(ModeInfo, ErrorList) -->
-	{ mode_info_get_context(ModeInfo, Context) },
-	mode_info_write_context(ModeInfo),
-	prog_out__write_context(Context),
-	io__write_string("  mode error: mutually exclusive bindings in parallel conjunction.\n"),
-	mode_info_write_context(ModeInfo),
-	prog_out__write_context(Context),
-	io__write_string("              (The current implementation does not permit\n"),
-	mode_info_write_context(ModeInfo),
-	prog_out__write_context(Context),
-	io__write_string("              parallel conjunctions to fail.)\n"),
-	write_merge_error_list(ErrorList, ModeInfo).
+report_mode_error_par_conj(ModeInfo, ErrorList, !IO) :-
+    mode_info_get_context(ModeInfo, Context),
+    mode_info_write_context(ModeInfo, !IO),
+    Pieces = [words("mode error: mutually exclusive bindings"),
+        words("in parallel conjunction."),
+        words("(The current implementation does not permit"),
+        words("parallel conjunctions to fail.)"), nl],
+    write_error_pieces_not_first_line(Context, 1, Pieces, !IO),
+    io__write_list(ErrorList, "", write_merge_error(ModeInfo), !IO).
+
+:- pred write_merge_error(mode_info::in, merge_error::in, io::di, io::uo)
+    is det.
+
+write_merge_error(ModeInfo, Var - Insts, !IO) :-
+    mode_info_get_context(ModeInfo, Context),
+    mode_info_get_varset(ModeInfo, VarSet),
+    Pieces = [words(add_quotes(mercury_var_to_string(Var, VarSet, no))),
+        fixed("::"),
+        words(inst_list_to_string(ModeInfo, Insts)), suffix("."), nl],
+    write_error_pieces_not_first_line(Context, 0, Pieces, !IO).
 
-:- pred write_merge_error_list(merge_errors::in, mode_info::in,
-	io::di, io::uo) is det.
+:- func merge_context_to_string(merge_context) = string.
 
-write_merge_error_list([], _) --> [].
-write_merge_error_list([Var - Insts | Errors], ModeInfo) -->
-	{ mode_info_get_context(ModeInfo, Context) },
-	{ mode_info_get_varset(ModeInfo, VarSet) },
-	prog_out__write_context(Context),
-	io__write_string("  `"),
-	mercury_output_var(Var, VarSet, no),
-	io__write_string("' :: "),
-	output_inst_list(Insts, ModeInfo),
-	io__write_string(".\n"),
-	write_merge_error_list(Errors, ModeInfo).
-
-:- pred write_merge_context(merge_context::in, io::di, io::uo) is det.
-
-write_merge_context(disj) -->
-	io__write_string("disjunction").
-write_merge_context(if_then_else) -->
-	io__write_string("if-then-else").
+merge_context_to_string(disj) = "disjunction".
+merge_context_to_string(if_then_else) = "if-then-else".
 
 %-----------------------------------------------------------------------------%
 
 :- pred report_mode_error_bind_var(mode_info::in, var_lock_reason::in,
 	prog_var::in, (inst)::in, (inst)::in, io::di, io::uo) is det.
 
-report_mode_error_bind_var(ModeInfo, Reason, Var, VarInst, Inst) -->
-	{ mode_info_get_context(ModeInfo, Context) },
-	{ mode_info_get_varset(ModeInfo, VarSet) },
-	mode_info_write_context(ModeInfo),
-	prog_out__write_context(Context),
-	io__write_string("  scope error: "),
-	( { Reason = negation },
-		io__write_string("attempt to bind a variable inside a negation.\n")
-	; { Reason = if_then_else },
-		io__write_string("attempt to bind a non-local variable\n"),
-		prog_out__write_context(Context),
-		io__write_string("  inside the condition of an if-then-else.\n")
-	; { Reason = lambda(PredOrFunc) },
-		{ PredOrFuncS = prog_out__pred_or_func_to_str(PredOrFunc) },
-		io__write_string("attempt to bind a non-local variable inside\n"),
-		prog_out__write_context(Context),
-		io__write_strings(["  a ", PredOrFuncS, " lambda goal.\n"])
-	; { Reason = par_conj },
-		io__write_string("attempt to bind a non-local variable\n"),
-		prog_out__write_context(Context),
-		io__write_string("  inside more than one parallel conjunct.\n")
+report_mode_error_bind_var(ModeInfo, Reason, Var, VarInst, Inst, !IO) :-
+    mode_info_get_context(ModeInfo, Context),
+    mode_info_get_varset(ModeInfo, VarSet),
+    mode_info_write_context(ModeInfo, !IO),
+    (
+        Reason = negation,
+        ReasonStr = "attempt to bind a variable inside a negation."
+    ;
+        Reason = if_then_else,
+        ReasonStr = "attempt to bind a non-local variable" ++
+            " inside the condition of an if-then-else."
+    ;
+        Reason = lambda(PredOrFunc),
+        PredOrFuncS = prog_out__pred_or_func_to_str(PredOrFunc),
+        ReasonStr = "attempt to bind a non-local variable inside" ++
+            " a " ++ PredOrFuncS ++ " lambda goal."
+    ;
+        Reason = par_conj,
+        ReasonStr = "attempt to bind a non-local variable" ++
+            "inside more than one parallel conjunct."
 	),
-	prog_out__write_context(Context),
-	io__write_string("  Variable `"),
-	mercury_output_var(Var, VarSet, no),
-	io__write_string("' has instantiatedness `"),
-	output_inst(VarInst, ModeInfo),
-	io__write_string("',\n"),
-	prog_out__write_context(Context),
-	io__write_string("  expected instantiatedness was `"),
-	output_inst(Inst, ModeInfo),
-	io__write_string("'.\n"),
-	globals__io_lookup_bool_option(verbose_errors, VerboseErrors),
-	( { VerboseErrors = yes } ->
-		( { Reason = negation },
-			io__write_string("\tA negation is only allowed to bind variables which are local to the\n"),
-			io__write_string("\tnegation, i.e. those which are implicitly existentially quantified\n"),
-			io__write_string("\tinside the scope of the negation.\n")
-		; { Reason = if_then_else },
-			io__write_string("\tThe condition of an if-then-else is only allowed\n"),
-			io__write_string("\tto bind variables which are local to the condition\n"),
-			io__write_string("\tor which occur only in the condition and the `then' part.\n")
-		; { Reason = lambda(_) },
-			io__write_string("\tA lambda goal is only allowed to bind its arguments\n"),
-			io__write_string("\tand variables local to the lambda expression.\n")
-		; { Reason = par_conj },
-			io__write_string("\tA nonlocal variable of a parallel conjunction may be\n"),
-			io__write_string("\tbound in at most one conjunct.\n")
+    Pieces1 = [words("scope error:"), words(ReasonStr), nl,
+        words("Variable"),
+        words(add_quotes(mercury_var_to_string(Var, VarSet, no))),
+        words("has instantiatedness"),
+        words(add_quotes(inst_to_string(ModeInfo, VarInst))), suffix(","), nl,
+        words("expected instantiatedness was"),
+        words(add_quotes(inst_to_string(ModeInfo, Inst))), suffix("."), nl],
+    globals__io_lookup_bool_option(verbose_errors, VerboseErrors, !IO),
+    (
+        VerboseErrors = yes,
+        (
+            Reason = negation,
+            Pieces2 = [words("A negation is only allowed to bind variables"),
+                words("which are local to the negation, i.e. those which are"),
+                words("implicitly existentially quantified"),
+                words("inside the scope of the negation."), nl]
+        ;
+            Reason = if_then_else,
+            Pieces2 = [words("The condition of an if-then-else is only"),
+                words("allowed to bind variables which are local to the"),
+                words("condition or which occur only in the condition"),
+                words("and the `then' part."), nl]
+        ;
+            Reason = lambda(_),
+            Pieces2 = [words("A lambda goal is only allowed to bind"),
+                words("its arguments and variables local to the "),
+                words("lambda expression."), nl]
+        ;
+            Reason = par_conj,
+            Pieces2 = [words("A nonlocal variable of a parallel conjunction"),
+                words("may be bound in at most one conjunct."), nl]
 		)
 	;
-		[]
-	).
+        VerboseErrors = no,
+        Pieces2 = []
+    ),
+    write_error_pieces_not_first_line(Context, 0, Pieces1 ++ Pieces2, !IO).
 
 %-----------------------------------------------------------------------------%
 
 :- pred report_mode_error_non_local_lambda_var(mode_info::in, prog_var::in,
 	(inst)::in, io::di, io::uo) is det.
 
-report_mode_error_non_local_lambda_var(ModeInfo, Var, VarInst) -->
-	{ mode_info_get_context(ModeInfo, Context) },
-	{ mode_info_get_varset(ModeInfo, VarSet) },
-	mode_info_write_context(ModeInfo),
-	prog_out__write_context(Context),
-	io__write_string("  mode error: variable `"),
-	mercury_output_var(Var, VarSet, no),
-	io__write_string("' has instantiatedness `"),
-	output_inst(VarInst, ModeInfo),
-	io__write_string("',\n"),
-	prog_out__write_context(Context),
-	io__write_string("  expected instantiatedness for non-local variables\n"),
-	prog_out__write_context(Context),
-	io__write_string("  of lambda goals is `ground'.\n").
+report_mode_error_non_local_lambda_var(ModeInfo, Var, VarInst, !IO) :-
+    mode_info_get_context(ModeInfo, Context),
+    mode_info_get_varset(ModeInfo, VarSet),
+    mode_info_write_context(ModeInfo, !IO),
+    Pieces = [words("mode error: variable"),
+        fixed(add_quotes(mercury_var_to_string(Var, VarSet, no))),
+        words("has instantiatedness"),
+        words(add_quotes(inst_to_string(ModeInfo, VarInst))),
+        suffix(","), nl,
+        words("expected instantiatedness for non-local variables"),
+        words("of lambda goals is `ground'."), nl],
+    write_error_pieces_not_first_line(Context, 0, Pieces, !IO).
 
 %-----------------------------------------------------------------------------%
 
@@ -512,199 +528,178 @@
 	list(inst)::in, pred_id::in, proc_id::in, list(mode_error_info)::in,
 	io::di, io::uo) is det.
 
-report_mode_error_in_callee(ModeInfo0, Vars, Insts,
-		CalleePredId, CalleeProcId, CalleeModeErrors) -->
-	{ mode_info_get_module_info(ModeInfo0, ModuleInfo) },
-	{ mode_info_get_context(ModeInfo0, Context) },
-	{ mode_info_get_varset(ModeInfo0, VarSet) },
-	mode_info_write_context(ModeInfo0),
-	prog_out__write_context(Context),
-	io__write_string("  mode error: arguments `"),
-	mercury_output_vars(Vars, VarSet, no),
-	io__write_string("'\n"),
-	prog_out__write_context(Context),
-	io__write_string("  have the following insts:\n"),
-	output_inst_list_sep_lines(Context, Insts, ModeInfo0),
-	prog_out__write_context(Context),
-	io__write_string("  which does not match any of the valid modes for\n"),
-	globals__io_lookup_bool_option(verbose_errors, VerboseErrors),
+report_mode_error_in_callee(!.ModeInfo, Vars, Insts,
+        CalleePredId, CalleeProcId, CalleeModeErrors, !IO) :-
+    mode_info_get_module_info(!.ModeInfo, ModuleInfo),
+    mode_info_get_context(!.ModeInfo, Context),
+    mode_info_get_varset(!.ModeInfo, VarSet),
+    mode_info_write_context(!.ModeInfo, !IO),
+    Pieces1 = [words("mode error: arguments"),
+        words(add_quotes(mercury_vars_to_string(Vars, VarSet, no))),
+        words("have the following insts:"), nl_indent_delta(1)] ++
+        inst_list_to_sep_lines(!.ModeInfo, Insts) ++
+        [words("which does not match any of the valid modes for")],
+    globals__io_lookup_bool_option(verbose_errors, VerboseErrors, !IO),
 	(
-		{ VerboseErrors = yes },
-		prog_out__write_context(Context),
-		io__write_string("  the callee ("),
-		hlds_out__write_pred_id(ModuleInfo, CalleePredId),
-		io__write_string("),\n"),
-		prog_out__write_context(Context),
-		io__write_string("  because of the following error.\n")
+        VerboseErrors = yes,
+        Pieces2 = [words("the callee"), prefix("(")] ++
+            describe_one_pred_name(ModuleInfo, should_module_qualify,
+                CalleePredId) ++ [suffix(")"), nl,
+            words("because of the following error."), nl]
 	;
-		{ VerboseErrors = no },
-		prog_out__write_context(Context),
-		io__write_string("  the callee, because of the following error.\n")
+        VerboseErrors = no,
+        Pieces2 = [words("the callee, because of the following error."), nl]
 	),
+    write_error_pieces_not_first_line(Context, 0, Pieces1 ++ Pieces2, !IO),
 	(
-		{ CalleeModeErrors = [First | _] },
-		{ First = mode_error_info(_, CalleeModeError,
-			CalleeContext, CalleeModeContext) },
-		{ mode_info_set_predid(CalleePredId, ModeInfo0, ModeInfo1) },
-		{ mode_info_set_procid(CalleeProcId, ModeInfo1, ModeInfo2) },
-		{ mode_info_set_context(CalleeContext, ModeInfo2, ModeInfo3) },
-		{ mode_info_set_mode_context(CalleeModeContext,
-			ModeInfo3, ModeInfo4) },
-		report_mode_error(CalleeModeError, ModeInfo4)
+        CalleeModeErrors = [First | _],
+        First = mode_error_info(_, CalleeModeError,
+            CalleeContext, CalleeModeContext),
+        mode_info_set_predid(CalleePredId, !ModeInfo),
+        mode_info_set_procid(CalleeProcId, !ModeInfo),
+        mode_info_set_context(CalleeContext, !ModeInfo),
+        mode_info_set_mode_context(CalleeModeContext, !ModeInfo),
+        report_mode_error(CalleeModeError, !.ModeInfo, !IO)
 	;
-		{ CalleeModeErrors = [] },
-		{ error("report_mode_error_in_callee: no error") }
+        CalleeModeErrors = [],
+        error("report_mode_error_in_callee: no error")
 	).
 
 :- pred report_mode_error_no_matching_mode(mode_info::in, list(prog_var)::in,
 	list(inst)::in, io::di, io::uo) is det.
 
-report_mode_error_no_matching_mode(ModeInfo, Vars, Insts) -->
-	{ mode_info_get_context(ModeInfo, Context) },
-	{ mode_info_get_varset(ModeInfo, VarSet) },
-	mode_info_write_context(ModeInfo),
-	prog_out__write_context(Context),
-	io__write_string("  mode error: arguments `"),
-	mercury_output_vars(Vars, VarSet, no),
-	io__write_string("'\n"),
-	prog_out__write_context(Context),
-	io__write_string("  have the following insts:\n"),
-	output_inst_list_sep_lines(Context, Insts, ModeInfo),
-	prog_out__write_context(Context),
-	io__write_string("  which does not match any of the modes for "),
-	{ mode_info_get_mode_context(ModeInfo, ModeContext) },
-	( { ModeContext = call(CallId, _) } ->
-		hlds_out__write_call_id(CallId)
+report_mode_error_no_matching_mode(ModeInfo, Vars, Insts, !IO) :-
+    mode_info_write_context(ModeInfo, !IO),
+    mode_info_get_context(ModeInfo, Context),
+    mode_info_get_varset(ModeInfo, VarSet),
+    mode_info_get_mode_context(ModeInfo, ModeContext),
+    ( ModeContext = call(CallId, _) ->
+        CallIdStr = hlds_out__call_id_to_string(CallId)
 	;
-		{ error("report_mode_error_no_matching_mode: invalid context") }
+        unexpected(this_file,
+            "report_mode_error_no_matching_mode: invalid context")
 	),
-	io__write_string(".\n").
+    Pieces = [words("mode error: arguments"),
+        fixed(add_quotes(mercury_vars_to_string(Vars, VarSet, no))),
+        words("have the following insts:"), nl_indent_delta(1)] ++
+        inst_list_to_sep_lines(ModeInfo, Insts) ++
+        [words("which does not match any of the modes for"),
+        words(CallIdStr), suffix("."), nl],
+    write_error_pieces_not_first_line(Context, 0, Pieces, !IO).
 
 :- pred report_mode_error_higher_order_pred_var(mode_info::in, pred_or_func::in,
 	prog_var::in, (inst)::in, arity::in, io::di, io::uo) is det.
 
 report_mode_error_higher_order_pred_var(ModeInfo, PredOrFunc, Var, VarInst,
-		Arity) -->
-	{ mode_info_get_context(ModeInfo, Context) },
-	{ mode_info_get_varset(ModeInfo, VarSet) },
-	mode_info_write_context(ModeInfo),
-	prog_out__write_context(Context),
-	io__write_string("  mode error: variable `"),
-	mercury_output_var(Var, VarSet, no),
-	io__write_string("' has instantiatedness `"),
-	output_inst(VarInst, ModeInfo),
-	io__write_string("',\n"),
-	prog_out__write_context(Context),
+        Arity, !IO) :-
+    mode_info_get_context(ModeInfo, Context),
+    mode_info_get_varset(ModeInfo, VarSet),
+    mode_info_write_context(ModeInfo, !IO),
 	(
-		{ PredOrFunc = predicate },
-		io__write_string(
-			"  expecting higher-order pred inst (of arity "),
-		io__write_int(Arity)
-	;
-		{ PredOrFunc = function },
-		io__write_string(
-			"  expecting higher-order func inst (of arity "),
-		{ Arity1 = Arity - 1 },
-		io__write_int(Arity1)
+        PredOrFunc = predicate,
+        Expecting = "expecting higher-order pred inst (of arity " ++
+            int_to_string(Arity) ++ ")."
+    ;
+        PredOrFunc = function,
+        Expecting = "expecting higher-order func inst (of arity " ++
+            int_to_string(Arity - 1) ++ ")."
 	),
-	io__write_string(").\n").
+    Pieces = [words("mode error: variable"),
+        fixed(add_quotes(mercury_var_to_string(Var, VarSet, no))),
+        words("has instantiatedness"),
+        words(add_quotes(inst_to_string(ModeInfo, VarInst))),
+        suffix(","), nl,
+        words(Expecting), nl],
+    write_error_pieces_not_first_line(Context, 0, Pieces, !IO).
 
 :- pred report_mode_error_poly_unify(mode_info::in, prog_var::in, (inst)::in,
 	io::di, io::uo) is det.
 
-report_mode_error_poly_unify(ModeInfo, Var, VarInst) -->
-	{ mode_info_get_context(ModeInfo, Context) },
-	{ mode_info_get_varset(ModeInfo, VarSet) },
-	mode_info_write_context(ModeInfo),
-	prog_out__write_context(Context),
-	io__write_string("  in polymorphically-typed unification:\n"),
-	prog_out__write_context(Context),
-	io__write_string("  mode error: variable `"),
-	mercury_output_var(Var, VarSet, no),
-	io__write_string("' has instantiatedness `"),
-	output_inst(VarInst, ModeInfo),
-	io__write_string("',\n"),
-	prog_out__write_context(Context),
-	io__write_string(
-		"  expected instantiatedness was `ground' or `any'.\n"),
-	globals__io_lookup_bool_option(verbose_errors, VerboseErrors),
-	( { VerboseErrors = yes } ->
-		io__write_string(
-"\tWhen unifying two variables whose type will not be known until
-\truntime, the variables must both be ground (or have inst `any').
-\tUnifications of polymorphically-typed variables with partially
-\tinstantiated modes are not allowed.\n")
+report_mode_error_poly_unify(ModeInfo, Var, VarInst, !IO) :-
+    mode_info_get_context(ModeInfo, Context),
+    mode_info_get_varset(ModeInfo, VarSet),
+    mode_info_write_context(ModeInfo, !IO),
+    Pieces1 = [words("in polymorphically-typed unification:"), nl,
+        words("mode error: variable"),
+        words(add_quotes(mercury_var_to_string(Var, VarSet, no))),
+        words("has instantiatedness"),
+        words(add_quotes(inst_to_string(ModeInfo, VarInst))), suffix(","), nl,
+        words("expected instantiatedness was `ground' or `any'."), nl],
+    globals__io_lookup_bool_option(verbose_errors, VerboseErrors, !IO),
+    (
+        VerboseErrors = yes,
+        Pieces2 = [words("When unifying two variables whose type"),
+            words("will not be known until runtime, the variables must both"),
+            words("be ground (or have inst `any'). Unifications of"),
+            words("polymorphically-typed variables with partially"),
+            words("instantiated modes are not allowed.")]
 	;
-		[]
-	).
+        VerboseErrors = no,
+        Pieces2 = []
+    ),
+    write_error_pieces_not_first_line(Context, 0, Pieces1 ++ Pieces2, !IO).
 
 :- pred report_mode_error_var_is_live(mode_info::in, prog_var::in,
 	io::di, io::uo) is det.
 
-report_mode_error_var_is_live(ModeInfo, Var) -->
-	{ mode_info_get_context(ModeInfo, Context) },
-	{ mode_info_get_varset(ModeInfo, VarSet) },
-	mode_info_write_context(ModeInfo),
-	prog_out__write_context(Context),
-	io__write_string("  unique-mode error: the called procedure would clobber\n"),
-	prog_out__write_context(Context),
-	io__write_string("  its argument, but variable `"),
-	mercury_output_var(Var, VarSet, no),
-	io__write_string("' is still live.\n").
+report_mode_error_var_is_live(ModeInfo, Var, !IO) :-
+    mode_info_get_context(ModeInfo, Context),
+    mode_info_get_varset(ModeInfo, VarSet),
+    mode_info_write_context(ModeInfo, !IO),
+    Pieces = [words("unique-mode error: the called procedure"),
+        words("would clobber its argument, but variable"),
+        words(add_quotes(mercury_var_to_string(Var, VarSet, no))),
+        words("is still live."), nl],
+    write_error_pieces_not_first_line(Context, 0, Pieces, !IO).
 
 :- pred report_mode_error_var_has_inst(mode_info::in, prog_var::in,
 	(inst)::in, (inst)::in, io::di, io::uo) is det.
 
-report_mode_error_var_has_inst(ModeInfo, Var, VarInst, Inst) -->
-	{ mode_info_get_context(ModeInfo, Context) },
-	{ mode_info_get_varset(ModeInfo, VarSet) },
-	mode_info_write_context(ModeInfo),
-	prog_out__write_context(Context),
-	io__write_string("  mode error: variable `"),
-	mercury_output_var(Var, VarSet, no),
-	io__write_string("' has instantiatedness `"),
-	output_inst(VarInst, ModeInfo),
-	io__write_string("',\n"),
-	prog_out__write_context(Context),
-	io__write_string("  expected instantiatedness was `"),
-	output_inst(Inst, ModeInfo),
-	io__write_string("'.\n").
+report_mode_error_var_has_inst(ModeInfo, Var, VarInst, Inst, !IO) :-
+    mode_info_get_context(ModeInfo, Context),
+    mode_info_get_varset(ModeInfo, VarSet),
+    mode_info_write_context(ModeInfo, !IO),
+    Pieces = [words("mode error: variable"),
+        words(add_quotes(mercury_var_to_string(Var, VarSet, no))),
+        words("has instantiatedness"),
+        words(add_quotes(inst_to_string(ModeInfo, VarInst))), suffix(","), nl,
+        words("expected instantiatedness was"),
+        words(add_quotes(inst_to_string(ModeInfo, Inst))), suffix("."), nl],
+    write_error_pieces_not_first_line(Context, 0, Pieces, !IO).
 
 :- pred report_mode_error_implied_mode(mode_info::in, prog_var::in,
 	(inst)::in, (inst)::in, io::di, io::uo) is det.
 
-report_mode_error_implied_mode(ModeInfo, Var, VarInst, Inst) -->
-		% This "error" message is really a "sorry, not implemented"
-		% message.  We only print the message if we are actually
-		% going to generating code.
-	globals__io_lookup_bool_option(errorcheck_only, ErrorcheckOnly),
-	( { ErrorcheckOnly = no } ->
-		{ mode_info_get_context(ModeInfo, Context) },
-		{ mode_info_get_varset(ModeInfo, VarSet) },
-		mode_info_write_context(ModeInfo),
-		prog_out__write_context(Context),
-		io__write_string("  sorry, implied modes not implemented.\n"),
-		prog_out__write_context(Context),
-		io__write_string("  Variable `"),
-		mercury_output_var(Var, VarSet, no),
-		io__write_string("' has instantiatedness `"),
-		output_inst(VarInst, ModeInfo),
-		io__write_string("',\n"),
-		prog_out__write_context(Context),
-		io__write_string("  expected instantiatedness was `"),
-		output_inst(Inst, ModeInfo),
-		io__write_string("'.\n")
+report_mode_error_implied_mode(ModeInfo, Var, VarInst, Inst, !IO) :-
+        % This "error" message is really a "sorry, not implemented" message.
+        % We only print the message if we will actually generating code.
+    globals__io_lookup_bool_option(errorcheck_only, ErrorcheckOnly, !IO),
+    (
+        ErrorcheckOnly = no,
+        mode_info_get_context(ModeInfo, Context),
+        mode_info_get_varset(ModeInfo, VarSet),
+        mode_info_write_context(ModeInfo, !IO),
+        Pieces = [words("sorry, implied modes not implemented."), nl,
+            words("Variable"),
+            words(add_quotes(mercury_var_to_string(Var, VarSet, no))),
+            words("has instantiatedness"),
+            words(add_quotes(inst_to_string(ModeInfo, VarInst))),
+            suffix(","), nl,
+            words("expected instantiatedness was"),
+            words(add_quotes(inst_to_string(ModeInfo, Inst))),
+            suffix("."), nl],
+        write_error_pieces_not_first_line(Context, 0, Pieces, !IO)
 	;
-		[]
+        ErrorcheckOnly = yes
 	).
 
 :- pred report_mode_error_no_mode_decl(mode_info::in, io::di, io::uo) is det.
 
-report_mode_error_no_mode_decl(ModeInfo) -->
-	{ mode_info_get_context(ModeInfo, Context) },
-	mode_info_write_context(ModeInfo),
-	prog_out__write_context(Context),
-	io__write_string("  no mode declaration for called predicate.\n").
+report_mode_error_no_mode_decl(ModeInfo, !IO) :-
+    mode_info_get_context(ModeInfo, Context),
+    mode_info_write_context(ModeInfo, !IO),
+    Pieces = [words("no mode declaration for called predicate."), nl],
+    write_error_pieces_not_first_line(Context, 0, Pieces, !IO).
 
 :- pred report_mode_error_unify_pred(mode_info::in, prog_var::in,
 	mode_error_unify_rhs::in, (type)::in, pred_or_func::in,
@@ -766,52 +761,44 @@
 :- pred report_mode_error_unify_var_var(mode_info::in, prog_var::in,
 	prog_var::in, (inst)::in, (inst)::in, io::di, io::uo) is det.
 
-report_mode_error_unify_var_var(ModeInfo, X, Y, InstX, InstY) -->
-	{ mode_info_get_context(ModeInfo, Context) },
-	{ mode_info_get_varset(ModeInfo, VarSet) },
-	mode_info_write_context(ModeInfo),
-	prog_out__write_context(Context),
-	io__write_string("  mode error in unification of `"),
-	mercury_output_var(X, VarSet, no),
-	io__write_string("' and `"),
-	mercury_output_var(Y, VarSet, no),
-	io__write_string("'.\n"),
-	prog_out__write_context(Context),
-	io__write_string("  Variable `"),
-	mercury_output_var(X, VarSet, no),
-	io__write_string("' has instantiatedness `"),
-	output_inst(InstX, ModeInfo),
-	io__write_string("',\n"),
-	prog_out__write_context(Context),
-	io__write_string("  variable `"),
-	mercury_output_var(Y, VarSet, no),
-	io__write_string("' has instantiatedness `"),
-	output_inst(InstY, ModeInfo),
-	io__write_string("'.\n").
+report_mode_error_unify_var_var(ModeInfo, X, Y, InstX, InstY, !IO) :-
+    mode_info_get_context(ModeInfo, Context),
+    mode_info_get_varset(ModeInfo, VarSet),
+    mode_info_write_context(ModeInfo, !IO),
+    Pieces = [words("mode error in unification of"),
+        words(add_quotes(mercury_var_to_string(X, VarSet, no))),
+        words("and"),
+        words(add_quotes(mercury_var_to_string(Y, VarSet, no))),
+        suffix("."), nl,
+        words("Variable"),
+        words(add_quotes(mercury_var_to_string(X, VarSet, no))),
+        words("has instantiatedness"),
+        words(add_quotes(inst_to_string(ModeInfo, InstX))), suffix(","), nl,
+        words("variable"),
+        words(add_quotes(mercury_var_to_string(Y, VarSet, no))),
+        words("has instantiatedness"),
+        words(add_quotes(inst_to_string(ModeInfo, InstY))), suffix("."), nl],
+    write_error_pieces_not_first_line(Context, 0, Pieces, !IO).
 
 %-----------------------------------------------------------------------------%
 
 :- pred report_mode_error_unify_var_lambda(mode_info::in, prog_var::in,
 	(inst)::in, (inst)::in, io::di, io::uo) is det.
 
-report_mode_error_unify_var_lambda(ModeInfo, X, InstX, InstY) -->
-	{ mode_info_get_context(ModeInfo, Context) },
-	{ mode_info_get_varset(ModeInfo, VarSet) },
-	mode_info_write_context(ModeInfo),
-	prog_out__write_context(Context),
-	io__write_string("  mode error in unification of `"),
-	mercury_output_var(X, VarSet, no),
-	io__write_string("' and lambda expression.\n"),
-	prog_out__write_context(Context),
-	io__write_string("  Variable `"),
-	mercury_output_var(X, VarSet, no),
-	io__write_string("' has instantiatedness `"),
-	output_inst(InstX, ModeInfo),
-	io__write_string("',\n"),
-	prog_out__write_context(Context),
-	io__write_string("  lambda expression has instantiatedness `"),
-	output_inst(InstY, ModeInfo),
-	io__write_string("'.\n").
+report_mode_error_unify_var_lambda(ModeInfo, X, InstX, InstY, !IO) :-
+    mode_info_get_context(ModeInfo, Context),
+    mode_info_get_varset(ModeInfo, VarSet),
+    mode_info_write_context(ModeInfo, !IO),
+    Pieces = [words("mode error in unification of"),
+        words(add_quotes(mercury_var_to_string(X, VarSet, no))),
+        words("and lambda expression."), nl,
+        words("Variable"),
+        words(add_quotes(mercury_var_to_string(X, VarSet, no))),
+        words("has instantiatedness"),
+        words(add_quotes(inst_to_string(ModeInfo, InstX))), suffix(","), nl,
+        words("lambda expression has instantiatedness"),
+        words(add_quotes(inst_to_string(ModeInfo, InstY))), suffix("."), nl],
+    write_error_pieces_not_first_line(Context, 0, Pieces, !IO).
 
 %-----------------------------------------------------------------------------%
 
@@ -861,63 +848,58 @@
 
 :- pred mode_info_write_context(mode_info::in, io::di, io::uo) is det.
 
-mode_info_write_context(ModeInfo) -->
-	{ mode_info_get_module_info(ModeInfo, ModuleInfo) },
-	{ mode_info_get_context(ModeInfo, Context) },
-	{ mode_info_get_predid(ModeInfo, PredId) },
-	{ mode_info_get_procid(ModeInfo, ProcId) },
-	{ module_info_pred_proc_info(ModuleInfo, PredId, ProcId,
-		PredInfo, ProcInfo) },
-	{ PredOrFunc = pred_info_is_pred_or_func(PredInfo) },
-	{ pred_info_get_markers(PredInfo, PredMarkers) },
-	{ proc_info_declared_argmodes(ProcInfo, Modes0) },
-	{ strip_builtin_qualifiers_from_mode_list(Modes0, Modes) },
-	{ Name0 = pred_info_name(PredInfo) },
-	{ Name = unqualified(Name0) },
-	{ mode_info_get_instvarset(ModeInfo, InstVarSet) },
-	{ MaybeDet = no },
+mode_info_write_context(ModeInfo, !IO) :-
+    mode_info_get_module_info(ModeInfo, ModuleInfo),
+    mode_info_get_context(ModeInfo, Context),
+    mode_info_get_predid(ModeInfo, PredId),
+    mode_info_get_procid(ModeInfo, ProcId),
+    module_info_pred_proc_info(ModuleInfo, PredId, ProcId,
+        PredInfo, ProcInfo),
+    PredOrFunc = pred_info_is_pred_or_func(PredInfo),
+    pred_info_get_markers(PredInfo, PredMarkers),
+    proc_info_declared_argmodes(ProcInfo, Modes0),
+    strip_builtin_qualifiers_from_mode_list(Modes0, Modes),
+    Name0 = pred_info_name(PredInfo),
+    Name = unqualified(Name0),
+    mode_info_get_instvarset(ModeInfo, InstVarSet),
+    MaybeDet = no,
 
-	prog_out__write_context(Context),
-	io__write_string("In clause for `"),
+    prog_out__write_context(Context, !IO),
+    io__write_string("In clause for `", !IO),
 	mercury_output_mode_subdecl(PredOrFunc, InstVarSet, Name, Modes,
-				MaybeDet, Context),
-	io__write_string("':\n"),
-	{ mode_info_get_mode_context(ModeInfo, ModeContext) },
-	write_mode_context(ModeContext, Context, PredMarkers, ModuleInfo).
+        MaybeDet, Context, !IO),
+    io__write_string("':\n", !IO),
+    mode_info_get_mode_context(ModeInfo, ModeContext),
+    write_mode_context(ModeContext, Context, PredMarkers, !IO).
 
 %-----------------------------------------------------------------------------%
 
 :- pred report_mode_error_final_inst(mode_info::in, int::in, prog_var::in,
 	(inst)::in, (inst)::in, final_inst_error::in, io::di, io::uo) is det.
 
-report_mode_error_final_inst(ModeInfo, ArgNum, Var, VarInst, Inst, Reason) -->
-	{ mode_info_get_context(ModeInfo, Context) },
-	{ mode_info_get_varset(ModeInfo, VarSet) },
-	mode_info_write_context(ModeInfo),
-	prog_out__write_context(Context),
-	io__write_string("  mode error: argument "),
-	io__write_int(ArgNum),
-	( { Reason = too_instantiated } ->
-		io__write_string(" became too instantiated")
-	; { Reason = not_instantiated_enough } ->
-		io__write_string(" did not get sufficiently instantiated")
+report_mode_error_final_inst(ModeInfo, ArgNum, Var, VarInst, Inst, Reason,
+        !IO) :-
+    mode_info_get_context(ModeInfo, Context),
+    mode_info_get_varset(ModeInfo, VarSet),
+    mode_info_write_context(ModeInfo, !IO),
+    ( Reason = too_instantiated ->
+        Problem = " became too instantiated."
+    ; Reason = not_instantiated_enough ->
+        Problem = "did not get sufficiently instantiated."
 	;
 		% I don't think this can happen.  But just in case...
-		io__write_string(" had the wrong instantiatedness")
+        Problem = "had the wrong instantiatedness."
 	),
-	io__write_string(".\n"),
-
-	prog_out__write_context(Context),
-	io__write_string("  Final instantiatedness of `"),
-	mercury_output_var(Var, VarSet, no),
-	io__write_string("' was `"),
-	output_inst(VarInst, ModeInfo),
-	io__write_string("',\n"),
-
-	prog_out__write_context(Context),
-	io__write_string("  expected final instantiatedness was `"),
-	output_inst(Inst, ModeInfo),
-	io__write_string("'.\n").
+    Pieces = [words("mode error: argument"), fixed(int_to_string(ArgNum)),
+        words(Problem), nl,
+        words("Final instantiatedness of"),
+        words(add_quotes(mercury_var_to_string(Var, VarSet, no))),
+        words("was"), words(add_quotes(inst_to_string(ModeInfo, VarInst))),
+        suffix(","), nl,
+        words("expected final instantiatedness was"),
+        words(add_quotes(inst_to_string(ModeInfo, Inst))),
+        suffix("."), nl],
+    write_error_pieces_not_first_line(Context, 0, Pieces, !IO).
 
 %-----------------------------------------------------------------------------%
 
@@ -927,205 +909,257 @@
 
 	% XXX some parts of the mode context never get set up
 
-:- pred write_mode_context(mode_context::in, prog_context::in, pred_markers::in,
-	module_info::in, io::di, io::uo) is det.
-write_mode_context(uninitialized, _Context, _Markers, _ModuleInfo) -->
-	[].
-write_mode_context(call(CallId, ArgNum), Context, Markers, _ModuleInfo) -->
-	prog_out__write_context(Context),
-	io__write_string("  in "),
-	hlds_out__write_call_arg_id(CallId, ArgNum, Markers),
-	io__write_string(":\n").
-write_mode_context(unify(UnifyContext, _Side), Context, _Markers,
-		_ModuleInfo) -->
-	hlds_out__write_unify_context(UnifyContext, Context).
+:- pred write_mode_context(mode_context::in, prog_context::in,
+    pred_markers::in, io::di, io::uo) is det.
+
+write_mode_context(uninitialized, _Context, _Markers, !IO).
+write_mode_context(call(CallId, ArgNum), Context, Markers, !IO) :-
+    prog_out__write_context(Context, !IO),
+    io__write_string("  in ", !IO),
+    hlds_out__write_call_arg_id(CallId, ArgNum, Markers, !IO),
+    io__write_string(":\n", !IO).
+write_mode_context(unify(UnifyContext, _Side), Context, _Markers, !IO) :-
+    hlds_out__write_unify_context(UnifyContext, Context, !IO).
 
 %-----------------------------------------------------------------------------%
 
-maybe_report_error_no_modes(PredId, PredInfo, ModuleInfo) -->
-	{ pred_info_import_status(PredInfo, ImportStatus) },
-	( { ImportStatus = local } ->
-		globals__io_lookup_bool_option(infer_modes, InferModesOpt),
-		( { InferModesOpt = yes } ->
-			[]
+maybe_report_error_no_modes(PredId, PredInfo, ModuleInfo, !IO) :-
+    pred_info_import_status(PredInfo, ImportStatus),
+    ( ImportStatus = local ->
+        globals__io_lookup_bool_option(infer_modes, InferModesOpt, !IO),
+        (
+            InferModesOpt = yes
 		;
-			io__set_exit_status(1),
-			{ pred_info_context(PredInfo, Context) },
-			prog_out__write_context(Context),
-			io__write_string("Error: no mode declaration for "),
-			hlds_out__write_pred_id(ModuleInfo, PredId),
-			io__write_string(".\n"),
-			globals__io_lookup_bool_option(verbose_errors,
-				VerboseErrors),
-			( { VerboseErrors = yes } ->
-				prog_out__write_context(Context),
-				io__write_string(
-			"  (Use `--infer-modes' to enable mode inference.)\n")
+            InferModesOpt = no,
+            io__set_exit_status(1, !IO),
+            pred_info_context(PredInfo, Context),
+            Pieces1 = [words("Error: no mode declaration for")] ++
+                describe_one_pred_name(ModuleInfo, should_module_qualify,
+                    PredId) ++ [suffix("."), nl],
+            globals__io_lookup_bool_option(verbose_errors, VerboseErrors, !IO),
+            (
+                VerboseErrors = yes,
+                Pieces2 = [words("(Use `--infer-modes'"),
+                    words("to enable mode inference.)"), nl]
 			;
-				[]
-			)
+                VerboseErrors = no,
+                Pieces2 = []
+            ),
+            write_error_pieces(Context, 0, Pieces1 ++ Pieces2, !IO)
 		)
 	;
-		io__set_exit_status(1),
-		{ pred_info_context(PredInfo, Context) },
-		prog_out__write_context(Context),
-		io__write_string("Error: no mode declaration for exported\n"),
-		prog_out__write_context(Context),
-		io__write_string("  "),
-		hlds_out__write_pred_id(ModuleInfo, PredId),
-		io__write_string(".\n")
+        io__set_exit_status(1, !IO),
+        pred_info_context(PredInfo, Context),
+        Pieces = [words("Error: no mode declaration for exported")] ++
+            describe_one_pred_name(ModuleInfo, should_module_qualify, PredId)
+            ++ [suffix("."), nl],
+        write_error_pieces(Context, 0, Pieces, !IO)
 	).
 
 %-----------------------------------------------------------------------------%
 
-	% write out the inferred `mode' declarations for a list of pred_ids.
-
-write_mode_inference_messages([], _, _) --> [].
-write_mode_inference_messages([PredId | PredIds], OutputDetism, ModuleInfo) -->
-	{ module_info_pred_info(ModuleInfo, PredId, PredInfo) },
-	{ pred_info_get_markers(PredInfo, Markers) },
-	( { check_marker(Markers, infer_modes) } ->
-		{ ProcIds = pred_info_all_procids(PredInfo) },
-		{ pred_info_procedures(PredInfo, Procs) },
+    % Write out the inferred `mode' declarations for a list of pred_ids.
+    %
+write_mode_inference_messages([], _, _, !IO).
+write_mode_inference_messages([PredId | PredIds], OutputDetism, ModuleInfo,
+        !IO) :-
+    module_info_pred_info(ModuleInfo, PredId, PredInfo),
+    pred_info_get_markers(PredInfo, Markers),
+    ( check_marker(Markers, infer_modes) ->
+        ProcIds = pred_info_all_procids(PredInfo),
+        pred_info_procedures(PredInfo, Procs),
 		write_mode_inference_messages_2(ProcIds, Procs, PredInfo,
-			OutputDetism, ModuleInfo)
+            OutputDetism, ModuleInfo, !IO)
 	;
-		[]
+        true
 	),
-	write_mode_inference_messages(PredIds, OutputDetism, ModuleInfo).
-
-	% write out the inferred `mode' declarations for a list of
-	% proc_ids
+    write_mode_inference_messages(PredIds, OutputDetism, ModuleInfo, !IO).
 
+    % Write out the inferred `mode' declarations for a list of proc_ids.
+    %
 :- pred write_mode_inference_messages_2(list(proc_id)::in, proc_table::in,
 	pred_info::in, bool::in, module_info::in, io::di, io::uo) is det.
 
-write_mode_inference_messages_2([], _, _, _, _) --> [].
+write_mode_inference_messages_2([], _, _, _, _, !IO).
 write_mode_inference_messages_2([ProcId | ProcIds], Procs, PredInfo,
-		OutputDetism, ModuleInfo) -->
-	globals__io_lookup_bool_option(verbose_errors, VerboseErrors),
-	{ map__lookup(Procs, ProcId, ProcInfo) },
+        OutputDetism, ModuleInfo, !IO) :-
+    globals__io_lookup_bool_option(verbose_errors, VerboseErrors, !IO),
+    map__lookup(Procs, ProcId, ProcInfo),
+    (
 	(
-		{
 			% We always output `Inferred :- mode ...'
 			proc_info_is_valid_mode(ProcInfo)
 		;
 			% We only output `REJECTED :- mode ...'
 			% if --verbose-errors is enabled
 			VerboseErrors = yes
-		}
+        )
 	->
 		write_mode_inference_message(PredInfo, ProcInfo, OutputDetism,
-			ModuleInfo)
+            ModuleInfo, !IO)
 	;
-		[]
+        true
 	),
 	write_mode_inference_messages_2(ProcIds, Procs, PredInfo, OutputDetism,
-		ModuleInfo).
-
-	% write out the inferred `mode' declaration
-	% for a single function or predicate.
+        ModuleInfo, !IO).
 
+    % Write out the inferred `mode' declaration for a single function
+    % or predicate..
+    %
 :- pred write_mode_inference_message(pred_info::in, proc_info::in, bool::in,
 	module_info::in, io::di, io::uo) is det.
 
-write_mode_inference_message(PredInfo, ProcInfo, OutputDetism, ModuleInfo) -->
-	{ PredName = pred_info_name(PredInfo) },
-	{ Name = unqualified(PredName) },
-	{ pred_info_context(PredInfo, Context) },
-	{ PredArity = pred_info_orig_arity(PredInfo) },
-	{ proc_info_argmodes(ProcInfo, ArgModes0) },
+write_mode_inference_message(PredInfo, ProcInfo, OutputDetism, ModuleInfo,
+        !IO) :-
+    PredName = pred_info_name(PredInfo),
+    Name = unqualified(PredName),
+    pred_info_context(PredInfo, Context),
+    PredArity = pred_info_orig_arity(PredInfo),
+    some [!ArgModes, !MaybeDet] (
+        proc_info_argmodes(ProcInfo, !:ArgModes),
 
 	% We need to strip off the extra type_info arguments inserted at the
 	% front by polymorphism.m - we only want the last `PredArity' of them.
 	%
-	{ list__length(ArgModes0, NumArgModes) },
-	{ NumToDrop = NumArgModes - PredArity },
-	( { list__drop(NumToDrop, ArgModes0, ArgModes1) } ->
-		{ ArgModes2 = ArgModes1 }
+        list__length(!.ArgModes, NumArgModes),
+        NumToDrop = NumArgModes - PredArity,
+        ( list__drop(NumToDrop, !ArgModes) ->
+            true
 	;
-		{ error("report_pred_proc_id: list__drop failed") }
+            error("report_pred_proc_id: list__drop failed")
 	),
 
-	{ varset__init(VarSet) },
-	{ PredOrFunc = pred_info_is_pred_or_func(PredInfo) },
-	( { OutputDetism = yes } ->
-		{ proc_info_inferred_determinism(ProcInfo, Detism) },
-		{ MaybeDet0 = yes(Detism) }
+        varset__init(VarSet),
+        PredOrFunc = pred_info_is_pred_or_func(PredInfo),
+        (
+            OutputDetism = yes,
+            proc_info_inferred_determinism(ProcInfo, Detism),
+            !:MaybeDet = yes(Detism)
 	;
-		{ MaybeDet0 = no }
+            OutputDetism = no,
+            !:MaybeDet = no
 	),
-	prog_out__write_context(Context),
-	( { proc_info_is_valid_mode(ProcInfo) } ->
-		io__write_string("Inferred "),
-		{ ArgModes3 = ArgModes2 },
-		{ MaybeDet = MaybeDet0 }
+        ( proc_info_is_valid_mode(ProcInfo) ->
+            Msg = "Inferred"
 	;
-		io__write_string("REJECTED "),
+            Msg = "REJECTED",
 		% Replace the final insts with dummy insts '...',
 		% since they won't be valid anyway -- they are just
 		% the results of whatever partial inference we did
 		% before detecting the error.
-		{ mode_list_get_initial_insts(ArgModes2, ModuleInfo,
-			InitialInsts) },
-		{ DummyInst = defined_inst(user_inst(unqualified("..."), [])) },
-		{ list__duplicate(PredArity, DummyInst, FinalInsts) },
-		{ ArgModes3 = list__map(func(I - F) = (I -> F),
-			assoc_list__from_corresponding_lists(
-				InitialInsts, FinalInsts)) },
+            mode_list_get_initial_insts(!.ArgModes, ModuleInfo, InitialInsts),
+            DummyInst = defined_inst(user_inst(unqualified("..."), [])),
+            list__duplicate(PredArity, DummyInst, FinalInsts),
+            !:ArgModes = list__map(func(I - F) = (I -> F),
+                assoc_list.from_corresponding_lists(InitialInsts, FinalInsts)),
 		% Likewise delete the determinism.
-		{ MaybeDet = no }
+            !:MaybeDet = no
 	),
-	{ strip_builtin_qualifiers_from_mode_list(ArgModes3, ArgModes) },
-	(	{ PredOrFunc = predicate },
-		mercury_output_pred_mode_decl(VarSet, Name, ArgModes,
-				MaybeDet, Context)
-	;	{ PredOrFunc = function },
-		{ pred_args_to_func_args(ArgModes, FuncArgModes, RetMode) },
-		mercury_output_func_mode_decl(VarSet, Name, FuncArgModes,
-				RetMode, MaybeDet, Context)
+        strip_builtin_qualifiers_from_mode_list(!ArgModes),
+        (
+            PredOrFunc = predicate,
+            Detail = mercury_pred_mode_decl_to_string(VarSet, Name,
+                !.ArgModes, !.MaybeDet, Context)
+        ;
+            PredOrFunc = function,
+            pred_args_to_func_args(!.ArgModes, FuncArgModes, RetMode),
+            Detail = mercury_func_mode_decl_to_string(VarSet, Name,
+                FuncArgModes, RetMode, !.MaybeDet, Context)
+        ),
+        Pieces = [words(Msg), words(Detail), nl],
+        write_error_pieces(Context, 0, Pieces, !IO)
 	).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-        % If there were any errors recorded in the mode_info,
-        % report them to the user now.
-
 report_mode_errors(!ModeInfo, !IO) :-
         mode_info_get_errors(!.ModeInfo, Errors),
-        ( Errors = [FirstError | _] ->	% XXX Why do we only report the first?
-                FirstError = mode_error_info(_, ModeError, Context,
-			ModeContext),
+    (
+        Errors = [FirstError | _],
+        % XXX Why do we only report the first?
+        FirstError = mode_error_info(_, ModeError, Context, ModeContext),
                 mode_info_set_context(Context, !ModeInfo),
                 mode_info_set_mode_context(ModeContext, !ModeInfo),
                 report_mode_error(ModeError, !.ModeInfo, !IO)
         ;
-                true
+        Errors = []
         ).
 
 %-----------------------------------------------------------------------------%
 
+report_indistinguishable_modes_error(OldProcId, NewProcId, PredId, PredInfo,
+        ModuleInfo, !IO) :-
+    io__set_exit_status(1, !IO),
+
+    pred_info_procedures(PredInfo, Procs),
+    map__lookup(Procs, OldProcId, OldProcInfo),
+    map__lookup(Procs, NewProcId, NewProcInfo),
+    proc_info_context(OldProcInfo, OldContext),
+    proc_info_context(NewProcInfo, NewContext),
+
+    Pieces1 = [words("In mode declarations for ")] ++
+        describe_one_pred_name(ModuleInfo, should_module_qualify, PredId)
+        ++ [suffix(":"), nl, words("error: duplicate mode declaration."), nl],
+    write_error_pieces(NewContext, 0, Pieces1, !IO),
+
+    globals__io_lookup_bool_option(verbose_errors, VerboseErrors, !IO),
+    (
+        VerboseErrors = yes,
+        Pieces2 = [words("Modes"),
+            fixed(add_quotes(mode_decl_to_string(OldProcId, PredInfo))),
+            words("and"),
+            fixed(add_quotes(mode_decl_to_string(NewProcId, PredInfo))),
+            words("are indistinguishable.")],
+        write_error_pieces_not_first_line(NewContext, 0, Pieces2, !IO)
+    ;
+        VerboseErrors = no
+    ),
+
+    Pieces3 = [words("Here is the conflicting mode declaration.")],
+    write_error_pieces_not_first_line(OldContext, 0, Pieces3, !IO).
+
+%-----------------------------------------------------------------------------%
+
+output_mode_decl(ProcId, PredInfo, !IO) :-
+    io__write_string(mode_decl_to_string(ProcId, PredInfo), !IO).
+
+mode_decl_to_string(ProcId, PredInfo) = String :-
+    PredOrFunc = pred_info_is_pred_or_func(PredInfo),
+    Name0 = pred_info_name(PredInfo),
+    Name = unqualified(Name0),
+    pred_info_procedures(PredInfo, Procs),
+    map__lookup(Procs, ProcId, ProcInfo),
+    proc_info_declared_argmodes(ProcInfo, Modes0),
+    proc_info_declared_determinism(ProcInfo, MaybeDet),
+    proc_info_context(ProcInfo, Context),
+    varset__init(InstVarSet),
+    strip_builtin_qualifiers_from_mode_list(Modes0, Modes),
+    String = mercury_mode_subdecl_to_string(PredOrFunc, InstVarSet, Name,
+        Modes, MaybeDet, Context).
+
 :- pred output_inst((inst)::in, mode_info::in, io::di, io::uo) is det.
 
 output_inst(Inst0, ModeInfo, !IO) :-
+    io__write_string(inst_to_string(ModeInfo, Inst0), !IO).
+
+:- func inst_to_string(mode_info, (inst)) = string.
+
+inst_to_string(ModeInfo, Inst0) = Str :-
 	strip_builtin_qualifiers_from_inst(Inst0, Inst),
 	mode_info_get_instvarset(ModeInfo, InstVarSet),
 	mode_info_get_module_info(ModeInfo, ModuleInfo),
-	mercury_output_expanded_inst(Inst, InstVarSet, ModuleInfo, !IO).
+    Str = mercury_expanded_inst_to_string(Inst, InstVarSet, ModuleInfo).
 
 :- pred output_inst_list(list(inst)::in, mode_info::in, io::di, io::uo) is det.
 
-output_inst_list([], _, !IO).
-output_inst_list([Inst | Insts], ModeInfo, !IO) :-
-	output_inst(Inst, ModeInfo, !IO),
-	(
-		Insts = []
-	;
-		Insts = [_ | _],
-		io__write_string(", ", !IO),
-		output_inst_list(Insts, ModeInfo, !IO)
-	).
+output_inst_list(Insts, ModeInfo, !IO) :-
+    io__write_string(inst_list_to_string(ModeInfo, Insts), !IO).
+
+:- func inst_list_to_string(mode_info, list(inst)) = string.
+
+inst_list_to_string(ModeInfo, Insts) =
+    string__join_list(", ", list__map(inst_to_string(ModeInfo), Insts)).
 
 :- pred output_inst_list_sep_lines(prog_context::in, list(inst)::in,
 	mode_info::in, io::di, io::uo) is det.
@@ -1144,62 +1178,26 @@
 	io__nl(!IO),
 	output_inst_list_sep_lines(Context, Insts, ModeInfo, !IO).
 
-%-----------------------------------------------------------------------------%
-
-report_indistinguishable_modes_error(OldProcId, NewProcId,
-		PredId, PredInfo, ModuleInfo) -->
-
-	io__set_exit_status(1),
+:- func inst_list_to_sep_lines(mode_info, list(inst)) = list(format_component).
 
-	{ pred_info_procedures(PredInfo, Procs) },
-	{ map__lookup(Procs, OldProcId, OldProcInfo) },
-	{ map__lookup(Procs, NewProcId, NewProcInfo) },
-	{ proc_info_context(OldProcInfo, OldContext) },
-	{ proc_info_context(NewProcInfo, NewContext) },
-
-	prog_out__write_context(NewContext),
-	io__write_string("In mode declarations for "),
-	hlds_out__write_pred_id(ModuleInfo, PredId),
-	io__write_string(":\n"),
-
-	prog_out__write_context(NewContext),
-	io__write_string("  error: duplicate mode declaration.\n"),
-
-	globals__io_lookup_bool_option(verbose_errors, VerboseErrors),
-	( { VerboseErrors = yes } ->
-		prog_out__write_context(NewContext),
-		io__write_string("  Modes `"),
-		output_mode_decl(OldProcId, PredInfo),
-		io__write_string("'\n"),
-
-		prog_out__write_context(NewContext),
-		io__write_string("  and `"),
-		output_mode_decl(NewProcId, PredInfo),
-		io__write_string("'\n"),
-
-		prog_out__write_context(NewContext),
-		io__write_string("  are indistinguishable.\n")
+inst_list_to_sep_lines(_ModeInfo, []) = [].
+inst_list_to_sep_lines(ModeInfo, [Inst | Insts]) = Pieces ++ MorePieces :-
+    (
+        Insts = [],
+        Comma = [],
+        Newline = nl_indent_delta(-1)
 	;
-		[]
+        Insts = [_ | _],
+        Comma = [suffix(",")],
+        Newline = nl
 	),
+    Pieces = [words(inst_to_string(ModeInfo, Inst))] ++ Comma ++ [Newline],
+    MorePieces = inst_list_to_sep_lines(ModeInfo, Insts).
 
-	prog_out__write_context(OldContext),
-	io__write_string(
-		"  Here is the conflicting mode declaration.\n").
+%-----------------------------------------------------------------------------%
 
-output_mode_decl(ProcId, PredInfo, !IO) :-
-	PredOrFunc = pred_info_is_pred_or_func(PredInfo),
-	Name0 = pred_info_name(PredInfo),
-	Name = unqualified(Name0),
-	pred_info_procedures(PredInfo, Procs),
-	map__lookup(Procs, ProcId, ProcInfo),
-	proc_info_declared_argmodes(ProcInfo, Modes0),
-	proc_info_declared_determinism(ProcInfo, MaybeDet),
-	proc_info_context(ProcInfo, Context),
-	varset__init(InstVarSet),
-	strip_builtin_qualifiers_from_mode_list(Modes0, Modes),
-	mercury_output_mode_subdecl(PredOrFunc, InstVarSet, Name, Modes,
-		MaybeDet, Context, !IO).
+:- func this_file = string.
+
+this_file = "mode_errors.m".
 
-%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: compiler/modes.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modes.m,v
retrieving revision 1.306
diff -u -b -r1.306 modes.m
--- compiler/modes.m	14 Aug 2005 18:33:55 -0000	1.306
+++ compiler/modes.m	17 Aug 2005 05:55:19 -0000
@@ -3086,14 +3086,13 @@
             mode_info_may_initialise_solver_vars(!.ModeInfo),
             type_util__type_is_solver_type(ModuleInfo0, VarType)
         ->
-            % Create code to initialize the variable to
-            % inst `any', by calling the solver type's
-            % initialisation predicate.
+            % Create code to initialize the variable to inst `any',
+            % by calling the solver type's initialisation predicate.
             insert_extra_initialisation_call(Var, VarType, InitialInst,
                 Context, CallUnifyContext, !ExtraGoals, !ModeInfo)
         ;
-            % If the type is a type variable,
-            % or isn't a solver type then give up.
+            % If the type is a type variable, or isn't a solver type
+            % then give up.
             set__singleton_set(WaitingVars, Var0),
             mode_info_error(WaitingVars,
                 mode_error_implied_mode(Var0, VarInst0, InitialInst),
@@ -3102,7 +3101,7 @@
     ;
         inst_is_bound(ModuleInfo0, InitialInst)
     ->
-        % This is the case we can't handle
+        % This is the case we can't handle.
         Var = Var0,
         set__singleton_set(WaitingVars, Var0),
         mode_info_error(WaitingVars,
@@ -3111,19 +3110,19 @@
         % This is the simple case of implied modes,
         % where the declared mode was free -> ...
 
-        % Introduce a new variable
+        % Introduce a new variable.
         mode_info_get_varset(!.ModeInfo, VarSet0),
         varset__new_var(VarSet0, Var, VarSet),
         map__set(VarTypes0, Var, VarType, VarTypes),
         mode_info_set_varset(VarSet, !ModeInfo),
         mode_info_set_var_types(VarTypes, !ModeInfo),
 
-        % Construct the code to do the unification
+        % Construct the code to do the unification.
         modecheck_unify__create_var_var_unification(Var0, Var,
             VarType, !.ModeInfo, ExtraGoal),
 
-        % append the goals together in the appropriate order:
-        % ExtraGoals0, then NewUnify
+        % Append the goals together in the appropriate order:
+        % ExtraGoals0, then NewUnify.
         NewUnifyExtraGoal = extra_goals([], [ExtraGoal]),
         append_extra_goals(!.ExtraGoals, NewUnifyExtraGoal, !:ExtraGoals)
     ).
Index: compiler/state_var.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/state_var.m,v
retrieving revision 1.2
diff -u -b -r1.2 state_var.m
--- compiler/state_var.m	12 Aug 2005 02:33:09 -0000	1.2
+++ compiler/state_var.m	17 Aug 2005 14:53:36 -0000
@@ -1030,8 +1030,7 @@
 
 report_illegal_state_var_update(Context, VarSet, StateVar, !IO) :-
     Name = varset__lookup_name(VarSet, StateVar),
-    % XXX: why the nl here?
-    Pieces = [nl, words("Error: cannot use"), fixed("!:" ++ Name),
+    Pieces = [words("Error: cannot use"), fixed("!:" ++ Name),
         words("in this context;"), nl,
         words("however"), fixed("!." ++ Name), words("may be used here.")],
     write_error_pieces(Context, 0, Pieces, !IO),
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing slice
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
Index: tests/invalid/aditi_update_mode_errors.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/aditi_update_mode_errors.err_exp,v
retrieving revision 1.10
diff -u -b -r1.10 aditi_update_mode_errors.err_exp
--- tests/invalid/aditi_update_mode_errors.err_exp	8 Aug 2005 02:33:16 -0000	1.10
+++ tests/invalid/aditi_update_mode_errors.err_exp	17 Aug 2005 14:24:02 -0000
@@ -48,64 +48,97 @@
 aditi_update_mode_errors.m:105:   this scope.
 aditi_update_mode_errors.m:053: In clause for `aditi_update_modes1((aditi.aditi_di), (aditi.aditi_uo))':
 aditi_update_mode_errors.m:053:   in argument 2 of the inserted tuple of `aditi_insert' of predicate `aditi_update_mode_errors.p/3':
-aditi_update_mode_errors.m:053:   mode error: variable `V_4' has instantiatedness `free',
+aditi_update_mode_errors.m:053:   mode error: variable `V_4' has
+aditi_update_mode_errors.m:053:   instantiatedness `free',
 aditi_update_mode_errors.m:053:   expected instantiatedness was `ground'.
 aditi_update_mode_errors.m:056: In clause for `aditi_update_modes2((aditi.aditi_di), (aditi.aditi_uo))':
 aditi_update_mode_errors.m:056:   in argument 2 of the inserted tuple of `aditi_insert' of function `aditi_update_mode_errors.q/2':
-aditi_update_mode_errors.m:056:   mode error: variable `V_4' has instantiatedness `free',
+aditi_update_mode_errors.m:056:   mode error: variable `V_4' has
+aditi_update_mode_errors.m:056:   instantiatedness `free',
 aditi_update_mode_errors.m:056:   expected instantiatedness was `ground'.
 aditi_update_mode_errors.m:059: In clause for `aditi_update_modes3((aditi.aditi_di), (aditi.aditi_uo))':
 aditi_update_mode_errors.m:059:   in argument 2 of `aditi_insert' of predicate `aditi_update_mode_errors.p/3':
-aditi_update_mode_errors.m:059:   mode error: variable `V_4' has instantiatedness `free',
+aditi_update_mode_errors.m:059:   mode error: variable `V_4' has
+aditi_update_mode_errors.m:059:   instantiatedness `free',
 aditi_update_mode_errors.m:059:   expected instantiatedness was `ground'.
 aditi_update_mode_errors.m:062: In clause for `aditi_update_modes4((aditi.aditi_di), (aditi.aditi_uo))':
 aditi_update_mode_errors.m:062:   in argument 1 of call to predicate `int.</2':
-aditi_update_mode_errors.m:062:   mode error: variable `X' has instantiatedness `free',
+aditi_update_mode_errors.m:062:   mode error: variable `X' has instantiatedness
+aditi_update_mode_errors.m:062:   `free',
 aditi_update_mode_errors.m:062:   expected instantiatedness was `ground'.
 aditi_update_mode_errors.m:065: In clause for `aditi_update_modes5((aditi.aditi_di), (aditi.aditi_uo))':
 aditi_update_mode_errors.m:065:   in argument 1 of call to predicate `int.</2':
-aditi_update_mode_errors.m:065:   mode error: variable `X' has instantiatedness `free',
+aditi_update_mode_errors.m:065:   mode error: variable `X' has instantiatedness
+aditi_update_mode_errors.m:065:   `free',
 aditi_update_mode_errors.m:065:   expected instantiatedness was `ground'.
 aditi_update_mode_errors.m:072: In clause for `aditi_update_modes6((aditi.aditi_di), (aditi.aditi_uo))':
 aditi_update_mode_errors.m:072:   in argument 2 of `aditi_bulk_delete' of predicate `aditi_update_mode_errors.p/3':
-aditi_update_mode_errors.m:072:   mode error: variable `DeleteP' has instantiatedness `/* unique */(pred((free >> free), (free >> ground), (ground >> ground)) is nondet)',
-aditi_update_mode_errors.m:072:   expected instantiatedness was `(pred(in, out, out) is nondet)'.
+aditi_update_mode_errors.m:072:   mode error: variable `DeleteP' has
+aditi_update_mode_errors.m:072:   instantiatedness `/* unique */(pred((free >>
+aditi_update_mode_errors.m:072:   free), (free >> ground), (ground >> ground))
+aditi_update_mode_errors.m:072:   is nondet)',
+aditi_update_mode_errors.m:072:   expected instantiatedness was `(pred(in, out,
+aditi_update_mode_errors.m:072:   out) is nondet)'.
 aditi_update_mode_errors.m:078: In clause for `aditi_update_modes7((aditi.aditi_di), (aditi.aditi_uo))':
 aditi_update_mode_errors.m:078:   in argument 2 of `aditi_bulk_delete' of function `aditi_update_mode_errors.q/2':
-aditi_update_mode_errors.m:078:   mode error: variable `DeleteQ' has instantiatedness `/* unique */(func((free >> free), (free >> ground)) = (ground >> ground) is nondet)',
-aditi_update_mode_errors.m:078:   expected instantiatedness was `(func(in, out) = out is nondet)'.
+aditi_update_mode_errors.m:078:   mode error: variable `DeleteQ' has
+aditi_update_mode_errors.m:078:   instantiatedness `/* unique */(func((free >>
+aditi_update_mode_errors.m:078:   free), (free >> ground)) = (ground >> ground)
+aditi_update_mode_errors.m:078:   is nondet)',
+aditi_update_mode_errors.m:078:   expected instantiatedness was `(func(in, out)
+aditi_update_mode_errors.m:078:   = out is nondet)'.
 aditi_update_mode_errors.m:087: In clause for `aditi_update_modes8((aditi.aditi_di), (aditi.aditi_uo))':
 aditi_update_mode_errors.m:087:   in argument 2 of `aditi_bulk_insert' of predicate `aditi_update_mode_errors.p/3':
-aditi_update_mode_errors.m:087:   mode error: variable `InsertP' has instantiatedness `/* unique */(pred((ground >> ground), (ground >> ground), (free >> ground)) is nondet)',
-aditi_update_mode_errors.m:087:   expected instantiatedness was `(pred(in, out, out) is nondet)'.
+aditi_update_mode_errors.m:087:   mode error: variable `InsertP' has
+aditi_update_mode_errors.m:087:   instantiatedness `/* unique */(pred((ground
+aditi_update_mode_errors.m:087:   >> ground), (ground >> ground), (free >>
+aditi_update_mode_errors.m:087:   ground)) is nondet)',
+aditi_update_mode_errors.m:087:   expected instantiatedness was `(pred(in, out,
+aditi_update_mode_errors.m:087:   out) is nondet)'.
 aditi_update_mode_errors.m:098: In clause for `aditi_update_modes9((aditi.aditi_di), (aditi.aditi_uo))':
 aditi_update_mode_errors.m:098:   in argument 2 of `aditi_bulk_insert' of function `aditi_update_mode_errors.q/2':
-aditi_update_mode_errors.m:098:   mode error: variable `InsertQ' has instantiatedness `/* unique */(func((ground >> ground), (ground >> ground)) = (free >> ground) is nondet)',
-aditi_update_mode_errors.m:098:   expected instantiatedness was `(func(in, out) = out is nondet)'.
+aditi_update_mode_errors.m:098:   mode error: variable `InsertQ' has
+aditi_update_mode_errors.m:098:   instantiatedness `/* unique */(func((ground
+aditi_update_mode_errors.m:098:   >> ground), (ground >> ground)) = (free >>
+aditi_update_mode_errors.m:098:   ground) is nondet)',
+aditi_update_mode_errors.m:098:   expected instantiatedness was `(func(in, out)
+aditi_update_mode_errors.m:098:   = out is nondet)'.
 aditi_update_mode_errors.m:102: In clause for `aditi_update_modes10((aditi.aditi_di), (aditi.aditi_uo))':
 aditi_update_mode_errors.m:102:   in call to function `int.+/2':
-aditi_update_mode_errors.m:102:   mode error: arguments `X0, V_12, V_10'
-aditi_update_mode_errors.m:102:   have the following insts:
+aditi_update_mode_errors.m:102:   mode error: arguments `X0, V_12, V_10' have
+aditi_update_mode_errors.m:102:   the following insts:
 aditi_update_mode_errors.m:102:     free,
 aditi_update_mode_errors.m:102:     unique(1),
 aditi_update_mode_errors.m:102:     free
-aditi_update_mode_errors.m:102:   which does not match any of the modes for function `int.+/2'.
+aditi_update_mode_errors.m:102:   which does not match any of the modes for
+aditi_update_mode_errors.m:102:   function `int.+/2'.
 aditi_update_mode_errors.m:105: In clause for `aditi_update_modes11((aditi.aditi_di), (aditi.aditi_uo))':
 aditi_update_mode_errors.m:105:   in call to function `int.+/2':
-aditi_update_mode_errors.m:105:   mode error: arguments `X0, V_12, V_10'
-aditi_update_mode_errors.m:105:   have the following insts:
+aditi_update_mode_errors.m:105:   mode error: arguments `X0, V_12, V_10' have
+aditi_update_mode_errors.m:105:   the following insts:
 aditi_update_mode_errors.m:105:     free,
 aditi_update_mode_errors.m:105:     unique(1),
 aditi_update_mode_errors.m:105:     free
-aditi_update_mode_errors.m:105:   which does not match any of the modes for function `int.+/2'.
+aditi_update_mode_errors.m:105:   which does not match any of the modes for
+aditi_update_mode_errors.m:105:   function `int.+/2'.
 aditi_update_mode_errors.m:115: In clause for `aditi_update_modes12((aditi.aditi_di), (aditi.aditi_uo))':
 aditi_update_mode_errors.m:115:   in argument 2 of `aditi_bulk_modify' of predicate `aditi_update_mode_errors.p/3':
-aditi_update_mode_errors.m:115:   mode error: variable `ModifyP' has instantiatedness `/* unique */(pred((free >> free), (free >> ground), (free >> ground), (free >> free), (ground >> ground), (ground >> ground)) is semidet)',
-aditi_update_mode_errors.m:115:   expected instantiatedness was `(pred(in, out, out, unused, out, out) is nondet)'.
+aditi_update_mode_errors.m:115:   mode error: variable `ModifyP' has
+aditi_update_mode_errors.m:115:   instantiatedness `/* unique */(pred((free >>
+aditi_update_mode_errors.m:115:   free), (free >> ground), (free >> ground),
+aditi_update_mode_errors.m:115:   (free >> free), (ground >> ground), (ground
+aditi_update_mode_errors.m:115:   >> ground)) is semidet)',
+aditi_update_mode_errors.m:115:   expected instantiatedness was `(pred(in, out,
+aditi_update_mode_errors.m:115:   out, unused, out, out) is nondet)'.
 aditi_update_mode_errors.m:125: In clause for `aditi_update_modes13((aditi.aditi_di), (aditi.aditi_uo))':
 aditi_update_mode_errors.m:125:   in argument 2 of `aditi_bulk_modify' of function `aditi_update_mode_errors.q/2':
-aditi_update_mode_errors.m:125:   mode error: variable `ModifyQ' has instantiatedness `/* unique */(pred((free >> free), (ground >> ground), (ground >> ground), (free >> free), (ground >> ground), (ground >> ground)) is nondet)',
-aditi_update_mode_errors.m:125:   expected instantiatedness was `(pred(in, out, out, unused, out, out) is nondet)'.
+aditi_update_mode_errors.m:125:   mode error: variable `ModifyQ' has
+aditi_update_mode_errors.m:125:   instantiatedness `/* unique */(pred((free >>
+aditi_update_mode_errors.m:125:   free), (ground >> ground), (ground >>
+aditi_update_mode_errors.m:125:   ground), (free >> free), (ground >> ground),
+aditi_update_mode_errors.m:125:   (ground >> ground)) is nondet)',
+aditi_update_mode_errors.m:125:   expected instantiatedness was `(pred(in, out,
+aditi_update_mode_errors.m:125:   out, unused, out, out) is nondet)'.
 aditi_update_mode_errors.m:047: In clause for `anc((aditi.aditi_mui), out, out)':
 aditi_update_mode_errors.m:047:   in argument 2 of clause head:
 aditi_update_mode_errors.m:047:   mode error in unification of `X' and `X'.
Index: tests/invalid/any_should_not_match_bound.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/any_should_not_match_bound.err_exp,v
retrieving revision 1.1
diff -u -b -r1.1 any_should_not_match_bound.err_exp
--- tests/invalid/any_should_not_match_bound.err_exp	25 Jul 2003 02:27:37 -0000	1.1
+++ tests/invalid/any_should_not_match_bound.err_exp	17 Aug 2005 08:31:01 -0000
@@ -1,17 +1,21 @@
 any_should_not_match_bound.m:021: In clause for `test_any_poly(in(any), out)':
 any_should_not_match_bound.m:021:   in argument 1 of call to predicate `any_should_not_match_bound.p/2':
-any_should_not_match_bound.m:021:   mode error: variable `X' has instantiatedness `any',
+any_should_not_match_bound.m:021:   mode error: variable `X' has
+any_should_not_match_bound.m:021:   instantiatedness `any',
 any_should_not_match_bound.m:021:   expected instantiatedness was `ground'.
 any_should_not_match_bound.m:024: In clause for `test_any_tuple(in(any), out)':
 any_should_not_match_bound.m:024:   in argument 1 of call to predicate `any_should_not_match_bound.p/2':
-any_should_not_match_bound.m:024:   mode error: variable `X' has instantiatedness `any',
+any_should_not_match_bound.m:024:   mode error: variable `X' has
+any_should_not_match_bound.m:024:   instantiatedness `any',
 any_should_not_match_bound.m:024:   expected instantiatedness was `ground'.
 any_should_not_match_bound.m:027: In clause for `test_any_du(in(any), out)':
 any_should_not_match_bound.m:027:   in argument 1 of call to predicate `any_should_not_match_bound.p/2':
-any_should_not_match_bound.m:027:   mode error: variable `X' has instantiatedness `any',
+any_should_not_match_bound.m:027:   mode error: variable `X' has
+any_should_not_match_bound.m:027:   instantiatedness `any',
 any_should_not_match_bound.m:027:   expected instantiatedness was `ground'.
 any_should_not_match_bound.m:030: In clause for `test_any_solver(in(any), out)':
 any_should_not_match_bound.m:030:   in argument 1 of call to predicate `any_should_not_match_bound.p/2':
-any_should_not_match_bound.m:030:   mode error: variable `X' has instantiatedness `any',
+any_should_not_match_bound.m:030:   mode error: variable `X' has
+any_should_not_match_bound.m:030:   instantiatedness `any',
 any_should_not_match_bound.m:030:   expected instantiatedness was `ground'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/bind_in_negated.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/bind_in_negated.err_exp,v
retrieving revision 1.2
diff -u -b -r1.2 bind_in_negated.err_exp
--- tests/invalid/bind_in_negated.err_exp	23 Aug 2004 09:53:12 -0000	1.2
+++ tests/invalid/bind_in_negated.err_exp	17 Aug 2005 08:31:02 -0000
@@ -1,6 +1,8 @@
 bind_in_negated.m:014: In clause for `p((bound(f(free, ground)) >> ground), (bound(f(ground, free)) >> ground), out)':
 bind_in_negated.m:014:   scope error: attempt to bind a non-local variable
 bind_in_negated.m:014:   inside the condition of an if-then-else.
-bind_in_negated.m:014:   Variable `A' has instantiatedness `bound(bind_in_negated.f(free, ground))',
-bind_in_negated.m:014:   expected instantiatedness was `bound(bind_in_negated.f(ground, ground))'.
+bind_in_negated.m:014:   Variable `A' has instantiatedness
+bind_in_negated.m:014:   `bound(bind_in_negated.f(free, ground))',
+bind_in_negated.m:014:   expected instantiatedness was
+bind_in_negated.m:014:   `bound(bind_in_negated.f(ground, ground))'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/bind_var_errors.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/bind_var_errors.err_exp,v
retrieving revision 1.4
diff -u -b -r1.4 bind_var_errors.err_exp
--- tests/invalid/bind_var_errors.err_exp	17 Jan 2003 05:57:07 -0000	1.4
+++ tests/invalid/bind_var_errors.err_exp	17 Aug 2005 08:31:03 -0000
@@ -1,5 +1,6 @@
 bind_var_errors.m:033: In clause for `bind_var_in_negation':
-bind_var_errors.m:033:   scope error: attempt to bind a variable inside a negation.
+bind_var_errors.m:033:   scope error: attempt to bind a variable inside a
+bind_var_errors.m:033:   negation.
 bind_var_errors.m:033:   Variable `X' has instantiatedness `free',
 bind_var_errors.m:033:   expected instantiatedness was `unique(42)'.
 bind_var_errors.m:039: In clause for `bind_var_in_ite_cond(in)':
@@ -10,11 +11,12 @@
 bind_var_errors.m:048: In clause for `bind_var_in_lambda':
 bind_var_errors.m:048:   in argument 1 (i.e. the predicate term) of higher-order predicate call:
 bind_var_errors.m:048:   mode error: variable `Y' has instantiatedness `free',
-bind_var_errors.m:048:   expected instantiatedness for non-local variables
-bind_var_errors.m:048:   of lambda goals is `ground'.
+bind_var_errors.m:048:   expected instantiatedness for non-local variables of
+bind_var_errors.m:048:   lambda goals is `ground'.
 bind_var_errors.m:053: In clause for `share_var_in_lambda(di)':
 bind_var_errors.m:053:   in argument 1 of call to predicate `bind_var_errors.destroy/1':
-bind_var_errors.m:053:   mode error: variable `X' has instantiatedness `ground',
+bind_var_errors.m:053:   mode error: variable `X' has instantiatedness
+bind_var_errors.m:053:   `ground',
 bind_var_errors.m:053:   expected instantiatedness was `unique'.
 bind_var_errors.m:060: In clause for `clobber_var_in_lambda(di)':
 bind_var_errors.m:060:   in argument 1 of call to predicate `bind_var_errors.destroy/1':
Index: tests/invalid/constrained_poly_insts.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/constrained_poly_insts.err_exp,v
retrieving revision 1.4
diff -u -b -r1.4 constrained_poly_insts.err_exp
--- tests/invalid/constrained_poly_insts.err_exp	14 Feb 2005 08:26:37 -0000	1.4
+++ tests/invalid/constrained_poly_insts.err_exp	17 Aug 2005 08:31:11 -0000
@@ -10,11 +10,14 @@
 constrained_poly_insts.m:025:   without preceding `func' declaration.
 constrained_poly_insts.m:023: Inferred :- pred q(T1, T1).
 constrained_poly_insts.m:025: Inferred :- func s(T1) = T1.
-constrained_poly_insts.m:006: Error: no mode declaration for exported
-constrained_poly_insts.m:006:   predicate `constrained_poly_insts.p/2'.
+constrained_poly_insts.m:006: Error: no mode declaration for exported predicate
+constrained_poly_insts.m:006:   `constrained_poly_insts.p/2'.
 constrained_poly_insts.m:027: In clause for `t(in((I =< ground)), out((I =< ground)))':
 constrained_poly_insts.m:027:   mode error: argument 2 became too instantiated.
-constrained_poly_insts.m:027:   Final instantiatedness of `HeadVar__2' was `unique(42)',
-constrained_poly_insts.m:027:   expected final instantiatedness was `(I =< ground)'.
-constrained_poly_insts.m:023: Error: no mode declaration for predicate `constrained_poly_insts.q/2'.
+constrained_poly_insts.m:027:   Final instantiatedness of `HeadVar__2' was
+constrained_poly_insts.m:027:   `unique(42)',
+constrained_poly_insts.m:027:   expected final instantiatedness was `(I =<
+constrained_poly_insts.m:027:   ground)'.
+constrained_poly_insts.m:023: Error: no mode declaration for predicate
+constrained_poly_insts.m:023:   `constrained_poly_insts.q/2'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/duplicate_modes.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/duplicate_modes.err_exp,v
retrieving revision 1.8
diff -u -b -r1.8 duplicate_modes.err_exp
--- tests/invalid/duplicate_modes.err_exp	23 Aug 2004 09:53:13 -0000	1.8
+++ tests/invalid/duplicate_modes.err_exp	17 Aug 2005 03:46:29 -0000
@@ -5,21 +5,23 @@
 duplicate_modes.m:001:   `:- import_module' in its interface section(s). This
 duplicate_modes.m:001:   would normally be a `:- pred', `:- func', `:- type',
 duplicate_modes.m:001:   `:- inst' or `:- mode' declaration.
-duplicate_modes.m:008: In mode declarations for predicate `duplicate_modes.q/2':
+duplicate_modes.m:008: In mode declarations for predicate
+duplicate_modes.m:008:   `duplicate_modes.q/2':
 duplicate_modes.m:008:   error: duplicate mode declaration.
-duplicate_modes.m:008:   Modes `q(in, out) is det'
-duplicate_modes.m:008:   and `q((ground >> ground), (free >> ground)) is det'
-duplicate_modes.m:008:   are indistinguishable.
+duplicate_modes.m:008:   Modes `q(in, out) is det' and
+duplicate_modes.m:008:   `q((ground >> ground), (free >> ground)) is det' are
+duplicate_modes.m:008:   indistinguishable.
 duplicate_modes.m:009:   Here is the conflicting mode declaration.
-duplicate_modes.m:008: In mode declarations for predicate `duplicate_modes.q/2':
+duplicate_modes.m:008: In mode declarations for predicate
+duplicate_modes.m:008:   `duplicate_modes.q/2':
 duplicate_modes.m:008:   error: duplicate mode declaration.
-duplicate_modes.m:008:   Modes `q(in, out) is det'
-duplicate_modes.m:008:   and `q((ground >> ground), (free >> ground)) is det'
-duplicate_modes.m:008:   are indistinguishable.
+duplicate_modes.m:008:   Modes `q(in, out) is det' and
+duplicate_modes.m:008:   `q((ground >> ground), (free >> ground)) is det' are
+duplicate_modes.m:008:   indistinguishable.
 duplicate_modes.m:010:   Here is the conflicting mode declaration.
-duplicate_modes.m:014: In mode declarations for predicate `duplicate_modes.r/2':
+duplicate_modes.m:014: In mode declarations for predicate
+duplicate_modes.m:014:   `duplicate_modes.r/2':
 duplicate_modes.m:014:   error: duplicate mode declaration.
-duplicate_modes.m:014:   Modes `r(in, in) is semidet'
-duplicate_modes.m:014:   and `r(in, in) is det'
+duplicate_modes.m:014:   Modes `r(in, in) is semidet' and `r(in, in) is det'
 duplicate_modes.m:014:   are indistinguishable.
 duplicate_modes.m:015:   Here is the conflicting mode declaration.
Index: tests/invalid/ho_default_func_1.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/ho_default_func_1.err_exp,v
retrieving revision 1.4
diff -u -b -r1.4 ho_default_func_1.err_exp
--- tests/invalid/ho_default_func_1.err_exp	25 Apr 2005 08:47:39 -0000	1.4
+++ tests/invalid/ho_default_func_1.err_exp	17 Aug 2005 11:26:27 -0000
@@ -1,9 +1,14 @@
 ho_default_func_1.m:029: In clause for `baz(in, out)':
 ho_default_func_1.m:029:   in call to function `std_util.univ/1':
-ho_default_func_1.m:029:   mode error: arguments `TypeInfo_13, V_7, V_6'
-ho_default_func_1.m:029:   have the following insts:
-ho_default_func_1.m:029:     unique(private_builtin.type_info(unique(<type_ctor_info for .func/0>), unique(2), unique(<type_ctor_info for .int/0>), unique(<type_ctor_info for .int/0>))),
-ho_default_func_1.m:029:     /* unique */(func((free >> ground)) = (ground >> ground) is det),
+ho_default_func_1.m:029:   mode error: arguments `TypeInfo_13, V_7, V_6' have
+ho_default_func_1.m:029:   the following insts:
+ho_default_func_1.m:029:     unique(private_builtin.type_info(unique(<type_ctor_info
+ho_default_func_1.m:029:     for .func/0>), unique(2), unique(<type_ctor_info
+ho_default_func_1.m:029:     for .int/0>), unique(<type_ctor_info for
+ho_default_func_1.m:029:     .int/0>))),
+ho_default_func_1.m:029:     /* unique */(func((free >> ground)) = (ground >>
+ho_default_func_1.m:029:     ground) is det),
 ho_default_func_1.m:029:     free
-ho_default_func_1.m:029:   which does not match any of the modes for function `std_util.univ/1'.
+ho_default_func_1.m:029:   which does not match any of the modes for function
+ho_default_func_1.m:029:   `std_util.univ/1'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/ho_default_func_2.sub.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/ho_default_func_2.sub.err_exp,v
retrieving revision 1.3
diff -u -b -r1.3 ho_default_func_2.sub.err_exp
--- tests/invalid/ho_default_func_2.sub.err_exp	23 Aug 2004 09:53:13 -0000	1.3
+++ tests/invalid/ho_default_func_2.sub.err_exp	17 Aug 2005 08:30:45 -0000
@@ -1,5 +1,7 @@
 ho_default_func_2.sub.m:014: In clause for `baz(out)':
 ho_default_func_2.sub.m:014:   in argument 1 of call to function `ho_default_func_2.id.mkid/1':
-ho_default_func_2.sub.m:014:   mode error: variable `V_2' has instantiatedness `/* unique */(func((free >> ground)) = (ground >> ground) is det)',
+ho_default_func_2.sub.m:014:   mode error: variable `V_2' has instantiatedness
+ho_default_func_2.sub.m:014:   `/* unique */(func((free >> ground)) = (ground
+ho_default_func_2.sub.m:014:   >> ground) is det)',
 ho_default_func_2.sub.m:014:   expected instantiatedness was `ground'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/ho_default_func_3.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/ho_default_func_3.err_exp,v
retrieving revision 1.4
diff -u -b -r1.4 ho_default_func_3.err_exp
--- tests/invalid/ho_default_func_3.err_exp	25 Apr 2005 08:47:39 -0000	1.4
+++ tests/invalid/ho_default_func_3.err_exp	17 Aug 2005 14:24:40 -0000
@@ -1,9 +1,14 @@
 ho_default_func_3.m:029: In clause for `baz(in, out)':
 ho_default_func_3.m:029:   in call to function `std_util.univ/1':
-ho_default_func_3.m:029:   mode error: arguments `TypeInfo_13, V_7, V_6'
-ho_default_func_3.m:029:   have the following insts:
-ho_default_func_3.m:029:     unique(private_builtin.type_info(unique(<type_ctor_info for .func/0>), unique(2), unique(<type_ctor_info for .int/0>), unique(<type_ctor_info for .int/0>))),
-ho_default_func_3.m:029:     /* unique */(func((unique >> clobbered)) = (free >> unique) is det),
+ho_default_func_3.m:029:   mode error: arguments `TypeInfo_13, V_7, V_6' have
+ho_default_func_3.m:029:   the following insts:
+ho_default_func_3.m:029:     unique(private_builtin.type_info(unique(<type_ctor_info
+ho_default_func_3.m:029:     for .func/0>), unique(2), unique(<type_ctor_info
+ho_default_func_3.m:029:     for .int/0>), unique(<type_ctor_info for
+ho_default_func_3.m:029:     .int/0>))),
+ho_default_func_3.m:029:     /* unique */(func((unique >> clobbered)) = (free
+ho_default_func_3.m:029:     >> unique) is det),
 ho_default_func_3.m:029:     free
-ho_default_func_3.m:029:   which does not match any of the modes for function `std_util.univ/1'.
+ho_default_func_3.m:029:   which does not match any of the modes for function
+ho_default_func_3.m:029:   `std_util.univ/1'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/ho_type_mode_bug.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/ho_type_mode_bug.err_exp,v
retrieving revision 1.2
diff -u -b -r1.2 ho_type_mode_bug.err_exp
--- tests/invalid/ho_type_mode_bug.err_exp	13 Jul 1999 08:55:10 -0000	1.2
+++ tests/invalid/ho_type_mode_bug.err_exp	17 Aug 2005 08:31:23 -0000
@@ -1,9 +1,11 @@
 ho_type_mode_bug.m:025: In clause for `my_foldl2((pred(in, in, out) is det), in, in, out, in, out)':
 ho_type_mode_bug.m:025:   in argument 1 (i.e. the predicate term) of higher-order predicate call:
-ho_type_mode_bug.m:025:   mode error: variable `P' has instantiatedness `(pred(in, in, out) is det)',
+ho_type_mode_bug.m:025:   mode error: variable `P' has instantiatedness
+ho_type_mode_bug.m:025:   `(pred(in, in, out) is det)',
 ho_type_mode_bug.m:025:   expecting higher-order pred inst (of arity 5).
 ho_type_mode_bug.m:025: In clause for `my_foldl2((pred(in, in, out) is det), in, in, out, di, uo)':
 ho_type_mode_bug.m:025:   in argument 1 (i.e. the predicate term) of higher-order predicate call:
-ho_type_mode_bug.m:025:   mode error: variable `P' has instantiatedness `(pred(in, in, out) is det)',
+ho_type_mode_bug.m:025:   mode error: variable `P' has instantiatedness
+ho_type_mode_bug.m:025:   `(pred(in, in, out) is det)',
 ho_type_mode_bug.m:025:   expecting higher-order pred inst (of arity 5).
 For more information, try recompiling with `-E'.
Index: tests/invalid/ho_unique_error.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/ho_unique_error.err_exp,v
retrieving revision 1.2
diff -u -b -r1.2 ho_unique_error.err_exp
--- tests/invalid/ho_unique_error.err_exp	14 May 2004 08:40:31 -0000	1.2
+++ tests/invalid/ho_unique_error.err_exp	17 Aug 2005 08:31:24 -0000
@@ -3,6 +3,7 @@
 ho_unique_error.m:007:   state arguments.
 ho_unique_error.m:012: In clause for `call_ho(di, uo)':
 ho_unique_error.m:012:   in argument 3 (i.e. argument 2 of the called predicate) of higher-order predicate call:
-ho_unique_error.m:012:   mode error: variable `DCG_0' has instantiatedness `mostly_unique',
+ho_unique_error.m:012:   mode error: variable `DCG_0' has instantiatedness
+ho_unique_error.m:012:   `mostly_unique',
 ho_unique_error.m:012:   expected instantiatedness was `unique'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/io_in_ite_cond.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/io_in_ite_cond.err_exp,v
retrieving revision 1.8
diff -u -b -r1.8 io_in_ite_cond.err_exp
--- tests/invalid/io_in_ite_cond.err_exp	17 Jan 2003 05:57:08 -0000	1.8
+++ tests/invalid/io_in_ite_cond.err_exp	17 Aug 2005 08:31:29 -0000
@@ -1,5 +1,6 @@
 io_in_ite_cond.m:016: In clause for `main(di, uo)':
 io_in_ite_cond.m:016:   in argument 1 of call to predicate `io_in_ite_cond.foo/2':
-io_in_ite_cond.m:016:   mode error: variable `DCG_0' has instantiatedness `mostly_unique',
+io_in_ite_cond.m:016:   mode error: variable `DCG_0' has instantiatedness
+io_in_ite_cond.m:016:   `mostly_unique',
 io_in_ite_cond.m:016:   expected instantiatedness was `unique'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/merge_ground_any.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/merge_ground_any.err_exp,v
retrieving revision 1.4
diff -u -b -r1.4 merge_ground_any.err_exp
--- tests/invalid/merge_ground_any.err_exp	17 Jan 2003 05:57:08 -0000	1.4
+++ tests/invalid/merge_ground_any.err_exp	17 Aug 2005 08:31:31 -0000
@@ -1,5 +1,9 @@
 merge_ground_any.m:013: In clause for `pass(in, in(merge_ground_any.hpair(ground, any)), out(merge_ground_any.hpair(ground, any)))':
-merge_ground_any.m:013:   mode error: argument 5 did not get sufficiently instantiated.
-merge_ground_any.m:013:   Final instantiatedness of `X' was `bound(merge_ground_any.'+'(ground, ground) ; merge_ground_any.'-'(ground, any))',
-merge_ground_any.m:013:   expected final instantiatedness was `bound(merge_ground_any.'-'(ground, any))'.
+merge_ground_any.m:013:   mode error: argument 5 did not get sufficiently
+merge_ground_any.m:013:   instantiated.
+merge_ground_any.m:013:   Final instantiatedness of `X' was
+merge_ground_any.m:013:   `bound(merge_ground_any.'+'(ground, ground) ;
+merge_ground_any.m:013:   merge_ground_any.'-'(ground, any))',
+merge_ground_any.m:013:   expected final instantiatedness was
+merge_ground_any.m:013:   `bound(merge_ground_any.'-'(ground, any))'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/mode_inf.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/mode_inf.err_exp,v
retrieving revision 1.4
diff -u -b -r1.4 mode_inf.err_exp
--- tests/invalid/mode_inf.err_exp	25 Apr 2005 08:47:39 -0000	1.4
+++ tests/invalid/mode_inf.err_exp	17 Aug 2005 14:24:49 -0000
@@ -1,11 +1,10 @@
 mode_inf.m:009: In clause for `p(out, out)':
 mode_inf.m:009:   in call to predicate `mode_inf.q/2':
-mode_inf.m:009:   mode error: arguments `X, Y'
-mode_inf.m:009:   have the following insts:
+mode_inf.m:009:   mode error: arguments `X, Y' have the following insts:
 mode_inf.m:009:     free,
 mode_inf.m:009:     free
-mode_inf.m:009:   which does not match any of the valid modes for
-mode_inf.m:009:   the callee, because of the following error.
+mode_inf.m:009:   which does not match any of the valid modes for the callee,
+mode_inf.m:009:   because of the following error.
 mode_inf.m:011: In clause for `q(out(not_reached), out(not_reached))':
 mode_inf.m:011:   in argument 2 of clause head:
 mode_inf.m:011:   mode error in unification of `HeadVar__2' and `X'.
Index: tests/invalid/modes_erroneous.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/modes_erroneous.err_exp,v
retrieving revision 1.6
diff -u -b -r1.6 modes_erroneous.err_exp
--- tests/invalid/modes_erroneous.err_exp	22 Apr 2005 08:08:21 -0000	1.6
+++ tests/invalid/modes_erroneous.err_exp	17 Aug 2005 08:31:34 -0000
@@ -1,5 +1,6 @@
 modes_erroneous.m:015: In clause for `p((ground >> ground), (free >> ground))':
 modes_erroneous.m:015:   in argument 1 of call to predicate `modes_erroneous.p/2':
-modes_erroneous.m:015:   mode error: variable `V_5' has instantiatedness `free',
+modes_erroneous.m:015:   mode error: variable `V_5' has instantiatedness
+modes_erroneous.m:015:   `free',
 modes_erroneous.m:015:   expected instantiatedness was `ground'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/mostly_uniq1.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/mostly_uniq1.err_exp,v
retrieving revision 1.12
diff -u -b -r1.12 mostly_uniq1.err_exp
--- tests/invalid/mostly_uniq1.err_exp	14 May 2004 08:40:31 -0000	1.12
+++ tests/invalid/mostly_uniq1.err_exp	17 Aug 2005 08:31:35 -0000
@@ -3,6 +3,7 @@
 mostly_uniq1.m:005:   arguments.
 mostly_uniq1.m:018: In clause for `my_main(di, uo)':
 mostly_uniq1.m:018:   in argument 2 of call to predicate `io.write_int/3':
-mostly_uniq1.m:018:   mode error: variable `DCG_0' has instantiatedness `mostly_unique',
+mostly_uniq1.m:018:   mode error: variable `DCG_0' has instantiatedness
+mostly_uniq1.m:018:   `mostly_unique',
 mostly_uniq1.m:018:   expected instantiatedness was `unique'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/mostly_uniq2.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/mostly_uniq2.err_exp,v
retrieving revision 1.10
diff -u -b -r1.10 mostly_uniq2.err_exp
--- tests/invalid/mostly_uniq2.err_exp	14 May 2004 08:40:31 -0000	1.10
+++ tests/invalid/mostly_uniq2.err_exp	17 Aug 2005 08:31:35 -0000
@@ -3,6 +3,7 @@
 mostly_uniq2.m:005:   arguments.
 mostly_uniq2.m:012: In clause for `foo(di, uo)':
 mostly_uniq2.m:012:   in argument 2 of call to predicate `io.write_int/3':
-mostly_uniq2.m:012:   mode error: variable `DCG_0' has instantiatedness `mostly_unique',
+mostly_uniq2.m:012:   mode error: variable `DCG_0' has instantiatedness
+mostly_uniq2.m:012:   `mostly_unique',
 mostly_uniq2.m:012:   expected instantiatedness was `unique'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/polymorphic_unification.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/polymorphic_unification.err_exp,v
retrieving revision 1.8
diff -u -b -r1.8 polymorphic_unification.err_exp
--- tests/invalid/polymorphic_unification.err_exp	23 Aug 2004 09:53:13 -0000	1.8
+++ tests/invalid/polymorphic_unification.err_exp	17 Aug 2005 08:31:42 -0000
@@ -1,5 +1,8 @@
 polymorphic_unification.m:019: In clause for `p(in, ((list.list_skel) >> dead))':
 polymorphic_unification.m:019:   in polymorphically-typed unification:
-polymorphic_unification.m:019:   mode error: variable `X' has instantiatedness `bound([] ; '[|]'(free, list.list_skel(free)))',
-polymorphic_unification.m:019:   expected instantiatedness was `ground' or `any'.
+polymorphic_unification.m:019:   mode error: variable `X' has instantiatedness
+polymorphic_unification.m:019:   `bound([] ; '[|]'(free,
+polymorphic_unification.m:019:   list.list_skel(free)))',
+polymorphic_unification.m:019:   expected instantiatedness was `ground' or
+polymorphic_unification.m:019:   `any'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/qualified_cons_id2.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/qualified_cons_id2.err_exp,v
retrieving revision 1.5
diff -u -b -r1.5 qualified_cons_id2.err_exp
--- tests/invalid/qualified_cons_id2.err_exp	14 May 2004 08:40:31 -0000	1.5
+++ tests/invalid/qualified_cons_id2.err_exp	17 Aug 2005 03:46:50 -0000
@@ -1,4 +1,5 @@
-qualified_cons_id2.m:015: In mode declarations for predicate `qualified_cons_id2.test/2':
+qualified_cons_id2.m:015: In mode declarations for predicate
+qualified_cons_id2.m:015:   `qualified_cons_id2.test/2':
 qualified_cons_id2.m:015:   error: duplicate mode declaration.
 qualified_cons_id2.m:016:   Here is the conflicting mode declaration.
 qualified_cons_id2.m:015: In `test(in(bound(qualified_cons_id2.yes(ground))),
Index: tests/invalid/state_vars_test4.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/state_vars_test4.err_exp,v
retrieving revision 1.6
diff -u -b -r1.6 state_vars_test4.err_exp
--- tests/invalid/state_vars_test4.err_exp	23 Aug 2004 09:53:13 -0000	1.6
+++ tests/invalid/state_vars_test4.err_exp	17 Aug 2005 08:31:51 -0000
@@ -2,6 +2,9 @@
 state_vars_test4.m:021:   Perhaps you meant !.X or !:X.
 state_vars_test4.m:021: In clause for `f(in) = out':
 state_vars_test4.m:021:   in argument 1 of call to function `list.foldl/3':
-state_vars_test4.m:021:   mode error: variable `V_5' has instantiatedness `free',
-state_vars_test4.m:021:   expected instantiatedness was `(func((ground >> ground), (ground >> ground)) = (free >> ground) is det)'.
+state_vars_test4.m:021:   mode error: variable `V_5' has instantiatedness
+state_vars_test4.m:021:   `free',
+state_vars_test4.m:021:   expected instantiatedness was `(func((ground >>
+state_vars_test4.m:021:   ground), (ground >> ground)) = (free >> ground) is
+state_vars_test4.m:021:   det)'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/state_vars_test5.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/state_vars_test5.err_exp,v
retrieving revision 1.6
diff -u -b -r1.6 state_vars_test5.err_exp
--- tests/invalid/state_vars_test5.err_exp	8 Aug 2005 02:33:16 -0000	1.6
+++ tests/invalid/state_vars_test5.err_exp	17 Aug 2005 08:31:51 -0000
@@ -2,7 +2,9 @@
 state_vars_test5.m:021:   warning: variable `STATE_VARIABLE_X' occurs only once
 state_vars_test5.m:021:   in this scope.
 state_vars_test5.m:021: In clause for `p(out)':
-state_vars_test5.m:021:   mode error: argument 1 did not get sufficiently instantiated.
-state_vars_test5.m:021:   Final instantiatedness of `STATE_VARIABLE_X' was `free',
+state_vars_test5.m:021:   mode error: argument 1 did not get sufficiently
+state_vars_test5.m:021:   instantiated.
+state_vars_test5.m:021:   Final instantiatedness of `STATE_VARIABLE_X' was
+state_vars_test5.m:021:   `free',
 state_vars_test5.m:021:   expected final instantiatedness was `ground'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/undeclared_mode.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/undeclared_mode.err_exp,v
retrieving revision 1.1
diff -u -b -r1.1 undeclared_mode.err_exp
--- tests/invalid/undeclared_mode.err_exp	25 Jul 2003 06:30:08 -0000	1.1
+++ tests/invalid/undeclared_mode.err_exp	17 Aug 2005 03:47:01 -0000
@@ -1,3 +1,4 @@
-undeclared_mode.m:032: Error: no mode declaration for predicate `undeclared_mode.sort_of_factorial/2'.
+undeclared_mode.m:032: Error: no mode declaration for predicate
+undeclared_mode.m:032:   `undeclared_mode.sort_of_factorial/2'.
 undeclared_mode.m:032: Inferred :- mode sort_of_factorial(di, uo).
 For more information, try recompiling with `-E'.
Index: tests/invalid/uniq_modes.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/uniq_modes.err_exp,v
retrieving revision 1.2
diff -u -b -r1.2 uniq_modes.err_exp
--- tests/invalid/uniq_modes.err_exp	17 Jan 2003 05:57:11 -0000	1.2
+++ tests/invalid/uniq_modes.err_exp	17 Aug 2005 08:32:08 -0000
@@ -1,5 +1,6 @@
 uniq_modes.m:012: In clause for `main(di, uo)':
 uniq_modes.m:012:   in argument 2 of call to predicate `io.write/3':
-uniq_modes.m:012:   mode error: variable `In' has instantiatedness `mostly_unique',
+uniq_modes.m:012:   mode error: variable `In' has instantiatedness
+uniq_modes.m:012:   `mostly_unique',
 uniq_modes.m:012:   expected instantiatedness was `unique'.
 For more information, try recompiling with `-E'.
Index: tests/invalid/uniq_neg.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/uniq_neg.err_exp,v
retrieving revision 1.2
diff -u -b -r1.2 uniq_neg.err_exp
--- tests/invalid/uniq_neg.err_exp	17 Jan 2003 05:57:11 -0000	1.2
+++ tests/invalid/uniq_neg.err_exp	17 Aug 2005 08:32:09 -0000
@@ -1,5 +1,6 @@
 uniq_neg.m:025: In clause for `unify(in, in, in, in, di, uo)':
 uniq_neg.m:025:   in argument 3 of call to predicate `uniq_neg.occurs/4':
-uniq_neg.m:025:   mode error: variable `DCG_0' has instantiatedness `mostly_unique',
+uniq_neg.m:025:   mode error: variable `DCG_0' has instantiatedness
+uniq_neg.m:025:   `mostly_unique',
 uniq_neg.m:025:   expected instantiatedness was `unique'.
 For more information, try recompiling with `-E'.
cvs diff: Diffing tests/invalid/purity
Index: tests/invalid/purity/impure_func_t5_fixed.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/purity/impure_func_t5_fixed.err_exp,v
retrieving revision 1.1
diff -u -b -r1.1 impure_func_t5_fixed.err_exp
--- tests/invalid/purity/impure_func_t5_fixed.err_exp	27 Jan 2003 09:21:03 -0000	1.1
+++ tests/invalid/purity/impure_func_t5_fixed.err_exp	17 Aug 2005 14:25:28 -0000
@@ -1,6 +1,8 @@
 impure_func_t5_fixed.m:022: In clause for `main(di, uo)':
 impure_func_t5_fixed.m:022:   in argument 2 (i.e. argument 1 of the called function) of impure higher-order function call:
-impure_func_t5_fixed.m:022:   mode error: variable `V_12' has instantiatedness `free',
+impure_func_t5_fixed.m:022:   mode error: variable `V_12' has instantiatedness
+impure_func_t5_fixed.m:022:   `free',
 impure_func_t5_fixed.m:022:   expected instantiatedness was `ground'.
-impure_func_t5_fixed.m:022:   The goal could not be reordered, because it was impure.
+impure_func_t5_fixed.m:022:   The goal could not be reordered, because it was
+impure_func_t5_fixed.m:022:   impure.
 For more information, try recompiling with `-E'.
Index: tests/invalid/purity/purity.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/purity/purity.err_exp,v
retrieving revision 1.8
diff -u -b -r1.8 purity.err_exp
--- tests/invalid/purity/purity.err_exp	17 Jan 2005 05:01:43 -0000	1.8
+++ tests/invalid/purity/purity.err_exp	17 Aug 2005 14:25:33 -0000
@@ -41,8 +41,8 @@
 purity.m:090:   in argument 1 of call to predicate `purity.in/1':
 purity.m:090:   mode error: variable `X' has instantiatedness `free',
 purity.m:090:   expected instantiatedness was `ground'.
-purity.m:090:   The goal could not be reordered, because
-purity.m:090:   it was followed by an impure goal.
+purity.m:090:   The goal could not be reordered, becaise it was followed by an
+purity.m:090:   impure goal.
 purity.m:091:   This is the location of the impure goal.
 purity.m:097: In clause for `e7':
 purity.m:097:   in argument 1 of call to predicate `purity.imp1/1':
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
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