Commit Graph

3696 Commits

Author SHA1 Message Date
Zoltan Somogyi
474035d884 Use test instead of [] in sh code. 2021-03-06 21:52:19 +11:00
Zoltan Somogyi
eeb69f14ba Use explicit streams in browser/*.m.
browser/browse.m:
browser/browser_info.m:
browser/collect_lib.m:
browser/declarative_debugger.m:
browser/declarative_oracle.m:
browser/declarative_user.m:
browser/diff.m:
browser/help.m:
browser/interactive_query.m:
browser/parse.m:
browser/util.m:
    Replace implicit streams with explicit streams.

    Shorten lines longer than 79 chars.

    In some places, simplify some code, often using constructs such as
    string.format that either did not exist or were too expensive to use
    when the original code was written.

    In some places, change predicate names that were not meaningful
    without module qualification by *including* the module qualification
    in the name (e.g. init -> browser_info_init).

    In some places, add XXXs.

    In browser_info.m, make the output stream *part* of the debugger type,
    because without this, having the debugger type belong to the stream
    typeclass does NOT make sense. (The typeclass instance for debugger
    used to always write to the current output stream, which this diff
    is replacing with the use of explicitly specified streams.)

    In browse.m, consistently put stream arguments before other arguments.

    In browse.m, when exporting Mercury predicates to C, export them
    under names with the standard ML_BROWSE_ prefix, NOT under the name
    of a *different* predicate with that prefix.

    In diff.m, eliminate an unnecessary difference between what we print
    when the difference between two terms is at the root, vs what we print
    when the difference between two terms is lower down.

    In interactive_query.m, when trying to write a program out to a file,
    do NOT write the program to the current output stream if we cannot open
    the file, since that would accomplish nothing useful.

    Also in interactive_query.m, cleanup .dylib instead of .so on MacOS.

    In util.m, delete some unused predicates.

    In collect_lib.m, document why some code is not worth updating.

    In declarative_oracle.m, rename predicates with previously-ambiguous
    names.

browser/MDBFLAGS.in:
    Specify --warn-implicit-stream-calls for all Mercury modules
    in the browser directory from now.

trace/mercury_trace_browse.c:
trace/mercury_trace_cmd_browsing.c:
ssdb/ssdb.m:
    Conform to the changes in browser/*.m.

tests/debugger/queens.{exp,exp2}:
    Expect the extra output from browser/diff.m.
2021-03-05 22:54:28 +11:00
Peter Wang
181122d1f8 Fix writing .module_dep files.
compiler/make.module_dep_file.m:
    Write foreign included file names to the .module_dep stream
    instead of the implicit output stream. The bug was introduced in
    commit 5f50259d16.

tests/mmc_make/Mmakefile:
    mmc --make does not set a non-zero exit status even if there were
    problems reading a .module_dep file. Explicitly grep for "error" in
    the mmc --make output in the include_file test that should have
    caught the preceding bug (assuming the workspace is built with
    --use-subdirs).

    grep for "error" in another test case.
2021-03-01 12:28:43 +11:00
Zoltan Somogyi
03d6c5f436 Get higher insts from types as well as modes.
compiler/modecheck_call.m:
    As above. This fixes Mantis bug #529.

compiler/options.m:
    Allow configure to test whether the bug is fixed, so we can delete
    any now-redundant explicit higher order insts in mode declarations.

tests/hard_coded/exist_cons_ho_arg.{m,exp}:
    A test case for the bug. This is a strengthened version of the
    Mantis test case.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2021-02-24 19:57:37 +11:00
Zoltan Somogyi
4ebe95672d Don't crash on inst_name nested inside itself.
This fixes Mantis bug #528.

compiler/error_msg_inst.m:
    Since an inst_name IN may be used nested inside itself, as in
    IN(..., IN(...), ...), do not insist that both occurrences of IN
    in such cases lead to the insertion of a new entry in the inst name
    expansion map.

tests/invalid/html.{m,err_exp}:
    The Mantis test case.

tests/invalid/Mmakefile:
    Enable the Mantis test case.
2021-01-30 01:45:26 +11:00
Zoltan Somogyi
5a5a35bd09 Don't crash for type errors in foreign_procs.
Normally, foreign_procs are assumed to be type correct, because they
have to be: a Mercury compiler cannot check foreign code. However,
in one case, we can get type errors for foreign_procs That case is when
a predicate has

- an existentially typed argument, and
- two or more modes implemented by foreign procs.

The compiler has never been able to correctly handle more than one clause
defining the type_info of an existentially typed argument. When those clauses
were Mercury clauses, it generated an error; when those "clauses" were
foreign_procs, it *tried* to generate an error, but the code that did that
crashed the compiler.

compiler/typecheck_errors.m:
    Fix the compiler abort, letting the error message be generated.

tests/invalid/foreign_procs_exist_type.{m,err_exp}:
    Add a test case for this fix.

tests/invalid/Mmakefile:
    Enable the new test case.
2021-01-27 14:40:49 +11:00
Zoltan Somogyi
63dabcfcf8 Fix filling in partial terms that use direct_arg tags.
This fix uses the approach discussed on m-dev 2020 nov 16/17 for fixing
github issue #72, whose core problem is a need for information flow
back to a the caller from a callee when the callee fills in the
argument of a function symbol whose representation is a direct_arg tag.
In most cases when the callee fills in the value of an argument,
the caller can see it because the argument is in a word on the heap,
but when the function symbol uses a direct_arg tag, that is not the case.

compiler/direct_arg_in_out.m:
    A new module that implements the transformation proposed on m-dev.
    It creates a fresh clone variable every time an argument of a direct_arg
    tag function symbol is (or may be) updated. This can happen several
    times if a type has more than one function symbol with a direct_arg tag.
    Since the affected variable can be bound to only one function symbol
    at the start, its argument can be filled in only once, but the
    compiler cannot know in advance what function symbol the variable
    contains, and therefore which of the possibly several fill-in sites
    (which fill in the arguments of different function symbols) executed
    in sequence will actually update the variable.

    The transformation ensures that once a variable is cloned, it is
    never referred to again. It also ensures that in a branched control
    structure (if-then-else, disjunction or switch), all branches will use
    the *same* variable to represent the latest version of each cloned
    variable at the end, so that following code has a consistent view
    regardless of through which branch execution has reached it.

    There are three situations that the transformation cannot and does not
    handle.

    1. Situations in which the mode of an argument is either an inst variable,
       or an abstract inst. In either case, the pass cannot know whether
       it should apply its transformation to the argument.

    2. Situations where a procedure that has such an argument is
       exported to C code as a function. In that case, the C signature
       of the function we would generate would be different from what
       the user would normally expect. We could modify the documentation
       of the export pragma, but I don't think there much point due to
       lack of demand. (The problem cannot arise when targeting any language
       other than C, because we use direct_arg tags only with the low level
       data representation, which we only use for C.)

    3. Situations where a procedure that has such an argument is defined
       by foreign_proc. Again, dealing with the problem would require
       nontrivial changes to the documented interface between code in
       foreign_procs and the surrounding Mercury code, and I see no demand
       for code that could benefit from that.

    In these cases, this module generates error messages.

compiler/transform_hlds.m:
    Include the new module in the transform_hlds package.

    Delete unnecessary module qualification on some existing inclusions.
    Put some existing inclusions into a more meaningful order.

compiler/notes/compiler_design.html:
    Document the new pass. Fix some nearby prose.

compiler/lambda.m:
compiler/simplify_proc.m:
    Use a predicate exported by direct_arg_in_out.m to test, for each
    procedure, whether the procedure has any argument positions that are
    subject to the problem that direct_arg_in_out.m addresses.
    simplify_proc.m does this for all procedures it processes;
    lambda.m does this for all the procedures it creates from
    lambda expressions.

    Give a predicate in simplify_proc.m a better name.

    Sort a list of predicate names.

compiler/hlds_module.m:
    Add a field to the module_info that simplify_proc.m and lambda.m
    can use to tell direct_arg_in_out.m what work (if any) it needs to do.

compiler/mercury_compile_middle_passes.m:
    Invoke direct_arg_in_out.m if the new field in the HLDS indicates
    that it has some work to do. (In the vast majority of compiler invocations,
    it won't have any.)

compiler/hlds_pred.m:
    The new code in direct_arg_in_out.m creates a clone of each procedure
    affected by the problem, before deleting the originals (to make sure that
    no references to the unfixed versions of now-fixed procedures remain.)
    Make it possible to create exact clones of both predicates and procedures
    by adding two pairs of predicates, {pred,proc}_prepare_to_clone and
    {pred,proc}_create.

    Add the direct_arg_in_out transformation as a possible source
    of transformed predicates.

library/private_builtin.m:
    Add a new builtin operation, partial_inst_copy, that the new module
    generates calls to.

configure.ac:
    Require the installed compiler to recognize partial_inst_copy
    as a no_type_info builtin.

compiler/builtin_ops.m:
    Recognize the new builtin. (This was committed before the rest; the diff
    to private_builtin.m can be done only once the change to builtin_ops.m
    is part of the installed compiler.)

compiler/options.m:
    Add a way to test whether the builtin_ops.m in the installed compiler
    recognizes the new builtin.

compiler/dead_proc_elim.m:
    Do not delete the new primitive before direct_arg_in_out.m has had
    a chance to generate calls to it.

    Add an XXX.

compiler/error_util.m:
    Recognize the new module as a source of error messages.

compiler/pred_table.m:
    Add a pair of utility predicates to be used when looking up
    builtin predicates, for which the compiler writer knows that
    there should be exactly one match. These are used in direct_arg_in_out.m.

compiler/simplify_goal_call.m:
    Replace some existing code with calls to the new predicates
    in pred_table.m.

compiler/hlds_goal.m:
    Add modes to rename_vars_in_goal_expr that express the fact
    that when an atomic goal_expr has some variables renamed inside it,
    it does not suddenly become some *other* kind of goal_expr.
    New code in direct_arg_in_out.m relies on this.

compiler/hlds_out_goal.m:
    When the HLDS we are dumping out is malformed because it contains
    calls to predicates that have been deleted, the compiler used to abort
    at such calls. (I ran into this while debugging direct_arg_in_out.m.)

    Fix this. When such calls are encountered, we now print out as much
    information we can about the call, and prefix the call with an
    unmistakable prefix to draw attention to the problem.

compiler/inst_util.m:
    Fix a bug that prevented direct_arg_in_out.m from even being invoked
    on some test code for it.

    The bug was in code that we use to unify a headvar's initial inst
    with its final inst. When the initial inst was a non-ground bound_inst
    such as the ones used in tests/hard_coded/gh72.m, and the final inst
    was simply "ground", this code quite properly returned a bound_inst
    (which, unlike ground, can show the exact set of function symbols
    that the headvar could be bound to). The problem was that it
    reused the original bound_inst's test results, including the one
    that said the final inst is NOT ground, which of course is wrong
    for any inst unified with ground. Fix two instances of this bug.

compiler/modes.m:
    Make some of the code I had to traverse to find the bug in inst_util.m
    easier to read and understand.

    Replace some uses of booleans with bespoke enum types.

    Change the argument lists of some predicates to put related arguments
    next to each other.

    Give some variables more descriptive names.

compiler/layout_out.m:
    Conform to the change in hlds_pred.m.

compiler/var_locn.m:
    Fix a code generation bug. When filling-in the value of the argument
    of a function symbol represented by a direct_arg tag, the code we
    generated for it worked only if the direct_arg tag used 0
    as its ptag value. In the test cases we initially used for
    github issue 72, that was the case, but the new tests/hard_coded/gh72.m
    has direct_tag args that use other ptag values as well.

    Document the reason why the updated code works.

compiler/term_constr_initial.m:
    Add the new primitive predicate added to private_builtin.m,
    partial_inst_copy, to a table of builtins that do not take type_infos,
    even though their signatures contain type variables.

    Fix a bunch of old bugs: most other such primitives were not listed
    either.

mdbcomp/program_representation.m:
    Add partial_inst_copy to the master list of builtins that do not take
    type_infos even though their signatures contain type variables. (Done
    by an earlier commit.)

    Document the fact that any updates here require updates to
    term_constr_initial.m.

library/multi_map.m:
    We have long had multi_map.add and multi_map.set as synonyms,
    but we only had multi_map.reverse_set. Add multi_map.reverse_add
    as a synonym for it.

    Define the "set" versions in terms of the "add" versions,
    instead of vice versa.

NEWS:
    Document the new predicates in multi_map.m.

tests/hard_coded/gh72a.m:
    Fix typo.

tests/hard_coded/gh72.{m,exp}:
    A new, much more comprehensive test case than gh72a.m.
    This one tries to tickle github issue 72 in as many forms of code
    as I can think of.

tests/invalid/gh72_errors.{m,err_exp}:
    A test case for testing the generation of error messages for
    two out of the three kinds of situations that direct_arg_in_out.m
    cannot handle. (Proposals for how to test the third category welcome.)

tests/hard_coded/Mmakefile:
tests/invalid/Mmakefile:
    Enable the two new test cases, as well as two old ones, gh72[ab].m,
    that previously we didn't pass.

tests/invalid/Mercury.option:
    Do not compile gh72_error.m with --errorcheck-only, since its errors
    are reported by a pass that --errorcheck-only does not invoke.
2021-01-13 05:35:40 +11:00
Julien Fischer
1e5f1c9b59 Use the correct comment character in a Mmakefile.
tests/invalid/Mmakefile:
    As above.
2021-01-07 16:14:46 +11:00
Julien Fischer
a3ff603f4f Update programming style in a test.
tests/term/existential_error1.m:
    Use '.' as a module qualifier in place of '__'.
2021-01-07 16:08:03 +11:00
Julien Fischer
7cdc88459d Document what some expected outputs are for.
test/hard_coded/write.m:
    As above.
2021-01-07 14:15:31 +11:00
Julien Fischer
f9f2e5e112 Enable a test case in the C# and Java grades.
test/hard_coded/Mmakefile:
    Run the pragma_export test in C# and Java grades.

tests/hard_coded/pragma_export.m:
    Add the foreign_proc and foreign_export pragmas required for
    this to work in the Java grade.
2021-01-07 14:08:04 +11:00
Julien Fischer
1f6d83692a Update programming style in tests/hard_coded.
tests/hard_coded/*.m:
    Update programming style, unless doing so would change
    the meaning of the test, in particular:

    - use '.' as a module qualifier in place of '__'
    - use {write,print}_line where appropriate
    - use if-then-else in place of C -> T ; E
    - use state variables in place of DCGs

tests/hard_coded/dir_test.m:
    Document what the expected outputs correspond to.

    Use a uniform module qualifier in the output.

tests/hard_coded/dir_test.exp*:
    Conform to the above change.
2021-01-07 13:58:12 +11:00
Julien Fischer
587ec47536 Lift restriction on formatting 64-bit integers.
Zoltan's recent addition of support for formatting fixed size integer types
using string.format and friends works by casting the fixed size integer value
to an int or uint value and then re-using the existing code we already have for
formatting those. This works in all cases except when formatting 64-bit integer
types on systems where int / uint is a 32-bit quantity (notably, both the C#
and Java backends). This diff lifts that restrictions.

library/string.format.m:
    Add support for formatting 64-bit integers without having to cast them
    to an int or uint.

    Export new format predicates for use by the code generated by
    compiler/format_call.m.

compiler/format_call.m:
    Generate calls to the 64-bit versions of the format_*_component predicates
    where necessary.

compiler/simplify_proc.m:
    Update the list of predicates that may be introduced by the compiler.

NEWS:
    Delete the mention of the restriction.

tests/hard_coded/opt_format.{m,exp}:
    Extend this test to cover 64-bit integers.
2021-01-07 12:19:22 +11:00
Julien Fischer
2ae3fa61da Update programming style in some tests.
tests/general/string_format_test.m:
tests/general/string_format_test_2.m:
tests/general/string_format_test_3.m:
      As above.
2021-01-05 14:58:54 +11:00
Julien Fischer
aa8bd480f4 Add string format tests for 64-bit integers.
tests/string_format/string_format_int64_[doux].{m,exp}:
tests/string_format/string_format_uint64_[oux].{m,exp}:
tests/string_format/Mmakefile:
     Add the new tests.
2021-01-04 11:04:46 +11:00
Zoltan Somogyi
0379e77188 Fix programming style. 2020-12-30 20:13:00 +11:00
Julien Fischer
52b31f5089 Add uint64 to string conversion for bases 8 and 16.
library/string.m:
     Add functions for converting uint64s to strings of base 8 or base 16
     digits. For most integer types we can cast to a uint and then use the
     uint versions of these operations but for 64-bit types we cannot since
     on some of our supported platforms uints are 32-bit.

NEWS:
     Announce the additions.

tests/hard_coded/Mmakefile:
tests/hard_coded/uint64_string_conv.{m,exp}:
     Add a test of the new functions.
2020-12-15 22:45:31 +11:00
Julien Fischer
f8e65add3a Format uints directly.
Currently, the Mercury implementation of string formatting handles uints by
casting them to ints and then using the code for formatting signed integers as
unsigned values.  Add an implementation that works directly on uints and make
the code that formats signed integers as unsigned integers use that instead.
The new implementation is simpler and avoids unnecessary conversions to
arbitrary precision integers.

Add new functions for converting uint values directly to octal and hexadecimal
strings that use functionality provided by the underlying platforms; replace
the Mercury code that previously did that with calls to these new functions.

library/string.m:
    Add the functions uint_to_hex_string/1, uint_to_uc_hex_string/1 and
    uint_to_octal_string/1.

library/string.format.m:
    Make format_uint/6 operate directly on uints instead of casting the value
    to a signed int and calling format_unsigned_int/6.

    Make format_unsigned_int/6 cast the int value to a uint and then call
    format_uint/6.

    Delete predicates and functions used to convert ints to octal and
    hexadecimal strings.  We now just use the functions exported by
    the string module.

NEWS:
    Announce the additions to the string module.

tests/hard_coded/Mmakefile:
tests/hard_coded/uint_string_conv.{m,exp*}:
     Add a test of uint string conversion.
2020-11-20 23:07:52 +11:00
Zoltan Somogyi
76900ca107 Update the style of some tests. 2020-11-16 12:52:33 +11:00
Julien Fischer
0cbbe0e9c1 Fix a typo.
tests/valid_seq/test_xmlreader.m:
    As above.
2020-11-15 21:24:15 +11:00
Julien Fischer
9638a6edd8 Fix failing string format tests on 32-bit systems.
tests/string_format/string_format_{d,u}.exp:
    Conform to recent additions to these tests.
2020-11-15 17:16:46 +11:00
Zoltan Somogyi
3ac1073811 Factor out common code for simplifying modes.
We used to have several predicates whose job was to simplify modes for
presentation to users. Their jobs were slightly different, but contained
a shared core: recognizing the exploded (from_inst >> to_inst)
forms of the standard builtin modes. Replace these

compiler/prog_mode.m:
    Moves an existing predicate in parse_tree_out_inst.m for recognizing
    the standard builtin modes to prog_mode.m, to make it generally available.

    Refactor the existing insts_to_mode predicate to use this predicate.
    Make insts_to_mode recognize mdi(I) modes as well.

    Add utility predicates for stripping all type_inst wrappers from
    insts and modes. Base these on the similar utility predicates
    for stripping builtin qualifiers from insts and modes. Export
    all meaningful variants of both sets of utilities.

    Use variables named InstNameX for inst names; the old InstX names
    were misleading, since the inst_name type is different from mer_inst.

compiler/parse_tree_out_inst.m:
    Delete the code moved to prog_mode.m.

    Use the updated functionality in prog_mode to simplify modes.
    This means that we can now simplify all in(...) modes, not just
    when the ... is a higher order inst.

    Strip module qualifiers from modes when printing output for humans
    (and *only* for humans), since in 99.9+% of cases they are clutter.

compiler/error_msg_inst.m:
    Replace the old code for recognizing standard modes with calls
    to the predicates in prog_mode.m. They can do a better job than
    the old code did. The recognize arity 1 standard modes, not just
    arity 0, and they remove typed_inst wrappers everywhere in insts,
    not just at the top level.

compiler/hlds_out_util.m:
    Fix an old bug: don't *assume* that any modes being converted to string
    are intended only for humans; get our callers to *tell us* whether
    that is the case. When intermod.m uses hlds_out_goal.m to write out
    the modes on the arguments of lambda goals, this is *not* the case,
    since some transformations intended for humans, such as stripping
    module qualifications, can actually break things.

    Give a field in the hlds_out_info a more meaningful name.

compiler/hlds_out_goal.m:
compiler/hlds_out_module.m:
compiler/intermod.m:
compiler/mode_errors.m:
    Conform to the changes in hlds_out_util.m.

tests/invalid/ho_any_inst.err_exp:
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/mode_inf.err_exp:
    Expect the updated forms of modes in error messages.
2020-11-15 08:19:30 +11:00
Zoltan Somogyi
21b0e35039 Update the style of the tests in valid_seq. 2020-11-15 08:02:47 +11:00
Peter Wang
5d4f845f4b Reset memo tables in fast_loose test.
tests/tabling/fast_loose.m:
    Reset memo tables between before each trial. Results left in the
    memo tables from previous trials cause subsequent trials to run
    faster than they otherwise would, making it harder to detect a
    difference in run time between strict and fast-loose tabling.
    The program ends up trying bigger and bigger numbers, inflating the
    memo tables, and possibly running out of heap or stack space.
2020-11-11 18:10:13 +11:00
Peter Wang
d69bb27dfb Avoid require_tailrec_N failures at higher optimisation levels.
tests/invalid/require_tailrec_1.m:
tests/invalid/require_tailrec_2.m:
tests/invalid/require_tailrec_3.m:
    Suppress some inlining that occurs at higher optimisation levels,
    that changes the warnings produced for require_tail_recursion
    pragmas.

tests/invalid/require_tailrec_1.err_exp:
tests/invalid/require_tailrec_1.err_exp2:
tests/invalid/require_tailrec_1.err_exp3:
tests/invalid/require_tailrec_2.err_exp:
tests/invalid/require_tailrec_2.err_exp2:
tests/invalid/require_tailrec_2.err_exp3:
    Update expected outputs for changed line numbers.
2020-11-11 16:25:26 +11:00
Peter Wang
332002da68 Avoid tests/invalid failures with intermodule optimisation.
tests/invalid/Mmakefile:
    For modules for which the compiler may emit errors while making
    their .opt files, redirect the errors to a .err file and ignore the
    exit status. The .err file will then be compared to .err_exp* files.
2020-11-10 13:06:22 +11:00
Zoltan Somogyi
d4861d739d Allow formatting of sized integers.
library/string.m:
    Add {i,u}{8.16,32,64} as function symbols in the poly_type type,
    each with a single argument containing an integer with the named
    signedness and size.

    The idea is that each of these poly_type values works exactly
    the same way as the i(_) poly_type (if signed) or the u(_) poly_type
    (if unsigned), with the exception that the value specified by the call
    is cast to int or uint before being processed.

library/string.parse_runtime.m:
    Parse the new kinds of poly_types. Change the representation of the result
    of the parsing to allow recording of the sizes of ints and uints.

    Put the code that does the parsing into a predicate of its own.

library/string.format.m:
    Do a cast to int or uint if the size information recorded in the
    specification of a signed or unsigned integer value calls for it.

    Provide functions to do the casting that do not require the import
    of {int,uint}{8,16,32,64}.m. This is to allow the compiler to generate
    calls to do such casts without having to implicitly import those modules.

    Abort if a 64 bit number is being cast to a 32 bit word.

compiler/parse_string_format.m:
    Make the same changes as in string.parse_runtime.m, mutatis mutandis.

compiler/format_call.m:
    Handle the new kinds of poly_types by adding a cast to int or uint
    if necessary, using the predicates added to library/string.format.m.

    Use a convenience function to make code creating instmap deltas
    more readable.

library/io.m:
library/pprint.m:
library/string.parse_util.m:
tests/invalid/string_format_bad.m:
tests/invalid/string_format_unknown.m:
    Conform to the changes above.

tests/string_format/string_format_d.m:
tests/string_format/string_format_u.m:
    Test the printing of some of the new poly_types.

tests/string_format/string_format_d.exp2:
tests/string_format/string_format_u.exp2:
    Update the expected output of these tests on 64-bit platforms.

tests/string_format/string_format_lib.m:
    Update programming style.
2020-11-10 11:00:47 +11:00
Zoltan Somogyi
1045c37bd3 Report references to nonexistent typeclasses.
compiler/check_typeclass.m:
    Look for typeclass constraints on predicates and data constructors
    that refer to nonexistent typeclasses. We already report such references
    when they occur in the module being compiled, but not when they occur
    in declarations imported from other modules.

    Before this diff, the compiler used to abort with a failed map.lookup
    when this occurred. With this diff, the compiler prints a diagnostic
    and exits normally.

    Give some predicates more meaningful names. Update an accumulator
    using a predicate, not a function. Exploit capabilities in error_util.m
    that did not exist when this module first started to use it.
    Use set operations instead of solutions to compute an intersection.
    Avoid repeated string copying. Fix indentation.

tests/invalid/bad_type_class_constraint_intermodule.err_exp:
tests/invalid/bad_type_class_constraint_intermodule.m:
tests/invalid/bad_type_class_constraint_intermodule_2.m:
    A new test case for this problem.

tests/invalid/Mmakefile:
    Enable the new test case.
2020-11-07 11:28:39 +11:00
Zoltan Somogyi
29b560b7b6 Fix indentation. 2020-11-06 00:49:21 +11:00
Zoltan Somogyi
185e4c4e96 Delete all stale code for Erlang from the compiler.
compiler/Mercury.options:
    Delete a workaround we needed only for Erlang.

compiler/add_mutable_aux_preds.m:
    Delete the implementation of mutables for Erlang.

compiler/builtin_ops.m:
    Document the fact that the Erlang backend was the only user of
    two operations.

compiler/compile_target_code.m:
compiler/module_cmds.m:
    Delete the predicates that handled the compilation of Erlang code.

compiler/file_names.m:
    Delete code dealing with file names used only by the Erlang backend.

compiler/options.m:
    Delete the old internal-only order_constructors_for_erlang option.

    Add an XXX about another option intended for Erlang being unused.

    Leave the other erlang-related options alive for now, to avoid breaking
    Mmakefiles, Mercury.options files etc that may still refer to them.

    Delete references to Erlang in help and/or error messages.

compiler/handle_options.m:
    Don't both updating options that were used only by the Erlang backend,
    and which are now unused.

    Delete references to Erlang in help and/or error messages.

compiler/unify_proc.m:
    Delete the code handling the Erlang-specific option deleted from options.m.

compiler/check_libgrades.m:
compiler/delay_partial_inst.m:
compiler/llds_out_data.m:
compiler/make_hlds_passes.m:
compiler/mlds_to_c_data.m:
compiler/prog_item.m:
compiler/simplify_goal_call.m:
compiler/write_deps_file.m:
    Either delete comments referring to Erlang or the Erlang backend,
    or, where their existence was the motivation for some design decisions,
    shift the comments to the past tense.

tests/mmc_make/Mmakefile:
    Delete a reference to a recently deleted .hrl file.
2020-10-29 23:29:36 +11:00
Zoltan Somogyi
122fd8202a Update programming style. 2020-10-29 23:06:06 +11:00
Zoltan Somogyi
a19a5f0267 Delete the Erlang backend from the compiler.
compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_backend.m:
compiler/erl_call_gen.m:
compiler/erl_code_gen.m:
compiler/erl_code_util.m:
compiler/erl_rtti.m:
compiler/erl_unify_gen.m:
compiler/erlang_rtti.m:
compiler/mercury_compile_erl_back_end.m:
    Delete these modules, which together constitute the Erlang backend.

compiler/notes/compiler_design.html:
    Delete references to the deleted modules.

compiler/parse_tree_out_type_repn.m:
    Update the format we use to represent the sets of foreign_type and
    foreign_enum declarations for a type as part of its item_type_repn_info,
    now that Erlang is no longer a target language.

compiler/parse_type_repn.m:
    Accept both the updated version of the item_type_repn_info and the
    immediately previous version, since the installed compiler will
    initially generate that previous version. However, stop accepting
    an even older version that we stopped generating several months ago.

compiler/parse_pragma_foreign.m:
    When the compiler finds a reference to Erlang as a foreign language,
    add a message about support for Erlang being discontinued to the error
    message.

    Make the code parsing foreign_decls handle the term containing
    the foreign language the same way as the codes parsing foreign
    codes, procs, types and enums.

    Add a mechanism to help parse_mutable.m to do the same.

compiler/parse_mutable.m:
    When the compiler finds a reference to Erlang as a foreign language,
    print an error message about support for Erlang being discontinued.

compiler/compute_grade.m:
    When the compiler finds a reference to Erlang as a grade component,
    print an informational message about support for Erlang being discontinued.

compiler/pickle.m:
compiler/make.build.m:
    Delete Erlang foreign procs and types.

compiler/add_foreign_enum.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pred.m:
compiler/add_solver.m:
compiler/add_type.m:
compiler/check_libgrades.m:
compiler/check_parse_tree_type_defns.m:
compiler/code_gen.m:
compiler/compile_target_code.m:
compiler/compute_grade.m:
compiler/const_struct.m:
compiler/convert_parse_tree.m:
compiler/dead_proc_elim.m:
compiler/decide_type_repn.m:
compiler/deps_map.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/foreign.m:
compiler/globals.m:
compiler/granularity.m:
compiler/handle_options.m:
compiler/hlds_code_util.m:
compiler/hlds_data.m:
compiler/hlds_module.m:
compiler/inlining.m:
compiler/int_emu.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/lambda.m:
compiler/lco.m:
compiler/llds_out_file.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/make_hlds_separate_items.m:
compiler/make_hlds_warn.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/ml_code_util.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_target_util.m:
compiler/ml_top_gen.m:
compiler/mlds.m:
compiler/mlds_dump.m:
compiler/mlds_to_c_export.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_data.m:
compiler/mlds_to_cs_export.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_cs_type.m:
compiler/mlds_to_java_export.m:
compiler/mlds_to_java_file.m:
compiler/mlds_to_java_type.m:
compiler/module_imports.m:
compiler/parse_pragma_foreign.m:
compiler/parse_tree_out.m:
compiler/polymorphism.m:
compiler/pragma_c_gen.m:
compiler/prog_data.m:
compiler/prog_data_foreign.m:
compiler/prog_foreign.m:
compiler/prog_item.m:
compiler/simplify_goal_scope.m:
compiler/special_pred.m:
compiler/string_encoding.m:
compiler/top_level.m:
compiler/uint_emu.m:
compiler/write_deps_file.m:
    Remove references to Erlang as a backend or as a target language.

tests/invalid/bad_foreign_code.{m,err_exp}:
tests/invalid/bad_foreign_decl.{m,err_exp}:
tests/invalid/bad_foreign_enum.{m,err_exp}:
tests/invalid/bad_foreign_export.{m,err_exp}:
tests/invalid/bad_foreign_export_enum.{m,err_exp}:
tests/invalid/bad_foreign_import_module.{m,err_exp}:
tests/invalid/bad_foreign_proc.{m,err_exp}:
tests/invalid/bad_foreign_type.{m,err_exp}:
    Add a test for Erlang as an invalid foreign language. Expect both the
    new error message for this new error, and the updated list of now-valid
    foreign languages on all errors.
2020-10-29 13:24:49 +11:00
Zoltan Somogyi
eee5821ea5 Clarify an error message by adding a comma.
compiler/check_promise.m:
    As above.

tests/invalid/assert_in_interface.err_exp:
tests/invalid/tricky_assert1.err_exp:
    Expect the comma.
2020-10-28 13:39:32 +11:00
Zoltan Somogyi
f6b21b418c Update programming style. 2020-10-27 23:11:11 +11:00
Peter Wang
88047bbb45 Delete Erlang from tests.
tests/general/float_test.exp3:
tests/general/float_test.m:
tests/general/read_dir_regression.exp4:
tests/general/read_dir_regression.m:
tests/hard_coded/remove_file.exp2:
tests/hard_coded/remove_file.m:
    Delete Erlang backend specific expected outputs.

tests/hard_coded/Mmakefile:
tests/hard_coded/erlang_deconstruct.exp:
tests/hard_coded/erlang_deconstruct.m:
tests/hard_coded/existential_list.exp:
tests/hard_coded/existential_list.m:
tests/valid/Mmakefile:
tests/valid/erl_ite_vars.m:
tests/valid/zf_erlang_bug.m:
    Delete erlang target specific tests.

tests/*:
    Delete Erlang foreign procs and foreign types.
2020-10-27 11:10:11 +11:00
Peter Wang
524f4d72e2 Delete references to Erlang backend in makefiles.
Mmake.workspace:
Mmakefile:
*/Mmakefile:
tests/*/Mmakefile:
tests/valid/Mmake.valid.common:
trace/Mmakefile:
    As above.
2020-10-27 11:10:11 +11:00
Zoltan Somogyi
660cfe4f83 s/predicate symbol predicate/predicate symbol/ in a diagnostic.
We used to generate diagnostics of the form

    The predicate symbol predicate `<'/2 is also overloaded here.

The second "predicate" is pure noise. It could never be "function",
even though the code generating that message was prepared for that.

compiler/typecheck.m:
    When typechecking a *predicate* call, don't specify the predicate
    being called using a data structure that can also refer to functions.

compiler/typecheck_info.m:
    When representing an overloaded predicate name, as opposed to
    an overloaded function name, don't include a pred_or_func indication
    that should *always* be pf_predicate.

compiler/typecheck_errors.m:
    When reporting an overloaded predicate name, or talking about a
    predicate's argument vector, do not take a pred_or_func indication,
    since it should *always* be pf_predicate.

tests/invalid/ambiguous_overloading_error.err_exp:
tests/warnings/ambiguous_overloading.exp:
    Don't expect the redundant "predicate" in the overload error message.

tests/invalid/max_error_line_width.err_exp:
tests/invalid/max_error_line_width.m:
    The deletion of the redundant "predicate" in overload error messages
    made them all fit on one line, robbing this test of its task of testing
    longer-than-80-column output lines. Change the test so that the overload
    is not between int.< and float.<, but between the unchecked_left_shift
    functions in int and uint, since the longer function name yields error
    message lines in the length range this test case wants to test.

tests/invalid/ambiguous_overloading_error.m:
tests/invalid/arg_permutation.m:
tests/invalid/assert_in_interface.m:
tests/invalid/bad_detism_category.m:
    Fix programming style.

tests/invalid/assert_in_interface.err_exp:
    Update a line number.
2020-10-26 20:28:18 +11:00
Zoltan Somogyi
c18cd1ff51 Rebuild nonlocals and instmaps when deleting code.
This fixes Mantis bug #512, whose symptom is a compiler abort in some
very specific circumstances. The regression test for the bug below
documents the long causal chain needed to tickle this abort.

compiler/simplify_goal_conj.m:
    When deleting unreachable code, set the requanify flag, which also
    causes instmap_deltas to be recomputed. The immediate cause of the bug
    was an instmap_delta that should have been thus recomputed, but wasn't.

    Do this in both places where simplification can delete dead code,
    though the Mantis 512 test case involves only one.

tests/valid/bug512.m:
    A regression test for this bug.

tests/valid/Mercury.options:
tests/valid/Mmakefile:
    Enable the new test case, and run it with the flags that tickle
    the bug it is guarding against.
2020-10-23 01:38:58 +11:00
Zoltan Somogyi
f290cffc7e Delete code to clean up obsolete files. 2020-10-16 07:27:26 +11:00
Peter Wang
89e59e7cc8 Delete support for browsing terms as XML.
The 'browse --xml' command has not worked with current versions of
xsltproc for quite some time, but we have not received any bug reports,
nor has anyone tried to fix it. We have a method for interactively
exploring a term in 'browse --web' so IMHO there is no need to keep
support for 'browse --xml'.

browser/browse.m:
browser/browser_info.m:
browser/declarative_user.m:
trace/mercury_trace_browse.c:
trace/mercury_trace_browse.h:
trace/mercury_trace_cmd_browsing.c:
trace/mercury_trace_cmd_parameter.c:
trace/mercury_trace_cmd_parameter.h:
trace/mercury_trace_internal.c:
    Delete code.

doc/mdb_categories:
doc/user_guide.texi:
    Delete documentation.

configure.ac:
    Don't search for a XUL browser and xsltproc.

scripts/mdbrc.in:
    Delete 'xml_browser_cmd' and 'xml_tmp_filename' lines.

scripts/xul_tree.xsl:
    Delete now unused file.

scripts/Mmakefile:
    Conform to deletions.

tests/debugger/Mmakefile:
tests/debugger/browser_test.exp:
tests/debugger/browser_test.exp3:
tests/debugger/browser_test.inp:
tests/debugger/mdb_command_test.inp:
tests/debugger/save.exp2:
tests/declarative_debugger/browse_arg.exp:
tests/declarative_debugger/browse_arg.inp:
    Don't test 'browse --xml' any longer.

extras/xml_stylesheets/README:
    Delete reference to 'browse --xml' command.

NEWS:
    Announce change.
2020-10-14 17:41:54 +11:00
Zoltan Somogyi
dd1d427578 Update programming style. 2020-10-11 11:44:13 +11:00
Zoltan Somogyi
409cbcb6a3 Unify getopt.m and getopt_io.m ...
... using an approach proposed by Peter, with an extra twist from Julien.

Instead of having two modules, getopt.m and getopt_io.m, with the former
defining predicates that do not take an I/O state pair, and the latter
defining predicates that do take an I/O state pair, put both kinds of
predicates into a single module. The versions with an I/O state pair
have an "_io" suffix added to their names for disambiguation.
Both versions are a veneer on top of a common infrastructure,
which relies on a simple type class to implement the operation
"give the contents of the file with this name". The predicate versions
with I/O state pairs have a normal implementation of this typeclass,
while the predicate versions that do not have I/O state pairs
have an implementation that always returns an error indication.

The above change just about doubles the number of exported predicates.
We already had two versions of most exported predicates that differed
in whether we returned errors in the form of a string, or in the form
of a structured representation, with names of the latter having
an "_se" suffix. Since we agreed that the structured representation
is the form we want to encourage, this diff deletes the string versions,
and deletes the "_se" suffix from the predicate names that used to have them.
(It still remains at the end of the name of a type.) This "undoubling"
should offset the effect of the doubling in the previous paragraph.

Eventually, we want to have just one module, getopt.m, containing
the updated code described above, but for now, we put the same code
into both getopt_io.m and getopt.m to prevent too big a shock to
people with existing code that uses getopt_io.m.

library/getopt.m:
library/getopt_io.m:
    Make the changes described above.

library/Mmakefile:
    Instead of building both getopt_io.m and getopt.m from getopt_template,
    build getopt.m from getopt_io.m.

tools/bootcheck:
    Delete references to getopt_template.

compiler/typecheck_errors.m:
    When a type error involves one of the getopt/getopt_io predicates
    whose interfaces are changed by this diff, tell the user about
    how these changes could have caused the error, and thus what the
    probable fix is.

compiler/handle_options.m:
browser/parse.m:
deep_profiler/mdprof_cgi.m:
deep_profiler/mdprof_create_feedback.m:
deep_profiler/mdprof_dump.m:
deep_profiler/mdprof_procrep.m:
deep_profiler/mdprof_report_feedback.m:
deep_profiler/mdprof_test.m:
profiler/mercury_profile.m:
slice/mcov.m:
slice/mdice.m:
slice/mslice.m:
slice/mtc_diff.m:
slice/mtc_union.m:
tests/hard_coded/space.m:
    Use the updated getopt interface.

compiler/compile_target_code.m:
compiler/compute_grade.m:
compiler/deforest.m:
compiler/det_report.m:
compiler/format_call.m:
compiler/globals.m:
compiler/goal_expr_to_goal.m:
compiler/make.build.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_main.m:
compiler/ml_top_gen.m:
compiler/module_cmds.m:
compiler/op_mode.m:
compiler/optimization_options.m:
compiler/options.m:
compiler/write_module_interface_files.m:
tools/make_optimization_options_middle:
tools/make_optimization_options_start:
    Replace references to getopt_io.m with references to getopt.m.

tests/invalid/getopt_io_old.{m,err_exp}:
tests/invalid/getopt_old.{m,err_exp}:
tests/invalid/getopt_old_se.{m, err_exp}:
    New test cases for the extra help

tests/invalid/Mmakefile:
    Enable the new test cases.
2020-10-09 19:30:46 +11:00
Zoltan Somogyi
7583d27f21 Warn about missing information in .int files.
compiler/add_pred.m:
    When recording the declaration of a predicate or function that is
    imported from another module, report an error for any types in the
    argument list that were not module qualified when the .int file
    was constructed.

    Eventually, once the cleanup of our system of managing interface files
    is done, we can switch to preventing the generation of .int files
    with missing information. The above change should help until then.

tests/invalid/bug521.m:
tests/invalid/bug521_sub.m:
tests/invalid/bug521.err_exp:
    A new test case for the new error message.

tests/invalid_make_int/bug521_sub.m:
tests/invalid_make_int/bug521_sub.int_err_exp:
tests/invalid_make_int/Mercury.options:
    A new test case for how we would diagnose the same problem
    at interface-generation time.

tests/invalid/Mmakefile:
tests/invalid_make_int/Mmakefile:
    Enable the new test cases.
2020-10-08 16:04:02 +11:00
Zoltan Somogyi
d23c4f74a3 Update the style of more tests. 2020-10-06 19:20:18 +11:00
Peter Wang
7fec2d28a7 Add test for mdb 'list' external command.
tests/debugger/list_cmd.m:
tests/debugger/list_cmd.inp:
tests/debugger/list_cmd.exp:
tests/debugger/list_cmd.exp2:
    Add new test case.

tests/debugger/list_cmd.sh:
    Add script to be set as the 'list_cmd'.

tests/debugger/Mmakefile:
    Enable the new test.
2020-10-06 13:42:39 +11:00
Zoltan Somogyi
a69fc36be0 Update some tests' programming style. 2020-10-05 17:53:05 +11:00
Zoltan Somogyi
f8c67929de Modernize library/array2d.m.
library/array2d.m:
    Add lookup and unsafe_lookup, in both function and predicate forms,
    as alternatives to rafe's ^elem notation.

    Use meaningful variable names in both code and documentation.
    For example, use NumRows and NumColumns instead of M and N.

    Replace the implementation of the function that converts a 2d array
    back to lists. The new implementation has one loop over rows and one
    loop over columns, while the old one had a single loop that did
    both jobs. The new one returns [] (meaning no rows) for a 0x0 array,
    while the old returned [[]] (meaning one row with no columns).

NEWS:
    Announce the changes.

tests/hard_coded/test_array2d.m:
    Use a lookup instead of ^elem.

tests/hard_coded/test_array2d.exp:
    Expect the updated output from lists. Expect any exceptions to come
    from lookup functions, not ^elem functions (since the latter now
    just call the former).
2020-10-05 00:06:37 +11:00
Zoltan Somogyi
be3f9443b1 Simplify the setup of mdbrc for tests.
We used to set up *two* mdbrc files for use by test cases:
scripts/test_mdbrc, and tests/mdbrc. Tools/bootcheck said
the tests should use the former, while tests/Mmake.common
said they should use the latter. This diff deletes the latter,
and uniformly uses the former.

The setup code was also scattered, with parts being done by
the configure script, and part being done by tools/bootcheck.
Move it all to scripts/Mmakefile, since that is the natural
place to put code to build scripts/test_mdbrc.

Mmakefile:
    Fix the action for cleaning up the tests directory.
    This started out as the reason for this whole change.
    As it happens, a *working* action for cleaning up the tests
    broke things, because it deleted an autoconfigured file
    (tests/mdbrc) that there was no rule for rebuilding.
    This issue is what required the rest of this diff.

    When doing "mmake clean/realclean", clean the extras as well.

configure.ac:
    Delete the code creating tests/mdbrc.in.

scripts/Mmakefile:
    Add a rule to build test_mdbrc, as mentioned above.

tests/Mmake.common:
    Switch to using scripts/test_mdbrc in test cases
    run under mdb.

    Mark the rules that clean up mdbrc and mdbrc.in
    as obsolete, since we will now stop creating those files.

tools/bootcheck:
    Delete the code that used to build tests/mdbrc. Instead,
    rebuild scripts/test_mdbrc (in case the workspace was moved),
    and use that.

tests/Mmakefile:
    When cleaning the tests directory, clean its subdirectories
    (since the top level directory does not have much clean).
2020-10-04 23:00:29 +11:00
Zoltan Somogyi
0d59d6faef Update programming style. 2020-10-04 18:07:18 +11:00
Zoltan Somogyi
4865f11503 Update programming style. 2020-10-04 13:20:42 +11:00