Commit Graph

163 Commits

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

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

    Fix the one_or_more_to_doc function, which was

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

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

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

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

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

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

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

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

NEWS:
    Announce all the user-visible changes above.
2022-12-27 18:27:52 +11:00
Zoltan Somogyi
4c528d429d Add <<u and >>u to library/{int,uint}*.m ...
... along with their unchecked equivalents. These differ from <<, >> and
their unchecked equivalents in that they take the shift amount as a uint,
instead of an int.

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

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

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

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

tests/hard_coded/bitwise_int.exp:
tests/hard_coded/bitwise_int.exp2:
tests/hard_coded/bitwise_int.m:
tests/hard_coded/bitwise_int16.exp:
tests/hard_coded/bitwise_int16.m:
tests/hard_coded/bitwise_int32.exp:
tests/hard_coded/bitwise_int32.m:
tests/hard_coded/bitwise_int64.exp:
tests/hard_coded/bitwise_int64.m:
tests/hard_coded/bitwise_int8.exp:
tests/hard_coded/bitwise_int8.m:
tests/hard_coded/bitwise_uint.exp:
tests/hard_coded/bitwise_uint.exp2:
tests/hard_coded/bitwise_uint.m:
tests/hard_coded/bitwise_uint16.exp:
tests/hard_coded/bitwise_uint16.m:
tests/hard_coded/bitwise_uint32.exp:
tests/hard_coded/bitwise_uint32.m:
tests/hard_coded/bitwise_uint64.exp:
tests/hard_coded/bitwise_uint64.m:
tests/hard_coded/bitwise_uint8.exp:
tests/hard_coded/bitwise_uint8.m:
    Check that <<u and >>u compute the same results as << and >> respectively.
2022-12-07 23:12:33 +11:00
Zoltan Somogyi
ec20b1ed0a Make sparse_bitset.m operate on uints.
NEWS:
    Mention all the user-visible changes below.

library/enum.m:
    Add the typeclass uenum, which is a version of the existing enum typeclass
    that maps items to uints, not ints. It also uses a semidet predicate,
    not a semidet function, to get back to the item from the uint.

library/sparse_bitset.m:
library/fat_sparse_bitset.m:
    Make these modules operate on uints, which means requiring the items
    in the sets to be instances of uenum, not enum.

    If a few places, improve loops by doing previously-repeated conversions
    of [u]ints into <offset, bit-to-set> pairs just once.

library/counter.m:
    Define ucounters, which allocate uints. Improve documentation.

library/digraph.m:
    Change digraph_keys from ints to uints, since we put them into
    sparse_bitsets.

library/int.m:
    Make int an instance of the uenum typeclass. This can help users
    who currently put ints into sparse_bitsets.

library/pprint.m:
    Prettyprint sparse_bitsets as lists of uints.

library/term.m:
    Make vars instances of uenum as well as enum.

library/uint.m:
    Make uint an instance of the uenum typeclass.

    Add the ubits_per_uint function, which allows some casts to be avoided.

compiler/make.deps_set.m:
    Change the indexes we put into sparse_bitsets from ints to uints.

compiler/make.make_info.m:
    Change the source of those indexes from ints to uints.

compiler/make.top_level.m:
compiler/make.util.m:
    Conform to the changes above.

compiler/pre_quantification.m:
    Change zones from ints to uints, since we put them into sparse_bitsets.

tests/hard_coded/int_uenum.{m,exp}:
tests/hard_coded/Mmakefile:
    Enable the new test case.

tests/valid/use_import_only_for_instance.m:
    Update this extract from library/digraph.m the same way as
    library/digraph.m itself.
