Commit Graph

185 Commits

Author SHA1 Message Date
Zoltan Somogyi
47e867b5e0 Delete redundant module qualifiers. 2023-02-21 00:40:31 +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
bda87983d4 Move some code to new io.error_util module.
This reduces the size of io.m a bit. The other reason for moving the
code is to allow modules that occur in a dependency cycle with io.m
to read results from io.error_util.trans_opt, whereas they may have
been prevented from reading io.trans_opt.

library/io.m:
library/io.error_util.m:
    Move is_error, throw_on_error and other similar predicates to a
    new undocumented submodule of io.m.

    Also move the support functions/predicates used by those predicates.

    Make io.make_io_error_from_system_error and
    io.make_io_error_from_windows_error call the implementations in
    io.error_util.m.

library/MODULES_UNDOC:
library/library.m:
    List the new submodule as undocumented.

library/benchmarking.m:
library/bitmap.m:
library/dir.m:
library/io.call_system.m:
library/io.file.m:
     Import the new submodule.
2023-01-13 18:54:04 +11:00
Zoltan Somogyi
07f877bc3f Carve term_context.m out of term.m.
library/term.m:
library/term_context.m:
    As above.

    Rename the term.context type as term_context.term_context, with
    term.context now being defined as an equivalence type.

    Replace the context_init function and predicate and the dummy_context_init
    function with just one function: dummy_context. This name includes
    the important part (the fact that it return a *dummy* context) and deletes
    the nonimportant part (dummy contexts are just about never updated,
    so the function does not really "initialize" them).

    Reduce function/predicate pairs that do the same thing to just a function.

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

NEWS:
    Mention the new module, and the obsoleting of the moved predicates
    and functions in term.m.

