Commit Graph

1472 Commits

Author SHA1 Message Date
Zoltan Somogyi
8ab02a3134 Stop littering /tmp with temp files. 2023-10-06 05:30:37 +11:00
Zoltan Somogyi
c69b7e4b9a Add "did you mean ..." to undef pred reports.
compiler/typecheck_error_undef.m:
    If we are reporting an error for a reference to an undefined predicate,
    check whether any predicates exist whose names are "close enough"
    to the name of the referenced predicate, and if yes, add to the
    error message a line containing "(Did you mean x, y or z?)".

    (Doing the same for references to undefined functions is future work.
    The two are separate because things that look like function references
    can also refer to e.g. data constructors.)

library/edit_distance.m:
    Add this new module to implement the "close enough" check.
    This new module is similar to the existing edit_seq.m module,
    but it is designed to serve different requirements, and it seems to me
    to be far from trivial to write code to meet both sets of requirements
    at once.

library/library.m:
library/MODULES_DOC:
    Include the new module in the standard library.

NEWS.md:
    Announce the new library module.

tests/hard_coded/edit_distance_test_closest.{m,exp}:
tests/hard_coded/edit_distance_test_cost.{m,exp}:
    Two new test cases, each of which tests one of the two predicates
    exported by the new library module.

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

tests/invalid/qual_basic_test2.err_exp:
tests/invalid/types2.err_exp:
tests/invalid/undef_symbol.err_exp:
tests/invalid_submodules/undef_mod_qual.err_exp:
    Expect the new "did you mean" additions to error messages.
2023-09-26 00:56:19 +10:00
Zoltan Somogyi
a0d6710407 Use "ts=4 sw=4 expandtab" as modeline ...
... in Mercury.options files.
2023-09-16 19:12:52 +10:00
Zoltan Somogyi
7b21fcfe0a Fix an old fat-fingered update to this .exp file. 2023-09-07 08:55:42 +10:00
Zoltan Somogyi
1d2b4bf503 Improve the style of a test case. 2023-08-23 01:53:43 +02:00
Zoltan Somogyi
97441ce3fe Simplify the code adding foreign_proc to the HLDS.
compiler/add_foreign_proc.m:
    Simplify the if-then-else chain that checks whether a foreign_proc
    should be added to the HLDS, and if not, what, if any, error message
    should be generated for it.

    Document two separate factors that complicate the cases that
    this chain has to deal with. Name the test cases that exemplify
    those complications.

compiler/hlds_pred.m:
    Activate an old commented-out optimization.

tests/hard_coded/foreign_type2.m:
    Put the contents of this test case (one of the ones now listed in
    add_foreign_proc) into a logical order. The reordering does not affect
    the substance of the test.
2023-08-03 03:30:20 +02:00
Julien Fischer
85e84f4f62 Fix the failure of hard_coded/runtime_opt on Windows.
tests/hard_coded/runtime_opt.exp2:
    Alternative expected output for where stdout and stderr are
    interleaved differently.

tests/hard_coded/runtime_opt.m:
    Document what the expected outputs are for.
2023-07-28 20:20:19 +10:00
Zoltan Somogyi
88d4bccdba Add new optimization option --split-switch-arms.
Given a switch arm that matches several cons_ids, and which contains
one or more switches on the *same* variable, such as the arm for
f1/f2/f3/f4 below,

    (
        (X = f1 ; X = f2 ; X = f3 ; X = f4),
        ...
        (
            X = f1,
            ...
        ;
            (X = f2 ; X = f3),
            ...
        ;
            X = f4,
            ...
        ),
        ...
    ;
        ...
    )

this new optimization

- partitions the set of cons_id in that arm (in this case, {f1,f2,f3,f4})
  as finely as needed by any other the switches on X in that arm
  (in this case, that is three partitions containing {f1}, {f2,f3} and {f4}),

- splits that original switch arm into N arms, one arm for each partition,
  making a copy of the switch arm's goal for each partition,

- restricts any switches on the original switch variable (in this case, X)
  inside the copy of the arm goal inside each new case to only the cons_ids
  in that case's partition, and then replacing any resulting one-arm switches
  with the just goal inside that one arm.

The code resulting from these three steps will include some code duplication
(some of the pieces of code denoted by ... in the example above would be
duplicated), but it will need to execute fewer transfers of control.
This is worthwhile because (a) the branch instructions used to implement
switches are hard to predict unless most paths through the nested switches
are rarely if ever taken, and (b) the pipeline breaks caused by branches
that are not correctly predicted are one of the two major contributors
to the runtime of Mercury programs. (The other major contributors are
data cache misses.)

