Commit Graph

24782 Commits

Author SHA1 Message Date
Zoltan Somogyi
38995e52e1 Simplify some code. 2025-11-16 19:31:25 +11:00
Zoltan Somogyi
7597f24121 Break up two large predicates. 2025-11-16 19:30:04 +11:00
Zoltan Somogyi
82da94f071 Break up three large predicates. 2025-11-16 18:05:59 +11:00
Zoltan Somogyi
653f8d1c28 Fix typos. 2025-11-16 15:31:44 +11:00
Zoltan Somogyi
d5c08567e4 Make format after switch work.
compiler/simplify_proc.m:
    If a first attempt to analyse and optimize format calls fails
    due to insufficient information about format strings and/or values,
    then try the whole process again after pushing copies of the format calls,
    and the conjuncts that precede them, into the last preceding branched
    control structure (disjunction, switch, or if-then-else). This will
    fix the problem if each branch does construct known format strings
    and/or values, and is harmless if this is not the case.

tests/valid/format_after_switch.m:
    A test case for the new capability.

tests/valid/Mmakefile:
tests/valid/Mercury.options:
    Enable the new test case.
2025-11-16 13:42:36 +11:00
Zoltan Somogyi
bdd2a574a8 Replace conditional_specs with a new severity.
compiler/error_spec.m:
    Delete conditional_spec from the error_spec type, which had
    exactly one use left in the compiler. Replace it with a conditional form
    of severity_error, which handles that use case.

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

    For the same reason, rename error_phase to spec_phase.

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

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

compiler/add_pragma.m:
compiler/check_typeclass.m:
compiler/compiler_util.m:
compiler/error_sort.m:
compiler/mark_tail_calls.m:
compiler/parse_error.m:
compiler/parse_item.m:
    Conform to the changes above.
2025-11-15 10:29:23 +11:00
Zoltan Somogyi
c6ab9b02c1 Break up a predicate. 2025-11-15 07:09:03 +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
87d04f3428 Add get_values_for_key/2 to multi_map and one_or_more_map.
library/multi_map.m:
library/one_or_more_map.m:
    As above.

NEWS.md:
    Announce the additions.
2025-11-14 12:55:43 +11:00
Zoltan Somogyi
f4b3329e4e Put predicates into top-down order. 2025-11-13 15:10:28 +11:00
Zoltan Somogyi
1a5568fbfd Put switch arms in type declaration order. 2025-11-13 14:30:26 +11:00
Julien Fischer
91cfdc5978 Fix documentation copy-and-paste errors.
library/multi_map.m:
library/one_or_more_map.m:
    As above.
2025-11-11 10:34:21 +11:00
Zoltan Somogyi
9b7bce9c1c Add history to a module comment. 2025-11-07 10:46:09 +11:00
Zoltan Somogyi
cf37b1bd53 Fix typos. 2025-11-07 10:45:20 +11:00
Julien Fischer
88b7a207a2 Fix markup in NEWS file.
NEWS.md:
    As above.
2025-11-06 11:07:26 +11:00
Julien Fischer
499d193580 Fix a typo.
compiler/state_vars.m:
    s/errrors/errors/
2025-11-05 21:41:27 +11:00
Zoltan Somogyi
9c850f3557 Replace clauses with explicit disjunction. 2025-11-05 16:02:47 +11:00
Zoltan Somogyi
6e41bcd9c0 Document a function symbol. 2025-11-05 16:02:15 +11:00
Zoltan Somogyi
6c7688ec52 Add a new task for the next release, ...
... and update an existing one.
2025-11-05 03:58:19 +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
Julien Fischer
6b031c1ec6 Fix markup in NEWS file.
NEWS.md:
    As above.
2025-11-04 14:29:05 +11:00
Zoltan Somogyi
6f70c69d51 Avoid an abort during coercion checking.
compiler/typecheck_coerce.m:
    As above. While this diff solves the problem, it is mainly just
    a first step towards a better solution.