compiler/*.m:
library/*.m:
    Conform to the changes above.
2022-08-23 12:56:37 +10:00
Zoltan Somogyi
752bb66f5b Carve four modules out of term.m.
Most modules that imported the old term.m need only a small subset
of its functionality. After this diff, most modules that used to import
term.m will need to import just one more module, and will import many
fewer predicates and functions in total.

library/term_int.m:
    A new module carved out of term.m containing the predicates
    that recognize terms containing integers, and the functions
    that construct such terms.

    While this job has *some* similarity to the job of the existing
    term_conversion.m module, most modules in the compiler use only one
    of those two modules, so merging them would not be a good idea.

library/term_subst.m:
    A new module carved out of term.m containing code to do
    substitutions and renames of various kinds.

    Rename the occurs predicate as var_occurs_in_subst_term,
    and occurs_list as var_occurs_in_subst_terms, since the latter
    are much more descriptive. Change the argument order to match
    the new names (var, subst, term/terms), as the old one did not
    even have the term/terms and the substitution next to each other,
    even though neither makes sense without the other.

library/term_unify.m:
    A new module carved out of term.m containing code to do unifications.

    Give all the predicates more meaningful names:

    unify_term ->                   unify_terms
    unify_term_list ->              unify_term_lists
    unify_term_dont_bind ->         unify_terms_dont_bind
    unify_term_list_dont_bind ->    unify_term_lists_dont_bind
    list_subsumes ->                first_term_list_subsumes_second

library/term_vars.m:
    A new module carved out of term.m containing code that find variables
    in terms.

    Give all the predicates more meaningful names:

    vars ->                         vars_in_term
    vars_2 ->                       vars_in_term_acc
    vars_list ->                    vars_in_terms
    contains_var ->                 term_contains_var
    contains_var_list ->            terms_contain_var

    Don't move the function version of vars_2 to term_vars.m, effectively
    deleting it, since operations that update an accumulator are awkward
    for functions.

library/term.m:
    Keep the moved predicates and functions in term.m, but

    - change their implementation to simply call the moved copy, and
    - obsolete the original in favor of the moved copy.

    Eventually, after either the next release or the release after the next,
    we should delete the obsoleted predicates and functions.

library/MODULES_DOC:
library/library.m:
    Add the new modules as documented parts of the standard library.

browser/interactive_query.m:
compiler/analysis.file.m:
compiler/det_util.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/intermod.m:
compiler/make.module_dep_file.m:
compiler/make_hlds_passes.m:
compiler/parse_class.m:
compiler/parse_inst_mode_defn.m:
compiler/parse_item.m:
compiler/parse_mutable.m:
compiler/parse_pragma.m:
compiler/parse_pragma_analysis.m:
compiler/parse_sym_name.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_defn.m:
compiler/parse_util.m:
compiler/prog_ctgc.m:
compiler/prog_util.m:
compiler/recompilation.used_file.m:
compiler/recompilation.version.m:
compiler/superhomogeneous.m:
compiler/switch_detection.m:
compiler/typecheck.m:
library/io.m:
library/term_conversion.m:
library/varset.m:
    Conform to the changes above.
2022-08-21 01:01:21 +10:00
Zoltan Somogyi
9047bdbf05 Improve programming style in the browser directory.
browser/declarative_analyser.m:
browser/declarative_debugger.m:
browser/declarative_oracle.m:
browser/declarative_tree.m:
browser/declarative_user.m:
browser/interactive_query.m:
browser/listing.m:
browser/parse.m:
browser/util.m:
    Rename some predicates to avoid ambiguity.

    Factor out common code.

    If some versions of a field of a structure have names in a predicate
    (by being stored in a named variable), then give all *other* versions
    of that field in that structure names in that predicate as well.

    If a field of a structure is used more than once in a predicate,
    then again, store it in a named variable.

    Reorder predicate arguments to put state variables last.

    Use io.format instead of sequences of calls to io.write_string.

    In declarative_user.m, note a probable bug (in a position where
    it is probably rarely stumbled upon).

    In listing.m, use a consistent naming scheme to differentiate
    between Mercury streams and their C counterparts.

    Replace if-then-else chains with switches where possible.

browser/name_mangle.m:
    Note bit rot.

browser/browse.m:
    Conform to the changes above.

library/io.m:
    Improve predicate and variable names.

browser/mdb.m:
browser/mer_browser.m:
browser/percent_encoding.m:
browser/term_rep.m:
browser/tree234_cc.m:
library/library.m:
    Improve comments.
2022-07-03 13:55:54 +10:00
Zoltan Somogyi
56509009dd Fix some test failures in debug grades.
browser/declarative_oracle.m:
    The code that checks whether the declarative debugger should trust
    a module because it is a standard library module was apparently written
    before any of module in the standard library had submodules, because
    it checked the unqualified name of the module in question against
    the *qualified* module names returned by the mercury_std_library_module
    predicate.

    For a long time after we had submodules such as thread.mvar.m in the
    standard library, this caused no test failures, because our tests
    did not execute code in those submodules. This changed with the breakup
    of io.m. The move of the output_stream_2 predicate from io.m, which
    this code recognized as trusted, to io.stream_ops.m, which it did not,
    caused the declarative debugger to ask questions about the validity
    of calls to it, which the caused the failure of the declarative_debugger/
    all_trusted test case, due to its .inp file containing something other
    than the corresponding answers.

    Fix this for the case of module names of the forms a.b and a.b.c.

library/library.m:
    Add a note to the mercury_std_library_module predicate to update
    the code in declarative_oracle.m if we ever add a library module
    whose fully qualified name has the form a.b.c.d.

tests/debugger/user_event_shallow.exp:
    Update the expected output of this test for some ancient change.

tests/debugger/Mercury.options:
    Specify the optimization level for the user_event_shallow test,
    which eliminates one source of variability in the output.
    Another source is intermodule optimization, which this diff does *not*
    eliminate.

tests/debugger/all_solutions.exp:
tests/debugger/all_solutions.exp2:
tests/debugger/all_solutions.exp3:
tests/debugger/all_solutions.exp4:
tests/debugger/all_solutions.m:
    The output of this test case in debug grades with intermodule optimization
    did not match any of the .exp* files, though it differed from .exp2 only
    in the text of an error message. (The difference was not a bug.)

    Instead of adding this expected output as .exp5, use it to replace
    the .exp3 file. This expected output file could not have been matched
    in the last seven years, because it expects main/2 to be on line 16,
    and that predicate's context has been line 20 since 2015.

    Document the fact that .exp3 is the expected output for debug grade
    bootchecks with intermodule optimization. This documentation changes
    line numbers yet again, so update the line numbers in all the *other*
    .exp* files as well.

tests/declarative_debugger/Mmakefile:
    Fix indentation.
2022-06-26 10:09:48 +10:00
Zoltan Somogyi
3459266a7a Carve stdlib module ra_list.m out of bt_array.m.
library/ra_list.m:
    As above.

    Rename ra_list_lookup to ra_list_search, since it fails if the item
    to be accessed does not exist. Add a version, ra_list_lookup, which
    aborts in that case.

    Add predicates to append two ra_lists, and to convert ra_lists
    to just plain lists.

    Change the argument order of some predicates to be more
    state variable friendly.

    Add some documentation.

library/bt_array.m:
    Delete the moved code, and update the references to the changed predicates.

library/Mercury.options:
    Now that the ra_list predicates have been moved to their own module,
    stop giving bt_array.m a free pass on inconsistent predicate order.

library/MODULES_DOC:
library/library.m:
    Add ra_list.m as a documented module of the Mercury standard library.

library/array.m:
    Delete a predicate that served as a test for an ancient bug fix.

NEWS:
    Announce both the new ra_list module, and the deletion of the predicate
    from array.m.

tests/hard_coded/array_sort.m:
    Don't call the predicate deleted from array.m.

tests/hard_coded/ra_list_test.{m,exp}:
    A new test case to test operations on ra_lists.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2022-06-11 11:11:30 +10:00
Julien Fischer
e7d28ff90f Update copyright notices in stdlib.
library/*.m:
    As above.
2022-06-07 21:51:03 +10:00
Zoltan Somogyi
e163ea91b6 Carve io.text_read.m out of io.m, and ...
... move the implementation of flush_*output to io.stream_ops.m.

In both cases, improve the predicate names a bit.

Add a distinguishing prefix to the names of the function symbols of a type,
to reduce the number of times the function symbol names ok, error and eof
are overloaded from ridiculous to slighly less ridiculous :-(

Move related predicate arguments next to each other.

library/io.text_read.m:
    New submodule containing the code that implement the predicates
    that read values of non-primitive types, all but one of which are text.

library/io.stream_ops.m:
    Move the implementation of flushing output here from io.m.

library/io.m:
    Delete the code moved to the above modules.

library/MODULES_UNDOC:
library/library.m:
    List the new submodule as undocumented.

library/Mercury.options:
    Allow io.text_read.m, instead of io.m, to define an inst for a type
    that has a definition in a foreign language as well as Mercury.
    This diff moves this inst definition to io.text_read.m.
2022-03-15 01:12:07 +11:00
Zoltan Somogyi
05fd615471 Carve io.stream_ops.m out of io.m.
Also, move foreign code pieces still in io.m that belong in
previously-carved-out modules to those modules.

library/io.m:
library/io.stream_ops.m:
    As above. The new private submodule contains the implementations
    (helper predicates) of the operations that

    - open and close streams,
    - get and set offsets in those streams,
    - get and set line numbers on streams,
    - return the standard streams, and
    - set streams as the current streams.

library/io.m:
    Make some previously private includes public, to allow modules outside
    of io.m to refer to the C# and Java symbols they define. These includes
    are in the second, undocumented interface section of io.m.

    Delete the foreign code moved to io.primitives_{read,write}.m,
    as well as the foreign code moved to io.stream_ops.m.

    Change {get,set}_{line_number,output_line_number}/3, which used
    to be implemented directly using foreign_procs, to implement them
    in terms of their arity-4 counterparts which take an explicit stream
    argument, which now are in io.stream_ops.m. This can yield a slowdown,
    but it should be so small as to be unmeasurable on all non-microbenchmark
    workloads.

    Move related code together.

    Update module qualifications in C# and Java code.

    Delete the second #include of mercury_library_types.h.

    Delete the MR_{initial,final}_io_state macros.

library/MODULES_UNDOC:
library/library.m:
    List the new submodule as undocumented.

library/io.primitives_read.m:
library/io.primitives_write.m:
    Move the C, C# and Java code related to reading and writing values
    of primitive types here from io.m. Put them into one foreign_decl
    and one foreign_code per language.

    Update module qualifications in C# and Java code.

library/benchmarking.m:
library/bitmap.m:
library/io.call_system.m:
    Update module qualifications in C# and Java code.

library/stm_builtin.m:
    Replace uses of the MR_{initial,final}_io_state macros with their bodies.
2022-03-14 15:20:22 +11:00
Zoltan Somogyi
f3d7165a3a Carve io.primitives_{read,write}.m out of io.m.
library/io.m:
library/io.primitives_read.m:
library/io.primitives_write.m:
    As above. The two new private submodules contain the implementations
    (helper predicates) of the operations that respectively read and write
    values of primitive types.

library/MODULES_UNDOC:
library/library.m:
    List the new submodules as undocumented.
2022-03-12 15:00:41 +11:00
Zoltan Somogyi
80e1a47397 Carve io.stream_db.m out of io.m.
library/io.m:
library/io.stream_db.m:
    Move the data types describing the stream database, and the
    predicates and functions managing and accessing it, to the new
    submodule io.stream_db.m. Move the declarations and definitions
    of the global variables holding the dabase accordingly.

library/MODULES_UNDOC:
library/library.m:
    List the new module as an undocumented new module.

browser/browse.m:
browser/browser_info.m:
library/stream.string_writer.m:
    Get stream information from the new module.
2022-03-11 18:13:28 +11:00
Zoltan Somogyi
c02eb5163e Carve io.{call_system,environment}.m out of io.m.
library/io.call_system.m:
    Move the code in the "system access predicates" section of io.m
    to this new module.

library/io.environment.m:
    Move the predicates dealing with environment variables in io.m
    to this new module.

library/io.m:
    Delete the code moved to the new modules.

    Leave behind in io.m "forwarding predicates", predicates that do nothing
    except call the moved predicates in the new modules, to provide backward
    compatibility. But do mark the forwarding predicates as obsolete,
    to tell people to update their (at their leisure, since the obsoleteness
    warning can be turned off).

    Also leave behind in io.m the definitions of the types used
    by some parameters of some of the moved predicates.

library/MODULES_DOC:
    List the new modules among the documented modules.

library/library.m:
    List the new modules, including io.file.m (added in a previous change)
    among the documented standard library modules.

NEWS:
    Announce the changes.

browser/browse.m:
browser/interactive_query.m:
compiler/fact_table.m:
compiler/handle_options.m:
compiler/make.module_target.m:
compiler/mercury_compile_main.m:
compiler/module_cmds.m:
compiler/optimize.m:
compiler/options_file.m:
deep_profiler/conf.m:
deep_profiler/mdprof_cgi.m:
deep_profiler/mdprof_test.m:
library/io.file.m:
mdbcomp/trace_counts.m:
ssdb/ssdb.m:
tests/general/environment.m:
tests/hard_coded/closeable_channel_test.m:
tests/hard_coded/setenv.m:
tests/hard_coded/system_sort.m:
    Call the moved predicates directly in their new modules,
    not indirectly through io.m.
2022-03-08 09:38:27 +11:00
Zoltan Somogyi
06f81f1cf0 Add end_module declarations ...
.. to modules which did not yet have them.
2022-01-09 10:36:15 +11:00
Zoltan Somogyi
b64f0fbedc Add a "mercury_term_" prefix to lexer.m/parser.m.
library/mercury_term_lexer.m:
library/mercury_term_parser.m:
    As above.

NEWS:
    Announce the change.

browser/interactive_query.m:
compiler/analysis.file.m:
compiler/fact_table.m:
compiler/make.module_dep_file.m:
compiler/parse_module.m:
compiler/parse_tree_out_term.m:
compiler/recompilation.used_file.m:
library/MODULES_DOC:
library/char.m:
library/integer.m:
library/io.m:
library/library.m:
library/ops.m:
library/term.m:
library/term_io.m:
mdbcomp/trace_counts.m:
tests/hard_coded/impl_def_lex.m:
tests/hard_coded/impl_def_lex_string.m:
tests/hard_coded/lco_pack_args_3.m:
tests/hard_coded/lexer_bigint.m:
tests/hard_coded/lexer_ints.m:
tests/hard_coded/lexer_zero.m:
tests/hard_coded/parse_number_from_string.m:
tests/valid_seq/nested_module_bug.m:
    Conform to the change.
2021-12-31 02:38:07 +11:00
Zoltan Somogyi
be03537f10 Set up for --warn-stdlib-shadowing.
This diff does not implement the option itself. The reason is that we want
to turn it off in library/LIB_FLAGS.in, and we can do that only when the
installed compiler knows about the option. This diff is therefore the first
step in the two-step bootstrapping process.

compiler/options.m:
    Add a new option --warn-stdlib-shadowing, which, after the bootstrapping
    step, will cause the compiler to warn about module names that could be
    confused with the name of a module in the Mercury standard library.

    Add a new option, --output-stdlib-modules, that tools/bootcheck can use
    to test whether the compiler's list of Mercury standard library modules
    is complete.

    Rename the option name output_class_dir to output_java_class_dir
    (internally only, leaving the user-visible name unchanged), to fit in
    with the names of options related to C#, which have csharp in the name.

compiler/op_mode.m:
    Add a new op_mode for --output-stdlib-modules.

compiler/mercury_compile_main.m:
    Implement the new op_mode, using new code in library/library.m.

    Simplify some existing code.

library/library.m:
    Add an exported but undocumented predicate that mercury_compile_main.m
    can use to

    - find a list of all the Mercury standard library modules, and
    - find out for each whether it is documented or not.

    Reimplement the existing exported-but-undocumented predicate
    in terms of the new one.

library/Mmakefile:
    Add mmake targets that check whether the contents of MODULES_DOC and
    MODULES_UNDOC match the output of mmc --output-stdlib-modules.

tools/bootcheck:
    Use the new mmake targets to do that check.
2021-12-31 00:57:18 +11:00
Zoltan Somogyi
0d7c8a7654 Specify pred or func for all pragmas.
*/*.m:
    As above.

