mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-20 08:19:28 +00:00
Estimated hours taken: 8
Branches: main
Improve the error messages generated for determinism errors involving committed
choice contexts. Previously, we printed a message to the effect that e.g.
a cc pred is called in context that requires all solutions, but we didn't say
*why* the context requires all solutions. We now keep track of all the goals
to the right that could fail, since it is these goals that may reject the first
solution of a committed choice goal.
The motivation for this diff was the fact that I found that locating the
failing goal can be very difficult if the conjunction to the right is
a couple of hundred lines long. This would have been a nontrivial problem,
since (a) unifications involving values of user-defined types are committed
choice goals, and (b) we can expect uses of user-defined types to increase.
compiler/det_analysis.m:
Keep track of goals to the right of the current goal that could fail,
and include them in the error representation if required.
compiler/det_report.m:
Include the list of failing goals to the right in the representations
of determinism errors involving committed committed choice goals.
Convert the last part of this module that wasn't using error_util
to use error_util. Make most parts of this module just construct
error message specifications; print those specifications (using
error_util) in only a few places.
compiler/hlds_out.m:
Add a function for use by the new code in det_report.m.
compiler/error_util.m:
Add a function for use by the new code in det_report.m.
compiler/error_util.m:
compiler/compiler_util.m:
Error_util is still changing reasonably often, and yet it is
included in lots of modules, most of which need only a few simple
non-parse-tree-related predicates from it (e.g. unexpected).
Move those predicates to a new module, compiler_util.m. This also
eliminates some undesirable dependencies from libs to parse_tree.
compiler/libs.m:
Include compiler_util.m.
compiler/notes/compiler_design.html:
Document compiler_util.m, and fix the documentation of some other
modules.
compiler/*.m:
Import compiler_util instead of or in addition to error_util.
To make this easier, consistently use . instead of __ for module
qualifying module names.
tests/invalid/det_errors_cc.{m,err_exp}:
Add this new test case to test the error messages for cc contexts.
tests/invalid/det_errors_deet.{m,err_exp}:
Add this new test case to test the error messages for unifications
inside function symbols.
tests/invalid/Mmakefile:
Add the new test cases.
tests/invalid/det_errors.err_exp:
tests/invalid/magicbox.err_exp:
Change the expected output to conform to the change in det_report.m,
which is now more consistent.
152 lines
5.4 KiB
Mathematica
152 lines
5.4 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2003-2005 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% file: proc_label.m
|
|
% main author: zs
|
|
|
|
% This file defines backend-independent identifiers for procedures that a
|
|
% backend can use as the basis for the names of the labels or functions
|
|
% implementing those procedures. It also has functions for creating these
|
|
% identifiers.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module backend_libs__proc_label.
|
|
|
|
:- interface.
|
|
|
|
:- import_module hlds.hlds_module.
|
|
:- import_module hlds.hlds_pred.
|
|
:- import_module mdbcomp.prim_data.
|
|
:- import_module parse_tree.prog_data.
|
|
|
|
:- import_module bool.
|
|
|
|
% Return the id of the procedure specified by the rtti_proc_label.
|
|
%
|
|
:- func make_proc_label_from_rtti(rtti_proc_label) = proc_label.
|
|
|
|
% Return the id of the specified procedure.
|
|
%
|
|
:- func make_proc_label(module_info, pred_id, proc_id) = proc_label.
|
|
|
|
% make_user_proc_label(ModuleName, PredIsImported,
|
|
% PredOrFunc, ModuleName, PredName, Arity, ProcId) = Label:
|
|
%
|
|
% Make a proc_label for a user-defined procedure.
|
|
%
|
|
% The PredIsImported argument should be the result of
|
|
% calling pred_info_is_imported.
|
|
%
|
|
:- func make_user_proc_label(module_name, bool, pred_or_func, module_name,
|
|
string, arity, proc_id) = proc_label.
|
|
|
|
% Return the id of the specified mode of the unification procedure
|
|
% for the given type.
|
|
|
|
:- func make_uni_label(module_info, type_ctor, proc_id) = proc_label.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module backend_libs.rtti.
|
|
:- import_module check_hlds.type_util.
|
|
:- import_module hlds.special_pred.
|
|
:- import_module libs.compiler_util.
|
|
:- import_module parse_tree.prog_type.
|
|
:- import_module parse_tree.prog_util.
|
|
|
|
:- import_module list.
|
|
:- import_module require.
|
|
:- import_module std_util.
|
|
:- import_module string.
|
|
|
|
make_proc_label_from_rtti(RttiProcLabel) = ProcLabel :-
|
|
RttiProcLabel = rtti_proc_label(PredOrFunc, ThisModule,
|
|
PredModule, PredName, PredArity, _ArgTypes, _PredId, ProcId,
|
|
_ProcHeadVarsWithNames, _ArgModes, _CodeModel,
|
|
PredIsImported, _PredIsPseudoImported, Origin,
|
|
_ProcIsExported, _ProcIsImported),
|
|
( Origin = special_pred(SpecialPred - TypeCtor) ->
|
|
(
|
|
% All type_ctors other than tuples here should be module qualified,
|
|
% since builtin types are handled separately in polymorphism.m.
|
|
(
|
|
TypeCtor = unqualified(TypeName) - _,
|
|
type_ctor_is_tuple(TypeCtor),
|
|
mercury_public_builtin_module(TypeModule)
|
|
;
|
|
TypeCtor = qualified(TypeModule, TypeName) - _
|
|
)
|
|
->
|
|
TypeCtor = _ - TypeArity,
|
|
(
|
|
ThisModule \= TypeModule,
|
|
SpecialPred = spec_pred_unify,
|
|
\+ hlds_pred__in_in_unification_proc_id(ProcId)
|
|
->
|
|
DefiningModule = ThisModule
|
|
;
|
|
DefiningModule = TypeModule
|
|
),
|
|
proc_id_to_int(ProcId, ProcIdInt),
|
|
ProcLabel = special_proc(DefiningModule, SpecialPred,
|
|
TypeModule, TypeName, TypeArity, ProcIdInt)
|
|
;
|
|
string__append_list(["make_proc_label:\n",
|
|
"cannot make label for special pred `", PredName, "'"],
|
|
ErrorMessage),
|
|
unexpected(this_file, ErrorMessage)
|
|
)
|
|
;
|
|
ProcLabel = make_user_proc_label(ThisModule, PredIsImported,
|
|
PredOrFunc, PredModule, PredName, PredArity, ProcId)
|
|
).
|
|
|
|
make_proc_label(ModuleInfo, PredId, ProcId) = ProcLabel :-
|
|
RttiProcLabel = rtti__make_rtti_proc_label(ModuleInfo, PredId, ProcId),
|
|
make_proc_label_from_rtti(RttiProcLabel) = ProcLabel.
|
|
|
|
make_user_proc_label(ThisModule, PredIsImported, PredOrFunc, PredModule,
|
|
PredName, PredArity, ProcId) = ProcLabel :-
|
|
(
|
|
% Work out which module supplies the code for the predicate.
|
|
ThisModule \= PredModule,
|
|
PredIsImported = no
|
|
->
|
|
% This predicate is a specialized version of a pred from a `.opt' file.
|
|
DefiningModule = ThisModule
|
|
;
|
|
DefiningModule = PredModule
|
|
),
|
|
proc_id_to_int(ProcId, ProcIdInt),
|
|
ProcLabel = proc(DefiningModule, PredOrFunc,
|
|
PredModule, PredName, PredArity, ProcIdInt).
|
|
|
|
make_uni_label(ModuleInfo, TypeCtor, UniModeNum) = ProcLabel :-
|
|
module_info_get_name(ModuleInfo, ModuleName),
|
|
( TypeCtor = qualified(TypeModule, TypeName) - Arity ->
|
|
( hlds_pred__in_in_unification_proc_id(UniModeNum) ->
|
|
Module = TypeModule
|
|
;
|
|
Module = ModuleName
|
|
),
|
|
proc_id_to_int(UniModeNum, UniModeNumInt),
|
|
ProcLabel = special_proc(Module, spec_pred_unify, TypeModule,
|
|
TypeName, Arity, UniModeNumInt)
|
|
;
|
|
unexpected(this_file, "make_uni_label: unqualified type_ctor")
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- func this_file = string.
|
|
|
|
this_file = "proc_label.m".
|
|
|
|
%-----------------------------------------------------------------------------%
|