Commit Graph

1448 Commits

Author SHA1 Message Date
Julien Fischer
d51accb7f2 Add a stronger test of generic_refs from the store module.
tests/hard_coded/Mmakefile:
tests/hard_coded/test_generic_ref.{m,exp}:
    Add a test of updating the fields of term inside a generic_ref.
2018-08-29 04:55:45 +00:00
Julien Fischer
d947a6d2d4 Implement RTTI operations for C# foreign enumerations.
library/rtti_implementation.m
    Implement some missing RTTI operations for foreign enumerations in the C#
    grade.  (This would also handle the Java grade if that ever supports
    foreign enumerations.)

tests/hard_coded/foreign_enum_rtti.m:
     Use a C# foreign enumeration here.
2018-08-20 14:12:45 +00:00
Julien Fischer
759f1b544e Add a cast from uint32 -> uint64.
library/uint32.m:
   Add the function cast_to_uint64/1.

tests/hard_coded/Mmakefile:
tests/hard_coded/uint32_to_uint64.{m,exp}:
   Add a test of the new function.
2018-08-18 13:27:44 +00:00
Julien Fischer
d51e2a5bbb Fix the modes of array.map.
library/array.m:
    The current modes for array.map do not match what the implementation
    actually does: specifically, map does not destructively update its
    input array argument.

    Call unsafe_init/3 in a few spots where it is safe to do so.

tests/hard_coded/ho_array_ops.{m,exp}:
    Extend this test to cover array.map.
2018-08-16 16:17:13 +10:00
Julien Fischer
18c10e832d Extend the ho_array_ops test case.
tests/hard_coded/ho_array_ops.{m,exp}:
    As above.
2018-08-15 14:10:10 +10:00
Julien Fischer
c32c99b269 Minor improvement to equality and comparison for arrays.
library/array.m:
    Use unsafe lookups in the implementation of equality and
    comparison.  In these cases the lookups are safe since
    the necessary bounds checks are done by the caller.

    Avoid unnecessary module qualification.

tests/hard_coded/Mmakefile:
tests/hard_coded/array_unify_compare.{m,exp}:
    Add a systematic test for array equality and comparison.
2018-08-15 09:46:49 +10:00
Julien Fischer
a3efc705a9 Change semantics of array.map_corresponding_foldl/6.
library/array.m:
    Make array.map_corresponding_foldl/6 throw an exception if the input
    arrays differ in size.   This brings its behaviour into line with that of
    the other "corresponding" predicates.  It also avoids the unsafe behaviour
    that can currently result when the second input array has fewer elements
    than the first.

    Add some additional modes to array.map_corresponding_foldl/6.

    Replace calls to error/1 with calls to unexpected/2 throughout this
    module.

NEWS:
    Announce the above change.

tests/hard_coded/ho_array_ops.{m,exp}:
    Extend this test to cover map_corresponding_foldl/6.
2018-08-14 11:08:49 +10:00
Julien Fischer
0dc0834973 Add foldl_corresponding/5 and foldl2_corresponding/7 for arrays.
library/array.m:
    Add the above predicates.

NEWS:
    Announce the additions.

tests/hard_coded/Mmakefile:
tests/hard_coded/ho_array_ops.{m,exp}:
    Add tests of the new predicates.
2018-08-14 11:08:49 +10:00
Zoltan Somogyi
1b43d32cf9 Make a test case output more readable.
tests/hard_coded/deconstruct_arg.m:
    The (bigger) expected output file of this test was 826 lines,
    much of which was very repetitive. This made its correctness hard
    to assess. Fix this by

    - printing the term being tested just once;

    - printing the results of individual argument access tests only they
      succeed, printing only a single summary line for all the argument
      access tests that did not succeed;

    - omitting even the summary line for tests on constants, for which
      having them all fail is the natural expectation;

    - likewise, not printing anything for the full deconstruct tests
      on constants if their output is exactly one would expect from
      just the functor access test.

    Also, print the results of the limited and unlimited deconstruct tests
    using the same formatting, to make it easy to see whether they are
    the same.

    Document the reason for the existence of the .exp2 file.

tests/hard_coded/deconstruct_arg.{exp,exp2}:
    Update both expected output files.
2018-08-14 02:48:49 +10:00
Peter Wang
dcde485b51 Use spawn_native in thread_sbrk test.
The thread_sbrk test is only meaningful with OS threads so use
thread.spawn_native instead of thread.spawn now that it is available.

It was harmless to run the test with only concurrent Mercury threads
anyway, except that calling thread.yield leads to a crash in deep
profiling grades (whether or not concurrent Mercury threads *should*
work in deep profiling grades is another matter).

tests/hard_coded/thread_sbrk.m:
tests/hard_coded/thread_sbrk.exp2:
    Use thread.spawn_native instead of thread.spawn.

    Delete unnecessary thread.yield calls.
