Commit Graph

4452 Commits

Author SHA1 Message Date
Zoltan Somogyi
b78befa865 Fix programming style. 2026-02-03 01:15:16 +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
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
325fb21cbb Check all foreign_procs for more kinds of issues.
compiler/add_foreign_proc.m:
    Perform several more kinds of checks on all foreign_procs,
    not just on the foreign_procs that we end up adding to the HLDS.
    These are

    - the checks for whether the foreign_proc is for a builtin operation;

    - the checks for repeated variables in the foreign_proc's argument list;
      and

    - the checks for purity mismatches between the foreign_proc
      and the predicate/function it is for.

    An unrelated change: simplify, and make much more direct, the logic
    of the is_foreign_proc_for_this_backend predicate.

tests/invalid/foreign_proc_dup_var.err_exp:
tests/invalid/foreign_purity_mismatch.err_exp:
    Expect error messages not just for C foreign_procs, but Java and C#
    foreign_procs as well.

tests/invalid/foreign_proc_dup_var.err_exp2:
tests/invalid/foreign_proc_dup_var.err_exp3:
tests/invalid/foreign_purity_mismatch.err_exp2:
tests/invalid/foreign_purity_mismatch.err_exp3:
    Delete these files, which used to hold the diagnostics for
    Java and C# foreign_procs respectively.
2026-01-30 05:18:33 +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
44a0c62d96 Include state var references in "did you mean" messages.
compiler/make_hlds_warn.m:
    When generating "did you mean" messages to add to warnings about
    singleton variables, consider state variables in two separate ways.

    - When figuring out what you could have meant with a singleton reference
      that is a variable such as PredInfo, consider that the intended reference
      *could* have been to a state variable (such as !.PredInfo).

    - When figuring out what you could have meant with a singleton reference
      that is a state variable reference as !.PredIfno or !:PredIfno, consider
      that the intended reference *could* have been to another state variable
      (such as !.PredInfo or !:PredInfo).

    Stop passing around a parameter that, for some predicates, was *always*
    set to the same value.

tests/invalid/undef_symbol.{m,err_exp}:
    Extend this test case with code that (except for the types)
    duplicates the motivating example for this change.

tests/invalid/bug278.err_exp:
tests/invalid/field_syntax_error.err_exp:
    Expect the extra dym messages that we now generate.
2026-01-29 01:20:54 +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
Zoltan Somogyi
c6637a41ca Delete an obsolete workaround ...
... since Solaris died decades ago.

Add comments explaining some parts of this Mmakefile, and make
some other comments more readable.
2026-01-27 15:01:37 +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
8583f96d25 Add unsigned versions of version_array2d operations.
library/version_array2d.m:
    For every predicate or function that takes an integer argument,
    if that integer is required to be non-negative, add an unsigned version.

    Add bounds checks to lookup (read) and set (write) operations.

    Improve the documentation of the exported operations.

    Add a new implementation of the function that returns the rows
    of the array as a list of lists.

    Improve variable names in operations that have new unsigned versions.

NEWS.md:
    Announce the new operations.

tests/hard_coded/version_array2d_test.{m,exp}:
    New test case to test the operation of version_array2d.m.
    It is based on the applicable parts of version_array_test.m,
    but with somewhat improved organization.

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

tests/hard_coded/version_array_test.m:
    Minor style fixes.
2026-01-20 12:11:19 +11:00
Zoltan Somogyi
b6b4e85067 Add unsigned versions of version_array operations.
library/version_array.m:
    For every predicate or function that takes an integer argument,
    if that integer is required to be non-negative, add an unsigned version.

    Improve the documentation of the exported operations.

    Improve variable names in operations that have new unsigned versions.

NEWS.md:
    Announce the new operations.

tests/hard_coded/version_array_test.m:
    Modify this test case to test the new operations.