2022-12-05 09:45:11 +11:00
Julien Fischer
e7d28ff90f Update copyright notices in stdlib.
library/*.m:
    As above.
2022-06-07 21:51:03 +10:00
Zoltan Somogyi
0186a64520 Warn for unneeded use of mode-specific clauses.
compiler/add_clause.m:
    Generate a warning for mode-specific clauses when the clause is for
    a predicate that has only one mode, provided that the warning is enabled.

compiler/options.m:
    Add an option to enable this warning.

doc/user_guide.texi:
    Document this option.

library/exception.m:
library/int.m:
library/rtti_implementation.m:
library/string.m:
    Delete modes from clause heads that would get this warning.

tests/valid/spurious_purity_warning.m:
    Delete modes from clause heads that would get this warning.

    Do not interleave predicate definitions.

tests/warnings/unneeded_mode_specific_clause.{m,exp}:
    A test case for this warning.
tests/warnings/Mmakefile:
    Enable the new test case.

tests/invalid/multimode_syntax.err_exp:
    Expect the new warning.
2022-04-13 23:39:23 +10:00
Zoltan Somogyi
8ff61f8a4b Delete quotes from `VarNames' in stdlib comments.
In the Mercury standard library, every exported predicate or function
has (or at least *should* have) a comment that documents it, including
the meanings of its arguments. About 35-40% of these modules put `'s
(left and right quotes) around the names of the variable representing
those arguments. Some tried to do it consistently (though there were spots
with unquoted or half quoted names), while some did it only a few places.
This is inconsistent: we should either do it everywhere, or nowhere.
This diff makes it nowhere, because

- this is what the majority of the standard library modules do;
- this is what virtually all of the modules in the compiler, profiler,
  deep_profiler etc directories do;
- typing all those quotes when adding new predicates in modules that
  follow this convention is a pain in the ass; and because
- on many modern terminals, `' looks non-symmetrical and weird.

Likewise, the comment explaining a predicate often started with

    % `predname(arguments)' returns ...

This diff deletes these quotes as well, since they add nothing useful.

This diff does leave in place quotes around code fragments, both terms
and goals, where this helps delineate the boundaries of that fragment.
2022-03-07 11:49:00 +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
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
Zoltan Somogyi
58ea6ffff2 Delete old obsolete predicates and functions.
library/*.m:
    Specifically, delete any predicates and functions whose `pragma obsolete'
    dates from 2018 or before. Keep the ones that were obsoleted
    only this year or last year.

NEWS:
    Announce the changes.

tests/debugger/io_tab_goto.m:
tests/debugger/tabled_read.m:
tests/declarative_debugger/io_stream_test.m:
tests/declarative_debugger/tabled_read_decl.m:
tests/declarative_debugger/tabled_read_decl_goto.m:
tests/general/array_test.m:
tests/hard_coded/mutable_init_impure.m:
tests/hard_coded/remove_file.m:
tests/tabling/mercury_java_parser_dead_proc_elim_bug.m:
tests/tabling/mercury_java_parser_dead_proc_elim_bug2.m:
tests/valid/mercury_java_parser_follow_code_bug.m:
    Replace references to predicates and functions that this diff deletes
    with their suggested replacements.

    In several test cases, bring the programming style up to date.

tests/hard_coded/shift_test.{m,exp}:
    Most of this test case tested the now-deleted legacy shift operations.
    Replace these with tests of their non-legacy versions, including
    testing for the expected exceptions.

tests/hard_coded/shift_test.{m,exp}:
    Don't pass --no-warn-obsolete when compiling shift_test.m anymore.
2020-08-18 11:57:47 +10:00
Zoltan Somogyi
1e64d0ed0e Declare private_builtin.unsigned_{lt,le}.
library/private_builtin.m:
    As above. The code recognizing them as builtins was added a few weeks ago.

configure.ac:
    Require the installed compiled to contain that code.

compiler/options.m:
    Provide a way to test whether the compiler has *this* diff.

library/int.m:
    Delete int.unsigned_lt, and use private_builtin.unsigned_lt instead.

tests/hard_coded/unsigned_lt_le.{m,exp}:
    A test case for the two operations.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2020-05-25 16:50:46 +10:00
Zoltan Somogyi
ba59f6313c Make unsigned_lt a builtin operation, step 1.
Step 1 is making it a builtin; step 2 will be declaring it.
(We won't define it, since builtins may not have definitions.)

compiler/builtin_ops.m:
    Make unsigned_lt a builtin operation, and recognize
    private_builtin.unsigned_lt which does not exist yet,
    as that operation.

    We already had a builtin operation unsigned_le, which the compiler
    generated references to internally. Recognize private_builtin.unsigned_le
    as this builtin operation. The difference is that just having a builtin op
    is enough for compiler passes inside the LLDS/MLDS/ELDS backends
    that generate LLDS/MLDS/ELDS code that refer to the builtin op,
    (though the ELDS backend does not have any code that does such things),
    while code that wants to create references to builtin ops in the HLDS
    needs to have access to the predicate declaration of each builtin.
    So far, we intend to use only unsigned_lt, not unsigned_le, in this manner,
    but treating two such closely related ops differently would violate
    the law of least astonishment.

    Fix an old XXX that is related to this diff only in affecting the same
    type: standardize on add/sub/mil/div terminology over
    plus/minus/times/divide terminology.

compiler/erl_call_gen.m:
    Abort on references to unsigned_lt as well as unsigned_le.

compiler/llds_out_data.m:
compiler/ml_global_data.m:
compiler/mlds_to_c_data.m:
    The C backends already implemented unsigned_le. Handle unsigned_lt
    the same way as unsigned_le, only with s/<=/</.

compiler/mlds_to_cs_data.m:
    Implement both unsigned_lt and unsigned_le, using the C# foreign_proc
    implementation of unsigned_lt in library/int.m as a basis.

compiler/mlds_to_java_data.m:
    Implement both unsigned_lt and unsigned_le, using the Java foreign_proc
    implementation of unsigned_lt in library/int.m as a basis.

compiler/options.m:
    Provide a way to detect whether the installed compiler has this diff.
    We will need such a test in configure.ac for stage 2.

compiler/bytecode.m:
compiler/llds.m:
compiler/mlds_dump.m:
compiler/opt_debug.m:
    Conform to the changes above.

library/int.m:
    Module qualify references to unsigned_lt. This is to allow the
    affected code to compile even after the declaration of unsigned_lt
    as a predicate in private_builtin.m. (The last step of this sequence
    would be the deletion of both int.unsigned_lt and the references to it.)
2020-05-02 20:07:46 +10:00
Zoltan Somogyi
85f20002c5 Move the domain_error type to exception.m.
library/math.m:
library/exception.m:
    Move the domain_error type from math.m to exception.m.

NEWS:
    Announce the change as a potentially breaking change.

deep_profiler/query.m:
library/float.m:
library/int.m:
library/int16.m:
library/int32.m:
library/int64.m:
library/int8.m:
library/integer.m:
library/uint.m:
library/uint16.m:
library/uint32.m:
library/uint64.m:
library/uint8.m:
    Replace all references to math.domain_error with just domain_error.
    Delete imports of math.m where this was the only reason for the import.
2020-05-01 18:57:43 +10:00
Julien Fischer
d33647299a Rationalise hash functions across the standard library.
Currently, the hash functions for (some of) the primitive types are defined in
three places:

   1. The hash_table module.
   2. The version_hash_table module (duplicates of the above).
   3. Some (but not all) of the library modules for the primitive types.

This change makes the library module for a primitive type provide the hash
function for that type and deprecates the versions in the hash table modules.

Additionally, deprecate the "generic" has functions in the hash table modules.

library/hash_table.m:
library/version_hash_table.m:
    As above.

library/char.m:
library/int.m:
library/uint.m:
    Add hash/1 and hash/2.

library/float.m:
    Add hash/2.

library/robdd.m:
    Replace a call to the deprecated function.

NEWS:
    Announce the above additions and deprecations.

tests/hard_coded/hash_table_delete.m:
tests/hard_coded/hash_table_test.m:
tests/hard_coded/version_hash_table_delete.m:
tests/hard_coded/version_hash_table_test.m:
    Conform to the above change.
2020-02-11 14:22:42 +11:00
Zoltan Somogyi
c7f8ebbe2f Avoid warnings from --warn-non-contiguous-{clauses,foreign-procs}.
browser/collect_lib.m:
browser/declarative_execution.m:
browser/dl.m:
browser/io_action.m:
compiler/make.util.m:
compiler/pickle.m:
compiler/process_util.m:
compiler/prog_event.m:
library/array.m:
library/benchmarking.m:
library/bit_buffer.m:
library/builtin.m:
library/char.m:
library/deconstruct.m:
library/dir.m:
library/erlang_rtti_implementation.m:
library/int.m:
library/int16.m:
library/int32.m:
library/int64.m:
library/int8.m:
library/io.m:
library/math.m:
library/mutvar.m:
library/private_builtin.m:
library/profiling_builtin.m:
library/rtti_implementation.m:
library/store.m:
library/string.format.m:
library/string.m:
library/table_builtin.m:
library/term_size_prof_builtin.m:
library/thread.m:
library/time.m:
library/type_desc.m:
library/uint16.m:
library/uint32.m:
library/uint64.m:
library/uint8.m:
ssdb/ssdb.m:
    As above. This mostly involved two things.

    The first was grouping foreign_procs by predicate instead of by language.
    In a few cases, this revealed that some predicates *had* no foreign_proc
    for a language, while related predicates did have one that just aborted
    if called. This diff adds similar aborting foreign_procs to predicate/
    language combinations that were missing them, when this seemed obviously
    the right thing to do.

    The second was moving pragmas about a predicate from the middle of the
    block of clauses of that predicate to the start of that block.
2018-10-19 11:01:33 +11: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
a8f095d555 Avoid undefined behaviour of int.abs.
library.m:
    Make int.abs throw an exception for int.min_int.

    Add the new function unchecked_abs/1, whose behaviour is
    undefined for int.min_int.

    Add the new function nabs/1 which computes the negative
    absolute value of an int.  Unlike abs, this is defined for
    all ints.

NEWS:
    Announce the above.

    Unrelated change: list int64 and uint64 as reserved type names.
2018-01-14 18:57:57 -05:00
Julien Fischer
17ef2d1e7f Fix a cut-and-paste error.
library/int.m:
    s/<</>>/ in an error message.
2017-10-21 07:27:58 -04:00
Julien Fischer
579964fb13 Fix a compilation error in Erlang grade.
library/int.m:
    Call private_builtin.sorry/1 instead of require.sorry/2 in the
    stub definition of unsigned_lt/2.
2017-08-31 12:19:55 +10:00
Julien Fischer
8e66e5b075 Change the semantics of the int shift operations.
Change int.(<<) and int.(>>) to throw an exception if their second operand is
not in [0, bits_per_int).  This brings them into line with the other integer
types.

As a transitional measure, add new functions that provide the old semantics.

library/int.m:
    As above.

NEWS:
    Announce the above change.

    Include the fixed size integer types in the list of reserved type names.

tests/hard_coded/shift_test.m:
     Call the legacy versions of the int shift operations.

tests/hard_coded/bitwise_int.{m,exp}:
     A new test of bitwise operations for the int type.
     (XXX I will add a 32-bit expected output separately.)

tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
     Include the new test case.

     Do not warn about the use of the obsolete legacy shift operations.
2017-08-30 20:46:11 +10:00
Zoltan Somogyi
54e84b908f Fix more warnings from --warn-inconsistent-pred-order-clauses. 2017-05-04 12:03:15 +10:00
Julien Fischer
8e8fc26209 Add a builtin unsigned word sized integer type -- Part 2.
Begin implementing library support for uints.

Update the compiler to use the uint type.

library/uint.m:
    Begin filling this module in.

library/private_builtin.m:
    Use the proper argument type for builtin_{unify,compare}_uint
    and provide actual implementations for them.

library/table_builtin.m:
    Add tabling builtins for uints.

library/string.m:
    Add a function to convert a uint to a decimal string.
    (XXX NYI for Erlang).

library/io.m:
    Add write_uint/[45].

    Add the stream instance for uints and text output streams.

library/stream.string_writer.m:
    Add put_uint/4.

    Support uints in string_writer.write etc.

library/pprint.m:
    Make uint an instance of the doc/1 type class.

library/pretty_printer.m:
    Add a default formatter for uints.

library/int.m:
    Unrelated change: fix formatting.

compiler/builtin_ops.m:
compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/hlds_data.m:
compiler/llds.m:
compiler/llds_out_data.m:
compiler/mercury_to_mercury.m:
compiler/ml_lookup_switch.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/opt_debug.m
compiler/parse_tree_out.m:
compiler/parse_tree_out_info.m:
compiler/prog_data.m:
compiler/prog_out.m:
compiler/prog_rep.m:
compiler/hlds_out_util.m:
    Use the uint type in places where we should.

compiler/mlds_to_java.m:
    Fix a bug that causes us to generate badly typed Java.
    For div and mod we need to cast the entire expression to
    an int, not just the first operand.

compiler/c_util.m:
compiler/mlds_to_cs.m:
    Add predicates for outputting unsigned integers in C and C#.

tests/hard_coded/test_pretty_printer_defaults.exp:
    Conform to the above change to the pretty_printer module.
2016-10-31 10:31:05 +11:00
Zoltan Somogyi
8a6165b499 Give some variables better names. 2016-04-10 06:17:47 +10:00
Zoltan Somogyi
e99b7318c3 Mark is/2 as obsolete. 2016-01-13 02:37:53 +11:00
Julien Fischer
94535ec121 Fix spelling and formatting throughout the system.
configure.ac:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
library/*.m:
ssdb/*.m:
runtime/mercury_conf.h.in:
runtime/*.[ch]:
scripts/Mmake.vars.in:
trace/*.[ch]:
util/*.c:
	Fix spelling and doubled-up words.

	Delete trailing whitespace.

	Convert tabs into spaces (where appropriate).
2015-12-02 18:46:14 +11:00
Zoltan Somogyi
d121f0a85b Convert (C->T;E) to (if C then T else E). 2015-10-21 01:14:32 +11:00
Julien Fischer
c6da21fda2 Add the predicate int.all_true_in_range/3.
Add the predicate all_true_in_range/3 where

   all_true_in_range(P, Low, High) <=>
       list.all_true(P, Low .. High)

except that it avoids construction of the list 'Low..High'.

library/int.m:
    Add the above predicate.

    s/Lo to Hi/Low to High/ in the description of the predicate
    nondet_int_in_range/3.  We use the latter form when describing
    the fold predicates above.

NEWS:
    Announce the new predicate.

    Adjust an existing entry.

tests/hard_coded/Mmakefile:
tests/hard_coded/int_range_ops.{m,exp}:
    Test the new predicate and also test the predicate nondet_in_range/3
    since none of the existing tests covered that.
2015-01-24 01:58:03 +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
Julien Fischer
bed96b93ff Avoid module qualification in library interfaces where possible.
NOTE: this change does not affect the io module -- I've left that for a
separate change.

library/*.m:
	As per the recent change to the coding standard, avoid module
	qualification in library interfaces where possible.

	Reformat declarations and descriptive comments to better utilise
	any space freed up by the above.
2014-10-10 15:08:24 +11:00
Julien Fischer
b262a2b0a7 Add new float classification predicates.
Add the predicates is_finite/1 and is_zero/1 to the float module.
In C grades the implementation of the former maps down to the isfinite macro
(with C99).

configure.ac:
runtime/mercury_confg.h.in:
	Check if the C99 macro isfinite is available.

runtime/mercury_float.h:
	Add the macro MR_is_finite for testing if a floating point
	number is finite.  If the C stdlib provides this operation
	directly we use that, otherwise we define it in terms of
	MR_is_infinite and MR_is_nan.

library/float.m:
	Add the predicates is_finite/2 and is_zero/2.

	Expand tabs in this file.

	Fix capitalization in documentation.

library/int.m:
	Fix inconsistent capitalization in a spot.

library/string.m:
	Use is_finite/1 in place of negating is_nan_or_infinite/1.
2014-09-17 14:43:25 +10:00
Julien Fischer
3c705c9ecd Avoid some C compiler warnings on Cygwin.
library/int.m:
	Avoid warnings about overflows in implicit constant conversions in the
	implementations of {min,max}_int/0 on Cygwin.  The C compiler is
	complaining about where we assign LONG_MIN or LLONG_MIN to a 32-bit
	MR_Integer.  This only occurs in code branches that are dead when
	MR_Integer is 32-bit, so the fix here is just to put in some explicit
	casts.
2014-02-28 17:12:26 +11:00
Julien Fischer
36f58a2d48 Add some more standard library procedures.
library/bimap.m:
	Add a predicate for testing semantic equality of bimaps.

library/assoc_list.m:
	Add fold_values with two or three accumulator arguments.

library/int.m:
	Add fold_{up,down} with three accumulator arguments.

library/map.m:
library/tree234.m;
	Add foldl_values with two or three accumulator arguments.

NEWS:
	Announce the above additions.

	Reformat the existing changes to the pqueue module slightly
2013-12-17 11:42:01 +11:00
Julien Fischer
27418bf187 Fix a build problem on Mac OS X.
library/int.m:
    LLONG_{MIN,MAX} are the standard (C99) names for the limits
    of the long long int type; use them in preference to LONG_LONG_{MIN,MAX},
    which are a GNU C thing.

    Make the use of the above macros conditional on them actually being
    defined since we cannot guarantee that they will be defined if the
    C compiler is not in C99 mode (or something similar to it).
2013-03-26 13:07:31 +11:00
Julien Fischer
60f77ac95d Fix int.{min,max}_int/0 on Windows 64.
library/int.m:
    On 64-bit Windows MR_Integer has the same size as C's long long type; the
    implementations of int.{min,max}_int/0 did not handle this case.
2013-03-22 14:10:26 +11:00
Zoltan Somogyi
276614c943 Fix spelling.
Estimated hours taken: 0.1
Branches: main

brary/int.m:
	Fix spelling.
2012-10-24 03:49:32 +00:00
Julien Fischer
ba4803fcf9 Add an unsafe version of field update for arrays,
Branches: 11.07, main

library/array.m:
	Add an unsafe version of field update for arrays,
	'unsafe_elem :='/3.

	Support foldl and foldr over arrays with 3-5 accumulators.

	Privately export the predicate dynamic_cast_to_array/2 from
	this module.  Previously, there were several definitions of
	this scattered throughout the library.

	Use unsafe operations (which are more efficient) in several places
	where it is safe to do so.

	Use state variable notation in more places.

library/int.m:
	Add an additional mode to each of int.fold_up2/7 and int.fold_down2/7
	with the modes (array_di, array_uo).

library/hash_table.m:
library/pprint.m:
library/version_hash_table.m:
	Delete duplicate definitions of dynamic_cast_to_array/2 and use
	the definition exported from the array module instead.

NEWS:
	Announce the above.
2011-08-13 16:19:58 +00:00
Julien Fischer
4255cdd025 Add cord.init/0 for consistency with other modules.
Branches: main

library/cord.m:
	Add cord.init/0 for consistency with other modules.

library/int.m:
library/char.m:
	Group function definitions with the corresponding
	predicate definition.

library/version_store.m:
	Fix indentation.

NEWS:
	Announce the addition of cord.init/0.

	Fix some earlier entries.
2011-05-10 07:02:28 +00:00
Zoltan Somogyi
d735690f4c Make a module list easier to modify.
Estimated hours taken: 1
Branches: main

library/Mmakefile:
	Make a module list easier to modify.

library/array.m:
library/int.m:
	Add predicates needed by g12.

NEWS:
	Mention the new predicates.

	Remove announcements of new modes for predicates which are themselves
	new.
2010-12-13 04:40:39 +00:00
Peter Wang
c053f90088 Allow inlining of Java foreign_procs.
Branches: main, 10.04

Allow inlining of Java foreign_procs.

This revealed a problem with directly using the `succeeded' flag directly as
the success indicator in Java foreign_procs.  When the code of the foreign_proc
becomes a nested function, and after nested functions are eliminated, there may
not be a variable called `succeeded' in that context; it is moved into
environment struct, and the transformation is not able to update handwritten
code to reflect that.  The solution is to declare a local variable for the
foreign_proc, let the handwritten code assign that, then assign its final
value to the `succeeded' flag with an MLDS statement.

We take the opportunity to name the local variable `SUCCESS_INDICATOR', in
line with other backends.

compiler/inlining.m:
        Allow inlining of Java foreign_procs.

compiler/ml_foreign_proc_gen.m:
        In the code generated for semidet Java foreign_procs, declare a local
        `SUCCESS_INDICATOR' variable and assign its value to the `succeeded'
        flag afterwards.

        Add braces to give the foreign_proc variables a limited scope.

compiler/make_hlds_warn.m:
        Conform to renaming.

doc/reference_manual.texi:
        Update documentation for the renaming of the `succeeded' variable.

library/array.m:
library/bitmap.m:
library/builtin.m:
library/char.m:
library/construct.m:
library/dir.m:
library/exception.m:
library/float.m:
library/int.m:
library/io.m:
library/math.m:
library/private_builtin.m:
library/rtti_implementation.m:
library/string.m:
library/thread.m:
library/time.m:
library/type_desc.m:
library/version_array.m:
        Conform to renaming.

        Fix problems with Java foreign_procs that may now be copied into other
        modules when intermodule optimisation is enabled, some by disallowing
        the procedures from being duplicated, some by making referenced
        classes/fields `public'.

        [Some of the `may_not_duplicate' attributes may not indicate actual
        problems, just that it seems not worthwhile inlining calls to the
        procedure.]

extras/solver_types/library/any_array.m:
tests/hard_coded/equality_pred_which_requires_boxing.m:
tests/hard_coded/external_unification_pred.m:
tests/hard_coded/java_test.m:
tests/hard_coded/redoip_clobber.m:
tests/hard_coded/user_compare.m:
tests/valid/exported_foreign_type2.m:
tests/warnings/warn_succ_ind.m:
tests/warnings/warn_succ_ind.exp3:
        Conform to renaming.
2010-05-07 03:12:27 +00:00
Zoltan Somogyi
0723c2e4b2 Fix the style of some documentation.
Estimated hours taken: 0.2
Branches: main

library/int.m:
	Fix the style of some documentation.

library/set_ordlist.m:
	Fix the style of some code.
2009-11-02 05:13:30 +00:00
Ian MacLarty
9f8aff5b0b Add a new standard library module for working with the Gregorian
Estimated hours taken: 4
Branches: main

Add a new standard library module for working with the Gregorian
calendar.

NEWS:
	Mention the new module.

library/calendar.m:
	The new module.

library/int.m:
	Fix a typo in a comment.

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

tests/hard_coded/Mmakefile:
tests/hard_coded/calendar_test.exp:
tests/hard_coded/calendar_test.m:
	Test the new module.
2009-02-04 23:10:50 +00:00
Julien Fischer
f2b16090a7 Add some more modes to some standard library predicates.
library/int.m:
	Add more modes to the int.fold* family of predicates.

	Re-order the mode declarations as-per the ordering of
	the higher-order predicates in the list module.

library/list.m:
	Add another mode of list.foldl2/6.

	Re-order the mode declarations for list.foldl/4 to conform
	to the style used for the other fold-style predicates in
	this module.
2008-12-13 12:59:02 +00:00
Zoltan Somogyi
599e1c2fdb Implement the proc command of the deep profiler using the report mechanism.
Estimated hours taken: 16
Branches: main

Implement the proc command of the deep profiler using the report mechanism.

Some of the detailed changes also address Paul's post-commit review of my
previous diff.

deep_profiler/report.m:
	Define the representation of the proc report.

	Change some names to be more consistent.

deep_profiler/profile.m:
	Add a type for use in report.m.

	Document the fields of an existing type.

deep_profiler/create_report.m:
	Add code to create proc reports.

	Change some names to be more consistent.

	Fix a bug: avoid divide by zero exceptions in some rare cases.

deep_profiler/measurement units.m:
	Fix a bug: avoid divide by zero exceptions in some rare cases.

deep_profiler/display_report.m:
	Add the code for converting proc reports to displays. This required
	rewriting almost everthing in this module to remove the assumption,
	which was previously embedded in many places, that the code is part
	of the implementation of the top_procs command. The new code is
	separated into two parts; the command-specific parts, and the parts
	that should be usable for all commands. (The reusable part is much
	bigger.)

deep_profiler/display.m:
	Expand the display representation to allow the specification of

	- plain text as distinguished from headings
	- paragraph breaks
	- pseudo-links, i.e. text fragments that are formatted like links
	- table separator rows
	- table cells that span more than one column

	which are used in the new version of display_report.m.

	Simplify the mechanism for setting up table header groups.

deep_profiler/html_format.m:
	Handle the changes in display.m.

	Fix some anomalies in the formatting of lists and tables.

	Group related code together.

deep_profiler/query.m:
	Provide a switch for selecting which of the two mechanisms,
	the old direct generation of HTML or the new indirect generation
	through the report and display structures, should generate the HTML
	page for a command that both mechanisms can implement. The default
	is the new mechanism, but it can be overridden by implementors
	by creating a file called "/tmp/old_deep_profiler".

	Switch the default handling of the proc command over to the new
	mechanism.

	Rename some types and function symbols to make them more consistent
	and expressive.

	Generate more informative error messages for domain error exceptions.

deep_profiler/mdprof_cgi.m:
	Add a mechanism for decoding the links in the generated pages.
	The mechanism takes the form of three new options: --decode,
	--decode-cmd, and --decode-prefs. When one or more of these are given,
	mdprof_cgi will not do its usual stuff, instead of just loops waiting
	for lines whose contents it will then try to decode as queries,
	as commands and/or as preferences.

deep_profiler/Mercury.options:
	Try to postpone thrashing in the deep compiler when compiled in
	debug grades, by compiling their contents with shallow tracing.

deep_profiler/array_util.m:
	Make shallow tracing effective by moving the deep recursions
	into non-exported predicates.

deep_profiler/callgraph.m:
deep_profiler/canonical.m:
deep_profiler/startup.m:
	Convert the debugging code to use trace goals.

deep_profiler/cliques.m:
deep_profiler/read_profile.m:
	Convert the debugging code to use trace goals.

	Use more expressive names for lots of variables.

	In read_profile.m, avoid an unnecessary repackaging of data.

deep_profiler/util.m:
	Fix some grammar errors in a comment, and comment some code to use
	state variables.

deep_profiler/interface.m:
	Fix some grammar errors in a comment.

deep_profiler/mdprof_feedback.m:
	Change some variable names to be consistent with the other modules.

library/float.m:
library/int.m:
	Make the messages in the domain errors we throw more expressive.

library/io.m:
	Minor style changes.
2008-08-18 02:14:59 +00:00
Ralph Becket
67ec243a51 Define pretty_printer formatters for some common standard library types.
Estimated hours taken: 4
Branches: main

Define pretty_printer formatters for some common standard library types.
Include these formatters in the default pretty_printer formatter_map.
Add a useful function to the pretty_printer interface.

library/array.m:
library/char.m:
library/float.m:
library/int.m:
library/list.m:
library/string.m:
library/tree234.m:
	Add <type>_to_doc functions.

library/pretty_printer.m:
	Added function format_arg/1.
	Initialise the default formatter_map to use the <type>_to_doc
	functions.

tests/hard_coded/Mmakefile:
tests/hard_coded/test_pretty_printer_defaults.exp:
tests/hard_coded/test_pretty_printer_defaults.m:
	Test case.
2007-08-14 04:21:09 +00:00
Peter Ross
e3f8bbf9aa Implement the TypeCtorInfo RTTI so that generic compare
Estimated hours taken: 16
Branches: main

Implement the TypeCtorInfo RTTI so that generic compare
and unify work via rtti_implementation.

However after discussion with zs, this current design of
RTTI has to be adapted to become more erlang specific, due
to the different data representation on the erlang backend.
The current code will serve as a template for this new design
though, which is why it is being checked in.

Add various erlang library implementations which are
needed to run useful programs when testing the erlang backend.

compiler/elds.m:
	Add a type_info_id.

compiler/elds_to_erlang.m:
	We now generate type_ctor_info's so call them.

compiler/erl_rtti.m:
	After discussions with zs, type_info and pseudo_type_infos
	should never occur on the erlang backend as they are needed
	for gc and the debugger so throw an exception for them.
	Add an implementation of creating a static type_info, but which
	isn't used in case we need it again later.
	Create type_ctor_info with all the fields except the
	TypeFunctors, the TypeLayout and the FunctorNumberMap

compiler/special_pred.m:
	Make sure we generate RTTI for the builtin types.

library/builtin.m:
library/char.m:
library/exception.m:
library/float.m:
library/int.m:
library/io.m:
library/lexer.m:
library/math.m:
library/mutvar.m:
library/ops.m:
library/par_builtin.m:
library/private_builtin.m:
library/rtti_implementation.m:
library/solutions.m:
library/store.m:
library/string.m:
library/table_builtin.m:
library/thread.semaphore.m:
library/time.m:
library/type_desc.m:
	Erlang implementations of std library functions.
2007-05-30 08:16:09 +00:00
Zoltan Somogyi
7b7dabb89a Extend this optimization to handle temporaries being both defined in
Estimated hours taken: 12
Branches: main

compiler/use_local_vars.m:
	Extend this optimization to handle temporaries being both defined in
	and used by foreign_proc_code instructions. This should eliminate
	unnecessary accesses to the MR_fake_reg array, and thus speed up
	programs that use foreign code a lot, including typeclass- and
	tabling-intensive programs, since those features are implemented using
	inline foreign code. I/O intensive should also benefit, but not much,
	since the cost of the I/O itself overwhelms the cost of the
	MR_fake_reg accesses.

	Group together the LLDS instructions that are handled similarly.
	Factor out some common code.

compiler/opt_util.m:
	Allow for the fact that foreign_proc_codes can now refer to
	temporaries.

compiler/opt_debug.m:
	Print more useful information about foreign_proc_code components.

compiler/prog_data.m:
	Rename the types and function symbols of the recently added
	foreign_proc attributes to avoid clashing with the keywords
	representing them in source code.

	Add a new foreign_proc attribute, proc_may_duplicate that governs
	whether the body of foreign code is allowed to be duplicated.

compiler/table_gen.m:
	Include does_not_affect_liveness among the annotations for the
	foreign_proc calls generated by this module. Some of these procedures
	affect memory beyond their arguments, but that memory is in tables,
	not in unlisted registers.

	Allow some of the smaller code fragments generated by this module
	to be duplicated.

compiler/inlining.m:
	Respect the may_not_duplicate foreign_proc attribute.

compiler/pragma_c_gen.m:
	Transmit any annotations about liveness from the HLDS to the LLDS,
	since without does_not_affect_liveness annotations use_local_vars.m
	cannot optimize foreign_proc_codes.

	Transmit any annotations about may_duplicate from the HLDS to the LLDS,
	since with them jumpopt can do a better job.

compiler/llds.m:
	Use the new foreign_proc attribute instead of a boolean to represent
	whether a foreign code fragment may be duplicated.

compiler/simplify.m:
	Generate an error message if a may_duplicate or may_not_duplicate
	attribute on a foreign_proc conflicts with a no_inline or inline pragma
	(respectively) on the predicate it belongs to.

compiler/hlds_pred.m:
	Fix some comment rot.

compiler/jumpopt.m:
compiler/livemap.m:
compiler/proc_gen.m:
compiler/trace_gen.m:
	Conform to the changes above.

doc/reference_manual.texi:
	Document the new foreign_proc attribute.

library/array.m:
library/builtin.m:
library/char.m:
library/dir.m:
library/float.m:
library/int.m:
library/io.m:
library/lexer.m:
library/math.m:
library/private_builtin.m:
library/string.m:
library/version_array.m:
	Add does_not_affect_liveness annotations to the C foreign_procs that
	deserve them.

configure.in:
	Require the installed compiler to support does_not_affect_liveness.

tests/invalid/test_may_duplicate.{m,err_exp}:
	Add a new test case to test the error checking code in simplify.m.

tests/invalid/Mmakefile:
	Enable the new test case.
2007-01-15 02:24:04 +00:00
Zoltan Somogyi
c06e22e3ba Instead of printing each error message immediately, pass them back to
Estimated hours taken: 1
Branches: main

compiler/table_gen.m:
compiler/unused_args.m:
	Instead of printing each error message immediately, pass them back to
	mercury_compile.m to print them all at once.

compiler/mercury_compile.m:
	Do the printing.

compiler/hlds_goal.m:
compiler/inst_graph.m:
library/float.m:
library/int.m:
library/math.m:
	Rename some predicates to avoid ambiguity.

compiler/*.m:
	Conform to the changes above.
2006-12-27 03:18:04 +00:00
Zoltan Somogyi
0724668056 Add to the library a new module called tree_bitset.m, which is a version
Estimated hours taken: 32
Branches: main

Add to the library a new module called tree_bitset.m, which is a version
of sparse_bitset.m modified to allow algorithms (for union, intersection etc)
that do not require scanning the entire list of bitmaps.

Use this module as the set representation in quantification.

This reduces the time to compile training_cars_full.m from 250 seconds
to 110 seconds (a reduction of about 56%). As for compiling ordinary files,
the time taken for our usual speedtest (compiling the six largest files
of the compiler itself) is reduced from 20.2 seconds to 19.5 (a reduction
of about 3.5%).

library/tree_bitset.m:
	Add the new module.

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

library/int.m:
	Improve the formatting of some comments.

library/sparse_bitset.m:
	Fix a bug in a comment.

compiler/quantification.m:
	Use the new module in the library.

	Avoid using predicates that exist in sparse_bitset.m and in set.m
	but are available only as functions in tree_bitset.m.

	Rename a predicate to avoid ambiguity.

compiler/hlds_out.m:
	Output the number of variables in a predicate or procedure when
	printing the set of variables and their types.

tests/hard_coded/test_tree_bitset.{m,exp}:
tests/hard_coded/tree_bitset_tester.m:
	Two modules of a new test case, modelled on the test case that tests
	sparse_bitsets, for testing tree_bitsets.

tests/hard_coded/Mmakefile:
	Don't enable the new test case yet, since the .exp file is only a dummy
	so far.
2006-12-22 05:44:29 +00:00
Zoltan Somogyi
2ad9119e1f Delete two semidet functions.
Estimated hours taken: 0.1
Branches: main

library/sparse_bitset.m:
	Delete two semidet functions.

library/int.m:
	Fix some layout.
2006-12-14 05:53:59 +00:00
Julien Fischer
42ded6d070 Delete library predicates that were marked as obsolete prior to the 0.12
Estimated hours taken: 0.1
Branches: main

Delete library predicates that were marked as obsolete prior to the 0.12
release.

library/int.m:
library/integer.m:
library/rational.m:
library/rbtree.m:
	Delete some obsolete predicates.
2006-09-27 07:39:52 +00:00
Julien Fischer
e0f5ac47db Make it easier for vi to jump past the initial comments
Estimated hours taken: 0.1
Branches: main

library/*.m:
	Make it easier for vi to jump past the initial comments
	at the head of a module.
2006-04-19 05:18:00 +00:00