mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-13 21:04:00 +00:00
Estimated hours taken: 50
Add support for nested modules.
- module names may themselves be module-qualified
- modules may contain `:- include_module' declarations
which name sub-modules
- a sub-module has access to all the declarations in the
parent module (including its implementation section).
This support is not yet complete; see the BUGS and LIMITATIONS below.
LIMITATIONS
- source file names must match module names
(just as they did previously)
- mmc doesn't allow path names on the command line any more
(e.g. `mmc --make-int ../library/foo.m').
- import_module declarations must use the fully-qualified module name
- module qualifiers must use the fully-qualified module name
- no support for root-qualified module names
(e.g. `:parent:child' instead of `parent:child').
- modules may not be physically nested (only logical nesting, via
`include_module').
BUGS
- doesn't check that the parent module is imported/used before allowing
import/use of its sub-modules.
- doesn't check that there is an include_module declaration in the
parent for each module claiming to be a child of that parent
- privacy of private modules is not enforced
-------------------
NEWS:
Mention that we support nested modules.
library/ops.m:
library/nc_builtin.nl:
library/sp_builtin.nl:
compiler/mercury_to_mercury.m:
Add `include_module' as a new prefix operator.
Change the associativity of `:' from xfy to yfx
(since this made parsing module qualifiers slightly easier).
compiler/prog_data.m:
Add new `include_module' declaration.
Change the `module_name' and `module_specifier' types
from strings to sym_names, so that module names can
themselves be module qualified.
compiler/modules.m:
Add predicates module_name_to_file_name/2 and
file_name_to_module_name/2.
Lots of changes to handle parent module dependencies,
to create parent interface (`.int0') files, to read them in,
to output correct dependencies information for them to the
`.d' and `.dep' files, etc.
Rewrite a lot of the code to improve the readability
(add comments, use subroutines, better variable names).
Also fix a couple of bugs:
- generate_dependencies was using the transitive implementation
dependencies rather than the transitive interface dependencies
to compute the `.int3' dependencies when writing `.d' files
(this bug was introduced during crs's changes to support
`.trans_opt' files)
- when creating the `.int' file, it was reading in the
interfaces for modules imported in the implementation section,
not just those in the interface section.
This meant that the compiler missed a lot of errors.
library/graph.m:
library/lexer.m:
library/term.m:
library/term_io.m:
library/varset.m:
compiler/*.m:
Add `:- import_module' declarations to the interface needed
by declarations in the interface. (The previous version
of the compiler did not detect these missing interface imports,
due to the above-mentioned bug in modules.m.)
compiler/mercury_compile.m:
compiler/intermod.m:
Change mercury_compile__maybe_grab_optfiles and
intermod__grab_optfiles so that they grab the opt files for
parent modules as well as the ones for imported modules.
compiler/mercury_compile.m:
Minor changes to handle parent module dependencies.
(Also improve the wording of the warning about trans-opt
dependencies.)
compiler/make_hlds.m:
compiler/module_qual.m:
Ignore `:- include_module' declarations.
compiler/module_qual.m:
A couple of small changes to handle nested module names.
compiler/prog_out.m:
compiler/prog_util.m:
Add new predicates string_to_sym_name/3 (prog_util.m) and
sym_name_to_string/{2,3} (prog_out.m).
compiler/*.m:
Replace many occurrences of `string' with `module_name'.
Change code that prints out module names or converts
them to strings or filenames to handle the fact that
module names are now sym_names intead of strings.
Also change a few places (e.g. in intermod.m, hlds_module.m)
where the code assumed that any qualified symbol was
fully-qualified.
compiler/prog_io.m:
compiler/prog_io_goal.m:
Move sym_name_and_args/3, parse_qualified_term/4 and
parse_qualified_term/5 preds from prog_io_goal.m to prog_io.m,
since they are very similar to the parse_symbol_name/2 predicate
already in prog_io.m. Rewrite these predicates, both
to improve maintainability, and to handle the newly
allowed syntax (module-qualified module names).
Rename parse_qualified_term/5 as `parse_implicit_qualified_term'.
compiler/prog_io.m:
Rewrite the handling of `:- module' and `:- end_module'
declarations, so that it can handle nested modules.
Add code to parse `include_module' declarations.
compiler/prog_util.m:
compiler/*.m:
Add new predicates mercury_public_builtin_module/1 and
mercury_private_builtin_module/1 in prog_util.m.
Change most of the hard-coded occurrences of "mercury_builtin"
to call mercury_private_builtin_module/1 or
mercury_public_builtin_module/1 or both.
compiler/llds_out.m:
Add llds_out__sym_name_mangle/2, for mangling module names.
compiler/special_pred.m:
compiler/mode_util.m:
compiler/clause_to_proc.m:
compiler/prog_io_goal.m:
compiler/lambda.m:
compiler/polymorphism.m:
Move the predicates in_mode/1, out_mode/1, and uo_mode/1
from special_pred.m to mode_util.m, and change various
hard-coded definitions to instead call these predicates.
compiler/polymorphism.m:
Ensure that the type names `type_info' and `typeclass_info' are
module-qualified in the generated code. This avoids a problem
where the code generated by polymorphism.m was not considered
type-correct, due to the type `type_info' not matching
`mercury_builtin:type_info'.
compiler/check_typeclass.m:
Simplify the code for check_instance_pred and
get_matching_instance_pred_ids.
compiler/mercury_compile.m:
compiler/modules.m:
Disallow directory names in command-line arguments.
compiler/options.m:
compiler/handle_options.m:
compiler/mercury_compile.m:
compiler/modules.m:
Add a `--make-private-interface' option.
The private interface file `<module>.int0' contains
all the declarations in the module; it is used for
compiling sub-modules.
scripts/Mmake.rules:
scripts/Mmake.vars.in:
Add support for creating `.int0' and `.date0' files
by invoking mmc with `--make-private-interface'.
doc/user_guide.texi:
Document `--make-private-interface' and the `.int0'
and `.date0' file extensions.
doc/reference_manual.texi:
Document nested modules.
util/mdemangle.c:
profiler/demangle.m:
Demangle names with multiple module qualifiers.
tests/general/Mmakefile:
tests/general/string_format_test.m:
tests/general/string_format_test.exp:
tests/general/string__format_test.m:
tests/general/string__format_test.exp:
tests/general/.cvsignore:
Change the `:- module string__format_test' declaration in
`string__format_test.m' to `:- module string_format_test',
because with the original declaration the `__' was taken
as a module qualifier, which lead to an error message.
Hence rename the file accordingly, to avoid the warning
about file name not matching module name.
tests/invalid/Mmakefile:
tests/invalid/missing_interface_import.m:
tests/invalid/missing_interface_import.err_exp:
Regression test to check that the compiler reports
errors for missing `import_module' in the interface section.
tests/invalid/*.err_exp:
tests/warnings/unused_args_test.exp:
tests/warnings/unused_import.exp:
Update the expected diagnostics output for the test cases to
reflect a few minor changes to the warning messages.
tests/hard_coded/Mmakefile:
tests/hard_coded/parent.m:
tests/hard_coded/parent.child.m:
tests/hard_coded/parent.exp:
tests/hard_coded/parent2.m:
tests/hard_coded/parent2.child.m:
tests/hard_coded/parent2.exp:
Two simple tests case for the use of nested modules with
separate compilation.
577 lines
19 KiB
Mathematica
577 lines
19 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 1997-1998 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.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% term_errors.m
|
|
% Main author: crs.
|
|
%
|
|
% This module prints out the various error messages that are produced by
|
|
% the various modules of termination analysis.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module term_errors.
|
|
|
|
:- interface.
|
|
|
|
:- import_module hlds_module, hlds_pred.
|
|
|
|
:- import_module io, bag, std_util, list, assoc_list, term.
|
|
|
|
:- type termination_error
|
|
---> pragma_c_code
|
|
% The analysis result depends on the change constant
|
|
% of a piece of pragma C code, (which cannot be
|
|
% obtained without analyzing the C code, which is
|
|
% something we cannot do).
|
|
% Valid in both passes.
|
|
|
|
; imported_pred
|
|
% The SCC contains some imported procedures,
|
|
% whose code is not accessible.
|
|
|
|
; can_loop_proc_called(pred_proc_id, pred_proc_id)
|
|
% can_loop_proc_called(Caller, Callee, Context)
|
|
% The call from Caller to Callee at the associated
|
|
% context is to a procedure (Callee) whose termination
|
|
% info is set to can_loop.
|
|
% Although this error does not prevent us from
|
|
% producing argument size information, it would
|
|
% prevent us from proving termination.
|
|
% We look for this error in pass 1; if we find it,
|
|
% we do not perform pass 2.
|
|
|
|
; horder_args(pred_proc_id, pred_proc_id)
|
|
% horder_args(Caller, Callee, Context)
|
|
% The call from Caller to Callee at the associated
|
|
% context has some arguments of a higher order type.
|
|
% Valid in both passes.
|
|
|
|
; horder_call
|
|
% horder_call
|
|
% There is a higher order call at the associated
|
|
% context.
|
|
% Valid in both passes.
|
|
|
|
; inf_termination_const(pred_proc_id, pred_proc_id)
|
|
% inf_termination_const(Caller, Callee, Context)
|
|
% The call from Caller to Callee at the associated
|
|
% context is to a procedure (Callee) whose arg size
|
|
% info is set to infinite.
|
|
% Valid in both passes.
|
|
|
|
; not_subset(pred_proc_id, bag(var), bag(var))
|
|
% not_subset(Proc, SupplierVariables, InHeadVariables)
|
|
% This error occurs when the bag of active variables
|
|
% is not a subset of the input head variables.
|
|
% Valid error only in pass 1.
|
|
|
|
; inf_call(pred_proc_id, pred_proc_id)
|
|
% inf_call(Caller, Callee)
|
|
% The call from Caller to Callee at the associated
|
|
% context has infinite weight.
|
|
% Valid error only in pass 2.
|
|
|
|
; cycle(pred_proc_id, assoc_list(pred_proc_id, term__context))
|
|
% cycle(StartPPId, CallSites)
|
|
% In the cycle of calls starting at StartPPId and
|
|
% going through the named call sites may be an
|
|
% infinite loop.
|
|
% Valid error only in pass 2.
|
|
|
|
; no_eqns
|
|
% There are no equations in this SCC.
|
|
% This has 2 possible causes. (1) If the predicate has
|
|
% no output arguments, no equations will be created
|
|
% for them. The change constant of the predicate is
|
|
% undefined, but it will also never be used.
|
|
% (2) If the procedure is a builtin predicate, with
|
|
% an empty body, traversal cannot create any equations.
|
|
% Valid error only in pass 1.
|
|
|
|
; too_many_paths
|
|
% There were too many distinct paths to be analyzed.
|
|
% Valid in both passes (which analyze different sets
|
|
% of paths).
|
|
|
|
; solver_failed
|
|
% The solver could not find finite termination
|
|
% constants for the procedures in the SCC.
|
|
% Valid only in pass 1.
|
|
|
|
; is_builtin(pred_id)
|
|
% The termination constant of the given builtin is
|
|
% set to infinity; this happens when the type of at
|
|
% least one output argument permits a norm greater
|
|
% than zero.
|
|
|
|
; does_not_term_pragma(pred_id).
|
|
% The given procedure has a does_not_terminate pragma.
|
|
|
|
:- type term_errors__error == pair(term__context, termination_error).
|
|
|
|
:- pred term_errors__report_term_errors(list(pred_proc_id)::in,
|
|
list(term_errors__error)::in, module_info::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
% An error is considered an indirect error if it is due either to a
|
|
% language feature we cannot analyze or due to an error in another part
|
|
% of the code. By default, we do not issue warnings about indirect errors,
|
|
% since in the first case, the programmer cannot do anything about it,
|
|
% and in the second case, the piece of code that the programmer *can* do
|
|
% something about is not this piece.
|
|
|
|
:- pred indirect_error(term_errors__termination_error).
|
|
:- mode indirect_error(in) is semidet.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module hlds_out, prog_out, passes_aux, error_util.
|
|
:- import_module mercury_to_mercury, term_util, options, globals.
|
|
|
|
:- import_module bool, int, string, map, bag, require, varset.
|
|
|
|
indirect_error(horder_call).
|
|
indirect_error(pragma_c_code).
|
|
indirect_error(imported_pred).
|
|
indirect_error(can_loop_proc_called(_, _)).
|
|
indirect_error(horder_args(_, _)).
|
|
indirect_error(does_not_term_pragma(_)).
|
|
|
|
term_errors__report_term_errors(SCC, Errors, Module) -->
|
|
{ get_context_from_scc(SCC, Module, Context) },
|
|
( { SCC = [PPId] } ->
|
|
{ Pieces0 = [words("Termination of")] },
|
|
{ term_errors__describe_one_proc_name(PPId, Module, PredName) },
|
|
{ list__append(Pieces0, [fixed(PredName)], Pieces1) },
|
|
{ Single = yes(PPId) }
|
|
;
|
|
{ Pieces0 = [words("Termination of the mutually recursive procedures")] },
|
|
{ term_errors__describe_several_proc_names(SCC, Module, Context,
|
|
ProcNames) },
|
|
{ list__map(lambda([PN::in, FPN::out] is det,
|
|
(FPN = fixed(PN))),
|
|
ProcNames, ProcNamePieces) },
|
|
{ list__append(Pieces0, ProcNamePieces, Pieces1) },
|
|
{ Single = no }
|
|
),
|
|
(
|
|
{ Errors = [] },
|
|
% XXX this should never happen
|
|
% XXX but for some reason, it often does
|
|
% { error("empty list of errors") }
|
|
{ Pieces2 = [words("not proven, for unknown reason(s).")] },
|
|
{ list__append(Pieces1, Pieces2, Pieces) },
|
|
write_error_pieces(Context, 0, Pieces)
|
|
;
|
|
{ Errors = [Error] },
|
|
{ Pieces2 = [words("not proven for the following reason:")] },
|
|
{ list__append(Pieces1, Pieces2, Pieces) },
|
|
write_error_pieces(Context, 0, Pieces),
|
|
term_errors__output_error(Error, Single, no, 0, Module)
|
|
;
|
|
{ Errors = [_, _ | _] },
|
|
{ Pieces2 = [words("not proven for the following reasons:")] },
|
|
{ list__append(Pieces1, Pieces2, Pieces) },
|
|
write_error_pieces(Context, 0, Pieces),
|
|
term_errors__output_errors(Errors, Single, 1, 0, Module)
|
|
).
|
|
|
|
:- pred term_errors__report_arg_size_errors(list(pred_proc_id)::in,
|
|
list(term_errors__error)::in, module_info::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
term_errors__report_arg_size_errors(SCC, Errors, Module) -->
|
|
{ get_context_from_scc(SCC, Module, Context) },
|
|
( { SCC = [PPId] } ->
|
|
{ Pieces0 = [words("Termination constant of")] },
|
|
{ term_errors__describe_one_proc_name(PPId, Module, ProcName) },
|
|
{ list__append(Pieces0, [fixed(ProcName)], Pieces1) },
|
|
{ Single = yes(PPId) }
|
|
;
|
|
{ Pieces0 = [words("Termination constants"),
|
|
words("of the mutually recursive procedures")] },
|
|
{ term_errors__describe_several_proc_names(SCC, Module,
|
|
Context, ProcNames) },
|
|
{ list__map(lambda([PN::in, FPN::out] is det,
|
|
(FPN = fixed(PN))),
|
|
ProcNames, ProcNamePieces) },
|
|
{ list__append(Pieces0, ProcNamePieces, Pieces1) },
|
|
{ Single = no }
|
|
),
|
|
{ Piece2 = words("set to infinity for the following") },
|
|
(
|
|
{ Errors = [] },
|
|
{ error("empty list of errors") }
|
|
;
|
|
{ Errors = [Error] },
|
|
{ Piece3 = words("reason:") },
|
|
{ list__append(Pieces1, [Piece2, Piece3], Pieces) },
|
|
write_error_pieces(Context, 0, Pieces),
|
|
term_errors__output_error(Error, Single, no, 0, Module)
|
|
;
|
|
{ Errors = [_, _ | _] },
|
|
{ Piece3 = words("reasons:") },
|
|
{ list__append(Pieces1, [Piece2, Piece3], Pieces) },
|
|
write_error_pieces(Context, 0, Pieces),
|
|
term_errors__output_errors(Errors, Single, 1, 0, Module)
|
|
).
|
|
|
|
:- pred term_errors__output_errors(list(term_errors__error)::in,
|
|
maybe(pred_proc_id)::in, int::in, int::in, module_info::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
term_errors__output_errors([], _, _, _, _) --> [].
|
|
term_errors__output_errors([Error | Errors], Single, ErrNum0, Indent, Module)
|
|
-->
|
|
term_errors__output_error(Error, Single, yes(ErrNum0), Indent, Module),
|
|
{ ErrNum1 is ErrNum0 + 1 },
|
|
term_errors__output_errors(Errors, Single, ErrNum1, Indent, Module).
|
|
|
|
:- pred term_errors__output_error(term_errors__error::in,
|
|
maybe(pred_proc_id)::in, maybe(int)::in, int::in, module_info::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
term_errors__output_error(Context - Error, Single, ErrorNum, Indent, Module) -->
|
|
{ term_errors__description(Error, Single, Module, Pieces0, Reason) },
|
|
{ ErrorNum = yes(N) ->
|
|
string__int_to_string(N, Nstr),
|
|
string__append_list(["Reason ", Nstr, ":"], Preamble),
|
|
Pieces = [fixed(Preamble) | Pieces0]
|
|
;
|
|
Pieces = Pieces0
|
|
},
|
|
write_error_pieces(Context, Indent, Pieces),
|
|
( { Reason = yes(InfArgSizePPId) } ->
|
|
{ lookup_proc_arg_size_info(Module, InfArgSizePPId, ArgSize) },
|
|
( { ArgSize = yes(infinite(ArgSizeErrors)) } ->
|
|
% XXX the next line is cheating
|
|
{ ArgSizePPIdSCC = [InfArgSizePPId] },
|
|
term_errors__report_arg_size_errors(ArgSizePPIdSCC,
|
|
ArgSizeErrors, Module)
|
|
;
|
|
{ error("inf arg size procedure does not have inf arg size") }
|
|
)
|
|
;
|
|
[]
|
|
).
|
|
|
|
:- pred term_errors__description(termination_error::in,
|
|
maybe(pred_proc_id)::in, module_info::in, list(format_component)::out,
|
|
maybe(pred_proc_id)::out) is det.
|
|
|
|
term_errors__description(horder_call, _, _, Pieces, no) :-
|
|
Pieces = [words("It contains a higher order call.")].
|
|
|
|
term_errors__description(pragma_c_code, _, _, Pieces, no) :-
|
|
Pieces = [words("It depends on the properties of"),
|
|
words("foreign language code included via a"),
|
|
fixed("`pragma c_code'"),
|
|
words("declaration.")].
|
|
|
|
term_errors__description(inf_call(CallerPPId, CalleePPId),
|
|
Single, Module, Pieces, no) :-
|
|
(
|
|
Single = yes(PPId),
|
|
require(unify(PPId, CallerPPId), "caller outside this SCC"),
|
|
Piece1 = words("It")
|
|
;
|
|
Single = no,
|
|
term_errors__describe_one_proc_name(CallerPPId, Module,
|
|
ProcName),
|
|
Piece1 = fixed(ProcName)
|
|
),
|
|
Piece2 = words("calls"),
|
|
term_errors__describe_one_proc_name(CalleePPId, Module, CalleePiece),
|
|
Pieces3 = [words("with an unbounded increase"),
|
|
words("in the size of the input arguments.")],
|
|
Pieces = [Piece1, Piece2, fixed(CalleePiece) | Pieces3].
|
|
|
|
term_errors__description(can_loop_proc_called(CallerPPId, CalleePPId),
|
|
Single, Module, Pieces, no) :-
|
|
(
|
|
Single = yes(PPId),
|
|
require(unify(PPId, CallerPPId), "caller outside this SCC"),
|
|
Piece1 = words("It")
|
|
;
|
|
Single = no,
|
|
term_errors__describe_one_proc_name(CallerPPId, Module,
|
|
ProcName),
|
|
Piece1 = fixed(ProcName)
|
|
),
|
|
Piece2 = words("calls"),
|
|
term_errors__describe_one_proc_name(CalleePPId, Module, CalleePiece),
|
|
Pieces3 = [words("which could not be proven to terminate.")],
|
|
Pieces = [Piece1, Piece2, fixed(CalleePiece) | Pieces3].
|
|
|
|
term_errors__description(imported_pred, _, _, Pieces, no) :-
|
|
Pieces = [words("It contains one or more"),
|
|
words("predicates and/or functions"),
|
|
words("imported from another module.")].
|
|
|
|
term_errors__description(horder_args(CallerPPId, CalleePPId), Single, Module,
|
|
Pieces, no) :-
|
|
(
|
|
Single = yes(PPId),
|
|
require(unify(PPId, CallerPPId), "caller outside this SCC"),
|
|
Piece1 = words("It")
|
|
;
|
|
Single = no,
|
|
term_errors__describe_one_proc_name(CallerPPId, Module,
|
|
ProcName),
|
|
Piece1 = fixed(ProcName)
|
|
),
|
|
Piece2 = words("calls"),
|
|
term_errors__describe_one_proc_name(CalleePPId, Module, CalleePiece),
|
|
Pieces3 = [words("with one or more higher order arguments.")],
|
|
Pieces = [Piece1, Piece2, fixed(CalleePiece) | Pieces3].
|
|
|
|
term_errors__description(inf_termination_const(CallerPPId, CalleePPId),
|
|
Single, Module, Pieces, yes(CalleePPId)) :-
|
|
(
|
|
Single = yes(PPId),
|
|
require(unify(PPId, CallerPPId), "caller outside this SCC"),
|
|
Piece1 = words("It")
|
|
;
|
|
Single = no,
|
|
term_errors__describe_one_proc_name(CallerPPId, Module,
|
|
ProcName),
|
|
Piece1 = fixed(ProcName)
|
|
),
|
|
Piece2 = words("calls"),
|
|
term_errors__describe_one_proc_name(CalleePPId, Module, CalleePiece),
|
|
Pieces3 = [words("which has a termination constant of infinity.")],
|
|
Pieces = [Piece1, Piece2, fixed(CalleePiece) | Pieces3].
|
|
|
|
term_errors__description(not_subset(ProcPPId, OutputSuppliers, HeadVars),
|
|
Single, Module, Pieces, no) :-
|
|
(
|
|
Single = yes(PPId),
|
|
( PPId = ProcPPId ->
|
|
Pieces1 = [words("The set of"),
|
|
words("its output supplier variables")]
|
|
;
|
|
% XXX this should never happen (but it does)
|
|
% error("not_subset outside this SCC"),
|
|
term_errors__describe_one_proc_name(ProcPPId, Module,
|
|
PPIdPiece),
|
|
Pieces1 = [words("The set of"),
|
|
words("output supplier variables of"),
|
|
fixed(PPIdPiece)]
|
|
)
|
|
;
|
|
Single = no,
|
|
term_errors__describe_one_proc_name(ProcPPId, Module,
|
|
PPIdPiece),
|
|
Pieces1 = [words("The set of output supplier variables of"),
|
|
fixed(PPIdPiece)]
|
|
),
|
|
ProcPPId = proc(PredId, ProcId),
|
|
module_info_pred_proc_info(Module, PredId, ProcId, _, ProcInfo),
|
|
proc_info_varset(ProcInfo, Varset),
|
|
term_errors_var_bag_description(OutputSuppliers, Varset,
|
|
OutputSuppliersNames),
|
|
list__map(lambda([OS::in, FOS::out] is det, (FOS = fixed(OS))),
|
|
OutputSuppliersNames, OutputSuppliersPieces),
|
|
Pieces3 = [words("was not a subset of the head variables")],
|
|
term_errors_var_bag_description(HeadVars, Varset, HeadVarsNames),
|
|
list__map(lambda([HV::in, FHV::out] is det, (FHV = fixed(HV))),
|
|
HeadVarsNames, HeadVarsPieces),
|
|
list__condense([Pieces1, OutputSuppliersPieces, Pieces3,
|
|
HeadVarsPieces], Pieces).
|
|
|
|
term_errors__description(cycle(_StartPPId, CallSites), _, Module, Pieces, no) :-
|
|
( CallSites = [DirectCall] ->
|
|
term_errors__describe_one_call_site(DirectCall, Module, Site),
|
|
Pieces = [words("At the recursive call to"),
|
|
fixed(Site),
|
|
words("the arguments are"),
|
|
words("not guaranteed to decrease in size.")]
|
|
;
|
|
Pieces1 = [words("In the recursive cycle"),
|
|
words("through the calls to")],
|
|
term_errors__describe_several_call_sites(CallSites, Module,
|
|
Sites),
|
|
list__map(lambda([S::in, FS::out] is det, (FS = fixed(S))),
|
|
Sites, SitePieces),
|
|
Pieces2 = [words("the arguments are"),
|
|
words("not guaranteed to decrease in size.")],
|
|
list__condense([Pieces1, SitePieces, Pieces2], Pieces)
|
|
).
|
|
|
|
term_errors__description(too_many_paths, _, _, Pieces, no) :-
|
|
Pieces = [words("There were too many execution paths"),
|
|
words("for the analysis to process.")].
|
|
|
|
term_errors__description(no_eqns, _, _, Pieces, no) :-
|
|
Pieces = [words("The analysis was unable to form any constraints"),
|
|
words("between the arguments of this group of procedures.")].
|
|
|
|
term_errors__description(solver_failed, _, _, Pieces, no) :-
|
|
Pieces = [words("The solver found the constraints produced"),
|
|
words("by the analysis to be infeasible.")].
|
|
|
|
term_errors__description(is_builtin(_PredId), _Single, _, Pieces, no) :-
|
|
% XXX require(unify(Single, yes(_)), "builtin not alone in SCC"),
|
|
Pieces = [words("It is a builtin predicate.")].
|
|
|
|
term_errors__description(does_not_term_pragma(PredId), Single, Module,
|
|
Pieces, no) :-
|
|
Pieces1 = [words("There was a `does_not_terminate' pragma defined on")],
|
|
(
|
|
Single = yes(PPId),
|
|
PPId = proc(SCCPredId, _),
|
|
require(unify(PredId, SCCPredId), "does not terminate pragma outside this SCC"),
|
|
Piece2 = words("It")
|
|
;
|
|
Single = no,
|
|
term_errors__describe_one_pred_name(PredId, Module,
|
|
Piece2Nodot),
|
|
string__append(Piece2Nodot, ".", Piece2Str),
|
|
Piece2 = fixed(Piece2Str)
|
|
),
|
|
list__append(Pieces1, [Piece2], Pieces).
|
|
|
|
%----------------------------------------------------------------------------%
|
|
|
|
:- pred term_errors_var_bag_description(bag(var)::in, varset::in,
|
|
list(string)::out) is det.
|
|
|
|
term_errors_var_bag_description(HeadVars, Varset, Pieces) :-
|
|
bag__to_assoc_list(HeadVars, HeadVarCountList),
|
|
term_errors_var_bag_description_2(HeadVarCountList, Varset, yes,
|
|
Pieces).
|
|
|
|
:- pred term_errors_var_bag_description_2(assoc_list(var, int)::in, varset::in,
|
|
bool::in, list(string)::out) is det.
|
|
|
|
term_errors_var_bag_description_2([], _, _, ["{}"]).
|
|
term_errors_var_bag_description_2([Var - Count | VarCounts], Varset, First,
|
|
[Piece | Pieces]) :-
|
|
varset__lookup_name(Varset, Var, VarName),
|
|
( Count > 1 ->
|
|
string__append(VarName, "*", VarCountPiece0),
|
|
string__int_to_string(Count, CountStr),
|
|
string__append(VarCountPiece0, CountStr, VarCountPiece)
|
|
;
|
|
VarCountPiece = VarName
|
|
),
|
|
( First = yes ->
|
|
string__append("{", VarCountPiece, Piece0)
|
|
;
|
|
Piece0 = VarCountPiece
|
|
),
|
|
( VarCounts = [] ->
|
|
string__append(Piece0, "}.", Piece),
|
|
Pieces = []
|
|
;
|
|
Piece = Piece0,
|
|
term_errors_var_bag_description_2(VarCounts, Varset, First,
|
|
Pieces)
|
|
).
|
|
|
|
%----------------------------------------------------------------------------%
|
|
|
|
:- pred term_errors__describe_one_pred_name(pred_id::in, module_info::in,
|
|
string::out) is det.
|
|
|
|
% The code of this predicate duplicates the functionality of
|
|
% hlds_out__write_pred_id. Changes here should be made there as well.
|
|
|
|
term_errors__describe_one_pred_name(PredId, Module, Piece) :-
|
|
module_info_pred_info(Module, PredId, PredInfo),
|
|
pred_info_module(PredInfo, ModuleName),
|
|
prog_out__sym_name_to_string(ModuleName, ModuleNameString),
|
|
pred_info_name(PredInfo, PredName),
|
|
pred_info_arity(PredInfo, Arity),
|
|
pred_info_get_is_pred_or_func(PredInfo, PredOrFunc),
|
|
(
|
|
PredOrFunc = predicate,
|
|
PredOrFuncPart = "predicate ",
|
|
OrigArity = Arity
|
|
;
|
|
PredOrFunc = function,
|
|
PredOrFuncPart = "function ",
|
|
OrigArity is Arity - 1
|
|
),
|
|
string__int_to_string(OrigArity, ArityPart),
|
|
string__append_list([
|
|
PredOrFuncPart,
|
|
ModuleNameString,
|
|
":",
|
|
PredName,
|
|
"/",
|
|
ArityPart
|
|
], Piece).
|
|
|
|
:- pred term_errors__describe_one_proc_name(pred_proc_id::in, module_info::in,
|
|
string::out) is det.
|
|
|
|
term_errors__describe_one_proc_name(proc(PredId, ProcId), Module, Piece) :-
|
|
term_errors__describe_one_pred_name(PredId, Module, PredPiece),
|
|
proc_id_to_int(ProcId, ProcIdInt),
|
|
string__int_to_string(ProcIdInt, ProcIdPart),
|
|
string__append_list([
|
|
PredPiece,
|
|
" mode ",
|
|
ProcIdPart
|
|
], Piece).
|
|
|
|
:- pred term_errors__describe_several_proc_names(list(pred_proc_id)::in,
|
|
module_info::in, term__context::in, list(string)::out) is det.
|
|
|
|
term_errors__describe_several_proc_names([], _, _, []).
|
|
term_errors__describe_several_proc_names([PPId | PPIds], Module,
|
|
Context, Pieces) :-
|
|
term_errors__describe_one_proc_name(PPId, Module, Piece0),
|
|
( PPIds = [] ->
|
|
Pieces = [Piece0]
|
|
; PPIds = [LastPPId] ->
|
|
term_errors__describe_one_proc_name(LastPPId, Module,
|
|
LastPiece),
|
|
Pieces = [Piece0, "and", LastPiece]
|
|
;
|
|
string__append(Piece0, ",", Piece),
|
|
term_errors__describe_several_proc_names(PPIds, Module,
|
|
Context, Pieces1),
|
|
Pieces = [Piece | Pieces1]
|
|
).
|
|
|
|
:- pred term_errors__describe_one_call_site(pair(pred_proc_id,
|
|
term__context)::in, module_info::in, string::out) is det.
|
|
|
|
term_errors__describe_one_call_site(PPId - Context, Module, Piece) :-
|
|
term_errors__describe_one_proc_name(PPId, Module, ProcName),
|
|
Context = term__context(FileName, LineNumber),
|
|
string__int_to_string(LineNumber, LineNumberPart),
|
|
string__append_list([
|
|
ProcName,
|
|
" at ",
|
|
FileName,
|
|
":",
|
|
LineNumberPart
|
|
], Piece).
|
|
|
|
:- pred term_errors__describe_several_call_sites(assoc_list(pred_proc_id,
|
|
term__context)::in, module_info::in, list(string)::out) is det.
|
|
|
|
term_errors__describe_several_call_sites([], _, []).
|
|
term_errors__describe_several_call_sites([Site | Sites], Module, Pieces) :-
|
|
term_errors__describe_one_call_site(Site, Module, Piece0),
|
|
( Sites = [] ->
|
|
Pieces = [Piece0]
|
|
; Sites = [LastSite] ->
|
|
term_errors__describe_one_call_site(LastSite, Module,
|
|
LastPiece),
|
|
Pieces = [Piece0, "and", LastPiece]
|
|
;
|
|
string__append(Piece0, ",", Piece),
|
|
term_errors__describe_several_call_sites(Sites, Module,
|
|
Pieces1),
|
|
Pieces = [Piece | Pieces1]
|
|
).
|
|
|
|
%----------------------------------------------------------------------------%
|