[m-rev.] diff: move software_error/0 to exception.m

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Dec 20 17:40:09 AEDT 2006


Estimated hours taken: 0.2
Branches: main

Move the type software_error/0 from the require module into the exception
module.  This breaks the (immediate) cyclic dependency between those two
modules (there may still be indirect ones).

library/require.m:
 	Delete the definition of the type software_error/0.

library/exception.m
 	Add the definition here.

 	Replace calls to error/1 with calls to throw/1.

NEWS:
 	Mention this change.

Julien.

Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.432
diff -u -r1.432 NEWS
--- NEWS	18 Dec 2006 13:00:06 -0000	1.432
+++ NEWS	20 Dec 2006 06:38:27 -0000
@@ -37,6 +37,9 @@

  * We have renamed some library predicates whose names were ambiguous.

+* The type software_error/0 has been moved from the require module into
+  the exception module.
+
  Changes to the Mercury compiler:

  * The compiler now issues a warning when an inst declaration is not
Index: library/exception.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/exception.m,v
retrieving revision 1.118
diff -u -r1.118 exception.m
--- library/exception.m	29 Nov 2006 05:18:17 -0000	1.118
+++ library/exception.m	20 Dec 2006 06:29:26 -0000
@@ -31,6 +31,12 @@

  %-----------------------------------------------------------------------------%

+    % Exceptions of this type are used by many parts of the Mercury
+    % implementation to indicate an internal error.
+    %
+:- type software_error
+    --->    software_error(string).
+
      % throw(Exception):
      %   Throw the specified exception.
      %
@@ -205,7 +211,6 @@

  :- implementation.

-:- import_module require.
  :- import_module solutions.
  :- import_module string.
  :- import_module unit.
@@ -288,32 +293,32 @@
  get_determinism(_Pred::(pred(out) is det),
          Det::out(bound(exp_detism_det))) :-
      ( cc_multi_equal(exp_detism_det, Det)
-    ; error("get_determinism")
+    ; throw(software_error("get_determinism"))
      ).
  get_determinism(_Pred::(pred(out) is semidet),
          Det::out(bound(exp_detism_semidet))) :-
      ( cc_multi_equal(exp_detism_semidet, Det)
-    ; error("get_determinism")
+    ; throw(software_error("get_determinism"))
      ).
  get_determinism(_Pred::(pred(out) is cc_multi),
          Det::out(bound(exp_detism_cc_multi))) :-
      ( cc_multi_equal(exp_detism_cc_multi, Det)
-    ; error("get_determinism")
+    ; throw(software_error("get_determinism"))
      ).
  get_determinism(_Pred::(pred(out) is cc_nondet),
          Det::out(bound(exp_detism_cc_nondet))) :-
      ( cc_multi_equal(exp_detism_cc_nondet, Det)
-    ; error("get_determinism")
+    ; throw(software_error("get_determinism"))
      ).
  get_determinism(_Pred::(pred(out) is multi),
          Det::out(bound(exp_detism_multi))) :-
      ( cc_multi_equal(exp_detism_multi, Det)
-    ; error("get_determinism")
+    ; throw(software_error("get_determinism"))
      ).
  get_determinism(_Pred::(pred(out) is nondet),
          Det::out(bound(exp_detism_nondet))) :-
      ( cc_multi_equal(exp_detism_nondet, Det)
-    ; error("get_determinism")
+    ; throw(software_error("get_determinism"))
      ).

  :- pragma promise_equivalent_clauses(get_determinism_2/2).
@@ -321,12 +326,12 @@
  get_determinism_2(_Pred::pred(out, di, uo) is det,
          Det::out(bound(exp_detism_det))) :-
      ( cc_multi_equal(exp_detism_det, Det)
-    ; error("get_determinism_2")
+    ; throw(software_error("get_determinism_2"))
      ).
  get_determinism_2(_Pred::pred(out, di, uo) is cc_multi,
          Det::out(bound(exp_detism_cc_multi))) :-
      ( cc_multi_equal(exp_detism_cc_multi, Det)
-    ; error("get_determinism_2")
+    ; throw(software_error("get_determinism_2"))
      ).

  % These are not worth inlining, since they will (presumably) not be called
@@ -390,7 +395,7 @@
          ->
              rethrow(ExcpResult)
          ;
-            error("exception.finally_2")
+            throw(software_error("exception.finally_2"))
          )
      ).

@@ -534,7 +539,7 @@
  process_one_exception_result(succeeded(S), !MaybeException, !Solutions) :-
      !:Solutions = [S | !.Solutions].
  process_one_exception_result(failed, !MaybeException, !Solutions) :-
-    error("exception.process_one_exception_result: unexpected failure").
+    throw(software_error("process_one_exception_result: unexpected failure")).

  incremental_try_all(Goal, AccPred, !Acc) :-
      WrappedGoal = (pred(R::out) is nondet :-
Index: library/require.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/require.m,v
retrieving revision 1.41
diff -u -r1.41 require.m
--- library/require.m	19 Apr 2006 05:17:55 -0000	1.41
+++ library/require.m	20 Dec 2006 06:25:29 -0000
@@ -18,8 +18,6 @@
  :- module require.
  :- interface.

-:- type software_error ---> software_error(string).
-
      % error(Message):
      %
      % Throw a `software_error(Message)' exception.

--------------------------------------------------------------------------
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