Commit Graph

79 Commits

Author SHA1 Message Date
Julien Fischer
b85f11b41d Fix library documentation errors.
library/*.m:
    As above.

library/getopt.m:
    Regenerate this file.
2026-01-22 21:22:38 +11:00
Zoltan Somogyi
b6b4e85067 Add unsigned versions of version_array operations.
library/version_array.m:
    For every predicate or function that takes an integer argument,
    if that integer is required to be non-negative, add an unsigned version.

    Improve the documentation of the exported operations.

    Improve variable names in operations that have new unsigned versions.

NEWS.md:
    Announce the new operations.

tests/hard_coded/version_array_test.m:
    Modify this test case to test the new operations.
2026-01-19 19:27:50 +11:00
Zoltan Somogyi
3f72528869 Update module stability levels. 2025-08-11 22:32:52 +02:00
Zoltan Somogyi
34e64a623b Replace "iff" with "if-and-only-if" in the library. 2025-06-08 10:33:56 +10:00
Zoltan Somogyi
3ba06086be Update copyright notices. 2025-01-24 13:34:34 +11:00
Zoltan Somogyi
dcf48e2315 Add a new option, --warn-unsorted-import-blocks.
compiler/options.m:
doc/user_guide.texi:
NEWS.md:
    Add, document and announce the new option. It is off by default,
    but of course I tested its behavior when turned on. Most of this
    diff deals with the consequences.

compiler/item_util.m:
    Add code to generate the new warnings if requested.

compiler/convert_parse_tree.m:
    Request the new warning if the new option is set when processing
    source files..

compiler/handle_options.m:
    Disable all style warnings, including the new one, when generating
    .int* files or .*opt files.

compiler/mercury_compile_main.m:
    Fix an unrelated bug I noticed while working on this diff:
    report the "unfindability" of a given file at most once.

browser/dl.m:
browser/io_action.m:
compiler/mercury_compile_augment.m:
compiler/mercury_compile_llds_back_end.m:
compiler/unused_args.m:
deep_profiler/autopar_find_best_par.m:
deep_profiler/dump.m:
deep_profiler/html_format.m:
deep_profiler/mdprof_create_feedback.m:
deep_profiler/profile.m:
deep_profiler/read_profile.m:
deep_profiler/recursion_patterns.m:
deep_profiler/var_use_analysis.m:
library/array2d.m:
library/bit_buffer.read.m:
library/construct.m:
library/edit_distance.m:
library/library.m:
library/mercury_term_lexer.m:
library/one_or_more_map.m:
library/private_builtin.m:
library/set_bbbtree.m:
library/string.parse_runtime.m:
library/thread.future.m:
library/univ.m:
library/version_array.m:
library/version_bitmap.m:
mdbcomp/program_representation.m:
profiler/call_graph.m:
profiler/demangle.m:
profiler/output.m:
profiler/process_file.m:
profiler/propagate.m:
slice/mdice.m:
slice/mslice.m:
    Fix unsorted import blocks pointed out by the new option.

tests/invalid/ambiguous_overloading_error.err_exp:
tests/invalid/bad_tscp.err_exp:
tests/invalid/bug10.err_exp:
tests/invalid/gh72_errors.err_exp:
tests/invalid/ho_default_func_2.err_exp:
tests/invalid/require_scopes.err_exp:
tests/invalid/type_error_use_module.err_exp:
tests/invalid/types.err_exp:
tests/invalid_nodepend/errors_2.err_exp:
tests/invalid_nodepend/funcs_as_preds.err_exp:
tests/warnings/ambiguous_overloading.err_exp:
tests/warnings/save.err_exp:
tests/warnings/singleton_test.err_exp:
tests/warnings/unused_interface_import.err_exp:
    Update the expected outputs of these test cases to expect the new warning
    for unsorted import blocks in their source files.

tests/invalid/Mercury.options:
tests/invalid_nodepend/Mercury.options:
tests/warnings/Mercury.options:
    Execute those test cases with the warning enabled.

tests/invalid_nodepend/require_tailrec_invalid.m:
tests/invalid_nodepend/specified.m:
tests/recompilation/pragma_type_spec_r.m.1:
tests/recompilation/type_qual_re.m.1:
tests/recompilation/type_qual_re_2.m.1:
tests/recompilation/type_spec_unname_var_r.m.1:
tests/recompilation/type_spec_unname_var_r_2.m.1:
tests/recompilation/type_spec_unname_var_r_2.m.2:
tests/recompilation/unchanged_pred_nr.m.1:
tests/recompilation/with_type_re.m.1:
    Sort the import blocks in these test cases, and where relevant,
    import only one module per line.

tests/recompilation/with_type_re.err_exp.2:
    Expect updated line numbers after splitting a line that imported
    two modules.

tests/warnings/unsorted_import_blocks.{m,err_exp}:
    New test case to exercise one nontrivial part of the sortedness check,
    numerical non-sortedness. (The other affected test cases already exercise
    all the other parts.)

tests/warnings/Mmakefile:
    Enable the new test case.
2025-01-21 19:19:33 +11:00
Zoltan Somogyi
a19bcaaed5 Updates to programming style in the library.
library/bt_array.m:
    Reorder the arguments of the resize and shrink predicates
    to make them easier to use with state variables.

tests/general/array_test.m:
    Update the test calls to these two predicates.

library/version_array2d.m:
    Rewrite part of this module using a programming style that includes
    variable names that are longer than one character :-(. In the absence
    of comprehensive, or even basic, test cases, leave the rest using
    the old style.

    Add a non-field-syntax lookup operation.

    Mark the site of a probable bug.

library/version_bitmap.m:
    Add non-field-syntax versions of the get_bit and set_bit operations.

NEWS.md:
    Announce the reordering and the new predicates above.

library/getopt.m:
library/getopt_io.m:
    Apply to getopt_io.m an update that was previously applied to getopt.m,
    even though getopt.m is now computed from getopt_io.m.

library/array2d.m:
library/bit_buffer.m:
library/bit_buffer.read.m:
library/bit_buffer.write.m:
library/bitmap.m:
library/cord.m:
library/edit_distance.m:
library/edit_seq.m:
library/fat_sparse_bitset.m:
library/fatter_sparse_bitset.m:
library/list.m:
library/one_or_more.m:
library/pair.m:
library/ra_list.m:
library/rbtree.m:
library/set_bbbtree.m:
library/set_ctree234.m:
library/set_ordlist.m:
library/set_tree234.m:
library/set_unordlist.m:
library/solutions.m:
library/sparse_bitset.m:
library/test_bitset.m:
library/thread.barrier.m:
library/thread.m:
library/thread.semaphore.m:
library/time.m:
library/tree_bitset.m:
library/version_array.m:
library/version_hash_table.m:
library/version_store.m:
    General updates to style, the main ones being the following.

    Using standard names for type variables:

    - K and V for key and value types in map-like structures
    - A to F for types of accumulators
    - T for most everything else, possibly with a numeric suffix
      to distinguish two separate types that nevertheless play
      similar roles.

    (I left descriptive type var names such as Stream and Store unchanged.)

    Adding or expanding descriptions of exported predicates and functions.

    Declaring and defining field syntax getters and setters without using ^,
    while keeping the use of field syntax, including ^, in the operations'
    descriptions.

    Defining field syntax operations operations in terms of the
    non-field-syntax versions, not vice versa.

    Defining function versions of operations in terms of the predicate
    versions, not vice versa.
2024-12-29 20:09:09 +11:00
Zoltan Somogyi
efafcdd0c1 Stop using higher order insts as modes ...
... in the fourth and final batch of library modules.

Set -no-allow-ho-insts-as-modes as the default for this directory
from now on.
2023-07-26 23:55:07 +02:00
Peter Wang
305739a58b Make version_hash_table maintain concurrency (un)safeness.
When a version hash table expanded its underlying version array,
it would always create a concurrency-safe version array even if the
hash table itself was originally created with a
version_hash_table.unsafe_init* functions.

This change makes it so that when an "unsafe" version hash table
expands, it will create an "unsafe" version array internally.

library/version_array.m:
    Export a predicate has_lock/1 for use by version_hash_table.m

    Replace occurrences of max(VA) with size(VA) - 1. The latter makes
    it more obvious that an index may start out negative.

    Other minor style changes.

    Fix typos.

library/version_hash_table.m:
    When expanding a hash table, create a new version array with
    version_array.init or version_array.unsafe_init
    depending on whether the old version array had an internal lock.

    Replace field access expressions with predicate calls.
2023-07-20 11:02:32 +10:00
Zoltan Somogyi
e167c8ffc3 Delete redundant module qualifications. 2022-12-28 03:52:42 +11:00
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
53333256f8 Reword the fixed comment. 2022-12-03 12:20:19 +11:00
Zoltan Somogyi
901d88263d Fix documentation. 2022-12-03 09:46:52 +11:00
Peter Wang
2b1c6f33ec Opt-export version_array lookup and set.
This allows the compiler to eliminate the construction of typeinfo
arguments for calls to version_array.lookup and version_array.set,
when compiling with intermodule optimisation and --optimize-unused-args.

In particular, version_hash_table would previously dynamically construct
typeinfos in order lookup or update hash table buckets.

This change improves the run time of a do-nothing build of Prince using
mmc --make on my machine from 1.6 s to 1.43 s.

library/version_array.m:
    Add pragma inlines for version_array.lookup and version_array.set.

library/Mercury.options:
    Always compile version_hash_table with --optimize-unused-args.
2022-12-01 17:29:33 +11:00
Peter Wang
7d268cb20c Add version_array.lookup predicate.
library/version_array.m:
    Add version_array.lookup predicate.

    Use it instead of the lookup function in some places,
    mostly because lookup(A, I) now has an ambiguous type.

NEWS:
    Announce change.
2022-12-01 16:44:11 +11:00
Zoltan Somogyi
2f0fa9d7b4 Use logic programming style in version_store.m.
library/version_store.m:
    Many operations of this module have both predicate and function forms.
    Instead of implementing the predicates in terms of the functions,
    do the reverse. Make the auxiliary routines predicates as well,
    in order to allow the use of state variables.

    Improve the documentation.

library/version_array.m:
    Change some auxiliary routines from functions to predicates,
    for the same reason.
2022-05-12 13:55:29 +10:00
Julien Fischer
6d5792321e Fix stage 2 java grade compiler with --intermod-opt
library/version_array.m:
    Fully qualify things in foreign_procs that end up in .opt files.
    (The lack of the these qualifiers breaks the compilation of the
    stage 2 .java files in the compiler directory.)

    Delete foreign code attributes from C# and Java foreign_procs
    that do not apply to those backends.
2022-03-16 19:58:31 +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
Julien Fischer
1029ace046 Fix library compilation in non-C grades.
The recent change to enable --warn-dead-predicates in the library directory
broke standard library compilation due to various predicates being dead in some
grades.

library/io.m:
    Add a default Mercury clause for compare_file_id_2/3; having a Java one
    that throws a (Java) exception results in the Java compiler complaining
    about unreachable code when compare_file_id_2/3 is inlined in its caller.

    Add consider_used pragmas where necessary.

library/erlang_rtti_implementation.m:
library/rtti_implementation.m:
library/time.m:
library/version_array.m:
    Add consider_used pragmas where necessary.
2020-06-19 23:34:41 +10:00
Zoltan Somogyi
a6228a9e1a Fix too-long lines. 2020-04-10 03:22:40 +10:00
Julien Fischer
eed0f86519 Delete some obsolete procedures.
Delete some procedures that have been marked as obsolete since before the 14.01
release.

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

NEWS:
    Announce the deletions.

tests/hard_coded/hash_table_delete.m:
    Replace a call to one of the deleted functions.
2020-02-02 02:31:35 +11:00
Julien Fischer
7fcd3da993 Update a comment.
library/version_array.m:
    As above.
2019-10-17 16:12:50 +11:00
Zoltan Somogyi
a12692a0de Replace /* */ comments with // in the library.
Keep the old style comments where they do not go to the end of the line,
or where it is important that the comment line not have a // on it.
2018-06-21 18:55:08 +02:00
Mark Brown
d465fa53cb Update the COPYING.LIB file and references to it.
Discussion of these changes can be found on the Mercury developers
mailing list archives from June 2018.

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

