Commit Graph

281 Commits

Author SHA1 Message Date
Zoltan Somogyi
36e8833145 Add a new option, --warn-unused-types.
When set, this option tells the compiler to generate warnings
about locally-defined types that are neither used in the module
nor exported to any other module.

compiler/options.m:
    Add the new option.

compiler/unused_types.m:
    New module to implement the new option.

compiler/mercury_compile_front_end.m:
    Invoke the new module, unless the presence of previous errors
    would make its warnings just a distraction.

compiler/check_hlds.m:
    Include the new module.

compiler/notes/compiler_design.html:
    Document the new module.

compiler/typecheck_error_wrong_type.m:
    Simplify some code.

browser/declarative_tree.m:
compiler/accumulator.m:
compiler/du_type_layout.m:
compiler/intermod.m:
compiler/mode_errors.m:
compiler/parse_inst_mode_defn.m:
compiler/polyhedron.m:
compiler/split_parse_tree_src.m:
compiler/tag_switch_util.m:
compiler/typecheck_error_unify.m:
compiler/unneeded_code.m:
deep_profiler/mdprof_test.m:
library/getopt.m:
library/getopt_io.m:
    Delete unused types reported by the new option.

library/rtti_implementation.m:
    Comment out unused type reported by the new option. This type was exported
    to both Java and C#, but this diff comments it out because neither language
    the Java or the C# runtime system seems to use the exported versions
    either. (Bootcheck in both java and csharp grades worked, with the
    same number of test case failures as before.) We do not delete it,
    because it may be useful in the future.

tests/warnings/help_text.err_exp:
    Expect the documentation of the new option.

tests/invalid_nodepend/Mmakefile:
    Specify --warn-unused-types for two test cases to test that the compiler
    does NOT generate warnings about unused types in the presence of previous
    errors.

tests/warnings/abstract_type_decl.err_exp:
tests/warnings/bug412.err_exp:
tests/warnings/warn_dead_procs.err_exp:
    Expect the new warnings for unused types.

tests/warnings/Mmakefile:
    Specify --warn-unused-types for the three test cases listed above.
2026-02-15 11:26:34 +11:00
Zoltan Somogyi
280db1b10e Describe the reason for the mode_error_info type. 2026-01-19 14:30:49 +11:00
Zoltan Somogyi
b34fa01682 Make mode errors in nondet contexts more understanable.
compiler/mode_errors.m:
    When generating diagnostics about code that is mode-incorrect
    because it can be backtracked over, explicitly mention the possibility
    that the culprit is a comma accidentally replaced by a period elsewhere.

compiler/options.m:
    Turn --warn-non-contiguous-clauses on by default. This should provide
    the context of any such typos.

NEWS.md:
    Mention the change in options.m.

    Fix existing typos.

tests/invalid/ho_unique_error.err_exp:
tests/invalid/io_in_ite_cond.err_exp:
tests/invalid/mostly_uniq_1.err_exp:
tests/invalid/mostly_uniq_2.err_exp:
tests/invalid/uniq_modes.err_exp:
tests/invalid/uniq_neg.err_exp:
    Conform to the change in mode_errors.m.

tests/warnings/help_text.err_exp:
    Conform to the change in options.m.
2025-11-03 22:01:50 +11:00
Zoltan Somogyi
d8a31e574e Move six utility modules from check_hlds to hlds.
compiler/inst_lookup.m:
compiler/inst_mode_type_prop.m:
compiler/inst_test.m:
compiler/inst_util.m:
compiler/mode_util.m:
compiler/type_util.m:
    Move these modules from the check_hlds package to the hlds package.
    The reason is that all the content of five of these modules, and
    most of the content of one module (inst_util.m) is not used
    exclusively during semantic checking passes. (A later diff
    should deal with the exception.) Some are used by the pass that
    builds the initial HLDS, and all are used by middle-end and backend
    passes. The move therefore reduces the number of inappropriate imports
    of the check_hlds package.

compiler/check_hlds.m:
compiler/hlds.m:
    Effect the transfer.