configure.ac:
    Require the installed compiler to support this capability.
2021-06-16 15:23:58 +10:00
Julien Fischer
65566350b5 Add the system random number generator interface.
This is work-in-progress, currently only the C# and Java backends
are supported. Support for the C backends will be added separately.

library/random.system_rng.m:
    A new submodule containing the system RNG.

library/random.m:
library/library.m:
    Include the new submodule.

library/MODULES_UNDOC:
    Do not generate documentation for the new submodule.
2021-01-29 16:30:18 +11:00
Peter Wang
0d3fcbaae3 Delete Erlang code from library/mdbcomp/browser directories.
library/*.m:
    Delete Erlang foreign code and foreign types.

    Delete documentation specific to Erlang targets.

library/deconstruct.m:
    Add pragma no_determinism_warning to allow functor_number_cc/3
    to compile for now.

library/Mercury.options:
    Delete workaround only needed when targetting Erlang.

browser/listing.m:
mdbcomp/rtti_access.m:
    Delete Erlang foreign code and foreign types.
2020-10-28 14:10:56 +11:00
Peter Wang
c28a79a382 Delete Erlang-specific standard library modules.
library/MODULES_UNDOC:
library/Mercury.options:
library/construct.m:
library/deconstruct.m:
library/erlang_builtin.m:
library/erlang_rtti_implementation.m:
library/library.m:
library/type_desc.m:
    Delete erlang_builtin and erlang_rtti_implementation modules.
2020-10-28 14:10:56 +11:00
Peter Wang
c4c840cb7e Delete Erlang backend from configure.
configure.ac:
m4/mercury.m4:
    Delete --enable-erlang-grade configure option.

    Don't search for erlang compiler and interpreter.

    Don't substitute @ERLC@ and @ERL@.

    Don't add erlang to libgrades.

    Don't generate erlang_conf.hrl

library/erlang_conf.hrl.in:
    Delete template file.

.dockerignore:
browser/MDB_FLAGS.in:
compiler/COMP_FLAGS.in:
deep_profiler/DEEP_FLAGS.in:
library/.gitignore:
library/Mmakefile:
library/library.m:
mdbcomp/MDBCOMP_FLAGS.in:
mfilterjavac/MFILTERJAVAC_FLAGS.in:
profiler/PROF_FLAGS.in:
scripts/Mercury.config*.in:
scripts/mercury_config.in:
scripts/prepare_install_dir.in:
ssdb/SSDB_FLAGS.in:
tools/bootcheck:
    Delete references to Erlang .hrl files.

    Delete references to @ERLC@ and @ERL@.
2020-10-27 11:10:11 +11:00
Zoltan Somogyi
36c2000516 Add the one_or_more and one_or_more_map modules to the library.
library/one_or_more.m:
    We used to have a type named one_or_more in the list module representing
    nonempty lists. It had literally just two predicates and two functions
    defined on it, three of which did conversions to and from lists, which
    limited their usefulness.

    This new module is the new home of the one_or_more type, together with
    a vastly expanded set of utility predicates and functions. Specifically,
    it implements every operation in list.m which makes sense for nonempty
    lists.

library/list.m:
    Delete the code moved over to one_or_more.m.

library/one_or_more_map.m:
    This new module is a near copy of multi_map.m, with the difference being
    that while the multi_map type defined in multi_map.m maps each key
    to a list(V) of values (a list that happens to always be nonempty),
    the one_or_more_map type defined in one_or_more_map.m maps each key
    to a one_or_more(V) of values (which enforces the presence of at least
    one value for each key in the type).

library/map.m:
    Mention the existence of one_or_more_map.m as well as multi_map.m.

library/MODULES_DOC:
library/library.m:
    List the new modules as belonging to the standard library.

NEWS:
    Mention the new modules, and the non-backwards-compatible changes to
    list.m.

compiler/*.m:
    Import the one_or_more module when needed.

tests/hard_coded/test_one_or_more_chunk.{m,exp}:
    Test the one predicate in one_or_more.m that is non-trivially different
    from the corresponding predicate in list.m: the chunk predicate.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2020-02-28 14:29:05 +11:00
Peter Wang
dae414d920 Add closeable channels to the standard library.
library/thread.closeable_channel.m
    Add the new module. It omits two operations from thread.channel.m:
    - untake, because it is deprecated
    - duplicate, because I'm not sure what it's useful for in practice

library/MODULES_DOC:
library/library.m
library/thread.m:
NEWS:
    Mention the new module.
2020-02-17 14:36:31 +11:00
Zoltan Somogyi
09e81967b7 Add a new module, kv_list, to the standard library.
library/kv_list.m:
    This new module is a version of assoc_list.m in which the list of
    key-value pairs is represented not by a list of pairs (which has
    two two-word cells per key-value pair) but by a bespoke, flattened
    data structure (which has one three-word cell per key-value pair).
    This should improve performance by reducing the number of memory
    allocations and traffic to and from the data cache. (The *amount*
    of memory allocated will not be affected, since Boehm rounds up
    three words to four. And since cache block sizes are also powers
    of two, traffic to and from memory should stay roughly the same.)

    The new module has one operation for every operation in assoc_list.m,
    plus two functions for converting between assoc_lists and kv_lists
    (one for each direction).

library/assoc_list.m:
    Improve comments on some exported predicates and/or functions.

    Add a lookup operation on assoc lists as a predicate. This operation
    already existed as a field access function; not having it available
    using normal syntax was a bit strange.

library/library.m:
library/MODULES_DOC:
NEWS:
    Mention the new module.
2020-02-13 13:42:31 +11:00
Mark Brown
c8780cdfa7 Address more of Julien's review comments.
library/random.m:
    Move the new code to the existing random module. Update names and
    typeclass methods.

    Add adaptors to attach any ground or shared generator to the I/O
    state.

library/random.sfc{16,32,64}.m:
    Move sfc generators to here. Update for changes to interface.

extras/README:
extras/random/*.m:
    Move unused generators to a new directory under extras.

library/uint32.m:
    Add cast_from_uint/1.

library/MODULES_DOC:
library/library.m:
    Update for the module changes.

tests/hard_coded/*:
    Rename test cases to correspond with the library module name.

    Test the I/O adaptor.
2019-08-28 00:52:17 +10:00
Mark Brown
7721516520 Implement SFC random number generators, in various sizes
library/rng.sfc.m:
	New module that implements the above.

library/MODULES_DOC:
library/library.m:
library/rng.m:
	Add the new library module.

library/uint16.m:
	Add functions to cast to/from uint64.

tests/hard_coded/Mmakefile:
tests/hard_coded/*.*:
	Update/extend tests.
2019-08-28 00:52:17 +10:00
Mark Brown
1d0bde74f4 Some RNGs for the standard library, plus typeclass interfaces.
library/rng.m:
    Top-level module containing typeclasses and generic routines,
    as well as overall documentation.

library/rng.binfile.m:
    A generator that reads from a file.

library/rng.marsaglia.m:
    Fast, simple generator. Diehard results for default seed:
        PASSED: 109
        WEAK:   2
        FAILED: 3

library/rng.tausworthe.m:
    Combined Tausworthe generators. Diehard results for default seed:

    generator T3
        PASSED: 113
        WEAK:   1
        FAILED: 0

    generator T4
        PASSED: 112
        WEAK:   2
        FAILED: 0

library/library.m:
library/MODULES_DOC:
    Add the new modules to the public interface.

library/float.m:
    Add functions to convert from (u)int32/64 to float.

library/uint32.m:
    Add function to convert from uint64 to uint32.

tests/hard_coded/Mmakefile:
tests/hard_coded/rng1.{m,exp}:
tests/hard_coded/rng2.{m,exp}:
    Test the generators. The expected outputs are derived from
    the output of the C reference implementations.
2019-08-28 00:52:17 +10:00
Zoltan Somogyi
4aed1a57e4 Print an arg type list diff for arg lists with wrong arity.
When a user writes a clause for a predicate (or function) that does not exist
with that arity, but does exist with one or more other arities, report not
just the list of the other arity/arities, but, for each such other arity,
a diff between the declared arg types and the inferred arg types.

After this diff, we generate output like this:

bad_pred_arity.m:027: Error: clause for predicate `bad_pred_arity.p'/4
bad_pred_arity.m:027:   without corresponding `:- pred' declaration.
bad_pred_arity.m:027:   However, predicates of that name do exist with arities
bad_pred_arity.m:027:   3 and 5.
bad_pred_arity.m:027: Inferred :- pred p(int, string, int, string).
bad_pred_arity.m:027:   The argument list difference from the arity 3 version
bad_pred_arity.m:027:   is
bad_pred_arity.m:027:     pred(
bad_pred_arity.m:027:         int,
bad_pred_arity.m:027:   +     string,
bad_pred_arity.m:027:         int,
bad_pred_arity.m:027:         string
bad_pred_arity.m:027:     )
bad_pred_arity.m:027:   The argument list difference from the arity 5 version
bad_pred_arity.m:027:   is
bad_pred_arity.m:027:     pred(
bad_pred_arity.m:027:         int,
bad_pred_arity.m:027:   -     float,
bad_pred_arity.m:027:         string,
bad_pred_arity.m:027:         int,
bad_pred_arity.m:027:         string
bad_pred_arity.m:027:     )

compiler/typecheck_errors.m:
    Generate the diff part of the message above.

compiler/typecheck.m:
    Invoke typecheck_errors.m when relevant.

compiler/error_util.m:
    When comparing two error_specs, switch from a two-level comparison
    (first the contexts of error_msgs, then everything else) to three levels
    first the contexts of error_msgs, then their error_msg_components,
    then everything else). This is needed to allow the error message from
    make_hlds_error.m (which reports the error and mentions the arities
    with which the named predicate or function does exist) come out before
    the informational message from typecheck.m that prints the inferred
    arg types and their differences from the other arities. (With the old
    comparison, the difference in severity would trump the invisible order
    components that this diff includes in both specs to force the desire
    order.)

    Base the code comparing error_specs on the code for comparing error_msgs.
    Move the two previously separate pieces code for those tasks next to each
    other.

compiler/make_hlds_error.m:
    Add the invisble ordering component.

    When we see clauses with two or more wrong arities for a given predicate
    or function, don't list the automatically created pred declaration
    for an *earlier* wrong-arity clause as a real declaration whose arity
    is to be listed in the error messages we generate for *later* wrong-arity
    clauses.

    Add some documentation.

compiler/add_pred.m:
    Factor out some common code.

library/edit_seq.m:
    A new module for computing diffs.

library/library.m:
library/MODULES_DOC:
    Add the new module to the standard library.

tests/hard_coded/edit_seq_test.{m,exp}:
    A new test case for the diff algorithm.

tests/invalid/bad_pred_arity.{m,err_exp}:
    A new test case for the new error message.

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

tests/invalid/bigtest.err_exp:
tests/invalid/bug197.err_exp:
tests/invalid/bug278.err_exp:
tests/invalid/errors2.err_exp:
tests/invalid/invalid_binary_literal.err_exp:
tests/invalid/invalid_float_literal.err_exp:
tests/invalid/invalid_hex_literal.err_exp:
tests/invalid/invalid_main.err_exp:
tests/invalid/invalid_octal_literal.err_exp:
tests/invalid/multimode_dcg.err_exp:
tests/invalid/multisoln_func.err_exp:
tests/invalid/null_char.err_exp:
tests/invalid/state_vars_test3.err_exp:
tests/invalid/try_detism.err_exp2:
tests/invalid/typeclass_test_5.err_exp:
tests/invalid/typeclass_test_8.err_exp:
tests/invalid/unsatisfiable_constraint.err_exp:
tests/invalid_purity/impure_func_t3.err_exp:
    Update these files to expect error messages in the new order.

samples/diff/*.m:
    Fix comments, mostly by moving them to where our programming style
    wants them.
2019-01-03 08:57:20 +11:00
Zoltan Somogyi
a12692a0de Replace /* */ comments with // in the library.
Keep the old style comments where they do not go to the end of the line,
or where it is important that the comment line not have a // on it.
2018-06-21 18:55:08 +02:00
Mark Brown
d465fa53cb Update the COPYING.LIB file and references to it.
Discussion of these changes can be found on the Mercury developers
mailing list archives from June 2018.

