Commit Graph

11162 Commits

Author SHA1 Message Date
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
Zoltan Somogyi
5275a670b7 Fix too-long lines. 2026-02-16 08:32:17 +11:00
Zoltan Somogyi
17dfe80eb6 Give some predicates better names. 2026-02-16 07:40:41 +11:00
Zoltan Somogyi
8597feaae6 Improve two rarely-seen diagnostics.
compiler/parse_type_defn.m:
    As above.

tests/invalid/field_syntax_error.{m,err_exp}:
tests/invalid/types.{m,err_exp}:
    Add an instance of each bug the diagnostics are for,
    and test for the updated diagnostic text.
2026-02-15 23:45:25 +11:00
Zoltan Somogyi
f51eb26a44 Delete some obsolete XXXs. 2026-02-15 22:10:12 +11:00
Zoltan Somogyi
5f4a14a189 Clarify the diagnostics about missing section markers.
compiler/parse_module.m:
    When complaining about missing ":- interface"/":- implementation" markers,
    reword the diagnostic to clarify that these should come after
    the initial ":- module" declaration.

tests/invalid_make_int/missing_initial_section.int_err_exp:
tests/invalid_nodepend/bigtest.err_exp:
tests/invalid_nodepend/errors_1.err_exp:
tests/invalid_nodepend/errors_2.err_exp:
tests/invalid_nodepend/errors_3.err_exp:
tests/invalid_nodepend/funcs_as_preds.err_exp:
tests/invalid_nodepend/invalid_main.err_exp:
tests/invalid_nodepend/no_exports.err_exp:
tests/invalid_nodepend/occurs.err_exp:
tests/invalid_nodepend/prog_io_erroneous.err_exp:
tests/invalid_nodepend/types.err_exp:
tests/invalid_nodepend/vars_in_wrong_places.err_exp:
    Expect the updated wording.
2026-02-15 16:20:34 +11:00
Zoltan Somogyi
1cc34eb911 Simplify the "warn about unused args?" test.
compiler/unused_args.m:
    The old code that we use to decide whether we want to warn
    about unused args in a predicate was built up piecemeal
    over a long time, mostly before the creation pred_origins.
    It never had a cohesive design.

    Add a new version of the test that has a cohesive design,
    consisting of just a test of the pred_status, and a case analysis
    of the various possible values of the pred's origin.

    Add code to automatically compare the result of the old and new tests,
    and abort if they do not match. After a few days of tests on code
    other than the Mercury system that don't trigger any of the new exceptions,
    we can throw away the old code.
2026-02-15 14:43:58 +11:00
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
81c6c5e04a Decide what unused_args.m should do just once.
compiler/mercury_compile_middle_passes.m:
    Pass the main predicate of unused_args.m two flags that together
    specify what it should do, besides generating warnings. This makes
    the code easier to understand, since each ignored argument representing
    a set of unused_args pragmas is now preceded by a flag argument
    that says "do not generate those pragmas".

compiler/unused_args.m:
    Delete the code for deciding whether (a) we want to generate unused_args
    pragmas or (b) record unused_args information in the analysis registry.
    This is because the code doing that was duplicating the code fragments
    in mercury_compile_front_end.m and mercury_compile_augment.m that decided
    which predicate to call in mercury_compile_middle_passes.m:
    either middle_pass_for_opt_file, or output_analysis_file.

    This duplication not only violates the "Don't repeat yourself" principle",
    but also led to hard-to-understand code in unused_args.m.
2026-02-15 09:32:48 +11:00
Zoltan Somogyi
e1ff6d4077 Break up a large predicate.
Replace bools with two new bespoke types.

Replace an unnecessary fold operation.

Put some switch arms into the same order as the cases' cons_ids.
2026-02-14 22:32:44 +11:00
Zoltan Somogyi
5763792c36 Stop the unneeded export of a predicate. 2026-02-14 22:28:18 +11:00
Zoltan Somogyi
45cf0f5f92 Do not warn about foreign_procs from other modules. 2026-02-14 22:27:21 +11:00
Zoltan Somogyi
142b59f9d4 Fix typos. 2026-02-14 09:34:29 +11:00
Zoltan Somogyi
b7a4aa83dc Reorder the contents of unused_args.m.
compiler/unused_args.m:
    Put both the primitive operations on the module's main analysis
    data structure, and the code required for the analysis typeclass
    instances, into separate blocks near the end of the module,
    just before the debugging routines.

    Replace more uses of bools with the maybe_changed type.

    Do not allocate new hlds_goal structures that are identical to
    already existing hlds_goal structure.

    Carve two new small predicates out of an existing too-big one.

    Make some other simplifications, and improve some other type,
    predicate and variable names.