compiler/*.m:
    Conform to the changes above.
2025-10-08 23:07:13 +11:00
Zoltan Somogyi
ca20c38987 Split --warn-redundant-code from --warn-simple-code.
compiler/options.m:
    Move --warn-simple-code to the "warnings about dodgy code"
    category, as

    - most of the issues that it warns about are indeed evidence
      of dodgy code, and
    - its existing documentation also states that it is intended
      to report likely-to-be-incorrect code.

    Change the internal name of --warn-simple-code, in order to force
    all its existing uses to be reclassified.

    Let the --warn-redundant-code part stay in the style issues category,
    since the code will work just the same if the redundancies are removed.

NEWS.md:
    Announce the new option.

compiler/simplify_goal_call.m:
    Reclassify all uses of --warn-simple-code.

    Add a missing condition in an if-then-else.

compiler/add_clause.m:
compiler/add_type.m:
compiler/check_type_inst_mode_defns.m:
compiler/convert_import_use.m:
compiler/convert_parse_tree.m:
compiler/det_analysis.m:
compiler/det_infer_goal.m:
compiler/mercury_compile_front_end.m:
compiler/mode_errors.m:
compiler/simplify_goal.m:
compiler/simplify_goal_disj.m:
compiler/simplify_goal_ite.m:
compiler/simplify_info.m:
compiler/simplify_tasks.m:
compiler/state_var.m:
    Reclassify all uses of --warn-simple-code.

tests/warnings/help_text.err_exp:
    Expect the updated help text.
2025-08-18 14:53:08 +02:00
Zoltan Somogyi
823de2d37b Require warning/info messages to specify an option.
The objective of this step is two-fold:

- to fix --inhibit-warnings, making it shut up all warning
  and informational messages; and

- to ensure that it *stays* fixed, even when after new diagnostics
  are added.

As part of this fix, this diff adds a whole bunch of new warning
options, in order to control the warnings that previously were
not controlled by any option. (There was no need for new
informational options.)

As it happens, we have long used severity_informational for messages
that did not report any information about the code being compiled,
but to report actions that the compiler was taking. Create a new
option category, oc_report, for the new options that now control
those diagnostics.

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

compiler/error_spec.m:
    Change severity_warning and severity_informational to take an option
    as as argument. The semantics is that the diagnostic in which
    the severity occurs is conditional on that option, meaning that
    it is printed only if that option is set to "yes".

    Delete the severity_conditional function symbol from the severity
    type, since the mechanism just above handles its only use case.

    Define subtypes to represent error_specs in a standard form.

compiler/error_sort.m:
    Provide operations to convert error specs into their standard form.

    Make the sorting operation itself operate on the standard form.

compiler/write_error_spec.m:
    Convert error_specs to standard form before writing them out,
    in order to avoid duplicating the code for their standardization.

    Change the code that writes out error_specs to operate on the
    standard form. Implement the test implicit in the warning and
    and informational severities in this code.

compiler/error_util.m:
compiler/compiler_util.m:
    Delete operations that do not make sense with the new severity type.

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

compiler/options.m:
    Add new options to control all the previously-uncontrolled
    warning and informational messages.

NEWS.md:
    Announce the *public* new options.

compiler/option_categories.m:
compiler/print_help.m:
    Add the new option category, and fake-include it in the help text
    and the user guide. (The inclusion is fake because none of the
    options in the new category are user visible, meaning the section
    containing them is not visible either.)

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

compiler/det_infer_goal.m:
    Start a severity warning diagnostic with "Warning:"
    instead of "Error:".

compiler/mark_trace_goals.m:
    Fix an incorrect error message.

compiler/purity.m:
    Replace a correct/incorrect color pair with two inconsistent colors,
    because there is a reasonable probability of each one being right.

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

compiler/accumulator.m:
compiler/add_clause.m:
compiler/add_mode.m:
compiler/add_pragma.m:
compiler/add_pragma_tabling.m:
compiler/add_pred.m:
compiler/add_type.m:
compiler/check_module_interface.m:
compiler/check_type_inst_mode_defns.m:
compiler/check_typeclass.m:
compiler/color_schemes.m:
compiler/common.m:
compiler/convert_import_use.m:
compiler/convert_parse_tree.m:
compiler/dead_proc_elim.m:
compiler/det_check_proc.m:
compiler/det_check_switch.m:
compiler/det_infer_goal.m:
compiler/du_type_layout.m:
compiler/format_call_errors.m:
compiler/grab_modules.m:
compiler/hlds_call_tree.m:
compiler/inst_check.m:
compiler/introduce_parallelism.m:
compiler/make_hlds_error.m:
compiler/make_hlds_warn.m:
compiler/mark_tail_calls.m:
compiler/mark_trace_goals.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.m:
compiler/mode_errors.m:
compiler/modes.m:
compiler/module_qual.qual_errors.m:
compiler/opt_deps_spec.m:
compiler/options_file.m:
compiler/parse_goal.m:
compiler/post_term_analysis.m:
compiler/post_typecheck.m:
compiler/pre_typecheck.m:
compiler/purity.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/simplify_goal.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_disj.m:
compiler/simplify_goal_ite.m:
compiler/split_parse_tree_src.m:
compiler/state_var.m:
compiler/stratify.m:
compiler/style_checks.m:
compiler/superhomogeneous.m:
compiler/table_gen.m:
compiler/term_constr_errors.m:
compiler/term_errors.m:
compiler/termination.m:
compiler/typecheck_clauses.m:
compiler/typecheck_error_overload.m:
compiler/typecheck_error_undef.m:
compiler/typecheck_errors.m:
compiler/typecheck_msgs.m:
compiler/unused_args.m:
compiler/unused_imports.m:
compiler/warn_unread_modules.m:
compiler/write_module_interface_files.m:
    Conform to the changes above, mostly by either

    - adding an option to all warning and informational messages,
      sometimes using existing warning options and sometimes new ones,
      or

    - turning already explicitly-conditional-on-an-option messages
      into implicitly-conditional-on-that-option messages.

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

tests/invalid/one_member.m:
    Conform to the change in det_infer_goal.m.

tests/invalid/require_tailrec_1.err_exp:
tests/invalid/require_tailrec_2.err_exp:
    Actually obey the options for these modules in Mercury.options.

tests/invalid_purity/purity.err_exp:
tests/warnings/purity_warnings.err_exp:
    Conform to the change in purity.m.

tests/warnings/moved_trace_goal.err_exp:
    Conform to the change in mark_trace_goals.m.

tests/warnings/help_text.err_exp:
    Expect the documentation of all the new options.
2025-08-18 12:07:38 +02:00
Zoltan Somogyi
36044f1397 Eliminate clutter for no-matching-mode errors.
compiler/mode_errors.m:
    When a call matches none of the modes of the callee, we have long
    generated message about all the arguments whose initial inst
    is not right for *some* of the callee's modes. However, if there
    is at least one argument whose initial inst is not right for *any* of
    the callee's modes, then such arguments *definitely* represent bugs
    that the programmer must fix, while any *other* arguments only *may*
    represent bugs. but are actually quite likely to be completely ok
    (since they *do* match one or more modes).

    If there are any arguments that do not match any more, then report
    only those arguments. If there are no such arguments, then keep the
    report as is.

    Simplify the approach handling all those arguments in two ways:

    - use a two-arg structure instead of a map with two possible keys, and
    - do not require the generation of piece lists for compiler-generated
      arguments just so they can be dropped later.

tests/invalid/any_passed_as_ground.err_exp:
    Do not expect the message component deleted by the change above.
2025-06-29 00:09:09 +02:00
Zoltan Somogyi
f70b5d6de7 Implement options to warn about unused state vars.
The new --warn-unneeded-initial-statevar option asks the compiler
to warn about code such as

    pred_a(!.X, ...) :-
        ... code that uses !.X, but does not update it ...

In this case, the preferred fix is to just replace all occurrences
of !.X with X.

The new --warn-unneeded-final-statevar option asks the compiler
to warn about code such as

    pred_a(!X, ...) :-
        ... code that maybe uses !.X, but does not update it ...

In this case, the preferred fix also involves replacing all occurrences
of !.X with X, but it also involves either deleting the argument
containing !:X (the best option), or, if there is some reason why
the predicate's signature must stay unchanged, to replace !:X with X as well.
And if the clause body does not actually refer to either !.X or !:X, then
*both* arguments represented by !X should be deleted.

The first option is a style warning; the second option, due to the
signature change it may call for, is a non-style warning.

Both options have a version whose name adds a "-lambda" suffix, and which
does the same warnings for the heads of lambda expressions, not clauses.

Note that several of the modules below, including some that help to implement
the warnings, also contain code changes that result from *acting* on
the new warnings, e.g. by deleting unneeded statevar arguments.
Other, similar changes will also come after this diff is committed.

compiler/options.m:
doc/user_guide.texi:
    Document the new options.

compiler/state_var.m:
    Gather the information needed to decide what code merits the new warnings.
    Do so in three stages:

    - when processing the head of a clause or of a lambda expression,
    - when processing the body goal of that clause or lambda expression,
    - when finishing up the processing of the clause or lambda expression.

    Add a predicate to generate the warnings for lambda expressions.

    Do not generate the warnings for clauses. This is because whether or not
    we want to warn about state vars in some clauses depends on the properties
    of *other* clauses of the same predicate, and state_var.m has access
    to only one clause at a time. Instead,

    - return the info needed by the warning-generating code in pre_typecheck.m
      (one of the first passes we execute after adding all clauses
      to the HLDS), and

    - we export some functionality for use by that code.

    Switch to a convention for naming the program variables corresponding
    to the middle (non-initial, non-final) versions of state variables
    whose output is affected by changes in the code of the clause body goal
    only if they involve that specific state variable.

    Give some predicates more descriptive names.

compiler/make_hlds.m:
    Make state_var.m and its new functionality visible from outside
    the make_hlds package.

compiler/add_clause.m:
    Record the information gathered by state_var.m in each clause.

compiler/hlds_clauses.m:
    Add a slot to each clause for this information.

    Give some predicates more descriptive names.

compiler/headvar_names.m:
    Use the contents of the new slots to detect whether any clauses
    have unused state vars, and if so, return the chosen consensus names
    of the head vars to the code of pre_typecheck.m, which uses this info
    as part of the implementation of the new warnings.

compiler/pre_typecheck.m:
    Implement the new warnings.

compiler/mercury_compile_front_end.m:
    Record the warnings that pre_typecheck.m can now return.

compiler/error_spec.m:
compiler/write_error_spec.m:
    Add unsigned versions of the format pieces involving ints, for use
    by the new code in pre_typecheck.m, and implement them.

compiler/hlds_out_util.m:
compiler/maybe_util.m:
    Move two related types from hlds_out_util.m to maybe_util.m,
    in order to allow pre_typecheck.m to use one of them.

compiler/hlds_args.m:
    Add a new utility function for use by the new code above.

compiler/foreign.m:
    Act on the new warnings by deleting the long-unused predicates
    being warned about.

compiler/post_typecheck.m:
    Speed up this traversal. (I originally thought to implement
    the new warnings in this pass.)

compiler/add_foreign_proc.m:
compiler/add_pragma.m:
compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/add_type.m:
compiler/build_mode_constraints.m:
compiler/call_gen.m:
compiler/check_typeclass.m:
compiler/clause_to_proc.m:
compiler/code_loc_dep.m:
compiler/delay_info.m:
compiler/delay_partial_inst.m:
compiler/dense_switch.m:
compiler/det_check_goal.m:
compiler/det_infer_goal.m:
compiler/disj_gen.m:
compiler/du_type_layout.m:
compiler/format_call.m:
compiler/goal_expr_to_goal.m:
compiler/hlds_dependency_graph.m:
compiler/hlds_out_pred.m:
compiler/hlds_pred.m:
compiler/hlds_rtti.m:
compiler/inst_merge.m:
compiler/instance_method_clauses.m:
compiler/intermod.m:
compiler/interval.m:
compiler/ite_gen.m:
compiler/lookup_switch.m:
compiler/make_hlds_passes.m:
compiler/mark_tail_calls.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mode_errors.m:
compiler/parse_string_format.m:
compiler/passes_aux.m:
compiler/polymorphism.m:
compiler/polymorphism_info.m:
compiler/polymorphism_type_info.m:
compiler/pragma_c_gen.m:
compiler/prop_mode_constraints.m:
compiler/purity.m:
compiler/quantification.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_conj.m:
compiler/string_switch.m:
compiler/superhomogeneous.m:
compiler/switch_gen.m:
compiler/tag_switch.m:
compiler/type_constraints.m:
compiler/typecheck.m:
compiler/typecheck_clauses.m:
compiler/typecheck_coerce.m:
compiler/typecheck_error_unify.m:
compiler/unify_gen_deconstruct.m:
compiler/unify_proc.m:
compiler/var_origins.m:
    Conform to the changes above, and/or act on the new warnings.

browser/diff.m:
library/bit_buffer.m:
library/getopt.m:
library/getopt_io.m:
library/io.error_util.m:
library/io.file.m:
library/mercury_term_lexer.m:
library/parsing_utils.m:
library/pretty_printer.m:
library/robdd.m:
library/rtti_implementation.m:
library/string.builder.m:
library/string.parse_runtime.m:
mdbcomp/feedback.m:
    Act on the new warnings.

tests/hard_coded/sv_nested_closures.m:
    Change this test's code to avoid the new warnings, since
    (if --halt-at-warn is ever enabled) the warnings would interfere
    with its job .

tests/invalid/bug197.err_exp:
tests/invalid/bug487.err_exp:
tests/invalid/nullary_ho_func_error.err_exp:
tests/invalid/try_detism.err_exp:
tests/warnings/singleton_test_state_var.err_exp:
    Expect variable names for the middle versions of state vars
    using the new naming scheme.
2025-05-18 06:43:24 +10:00
Zoltan Somogyi
20b554d349 Work around the bug moving trace goals too far.
compiler/modecheck_goal.m:
    When attempting to schedule a trace goal, delay it if some of its
    nonlocals are not ground. Doing the delaying there and then allows us
    to specify the right set of waiting-on variables; allowing the scheduling
    of the goal inside the trace scope would lead to

compiler/delay_info.m:
    Add a pointer to the bug description in modecheck_goal.m.

compiler/mode_errors.m:
    Implement the new error, even though it should never be printed out
    to users.

tests/warnings/moved_trace_goal.err_exp:
    Expect a warning about the first trace goal in this test being moved
    to the correct location.
2025-05-06 14:25:00 +10:00
Zoltan Somogyi
0326634b10 Move pred markers and goal features to a new module.
compiler/hlds_markers.m:
    This is that new module.

compiler/hlds.m:
compiler/notes/compiler_design.html:
    Include and document the new module.

compiler/hlds_pred.m:
compiler/hlds_goal.m:
    Delete the moved code.

compiler/*.m:
    Conform to the changes above. Roughly a third of the modules
    that import hlds_pred.m or hlds_goal.m import the new module.
2025-01-12 22:10:28 +11:00
Zoltan Somogyi
c3f58711fc Move pred markers and goal features to a new module.
compiler/hlds_markers.m:
    This is that new module.

compiler/hlds.m:
compiler/notes/compiler_design.html:
    Include and document the new module.

compiler/hlds_pred.m:
compiler/hlds_goal.m:
    Delete the moved code.

compiler/*.m:
    Conform to the changes above. Roughly a third of the modules
    that import hlds_pred.m or hlds_goal.m import the new module.
2025-01-12 22:06:06 +11:00
Julien Fischer
b4a069559b Minor fixes for some copyright notices.
compiler/mode_errors.m:
compiler/simplify_goal_conj.m:
    Delete extra spaces.
2025-01-11 01:41:55 +11:00
Zoltan Somogyi
f8a101d503 Extend --errorcheck-only to some middle passes.
Some passes in the middle-end return warnings and/or errors, so having
--errorcheck-only stop after the front end was never ideal. We used to
make an exception for *one* middle-end pass, executing it even with
--errorcheck-only, but this was never systematic, nor would *making it*
systematic be viable (since it would involve a lot of unnecessary code
duplication).

Fix this by changing --errorcheck-only to call for the execution of all
compiler passes up to and including the last middle-end pass that can
generate any diagnostic.

compiler/op_mode.m:
    To reflect this new reality, move the op_mode representing
    --errorcheck-only to the op_mode category that represents
    going beyond the front end. Give this category a new name,
    since the old one would be misleading.

compiler/mercury_compile_augment.m:
    Stop the special-casing of the one middle-end pass mentioned above.

    In place of it, go on to the middle pass with --errorcheck-only.

compiler/mercury_compile_middle_passes.m:
    With --errorcheck-only, stop executing the middle end passes
    after the last one that can generate diagnostics.

compiler/handle_options.m:
    Conform to the changes above. Delete an error about an incompatibility
    with --errorcheck-only, since this diff cures that incompatibility.

compiler/make_hlds_error.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.m:
compiler/mode_errors.m:
    Conform to the changes above.

    In make_hlds_error.m and mode_errors.m, handle --errorcheck-only
    the same way as the code generation op_modes, since in both cases,
    this change enables diagnostics that one would get when generating
    target code.

tests/warnings/Mmakefile:
    Erase the distinction between test cases that use -errorcheck-only
    and those that asked for code generation, because the latter did that
    as the *only* way to get diagnostics from middle passes, and that is
    not true anymore.

    Use the standard %.err_res target defined in tests/Mmake.common,
    instead of an inferior copy, to execute the --errorcheck-only test cases
    (which now is all test cases but one).
2024-12-14 05:40:29 +11:00
Zoltan Somogyi
407525af59 Describe calls using not strings, but pieces.
compiler/hlds_out_util.m:
    Make the functions that describe calls return format_pieces instead of
    strings, and rename them accordingly.

compiler/det_report.m:
compiler/mode_errors.m:
compiler/typecheck_error_util.m:
    Use the returned pieces.

compiler/error_spec.m:
    Add a new format_piece, upper_case_next, for use in one of the modules
    above.

compiler/write_error_spec.m:
    Implement the new format_piece, by generalizing
    lower_case_next_if_not_first.
2024-11-01 16:46:28 +11:00
Zoltan Somogyi
0c162fb50e Improve diagnostics for higher-order mode errors.
In case of a problem with an argument of a higher order call,
we used to generate diagnostics containing text such as

    in argument 2 (i.e. argument 1 of the called function)
    of impure higher-order function call:

This clumsy construction was needed because the HLDS did not contain
enough info. Specifically, it did not specify whether in the source code,
the higher order call was written as e.g. call(P, A, B, C) or as P(A, B, C).
If the former, then then a problem with e.g. A occurs in argument 2
of the call to the 'call' builtin; if the latter, then it occurs
in argument 1 of the call to 'P'.

This diff fixes that. It adds to the HLDS representation of higher order
calls a record of the original form of the call in the source code

compiler/hlds_goal.m:
    Add this field, the higher_order_syntax field, to the representation
    of higher order calls.

compiler/goal_expr_to_goal.m:
    Fill the higher_order_syntax field for higher order predicate calls.

compiler/resolve_unify_functor.m:
    Fill the higher_order_syntax field for higher order function calls.

compiler/hlds_pred.m:
    Change the representation of generic calls in call_ids, which we use
    to identify callees for diagnostics, to include both the variable
    specifying the callee in higher order calls (by changing from a
    generic_call_id to the generic_call from which it would be derived
    by throwing out that info), and the var_name_source needed to
    look up its name.

compiler/hlds_out_util.m:
    Use the new higher_order_syntax field to generate text that

    - identifies the higher order call as using either call(P, A, B, C)
      syntax or P(A, B, C) syntax, and likewise for function, and

    - specifies the exact argument number (which will depend on the above
      distinction).

    This should result in more easily understandable diagnostics.

    Add a version of this predicate that generates text that specifically
    describes the higher order callee, not the higher order call as a whole.

    Add an option to suppress the printing of variable names.
    We use this to *not* refer to e.g. "the predicate P" when reporting
    an error about P actually being a function, not a predicate.

compiler/mode_info.m:
    Rename mode_context_call to mode_context_call_arg, because
    the context it describes is one argument of a call.

    Add a new mode context, mode_context_call, which now describes
    a call as a whole.

compiler/mode_errors.m:
    Use the new facilies described above to generate better diagnostics
    for higher order calls.

compiler/modecheck_util.m:
    Document the reason why we handle argument numbers for higher order calls
    the way we do.

    When generating an error that relates the whole of a higher order call,
    use the new mechanism in mode_info.m to record the fact that the error
    is not specific to any one argument of the call. Not doing this would
    include the argument number in the context of the error, which would be
    misleading.

    Add a utility function that is needed by more than one module below.

compiler/*.m:
    Conform to the changes above.

tests/invalid/anys_in_negated_contexts.err_exp:
tests/invalid/bind_var_errors.err_exp:
tests/invalid/constrained_poly_insts_2.err_exp:
tests/invalid/det_errors_cc.err_exp:
tests/invalid/fbnf.err_exp:
tests/invalid/functor_ho_inst_bad_2.err_exp:
tests/invalid/higher_order_mode_mismatch.err_exp:
tests/invalid/ho_any_inst.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
tests/invalid/ho_unique_error.err_exp:
tests/invalid/mode_error_arg_number_ho.err_exp:
tests/invalid/no_ho_inst.err_exp:
tests/invalid/type_diff.err_exp:
tests/invalid_purity/impure_func_t5_fixed.err_exp:
tests/invalid_purity/impure_pred_t1_fixed.err_exp:
tests/invalid_purity/impure_pred_t2.err_exp:
tests/invalid_purity/purity_nonsense_1.err_exp:
tests/invalid_purity/purity_nonsense_2.err_exp:
    Expect updated error messages.
2024-11-01 13:56:55 +11:00
Zoltan Somogyi
8d1a85a2f4 Fix typos. 2024-10-31 12:38:31 +11:00
Zoltan Somogyi
613345461c Report mode errors for bound inst vars.
compiler/mode_errors.m:
    When a procedure whose mode includes a constrained inst var makes
    a call that would bind that inst var, we have always considered that
    to be a mode error, but we reported that error only as actual insts
    of the actual arguments not matching the initial insts of the formal
    arguments.

    Change this by explicitly reporting the binding of one or more inst
    variables as the cause of the non-match, and naming those inst vars.

    Add a distinguishing prefix to all the function symbols of a type.

compiler/modecheck_call.m:
    Collect the extra info now required by mode_errors.m.

    Simplify the code that does the collecting, by setting the errors
    field of the mode_info to empty at the *start* of the processing
    of each procedure of the callee, and by returning info about a
    mismatch only when a mismatch actually happens.

    Fix some places that should have used modecheck_util.m's mechanism
    for computing arg offsets (to refer to user-visible arguments by
    their correct argument numbers even in the presence of compiler
    generated arguments) but didn't.

compiler/modecheck_util.m:
    Use an abstract type (modecheck_arg_offset) to make that kind of bug
    impossible to make.

    Record inst vars being bound when they shouldn't be bound.

    Use more descriptive variable names.

compiler/modecheck_unify.m:
compiler/unique_modes.m:
    Conform to the changes abovee.

tests/invalid/constrained_poly_insts_2.err_exp:
    Expect the extra info in error messages.
2024-10-30 17:03:59 +11:00
Zoltan Somogyi
07109943df Better diagnostics for "no matching mode" errors.
compiler/mode_errors.m:
    Completely rewrite the code that generates diagnostics for
    calls to predicates and functions where the insts of the arguments
    in the caller don't meet the requirements of any of the modes
    of the callee.

    The old code printed

    - a list of the arguments in the call together with their insts, and
    - a list of the arguments that do not match *any* of the modes.

    This was both too much and too little. It was too much in that
    arguments that match the initial inst requirements of all the modes
    cannot possibly be the cause of the mode error, so including
    their inst in the output adds only clutter. In was too little
    in that it did not identify arguments that failed to match
    the requirements of some modes while matching others.

    The new code prints the names of all the arguments, but

    - it prints the insts of only the arguments that fail to match
      the requirements of at one least mode, and
    - for each such argument, it specifies *which* modes of the callee
      its inst is incompatible with.

    An unrelated change: use lagged iteration to format lists of insts.

compiler/modecheck_util.m:
    Fix an old issue that wasn't a problem until now: when reporting
    a "no matching mode" error, include the mode that wasn't matched
    in the representation of the error. (The old code did not assume
    the presence of at least one mode, but the new one does.)

    Add an XXX about a desirable improvement, and make the first step
    towards implementing it.

compiler/modecheck_call.m:
    Fix comment rot.

compiler/write_error_spec.m:
    Fix an old bug that affected the updated output for one of the
    changed .err_exp files below. The bug was that when a word is
    followed by a color change, we assumed that it is ok to break the line
    after the color change. When e.g. some text wrapped up in a color
    is followed by a suffix, this assumption is false.

    The fix is to include the last word before the color change
    on the current line only if there is also room on the line
    for any following suffix.

    Document an invariant.

compiler/inst_mode_type_prop.m:
    Fix a typo in an error message.

tests/invalid/any_passed_as_ground.err_exp:
tests/invalid/constrained_poly_insts_2.err_exp:
tests/invalid/ho_default_func_1.err_exp:
tests/invalid/ho_default_func_3.err_exp:
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
tests/invalid/state_vars_test_1.err_exp:
tests/invalid/try_detism.err_exp:
    Expect the updated diagnostics.
2024-10-27 21:53:38 +11:00
Zoltan Somogyi
454a9e2d84 Make --print-error-spec-id apply to extracted msgs.
When e.g. mode analysis prints a diagnostic for a mode error,
it does so by taking an error_spec generated for the *actual* error,
extracing the error_msgs from it, and wrapping a new error_spec around them.
This has meant that if you specify --print-error-spec-id, you get the
id of the predicate that does the wrapping, NOT the id of the predicate
that generated the message describing the actual error.

This diff fixes this.

compiler/error_spec.m:
    Make the predicates that extract error_msgs from error_specs
    also return the error_spec's id.

    Add a version of those predicates that adds a final error_msg
    to the extracted error_msgs that includes this id at the end
    of the message, if --print-error-spec-id is specified.

    To do that, move here the code from write_error_spec.m that
    has always done this job for --print-error-spec-id, and wrap
    an (exported) predicate around it.

compiler/write_error_spec.m:
    Replace the moved code with that predicate.

compiler/mode_errors.m:
compiler/recompilation.check.m:
    Include the id in any extracted error_msgs if asked for.

compiler/error_sort.m:
    Ignore extracted ids.
2024-10-25 16:18:17 +11:00
Zoltan Somogyi
c7a72fee02 Add a blank before "possible reason" messages.
Mode analysis and determinism analysis can generate error_specs that
have long had the form:

    context1:   There was a problem with X. The following messages give
    context1:    possible reasons for this problem.
    context2:   Possible reason 1.
    context3:   Possible reason 2.

This diff adds a line containing only a context before every reason, yielding
this modified output:

    context1:   There was a problem with X. The following messages give
    context1:    possible reasons for this problem.
    context2:
    context2:   Possible reason 1.
    context3:
    context3:   Possible reason 2.

The new layout makes it significantly easier for readers to find
where each reason's description begins, especially when a single reason's
description itself takes several lines.

compiler/error_spec.m:
    Add a new kind of error_msg for the new lines, which are blank
    except possibly (usually) for a context.

    Move a utility predicate here from error_sort.m, to make it available
    to error_util.m.

compiler/error_util.m:
    Add a predicate that prefaces each reason's error_msg with the new
    blank line error_msg.

compiler/write_error_spec.m:
    Implement the new kind of error_msg.

compiler/det_report.m:
compiler/mode_errors.m:
    Use the new capability in the error_specs that list possible reasons
    for a problem.

compiler/error_sort.m:
    Conform to the changes above.

    Delete a predicate moved to error_spec.

tests/invalid/bug150.err_exp:
tests/invalid/bug150_partial_color.err_exp:
tests/invalid/bug496.err_exp:
tests/invalid/det_atomic_goal_msgs.err_exp:
tests/invalid/det_errors.err_exp:
tests/invalid/det_errors_and_io.err_exp:
tests/invalid/det_errors_deep.err_exp:
tests/invalid/magicbox.err_exp:
tests/invalid/mode_inf.err_exp:
tests/invalid/not_a_switch.err_exp:
tests/invalid/try_detism.err_exp:
tests/invalid/user_field_access_decl_override_1.err_exp:
    Expect updated diagnostics.
2024-10-01 13:34:26 +02:00
Zoltan Somogyi
386160f937 s/dont/do_not/ in the compiler directory.
compiler/*.m:
    Standardize on the do_not spelling over the dont contraction
    in the compiler directory. (We used to have a lot of both spellings.)
2024-08-12 12:49:23 +02:00
Zoltan Somogyi
f74e2b70c6 Rename the bound_inst type to bound_functor.
compiler/prog_data.m:
    As above. The main function symbol of the type was already named
    bound_functor, and "bound inst", when spoken/typed in text,
    usually refers to the bound/3 function symbol of the mer_inst type,
    not to new-renamed type.

compiler/add_mutable_aux_preds.m:
compiler/comp_unit_interface.m:
compiler/cse_detection.m:
compiler/det_report.m:
compiler/direct_arg_in_out.m:
compiler/equiv_type_hlds.m:
compiler/error_msg_inst.m:
compiler/float_regs.m:
compiler/hlds_code_util.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_mode.m:
compiler/hlds_statistics.m:
compiler/inst_abstract_unify.m:
compiler/inst_check.m:
compiler/inst_match.m:
compiler/inst_merge.m:
compiler/inst_mode_type_prop.m:
compiler/inst_test.m:
compiler/inst_user.m:
compiler/inst_util.m:
compiler/lco.m:
compiler/mode_constraints.m:
compiler/mode_errors.m:
compiler/mode_top_functor.m:
compiler/mode_util.m:
compiler/modecheck_coerce.m:
compiler/modecheck_util.m:
compiler/module_qual.qualify_items.m:
compiler/parse_inst_mode_name.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_out_item.m:
compiler/parse_tree_to_term.m:
compiler/pd_util.m:
compiler/prog_mode.m:
compiler/recompilation.usage.m:
compiler/simplify_goal_switch.m:
compiler/switch_detection.m:
compiler/types_into_modes.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Perform s/bound_inst/bound_functor/ and s/BoundInst/BoundFunctor/ where
    appropriate, with some instances of s/bound_inst_list/bound_functors/.
2024-07-23 13:33:59 +02:00
Zoltan Somogyi
a6f0470291 Use actual types in groundness tests.
compiler/inst_test.m:
    Add a type argument to inst_is_ground and related predicates.
    Previously, these predicates passed the type variable returned by
    the "no_type_available" function, which was less than ideal, because
    it prevents the recognition of a bound inst that lists all the function
    symbols of the type as being ground (provided of course that all
    *their* arguments are themselves ground).

    Stop considering "any" to match "ground" if the type is not a solver type.
    The previous code did the right thing for invalid/bad_fact_table_decls
    *only* because of the absence of type information; the new code does
    the right thing by design. (However, valid/any_matches_bound did depend
    on the old behavior.)

compiler/add_pragma_tabling.m:
compiler/common.m:
compiler/complexity.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/delay_partial_inst.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/fact_table.m:
compiler/goal_mode.m:
compiler/hlds_proc_util.m:
compiler/instmap.m:
compiler/interval.m:
compiler/lco.m:
compiler/loop_inv.m:
compiler/mode_errors.m:
compiler/mode_test.m:
compiler/modecheck_call.m:
compiler/modecheck_coerce.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/modes.m:
compiler/pd_util.m:
compiler/proc_requests.m:
compiler/prog_rep.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_disj.m:
compiler/ssdebug.m:
compiler/table_gen.m:
    Conform to the changes in inst_test.m, by passing along either
    the actual types of the variables later being tested for groundness,
    or the whole var_table in which their type can later be looked up.

tests/valid/Mmakefile:
tests/valid/any_matches_bound.m:
    Disable the any_matches_bound test case, because it depends on behavior
    that this diff changes. (That behavior was intented to support HAL,
    but is now obsolete.)
2024-07-02 16:16:24 +10:00
Zoltan Somogyi
5a45d1afb8 Replace the cons/3 cons_id ...
... with the du_data_ctor/1 cons_id, which contains a du_ctor/3.
Putting all the info about discriminated union data constructors into a
separate type allows code that works only with the cons_ids of du types
to stop having to worry about all the other kinds of cons_ids.

compiler/prog_data.m:
    As above.

    Delete the cons_ctor type from this module after moving it to
    recompilation.usage.m, which is the only part of the compiler
    that uses it.

compiler/add_foreign_enum.m:
    Replace cons_id_to_tag_map with du_ctor_to_tag_map, since the only
    cons_ids the map handles are du_ctors.

compiler/hlds_cons.m:
    Replace cons_ids with du_ctors in the cons_table and in the
    info we keep about du types' fields.

compiler/hlds_data.m:
    Replace cons_ids with du_ctors in cheaper_tag_tests.

    Provide two forms of a utility function. Both return du_ctors,
    but one wraps them up as cons_ids.

compiler/type_assign.m:
    Replace cons_ids with du_ctors in cons_type_info_sources.

compiler/type_util.m:
    Switch many of the utility predicates and functions in this module
    to operate on du_ctors instead of cons_ids. Split some of the others
    to have both du_ctor and cons_id versions.

    Replace a predicate that returned a set of solutions one at a time
    on backtracking with a predicate that returns all the solutions
    at once in a list.

    Reduce unnecessary variability in variable names.

    Add some XXXs for code with unclear motivations.

compiler/typecheck_error_undef.m:
    Delete a function argument that was used only in a sanity check,
    because the code at its only call site derived that argument using code
    that made it impossible for the sanity check to fail.

    Factor out some common code.

compiler/parse_tree_out_cons_id.m:
    For three functions that operate on cons_ids, add versions
    that do the same job on du_ctors.

compiler/inst_match.m:
    Conform to the changes above. This diff rewrites from scratch
    the algorithm for testing whether a list of bound insts covers
    *all* the du_ctors of a type, because the old code was both inefficient
    and very opaque.

compiler/float_regs.m:
    Conform to the changes above, and delete a conditionally enabled abort
    that shouldn't ever be enabled.

compiler/inst_util.m:
    Conform to the changes above, and rename a predicate to avoid
    an ambiguity.

compiler/mode_errors.m:
    Conform to the changes above, and switch to printing the cons_ids
    in some error messages using the standard mechanisms of
    write_error_spec.m.

compiler/resolve_unify_functor.m:
    Conform to the changes above. Factor out repeated tests against
    du_data_ctor.

compiler/term_norm.m:
    Conform to the changes above. Add XXXs for some bugs.

compiler/add_type.m:
compiler/assertion.m:
compiler/builtin_lib_types.m:
compiler/comp_unit_interface.m:
compiler/complexity.m:
compiler/const_struct.m:
compiler/cse_detection.m:
compiler/ctgc.selector.m:
compiler/dead_proc_elim.m:
compiler/deep_profiling.m:
compiler/delay_partial_inst.m:
compiler/direct_arg_in_out.m:
compiler/distance_granularity.m:
compiler/du_type_layout.m:
compiler/error_msg_inst.m:
compiler/field_access.m:
compiler/format_call.m:
compiler/goal_expr_to_goal.m:
compiler/goal_util.m:
compiler/hhf.m:
compiler/higher_order.specialize_calls.m:
compiler/higher_order.specialize_unify_compare.m:
compiler/hlds_code_util.m:
compiler/hlds_dependency_graph.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_type_table.m:
compiler/hlds_out_util.m:
compiler/implementation_defined_literals.m:
compiler/inst_abstract_unify.m:
compiler/inst_check.m:
compiler/inst_merge.m:
compiler/inst_mode_type_prop.m:
compiler/inst_test.m:
compiler/instmap.m:
compiler/intermod.m:
compiler/intermod_decide.m:
compiler/lco.m:
compiler/ml_global_data.m:
compiler/ml_unify_gen_construct.m:
compiler/ml_unify_gen_deconstruct.m:
compiler/ml_unify_gen_util.m:
compiler/mode_top_functor.m:
compiler/mode_util.m:
compiler/modecheck_coerce.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/module_qual.qualify_items.m:
compiler/old_type_constraints.m:
compiler/parse_inst_mode_name.m:
compiler/parse_tree_out_item.m:
compiler/parse_tree_to_term.m:
compiler/polymorphism_goal.m:
compiler/polymorphism_lambda.m:
compiler/pre_typecheck.m:
compiler/prog_ctgc.m:
compiler/prog_mode.m:
compiler/prog_rep.m:
compiler/prog_type.m:
compiler/prog_util.m:
compiler/purity.m:
compiler/qual_info.m:
compiler/rbmm.execution_path.m:
compiler/rbmm.region_transformation.m:
compiler/recompilation.usage.m:
compiler/recompilation.used_file.m:
compiler/recompute_instmap_deltas.m:
compiler/simplify_goal.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_switch.m:
compiler/simplify_goal_unify.m:
compiler/size_prof.m:
compiler/ssdebug.m:
compiler/stack_opt.m:
compiler/structure_reuse.direct_choose_reuse.m:
compiler/structure_reuse.direct_detect_garbage.m:
compiler/superhomogeneous.m:
compiler/table_gen.m:
compiler/term_constr_build.m:
compiler/typecheck_clauses.m:
compiler/typecheck_error_util.m:
compiler/typecheck_errors.m:
compiler/unify_gen_test.m:
compiler/unify_gen_util.m:
compiler/unify_proc.m:
compiler/untupling.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Conform to the changes above.

tests/invalid/coerce_int.err_exp:
tests/invalid/coerce_mode_error.err_exp:
tests/invalid/coerce_mode_error2.err_exp:
tests/invalid/coerce_recursive_inst.err_exp:
tests/invalid/coerce_recursive_type.err_exp:
    Expect diagnostics generated using the standard error_spec representations
    of cons_ids.
2024-06-30 21:36:03 +10:00
Zoltan Somogyi
0e2997dc1e Enable, document and announce color diagnostics.
compiler/options.m:
    Make --color-diagnostics enabled by default.

    Add a synonym for the --color-scheme option that uses British spelling.
    (We already had such a synonym for --color-diagnostics.)

    Document the user-visible options controlling colors in diagnostics.

    Delete old, now-superseded commented-out documentation.

doc/user_guide.texi:
    Document the user-visible options and environment variables
    controlling colors in diagnostics.

    Add a new chapter that explains in some detail not only the use of color
    in diagnostics, but also the effects of the --verbose-error-messages,
    --reverse-error-order and --limit-error-contexts options.

    Delete old, now-superseded commented-out documentation.

NEWS.md:
    Announce the compiler's new capabilities.

The rest of this diff is concerned with fixing an old issue with
--limit-error-contexts, which is that it operated on error_msgs.
If an error_spec contained two or more error_msgs, the compiler
could print some error_msgs whose contexts fell into one of the to-be-printed
ranges of line numbers, while NOT printing some other error_msgs whose
contexts did not do so. Since the wording of a non-first error_msg
often builds upon and references the wording of previous error_msgs
in the same error_spec, this was a problem. This diff changes things
so that if *any* error_msg in an error_spec has a context that falls into
one of the to-be-printed ranges of line numbers, we print *all* of the
error_msgs in that error_spec.

compiler/write_error_spec.m:
    To make the above possible, separate out the task of deciding which parts
    of error_specs to print, and which parts not to print, from the task
    of actually writing them out. The decision part takes into account
    the conditional-on-verbosity-level and conditional-on-an-option-value
    parts of error_msgs, as well as the effect of --limit-error-contexts.

    Construct the color database and look up the max line width exactly once
    for each call to the exported predicates of this module.

compiler/error_spec.m:
    Delete the print_anything function symbol from the error_msg_component
    type. Its presence would have made the separation of making-decisions code
    from writing-out code in write_error_spec.m more complicated. Since
    the stuff it prints is not a list of pieces, handling it would have
    required using a data structure containing either lists of (either pieces
    or anythings) to communicate between the decision code and the writing
    code. While this is doable, it is not elegant, and it turns out to be
    far simpler to just eliminate print_anything.

    Take the opportunity to change the type of the extra indent field
    in error_msgs from int to uint.

compiler/mode_errors.m:
    Replace the only use of print_anything in the compiler with code
    that just uses lists of pieces. (This is possible now due to the
    rewrite of write_goal in terms of format_goal, which happened many years
    *after* we implemented print_anything specifically for this use case.)

compiler/accumulator.m:
    Fix the only place in the compiler that actually depended on the
    implicit newline we used to add between consecutive error_msgs in an
    error_spec (at least according to our test suite). Everywhere else,
    we routine end every error_msg with an *explicit* nl piece, and now
    we do so here as well.

    Simplify the code constructing the one error_spec here by replacing
    several conditional-on-an-option-value error_messages with a simple
    test of that option, since its value is trivially available here.
    (Two components of that error_spec *should* have been conditional
    on the same option but were not, so this is a bug fix as well.)

    Rename some predicates to avoid ambiguity.

compiler/check_typeclass.m:
compiler/common.m:
compiler/error_sort.m:
compiler/error_util.m:
compiler/fact_table.m:
compiler/mercury_compile_main.m:
compiler/options_file.m:
compiler/parse_module.m:
compiler/post_typecheck.m:
compiler/term_constr_errors.m:
compiler/term_errors.m:
    Conform to the int->uint change in error_spec.m.
2024-06-23 14:37:27 +10:00
Zoltan Somogyi
8f490f6b69 Make module_qual.m a proper package.
compiler/module_qual.m:
    Delete from this module everything except include_module declarations,
    making it a proper package, after moving (most of) the deleted things
    to other modules. The rest were already unused.

compiler/module_qual.mq_info.m:
    This new submodule of module_qual.m contains the definition of the
    mq_info type, its getter/setter predicates, and some utility operations.
    This is the bulk of the old module_qual.m.

    Delete two fields of the old mq_info/mq_sub_info structure, because
    they were never used.

compiler/module_qual.qualify_items.m:
    Move the predicates that module qualify entire aug_comp_units,
    aug_make_int_units and parse_tree_int3s here from module_qual.m.

    Rename some already-here predicates to avoid name clashes with
    the newly moved predicates.

    Export only the predicates that are used outside the module *now*.

    Update some comments.

compiler/module_qual.id_set.m:
    Move a type and a predicate here from module_qual.m.

    Make a comment more detailed.

    Reorder the args of a predicate.

compiler/module_qual.collect_mq_info.m:
    Delete some trace goals that lost their usefulness a long time ago.

compiler/notes/compiler_design.html:
    Update the documentation of the module_qual package.

    Conform to the changes above.

compiler/add_clause.m:
compiler/add_type.m:
compiler/comp_unit_interface.m:
compiler/hlds_module.m:
compiler/make_hlds_passes.m:
compiler/mercury_compile_make_hlds.m:
compiler/module_qual.qual_errors.m:
compiler/pred_table.m:
compiler/qual_info.m:
compiler/superhomogeneous.m:
    Conform to the changes above.

compiler/add_class.m:
compiler/add_foreign_proc.m:
compiler/higher_order.make_specialized_preds.m:
compiler/ml_lookup_switch.m:
compiler/mode_errors.m:
compiler/tag_switch_util.m:
    Sort import_module declarations.
2024-06-08 02:28:36 +10:00
Zoltan Somogyi
2526c4b8cb Split possible_cause into hint and inconsistent.
compiler/error_spec.m:
    Replace the possible_cause color name with the hint and inconsistent
    color names, as agreed on m-rev.

compiler/globals.m:
compiler/write_error_spec.m:
    Update the code handling color names and their mapping to color shades.

compiler/options.m:
    Update the invisible options that record that mapping.

tools/bootcheck:
    Update the color scheme used for the test suite.

compiler/accumulator.m:
compiler/add_pragma.m:
compiler/add_pragma_tabling.m:
compiler/add_type.m:
compiler/check_typeclass.m:
compiler/equiv_type.m:
compiler/format_call_errors.m:
compiler/inst_check.m:
compiler/make_hlds_error.m:
compiler/make_hlds_passes.m:
compiler/make_hlds_warn.m:
compiler/mode_errors.m:
compiler/module_qual.qual_errors.m:
compiler/parse_item.m:
compiler/parse_mutable.m:
compiler/parse_pragma.m:
compiler/parse_type_defn.m:
compiler/post_typecheck.m:
compiler/simplify_goal_call.m:
compiler/simplify_proc.m:
compiler/split_parse_tree_src.m:
compiler/state_var.m:
compiler/termination.m:
compiler/typecheck_error_overload.m:
compiler/typecheck_error_undef.m:
compiler/typecheck_errors.m:
    Replace uses of the possible_cause color with one of its replacements.
    In a few cases, adjust some other colors as well.

tests/invalid/bad_statevar_bad_context.err_exp:
tests/invalid/bind_in_negated.err_exp:
tests/invalid/bug197.err_exp:
tests/invalid/bug487.err_exp:
tests/invalid/coerce_disambig.err_exp:
tests/invalid/coerce_implied_mode.err_exp:
tests/invalid/coerce_infer.err_exp:
tests/invalid/coerce_non_du.err_exp:
tests/invalid/coerce_type_error.err_exp:
tests/invalid/coerce_unify_tvars.err_exp:
tests/invalid/conflicting_tabling_pragmas.err_exp:
tests/invalid/dcg_context.err_exp:
tests/invalid/default_ho_inst_2.err_exp:
tests/invalid/fbnf.err_exp:
tests/invalid/freefree.err_exp:
tests/invalid/functor_ho_inst_bad_1.err_exp:
tests/invalid/functor_ho_inst_bad_3.err_exp:
tests/invalid/higher_order_mode_mismatch.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
tests/invalid/merge_inst_error.err_exp:
tests/invalid/mode_inf.err_exp:
tests/invalid/modes_erroneous.err_exp:
tests/invalid/multimode_dcg.err_exp:
tests/invalid/partial_implied_mode.err_exp:
tests/invalid/quant_constraint_1.err_exp:
tests/invalid/quant_constraint_2.err_exp:
tests/invalid/string_format_bad.err_exp:
tests/invalid/string_format_unknown.err_exp:
tests/invalid/test_may_duplicate.err_exp:
tests/invalid/test_may_export_body.err_exp:
tests/invalid/type_diff.err_exp:
tests/invalid/typeclass_dup_method_mode.err_exp:
tests/invalid_make_int/bad_mutable_int.int_err_exp:
tests/invalid_nodepend/duplicate_modes.err_exp:
tests/invalid_nodepend/errors_2.err_exp:
tests/invalid_nodepend/occurs.err_exp:
tests/invalid_nodepend/require_tailrec_invalid.err_exp:
tests/invalid_nodepend/test_with_type.err_exp:
tests/invalid_nodepend/unbound_type_vars.err_exp:
tests/invalid_purity/impure_pred_t1_fixed.err_exp:
tests/invalid_purity/impure_pred_t2.err_exp:
tests/invalid_purity/purity_nonsense_1.err_exp:
tests/invalid_purity/purity_nonsense_2.err_exp:
tests/warnings/foreign_term_invalid.err_exp:
tests/warnings/format_call_multi.err_exp:
tests/warnings/format_call_warning.err_exp:
tests/warnings/table_with_inline.err_exp:
tests/warnings/warn_succ_ind.err_exp:
tests/warnings/warn_succ_ind.err_exp2:
tests/warnings/warn_succ_ind.err_exp3:
    Expect updated diagnostics.
2024-06-07 08:42:26 +10:00
Zoltan Somogyi
4d32e801f6 Use color in prog_event.m.
compiler/prog_event.m:
    Add color to the diagnostics generated by this module. Add the word
    "Error" to the start of each diagnostic.

compiler/add_type.m:
compiler/format_call_errors.m:
    Refine just what gets colored in some diagnostics.

compiler/mode_errors.m:
    Fix a singular/plural disagreement.

tests/invalid/any_passed_as_ground.err_exp:
tests/invalid/constrained_poly_insts_2.err_exp:
tests/invalid/ho_default_func_1.err_exp:
tests/invalid/ho_default_func_3.err_exp:
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
tests/invalid/state_vars_test_1.err_exp:
tests/invalid/string_format_bad.err_exp:
tests/invalid/string_format_unknown.err_exp:
tests/invalid/subtype_foreign_supertype_1.err_exp:
tests/invalid/subtype_foreign_supertype_2.err_exp:
tests/invalid/synth_attr_error.err_exp:
tests/invalid/try_detism.err_exp:
tests/warnings/format_call_multi.err_exp:
tests/warnings/format_call_warning.err_exp:
    Expect updated diagnostics.
2024-06-01 23:08:34 +10:00
Zoltan Somogyi
76f95cfa98 Fit the x_list_to_y_pieces functions into a scheme.
compiler/error_spec.m:
    The existing functions for formatting lists of items as the
    components of diagnostics grew without design. Impose a design
    on them, by fitting them into an overall scheme with consistent
    rules, and document those rules.

    Add a utility function that me

compiler/format_call_errors.m:
    when generating a diagnostic reporting a mismatch between a
    conversion specifier and the value in a poly_type, and that kind of
    poly_type had more than one valid conversion specifier, we intended
    to print all of those valid conversion specifiers, but missed printing
    the first one. Fix this.

compiler/typecheck_error_type_assign.m:
    Fix an old bug: when dumping a type assign for the verbose part
    of a type error's diagnostic, we used to print the first of
    any typeclass constraints on the type vars of the type assign
    at the end of the line giving the type of the last program variable,
    even though that info is not specific to that program variable.

compiler/add_clause.m:
compiler/add_foreign_enum.m:
compiler/add_foreign_proc.m:
compiler/add_mode.m:
compiler/add_pragma.m:
compiler/check_import_accessibility.m:
compiler/check_pragma_format_call.m:
compiler/check_type_inst_mode_defns.m:
compiler/check_typeclass.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/direct_arg_in_out.m:
compiler/du_type_layout.m:
compiler/equiv_type.m:
compiler/error_msg_inst.m:
compiler/error_type_util.m:
compiler/handle_options.m:
compiler/hlds_call_tree.m:
compiler/hlds_error_util.m:
compiler/inst_check.m:
compiler/make_hlds_error.m:
compiler/make_hlds_warn.m:
compiler/mode_errors.m:
compiler/module_qual.qual_errors.m:
compiler/old_type_constraints.m:
compiler/options_file.m:
compiler/parse_class.m:
compiler/parse_goal.m:
compiler/parse_inst_mode_defn.m:
compiler/parse_inst_mode_name.m:
compiler/parse_item.m:
compiler/parse_pragma.m:
compiler/parse_pragma_foreign.m:
compiler/parse_type_defn.m:
compiler/post_typecheck.m:
compiler/prog_event.m:
compiler/prog_foreign_enum.m:
compiler/prog_mode.m:
compiler/recompilation.check.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_disj.m:
compiler/state_var.m:
compiler/superhomogeneous.m:
compiler/typecheck_error_overload.m:
compiler/typecheck_error_undef.m:
compiler/typecheck_errors.m:
    Conform to the changes in error_spec.m.

tests/invalid/mpj_1.err_exp:
tests/invalid/string_format_bad.err_exp:
tests/invalid/string_format_unknown.err_exp:
tests/warnings/format_call_warning.err_exp:
    Expect updated diagnostics.
2024-06-01 16:21:40 +10:00
Zoltan Somogyi
12d3d1cecd Report coerce inst errors more systematically.
compiler/modecheck_coerce.m:
    When checking the bound_insts occurring in the initial inst of the
    coerced term, use the same mechanism to handle

    - any cons_ids they contain that do not occur in the input type,
    - any cons_ids they contain that do occur in the input type but are
      used in the bound_inst with the wrong arity, and
    - any cons_ids they contain that do not occur in the result type.

    The new mechanism allows us to catch any combination of these kinds
    of errors in the same list of bound insts. The old mechanism could not
    do this, partially because it only ever tried collect at most one
    error of some of the above kinds.

    Use more standard variable names.

compiler/mode_errors.m:
    Change the representation of coerce mode errors to accommodate
    the new capability in modecheck_coerce.m, and change the code
    that reports such mode errors accordingly.

tests/invalid/coerce_int.m:
    Make this case just a bit tougher.

tests/invalid/coerce_int.err_exp:
tests/invalid/coerce_mode_error2.err_exp:
tests/invalid/coerce_recursive_type.err_exp:
    Expect updated diagnostics.
2024-05-30 17:20:37 +10:00
Zoltan Somogyi
2e0f12ba39 Use the last context word in type diagnostics.
compiler/hlds_out_util.m:
    When returning the pieces to use to describe a unify context,
    return an indication of what we called the innermost part of the context.

compiler/typecheck_errors.m:
    Use this info to decide what to call the variable that has the
    incorrect type in a diagnostic, if the variable has no name of its own,
    and therefore *has* to be described by position.

compiler/det_analysis.m:
compiler/det_report.m:
compiler/mode_errors.m:
compiler/typecheck_error_util.m:
    Ignore the extra info now returned by the updated predicate
    in hlds_out_util.m.

tests/invalid/error_in_list.err_exp:
tests/invalid/getopt_old.err_exp:
    Expect updated diagnostics.
2024-05-24 10:08:11 +10:00
Zoltan Somogyi
8a1c24010c Expand a diagnostic, and use quotes more consistently.
compiler/mode_errors.m:
    When a closure using a defined predicate/function matches more than one
    procedure, does not just print this fact; list the mode numbers of the
    matched procedures as well.

compiler/modecheck_unify.m:
    Record the extra info for mode_errors.m.

compiler/det_analysis.m:
    Put quotes around var names more consistently.

tests/invalid/currying_multimode_func.err_exp:
tests/invalid/multimode_addr_problems.err_exp:
tests/invalid/one_member.err_exp:
tests/invalid/promise_equivalent_solutions_test_1.err_exp:
tests/invalid/promise_equivalent_solutions_test_2.err_exp:
    Expect updated diagnostics.
2024-05-23 17:53:15 +10:00
Zoltan Somogyi
4da9c3745e Use understated colors in mode_errors.m.
compiler/mode_errors.m:
    Use color more sparingly, to preserve the impact of when we *do* use it.

    Improve the wording of some diagnostics. In one case, include
    more information in a diagnostic.

    Add some XXXs about possible further improvements.

compiler/make_hlds_warn.m:
    Use color more sparingly, to preserve the impact of when we *do* use it.

compiler/error_spec.m:
    Add two utility functions for use by new code in mode_errors.m.

compiler/modecheck_call.m:
    Supply the extra detail now expected by mode_errors.m.

tests/invalid/any_mode.err_exp:
tests/invalid/any_passed_as_ground.err_exp:
tests/invalid/any_should_not_match_bound.err_exp:
tests/invalid/any_to_ground_in_ite_cond.err_exp:
tests/invalid/any_to_ground_in_ite_cond_nomax.err_exp:
tests/invalid/anys_in_negated_contexts.err_exp:
tests/invalid/bad_sv_unify_msg.err_exp:
tests/invalid/bind_in_negated.err_exp:
tests/invalid/bind_var_errors.err_exp:
tests/invalid/bug197.err_exp:
tests/invalid/bug278.err_exp:
tests/invalid/bug487.err_exp:
tests/invalid/char_inst.err_exp:
tests/invalid/coerce_clobbered.err_exp:
tests/invalid/coerce_disambig.err_exp:
tests/invalid/coerce_instvar.err_exp:
tests/invalid/coerce_int.err_exp:
tests/invalid/coerce_mode_error.err_exp:
tests/invalid/coerce_mode_error2.err_exp:
tests/invalid/coerce_recursive_inst.err_exp:
tests/invalid/coerce_recursive_type.err_exp:
tests/invalid/constrained_poly_insts2.err_exp:
tests/invalid/currying_multimode_func.err_exp:
tests/invalid/dcg_context.err_exp:
tests/invalid/default_ho_inst_1.err_exp:
tests/invalid/default_ho_inst_2.err_exp:
tests/invalid/field_syntax_error.err_exp:
tests/invalid/freefree.err_exp:
tests/invalid/functor_ho_inst_bad_1.err_exp:
tests/invalid/functor_ho_inst_bad_2.err_exp:
tests/invalid/functor_ho_inst_bad_3.err_exp:
tests/invalid/ho_any_inst.err_exp:
tests/invalid/ho_default_func_1.err_exp:
tests/invalid/ho_default_func_2.err_exp:
tests/invalid/ho_default_func_3.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
tests/invalid/ho_unique_error.err_exp:
tests/invalid/invalid_integral_call_inst.err_exp:
tests/invalid/io_in_ite_cond.err_exp:
tests/invalid/merge_inst_error.err_exp:
tests/invalid/mode_inf.err_exp:
tests/invalid/modes_erroneous.err_exp:
tests/invalid/mostly_uniq1.err_exp:
tests/invalid/mostly_uniq2.err_exp:
tests/invalid/multimode_addr_problems.err_exp:
tests/invalid/multimode_dcg.err_exp:
tests/invalid/partial_implied_mode.err_exp:
tests/invalid/polymorphic_unification.err_exp:
tests/invalid/state_vars_test_1.err_exp:
tests/invalid/state_vars_test_2.err_exp:
tests/invalid/state_vars_test_5.err_exp:
tests/invalid/try_detism.err_exp:
tests/invalid/unify_mode_error.err_exp:
tests/invalid/uniq_modes.err_exp:
tests/invalid/uniq_neg.err_exp:
tests/invalid_nodepend/errors_1.err_exp:
tests/invalid_nodepend/errors_2.err_exp:
tests/invalid_nodepend/errors_3.err_exp:
tests/invalid_nodepend/occurs.err_exp:
tests/invalid_purity/impure_func_t5_fixed.err_exp:
tests/invalid_purity/purity.err_exp:
tests/warnings/double_underscore.err_exp:
tests/warnings/foreign_singleton.err_exp:
tests/warnings/missing_singleton_warning.err_exp:
tests/warnings/pragma_source_file.err_exp:
tests/warnings/singleton_test.err_exp:
tests/warnings/singleton_test_state_var.err_exp:
tests/warnings/unknown_warning.err_exp:
    Expect updated diagnostics.
2024-05-21 18:46:21 +10:00
Zoltan Somogyi
0fa51cc45c Use color in typecheck_error_undef.m ...
... and change the coloring done in many other modules.

compiler/typecheck_error_undef.m:
    Add color to the diagnostics generated by this module.

    In a few cases, improve the wording of the diagnostic.

    Make the name of a function and of a function symbol more descriptive.

    Convert some predicates from using many clauses to using
    an explicit disjunction.

    Delete a function that was sort-of a specialize version of a
    utility function in error_spec.m.

compiler/hlds_error_util.m:
    Change the functions that return descriptions of predicates and procedures,
    mostly for use in diagnostics, to allow the parts of those descriptions
    specific to an individual predicate or procedure to be colored *without*
    coloring the generic parts (such as the word "predicate" or "function").

    Add simpler versions of the affected functions for use cases that
    do not need any coloring.

compiler/accumulator.m:
compiler/add_clause.m:
compiler/add_pragma.m:
compiler/check_pragma_format_call.m:
compiler/check_typeclass.m:
compiler/dead_proc_elim.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/direct_arg_in_out.m:
compiler/fact_table.m:
compiler/float_regs.m:
compiler/format_call.m:
compiler/hlds_out_module.m:
compiler/hlds_statistics.m:
compiler/inst_mode_type_prop.m:
compiler/make_hlds_error.m:
compiler/mode_errors.m:
compiler/modes.m:
compiler/oisu_check.m:
compiler/old_type_constraints.m:
compiler/ordering_mode_constraints.m:
compiler/parse_module.m:
compiler/post_typecheck.m:
compiler/prop_mode_constraints.m:
compiler/purity.m:
compiler/simplify_goal_call.m:
compiler/stratify.m:
compiler/style_checks.m:
compiler/table_gen.m:
compiler/tabling_analysis.m:
compiler/term_constr_errors.m:
compiler/term_errors.m:
compiler/termination.m:
compiler/trailing_analysis.m:
compiler/typecheck.m:
compiler/typecheck_clauses.m:
compiler/typecheck_error_overload.m:
compiler/typecheck_error_util.m:
compiler/typecheck_errors.m:
compiler/typecheck_msgs.m:
    Conform to the changes in hlds_error_util.m.

    In many cases, improve the affected diagnostics, and maybe other nearby
    diagnostics, in other ways as well.

compiler/hlds_data.m:
    Fix comments.

tests/invalid/bad_exported_mode.err_exp:
tests/invalid/bad_fact_table_data.err_exp:
tests/invalid/bad_fact_table_data.err_exp2:
tests/invalid/bad_fact_table_decls.err_exp:
tests/invalid/bad_format_call.err_exp:
tests/invalid/bad_pred_arity.err_exp:
tests/invalid/bad_sv_unify_msg.err_exp:
tests/invalid/bug10.err_exp:
tests/invalid/bug113.err_exp:
tests/invalid/bug150.err_exp:
tests/invalid/bug184.err_exp:
tests/invalid/bug197.err_exp:
tests/invalid/bug214.err_exp:
tests/invalid/bug238.err_exp:
tests/invalid/bug257.err_exp:
tests/invalid/bug476.err_exp:
tests/invalid/bug496.err_exp:
tests/invalid/builtin_proc.err_exp:
tests/invalid/coerce_syntax.err_exp:
tests/invalid/coerce_void.err_exp:
tests/invalid/constructor_warning.err_exp:
tests/invalid/det_atomic_goal_msgs.err_exp:
tests/invalid/det_errors.err_exp:
tests/invalid/det_errors_and_io.err_exp:
tests/invalid/det_errors_cc.err_exp:
tests/invalid/erroneous_throw_promise.err_exp:
tests/invalid/exist_foreign_error.err_exp:
tests/invalid/exported_mode.err_exp:
tests/invalid/exported_unify.err_exp:
tests/invalid/field_syntax_error.err_exp:
tests/invalid/foreign_purity_mismatch.err_exp:
tests/invalid/foreign_purity_mismatch.err_exp2:
tests/invalid/foreign_purity_mismatch.err_exp3:
tests/invalid/foreign_type_2.err_exp:
tests/invalid/freefree.err_exp:
tests/invalid/getopt_io_old.err_exp:
tests/invalid/getopt_old_se.err_exp:
tests/invalid/gh72_errors.err_exp:
tests/invalid/hawkins_mm_fail_reset.err_exp:
tests/invalid/ho_unique_error.err_exp:
tests/invalid/impure_method_impl.err_exp:
tests/invalid/invalid_event.err_exp:
tests/invalid/invalid_new.err_exp:
tests/invalid/io_in_ite_cond.err_exp:
tests/invalid/loopcheck.err_exp:
tests/invalid/magicbox.err_exp:
tests/invalid/make_opt_error.err_exp:
tests/invalid/method_impl.err_exp:
tests/invalid/missing_det_decls.err_exp:
tests/invalid/mode_decl_in_wrong_section.err_exp:
tests/invalid/mostly_uniq1.err_exp:
tests/invalid/mostly_uniq2.err_exp:
tests/invalid/multimode_missing_impure.err_exp:
tests/invalid/multimode_syntax.err_exp:
tests/invalid/multiply_star.err_exp:
tests/invalid/no_method.err_exp:
tests/invalid/not_a_switch.err_exp:
tests/invalid/one_member.err_exp:
tests/invalid/pragma_c_code_dup_var.err_exp:
tests/invalid/pragma_c_code_no_det.err_exp:
tests/invalid/pragma_c_code_no_det.err_exp2:
tests/invalid/pragma_c_code_no_det.err_exp3:
tests/invalid/pragma_qual_error.err_exp:
tests/invalid/qual_basic_test2.err_exp:
tests/invalid/qualified_cons_id2.err_exp:
tests/invalid/quant_constraint_1.err_exp:
tests/invalid/quant_constraint_2.err_exp:
tests/invalid/record_syntax_errors.err_exp:
tests/invalid/ref_to_implicit_comma.err_exp:
tests/invalid/ref_to_implicit_pred.err_exp:
tests/invalid/spurious_mode_error.err_exp:
tests/invalid/state_vars_test_3.err_exp:
tests/invalid/string_format_bad.err_exp:
tests/invalid/string_format_unknown.err_exp:
tests/invalid/test_promise_equivalent_clauses.err_exp:
tests/invalid/test_type_spec.err_exp:
tests/invalid/transitive_import_class.err_exp:
tests/invalid/try_detism.err_exp:
tests/invalid/type_error_use_module.err_exp:
tests/invalid/type_inf_loop.err_exp:
tests/invalid/typeclass_dup_method_mode.err_exp:
tests/invalid/typeclass_mode_2.err_exp:
tests/invalid/typeclass_mode_3.err_exp:
tests/invalid/typeclass_mode_4.err_exp:
tests/invalid/typeclass_test_8.err_exp:
tests/invalid/types2.err_exp:
tests/invalid/undeclared_mode.err_exp:
tests/invalid/undef_mode_and_no_clauses.err_exp:
tests/invalid/undef_symbol.err_exp:
tests/invalid/unsatisfiable_constraint.err_exp:
tests/invalid/user_field_access_decl_override_1.err_exp:
tests/invalid/wrong_arity_function.err_exp:
tests/invalid_make_int/bad_end_module.int_err_exp:
tests/invalid_make_int/missing_initial_section.int_err_exp:
tests/invalid_nodepend/after_end_module.err_exp:
tests/invalid_nodepend/bad_fact_table.err_exp:
tests/invalid_nodepend/bigtest.err_exp:
tests/invalid_nodepend/bug410.err_exp:
tests/invalid_nodepend/constrained_poly_insts.err_exp:
tests/invalid_nodepend/duplicate_modes.err_exp:
tests/invalid_nodepend/errors_1.err_exp:
tests/invalid_nodepend/errors_2.err_exp:
tests/invalid_nodepend/errors_3.err_exp:
tests/invalid_nodepend/external.err_exp:
tests/invalid_nodepend/funcs_as_preds.err_exp:
tests/invalid_nodepend/impl_def_literal_syntax.err_exp:
tests/invalid_nodepend/invalid_binary_literal.err_exp:
tests/invalid_nodepend/invalid_decimal_literal.err_exp:
tests/invalid_nodepend/invalid_float_literal.err_exp:
tests/invalid_nodepend/invalid_hex_literal.err_exp:
tests/invalid_nodepend/invalid_main.err_exp:
tests/invalid_nodepend/invalid_octal_literal.err_exp:
tests/invalid_nodepend/no_exports.err_exp:
tests/invalid_nodepend/null_char.err_exp:
tests/invalid_nodepend/occurs.err_exp:
tests/invalid_nodepend/pragma_export.err_exp:
tests/invalid_nodepend/prog_io_erroneous.err_exp:
tests/invalid_nodepend/reserved_type_name.err_exp:
tests/invalid_nodepend/test_with_type.err_exp:
tests/invalid_nodepend/typeclass_test_1.err_exp:
tests/invalid_nodepend/typeclass_test_2.err_exp:
tests/invalid_nodepend/types.err_exp:
tests/invalid_nodepend/unbound_type_vars.err_exp:
tests/invalid_nodepend/unterminated_octal_escape.err_exp:
tests/invalid_nodepend/vars_in_wrong_places.err_exp:
tests/invalid_purity/impure_func_t2.err_exp:
tests/invalid_purity/impure_func_t3.err_exp:
tests/invalid_purity/impure_func_t4.err_exp:
tests/invalid_purity/pragma_c_and_mercury.err_exp:
tests/invalid_purity/purity.err_exp:
tests/invalid_purity/purity_nonsense_1.err_exp:
tests/invalid_purity/purity_nonsense_2.err_exp:
tests/invalid_submodules/exported_unify3.err_exp:
tests/invalid_submodules/func_class.err_exp:
tests/invalid_submodules/undef_mod_qual.err_exp:
tests/recompilation/typeclass_method_pragma_r.err_exp.2:
tests/recompilation/with_type_re.err_exp.2:
tests/warnings/arg_order_rearrangment.err_exp:
tests/warnings/bug477.err_exp:
tests/warnings/det_infer_warning.err_exp:
tests/warnings/disabled_warning.err_exp:
tests/warnings/foreign_term_invalid.err_exp:
tests/warnings/format_call_multi.err_exp:
tests/warnings/format_call_warning.err_exp:
tests/warnings/infinite_recursion.err_exp:
tests/warnings/non_contiguous_decls.err_exp:
tests/warnings/non_stratification.err_exp:
tests/warnings/obsolete_proc_pragma.err_exp:
tests/warnings/pragma_term_conflict.err_exp:
tests/warnings/purity_warnings.err_exp:
tests/warnings/save.err_exp:
tests/warnings/simple_code.err_exp:
tests/warnings/singleton_test.err_exp:
tests/warnings/spurious_obsolete.err_exp:
tests/warnings/suspicious_recursion.err_exp:
tests/warnings/unneeded_mode_specific_clause.err_exp:
tests/warnings/unsigned_zero_cmp.err_exp:
tests/warnings/warn_dead_procs.err_exp:
tests/warnings/warn_dead_procs_trace.err_exp:
tests/warnings/warn_non_contiguous.err_exp:
tests/warnings/warn_non_contiguous_foreign.err_exp:
tests/warnings/warn_stubs.err_exp:
    Expect updated diagnostics.
2024-05-20 18:31:15 +10:00
Zoltan Somogyi
a16cd8c725 Replace three pred_or_func_to_* functions with two.
mdbcomp/prim_data.m:
    Delete the pred_or_func_to_string function that used to be defined here,
    and replace it with pred_or_func_to_str and pred_or_func_to_full_str
    that used to be in parse_tree_out_misc.m. These two names make it
    clear which one returns "pred" or "func", and which returns "predicate"
    or "function".

compiler/parse_tree_out_misc.m:
    Delete the functions moved to prim_data.m.

compiler/add_clause.m:
compiler/add_pred.m:
compiler/hlds_desc.m:
compiler/hlds_out_typeclass_table.m:
compiler/hlds_out_util.m:
compiler/make_hlds_error.m:
compiler/mlds_to_target_util.m:
compiler/mode_errors.m:
compiler/module_qual.qual_errors.m:
compiler/optimize.m:
compiler/parse_tree_out_sym_name.m:
compiler/polymorphism_lambda.m:
compiler/pred_name.m:
compiler/pred_table.m:
compiler/prog_type_test.m:
compiler/recompilation.check.m:
compiler/recompilation.used_file.m:
compiler/style_checks.m:
compiler/unused_args.m:
compiler/unused_imports.m:
compiler/write_error_spec.m:
    Conform to the changes above, mostly by not importing
    parse_tree_out_misc.m.
2024-05-12 15:41:09 +10:00
Zoltan Somogyi
75dc210ab3 Color subjects in mode errors.
compiler/mode_errors.m:
    Use color to emphasize the subject variables and terms of mode errors.

    Use color to emphasize disagreements as possible causes
    in a few more places.

    Require reporters of the "no matching mode" error to specify
    what the match was against. This is to allow us to generate
    better diagnostics. Note the things that should still be improved.

    Use the names of numbers (as in two, three etc) instead of their numeral
    versions.

    Improve the wording and/or the punctuation of some error messages.

compiler/inst_mode_type_prop.m:
    Use the names of numbers (as in two, three etc) instead of their numeral
    versions.

compiler/error_spec.m:
compiler/write_error_spec.m:
    Move two formerly private utility functions of write_error_spec.m
    to error_spec.m, and export them. One of them is now used in
    the modules above.

compiler/modecheck_call.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/unique_modes.m:
    Pass around info about "what the match was against" for the change
    in mode_errors.m descrived above.

compiler/hlds_out_util.m:
    Improve variable name.

compiler/hlds_module.m:
    Add an XXX.

tests/invalid/any_mode.err_exp:
tests/invalid/any_passed_as_ground.err_exp:
tests/invalid/any_should_not_match_bound.err_exp:
tests/invalid/any_to_ground_in_ite_cond.err_exp:
tests/invalid/any_to_ground_in_ite_cond_nomax.err_exp:
tests/invalid/anys_in_negated_contexts.err_exp:
tests/invalid/bad_sv_unify_msg.err_exp:
tests/invalid/bind_in_negated.err_exp:
tests/invalid/bind_var_errors.err_exp:
tests/invalid/bug117.err_exp:
tests/invalid/bug191.err_exp:
tests/invalid/bug278.err_exp:
tests/invalid/bug415.err_exp:
tests/invalid/bug487.err_exp:
tests/invalid/char_inst.err_exp:
tests/invalid/coerce_clobbered.err_exp:
tests/invalid/coerce_disambig.err_exp:
tests/invalid/coerce_implied_mode.err_exp:
tests/invalid/coerce_instvar.err_exp:
tests/invalid/coerce_int.err_exp:
tests/invalid/coerce_mode_error.err_exp:
tests/invalid/coerce_mode_error2.err_exp:
tests/invalid/coerce_recursive_inst.err_exp:
tests/invalid/coerce_recursive_type.err_exp:
tests/invalid/coerce_uniq.err_exp:
tests/invalid/constrained_poly_insts2.err_exp:
tests/invalid/currying_multimode_func.err_exp:
tests/invalid/dcg_context.err_exp:
tests/invalid/default_ho_inst.err_exp:
tests/invalid/default_ho_inst_2.err_exp:
tests/invalid/freefree.err_exp:
tests/invalid/functor_ho_inst_bad.err_exp:
tests/invalid/functor_ho_inst_bad_2.err_exp:
tests/invalid/functor_ho_inst_bad_3.err_exp:
tests/invalid/ho_any_inst.err_exp:
tests/invalid/ho_default_func_1.err_exp:
tests/invalid/ho_default_func_2.err_exp:
tests/invalid/ho_default_func_3.err_exp:
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
tests/invalid/ho_unique_error.err_exp:
tests/invalid/html.err_exp:
tests/invalid/inst_matches_final_bug.err_exp:
tests/invalid/invalid_integral_call_inst.err_exp:
tests/invalid/io_in_ite_cond.err_exp:
tests/invalid/merge_ground_any.err_exp:
tests/invalid/merge_inst_error.err_exp:
tests/invalid/mode_error_arg_number.err_exp:
tests/invalid/mode_inf.err_exp:
tests/invalid/modes_erroneous.err_exp:
tests/invalid/mostly_uniq1.err_exp:
tests/invalid/mostly_uniq2.err_exp:
tests/invalid/multimode_dcg.err_exp:
tests/invalid/no_ho_inst.err_exp:
tests/invalid/partial_implied_mode.err_exp:
tests/invalid/polymorphic_unification.err_exp:
tests/invalid/state_vars_test1.err_exp:
tests/invalid/state_vars_test5.err_exp:
tests/invalid/try_detism.err_exp:
tests/invalid/unify_mode_error.err_exp:
tests/invalid/uniq_modes.err_exp:
tests/invalid/uniq_neg.err_exp:
tests/invalid_nodepend/constrained_poly_insts.err_exp:
tests/invalid_nodepend/occurs.err_exp:
tests/invalid_purity/impure_func_t5_fixed.err_exp:
tests/invalid_purity/purity.err_exp:
tests/warnings/simple_code.err_exp:
tests/warnings/unify_f_g.err_exp:
    Expect the updated versions of diagnostics.
2024-05-07 10:11:11 +10:00
Zoltan Somogyi
47a29bf5fa Act on two of Julien's requests about mode errors.
compiler/mode_errors.m:
    Don't color the "or" between two colored insts.

    Put quotes a variable name. Reword the error message this occurs in
    to avoid using a possessive form of the variable name, to avoid
    two right quote characters in a row.

tests/invalid/no_ho_inst.err_exp:
tests/invalid/polymorphic_unification.err_exp:
    Expect the updated messages.
2024-05-04 03:17:00 +10:00
Zoltan Somogyi
e64210c2b0 Add more diagnostics to inst_mode_type_prop.m.
compiler/inst_mode_type_prop.m:
    This module used to check for only one kind of error:
    an inst name that was declared as being for a given type_ctor
    being applied to a value of a type whose principal type_ctor
    is not the declared one. Add tests for other incompatibilities
    between the inst and the type it is applied to:

    - a cons_id in a bound inst having a module qualifier that is
      incompatible with the module qualification of the type_ctor;

    - a cons_id in a bound inst not being a data constructor
      in the type_ctor;

    - a higher order inst being applied to a non-higher-order type, and

    - a higher order inst being applied to a higher-order type of the
      wrong arity.

    To make it possible to generate well-formatted error messages, especially
    for the last two kinds of errors, pass around the traversals not just
    the module_info, but also the type- and inst-varsets that specify the
    names of the type and inst vars in the types and insts. To do this
    without excessive argument passing, group all three into a single
    structure, and make this structure the fourth type in the main typeclass
    of this module.

compiler/types_into_modes.m:
    Conform to the changes in inst_mode_type_prop.m.

compiler/error_msg_inst.m:
    To make possible the proper formatting of one of the new diagnostics
    in inst_mode_type_prop.m, add an extra parameter to the error_msg_inst
    function (and to its error_msg_inst_name cousin): the prefix to use when
    choosing to format an inst to fit all on one line. For all previous
    callers of this function, there was no prefix required, but now there is.

compiler/add_mutable_aux_preds.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_inst_table.m:
compiler/mode_errors.m:
    Conform to the change in error_msg_inst.m.

tests/hard_coded/curry.m:
tests/hard_coded/ho_solns.m:
tests/valid/constrained_poly_bound_arg.m:
tests/valid/constrained_poly_insts.m:
    Fix code that has been broken all along, we just lacked the diagnostics
    to report it :-(

tests/invalid/type_prop_into_inst.{m,err_exp}:
    Add a new test case, containing the old, incorrect code in the above
    test cases, to test the new diagnostics.

tests/invalid/Mmakefile:
    Enable the new test case.

tests/invalid/coerce_recursive_type.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
    Expect one of the new diagnostics in addition to the existing ones.

tests/invalid/qualified_cons_id2.err_exp:
    Expect one of the new diagnostics in addition to some of existing ones.
    Do not expect two old diagnostics. One reported the same problem that
    the new diagnostic reports, but in a very confusing way: it reported
    that yes(ground) cannot be unified with yes(_), which is nonsense;
    the new diagnostic reports the actual problem, which is that the code
    tried to apply an inst that specified qualified_cons_id2.yes(...) to
    a term of type maybe.yes(...) (i.e. the bug was a disagreement over
    module qualification.) The other old diagnostics we don't get anyone
    is a consequence of the fact that we now report the bug earlier, and
    this makes the compiler stop before determinism analysis.
2024-05-01 20:12:42 +10:00
Zoltan Somogyi
af90a1702c Use color in mode error diagnostics.m.
compiler/mode_errors.m:
    Add color to diagnostics about mode errors where appropriate.

compiler/error_spec.m:
    Fix an issue raised by the changes to mode_errors.m, which was that
    having a colored span end in two or more newline pieces led to
    an unnecessary seemingly blank line at the end. (The line actually
    contained escape sequences to first set a color, and to then reset colors,
    but none of that was visible.) The fix is to always add color resets
    *before* any final sequence of newline pieces in the span being colored.

compiler/error_msg_inst.m:
    Add a note to a comment.

tests/invalid/any_mode.err_exp:
tests/invalid/any_should_not_match_bound.err_exp:
tests/invalid/any_to_ground_in_ite_cond.err_exp:
tests/invalid/any_to_ground_in_ite_cond_nomax.err_exp:
tests/invalid/anys_in_negated_contexts.err_exp:
tests/invalid/bad_sv_unify_msg.err_exp:
tests/invalid/bind_in_negated.err_exp:
tests/invalid/bind_var_errors.err_exp:
tests/invalid/bug117.err_exp:
tests/invalid/bug191.err_exp:
tests/invalid/bug278.err_exp:
tests/invalid/bug415.err_exp:
tests/invalid/bug487.err_exp:
tests/invalid/char_inst.err_exp:
tests/invalid/coerce_clobbered.err_exp:
tests/invalid/coerce_disambig.err_exp:
tests/invalid/coerce_implied_mode.err_exp:
tests/invalid/coerce_instvar.err_exp:
tests/invalid/coerce_int.err_exp:
tests/invalid/coerce_mode_error.err_exp:
tests/invalid/coerce_mode_error2.err_exp:
tests/invalid/coerce_recursive_inst.err_exp:
tests/invalid/coerce_recursive_type.err_exp:
tests/invalid/coerce_uniq.err_exp:
tests/invalid/constrained_poly_insts2.err_exp:
tests/invalid/currying_multimode_func.err_exp:
tests/invalid/dcg_context.err_exp:
tests/invalid/default_ho_inst.err_exp:
tests/invalid/functor_ho_inst_bad.err_exp:
tests/invalid/functor_ho_inst_bad_2.err_exp:
tests/invalid/functor_ho_inst_bad_3.err_exp:
tests/invalid/ho_any_inst.err_exp:
tests/invalid/ho_default_func_2.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
tests/invalid/ho_unique_error.err_exp:
tests/invalid/html.err_exp:
tests/invalid/inst_matches_final_bug.err_exp:
tests/invalid/invalid_integral_call_inst.err_exp:
tests/invalid/io_in_ite_cond.err_exp:
tests/invalid/merge_ground_any.err_exp:
tests/invalid/merge_inst_error.err_exp:
tests/invalid/mode_error_arg_number.err_exp:
tests/invalid/modes_erroneous.err_exp:
tests/invalid/mostly_uniq1.err_exp:
tests/invalid/mostly_uniq2.err_exp:
tests/invalid/multimode_dcg.err_exp:
tests/invalid/no_ho_inst.err_exp:
tests/invalid/partial_implied_mode.err_exp:
tests/invalid/polymorphic_unification.err_exp:
tests/invalid/qualified_cons_id2.err_exp:
tests/invalid/state_vars_test5.err_exp:
tests/invalid/unify_mode_error.err_exp:
tests/invalid/uniq_modes.err_exp:
tests/invalid/uniq_neg.err_exp:
tests/invalid_nodepend/constrained_poly_insts.err_exp:
tests/invalid_nodepend/occurs.err_exp:
tests/invalid_purity/impure_func_t5_fixed.err_exp:
tests/invalid_purity/purity.err_exp:
tests/warnings/simple_code.exp:
tests/warnings/unify_f_g.exp:
    Expect colors in these diagnostics.
2024-04-30 19:27:32 +10:00
Zoltan Somogyi
dc12878708 Shorten function symbols in error_specs.
compiler/error_spec.m:
    Replace simplest_spec with spec, and simplest_no_context_spec with
    no_ctxt_spec. These are now the most frequently used function symbols
    to create error specs, so their name should not make them out to be
    the exception.

    Replace simplest_msg with msg, and simplest_no_context_msg with
    no_ctxt_msg for the same reason.

    Abbreviate some of the long phase names.

compiler/*.m:
    Conform to the changes above. Most of these changes were done by a script,
    with minor manual tidying up, which consisted mostly of fitting code
    constructing error specs onto fewer lines than before.
2024-04-20 21:51:15 +10:00
Zoltan Somogyi
83dce9f612 Strip default function modes from diagnostics.
compiler/prog_mode.m:
compiler/prog_type.m:
    Add a new parameter to the operations that strip module qualifiers
    from types and modes, which can ask for the replacement of ho_inst_infos
    that explicit list

        all of a function's non-return args as being input,
        the function's return arg as being output, and
        the function being det

    which together specify the default for functions, with
    none_or_default_func. The point is to avoid printing unnecessary
    and potentially distracting detail in error messages.

compiler/prog_util.m:
    Add the maybe_set_default_func type, which controls the above behavior.
    Add it here because it is needed in the interface of both prog_mode.m
    and prog_type.m, and neither imports the other in the interface.

compiler/check_typeclass.m:
compiler/hlds_error_util.m:
compiler/make_hlds_error.m:
compiler/typecheck_error_type_assign.m:
compiler/typecheck_errors.m:
compiler/typecheck_msgs.m:
    Use the new capability to simplify error messages.

compiler/modes.m:
    Use the new capability to simplify messages from mode inference.

compiler/mode_errors.m:
    Do noT change the description of function declarations in error preambles.

compiler/typecheck_debug.m:
    Do not change the description of function declarations in messages
    intended to debug the typechecker itself.

compiler/parse_tree_out_inst.m:
    Do not change the description of function declarations in Mercury code
    we write to .int* and .*opt files.

tests/invalid/type_diff.err_exp:
    Expect the simpler form of these error messages.
2024-04-14 11:38:43 +10:00
Julien Fischer
4cd5c17f61 Fix more copyright notices ...
... and other minor fixes.

library/*.m:
library/LIB_FLAGS.in:
compiler/*.m:
mdbcomp/*.m:
    Fix and update copyright notices.

    Fix spelling.

    Delete trailing whitespace.
2024-02-20 17:18:52 +11:00
Zoltan Somogyi
a9c76976b4 Make indents unsigned.
compiler/indent.m:
    Make the indent type a synonym for uint.

compiler/*.m:
    Conform to the change above.
2023-11-22 07:46:14 +11:00
Zoltan Somogyi
bb5b24173c Add an explicit stream to the print_anything method.
compiler/error_spec.m:
    As above.

compiler/mode_errors.m:
    Get the stream from this extra arg.

compiler/write_error_spec.m:
    Supply the stream argument.
2023-09-13 10:19:52 +10:00
Zoltan Somogyi
a13a6d0f97 Carve hlds_proc_util.m out of hlds_pred.m.
compiler/hlds_pred.m:
compiler/hlds_proc_util.m:
    As above. hlds_proc_util.m now contains utility predicates
    that most modules that import hlds_pred.m don't need.
    (More than four times as many modules import hlds_pred.m
    as now import hlds_proc_util.m.)

compiler/*.m:
    Conform to the changes above.
2023-09-01 16:41:33 +10:00
Zoltan Somogyi
b2ba2dd917 Extend and fix the code for dumping insts.
The motivation for this diff is something I saw when I fixed the bug in
equiv_type_hlds.m on aug 13. During the bootcheck to verify the bug fix,
I enabled the end-of-front-end HLDS dump, and I saw that one module,
deep_profiler/display_report.m, had some references to MISSING_INSTs
in its HLDS dump. Since these could be signs of a bug in mode analysis,
I tracked them down. It turns out that the cause was an incompatibility
between the code that existed in error_msg_inst.m before that fix,
and the new code there added by that fix. But ironically, to find that
incompatibility, I first had to extend error_msg_inst.m's functionality
still further, specifically to make it possible to use it to write out insts
in HLDS dumps.

The reason for this need is that that the old code for dumping out insts
left a lot to be desired. It ignored (as in, it never wrote out) some parts
of specific kinds insts, such as the types in typed insts, without which
some parts of HLDS dumps did not make sense. For example, the ground inst
table in the HLDS dump of display_report.m contained several keys whose
printed versions were identical, seemingly indicating a bug in the code
that added new entries to that table (since it is supposed to add a new entry
to the table if the relevant key does not yet exist in the table). It turns
out that there was no bug; the keys differed, but only in the types.

compiler/error_msg_inst.m:
    Fix the incompatibility, and document both it, and its solution.

    Besides error_msg_inst, export a new function error_msg_inst_name,
    which does the same thing for inst_names as error_msg_inst does for insts.

    Add a flag to both functions that specifies whether the intended use
    of the return value is in an error message (whose audience is usually
    an ordinary Mercury user) or a HLDS dump (whose audience is always
    a Mercury developer). Include details such as the types in typed insts,
    and the structure of the compiler-generated inst names generally,
    which involve concepts that users do not know about, in the output
    only if the flag says the audience is Mercury developers.

    When printing out type or inst variables, use their actual names
    if these are available. To make this possible, require the callers
    of error_msg_{inst,inst_name} to provide tvarsets and inst_varsets,
    instead of always using empty varsets. The caller may still pass
    empty varsets if cannot do better than that, but most callers can,
    and now do pass valid varsets.

compiler/hlds_out_goal.m:
    Since we now want to pass a valid tvarset to error_msg_inst.m
    when printing the insts in goals' instmap_deltas, we need to pass around
    the tvarset, as well as the inst_varset, of the procedure that the goal
    was taken from. Instead of adding yet another parameter to all the affected
    predicates, replace all the existing parameters that have the same role
    (of which there were already about half a dozen) with a parameter
    of a new type named hlds_out_info_goal, which contains the values of
    all these old parameters, and the new one.

compiler/hlds_out_inst_table.m:
    Use the same setting to govern whether we use error_msg_inst.m's
    facilities for writing out insts and inst names in both the keys
    and the values of the various inst tables.

compiler/simplify_info.m:
    Include tvarsets in simplify_infos, since dumping out goals during
    simplification pass can now use this information.

compiler/add_clause.m:
compiler/add_mutable_aux_preds.m:
compiler/delay_partial_inst.m:
compiler/dep_par_conj.m:
compiler/direct_arg_in_out.m:
compiler/format_call.m:
compiler/goal_expr_to_goal.m:
compiler/hlds_out_pred.m:
compiler/inst_abstract_unify.m:
compiler/inst_lookup.m:
compiler/intermod.m:
compiler/lco.m:
compiler/liveness.m:
compiler/make_hlds_warn.m:
compiler/mode_errors.m:
compiler/pd_debug.m:
compiler/prog_mode.m:
compiler/push_goals_together.m:
compiler/saved_vars.m:
compiler/simplify_goal.m:
compiler/simplify_goal_conj.m:
compiler/simplify_proc.m:
compiler/stack_opt.m:
compiler/superhomogeneous.m:
compiler/unneeded_code.m:
    Conform to the changes above.
2023-08-31 16:25:31 +10:00
Zoltan Somogyi
75320f5d14 Update the error message for missing ho insts.
compiler/mode_errors.m:
    Improve the error message you get when you pass a higher order value
    without specifying its higher order inst, along the lines in the
    discussion on m-rev over the last week.

compiler/error_msg_inst.m:
    Make some variables more descriptive.

tests/invalid/no_ho_inst.err_exp:
    Update the expected error message.
2023-07-25 00:16:24 +02:00
Zoltan Somogyi
dde8c1f396 Delete mer_inst's free/1 functor.
This functor was intended to have the same semantics as free/0, while
containing the type of the value it was applied to. However, commit
87e7e3bafa, the commit in which Fergus
introduced this function symbol, also contained an "XXX temporary hack"
in which the code that was supposed to create a value using this function
symbol when propagating a type into a free/0 inst, just ignored the type,
and left the inst as free/0. THIS TEMPORARY HACK HAS REMAINED IN THE CODE
SINCE 1994.

In a few places, we did hand-create insts using free/1 for code created
by the compiler itself. However, as far as I can tell, no free/1 inst
ever described any code read in from source files. This meant that
any code in switch arms for free/1 in switches on insts was never tested
in any meaningful sense. And predicates such as inst_merge_4, which
processed several kinds of insts without doing a complete switch on insts,
simply lacked code handle free/1 at all.

This diff deletes the free/1 function symbol. It does so NOT because
the type stored as its argument is not useful, but because it is useful
NOT JUST for free insts, but for ALL insts. This means that any mechanism
for providing information about the type of the value that an inst applies to
should work for all insts. This can be done

- either by passing along the type with every inst, and stepping into
  the argument types of each argument of a function symbol as we process
  bound insts, in every operation that operates on insts that needs
  type information.

- or by including a type in ALL the function symbols of the inst type.
  (We could do this either by adding a maybe(mer_type) field to each
  function symbol, which would be "no" before the propagate-types-
  into-modes pass, or by adding just a mer_type field, which would
  be a special dummy value before that pass. I (zs) prefer the latter,
  and so would juliensf.)

The second option would involve reintroducing a free/1 function symbol
into the inst type, but this would replace the existing free/0
function symbol, and it would inherit all the code that currently
handles free/0, NOT the code being deleted by this diff for handling
the *current* free/1.

The first option would be easier to implement if only one or maybe two
operations needed type info, the second would be both easier to implement
and more efficient if more operations needed that info.

compiler/prog_data.m:
    Delete free/1.

compiler/add_mode.m:
compiler/add_mutable_aux_preds.m:
compiler/comp_unit_interface.m:
compiler/dep_par_conj.m:
compiler/direct_arg_in_out.m:
compiler/equiv_type_hlds.m:
compiler/error_msg_inst.m:
compiler/float_regs.m:
compiler/hlds_code_util.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_mode.m:
compiler/hlds_statistics.m:
compiler/inst_abstract_unify.m:
compiler/inst_check.m:
compiler/inst_match.m:
compiler/inst_merge.m:
compiler/inst_mode_type_prop.m:
compiler/inst_test.m:
compiler/inst_user.m:
compiler/inst_util.m:
compiler/mode_constraints.m:
compiler/mode_errors.m:
compiler/mode_top_functor.m:
compiler/modecheck_coerce.m:
compiler/modecheck_util.m:
compiler/modes.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_to_term.m:
compiler/pd_util.m:
compiler/prog_mode.m:
compiler/prog_rep.m:
compiler/recompilation.usage.m:
compiler/types_into_modes.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Conform to the change above.
2023-07-22 12:26:55 +02:00
Zoltan Somogyi
92941c4239 Delete mer_inst's abstract_inst functor.
We have never supported abstract insts, and we are not likely to start
using them any time soon, but we have had them in the representation of insts
since the beginning. Since they were never actually generated, the code
that operated on them was never really tested, which is good, because
in many places, that code simply threw an exception. The code that didn't
throw an exception when it found an abstract inst had to work correctly
for the abstract_insts that we actually generated, which were abstract
only in the sense that they were references to a would-be user-defined inst
name that wasn't actually defined.

There were two sources of such "abstract" insts.

- One was failed calls to inst_lookup that specified an user_inst inst_name.

- The other consisted of predicates whose job was to construct error messages
  involving insts. These either converted cons_ids into abstract insts,
  or mangled valid user_inst inst_names into invalid user_inst inst_names,
  because error_msg_inst.m generated good-looking messages when given
  the results of such conversions.

The first is handled by the fact that module qualification detects and
reports references to undefined insts and modes, and does not let the
compiler proceed to the compiler phases that may call inst_lookup.

The second is handled by the changes to error_msg_inst.m below.
These change to handle the use cases of the two error-message-constructing
predicates that used to employ abstract_insts, but now employ user_inst
defined_insts with a two particular kinds of undefined inst ctor,
one for each use case.

compiler/prog_data.m:
    Delete the abstract_int function symbol from the mer_inst type.

compiler/inst_lookup.m:
    When the lookup of an user_inst inst_name inside a defined_inst
    fails, don't convert that defined_inst into abstract inst,
    throw an exception.

compiler/error_msg_inst.m:
    Add code to deal with the insts that add_mutable_aux_preds.m and
    mode_errors.m generate for us to convert to lists of error message pieces.
    The addition is done twice, in an as identical a fashion as possible,
    when generating non-inline pieces and when generating inline pieces.

compiler/add_mutable_aux_preds.m:
compiler/mode_errors.m:
    Document how these modules cooperates with error_msg_inst.m.

compiler/add_mode.m:
compiler/comp_unit_interface.m:
compiler/direct_arg_in_out.m:
compiler/equiv_type_hlds.m:
compiler/float_regs.m:
compiler/hlds_code_util.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_mode.m:
compiler/hlds_statistics.m:
compiler/inst_abstract_unify.m:
compiler/inst_check.m:
compiler/inst_match.m:
compiler/inst_merge.m:
compiler/inst_mode_type_prop.m:
compiler/inst_test.m:
compiler/inst_user.m:
compiler/inst_util.m:
compiler/make_hlds_passes.m:
compiler/mode_top_functor.m:
compiler/modecheck_coerce.m:
compiler/modecheck_util.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_to_term.m:
compiler/pd_util.m:
compiler/prog_mode.m:
compiler/recompilation.usage.m:
compiler/types_into_modes.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Conform to the changes above, mostly by deleting code dealing with
    abstract_insts.

tests/invalid/functor_ho_inst_bad.err_exp:
tests/invalid/functor_ho_inst_bad_3.err_exp:
tests/invalid/partial_implied_mode.err_exp:
tests/invalid_nodepend/occurs.err_exp:
    Update these expected outputs, which each involve errors generated
    by the modified code in mode_errors.m or add_mutable_aux_preds.m.
    Some of these referred to some things as "named insts" when they were
    *not* named insts in the program.

tests/invalid_nodepend/kind.{m,err_exp}:
    Add some invalid code to this test, and update the expected output
    accordingly.
2023-07-21 21:03:40 +02:00
Zoltan Somogyi
fde993b523 Improve diagnostics for missing higher order insts.
compiler/mode_errors.m:
    Generate a significantly more detailed error message, including an example,
    when a higher order value is used in a call without having higher order
    inst information.

compiler/write_error_spec.m:
    Fix a bug I encountered with a draft of the diff to mode_errors.m:
    don't let the indent of a paragraph become negative.

compiler/indent.m:
    Fix an effective infinite loop when the indent function is asked
    to convert a negative indent to a string.

tests/invalid/no_ho_inst.{m,err_exp}:
    A test case derived from the code on mercury-users.

tests/invalid/Mmakefile:
    Enable the new test case.
2023-07-19 00:06:41 +02:00