[m-rev.] diff: make lookups in the pred table det

Zoltan Somogyi zs at unimelb.edu.au
Tue Sep 11 03:10:21 AEST 2012


compiler/pred_table.m:
	The predicates that searched the pred table used to return lists of
	matching pred_ids, but they never returned empty lists; if there
	were no matching pred_ids, they failed. This diff changes them
	from semidet to det, and makes them return empty lists if there
	are no matches.

	This change simplifies both the code of these predicates, and the code
	of the predicates calling them.
	
	- Some callers of these predicates were prepared BOTH for the call
	  to fail, and for it to succeed returning an empty list; their types
	  allowed both.

	- Some pattern-matched the return value againt a one-element list
	  in the call itself, and treated both no matches and multiple matches
	  the same, even though an error message for one will be misleading
	  for the other.

	- All calls had to have a test for cons to pick up the first match; 
	  this test was logically redundant, since they also had a test for
	  success/failure.

	Change the names of the affected predicates by replacing "search"
	in their names with "lookup", both to give the right intuition
	about what they do, and to make sure I didn't miss updating any
	callers.

compiler/add_class.m:
compiler/add_clause.m:
compiler/add_pragma.m:
compiler/add_pred.m:
compiler/check_typeclass.m:
compiler/dead_proc_elim.m:
compiler/deep_profiling.m:
compiler/elds_to_erlang.m:
compiler/hlds_module.m:
compiler/intermod.m:
compiler/make_hlds_passes.m:
compiler/mmc_analysis.m:
compiler/post_typecheck.m:
compiler/recompilation.usage.m:
compiler/simplify.m:
compiler/type_constraints.m:
compiler/typecheck.m:
compiler/typecheck_errors.m:
	Conform to the above change.

Zoltan.

cvs diff: Diffing .
Index: add_class.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/add_class.m,v
retrieving revision 1.41
diff -u -b -r1.41 add_class.m
--- add_class.m	2 Jul 2012 01:16:32 -0000	1.41
+++ add_class.m	10 Sep 2012 14:20:30 -0000
@@ -293,20 +293,24 @@
     module_info_get_predicate_table(!.ModuleInfo, PredTable),
     PredArity = list.length(Modes) : int,
     (
+        MaybePredOrFunc = no,
         % The only way this could have happened now is if a `with_inst`
         % annotation was not expanded.
-        MaybePredOrFunc = no,
         unexpected($module, $pred, "unexpanded `with_inst` annotation")
     ;
         MaybePredOrFunc = yes(PredOrFunc)
     ),
+    predicate_table_lookup_pf_sym_arity(PredTable, is_fully_qualified,
+        PredOrFunc, PredName, PredArity, PredIds),
     (
-        predicate_table_search_pf_sym_arity(PredTable, is_fully_qualified,
-            PredOrFunc, PredName, PredArity, Preds),
-        Preds = [_ | _]
-    ->
+        PredIds = [],
+        missing_pred_or_func_method_error(PredName, PredArity, PredOrFunc,
+            Context, !Specs)
+    ;
+        PredIds = [HeadPredId | TailPredIds],
         (
-            Preds = [PredId],
+            TailPredIds = [],
+            PredId = HeadPredId,
             module_info_pred_info(!.ModuleInfo, PredId, PredInfo),
             pred_info_get_markers(PredInfo, PredMarkers),
             ( check_marker(PredMarkers, marker_class_method) ->
@@ -321,13 +325,10 @@
                     PredOrFunc, Context, !Specs)
             )
         ;
+            TailPredIds = [_ | _],
             % This shouldn't happen.
-            Preds = [_, _ | _],
             unexpected($module, $pred, "multiple preds matching method mode")
         )
-    ;
-        missing_pred_or_func_method_error(PredName, PredArity, PredOrFunc,
-            Context, !Specs)
     ).
 
 :- pred add_class_pred_or_func_methods(sym_name::in, list(tvar)::in,
@@ -413,10 +414,9 @@
         ),
         list.length(TypesAndModes, PredArity),
         module_info_get_predicate_table(!.ModuleInfo, PredTable),
-        (
-            predicate_table_search_pf_m_n_a(PredTable, is_fully_qualified,
-                PorF, ModuleName, Name, PredArity, [PredId])
-        ->
+        predicate_table_lookup_pf_m_n_a(PredTable, is_fully_qualified,
+            PorF, ModuleName, Name, PredArity, PredIds),
+        ( PredIds = [PredId] ->
             module_info_pred_info(!.ModuleInfo, PredId, PredInfo0),
             (
                 PorF = pf_function,
@@ -439,7 +439,7 @@
                 )
             )
         ;
-            unexpected($module, $pred, "handle_methods_with_no_modes")
+            unexpected($module, $pred, "number of preds != 1")
         )
     ;
         Method = method_pred_or_func_mode(_, _, _, _, _, _, _, _)
