11201 Commits

Author SHA1 Message Date
Julien Fischer
e4e1f09507 Fix minor errors.
compiler/mlds.m:
    Fix the prefix of a field name.

    Fix errors in comments.
2026-04-11 00:46:57 +10:00
Zoltan Somogyi
d451d8aca5 Simplify the error_spec type.
compiler/error_spec.m:
    Delete the function symbol of the error_msg_component type
    that allowed the inclusion of help text *if* an option had a given value.
    This functionality has been unused since we made all warning and
    informational error_specs conditional on an option.

    Delete the subtype whose only job was to rule out the now-deleted
    function symbol.

    Add a comment about a possible solution of a have-your-cake-AND-eat-it
    problem.

compiler/error_sort.m:
compiler/error_util.m:
compiler/write_error_spec.m:
    Conform to the change in error_spec.m.
2026-04-06 10:35:59 +10:00
Zoltan Somogyi
04d1406c99 Replace error flags with the list of errors themselves.
This is another move towards making it impossible for the compiler
to stop due to the presence of an error *without* printing a diagnostic
about that error.

compiler/grab_modules.m:
    Some of the errors that this module are intended to block the compiler
    from continuing on to semantic analysis, and some are not. We used
    to make the distinction by returning a flag saying "some of these
    are blocking errors", but the list of diagnostics that contained
    these blocking errors

    - contained a list of error_specs reporting *both* kinds of errors, and
    - was not returned alongside the flag, but instead hidden inside
      the module baggage, making it hard to find, and easy to ignore.

    Change this to computing two lists of error_specs: one for blocking errors,
    and one for nonblocking ones. Return the former explicitly, keeping the
    latter in the baggage. This design lets the code that stops execution
    before semantic analysis to test for the list of blocking errors
    being non-empty, which makes printing them the easy thing to do.

    Delete the code that, with --very-verbose, wrote out any error_specs
    we generated during the processing of a .opt or .trans_opt file
    immediately after that processing. The reason is that

    - if we print those error_specs out and then do not return them
      to mercury_compile_make_hlds.m, then mercury_compile_make_hlds.m
      will be making decisions on incomplete and therefore incorrect data,
      while

    - if we print those error_specs out and *also* return them, then

      - either those diagnostics will be printed twice, or
      - we need to implement a new system whereby write_error_spec.m
        keeps a database of the diagnostics it has already printed,
        and simply skips printing any repeats.

    Neither of those alternative is palatable, and since in several
    decades, I have never needed such immediate printing of diagnostics,
    losing that capability is not really an issue.

    Fix some relics of the era when the data structures that were
    module_baggage's predecessors could not distinguish between fatal
    and nonfatal errors.

compiler/mercury_compile_make_hlds.m:
    For now, make the new code in grab_modules.m work with the existing
    decision making code. Changing that is future work, since it requires
    changes to other compiler components as well.
2026-04-06 05:09:01 +10:00
Zoltan Somogyi
d631c0bb22 Avoid compiler crashes with --optimize-saved-vars. 2026-04-05 02:53:05 +10:00
Zoltan Somogyi
7e8781390d Turn a set of clauses into an explicit disjunction. 2026-04-05 02:52:19 +10:00
Zoltan Somogyi
a14544b7e7 Rationalize the code expanding @file cmd line args.
compiler/mercury_compile_args.m:
    Instead of writing out any error messages (and setting the exit status)
    in different ways in different circumstances, return all error messages
    to our caller, as error_specs, and the option_table needed to print
    those error_specs out.

    Simplify the code that actually does the expansion of @file arguments,
    both by invoking higher level primitives than were available when
    the original code was written, and by avoiding repeatedly putting
    arguments info ok/1 wrappers and taking them out again.

    Change the argument list of setup_all_args to delete the ErrorStream
    argument and pass only ProgressStream, because its only caller always
    passes the *same* stream as both arguments.

compiler/mercury_compile_main.m:
    Print the error messages that mercury_compile_args.m now returns.
    Standardize on printing "mmc:" before those messages to identify
    the program reporting those errors. (The old code could print any
    one of "mercury_compile:", "mmc:", the name of the executable,
    or nothing.)

compiler/file_util.m:
    Add two utility functions for the new code in mercury_compile_args.m.

compiler/handle_options.m:
    Add an XXX.