The implementation of this option has two major parts.

- Part 1 consists of discovering whether a procedure body contains
  any code in which a switch on a variable is nested inside an arm
  of another switch on that same variable. For any instance of such
  a pair of switches, it records the identity of the variable and
  the set of cons_ids of the outermost arm.

- Part 2 consists of actually transforming the procedure body
  by splitting each outermost switch arm thus recorded. (This part
  contains all three of the steps above.)

We integrate part 1 with the usual procedure body traversal of the
simplification pass, which makes it quite cheap. In most procedure bodies,
it won't find any nested switches meeting its criteria. We execute part 2,
which is relatively expensive, only if it does.

compiler/simplify_info.m:
    Add a new type, switch_arm, which represents one arm of a switch.

    Add a new field to the simplify_nested_context type. Its type
    is list(switch_arm), and it represents the stack of switch arms (if any)
    that the goal currently being simplified is inside. simplify_goal_switch.m
    uses this field to detect switches that occur inside an arm of an
    ancestor goal that is also a switch on the same variable.

    Add a new field to the simplify_info, a set of switch_arms,
    that denotes the set of switch arms from which that detection
    has actually happened, and which should therefore be
    partitioned and split.

compiler/simplify_goal_switch.m:
    Add the code for doing the detection and recording mentioned just above.
    This is the Part 1 mentioned above.

compiler/split_switch_arms.m:
    This new module implements the splitting up process.
    This is the Part 2 mentioned above.

compiler/simplify.m:
    Include the new module in the simplify subpackage of the check_hlds
    package.

compiler/notes/compiler_design.html:
    Document the new module.

compiler/simplify_proc.m:
    Invoke split_switch_arms.m (part 2) if the part of simplify_goal_switch.m
    implementing part 1 has found any work for it to do.

compiler/simplify_tasks.m:
    Add split_switch_arms as one of the tasks that simplification
    may be asked to do. Set its default value from the value of
    a new optimization option that, when specified, calls for it to be done.

compiler/options.m:
    Add this option, --split-switch-arms.

    Change the internal name of an existing option,
    everything_in_one_c_function, to the one expected by
    tools/make_optimization_options_middle.

    Replace the part of this file that is constructed by
    tools/make_optimization_options_middle.

doc/user_guide.texi:
    Document the new option.

tools/make_optimization_options_db:
    Add --split-switch-arms to the optimization tuple.

    Fix software rot by

    - renaming optimize_tailcalls to optimize_mlds_tailcalls inside the
      optimization tuple, as it has been in options.m, and

    - deleting erlang_switch_on_strings_as_atoms from the opt_tuple,
      as it has been from options.m.

tools/make_optimization_options_end:
    Enable the new option by default at optimization level 2.

tools/make_optimization_options_middle:
    Fix bugs in this script, which generates compiler/optimization_options.m.

    One bug was that it referred to the opt_level and opt_space options
    by the wrong name (optopt_level and optopt_space respectively).
    The other bug was that it expected opt_level to be a string_special option,
    when it is an int_special option.

    Make the handler_file this script generates easier to put into options.m
    by not generating a line that (a) already exists in options.m, and
    (b) would need to have a comma put after it, if one wanted this line
    to replace the copy already in options.m.

compiler/optimization_options.m:
    Rebuild this file after the changes above.

compiler/simplify_goal_unify.m:
    Conform to the changes above.

compiler/inst_merge.m:
    Mark two predicates, inst_merge_[34], to be inlined. The intention
    is that inst_merge_4 should be inlined into inst_merge_3, and then
    inst_merge_3 should be inlined inside inst_merge_2; that would then
    generate six levels of switches, three on one of the insts to be
    merged and three on the other, which the new optimization could
    then flatten. Unfortunately, inlining does not do this yet.

tests/hard_coded/test_split_switch_arms.{m,exp}:
    A new test case for the the new transformation.

tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
    Enable the new test case, and specify the new option for it.
2023-07-24 19:14:17 +02:00
Julien Fischer
1c8eece402 Avoid warnings from MSVC in tests.
tests/hard_coded/backend_external.m:
tests/hard_coded/backend_external_pred.m:
tests/hard_coded/c_write_string.m:
tests/hard_coded/ee_dummy.m:
tests/hard_coded/pragma_c_code.m:
tests/hard_coded/pragma_foreign_export.m:
tests/hard_coded/target_mlobjs.m:
tests/hard_coded/type_tables.m:
tests/submodules/sm_exp_bug.m:
    Use don't-care variables to handle the I/O state in foreign procs.
    Assigning the I/O state at the end of the foreign_proc body results
    in spurious warnings about uninitialized variables from MSVC.
