Commit Graph

387 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
f41e76cfbe Use the agreed wording in foreign_proc diagnostics.
compiler/add_foreign_proc.m:
    Use the agreed wording *consistently* in the diagnostics
    generated by this module.

    Also, delete a call to the test for builtins that I recently
    accidentally duplicated instead of just moving.

tests/invalid/foreign_proc_dup_var.err_exp:
tests/invalid/foreign_purity_mismatch.err_exp:
tests/invalid/fp_dup_bug.err_exp:
tests/invalid/pragma_qual_error.err_exp:
tests/warnings/foreign_singleton.err_exp:
tests/warnings/singleton_test.err_exp:
tests/warnings/warn_return.err_exp:
tests/warnings/warn_succ_ind.err_exp:
    Expect the updated wording for all those diagnostics.
2026-01-30 20:27:30 +11:00
Zoltan Somogyi
2448461ae1 Warn about singletons for *all* foreign procs.
compiler/add_foreign_proc.m:
    The existing code for adding foreign_procs

    - tests whether the foreign_proc is for an imported predicate,
      and if so, stops with an error message,

    - then tests whether the foreign_proc is for the current backend,
      and if it is not, ignores the foreign_proc,

    - and then both adds the foreign proc to the HLDS, and checks it
      for singletons.

    Reverse the order of the last two tests, so that we now test
    foreign_procs for singletons *even if* they are not for the current
    backend. (Though of course we do not add such foreign_procs to the HLDS.)

library/io.environment.m:
library/private_builtin.m:
library/rtti_implementation.m:
    Fix the warnings for now result for non-C foreign_procs even during
    bootchecks in C grades.

tests/warnings/foreign_singleton.err_exp:
    Expect warnings for Java and C# foreign_procs as well as C foreign_procs.

tests/warnings/singleton_test.{m,err_exp}:
tests/warnings/warn_return.{m,err_exp}:
tests/warnings/warn_succ_ind.{m,err_exp}:
    Make these test cases more readable. Delete any obsolete parts,
    as well as the causes of warnings that these test cases are
    not intended to test for. (The latter makes the tests' *outputs*
    more readable.)

    Expect warnings for Java and C# foreign_procs as well as C foreign_procs,
    and expect them with the new line numbers.

tests/warnings/foreign_singleton.err_exp2:
tests/warnings/foreign_singleton.err_exp3:
tests/warnings/singleton_test.err_exp2:
tests/warnings/singleton_test.err_exp3:
tests/warnings/warn_return.err_exp2:
tests/warnings/warn_return.err_exp3:
tests/warnings/warn_succ_ind.err_exp2:
tests/warnings/warn_succ_ind.err_exp3:
    Delete these Java- and C#-specific expected outputs, since the warnings
    they test for are now in the corresponding .err_exp files.
2026-01-29 22:09:58 +11:00
Zoltan Somogyi
62d9fcbe4b Ignore (mostly) comments inside foreign_procs.
compiler/foreign.m:
    When returning the list of identifiers inside a foreign_proc's code,
    ignore the contents of comments. This means that warnings about
    variable names that occur in the foreign_proc's argument list
    but do not occur in the foreign_proc's code cannot be shut up anymore
    by mention the variable name in comments.

    The "mostly" part is that typecheck.m still looks at the bodies
    of foreign_procs without knowing about comments. Fixing that
    will be part a future change.

NEWS.md:
    Announce this breaking change.

compiler/fact_table_gen.m:
    When we try to generate a foreign_proc's body for a fact table
    but cannot do so due to the fact table file not being readable,
    add a marker to the predicate that the fact table is for.

compiler/hlds_markers.m:
    Update the documentation of the existing predicate marker
    we use for this.

compiler/make_hlds_warn.m:
    Do not warn about singleton variables in foreign_proc bodies
    that are empty due to missing fact table files.

library/array.m:
library/io.file.m:
library/profiling_builtin.m:
library/stm_builtin.m:
library/table_builtin.m:
library/term_size_prof_builtin.m:
tests/invalid/erroneous_throw_promise.m:
tests/invalid/foreign_procs_exist_type.m:
tests/invalid/foreign_purity_mismatch.m:
tests/invalid/gh72_errors.m:
tests/invalid_purity/purity.m:
tests/valid/solv.m:
    Shut up warnings about singletons in foreign_procs by adding a _ prefix
    to the names of the relevant arguments, and delete the comments
    that can no longer do that job.

