Commit Graph

11187 Commits

Author SHA1 Message Date
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
Zoltan Somogyi
7b549bc6ae Fix typos. 2026-02-18 13:09:25 +11:00
Zoltan Somogyi
54b6bfc354 Put the contents of equiv_type.m in top-down order. 2026-02-18 09:38:16 +11:00
Zoltan Somogyi
51282bd2a4 Document forcing preds for type_spec pragmas.
compiler/higher_order.specialize_in_module.m:
    Document the meaning of a field.

compiler/add_pragma_type_spec.m:
compiler/hlds_module.m:
    Change the code filling and using that field to avoid misleading
    variable and predicate names. Add some extra documentation
    where that can help.
2026-02-17 22:24:31 +11:00
Zoltan Somogyi
019ea41ec4 Break up add_pragma.m into four new modules.
compiler/add_pragma_decl.m:
compiler/add_pragma_gen.m:
compiler/add_pragma_impl.m:
    These three new modules add declarative pragmas, implementation pragmas,
    and compiler-generated pragmas to the HLDS respectively.

compiler/add_pragma_util.m:
    This new module contains the parts of the old add_pragma.m
    that are needed by more than one of the three modules above.

compiler/add_pragma.m:
    Delete this module.

compiler/notes/compiler_design.html:
    Update the relevant documentation.

compiler/add_pragma_tabling.m:
    Use standard length section dividers.

compiler/make_hlds.m:
    Include the new modules.

compiler/make_hlds_passes.m:
    Import the new modules.
2026-02-17 16:45:43 +11:00
Zoltan Somogyi
ab0d1a31a2 Carve add_pragma_type_spec_constr.m ...
... out of add_pragma_type_spec.m.

compiler/add_pragma_type_spec.m:
compiler/add_pragma_type_spec_constr.m:
    As above.

compiler/add_pragma.m:
    Import the new module.

compiler/make_hlds.m:
    Include the new module.

compiler/notes/compiler_design.html:
    Document the new module.
2026-02-17 15:11:03 +11:00
Zoltan Somogyi
29deb20fde Fix the --show-pred-movability option.
I seem to have been broken it on Aug 18 with the move to associate
a option with every severity_informational spec. The code added then
treated all these options as bool options, but one is not.

compiler/error_util.m:
    Allow a severity_informational spec to depend on an accumulating
    option, which --show-pred-movability is.

    As far as I can see, it is the only non-bool option used
    in such messages, but since we don't have a database of
    options named in severity_informational specs, I can't be sure.

compiler/hlds_call_tree.m:
    Avoid printing a sentence when its subject is moot.

tests/valid/show_movability.m:
    New test case to test the --show-pred-movability option.

tests/valid/Mercury.options:
    Specify the option for the new test case.
2026-02-17 14:11:41 +11:00
Zoltan Somogyi
465e82ed6d Fix an abort. 2026-02-17 08:51:22 +11:00
Zoltan Somogyi
3a431411cd Pass goal components when those are wanted.
Move a predicate next to a related predicate.
2026-02-17 08:49:51 +11:00
Zoltan Somogyi
ac6abd4694 Delete obsolete history from two comments. 2026-02-17 08:48:54 +11:00
Zoltan Somogyi
6c45431924 Give a predicate a more descriptive name. 2026-02-17 08:48:28 +11:00
Zoltan Somogyi
88c7d52bb6 Simplify a call. 2026-02-17 08:47:59 +11:00
Zoltan Somogyi
33fb4d7618 Fix a mismatch between old and new code.
compiler/unused_args.m:
    Make the new version of a test succeeds, where the old version
    *looked like* it failed, but did not.

compiler/lambda.m:
    Fix misleading module comment.
2026-02-16 15:23:12 +11:00
Zoltan Somogyi
b024b5f533 Carve build_eqv_maps.m out of equiv_type.m.
compiler/build_eqv_maps.m:
compiler/equiv_type.m:
    As above.

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

compiler/decide_type_repn.m:
compiler/equiv_type_hlds.m:
compiler/make_hlds_passes.m:
compiler/mercury_compile_make_hlds.m:
compiler/qual_info.m:
    Conform to the changes above.
2026-02-16 11:11:10 +11:00
Zoltan Somogyi
4254e2f648 Make some variable names more descriptive. 2026-02-16 10:00:56 +11:00