*:
    Update references to COPYING.LIB.

    Clean up some minor errors that have accumulated in copyright
    messages.
2018-06-09 17:43:12 +10:00
Peter Wang
d7d1471881 Clarify behaviour of upper bounds functions for array types.
library/array.m:
library/bt_array.m:
library/version_array.m:
    As above.
2017-12-01 17:36:20 +11:00
Zoltan Somogyi
5898b127db Fix some warnings from --warn-inconsistent-pred-order-clauses.
library/bimap.m:
library/bitmap.m:
library/calendar.m:
library/char.m:
library/cord.m:
library/deconstruct.m:
library/diet.m:
library/dir.m:
library/eqvclass.m:
library/map.m:
library/pprint.m:
library/pqueue.m:
library/stream.string_writer.m:
library/term_conversion.m:
library/time.m:
library/type_desc.m:
library/version_array.m:
library/version_array2d.m:
library/version_bitmap.m:
library/version_hash_table.m:
    Fix inconsistencies between (a) the order in which functions and predicates
    are declared, and (b) the order in which they are defined.

    In most of these modules, either the order of the declarations
    or the order of the definitions made sense, and I changed the other
    to match. In a few modules, neither made sense, so I changed *both*
    to an order that *does* make sense (i.e. it has related predicates
    together).

    In some places, put dividers between groups of related
    functions/predicates, to make the groups themselves more visible.

    In some places, fix comments or programming style, give some auxiliary
    (non-exported) predicates better names, or delete some unneeded module
    qualifications.

    In some places, have the function form of a procedure forward
    the work to the predicate form, instead of vice versa, where this is
    more natural (usually because it allows the use of state variables).
    However, this is the only kind of "algorithmic" change in this diff;
    the rest is just moving code around.