2023-07-22 23:24:54 +10:00
Julien Fischer
03aa92fa34 Fix failure of hard_coded/write_xml with 32-bit MSVC.
tests/hard_coded/write_xml.m:
tests/hard_coded/write_xml.exp5:
     Add an expected output for 32-bit MSVC.
2023-07-15 01:33:25 +10:00
Julien Fischer
8032229faa Fix a typo.
tests/hard_coded/Mmakefile:
    As above.
2023-07-12 01:42:31 +10:00
Julien Fischer
7d5bd151be Fix tests/hard_coded/nonascii with MSVC.
tests/hard_coded/Mmakefile:
    Invoke cl appropriately to compile nonascii_gen.

    Handle the .exe extension where necessary.

tests/DEFNS_FOR_TESTS.in:
    Add a variable that says of we are using MSVC.
2023-07-11 17:17:03 +10:00
Julien Fischer
f999105ad4 Fix the failure tests/hard_coded/write_xml on Windows.
tests/hard_coded/write_xml.m:
tests/hard_coded/write_xml.exp4:
     Add an expected output for the low-level C grades on Windows.
2023-07-09 13:23:31 +10:00
Julien Fischer
0e980917e1 Fix the failure tests/hard_coded/write_xml on Windows.
tests/hard_coded/write_xml.m:
    Update the comment at the head of this module that explains the
    differences between the expected outputs.

tests/hard_coded/write_xml.exp3:
    Expected output for this test on in a high-level C grade on Windows.
2023-07-08 23:16:12 +10:00
Julien Fischer
837a677c37 Fix failure of test/hard_coded/nonascii on Windows.
The Substitute character (U+001A) is treated as EOF for text mode files on
Windows. Omit that character from the test.

tests/hard_coded/nonascii_gen.c:
    Do not emit U+001A in the set of test characters.

tests/hard_coded/nonascii.m:
    Conform to the above change.

    Update syntax in a spot.

tests/hard_coded/nonascii.exp:
    Conform to the above change.
2023-07-08 21:30:45 +10:00
Julien Fischer
b1ebb1b35e Replace tabs with spaces.
tests/hard_coded/nonascii_gen.c:
    As above. Add the usual vim modeline.
2023-07-08 20:58:24 +10:00
Peter Wang
7ba2f4d5c4 Fix typo causing compilation failure. 2023-07-06 17:40:34 +10:00
Zoltan Somogyi
f6e5a438c4 Allow underscores before exponents in floats.
library/mercury_term_lexer.m:
    As above.

NEWS.md:
    Announce the change.

doc/reference_manual.texi:
    Document the change.

tests/hard_coded/parse_number_from_string.exp:
tests/invalid_nodepend/invalid_float_literal.err_exp:
    Update these expected outputs after the change.
2023-07-02 02:20:39 +02:00
Julien Fischer
d0b64c87c7 Ignore files generated by MSVC.
*/.gitignore:
   Ignore any increment linker files (.ilk) and program database (.pdb)
   file that MSVC generates.
2023-07-01 02:25:53 +10:00
Julien Fischer
3e020479ec Fix typo.
test/hard_coded/Mercury.options:
    As above.
2023-06-24 14:46:23 +10:00
Julien Fischer
403d9c4e3d Add XXXs about some test failures with MSVC.
tests/hard_coded/Mercury.options:
    As above.
2023-06-24 14:21:42 +10:00
Zoltan Somogyi
ac57c2f70d Improve diagnostics for malformed number literals.
library/mercury_term_lexer.m:
    Make the diagnostics for malformed numbers more detailed, and thus
    more easily understandable.

tests/hard_coded/parse_number_from_string.exp:
tests/invalid_nodepend/invalid_binary_literal.err_exp:
tests/invalid_nodepend/invalid_decimal_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:
    Update the expected error messages.
2023-06-19 01:10:19 +02:00
Julien Fischer
c14af1428e Fix the failure of hard_coded/special_char on Windows.
tests/hard_coded/special_char.m:
tests/hard_coded/special_char.exp2:
    Add an additional expected output for systems that use
    CRLF line endings.