tests/invalid/foreign_purity_mismatch.err_exp:
tests/invalid/gh72_errors.err_exp:
tests/invalid/gh72_errors.err_exp2:
tests/invalid/gh72_errors.err_exp3:
tests/invalid_purity/purity.err_exp:
    Expect updated line numbers.

tests/warnings/warn_return.{m,err_exp}:
    Extend this test case to test that

    - we DO warn about return statements outside comments, but
    - we DO NOT warn about return statements inside comments.
2026-01-28 13:34:30 +11:00
Julien Fischer
fd02945ecc Fix errors in usage message.
compiler/options.m:
    As above.

tests/warnings/help_text.err_exp:
    Conform to the above change.
2026-01-20 20:54:55 +11:00
Zoltan Somogyi
3f58eabe9f Delete the allow_multi_arm_switches internal option.
The compiler has had no code to set it from its default value of "yes"
to "no" since the Erlang backend was deleted in October 2020.

compiler/options.m:
    Delete the option.

compiler/handle_options.m:
    Delete an (incorrect) reference to the option.

compiler/switch_detection.m:
    Stop paying attention to the option.

tests/warnings/help_text.err_exp:
    Stop expecting documentation of the option.
2026-01-13 15:22:12 +11:00
Zoltan Somogyi
03b07d8675 Expect a 2026 copyright year. 2026-01-02 20:31:48 +11:00
Julien Fischer
707319b482 Fix another broken link.
Fix a copy-and-past error.

compiler/options.m:
    Update a link to a README file.

    s/Inferemce/Inference/ in a number of spots.

tests/warnings/help_text.err_exp:
    Conform to the above change.
2025-12-26 17:48:30 +11:00
Zoltan Somogyi
dd51db8762 Extend the help text for --options-file. 2025-12-16 13:37:39 +11:00
Zoltan Somogyi
2a1f376c5d Use spaces in all Mercury.options files.
Use consistent indentation.

Sort many blocks of module-specific MCFLAGS settings by module name.

Add XXXs about some questionable options.
2025-12-06 10:39:04 +11:00
Zoltan Somogyi
f2ac8bc60a Merge --warn-interface-imports into --warn-unused-interface-imports.
compiler/options.m:
    Merge the two options into one, which can be specified by either name.

compiler/module_qual.m:
    Update their documentation.

compiler/module_qual.qualify_items.m:
    Conform to the change above.

tests/warnings/help_text.err_exp:
    Expect the merged option's documentation.

NEWS.md:
    Announce the new option name.

RELEASE_NOTES_NEXT:
    Schedule the old option name for deletion.

extras/base64/Mercury.options:
extras/fixed/Mercury.options:
extras/graphics/mercury_allegro/Mercury.options:
extras/graphics/mercury_cairo/Mercury.options:
extras/graphics/mercury_glfw/Mercury.options:
extras/graphics/mercury_glut/Mercury.options:
extras/graphics/mercury_glut/Mmakefile:
extras/graphics/mercury_glut/Mmakefile.MacOSX:
extras/graphics/mercury_opengl/Mercury.options:
extras/graphics/mercury_opengl/Mmakefile:
extras/graphics/mercury_opengl/Mmakefile.MacOSX:
extras/odbc/Mercury.options:
extras/odbc/Mmakefile:
extras/references/Mercury.options:
extras/solver_types/library/Mercury.options:
extras/solver_types/library/Mmakefile:
extras/trail/Mercury.options:
tests/submodules/Mercury.options:
tests/warnings/Mercury.options:
    Replace all references to --warn-interface-imports with
    --warn-unused-interface-imports, the new preferred name.

    In several places, compiler options (both module-specific
    and otherwise) were specified in Mmakefiles. Move them
    to Mercury.options files. In some cases, this meant creating
    new Mercury.options files.
2025-11-29 02:23:32 +11:00
Zoltan Somogyi
c9e549996a Let switch detection handle deeper disjunctions.
compiler/switch_detection.m:
    The existing switch detection algorithm does a single forward
    traversal of the procedure body, doing only very limited lookahead.
    This prevents it from recognizing some switches. To fix this, add
    a new prepass that provides unlimited lookahead.

    Add one use of this lookahead information. Later diffs should add
    more uses.

compiler/print_help.m:
    Fix the code that served as motivation for this change.
    It was a block of unifications that was intended to supply
    the lookahead that the old algorithm needed but did not have,
    but it actually lied: it said that the the following disjunction
    covered cons_ids that it actually did not cover. The fact that
    the compiler did not diagnose this lie until now was a bug.
    (After this diff, the compiler now reports an error.)

deep_profiler/message.m:
    Avoid the limitation of the new algorithm that was discussed today
    on m-dev.