2017-04-27 11:44:24 +10:00
Julien Fischer
64861b2d13 Add version_array.from_reverse_list/1.
library/version_array.m:
     Add the above function.

     Minor fixes to some comments.

tests/hard_coded/version_array_test.{m,exp}:
     Extend this test to cover from_reverse_list/1 and
     from_list/1.

NEWS:
     Announce the addition.
2016-07-22 13:51:53 +10:00
Zoltan Somogyi
2a12b90486 Move pragmas before the referenced predicate declarations. 2016-03-12 18:56:19 +11:00
Julien Fischer
ae75849e28 Hide an XXX comment in the library reference manual.
library/version_array.m:
    Do not include an XXX comment about the .agc grades (which
    are undocumented) in the library reference manual.
2016-01-09 15:25:41 +11:00
Julien Fischer
74e3d35ae9 Fixes for library documentation.
library/pretty_printer.m:
library/getopt_io.m:
library/getopt.m:
	Fix typos.

library/array.m:
library/list.m:
library/queue.m:
library/version_array.m:
	s/Nth/N'th/ etc.
2015-01-14 13:49:44 +11:00
Julien Fischer
8a92327d21 Fix compilation of library/version_array.m in memory profiling grades.
library/version_array.m:
    The macro MR_ALLOC_ID is only defined for foreign_proc pragmas *not* for
    foreign_code pragmas.  Commit ab44bba introduced several references to
    MR_ALLOC_ID inside functions defined foreign_code pragmas.  Fix this by
    passing the appropriate alloc id down from the foreign_proc pragmas
    that call the affected functions.