2025-11-04 03:48:54 +11:00
Zoltan Somogyi
357e1ef8a9 Simplify some code. 2025-11-04 00:53:04 +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
0f3f4b934c Don't look for disjunctions in from_ground_term scopes. 2025-11-03 21:49:56 +11:00
Zoltan Somogyi
fca4505501 Document a type. 2025-11-03 05:08:44 +11:00
Zoltan Somogyi
01836315ac Specialize diagnostics for numeric operations.
compiler/typecheck_error_undef.m:
    When users try to use arithmetic operations, bitwise operations,
    or comparisons (meaning functions such as '+' or '<<', or predicates
    such as '<') without importing any of the modules that define those ops,
    generate a diagnostic that explains this specific situation. Mercury
    is unusual in requiring such imports, so novices need to have this
    pointed out to them. Have these messages replace the less-specific
    messages we used to generate in such situations.

    Fix a persistent typo.

tests/invalid/int_ops.{m,err_exp}:
    A new test case for the new diagnostics.

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

tests/invalid/multiply_star.err_exp:
    Expect the diagnostic text, and stop expecting the "did you mean"
    message that it replaces.

tests/invalid/multiply_star.err_exp[23]:
    Delete these files. They existed only because different sets of imports
    with different options yielded different "did you mean" suggestions,
    and we don't have those anymore.

tests/invalid/multiply_star.m:
    Update the descriptions of the deleted .err_exp[23] files.
2025-11-02 16:25:59 +11:00
Julien Fischer
159ca8a004 Update .gitignore file.
.gitignore:
    As above.
2025-11-01 16:50:02 +11:00
Zoltan Somogyi
840e9e4b0a Stop expecting warnings that we don't ask for.
tests/invalid/require_tailrec_2.err_exp3:
    This test case asks for warnings only about non-tail *self* recursion.
    Since 2025 aug 18, the compiler actually respects this. Update the
    expected output for deep profiling grades to conform to this.
2025-11-01 14:30:34 +11:00
Zoltan Somogyi
357caf3f38 Look for up to six expected output files, not five.
tests/Mmake.common:
    As above. This should fix the failure of invalid/foreign_decl_line_number
    with clang, because we no longer ignore the expected output for situation,
    which is in the test case's .err_exp6 file.
2025-11-01 14:11:31 +11:00
Zoltan Somogyi
70347128ee Fix typos in comments. 2025-11-01 04:21:18 +11:00
Zoltan Somogyi
04a5d9f530 Break up a large predicate. 2025-11-01 04:20:58 +11:00
Zoltan Somogyi
d906af74c1 Clarify code in purity.m. 2025-10-31 21:51:10 +11:00
Julien Fischer
0dbf9e21cc Fix a problme with bootcheck --no-bootcheck.
tools/bootcheck:
     With --no-bootcheck in the Java grade, do not pass any runtime
     options. The Java version of the runtime only supports a very
     small subset of the options.
2025-10-31 15:02:41 +11:00
Julien Fischer
cfeaafd627 Fix a failing test in the Java grade.
tests/invalid/foreign_include_file_missing.{m,err_exp4}:
    Add an additional expected output for Java.
2025-10-30 11:30:27 +11:00
Julien Fischer
b11338ca23 Fix compilation in non-C grades.
compiler/prog_event.m:
    Avoid a warning.
2025-10-29 21:07:52 +11:00
Zoltan Somogyi
c96aca6143 Improve some comments. 2025-10-29 17:41:06 +11:00
Zoltan Somogyi
031dee09e0 Put predicates into a more logical order. 2025-10-29 16:05:35 +11:00
Zoltan Somogyi
b200344394 Update expected outputs for cord test cases. 2025-10-29 16:04:31 +11:00
Zoltan Somogyi
ee1aca8331 Fix warnings you get from tools/speedtest.
compiler/state_var.m:
    Move an import to the implementation section.

compiler/mode_constraints.m:
compiler/mode_ordering.m:
compiler/stm_expand.m:
    Avoid warnings about final statevars being unused.

compiler/Mercury.options:
    Stop switching off the warnings this diff avoids, not just for the
    above three modules, but also for two others, one of which
    (parse_module.m) apparently had the warnings a while ago,
    while the second (prog_event.m) never got them in the first place.

compiler/prog_event.m:
    Remove an ambiguity.
2025-10-29 12:26:20 +11:00
Zoltan Somogyi
d60c724fcc Speed up operations on cords.
library/cord.m:
    Delete the unit_node function symbol, since it is just a special case
    of the list_node function symbol. Reducing the number of function symbols
    that traversals have to choose between gains more performance than
    using two-argument list_nodes to replace one-argument unit_nodes loses.