compiler/options.m:
    Add a way to test for the presence of this new capability
    in the installed compiler.

tests/warnings/help_text.err_exp:
    Expect the new option name.
2025-11-15 05:08:29 +11:00
Zoltan Somogyi
8e64bfc805 Add a "quoted-" prefix to several option names.
compiler/options.m:
    Add this prefix to the user-visible names of all the options
    that specify flags that the compiler will pass to shell commands
    *after quoting*. The internal names already had this prefix.

NEWS.md:
    Document the new names, and the eventual names of the old names.

tests/warnings/help_text.err_exp:
    Expect the new names as well as the old.
2025-11-05 03:58:05 +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
4e6a6357c4 Use standard but controllable "can't open file" messages.
compiler/file_util.m:
    Define standard routines for reporting that we couldn't open a file
    for either input or output. Rename the one other predicate in this file
    that the compiler used for that purpose, so that its call sites
    can be redirected to use one of the routines intended for this purpose.

    Give these routines the ability to standardize path names (by removing
    "./" prefixes from relative path names, and removing all directory names
    from adsolute path names) if a new option is given.

compiler/options.m:
    Add that (developer-only) option.

compiler/compile_target_code.m:
compiler/copy_util.m:
compiler/export.m:
compiler/llds_out_file.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_make_hlds.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/module_cmds.m:
compiler/opt_deps_spec.m:
compiler/output_imports_graph.m:
compiler/passes_aux.m:
compiler/system_cmds.m:
compiler/write_deps_file.m:
compiler/xml_documentation.m:
    Replace all call sites to the file_util.m predicates modified
    by this diff. In many cases, it replaces duplicate copies of the
    same code with a call. In some cases, redirect the error message
    to the progress stream, where it belongs.

tests/invalid/Mercury.options:
tests/invalid/foreign_include_file_missing.err_exp3:
    Compile the foreign_include_file_missing test case with the new option,
    and add the expected output in C# grades, which (thanks to the option)
    no longer includes the pathname of the test directory.

tests/invalid/foreign_include_file_missing.m:
    Record what the new .err_exp3 file is for.

tests/warnings/help_text.err_exp:
    Expect the new option.
2025-10-11 12:10:26 +11:00
Zoltan Somogyi
6542c52c91 Generate same final state var warnings for lambdas ...
.. as for final state vars in clause heads.

compiler/state_var.m:
    Do the above.

compiler/mode_util.m:
    Move a utility predicate here from pre_typecheck.m, since now
    state_var.m also needs it.

compiler/pre_typecheck.m:
    Delete the moved predicate, and update a reference.

compiler/superhomogeneous_lambda.m:
    Pass more info to state_var.m for its new job.

tests/warnings/unneeded_final_statevar.{m,err_exp}:
    Extend this test case to test final state var warnings not just
    in clause heads, but in the heads of lambda expressions as well.
    Also, document the test case better.
2025-10-08 19:55:29 +11:00
Zoltan Somogyi
bb0b12deba Add in_range as a builtin op.
It is almost the same as the unsigned_lt builtin op, but it is
implemented as "0 =< Index, Index < Range" just for Java.

This is the first step of the bootstrapping process; the second step
will add a declaration for private_builtin.in_range.

compiler/builtin_ops.m:
    As above.

compiler/llds_out_data.m:
compiler/mlds_to_c_data.m:
compiler/mlds_to_cs_data.m:
compiler/mlds_to_java_data.m:
    Implement the new operation.

compiler/code_util.m:
compiler/llds.m:
compiler/ml_global_data.m:
compiler/mlds_dump.m:
compiler/opt_debug.m:
    Conform to the change above.

compiler/options.m:
    Add a way to test whether the installed compiler supports this new op.

tests/warnings/help_text.err_exp:
    Expect the new option name.
2025-10-01 15:24:55 +10:00
Zoltan Somogyi
847f30b227 Fix more test case failures.
compiler/direct_arg_in_out.m:
    Add color to some overlooked diagnostics.

tests/invalid/gh72_errors.err_exp:
tests/invalid/gh72_errors.err_exp3:
    Update these expected outputs for the change above, and for some
    earlier changes.

tests/invalid/try_detism.err_exp2:
tests/warnings/warn_succ_ind.err_exp2:
    Update these expected outputs for some earlier changes.
2025-09-15 15:44:54 +10:00
Zoltan Somogyi
c53f9ab46e Don't output lines that end with a space.
compiler/write_error_spec.m:
    When error_specs include blank lines, we used to output lines
    of the form "filename:linenumber: ". Stop generating the final space.