2014-12-12 02:15:00 +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
Paul Bone
ab44bbad3f Use a better algorithm for unwinding version_arrays.
The old version_array rewind code used linear stack space in order to
perform it's updates in the right order (newest to oldest) by following the
structure's next pointers (which are a oldest to newest list).  I previously
introduced week prev pointers so that walking over this structure newest to
oldest could be done with constant stack space.  However that is less
efficient than the method suggested by Peter Wang.

Peter suggested using a bitmap and traversing oldest-to-newest, marking
each update in the bitmap and checking the bitmap before making any update.
Thus preserving older values over newer ones (which is good, this code
_rewinds_ updates).  This patch implements Peter's suggestion and removes
the prev pointers from the structure for C and Java backends.

Thanks to Peter Wang for giving me a hand with C#.

library/version_array.m:
    As above.

runtime/mercury_bitmap.h:
    Add some macros for initialising bitmaps and testing, setting and clearing
    their bits.

library/bitmap.m:
java/runtime/MercuryBitmap.java:
    Move the Java MercuryBitmap class into the runtime library.  This makes
    it easier for other standard library modules to use this Java class.

library/bitmap.m:
runtime/mercury_dotnet.cs.in:
    Move C# MercuryBitmap class into runtime/mercury_dotnet.cs

library/bitmap.m:
    Add extra methods to the C# MercuryBitmap class.

tests/hard_coded/version_array_test.exp:
tests/hard_coded/version_array_test.m:
    Ensure that the test verifies that rolling back updates to a version
    array rolls back changes in the correct order: If two updates modify the
    same cell, then the older one should be visible in the result.

    Use longer arrays so that the bitmap used in the rollback code is more
    than one byte in length.
2014-09-10 12:04:53 +10:00
Paul Bone
35ade3c94e Escape backslashes in foreign code.
library/version_array.m:
    Escape backslashes in foreign code so that gcc and gdb give us
    meaningful line numbers.
2014-07-18 14:48:29 +10:00
Paul Bone
b1a0a7e478 Make version_array's rewind code use constant stack space.
Although rewinding version arrays should be rare it is better if this code
uses constant stack space to avoid crashes.  Currently the list of updates
made in a version array is kept in a singly linked list.  This list needs to
be walked backwards to unwind updates, such as when updating an old version
of an array (to fork into two separate arrays).  The stack is used to
perform this backwards work and can overflow for long histories.

This patch makes these lists doubly-linked so that they can be traversed in
either direction.  The back pointers are implemented using weak pointers in
all backends.  This avoids unnecessary memory retention when a programmer
only maintains a reference to the lastest version of the array, which is the
common case.

library/version_array.m:
    As above; I developed this algorithm in the C implementation first and
    then replicated the changes in the Java and C# implementations.

tests/hard_coded/version_array_test.m:
tests/hard_coded/version_array_test.exp:
    Extend the test case to exercise implicitly unwinding a version array by
    updating an old version of an array.  Note that the implicit and
    explicit unwind codepaths are different as they are out-of-place and
    in-place respectively.
2014-07-18 12:59:18 +10:00
Paul Bone
f33e6a8416 Use C's 'const' keyword correctly in version_array.m
library/version_array.m:
    Use pointers to constant structures rather than constant pointers to
    structures.
2014-07-18 12:59:18 +10:00
Julien Fischer
6ffec8a4af Add all_{true,false}/2 and is_empty/1 to array and version_array.
library/array.m:
library/version_array.m:
	Add the above predicates.

NEWS:
	Announce the new predicates.

tests/hard_coded/Mmakefile:
tests/hard_coded/array_all_tf.{m,exp}:
	Test the new predicates.

