Commit Graph

1537 Commits

Author SHA1 Message Date
Julien Fischer
e3cc72cb0b Fix bug in term_io.format_term_nl/5.
library/term_io.m:
     foramt_term_nl/5 should call format_term_nl_with_op_table/6, *not*
     format_term_with_op_table/6, otherwise the terminating ".\n" will
     not be written.

tests/hard_coded/Mmakefile:
tests/hard_coded/format_term_nl.{exp,m}:
     Add a regression test.
2026-02-20 16:03:18 +11:00
Julien Fischer
7f771cb245 Fix rbtree.count and rbtree.ucount.
These were inadvertently broken by updates to programming style in
commit 185443d79.

library/rbree.m:
    In the implementation of ucount, increment the count for the
    current node.

tests/hard_coded/Mmakefile:
tests/hard_coded/rbtree_count.{m,exp}:
    Add a regression test.
2026-02-20 13:40:40 +11:00
Julien Fischer
778e75f696 Fix problems in the library.
library/array.m:
library/builtin.m:
library/construct.m:
    Fix copy-and-paste errors.

library/arrayd2d.m:
    Use the mode array2d_di instead of array_di in a spot.

    Delete an extra space from an exception message.

library/bimap.m:
    Fix formatting.

library/bit_buffer.m:
    Fix inverted argument types.

library/dir.m:
    Say that make_single_directory/4 returns an error rather
    than saying that it fails.

library/io.m:
    Fix errors in obsolete pragmas.

library/assoc_list.m:
library/bag.m:
library/cord.m:
library/deconstruct.m:
library/enum.m:
library/fat_sparse_bitset.m:
library/getopt*.m:
library/int*.m:
library/io*.m:
library/type_desc.m:
    Fix documentation errors.

tests/hard_coded/array2d_from_array.exp:
    Conform to the changed exception message in array2d.m.
2026-02-19 15:24:59 +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
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
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
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
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
b200344394 Update expected outputs for cord test cases. 2025-10-29 16:04:31 +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
Zoltan Somogyi
cc654dd2e6 Fix typo. 2025-10-09 05:08:55 +11:00
Zoltan Somogyi
36dc154ceb Fix two failing C# tests.
tests/general/read_dir_regression.m:
    Fix the code that canonicalized error messages for C#.
    It probably broke when we added a "can't open input file:" prefix
    to the error message, because the quote in "can't" confused it.

tests/hard_coded/foreign_import_module.m:
tests/hard_coded/foreign_import_module_helper_1.m:
    Fix several things to make this test case work.

    - Add a foreign_import_module pragma for the helper module.
      There was one originally, but it was marked as being for "il",
      and the pragma was deleted, not replaced, when the IL backend
      was deleted.

    - Refer to the foo function and the foo2 predicate that
      the main module imports from the helper module by their
      actual names in the compiler-generated C# code.
      (The old names the test used were probably IL-specific,
      though I am not sure.)

    - Invoke the foo function as a function; we used to invoke it as
      a predicate. (The C# calling convention may have changed
      in the meantime, and in fact, the original convention could have
      been for Managed C++ instead.)

    - Make the predicate exported by the C# foreign_code in the
      helper module public.

    - Initialize a variable passed by reference in order to avoid
      an error message from the C# compiler.

    Add an XXX about the code of foreign_import_module.m containing
    two just-about-identical halves.

tests/EXPECT_FAIL_TESTS.csharp:
    Stop expecting the foreign_import_module test case to fail.

tests/hard_coded/dst_test.m:
    Improve programming style, and fix some typos.
2025-10-09 01:34:13 +11:00
Julien Fischer
b2ebb02990 Fix a failing test case.
The test case hard_coded/intermod_foreign_type is failing in the C# grades due
to a missing foreign_type pragma. When originally added this test case had a
foreign_type pragma for IL, but at some point that was deleted (presumably at
the same time the IL backend was removed). This meant that for C# grades, the
coord/0 type would default to its Mercury definition, which conflicts with
the handwritten definition used by the C# foreign_procs.
The fix is to add a C# foreign_type pragma.

tests/hard_coded/intermod_foreign_type.m:
tests/hard_coded/intermod_foreign_type_helper_1.m:
    Add a missing c# foreign_type pragma.

    Delete unused imports.
2025-10-05 15:56:34 +11:00
Julien Fischer
8a6756d307 Update expected outputs for hard_coded/parse_number_from_string.
The expected outputs for the Java and C# grades were not updated after commit
ac57c2f70.

tests/hard_coded/parse_number_from_string.exp[23]:
     Update the expected outputs for this test for Java and C# grades.

tests/hard_coded/parse_number_from_string.m:
     Document what the expected outputs are for.
2025-10-01 16:31:40 +10:00
Zoltan Somogyi
3791da71dd Make a stress test better for benchmarking. 2025-09-24 08:29:52 +10:00
Zoltan Somogyi
7c42c97018 Format sparse_bitset docs as lists of ints.
library/pretty_printer.m:
    Register default handlers for sparse bitsets of all forms.
    Since we no way to find the from_uint methods needed to turn
    each uint in the set back to the value it came from, print
    the uints themselves, since that is still much better than nothing.

tests/hard_coded/test_pretty_printer_defaults.{m,exp}:
    Add tests of all the new handlers.
2025-09-23 15:36:48 +10:00
Julien Fischer
4f34f43317 Fix pretty_printer's handling of uint32s.
library/pretty_printer.m:
    s/int32/uint32/ in a spot.

tests/hard_coded/test_pretty_printer_defaulte.exp:
    Conform to the above change.
2025-09-20 17:30:09 +10:00
Zoltan Somogyi
5b32cd1e9a Rename test cases away from pragma_c_code. 2025-09-16 15:08:45 +10:00
Zoltan Somogyi
a4e03986e5 Update module qualifiers after module rename. 2025-09-12 13:25:33 +10:00
Zoltan Somogyi
80943c1142 Fix some Java/C# test case failures.
library/rtti_implementation.m:
    Return zero arity for null TypeInfo.args arrays. This fixes the
    failure of the hard_coded/pretty_printing test case in the Java grade,
    and probably in the C# grade as well.

tests/general/read_dir_regression.m:
    Fix the failure of the failure of this test case in the Java grade,
    by massaging the error message returned for an intentionally-failed
    open of a directory as a plain file. When opening ".", the error message
    (on my laptop, at least) returns the full absolute path name of the
    current directory. Since this will be different in different workspaces,
    we can't update the expected output file, but we can replace this
    changeable part of the error message with a fixed string. This diff
    does this.

tests/hard_coded/ho_solns.m:
    Add a note about the cause of the failure of this test case.

tests/hard_coded/string_code_point.exp2:
    Conform to the old switchover from the "codepoint" spelling
    to "code_point".