compiler/parse_tree_out_misc.m:
    Add a new version of an existing function.

tests/invalid/actual_more_expected.err_exp:
tests/invalid/ambiguous_overloading_error.err_exp:
tests/invalid/any_passed_as_ground.err_exp:
tests/invalid/anys_in_negated_contexts.err_exp:
tests/invalid/bad_ambiguity_msg.err_exp:
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/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/magicbox.err_exp:
tests/invalid/max_error_line_width.err_exp:
tests/invalid/mode_inf.err_exp:
tests/invalid/modes_erroneous.err_exp:
tests/invalid/no_ho_inst.err_exp:
tests/invalid/not_a_switch.err_exp:
tests/invalid/state_vars_test_1.err_exp:
tests/invalid/try_detism.err_exp:
tests/invalid/user_field_access_decl_override_1.err_exp:
tests/invalid_nodepend/errors_2.err_exp:
tests/warnings/ambiguous_overloading.err_exp:
tests/warnings/inconsistent_pred_order.err_exp:
tests/warnings/subtype_order.err_exp:
tests/warnings/test_tscp.err_exp:
    Stop expecting a final space.
2025-09-15 06:28:07 +10:00
Zoltan Somogyi
369fda6826 Fix the warnings/test_tscp test case ...
... which tests the compiler's output with the
--inform-generated-type-spec-pragmas option.

The reason why it failed in C# and Java grades was that before
this diff, the compiler printed the messages that this option calls for
to a different stream (ProgressStream) than the stream (ErrorStream)
whose output we capture in the .err file we compare with the .err_exp file.

compiler/add_pragma_type_spec.m:
    Fix this. Not by writing the same output to ErrorStream,
    but by returning the requested info in error_specs, which will
    later be printed to ErrorStream. This allows us to attach the
    context to the message in the standard way, and allows this output
    to fit in with any other diagnostics we generate for that module.

    Delete the no-longer-needed arguments from the affected. predicates.

compiler/add_pragma.m:
compiler/make_hlds_passes.m:
    Conform to the changes above.

compiler/globals.m:
    Stop module-specific streams from being closed more than once.
    This bugfix is unrelated to the change to add_pragma_type_spec.m above,
    but I found the bug while investigating this issue, and there is
    no point in leaving this bug unfixed.

compiler/parse_tree_out_pragma.m:
    Add a utility function for use by the new code in add_pragma_type_spec.m.

tests/warnings/test_tscp.err_exp:
    Expect the updated output.
2025-09-15 05:37:16 +10:00
Zoltan Somogyi
99c379d651 Fix some more tests/invalid failures.
tests/invalid/illtyped_compare.err_exp2:
    Add an expected output for target languages for which
    unification pretests cast the input arguments to c_pointers,
    not ints.

tests/invalid/pragma_c_code_dup_var.err_exp3:
tests/invalid/pragma_c_code_no_det.err_exp3:
tests/invalid/test_may_duplicate.err_exp3:
tests/invalid/test_may_export_body.err_exp3:
tests/invalid/try_detism.err_exp2:
tests/warnings/foreign_singleton.err_exp3:
    Update these expected output files to expect color in diagnostics,
    and (in some cases) updated wording as well.

tests/invalid_make_int/unbalanced.{m,int_err_exp}:
    Move the tests/invalid_nodepend/unbalanced test case here,
    since the diagnostics we are testing are reported when making
    interface files.

tests/invalid_make_int/Mmakefile:
tests/invalid_nodepend/Mmakefile:
    Conform to the move.

tests/warnings/Mmakefile:
    Disable the unused_args_analysis test case in non-C grades,
    because the test setup works only for C.
2025-09-14 14:28:42 +10:00
Zoltan Somogyi
e8eadc61bd Fix some causes of test case failures in java grade.
tests/warnings/foreign_singleton.err_exp2:
tests/warnings/singleton_test.err_exp2:
tests/warnings/singleton_test.err_exp3:
    Update expected outputs for recent changes.

tests/warnings/table_with_inline.m:
    Document the new .err_exp3 file.

tests/warnings/table_with_inline.err_exp3:
    Add this expected output for non-C grades.

tests/warnings/table_with_inline.err_exp:
tests/warnings/table_with_inline.err_exp2:
    Update line numbers.
2025-09-13 14:06:18 +10:00
Zoltan Somogyi
c690fac030 Rename tests that duplicate library module names.
These interfere with tests in this directory with mmc --make.
2025-09-03 18:28:54 +02:00
Peter Wang
93683479cc Fix typo in help text. 2025-09-01 11:25:45 +10:00
Zoltan Somogyi
108e221cfb Rename --generate-module-order to --also-output-module-order,
... and change the extensions of the files to which it writes its output, from
.order and order_trans_opt to .module_order and .module_order_for_trans_opt.

