Commit Graph

4288 Commits

Author SHA1 Message Date
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
a67a416fd8 Add lookup_name_default_prefix to varset.m.
library/varset.m:
    We have long had two versions of the lookup_name function, and of
    the equivalent lookup_name predicate, with the difference being
    that one version had an extra argument that specified to prefix
    for the names to be constructed for not-explicitly-named variables.

    Obsolete the function and the predicate with this extra argument
    in favor of a new function/predicate pair, whose shared name is
    lookup_name_default_prefix.

    Act on an old sortof-XXX by changing the order of arguments of the
    set_bindings predicate to make it state-variable-friendly.

    Improve some comments.

NEWS.md:
    Document the above changes.

library/term.m:
    Document the var and var_supply types at their definitions.

    Don't intersperse obsolete pragmas together with predicate/function
    declarations.

    Update some old comments.

compiler/lp_rational.m:
compiler/mlds_to_target_util.m:
    Replace calls to the newly-obsoleted function and predicate.
2023-05-29 11:51:23 +02:00
Peter Wang
025472eb02 Fix spelling. 2023-05-29 11:03:39 +10:00
Zoltan Somogyi
d769b04a96 Base string.format_table{,_max} on common code.
library/string.m:
    Even though format_table_max is a minor tweak on format_table,
    its implementation used to be completely separate. Act on an old XXX
    and make format_table use the same primitive ops as format_table_max.

    Document the operation of format_table a bit better.

    Change the way that format_table_max handles column-width limits,
    by accepting overlong column contents *without* starting a new line.
    Document the new semantics.

    Use predmode decls when possible.

tests/general/string_test.{m,exp}:
    Add a test of format_table_max, which previously did not have one.
2023-05-22 19:23:37 +10:00
Zoltan Somogyi
556d9a4fea Improve variable names. 2023-05-02 01:32:22 +10:00
Zoltan Somogyi
91782bd972 Put io.primitives_write.m into a logical order. 2023-04-27 17:34:03 +10:00
Zoltan Somogyi
ecf7afcb8b Fix indentation. 2023-04-25 02:33:04 +10:00
Zoltan Somogyi
a47de48c4d s/input_stream/text_input_stream/ ...
... and the same for output streams.
2023-04-24 14:59:20 +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
Zoltan Somogyi
79b65ff650 Fully initialize C# MR_MercuryFileStructs at open ...
... by setting up their reader or writer fields then, instead of
testing at each input or output operation whether the relevant field is null,
and filling it in if it is.

library/io.primitives_read.m:
library/io.primitives_write.m:
    Delete the test-and-fill-if-needed code from the read and write operations.

library/io.stream_ops.m:
    Initialize the reader and writer fields of each MR_MercuryFileStruct
    as it is created an file open time.

    Document when each field of the MR_MercuryFileStruct is meaningful.

    Add an XXX about binary vs text files.

    Add an XXX proposing a new arrangement of stream types.
2023-04-24 11:43:50 +10:00
Julien Fischer
199bd81ee6 Fix standard library compilation the C# grade.
library/string.m:
    As above.
2023-04-21 23:41:46 +10:00
Zoltan Somogyi
2a12732260 Improve well-formedness checks on UTF strings.
library/io.m:
    Add the predicates

        read_named_file_as_string_wf
        read_named_file_as_lines_wf
        read_file_as_string_wf
        read_file_as_string_and_num_code_units_wf

    which extend their base predicates (without the _wf suffix) by checking
    whether the string read from the file is well formed, and returning
    an error if it is not.

library/io.stream_op.m:
    Fix and expand a comment.

library/io.text_read.m:
    Add a comment.

library/string.m:
    Add check_well_formedness, a predicate that checks whether a string
    is well formed, and (if relevant) specifies the offset of the first
    non-well-formed character.

    Make the documentation of index_next and index_next_repl more detailed.

runtime/mercury_string.[ch]:
    Define MR_utf8_find_ill_formed_char, a version of MR_utf8_verify
    that returns the offset of the first ill-formed UTF-8 char in the
    given string, if there is one. This is used in the implementation of
    check_well_formedness for C.

NEWS.md:
    Announce the new library predicates.

    Sort some lists of pred names.
2023-04-21 15:55:23 +10:00
Zoltan Somogyi
6d184346d5 Fix indentation. 2023-04-20 19:49:05 +10:00
Zoltan Somogyi
7c145ba274 Document a library predicate.
library/mercury_term_lexer.m:
    Clarify that the documentation of string_get_token_list applies
    to its linestr version too.