2018-08-09 18:48:35 +10:00
Peter Wang
0ada472e9e Prevent another failure of thread_barrier_test.
tests/hard_coded/thread_barrier_test.exp:
tests/hard_coded/thread_barrier_test.m:
    Prevent failure of thread_barrier_test due to nondeterministic
    output.
2018-08-07 10:20:49 +10:00
Peter Wang
9b6676a307 Avoid thread_barrier_test test failure.
tests/hard_coded/thread_barrier_test.m:
tests/hard_coded/thread_barrier_test.exp:
    The barrier.release sub-test could produce output different from the
    expected output depending on how threads are scheduled.
    Change the expected output to be less sensitive to the order that
    threads are executed.
2018-08-04 16:17:19 +10:00
Peter Wang
fd24b2e331 Don't compress failed test executables.
Disk space isn't the concern that it used to be so compressing
failed test executables is mostly just a waste of time.

tests/run_one_test:
    Don't compress failed test executables.

tests/Mmake.common:
    Delete clean_zip target.

tests/*/.gitignore:
    Delete *.gz ignore patterns.
2018-07-31 16:32:41 +10:00
Julien Fischer
1d101b5a73 Fix a typo.
tests/hard_coded/Mmakefile:
    As above.
2018-07-31 04:12:25 +00:00
Julien Fischer
6d1efe923a Fix the "failure" of tests/hard_coded/init_excp for C# and Java grades.
tests/hard_coded/Mmakefile:
    Filter the output for the above test to remove C# (Mono) and
    Java stack traces.  Because of the way initialisers are (currently)
    implemented for those backends using MERCURY_SUPPRESS_STACK_TRACE
    would not work (even if the respective runtimes supported it).

tests/hard_coded/init_excp.exp2:
    Expected output for the Java grades.

tests/hard_coded/init_excp.exp3:
    Expected output for the C# grades.
2018-07-30 17:49:47 +10:00
Julien Fischer
726c8269f8 Fix the failure of tests/hard_coded/write in the java grade.
tests/hard_coded/write.exp4:
    Conform to recent changes to the handling of character escapes.
2018-07-30 16:13:48 +10:00
Julien Fischer
796fcd3eb8 Fix the failure of tests/hard_coded/write in the csharp grade.
tests/hard_coded/write.exp3:
    Conform to recent changes to the handling of character
    escapes.
2018-07-30 16:12:02 +10:00
Zoltan Somogyi
9d4646335a Fix gcc warnings caused by lack of casts.
compiler/ml_unify_gen_construct.m:
    Add missing casts after OR-ing together the rvals of the arguments
    packed together into a word.

tests/hard_coded/local_args.{m,exp}:
    A regression test for this bug.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2018-07-30 10:06:40 +10:00
Zoltan Somogyi
ffb357724f Fix gcc warnings in some test cases.
tests/hard_coded/target_mlobjs_c.c:
    Fix a bad use of printf.

tests/hard_coded/trace_goal_4.m:
tests/hard_coded/word_aligned_pointer.m:
tests/hard_coded/word_aligned_pointer_2.m:
tests/tabling/memo_non.m:
tests/tabling/table_foreign_output.m:
tests/tabling/test_enum.m:
    Don't assume that MR_Integers are ints; print them using
    MR_INTEGER_LENGTH_MODIFIER.
2018-07-30 09:26:12 +10:00
Julien Fischer
92802b9ad7 Fix a typo in MR_escape_string_quote.
runtime/mercury_string.c:
    s/b/v/ in a spot.

tests/hard_coded/deconstruct_arg.exp:
tests/hard_coded/deconstruct_arg.exp2:
    Conform to the above change.
2018-07-29 12:42:30 +00:00
Peter Wang
45ba4d0488 Add regression test.
Add regression test for a bug introduced in
commit f6e2290031
and fixed in
commit 53e73a9e95

tests/hard_coded/Mmakefile:
tests/hard_coded/static_term_bug.m:
tests/hard_coded/static_term_bug.exp:
    Add new test.
2018-07-27 17:55:38 +10:00
Julien Fischer
2f5765d065 Fix failure of tests/hard_coded/expand.
tests/hard_coded/expand.exp*:
    Conform to recent changes to the decconstruct module.
2018-07-10 12:34:20 -04:00
Julien Fischer
4455d3601e Escape characters in strings returned by deconstruct.functor/4.
runtime/mercury_string.[ch]:
    Add a function that returns a copy of a string inside double
    quotes and with escapes for any control characters inserted.

    Add macro that tests if a character is a control character.

runtime/mercury_ml_expand_body.h:
    Use the above function to escape characters in the representation
    of string functors.

library/rtti_implementation.m:
    Do the same for the C# and Java backends.

library/term_io.m:
    Update a comment.

NEWS:
    Announce the above change to deconstruct.functor/4, as well
    the earlier change to its handling of characters.

tests/hard_coded/deconstruct_arg.m:
tests/hard_coded/deconstruct_arg.exp:
    Extend this test case to cover strings.
2018-07-11 01:42:33 +10:00
Zoltan Somogyi
624aaa01f1 Pack subword-sized arguments next to a local sectag.
compiler/du_type_layout.m:
    If a new option is set, then try to represent function symbols with
    only subword-sized arguments by packing those arguments into the same word
    as the primary tag and (if it is needed) a secondary tag.

    If there are too many such function symbols for the available number of
    bits, pick the ones that need the least number of bits, in order to
    allow us to use this representation for as many such function symbols
    as possible.

    This diff implements this packing only for types that have more than one
    argument, because implementing it for types that have only one argument
    has two extra complications. One is the need for another new cons_id
    (see below), which would make this diff bigger and harder to review.
    The other is the need to consider interactions with the direct_arg
    optimization.

    Don't invoke the code for deciding the representation of arguments
    if either (a) the function symbol has no arguments, or (b) its cons_id
    alone dictates how we will treat its argument (in such cases, there is
    always exactly one).

    Fix a bug in computing the number of bits needed to distinguish N things.

    Store the value of the "experiment" option in the params for now,
    since it has helped track down bugs in this change, and may do the same
    for my next change. It costs next to nothing.

compiler/options.m:
    Add an option that controls whether we allow du_type_layout to pack
    arguments next to local secondary tags. The default value is "no",
    since "yes" may break binary compatibility.

    Add an option that controls whether we allow du_type_layout to pack
    arguments next to remote secondary tags. This option is not yet used.

compiler/hlds_data.m:
    Add a new cons_id, shared_local_tag_with_args, to represent function
    symbols in which the arguments are packed next to a local secondary tag.
    Rename the existing shared_local_tag cons_id as shared_local_tag_no_args,
    to clarify the distinction.

    Redesign the representation of secondary tags a bit, to meet the
    requirements I discovered while implementing the new data representation.

compiler/prog_data.m:
    Document the now-expanded uses of the arg_pos_width type.

compiler/ml_unify_gen.m:
compiler/unify_gen.m:
    Implement unifications involving the new cons_id.

compiler/var_locn.m:
    Implement deconstruction unifications involving both right-to-left data
    flow and the new cons_id for the LLDS backend requires var_locn.m
    to implement a new kind of assignment to a variable: one that updates
    its old value. Add a predicate for this. (Previously, deconstructions
    with right-to-left flow could update the old value of a word in a
    memory cell, whose state var_locn.m does *not* track.)

compiler/code_loc_dep.m:
    Provide the interface between unify_gen. and var_locn.m.

compiler/code_info.m:
    Store the number of primary tag bits in the code_info, to save it looking
    up in the globals structure, since with its new code, unify_gen.m needs it
    more often now.

compiler/hlds_out_module.m:
doc/user_guide.texi:
    Implement the capability of restricting the dump of the type table
    to only the types defined in the module being compiled. Without this,
    the type table is cluttered with information about types in other
    modules, including the automatically-included builtin modules.

compiler/handle_options.m:
    Add a new value of the -D option. The new value, du, asks for the
    dumping out of the representations of only the locally defined types.

compiler/ml_gen_info.m:
    Store the number of primary tag bits as a uint8, not as int.

compiler/ml_tag_switch.m:
compiler/switch_util.m:
compiler/tag_switch.m:
    Update the code that generates switches on du types to handle
    local secondary tags that must be masked off before use.

compiler/rtti.m:
    Update the compiler's representation of RTTI information to account for
    the new data representation.

compiler/type_ctor_info.m:
    Construct the updated RTTI representation.

compiler/bytecode_gen.m:
compiler/export.m:
compiler/ml_switch_gen.m:
compiler/ml_type_gen.m:
compiler/modecheck_goal.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
    Conform for the changes above.

runtime/mercury_type_info.h:
    Extend the representation of du functors in the RTTI to account for
    the new data representation scheme. The extensions add only to the
    *ends* of structures, or to lists of enum values, with the extensions
    only being used if the representation is actually used, which should
    allow the updated runtime to also work with .c files that were compiled
    with a compiler that does *not* have this diff. For the same reason,
    make the old enum value MR_SECTAG_LOCAL a synonym for the new
    MR_SECTAG_LOCAL_REST_OF_WORD, which expresses a distinction that
    did not previously exist.

    Delete a reference to a file that no longer exists.

runtime/mercury_dotnet.cs.in:
library/rtti_implementation.m:
    Update the C# and Mercury mirrors of the types updated in
    mercury_type_info.h.

runtime/mercury_deconstruct.c:
runtime/mercury_deconstruct_macros.h:
runtime/mercury_ml_expand_body.h:
    Implement the deconstruction of terms using the new data representation.

runtime/mercury_deep_copy_body.h:
    Implement the copying of terms using the new data representation.

runtime/mercury_table_type_body.h:
    Implement the tabling of terms using the new data representation.

runtime/mercury_term_size.c:
    Implement computing the size of terms using the new data representation.

runtime/mercury_unify_compare_body.h:
    Implement RTTI-based unifications of terms using the new data
    representation. (Or at least make a first attempt at this implementation.
    We never use RTTI-based unification, so this code has not been tested,
    but it is not clear that it *needs* to be tested.)

library/construct.m:
    Implement the construction of terms using the new data representation.

library/private_builtin.m:
    List MR_SECTAG_LOCAL_REST_OF_WORD as a synonym of MR_SECTAG_LOCAL for Java,
    since rtti_to_mlds.m will now emit the new version.

    Note that the new data representation is not applicable to Java (or C#),
    so it should never see the other kind of sectag (MR_SECTAG_LOCAL_BITS).

tests/hard_coded/sectag_bits.{m,exp}:
tests/hard_coded/sectag_bits_test_data:
    A new test case to test the reading in and writing out (and therefore
    the construction and deconstruction) of terms containing arguments
    packed with a local sectag.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2018-07-08 17:54:11 +02:00
Zoltan Somogyi
3e6924c499 Fix too-long lines. 2018-07-07 01:08:11 +02:00
Julien Fischer
a00e86be35 Escape all control characters in io.write, deconstruct.functor etc.
The above predicates currently escape all of the C0 control characters (+
Delete).  This change modifies them to escape all of the characters in the
Unicode category `Other,control' using backslash escapes when they exist and
octal escapes otherwise.

library/term_io.m:
    Do not treat C1 control characters as Mercury source characters.

    Re-order the list of Mercury punctuation characters by codepoint
    order; it is difficult to check for completion otherwise.

    Put a list of special characters escapes in order.

runtime/mercury_ml_expand_body.h:
library/rtti_implementation.m:
   Update the implementations of functor/4 to escape all control
   characters when returning the functor of a character.

library/deconstruct.m:
    Specify that functor/4 should escape all control characters in
    the value returned for characters and strings.  (XXX TODO: it
    currently doesn't implement the new behaviour for strings; I'll
    add that separately.)

library/io.m:
library/stream.string_writer.m:
    Similar to the above but for io.write etc.

tests/hard_coded/write.{m,exp}:
tests/hard_coded/deconstruct_arg.{m,exp,exp2}:
   Extend these tests to cover the block of C1 control characters
   and the boundaries around it.
2018-06-19 17:08:20 +10:00
Julien Fischer
0f4458b17d Update a test case.
tests/hard_coded/write.m
   Use io.write_line/3 throughout this test, rather than following every call
   to io.write/3 with call to newline/2.
2018-06-15 03:58:27 +10:00
Julien Fischer
422c598b3c Update a test case.
tests/hard_coded/deconstruct_arg.m:
   Use io.write_line/3 throughout this test, rather than following every call
   to io.write/3 with call to newline/2.

   Extend the test slightly.

test/s/hard_coded/deconstruct_arg.exp*:
   Conform to the above changes.
2018-06-14 22:03:17 +10:00
Julien Fischer
58f5168b5f Fixes for deconstruct.functor and io.write.
Fix two problems with deconstruct.functor/4 and characters.

1. Control characters were not being octal escaped as they are by
   io.write etc.

2. The higher bytes of multibyte characters were being discarded.

Note that as part of the above fix deconstruct.functor/4 will now abort if
called with a surrogate code point.

Fix problem with io.write (and related predicates) where characters were
being octal escaped even though a more specific escape character existed
(e.g. \r or \a).

runtime/mercury_ml_expand_body.h:
    Make the above fixes.

library/rtti_implementation.m:
    Conform to the above.

    Fix the escaping of single quote characters.

library/term_io.m:
    Add missing character escapes to the predicate
    mercury_escape_special_char/2.  The omission of these
    was the cause of the above problem with character escapes
    and io.write.

tests/hard_coded/deconstruct_arg.{m,exp,exp2}:
    Modify this test to use io.write rather than io.print since
    the former will insert character escapes.

    Do more thorough testing of characters.

tests/hard_coded/write.{m,exp}:
    Add more tests for escape characters.

    Add tests for infinite float values.
2018-06-14 21:25:44 +10:00
Zoltan Somogyi
caa5c02535 Update a test's expected output after recent changes.
tests/hard_coded/deconstruct_arg.exp2:
    Update this file after recent changes.

tests/hard_coded/deconstruct_arg.m:
    Simplify the code of the test itself.
2018-06-12 13:31:07 +02:00
Julien Fischer
ca13b54a40 Fix an XXX: escape characters returned by deconstruct.functor/4.
runtime/mercury_ml_expand_body.h:
    Fix an XXX: escape characters in functors.

library/rtti_implementation.m:
    Do the same for the C# and Java backends.

tests/hard_coded/deconstruct_arg.{m,exp}:
    Extend this test to cover the above.

tests/declarative_debugger/io_stream_test.exp2:
    Update this expected output: one of the I/O actions contains
    a newline character and previously the lack of a character escape
    meant that it was split across two lines.
2018-06-09 05:48:46 +10:00
Julien Fischer
a6c8350491 Document deconstruct_functor with infinity.
library/deconstruct.m:
    Document what deconstruct_functor/4 returns with infinite floating point
    values.  Also, the functor returned will only be a floating point base 10
    number for finite float values.

tests/hard_coded/deconstruct_arg.{m,exp}:
    Extend this test to cover infinity and -infinity.
2018-06-08 21:59:15 +10:00
Zoltan Somogyi
d3fd088aea Pack args using unsigned arithmetic.
compiler/ml_unify_gen.m:
    Do ORs and shifts on argument values being packed using MR_Unsigned.
    Cast the results to MR_Box explicitly.

compiler/ml_util.m:
    Add utility functions that return (static terms containing) the MLDS
    representations of the builtin integer types.

compiler/mlds_to_c_data.m:
    Parenthesize values being cast, to ensure that the cast applies
    to the *whole* of the value, not just an initial part. (For example,
    "(uint32_t) x >> 32" casts just x, not the result of the shift.)

tests/hard_coded/pack_int32.{m,exp}:
    A regression test for the bug report that this diff addresses.

tests/hard_coded/Mmakefile:
    Add the new test case.
2018-05-16 15:50:25 +02:00
Zoltan Somogyi
24b98fdafe Pack sub-word-sized ints and dummies in terms.
Previously, the only situation in which we could pack two or more arguments
of a term into a single word was when all those arguments are enums. This diff
changes that, so that the arguments can also be sub-word-sized integers
(signed or unsigned), or values of dummy types (which occupy zero bits).

This diff also records, for each argument of a function symbol, not just
whether, and if yes, how it is packed into a word, but also at *what offset*
that word is in the term's heap cell. It is more economical to compute this
once, when the representation of the type is being decided, than to compute
it over and over again when terms with that function symbol are being
constructed or deconstructed. However, for a transition period, we compute
these offsets at *both* times, to check the consistency of the new algorithm
for computing offsets that is run at "decide representation time" with
the old algorithms run at "generate code for a unification time".

compiler/du_type_layout.m:
    Make the changes described above: pack sub-word-sized integers and
    dummy values into argument words, if possible, and if the relevant
    new option allows it. These options are temporary. If we find no problems
    with the new packing algorithm in a few weeks, we should be able to
    delete them.

    Allow 64 bit ints and uints to be stored in unboxed in two words
    on 32 bit platforms, if the relevant new option allows it. Support
    for this is not yet complete, but it makes sense to implement the
    RTTI changes for both this change and one described in the above
    paragraph together.

    For each packed argument, record not just its width, its shift and
    the mask, but also the number of bits the argument takes. Previously,
    we computed this on demand from the mask, but there is no real need
    for that when simply storing this info is so cheap.

    For all arguments, packed or not, record its offset, relative to both
    the start of the arguments, and the start of the memory cell. (The two
    are different if the arguments are preceded by either a remote secondary
    tag, the typeinfos and/or typeclass_infos describing some existentially
    typed arguments, or both.) The reason for this is given at the top.

    Centralize the decision of the parameters of packing in one predicate.

    If the option --inform-suboptimal-packing is given, print an informational
    message whenever the code deciding type representations finds that
    reordering the arguments of a function symbol would allow it to pack
    the arguments of that function symbol into less space.

compiler/options.m:
    Add the option --allow-packing-ints which controls whether
    du_type_layout.m will attempt to pack {int,uint}{8,16,32} arguments
    alongside enum arguments.

    Add the option --allow-packing-dummies which controls whether
    du_type_layout.m will optimize away (in other words, represent in 0 bits)
    arguments of dummy types.

    Add the option --allow-double-word-ints which controls whether
    du_type_layout.m will store arguments of the types int64 and uint64
    unboxed in two words on 32 bit platforms, the way it currently stores
    double precision floats.

    All three those options are off by default, which preserves binary
    compatibility with existing code. However, the first two are ready
    to be switched on (the third is not).

    All three options are intended to be present in the compiler
    only until these changes are tested. Once we deem them sufficiently
    tested, I will modify the compiler to always do the packing they control,
    at which point we can delete these options. This is why they are not
    documented.

    Add the option --inform-suboptimal-packing, whose meaning is described
    above.

doc/user_guide.texi:
    Document --inform-suboptimal-packing.

compiler/prog_data.m:
    For each argument of a function symbol in a type definition, use
    a new type called arg_pos_width to record the extra information
    mentioned above in (offsets for all arguments, and number of bits
    for packed arguments).

    For each function symbol that has some existential type constraints,
    record the extra information mentioned for parse_type_defn.m below.

compiler/hlds_data.m:
    Include the position, as well as the width, in the representation
    of the arguments of function symbols.

    Previously, we used the integer 0 as a tag for dummies. Add a tag to
    represent dummy values, since this gives more information to any code
    that sees that tag.

compiler/ml_unify_gen.m:
compiler/unify_gen.m:
    Handle the packing of dummy values, and of sub-word-sized ints and uints.

    Compare the cell offset of each argument computed using existing
    algorithms here with the cell offset recorded in the argument's
    representation, and abort if they are different.

    In some cases, restructure code a bit to make it possible.
    For example, for tuples and closures, this means that instead of
    simply recording that each tuple argument or closure element
    is a full word, we must record its correct offset as well.

    Handle the new dummy_tag.

    Add prelim (not yet finished) support for double-word int64s/uint64s
    on 32 bit platforms.

    When packing the values of two or more variables (or constants) into a
    single word in a memory cell, optimize away operations that are no-ops,
    such as shifting anything by zero bits, shifting the constant zero
    by any number of bits, and ORing anything with zero. This makes the
    generated code easier to read. It is probably also faster for us
    to do it here than to write out a bigger expression, have the C compiler
    read in the bigger expression, and then later make the same optimization.

    In ml_unify_gen.m, avoid the unnecessary use of a list of the argument
    variables' types separate from the list of the argument variables
    themselves; just look up the type of each argument variable when it is
    processed.

compiler/add_special_pred.m:
    When creating special (unify and compare) predicates for tuples,
    include the offsets in the representation of their arguments.

    Delete an unused predicate.

compiler/llds.m:
    Add a new way to create an rval: a cast. We use it to implement
    the extraction of signed sub-word-sized integers from packed argument
    words in terms. Masking the right N bits out of the packed word
    leaves the other 32-N or 64-N bits as zeroes; a cast to int8_t,
    int16_t or int32_t will copy the sign bit to these bits.
    Likewise, when we pack signed int{8,16,32} values into words,
    we cast them to their unsigned versions to throw away any sign-extension
    bits in their original word-sized representations.

    No similar change is needed for the MLDS, since that already had
    a mechanism for casts.

compiler/mlds.m:
    Note a potential simplification in the MLDS.

compiler/builtin_lib_types.m:
    Add functions to return the Mercury representation of the int64
    and uint64 types.

compiler/foreign.m:
    Export a specialized version of an existing predicate, to allow
    ml_unify_gen.m to avoid the costs of the more general version.

compiler/hlds_out_module.m:
    Always print the representations of all arguments, since the
    inclusion of position information in those representation means that
    the representations of even all-full-word-argument terms are of potential
    interest when debugging term representations.

compiler/lco.m:
    Do not try to apply LCO to arguments of dummy types. (We could optimize
    them differently, by filling them in before they are "computed", but
    that is a separate optimization, which is of *very* low priority.)

compiler/liveness.m:
    Do not include variables of dummy types in resume points.

    The reason for this is that the code that establishes a resume point
    returns, for each such variable, a list of *lvals* where that variable
    can be found. The new code in unify_gen.m will optimize away assignments
    to values of dummy types, so there is *no* lval where they can be found.
    We could allocate one, but doing so would be a pessimization. Instead,
    we simply don't save and restore such values. When their value (which is
    always 0) is needed, we can create them out of thin air.

compiler/ml_global_data.m:
    Include the target language in the ml_global_data structure, to prevent
    some of its users having to look it up in the module_info.

    Add notes about the specializing the implementation of arrays of
    int64s/uint64s on 32 bit platforms.

compiler/check_typeclass.m:
compiler/ml_type_gen.m:
    Add sanity checks of the new precomputed fields of exist_constraints.

    Conform to the changes above.

compiler/mlds_to_c.m:
    Add prelim (not yet finished) support for double-word int64s/uint64s
    on 32 bit platforms.

    Add notes about possible optimizations.

compiler/parse_type_defn.m:
    When a function symbol in a type definition contains existential
    arguments, precompute and store the set of constrained and unconstrained
    type variables. The code in du_type_layout.m needs this information
    to compute the number of slots occupied by typeinfos and typeclass_infos
    in memory cells for this function symbol, and several other places
    in the compiler do too. It is easier and faster to compute this
    information just once, and this is the earliest time what that can be done.

compiler/type_ctor_info.m:
    Use the prerecorded information about existential types to simplify
    the code here

compiler/polymorphism.m:
    Add an XXX about possibly using the extra info we now record in
    exist_constraints to simplify the job of polymorphism.m.

compiler/pragma_c_gen.m:
compiler/var_locn.m:
    Create the values of dummy variables from scratch, if needed.

compiler/rtti.m:
    Replace a bool with a bespoke type.

compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
    When generating RTTI information for the LLDS and MLDS backends
    respectively, record new kinds of arguments as needing special
    treatment. These are int64s and uint64s stored unboxed in two words
    on 32 bit platforms, {int,uint}{8,16,32} values packed into words,
    and dummy arguments. Each of these has a special code: its own negative
    negative value in the num_bits field of the argument.

    Generate slightly better formatted output.

compiler/type_util.m:
    Delete a predicate that isn't needed anymore.

compiler/opt_util.m:
    Delete a function that hasn't been needed for a while.

    Conform to the changes above.

compiler/arg_pack.m:
compiler/bytecode_gen.m:
compiler/call_gen.m:
compiler/code_util.m:
compiler/ctgc.selector.m:
compiler/dupelim.m:
compiler/dupproc.m:
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/erl_code_gen.m:
compiler/erl_rtti.m:
compiler/export.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_out_data.m:
compiler/middle_rec.m:
compiler/ml_closure_gen.m:
compiler/ml_switch_gen.m:
compiler/ml_top_gen.m:
compiler/module_qual.qualify_items.m:
compiler/opt_debug.m:
compiler/parse_tree_out.m:
compiler/peephole.m:
compiler/recompilation.usage.m:
compiler/resolve_unify_functor.m:
compiler/stack_layout.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/switch_util.m:
compiler/typecheck.m:
compiler/unify_proc.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Conform to the changes above.

compiler/llds_out_util.m:
    Add a comment.

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

runtime/mercury_type_info.h:
    Allocate special values of the MR_arg_bits field of the MR_DuArgLocn type
    to designate arguments as two word int64/uint64s, as sub-word-sized
    arguments of types {int,uint}{8,16,32}, or as arguments of dummy types.
    (We already had a special value for two word float arguments.)

    Document the list of places that know about this code, so that they
    can be updated if and when it changes.

library/construct.m:
    Handle the construction of terms with two-word int64/uint64 arguments,
    with packed {int,uint}{8,16,32} arguments, and with dummy arguments.

    Factor out the code common to the sectag-present and sectag-absent cases,
    to make it possible to do the above in just *one* place.

library/store.m:
    Add an XXX to a place that I don't think handles two word arguments
    correctly. (I think this is an old bug.)

runtime/mercury_deconstruct.c:
    Handle the deconstruction of terms with two-word int64/uint64 arguments,
    with packed {int,uint}{8,16,32} arguments, and with dummy arguments.

runtime/mercury_deep_copy_body.h:
    Handle the copying of terms with two-word int64/uint64 arguments,
    with packed {int,uint}{8,16,32} arguments, and with dummy arguments.

    Give a macro a more descriptive name.

runtime/mercury_type_info.c:
    Handle taking the size of terms with two-word int64/uint64 arguments,
    with packed {int,uint}{8,16,32} arguments, and with dummy arguments.

runtime/mercury.h:
    Put related definitions next to each other.

runtime/mercury_deconstruct.h:
runtime/mercury_ml_expand_body.h:
    Fix indentation.

tests/hard_coded/construct_test.{m,exp}:
    Add to this test case a test of the construction, via the library's
    construct.m module, of terms containing packed sub-word-sized integers,
    and packed dummies.

tests/hard_coded/deconstruct_arg.{m,exp}:
    Convert the source code of this test case to state variable notation,
    and update the line number references (in the names of predicates created
    from lambda expressions) accordingly.

tests/hard_coded/uint64_ground_term.{m,exp}:
    A new test case to check that uint64 values too large to be int64 values
    can be stored in static structures.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2018-05-05 13:22:19 +02:00
Zoltan Somogyi
aa73ebf306 Delete a redundant predicate argument. 2018-04-22 08:58:09 +10:00
Zoltan Somogyi
e4092f2380 Make the output of this test easier to read. 2018-04-22 08:39:39 +10:00
Zoltan Somogyi
642cecba55 Put the parts of this test case into a logical order. 2018-04-22 06:48:44 +10:00
Zoltan Somogyi
988c22da40 Update the programming style of a test. 2018-04-22 06:36:11 +10:00
Julien Fischer
bb55d65023 Fix bug #455.
compiler/simplify_proc.m:
    Update the list of predicates that can be introduced by the simplification
    pass to include those from the uint, int{8,16,32,64} and uint{8,16,32,64}
    modules.  (The list not being up-to-date was the cause of bug #455.)

tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options.m:
tests/hard_coded/bug455_mod_a.m:
tests/hard_coded/bug455_mod_b.m:
tests/hard_coded/bug455_mod_a.exp:
    Add a regression test for the above issue.
2018-04-21 07:15:18 -04:00
Julien Fischer
678922eba0 Add more operations on 8-bit integers.
library/int8.m:
library/uint8.m:
     Add num_zeros/1, num_ones/1, num_leading_zeros/1, num_trailing_zeros/1 and
     reverse_bits/1.

library/int16.m:
     Implement num_trailing_zeros/1 by calling the unsigned version.

tests/hard_coded/Mmakefile:
tests/hard_coded/bit_twiddle_int8.{m,exp}:
tests/hard_coded/bit_twiddle_uint8.{m,exp}:
     Add tests of the new operations.
2018-04-02 12:17:30 +10:00
Julien Fischer
2fb7127729 Add more operations on 64-bit integers.
library/int64.m:
library/uint64.m:
    Add num_zeros/1, num_ones/1, num_leading_zeros/1, num_trailing_zeros/1
    and reverse_bits/1.

configure.ac:
runtime/mercury_conf.h.in:
    Add a new configuration macro that is defined if C's long type
    is 64-bit.

tests/hard_coded/Mmakefile:
tests/hard_coded/bit_twiddle_uint64.{m,exp}:
tests/hard_coded/bit_twiddle_int64.{m,exp}:
    Add tests of the above.
2018-04-01 15:23:24 +10:00
Zoltan Somogyi
43a9169cfc Fix partially instantiated structures with floats.
compiler/llds.m:
    Change the cell_arg type to allow the representation of both
    two-word skipped arguments (used when a float argument in a structure
    is not instantiated), and two-word arguments whose address is taken.

compiler/unify_gen.m:
    Use the two-word variants of both take_addr and skip cell args
    when called for.

compiler/closure_gen.m:
compiler/code_util.m:
compiler/var_locn.m:
    Conform to the change in llds.m.

tests/hard_coded/Mmakefile:
    Enable the test case for this problem, since we pass it now
    in 32 bit mode.
2018-04-01 12:45:27 +10:00
Julien Fischer
ee76350044 Add more operations on 16-bit integers.
library/int16.m:
library/uint16.m:
    Add num_zeros/1, num_ones/1, num_leading_zeros/1, num_trailing_zeros/1
    and reverse_bits/1.

tests/hard_coded/Mmakefile:
tests/hard_coded/bit_twiddle_uint16.{m,exp}:
tests/hard_coded/bit_twiddle_int16.{m,exp}:
    Add tests of the above.
2018-03-31 22:29:25 +11:00
Zoltan Somogyi
a9f06a4c81 Add a test case we don't pass yet. 2018-03-31 14:42:47 +11:00
Julien Fischer
babe9f2fbf Add more operations on signed 32-bit integers.
library/int32.m:
    Add num_zeros/1, num_ones/1, num_leading_zeros/1, num_trailing_zeros/1
    and reverse_bits/1.

library/uint32.m:
    Fix spelling.

tests/hard_coded/Mmakefile:
tests/hard_coded/bit_twiddle_int32.{m,exp}:
    Add tests of the above operations.
2018-03-31 00:19:58 +11:00
Julien Fischer
58341fd955 Add more operations 32-bit unsigned integers.
library/uint32.m:
    Add num_zeros/1, num_ones/1, num_leading_zeros/1, num_trailing_zeros/1
    and reverse_bits/1.

tests/hard_coded/Mmakefile:
tests/hard_coded/bit_twiddle_uint32.{m,exp}:
     Add tests of the above operations.
2018-03-14 05:11:32 -04:00
Peter Wang
2bcdf28084 Avoid C compiler miscompiling write_float_special test case.
tests/hard_coded/write_float_special.m:
    Make it harder for a C compiler to incorrectly "optimise"
    Inf * 0.0 to 0.0 instead of NaN.
    Seen with gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9)
    i686 at -O1 and above.
2018-03-09 15:00:45 +11:00
Peter Wang
ac3891136f Fix abort in float_regs pass (bug #409).
The float_regs pass did not consider this possibility: a term being
deconstructed can have a ground inst with no higher-order inst
information, but higher-order inst information is still available for
the sub-unifications of the term's arguments. This is possible with the
introduction of the "combined higher-order types and insts" feature.
Losing the higher-order inst information led to an exception:

    Unexpected: no higher order inst

compiler/float_regs.m:
    Handle the case above in unify_mode_set_rhs_final_inst.

    Minor improvements in comments.

tests/hard_coded/Mmakefile:
tests/hard_coded/functor_ho_inst_float_reg.exp:
tests/hard_coded/functor_ho_inst_float_reg.m:
    Add test case.
2018-03-09 14:19:00 +11:00
Zoltan Somogyi
d03ee8215c Fix two bugs in last call modulo constructor.
compiler/lco.m:
    Fix the first bug, which was a compiler abort when lco tried to take
    the address of a sub-word-sized argument. Don't allow this.

    Don't allow the address to be taken of double-word arguments either,
    until I can test whether this works.

    Make a switch complete.

compiler/unify_gen.m:
    Fix the second bug, which caused a compiler abort if we tried to take
    the address of more than one field of a memory cell.

    Factor out some common code.

tests/hard_coded/lco_pack_args_2.{m,exp}:
    New test case for the first bug.

tests/hard_coded/lco_pack_args_3.{m,exp}:
    New test case for the second bug.

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
    Enable the new test cases.
2018-03-08 21:20:48 +11:00
Zoltan Somogyi
1373b34a04 Do expansion and packing in the same pass.
compiler/ml_unify_gen.m:
    Expand double-word args and pack sub-word arguments in the same pass,
    initially for dynamically constructed cells only.

    Doing both in the same pass is a prerequisite for future improvements
    in argument packing schemes.

tests/hard_coded/packed_arg_partial_inst.{m,exp}:
    A new test case to test the packing of arguments when some of them
    have inst "free".

tests/hard_coded/Mmakefile:
    Enable the new test case.
2018-03-05 16:48:05 +11:00