compiler/options.m:
    Change the name of the option from --generate-module-order
    to --also-output-module-order, while keeping the old external name
    as well for now. Update its documentation accordingly.

    Document the private option --trans-opt-deps-spec more extensively.

compiler/file_names.m:
    Change the extension strings we use for those two files.

NEWS.md:
    Announce the change in the option name and in the *public* file extension.

compiler/opt_deps_spec.m:
    Refer to the option by its new internal name.

tests/warnings/help_text.err_exp:
    Expect the updated option names and help text.
2025-08-29 17:16:43 +02:00
Julien Fischer
b7685aae5f Disable concurrency in non .par LLDS grades.
The non .par LLDS grades currently "support" concurrency. However, this support
is really only usable with a small few benchmark programs, due to the inability
of the implementation to switch threads if the executing thread blocks. Disable
this capability by causing spawn/3 to abort if used in non .par LLDS grades.

library/thread.m:
    Make the above change to spawn/3.

compiler/globals.m:
    Update the code that checks if the current grade supports concurrency.

compiler/options.m:
    Adjust documentation for the --parallel option.

tests/warnings/help_text.err_exp:
    Conform to the above change.
2025-08-21 22:08:48 +10: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
a0769526e6 Rename three options from inform_X to warn_X.
compiler/options.m:
    Rename the internal names of these three options. Keep the old
    external names, but make the main external name the new name.

NEWS.mdb:
    Announce the renames.

compiler/check_options.m:
compiler/det_check_proc.m:
compiler/det_check_switch.m:
compiler/simplify_goal_ite.m:
    Conform to the change above. Change the severity of the messages
    controlled by the changed options severity_warning.

tests/warnings/help_text.err_exp:
    Expect the updated help text.
2025-08-18 13:13:10 +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
32006a1c7c Rename and generalize .c_debug to .target_debug.
runtime/mercury_grade.h:
    Rename the grade modifier, and the C macro that represents it.

compiler/options.m:
    Rename the --c-debug-grade option to --target-debug-grade.

compiler/compute_grade.m:
    Rename the grade modifier, and the option that represents it.

    Restrict the .target_debut grade modifier to MLDS grades.

compiler/handle_options.m:
    Implement --target-debug-grade by having it imply --target-debug.

compiler/compile_target_code.m:
compiler/link_target_code.m:
    Pay attention to either --target-debug-grade (for purposes related
    to the grade itself) and to --target-debug (for all other purposes).

scripts/canonical_grade.in:
scripts/canonical_grade.sh-subr:
scripts/final_grade_options.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
    Parse target_debug grade modifiers and --target-debug-grade options
    instead of c_debug grade modifiers and --c-debug-grade options.

    Add (normally commented-out) infrastructure to make it easier
    to debug changes.

    Restrict the .target_debut grade modifier to MLDS grades.

scripts/mgnuc.in:
scripts/mgnuc_file_opts.sh-subr:
    Rename some variables to clarify the distinction between the
    --target-debug option (which, like -g, enabled debugging of only one file)
    and the --target-debug-grade option (which enables it for the whole
    program).

configure.ac:
    Make it easier to debug grade-related changes by recording
    both autoconfigured and user-supplied grades that the rejected by
    the canonical_grade script.

    Conform to the changes above.

README.sanitizers:
doc/user_guide.texi:
grade_lib/grade_spec.m:
grade_lib/grade_string.m:
scripts/ml.in:
tests/warnings/help_text.err_exp:
tools/lmc.in:
tools/test_mercury:
    Conform to the changes above.

scripts/Mmake.vars.in:
    Add some XXXs about style.
2025-08-09 21:48:23 +02:00
Zoltan Somogyi
7e8ab98f21 Add a new option, --warn-include-and-non-include.
When enabled, the compiler emits a warning for modules that contain
both include_module declarations, and other constructs. In other words,
it warns about modules that include submodules but are not "packages".

compiler/make_hlds_passes.m:
    Implement the new option.

compiler/options.m:
    Add the new option.

NEWS.md:
    Announce the new option.

compiler/option_categories.m:
    Add a new subcategory for the new option.

compiler/print_help.m:
    Print the new option in the new category.

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