2025-09-04 23:44:40 +02:00
Zoltan Somogyi
078d110e23 Avoid an unneeded warning. 2025-09-03 18:12:39 +02:00
Zoltan Somogyi
ca7385d2c7 Generate better diagnostics for parentheses mismatches.
When you have an unclosed (, [ or { in a clause, the diagnostic
you got did not tell you

- where the unclosed parenthesis was,
- which kind of parenthesis it was.

Fix this by including both pieces of information in the diagnostic.

Likewise, print more useful info for mixed-up parentheses,
such as [(]).

library/mercury_term_parser.m:
    When consuming a (, [ or { token, push it and its context on a stack.
    When consuming a ), ] or } token, pop off the top item from this stack,
    and generate a diagnostic if the close token does not match it.
    The one exception from this pushing and pulling is for code that
    handles the case where the open is followed immediately by
    the matching close, such as when parsing [] or {}.

    Print the contents of the stack also when getting to either
    the end of the term, or the end of the input, with a nonempty stack.

    Maintaining this stack has a small performance cost, but I expect
    it to be negligible, especially compared to the usefulness
    of the new detail in diagnostics,

    Completely rework the error handling parts of this module.
    The main changes are the following.

    First, the old code used to include *part* of the intended message
    in the pr_error structures it created, with a "Syntax error: "
    prefix being added later. Since this makes it hard to ensure
    that the error messages follow the rules of English, change this
    to generate each error message all at once.

    Second, the old code included the list of the remaining tokens
    in each pr_error structure. This was overkill, because the only part
    of this list that was used was the id and the context of the
    first token in the list. Apart from being inelegant, the main flaw
    of this approach was that in the case of premature end-of-file
    errors, the only token list available was token_nil, which
    of course contains neither a token nor its context. The old code
    compensated for it later by using the context of the *first* token
    of the whole term being parsed, which is ... less than useful.
    (The missing token is trivially replaced by "end-of-file".)

    The new code replaces the token list with the context, if it
    is available; if it is not, then later we compute the context
    of the last token in the whole token list. The new code
    does not return the token itself; instead, it includes
    its string version in the generated error message where appropriate.

    Third, as mentioned above, we now include info about unbalanced
    (), [] and {} pairs in diagnostics, as extra sentences.
    (These extra sentences are preceded by \n characters;
    see the change to parse_module.m below.)

    Fifth, to make the above possible without adding unnecesary
    complications, the diagnostic texts this module generates
    now always include the period at the ends of sentences:
    they are not added by the compiler.

    Fourth, we now consistently use "Syntax error at token abc:
    expected def, fgh, or xyz" phraseology.

library/mercury_term_lexer.m:
    Stop requiring the customers of this module to handle

    - integer_dot tokens, which are needed only by, and are
      an implementation detail of, the get_* family of predicates, and

    - eof tokens, which the lexer also never returns, converting each one
      into the end of its token list instead.

    The fact that the lexer never returned integer_dot tokens was
    documented, but the fact that it never returned eof tokens was not.

    The reason for this change was simply that I did not want to write
    two pieces of code to handle the out-of-input case in each affected
    spot in the parser: once for an eof token, and once for token_nil.

library/stack.m:
    Add a utility function needed by new code in mercury_term_parser.m.

compiler/parse_module.m:
    Stop adding a period at the ends of error messages generated by
    mercury_term_parser.m; mercury_term_parser.m now adds those itself.
    Do post-process those messages by turning any \n characters in them
    into nl format_pieces.

NEWS.md:
    Announce the change in mercury_term_lexer.m, and the
    new function in stack.m.

library/io.text_read.m:
    Unrelated bug fix, for which I discovered the need while
    working on the other library files: add a missing foreign import.

tests/invalid_nodepend/unbalanced.{m,err_exp}:
    A new test case to check the updated diagnostics.

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

tests/hard_coded/parse_number_from_string.exp:
tests/invalid_nodepend/impl_def_literal_syntax.err_exp:
tests/invalid_nodepend/invalid_binary_literal.err_exp:
tests/invalid_nodepend/invalid_float_literal.err_exp:
tests/invalid_nodepend/invalid_hex_literal.err_exp:
tests/invalid_nodepend/invalid_octal_literal.err_exp:
tests/invalid_nodepend/null_char.err_exp:
tests/invalid_nodepend/typeclass_test_1.err_exp:
tests/invalid_nodepend/unicode_1.err_exp:
tests/invalid_nodepend/unicode_2.err_exp:
tests/invalid_purity/purity_nonsense_2.err_exp:
    Expect the updated diagnostics.
2025-07-30 01:37:28 +02:00
Zoltan Somogyi
7d0d0ae17c Delete leftover references to --inline-linear-tail-rec-sccs.
tests/hard_coded/Mercury.options:
tests/valid/Mercury.options:
    Delete left-over references.

    Break up too-long lines.

tests/valid/mutual_tailrec_outputs.m:
    Document that the option that this test case tests is deleted.
2025-07-10 09:52:22 +02:00
Zoltan Somogyi
f70b5d6de7 Implement options to warn about unused state vars.
The new --warn-unneeded-initial-statevar option asks the compiler
to warn about code such as

    pred_a(!.X, ...) :-
        ... code that uses !.X, but does not update it ...

In this case, the preferred fix is to just replace all occurrences
of !.X with X.

The new --warn-unneeded-final-statevar option asks the compiler
to warn about code such as

    pred_a(!X, ...) :-
        ... code that maybe uses !.X, but does not update it ...

In this case, the preferred fix also involves replacing all occurrences
of !.X with X, but it also involves either deleting the argument
containing !:X (the best option), or, if there is some reason why
the predicate's signature must stay unchanged, to replace !:X with X as well.
And if the clause body does not actually refer to either !.X or !:X, then
*both* arguments represented by !X should be deleted.

The first option is a style warning; the second option, due to the
signature change it may call for, is a non-style warning.

Both options have a version whose name adds a "-lambda" suffix, and which
does the same warnings for the heads of lambda expressions, not clauses.

Note that several of the modules below, including some that help to implement
the warnings, also contain code changes that result from *acting* on
the new warnings, e.g. by deleting unneeded statevar arguments.
Other, similar changes will also come after this diff is committed.

compiler/options.m:
doc/user_guide.texi:
    Document the new options.

compiler/state_var.m:
    Gather the information needed to decide what code merits the new warnings.
    Do so in three stages:

    - when processing the head of a clause or of a lambda expression,
    - when processing the body goal of that clause or lambda expression,
    - when finishing up the processing of the clause or lambda expression.

    Add a predicate to generate the warnings for lambda expressions.

    Do not generate the warnings for clauses. This is because whether or not
    we want to warn about state vars in some clauses depends on the properties
    of *other* clauses of the same predicate, and state_var.m has access
    to only one clause at a time. Instead,

    - return the info needed by the warning-generating code in pre_typecheck.m
      (one of the first passes we execute after adding all clauses
      to the HLDS), and

    - we export some functionality for use by that code.

    Switch to a convention for naming the program variables corresponding
    to the middle (non-initial, non-final) versions of state variables
    whose output is affected by changes in the code of the clause body goal
    only if they involve that specific state variable.

    Give some predicates more descriptive names.

compiler/make_hlds.m:
    Make state_var.m and its new functionality visible from outside
    the make_hlds package.

compiler/add_clause.m:
    Record the information gathered by state_var.m in each clause.

compiler/hlds_clauses.m:
    Add a slot to each clause for this information.

    Give some predicates more descriptive names.

compiler/headvar_names.m:
    Use the contents of the new slots to detect whether any clauses
    have unused state vars, and if so, return the chosen consensus names
    of the head vars to the code of pre_typecheck.m, which uses this info
    as part of the implementation of the new warnings.

compiler/pre_typecheck.m:
    Implement the new warnings.

compiler/mercury_compile_front_end.m:
    Record the warnings that pre_typecheck.m can now return.

compiler/error_spec.m:
compiler/write_error_spec.m:
    Add unsigned versions of the format pieces involving ints, for use
    by the new code in pre_typecheck.m, and implement them.

compiler/hlds_out_util.m:
compiler/maybe_util.m:
    Move two related types from hlds_out_util.m to maybe_util.m,
    in order to allow pre_typecheck.m to use one of them.

compiler/hlds_args.m:
    Add a new utility function for use by the new code above.

compiler/foreign.m:
    Act on the new warnings by deleting the long-unused predicates
    being warned about.

compiler/post_typecheck.m:
    Speed up this traversal. (I originally thought to implement
    the new warnings in this pass.)

compiler/add_foreign_proc.m:
compiler/add_pragma.m:
compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/add_type.m:
compiler/build_mode_constraints.m:
compiler/call_gen.m:
compiler/check_typeclass.m:
compiler/clause_to_proc.m:
compiler/code_loc_dep.m:
compiler/delay_info.m:
compiler/delay_partial_inst.m:
compiler/dense_switch.m:
compiler/det_check_goal.m:
compiler/det_infer_goal.m:
compiler/disj_gen.m:
compiler/du_type_layout.m:
compiler/format_call.m:
compiler/goal_expr_to_goal.m:
compiler/hlds_dependency_graph.m:
compiler/hlds_out_pred.m:
compiler/hlds_pred.m:
compiler/hlds_rtti.m:
compiler/inst_merge.m:
compiler/instance_method_clauses.m:
compiler/intermod.m:
compiler/interval.m:
compiler/ite_gen.m:
compiler/lookup_switch.m:
compiler/make_hlds_passes.m:
compiler/mark_tail_calls.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mode_errors.m:
compiler/parse_string_format.m:
compiler/passes_aux.m:
compiler/polymorphism.m:
compiler/polymorphism_info.m:
compiler/polymorphism_type_info.m:
compiler/pragma_c_gen.m:
compiler/prop_mode_constraints.m:
compiler/purity.m:
compiler/quantification.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_conj.m:
compiler/string_switch.m:
compiler/superhomogeneous.m:
compiler/switch_gen.m:
compiler/tag_switch.m:
compiler/type_constraints.m:
compiler/typecheck.m:
compiler/typecheck_clauses.m:
compiler/typecheck_coerce.m:
compiler/typecheck_error_unify.m:
compiler/unify_gen_deconstruct.m:
compiler/unify_proc.m:
compiler/var_origins.m:
    Conform to the changes above, and/or act on the new warnings.

browser/diff.m:
library/bit_buffer.m:
library/getopt.m:
library/getopt_io.m:
library/io.error_util.m:
library/io.file.m:
library/mercury_term_lexer.m:
library/parsing_utils.m:
library/pretty_printer.m:
library/robdd.m:
library/rtti_implementation.m:
library/string.builder.m:
library/string.parse_runtime.m:
mdbcomp/feedback.m:
    Act on the new warnings.

tests/hard_coded/sv_nested_closures.m:
    Change this test's code to avoid the new warnings, since
    (if --halt-at-warn is ever enabled) the warnings would interfere
    with its job .

tests/invalid/bug197.err_exp:
tests/invalid/bug487.err_exp:
tests/invalid/nullary_ho_func_error.err_exp:
tests/invalid/try_detism.err_exp:
tests/warnings/singleton_test_state_var.err_exp:
    Expect variable names for the middle versions of state vars
    using the new naming scheme.
2025-05-18 06:43:24 +10:00
Zoltan Somogyi
02c4f5b7ce s/codepoint/code_point/ in test case names. 2025-02-20 23:48:10 +11:00
Zoltan Somogyi
38f1f5faf2 Shut up many warnings in executable test dirs.
tests/hard_coded/bitmap_test_helper_1.m:
tests/hard_coded/curry_2_helper_1.m:
tests/hard_coded/deep_copy_bug.m:
tests/hard_coded/erroneous_liveness.m:
tests/hard_coded/foreign_type_1.m:
tests/hard_coded/hash_table_test.m:
tests/hard_coded/ho_float_reg.m:
tests/hard_coded/impl_def_lex_string.m:
tests/hard_coded/impure_foreign.m:
tests/hard_coded/intermod_multimode_helper_1.m:
tests/hard_coded/multimode.m:
tests/hard_coded/qual_is_test.m:
tests/hard_coded/string_codepoint.m:
tests/hard_coded/string_codepoint_offset_ilseq.m:
tests/hard_coded/string_count_codepoints_ilseq.m:
tests/hard_coded/string_set_char.m:
tests/hard_coded/version_hash_table_test_2.m:
tests/submodules/parent_t2.m:
tests/typeclasses/arbitrary_constraint_pred_1.m:
tests/typeclasses/arbitrary_constraint_pred_2.m:
tests/typeclasses/instance_unconstrained_tvar_type_spec.m:
tests/typeclasses/typeclass_order_bug_1.m:
    Change code to avoid compiler warnings where this is (a) possible,
    and (b) does not interfere with the purpose of the test.

tests/hard_coded/string_codepoint.exp:
tests/hard_coded/string_codepoint_offset_ilseq.exp:
tests/hard_coded/string_codepoint_offset_ilseq.exp2:
    The changes to the source files of these tests changed all references
    to "codepoint" to "code_point", including in the text they output.
    Expect the updated output.

tests/general/Mercury.options:
tests/hard_coded/Mercury.options:
tests/typeclasses/Mercury.options:
tests/submodules/Mercury.options:
    Disable many of the remaining warnings.
2025-02-20 23:11:53 +11:00
Julien Fischer
2bf48dbec6 Change some predicate argument orders in the ranges module.
library/ranges.m:
    Change the argument order of nondet_member/2 and nondet_range_member/3 so
    that their ranges argument is first.

NEWS.md:
    Announce the change.

tests/hard_coded/test_ranges.m:
    Conform to the above change.
2025-01-10 20:36:32 +11:00
Julien Fischer
369e24a49a Extend testing of the ranges module.
Document some exception conditions in the ranges module.

library/ranges.m:
    Document the when insert and delete will throw an exception.

tests/test_ranges.{m,ex}:
    Test that attempting to construct a ranges value containing min_int
    results in an exception being thrown. To do this without hardcoding
    machine-specific values in the expected value, extend the code used
    to print ranges to output symbolic names for {min,max}_int.

    Fix spelling.
2025-01-10 17:11:57 +11:00
Julien Fischer
e58e36f355 Being addressing issues in the ranges module.
Extend testing of the ranges module.

library/ranges.m:
    Address a bunch of issues that were previously identified by notes to
    implementors and/or XXXs. This involves:

    1. adding state variable friendly predicate versions of many of the
    functions.

    2. replacing some predicates or functions with equivalent ones whose names
    are consistent with the usual names used in set-like modules. The existing
    versions have been marked as obsolete.

    3. adding some operations that the other set-like modules provide, but this
    one does not.

NEWS.md:
    Announce the above.

tests/hard_coded/test_ranges.{m,exp}:
    Test newly added operations and conform to renamings.

    Extend the construction tests to check that we do not allow the
    inclusion of min_int in ranges.
2025-01-06 02:43:39 +11:00
Julien Fischer
6fb942d079 More comprehensive testing of the ranges module.
The existing test of the ranges module in the test suite consists of an
assortment of miscellaneous regression tests inherited from G12. Extend
this test to cover all of the predicates and functions exported by the
ranges module.

tests/hard_coded/test_ranges.{m,exp}:
    As above.

tests/hard_coded/Mmakefile:
    Move test_ranges to the list of tests that are *not* run in
    deep profiling grades since it now catches exceptions.
2025-01-05 16:43:16 +11:00
Zoltan Somogyi
63215891e9 Fix typo. 2025-01-02 15:36:48 +11:00
Zoltan Somogyi
a9376f2bd3 Replace an if-then-else chain with two switches.
library/string.to_string.m:
    Replace a long series of dynamic cast tests with a switch on the
    id of the type of the value we are trying to convert to a string.
    Besides being clearer, the new code is also faster. To help the latter
    along, also change the code of det_dynamic_casts to avoid a memory
    allocation.

    In the process, fix an old oversight: treat int64 and uint64 values
    the same way as we treat other sized integers.

tests/hard_coded/uint64_switch_test.exp:
    Expect that updated treatment.
2025-01-01 18:59:27 +11:00
Zoltan Somogyi
9fd51ae7af Add --deep-std-name option to control deep prof file names.
When this new runtime option is specified, the runtime system will use
Deep.{data,procrep} as the names of the files it writes out.

runtime/mercury_engine.h:
    Add a flag to the engine that records whether this option has been
    specified or not.

runtime/mercury_wrapper.c:
    Set the flag if/when we see the --deep-std-name option.

runtime/mercury_deep_profiling.c:
    If the new flag is set, use Deep.{data,procrep} as filenames.

doc/user_guide.texi:
    Document the new option.

tools/bootcheck:
    Specify the new option for bootchecks.

tests/debugger/Mmakefile:
tests/declarative_debugger/Mmakefile:
tests/hard_coded/Mmakefile:
tests/par_conj/Mmakefile:
tests/stm/Mmakefile:
    When specifying a value of MERCURY_OPTIONS that overrides the value
    set by tools/bootcheck, include --deep-std-name in that value.
2024-10-13 19:47:06 +11:00
Zoltan Somogyi
ec97594862 Use test case numbers according to our conventions ...
... in some previously overlooked test cases.

tests/debugger/Mercury.options:
tests/debugger/Mmakefile:
tests/debugger/completion.completion_helper_1.m:
tests/debugger/completion.completion_helper_2.completion_helper_3.m:
tests/debugger/completion.completion_helper_2.m:
tests/debugger/completion.exp:
tests/debugger/completion.inp:
tests/debugger/completion.m:
    Rename completion.sub1.m to completion.completion_helper_1.m,
    rename completion.sub2.m to completion.completion_helper_2.m, and
    rename completion.sub2.sub3.m to
    completion.completion_helper_2.completion_helper_3.m.

tests/debugger/poly_io_retry_1.exp:
tests/debugger/poly_io_retry_1.inp:
tests/debugger/poly_io_retry_1.m:
tests/debugger/poly_io_retry_2.exp:
tests/debugger/poly_io_retry_2.inp:
tests/debugger/poly_io_retry_2.m:
    Rename poly_io_retry/poly_io_retry2 to poly_io_retry_[12].

tests/debugger/shallow.exp:
tests/debugger/shallow.m:
tests/debugger/shallow_helper_1.m:
    Rename shallow2.m to shallow_helper_1.m.

tests/debugger/user_event_1.exp:
tests/debugger/user_event_1.inp:
tests/debugger/user_event_1.m:
    Rename user_event to user_event_1, due to the existence of user_event_2.

tests/general/Mmakefile:
tests/general/det_complicated_unify_1.exp:
tests/general/det_complicated_unify_1.m:
tests/general/det_complicated_unify_2.exp:
tests/general/det_complicated_unify_2.m:
    Rename det_complicated_unify/det_complicated_unify2 to
    det_complicated_unify_[12]. Note: only det_complicated_unify_1
    is currently enabled.

tests/general/double_error_1.exp:
tests/general/double_error_1.m:
tests/general/double_error_2.exp:
tests/general/double_error_2.m:
    Rename double_error/double_error2 as double_error_[12].

tests/general/liveness_1.exp:
tests/general/liveness_1.m:
tests/general/liveness_2.exp:
tests/general/liveness_2.m:
    Rename liveness/liveness2 as liveness_[12].

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/user_defined_equality_1.exp:
tests/hard_coded/user_defined_equality_1.m:
tests/hard_coded/user_defined_equality_2.exp:
tests/hard_coded/user_defined_equality_2.m:
    Rename user_defined_equality/user_defined_equality2 as
    user_defined_equality_[12].

tests/tabling/Mmakefile:
tests/tabling/expand_tuple_1.exp:
tests/tabling/expand_tuple_1.m:
tests/tabling/expand_tuple_2.exp:
tests/tabling/expand_tuple_2.m:
    Rename expand_tuple/expand_tuple2 as expand_tuple_[12].
2024-08-12 15:24:24 +02:00
Zoltan Somogyi
6e5b9ca8c8 Make some predicates' arg order state var friendly.
library/injection.m:
    As above.

NEWS.md:
    Announce this breaking change.

tests/hard_coded/test_injection.m:
    Conform to the new argument orders.
2024-08-09 22:36:45 +02:00
Zoltan Somogyi
f32a26b4b3 Make the from_int method in enum cless a predicate.
library/enum.m:
    As above.

NEWS.md:
    Announce this breaking change.

library/bool.m:
library/char.m:
library/int.m:
library/term.m:
library/uint.m:
tests/hard_coded/deep_copy_exist.m:
tests/typeclasses/extract_typeinfo2.m:
    Conform to the change in enum.m.

compiler/pred_table.m:
    When typechecking leaves am ambiguity unresolved, a predicate
    in this module used to pick one of the candidate matches effectively
    at random to "resolve" it.

    After the change to enum.m, this led to a compiler abort when compiling
    uint.m. The ambiguity was between uint.from_int/2 and the new
    enum.from_int/2. The old algorithm picked enum.from_int/2, and tried
    to look up its class constraints in the current class context; this failed
    with an abort, because the current class context was empty.

    Fix this by choosing the match (or *a* match) with the fewest typeclass
    constraints to "resolve" any ambiguities.

tests/invalid/overload_resolution_preference.{m,err_exp}:
    A test case for the change to pred_table.m.

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

tests/invalid_submodules/unresolved_overloading.err_exp:
    Update this expected output after the change to pred_table.m.
2024-08-09 21:43:03 +02:00
Zoltan Somogyi
4df3cfbbd8 Add back an accidentally deleted test case. 2024-08-09 20:00:58 +02:00
Zoltan Somogyi
89b05266a1 Provide alternatives to can-fail library functions.
library/array.m:
library/assoc_list.m:
library/bimap.m:
library/bitmap.m:
library/construct.m:
library/deconstruct.m:
library/dir.m:
library/hash_table.m:
library/injection.m:
library/io.stream_db.m:
library/kv_list.m:
library/list.m:
library/map.m:
library/robdd.m:
library/stream.string_writer.m:
library/term_conversion.m:
library/term_to_xml.m:
library/tree234.m:
library/type_desc.m:
library/version_hash_table.m:
    For nearly every ordinary function in this directory that can fail in its
    primary mode (all of which were semidet functions),

    - provide a semidet predicate as an alternative, if it did not
      already exist,

    - implement the function in terms of the predicate, instead of vice versa,

    - mark the semidet function as obsolete in favor of the semidet predicate
      version,

    - fix all the resulting warnings, and then

    - comment out the obsolete pragmas (at least for now).

    Note that this diff does not touch the semidet function in the
    enum typeclass, or the functions that implement that method
    in instances.

NEWS.md:
    Announce the new predicates in the (documented) modules of the library.

browser/term_rep.m:
compiler/lp_rational.m:
compiler/mcsolver.m:
compiler/mode_ordering.m:
compiler/mode_robdd.equiv_vars.m:
compiler/mode_robdd.implications.m:
compiler/old_type_constraints.m:
compiler/pickle.m:
compiler/prog_event.m:
compiler/type_ctor_info.m:
compiler/var_table.m:
tests/hard_coded/bitmap_empty.m:
tests/hard_coded/construct_mangle.m:
tests/hard_coded/construct_packed.m:
tests/hard_coded/construct_test.m:
tests/hard_coded/dummy_type_construct.m:
tests/hard_coded/expand.m:
tests/hard_coded/foreign_enum_rtti.m:
tests/hard_coded/subtype_rtti.m:
tests/hard_coded/term_to_univ_test.m:
tests/hard_coded/type_to_term.m:
tests/hard_coded/type_to_term_bug.m:
    Stop calling the semidet functions from the library that were temporarily
    marked obsolete.

    In a few places, add explicit type qualification to avoid warnings
    about unresolved polymorphism.

tests/hard_coded/test_injection.exp:
    Expect an abort message from the predicate version of a semidet function.

tests/declarative_debugger/ho_2.exp2:
    Update this .exp file for a previous commit.
2024-08-09 09:14:46 +02:00
Zoltan Somogyi
bb56144303 Use test case numbers according to our conventions ...
... in the remaining test case directories.

tests/hard_coded/write_reg_1.exp[2345]:
    Rename these files to complete the update to the hard_coded test dir.

tests/invalid/Mmakefile:
tests/invalid/coerce_mode_error_1.err_exp:
tests/invalid/coerce_mode_error_1.m:
tests/invalid/coerce_mode_error_2.err_exp:
tests/invalid/coerce_mode_error_2.m:
    Rename the coerce_mode_error and coerce_mode_error2 test cases
    to coerce_mode_error_[12].

tests/tabling/Mercury.options:
tests/tabling/Mmakefile:
tests/tabling/coup_1.exp:
tests/tabling/coup_1.m:
tests/tabling/coup_2.exp:
tests/tabling/coup_2.m:
tests/tabling/coup_3.exp:
tests/tabling/coup_3.m:
tests/tabling/coup_4.exp:
tests/tabling/coup_4.m:
    Rename the coup and coup[233] test cases to coup_[1234].

tests/tabling/seq_1.exp:
tests/tabling/seq_1.m:
tests/tabling/seq_2.exp:
tests/tabling/seq_2.m:
tests/tabling/seq_3.exp:
tests/tabling/seq_3.m:
tests/tabling/seq_4.exp:
tests/tabling/seq_4.m:
    Rename the seq and seq[233] test cases to seq_[1234].

tests/tabling/tc_memo_1.exp:
tests/tabling/tc_memo_1.m:
tests/tabling/tc_memo_2.exp:
tests/tabling/tc_memo_2.m:
    Rename the tc_memo and tc_memo2 test cases to tc_memo_[12].

tests/tabling/tc_minimal_1.exp:
tests/tabling/tc_minimal_1.m:
tests/tabling/tc_minimal_2.exp:
tests/tabling/tc_minimal_2.m:
    Rename the tc_minimal and tc_minimal2 test cases to tc_minimal_[12].

tests/trailing/Mercury.options:
tests/trailing/Mmakefile:
tests/trailing/func_trail_test_1.exp:
tests/trailing/func_trail_test_1.m:
    Rename the func_trail_test test case to func_trail_test_1,
    due to the existence of func_trail_test_2.

tests/trailing/tu_test_1.exp:
tests/trailing/tu_test_1.m:
tests/trailing/tu_test_2.exp:
tests/trailing/tu_test_2.m:
    Rename the tu_test[12] test cases to tu_test_[12].

tests/typeclasses/Mercury.options:
    Fix an old oversight by updating a previously-changed module name.

tests/typeclasses/Mmakefile:
tests/typeclasses/ground_constraint_1.exp:
tests/typeclasses/ground_constraint_1.m:
    Rename the ground_constraint test case to ground_constraint_1,
    due to the existence of ground_constraint_2.

tests/typeclasses/inference_test_1.exp:
tests/typeclasses/inference_test_1.m:
    Rename the inference_test test case to inference_test_1,
    due to the existence of inference_test_2..

tests/typeclasses/superclass_bug_1.exp:
tests/typeclasses/superclass_bug_1.m:
tests/typeclasses/superclass_bug_2.exp:
tests/typeclasses/superclass_bug_2.m:
tests/typeclasses/superclass_bug_3.exp:
tests/typeclasses/superclass_bug_3.m:
    Rename the superclass_bug and superclass_bug[23] test cases
    to superclass_bug_[123].

tests/typeclasses/typeclass_exist_method_1.exp:
tests/typeclasses/typeclass_exist_method_1.m:
    Rename the typeclass_exist_method test case to typeclass_exist_method_1,
    due to the existence of typeclass_exist_method_2.

tests/typeclasses/typeclass_order_bug_1.exp:
tests/typeclasses/typeclass_order_bug_1.m:
tests/typeclasses/typeclass_order_bug_2.exp:
tests/typeclasses/typeclass_order_bug_2.m:
tests/typeclasses/typeclass_order_bug_3.exp:
tests/typeclasses/typeclass_order_bug_3.m:
    Rename the typeclass_order_bug and typeclass_order_bug[23] test cases
    to typeclass_order_bug_[123].

tests/valid/Mercury.options:
    Execute the mpj_7 test case with --infer-all, as its source code says
    it should be executed.

tests/valid/Mmakefile:
tests/valid/agc_unbound_typevars_1.m:
tests/valid/agc_unbound_typevars_2.m:
    Rename the agc_unbound_typevars and agc_unbound_typevars2 test cases
    to agc_unbound_typevars_[12].

tests/valid/exists_fundeps_1.m:
    Rename the exists_fundeps test case to exists_fundeps_1,
    due to the existence of exists_fundeps_[23].

tests/valid/higher_order_1.m:
tests/valid/higher_order_2.m:
tests/valid/higher_order_3.m:
tests/valid/higher_order_4.m:
tests/valid/higher_order_5.m:
    Rename the higher_order and higher_order[2345] test cases
    to higher_order_[12345].

tests/valid/ho_func_call_1.m:
    Rename the ho_func_call test case to ho_func_call_1,
    due to the existence of ho_func_call_2.

tests/valid/lambda_instmap_bug_1.m:
tests/valid/lambda_instmap_bug_2.m:
    Rename the lambda_instmap_bug and lambda_instmap_bug2 test cases
    to lambda_instmap_bug_[12].

tests/valid/livevars_shallow_1.m:
tests/valid/livevars_shallow_2.m:
    Rename the livevars_shallow and livevars_shallow2 test cases
    to livevars_shallow_[12].

tests/valid/mpj_2.m:
tests/valid/mpj_5.m:
tests/valid/mpj_6.m:
tests/valid/mpj_7.m:
    Rename the mpj_[2567] test cases to mpj_[2567].

tests/valid/multidet_prune.m:
    Rename the multidet_prune1 test case to multidet_prune,
    since there is no other multidet_prune* test case.

tests/valid/record_syntax_bug_1.m:
    Rename the record_syntax_bug test case to record_syntax_bug_1
    due to the existence of record_syntax_bug_[234].

tests/valid/reuse_static_1.m:
tests/valid/reuse_static_2.m:
    Rename the reuse_static and reuse_static2 test cases
    to reuse_static_[12].

tests/valid/sharing_loop_1.m:
tests/valid/sharing_loop_2.m:
tests/valid/sharing_loop_3.m:
    Rename the sharing_loop and sharing_loop[23] test cases
    to sharing_loop_[123].

tests/valid/simplify_bug_1.m:
tests/valid/simplify_bug_2.m:
    Rename the simplify_bug and simplify_bug2 test cases
    to simplify_bug_[12].

tests/valid/solver_type_bug_1.m:
    Rename the solver_type_bug test case to solver_type_bug_1,
    due to the existence of solver_type_bug_2.

tests/valid/state_var_mode_bug_1.m:
tests/valid/state_var_mode_bug_2.m:
    Rename the state_var_mode_bug and state_var_mode_bug2 test cases
    to state_var_mode_bug_[12].

tests/valid/switch_detection_bug_1.m:
tests/valid/switch_detection_bug_2.m:
    Rename the switch_detection_bug and switch_detection_bug2 test cases
    to switch_detection_bug_[12].

tests/valid/tricky_assert.m:
    Rename the tricky_assert2 test case to tricky_assert,
    since there is no other tricky_assert* test case.

tests/valid/unused_args_test.m:
    Rename the unused_args_test2 test case to unused_args_test,
    since there is no other unused_args_test* test case.
2024-08-06 00:32:48 +02:00
Zoltan Somogyi
2cec289e70 Use test case numbers according to our conventions ...
... in the general and hard_coded test case directories.

tests/general/Mercury.options:
tests/general/Mmakefile:
tests/general/commit_bug_1.exp:
tests/general/commit_bug_1.m:
    Rename the commit_bug test case as commit_bug_1, due to the existence
    of commit_bug_2.

tests/general/intermod_type.m:
tests/general/intermod_type_helper_1.m:
    Rename intermod_type2.m as intermod_type_helper_1.m.

tests/general/nondet_ite_1.exp:
tests/general/nondet_ite_1.m:
    Rename the nondet_ite test case as nondet_ite_1, due to the existence
    of nondet_ite_[234].

tests/general/string_format_test_1.exp:
tests/general/string_format_test_1.exp2:
tests/general/string_format_test_1.exp3:
tests/general/string_format_test_1.m:
    Rename the string_format_test test case as string_format_test_1,
    due to the existence of string_format_test_[23].

tests/general/string_test_1.exp:
tests/general/string_test_1.m:
    Rename the string_test test case as string_test_1,
    due to the existence of string_test_2.

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/array_test_1.exp:
tests/hard_coded/array_test_1.m:
tests/hard_coded/array_test_2.exp:
tests/hard_coded/array_test_2.m:
    Rename the array_test and array_test2 test cases as
    array_test_1 and array_test_2.

tests/hard_coded/bad_indirect_reuse_1.exp:
tests/hard_coded/bad_indirect_reuse_1.m:
tests/hard_coded/bad_indirect_reuse_2.exp:
tests/hard_coded/bad_indirect_reuse_2.m:
tests/hard_coded/bad_indirect_reuse_3.exp:
tests/hard_coded/bad_indirect_reuse_3.m:
tests/hard_coded/bad_indirect_reuse_4.exp:
tests/hard_coded/bad_indirect_reuse_4.m:
    Rename the bad_indirect_reuse and bad_indirect_reuse[234] test cases
    as bad_indirect_reuse_[1234].

tests/hard_coded/copy_pred_1.exp:
tests/hard_coded/copy_pred_1.m:
    Rename the copy_pred test case as copy_pred_1, due to the existence
    of copy_pred_2.

tests/hard_coded/curry_1.exp:
tests/hard_coded/curry_1.m:
tests/hard_coded/curry_2.exp:
tests/hard_coded/curry_2.m:
tests/hard_coded/curry_2_helper_1.m:
    Rename the curry and curry2 test cases as curry_1 and curry_2,
    and rename the curry2_test module as curry_2_helper_1.

tests/hard_coded/cycles_1.exp:
tests/hard_coded/cycles_1.m:
tests/hard_coded/cycles_2.exp:
tests/hard_coded/cycles_2.m:
    Rename the cycles and cycles2 test cases as cycles_1 and cycles_2.

tests/hard_coded/delay_partial_test_1.exp:
tests/hard_coded/delay_partial_test_1.m:
tests/hard_coded/delay_partial_test_2.exp:
tests/hard_coded/delay_partial_test_2.m:
    Rename the delay_partial_test and delay_partial_test2 test cases
    as delay_partial_test_1 and delay_partial_test_2.

tests/hard_coded/dense_lookup_switch_1.exp:
tests/hard_coded/dense_lookup_switch_1.m:
tests/hard_coded/dense_lookup_switch_2.exp:
tests/hard_coded/dense_lookup_switch_2.m:
tests/hard_coded/dense_lookup_switch_3.exp:
tests/hard_coded/dense_lookup_switch_3.m:
tests/hard_coded/dense_lookup_switch_4.exp:
tests/hard_coded/dense_lookup_switch_4.m:
    Rename the dense_lookup_switch and dense_lookup_switch[234] test cases
    as dense_lookup_switch_[1234].

tests/hard_coded/dense_lookup_switch_non_1.exp:
tests/hard_coded/dense_lookup_switch_non_1.m:
tests/hard_coded/dense_lookup_switch_non_2.exp:
tests/hard_coded/dense_lookup_switch_non_2.m:
    Rename the dense_lookup_switch_non and dense_lookup_non2 test cases
    as dense_lookup_switch_non_[12].

tests/hard_coded/direct_arg_partial_inst_1.exp:
tests/hard_coded/direct_arg_partial_inst_1.m:
tests/hard_coded/direct_arg_partial_inst_2.exp:
tests/hard_coded/direct_arg_partial_inst_2.m:
    Rename the direct_arg_partial_inst and direct_arg_partial_inst2 test cases
    as direct_arg_partial_inst_[12].

tests/hard_coded/direct_arg_tags_1.exp:
tests/hard_coded/direct_arg_tags_1.m:
    Rename the direct_arg_tags test case as direct_arg_tags_1, due to
    the existence of direct_arg_tags_2.

tests/hard_coded/export_test_1.exp:
tests/hard_coded/export_test_1.m:
tests/hard_coded/export_test_2.exp:
tests/hard_coded/export_test_2.m:
    Rename the export_test and export_test2 test cases as export_test_[12].

tests/hard_coded/follow_code_bug_1.exp:
tests/hard_coded/follow_code_bug_1.m:
    Rename the follow_code_bug test case as follow_code_bug_1, due to
    the existence of follow_code_bug_2.

tests/hard_coded/foreign_type_1.exp:
tests/hard_coded/foreign_type_1.m:
tests/hard_coded/foreign_type_2.exp:
tests/hard_coded/foreign_type_2.m:
tests/hard_coded/foreign_type_3.exp:
tests/hard_coded/foreign_type_3.m:
    Rename the foreign_type and foreign_type[23] test cases
    as foreign_type_[123].

tests/hard_coded/functor_ho_inst_1.exp:
tests/hard_coded/functor_ho_inst_1.m:
    Rename the functor_ho_inst test case as functor_ho_inst_1, due to
    the existence of functor_ho_inst_2.

tests/hard_coded/functor_ho_inst_excp_1.exp:
tests/hard_coded/functor_ho_inst_excp_1.m:
    Rename the functor_ho_inst_excp test case as functor_ho_inst_excp_1,
    due to the existence of functor_ho_inst_excp_2.

tests/hard_coded/higher_order_syntax_1.exp:
tests/hard_coded/higher_order_syntax_1.m:
tests/hard_coded/higher_order_syntax_2.exp:
tests/hard_coded/higher_order_syntax_2.m:
    Rename the higher_order_syntax and higher_order_syntax2 test cases
    as higher_order_syntax_[12].

tests/hard_coded/ho_order_1.exp:
tests/hard_coded/ho_order_1.m:
tests/hard_coded/ho_order_2.exp:
tests/hard_coded/ho_order_2.m:
    Rename the ho_order and ho_order2 test cases as ho_order_[12].

tests/hard_coded/lco_pack_args_1.exp:
tests/hard_coded/lco_pack_args_1.m:
    Rename the lco_pack_args test case as lco_pack_args_1, due to
    the existence of lco_pack_args_[23].

tests/hard_coded/loop_inv_extra_test_1.inp:
tests/hard_coded/loop_inv_extra_test_1.m:
tests/hard_coded/loop_inv_extra_test_2.inp:
tests/hard_coded/loop_inv_extra_test_2.m:
    Rename the loop_inv_test0 and loop_inv_test2 test cases as
    loop_inv_extra_test_1 and loop_inv_extra_test_2 respectively.
    Both these test cases test "extra" functionality that the compiler
    does not currently have, and thus neither is currently enabled.

tests/hard_coded/loop_inv_test_2.exp:
tests/hard_coded/loop_inv_test_2.inp:
tests/hard_coded/loop_inv_test_2.m:
    Rename the loop_inv_test test case as loop_inv_test_2,
    because loop_inv_test_1 was already taken (see below).

tests/hard_coded/loop_inv_test_1.exp:
tests/hard_coded/loop_inv_test_1.inp:
tests/hard_coded/loop_inv_test_1.m:
tests/hard_coded/loop_inv_test_3.exp:
tests/hard_coded/loop_inv_test_3.m:
tests/hard_coded/loop_inv_test_4.exp:
tests/hard_coded/loop_inv_test_4.m:
    Rename the loop_inv_test[134] test cases as loop_inv_test_[134].

tests/hard_coded/pprint_test_1.exp:
tests/hard_coded/pprint_test_1.m:
tests/hard_coded/pprint_test_2.exp:
tests/hard_coded/pprint_test_2.m:
    Rename the pprint_test and pprint_test2 test cases as pprint_test_[12].

tests/hard_coded/quantifier_1.exp:
tests/hard_coded/quantifier_1.m:
tests/hard_coded/quantifier_2.exp:
tests/hard_coded/quantifier_2.m:
    Rename the quantifier and quantifier2 test cases as quantifier_[12].

tests/hard_coded/random_1.exp:
tests/hard_coded/random_1.m:
tests/hard_coded/random_2.exp:
tests/hard_coded/random_2.m:
tests/hard_coded/random_3.exp:
tests/hard_coded/random_3.m:
    Rename the random[123] test cases as random_[123].

tests/hard_coded/random_shuffle_1.exp:
tests/hard_coded/random_shuffle_1.m:
tests/hard_coded/random_shuffle_2.exp:
tests/hard_coded/random_shuffle_2.m:
    Rename the random_shuffle[12] test cases as random_shuffle_[12].

tests/hard_coded/string_split_1.exp:
tests/hard_coded/string_split_1.m:
    Rename the string_split test case as string_split_1, due to
    the existence of string_split_2.

tests/hard_coded/string_switch_1.exp:
tests/hard_coded/string_switch_1.m:
tests/hard_coded/string_switch_2.exp:
tests/hard_coded/string_switch_2.m:
tests/hard_coded/string_switch_3.exp:
tests/hard_coded/string_switch_3.m:
tests/hard_coded/string_switch_4.exp:
tests/hard_coded/string_switch_4.m:
    Rename the string_switch and string_switch[233] test cases
    as string_switch_[1234].

tests/hard_coded/test_cord_1.exp:
tests/hard_coded/test_cord_1.m:
tests/hard_coded/test_cord_2.exp:
tests/hard_coded/test_cord_2.m:
tests/hard_coded/test_cord_3.exp:
tests/hard_coded/test_cord_3.m:
    Rename the test_cord and test_cord[23] test cases as test_cord_[123].

tests/hard_coded/trace_goal_opt.m:
tests/hard_coded/trace_goal_opt_helper_1.m:
    Rename the trace_goal_opt_2 module as trace_goal_opt_helper_1.

tests/hard_coded/tuple_test_1.exp:
tests/hard_coded/tuple_test_1.m:
tests/hard_coded/tuple_test_2.exp:
tests/hard_coded/tuple_test_2.m:
    Rename the tuple_test and tuple_test2 test cases as tuple_test_[12].

tests/hard_coded/version_hash_table_test_1.exp:
tests/hard_coded/version_hash_table_test_1.m:
tests/hard_coded/version_hash_table_test_2.exp:
tests/hard_coded/version_hash_table_test_2.m:
    Rename the version_hash_table_test and version_hash_table_test2
    test cases as version_hash_table_test_[12].

tests/hard_coded/write_reg_1.exp:
tests/hard_coded/write_reg_1.m:
tests/hard_coded/write_reg_2.exp:
tests/hard_coded/write_reg_2.m:
    Rename the write_reg[12] test cases as write_reg_[12].
2024-08-05 15:09:33 +02:00
Zoltan Somogyi
9e975dbad7 Use "MCFLAGS-X += <values>" in tests/*/Mercury.options.
Replace "=" with "+=" in these files, because this eliminates the chance
that one such rule will override another.
2024-07-29 18:01:17 +02:00
Zoltan Somogyi
e78cfaaa8c Allow higher order inst info in mutables.
compiler/parse_mutable.m:
compiler/parse_type_name.m:
    As above.

tests/hard_coded/higher_order_mutable.{m,exp}:
    A new test case for the new capability, checking whether we can call
    a closure we got out of a mutable.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2024-07-24 09:46:00 +02:00
Peter Wang
e23fd6c7d4 Add predicates to find chars in strings.
Add the following predicates to find the first or last occurrence of a
code point in a string:

find_first_char
    We already had the code to implement contains_char.
    Not strictly necessary as we have sub_string_search.

find_first_char_start
    Safe wrapper for unsafe_find_first_char_start.

unsafe_find_first_char_start
    This is just the body of find_first_char, which should be useful for
    users. Not strictly needed as we have sub_string_search_start.

find_last_char
    Commonly needed.

NOTE: I also considered these predicates but discarded them for now:

    :- pred find_first_char_between(string::in, char::in,
        int::in, int::in, int::out) is semidet.

    :- pred find_last_char_between(string::in, char::in,
        int::in, int::in, int::out) is semidet.

    :- pred find_first_match_between(pred(char)::in(pred(in) is semidet),
        string::in, int::in, int::in, int::out) is semidet.

    :- pred find_last_match_between(pred(char)::in(pred(in) is semidet),
        string::in, int::in, int::in, int::out) is semidet.

The _between predicates required a bit more code than I'd like, for the
amount of use that they would (I imagine) get. The _match predicates
were just conveniences over iterating over a string manually.
All four predicates would incur calls to strlen() in C grades,
which suggests adding "unsafe" versions as well.

library/string.m:
    Add the predicates above.

    Implement string.contains_char using string.find_first_char.

tests/hard_coded/Mmakefile:
tests/hard_coded/string_find_char.exp:
tests/hard_coded/string_find_char.exp2:
tests/hard_coded/string_find_char.m:
    Add test case.

NEWS.md:
    Announce additions.
2024-07-19 17:58:25 +10:00
Zoltan Somogyi
792ee5e89c Fix compiler abort for undeleted dead code.
This fixes Github issue #133.

The bug occurred after jumpopt.m transformed code of the form

    %       if (Cond) L1
    %       r1 = MR_FALSE

when followed immediately by

    %       <epilog>
    %       ...
    %     L1:
    %       r1 = MR_TRUE
    %       <epilog>

into code of the form

    %       r1 = Cond
    %       <epilog>

The transformation left both epilogs in the instruction sequence,
even though at least the first, and probably both, were now being dead code.
The problem arose because the compiler did not clean up either dead epilogue,
leading to failed assertion in a later code optimization pass.

compiler/optimize.m:
    Fix the bug by forcing the execution of the passes that clean up dead code
    if jumpopt makes any changes to the instruction sequence.

compiler/jumpopt.m:
    When replacing an if_val instruction whose target and fallthrough
    lead to two different semidet epilogues (one assigning 0 to r1 and
    one assigning 1) with a single epilogue assigning to r1 the value
    of a bool expression and then returning, delete all the instructions
    following the if_val up to but not including the next label.
    This is because replacing the if_val by by the new epilogue makes
    those instructions unreachable.

The diffs for the next two files are not part of the fix, but I noticed
the need for them while hunting the bug.

compiler/opt_debug.m:
    Give a predicate a more descriptive name, and simplify its code.

    Make the dumps of computed goto instructions more readable, both
    by printing each target on its own line, and by printing the value
    corresponding to each target.

compiler/hlds_out_type_table.m:
    Format the description of arguments' offsets in heap cells
    in a way that is more readable. Print just one offset for an argument
    in the usual case where it is not preceded by any nonarguments such as
    type_infos/typeclass_infos (i.e. if its arg-only offset is the same
    as its offset from the start of the heap cell). If those two offsets
    differ, then include a description of each offset with its value.

    Move the description of each du type's kind (i.e. whether it is an
    enum type, notag type etc) to *before* the description of its
    function symbols.

tests/hard_coded/gh133.{m,exp}:
    A test case for this bug, derived from the one in github issue #133.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2024-07-11 11:08:15 +02:00
Peter Wang
d013421326 Modecheck coerce of terms with existential types.
The modechecking for coerce did not take into account existentially
typed arguments in the term being coerced. There are two main changes:

1. If the input (sub)term being coerced has an existential type, the
   result must have the same type. Therefore, we can use the inst
   approximating the input (sub)term for the result.

2. Each existentially quantified type variable or existential class
   constraint on a data constructor adds a type_info or type_class_info
   to the resulting heap cell. Internally, the inst for that cell will
   include insts for those extra arguments, which the modechecker for
   coerce will need to be aware of.

Fixes GitHub issue #132

compiler/modecheck_coerce.m:
    As above.

doc/reference_manual.texi:
    Account for existential types in the description of
    how modechecking of coerce works.

tests/hard_coded/Mmakefile:
tests/hard_coded/coerce_existq.exp:
tests/hard_coded/coerce_existq.m:
    Add test case.
2024-07-11 16:17:48 +10:00
Peter Wang
bab9106220 Fix codegen for subtype field names in high-level data grades.
Fix a bug where the compiler generated incorrect code in C# and Java
grades when a subtype type definition did not repeat the field names of
its base type. Subtypes use the same data represention with their base
type, so in target code we must use the names of fields from the
base type instead of the subtype.

compiler/hlds_data.m:
    Add a field to ctor_arg_repn to tell if a constructor argument
    belongs to a subtype, and if so, the field name of the corresponding
    constructor argument in the base type (if any).

compiler/du_type_layout.m:
    Fill in the field appropriately for the ctor_arg_repn of a subtype
    constructor argument.

    Rename predicates which only deal with non-subtype du types,
    for clarity.

    Conform to changes elsewhere.

compiler/ml_code_util.m:
    Make ml_gen_hld_field_name use the field name from the base type
    if generating the field name for a subtype constructor argument.

compiler/ml_type_gen.m:
    Pass MaybeBaseTypeCtor to ml_gen_hld_field_name.

compiler/add_special_pred.m:
compiler/equiv_type_hlds.m:
compiler/hlds_out_type_table.m:
compiler/ml_unify_gen_deconstruct.m:
compiler/ml_unify_gen_util.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/type_ctor_info.m:
    Conform to changes.

compiler/mlds.m:
    Add comment.

compiler/tag_switch_util.m:
    Delete comment about the bug that this change fixes.

tests/hard_coded/Mmakefile:
tests/hard_coded/subtype_field_names.exp:
tests/hard_coded/subtype_field_names.m:
    Add test case.

NEWS.md:
    Announce change.
2024-05-02 12:32:39 +10:00