COPYING.LIB:
    Add a special linking exception to the LGPL.

*:
    Update references to COPYING.LIB.

    Clean up some minor errors that have accumulated in copyright
    messages.
2018-06-09 17:43:12 +10:00
Julien Fischer
f519e26173 Add builtin 64-bit integer types -- Part 1.
Add the new builtin types: int64 and uint64.

Support for these new types will need to be bootstrapped over several changes.
This is the first such change and does the following:

- Extends the compiler to recognise 'int64' and 'uint64' as builtin types.
- Extends the set of builtin arithmetic, bitwise and relational operators
  to cover the new types.
- Adds the new internal option '--unboxed-int64s' to the compiler; this will be
  used to control whether 64-bit integer types are boxed or not.
- Extends all of the code generators to handle the new types.
- Extends the runtimes to support the new types.
- Adds new modules to the standard library intend to contain basic operations
  on the new types.  (These are currently empty and not documented.)

There are bunch of limitations marks with "XXX INT64"; these will be lifted in
part 2 of this change.  Also, 64-bit integer types are currently always boxed,
again this limitation will be lifted in later changes.

compiler/options.m:
    Add the new option --unboxed-int64s.

compiler/prog_type.m:
compiler/prog_data.m:
compiler/builtin_lib_types.m:
     Recognise int64 and uint64 as builtin types.

compiler/builtin_ops.m:
     Add builtin operations for the new types.

compiler/hlds_data.m:
     Add new tag types for the new types.

compiler/ctgc.selector.m:
compiler/dead_proc_elim.m:
compiler/export.m:
compiler/foreign.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_code_util.m:
compiler/hlds_dependency_graph.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/implementation_defined_literals.m:
compiler/inst_check.m:
compiler/mercury_to_mercury.m:
compiler/mode_util.m:
compiler/module_qual.qualify_items.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_name.m:
compiler/polymorphism.m:
compiler/prog_out.m:
compiler/prog_util.m:
compiler/rbmm.execution_path.m:
compiler/rtti.m:
compiler/table_gen.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Conform to the above changes to the parse tree and HLDS.