browser/Mercury.options:
compiler/Mercury.options:
library/Mercury.options:
mdbcomp/Mercury.options:
    Add commented-out-for-now lines that disable the new option
    for modules that include submodules but are intentionally
    not packages. The three reasons for the latter are

    - that the only thing in the module other than include_module
      declarations is a predicate to print a version id, so a package
      wouldn't improve things (browser, mdb, library/library.m),

    - that changing the module into a package is not worthwhile
      because the module is obsolete (compiler), and

    - that changing the module into a package would cause significant
      disruption for our users (the other modules in the library).
2025-07-27 00:42:17 +02:00
Zoltan Somogyi
c616206f7a Update after recent change. 2025-07-23 14:40:02 +02:00
Zoltan Somogyi
3540f7431b Improve --warn-too-private-instances.
This implements some improvements to its idea from 2022 mar 19 on m-rev.

compiler/check_typeclass.m:
    Consider an instance justifiably kept private if a constraint
    on the instance refers to a private type class or type constructor.

    Extend the test for what is considered "private" to also include
    classes and type constructs that are defined in private submodules
    of the current module.

    Extend the text of the warning to explain the reasoning behind it.

compiler/options.m:
    Extend the documentation of the option to explain the reasoning
    behind it.

tests/invalid/impure_method_impl.err_exp:
tests/invalid/inconsistent_instances.err_exp:
tests/invalid/method_impl.err_exp:
tests/invalid/mpj_3.err_exp:
tests/invalid/mpj_4.err_exp:
tests/invalid/range_restrict.err_exp:
tests/warnings/unused_interface_import.err_exp:
    Expect the new text for the warning.

tests/warnings/help_text.err_exp:
    Expect the new help text.
2025-07-22 14:57:42 +02:00
Zoltan Somogyi
87f443a070 Add a reference to another memprof UG section. 2025-07-19 13:39:32 +02:00
Zoltan Somogyi
01697602da Add --warn-too-private-instances.
This implements an idea from 2022 mar 8 on m-rev.

compiler/options.m:
    Add this option.

compiler/check_typeclass.m:
    Generate a warning that is conditional on this option if an instance
    is local to the module even if both

    - the class the instance is for, and
    - all the type_ctors that occur in the instance's arg type vector

    are visible outside the module.

    Add an XXX about the status we record for instances.

NEWS.md:
    Announce the new option.

tests/invalid/Mercury.options:
tests/warnings/Mercury.options:
    Explicitly enable the new warning for some of the affected tests, and
    explicitly disable it for others.

tests/invalid/impure_method_impl.err_exp:
tests/invalid/inconsistent_instances.err_exp:
tests/invalid/method_impl.err_exp:
tests/invalid/mpj_3.err_exp:
tests/invalid/mpj_4.err_exp:
tests/invalid/range_restrict.err_exp:
tests/warnings/help_text.err_exp:
tests/warnings/unused_interface_import.err_exp:
    For the tests for which the new warning is enabled, expect that warning.
2025-07-18 08:45:06 +02:00
Zoltan Somogyi
dc73319765 Merge oc_verb_dev and oc_verb_dbg ...
compiler/option_categories.m:
compiler/print_help.m:
compiler/options.m:
    ... name the result oc_dev_verb, and move it to the developer section.

    Also, make --implicit-parallelism and --feedback-file private.
    They are still for developers only.

doc/user_guide.texi:
tests/warnings/help_text.err_exp:
    Expect the updated help text.
2025-07-12 17:11:55 +02:00
Zoltan Somogyi
7fb78a9ea8 Add an intermodule optimization section to help text.
compiler/print_help.m:
compiler/option_categories.m:
    Add an intermodule optimization category with three subcategories:
    non-transitive intermodule optimization, transitive intermodule
    optimization, and the not-yet-public latex-model system.

compiler/options.m:
    Reclassify and reorder options accordingly.

doc/user_guide.texi:
tests/warnings/help_text.err_exp:
    Expect the new categorization.
2025-07-12 16:07:01 +02:00
Zoltan Somogyi
f71f453c6a Split oc_analysis into three subsections.
compiler/option_categories.m:
compiler/print_help.m:
compiler/options.m:
    As above.

doc/user_guide.texi:
tests/warnings/help_text.err_exp:
    Expect the subsections.
2025-07-12 00:07:43 +02:00
Zoltan Somogyi
7f1780a035 Update the expected help text for recent changes. 2025-07-10 09:49:14 +02:00
Zoltan Somogyi
111e2c6277 Add a third level to help text and the invocation chapter.
compiler/option_categories.m:
    Split up some option sub-categories into sub-sub-categories.

compiler/options.m:
    Distribute the options that were part of the split-up sub-categories
    into the sub-sub-categories.

