Commit Graph

1448 Commits

Author SHA1 Message Date
Mark Brown
97ad133625 Disable tests of random module in C# and Erlang grades. 2019-08-28 00:52:17 +10:00
Mark Brown
5ef1b0e62c s/gen_uint/generate_uint/g, per review comments 2019-08-28 00:52:17 +10: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
4b147be3f2 Add test cases for Github issue 72.
Disable the test_generic_ref test case.
2019-08-27 11:26:07 +10:00
Zoltan Somogyi
a6b652c7c1 Avoid camelCase. 2019-08-27 11:26:07 +10:00
Zoltan Somogyi
c3cce83f0a Fix grammar in comment. 2019-08-20 18:48:46 +10:00
Julien Fischer
e876db7873 Adjust bounds checking behaviour of array.fetch_items/4.
Change array.fetch_items/4 to return an empty list for an empty range in the
case where the endpoints of that range are not within the array bounds.

library/array.m:
   As above.

deep_profiler/autopar_types.m:
   Undo Zoltan's recent workaround for the above behaviour.

tests/hard_coded/array_fetch_items.{m,ex}:
   Add tests for this behaviour.
2019-08-16 12:40:36 +10:00
Zoltan Somogyi
42c974c240 Improve programming style. 2019-08-07 21:16:53 +02:00
Zoltan Somogyi
10e7ababb0 Don't generate irrelevant warnings. 2019-08-07 21:16:16 +02:00
Zoltan Somogyi
4b2a4a88b5 Fix handling "int used, imp imported" modules when making interface files.
This fixes the second incarnation of Mantis bug #401. (The first incarnation
was the handling of such modules when generating target code.)

compiler/grab_modules.m:
    Compute the set of modules that have a use_module declaration in the
    interface section and an import_module declaration in the implementation
    section, and set the status of the items imported from that module
    accordingly.

compiler/module_qual.id_set.m:
    If module A defines an entity (such as a type) that module B refers to
    without the required qualification (which can happen if B has a use_module,
    not import_module for A), then do NOT report A as unused in B; it IS used,
    just not properly.

tests/hard_coded/int_impl_imports.exp:
tests/hard_coded/int_impl_imports.m:
tests/hard_coded/int_impl_imports_2.m:
    A new test case to see whether we can compile a module that has
    "int used, imp imported" references to another module, and has
    unqualified references to an imported entity in the implementation.

tests/invalid/int_impl_imports.err_exp:
tests/invalid/int_impl_imports.m:
tests/invalid/int_impl_imports_2.m:
    A new test case to see whether we can generate the right error message
    for a module that has "int used, imp imported" references to another
    module, and has an unqualified references to an imported entity
    in the interface.

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

tests/valid_seq/int_impl_imports.m:
tests/valid_seq/int_impl_imports_2.m:
    Add vim mode lines.
2019-08-02 10:36:59 +02:00
Adrian Wong
081aba18cd Add tests for string.hash{4,5,6}.
tests/hard_coded/string_hash.m:
    As above.
2019-07-29 11:35:53 +10:00
Zoltan Somogyi
bc19b1ad9b Update programming style of a test case. 2019-07-27 09:49:47 +02:00
Zoltan Somogyi
d634e23105 Standardize %---% line lengths in the tests. 2019-07-26 01:29:53 +02:00
Zoltan Somogyi
d704a883f8 Misc style cleanups. 2019-07-04 23:02:10 +02:00
Zoltan Somogyi
f79b951baa Compute change hunks from diff sequences.
library/edit_seq.m:
    Extend this module with code to compute change hunk sequences
    from diff sequences. Each change hunk contains one or more
    insertions and/or deletions surrounded by a few lines of context.

compiler/style_checks.m:
    Print any differences between declaration and definition order
    using change hunks. This omits the boring parts of the diff.

tests/hard_coded/change_hunk_test.{m,exp}:
    A new test case for the new functionality in edit_seq.m.

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

tests/hard_coded/edit_seq_test.m:
    Fix the copyright year. (The file was written in 2018, but committed
    in 2019.)