compiler/c_util.m:
    Support writing out constants of the new types.

compiler/llds.m:
    Add a representation for constants of the new types to the LLDS.

compiler/stack_layout.m:
    Add a new field to the stack layout params that records whether
    64-bit integers are boxed or not.

compiler/call_gen.:m
compiler/code_info.m:
compiler/disj_gen.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/llds_out_data.m:
compiler/llds_out_instr.m:
compiler/lookup_switch.m:
compiler/mercury_compile_llds_back_end.m:
compiler/prog_rep.m:
compiler/prog_rep_tables.m:
compiler/var_locn.m b/compiler/var_locn.m:
    Support the new types in the LLDS code generator.

compiler/mlds.m:
    Support constants of the new types in the MLDS.

compiler/ml_call_gen.m:
compiler/ml_code_util.m:
compiler/ml_global_data.m:
compiler/ml_rename_classes.m:
compiler/ml_top_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_target_util.m:
compiler/rtti_to_mlds.m:
     Conform to the above changes to the MLDS.

compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
    Generate the appropriate target code for constants of the new types
    and operations involving them.

compiler/bytecode.m:
compiler/bytecode_gen.m:
    Handle the new types in the bytecode generator; we just abort if we
    encounter them for now.

compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_call_gen.m:
compiler/erl_code_util.m:
compiler/erl_unify_gen.m:
    Handle the new types in the Erlang code generator.

library/private_builtin.m:
    Add placeholders for the builtin unify and compare operations for
    the new types.  Since the bootstrapping compiler will not recognise
    the new types we give them polymorphic arguments.  These can be
    replaced after this change has bootstrapped.

    Update the Java list of TypeCtorRep constants here.

library/int64.m:
library/uint64.m:
    New modules that will eventually contain builtin operations on the new
    types.

library/library.m:
library/MODULES_UNDOC:
    Do not include the above modules in the library documentation for now.

library/construct.m:
library/erlang_rtti_implementation.m:
library/rtti_implementation.m:
library/table_statistics.m:
deep_profiler/program_representation_utils.m:
mdbcomp/program_representation.m:
    Handle the new types.

configure.ac:
runtime/mercury_conf.h.in:
    Define the macro MR_BOXED_INT64S.  For now it is always defined, support for
    unboxed 64-bit integers will be enabled in a later change.

runtime/mercury_dotnet.cs.in:
java/runtime/TypeCtorRep.java:
runtime/mercury_type_info.h:
    Update the list of type_ctor reps.

runtime/mercury.h:
runtime/mercury_int.[ch]:
    Add macros for int64 / uint64 -> MR_Word conversion, boxing and
    unboxing.

    Add functions for hashing 64-bit integer types suitable for use
    with the tabling mechanism.

runtime/mercury_tabling.[ch]:
    Add additional HashTableSlot structs for 64-bit integer types.

    Omit the '%' character from the conversion specifiers we pass via
    the 'key_format' argument to the macros that generate the table lookup
    function.  This is so we can use the C99 exact size integer conversion
    specifiers (e.g. PRIu64 etc.) directly here.

runtime/mercury_hash_lookup_or_add_body.h:
    Add the '%' character that was omitted above to the call to debug_key_msg.

runtime/mercury_memory.h:
     Add new builtin allocation sites for boxed 64-bit integer types.

runtime/mercury_builtin_types.[ch]:
runtime/mercury_builitn_types_proc_layouts.h:
runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_ml_expand_body.h:
runtime/mercury_table_type_body.h:
runtime/mercury_tabling_macros.h:
runtime/mercury_tabling_preds.h:
runtime/mercury_term_size.c:
runtime/mercury_unify_compare_body.h:
    Add the new builtin types and handle them throughout the runtime.

runtime/Mmakefile:
    Add mercury_int.c to the list of .c files.

doc/reference_manual.texi:
     Add the new types to the list of reserved type names.

     Add the mapping from the new types to their target language types.
     These are commented out for now.
2018-01-12 09:29:24 -05:00
Julien Fischer
c596c93ed0 Workaround standard library initialization problems in the C# grade.
(A similar workaround was made for the Java grade in commit 5e09921;
that log message has further details.)

library/library.m:
    Export std_library_init/2 to C#.

library/io.m:
    Provide a no-op version of init_current_streams/2 for C#.  As with the
    Java grade, setting up the current streams is handled during class
    initialization.

compiler/mlds_to_cs.m:
     Emit a call to library.std_library_init before we call main.
2017-11-10 23:07:28 -05:00
Julien Fischer
8a240ba3f0 Add builtin 8, 16 and 32 bit integer types -- Part 1.
Add the new builtin types: int8, uint8, int16, uint16, int32 and uint32.
Support for these new types will need to be bootstrapped over several changes.
This is the first such change and does the following:

- Extends the compiler to recognise 'int8', 'uint8', 'int16', 'uint16', 'int32'
  and 'uint32' as builtin types.
- Extends the set of builtin arithmetic, bitwise and relational operators to
  cover the new types.
- Extends all of the code generators to handle new types.  There currently lots
  of limitations and placeholders marked by 'XXX FIXED SIZE INT'.  These will
  be lifted in later changes.
- Extends the runtimes to support the new types.
- Adds new modules to the standard library intended to hold the basic
  operations on the new types.  (These are currently empty and not documented.)

This change does not introduce the two 64-bit types, 'int64' and 'uint64'.
Their implementation is more complicated and is best left to a separate change.

compiler/prog_type.m:
compiler/prog_data.m:
compiler/builtin_lib_types.m:
    Recognise int8, uint8, int16, uint16, int32 and uint32 as builtin types.

    Add new type, int_type/0,that enumerates all the possible integer types.

    Extend the cons_id/0 type to cover the new types.

compiler/builtin_ops.m:
    Parameterize the integer operations in the unary_op/0 and binary_op/0
    types by the new int_type/0 type.

    Add builtin operations for all the new types.

compiler/hlds_data.m:
    Add new tag types for the new types.

compiler/hlds_pred.m:
    Parameterize integers in the table_trie_step/0 type.

compiler/ctgc.selector.m:
compiler/dead_proc_elim.m:
compiler/export.m:
compiler/foreign.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_code_util.m:
compiler/hlds_dependency_graph.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/implementation_defined_literals.m:
compiler/inst_check.m:
compiler/mercury_to_mercury.m:
compiler/mode_util.m:
compiler/module_qual.qualify_items.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/parse_tree_out_info.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_name.m:
compiler/polymorphism.m:
compiler/prog_out.m:
compiler/prog_rep.m:
compiler/prog_rep_tables.m:
compiler/prog_util.m:
compiler/rbmm.exection_path.m:
compiler/rtti.m:
compiler/rtti_to_mlds.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/type_constraints.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Conform to the above changes to the parse tree and HLDS.

compiler/c_util.m:
    Support generating the builtin operations for the new types.

doc/reference_manual.texi:
    Add the new types to the list of reserved type names.

    Add the mapping from the new types to their target language types.
    These are commented out for now.

compiler/llds.m:
    Replace the lt_integer/0 and lt_unsigned functors of the llds_type/0,
    with a single lt_int/1 functor that is parameterized by the int_type/0
    type.

    Add a representations for constants of the new types to the LLDS.

compiler/call_gen.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/llds_out_data.m:
compiler/llds_out_global.m:
compiler/llds_out_instr.m:
compiler/lookup_switch.m:
compiler/middle_rec.m:
compiler/peephole.m:
compiler/pragma_c_gen.m:
compiler/stack_layout.m:
compiler/string_switch.m:
compiler/switch_gen.m:
compiler/tag_switch.m:
compiler/trace_gen.m:
compiler/transform_llds.m:
    Support the new types in the LLDS code generator.

compiler/mlds.m:
    Support constants of the new types in the MLDS.