compiler/print_help.m:
    Generalize the existing code, which could handle one- or two-level
    sections, to support arbitrarily deep nesting, though we use
    only sections, subsections and subsubsections, both for now and
    for the foreseeable future.

tests/warnings/help_text.err_exp:
    Expect the updated help text.
2025-07-09 01:47:27 +02:00
Zoltan Somogyi
71f35a08a3 Add --warn-all-format-string-errors ...
... to replace --no-warn-only-one-format-string-error.

compiler/options.m:
    As above.

    Add a synonym for an existing option.

    Make two more options private.

NEWS.md:
    Announce the change.

    Move the announcement of a non-breaking change to its proper place.

compiler/format_call_errors.m:
tests/warnings/help_text.err_exp:
    Conform to the changes above.
2025-07-08 14:25:28 +02:00
Zoltan Somogyi
89523c5061 Mark many options as private.
compiler/options.m:
    Mark as private options that are any of

    - experimental, such as structure reuse,

    - unmaintained and probably suffering from bitrot,
      such as threadscope, or

    - useful *only* to Mercury system maintainers.

    Make some other improvements as well.

tests/warnings/help_text.err_exp:
    Expect the extra PRIVATE_OPTION markers, and the improvements.
2025-07-08 11:12:23 +02:00
Zoltan Somogyi
0891ff754f Include modules named in supertypes in .int2 files.
This fixes a bug that prevented the compilation of another change
to the compiler I am working on. The commit of that change will ve
the test case for this fix.

compiler/comp_unit_interface.m:
    When computing which modules need to be imported in .int2 files,
    include modules named by the supertype of an exported subtype.

compiler/notes/interface_files.html:
    Fix some documentation errors I found while researching the bug.

compiler/options.m:
    Make it possible to test for the presence of this fix in the
    installed compiler.

tests/warnings/help_text.err_exp:
    Expect the new synonym for compiler_sufficiently_recent.
2025-07-07 19:29:55 +02:00
Zoltan Somogyi
51b1304b0d Record the initial values of the bool_special options ...
... which are managed by tools/make_optimization_options.

tools/make_optimization_options_middle:
    When creating compiler/optimization_options.m, put into it
    a new predicate that records, for each bool_special option
    managed by this module, its initial value.

compiler/print_help.m:
    Handle bool_special options whose initial value this new predicate
    makes known the same way we now handle plain bool options.
    The difference this makes is that bool_special options that
    default to "yes" will now have their --no-xyz form listed as
    the user-visible form of the option, not their --xyz form.

tools/make_optimization_options_db:
tools/make_optimization_options_end:
    Fix a discrepancy that made documenting the smart indexing
    unnecessarily complicated. The first such option defaulted to "no",
    but was switched to "yes" at -O0, while the others all defaulted
    to "yes". Allow these options to be documented in the same manner
    by making them *all* default to "no", and switch them all on at -O0.

compiler/optimization_options.m:
    Rebuilt with the updated make_optimization_options.

compiler/options.m:
    Many of the bool_special options that default to "yes" had
    help text that already assumed that this text followed
    the option name being printed as --no-xyz.

    For the others, which assumed that they followed --xyz,
    change the help text to be appropriate when following
    the --no-xyz form.

tests/warnings/help_text.err_exp:
    Expect the updated help texts.

doc/user_guide.texi:
    Expect the updated help texts, from this and earlier commits.

tests/warnings/help_opt_level.err_exp:
    Expect the added level-enabled options.
2025-07-07 13:19:35 +02:00
Zoltan Somogyi
96e1ed99e1 Give many optimization options backend-specific names ...
... and delete their second name.

compiler/options.m:
    The internal names of many optimization options have traditionally
    given no clue about which backend(s) they apply to, which made it
    hard to document them. Change this by including either llds or mlds
    in the names of these options, unless the rest of the name already
    ruled out one or the other backend.

    In one case, this exercise relevaled that an option that was classified
    as MLDS-only is used by the LLDS backend as well. Reclassify this option.

    Also, rename many options to the names they have in the opt_tuple.
    Those names are more recent, and their naming is more consistent
    (e.g. they are all verb phrases).

tools/make_optimization_options_db:
    Delete the different-from-the-opt-tuple name alternatives.

tools/make_optimization_options_end:
    Conform to the option renames.

    Also, fix a bug. The list of options enabled at each optimization
    level lists each option twice, once by its name in the opt_tuple
    (which is what we use to actually implement optimization levels)
    and once by its name in options.m (which we use to implement
    the option that prints out the optimization levels). In one case,
    the two names did not match; fix this.