tests/hard_coded/version_array_test.{m,exp}:
	Extend this test case to cover the new predicates.
2013-07-22 15:45:23 +10:00
Julien Fischer
92ddfdcf11 Delete obsolete procedures and modules from the standard library.
library/array.m:
library/array2d.m:
library/bitmap.m:
library/store.m:
library/thread.semaphore.m:
library/version_array2d.m:
library/version_bitmap.m:
library/version_hash_table.m:
library/version_store.m:
	Delete predicates that were deprecated in Mercury 13.05 and before.

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

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

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

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

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

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

tests/hard_coded/*/*.m
tests/tabling/*.m:
	Update test cases where they made use of predicates that have
	now been deleted from the standard library.
2013-05-16 17:50:15 +10:00
Paul Bone
1b67cb305f Add an extra note about costs in version_array.m
version_array.m did not document the cost of modifying an old part of the
array.  This change adds a simple description.

library/version_array.m:
    As above.
2013-05-07 11:55:49 +10:00
Zoltan Somogyi
86e0a81f94 Make vartypes an abstract data type, in preparation for exploring
Estimated 3ours taken: 4
Branches: main

compiler/prog_data.m:
	Make vartypes an abstract data type, in preparation for exploring
	better representations for it.

compiler/mode_util.m:
	Provide two different versions of a predicate. The generic version
	continues to use map lookups. The other version knows it works on
	prog_vars, so it can use the abstract operations on them provided
	by prog_data.m.

compiler/accumulator.m:
compiler/add_class.m:
compiler/add_heap_ops.m:
compiler/add_pragma.m:
compiler/add_pred.m:
compiler/add_trail_ops.m:
compiler/arg_info.m:
compiler/builtin_lib_types.m:
compiler/bytecode_gen.m:
compiler/call_gen.m:
compiler/clause_to_proc.m:
compiler/closure_analysis.m:
compiler/code_info.m:
compiler/common.m:
compiler/complexity.m:
compiler/const_prop.m:
compiler/constraint.m:
compiler/continuation_info.m:
compiler/cse_detection.m:
compiler/ctgc.datastruct.m:
compiler/ctgc.util.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/dep_par_conj.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/det_util.m:
compiler/disj_gen.m:
compiler/equiv_type_hlds.m:
compiler/erl_call_gen.m:
compiler/erl_code_gen.m:
compiler/erl_code_util.m:
compiler/exception_analysis.m:
compiler/float_regs.m:
compiler/follow_vars.m:
compiler/format_call.m:
compiler/goal_path.m:
compiler/goal_util.m:
compiler/hhf.m:
compiler/higher_order.m:
compiler/hlds_clauses.m:
compiler/hlds_goal.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_pred.m:
compiler/hlds_pred.m:
compiler/hlds_rtti.m:
compiler/inlining.m:
compiler/instmap.m:
compiler/intermod.m:
compiler/interval.m:
compiler/lambda.m:
compiler/lco.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/lookup_switch.m:
compiler/mercury_to_mercury.m:
compiler/ml_accurate_gc.m:
compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_disj_gen.m:
compiler/ml_lookup_switch.m:
compiler/ml_proc_gen.m:
compiler/ml_unify_gen.m:
compiler/mode_info.m:
compiler/modecheck_call.m:
compiler/modecheck_conj.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/modes.m:
compiler/par_loop_control.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/prog_type_subst.m:
compiler/prop_mode_constraints.m:
compiler/purity.m:
compiler/qual_info.m:
compiler/rbmm.points_to_info.m:
compiler/rbmm.region_liveness_info.m:
compiler/rbmm.region_transformation.m:
compiler/saved_vars.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/ssdebug.m:
compiler/stack_alloc.m:
compiler/stack_opt.m:
compiler/store_alloc.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/structure_reuse.direct.detect_garbage.m:
compiler/structure_reuse.indirect.m:
compiler/structure_sharing.analysis.m:
compiler/structure_sharing.domain.m:
compiler/switch_detection.m:
compiler/table_gen.m:
compiler/term_constr_build.m:
compiler/term_constr_util.m:
compiler/term_traversal.m:
compiler/term_util.m:
compiler/trace_gen.m:
compiler/trailing_analysis.m:
compiler/try_expand.m:
compiler/tupling.m:
compiler/type_constraints.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/typecheck_errors.m:
compiler/typecheck_info.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
compiler/untupling.m:
compiler/unused_args.m:
compiler/var_locn.m:
	Conform to the above.

compiler/prog_type.m:
compiler/rbmm.points_to_graph.m:
	Conform to the above.

	Move some comments where they belong.

compiler/stm_expand.m:
	Conform to the above.

	Do not export a predicate that is not used outside this module.

	Disable some debugging output unless it is asked for.

	Remove unnecessary prefixes on variable names.

library/version_array.m:
	Instead writing code for field access lookalike functions and defining
	lookup, set etc in terms of them, write code for lookup, set etc,
	and define the field access lookalike functions in terms of them.

	Change argument orders of some internal predicates to be
	more state variable friendly.

	Fix typos in comments.

tests/hard_coded/version_array_test.exp:
	Conform to the change to version_array.m.
2012-07-02 01:16:51 +00:00
Peter Wang
0ee6a5ac92 Allow type_info arguments to version_array getter and setter functions
Branches: main

Allow type_info arguments to version_array getter and setter functions
to be eliminated.

library/version_array.m:
	Change the way that out-of-bounds errors are reported, so that the
	type_info arguments to version_array.elem and version_array.'elem :='
	can be eliminated when intermodule optimisation is enabled.
	The out-of-bounds reporting mirrors that of array.m.

	Ensure `elem' and 'elem :=' are opt-exported.
2012-05-10 00:17:06 +00:00
Peter Wang
2a7d7766e9 Set `thread_safe' attributes on version array predicates,
Branches: main, 11.07

library/version_array.m:
	Set `thread_safe' attributes on version array predicates,
	with justification.

	Conform to renaming of `new' to `init' previously.
	The Java and C# foreign_procs were not renamed.

	Reword a bit of documentation.
2012-04-16 00:17:28 +00:00
Julien Fischer
3022bee136 Fix some typos in comments.
Branches: main

library/array.m:
library/version_array.m:
	Fix some typos in comments.
2011-06-27 14:31:40 +00:00
Julien Fischer
0cc37acb5a Make io.write and the two pretty-printers in the standard library handle
Branches: main

Make io.write and the two pretty-printers in the standard library handle
version arrays in a similar way to normal arrays.

library/pprint.m:
library/pretty_printer.m:
library/stream.string_writer.m:
	As above.

library/version_array.m:
	Add a function for converting a version_array to a pretty_printer.doc
	value.

tests/hard_coded/pretty_printing.{m,exp}:
tests/hard_coded/test_pretty_printer_defaults.{m,exp}:
tests/hard_coded/write.{m,exp}:
	Include printing version_arrays in these tests.
2011-05-20 16:54:30 +00:00
Peter Wang
7e26b55e74 Implement a new form of memory profiling, which tells the user what memory
Branches: main

Implement a new form of memory profiling, which tells the user what memory
is being retained during a program run.  This is done by allocating an extra
word before each cell, which is used to "attribute" the cell to an
allocation site.  The attribution, or "allocation id", is an address to an
MR_AllocSiteInfo structure generated by the Mercury compiler, giving the
procedure, filename and line number of the allocation, and the type
constructor and arity of the cell that it allocates.

The user must manually instrument the program with calls to
`benchmarking.report_memory_attribution', which forces a GC and summarises
the live objects on the heap using the attributions.  The mprof tool is
extended with a new mode to parse and present that data.

Objects which are unattributed (e.g. by hand-written C code which hasn't
been updated) are still accounted for, but show up in profiles as "unknown".

Currently this profiling mode only works in conjunction with the Boehm
garbage collector, though in principle it can work with any memory allocator
for which we can access a list of the live objects.  Since term size
profiling relies on the same technique of using an extra word per memory
cell, the two profiling modes are incompatible.

The output from `mprof -s' looks like this:

------ [1] some label ------
   cells            words         cumul  procedure / type (location)
   14150            38872                total

*   1949/ 13.8%      4872/ 12.5%  12.5%  <predicate `parser.parse_rest/7' mode 0>
     975/  6.9%      1950/  5.0%         list.list/1 (parser.m:502)
     487/  3.4%      1948/  5.0%         term.term/1 (parser.m:501)
     487/  3.4%       974/  2.5%         term.const/0 (parser.m:501)

*   1424/ 10.1%      4272/ 11.0%  23.5%  <predicate `parser.parse_simple_term_2/6' mode 0>
     708/  5.0%      2832/  7.3%         term.term/1 (parser.m:643)
     708/  5.0%      1416/  3.6%         term.const/0 (parser.m:643)
...


boehm_gc/alloc.c:
boehm_gc/include/gc.h:
boehm_gc/misc.c:
boehm_gc/reclaim.c:
	Add a callback function to be called for every live object after a GC.

	Add a function to write out the GC_size_map array.

compiler/layout.m:
	Define the alloc_site_info type which is equivalent to the
	MR_AllocSiteInfo C structure.

	Add alloc_site_array as a kind of "layout" array.

compiler/llds.m:
	Add allocation sites to `cfile' structure.

	Replace TypeMsg argument (which was also for profiling) on `incr_hp'
	instructions by an allocation site identifier.

	Add a new foreign_proc_component for allocation site ids.

compiler/code_info.m:
compiler/global_data.m:
compiler/proc_gen.m:
	Keep the set of allocation sites in the code_info and global_data
	structures.

compiler/unify_gen.m:
	Add allocation sites to LLDS allocation instructions.

compiler/layout_out.m:
compiler/llds_out_file.m:
compiler/llds_out_instr.m:
	Output MR_AllocSiteInfo arrays in generated C files.

	Output code to register the MR_AllocSiteInfo array with the Mercury
	runtime.

	Output allocation site ids for memory allocation instructions.

compiler/llds_out_util.m:
	Add allocation sites to llds_out_info.

compiler/pragma_c_gen.m:
compiler/ml_foreign_proc_gen.m:
	Generate a macro MR_ALLOC_ID which resolves to an allocation site
	structure, for every foreign_proc whose C code contains the string
	"MR_ALLOC_ID".  This is to be used by hand-written C code which
	allocates memory.

	MR_PROC_LABELs are retained for backwards compatibility.  Though
	they were introduced for profiling, they seem to have been co-opted
	for printf-debugging since then.

compiler/ml_global_data.m:
	Add allocation site structures to the MLDS global data.

compiler/mlds.m:
compiler/ml_unify_gen.m:
	Add allocation site id to `new_object' instruction.

compiler/mlds_to_c.m:
	Output allocation site arrays and allocation ids in high-level C code.

	Output a call to register the allocation site array with the Mercury
	runtime.

	Delete an unused predicate.

compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/mercury_compile_llds_back_end.m:
compiler/middle_rec.m:
compiler/ml_accurate_gc.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_util.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/use_local_vars.m:
compiler/var_locn.m:
	Conform to changes.

compiler/pickle.m:
compiler/prog_event.m:
compiler/timestamp.m:
	Conform to changes in memory allocation macros.

library/benchmarking.m:
	Add the `report_memory_attribution' instrumentation predicates.

	Conform to changes to MR_memprof_record.

library/array.m:
library/bit_buffer.m:
library/bitmap.m:
library/construct.m:
library/deconstruct.m:
library/dir.m:
library/io.m:
library/mutvar.m:
library/store.m:
library/string.m:
library/thread.semaphore.m:
library/version_array.m:
	Use attributed memory allocation throughout the standard library so
	that objects don't show up in the memory profile as "unknown".

	Replace MR_PROC_LABEL by MR_ALLOC_ID.

mdbcomp/program_representation.m:
mdbcomp/rtti_access.m:
	Replace MR_PROC_LABEL by MR_ALLOC_ID.

profiler/Mercury.options:
profiler/globals.m:
profiler/mercury_profile.m:
profiler/options.m:
profiler/output.m:
profiler/snapshots.m:
	Add a new mode to `mprof' to parse and present the data from
	`Prof.Snapshots' files.

	Add options for the new profiling mode.

profiler/process_file.m:
	Fix a typo.

runtime/mercury_conf_param.h:
	#define MR_MPROF_PROFILE_MEMORY_ATTRIBUTION if memory profiling
	is enabled and we are using Boehm GC.

runtime/mercury.h:
	Make MR_new_object take an allocation id argument.

	Conform to changes in memory allocation macros.

runtime/mercury_memory.c:
runtime/mercury_memory.h:
runtime/mercury_types.h:
	Define MR_AllocSiteInfo.

	Add memory allocation functions and macros which take into the
	account the additional word necessary for the new profiling mode.
	These should be used in preferences to the raw memory allocation
	functions wherever possible so that objects do not show up in the
	profile as "unknown".

	Add analogues of realloc/free which take into account the offset
	introduced by the attribution word.

	Add function versions of the MR_new_object macros, which can't be
	written in standard C.  They are only used when necessary.

	Add built-in allocation site ids, to be used in the runtime and
	other hand-written code when context-specific ids are unavailable.

runtime/mercury_heap.h:
	Make MR_tag_offset_incr_hp_msg and MR_tag_offset_incr_hp_atomic_msg
	allocate an extra word when memory attribution is desired, and store
	the allocation id there.

	Similarly for MR_create{1,2,3}_msg.

	Replace proclabel arguments in allocation macros by alloc_id
	arguments.

	Replace MR_hp_alloc_atomic by MR_hp_alloc_atomic_msg.  It was only
	used for boxing floats.

	Conform to change to MR_new_object macro.

runtime/mercury_bootstrap.h:
	Delete obsolete macro hp_alloc_atomic.

runtime/mercury_heap_profile.c:
runtime/mercury_heap_profile.h:
	Add the code to summarise the live objects on the Boehm GC heap and
	writes out the data to `Prof.Snapshots', for display by mprof.

	Don't store the procedure name in MR_memprof_record: the procedure
	address is enough and faster to compare.

runtime/mercury_prof.c:
	Finish and close the `Prof.Snapshots' file when the program
	terminates.

	Conform to changes in MR_memprof_record.

runtime/mercury_misc.h:
	Add a macro to expand to the name of the allocation sites array
	in LLDS grades.

runtime/mercury_bitmap.c:
runtime/mercury_bitmap.h:
	Pass allocation id through bitmap allocation functions.

	Delete unused function MR_string_to_bitmap.

runtime/mercury_string.h:
	Add MR_make_aligned_string_copy_msg.

	Make string allocation macros take allocation id arguments.

runtime/mercury.c:
runtime/mercury_array_macros.h:
runtime/mercury_context.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deconstruct_macros.h:
runtime/mercury_dlist.c:
runtime/mercury_engine.c:
runtime/mercury_float.h:
runtime/mercury_hash_table.c:
runtime/mercury_ho_call.c:
runtime/mercury_label.c:
runtime/mercury_prof_mem.c:
runtime/mercury_stacks.c:
runtime/mercury_stm.c:
runtime/mercury_string.c:
runtime/mercury_thread.c:
runtime/mercury_trace_base.c:
runtime/mercury_trail.c:
runtime/mercury_type_desc.c:
runtime/mercury_type_info.c:
runtime/mercury_wsdeque.c:
	Use attributed memory allocation throughout the runtime so that
	objects don't show up in the profile as "unknown".

runtime/mercury_memory_zones.c:
	Attribute memory zones to the Mercury runtime.

runtime/mercury_tabling.c:
runtime/mercury_tabling.h:
	Use attributed memory allocation macros for tabling structures.

	Delete unused MR_table_realloc_* and MR_table_copy_bytes macros.

runtime/mercury_deep_copy_body.h:
	Try to retain the original attribution word when copying values.

runtime/mercury_ml_expand_body.h:
	Conform to changes in memory allocation macros.

runtime/mercury_tags.h:
	Replace proclabel arguments by alloc_id arguments in allocation macros.

runtime/mercury_wrapper.c:
	If memory attribution is enabled, tell Boehm GC that pointers may be
	displaced by an extra word.

trace/mercury_trace.c:
trace/mercury_trace_tables.c:
	Conform to changes in memory allocation macros.

extras/net/tcp.m:
extras/solver_types/library/any_array.m:
extras/trailed_update/tr_array.m:
	Conform to changes in memory allocation macros.

doc/user_guide.texi:
	Document the new profiling mode.

doc/reference_manual.texi:
	Update a commented out example.
2011-05-20 04:16:58 +00:00
Julien Fischer
79cbce2d85 Delete the empty version_types module from the standard library.
Branches: main

Delete the empty version_types module from the standard library.
Shift the documentation it previously contained into the version_array module.

library/version_types.m:
	Delete this module.  It never contained anything other than
	documentation and that can be moved elsewhere.

library/version_array.m:
	Shift the documentation from the head of version_types.m to the head
	of this module.

library/version_array2d.m:
library/version_bitmap.m:
library/version_hash_table.m:
library/version_store.m:
	Point to the version_array module instead of the version_types module.

library/library.m:
	Don't include the version_types module.
2011-05-18 04:25:18 +00:00
Julien Fischer
8523c4ddcc Improve consistency amongst the standard library modules.
Branches: main

Improve consistency amongst the standard library modules.

library/array2d.m:
library/bitmap.m:
library/hash_table.m:
library/store.m:
library/thread.semaphore.m:
library/version_array.m:
library/version_array2d.m:
library/version_bitmap.m:
library/version_hash_table.m:
library/version_store.m:
	Use the name "init" for predicates and functions that create new empty
	data structures instead of the name "new".  (The majority of standard
	library modules already use the former.)

	Mark the "new" versions as obsolete.

library/bit_buffer.read.m:
library/bit_buffer.write.m:
library/io.m:
library/thread.mvar.m:
browser/declarative_execution.m:
compiler/make.m:
compiler/make.program_target.m:
ssdb/ssdb.m:
	Conform to the above changes.

NEWS:
	Announce the above changes.
2011-05-08 16:02:23 +00:00
Julien Fischer
d086147856 Improve support for folds over version arrays.
Branches: main

Improve support for folds over version arrays.

library/version_array.m:
	Add foldl2, foldr, and foldr2.

	Re-arrange C declarations in this module so that those
	with static linkage are not written out to the .mh file.

	s/int/MR_bool/ in a few spots.

NEWS:
	Announce the new predicates.
2010-11-18 07:39:07 +00:00
Peter Wang
1873195aec Output #pragmas to disable warnings for C# we generate.
Branches: main

compiler/mlds_to_cs.m:
        Output #pragmas to disable warnings for C# we generate.
        Restore warnings for handwritten code.

library/Mmakefile:
        Delete an unnecessary line.

library/array.m:
library/dir.m:
library/io.m:
library/thread.m:
library/version_array.m:
ssdb/ssdb.m:
        Make some of the remaining warnings from the C# compiler go away.
2010-11-09 03:46:32 +00:00