library/mercury_term_parser.m:
    Fix the comment for a predicate.
2023-04-08 10:47:31 +10:00
Julien Fischer
0f0df8bd03 Fix spelling.
library/stream:
    As above.

library/term_io.m:
    Bump year in copyright notice.
2023-04-07 16:36:08 +10:00
Zoltan Somogyi
f019787c20 Avoid contractions. 2023-04-07 14:48:55 +10:00
Zoltan Somogyi
9c91bae4c9 Fix user-visible documentation in term_io.m.
library/term_io.m:
    Four predicates that wrote to the current output stream were documented
    as writing to stdout, which may, or *may not*, be stdout. Fix this.

    Make the code of escaped_string more readable.

    Delete unneeded explicit module qualifications.

NEWS.md:
    Announce the fix.
2023-04-07 00:57:43 +10:00
Zoltan Somogyi
5c8e430c78 Improve formatting. 2023-04-07 00:42:51 +10:00
Julien Fischer
9627df5a68 Fix typo.
library/eqvclass.m:
    As above.
2023-04-04 21:36:50 +10:00
Zoltan Somogyi
e1fe6f9871 Improve the style of library/eqvclass.m.
Use the same variable (base) name for each field of the eqvclass
structure in all predicates. Make this base name match the name
of that field.

Delete redundant module qualifiers, except in the few cases where
it helps readability.

Add dividers to separate unrelated predicates.

Expand out deeply nested function calls, giving names
to the intermediate results.
2023-04-04 11:19:30 +10:00
Julien Fischer
33ea40c8a3 Fix spelling.
library/uint16.m:
library/uint32.m:
library/uint64.m:
    As above.
2023-04-03 20:22:33 +10:00
Julien Fischer
69569b1bbf Secure temporary file and directory creation for Java.
In the Java grade, the implementation of predicates used to create unique
temporary files and directories was not secure, due to the underlying Java API
methods not setting permissions correctly. Alternative methods were added in
Java 7, but we currently use the older insecure methods. This change switches
the Java implementations of temporary file and directory creation over to the
newer methods.

We have long provided a Mercury wrapper for secure temporary file / directory
creation in the extras/java_extra_libs. That will be redundant after this change
and I will remove it in a separate change.

library/io.file.m:
     Use the secure temporary file and directory creation methods introduced
     in Java 7.

     Mention that for make_temp_directory/6, the Java implementation will now
     ignore the Suffix argument.

     Delete some that was used to generated temp file names; its use of
     java.util.Random probably wasn't particularly secure either.
2023-03-28 21:46:00 +11:00
Mark Brown
81ce3a3459 Tweak a comment.
library/list.m:
	Make the same change as was suggested elsewhere, where the
	comment was being quoted.
2023-03-25 01:06:56 +11:00
Mark Brown
ec24859b4c Update library documentation.
library/random.m:
    Add a guide for people implementing RNGs using this interface.

    Other minor improvements.
2023-02-26 21:52:41 +11:00
Zoltan Somogyi
47e867b5e0 Delete redundant module qualifiers. 2023-02-21 00:40:31 +11:00
Zoltan Somogyi
03ed92ad75 Fix indentation. 2023-02-21 00:40:12 +11:00
Julien Fischer
fbd1005eee Add system_error_is_success/1.
library/io.m:
     As above.

library/io.error_util.m:
     Delete the equivalent operation is_success/1 from here and
     just use system_error_is_success/1 instead.

NEWS.md:
     Announce the new predicate.
2023-02-13 11:30:40 +11:00
Julien Fischer
2c8ada3dcc Delete unused string formatting predicates.
library/string.format.m:
    Delete the old predicates for formatting ints as unsigned values;
    these are now unused.

configure.ac:
    Require the use of a compiler that does not generate references
    to the deleted predicates.

compiler/introduced_call_table.m:
    Delete the above predicates from the introduced call table.
2023-02-09 10:39:58 +11:00
Zoltan Somogyi
278ebc172a Mark string.*codepoint* as obsolete ...
library/string.m:
    ... in favor of the s/codepoint/code_point/ versions.

NEWS.md:
    Mention that these predicates and functions have been marked obsolete.

    Mention that all the X_to_doc functions in modules other than
    pretty_printer.m have been marked obsolete in favour of the versions
    in pretty_printer.m.

    Standardize on indenting lists of function and predicate names
    by four spaces, not three. (There were more than five times as many
    that were indented by four than by three.)