compiler/optimization_options.m:
    Rebuild this module with tools/make_optimization_options.

compiler/add_trail_ops.m:
compiler/global_data.m:
compiler/handle_options.m:
compiler/ite_gen.m:
compiler/jumpopt.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/ml_optimize.m:
compiler/optimize.m:
compiler/options.m:
compiler/proc_gen.m:
compiler/stack_layout.m:
    Conform to the option renames.

tests/warnings/help_opt_levels.err_exp:
    Expect the fix to make_optimization_options_end.

tests/warnings/help_text.err_exp:
    Expect the option reclassification.
2025-07-07 05:00:37 +02:00
Julien Fischer
33bfb7364d Minor fixes for spelling etc.
compiler/optdb_help.m:
compiler/options.m:
     As above.

tests/warnings/help_text.err_exp:
    Conform to the above change.
2025-07-07 11:50:30 +10:00
Zoltan Somogyi
cc37cbd2b2 Make automatic texinfo documentation of options work.
Include the now-automatically-generated texinfo as the body
of the Invocation chapter of the user's guide. The resulting
guide is still not final, but it already fixes the previous absence
of several options' documentation from the invocation chapter.

compiler/optdb_help.m:
    Provide ways to give different aligned texts to print_help.m
    when it generates plain help text than when generating texinfo.
    We need this because we want to add markup to the texinfo version.

    Provide ways to add index entries to help texts. This is needed
    only when creating texinfo output.

    Add some more kinds of help_pieces, which provide previously
    unavailable combination of what we generate for help text vs
    what we generate for texinfo.

    Either delete obsolete documentation, or replace it
    with current documentation.

compiler/print_help.m:
    Redo the handling of index entries, mainly driven by the need
    to handle both default-on and default-off boolean options
    appropriately.

    Do not generate subsection headings for fully-commented-out subsections.

    Sort the output by option, not first on option category
    and then on option.

compiler/options.m:
    Check that the texinfo we now generate from optdb records
    with --help-texinfo is at least as informative as the entry
    for the relevant option in the old invocation chapter.
    Fix cases where it wasn't.

    Add index entries as they occurred in the old invocation chapter,
    except where I think they are either inappropriate or just not needed
    (usually due to the same index entry on the previous option).

    Add cross references that existed in the old invocation chapter.

    Improve a whole bunch of help texts where I felt the need
    during all the above changes.

    In some cases, just add XXXs calling for future changes.

    In one case, add a non-abbreviated version of an option's old,
    abbreviated-only "long" name.

    Pick "directory", "filename" and "N" as the respective standard
    argument names in their domains.

    Put some options into a new order for greater readability.

doc/Mmakefile:
doc/update_opts:
    For simpliciy and easier control over quotations and errors,
    move all the work of including the output of mmc --help-texinfo
    as the invocation chapter in the user's guide from the Mmakefile
    to the update_opts script.

doc/user_guide.texi:
    Replace the invocation chapter.

    Update all dangling references to that chapter to point to
    the new section or subsection that they want to refer to.

    Add a now-ignored block that can later become a chapter on grades.

tests/warnings/help_text.err_exp:
tests/warnings/help_opt_levels.err_exp:
    Conform to the changes above.
2025-07-06 19:18:29 +02:00
Zoltan Somogyi
874cf2598c Make the documentation of smart recompilation private.
compiler/options.m:
doc/user_guide.texi:
    As above.

tests/warnings/help_text.err_exp:
    Expect the updated help text.

compiler/print_help.m:
    Fix typo.
2025-07-05 16:31:20 +02:00
Zoltan Somogyi
812d71063a Fix a reversed sanity check.
compiler/pre_typecheck.m:
    As above.

tests/warnings/bug576.{m,err_exp}:
    Add the Mantis test case for this bug.

tests/warnings/Mmakefile:
    Enable the new test case.
2025-07-05 11:45:24 +02:00
Zoltan Somogyi
2ef8b3d13f Implement (mostly) mmc --help-texinfo.
compiler/print_help.m:
    Implement mmc --help-texinfo for real by generating near-final texinfo
    output when asked to.

    Move some utility operations to the end of the file.

doc/update_opts:
    A script to replace the bulk of the invocation chapter of the
    User's Guide with the output of mmc --help-texinfo.

doc/Mmakefile:
    Add a new target, intended to be invoked manually, to both
    invoke update_opts, and to show the user its effect.

compiler/options.m:
    Fix a link and some texinfo format bugs.

tests/warnings/help_text.err_exp:
    Expect the fixed link.
2025-07-03 20:25:59 +02:00