2023-06-18 23:08:13 +10:00
Zoltan Somogyi
2bd7c5ee3e Rename X's aux modules as X_helper_N in hard_coded.
tests/hard_coded/*.m:
    Rename modules as mentioned above.

    In a few cases, where the main module's name itself had a suffix,
    such as "_mod_a" or "_main", remove that suffix. This entails
    renaming the .exp file as well. (In some cases, this meant that
    the name of a helper module was "taken over" by the main module
    of the test case.)

    Update all references to the moved modules.

    General updates to programming style, such as

    - replacing DCG notation with state var notation
    - replacing (C->T;E) with (if C then T else E)
    - moving pred/func declarations to just before their code
    - replacing io.write/io.nl sequences with io.write_line
    - replacing io.print/io.nl sequences with io.print_line
    - fixing too-long lines
    - fixing grammar errors in comments

tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
    Update all references to the moved modules.

    Enable the constant_prop_int test case. The fact that it wasn't enabled
    before is probably an accident. (When constant_prop_int.m was created,
    the test case was added to a list in the Mmakefile, but that list
    was later removed due to never being referenced.)

tests/hard_coded/constant_prop_int.{m,exp}:
    Delete the calls to shift operations with negative shift amounts,
    since we have added a compile-time error for these since the test
    was originally created.
2023-06-16 08:33:22 +02:00
Julien Fischer
2a366cf295 Deprecate --no-ansi and --no-ansi-c.
--no-ansi (mgnuc) and --no-ansi-c (mmc) have not actually done anything for
many years now. Deprecate these options and remove their "use" throughout most
of the Mercury system. (The remaining uses are in the Makefiles for the Boehm
GC, which need to be updated separately.)

Also deprecate the internal compiler option --cflags-for-ansi.

compiler/options.m:
    Document that --no-ansi-c is now deprecated.

    Document that the internal option --cflags-for-ansi is now
    deprecated.

compiler/compile_target_code.m:
    Do not pass the ANSI options to the C compiler.

scripts/mgnuc.in:
scripts/mgnuc_file_opts.sh-subr:
    Deprecate the --no-ansi option; delete code that no longer does
    anything useful.

configure.ac:
    Delete the configuration variable CFLAGS_FOR_ANSI; it is only ever
    set to be empty. (The comment talks about --no-ansi doing other things
    in the mgnuc script. It used to also cause some preprocessor macros
    to be defined for compatibility with the system headers on some
    platforms -- that has not been the case since 2013.)

doc/user_guide.texi:
    Document that --no-ansi-c is deprecated.

bytecode/Mmakefile:
compiler/Mercury.options:
library/Mercury.options:
extras/odbc/odbc.m:
runtime/Mmakefile:
scripts/Mercury.config.bootstrap.in:
scripts/Mercury.config.in:
tests/hard_coded/Mercury.options:
tests/valid/Mercury.options:
trace/Mmakefile:
util/Mmakefile:
    Conform to the above change.

NEWS.md:
    Announce the above.
2023-05-31 17:44:26 +10:00
Zoltan Somogyi
9364d4cbc5 Replace tables with spaces. 2023-05-02 02:25:38 +10:00
Zoltan Somogyi
3364b69e34 Simplify a test. 2023-05-02 02:22:46 +10:00
Zoltan Somogyi
b2ab9f8711 Wrap the test term in angle brackets.
tests/hard_coded/write_binary.{m,exp}:
    Wrap the test term in angle brackets, in order to make the presence
    of spaces, tabs and newlines apparent.
2023-04-27 21:27:21 +10:00
Zoltan Somogyi
810d95a7ea Update the hard_coded/write_binary test case.
tests/hard_coded/write_binary.m:
    Print the term whose write-out-and-read-back is being tested
    before the test, not after. Print the result of the test after this.

    If the test succeeds, don't print the term out again.

    Put blank lines between different kinds of tests, and between
    tests of different terms.

    Return error messages as strings, rather than as exceptions,
    where possible.

    Make the diagnostic for "read back term differs from original"
    more useful for debugging write_binary/read_binary.

    Put the declaration of a predicate just before the predicate.

tests/hard_coded/write_binary.exp:
    Expect the updated output.
2023-04-27 21:19:51 +10:00
Zoltan Somogyi
4281a28f73 Make text_{input,output}_stream standalone types ...
... and make {input,output}_stream synonyms for them, rather than vice versa.

library/io.m:
    As above.

library/bitmap.m:
library/dir.m:
library/io.primitives_read.m:
library/io.stream_db.m:
library/io.text_read.m:
library/mercury_term_lexer.m:
library/stream.string_writer.m:
    Conform to the change above.

tests/hard_coded/stream_string_writer_types.exp:
    Expect the new type_ctor for text streams.
2023-04-24 13:52:10 +10:00
Julien Fischer
5de97e355a Replace references to the c_header_code pragma.
tests/hard_coded/needs_init.m:
tests/hard_coded/pragma_c_code.m:
    As above.
2023-02-25 12:55:08 +11:00
Zoltan Somogyi
3c931d074c Delete old_list_to_set.
library/fat_sparse_bitset.m:
library/sparse_bitset.m:
    As above.

tests/hard_coded/speedtest_bitset.m:
    Delete references to old_list_to_set.
2023-02-03 19:30:53 +11:00
Zoltan Somogyi
ee0f9f73d7 Add library/fatter_sparse_bitset.m.
library/fatter_sparse_bitset.m:
    Add this version of fat_sparse_bitset.m, which stores *two* words
    worth of bits in each cell, not one. This word would otherwise be unused,
    because the Boehm-Demers-Weiser allocator rounds up requests for three
    word cells to four.

library/MODULES_DOC:
library/library.m:
    Add the new module to the list of library modules.

library/fat_sparse_bitset.m:
library/sparse_bitset.m:
library/tree_bitset.m:
    Update the documentation of all these other bitset modules. Copy
    the same basic introduction to all the relevant modules. Add documentation
    of the differences to tree_bitset.m and fatter_sparse_bitset.m, with
    a pointer in fat_sparse_bitset.m to fatter_sparse_bitset.m.

library/test_bitset.m:
    Test the new module as well as the others.

tests/hard_coded/speedtest_bitset.m:
    Extend the benchmarking of list_to_set operations to the new module.
    To allow the benchmarking to be tough enough to be informative, comment
    out the benchmarking of the old_list_to_set operations.
2023-01-31 18:36:16 +11:00
Zoltan Somogyi
6f6d30b8f2 Improve the speed of fat_sparse_bitset.list_to_set ...
... by using the algorithm now in sparse_bitset.list_to_set.

Keep the old list_to_set algorithm around in both modules for a short while
to allow comparative benchmarking.

library/fat_sparse_bitset.m:
library/sparse_bitset.m:
    As above.

tests/hard_coded/speedtest_bitset.m:
    A benchmark program to compare the old and new list_to_set algorithms,
    both versus each other, and between sparse_bitset and fat_sparse_bitset.
2023-01-29 07:57:44 +11:00
Zoltan Somogyi
80b1d4a7e3 Test all bitset implementation at once.
library/test_bitset.m:
    Instead of comparing just one bitset module (tree_bitset by default)
    against set_ordlist, compare all of them (tree_bitset, sparse_bitset,
    and fat_sparse_bitset) against set_ordlist.

tests/hard_coded/test_bitsets.{m,exp}:
    Rename this test case from test_tree_bitset to test_bitsets, since
    (through library/test_bitset.m) we now test ALL bitset implementations,
    not just tree_bitset.

tests/hard_coded/Mmakefile:
    Refer to the test by its new name.
2023-01-29 04:04:24 +11:00
Julien Fischer
bbff6f8609 Fix a bug in string.format.
The current implementation of the unsigned conversion specifiers (i.e. %x, %X,
%o, %u) for fixed-size 8-, 16- and 32-bit signed integers works by casting
theses values into (word-sized) ints and then using the existing code for
formatting ints as unsigned values. This does not work for negative values as
they are being sign extended when converted to ints. For example,

      io.format("%x", [i8(min_int8)], !IO)

prints:

      ffffffffffffff80 (on a 64-bit machine)

rather than just:

      80

Fix the above problem by casting ints, int8s, int16s etc. that are being
formatted as unsigned values to uints and using the uint formatting code.

NOTE: the formatting code for 64-bit integers follows a different code path
and is not affected by any of this.

library/string.format.m:
    Implement unsigned conversion specifiers for non-64-bit signed
    integers by casting to uint and using the uint formatting code.

    Add predicates for converting signed integers into uints.

    The format_unsigned_int_* predicates can be deleted after this change
    is installed.

compiler/format_call.m:
    Implement unsigned conversion specifiers for non-64-bit signed
    integers by casting to uint and using the uint formatting code.

compiler/introduced_call_table.m:
    Update the table of introduced predicates.

compiler/options.m:
    Add an option that can be used to test whether this fix is
    installed.

tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
tests/hard_coded/opt_format_sign_extend.{m,exp}:
    Test that formatting code introduced by the compiler does not
    accidentally sign-extend negative values.

tests/string_format/string_format_{o,x,u}.{m,exp,exp2}:
    Make these tests much more comprehensive then they previously
    were.
2023-01-27 17:16:54 +11:00
Peter Wang
9fa20d1e71 Delete unused transitive closure implementations.
library/digraph.m:
    Delete simple_tc and stack_tc.

    Reorder some code.

tests/hard_coded/digraph_tc.m:
    Delete code for testing simple_tc and stack_tc.
2023-01-25 16:14:11 +11:00
Peter Wang
0eb4281a90 Implement two more transitive closure algorithms.
Implement two transitive closure algorithms in the digraph module:

  - Basic_TC by Yannis Ioannidis et al.

  - STACK_TC by Esko Nuutila, a refinement of the SIMPLE_TC algorithm
    previously implemented

On 450 graphs randomly generated by tests/hard_coded/digraph_tc.m,
ranging from 100 to 3000 vertices:

  - basic_tc ran from 0.79 to 1.66 times as fast as simple_tc
    (mean 1.139, stdev 0.136)

  - basic_tc ran from 0.83 to 1.81 times as fast as stack_tc
    (mean 1.131, stdev 0.160)

Therefore, after this commit, I will delete the simple_tc and stack_tc
implementations, but they will be available in the version history.

library/digraph.m:
    Implement Basic_TC and STACK_TC.

    Use map.transform_value in key_set_map_union to replace a search
    followed by update.

tests/hard_coded/digraph_tc.m:
    Test and benchmark the new algorithms.

    Also compare inverse graphs to check that predecessor maps are
    maintained properly.
2023-01-25 12:28:45 +11:00
Zoltan Somogyi
56ed26f650 Improve the remove_{leq,gt} sparse bitset ops.
library/sparse_bitset.m:
library/fat_sparse_bitset.m:
    Speed up the remove_leq and remove_gt operations by moving a
    loop invariant computation, the conversion of the boundary item's index
    into an <offset,bitposn> pair, out of the loop.

    Eliminate some unnecessary differences between the two modules,
    e.g. clear_bit being a predicate rather than a function.

library/test_bitset.m:
    Add facilities to test the remove_leq and remove_gt operations
    of sparse_bitset.m, fat_sparse_bitset.m, and tree_bitset.m
    against the same operations on plain old set_ordlists.

    Bring this module up to date by requiring set elements to be
    members of the uenum typeclass, not the enum typeclass.

    Make the test_bitset type a bespoke type.

library/tree_bitset.m:
    Add predicate versions of the remove_leq and remove_gt operations
    alongside the existing function versions, to allow the new code
    in test_bitset.m to work the same way regardless of which bitset module
    it is testing.

    For uniformity with the other bitset modules, require set elements to be
    members of the uenum typeclass, not the enum typeclass.

    Change the other integers, such as level numbers, to be unsigned
    as well, to avoid the need for casts.

NEWS:
    Announce the new additions and changes.

tests/hard_coded/test_tree_bitset.{m,exp}:
    Use those new facilities to test those operations, and add some
    test sets designed for that purpose.

    Add a comment about the limitations of this testing strategy.

tests/hard_coded/bitset_tester.m:
    Delete this long-unused module. (It was the original basis of
    the test_bitset.m module in the library directory, but it became unused
    when test_tree_bitset.m switched to using that module a long time ago.)
2023-01-19 14:42:34 +11:00
Peter Wang
b270b6d01c Delete old transitive closure implementation.
library/digraph.m:
    Delete digraph.old_tc, digraph.old_rtc and digraph.slow_rtc.

tests/hard_coded/digraph_tc.m:
tests/hard_coded/digraph_tc.exp:
    Delete comparisons using old_tc, old_rtc and slow_rtc.
2023-01-18 16:50:41 +11:00
Peter Wang
685e632a13 Implement simple_tc algorithm.
Implement transitive closure using the simple_tc algorithm from
Esko Nuutila's doctoral thesis.

On a sample of graphs randomly generated by tests/hard_coded/digraph_tc.m,
ranging from 100 to 3000 vertices, the simple_tc implementation ran
from 2.33 to 93 times as fast as the old implementation on my machine.

library/digraph.m:
    Rename digraph.tc and digraph.rtc to digraph.old_tc and
    digraph.old_rtc. They are kept around for benchmarking,
    and will be deleted soon.

    Use the simple_tc algorithm to implement digraph.tc.

    Use digraph.tc to implement digraph.rtc.

    Let key_set_map_add call sparse_bitset.insert_new instead of
    sparse_bitset.contains followed by sparse_bitset.insert.

tests/hard_coded/digraph_tc.m:
    Add code to benchmark the new and old TC implementations.
2023-01-18 16:50:41 +11:00
Julien Fischer
97735d9630 Do not allow std_util.pow/3 with negative values.
library/std_util.m:
    Make std_util.pow/3 throw an exception if it is called with a negative
    integer as its second argument.

tests/hard_coded/Mmakefile:
tests/hard_coded/func_exp.{m,exp}:
    Add a test of pow/3.

NEWS:
    Announce the above change.
2023-01-11 17:10:00 +11:00
Peter Wang
fba3fda155 Fix digraph.tc and digraph.rtc.
The implementation of digraph.rtc was incorrect (as demonstrated in the
new test case), which meant that digraph.tc was also incorrect.

library/digraph.m:
    Fix the implementation of rtc (reflexive transitive closure):

    - Following the algorithm used in digraph.cliques, it needs to
      traverse the graph G in *reverse* depth-first order.

    - To find the clique containing a vertex X, it needs to do a DFS on
      the *reversed* graph to find the vertices with a path to X.
      The vertices that were previously unvisited will be members of
      the same clique as X.

    - Previously it found the "followers" of the elements of the clique,
      and the followers of those followers, then added edges from the
      members of the current clique to those followers. However, that
      only includes vertices two steps removed from the clique.
      I have fixed it to add edges to *all* vertices reachable from
      members of the clique.

    Add straightforward implementations of tc and rtc for comparison.

    Add some comments.

tests/hard_coded/Mmakefile:
tests/hard_coded/digraph_tc.exp:
tests/hard_coded/digraph_tc.inp:
tests/hard_coded/digraph_tc.m:
    Add test case.

NEWS:
    Announce the fixes.
2023-01-11 11:04:26 +11:00
Zoltan Somogyi
5cbcfaa0ed Move X_to_doc functions to pretty_printer.m.
library/array.m:
library/char.m:
library/float.m:
library/int.m:
library/int16.m:
library/int32.m:
library/int64.m:
library/int8.m:
library/list.m:
library/one_or_more.m:
library/string.m:
library/tree234.m:
library/uint.m:
library/uint16.m:
library/uint32.m:
library/uint64.m:
library/uint8.m:
library/version_array.m:
    Mark the X_to_doc function in each of these modules as obsolete,
    and make it a forwarding function to the actual implementation
    in pretty_printer.m. The intention is that when these forwarding
    functions are eventually removed, this will also remove the dependency
    of these modules on pretty_printer.m. This should help at least some
    of these modules escape the giant SCC in the library's dependency graph.
    (It does not make sense that a library module that adds code to increment
    an int thereby becomes dependent on pretty_printer.m through int.m.)

library/pretty_printer.m:
    Move all the X_to_doc functions from the above modules here.

    Fix the one_or_more_to_doc function, which was

    - missing the comma between the two arguments of the one_or_more
      function symbol, and

    - would print "..., ...]" instead of just "...]" at the end of the
      tail list when that list exceeded the limits of the specified pp_params.

    Rename one of the moved types along with its function symbols,
    to reduce ambiguity.

    Put arrays before their indexes in the argument lists of some of
    the moved functions.

    Some of the moved X_to_doc functions for compound types returned
    a doc that had an indent wrapper. These indents differed between the
    various X_to_doc functions without any visible reason, but they are
    also redundant. The callers can trivially add such wrappers if they
    want to, but taking them off, if they want them off, is harder.
    Eliminate the problem by deleting all such indent wrappers.

    Add formatters for the intN, uintN and one_or_more types to the
    default formatter map. Their previous absence was an oversight.

    Add a function, get_formatter_map_entry_types, that returns the ids
    of the types in the formatter_map given to the function. It is intended
    for tests/hard_coded/test_pretty_printer_defaults.m, but is exported
    for anyone to use.

tests/hard_coded/test_pretty_printer_defaults.{m,exp}:
    Use get_formatter_map_entry_types to print the default formatter map
    in a format that is much more easily readable.

NEWS:
    Announce all the user-visible changes above.
2022-12-27 18:27:52 +11:00
Julien Fischer
5274170784 Make characters an instance of the uenum typeclass
The recent change to sparse_bitsets broke the lex library in extras.
Specifically, we now now need to make characters an instance of the
uenum typeclass. This diff does so.

library/char.m:
     Add predicates and functions for converting between unsigned integers
     and characters.

     Make characters an instance of the uenum typeclass.

tests/hard_coded/Mmakefile:
tests/hard_coded/char_uint_conv.{m,exp,exp2}:
     Add a test of the above conversions.

NEWS:
     Announce the additions.

extras/lex/lex.m:
     Conform to recent changes.
2022-12-20 20:18:54 +11:00
Zoltan Somogyi
fc3c6b462c Update an expected output file for Java ...
... for a change to io.file.m on 2022 aug 24.
2022-12-09 23:56:59 +11:00
Zoltan Somogyi
4c528d429d Add <<u and >>u to library/{int,uint}*.m ...
... along with their unchecked equivalents. These differ from <<, >> and
their unchecked equivalents in that they take the shift amount as a uint,
instead of an int.

library/int.m:
library/int16.m:
library/int32.m:
library/int64.m:
library/int8.m:
library/uint.m:
library/uint16.m:
library/uint32.m:
library/uint64.m:
library/uint8.m:
    As above. The unchecked versions have only declarations, since
    these operations have been recognized as builtins for a while now.

NEWS:
    Document the new operations, and the recent change to recognize
    <<u and >>u as single tokens, and fix a typo in a recent addition.

configure.ac:
    Require the compiler to be sufficiently recent to be able to parse
    <<u and >>u as operators.

compiler/options.m:
    Provide a way for a later change to configure.ac to detect the presence
    of this change.

tests/hard_coded/bitwise_int.exp:
tests/hard_coded/bitwise_int.exp2:
tests/hard_coded/bitwise_int.m:
tests/hard_coded/bitwise_int16.exp:
tests/hard_coded/bitwise_int16.m:
tests/hard_coded/bitwise_int32.exp:
tests/hard_coded/bitwise_int32.m:
tests/hard_coded/bitwise_int64.exp:
tests/hard_coded/bitwise_int64.m:
tests/hard_coded/bitwise_int8.exp:
tests/hard_coded/bitwise_int8.m:
tests/hard_coded/bitwise_uint.exp:
tests/hard_coded/bitwise_uint.exp2:
tests/hard_coded/bitwise_uint.m:
tests/hard_coded/bitwise_uint16.exp:
tests/hard_coded/bitwise_uint16.m:
tests/hard_coded/bitwise_uint32.exp:
tests/hard_coded/bitwise_uint32.m:
tests/hard_coded/bitwise_uint64.exp:
tests/hard_coded/bitwise_uint64.m:
tests/hard_coded/bitwise_uint8.exp:
tests/hard_coded/bitwise_uint8.m:
    Check that <<u and >>u compute the same results as << and >> respectively.
2022-12-07 23:12:33 +11:00
Zoltan Somogyi
d551bc743a Add an expected output file for 32 bit targets.
tests/hard_coded/int_uenum.exp2:
    Add this expected output file.

tests/hard_coded/int_uenum.m:
    Note what conditions call for each expected output file.
2022-12-07 11:16:18 +11:00
Zoltan Somogyi
925db2061d Update expected outputs for 32-bit machines. 2022-12-07 11:15:43 +11:00
Zoltan Somogyi
3c3c072a33 Make bitwise op tests' .exp files more readable.
tests/hard_coded/bitwise_int.m:
tests/hard_coded/bitwise_int16.m:
tests/hard_coded/bitwise_int32.m:
tests/hard_coded/bitwise_int64.m:
tests/hard_coded/bitwise_int8.m:
tests/hard_coded/bitwise_uint.m:
tests/hard_coded/bitwise_uint16.m:
tests/hard_coded/bitwise_uint32.m:
tests/hard_coded/bitwise_uint64.m:
tests/hard_coded/bitwise_uint8.m:
    Most of the expected output files of these test cases were
    easily readable already, but there were some exceptions caused
    by unnecessary differences between their source codes.

    The main problem was with bitwise_uint.m (uint_bitwise.m until recently),
    whose .exp file contained very long lines of the form A op B = C
    where A, B and C could each be 64 bits (and chars) long. Fix this
    by adopting the format used by the other modules:

        A op
        B =
        C

    The other problem was that in some test cases, the indentation had
    an off-by-one bug. They generated output such as

        \ aaaa =
         bbbb

    instead of the much-easier-to-visually-check

        \ aaaa =
          bbbb

    A third, much less important change is the deletion of unnecessary
    blank lines.

tests/hard_coded/bitwise_int.exp:
tests/hard_coded/bitwise_int16.exp:
tests/hard_coded/bitwise_int32.exp:
tests/hard_coded/bitwise_int64.exp:
tests/hard_coded/bitwise_int8.exp:
tests/hard_coded/bitwise_uint.exp:
tests/hard_coded/bitwise_uint16.exp:
tests/hard_coded/bitwise_uint32.exp:
tests/hard_coded/bitwise_uint64.exp:
tests/hard_coded/bitwise_uint8.exp:
    Conform to the changes in codes of the tests.
2022-12-05 21:25:07 +11:00