[m-rev.] diff: Use error($pred, "...") in more spots in the standard library

Julien Fischer jfischer at opturion.com
Tue Oct 15 17:44:10 AEDT 2019


As discussed on the reviews list recently.

--------------------------

Use error($pred, "...") in more spots in the standard library.

Also, throw software_error/1 exceptions rather than directly throwing strings
in a few spots.

Undo special Ralph-style formatting.

library/*.:
     As above.

tests/hard_coded/array2d_from_array.exp:
tests/hard_coded/array2d.exp:
tests/hard_coded/test_injection.exp:
    Update to conform with the above change.

Julien.

diff --git a/library/array2d.m b/library/array2d.m
index d292543..2391675 100644
--- a/library/array2d.m
+++ b/library/array2d.m
@@ -167,9 +167,10 @@
  %---------------------------------------------------------------------------%

  init(M, N, X) =
-    ( if    M >= 0, N >= 0
-      then  array2d(M, N, array.init(M * N, X))
-      else  func_error("array2d.init: bounds must be non-negative")
+    ( if M >= 0, N >= 0 then
+        array2d(M, N, array.init(M * N, X))
+    else
+        func_error($pred, "bounds must be non-negative")
      ).

  %---------------------------------------------------------------------------%
@@ -179,10 +180,11 @@ array2d(Xss @ [Xs | _]) = T :-
      M = length(Xss),
      N = length(Xs),
      A = array(condense(Xss)),
-    T = ( if    all [Ys] ( member(Ys, Xss) => length(Ys) = N )
-          then  array2d(M, N, A)
-          else  func_error("array2d.array2d/1: non-rectangular list of lists")
-        ).
+    ( if all [Ys] ( member(Ys, Xss) => length(Ys) = N ) then
+        T = array2d(M, N, A)
+    else
+        error($pred,  "non-rectangular list of lists")
+    ).

  from_lists(Xss) = array2d(Xss).

@@ -198,13 +200,13 @@ from_array(M, N, Array) = Array2d :-
              Array2d = array2d(M, N, Array)
          ;
              Result = (>),
-            error("array2d.from_array: too many elements")
+            error($pred, "too many elements")
          ;
              Result = (<),
-            error("array2d.from_array: too few elements")
+            error($pred, "too few elements")
          )
      else
-        error("array2d.from_array: bounds must be non-negative")
+        error($pred, " bounds must be non-negative")
      ).

  %---------------------------------------------------------------------------%
@@ -225,9 +227,10 @@ in_bounds(array2d(M, N, _A), I, J) :-
  %---------------------------------------------------------------------------%

  T ^ elem(I, J) =
-    ( if    in_bounds(T, I, J)
-      then  T ^ unsafe_elem(I, J)
-      else  func_error("array2d.elem: indices out of bounds")
+    ( if in_bounds(T, I, J) then
+        T ^ unsafe_elem(I, J)
+    else
+        func_error($pred, "indices out of bounds")
      ).

  %---------------------------------------------------------------------------%
@@ -237,9 +240,10 @@ array2d(_M, N, A) ^ unsafe_elem(I, J) = A ^ unsafe_elem(I * N + J).
  %---------------------------------------------------------------------------%

  ( T ^ elem(I, J) := X ) =
-    ( if    in_bounds(T, I, J)
-      then  T ^ unsafe_elem(I, J) := X
-      else  func_error("array2d.'elem :=': indices out of bounds")
+    ( if in_bounds(T, I, J) then
+        T ^ unsafe_elem(I, J) := X
+    else
+        func_error("array2d.'elem :=': indices out of bounds")
      ).

  set(I, J, X, A, A ^ elem(I, J) := X).
diff --git a/library/bag.m b/library/bag.m
index 59bba98..cb33c9c 100644
--- a/library/bag.m
+++ b/library/bag.m
@@ -475,7 +475,7 @@ det_insert_duplicates(N, Item, !Bag) :-
      ( if insert_duplicates(N, Item, !Bag) then
          true
      else
-        error("bag.det_insert_duplicates: number of items is negative")
+        error($pred, "number of items is negative")
      ).

  insert_set(!.Bag, Xs) = !:Bag :-
diff --git a/library/bimap.m b/library/bimap.m
index e8a6aaf..cde5435 100644
--- a/library/bimap.m
+++ b/library/bimap.m
@@ -496,9 +496,9 @@ det_insert_from_corresponding_lists(Ks, Vs, !.BM) = !:BM :-

  det_insert_from_corresponding_lists([], [], !BM).
  det_insert_from_corresponding_lists([], [_ | _], !BM) :-
-    error("bimap.det_insert_from_corresponding_lists: length mismatch").
+    error($pred, "length mismatch").
  det_insert_from_corresponding_lists([_ | _], [], !BM) :-
-    error("bimap.det_insert_from_corresponding_lists: length mismatch").
+    error($pred, "length mismatch").
  det_insert_from_corresponding_lists([Key | Keys], [Value | Values],
          !BM) :-
      bimap.det_insert(Key, Value, !BM),
@@ -517,9 +517,9 @@ set_from_corresponding_lists(Ks, Vs, BM0) = BM :-

  set_from_corresponding_lists([], [], !BM).
  set_from_corresponding_lists([], [_ | _], !BM) :-
-    error("bimap.set_from_corresponding_lists: length mismatch").
+    error($pred, "length mismatch").
  set_from_corresponding_lists([_ | _], [], !BM) :-
-    error("bimap.set_from_corresponding_lists: length mismatch").
+    error($pred, "length mismatch").
  set_from_corresponding_lists([Key | Keys], [Value | Values],
          !BM) :-
      bimap.set(Key, Value, !BM),
diff --git a/library/bit_buffer.m b/library/bit_buffer.m
index c82ce01..4162991 100644
--- a/library/bit_buffer.m
+++ b/library/bit_buffer.m
@@ -56,6 +56,7 @@
  :- import_module exception.
  :- import_module int.
  :- import_module list.
+:- import_module require.

  :- instance stream.error(error_stream_error) where
  [
@@ -157,7 +158,7 @@ typedef ML_BitBuffer *ML_BitBufferPtr;

  new_buffer(BM, Pos, Size, UseStream, Stream, State) =
      ( if Size =< 0 then
-        throw("bit_buffer: invalid buffer size")
+        func_error($pred, "invalid buffer size")
        else
          new_buffer_2(BM, Pos, Size, UseStream, Stream, State, ok)
      ).
diff --git a/library/char.m b/library/char.m
index 2934b8b..04ecac3 100644
--- a/library/char.m
+++ b/library/char.m
@@ -803,7 +803,7 @@ is_base_digit(Base, Digit) :-
      ( if 2 =< Base, Base =< 36 then
          base_digit_to_int(Base, Digit, _Int)
      else
-        error("char.is_base_digit: invalid base")
+        error($pred, "invalid base")
      ).

  %---------------------------------------------------------------------------%
@@ -818,7 +818,7 @@ det_binary_digit_to_int(Digit) = Int :-
      ( if binary_digit_to_int(Digit, IntPrime) then
          Int = IntPrime
      else
-        error("char.binary_digit_to_int failed")
+        error($pred, "char.binary_digit_to_int failed")
      ).

  octal_digit_to_int('0', 0).
@@ -834,7 +834,7 @@ det_octal_digit_to_int(Digit) = Int :-
      ( if octal_digit_to_int(Digit, IntPrime) then
          Int = IntPrime
      else
-        error("char.octal_digit_to_int failed")
+        error($pred, "char.octal_digit_to_int failed")
      ).

  decimal_digit_to_int('0', 0).
@@ -852,7 +852,7 @@ det_decimal_digit_to_int(Digit) = Int :-
      ( if decimal_digit_to_int(Digit, IntPrime) then
          Int = IntPrime
      else
-        error("char.decimal_digit_to_int failed")
+        error($pred, "char.decimal_digit_to_int failed")
      ).

  hex_digit_to_int('0', 0).
@@ -882,7 +882,7 @@ det_hex_digit_to_int(Digit) = Int :-
      ( if hex_digit_to_int(Digit, IntPrime) then
          Int = IntPrime
      else
-        error("char.hex_digit_to_int failed")
+        error($pred, "char.hex_digit_to_int failed")
      ).

  base_digit_to_int(Base, Digit, Int) :-
@@ -894,14 +894,14 @@ base_digit_to_int(Base, Digit, Int) :-
          ),
          Int < Base
      else
-        error("char.base_digit_to_int: invalid base")
+        error($pred, "invalid base")
      ).

  det_base_digit_to_int(Base, Digit) = Int :-
      ( if base_digit_to_int(Base, Digit, IntPrime) then
          Int = IntPrime
      else
-        error("char.base_digit_to_int failed")
+        error($pred, "char.base_digit_to_int failed")
      ).

  %---------------------------------------------------------------------------%
@@ -916,7 +916,7 @@ det_int_to_binary_digit(Int) = Digit :-
      ( if int_to_binary_digit(Int, DigitPrime) then
          Digit = DigitPrime
      else
-        error("char.int_to_binary_digit failed")
+        error($pred, "char.int_to_binary_digit failed")
      ).

  int_to_octal_digit(0, '0').
@@ -932,7 +932,7 @@ det_int_to_octal_digit(Int) = Digit :-
      ( if int_to_octal_digit(Int, DigitPrime) then
          Digit = DigitPrime
      else
-        error("char.int_to_octal_digit failed")
+        error($pred, "char.int_to_octal_digit failed")
      ).

  int_to_decimal_digit(0, '0').
@@ -950,7 +950,7 @@ det_int_to_decimal_digit(Int) = Digit :-
      ( if int_to_decimal_digit(Int, DigitPrime) then
          Digit = DigitPrime
      else
-        error("char.int_to_decimal_digit failed")
+        error($pred, "char.int_to_decimal_digit failed")
      ).

  int_to_hex_digit(0, '0').
@@ -974,7 +974,7 @@ det_int_to_hex_digit(Int) = Digit :-
      ( if int_to_hex_digit(Int, DigitPrime) then
          Digit = DigitPrime
      else
-        error("char.int_to_hex_digit failed")
+        error($pred, "char.int_to_hex_digit failed")
      ).

  base_int_to_digit(Base, Int, Digit) :-
@@ -982,14 +982,14 @@ base_int_to_digit(Base, Int, Digit) :-
          Int < Base,
          int_to_extended_digit(Int, Digit)
      else
-        error("char.base_int_to_digit: invalid base")
+        error($pred, "invalid base")
      ).

  det_base_int_to_digit(Base, Int) = Digit :-
      ( if base_int_to_digit(Base, Int, DigitPrime) then
          Digit = DigitPrime
      else
-        error("char.base_int_to_digit failed")
+        error($pred, "char.base_int_to_digit failed")
      ).

  %---------------------------------------------------------------------------%
@@ -1117,7 +1117,7 @@ det_int_to_digit(Int, Digit) :-
      ( if int_to_extended_digit(Int, DigitPrime) then
          Digit = DigitPrime
      else
-        error("char.int_to_digit failed")
+        error($pred, "char.int_to_digit failed")
      ).

  :- pred int_to_extended_digit(int, char).
diff --git a/library/hash_table.m b/library/hash_table.m
index d3d00e3..2ce30b8 100644
--- a/library/hash_table.m
+++ b/library/hash_table.m
@@ -280,11 +280,11 @@

  :- import_module bool.
  :- import_module deconstruct.
-:- import_module exception.
  :- import_module float.
  :- import_module int.
  :- import_module list.
  :- import_module pair.
+:- import_module require.
  :- import_module string.
  :- import_module uint.
  :- import_module univ.
@@ -334,13 +334,11 @@

  init(HashPred, N, MaxOccupancy) = HT :-
      ( if N =< 0 then
-        throw(software_error("hash_table.init: N =< 0"))
+        error($pred, "N =< 0")
      else if N >= int.bits_per_int then
-        throw(software_error(
-            "hash_table.init: N >= int.bits_per_int"))
+        error($pred, "N >= int.bits_per_int")
      else if MaxOccupancy =< 0.0 then
-        throw(software_error(
-            "hash_table.init: MaxOccupancy =< 0.0"))
+        error($pred, "MaxOccupancy =< 0.0")
      else
          NumBuckets = 1 << N,
          MaxOccupants = ceiling_to_int(float(NumBuckets) * MaxOccupancy),
@@ -470,8 +468,7 @@ det_insert(HT0, K, V) = HT :-
          ; AL0 = ht_cons(_, _, _)
          ),
          ( if alist_search(AL0, K, _) then
-            throw(software_error(
-                "hash_table.det_insert: key already present"))
+            error($pred, "key already present")
          else
              AL = ht_cons(K, V, AL0)
          )
@@ -495,7 +492,7 @@ det_update(!.HT, K, V) = !:HT :-
      ( if alist_replace(AL0, K, V, AL1) then
          AL = AL1
      else
-        throw(software_error("hash_table.det_update: key not found"))
+        error($pred, "key not found")
      ),
      array.unsafe_set(H, AL, Buckets0, Buckets),
      !HT ^ buckets := Buckets.
@@ -573,7 +570,7 @@ lookup(HT, K) =
      ( if V = search(HT, K) then
          V
      else
-        throw(software_error("hash_table.lookup: key not found"))
+        func_error($pred, "key not found")
      ).

  elem(K, HT) = lookup(HT, K).
diff --git a/library/injection.m b/library/injection.m
index c284cbc..b8b5864 100644
--- a/library/injection.m
+++ b/library/injection.m
@@ -532,7 +532,7 @@ delete_value(injection(!.F, !.R), V) = injection(!:F, !:R) :-
          % Only K could possibly be associated with V.  If it is,
          % then we throw an exception.
          ( if map.lookup(!.F, K, V) then
-            error("injection.delete_value: value is associated with a key")
+            error($pred, "value is associated with a key")
          else
              true
          )
diff --git a/library/int16.m b/library/int16.m
index e6ae285..6d7bf64 100644
--- a/library/int16.m
+++ b/library/int16.m
@@ -378,7 +378,7 @@ det_from_int(I) = I16 :-
      ( if from_int(I, I16Prime) then
          I16 = I16Prime
      else
-        error("int16.det_from_int: cannot convert int to int16")
+        error($pred, "cannot convert int to int16")
      ).

  :- pragma no_determinism_warning(cast_from_int/1).
@@ -541,7 +541,7 @@ min(X, Y) =

  abs(Num) =
      ( if Num = int16.min_int16 then
-        throw(software_error("int16.abs: abs(min_int16) would overflow"))
+        func_error($pred, "abs(min_int16) would overflow")
      else
          unchecked_abs(Num)
      ).
diff --git a/library/int32.m b/library/int32.m
index c57e6fb..83c9c54 100644
--- a/library/int32.m
+++ b/library/int32.m
@@ -410,7 +410,7 @@ det_from_int(I) = I32 :-
      ( if from_int(I, I32Prime) then
          I32 = I32Prime
      else
-        error("int32.det_from_int: cannot convert int to int32")
+        error($pred, "cannot convert int to int32")
      ).

  :- pragma no_determinism_warning(cast_from_int/1).
@@ -581,7 +581,7 @@ min(X, Y) =

  abs(Num) =
      ( if Num = int32.min_int32 then
-        throw(software_error("int32.abs: abs(min_int32) would overflow"))
+        func_error($pred, "abs(min_int32) would overflow")
      else
          unchecked_abs(Num)
      ).
diff --git a/library/int64.m b/library/int64.m
index e3233d9..623450a 100644
--- a/library/int64.m
+++ b/library/int64.m
@@ -421,7 +421,7 @@ det_to_int(I64) = I :-
      ( if to_int(I64, IPrime) then
          I = IPrime
      else
-        error("int64.det_to_int: cannot convert int64 to int")
+        error($pred, "cannot convert int64 to int")
      ).

  %---------------------------------------------------------------------------%
@@ -561,7 +561,7 @@ min(X, Y) =

  abs(Num) = Abs :-
      ( if Num = int64.min_int64 then
-        throw(software_error("int64.abs: abs(min_int64) would overflow"))
+        error($pred, "abs(min_int64) would overflow")
      else
          Abs = unchecked_abs(Num)
      ).
diff --git a/library/int8.m b/library/int8.m
index eb21389..4137ce8 100644
--- a/library/int8.m
+++ b/library/int8.m
@@ -350,7 +350,7 @@ det_from_int(I) = I8 :-
      ( if from_int(I, I8Prime) then
          I8 = I8Prime
      else
-        error("int8.det_from_int: cannot convert int to int8")
+        error($pred, "cannot convert int to int8")
      ).

  :- pragma no_determinism_warning(cast_from_int/1).
diff --git a/library/io.m b/library/io.m
index 90c3fa3..91c1a72 100644
--- a/library/io.m
+++ b/library/io.m
@@ -3495,7 +3495,7 @@ read_bitmap(Stream, !Bitmap, BytesRead, Result, !IO) :-
      ( if NumBytes = !.Bitmap ^ num_bytes then
          io.read_bitmap(Stream, 0, NumBytes, !Bitmap, BytesRead, Result, !IO)
      else
-        error("io.read_bitmap: bitmap contains partial final byte")
+        error($pred, "bitmap contains partial final byte")
      ).

  read_bitmap(binary_input_stream(Stream), Start, NumBytes, !Bitmap,
@@ -10944,7 +10944,7 @@ write_bitmap(binary_output_stream(Stream), Bitmap, !IO) :-
          do_write_bitmap(Stream, Bitmap, 0, NumBytes, Error, !IO),
          throw_on_output_error(Error, !IO)
      else
-        error("io.write_bitmap: bitmap contains partial final byte")
+        error($pred, "bitmap contains partial final byte")
      ).

  write_bitmap(binary_output_stream(Stream), Bitmap, Start, NumBytes, !IO) :-
diff --git a/library/lexer.m b/library/lexer.m
index ee28894..2e96e26 100644
--- a/library/lexer.m
+++ b/library/lexer.m
@@ -1305,7 +1305,7 @@ handle_special_token(Char, ScannedPastWhiteSpace, Token) :-
              Token = SpecialToken
          )
      else
-        error("lexer.m: handle_special_token: unknown special token")
+        error($pred, "unknown special token")
      ).

  :- pred special_token(char::in, token::out) is semidet.
diff --git a/library/ranges.m b/library/ranges.m
index 52acc45..74c5c68 100644
--- a/library/ranges.m
+++ b/library/ranges.m
@@ -368,8 +368,8 @@

  :- implementation.

-:- import_module exception.
  :- import_module int.
+:- import_module require.

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

@@ -427,7 +427,7 @@ universe = range(min_int, max_int, nil).

  range(Min, Max) = Ranges :-
      ( if Min = min_int then
-        throw("ranges.range: cannot represent min_int")
+        error($pred, "cannot represent min_int")
      else if Min > Max then
          Ranges = nil
      else
@@ -465,7 +465,7 @@ median(As) = N :-
      ( if Size > 0 then
          MiddleIndex = (Size + 1) / 2
      else
-        throw("ranges.median: empty set")
+        error($pred, "empty set")
      ),
      N = element_index(As, MiddleIndex).

@@ -475,7 +475,7 @@ median(As) = N :-
  :- func element_index(ranges, int) = int.

  element_index(nil, _) =
-    throw("ranges.element_index: index out of range").
+    func_error($pred, "index out of range").
  element_index(range(L, U, Rest), I) = N :-
      N0 = L + I,
      ( if N0 =< U then
diff --git a/library/rational.m b/library/rational.m
index c888414..253eb34 100644
--- a/library/rational.m
+++ b/library/rational.m
@@ -154,7 +154,7 @@ R1 / R2 = R1 * reciprocal(R2).

  reciprocal(r(Num, Den)) =
      ( if Num = integer.zero then
-        func_error("rational.reciprocal: division by zero")
+        func_error($pred, "division by zero")
      else
          r(signum(Num) * Den, integer.abs(Num))
      ).
diff --git a/library/rbtree.m b/library/rbtree.m
index f49af1b..04abc21 100644
--- a/library/rbtree.m
+++ b/library/rbtree.m
@@ -287,7 +287,7 @@ singleton(K, V) = black(K, V, empty, empty).

  insert(K, V, empty, black(K, V, empty, empty)).
  insert(_K, _V, red(_, _, _, _), _Tree) :-
-    error("rbtree.insert: root node cannot be red!").
+    error($pred, "root node cannot be red!").
  insert(K, V, black(K0, V0, L0, R0), Tree) :-
      rbtree.insert_2(black(K0, V0, L0, R0), K, V, Tree0),
      % Ensure that the root of the tree is black.
@@ -299,7 +299,7 @@ insert(K, V, black(K0, V0, L0, R0), Tree) :-
          Tree = black(K1, V1, L1, R1)
      ;
          Tree0 = empty,
-        error("rbtree.insert: new tree is empty")
+        error($pred, "new tree is empty")
      ).

      % rbtree.insert_2:
@@ -477,7 +477,7 @@ set(!.RBT, K, V) = !:RBT :-

  set(K, V, empty, black(K, V, empty, empty)).
  set(_K, _V, red(_, _, _, _), _Tree) :-
-    error("rbtree.set: root node cannot be red!").
+    error($pred, "root node cannot be red!").
  set(K, V, black(K0, V0, L0, R0), Tree) :-
      rbtree.set_2(black(K0, V0, L0, R0), K, V, Tree0),
      % Ensure that the root of the tree is black.
@@ -489,7 +489,7 @@ set(K, V, black(K0, V0, L0, R0), Tree) :-
          Tree = black(K1, V1, L1, R1)
      ;
          Tree0 = empty,
-        error("rbtree.set: new tree is empty")
+        error($pred, "new tree is empty")
      ).

      % rbtree.set_2:
@@ -602,7 +602,7 @@ insert_duplicate(!.RBT, K, V) = !:RBT :-

  insert_duplicate(K, V, empty, black(K, V, empty, empty)).
  insert_duplicate(_K, _V, red(_, _, _, _), _Tree) :-
-    error("rbtree.insert_duplicate: root node cannot be red!").
+    error($pred, "root node cannot be red!").
  insert_duplicate(K, V, black(K0, V0, L0, R0), Tree) :-
      rbtree.insert_duplicate_2(black(K0, V0, L0, R0), K, V, Tree0),
      % Ensure that the root of the tree is black.
diff --git a/library/rtree.m b/library/rtree.m
index 6552d37..e3a6146 100644
--- a/library/rtree.m
+++ b/library/rtree.m
@@ -596,7 +596,7 @@ delete(K, V, !Tree) :-
                              NextOrphanTree),
                          !:Tree = rtree(!.T)
                      else
-                        error("delete: unbalanced rtree")
+                        error($pred, "unbalanced rtree")
                      )
                  else
                      reinsert_deleted_subtrees(Orphans0, 1, OrphanTree, !:T),
@@ -604,7 +604,7 @@ delete(K, V, !Tree) :-
                  )
              ;
                  Orphans = [],
-                error("delete: expected delete info")
+                error($pred, "expected delete info")
              )
          )
      ).
diff --git a/library/stream.string_writer.m b/library/stream.string_writer.m
index a3df610..c4978f2 100644
--- a/library/stream.string_writer.m
+++ b/library/stream.string_writer.m
@@ -253,7 +253,7 @@ put_int(Stream, Int, !State) :-
          ( if dynamic_cast(IOState, !:State) then
              !:State = unsafe_promise_unique(!.State)
          else
-            error("stream.string_writer.put_int: unexpected type error")
+            error($pred, "unexpected type error")
          )
      else
          put(Stream, string.int_to_string(Int), !State)
@@ -270,7 +270,7 @@ put_uint(Stream, UInt, !State) :-
          ( if dynamic_cast(IOState, !:State) then
              !:State = unsafe_promise_unique(!.State)
          else
-            error("stream.string_writer.put_uint: unexpected type error")
+            error($pred, "unexpected type error")
          )
      else
          put(Stream, string.uint_to_string(UInt), !State)
@@ -287,7 +287,7 @@ put_int8(Stream, Int8, !State) :-
          ( if dynamic_cast(IOState, !:State) then
              !:State = unsafe_promise_unique(!.State)
          else
-            error("stream.string_writer.put_int8: unexpected type error")
+            error($pred, "unexpected type error")
          )
      else
          put(Stream, string.int8_to_string(Int8), !State)
@@ -304,7 +304,7 @@ put_uint8(Stream, UInt8, !State) :-
          ( if dynamic_cast(IOState, !:State) then
              !:State = unsafe_promise_unique(!.State)
          else
-            error("stream.string_writer.put_uint8: unexpected type error")
+            error($pred, "unexpected type error")
          )
      else
          put(Stream, string.uint8_to_string(UInt8), !State)
@@ -321,7 +321,7 @@ put_int16(Stream, Int16, !State) :-
          ( if dynamic_cast(IOState, !:State) then
              !:State = unsafe_promise_unique(!.State)
          else
-            error("stream.string_writer.put_int16: unexpected type error")
+            error($pred, "unexpected type error")
          )
      else
          put(Stream, string.int16_to_string(Int16), !State)
@@ -338,7 +338,7 @@ put_uint16(Stream, UInt16, !State) :-
          ( if dynamic_cast(IOState, !:State) then
              !:State = unsafe_promise_unique(!.State)
          else
-            error("stream.string_writer.put_uint16: unexpected type error")
+            error($pred, "unexpected type error")
          )
      else
          put(Stream, string.uint16_to_string(UInt16), !State)
@@ -355,7 +355,7 @@ put_int32(Stream, Int32, !State) :-
          ( if dynamic_cast(IOState, !:State) then
              !:State = unsafe_promise_unique(!.State)
          else
-            error("stream.string_writer.put_int32: unexpected type error")
+            error($pred, "unexpected type error")
          )
      else
          put(Stream, string.int32_to_string(Int32), !State)
@@ -372,7 +372,7 @@ put_uint32(Stream, UInt32, !State) :-
          ( if dynamic_cast(IOState, !:State) then
              !:State = unsafe_promise_unique(!.State)
          else
-            error("stream.string_writer.put_uint32: unexpected type error")
+            error($pred, "unexpected type error")
          )
      else
          put(Stream, string.uint32_to_string(UInt32), !State)
@@ -389,7 +389,7 @@ put_int64(Stream, Int64, !State) :-
          ( if dynamic_cast(IOState, !:State) then
              !:State = unsafe_promise_unique(!.State)
          else
-            error("stream.string_writer.put_int64: unexpected type error")
+            error($pred, "unexpected type error")
          )
      else
          put(Stream, string.int64_to_string(Int64), !State)
@@ -406,7 +406,7 @@ put_uint64(Stream, UInt64, !State) :-
          ( if dynamic_cast(IOState, !:State) then
              !:State = unsafe_promise_unique(!.State)
          else
-            error("stream.string_writer.put_uint64: unexpected type error")
+            error($pred, "unexpected type error")
          )
      else
          put(Stream, string.uint64_to_string(UInt64), !State)
@@ -423,7 +423,7 @@ put_float(Stream, Float, !State) :-
          ( if dynamic_cast(IOState, !:State) then
              !:State = unsafe_promise_unique(!.State)
          else
-            error("stream.string_writer.put_float: unexpected type error")
+            error($pred, "unexpected type error")
          )
      else
          put(Stream, string.float_to_string(Float), !State)
@@ -440,7 +440,7 @@ put_char(Stream, Char, !State) :-
          ( if dynamic_cast(IOState, !:State) then
              !:State = unsafe_promise_unique(!.State)
          else
-            error("stream.string_writer.put_char: unexpected type error")
+            error($pred, "unexpected type error")
          )
      else
          put(Stream, string.char_to_string(Char), !State)
diff --git a/library/type_desc.m b/library/type_desc.m
index 260afdf..68aa476 100644
--- a/library/type_desc.m
+++ b/library/type_desc.m
@@ -280,7 +280,7 @@ pseudo_type_desc_to_rep(PseudoTypeDesc) = PseudoTypeRep :-
      else if is_univ_pseudo_type_desc(PseudoTypeDesc, UnivNum) then
          PseudoTypeRep = univ_tvar(UnivNum)
      else
-        error("pseudo_type_desc_to_rep: internal error")
+        error($pred, "internal error")
      ).

  :- pred is_univ_pseudo_type_desc(pseudo_type_desc::in, int::out) is semidet.
@@ -405,7 +405,7 @@ det_ground_pseudo_type_desc_to_type_desc(PseudoTypeDesc) = TypeDesc :-
      ( if pseudo_type_desc_is_ground(PseudoTypeDesc) then
          private_builtin.unsafe_type_cast(PseudoTypeDesc, TypeDesc)
      else
-        error("det_ground_pseudo_type_desc_to_type_desc: not ground")
+        error($pred, "not ground")
      ).

  %---------------------------------------------------------------------------%
@@ -992,7 +992,7 @@ det_make_type(TypeCtor, ArgTypes) = Type :-
      ( if make_type(TypeCtor, ArgTypes) = NewType then
          Type = NewType
      else
-        error("det_make_type/2: make_type/2 failed (wrong arity)")
+        error($pred, "make_type/2 failed (wrong arity)")
      ).

  %---------------------------------------------------------------------------%
diff --git a/library/uint.m b/library/uint.m
index 9df06a6..d9172cb 100644
--- a/library/uint.m
+++ b/library/uint.m
@@ -230,7 +230,7 @@ det_from_int(I) = U :-
      ( if from_int(I, UPrime) then
          U = UPrime
      else
-        error("uint.det_from_int: cannot convert int to uint")
+        error($pred, "cannot convert int to uint")
      ).

  %---------------------------------------------------------------------------%
diff --git a/library/uint16.m b/library/uint16.m
index 8153896..fc9db4a 100644
--- a/library/uint16.m
+++ b/library/uint16.m
@@ -377,7 +377,7 @@ det_from_int(I) = U16 :-
      ( if from_int(I, U16Prime) then
          U16 = U16Prime
      else
-        error("uint16.det_from_int: cannot convert int to uint16")
+        error($pred, "cannot convert int to uint16")
      ).

  :- pragma no_determinism_warning(cast_from_int/1).
diff --git a/library/uint32.m b/library/uint32.m
index af211c9..ec5b886 100644
--- a/library/uint32.m
+++ b/library/uint32.m
@@ -411,7 +411,7 @@ det_from_int(I) = U :-
      ( if from_int(I, U0) then
          U = U0
      else
-        error("uint32.det_from_int: cannot convert int to uint32")
+        error($pred, "cannot convert int to uint32")
      ).

  :- pragma no_determinism_warning(cast_from_int/1).
diff --git a/library/uint64.m b/library/uint64.m
index f6022e5..b54f1df 100644
--- a/library/uint64.m
+++ b/library/uint64.m
@@ -379,7 +379,7 @@ det_from_int(I) = U64 :-
      ( if from_int(I, U64Prime) then
          U64 = U64Prime
      else
-        error("uint64.det_from_int: cannot convert int to uint64")
+        error($pred, "cannot convert int to uint64")
      ).

  %---------------------------------------------------------------------------%
diff --git a/library/uint8.m b/library/uint8.m
index f8ec35b..87b6308 100644
--- a/library/uint8.m
+++ b/library/uint8.m
@@ -330,7 +330,7 @@ det_from_int(I) = U8 :-
      ( if from_int(I, U8Prime) then
          U8 = U8Prime
      else
-        error("uint8.det_from_int: cannot convert int to uint8")
+        error($pred, "cannot convert int to uint8")
      ).

  :- pragma no_determinism_warning(cast_from_int/1).
diff --git a/library/version_array2d.m b/library/version_array2d.m
index 2aad2a9..214b654 100644
--- a/library/version_array2d.m
+++ b/library/version_array2d.m
@@ -106,7 +106,6 @@

  :- import_module int.
  :- import_module require.
-:- import_module string.
  :- import_module version_array.

  %---------------------------------------------------------------------------%
@@ -126,8 +125,7 @@ version_array2d(Xss @ [Xs | _]) = VA2D :-
      ( if all [Ys] ( member(Ys, Xss) => length(Ys) = N ) then
          VA2D = version_array2d(M, N, A)
      else
-        error("version_array2d.version_array2d/1: " ++
-            "non-rectangular list of lists")
+        error($pred, "non-rectangular list of lists")
      ).

  %---------------------------------------------------------------------------%
@@ -136,7 +134,7 @@ init(M, N, X) =
      ( if M >= 0, N >= 0 then
          version_array2d(M, N, version_array.init(M * N, X))
      else
-        func_error("version_array2d.new: bounds must be non-negative")
+        func_error($pred, "bounds must be non-negative")
      ).

  %---------------------------------------------------------------------------%
diff --git a/library/version_bitmap.m b/library/version_bitmap.m
index 7873516..36847b0 100644
--- a/library/version_bitmap.m
+++ b/library/version_bitmap.m
@@ -114,9 +114,9 @@

  :- implementation.

-:- import_module exception.
  :- import_module int.
  :- import_module version_array.
+:- import_module require.

      % A version_bitmap is represented as an array of ints where each int stores
      % int.bits_per_int bits. The first element of the array (index 0)
@@ -132,7 +132,7 @@

  init(N, B) = BM :-
      ( if N < 0 then
-        throw(software_error("version_bitmap.init: negative size"))
+        error($pred, "negative size")
      else
          X    = initializer(B),
          BM0  = (version_array.init(num_ints_required(N), X) ^ elem(0) := N),
@@ -208,7 +208,7 @@ set(BM, I) =
          BM ^ elem(int_offset(I)) :=
              BM ^ elem(int_offset(I)) \/ bitmask(I)
      else
-        throw(software_error("version_bitmap.set: out of range"))
+        func_error($pred, "out of range")
      ).

  set(I, BM, set(BM, I)).
@@ -218,7 +218,7 @@ clear(BM, I) =
          BM ^ elem(int_offset(I)) :=
              BM ^ elem(int_offset(I)) /\ \bitmask(I)
      else
-        throw(software_error("version_bitmap.clear: out of range"))
+        func_error($pred, "out of range")
      ).

  clear(I, BM, clear(BM, I)).
@@ -228,7 +228,7 @@ flip(BM, I) =
          BM ^ elem(int_offset(I)) :=
              BM ^ elem(int_offset(I)) `xor` bitmask(I)
      else
-        throw(software_error("version_bitmap.flip: out of range"))
+        func_error($pred, "out of range")
      ).

  flip(I, BM, flip(BM, I)).
@@ -239,14 +239,14 @@ is_set(BM, I) :-
      ( if in_range(BM, I) then
          BM ^ elem(int_offset(I)) /\ bitmask(I) \= 0
      else
-        throw(software_error("version_bitmap.is_set: out of range"))
+        error($pred, "out of range")
      ).

  is_clear(BM, I) :-
      ( if in_range(BM, I) then
          BM ^ elem(int_offset(I)) /\ bitmask(I) = 0
      else
-        throw(software_error("version_bitmap.is_clear: out of range"))
+        error($pred, "out of range")
      ).

  %---------------------------------------------------------------------------%
@@ -273,8 +273,7 @@ union(BMa, BMb) =
      ( if num_bits(BMa) = num_bits(BMb) then
          zip(int_offset(num_bits(BMb) - 1), (\/), BMa, BMb)
      else
-        throw(software_error(
-            "version_bitmap.union: version_bitmaps not the same size"))
+        func_error($pred, "version_bitmaps not the same size")
      ).

  %---------------------------------------------------------------------------%
@@ -283,8 +282,7 @@ intersect(BMa, BMb) =
      ( if num_bits(BMa) = num_bits(BMb) then
          zip(int_offset(num_bits(BMb) - 1), (/\), BMa, BMb)
      else
-        throw(software_error(
-            "version_bitmap.intersect: version_bitmaps not the same size"))
+        func_error($pred, "version_bitmaps not the same size")
      ).

  %---------------------------------------------------------------------------%
@@ -293,8 +291,7 @@ difference(BMa, BMb) =
      ( if num_bits(BMa) = num_bits(BMb) then
          zip(int_offset(num_bits(BMb) - 1), (func(X, Y) = X /\ \Y), BMa, BMb)
      else
-        throw(software_error(
-            "version_bitmap.difference: version_bitmaps not the same size"))
+        func_error($pred, "version_bitmaps not the same size")
      ).

  %---------------------------------------------------------------------------%
@@ -303,8 +300,7 @@ xor(BMa, BMb) =
      ( if num_bits(BMa) = num_bits(BMb) then
          zip(int_offset(num_bits(BMb) - 1), (func(X, Y) = X `xor` Y), BMa, BMb)
      else
-        throw(software_error(
-            "version_bitmap.xor: version_bitmaps not the same size"))
+        func_error($pred, "version_bitmaps not the same size")
      ).

  %---------------------------------------------------------------------------%
diff --git a/library/version_hash_table.m b/library/version_hash_table.m
index 0cfe32e..50bab20 100644
--- a/library/version_hash_table.m
+++ b/library/version_hash_table.m
@@ -256,13 +256,11 @@ unsafe_init(HashPred, N, MaxOccupancy) = init_2(HashPred, N, MaxOccupancy, no).

  init_2(HashPred, N, MaxOccupancy, NeedSafety) = HT :-
      ( if N =< 0 then
-        throw(software_error("version_hash_table.new_hash_table: N =< 0"))
+        error("version_hash_table.init: N =< 0")
      else if N >= int.bits_per_int then
-        throw(software_error(
-            "version_hash_table.new: N >= int.bits_per_int"))
+        error("version_hash_table.init: N >= int.bits_per_int")
      else if MaxOccupancy =< 0.0 then
-        throw(software_error(
-            "version_hash_table.new: MaxOccupancy =< 0.0"))
+        error("version_hash_table.init: MaxOccupancy =< 0.0")
      else
          NumBuckets = 1 << N,
          MaxOccupants = ceiling_to_int(float(NumBuckets) * MaxOccupancy),
@@ -465,10 +463,10 @@ alist_search(AL, K, V) :-
  %---------------------------------------------------------------------------%

  lookup(HT, K) =
-    ( if   V = search(HT, K) then
+    ( if V = search(HT, K) then
          V
      else
-        func_error("version_hash_table.lookup: key not found")
+        func_error($pred, "key not found")
      ).

  elem(K, HT) = lookup(HT, K).
@@ -589,7 +587,7 @@ det_update(HT0, K, V) = HT :-
      ( if alist_replace(AL0, K, V, AL1) then
          AL = AL1
      else
-        throw(software_error("version_hash_table.det_update: key not found"))
+        error($pred, "key not found")
      ),
      Buckets = Buckets0 ^ elem(H) := AL,
      promise_equivalent_solutions [HT] (
diff --git a/tests/hard_coded/array2d_from_array.exp b/tests/hard_coded/array2d_from_array.exp
index 511ecf9..dde8cad 100644
--- a/tests/hard_coded/array2d_from_array.exp
+++ b/tests/hard_coded/array2d_from_array.exp
@@ -2,27 +2,27 @@
  Array = array([])
  M = -1
  N = -1
-EXCEPTION: "array2d.from_array: bounds must be non-negative"
+EXCEPTION: "function `array2d.from_array\'/3:  bounds must be non-negative"
  ------FROM ARRAY------
  Array = array([])
  M = 0
  N = -1
-EXCEPTION: "array2d.from_array: bounds must be non-negative"
+EXCEPTION: "function `array2d.from_array\'/3:  bounds must be non-negative"
  ------FROM ARRAY------
  Array = array([])
  M = -1
  N = 0
-EXCEPTION: "array2d.from_array: bounds must be non-negative"
+EXCEPTION: "function `array2d.from_array\'/3:  bounds must be non-negative"
  ------FROM ARRAY------
  Array = array([])
  M = 2
  N = 2
-EXCEPTION: "array2d.from_array: too few elements"
+EXCEPTION: "function `array2d.from_array\'/3: too few elements"
  ------FROM ARRAY------
  Array = array([1, 2, 3, 4, 5])
  M = 2
  N = 2
-EXCEPTION: "array2d.from_array: too many elements"
+EXCEPTION: "function `array2d.from_array\'/3: too many elements"
  ------FROM ARRAY------
  Array = array([])
  M = 0
diff --git a/tests/hard_coded/test_array2d.exp b/tests/hard_coded/test_array2d.exp
index aa2749d..c70dcda 100644
--- a/tests/hard_coded/test_array2d.exp
+++ b/tests/hard_coded/test_array2d.exp
@@ -30,10 +30,10 @@ Zeroes =
   [0, 0, 0]
   [0, 0, 0]]

-Empty ^ elem(0, 0) = exception(univ_cons(software_error("array2d.elem: indices out of bounds")))
-Zeroes ^ elem(-1, 0) = exception(univ_cons(software_error("array2d.elem: indices out of bounds")))
-Zeroes ^ elem(0, -1) = exception(univ_cons(software_error("array2d.elem: indices out of bounds")))
-Zeroes ^ elem(-1, -1) = exception(univ_cons(software_error("array2d.elem: indices out of bounds")))
-Zeroes ^ elem(3, 0) = exception(univ_cons(software_error("array2d.elem: indices out of bounds")))
-Zeroes ^ elem(0, 3) = exception(univ_cons(software_error("array2d.elem: indices out of bounds")))
-Zeroes ^ elem(3, 3) = exception(univ_cons(software_error("array2d.elem: indices out of bounds")))
+Empty ^ elem(0, 0) = exception(univ_cons(software_error("function `array2d.elem\'/3: indices out of bounds")))
+Zeroes ^ elem(-1, 0) = exception(univ_cons(software_error("function `array2d.elem\'/3: indices out of bounds")))
+Zeroes ^ elem(0, -1) = exception(univ_cons(software_error("function `array2d.elem\'/3: indices out of bounds")))
+Zeroes ^ elem(-1, -1) = exception(univ_cons(software_error("function `array2d.elem\'/3: indices out of bounds")))
+Zeroes ^ elem(3, 0) = exception(univ_cons(software_error("function `array2d.elem\'/3: indices out of bounds")))
+Zeroes ^ elem(0, 3) = exception(univ_cons(software_error("function `array2d.elem\'/3: indices out of bounds")))
+Zeroes ^ elem(3, 3) = exception(univ_cons(software_error("function `array2d.elem\'/3: indices out of bounds")))
diff --git a/tests/hard_coded/test_injection.exp b/tests/hard_coded/test_injection.exp
index 13a09bc..876b6b7 100644
--- a/tests/hard_coded/test_injection.exp
+++ b/tests/hard_coded/test_injection.exp
@@ -37,7 +37,7 @@ Test "set throw 1" threw exception: software_error("injection.det_set: value is
  Test "set throw 2" threw exception: software_error("injection.det_set: value is already associated with another key")
  Test "delete_key" passed.
  Test "delete_value succ" passed.
-Test "delete_value throw" threw exception: software_error("injection.delete_value: value is associated with a key")
+Test "delete_value throw" threw exception: software_error("function `injection.delete_value\'/2: value is associated with a key")
  Test "merge no overlap" passed.
  Test "overlay no overlap" passed.
  Test "overlay key overlap" passed.



More information about the reviews mailing list