tests/invalid/invalid_mllibs.err_exp:
tests/invalid_make_int/bad_color.int_err_exp:
tests/invalid_options_file/inf_incl_direct.err_exp:
tests/invalid_options_file/inf_incl_indirect.err_exp:
tests/invalid_options_file/no_assign.err_exp:
tests/invalid_options_file/no_var.err_exp:
tests/invalid_options_file/nonexistent_file.err_exp:
tests/invalid_options_file/undefined_var.err_exp:
tests/invalid_options_file/unterminated_string.err_exp:
tests/invalid_options_file/unterminated_var.err_exp:
    Consistently expect the "mmc:" prefix before the error messages
    now printed by mercury_compile_main.m.
2026-04-03 07:06:46 +11:00
Zoltan Somogyi
47e7b8eedd Reduce the number of modules that set the exit status ...
... by removing four more modules from that set.

compiler/make.module_dep_file.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_middle_passes.m:
    Replace bespoke error reporting code with invocations of standardized
    error reporting predicates.

compiler/source_file_map.m:
    Delete an unused predicate.
2026-04-03 04:16:56 +11:00
Zoltan Somogyi
6c50482539 Use separate loops for error and non-error cases. 2026-04-03 03:20:17 +11:00
Zoltan Somogyi
d067ea1255 Reduce the number of modules that set the exit status ...
... by removing globals.m, handle_options.m recompilation.used_file.m
from that set.

compiler/globals.m:
compiler/recompilation.used_file.m:
    Replace bespoke error reporting code with invocations of standardized
    error reporting predicates.

compiler/handle_options.m:
    Generate error_specs instead of writing out warnings directly.
2026-04-03 01:26:37 +11:00
Zoltan Somogyi
914402bea3 Put some predicates into top-down order. 2026-04-03 00:30:57 +11:00
Zoltan Somogyi
4717fac160 Simplify the internals of file_util.m. 2026-04-03 00:29:34 +11:00
Zoltan Somogyi
e00722533b Reduce the number of modules that set the exit status ...
... by removing export.m and options_file.m from that set.

compiler/export.m:
compiler/options_file.m:
    Replace bespoke error reporting code with invocations of standardized
    error reporting predicates.

compiler/file_util.m:
    Add versions of existing error reporting predicates and functions that
    work without access to a globals structure, for use by options_file.m.
2026-04-02 23:17:58 +11:00
Zoltan Somogyi
f79d98fd45 Fix indentation. 2026-04-02 21:12:54 +11:00
Zoltan Somogyi
6e468a5110 Reduce the number of modules that set the exit status ...
... by removing compiler_util.m from that set.

compiler/tupling.m:
    Replace the only two calls to report_warning with code to return
    error_specs.

compiler/mercury_compile_middle_passes.m:
    Accumulate the resulting error_specs.

compiler/write_error_spec.m:
    Inline the only call to record_warning_opt_table.

compiler/compiler_util.m:
    Delete report_warning and record_warning_opt_table, which now have
    no callers, and record_warning, which had no callers to begin with.
2026-04-02 20:55:38 +11:00
Julien Fischer
50ac3a9e66 Do not install low-level C parallel grades by default.
configure.ac:
compiler/handle_options.m:
     As above.
2026-03-27 12:28:31 +11:00
Zoltan Somogyi
bbb93b6eab Disable LLDS .par grades until its bug is fixed. 2026-03-26 22:39:15 +11:00
Zoltan Somogyi
9abf70bf16 Improve debuggability and style in cse_detection.m. 2026-03-26 16:54:25 +11:00
Zoltan Somogyi
5b74acdea0 Build flat conjunctions. 2026-03-21 20:47:35 +11:00
Zoltan Somogyi
ab4af128e0 Factor out common code. 2026-03-21 09:02:24 +11:00
Zoltan Somogyi
953ea7667f Fix deconstructing direct args.
The crash that this diff fixes occurred when giving a command such as
"print Var^1" to mdb, where the first argument of Var is a direct arg.

runtime/mercury_ml_expand_body.h:
    When deconstructing a term with a direct arg, return NULL
    as the value of expand_info->chosen_arg_word_sized_ptr.
    The crash occurred when we returned a non-null pointer,
    which violated the expectations of trace/mercury_trace_vars.c
    and its callers. (Not surprising, since those that function and
    its callers were written long before the direct_arg optimization
    was added to the system.)