2026-01-19 19:27:50 +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
Peter Wang
9f84fec4f5 Fix bug with direct-arg ctors and intermodule optimisation.
If the compiler decides that a du type should use the direct-arg
representation for some of its constructors, it must include information
about that into the .opt file of the module defining the type, in the
form of `where direct_arg is' clauses, which will be used by modules
opt-importing that module and that type. That information was not being
included for du types defined in the *interface* section of a module.

Also fix a related issue that was uncovered: a word_aligned_pointer
assertion on a foreign_type definition would have no effect if there is
a no-tag du type definition for the same type constructor.

compiler/intermod.m:
compler/intermod_decide.m:
    Make should_opt_export_type_defn and some_type_needs_to_be_written
    succeed for `status_exported' du type definitions with direct-arg
    constructors. While `status_exported' suggests those type
    definitions would be redundant in .opt files, the information about
    the direct-arg constructors is not redundant.

compiler/du_type_layout.m:
    Add a is_word_aligned_ptr() value to the ComponentTypeMap if a
    no-tag du type also has a foreign_type definition for the current
    target language with a word_aligned_pointer assertion. Previously,
    this was only being done for single ctor NON no-tag du types.

    Add a XXX mentioning that we silently ignore word_aligned_pointer
    assertions in other cases.

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/direct_arg_opt.m:
tests/hard_coded/direct_arg_opt_helper_1.m:
tests/hard_coded/direct_arg_opt_helper_1.direct_arg_opt_helper_2.m:
tests/hard_coded/direct_arg_opt.exp:
    Add a test case.
2026-01-12 11:33:56 +11:00
Zoltan Somogyi
a0d5c3590f Fix two (or three) C# test case failures.
tests/invalid_nodepend/Mercury.options:
    Prevent two test cases, fundeps_vars and require_tailrec_invalid,
    from stopping after the creation of their .int files finds errors.
    Continue on to the code generation stage, where the errors that
    these test cases for are detected. (The fix is needed only for
    bootchecks that use mmc --make.)

tests/EXPECT_FAIL_TESTS.csharp:
    Recognize that hard_coded/functor_ho_inst_excp_1 is expected to fail
    in C# grades. This test case was already on the expected-to-fail list,
    but under its old name, functor_ho_inst_excp, which was not updated
    when the name was changed.
2026-01-08 09:57:54 +11:00
Zoltan Somogyi
3c5f1a907b Put the contents of this file into meaningful order. 2026-01-08 06:10:14 +11:00
Zoltan Somogyi
928fd04f5a Update the style of this Mmakefile. 2026-01-08 03:59:52 +11:00
Zoltan Somogyi
94fadf1797 Add uint versions of array operations.
library/array.m:
    Add uint versions of most of this module's operations.

NEWS.md:
    Mention the new operations.

library/edit_distance.m:
    Use the new array operations to eliminate some casts.

library/edit_seq.m:
    Minor style fix.

tests/hard_coded/array_gen.{m,exp}:
tests/hard_coded/array_test_2.{m,exp}:
    Extend the tests of array.m's operations to the corresponding uint
    versions. Expect the output for the new versions.

tests/hard_coded/array_resize.m:
tests/hard_coded/array_shrink.m:
    Extend the tests of array.m's operations to the corresponding uint
    versions, but generate output only if their results differ from the
    original int versions. (They don't differ.)

tests/hard_coded/array_primitives.m:
    Style fixes.
2026-01-08 03:47:09 +11:00
Zoltan Somogyi
03b07d8675 Expect a 2026 copyright year. 2026-01-02 20:31:48 +11:00
Zoltan Somogyi
ce9c9230c9 Enforce an invariant using types.
library/edit_seq.m:
    Change to uint the types of all the integers that cannot be negative.
    This happens to be all of them.

NEWS.md:
    Announce the change.

compiler/add_type.m:
compiler/det_check_switch.m:
compiler/error_spec.m:
compiler/style_checks.m:
compiler/typecheck_msgs.m:
    Conform to the changes above.

tests/hard_coded/change_hunk_test.{m,exp}:
tests/hard_coded/edit_seq_test.{m,exp}:
    Change the code that sets up the parameters for testing edit_seq.m
    to use uints, and expect uints in the output.
2026-01-01 17:23:24 +11:00
Zoltan Somogyi
7238c14618 Expand diagostic for bad state var refs.
compiler/typecheck_error_undef.m:
    As above.

tests/invalid/field_syntax_error.err_exp:
    Expect the new output.
2025-12-27 01:05:16 +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
8ae645feb8 Delete an old relic. 2025-12-13 09:53:09 +11:00
Zoltan Somogyi
b492978134 Stop putting never-read entries in a map.
compiler/options_file.m:
    Stop putting entries for environment variables into the map for
    options variables, since the hit on the variable name in the environment
    variable map will cause them to always be ignored.

    After the above change, all entries in the map for options variables
    actually come from options files (some of which are called configuration
    files), so stop recording a source kind for each entry.

    Document the updated relationship between the two maps.

    Document the choice the two possible ways we can handle errors in
    the values of environment variables that represent Mercury options.

tests/options_file/basic_test.optfile_exp:
    Stop expecting the now-deleted source kind flags.
2025-12-12 09:04:22 +11:00
Zoltan Somogyi
084d28807d Document the interface to run_one_test. 2025-12-11 13:36:46 +11:00
Zoltan Somogyi
5210294e92 Clarify a comment. 2025-12-11 13:36:24 +11:00
Zoltan Somogyi
2402a91705 Rename two test cases.
tests/hard_coded/Mmakefile:
    Rename multi_arm_switch.m to multi_arm_switch_1.m, since there is
    also a separate test named multi_arm_switch_2.m.

    Shorten the name of the trans_intermod_user_equality test case
    to trans_intermod_user_eq.

tests/hard_coded/Mercury.options:
    As above.

    Fix references to trans_intermod_user_eq's helper modules.

tests/hard_coded/multi_arm_switch_1.exp:
tests/hard_coded/multi_arm_switch_1.inp:
tests/hard_coded/multi_arm_switch_1.m:
tests/hard_coded/trans_intermod_user_eq.exp:
tests/hard_coded/trans_intermod_user_eq.m:
tests/hard_coded/trans_intermod_user_eq_helper_1.m:
tests/hard_coded/trans_intermod_user_eq_helper_2.m:
2025-12-07 10:16: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
f9dcac624e Expand try goals inside lambda expressions.
compiler/try_expand.m:
    As above.

tests/valid/try_inside_lambda.m:
    A minimal version of Volker's test case, with English names.

tests/valid/Mmakefile:
    Enable the new test case.
2025-12-02 18:32:35 +11:00
Zoltan Somogyi
0aff352a12 Add a specific warning for "!V ^ fn = ...".
compiler/parse_goal.m:
    As above.

tests/invalid/field_syntax_error.{m,err_exp}:
    Extend this test case with a test of the new warning.
    Document its old as well as its new parts.
2025-11-30 03:38:12 +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
fb69294bc7 Put entries into lexicographic order. 2025-11-17 11:30:38 +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
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
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
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
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
Zoltan Somogyi
b200344394 Update expected outputs for cord test cases. 2025-10-29 16:04:31 +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
4ba3ef8602 Include field access functions in "did you mean" suggestions.
compiler/typecheck_error_undef.m:
    As above.

tests/invalid/bad_field.{m,err_exp}:
    A test case for this capability.

tests/invalid/Mmakefile:
    Enable the new test case.
2025-10-21 19:26:23 +11:00
Zoltan Somogyi
23768fc571 Improve diagnostics for type ambiguities.
compiler/typecheck_error_overload.m:
    When reporting type a type ambiguity that is itself an error
    (as opposed to being problematic *only* because it increases
    the number of type assigns needed), do NOT use terminology
    that implies that the problem is the sheer number of ambiguities.
    Indeed, the main test case of this code, bad_ambiguity_msg,
    involves just one predicate name that has two matches,
    which is the lowest possible level of ambiguity that
    deserves an error message.

    The old code used this bad terminology becaused it reused
    the code of the function that reported exceededing the
    ambiguity warning limit. Another effect of this bad reuse,
    apart from the bad wording of the always-printed message,
    was the addition of a verbose-only hint about the way to fix
    the excessive ambiguity, which is totally misleading in this
    situation.

    In the absence of this reuse, we can now simplify the operation
    of the code that generates warnings and errors about too much
    overloading.

    In some cases, eliminate some repetition in the diagnostic text.

tests/invalid/Mercury.options:
    Specify the printing of verbose-only parts of diagnostics.
    With this enabled, the inappropriateness of the reuse
    would have been immediately apparent.

tests/invalid/bad_ambiguity_msg.err_exp:
    Expect the updated wording. Do not expect a reminder about
    any verbose-only part, since now there is none.

tests/invalid/coerce_ambig.{m,err_exp}:
    Test for reporting not just one variable being ambiguous,
    but also for two variables being ambiguous. (Together,
    these exercise both paths through the relevant code.)
2025-10-17 15:05:16 +11:00
Zoltan Somogyi
c4ef3a35ef Better diagnostics for var/functor type mismatches.
compiler/typecheck_error_unify.m:
    As above.

compiler/hlds_error_util.m:
compiler/typecheck_error_util.m:
    Export operations that are now needed by typecheck_error_unify.m.
    To make this possible, carve some of those operations out of
    other operations.

tests/invalid/ho_type_arity_bug.err_exp:
tests/invalid/missing_closure_arg.err_exp:
tests/invalid/nullary_ho_func_error.err_exp:
tests/invalid_nodepend/errors_2.err_exp:
tests/invalid_purity/impure_func_t5.err_exp:
tests/invalid_purity/impure_pred_t1.err_exp:
    Expect the updated diagnostics.
2025-10-14 23:21:37 +11:00
Zoltan Somogyi
e5b4e5813d Test diagnostics for missing clause arguments. 2025-10-14 12:25:35 +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
c643291d1f Add cons_list and snoc_list to cord.m.
library/cord.m:
    Add those two new predicates.

NEWS.md:
    Announce the additions.

compiler/*.m:
    Use snoc_list in many places.

tests/hard_coded/test_cord_2.{m,exp}:
    Extend this test case to test cons_list.
2025-10-10 18:48:26 +11:00