Commit Graph

12 Commits

Author SHA1 Message Date
Zoltan Somogyi
bdd2a574a8 Replace conditional_specs with a new severity.
compiler/error_spec.m:
    Delete conditional_spec from the error_spec type, which had
    exactly one use left in the compiler. Replace it with a conditional form
    of severity_error, which handles that use case.

    Rename error_severity to spec_severity, since obviously not all severities
    represent errors.

    For the same reason, rename error_phase to spec_phase.

compiler/error_util.m:
    Export a predicate for write_error_spec.m.

compiler/write_error_spec.m:
    Use that export to delete what used to be duplicate code.

compiler/add_pragma.m:
compiler/check_typeclass.m:
compiler/compiler_util.m:
compiler/error_sort.m:
compiler/mark_tail_calls.m:
compiler/parse_error.m:
compiler/parse_item.m:
    Conform to the changes above.
2025-11-15 10:29:23 +11: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
Julien Fischer
bad6ce0733 Update and fix more copyright notices.
compiler/*.m:
    As above.
2024-12-14 23:55:01 +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
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
7bb3358c44 Group related error_msgs together.
compiler/det_report.m:
    When det_infer_goal reports that a disjunction can have more than one
    solution, it generates two or more error_msgs: one stating the above fact,
    and one for each later disjunct that can succeed.

    The lists of error_msgs det_infer_goal returns are sorted by its callers.
    This sorting can put unrelated error messages between the error_msgs
    describing the determinism problem with the disjunction.

    Fix this problem by making det_infer_goal return error_msg *groups*,
    so that we can then sort the *groups* while keeping the order of the
    messages within each group.

compiler/error_sort.m:
    Add a type to represent error_msg groups, and code to sort error_msg
    groups, and to flatten lists of error_msg groups.

compiler/det_analysis.m:
    Conform to the change in det_report.m.

tests/invalid/bug496.err_exp:
tests/invalid/not_a_switch.err_exp:
    Expect updated diagnostics.
2024-05-31 01:25:23 +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
68c3d4040b Let callers of write_*interface_file* print errors.
compiler/write_module_interface_files.m:
    When the process of generating the contents of an interface file
    finds some errors, don't print those errors immediately. Just return
    them instead, letting the caller decide what to do with them.

    Fix comment rot.

compiler/make.get_module_dep_info.m:
compiler/mercury_compile_main.m:
    Print the error specs returned by the updated predicates (for now,
    at least).

compiler/error_sort.m:
    Fix an issue exposed by the changes above. When comparing two error_specs
    to see which one should be printed first, don't take the lack of a content
    in an error_spec as a sign that it should be printed first. Instead,
    pay attention to the comparison of contexts *only* if both of the
    error_specs being compared actually *have* contexts.

tests/invalid/type_inf_loop.err_exp:
    Expect the contextless message about exceeding the type inference
    iteration limit to come after the other messages, due to the update
    to error_sort.m.

tests/invalid/type_inf_loop.err_exp2:
    Delete this file. It can't match the compiler's current output,
    or (it seems) the output of any compiler version since we switched
    to reporting type errors using error_specs.
2023-10-08 10:11:08 +11:00
Zoltan Somogyi
51280ed660 Simplify more calls to handle_given_options.
compiler/mercury_compile_main.m:
    The handle_given_options predicate, besides computing the direct effect
    of a given list of command line arguments on the option table, also

    - looks for and reports inconsistencies between option values,

    - applies implications between options, and

    - constructs the global structure.

    The code in the initial part of mercury_compile_main.m has long had
    calls to handle_given_options that did not really need any of this work
    to be done. The calls were nevertheless there because the later code,
    even though it needed unly the updated option table, could only
    *use* that updated option table if it was part of a globals structure.

    This diff makes a start on fixing that. It replaces two calls
    to handle_given_options with calls to getopt.process_options_userdata_io,
    which just returns the updated option table. It updates the code following
    those two calls to use the updated option table directly, NOT through
    a globals structure. The rest of this diff is there to make this possible.

compiler/check_libgrades.m:
    Make maybe_detect_stdlib_grades take an option_table, not a globals
    structure.

compiler/write_error_spec.m:
    Provide a version of write_error_specs that takes an option_table,
    not a globals structure.

    The changes in the following modules are there to implement this change.

compiler/compiler_util.m:
    Provide a version of record_warning that takes an option_table,
    not a globals structure.

compiler/error_sort.m:
    Provide a version of sort_error_specs that takes an option_table,
    not a globals structure.

compiler/error_spec.m:
    Provide a version of extract_spec_msgs that takes an option_table,
    not a globals structure.

compiler/error_util.m:
    Do the same for several functions dealing with severities.
2023-07-12 03:02:59 +02:00
Zoltan Somogyi
0337cee2df Add the new option --reverse-error-order.
compiler/options.m:
doc/user_guide.texi:
    As above.

NEWS:
    Announce the new option.

compiler/error_sort.m:
    Implement the new option.
2022-11-01 17:41:45 +11:00
Zoltan Somogyi
307b1dc148 Split up error_util.m into five modules.
compiler/error_spec.m:
    This new module contains the part of the old error_util.m that defines
    the error_spec type, and some functions that can help construct pieces
    of error_specs. Most modules of the compiler that deal with errors
    will need to import only this part of the old error_util.m.

    This change also renames the format_component type to format_piece,
    which matches our long-standing naming convention for variables containing
    (lists of) values of this type.

compiler/write_error_spec.m:
    This new module contains the part of the old error_util.m that
    writes out error specs, and converts them to strings.

    This diff marks as obsolete the versions of predicates that
    write out error specs to the current output stream, without
    *explicitly* specifying the intended stream.

compiler/error_sort.m:
    This new module contains the part of the old error_util.m that
    sorts lists of error specs and error msgs.

compiler/error_type_util.m:
    This new module contains the part of the old error_util.m that
    convert types to format_pieces that generate readable output.

compiler/parse_tree.m:
compiler/notes/compiler_design.html:
    Include and document the new modules.

compiler/error_util.m:
    The code remaining in the original error_util.m consists of
    general utility predicates and functions that don't fit into
    any of the modules above.

    Delete an unneeded pair of I/O states from the argument list
    of a predicate.

compiler/file_util.m:
    Move the unable_to_open_file predicate here from error_util.m,
    since it belongs here. Mark another predicate that writes
    to the current output stream as obsolete.

compiler/hlds_error_util.m:
    Mark two predicates that wrote out error_spec to the current output
    stream as obsolete, and add versions that take an explicit output stream.

compiler/Mercury.options:
    Compile the modules that call the newly obsoleted predicates
    with --no-warn-obsolete, for the time being.

compiler/*.m:
    Conform to the changes above, mostly by updating import_module
    declarations, and renaming format_component to format_piece.
2022-10-12 20:50:16 +11:00