compiler/maybe_util.m:
    Add two utility functions for use by unused_args.m.
2026-02-12 19:47:27 +11:00
Zoltan Somogyi
0816664388 Give some predicates in mmc_analysis.m more meaningful names.
compiler/mmc_analysis.m:
    As above.

compiler/exception_analysis.m:
compiler/structure_reuse.analysis.m:
compiler/structure_sharing.analysis.m:
compiler/tabling_analysis.m:
compiler/trailing_analysis.m:
compiler/unused_args.m:
    Conform to the changes above.
2026-02-12 17:09:07 +11:00
Zoltan Somogyi
93bd7db4d1 Make unused_args.m more readable.
Give some types, predicates and variables more descriptive and more
consistent names.

Document some predicates rather better. Add XXXs indicating where
further documentation would help :-(

Redirect some references to map.set to map.det_{insert,update}.
2026-02-12 16:41:58 +11:00
Zoltan Somogyi
37cfcf3726 Make the structure of a predicate explicit. 2026-02-04 04:17:10 +11:00
Zoltan Somogyi
ad942553b7 Fix too-long lines. 2026-02-04 04:16:37 +11:00
Zoltan Somogyi
de16b3f10e Fix comment. 2026-02-02 05:16:41 +11:00
Zoltan Somogyi
4542c7f24f Fix indentation. 2026-02-02 00:27:24 +11:00
Zoltan Somogyi
291879c8bb Move checks for type_infos to add_foreign_proc.m.
This allows to perform those checks for *all* foreign_procs,
not just the ones that get added to the HLDS.

compiler/add_foreign_proc.m:
    Move the code that checks the bodies of foreign_procs for the
    presence of type_info variables for existentially quantified
    type variables here from typecheck.m and typecheck_errors.m.
    Change the diagnostic's wording to match our new phraseology.

    Record identifiers in a set, not a list, for faster membership tests,
    since we now do even more of them.

compiler/foreign.m:
    Provide a mechanism to return the identifiers not just in the
    non-comment parts of foreign_procs, but the comment parts as well,
    since add_foreign_proc.m now needs this functionality.

compiler/make_hlds_warn.m:
    Conform to the change in foreign.m.

compiler/typecheck.m:
compiler/typecheck_errors.m:
    Delete the code that was moved (in a modified form)
    to add_foreign_proc.m.

compiler/ml_foreign_proc_gen.m:
    Update a reference in a comment.

tests/invalid/exist_foreign_error.err_exp:
    Expect the updated wording of the affected diagnostics,
    and expect diagnostics for *all* the foreign_procs in the test,
    regardless of which language they are for.

tests/invalid/exist_foreign_error.err_exp2:
tests/invalid/exist_foreign_error.err_exp3:
    Delete these files, since the output they expect is now
    in the .err_exp file.

tests/invalid/fp_dup_bug.err_exp2:
tests/invalid/fp_dup_bug.err_exp3:
tests/invalid/gh72_errors.err_exp2:
tests/invalid/gh72_errors.err_exp3:
    Expect the updated wording of diagnostics affected by previous
    changes (which updated the .err_exp files for C, not these for
    Java and C#).
2026-01-31 16:31:04 +11:00
Zoltan Somogyi
8362e1ca66 Centralize control of add_foreign_proc.m diagnostics.
compiler/add_foreign_proc.m:
    Create a single predicate, check_foreign_proc to invoke all the
    other predicates that each generate one kind of diagnostic
    about foreign_procs. Inline in it all the other predicates
    that previously did part of its job.

    Do not let the lack of a proc_id stop the invocation of any
    of those predicates, except the single one that needs the proc_id
    for its work.

    Also, make this the only place that decides how the foreign_proc
    being for an imported predicate affects what we do.

    Simplify predicate argument lists as allowed by the changes above.
2026-01-30 23:10:00 +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
9dc69a6cce Move all diagnostics predicates to the end. 2026-01-30 17:41:02 +11:00
Zoltan Somogyi
738ed9a35e Move a predicate to its only calling module. 2026-01-30 16:43:17 +11:00
Zoltan Somogyi
af3a275563 Stop double-warning about foreign_proc singletons.
compiler/make_hlds_warn.m:
    We have long invoked the predicate that warns about singletons
    (and a few other kinds of errors) in foreign_procs

    - both when we add the foreign_proc to the HLDS,
    - and when we add Mercury a clause to the HLDS, and the clause
      contains a call_foreign_proc goal.

    However, until the inlining pass, Mercury clauses can *never* contain
    a call_foreign_proc goal, so the latter code never does anything.
    Delete it.
2026-01-30 16:01:31 +11:00