compiler/ml_accurate_gc.m:
compiler/ml_call_gen.m:
compiler/ml_code_util.m:
compiler/ml_disj_gen.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_global_data.m:
compiler/ml_lookup_switch.m:
compiler/ml_simplify_switch.m:
compiler/ml_string_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_target_util.m:
    Conform to the above changes to the MLDS.

compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
    Generate the appropriate target code for constants of the new
    types and operations involving them.

compiler/bytecode.m:
compiler/bytecode_gen.m:
    Handle the new types in the bytecode generator; we just abort if we
    encounter them for now.

compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_call_gen.m:
compiler/erl_code_util.m:
compiler/erl_rtti.m:
compiler/erl_unify_gen.m:
    Handle the new types in the Erlang code generator.

library/private_builtin.m:
    Add placeholders for the builtin unify and compare operations for
    the new types.  Since the bootstrapping compiler will not recognise
    the new types we give the polymorphic arguments.  These can be
    replaced after this change has bootstrapped.

    Update the Java list of TypeCtorRep constants.

library/int8.m:
library/int16.m:
library/int32.m:
library/uint8.m:
library/uint16.m:
library/uint32.m:
    New modules that will eventually contain builtin operations
    on the new types.

library/library.m:
library/MODULES_UNDOC:
    Do not include the above modules in the library documentation
    for now.

library/construct.m:
library/erlang_rtti_implementation.m:
library/rtti_implementation.m:
deep_profiler/program_representation_utils.m:
mdbcomp/program_representation.m:
    Handle the new types.

runtime/mercury_dotnet.cs.in:
java/runtime/TypeCtorRep.java:
runtime/mercury_type_info.h:
    Update the list of TypeCtorReps.

configure.ac:
runtime/mercury_conf.h.in:
    Check for the header stdint.h.

runtime/mercury_std.h:
    Include stdint.h; abort if that header is no present.

runtime/mercury_builtin_types.[ch]:
runtime/mercury_builtin_types_proc_layouts.h:
runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_ml_expand_body.h
runtime/mercury_table_type_body.h:
runtime/mercury_tabling_macros.h:
runtime/mercury_tabling_preds.h:
runtime/mercury_term_size.c:
runtime/mercury_unify_compare_body.h:
    Add the new builtin types and handle them throughout the runtime.
2017-07-18 01:31:01 +10:00
Julien Fischer
31d5ca41e1 Add G12's ranges type to the standard library.
library/ranges.m:
library/library.m:
library/MODULES_DOC:
     As above.

NEWS:
     Announce the addition.
2017-03-31 19:45:00 +11:00
Julien Fischer
092e175f45 Add a builtin unsigned word sized integer type -- Part 1.
Add a new builtin type: uint, which is an unsigned word sized integer type.
Support for this new type will need be bootstrapped over several changes.
This is the first such change and does the following:

- Extends the compiler to recognize 'uint' as a builtin type.
- Extends the set of builtin operations to include relational and (some)
  arithmetic operations on uints.
- Extends all of the code generators to handle the above.  There are some
  limitations currently marked by 'XXX UINT'.  These will be lifted once
  the compiler recognised uint and additional library support becomes
  available.
- Extends the runtime to support uints.

compiler/prog_type.m:
compiler/prog_data.m:
compiler/builtin_lib_types.m:
    Recognize uint as a builtin type.

    Add a new alternative to the cons_id/0 type corresponding to the uint type
    -- for bootstrapping purposes its argument is currently an int.

compiler/builtin_ops.m:
    Add builtin relational and arithmetic operations on uints.  Note that the
    existing 'unsigned_le' operation is actually intended for use with signed
    values.  Rather than attempt to modify its meaning, I have just added new
    operations specific to the uint type.

compiler/hlds_data.m:
    Add a new tag type for uints.

compiler/type_ctor_info.m:
    Recognise uint as a builtin.

    Bump the RTTI version number here.

compiler/ctgc.selector.m:
compiler/dead_proc_elim.m:
compiler/dependency_graph.m:
compiler/export.m:
compiler/foreign.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_code_util.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/hlds_pred.m:
compiler/implementation_defined_literals.m:
compiler/inst_check.m:
compiler/mercury_to_mercury.m:
compiler/mode_util.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_name.m:
compiler/polymorphism.m:
compiler/prog_out.m:
compiler/prog_rep.m:
compiler/prog_rep_tables.m:
compiler/prog_util.m:
compiler/rbmm.execution_path.m:
compiler/rtti.m:
compiler/special_pred.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/type_constraints.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/unused_imports.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Conform to the above changes to the parse tree and HLDS.

compiler/c_util.m:
    Support generating builtin operations for uints.

compiler/llds.m:
    Add a representation for uint constants to the LLDS.

    Map uints onto MR_Unsigned.

compiler/call_gen.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/llds_out_data.m:
compiler/llds_out_instr.m:
compiler/opt_debug.m:
compiler/opt_util.m:
    Support uints in the LLDS code generator.

compiler/mlds.m:
     Support uint constants in the MLDS.

compiler/ml_accurate_gc.m:
compiler/ml_call_gen.m:
compiler/ml_global_data.m:
compiler/ml_simplify_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/rtti_to_mlds.m:
    Conform to the above change to the MLDS.

compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
compiler/mlds_to_cs.m:
     Generate the appropriate target code for uint constants and uint
     relational operations.

compiler/bytecode.m:
compiler/bytecode_gen.m:
     Handle uints in the bytecode generator: we just abort if we
     encounter them for now.

compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_call_gen.m:
compiler/erl_code_util.m:
compiler/erl_rtti.m:
compiler/erl_unify_gen.m:
    Handle uints in the Erlang code generator.

library/private_builtin.m:
    Add placeholders for builtin_{unify,compare}_uint.  Since the
    bootstrapping compiler will not recognize uint as a type, we
    give them polymorphic arguments.  These can be replaced after
    this change has bootstrapped.

    Update the Java list of TypeCtorRep constants, which for some
    reason is defined here.

library/uint.m:
    New module that will eventually contain operations on uints.

library/MODULES_DOCS:
library/library.m:
     Add the uint module.

library/construct.m:
library/erlang_rtti_implementation.m:
library/rtti_implementation.m:
mdbcomp/program_representation.m:
     Handle uints.

deep_profiler/program_representation_utils.m:
     Conform to the above change.

runtime/mercury_dotnet.cs.in:
     Update the list of TypeCtorReps for C#

java/runtime/TypeCtorRep.java:
     Update this, although the actual TypeCtorRep constants
     are defined the library.

runtime/mercury_type_info.h:
    Bump the RTTI version number.

    Add an alternative for uints to the tyepctor rep enum.

runtime/mercury_builtin_types.{h,c}:
runtime/mercury_builtin_types_proc_layouts.h:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_table_type_body.h:
runtime/mercury_tabling.h:
runtime/mercury_tabling_macros.h:
runtime/mercury_unify_compare_body.h:
    Add uint as a builtin type and handle it throughout the runtime.

runtime/mercury_grade.h:
    Bump the binary compatibility version.

runtime/mercury_term_size.c:
runtime/mercury_ml_expand_body.h:
    Handle uint and fix probable bugs with the handling of ints on
    64-bit Windows.
