[m-rev.] diff: workaround compiler abort with --errorcheck-only

Julien Fischer juliensf at csse.unimelb.edu.au
Thu Oct 25 14:59:10 AEST 2007


Estimated hours taken: 1.5
Branches: main

Workaround a bug reported by Nick Nethercote where compiling with
`--errorcheck-only' enabled was triggering a sanity check in error_util.
This sanity check required that something was actually printed out if the spec's
severity required something to be printed.  This condition is violated by the
code in mode_errors.m, which generates error specs that have severity error,
but whose messages are all conditional.  (These specs. are used for
--debug-modes.) The sanity check will fail when the message conditions
are all false because then nothing will be printed.
The workaround is to omit the sanity check for the time being.

compiler/error_util.m:
 	Comment out the above sanity check and add an XXX comment
 	explaining why it is commented out.

 	Document the effects of this change on how write_error_spec(s)/6
 	set the exit status.

 	Change an if-then-else into a switch.

tests/invalid/Mmakefile:
tests/invalid/Mercury.options:
tests/invalid/zinc2mer_lib.{m,err_exp}:
 	A regression test for the above bug, derived from Nick's
 	original example.

Julien.

Index: compiler/error_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/error_util.m,v
retrieving revision 1.65
diff -u -r1.65 error_util.m
--- compiler/error_util.m	2 Oct 2007 04:32:48 -0000	1.65
+++ compiler/error_util.m	25 Oct 2007 04:57:12 -0000
@@ -248,6 +248,11 @@
      %
      % Look up option values in the supplied Globals.
      %
+    % If an error spec contains only conditional messages and those conditions
+    % are all false, then nothing will be printed out and the exit status
+    % will not be changed.  This will happen even if the severity means
+    % that something should have been printed out.
+    %
  :- pred write_error_spec(error_spec::in, globals::in, int::in, int::out,
      int::in, int::out, io::di, io::uo) is det.
  :- pred write_error_specs(list(error_spec)::in, globals::in, int::in, int::out,
@@ -606,9 +611,13 @@
      MaybeContextA = project_msg_context(MsgA),
      MaybeContextB = project_msg_context(MsgB),
      compare(ContextResult, MaybeContextA, MaybeContextB),
-    ( ContextResult = (=) ->
+    (
+        ContextResult = (=),
          compare(Result, MsgA, MsgB)
      ;
+        ( ContextResult = (>)
+        ; ContextResult = (<)
+        ),
          Result = ContextResult
      ).

@@ -692,9 +701,15 @@
          !IO),
      MaybeActual = actual_error_severity(Globals, Severity),
      (
-        PrintedSome = no,
-        expect(unify(MaybeActual, no), this_file,
-            "do_write_error_spec: MaybeActual isn't no")
+        PrintedSome = no
+        % XXX the following assertion is commented out because the compiler
+        % can generate error specs that consist only of conditional error
+        % messages whose conditions can all be false (in which case nothing
+        % will be printed.)  Such specs will cause the assertion to fail if
+        % they have a severity that means something *should* have been 
+        % printed out.  Error specs like this are generated by --debug-modes.
+        %expect(unify(MaybeActual, no), this_file,
+        %    "do_write_error_spec: MaybeActual isn't no")
      ;
          PrintedSome = yes,
          (
Index: tests/invalid/Mercury.options
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/Mercury.options,v
retrieving revision 1.25
diff -u -r1.25 Mercury.options
--- tests/invalid/Mercury.options	20 Aug 2007 03:36:20 -0000	1.25
+++ tests/invalid/Mercury.options	25 Oct 2007 04:57:12 -0000
@@ -142,3 +142,6 @@
  MCFLAGS-unsatisfiable_constraint 	= --verbose-error-messages
  MCFLAGS-user_eq_dummy 			= --verbose-error-messages
  MCFLAGS-vars_in_wrong_places 		= --verbose-error-messages
+
+# --verbose-error-messages will mask the problem that zinc2mer_lib checks for.
+MCFLAGS-zinc2mer_lib = --no-verbose-error-messages
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.224
diff -u -r1.224 Mmakefile
--- tests/invalid/Mmakefile	22 Oct 2007 05:10:33 -0000	1.224
+++ tests/invalid/Mmakefile	25 Oct 2007 04:57:12 -0000
@@ -232,7 +232,8 @@
  	user_eq_dummy \
  	uu_type \
  	vars_in_wrong_places \
-	with_type
+	with_type \
+	zinc2mer_lib

  # The following require that num_tag_bits >= 1
  RESERVE_TAG_MODULES = \
Index: tests/invalid/zinc2mer_lib.err_exp
===================================================================
RCS file: tests/invalid/zinc2mer_lib.err_exp
diff -N tests/invalid/zinc2mer_lib.err_exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/zinc2mer_lib.err_exp	25 Oct 2007 04:57:12 -0000
@@ -0,0 +1,10 @@
+zinc2mer_lib.m:037: In `min_split_var'(in(any)) = in(any):
+zinc2mer_lib.m:037:   error: determinism declaration not satisfied.
+zinc2mer_lib.m:037:   Declared `det', inferred `semidet'.
+zinc2mer_lib.m:045:   Unification of `BranchConstraints' and `list.[]' can
+zinc2mer_lib.m:045:   fail.
+zinc2mer_lib.m:034: In clause for `min_domsize_min_split(ia, oa)':
+zinc2mer_lib.m:034:   mode error: argument 2 became too instantiated.
+zinc2mer_lib.m:034:   Final instantiatedness of `HeadVar__2' was `free',
+zinc2mer_lib.m:034:   expected final instantiatedness was `any'.
+For more information, recompile with `-E'.
Index: tests/invalid/zinc2mer_lib.m
===================================================================
RCS file: tests/invalid/zinc2mer_lib.m
diff -N tests/invalid/zinc2mer_lib.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/zinc2mer_lib.m	25 Oct 2007 04:57:12 -0000
@@ -0,0 +1,60 @@
+% When compiled with:
+%
+% 	$ mmc --errorcheck-only zinc2mer_lib.m
+%
+% this module generated the following assertion failure in rotd-2007-10-23:
+%
+% 	Software Error: error_util.m: Unexpected: do_write_error_spec: \
+% 	MaybeActual isn't no
+%
+% This bug was originally reported by Nick Nethercote.  The code here
+% is a cut-down version of his code.
+
+:- module zinc2mer_lib.
+:- interface.
+
+:- import_module list.
+
+:- solver type fdvar.
+
+:- type constraint_expression
+    --->    v(fdvar).
+
+:- pred new_fdvar(fdvar::oa) is det.
+
+:- impure pred min_domsize_min_split(list(fdvar)::ia,
+	list(constraint_expression)::oa) is det.
+
+:- implementation.
+
+:- import_module int.
+:- import_module require.
+
+min_domsize_min_split([], _) :- error("empty list").
+min_domsize_min_split([V | _Vs], BranchConstraints) :-
+    impure BranchConstraints = min_split_var(V).
+
+:- impure func min_split_var(fdvar::ia) = (list(constraint_expression)::ia)
+        is det.
+
+min_split_var(V) = BranchConstraints :-
+    impure get_min_max(V, Min, Max),
+    ( if Min = Max then
+        error("")
+      else
+       	BranchConstraints = [] 
+    ).
+
+:- impure pred get_min_max(fdvar::ia, int::out, int::out) is det.
+
+get_min_max(_, 3, 7) :-
+	impure impure_true.
+
+:- solver type fdvar
+    where   representation  is int,
+            initialisation  is new_fdvar.
+
+new_fdvar(V) :-
+	promise_pure (
+		impure V = 'representation to any fdvar/0'(10)
+	).

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list