2023-02-08 19:51:49 +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
726da4f03c Prepare to s/codepoint/code_point/ in string.m.
library/string.m:
    For each predicate and function whose name includes "codepoint",

    - create a version in which "codepoint" is replaced by "code_point",
    - make this version the main implementation, making the "codepoint"
      versions forward to the "code_point" versions,
    - add obsolete pragmas for the "codepoint" versions, though these are
      commented out for now. This is so that an installed compiler containing
      this change will already have the recommended alternative available
      when the commenting-out is removed (maybe in a week or so).

NEWS.md:
    Announce the new predicates and functions.

compiler/c_util.m:
compiler/const_prop.m:
compiler/inst_check.m:
compiler/parse_tree_out_term.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/write_error_spec.m:
library/pprint.m:
library/pretty_printer.m:
library/string.format.m:
    Replace all uses of the "codepoint" versions with the "code_point"
    versions.
2023-02-02 19:59:10 +11:00
Peter Wang
a07077914c Optimise digraph.compose.
Benchmarking on randomly generated digraphs shows a speedup of 30-40%.
The time to make dependencies in the compiler directory on my machine
is reduced from 3.65 seconds to 2.40 seconds.

library/digraph.m:
    Rewrite digraph.compose more efficiently.
2023-02-02 16:21:54 +11:00
Zoltan Somogyi
33ae129d45 Optimize contains/insert pairs in digraph.m ...
... by replacing them with insert_new operations.

Delete redundant module qualifications.
2023-02-01 16:45:05 +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
Peter Wang
bd074ec4c0 Increase parallelism when making standard library .trans_opt files.
Increase parallelism while making .trans_opt files in the library
directory by deleting more edges in the trans-opt dependency graph.
There are no regressions in the generated .trans_opt files.

On my machine, mmake -j32 trans_opts in the library directory
goes from 23 seconds to approximately 11 seconds.

library/mer_std.trans_opt_deps_spec:
    As above.
2023-01-30 17:26:31 +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
b0ae10248b Use --trans-opt-deps-spec option.
Use the recently added --trans-opt-deps-spec option to break cycles in
the trans-opt dependency graph for the standard library. This enables
more parallelism when making the .trans_opt files; it now takes about
half as long as before.

Ordering modules sensibly, so that .trans_opt files are created in a
logical order, also improves analysis results for many predicates and
functions. The only results which show a regression with this change are
for deprecated forwarding predicates/functions.

In future, we will probably be able to trim more dependencies to further
improve parallelism, without impacting analysis results.

configure.ac:
    Check that the bootstrap compiler supports --trans-opt-deps-spec.

library/mer_std.trans_opt_deps_spec:
    Add the spec file that adjusts dependencies in the trans-opt
    dependency graph.

library/INTER_FLAGS:
    Use the --trans-opt-deps-spec option when building with mmake.

scripts/prepare_install_dir.in:
tools/binary:
tools/bootcheck:
tools/unary:
    Copy mer_std.trans_opt_deps_spec when preparing a copy of the
    library directory.
2023-01-25 16:48:45 +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
9c9a44be00 Improve the worst case of list_to_set on sparse bitsets.
library/sparse_bitset.m:
    Replace the old algorithm, which had O(N^2) worst-case behavior,
    with a modified form of natural merge sort, whose worst-case complexity
    is O(NlogN).
2023-01-24 04:05:26 +11:00
Zoltan Somogyi
0497e18e7b Clarity the prereqs of sorted_list_to_set for bitsets. 2023-01-23 00:20:48 +11:00
Zoltan Somogyi
4a14c05ccc Union and intersect up to 8 bitsets at a time. 2023-01-19 15:36:49 +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
34af996ae4 Add synonyms for digraph sc, tc, rtc.
library/digraph.m:
    Add non-abbreviated synonyms for digraph.sc, digraph.tc, and
    digraph.rtc.

NEWS:
    Announce additions.
2023-01-19 13:16:22 +11:00
Peter Wang
0fa19819d9 Minor improvement to simple_tc implementation.
library/digraph.m:
    Skip map update when the candidate root for a vertex does not
    need to change.
2023-01-19 13:16:22 +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
Zoltan Somogyi
3c5075aced Add the init_posn function.
library/io.m:
    As above.

NEWS:
    Announce the addition.

compiler/generate_dep_d_files.m:
library/mercury_term_parser.m:
    Use the new function.
2023-01-14 00:09:48 +11:00