2016-10-24 12:55:35 +11:00
Julien Fischer
5e09921375 Workaround standard library initialization problems in the Java grades.
In the Java grade, the standard streams were not being entered into the stream
database and the I/O globals were not being initialized.  For executables,
generate a call to library.std_library_init/2 before main/2 is invoked.  There
is still a problem for Mercury libraries called from Java programs and for
predicates specified in `:- initialise' declarations.   For the latter, Mercury
requires that all standard library initialization be performed *before* any
user specified initialize predicates, but because we currently implement all of
this in Java using static initializers we can't guarantee that the order things
occur in.

The same issue affects the C# grade; I'll add a workaround for it separately.

library/io.m:
    In the predicate io.init_state/2, in the Java grade do not
    bother setting the current stream since for the standard text
    streams we do so as part of class initialization and

library/library.m:
    Export std_library_init/2 to Java.

compiler/mlds_to_java.m:
     Generate a call to library.std_library_init/2 before main/2 is called.
     XXX TODO we should roll the call that initializes the benchmarking module
     into the same.

tests/hard_coded/Mmakefile:
tests/hard_coded/stdlib_init.{m,exp}:
    Test that the stream database and globals in the io module are
    initialized before main/2 is called.
2016-03-06 00:30:20 +11:00
Zoltan Somogyi
86bfd1af78 Clean up term.m.
library/term_conversion.m:
    A new library module that contains old code, to wit, the parts of term.m
    that deal with conversions of values of arbitrary types to and from terms.

library/term.m:
    Remove the code that is now in term_conversion.m.

    Put the remaining types and predicates into a logical order. These have
    several problems.

    - Many have argument orders that predate state var notation and
      don't work well with it.
    - Some have names that are simply not very meaningful.
    - And some predicates duplicate the functionality of other predicates.

    Fix these problems by

    - introducing new predicates with meaningful names that have
      state-var-friendly argument orders,
    - make the old predicates forward to the new ones, and
    - add comments urging users to use these in preference to the old,
      problematic predicates.

    After branching the next release, these comments should be augmented with
    obsolete pragmas.

library/library.m:
library/MODULES_DOC:
    Mention the new module.

library/io.m:
compiler/structure_reuse.analysis.m:
compiler/structure_sharing.analysis.m:
compiler/unused_args.m:
    Import term_conversion.m.

tests/hard_coded/ground_dd.m:
tests/hard_coded/term_to_univ_test.m:
tests/hard_coded/tuple_test.m:
tests/hard_coded/type_to_term.m:
tests/hard_coded/type_to_term_bug.m:
    Import term_conversion.m, and bring the programming style of these modules
    up to date.
2015-02-02 21:46:08 +11:00
Matthias Güdemann
02c6c4f155 Add priority search queue ADT
This implements a priority search queue ADT. This is a kind of blend
between priority queues and search trees; in contrast to a priority
queue, it also allows changing priorities of keys, looking up keys and
deleting keys.

This is an implementation based on the ICFP 2001 paper "A Simple
Implementation Technique for Priority Search Queues" by Ralf Hinze.
http://www.mercurylang.org/list-archives/users/2014-October/007804.html

Commit message paraphrased from Matthias' e-mail.
http://www.mercurylang.org/list-archives/reviews/2014-October/017414.html

library/psqueue.m:
    Add new module.

library/MODULES_DOC:
library/library.m:
    Include new module.

tests/hard_coded/Mmakefile:
tests/hard_coded/psqueue_test.exp:
tests/hard_coded/psqueue_test.m:
    Add test for psqueue.m
2014-12-07 21:54:07 +11:00
Zoltan Somogyi
a9208b47a8 Specialize ALL calls to string.format and io.format.
Previously, we specialized calls to string.format and io.format only if
the format string specified no flags, widths, precisions or non-default
bases for any conversion. We now specialize calls to those predicates
regardless of the format string. To make this possible, we now have two
copies of the code to parse format strings.

library/string.parse_runtime.m:
    This new module, carved out out library/string.format.m, contains
    one of those copies. As the name suggests, this copy is used by
    the runtime system.

compiler/parse_string_format.m:
    This new module contains the other copy. As its location suggests,
    this copy is used by the compiler. The separate copy is necessary
    because the compiler's parsing needs are different from the runtime's.

    The main reason for the separation is that the compiler needs to be
    able to handle cases where widths and predicates are given by manifest
    constants, as well as when they are given by the values of variables
    at runtime (when the format string contains conversion specifiers
    such as "%*d"). Having the runtime handle this extra complexity
    would have inevitably increased the runtime's format string interpretation
    overhead, which is undesirable.

    The other reason is that compiler can afford to postprocess the result
    of the parsing in order to avoid having to concatenate two or more
    constant strings at runtime.

library/string.parse_util.m:
    Types and predicates that are common to the library and compiler copies
    of the format string parsing code.

compiler/format_call.m:
    We used to check whether format strings match the supplied list
    of values to be printed by invoking string.format on dummy inputs
    of the supplied types, and seeing whether you got an exception.
    We now call parse_string_format.m instead. Not only does this
    avoid shenanigans with exceptions (which the deep profiler cannot
    yet handle), but it also allows us to specialize all calls
    to string.format and io.format. We therefore do so.

    We used to specialize calls to io.format by creating a single string
    to be printed (using the machinery needed to specialize calls to
    string.format), and then printing that. This did unnecessary memory
    allocations to hold the intermediate strings. We now simply print
    each component one after the other, which avoids this overhead.

library/string.format.m:
    Add versions of the predicates that print chars, strings, ints and floats
    that are specialized to each possible situation about whether the caller
    specifies a width and/or a precision. This means that format_call.m
    doesn't have to generate code that allocates cells on the heap.

    Remove the code that was moved to new submodules of string.m.

compiler/simplify_proc.m:
    List the predicates in string.format.m that the compiler
    may generate calls to in the list of such predicates that we maintain
    to prevent dead_pred_elim from deleting them before format_call.m
    gets a chance to do its work.

compiler/module_imports.m:
    If the code of the module calls a predicate named "format" that
    may refer to string.format or io.format, then implicitly import
    the modules that contain the types and predicates that the code
    generated by format_call.m will refer to. Note that since this
    module_imports.m works on Mercury code that has not been module
    qualified yet, we have to use a conservative approximation.

    Reorganize the way we discover what library modules we have to
    implicitly import. Instead of a separate boolean for each piece
    of functionality that needs an implicit import, put them together
    into a structure. Due to Peter's work on argument packing some
    years back, this is now more efficient as well as more convenient
    that passing around a bunch of booleans. Also switch to passing
    around the structure as an accumulator, instead of having to do
    bool.ors all over the place.

    Since the code for computing the list of modules to be implicitly
    imported can sometimes add a library module to the list twice,
    sort that list and remove any duplicates.

    To make this possible, remove the version of the main predicate
    that appends the implicitly imported module names to a list of
    module names passed by our caller, since we don't want to sort
    THAT list of module names.

    Give the remaining version of that predicate that does this
    a name that better matches the names of related predicates.

compiler/modules.m:
    Conform to the change in module_imports.m. Mark some suspicious code
    with XXXs.

    Remove some redundant comments.

compiler/options.m:
doc/user_guide.texi:
    Add a new option that tells format_call.m what it should do
    when it finds more than one problem with a format string: whether
    it should print a message only for the first problem, or for all
    the problems. (The default is the latter.)

library/MODULES_DOC:
    A list of the all the Mercury source files in the library that
    should be included in the user guide.

library/MODULES_UNDOC:
    A list of the all the Mercury source files in the library that
    should NOT be included in the user guide.

library/library.m:
    Include the new publicly visible new submodule of string.m,
    (string.parse_util). And both string.parse_util and string.parse_runtime
    (which is NOT visible from outside string.m) to the list of modules
    in the Mercury standard library.

    Update the rules for where new library modules should be documented
    to account for non-publically-visible submodules, which we haven't had
    before. Document the need to include new modules in either MODULES_DOC
    or MODULES_UNDOC.

mdbcomp/builtin_modules.m:
    Provide convenient access for format_call.m to the names of the
    submodules of string.m that it needs access to.

library/Mmakefile:
    Add a new target, check_doc_undoc, which checks whether any source files
    are missing from MODULES_DOC or MODULES_UNDOC.

doc/Mmakefile:
    Read the list of modules to be documented from MODULES_DOC. This replaces
    old code that tried to list all the undocumented modules, but missed one:
    it referred to erlang_conf.m instead of erlang_builtin.m.

    When creating the library documentation, filter out any lines that
    contain the string NOTE_TO_IMPLEMENTORS. We now use this mechanism
    to include reminders to implementors in what would otherwise be a
    publically visible part of string.m.

tools/bootcheck:
    Copy MODULES_DOC and MODULES_UNDOC to the stage 2 and 3 library
    directories, since the check_doc_undoc target, which is invoked by
    "make all" in the library directory, needs them.

compiler/hlds_out_module.m:
    When dumping out the table of types, dump out discriminated union types
    in a style that follows our recommended coding style.
2014-11-25 12:46:08 +11:00
Zoltan Somogyi
7f9791aa26 Standardize divider line lengths in the library.
library/*.m:
    As above.

tool/stdlines:
    A new shell script to do the job.
2014-11-23 22:05:34 +11:00
Zoltan Somogyi
50c1e04480 Carve two submodules out of string.m.
There are no algorithmic changes, though there are some name changes.

library/string.format.m:
    New submodule of string.m. Contains the parts of old string.m
    that implement string.format. About 1500 lines.

library/string.to_string.m:
    New submodule of string.m. Contains the parts of old string.m
    that implement string.string, string.string_ops and
    string.string_ops_noncanon. About 500 lines.

library/string.m:
    Replace the code that is now in the new submodules with includes
    of those submodules.

library/library.m:
    List the two new submodules. Fix some bitrot about where
    new library modules may need to be listed.

doc/Mmakefile:
    Do not document the two new submodules, since they are implementation
    details.
2014-11-10 14:31:51 +11:00
Paul Bone
e3c2dfa344 Add a future data type for concurrent and parallel programming
library/library.m:
library/thread.future.m:
library/thread.m:
    Add new future standard library module.

NEWS:
    Announce the new addition.

library/thread.semaphore.m:
    Add an impure interface to thread.semaphore.m.  Semaphores are used to
    implement our other concurrency primitives and an impure interface can
    often be useful to implement things such as futures, which don't require
    IO state threading.  The impure interface predicate names are prefixed
    with "impure_".

library/thread.semaphore.m:
NEWS:
    Deprecate the impure init/1 function.

library/thread.mvar.m:
    Conform to changes in semaphore.m.

benchmarks/progs/mandelbrot/mandelbrot.m:
    Add future example to mandelbrot benchmark.
2014-10-10 00:57:36 +11:00
Peter Wang
7688546d03 Add thread_safe and not_thread_safe attributes.
library/benchmarking.m:
library/bit_buffer.m:
library/exception.m:
library/gc.m:
library/io.m:
library/library.m:
library/thread.m:
library/time.m:
	Add `thread_safe' or `not_thread_safe' to foreign procs
	where it is clear which is correct.