2025-10-29 12:14:00 +11:00
Zoltan Somogyi
b185409639 In errors about disjuncts, mention if they are clauses.
compiler/det_check_goal.m:
    When reporting that a disjunction has more than one disjunct
    that can succeed (which is an error if the disjunction is supposed
    to be e.g. det or semidet), if the disjunct is actually a whole clause
    in the source code, then mention that fact.

compiler/hlds_markers.m:
    Define a goal feature that, when present, says "this goal used to be
    a whole clause".

compiler/clause_to_proc.m:
    Set this feature on clauses that we turn into disjuncts.

    Make the predicate involved tail recursive.

compiler/saved_vars.m:
    Conform to the change in hlds_markers.m.

tests/invalid/accidental_clause.{m,err_exp}:
    Add this test case, which is a much-simplified version of the code
    from an old post on m-users that motivated this change.

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

tests/invalid/not_a_switch.err_exp:
    Expect the updated form of this diagnostic.
2025-10-29 01:05:52 +11:00
Julien Fischer
7e14738135 Fix test failure in the C# grade.
tests/invalid/foreign_type_visibility.err_exp3:
    Update this expected output for colored output.
2025-10-28 22:45:22 +11:00
Julien Fischer
3a08620733 Fix typos in an error message.
compiler/post_typecheck.m:
     As above.

tests/invalid/bug184.err_exp:
tests/invalid/bug214.err_exp:
tests/invalid/typeclass_test_8.err_exp:
tests/invalid/unsatisfiable_constraint.err_exp:
     Conform to the above change.
2025-10-28 01:06:35 +11:00
Zoltan Somogyi
d1e48cffa9 Fix a variable name. 2025-10-27 17:46:56 +11:00
Zoltan Somogyi
ab4e7f840d Check for ambiguity where we report it.
compiler/typecheck_clauses.m:
compiler/typecheck_error_overload.m:
    Move the code that checks for ambiguity to the module that reports it.

    Give some predicates better names. Put input args before in,out arg pairs.

    Define predicates in the order in which they are called.

compiler/typecheck.m:
    Conform to the changes above.
2025-10-24 16:57:38 +11:00
Zoltan Somogyi
ea24dc3e2f Put input args before in/out arg pairs. 2025-10-24 11:24:19 +11:00
Zoltan Somogyi
0f21b1ff03 Give a function a more descriptive name. 2025-10-24 10:22:28 +11:00
Zoltan Somogyi
c5b0481b97 Simplify the construction of cons_infos.
typecheck_unify_var_functor.m used to have separate code paths
- to handle the functors of builtin types, and
- to handle the functors of all other types.

However, the second path invoked code in typecheck_cons_infos.m that
*also* handled builtin types.

compiler/typecheck_unify_var_functor.m:
    Simplify this arrangement by deleting the code that chose between
    the two paths, and handling functors of builtin types together with
    all the other functors in (what used to be) the second path.

compiler/typecheck_cons_infos.m:
    Return a distinct result for cons_ids of all builtin types
    (including some that typecheck_unify_var_functor.m did not handle
    via the first code path.)

    Document the meanings of the possible results.

compiler/hlds_cons.m:
    Change the ctor_field_table type to encode the invariant
    that we don't map sym_names to the empty list of field definitions.

compiler/hlds_pred.m:
    The predicates that test whether a sym_name/arity pair or pred_info
    refer to a field access function must search the ctor_field_table
    to answer the question. Make them return the info they get from that
    search, to save their callers from having to do it again.

    Give a predicate a more meaningful name.

compiler/typecheck_info.m:
    Record extra info if we are typechecking in a field access function,
    since it may be needed, and storing it costs next to nothing.

compiler/add_clause.m:
compiler/add_type.m:
compiler/check_field_access_functions.m:
compiler/field_access.m:
compiler/intermod_decide.m:
compiler/pre_typecheck.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/resolve_unify_functor.m:
compiler/typecheck_error_undef.m:
    Conform to the changes above.
2025-10-23 23:18:11 +11:00
Zoltan Somogyi
7c8c6cfe15 Improve some documentation. 2025-10-23 17:12:22 +11:00