runtime/mercury_deconstruct.h:
    Document the rationale behind the above changes. (The contents of
    mercury_ml_expand_body.h are #included in mercury_deconstruct.c.)

trace/mercury_trace_vars.c:
    Add the debugging code I used to track down this issue, in disabled form.

    Fix missing copyright year.

trace/mercury_trace_browse.c:
    Delete obsolete comment.

    Fix missing copyright years.

tests/debugger/direct_arg_test.{m,inp,exp}:
    A test case for this bug.

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

compiler/hlds_out_type_table.m:
    When dumping out the data constructors in the type table,
    if a constructor has names for some of its fields,
    put the name and the type of each field on different lines.
    In the original test case for this bug, of which direct_arg_test.m
    is an extreme simplification, pretty much every line overflows
    without this.

    Also, factor out some duplicated code, and replace bools with values
    of a bespoke type.
2026-03-13 14:50:15 +11:00
Zoltan Somogyi
3aca14b385 Compile the Mercury system with --warn-unused-types.
configure.ac:
    Require the installed compiler to support that option.

STANDARD_MCFLAGS:
    Specify that option.

compiler/canonicalize_interface.m:
compiler/comp_unit_interface.m:
compiler/inst_user.m:
compiler/parse_module.m:
compiler/switch_util.m:
compiler/type_ctor_info.m:
deep_profiler/mdprof_dump.m:
library/digraph.m:
slice/mcov.m:
    Delete unused equivalence types that were picked up by the option.
2026-03-09 03:07:51 +11:00
Zoltan Somogyi
f359649d50 Warn about unused local equivalence types ...
... in some contexts.

compiler/unused_types.m:
    Implement the easy part of the above, the part that happens
    *after* we collect the info about which equivalence types are used.
    Document why we can report unused equivalence types only in some contexts.

compiler/prog_data_used_modules.m:
    Define an extension of the used_modules type that also records
    which equivalence types were expanded in the module.

    Define the operations we need on this extended type.

compiler/equiv_type.m:
    Invoke one of those operations to record the expansions of equivalence
    types, if requested to do so.

    Inline the predicate that used to do this at its only call site.

compiler/hlds_module.m:
    Replace the used_module field in the module_info with a value of
    the extended type that includes not just the old used_modules info,
    but also the set of expanded equivalence types.

    Delete a utility predicate on the old field. The last call to this
    predicate was deleted on 2022 march 30.

compiler/equiv_type_parse_tree.m:
compiler/make_hlds_passes.m:
compiler/mercury_compile_make_hlds.m:
compiler/unused_imports.m:
    Conform to the changes above.

tests/warnings/warn_dead_procs.{m,err_exp}:
    This test case already tests for warnings about unused du types.
    Extend it to also test for unused eqv types.
2026-03-08 19:36:28 +11:00
Zoltan Somogyi
0c1d2b22e4 Add from_int64 and det_from_int64 to int32.m.
library/int32.m:
    Add these library operations.

NEWS.md:
    Announce the new operations.

compiler/lookup_switch_util.m:
    Use the checked operations added by this diff and other recent diffs
    to replace unchecked casts.
2026-03-07 04:07:34 +11:00
Zoltan Somogyi
cb2beb88c1 Delete a ZZZs. 2026-03-04 20:08:33 +11:00
Zoltan Somogyi
a7159fa88f Give some variables more consistent names. 2026-03-04 20:07:22 +11:00
Zoltan Somogyi
b261c5fcb2 Enable dense switches on sized and unsigned ints.
Until now, the only integer type we generated dense switches
(including lookup switches) for was int itself; we did not do so
for any sized and/or unsigned integer types.

compiler/switch_util.m:
    Simplify the representation of whether a switch is on an integer type.
    The new version makes it impossible to make the mistake that caused
    bug582 in the first place: not having a single representation for
    for the switch being on *any* kind of integer type.

    This fix requires solving a problem we never had to solve before:
    representing information such as the min and max case values
    in a way that works for every integer type, signed or unsigned,
    sized or not. The solution that this diff adopts is to use int32s
    to represent those limits, which implies that whatever the type
    of the integer value being switched on, we will generate a dense
    or a lookup switch for it only if all case values fit into an int32.
    Since case values over two billion are vanishingly rare, this should be
    an acceptable restriction.

    Use uints instead of ints to represent counts of things.

    Delete an unneeded pair of arguments.

compiler/lookup_switch_util.m:
    Conform to the changes in switch_util.m. Use some of the new types
    there to make arguments in arguments lists less confusable.

    Provide some new utility operations.

    Add XXXs where the basic operations we need seem not to exist.

compiler/dense_switch.m:
compiler/lookup_switch.m:
    Use the new types in switch_util.m that can represent switches
    on any integer type.

compiler/ml_lookup_switch.m:
compiler/ml_simplify_switch.m:
compiler/ml_string_switch.m:
compiler/ml_switch_gen.m:
compiler/switch_gen.m:
    Conform to the changes above, and thereby gain the ability
    to generate switches on integer types other than int itself.

library/int64.m:
    Add a (commmented-out) declaration of an operation that could
    help resolve one of the issues in new code in the modules above.
    Similar operations would be needed in the modules of other
    sized integer types as well.

library/library.m:
    Fix a typo.

tests/hard_coded/bug582.{m,exp}:
    Add a test case for this issue. Note that while we test whether
    we get the expected output, there is no simple automatic way
    to detect whether it was generated using a lookup table.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2026-03-04 19:51:35 +11:00
Zoltan Somogyi
d0681be57a Factor out duplicate code. 2026-03-03 23:49:58 +11:00
Zoltan Somogyi
acef703a48 Do not export a predicate unnecessarily. 2026-03-03 05:13:49 +11:00
Zoltan Somogyi
10565df4f6 Break up a large predicate. 2026-03-02 05:19:45 +11:00
Zoltan Somogyi
85876a9ecc Split equiv_type.m into two parts.
The old equiv_type.m's growth was organic, not planned. It mixed predicates
operating on different levels, and even predicates on the same level
were not always logically organized.

compiler/equiv_type_parse_tree.m:
    This module contains the bulk of the old equiv_type.m, the part
    concerned with processing parse tree items and their major components.

compiler/equiv_type.m:
    The part of the old equiv_type.m that deals with expanding equivalences
    inside basic parts of program representations.

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

compiler/decide_type_repn.m:
compiler/mercury_compile_make_hlds.m:
    Conform to the changes above.
2026-03-01 22:43:32 +11:00
Zoltan Somogyi
48a95366e1 Move a predicate to where it belongs. 2026-03-01 18:36:22 +11:00
Zoltan Somogyi
7d2146d3a9 Make items' recompilation dependencies more understandable.
compiler/recompilation.record_uses.m:
    Rename the eqv_expand_info type to item_recomp_deps to better document
    its purpose (it is to record which equivalence expansions *an item
    depends on*). Finish documenting the type itself.

    Rename the predicates operating on values of that type accordingly,
    together with the variables in their clauses.

    Since the point of the type is to record info about an item,
    make the main predicate that constructs values of this type
    take *the id the actual item* as input. Previously, it was just
    a sym_name that was part of the item id. We still need that version
    in two places (where we don't know the final item id yet), but use it
    only when we have to. In each case, document *why* we have to.

compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/qual_info.m:
compiler/add_pragma_type_spec.m:
    Conform to the changes above.

    Use a consistent naming scheme for the variables of the renamed type.

    In one case, stop using a "some [!StateVar]" scope that hurts
    readability more than it helps.
2026-03-01 18:35:38 +11:00
Zoltan Somogyi
c174ccfdb6 Fix too-long lines. 2026-03-01 16:00:56 +11:00
Zoltan Somogyi
5d804166da Pass all invariants parameters in one arg. 2026-02-28 23:47:25 +11:00
Zoltan Somogyi
f197b229c9 Make debugging output more readable. 2026-02-28 19:40:24 +11:00
Zoltan Somogyi
199c1a9cd1 Generate mode-specific unused args warnings if needed.
compiler/unused_args_warn_pragma.m:
    The existing code processed only the first procedure of each predicate,
    skipping all the later procedures. It had a comment saying that it
    warns about an unused arg only if it was unused in all modes,
    but this claim was false.

    Replace this old code with new code that

    - gathers the set of unused args in each procedure, recording
      which ones have mode "unused",

    - considers all the procedures of a predicate together, and then

    - generates either a single warning for the predicate as a whole,
      or separate warnings for each procedure that has unused arguments.

    We now generate a single warning for the predicate only if all the
    procedures agree both on which arguments are unused, and on
    which of those are *marked* by the mode as unused. Of course,
    most of the time this will be the case simply because most predicates
    have just one procedure.

    Stop module qualifying predicate names in the warnings we generate,
    since we do not generate warnings for imported predicates.

    Color the unqualified name as the subject of the diagnostic.

    When reporting unused args, list the arguments with "unused" modes
    separately from the other arguments.

    Simplify the interface with our caller in unused_args.m.

compiler/unused_args.m:
    Conform to the simplified interface with unused_args_warn_pragma.m.

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

tests/warnings/unused_args_some_modes.{m,err_exp}:
    Add a test case for the new capability.

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

    Stop mixing "VAR = VALUE" and "Var += VALUE" definitions
    of make variables. Give some make variables better names.

    Move some dependency definitions out of a block of rules.

tests/warnings/Mercury.options:
    Enable --warn-unused-args for the new test case.

    Delete some accidentally-duplicated entries.

tests/warnings/unused_args_test.err_exp:
    Update the expected output.
2026-02-27 21:27:09 +11:00
Zoltan Somogyi
b560f66ab9 Move four modules from check_hlds.m to hlds.m.
After this, I think all modules in the check_hlds package belong there.

compiler/inst_match.m:
compiler/mode_test.m:
    Move these modules from the check_hlds package to the hlds package
    because most of their uses are outside the semantic analysis passes
    that the check_hlds package is intended to contain.

compiler/inst_merge.m:
    Move this module from the check_hlds package to the hlds package
    because it is imported by only two modules, instmap.m and inst_match.m,
    and after this diff, both are in the hlds package.

compiler/implementation_defined_literals.m:
    Move this module from the check_hlds package to the hlds package
    because it does a straightforward program transformation that
    does not have anything to do with semantic analysis (though its
    invocation does happen between semantic analysis passes).

compiler/notes/compiler_design.html:
    Update the documentation of the goal_path.m module. (I checked the
    documentation of the moved modules, which did not need updates,
    and found the need for this instead.)

compiler/*.m:
    Conform to the changes above. (For many modules, this deletes
    their import of the check_hlds package itself.)
2026-02-27 15:16:44 +11:00
Julien Fischer
cd48b281df Add a missing word.
compiler/notes/compiler_design.html:
    As above.
2026-02-25 15:27:00 +11:00
Julien Fischer
c99565e517 Minor fix for compiler design doc.
compiler/notes/compiler_design.html:
    s/compile_target_code.m/link_target_code.m/ where the latter
    was meant.
2026-02-25 15:24:02 +11:00
Zoltan Somogyi
1d736d1447 Delete may_gather_warning_pragma_for_pred_old. 2026-02-24 12:11:54 +11:00
Zoltan Somogyi
0a7b5c1a6b Give a type a more meaningful name. 2026-02-24 02:47:42 +11:00
Zoltan Somogyi
2afa32259a Carve four new modules out of unused_args.m.
compiler/unused_args_analysis.m:
    New module containing the parts of the old unused_args.m
    that deal with the intermodule analysis framework.

compiler/unused_args_base_ops.m:
    New module containing the parts of the old unused_args.m
    that define and operate on the main data structure we use
    to find out which variables are unused.

compiler/unused_args_optimize.m:
    New module containing the parts of the old unused_args.m
    that "optimize out" unused arguments.

compiler/unused_args_warn_pragma.m:
    New module containing the parts of the old unused_args.m
    that generate warnings about unused arguments, and that generate
    unused_args pragmas for .opt files. The module contains both
    because they share the same test for whether we want to ignore
    any unused arguments in a predicate.

compiler/unused_args.m:
    Delete the moved code.

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

compiler/mercury_compile_middle_passes.m:
compiler/mmc_analysis.m:
    Conform to the changes above.
2026-02-24 02:32:37 +11:00
Zoltan Somogyi
b28858717f Fix wording of an informational message. 2026-02-24 01:51:26 +11:00
Zoltan Somogyi
c6f77ce5c5 Fix typos. 2026-02-20 19:54:49 +11:00
Zoltan Somogyi
0966d89479 Expand a comment. 2026-02-20 00:41:49 +11:00
Zoltan Somogyi
4d6bc0cd5b Rename and document unused_args.m's main data structure.
compiler/unused_args.m:
    Rename the "usage_info" type to "required_by". Document the meaning
    of its contents.

    Rename the low-level predicates that operate on this data structure
    accordingly. Make them fit consistently into the same pattern:
    X_{is,are}_required_by_Y.

    In the argument lists of these predicates, pass values of arg_var_in_proc
    as a unit, instead of passing them as two separate components, one of which
    was easily confusable with another argument that has the opposite role.

    To make this possible *and* non-misleading, reorder arguments as needed.
    In one case, replace a call to list.foldl with an explicit loop
    to make the reordering possible.

    Give the high-level predicates that operate on this data structure
    more descriptive names as well. Document the logic behind the fixpoint
    iteration.
2026-02-19 18:05:31 +11:00
Zoltan Somogyi
2301658c7e Give predicates more descriptive names.
compiler/unused_args.m:
    Replace "fixup_x" naming scheme with "delete_unused_args_in_x".

    Fix some misleading comments.

    Add some comments on not-chosen alternative approaches.

    Move a utility predicate to the end of the module,
    and give it a simpler interface.
2026-02-19 18:05:31 +11:00
Zoltan Somogyi
c857c616a6 Replace a bool. 2026-02-19 08:47:19 +11:00
Zoltan Somogyi
c2dcc0e0c9 Give some variables more descriptive names. 2026-02-19 08:32:42 +11:00
Zoltan Somogyi
246bc5129e Reorder switch arms. 2026-02-18 20:42:17 +11:00