2014-07-25 17:45:33 +10:00
Peter Wang
06647ff390 Implement unify/compare of tuples in Mercury.
The hand-written C unify and compare predicates for tuples did not preserve
deep profiler invariants correctly across the recursive unify/compare of
tuple arguments.  I tried to do so, and failed.  Instead, implement the
predicates in Mercury so the compiler can perform the deep profiling
transformation on them.  Bug #3.

A micro-benchmark on my machine is about twice as fast in asm_fast.gc
after this patch, and about the same in hlc.gc.  The change to the
high-level C backend is only to reduce code duplication.

library/library.m:
	Add foreign-exported predicates to take the place of `io.init_state'
	and `io.finalize_state' as overall initialization/finalization
	predicates.

library/builtin.m:
	Add `unify_tuple', `compare_tuple', `compare_rep_tuple' predicates.

	Add initializer which sets `MR_special_pred_hooks' to point to those
	predicates.

	Delete unused predicates `call_rtti_generic_unify',
	`call_rtti_generic_compare'.

	Reorder some code.

library/io.m:
	Add `io.finalize_state' to hidden interface.

	Delete foreign exports for `io.init_state' and `io.finalize_state'.

	Reorder some code.

runtime/mercury_ho_call.c:
runtime/mercury_ho_call.h:
	Add a global variable `MR_special_pred_hooks' for the library to
	set up during initialisation.

	Add `tailcall' macros for use by `mercury_unify_compare_body.h'.
	Rename `tailcall_user_pred' to `tailcall_tci_pred'.

	Call the new unify/compare predicates in the high-level C
	backend via `MR_special_pred_hooks'.

	Delete `unify_tuples' and `compare_tuples' for the high-level C
	and call the Mercury predicates set in `MR_special_pred_hooks'.

runtime/mercury_unify_compare_body.h:
	Delete the unify and compare code for tuples in the low-level C
	backend.  Jump to the Mercury predicates set in
	`MR_special_pred_hooks' instead.

	Add some comments.

compiler/elds_to_erlang.m:
runtime/mercury_init.h:
runtime/mercury_wrapper.c:
util/mkinit.c:
	Conform to the library initializer/finalizer change.

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

NEWS:
	Announce the change.
2014-07-10 13:24:05 +10:00
Paul Bone
8ad499c685 Add barriers (for concurrency) to the standard library
Mission Critical IT has maintained a library of code for concurrent
programming.  We're happy to contribute this upstream to the Mercury
project starting with this module implementing barriers.

library/thread.barrier.m:
    Add the new module implementing barriers.

library/thread.m:
library/library.m:
    Add new module.

NEWS:
    Announce the new module.

library/thread.semaphore.m:
    Add a comment.
2014-05-16 20:15:32 +10:00
Paul Bone
28f1f9cfd8 Fix syntax errors in my version string change
library.m:
    As above
2014-03-11 17:10:15 +11:00
Paul Bone
8f6bbc437c Print version information more succinctly
In the Mercury compiler itself, and in a number of tools we print a version
string on one line,

    $ mmc --version
    Mercury Compiler, version rotd-2013-10-01, configured for x86_64-unknown-linux-gnu
    Copyright (C) 1993-2013 The University of Melbourne

When the version number is sufficiently long, such as for an ROTD release, this
will wrap on 80 column terminals.  This change splits these strings into two
parts: the version and the architecture string.  These can then either be
printed more succinctly on one line

    $ mmc --version
    Mercury Compiler, version rotd-2013-10-01, on x86_64-unknown-linux-gnu
    Copyright (C) 1993-2013 The University of Melbourne

Or when written to a file such as the .c files that mmc generates, can be
written out onto two lines:

    XXX

library/library.m:
    Make the version predicate return two values, one for the version number
    and the other for the architecture name.  This makes it easier to format
    the version information in the various places it is used.

compiler/handle_options.m:
deep_profiler/mdprof_cgi.m:
deep_profiler/mdprof_create_feedback.m:
deep_profiler/mdprof_report_feedback.m:
deep_profiler/mdprof_test.m:
profiler/mercury_profile.m:
    Format this as shown above for the Mercury compiler and other tools.

compiler/c_util.m:
compiler/elds_to_erlang.m:
compiler/export.m:
compiler/fact_table.m:
compiler/llds_out_file.m:
compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
compiler/write_deps_file.m:
    Format version information on two lines when it is used in the
    compiler's various output files.
2014-03-10 19:01:22 +11:00
Peter Wang
7099f7c60b Add discrete interval encoding tree module to the standard library.
Discrete Interval Encoding Trees are a highly efficient set
implementation for fat sets.

This implementation is, in large parts, a translation of Caml Diet.
I have permission from the authors to license this version either under
the LGPL, or LGPL/BSD dual license.  We will choose the LGPL for
consistency with the rest of the standard library, but retain the other
option for the future.

library/diet.m:
	Add the new module.

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

NEWS:
	Announce the above addition.
2014-03-04 10:30:07 +11:00
Julien Fischer
92ddfdcf11 Delete obsolete procedures and modules from the standard library.
library/array.m:
library/array2d.m:
library/bitmap.m:
library/store.m:
library/thread.semaphore.m:
library/version_array2d.m:
library/version_bitmap.m:
library/version_hash_table.m:
library/version_store.m:
	Delete predicates that were deprecated in Mercury 13.05 and before.

library/version_array.m
	Delete the deprecated function new/2.

	Deprecate unsafe_new/2	and unsafe_init/2 to replace it.
	(We had overlooked this previously.)

library/string.m:
	Delete the deprecated function set_char_char/3.
	(We will leave the other deprecated procedures in this module
	for at least another release.)

library/svlist.m:
library/svpqueue.m:
library/svstack.m:
	Delete these modules: they were only ever needed as a transitional
	mechanism.

library/library.m:
	Conform to the above changes.

doc/Mmakefile:
	Unrelated change: delete references to files that have been
	deleted since we moved to git.

tests/hard_coded/*/*.m
tests/tabling/*.m:
	Update test cases where they made use of predicates that have
	now been deleted from the standard library.
2013-05-16 17:50:15 +10:00