Index: add_clause.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/add_clause.m,v
retrieving revision 1.73
diff -u -b -r1.73 add_clause.m
--- add_clause.m	10 Sep 2012 13:33:07 -0000	1.73
+++ add_clause.m	10 Sep 2012 14:20:31 -0000
@@ -101,11 +101,10 @@
     Arity = Arity0 + ArityAdjustment,
     some [!PredInfo, !PredicateTable] (
         module_info_get_predicate_table(!.ModuleInfo, !:PredicateTable),
-        (
-            predicate_table_search_pf_sym_arity(!.PredicateTable,
-                is_fully_qualified, PredOrFunc, PredName, Arity, [PredId0])
-        ->
-            PredId = PredId0,
+        predicate_table_lookup_pf_sym_arity(!.PredicateTable,
+            is_fully_qualified, PredOrFunc, PredName, Arity, PredIds),
+        ( PredIds = [PredIdPrime] ->
+            PredId = PredIdPrime,
             ( GoalType = goal_type_promise(_) ->
                 NameString = sym_name_to_string(PredName),
                 string.format("%s %s %s (%s).\n",
Index: add_pragma.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/add_pragma.m,v
retrieving revision 1.131
diff -u -b -r1.131 add_pragma.m
--- add_pragma.m	10 Sep 2012 13:33:07 -0000	1.131
+++ add_pragma.m	10 Sep 2012 14:20:32 -0000
@@ -393,11 +393,8 @@
     PrednameModesPF = pred_name_modes_pf(Name, Modes, PredOrFunc),
     module_info_get_predicate_table(!.ModuleInfo, PredTable),
     list.length(Modes, Arity),
-    (
-        predicate_table_search_pf_sym_arity(PredTable,
-            may_be_partially_qualified, PredOrFunc, Name, Arity, PredIds),
-        PredIds = [_ | _]
-    ->
+    predicate_table_lookup_pf_sym_arity(PredTable, may_be_partially_qualified,
+        PredOrFunc, Name, Arity, PredIds),
         (
             PredIds = [PredId],
             add_pragma_foreign_export_2(Arity, PredTable, Origin, Lang, Name,
@@ -420,8 +417,8 @@
                 [always(MainPieces), verbose_only(VerbosePieces)]),
             Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
             !:Specs = [Spec | !.Specs]
-        )
     ;
+        PredIds = [],
         (
             Origin = user,
             undefined_pred_or_func_error(Name, Arity, Context,
@@ -1281,10 +1278,10 @@
     PredNameArityPFMn = pred_name_arity_pf_mn(SymName, Arity, PredOrFunc,
         ModeNum),
     module_info_get_predicate_table(!.ModuleInfo, Preds),
+    predicate_table_lookup_pf_sym_arity(Preds, is_fully_qualified,
+        PredOrFunc, SymName, Arity, PredIds),
     (
-        predicate_table_search_pf_sym_arity(Preds, is_fully_qualified,
-            PredOrFunc, SymName, Arity, [PredId])
-    ->
+        PredIds = [PredId],
         module_info_get_unused_arg_info(!.ModuleInfo, UnusedArgInfo0),
         % Convert the mode number to a proc_id.
         proc_id_to_int(ProcId, ModeNum),
@@ -1292,8 +1289,18 @@
             UnusedArgInfo0, UnusedArgInfo),
         module_info_set_unused_arg_info(UnusedArgInfo, !ModuleInfo)
     ;
+        PredIds = [],
+        Pieces = [words("Internal compiler error: "),
+            words("unknown predicate in"), quote("pragma unused_args"),
+            suffix("."), nl],
+        Msg = simple_msg(Context, [always(Pieces)]),
+        Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
+        !:Specs = [Spec | !.Specs]
+    ;
+        PredIds = [_, _ | _],
         Pieces = [words("Internal compiler error: "),
-            words("unknown predicate in `pragma unused_args'.")],
+            words("ambiguous predicate in "), quote("pragma unused_args"),
+            suffix("."), nl],
         Msg = simple_msg(Context, [always(Pieces)]),
         Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
         !:Specs = [Spec | !.Specs]
@@ -1310,10 +1317,10 @@
     PredNameArityPFMn = pred_name_arity_pf_mn(SymName, Arity, PredOrFunc,
         ModeNum),
     module_info_get_predicate_table(!.ModuleInfo, Preds),
+    predicate_table_lookup_pf_sym_arity(Preds, is_fully_qualified,
+        PredOrFunc, SymName, Arity, PredIds),
     (
-        predicate_table_search_pf_sym_arity(Preds, is_fully_qualified,
-            PredOrFunc, SymName, Arity, [PredId])
-    ->
+        PredIds = [PredId],
         module_info_get_exception_info(!.ModuleInfo, ExceptionInfo0),
         % convert the mode number to a proc_id
         proc_id_to_int(ProcId, ModeNum),
@@ -1322,11 +1329,12 @@
             ExceptionInfo0, ExceptionInfo),
         module_info_set_exception_info(ExceptionInfo, !ModuleInfo)
     ;
+        ( PredIds = []
+        ; PredIds = [_, _ | _]
+        )
         % XXX We'll just ignore this for the time being -
         % it causes errors with transitive-intermodule optimization.
-        % io.write_string("Internal compiler error: " ++
-        %   "unknown predicate in `pragma exceptions'.\n")
-        true
+        % XXX What kinds of errors?
     ).
 
 %-----------------------------------------------------------------------------%
@@ -1341,21 +1349,22 @@
     PredNameArityPFMn = pred_name_arity_pf_mn(SymName, Arity, PredOrFunc,
         ModeNum),
     module_info_get_predicate_table(!.ModuleInfo, Preds),
+    predicate_table_lookup_pf_sym_arity(Preds, is_fully_qualified,
+        PredOrFunc, SymName, Arity, PredIds),
     (
-        predicate_table_search_pf_sym_arity(Preds, is_fully_qualified,
-            PredOrFunc, SymName, Arity, [PredId])
-    ->
+        PredIds = [PredId],
         module_info_get_trailing_info(!.ModuleInfo, TrailingMap0),
         proc_id_to_int(ProcId, ModeNum),
         map.set(proc(PredId, ProcId), proc_trailing_info(TrailingStatus, no),
             TrailingMap0, TrailingMap),
         module_info_set_trailing_info(TrailingMap, !ModuleInfo)
     ;
+        ( PredIds = []
+        ; PredIds = [_, _ | _]
+        )
         % XXX We'll just ignore this for the time being -
         % it causes errors with transitive-intermodule optimization.
-        % io.write_string("Internal compiler error: " ++
-        %   "unknown predicate in `pragma trailing_info'.\n"),
-        true
+        % XXX What kinds of errors?
     ).
 
 %-----------------------------------------------------------------------------%
@@ -1370,21 +1379,22 @@
     PredNameArityPFMn = pred_name_arity_pf_mn(SymName, Arity, PredOrFunc,
         ModeNum),
     module_info_get_predicate_table(!.ModuleInfo, Preds),
+    predicate_table_lookup_pf_sym_arity(Preds, is_fully_qualified,
+        PredOrFunc, SymName, Arity, PredIds),
     (
-        predicate_table_search_pf_sym_arity(Preds, is_fully_qualified,
-            PredOrFunc, SymName, Arity, [PredId])
-    ->
+        PredIds = [PredId],
         module_info_get_mm_tabling_info(!.ModuleInfo, TablingInfo0),
         proc_id_to_int(ProcId, ModeNum),
         map.set(proc(PredId, ProcId), proc_mm_tabling_info(TablingStatus, no),
             TablingInfo0, TablingInfo),
         module_info_set_mm_tabling_info(TablingInfo, !ModuleInfo)
     ;
+        ( PredIds = []
+        ; PredIds = [_, _ | _]
+        )
         % XXX We'll just ignore this for the time being -
         % it causes errors with transitive-intermodule optimization.
-        % io.write_string("Internal compiler error: " ++
-        %   "unknown predicate in `pragma trailing_info'.\n"),
-        true
+        % XXX What kinds of errors?
     ).
 
 %-----------------------------------------------------------------------------%
@@ -1398,21 +1408,21 @@
         _, _, _, _),
     module_info_get_predicate_table(!.ModuleInfo, Preds),
     (
-        (
             MaybePredOrFunc = yes(PredOrFunc),
             adjust_func_arity(PredOrFunc, Arity, PredArity),
-            predicate_table_search_pf_sym_arity(Preds, is_fully_qualified,
+        predicate_table_lookup_pf_sym_arity(Preds, is_fully_qualified,
                 PredOrFunc, SymName, PredArity, PredIds)
         ;
             MaybePredOrFunc = no,
-            predicate_table_search_sym_arity(Preds, is_fully_qualified,
+        predicate_table_lookup_sym_arity(Preds, is_fully_qualified,
                 SymName, Arity, PredIds)
         ),
-        PredIds = [_ | _]
-    ->
+    (
+        PredIds = [_ | _],
         list.foldl3(add_pragma_type_spec_2(TSInfo, Context), PredIds,
             !ModuleInfo, !QualInfo, !Specs)
     ;
+        PredIds = [],
         undefined_pred_or_func_error(SymName, Arity, Context,
             [quote(":- pragma type_spec"), words("declaration")], !Specs)
     ).
@@ -1844,12 +1854,17 @@
     PredModesPF = pred_name_modes_pf(SymName, ModeList, PredOrFunc),
     module_info_get_predicate_table(!.ModuleInfo, Preds),
     list.length(ModeList, Arity),
+    predicate_table_lookup_pf_sym_arity(Preds, is_fully_qualified,
+        PredOrFunc, SymName, Arity, PredIds),
     (
-        predicate_table_search_pf_sym_arity(Preds,
-        is_fully_qualified, PredOrFunc, SymName, Arity, PredIds),
-        PredIds = [_ | _]
-    ->
-        ( PredIds = [PredId] ->
+        PredIds = []
+        % XXX This happens in `.trans_opt' files sometimes --
+        % so just ignore it.
+        %   undefined_pred_or_func_error(
+        %        SymName, Arity, Context,
+        %        "`:- pragma termination2_info' declaration", !Specs)
+    ;
+        PredIds = [PredId],
             module_info_get_preds(!.ModuleInfo, PredTable0),
             map.lookup(PredTable0, PredId, PredInfo0),
             pred_info_get_procedures(PredInfo0, ProcTable0),
@@ -1865,10 +1880,8 @@
                 some [!TermInfo] (
                     proc_info_get_termination2_info(ProcInfo0, !:TermInfo),
 
-                    !TermInfo ^ import_success :=
-                        MaybePragmaSuccessArgSizeInfo,
-                    !TermInfo ^ import_failure :=
-                        MaybePragmaFailureArgSizeInfo,
+                !TermInfo ^ import_success := MaybePragmaSuccessArgSizeInfo,
+                !TermInfo ^ import_failure := MaybePragmaFailureArgSizeInfo,
                     !TermInfo ^ term_status := MaybeTerminationInfo,
 
                     proc_info_set_termination2_info(!.TermInfo,
@@ -1884,26 +1897,17 @@
                     simple_call(simple_call_id(PredOrFunc, SymName, Arity)),
                     suffix("."), nl],
                 Msg = simple_msg(Context, [always(Pieces)]),
-                Spec = error_spec(severity_error, phase_parse_tree_to_hlds,
-                    [Msg]),
+            Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
                 !:Specs = [Spec | !.Specs]
             )
         ;
+        PredIds = [_, _ | _],
             Pieces = [words("Error: ambiguous predicate name"),
                 simple_call(simple_call_id(PredOrFunc, SymName, Arity)),
                 words("in"), fixed("`pragma termination2_info'."), nl],
             Msg = simple_msg(Context, [always(Pieces)]),
-            Spec = error_spec(severity_error, phase_parse_tree_to_hlds,
-                [Msg]),
+        Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
             !:Specs = [Spec | !.Specs]
-        )
-    ;
-        % XXX This happens in `.trans_opt' files sometimes --
-        % so just ignore it.
-        true
-        %   undefined_pred_or_func_error(
-        %        SymName, Arity, Context,
-        %        "`:- pragma termination2_info' declaration", !Specs)
     ).
 
 %-----------------------------------------------------------------------------%
@@ -1922,12 +1926,17 @@
         PredNameModesPF = pred_name_modes_pf(SymName, ModeList, PredOrFunc),
         module_info_get_predicate_table(!.ModuleInfo, Preds),
         list.length(ModeList, Arity),
-        (
-            predicate_table_search_pf_sym_arity(Preds, is_fully_qualified,
+        predicate_table_lookup_pf_sym_arity(Preds, is_fully_qualified,
                 PredOrFunc, SymName, Arity, PredIds),
-            PredIds = [_ | _]
-        ->
-            ( PredIds = [PredId] ->
+        (
+            PredIds = []
+            % XXX This happens in `.trans_opt' files sometimes --
+            % so just ignore it.
+            %   undefined_pred_or_func_error(SymName, Arity, Context,
+            %       "`:- pragma structure_sharing' declaration",
+            %       !Specs)
+        ;
+            PredIds = [PredId],
                 module_info_get_preds(!.ModuleInfo, PredTable0),
                 map.lookup(PredTable0, PredId, PredInfo0),
                 pred_info_get_procedures(PredInfo0, ProcTable0),
@@ -1954,6 +1963,7 @@
                     !:Specs = [Spec | !.Specs]
                 )
             ;
+            PredIds = [_ , _ | _],
                 Pieces = [words("Error: ambiguous predicate name"),
                     simple_call(simple_call_id(PredOrFunc, SymName, Arity)),
                     words("in"), quote("pragma structure_sharing."),
@@ -1963,14 +1973,6 @@
                     [Msg]),
                 !:Specs = [Spec | !.Specs]
             )
-        ;
-            % XXX This happens in `.trans_opt' files sometimes --
-            % so just ignore it.
-            true
-            %   undefined_pred_or_func_error(SymName, Arity, Context,
-            %       "`:- pragma structure_sharing' declaration",
-            %       !Specs)
-        )
     ).
 
 %-----------------------------------------------------------------------------%
@@ -1989,12 +1991,17 @@
         PredNameModesPF = pred_name_modes_pf(SymName, ModeList, PredOrFunc),
         module_info_get_predicate_table(!.ModuleInfo, Preds),
         list.length(ModeList, Arity),
-        (
-            predicate_table_search_pf_sym_arity(Preds, is_fully_qualified,
+        predicate_table_lookup_pf_sym_arity(Preds, is_fully_qualified,
                 PredOrFunc, SymName, Arity, PredIds),
-            PredIds = [_ | _]
-        ->
-            ( PredIds = [PredId] ->
+        (
+            PredIds = []
+            % XXX This happens in `.trans_opt' files sometimes --
+            % so just ignore it
+            %   undefined_pred_or_func_error(SymName, Arity, Context,
+            %       "`:- pragma structure_sharing' declaration",
+            %       !Specs)
+        ;
+            PredIds = [PredId],
                 module_info_get_preds(!.ModuleInfo, PredTable0),
                 map.lookup(PredTable0, PredId, PredInfo0),
                 pred_info_get_procedures(PredInfo0, ProcTable0),
@@ -2013,8 +2020,7 @@
                 ;
                     Pieces = [words("Error: `:- pragma structure_reuse'"),
                         words("declaration for undeclared mode of"),
-                        simple_call(
-                            simple_call_id(PredOrFunc, SymName, Arity)),
+                    simple_call(simple_call_id(PredOrFunc, SymName, Arity)),
                         suffix("."), nl],
                     Msg = simple_msg(Context, [always(Pieces)]),
                     Spec = error_spec(severity_error, phase_parse_tree_to_hlds,
@@ -2022,23 +2028,14 @@
                     !:Specs = [Spec | !.Specs]
                 )
             ;
+            PredIds = [_, _ | _],
                 Pieces = [words("Error: ambiguous predicate name"),
                     simple_call(simple_call_id(PredOrFunc, SymName, Arity)),
-                    words("in"), quote("pragma structure_reuse"), suffix("."),
-                    nl],
+                words("in"), quote("pragma structure_reuse"), suffix("."), nl],
                 Msg = simple_msg(Context, [always(Pieces)]),
-                Spec = error_spec(severity_error, phase_parse_tree_to_hlds,
-                    [Msg]),
+            Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
                 !:Specs = [Spec | !.Specs]
             )
-        ;
-            % XXX This happens in `.trans_opt' files sometimes --
-            % so just ignore it
-            true
-            %   undefined_pred_or_func_error(SymName, Arity, Context,
-            %       "`:- pragma structure_sharing' declaration",
-            %       !Specs)
-        )
     ).
 
 %-----------------------------------------------------------------------------%
@@ -2053,12 +2050,17 @@
     PredModesPF = pred_name_modes_pf(SymName, ModeList, PredOrFunc),
     module_info_get_predicate_table(!.ModuleInfo, Preds),
     list.length(ModeList, Arity),
-    (
-        predicate_table_search_pf_sym_arity(Preds, is_fully_qualified,
+    predicate_table_lookup_pf_sym_arity(Preds, is_fully_qualified,
             PredOrFunc, SymName, Arity, PredIds),
-        PredIds = [_ | _]
-    ->
-        ( PredIds = [PredId] ->
+    (
+        PredIds = []
+        % XXX This happens in `.trans_opt' files sometimes --
+        % so just ignore it.
+        %   undefined_pred_or_func_error(SymName, Arity, Context,
+        %       "`:- pragma termination_info' declaration",
+        %       !Specs
+    ;
+        PredIds = [PredId],
             module_info_get_preds(!.ModuleInfo, PredTable0),
             map.lookup(PredTable0, PredId, PredInfo0),
             pred_info_get_procedures(PredInfo0, ProcTable0),
@@ -2092,20 +2094,13 @@
                 !:Specs = [Spec | !.Specs]
             )
         ;
+        PredIds = [_, _ | _],
             Pieces = [words("Error: ambiguous predicate name"),
                 simple_call(simple_call_id(PredOrFunc, SymName, Arity)),
                 words("in"), fixed("`pragma termination_info'."), nl],
             Msg = simple_msg(Context, [always(Pieces)]),
             Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
             !:Specs = [Spec | !.Specs]
-        )
-    ;
-        % XXX This happens in `.trans_opt' files sometimes --
-        % so just ignore it.
-        true
-        %   undefined_pred_or_func_error(SymName, Arity, Context,
-        %       "`:- pragma termination_info' declaration",
-        %       !Specs
     ).
 
 %-----------------------------------------------------------------------------%
@@ -2163,16 +2158,29 @@
     % If it is not there, print an error message and insert
     % a dummy declaration for the predicate.
     module_info_get_predicate_table(!.ModuleInfo, PredTable0),
+    predicate_table_lookup_pf_sym_arity(PredTable0, is_fully_qualified,
+        PredOrFunc, PredName, Arity, PredIds),
     (
-        predicate_table_search_pf_sym_arity(PredTable0, is_fully_qualified,
-            PredOrFunc, PredName, Arity, [PredId0])
-    ->
-        PredId = PredId0
-    ;
+        PredIds = [],
         preds_add_implicit_report_error(ModuleName, PredOrFunc,
             PredName, Arity, Status, no, Context, origin_user(PredName),
             [quote(":- pragma foreign_proc"), words("declaration")], PredId,
             !ModuleInfo, !Specs)
+    ;
+        PredIds = [PredId]
+    ;
+        PredIds = [PredId, _ | _],
+        % Any attempt to define more than one pred with the same PredOrFunc,
+        % PredName and Arity should have been caught earlier, and an error
+        % message generated. We continue so that we can try to find more
+        % errors.
+        AmbiPieces = [words("Error: ambiguous predicate name"),
+            simple_call(simple_call_id(PredOrFunc, PredName, Arity)),
+            words("in"), quote("pragma foreign_proc"), suffix("."), nl],
+        AmbiMsg = simple_msg(Context, [always(AmbiPieces)]),
+        AmbiSpec = error_spec(severity_error, phase_parse_tree_to_hlds,
+            [AmbiMsg]),
+        !:Specs = [AmbiSpec | !.Specs]
     ),
 
     % Lookup the pred_info for this pred, add the pragma to the proc_info
@@ -2212,7 +2220,7 @@
         ;
             pred_info_is_imported(!.PredInfo)
         ->
-            Pieces = [words("Error: `:- pragma foreign_proc'"),
+            Pieces = [words("Error:"), quote(":- pragma foreign_proc"),
                 words("declaration for imported"),
                 simple_call(simple_call_id(PredOrFunc, PredName, Arity)),
                 suffix("."), nl],
@@ -2265,7 +2273,8 @@
                     PragmaImpl, PragmaForeignLanguage, ArgInfo, Context,
                     SimpleCallId, PredId, ProcId, !Specs)
             ;
-                Pieces = [words("Error: `:- pragma foreign_proc' declaration"),
+                Pieces = [words("Error:"),
+                    quote(":- pragma foreign_proc"), words("declaration"),
                     words("for undeclared mode of"),
                     simple_call(SimpleCallId), suffix("."), nl],
                 Msg = simple_msg(Context, [always(Pieces)]),
@@ -2297,12 +2306,13 @@
         % Lookup the pred declaration in the predicate table.
         % If it is not there, print an error message and insert
         % a dummy declaration for the predicate.
+        predicate_table_lookup_pf_sym_arity(PredicateTable0,
+            is_fully_qualified, PredOrFunc, PredName, Arity, PredIds0),
         (
-            predicate_table_search_pf_sym_arity(PredicateTable0,
-                is_fully_qualified, PredOrFunc, PredName, Arity, PredIds0)
-        ->
+            PredIds0 = [_ | _],
             PredIds = PredIds0
         ;
+            PredIds0 = [],
             module_info_get_name(!.ModuleInfo, ModuleName),
             DescPieces = [quote(":- pragma " ++ EvalMethodStr),
                 words("declaration")],
@@ -2313,12 +2323,13 @@
         )
     ;
         MaybePredOrFunc = no,
+        predicate_table_lookup_sym_arity(PredicateTable0,
+            is_fully_qualified, PredName, Arity, PredIds0),
         (
-            predicate_table_search_sym_arity(PredicateTable0,
-                is_fully_qualified, PredName, Arity, PredIds0)
-        ->
+            PredIds0 = [_ | _],
             PredIds = PredIds0
         ;
+            PredIds0 = [],
             module_info_get_name(!.ModuleInfo, ModuleName),
             DescPieces = [quote(":- pragma " ++ EvalMethodStr),
                 words("declaration")],
@@ -2333,9 +2344,7 @@
         Statistics = Attributes ^ table_attr_statistics,
         AllowReset = Attributes ^ table_attr_allow_reset,
         (
-            ( PredIds = []
-            ; PredIds = [_]
-            )
+            PredIds = [_]
         ;
             PredIds = [_, _ | _],
             (
@@ -2436,14 +2445,13 @@
         check_marker(Markers, marker_user_marked_inline),
         WarnInline = yes
     ->
-        TablePragmaStr = string.format("`:- pragma %s'", [s(EvalMethodStr)]),
         InlineWarningPieces = [words("Warning: "), simple_call(SimpleCallId),
-            words("has a"), fixed(TablePragmaStr),
+            words("has a"), quote(":- pragma " ++ EvalMethodStr),
             words("declaration but also has a"),
             quote(":- pragma inline"), words("declaration."), nl,
             words("This inline pragma will be ignored"),
             words("since tabled predicates cannot be inlined."), nl,
-            words("You can use the"), fixed("`--no-warn-table-with-inline'"),
+            words("You can use the"), quote("--no-warn-table-with-inline"),
             words("option to suppress this warning."), nl],
         InlineWarningMsg = simple_msg(Context, [always(InlineWarningPieces)]),
         InlineWarningSpec = error_spec(severity_warning,
@@ -2487,7 +2495,7 @@
                 module_info_set_pred_info(PredId, PredInfo, !ModuleInfo)
             ;
                 Pieces = [words("Error:"),
-                    fixed("`:- pragma " ++ EvalMethodStr ++ "'"),
+                    quote(":- pragma " ++ EvalMethodStr),
                     words("declaration for undeclared mode of"),
                     simple_call(SimpleCallId), suffix(".")],
                 Msg = simple_msg(Context, [always(Pieces)]),
@@ -2617,7 +2625,7 @@
                 MaybeError = yes(ArgMsg - ErrorMsg),
                 EvalMethodStr = eval_method_to_string(EvalMethod),
                 Pieces = [words("Error in"),
-                    fixed("`pragma " ++ EvalMethodStr ++ "'"),
+                    quote("pragma " ++ EvalMethodStr),
                     words("declaration for"), simple_call(SimpleCallId),
                     suffix(":"), nl, fixed(ArgMsg), words(ErrorMsg), nl],
                 Msg = simple_msg(Context, [always(Pieces)]),
@@ -3016,13 +3024,17 @@
     FTInfo = pragma_info_fact_table(PredArity, FileName),
     PredArity = pred_name_arity(Pred, Arity),
     module_info_get_predicate_table(!.ModuleInfo, PredicateTable),
+    predicate_table_lookup_sym_arity(PredicateTable, is_fully_qualified,
+        Pred, Arity, PredIds),
     (
-        predicate_table_search_sym_arity(PredicateTable, is_fully_qualified,
-            Pred, Arity, PredIds0),
-        PredIds0 = [PredId | PredIds1]
-    ->
+        PredIds = [],
+        undefined_pred_or_func_error(Pred, Arity, Context,
+            [quote(":- pragma fact_table"), words("declaration")], !Specs)
+    ;
+        PredIds = [HeadPredId | TailPredIds],
         (
-            PredIds1 = [],      % only one predicate found
+            TailPredIds = [],      % only one predicate found
+            PredId = HeadPredId,
             module_info_pred_info(!.ModuleInfo, PredId, PredInfo0),
 
             % Compile the fact table into a separate .o file.
@@ -3057,7 +3069,7 @@
                 ProcTable, Pred, PredOrFunc, NumArgs, ArgTypes, Status,
                 Context, !ModuleInfo, !Specs)
         ;
-            PredIds1 = [_ | _],     % >1 predicate found
+            TailPredIds = [_ | _],     % >1 predicate found
             Pieces = [words("In"), quote("pragma fact_table"), words("for"),
                 sym_name_and_arity(Pred/Arity), suffix(":"), nl,
                 words("error: ambiguous predicate/function name."), nl],
@@ -3065,9 +3077,6 @@
             Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
             !:Specs = [Spec | !.Specs]
         )
-    ;
-        undefined_pred_or_func_error(Pred, Arity, Context,
-            [quote(":- pragma fact_table"), words("declaration")], !Specs)
     ).
 
     % Add a `pragma c_code' for each mode of the fact table lookup to the
Index: add_pred.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/add_pred.m,v
retrieving revision 1.51
diff -u -b -r1.51 add_pred.m
--- add_pred.m	10 Sep 2012 13:33:07 -0000	1.51
+++ add_pred.m	10 Sep 2012 14:20:33 -0000
@@ -189,10 +189,10 @@
             origin_user(PredName), Status, goal_type_none, Markers, Types,
             TVarSet, ExistQVars, ClassContext, Proofs, ConstraintMap,
             ClausesInfo, VarNameRemap, PredInfo0),
+        predicate_table_lookup_pf_m_n_a(PredTable0, is_fully_qualified,
+            PredOrFunc, MNameOfPred, PName, Arity, PredIds),
         (
-            predicate_table_search_pf_m_n_a(PredTable0, is_fully_qualified,
-                PredOrFunc, MNameOfPred, PName, Arity, [OrigPred | _])
-        ->
+            PredIds = [OrigPred | _],
             module_info_pred_info(!.ModuleInfo, OrigPred, OrigPredInfo),
             pred_info_get_context(OrigPredInfo, OrigContext),
             DeclString = pred_or_func_to_str(PredOrFunc),
@@ -200,6 +200,7 @@
             multiple_def_error(ItemStatus, PredName, OrigArity, DeclString,
                 Context, OrigContext, [], !Specs)
         ;
+            PredIds = [],
             module_info_get_partial_qualifier_info(!.ModuleInfo, PQInfo),
             predicate_table_insert_qual(PredInfo0, NeedQual, PQInfo, PredId,
                 PredTable0, PredTable1),
@@ -411,11 +412,10 @@
     sym_name_get_module_name_default(PredName, ModuleName0, ModuleName),
     list.length(Modes, Arity),
     module_info_get_predicate_table(!.ModuleInfo, PredicateTable0),
-    (
-        predicate_table_search_pf_sym_arity(PredicateTable0,
-            is_fully_qualified, PredOrFunc, PredName, Arity, [PredId0])
-    ->
-        PredId = PredId0
+    predicate_table_lookup_pf_sym_arity(PredicateTable0,
+        is_fully_qualified, PredOrFunc, PredName, Arity, PredIds),
+    ( PredIds = [PredIdPrime] ->
+        PredId = PredIdPrime
     ;
         preds_add_implicit_report_error(ModuleName, PredOrFunc, PredName,
             Arity, Status, IsClassMethod, MContext, origin_user(PredName),
@@ -541,15 +541,16 @@
         PredInfo0),
     add_marker(marker_infer_type, Markers0, Markers),
     pred_info_set_markers(Markers, PredInfo0, PredInfo),
+    predicate_table_lookup_pf_sym_arity(!.PredicateTable,
+        is_fully_qualified, PredOrFunc, PredName, Arity, PredIds),
     (
-        predicate_table_search_pf_sym_arity(!.PredicateTable,
-            is_fully_qualified, PredOrFunc, PredName, Arity, _)
-    ->
-        unexpected($module, $pred, "search succeeded")
-    ;
+        PredIds = [],
         module_info_get_partial_qualifier_info(ModuleInfo, MQInfo),
         predicate_table_insert_qual(PredInfo, may_be_unqualified, MQInfo,
             PredId, !PredicateTable)
+    ;
+        PredIds = [_ | _],
+        unexpected($module, $pred, "search succeeded")
     ).
 
 %-----------------------------------------------------------------------------%
Index: check_typeclass.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/check_typeclass.m,v
retrieving revision 1.142
diff -u -b -r1.142 check_typeclass.m
--- check_typeclass.m	5 Jun 2012 15:14:26 -0000	1.142
+++ check_typeclass.m	10 Sep 2012 14:20:34 -0000
@@ -700,7 +700,7 @@
         % if the method definition p/f, name, and arity matches at least one
         % of the methods from the class interface.
         adjust_func_arity(MethodPredOrFunc, MethodArity, MethodPredArity),
-        predicate_table_search_pf_sym_arity(PredTable, is_fully_qualified,
+        predicate_table_lookup_pf_sym_arity(PredTable, is_fully_qualified,
             MethodPredOrFunc, MethodName, MethodPredArity, MatchingPredIds),
         some [PredId] (
             list.member(PredId, MatchingPredIds),
Index: dead_proc_elim.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/dead_proc_elim.m,v
retrieving revision 1.149
diff -u -b -r1.149 dead_proc_elim.m
--- dead_proc_elim.m	11 Jul 2012 04:00:59 -0000	1.149
+++ dead_proc_elim.m	10 Sep 2012 14:20:34 -0000
@@ -1253,14 +1253,9 @@
         ;
             module_info_get_predicate_table(ModuleInfo, PredicateTable),
             set_tree234.insert(Name, !NeededNames),
-            (
-                predicate_table_search_sym(PredicateTable,
-                    may_be_partially_qualified, Name, PredIds)
-            ->
-                queue.put_list(PredIds, !Queue)
-            ;
-                true
-            ),
+            predicate_table_lookup_sym(PredicateTable,
+                may_be_partially_qualified, Name, PredIds),
+            queue.put_list(PredIds, !Queue),
             !:DeadInfo = pred_elim_info(ModuleInfo, !.Queue, Examined,
                 Needed, !.NeededNames)
         )
Index: deep_profiling.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/deep_profiling.m,v
retrieving revision 1.118
diff -u -b -r1.118 deep_profiling.m
--- deep_profiling.m	2 Jul 2012 01:16:33 -0000	1.118
+++ deep_profiling.m	10 Sep 2012 14:20:36 -0000
@@ -1890,17 +1890,15 @@
 get_deep_profile_builtin_ppid(ModuleInfo, Name, Arity, PredId, ProcId) :-
     ModuleName = mercury_profiling_builtin_module,
     module_info_get_predicate_table(ModuleInfo, PredTable),
-    (
-        predicate_table_search_pred_m_n_a(PredTable,
-            is_fully_qualified, ModuleName, Name, Arity, PredIds)
-    ->
+    predicate_table_lookup_pred_m_n_a(PredTable,
+        is_fully_qualified, ModuleName, Name, Arity, PredIds),
         (
             PredIds = [],
             unexpected($module, $pred, "no pred_id")
         ;
             PredIds = [PredId],
             predicate_table_get_preds(PredTable, Preds),
-            lookup(Preds, PredId, PredInfo),
+        map.lookup(Preds, PredId, PredInfo),
             ProcIds = pred_info_procids(PredInfo),
             (
                 ProcIds = [],
@@ -1914,10 +1912,6 @@
         ;
             PredIds = [_, _ | _],
             unexpected($module, $pred, "pred_id not unique")
-        )
-    ;
-        format("couldn't find pred_id for `%s'/%d", [s(Name), i(Arity)], Msg),
-        unexpected($module, $pred, Msg)
     ).
 
 %-----------------------------------------------------------------------------%
Index: elds_to_erlang.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/elds_to_erlang.m,v
retrieving revision 1.43
diff -u -b -r1.43 elds_to_erlang.m
--- elds_to_erlang.m	15 Jun 2011 01:05:33 -0000	1.43
+++ elds_to_erlang.m	10 Sep 2012 14:20:36 -0000
@@ -267,8 +267,8 @@
 
 should_add_main_wrapper(ModuleInfo) = AddMainWrapper :-
     module_info_get_predicate_table(ModuleInfo, PredTable),
+    predicate_table_lookup_pred_name_arity(PredTable, "main", 2, PredIds),
     (
-        predicate_table_search_pred_name_arity(PredTable, "main", 2, PredIds),
         list.member(PredId, PredIds),
         module_info_pred_info(ModuleInfo, PredId, PredInfo),
         pred_info_get_import_status(PredInfo, ImportStatus),
Index: hlds_module.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/hlds_module.m,v
retrieving revision 1.177
diff -u -b -r1.177 hlds_module.m
--- hlds_module.m	5 Sep 2012 06:18:14 -0000	1.177
+++ hlds_module.m	10 Sep 2012 14:20:37 -0000
@@ -1122,10 +1122,9 @@
 
 module_info_user_init_fn_pred_procs_2(MI, SymName / Arity, PredProcId) :-
     module_info_get_predicate_table(MI, PredTable),
-    (
-        predicate_table_search_pred_sym_arity(PredTable,
-            may_be_partially_qualified, SymName, Arity, [PredId])
-    ->
+    predicate_table_lookup_pred_sym_arity(PredTable,
+        may_be_partially_qualified, SymName, Arity, PredIds),
+    ( PredIds = [PredId] ->
         pred_table.get_proc_id(MI, PredId, ProcId),
         PredProcId = proc(PredId, ProcId)
     ;
Index: intermod.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/intermod.m,v
retrieving revision 1.275
diff -u -b -r1.275 intermod.m
--- intermod.m	10 Sep 2012 13:33:07 -0000	1.275
+++ intermod.m	10 Sep 2012 14:20:39 -0000
@@ -998,10 +998,10 @@
     TypeCtors = TypeCtors0 ++ TypeCtors1,
 
     module_info_get_predicate_table(ModuleInfo, PredicateTable),
+    predicate_table_lookup_func_sym_arity(PredicateTable,
+        may_be_partially_qualified, InstanceMethodName0, MethodArity, PredIds),
     (
-        predicate_table_search_func_sym_arity(PredicateTable,
-            may_be_partially_qualified, InstanceMethodName0,
-            MethodArity, PredIds),
+        PredIds = [_ | _],
         find_matching_pred_id(ModuleInfo, PredIds, MethodCallTVarSet,
             MethodCallExistQTVars, MethodCallArgTypes,
             MethodCallHeadTypeParams, no, MethodContext,
Index: make_hlds_passes.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make_hlds_passes.m,v
retrieving revision 1.122
diff -u -b -r1.122 make_hlds_passes.m
--- make_hlds_passes.m	10 Sep 2012 13:33:07 -0000	1.122
+++ make_hlds_passes.m	10 Sep 2012 14:20:40 -0000
@@ -1009,15 +1009,16 @@
         list.length(TypesAndModes, Arity),
         adjust_func_arity(pf_function, FuncArity, Arity),
         module_info_get_predicate_table(!.ModuleInfo, PredTable0),
+        predicate_table_lookup_func_sym_arity(PredTable0,
+            is_fully_qualified, SymName, FuncArity, PredIds),
         (
-            predicate_table_search_func_sym_arity(PredTable0,
-                is_fully_qualified, SymName, FuncArity, PredIds)
-        ->
+            PredIds = [_ | _],
             predicate_table_get_preds(PredTable0, Preds0),
             maybe_add_default_func_modes(PredIds, Preds0, Preds),
             predicate_table_set_preds(Preds, PredTable0, PredTable),
             module_info_set_predicate_table(PredTable, !ModuleInfo)
         ;
+            PredIds = [],
             unexpected($module, $pred, "can't find func declaration")
         )
     ).
@@ -1485,11 +1486,21 @@
     % ModuleInfo. This is implied by the handling for the C backends.
 
     module_info_get_predicate_table(!.ModuleInfo, PredTable),
+    predicate_table_lookup_pred_sym_arity(PredTable,
+        may_be_partially_qualified, SymName, Arity, PredIds),
     (
-        predicate_table_search_pred_sym_arity(PredTable,
-            may_be_partially_qualified, SymName, Arity, PredIds)
-    ->
-        ( PredIds = [PredId] ->
+        PredIds = [],
+        Pieces = [words("Error:"), sym_name_and_arity(SymName/Arity),
+            words("used in initialise declaration"),
+            words("does not have a corresponding pred declaration."), nl],
+        Msg = simple_msg(Context, [always(Pieces)]),
+        Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
+        !:Specs = [Spec | !.Specs]
+    ;
+        PredIds = [HeadPredId | TailPredIds],
+        (
+            TailPredIds = [],
+            PredId = HeadPredId,
             module_info_pred_info(!.ModuleInfo, PredId, PredInfo),
             pred_info_get_arg_types(PredInfo, ArgTypes),
             pred_info_get_procedures(PredInfo, ProcTable),
@@ -1560,6 +1571,7 @@
                 !:Specs = [Spec | !.Specs]
             )
         ;
+            TailPredIds = [_ | _],
             Pieces = [words("Error:"), sym_name_and_arity(SymName/Arity),
                 words("used in initialise declaration"),
                 words("multiple pred declarations."), nl],
@@ -1567,13 +1579,6 @@
             Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
             !:Specs = [Spec | !.Specs]
         )
-    ;
-        Pieces = [words("Error:"), sym_name_and_arity(SymName/Arity),
-            words("used in initialise declaration"),
-            words("does not have a corresponding pred declaration."), nl],
-        Msg = simple_msg(Context, [always(Pieces)]),
-        Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
-        !:Specs = [Spec | !.Specs]
     ).
 add_pass_3_initialise(ItemInitialise, Status, !ModuleInfo, !QualInfo,
         !Specs) :-
@@ -1661,12 +1666,21 @@
         Origin = user
     ),
     module_info_get_predicate_table(!.ModuleInfo, PredTable),
+    predicate_table_lookup_pred_sym_arity(PredTable,
+        may_be_partially_qualified, SymName, Arity, PredIds),
     (
-        predicate_table_search_pred_sym_arity(PredTable,
-            may_be_partially_qualified, SymName, Arity, PredIds)
-    ->
+        PredIds = [],
+        Pieces = [words("Error:"), sym_name_and_arity(SymName/Arity),
+            words("used in finalise declaration"),
+            words("does not have a corresponding pred declaration."), nl],
+        Msg = simple_msg(Context, [always(Pieces)]),
+        Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
+        !:Specs = [Spec | !.Specs]
+    ;
+        PredIds = [HeadPredId | TailPredIds],
         (
-            PredIds = [PredId],
+            TailPredIds = [],
+            PredId = HeadPredId,
             module_info_pred_info(!.ModuleInfo, PredId, PredInfo),
             pred_info_get_arg_types(PredInfo, ArgTypes),
             pred_info_get_procedures(PredInfo, ProcTable),
@@ -1736,15 +1750,7 @@
                 !:Specs = [Spec | !.Specs]
             )
         ;
-            PredIds = [],
-            Pieces = [words("Error:"), sym_name_and_arity(SymName/Arity),
-                words("used in finalise declaration"),
-                words("has no pred declarations."), nl],
-            Msg = simple_msg(Context, [always(Pieces)]),
-            Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
-            !:Specs = [Spec | !.Specs]
-        ;
-            PredIds = [_, _ | _],
+            TailPredIds = [_ | _],
             Pieces = [words("Error:"), sym_name_and_arity(SymName/Arity),
                 words("used in finalise declaration"),
                 words("has multiple pred declarations."), nl],
@@ -1752,13 +1758,6 @@
             Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
             !:Specs = [Spec | !.Specs]
         )
-    ;
-        Pieces = [words("Error:"), sym_name_and_arity(SymName/Arity),
-            words("used in finalise declaration"),
-            words("does not have a corresponding pred declaration."), nl],
-        Msg = simple_msg(Context, [always(Pieces)]),
-        Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
-        !:Specs = [Spec | !.Specs]
     ).
 
 :- func target_lang_to_foreign_export_lang(compilation_target)
@@ -3122,14 +3121,15 @@
 
 add_stratified_pred(PragmaName, Name, Arity, Context, !ModuleInfo, !Specs) :-
     module_info_get_predicate_table(!.ModuleInfo, PredTable0),
+    predicate_table_lookup_sym_arity(PredTable0, is_fully_qualified,
+        Name, Arity, PredIds),
     (
-        predicate_table_search_sym_arity(PredTable0, is_fully_qualified,
-            Name, Arity, PredIds)
-    ->
+        PredIds = [_ | _],
         module_info_get_stratified_preds(!.ModuleInfo, StratPredIds0),
         set.insert_list(PredIds, StratPredIds0, StratPredIds),
         module_info_set_stratified_preds(StratPredIds, !ModuleInfo)
     ;
+        PredIds = [],
         DescPieces = [quote(":- pragma " ++ PragmaName), words("declaration")],
         undefined_pred_or_func_error(Name, Arity, Context, DescPieces, !Specs)
     ).
@@ -3156,8 +3156,9 @@
 
 do_add_pred_marker(PragmaName, Name, Arity, Status, MustBeExported, Context,
         UpdatePredInfo, !ModuleInfo, PredIds, !Specs) :-
-    ( get_matching_pred_ids(!.ModuleInfo, Name, Arity, PredIds0) ->
-        PredIds = PredIds0,
+    get_matching_pred_ids(!.ModuleInfo, Name, Arity, PredIds),
+    (
+        PredIds = [_ | _],
         module_info_get_predicate_table(!.ModuleInfo, PredTable0),
         predicate_table_get_preds(PredTable0, Preds0),
 
@@ -3179,7 +3180,7 @@
     ).
 
 :- pred get_matching_pred_ids(module_info::in, sym_name::in, arity::in,
-    list(pred_id)::out) is semidet.
+    list(pred_id)::out) is det.
 
 get_matching_pred_ids(Module0, Name, Arity, PredIds) :-
     module_info_get_predicate_table(Module0, PredTable0),
@@ -3189,7 +3190,7 @@
         unexpected($module, $pred, "unqualified name")
     ;
         Name = qualified(_, _),
-        predicate_table_search_sym_arity(PredTable0, is_fully_qualified,
+        predicate_table_lookup_sym_arity(PredTable0, is_fully_qualified,
             Name, Arity, PredIds)
     ).
 
@@ -3197,12 +3198,13 @@
     % `external' declarations can only apply to things defined in this module,
     % since everything else is already external.
     module_info_get_predicate_table(!.ModuleInfo, PredicateTable0),
+    predicate_table_lookup_sym_arity(PredicateTable0, is_fully_qualified,
+        PredName, Arity, PredIds),
     (
-        predicate_table_search_sym_arity(PredicateTable0, is_fully_qualified,
-            PredName, Arity, PredIdList)
-    ->
-        module_mark_preds_as_external(PredIdList, !ModuleInfo)
+        PredIds = [_ | _],
+        module_mark_preds_as_external(PredIds, !ModuleInfo)
     ;
+        PredIds = [],
         undefined_pred_or_func_error(PredName, Arity, Context,
             [quote(":- external"), words("declaration")], !Specs)
     ).
Index: mmc_analysis.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mmc_analysis.m,v
retrieving revision 1.31
diff -u -b -r1.31 mmc_analysis.m
--- mmc_analysis.m	23 May 2011 05:08:07 -0000	1.31
+++ mmc_analysis.m	10 Sep 2012 14:20:40 -0000
@@ -140,13 +140,16 @@
 func_id_to_ppid(ModuleInfo, ModuleName, FuncId, PPId) :-
     FuncId = func_id(PredOrFunc, FuncName, Arity, ProcId),
     module_info_get_predicate_table(ModuleInfo, PredTable),
-    (
-        predicate_table_search_pf_m_n_a(PredTable, is_fully_qualified,
+    predicate_table_lookup_pf_m_n_a(PredTable, is_fully_qualified,
             PredOrFunc, ModuleName, FuncName, Arity, PredIds),
-        PredIds = [PredId]
-    ->
+    (
+        PredIds = [],
+        unexpected($module, $pred, "no predicate")
+    ;
+        PredIds = [PredId],
         PPId = proc(PredId, ProcId)
     ;
+        PredIds = [_, _ | _],
         unexpected($module, $pred, "more than one predicate")
     ).
 
Index: post_typecheck.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/post_typecheck.m,v
retrieving revision 1.160
diff -u -b -r1.160 post_typecheck.m
--- post_typecheck.m	2 Jul 2012 01:16:36 -0000	1.160
+++ post_typecheck.m	10 Sep 2012 14:20:41 -0000
@@ -1068,8 +1068,9 @@
         pred_info_get_markers(!.PredInfo, Markers),
         module_info_get_predicate_table(ModuleInfo, PredTable),
         % This search will usually fail, so do it first.
-        predicate_table_search_func_sym_arity(PredTable,
+        predicate_table_lookup_func_sym_arity(PredTable,
             calls_are_fully_qualified(Markers), PredName, Arity, PredIds),
+        PredIds = [_ | _],
 
         % We don't do this for compiler-generated predicates; they are assumed
         % to have been generated with all functions already expanded. If we did
Index: pred_table.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/pred_table.m,v
retrieving revision 1.19
diff -u -b -r1.19 pred_table.m
--- pred_table.m	23 May 2011 05:08:09 -0000	1.19
+++ pred_table.m	10 Sep 2012 14:20:42 -0000
@@ -114,56 +114,62 @@
     % Search the table for (a) predicates or functions (b) predicates only
     % or (c) functions only matching this (possibly module-qualified) sym_name.
     %
-:- pred predicate_table_search_sym(predicate_table::in, is_fully_qualified::in,
-    sym_name::in, list(pred_id)::out) is semidet.
+:- pred predicate_table_lookup_sym(predicate_table::in, is_fully_qualified::in,
+    sym_name::in, list(pred_id)::out) is det.
 
-:- pred predicate_table_search_pred_sym(predicate_table::in,
-    is_fully_qualified::in, sym_name::in, list(pred_id)::out) is semidet.
+:- pred predicate_table_lookup_pred_sym(predicate_table::in,
+    is_fully_qualified::in, sym_name::in, list(pred_id)::out) is det.
 
-:- pred predicate_table_search_func_sym(predicate_table::in,
-    is_fully_qualified::in, sym_name::in, list(pred_id)::out) is semidet.
+:- pred predicate_table_lookup_func_sym(predicate_table::in,
+    is_fully_qualified::in, sym_name::in, list(pred_id)::out) is det.
 
     % Search the table for (a) predicates or functions (b) predicates only
     % or (c) functions only matching this (possibly module-qualified)
     % sym_name & arity.
     %
-:- pred predicate_table_search_sym_arity(predicate_table::in,
+:- pred predicate_table_lookup_sym_arity(predicate_table::in,
     is_fully_qualified::in, sym_name::in, arity::in, list(pred_id)::out)
-    is semidet.
+    is det.
 
-:- pred predicate_table_search_pred_sym_arity(predicate_table::in,
+:- pred predicate_table_lookup_pred_sym_arity(predicate_table::in,
     is_fully_qualified::in, sym_name::in, arity::in, list(pred_id)::out)
-    is semidet.
+    is det.
 
-:- pred predicate_table_search_func_sym_arity(predicate_table::in,
+:- pred predicate_table_lookup_func_sym_arity(predicate_table::in,
     is_fully_qualified::in, sym_name::in, arity::in, list(pred_id)::out)
-    is semidet.
+    is det.
 
     % Search the table for (a) predicates or functions
     % (b) predicates only or (c) functions only matching this name.
     %
-:- pred predicate_table_search_name(predicate_table::in, string::in,
-    list(pred_id)::out) is semidet.
+:- pred predicate_table_lookup_name(predicate_table::in, string::in,
+    list(pred_id)::out) is det.
 
-:- pred predicate_table_search_pred_name(predicate_table::in, string::in,
-    list(pred_id)::out) is semidet.
+:- pred predicate_table_lookup_pred_name(predicate_table::in, string::in,
+    list(pred_id)::out) is det.
 
-:- pred predicate_table_search_func_name(predicate_table::in, string::in,
-    list(pred_id)::out) is semidet.
+:- pred predicate_table_lookup_func_name(predicate_table::in, string::in,
+    list(pred_id)::out) is det.
 
     % Search the table for (a) predicates or functions (b) predicates only
     % or (c) functions only matching this name & arity. When searching for
     % functions, the arity used is the arity of the function, not the arity
     % N+1 predicate that it gets converted to.
     %
-:- pred predicate_table_search_name_arity(predicate_table::in, string::in,
-    arity::in, list(pred_id)::out) is semidet.
+:- pred predicate_table_lookup_name_arity(predicate_table::in, string::in,
+    arity::in, list(pred_id)::out) is det.
+
+:- pred predicate_table_lookup_pred_name_arity(predicate_table::in, string::in,
+    arity::in, list(pred_id)::out) is det.
 
-:- pred predicate_table_search_pred_name_arity(predicate_table::in, string::in,
-    arity::in, list(pred_id)::out) is semidet.
+:- pred predicate_table_lookup_func_name_arity(predicate_table::in, string::in,
+    arity::in, list(pred_id)::out) is det.
 
-:- pred predicate_table_search_func_name_arity(predicate_table::in, string::in,
-    arity::in, list(pred_id)::out) is semidet.
+    % Is the item known to be fully qualified? If so, a search for
+    % `pred foo.bar/2' will not match `pred baz.foo.bar/2'.
+:- type is_fully_qualified
+    --->    is_fully_qualified
+    ;       may_be_partially_qualified.
 
     % Search the table for (a) predicates or functions (b) predicates only
     % or (c) functions only matching this module, name & arity. When searching
@@ -179,24 +185,18 @@
     % break anything too badly...
     %
     % (`m_n_a' here is short for "module, name, arity".)
-
-    % Is the item known to be fully qualified? If so, a search for
-    % `pred foo.bar/2' will not match `pred baz.foo.bar/2'.
-:- type is_fully_qualified
-    --->    is_fully_qualified
-    ;       may_be_partially_qualified.
-
-:- pred predicate_table_search_m_n_a(predicate_table::in,
+    %
+:- pred predicate_table_lookup_m_n_a(predicate_table::in,
     is_fully_qualified::in, module_name::in, string::in, arity::in,
-    list(pred_id)::out) is semidet.
+    list(pred_id)::out) is det.
 
-:- pred predicate_table_search_pred_m_n_a(predicate_table::in,
+:- pred predicate_table_lookup_pred_m_n_a(predicate_table::in,
     is_fully_qualified::in, module_name::in, string::in, arity::in,
-    list(pred_id)::out) is semidet.
+    list(pred_id)::out) is det.
 
-:- pred predicate_table_search_func_m_n_a(predicate_table::in,
+:- pred predicate_table_lookup_func_m_n_a(predicate_table::in,
     is_fully_qualified::in, module_name::in, string::in, arity::in,
-    list(pred_id)::out) is semidet.
+    list(pred_id)::out) is det.
 
     % Search the table for predicates or functions matching this pred_or_func
     % category, module, name, and arity. When searching for functions, the
@@ -205,9 +205,9 @@
     % NB. This is opposite to what happens with the search predicates
     % declared above!!
     %
-:- pred predicate_table_search_pf_m_n_a(predicate_table::in,
+:- pred predicate_table_lookup_pf_m_n_a(predicate_table::in,
     is_fully_qualified::in, pred_or_func::in, module_name::in, string::in,
-    arity::in, list(pred_id)::out) is semidet.
+    arity::in, list(pred_id)::out) is det.
 
     % Search the table for predicates or functions matching this pred_or_func
     % category, name, and arity. When searching for functions, the arity used
@@ -216,9 +216,8 @@
     % NB. This is opposite to what happens with the search predicates
     % declared above!!
     %
-:- pred predicate_table_search_pf_name_arity(predicate_table::in,
-    pred_or_func::in, string::in, arity::in, list(pred_id)::out)
-    is semidet.
+:- pred predicate_table_lookup_pf_name_arity(predicate_table::in,
+    pred_or_func::in, string::in, arity::in, list(pred_id)::out) is det.
 
     % Search the table for predicates or functions matching this pred_or_func
     % category, sym_name, and arity. When searching for functions, the arity
@@ -227,16 +226,16 @@
     % NB. This is opposite to what happens with the search predicates
     % declared above!!
     %
-:- pred predicate_table_search_pf_sym_arity(predicate_table::in,
+:- pred predicate_table_lookup_pf_sym_arity(predicate_table::in,
     is_fully_qualified::in, pred_or_func::in, sym_name::in, arity::in,
-    list(pred_id)::out) is semidet.
+    list(pred_id)::out) is det.
 
     % Search the table for predicates or functions matching
     % this pred_or_func category and sym_name.
     %
-:- pred predicate_table_search_pf_sym(predicate_table::in,
+:- pred predicate_table_lookup_pf_sym(predicate_table::in,
     is_fully_qualified::in, pred_or_func::in, sym_name::in,
-    list(pred_id)::out) is semidet.
+    list(pred_id)::out) is det.
 
     % predicate_table_insert(PredTable0, PredInfo,
     %   NeedQual, PartialQualInfo, PredId, PredTable):
@@ -517,208 +516,242 @@
 
 %-----------------------------------------------------------------------------%
 
-predicate_table_search_sym(PredicateTable, may_be_partially_qualified,
-        unqualified(Name), PredIdList) :-
-    predicate_table_search_name(PredicateTable, Name, PredIdList).
-predicate_table_search_sym(PredicateTable, IsFullyQualified,
-        qualified(Module, Name), PredIdList) :-
-    predicate_table_search_module_name(PredicateTable, IsFullyQualified,
-        Module, Name, PredIdList),
-    PredIdList = [_ | _].
-
-predicate_table_search_pred_sym(PredicateTable, may_be_partially_qualified,
-        unqualified(Name), PredIdList) :-
-    predicate_table_search_pred_name(PredicateTable, Name, PredIdList).
-predicate_table_search_pred_sym(PredicateTable, IsFullyQualified,
-        qualified(Module, Name), PredIdList) :-
-    predicate_table_search_pred_module_name(PredicateTable,
-        IsFullyQualified, Module, Name, PredIdList),
-    PredIdList = [_ | _].
-
-predicate_table_search_func_sym(PredicateTable, may_be_partially_qualified,
-        unqualified(Name), PredIdList) :-
-    predicate_table_search_func_name(PredicateTable, Name, PredIdList).
-predicate_table_search_func_sym(PredicateTable, IsFullyQualified,
-        qualified(Module, Name), PredIdList) :-
-    predicate_table_search_func_module_name(PredicateTable,
-        IsFullyQualified, Module, Name, PredIdList),
-    PredIdList = [_ | _].
+predicate_table_lookup_sym(PredicateTable, IsFullyQualified, SymName,
+        PredIds) :-
+    (
+        SymName = unqualified(Name),
+        (
+            IsFullyQualified = may_be_partially_qualified,
+            predicate_table_lookup_name(PredicateTable, Name, PredIds)
+        ;
+            IsFullyQualified = is_fully_qualified,
+            PredIds = []
+        )
+    ;
+        SymName = qualified(Module, Name),
+        predicate_table_lookup_module_name(PredicateTable, IsFullyQualified,
+            Module, Name, PredIds)
+    ).
 
-%-----------------------------------------------------------------------------%
+predicate_table_lookup_pred_sym(PredicateTable, IsFullyQualified, SymName,
+        PredIds) :-
+    (
+        SymName = unqualified(Name),
+        (
+            IsFullyQualified = may_be_partially_qualified,
+            predicate_table_lookup_pred_name(PredicateTable, Name, PredIds)
+        ;
+            IsFullyQualified = is_fully_qualified,
+            PredIds = []
+        )
+    ;
+        SymName = qualified(Module, Name),
+        predicate_table_lookup_pred_module_name(PredicateTable,
+            IsFullyQualified, Module, Name, PredIds)
+    ).
 
-predicate_table_search_sym_arity(PredicateTable, IsFullyQualified,
-        qualified(Module, Name), Arity, PredIdList) :-
-    predicate_table_search_m_n_a(PredicateTable,
-        IsFullyQualified, Module, Name, Arity, PredIdList).
-predicate_table_search_sym_arity(PredicateTable, may_be_partially_qualified,
-        unqualified(Name), Arity, PredIdList) :-
-    predicate_table_search_name_arity(PredicateTable, Name, Arity, PredIdList).
-
-predicate_table_search_pred_sym_arity(PredicateTable, IsFullyQualified,
-        qualified(Module, Name), Arity, PredIdList) :-
-    predicate_table_search_pred_m_n_a(PredicateTable,
-        IsFullyQualified, Module, Name, Arity, PredIdList).
-predicate_table_search_pred_sym_arity(PredicateTable,
-        may_be_partially_qualified, unqualified(Name),
-        Arity, PredIdList) :-
-    predicate_table_search_pred_name_arity(PredicateTable, Name, Arity,
-        PredIdList).
-
-predicate_table_search_func_sym_arity(PredicateTable, IsFullyQualified,
-        qualified(Module, Name), Arity, PredIdList) :-
-    predicate_table_search_func_m_n_a(PredicateTable,
-        IsFullyQualified, Module, Name, Arity, PredIdList).
-predicate_table_search_func_sym_arity(PredicateTable,
-        may_be_partially_qualified, unqualified(Name),
-        Arity, PredIdList) :-
-    predicate_table_search_func_name_arity(PredicateTable, Name, Arity,
-        PredIdList).
+predicate_table_lookup_func_sym(PredicateTable, IsFullyQualified, SymName,
+        PredIds) :-
+    (
+        SymName = unqualified(Name),
+        (
+            IsFullyQualified = may_be_partially_qualified,
+            predicate_table_lookup_func_name(PredicateTable, Name, PredIds)
+        ;
+            IsFullyQualified = is_fully_qualified,
+            PredIds = []
+        )
+    ;
+        SymName = qualified(Module, Name),
+        predicate_table_lookup_func_module_name(PredicateTable,
+            IsFullyQualified, Module, Name, PredIds)
+    ).
 
 %-----------------------------------------------------------------------------%
 
-predicate_table_search_name(PredicateTable, Name, PredIds) :-
-    ( predicate_table_search_pred_name(PredicateTable, Name, PredPredIds0) ->
-        PredPredIds = PredPredIds0
+predicate_table_lookup_sym_arity(PredicateTable, IsFullyQualified,
+        SymName, Arity, PredIds) :-
+    (
+        SymName = unqualified(Name),
+        (
+            IsFullyQualified = may_be_partially_qualified,
+            predicate_table_lookup_name_arity(PredicateTable, Name, Arity,
+                PredIds)
     ;
-        PredPredIds = []
-    ),
-    ( predicate_table_search_func_name(PredicateTable, Name, FuncPredIds0) ->
-        FuncPredIds = FuncPredIds0
+            IsFullyQualified = is_fully_qualified,
+            PredIds = []
+        )
     ;
-        FuncPredIds = []
-    ),
-    list.append(FuncPredIds, PredPredIds, PredIds),
-    PredIds = [_ | _].
+        SymName = qualified(Module, Name),
+        predicate_table_lookup_m_n_a(PredicateTable,
+            IsFullyQualified, Module, Name, Arity, PredIds)
+    ).
 
-predicate_table_search_pred_name(PredicateTable, PredName, PredIds) :-
-    map.search(PredicateTable ^ pred_name_index, PredName, PredIds).
+predicate_table_lookup_pred_sym_arity(PredicateTable, IsFullyQualified,
+        SymName, Arity, PredIds) :-
+    (
+        SymName = unqualified(Name),
+        (
+            IsFullyQualified = may_be_partially_qualified,
+            predicate_table_lookup_pred_name_arity(PredicateTable, Name, Arity,
+                PredIds)
+        ;
+            IsFullyQualified = is_fully_qualified,
+            PredIds = []
+        )
+    ;
+        SymName = qualified(Module, Name),
+        predicate_table_lookup_pred_m_n_a(PredicateTable,
+            IsFullyQualified, Module, Name, Arity, PredIds)
+    ).
 
-predicate_table_search_func_name(PredicateTable, FuncName, PredIds) :-
-    map.search(PredicateTable ^ func_name_index, FuncName, PredIds).
+predicate_table_lookup_func_sym_arity(PredicateTable, IsFullyQualified,
+        SymName, Arity, PredIds) :-
+    (
+        SymName = unqualified(Name),
+        (
+            IsFullyQualified = may_be_partially_qualified,
+            predicate_table_lookup_func_name_arity(PredicateTable, Name, Arity,
+                PredIds)
+        ;
+            IsFullyQualified = is_fully_qualified,
+            PredIds = []
+        )
+    ;
+        SymName = qualified(Module, Name),
+        predicate_table_lookup_func_m_n_a(PredicateTable,
+            IsFullyQualified, Module, Name, Arity, PredIds)
+    ).
 
 %-----------------------------------------------------------------------------%
 
-:- pred predicate_table_search_module_name(predicate_table::in,
+predicate_table_lookup_name(PredicateTable, Name, PredIds) :-
+    predicate_table_lookup_pred_name(PredicateTable, Name, PredPredIds),
+    predicate_table_lookup_func_name(PredicateTable, Name, FuncPredIds),
+    PredIds = FuncPredIds ++ PredPredIds.
+
+predicate_table_lookup_pred_name(PredicateTable, PredName, PredIds) :-
+    ( map.search(PredicateTable ^ pred_name_index, PredName, PredIdsPrime) ->
+        PredIds = PredIdsPrime
+    ;
+        PredIds = []
+    ).
+
+predicate_table_lookup_func_name(PredicateTable, FuncName, PredIds) :-
+    ( map.search(PredicateTable ^ func_name_index, FuncName, PredIdsPrime) ->
+        PredIds = PredIdsPrime
+    ;
+        PredIds = []
+    ).
+
+%-----------------------------------------------------------------------------%
+
+:- pred predicate_table_lookup_module_name(predicate_table::in,
     is_fully_qualified::in, module_name::in, string::in,
-    list(pred_id)::out) is semidet.
+    list(pred_id)::out) is det.
 
-predicate_table_search_module_name(PredicateTable, IsFullyQualified,
+predicate_table_lookup_module_name(PredicateTable, IsFullyQualified,
         Module, Name, PredIds) :-
-    (
-        predicate_table_search_pred_module_name(PredicateTable,
-            IsFullyQualified, Module, Name, PredPredIds0)
-    ->
-        PredPredIds = PredPredIds0
-    ;
-        PredPredIds = []
-    ),
-    (
-        predicate_table_search_func_module_name(PredicateTable,
-            IsFullyQualified, Module, Name, FuncPredIds0)
-    ->
-        FuncPredIds = FuncPredIds0
-    ;
-        FuncPredIds = []
-    ),
-    list.append(FuncPredIds, PredPredIds, PredIds),
-    PredIds = [_ | _].
+    predicate_table_lookup_pred_module_name(PredicateTable,
+        IsFullyQualified, Module, Name, PredPredIds),
+    predicate_table_lookup_func_module_name(PredicateTable,
+        IsFullyQualified, Module, Name, FuncPredIds),
+    PredIds = FuncPredIds ++ PredPredIds.
 
-:- pred predicate_table_search_pred_module_name(predicate_table::in,
+:- pred predicate_table_lookup_pred_module_name(predicate_table::in,
     is_fully_qualified::in, module_name::in, string::in,
-    list(pred_id)::out) is semidet.
+    list(pred_id)::out) is det.
 
-predicate_table_search_pred_module_name(PredicateTable, IsFullyQualified,
+predicate_table_lookup_pred_module_name(PredicateTable, IsFullyQualified,
         Module, PredName, PredIds) :-
     Pred_MNA_Index = PredicateTable ^ pred_module_name_arity_index,
-    map.search(Pred_MNA_Index, Module - PredName, Arities),
+    ( map.search(Pred_MNA_Index, Module - PredName, Arities) ->
     map.values(Arities, PredIdLists),
     list.condense(PredIdLists, PredIds0),
     maybe_filter_pred_ids_matching_module(IsFullyQualified,
-        Module, PredicateTable, PredIds0, PredIds).
+            Module, PredicateTable, PredIds0, PredIds)
+    ;
+        PredIds = []
+    ).
 
-:- pred predicate_table_search_func_module_name(predicate_table::in,
+:- pred predicate_table_lookup_func_module_name(predicate_table::in,
     is_fully_qualified::in, module_name::in, string::in,
-    list(pred_id)::out) is semidet.
+    list(pred_id)::out) is det.
 
-predicate_table_search_func_module_name(PredicateTable, IsFullyQualified,
+predicate_table_lookup_func_module_name(PredicateTable, IsFullyQualified,
         Module, FuncName, PredIds) :-
     Func_MNA_Index = PredicateTable ^ func_module_name_arity_index,
-    map.search(Func_MNA_Index, Module - FuncName, Arities),
+    ( map.search(Func_MNA_Index, Module - FuncName, Arities) ->
     map.values(Arities, PredIdLists),
     list.condense(PredIdLists, PredIds0),
     maybe_filter_pred_ids_matching_module(IsFullyQualified,
-        Module, PredicateTable, PredIds0, PredIds).
+            Module, PredicateTable, PredIds0, PredIds)
+    ;
+        PredIds = []
+    ).
 
 %-----------------------------------------------------------------------------%
 
-predicate_table_search_name_arity(PredicateTable, Name, Arity, PredIds) :-
-    (
-        predicate_table_search_pred_name_arity(PredicateTable,
-            Name, Arity, PredPredIds0)
-    ->
-        PredPredIds = PredPredIds0
-    ;
-        PredPredIds = []
-    ),
-    (
-        predicate_table_search_func_name_arity(PredicateTable,
-            Name, Arity, FuncPredIds0)
-    ->
-        FuncPredIds = FuncPredIds0
-    ;
-        FuncPredIds = []
-    ),
-    list.append(FuncPredIds, PredPredIds, PredIds),
-    PredIds = [_ | _].
+predicate_table_lookup_name_arity(PredicateTable, Name, Arity, PredIds) :-
+    predicate_table_lookup_pred_name_arity(PredicateTable,
+        Name, Arity, PredPredIds),
+    predicate_table_lookup_func_name_arity(PredicateTable,
+        Name, Arity, FuncPredIds),
+    PredIds = FuncPredIds ++ PredPredIds.
 
-predicate_table_search_pred_name_arity(PredicateTable, PredName, Arity,
+predicate_table_lookup_pred_name_arity(PredicateTable, PredName, Arity,
         PredIds) :-
     PredNameArityIndex = PredicateTable ^ pred_name_arity_index,
-    map.search(PredNameArityIndex, PredName / Arity, PredIds).
+    ( map.search(PredNameArityIndex, PredName / Arity, PredIdsPrime) ->
+        PredIds = PredIdsPrime
+    ;
+        PredIds = []
+    ).
 
-predicate_table_search_func_name_arity(PredicateTable, FuncName, Arity,
+predicate_table_lookup_func_name_arity(PredicateTable, FuncName, Arity,
         PredIds) :-
     FuncNameArityIndex = PredicateTable ^ func_name_arity_index,
-    map.search(FuncNameArityIndex, FuncName / Arity, PredIds).
+    ( map.search(FuncNameArityIndex, FuncName / Arity, PredIdsPrime) ->
+        PredIds = PredIdsPrime
+    ;
+        PredIds = []
+    ).
 
 %-----------------------------------------------------------------------------%
 
-predicate_table_search_m_n_a(PredicateTable, IsFullyQualified,
+predicate_table_lookup_m_n_a(PredicateTable, IsFullyQualified,
         Module, Name, Arity, PredIds) :-
-    (
-        predicate_table_search_pred_m_n_a(PredicateTable,
-            IsFullyQualified, Module, Name, Arity, PredPredIds0)
-    ->
-        PredPredIds = PredPredIds0
-    ;
-        PredPredIds = []
-    ),
-    (
-        predicate_table_search_func_m_n_a(PredicateTable,
-            IsFullyQualified, Module, Name, Arity, FuncPredIds0)
-    ->
-        FuncPredIds = FuncPredIds0
-    ;
-        FuncPredIds = []
-    ),
-    list.append(FuncPredIds, PredPredIds, PredIds),
-    PredIds = [_ | _].
+    predicate_table_lookup_pred_m_n_a(PredicateTable,
+        IsFullyQualified, Module, Name, Arity, PredPredIds),
+    predicate_table_lookup_func_m_n_a(PredicateTable,
+        IsFullyQualified, Module, Name, Arity, FuncPredIds),
+    PredIds = FuncPredIds ++ PredPredIds.
 
-predicate_table_search_pred_m_n_a(PredicateTable, IsFullyQualified,
+predicate_table_lookup_pred_m_n_a(PredicateTable, IsFullyQualified,
         Module, PredName, Arity, !:PredIds) :-
     P_MNA_Index = PredicateTable ^ pred_module_name_arity_index,
+    (
     map.search(P_MNA_Index, Module - PredName, ArityIndex),
-    map.search(ArityIndex, Arity, !:PredIds),
+        map.search(ArityIndex, Arity, !:PredIds)
+    ->
     maybe_filter_pred_ids_matching_module(IsFullyQualified, Module,
-        PredicateTable, !PredIds).
+            PredicateTable, !PredIds)
+    ;
+        !:PredIds = []
+    ).
 
-predicate_table_search_func_m_n_a(PredicateTable, IsFullyQualified,
+predicate_table_lookup_func_m_n_a(PredicateTable, IsFullyQualified,
         Module, FuncName, Arity, !:PredIds) :-
     F_MNA_Index = PredicateTable ^ func_module_name_arity_index,
+    (
     map.search(F_MNA_Index, Module - FuncName, ArityIndex),
-    map.search(ArityIndex, Arity, !:PredIds),
+        map.search(ArityIndex, Arity, !:PredIds)
+    ->
     maybe_filter_pred_ids_matching_module(IsFullyQualified, Module,
-        PredicateTable, !PredIds).
+            PredicateTable, !PredIds)
+    ;
+        !:PredIds = []
+    ).
 
 :- pred maybe_filter_pred_ids_matching_module(is_fully_qualified::in,
     module_name::in, predicate_table::in,
@@ -740,43 +773,61 @@
 
 %-----------------------------------------------------------------------------%
 
-predicate_table_search_pf_m_n_a(PredicateTable, IsFullyQualified,
-        pf_predicate, Module, Name, Arity, PredIds) :-
-    predicate_table_search_pred_m_n_a(PredicateTable, IsFullyQualified,
-        Module, Name, Arity, PredIds).
-predicate_table_search_pf_m_n_a(PredicateTable, IsFullyQualified,
-        pf_function, Module, Name, Arity, PredIds) :-
+predicate_table_lookup_pf_m_n_a(PredicateTable, IsFullyQualified,
+        PredOrFunc, Module, Name, Arity, PredIds) :-
+    (
+        PredOrFunc = pf_predicate,
+        predicate_table_lookup_pred_m_n_a(PredicateTable, IsFullyQualified,
+            Module, Name, Arity, PredIds)
+    ;
+        PredOrFunc = pf_function,
     FuncArity = Arity - 1,
-    predicate_table_search_func_m_n_a(PredicateTable, IsFullyQualified,
-        Module, Name, FuncArity, PredIds).
+        predicate_table_lookup_func_m_n_a(PredicateTable, IsFullyQualified,
+            Module, Name, FuncArity, PredIds)
+    ).
 
-predicate_table_search_pf_name_arity(PredicateTable, pf_predicate, Name, Arity,
-        PredIds) :-
-    predicate_table_search_pred_name_arity(PredicateTable, Name, Arity,
-        PredIds).
-predicate_table_search_pf_name_arity(PredicateTable, pf_function, Name, Arity,
+predicate_table_lookup_pf_name_arity(PredicateTable, PredOrFunc, Name, Arity,
         PredIds) :-
+    (
+        PredOrFunc = pf_predicate,
+        predicate_table_lookup_pred_name_arity(PredicateTable, Name, Arity,
+            PredIds)
+    ;
+        PredOrFunc = pf_function,
     FuncArity = Arity - 1,
-    predicate_table_search_func_name_arity(PredicateTable, Name, FuncArity,
-        PredIds).
+        predicate_table_lookup_func_name_arity(PredicateTable, Name, FuncArity,
+            PredIds)
+    ).
 
-predicate_table_search_pf_sym_arity(PredicateTable, IsFullyQualified,
-        PredOrFunc, qualified(Module, Name), Arity, PredIdList) :-
-    predicate_table_search_pf_m_n_a(PredicateTable,
-        IsFullyQualified, PredOrFunc, Module, Name, Arity, PredIdList).
-predicate_table_search_pf_sym_arity(PredicateTable, may_be_partially_qualified,
-        PredOrFunc, unqualified(Name), Arity, PredIdList) :-
-    predicate_table_search_pf_name_arity(PredicateTable, PredOrFunc,
-        Name, Arity, PredIdList).
-
-predicate_table_search_pf_sym(PredicateTable, IsFullyQualified, pf_predicate,
-        SymName, PredIdList) :-
-    predicate_table_search_pred_sym(PredicateTable, IsFullyQualified,
-        SymName, PredIdList).
-predicate_table_search_pf_sym(PredicateTable, IsFullyQualified, pf_function,
-        SymName, PredIdList) :-
-    predicate_table_search_func_sym(PredicateTable, IsFullyQualified,
-        SymName, PredIdList).
+predicate_table_lookup_pf_sym_arity(PredicateTable, IsFullyQualified,
+        PredOrFunc, SymName, Arity, PredIds) :-
+    (
+        SymName = qualified(Module, Name), 
+        predicate_table_lookup_pf_m_n_a(PredicateTable,
+            IsFullyQualified, PredOrFunc, Module, Name, Arity, PredIds)
+    ;
+        SymName = unqualified(Name),
+        (
+            IsFullyQualified = may_be_partially_qualified,
+            predicate_table_lookup_pf_name_arity(PredicateTable, PredOrFunc,
+                Name, Arity, PredIds)
+        ;
+            IsFullyQualified = is_fully_qualified,
+            PredIds = []
+        )
+    ).
+
+predicate_table_lookup_pf_sym(PredicateTable, IsFullyQualified, PredOrFunc,
+        SymName, PredIds) :-
+    (
+        PredOrFunc = pf_predicate,
+        predicate_table_lookup_pred_sym(PredicateTable, IsFullyQualified,
+            SymName, PredIds)
+    ;
+        PredOrFunc = pf_function,
+        predicate_table_lookup_func_sym(PredicateTable, IsFullyQualified,
+            SymName, PredIds)
+    ).
 
 %-----------------------------------------------------------------------------%
 
@@ -966,14 +1017,9 @@
     % when resolving overloading.
 
     module_info_get_predicate_table(ModuleInfo, PredTable),
-    (
-        predicate_table_search_pred_sym(PredTable,
-            calls_are_fully_qualified(CallerMarkers), PredName0, PredIds0)
-    ->
-        PredIds = PredIds0
-    ;
-        PredIds = []
-    ),
+    IsFullyQualified = calls_are_fully_qualified(CallerMarkers),
+    predicate_table_lookup_pred_sym(PredTable, IsFullyQualified,
+        PredName0, PredIds),
 
     % Check if there any of the candidate pred_ids have argument/return types
     % which subsume the actual argument/return types of this function call.
@@ -1076,9 +1122,9 @@
         ExistQTVars, ArgTypes, HeadTypeParams, ModuleInfo, Context, PredId) :-
     module_info_get_predicate_table(ModuleInfo, PredicateTable),
     list.length(ArgTypes, Arity),
-    (
-        predicate_table_search_pf_sym_arity(PredicateTable, IsFullyQualified,
+    predicate_table_lookup_pf_sym_arity(PredicateTable, IsFullyQualified,
             PredOrFunc, SymName, Arity, PredIds),
+    (
         % Resolve overloading using the argument types.
         find_matching_pred_id(ModuleInfo, PredIds, TVarSet, ExistQTVars,
             ArgTypes, HeadTypeParams, no, Context, PredId0, _PredName)
@@ -1147,15 +1193,16 @@
     (
         (
             PredOrFunc = pf_predicate,
-            predicate_table_search_pred_m_n_a(PredTable, is_fully_qualified,
-                ModuleName, ProcName, Arity, [PredId0])
+            predicate_table_lookup_pred_m_n_a(PredTable, is_fully_qualified,
+                ModuleName, ProcName, Arity, PredIds)
         ;
             PredOrFunc = pf_function,
-            predicate_table_search_func_m_n_a(PredTable, is_fully_qualified,
-                ModuleName, ProcName, Arity, [PredId0])
-        )
+            predicate_table_lookup_func_m_n_a(PredTable, is_fully_qualified,
+                ModuleName, ProcName, Arity, PredIds)
+        ),
+        PredIds = [PredIdPrime]
     ->
-        PredId = PredId0
+        PredId = PredIdPrime
     ;
         % Some of the table builtins are polymorphic, and for them we need
         % to subtract one from the arity to take into account the type_info
@@ -1165,19 +1212,20 @@
         % inefficient.
         (
             PredOrFunc = pf_predicate,
-            predicate_table_search_pred_m_n_a(PredTable, is_fully_qualified,
-                ModuleName, ProcName, Arity - 1, [PredId0])
+            predicate_table_lookup_pred_m_n_a(PredTable, is_fully_qualified,
+                ModuleName, ProcName, Arity - 1, PredIds)
         ;
             PredOrFunc = pf_function,
-            predicate_table_search_func_m_n_a(PredTable, is_fully_qualified,
-                ModuleName, ProcName, Arity - 1, [PredId0])
-        )
+            predicate_table_lookup_func_m_n_a(PredTable, is_fully_qualified,
+                ModuleName, ProcName, Arity - 1, PredIds)
+        ),
+        PredIds = [PredIdPrime]
     ->
-        PredId = PredId0
+        PredId = PredIdPrime
     ;
-        string.int_to_string(Arity, ArityS),
+        string.int_to_string(Arity, ArityStr),
         unexpected($module, $pred, 
-            "can't locate " ++ ProcName ++ "/" ++ ArityS)
+            "can't locate " ++ ProcName ++ "/" ++ ArityStr)
     ),
     module_info_pred_info(Module, PredId, PredInfo),
     ProcIds = pred_info_procids(PredInfo),
Index: recompilation.usage.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/recompilation.usage.m,v
retrieving revision 1.66
diff -u -b -r1.66 recompilation.usage.m
--- recompilation.usage.m	5 Sep 2012 06:18:15 -0000	1.66
+++ recompilation.usage.m	10 Sep 2012 14:20:42 -0000
@@ -670,13 +670,12 @@
 do_record_used_pred_or_func(PredOrFunc, ModuleQualifier,
         SymName, Arity, Recorded, !MatchingNames, !Info) :-
     ModuleInfo = !.Info ^ module_info,
-    (
         module_info_get_predicate_table(ModuleInfo, PredTable),
         adjust_func_arity(PredOrFunc, OrigArity, Arity),
-        predicate_table_search_pf_sym_arity(PredTable,
-            may_be_partially_qualified, PredOrFunc, SymName,
-            OrigArity, MatchingPredIds)
-    ->
+    predicate_table_lookup_pf_sym_arity(PredTable, may_be_partially_qualified,
+        PredOrFunc, SymName, OrigArity, MatchingPredIds),
+    (
+        MatchingPredIds = [_ | _],
         Recorded = yes,
         PredModules = set.list_to_set(list.map(
             (func(PredId) = PredId - PredModule :-
@@ -689,6 +688,7 @@
         set.fold(find_items_used_by_pred(PredOrFunc, Name - Arity),
             PredModules, !Info)
     ;
+        MatchingPredIds = [],
         Recorded = no
     ).
 
@@ -757,16 +757,11 @@
 
     % Is it a higher-order term or function call.
     module_info_get_predicate_table(ModuleInfo, PredicateTable),
-    (
-        predicate_table_search_sym(PredicateTable,
-            may_be_partially_qualified, SymName, PredIds)
-    ->
+    predicate_table_lookup_sym(PredicateTable,
+        may_be_partially_qualified, SymName, PredIds),
         MatchingPreds = list.filter_map(
             get_pred_or_func_ctors(ModuleInfo, SymName, Arity),
-            PredIds)
-    ;
-        MatchingPreds = []
-    ),
+        PredIds),
 
     % Is it a field access function.
     (
Index: simplify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.282
diff -u -b -r1.282 simplify.m
--- simplify.m	2 Jul 2012 01:16:37 -0000	1.282
+++ simplify.m	10 Sep 2012 14:20:47 -0000
@@ -2826,7 +2826,7 @@
     OpSymName = qualified(IntModuleSymName, Op),
     simplify_info_get_module_info(!.Info, ModuleInfo),
     module_info_get_predicate_table(ModuleInfo, PredTable),
-    predicate_table_search_func_sym_arity(PredTable, is_fully_qualified,
+    predicate_table_lookup_func_sym_arity(PredTable, is_fully_qualified,
         OpSymName, 2, OpPredIds),
     OpPredIds = [OpPredId],
     OpProcIdInt = 0,
Index: type_constraints.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/type_constraints.m,v
retrieving revision 1.23
diff -u -b -r1.23 type_constraints.m
--- type_constraints.m	2 Jul 2012 01:16:39 -0000	1.23
+++ type_constraints.m	10 Sep 2012 14:20:48 -0000
@@ -1709,16 +1709,17 @@
             ),
             % If it is a closure constructor, create a disjunction
             % constraint for each predicate it could refer to.
+            predicate_table_lookup_sym(PredEnv, may_be_partially_qualified,
+                Name, PredIds),
             (
-                predicate_table_search_sym(PredEnv,
-                    may_be_partially_qualified, Name, PredIds)
-            ->
+                PredIds = [_ | _],
                 predicate_table_get_preds(PredEnv, Preds),
                 list.filter_map_foldl(
                     ho_pred_unif_constraint(Preds, GoalInfo, LTVar,
                         ArgTypeVars),
                     PredIds, PredConstraints, !TCInfo)
             ;
+                PredIds = [],
                 PredConstraints = []
             ),
             Constraints = TypeConstraints ++ PredConstraints,
@@ -1764,16 +1765,10 @@
     GoalExpr = plain_call(_, _, Args, _, _, Name),
     % Transform a call to variable assignments of the variables
     % used in the call.
-    (
-        predicate_table_search_pred_sym(PredEnv, may_be_partially_qualified,
-            Name, PredIds0)
-    ->
-        PredIds1 = PredIds0
-    ;
-        PredIds1 = []
-    ),
+    predicate_table_lookup_pred_sym(PredEnv, may_be_partially_qualified,
+        Name, PredIds0),
     predicate_table_get_preds(PredEnv, Preds),
-    list.filter(pred_has_arity(Preds, list.length(Args)), PredIds1, PredIds),
+    list.filter(pred_has_arity(Preds, list.length(Args)), PredIds0, PredIds),
     list.map_foldl(get_var_type, Args, ArgTVars, !TCInfo),
     list.map2_foldl(pred_call_constraint(Preds, GoalInfo, ArgTVars),
         PredIds, Constraints, PredTVars, !TCInfo),
Index: typecheck.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/typecheck.m,v
retrieving revision 1.471
diff -u -b -r1.471 typecheck.m
--- typecheck.m	11 Jul 2012 04:00:59 -0000	1.471
+++ typecheck.m	10 Sep 2012 14:20:49 -0000
@@ -1590,22 +1590,29 @@
     % Look up the called predicate's arg types.
     ModuleInfo = !.Info ^ tc_info_module_info,
     module_info_get_predicate_table(ModuleInfo, PredicateTable),
-    (
         CallId = simple_call_id(PorF, SymName, Arity),
         typecheck_info_get_pred_markers(!.Info, PredMarkers),
-        predicate_table_search_pf_sym_arity(PredicateTable,
-            calls_are_fully_qualified(PredMarkers),
-            PorF, SymName, Arity, PredIdList)
-    ->
+    IsFullyQualified = calls_are_fully_qualified(PredMarkers),
+    predicate_table_lookup_pf_sym_arity(PredicateTable, IsFullyQualified,
+        PorF, SymName, Arity, PredIds),
+    (
+        PredIds = [],
+        PredId = invalid_pred_id,
+        Spec = report_pred_call_error(!.Info, CallId),
+        typecheck_info_add_error(Spec, !Info)
+    ;
+        PredIds = [HeadPredId | TailPredIds],
+        (
+            TailPredIds = [],
         % Handle the case of a non-overloaded predicate specially
         % (so that we can optimize the case of a non-overloaded,
         % non-polymorphic predicate).
-        ( PredIdList = [PredId0] ->
-            PredId = PredId0,
+            PredId = HeadPredId,
             typecheck_call_pred_id(PredId, Args, GoalId, !Info)
         ;
-            typecheck_call_overloaded_pred(CallId, PredIdList, Args,
-                GoalId, !Info),
+            TailPredIds = [_ | _],
+            typecheck_call_overloaded_pred(CallId, PredIds, Args, GoalId,
+                !Info),
 
             % In general, we can't figure out which predicate it is until
             % after we have resolved any overloading, which may require
@@ -1621,10 +1628,6 @@
         % S. Peyton-Jones, M. Jones 1997, for a discussion of some of the
         % issues.
         perform_context_reduction(!Info)
-    ;
-        PredId = invalid_pred_id,
-        Spec = report_pred_call_error(!.Info, CallId),
-        typecheck_info_add_error(Spec, !Info)
     ).
 
     % Typecheck a call to a specific predicate.
@@ -2594,20 +2597,22 @@
 :- pred builtin_pred_type(typecheck_info::in, cons_id::in, int::in,
     goal_id::in, list(cons_type_info)::out) is semidet.
 
-builtin_pred_type(Info, ConsId, Arity, GoalId, PredConsInfoList) :-
+builtin_pred_type(Info, ConsId, Arity, GoalId, ConsTypeInfos) :-
     ConsId = cons(SymName, _, _),
     ModuleInfo = Info ^ tc_info_module_info,
     module_info_get_predicate_table(ModuleInfo, PredicateTable),
-    (
         typecheck_info_get_pred_markers(Info, PredMarkers),
-        predicate_table_search_sym(PredicateTable,
-            calls_are_fully_qualified(PredMarkers), SymName, PredIdList)
-    ->
+    IsFullyQualified = calls_are_fully_qualified(PredMarkers),
+    predicate_table_lookup_sym(PredicateTable, IsFullyQualified, SymName,
+        PredIds),
+    (
+        PredIds = [_ | _],
         predicate_table_get_preds(PredicateTable, Preds),
-        make_pred_cons_info_list(Info, PredIdList, Preds, Arity,
-            GoalId, [], PredConsInfoList)
+        make_pred_cons_info_list(Info, PredIds, Preds, Arity, GoalId,
+            [], ConsTypeInfos)
     ;
-        PredConsInfoList = []
+        PredIds = [],
+        ConsTypeInfos = []
     ).
 
 :- pred make_pred_cons_info_list(typecheck_info::in, list(pred_id)::in,
@@ -2626,8 +2631,7 @@
     int::in, goal_id::in,
     list(cons_type_info)::in, list(cons_type_info)::out) is det.
 
-make_pred_cons_info(Info, PredId, PredTable, FuncArity, GoalId,
-        !ConsInfos) :-
+make_pred_cons_info(Info, PredId, PredTable, FuncArity, GoalId, !ConsInfos) :-
     ModuleInfo = Info ^ tc_info_module_info,
     module_info_get_class_table(ModuleInfo, ClassTable),
     map.lookup(PredTable, PredId, PredInfo),
@@ -2804,8 +2808,9 @@
     typecheck_info_get_is_field_access_function(Info, IsFieldAccessFunc),
     (
         IsFieldAccessFunc = no,
-        \+ predicate_table_search_func_m_n_a(PredTable, is_fully_qualified,
-            TypeModule, UnqualFuncName, Arity, _)
+        predicate_table_lookup_func_m_n_a(PredTable, is_fully_qualified,
+            TypeModule, UnqualFuncName, Arity, PredIds),
+        PredIds = []
     ;
         IsFieldAccessFunc = yes
     ),
Index: typecheck_errors.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/typecheck_errors.m,v
retrieving revision 1.57
diff -u -b -r1.57 typecheck_errors.m
--- typecheck_errors.m	2 Jul 2012 01:16:39 -0000	1.57
+++ typecheck_errors.m	10 Sep 2012 14:20:50 -0000
@@ -130,33 +130,33 @@
 %-----------------------------------------------------------------------------%
 
 report_pred_call_error(Info, PredCallId) = Spec :-
-    PredCallId = simple_call_id(PredOrFunc0, SymName, _Arity),
+    PredCallId = simple_call_id(PredOrFunc, SymName, _Arity),
     ModuleInfo = Info ^ tc_info_module_info,
     module_info_get_predicate_table(ModuleInfo, PredicateTable),
     typecheck_info_get_pred_markers(Info, PredMarkers),
+    IsFullyQualified = calls_are_fully_qualified(PredMarkers),
+    predicate_table_lookup_pf_sym(PredicateTable, IsFullyQualified,
+        PredOrFunc, SymName, OtherIds),
     (
-        predicate_table_search_pf_sym(PredicateTable,
-            calls_are_fully_qualified(PredMarkers),
-            PredOrFunc0, SymName, OtherIds),
+        OtherIds = [_ | _],
         predicate_table_get_preds(PredicateTable, Preds),
-        OtherIds = [_ | _]
-    ->
         typecheck_find_arities(Preds, OtherIds, Arities),
         Spec = report_error_pred_num_args(Info, PredCallId, Arities)
     ;
+        OtherIds = [],
         UndefMsg = report_error_undef_pred(Info, PredCallId),
-        (
-            ( PredOrFunc0 = pf_predicate, PredOrFunc = pf_function
-            ; PredOrFunc0 = pf_function, PredOrFunc = pf_predicate
+        ( PredOrFunc = pf_predicate, SwitchedPredOrFunc = pf_function
+        ; PredOrFunc = pf_function,  SwitchedPredOrFunc = pf_predicate
             ),
-            predicate_table_search_pf_sym(PredicateTable,
-                calls_are_fully_qualified(PredMarkers),
-                PredOrFunc, SymName, OtherIds),
-            OtherIds = [_ | _]
-        ->
-            KindMsg = report_error_func_instead_of_pred(Info, PredOrFunc),
+        predicate_table_lookup_pf_sym(PredicateTable, IsFullyQualified,
+            SwitchedPredOrFunc, SymName, SwitchedOtherIds),
+        (
+            SwitchedOtherIds = [_ | _],
+            KindMsg = report_error_func_instead_of_pred(Info,
+                SwitchedPredOrFunc),
             Msgs = [UndefMsg, KindMsg]
         ;
+            SwitchedOtherIds = [],
             Msgs = [UndefMsg]
         ),
         Spec = error_spec(severity_error, phase_type_check, Msgs)
cvs diff: Diffing notes
--------------------------------------------------------------------------
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