tests/warnings/inconsistent_pred_order.exp:
    Expect the updated output of style_checks.m.
2019-06-28 15:59:40 +02:00
Zoltan Somogyi
eb623b17af Fix programming style ...
... and add an XXX.
2019-06-24 16:38:42 +02:00
Peter Wang
544f3bf095 Use musl getopt implementation.
LICENSE:
    Mention files derived from musl library.

runtime/process_getopt:
    Process files from ../getopt/*.[ch] to produce
    mercury_getopt.h, mercury_getopt.c, mercury_getopt_long.c.

runtime/mercury_getopt.h:
runtime/mercury_getopt.c:
runtime/mercury_getopt_long.c:
    Add files generated by process_getopt.

runtime/Mmakefile:
    Update list of source files.

util/Mmakefile:
    Use musl getopt if the system C library does not have getopt().

tests/debugger/browser_test.exp:
tests/debugger/browser_test.exp2:
tests/debugger/browser_test.exp3:
tests/hard_coded/runtime_opt.exp:
    Update expected error messages to match new getopt() output.

changed exp output
2019-06-10 13:30:49 +10:00
Zoltan Somogyi
65d173ba26 Delete wrongly added file. 2019-06-06 15:28:56 +02:00
Peter Wang
6a2492f570 Add tests/hard_coded/map_select_test.exp 2019-06-06 23:24:25 +10:00
Zoltan Somogyi
1afe6d2594 Add map.select_unselect and map.select_unselect_sorted_list.
library/map.m:
    As above.

NEWS:
    Announce the new predicates.

tests/hard_coded/map_select_test.{m,err_exp}:
    A test case for the new code.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2019-06-05 17:25:49 +02:00
Peter Wang
93802cf7fd Add expected outputs for big endian.
tests/hard_coded/read_binary_int16.exp2:
tests/hard_coded/read_binary_int32.exp2:
tests/hard_coded/read_binary_int64.exp2:
tests/hard_coded/read_binary_uint16.exp2:
tests/hard_coded/read_binary_uint32.exp2:
tests/hard_coded/read_binary_uint64.exp2:
    Add expected outputs on big endian architectures.

tests/hard_coded/read_binary_int16.m:
tests/hard_coded/read_binary_int32.m:
tests/hard_coded/read_binary_int64.m:
tests/hard_coded/read_binary_uint16.m:
tests/hard_coded/read_binary_uint32.m:
tests/hard_coded/read_binary_uint64.m:
    Document expected outputs.
2019-06-05 11:45:41 +10:00
Zoltan Somogyi
e08b8505e9 Import the parents of *all* imported modules. 2019-03-29 12:56:35 +11:00
Julien Fischer
3b7289d04b Improve deconstruction (and printing) of foreign types in C# and Java grades.
Currently, we return a placeholder string ("foreignxx") if we attempt to look
up the functor of a foreign type in the C# or Java grades.  For C, we return a
string of the form:

   <<foreign(Name, Rep)>>

where Name is the type's Mercury name and Rep is its "value" as results from
casting it to (void *) and then using sprintf's %p conversion specifier.  Do
something similar for both the C# and Java grades, except that for Rep we
return the output of the calling the toString() (ToString()) method.  If the
object in question is a null reference then we return "null" for Rep.

Document how the predicates in the deconstruct module handle foreign types.

library/rtti_implementation.m:
   Return more information about foreign type functors.

library/deconstruct.m:
   Make the above changes to the documentation.

tests/hard_coded/csharp_print_foreign.{m,exp}:
tests/hard_coded/java_print_foreign.{m,exp}:
   Tests of the new functionality in the C# and Java grades.

tests/hard_coded/Mmakefile:
    Add the new tests.

    Add a new category of test programs that are only run in the C# grades.
2019-03-13 05:57:46 +00:00
Zoltan Somogyi
35a3fd1fc4 Fix indentation. 2019-02-15 11:07:23 +11:00
Zoltan Somogyi
ce587b4689 Fix white space. 2019-02-07 05:04:30 +11:00
Julien Fischer
ae90cecc5c Reading multibyte integers from binary file streams.
Add predicates for reading multibyte integers from binary file streams.  As
with the corresponding predicates for writing multibyte integers to binary file
streams, we provide versions for big-endian, little-endian and native byte
orders.

library/io.m:
    Add a new type that represents possibly incomplete results when reading
    from binary file streams.

    Add the new predicates.

tests/hard_coded/Mmakefile:
tests/hard_coded/read_binary_{int,uint}{16,32,64}.{m,exp}:
    Add tests of the new predicates.
2019-01-18 08:38:52 +00: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
Julien Fischer
3a7254bca2 Improve the documentation for array.fetch_items.
Change the behaviour of the above predicate in the following ways:
- throw an index_out_of_bounds/0 exception instead of a software_error/0
  exception if either index is out of bounds.
- perform the out of bounds check before checking if the third argument is
  less than the second.

Add an more comprehensive test of fetch_items/4.

library/array.m:
    Make it clear that the range of indexes passed to fetch_items is
    inclusive.

    Throw an index_out_of_bounds/0 exception instead of a software_error/1
    exception if either of the indexes is out of bounds.

    Perform the array bounds check first, before checking if the third
    argument is less than the second.

    Document what happens if the upper index is less than the lower one.

    Fix a typo in the documentation of fill_range/4.

    Update the definition of to_list/2 to conform with the above change
    to the array bounds checks.

NEWS:
    Announce the above change to the semantics of fetch_items/0.

tests/hard_coded/Mmakefile:
tests/hard_coded/array_fetch_items.{m,exp}:
    Add a more comprehensive
2018-12-24 06:15:23 +00:00
Julien Fischer
d520113cdb Conversion from array/1 to array2d/1.
Add a function that uses an array/1 value to construct an array2d/1 value
without allocating new memory for the element storage or traversing the
elements.

library/array2d.m:
    Add a function that creates an array2d/1 from an array/1 value

    Fix minor documentation issues:
    - re-order the declarations so that of from_lists/1 is directly below
      that of array2d/1.

    - s/a/an/ in a few spots.

    - add missing apostrophes.

NEWS:
    Announce the new function.

tests/hard_coded/Mmakefile:
tests/hard_coded/array2d_from_array.{m,exp}:
    Add a test case.
2018-11-30 04:57:29 +00:00
Julien Fischer
8d89c9ff37 Add array.swap/4 and array.unsafe_swap/4.
Report out-of-bounds errors more precisely for array.fill_range/5.

library/array.m:
    As above.

NEWS:
    Announce the addition.

tests/hard_coded/Mmakefile:
tests/hard_coded/array_swap.{m,exp}:
    Add a test for array.swap/4.

tests/hard_coded/array_fill.exp:
    Conform to the second change above.
2018-11-12 06:40:46 +00:00
Julien Fischer
b049a5c3db Fix a problem with array.resize.
array.resize/4 has inconsistent behaviour across backends if its first argument
is negative; make it throw an exception if the first argument is negative.

library/array.m:
    As above.

NEWS:
    Announce the change.

tests/hard_coded/Mmakefile:
tests/hard_coded/array_resize.{m,exp}:
    Add a more extensive test case for array.resize.
2018-11-12 03:52:32 +00:00
Julien Fischer
71a78fa98c Fix problems with array.shrink/3.
The behaviour of array.shrink/3 was not defined if its first argument was
negative.  If this occurred, the C backends would return an empty array, while
the non-C backends would abort.  This diff changes the behaviour of shrink/3 so
that it throws an exception if its first argument is negative.

The implementation of shrink/3 for the Java backend did not handle the case
where the array's element type was represented by the one the following Java
primitive types: byte, short, long and float.  Handle those cases.

library/array.m:
   Make the above fixes.

   Fix a typo in my previous commit.

NEWS:
   Note the change in behaviour if the first argument of shrink/3 is
   negative.

tests/hard_coded/Mmakefile:
tests/hard_coded/array_shrink.{m,exp}:
   Add a test case.
2018-11-11 04:24:55 +00:00
Julien Fischer
2b47521daa Fix an abort in the Java implementation of array.copy/2.
library/array.m:
     Handle all Java primitive types in the implementation of
     array.copy/2.

tests/hard_coded/Mmakefile:
tests/hard_coded/array_copy.{m,exp}:
     Add a test case.
2018-11-09 11:55:45 +11:00
Julien Fischer
ee5f7f621d Add array.fill/3, array.fill_range/5 and array2d.fill/3.
library/array.m:
library/array2d.m:
    Add the new predicates.

    Add a note a likely problem with another predicate.

NEWS:
    Announce them.

tests/hard_coded/Mmakfile:
tests/hard_coded/array_fill.{m,exp}:
    Add a test case.
2018-11-08 10:15:03 +00:00
Peter Wang
ecdf8ae7dd Fix typos in test cases.
tests/hard_coded/bit_twiddle_int16.exp:
tests/hard_coded/bit_twiddle_int16.m:
tests/hard_coded/bitwise_int32.exp:
tests/hard_coded/bitwise_int32.m:
    Fix typos in test cases and update expected outputs.
2018-10-29 10:20:48 +11:00
Peter Wang
1d57550d2f Simplify away self-comparisons of variables of int types.
Newer versions of gcc and clang may warn about comparison of a variable
to itself that always evaluate to true or false, breaking builds in
which warnings are treated as errors.

compiler/simplify_goal_call.m:
    Replace calls to comparison predicates < > =< >= of int types in
    which both arguments are the same variable with 'true' or 'false'
    goals.

    Replace calls to builtin.compare/3 where the compared arguments are
    the same variable with a goal that assigns (=) as the comparison
    result.

    Factor out common simplifications to all int types.

tests/hard_coded/Mmakefile:
tests/hard_coded/tautological_compare.m:
tests/hard_coded/tautological_compare.exp:
    Add new test case.

tests/typeclasses/typeclass_exist_method.m:
    Revert now-unnecessary workaround.
2018-10-23 18:58:36 +11:00
Zoltan Somogyi
6e4f6466fb Don't emit noops on direct_arg tags with ptag=0.
compiler/ml_unify_gen_construct.m:
compiler/ml_unify_gen_deconstruct.m:
compiler/unify_gen_construct.m:
compiler/unify_gen_deconstruct.m:
    When the direct arg tag on a guaranteed-to-be-zero pointer
    is itself zero, don't emit instructions either to put on
    or to mask off the zero ptag, since both would noops.

tests/hard_coded/direct_arg_tags_2.{m,exp}:
    A new test case to test (a) the static construction, (b) the dynamic
    construction and (c) the deconstruction of direct_arg tags, both when
    the replacement ptag is zero and when it is not zero.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2018-10-14 22:07:25 +11:00
Zoltan Somogyi
8447b4124b Fix programming style in some tests. 2018-10-14 22:03:31 +11:00
Julien Fischer
8fe2751758 Conversion of 8- and 16-bit integers to floats.
Add functions for performing conversion of 8- and 16-bit integers to floats.
Since the ranges of all these integer types lie within the what can be exactly
represented by both single- and double-precision floating-point values, these
conversions always succeed.

Add a note about the float/1 function.

library/float.m:
     Add the new conversion functions.

     Note that the behaviour of float/1 is currently undefined if the
     argument is outside the range that the floating-point type can exactly
     represent integers.

     Fix section headings.

tests/hard_coded/Mmakfile:;
tests/hard_coded/float_conv.{m,exp}
    A test of int->float conversion; currently for 8- and 16-bit integers.
2018-10-09 04:42:31 +00:00
Julien Fischer
6e91909412 Putback of 8-bit values to binary input streams.
Support direct putback of int8 and uint8 values to binary input streams
instead of via the bottom 8 bits of an int value.

library/io.m:
    Add putback_{int8,uint8}/[34].

    Add stream type class instances for putback streams binary_input_stream
    with int8 and uint8.

tests/hard_coded/Mmakefile:
tests/hard_coded/putback_binary_int8.{m,exp}:
tests/hard_coded/putback_binary_uint8.{m,exp}:
    Add tests of the above.
2018-10-05 06:42:30 +00:00
Zoltan Somogyi
341b3247aa Test case for bulk comparisons.
tests/hard_coded/bulk_compare_packed.{m,exp}:
    A new test case to test comparison predicates involving bulk comparison
    of packed arguments.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2018-10-01 01:00:41 +10:00
Julien Fischer
c0524841a2 More documentation of expected outputs.
Fix a test failure in spf grades.

tests/hard_coded/backend_external.m:
tests/hard_coded/from_int_uint32.m:
tests/hard_coded/parse_number_from_io.m:
tests/hard_coded/remove_file.m:
tests/hard_coded/uint_arith.m:
    As above.

tests/hard_coded/parse_number_from_io.exp4:
    Alternative expected output for spf grades.
2018-09-06 13:45:50 +10:00
Julien Fischer
1c7e8c7cef More documentation of expected outputs.
tests/hard_coded/uint_bitwise.m:
tests/hard_coded/bitwise_int.m:
    As above.

tests/hard_coded/string_strip.exp2:
    Delete this: it was for the IL backend, which no longer exists.
    All our current backends just match the .exp file.
2018-09-05 15:06:35 +10:00
Julien Fischer
a735a6a07c Document expected outputs for a test case.
tests/hard_coded/expand.m:
    Document what each of the expected outputs corresponds to.
2018-09-05 14:51:41 +10:00
Julien Fischer
1deda0b07c Fix a test case failure in .spf grades.
tests/hard_coded/lexer_zero.m:
    Document what the expected outputs correspond.

tests/hard_coded/lexer_zero.exp4:
    Add an expected output for this test for spf grades.
2018-09-05 14:24:30 +10:00
Zoltan Somogyi
86f563a94d Pack subword-sized arguments next to a remote sectag.
compiler/du_type_layout.m:
    If the --allow-packing-remote-sectag option is set, then try to pack
    an initial subsequence of subword-sized arguments next to remote sectags.

    To allow the polymorphism transformation to put the type_infos and/or
    typeclass_infos it adds to a function symbol's argument list at the
    *front* of that argument list, pack arguments next to remote sectags
    only in function symbols that won't have any such extra arguments
    added to them.

    Do not write all new code for the new optimization; instead, generalize
    the code that already does a very similar job for packing args next to
    local sectags.

    Delete the code we used to have that picked the packed representation
    over the base unpacked representation only if it reduced the
    "rounded-to-even" number of words. A case could be made for its usefulness,
    but in the presence of the new optimization the extra code complexity
    it requires is not worth it (in my opinion).

    Extend the code that informs users about possible argument order
    rearrangements that yield better packing to take packing next to sectags
    into account.

compiler/hlds_data.m:
    Provide a representation for cons_tags that use the new optimization.
    Instead of adding a new cons_tag, we do this by replacing several old
    cons_tags that all represent pointers to memory cells with a single
    cons_tag named remote_args_tag with an argument that selects among
    the old cons_tags being replaced, and adding a new alternative inside
    this new type. The new alternative is remote_args_shared with a
    remote_sectag whose size is rsectag_subword(...).

    Instead of representing the value of the "data" field in classes
    on the Java and C# backends as a strange kind of secondary tag
    that is added to a memory cell by a class constructor instead of
    having to be explicitly added to the front of the argument vector
    by the code of a unification, represent it more directly as separate
    kind of remote_args_tag. Continuing to treat it as a sectag would have
    been very confusing to readers of the code of ml_unify_gen_*.m in the
    presence of the new optimization.

    Replacing several cons_tags that were usually treated similarly with
    one cons_tag simplifies many switches. Instead of an switch with that
    branches to the same switch arm for single_functor_tag, unshared_tag
    and shared_remote_tag, and then switches on these three tags again
    to get e.g. the primary tag of each, the new code of the switch arm
    is executed for just cons_tag value (remote_args_tag), and switches
    on the various kinds of remote args tags only when it needs to.
    In is also more natural to pass around the argument of remote_args_tag
    than to pass around a variable of type cons_tag that can be bound to only
    single_functor_tag, unshared_tag or shared_remote_tag.

    Add an XXX about possible further steps along these lines, such as
    making a new cons_tag named something like "user_const_tag" represent
    all user-visible constants.

compiler/unify_gen_construct.m:
compiler/unify_gen_deconstruct.m:
compiler/unify_gen_test.m:
compiler/unify_gen_util.m:
compiler/ml_unify_gen_construct.m:
compiler/ml_unify_gen_deconstruct.m:
compiler/ml_unify_gen_test.m:
compiler/ml_unify_gen_util.m:
    Implement X = f(Yi) unifications where f uses the new representation,
    i.e. some of its arguments are stored next to a remote sectag.

    Some of the Yi are stored in a tagword (a word that also contains a tag,
    in this case the remote secondary tag), while some are stored in other
    words in a memory cell. This means that such unifications have similarities
    both to unifications involving arguments being packed next to local
    sectags, and to unifications involving ordinary arguments in memory cells.
    Therefore wherever possible, their implemenation uses suitably generalized
    versions of existing code that did those two jobs for two separate kinds of
    cons_tags.

    Making such generalizations possible in some cases required shifting the
    boundary between predicates, moving work from a caller to a callee
    or vice versa.

    In unify_gen_deconstruct.m, stop using uni_vals to represent *either* a var
    *or* a word in a memory cell. While this enabled us to factor out some
    common code, the predicate boundaries it lead to are unsuitable for the
    generalizations we now need.

    Consistently use unsigned ints to represent both the whole and the parts
    of words containing packed arguments (and maybe sectags), except when
    comparing ptag constants with the result of applying the "tag" unop
    to a word, (since that unop returns an int, at least for now).

    In a few cases, avoid the recomputation of some information that we
    already know. The motivation is not efficiency, since the recomputation
    we avoid is usually cheap, but the simplification of the code's correctness
    argument.

    Use more consistent terminology in things such as variable names.

    Note the possibility of further future improvements in several places.

compiler/ml_foreign_proc_gen.m:
    Delete a long unused predicate.

compiler/mlds.m:
    Add an XXX documenting a possible improvement.

compiler/rtti.m:
    Update the compiler's internal representation of RTTI data structures
    to make them able to describe secondary tags that are smaller than
    a full word.

compiler/rtti_out.m:
    Conform to the changes above, and delete a long-unused predicate.

compiler/type_ctor_info.m:
    Use the RTTI's du_hl_rep to represent cons_tags that distinguish
    between function symbols using a field in a class.

compiler/ml_type_gen.m:
    Provide a specialized form of a function for code in ml_unify_gen_*.m.
    Conform to the changes above.

compiler/add_special_pred.m:
compiler/bytecode_gen.m:
compiler/export.m:
compiler/hlds_code_util.m:
compiler/lco.m:
compiler/ml_closure_gen.m:
compiler/ml_switch_gen.m:
compiler/ml_tag_switch.m:
compiler/rtti_to_mlds.m:
compiler/switch_util.m:
compiler/tag_switch.m:
    Conform to the changes above.

runtime/mercury_type_info.h:
    Update the runtime's representation of RTTI data structures to make them
    able to describe remote secondary tags that are smaller than a full word.

runtime/mercury_deconstruct.[ch]:
runtime/mercury_deconstruct.h:
runtime/mercury_deconstruct_macros.h:
runtime/mercury_ml_expand_body.h:
runtime/mercury_ml_arg_body.h:
runtime/mercury_ml_deconstruct_body.h:
runtime/mercury_ml_functor_body.h:
    These modules collectively implement the predicates in deconstruct.m
    in the library, and provide access to its functionality to other C code,
    e.g. in the debugger. Update these to be able to handle terms with the
    new data representation optimization.

    This update requires a significant change in the distribution of work
    between these files for the predicates deconstruct.deconstruct and
    deconstruct.limited_deconstruct. We used to have mercury_ml_expand_body.h
    fill in the fields of their expand_info structures (whose types are
    defined in mercury_deconstruct.h) with pointers to three vectors:
    (a) a vector of arg_locns with one element per argument, with a NULL
    pointer being equivalent to a vector with a given element in every slot;
    (b) a vector of type_infos with one element per argument, constructed
    dynamically (and later freed) if necessary; and (c) a vector of argument
    words. Once upon a time, before double-word and sub-word arguments,
    vector (c) also had one word per argument, but that hasn't been true
    for a while; we added vector (a) help the consumers of the expand_info
    decode the difference. The consumers of this info  always used these
    vectors to build up a Mercury term containing a list of univs,
    with one univ for each argument.

    This structure could be stretched to handle function symbols that store
    *all* their arguments in a tagword next to a local sectag, but I found
    that stretching it to cover function symbols that have *some* of their
    arguments packed next to a remote sectag and *some other* of their
    arguments in a memory cell as usual would have required a well-nigh
    incomprehensibly complex, and therefore almost undebuggable, interface
    between mercury_ml_expand_body.h and the other files above. This diff
    therefore changes the interface to have mercury_ml_expand_body.h
    build the list of univs directly. This make its code relatively simple
    and self-contained, and it should be somewhat faster then the old code
    as well, since it never needs to allocate, fill in and then free
    vectors of type_infos (each such typeinfo now gets put into a univ
    as soon as it is constructed). The downside is that if we ever wanted
    to get all the arguments at once for a purpose other than constructing
    a list of univs from them, it would nevertheless require constructing
    that list of univs anyway as an intermediate data structure. I don't see
    this downside is significant, because (a) I don't think such a use case
    is very likely, and (b) even if one arises, debuggable but a bit slow
    is probably preferable to faster but very hard to debug.

    Reduce the level of indentation of some of these files to make the code
    easier to edit. Do this by

    - not adding an indent level from switch statements to their cases; and
    - not adding an indent level when a case in a switch has a local block.

    Move the break or return ending a case inside that case's block,
    if it has one.

runtime/mercury_deep_copy_body.h:
runtime/mercury_table_type_body.h:
    Update these to enable the copying or tabling of terms whose
    representations uses the new optimization.

    Use the techniques listed above to reduce the level of indentation
    make the code easier to edit.

runtime/mercury_tabling.c:
runtime/mercury_term_size.c:
    Conform to the changes above.

runtime/mercury_unify_compare_body.h:
    Make this code compile after the changes above. It does need to work
    correctly, since we only ever used this code to compare the speed
    of unify-by-rtti with the speed of unify-by-compiler-generated-code,
    and in real life, we always use the latter. (It hasn't been updated
    to work right with previous arg packing changes either.)

library/construct.m:
    Update to enable the code to construct terms whose representations
    uses the new optimization.

    Add some sanity checks.

library/private_builtin.m:
runtime/mercury_dotnet.cs.in:
java/runtime/Sectag_Locn.java:
    Update the list of possible sectag kinds.

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

trace/mercury_trace_vars.c:
    Conform to the changes above.

tests/hard_coded/deconstruct_arg.{m,exp,exp2}:
    Extend this test to test the deconstruction of terms whose
    representations uses the new optimization.

    Modify some of the existing terms being tested to make them more diverse,
    in order to make the output easier to navigate.

tests/hard_coded/construct_packed.{m,exp}:
    A new test case to test the construction of terms whose
    representations uses the new optimization.

tests/debugger/browse_packed.{m,exp}:
    A new test case to test access to the fields of terms whose
    representations uses the new optimization.

tests/tabling/test_packed.{m,exp}:
    A new test case to test the tabling of terms whose
    representations uses the new optimization.

tests/debugger/Mmakefile:
tests/hard_coded/Mmakefile:
tests/tabling/Mmakefile:
    Enable the new test cases.
2018-08-30 05:14:38 +10:00
Zoltan Somogyi
180d2f7aa8 Fix too-long lines. 2018-08-30 03:38:16 +10:00
Julien Fischer
f2f9fb1d5c Extend a test case.
tests/hard_coded/test_generic_ref.{m,exp}:
    Extend this test to cover 64-bit integer types.
2018-08-29 05:07:29 +00:00