Commit Graph

172 Commits

Author SHA1 Message Date
Peter Wang
c053f90088 Allow inlining of Java foreign_procs.
Branches: main, 10.04

Allow inlining of Java foreign_procs.

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

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

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

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

        Add braces to give the foreign_proc variables a limited scope.

compiler/make_hlds_warn.m:
        Conform to renaming.

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

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

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

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

extras/solver_types/library/any_array.m:
tests/hard_coded/equality_pred_which_requires_boxing.m:
tests/hard_coded/external_unification_pred.m:
tests/hard_coded/java_test.m:
tests/hard_coded/redoip_clobber.m:
tests/hard_coded/user_compare.m:
tests/valid/exported_foreign_type2.m:
tests/warnings/warn_succ_ind.m:
tests/warnings/warn_succ_ind.exp3:
        Conform to renaming.
2010-05-07 03:12:27 +00:00
Zoltan Somogyi
d7e5ab83f3 Fix formatting.
Estimated hours taken: 0.1
Branches: main

library/array.m:
	Fix formatting.
2009-09-08 03:22:55 +00:00
Ralph Becket
f1c304939b Add approximate as well as exact binary search to array.m.
Estimated hours taken: 2
Branches: main

Add approximate as well as exact binary search to array.m.  An approximate
search looks for the index of the largest element in the array that is
not greater than the value for which we are searching.  This is useful for,
say, finding which line number corresponds to a particular offset into a file.

NEWS:
	Mention the new additions.

library/array.m:
	Added approx_binary_search and binary_search predicates.

tests/general/Mmakefile:
tests/general/array_binsearch.m:
tests/general/array_binsearch.exp:
	Test case.
2009-09-01 02:11:31 +00:00
Zoltan Somogyi
c2e55b9b44 Fix style.
Estimated hours taken: 0.1
Branches: main

library/array.m:
	Fix style.
2009-08-19 07:46:21 +00:00
Peter Wang
fe4c25c16f Some changes to the Java implementation of the standard library.
Branches: main

Some changes to the Java implementation of the standard library.

library/array.m:
        Use System.arraycopy and java.util.Arrays.fill and avoid using
        reflection to work with arrays in some places.

library/dir.m:
        Implement dir.current_directory.

library/rtti_implementation.m:
        Fix typos where expanded type_infos were not being used.

library/string.m:
        Make string.c_pointer_to_string handle null pointers.

tests/hard_coded/sub-modules/Mmakefile:
        Enable testing of java grade in this directory.

tests/hard_coded/sub-modules/non_word_mutable.m:
tests/hard_coded/sub-modules/sm_exp_bug.m:
        Add Java foreign code.
2009-08-14 06:11:46 +00:00
Peter Wang
d5b11b8cd0 Use java.lang.Object[] as the type of all non-primitive arrays instead of more
Branches: main

Use java.lang.Object[] as the type of all non-primitive arrays instead of more
specific types.  To create arrays with the more specific types we used
reflection on a representative element, but we can't do that if the element is
`null', as it might be for foreign types.

compiler/mlds_to_java.m:
        Write java.lang.Object[] instead of Type[] when Type is not a primitive
        type.

library/array.m:
        For non-primitive element types, just create an Object[] array.
2009-07-17 06:09:33 +00:00
Peter Wang
4fdc8f9d42 Fix Java ML_new_array() when passed a representative element which is
Branches: main

library/array.m:
        Fix Java ML_new_array() when passed a representative element which is
        itself an array.
2009-06-29 06:38:34 +00:00
Peter Wang
1b648d0ac2 Put all Mercury-generated Java classes into the package `jmercury' and
Branches: main

Put all Mercury-generated Java classes into the package `jmercury' and
runtime classes into `jmercury.runtime'.  The Mercury module hierarchy is
not reflected in the package name.  We name sub-module classes using
their fully-qualified module names with `__' between components, e.g.
`bit_buffer.read' produces `class bit_buffer__read'.

As all generated Java code is in the same package we don't need to package
qualify identifiers, and we don't need the hack to avoid clashing package
and class names.  It also makes it easier to write Java foreign code because
generated Java class names are easier to predict from Mercury module names.

The package names are not `mercury' and `mercury.runtime' because on
case-insensitive file systems we may end up with a `mercury' directory
that could be confused with the `Mercury' directory.


compiler/java_names.m:
        Delete code related to mangling package names.

        Remove the extra `mercury' prefix added to standard library module
        names, as it is redundant with `jmercury'.

        Change runtime package name.

compiler/mlds_to_java.m:
        Make generated code follow the new packaging scheme.

        Don't automatically import all runtime classes.  It doesn't seem
        necessary.

        Update for new packaging scheme.

compiler/file_names.m:
        Fix Java file paths for the new packaging scheme.

compiler/module_cmds.m:
compiler/rtti.m:
library/array.m:
library/backjump.m:
library/benchmarking.m:
library/bitmap.m:
library/builtin.m:
library/exception.m:
library/io.m:
library/library.m:
library/mutvar.m:
library/private_builtin.m:
library/rtti_implementation.m:
library/store.m:
library/string.m:
library/time.m:
library/type_desc.m:
java/runtime/*.java:
        Rename package names.

        Delete unnecessary package qualification.

compiler/mlds.m:
        Add some XXXs to be fixed later.

library/Mmakefile:
        Update for new packaging scheme.

        Let mmake --use-mmc-make work in this directory.
2009-06-17 07:48:16 +00:00
Peter Wang
e0a564f0f4 Fix two problems implementation of arrays for Java backend:
Branches: main

Fix two problems implementation of arrays for Java backend:

- array.from_list([1, 2, 3]) didn't work because it would create an Integer[]
  array, but the code generated by the Mercury compiler would try to assign
  it to a int[] variable.  Fix this by special casing the primitive types to
  create arrays with the expected types.

- We used the class of a representative element to determine the type of
  an array to create.  Enumeration types only have the one class
  corresponding to the Mercury type, so the class of the representative
  element is correct.

  However, general d.u. types have subclasses for each functor, so the class
  of a representative element could correspond to a functor.  This meant that
  arrays could only hold more elements with the same functor.  What is needed
  is actually the super class, corresponding to a Mercury type.

  The solution adopted here is to make Java classes corresponding to Mercury
  types implement an interface called `MercuryType'.  Then we can tell
  whether the class or the superclass of the representative element is the
  one needed.


java/runtime/MercuryType.java:
        Add the new interface.

compiler/ml_type_gen.m:
        When the target language is Java, make d.u. parent types implement
        the `MercuryType' interface.

compiler/mlds_to_java.m:
        Make the `MercuryType' interface special so it is printed without an
        arity suffix.

library/array.m:
        Fix the problems with creating/resizing ararys.
2009-06-05 04:17:10 +00:00
Peter Wang
eeec14a8b1 Replace the implementations of (version) hash tables by separate chaining hash
Branches: main

Replace the implementations of (version) hash tables by separate chaining hash
tables.  The old open addressing scheme was broken in the presence of deletes.
Fixes bug #68.

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

	We no longer use double hashing in case of a hash collision, so hash
	predicates only need to return one value now.

	Add fold with predicate arguments.

library/array.m:
	Add array.foldl for a predicate argument.

	Add array.foldl2 with a unique state pair.

library/version_array.m:
	Add version_array.foldl for a predicate argument.

compiler/make.m:
compiler/make.program_target.m:
compiler/make.util.m:
library/robdd.m:
	Conform to change in hashing predicates.

deep_profiler/dense_bitset.m:
	Add module qualifier to avoid ambiguity.

tests/hard_coded/Mmakefile:
tests/hard_coded/hash_table_delete.exp:
tests/hard_coded/hash_table_delete.m:
tests/hard_coded/hash_table_test.exp:
tests/hard_coded/hash_table_test.m:
tests/hard_coded/version_hash_table_delete.exp:
tests/hard_coded/version_hash_table_delete.m:
tests/hard_coded/version_hash_table_test2.exp:
tests/hard_coded/version_hash_table_test2.m:
	Add new test cases.

tests/hard_coded/hash_bug.m:
tests/hard_coded/hash_init_bug.m:
tests/hard_coded/version_hash_table_test.m:
	Conform to change in hashing predicates.

NEWS:
	Document additions.
2009-03-26 06:32:19 +00:00
Paul Bone
421e8c2aa1 Add a foldl2 predicate to the array module in the standard library.
Estimated Hours Taken: 0.25
Branches: main

Add a foldl2 predicate to the array module in the standard library.

library/array.m:
    As above.

NEWS:
    Announce the change.
2008-09-12 10:47:20 +00:00
Peter Wang
24cad543d8 Add structure sharing annotations for "C" foreign_procs.
Estimated hours taken: 0.5
Branches: main

library/array.m:
	Add structure sharing annotations for "C" foreign_procs.
2008-05-09 06:56:04 +00:00
Zoltan Somogyi
672f77c4ec Add a new compiler option. --inform-ite-instead-of-switch.
Estimated hours taken: 20
Branches: main

Add a new compiler option. --inform-ite-instead-of-switch. If this is enabled,
the compiler will generate informational messages about if-then-elses that
it thinks should be converted to switches for the sake of program reliability.

Act on the output generated by this option.

compiler/simplify.m:
	Implement the new option.

	Fix an old bug that could cause us to generate warnings about code
	that was OK in one duplicated copy but not in another (where a switch
	arm's code is duplicated due to the case being selected for more than
	one cons_id).

compiler/options.m:
	Add the new option.

	Add a way to test for the bug fix in simplify.

doc/user_guide.texi:
	Document the new option.

NEWS:
	Mention the new option.

library/*.m:
mdbcomp/*.m:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
	Convert if-then-elses to switches at most of the sites suggested by the
	new option. At the remaining sites, switching to switches would have
	nontrivial downsides. This typically happens with the switched-on type
	has many functors, and we treat one or two specially (e.g. cons/2 in
	the cons_id type).

	Perform misc cleanups in the vicinity of the if-then-else to switch
	conversions.

	In a few cases, improve the error messages generated.

compiler/accumulator.m:
compiler/hlds_goal.m:
	(Rename and) move insts for particular kinds of goal from
	accumulator.m to hlds_goal.m, to allow them to be used in other
	modules. Using these insts allowed us to eliminate some if-then-elses
	entirely.

compiler/exprn_aux.m:
	Instead of fixing some if-then-elses, delete the predicates containing
	them, since they aren't used, and (as pointed out by the new option)
	would need considerable other fixing if they were ever needed again.

compiler/lp_rational.m:
	Add prefixes to the names of the function symbols on some types,
	since without those prefixes, it was hard to figure out what type
	the switch corresponding to an old if-then-else was switching on.

tests/invalid/reserve_tag.err_exp:
	Expect a new, improved error message.
2007-11-23 07:36:01 +00:00
Peter Wang
35a0e5616f Make array.unsafe_lookup and array.unsafe_set part of the public
Branches: main

library/array.m:
	Make array.unsafe_lookup and array.unsafe_set part of the public
	interface so that the user can selectively omit bounds checks.

	Make array.from_list use array.unsafe_set to avoid redundant bounds
	checks.
2007-09-18 01:06:40 +00:00
Ralph Becket
6401388eba Simplify the handling of separators in array_to_doc.
Estimated hours taken: 4 (mostly testing)
Branches: main

library/array.m:
	Simplify the handling of separators in array_to_doc.

library/list.m:
	Simplify the handling of separators in list_to_doc.
	Change the indentation for list docs from two spaces
	to one: if, as is often the case, the opening bracket
	starts a new line, then this slightly improves the look
	of the output.

library/pretty_printer.m:
	Use a new constant `ellipsis' rather than `str("...")'
	throughout.

tests/debugger/browse_pretty.inp:
	Use a larger depth to see the whole term (the new pretty
	printer counts terms in a slightly different - more
	accurate - way to the old one).

tests/hard_coded/test_pretty_printer_defaults.exp:
	Update the expected output.
2007-08-15 06:03:57 +00:00
Ralph Becket
67ec243a51 Define pretty_printer formatters for some common standard library types.
Estimated hours taken: 4
Branches: main

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

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

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

tests/hard_coded/Mmakefile:
tests/hard_coded/test_pretty_printer_defaults.exp:
tests/hard_coded/test_pretty_printer_defaults.m:
	Test case.
2007-08-14 04:21:09 +00:00
Peter Wang
f445f78732 Fix off-by-one error in Erlang implementation of array.unsafe_set.
Estimated hours taken: 0.1
Branches: main

library/array.m:
	Fix off-by-one error in Erlang implementation of array.unsafe_set.
2007-06-12 07:18:31 +00:00
Peter Ross
b397669dad Implement the array module in erlang.
Estimated hours taken: 1
Branches: main

Implement the array module in erlang.

compiler/erl_rtti.m:
compiler/erlang_rtti.m:
	Handle RTTI for an array.

library/array.m:
	Erlang implementation of arrays.

library/erlang_rtti_implementation.m:
	Handle deconstruct of arrays.
2007-06-07 07:53:06 +00:00
Peter Wang
08f82a2f01 Initial version of a HLDS->Erlang code generator.
Estimated hours taken: 50
Branches: main

Initial version of a HLDS->Erlang code generator.  Currently det and semidet
code is supported.  The code generator converts HLDS data structures into a
new ELDS data structure, which is an internal representation of Erlang code.
Then the ELDS data structure is printed out into concrete Erlang syntax.

compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_backend.m:
compiler/erl_call_gen.m:
compiler/erl_code_gen.m:
compiler/erl_code_util.m:
compiler/erl_unify_gen.m:
	New files.

compiler/Mercury.options:
	Add --no-warn-unused-imports for erl_backend package.

compiler/top_level.m:
compiler/mercury_compile.m:
	Import the Erlang backend and call it for --target erlang.

compiler/modules.m:
	Add module_name_to_file_name_sep which is like module_name_to_file_name
	but allows modules to be qualified with a string other than ".".

library/array.m:
library/bitmap.m:
library/io.m:
	Add Erlang foreign_type declarations for array(T), bitmap and
	io.system_error so the compiler doesn't abort when generating
	interface files in the Erlang grade.

compiler/notes/compiler_design.html:
	Describe the Erlang backend.
2007-05-15 02:38:23 +00:00
Simon Taylor
67bcaf3817 Remove the bogus `array' constructor from the insts for arrays.
Estimated hours taken: 0.5
Branches: main

library/array.m:
library/array2d.m:
library/svarray.m:
	Remove the bogus `array' constructor from the insts for arrays.
	Comment out mode declarations that are now duplicates.

tests/hard_coded/Mmakefile:
tests/hard_coded/array_test.{m,exp}:
	Test case.
2007-02-27 02:12:37 +00:00
Ben Schmidt
9cfc93ce1c Fix comment to reference correct file where MR_ArrayPtr is defined.
Estimated hours taken: 0
Branches: main

library/array.m:
	Fix comment to reference correct file where MR_ArrayPtr is defined.
2007-02-01 01:34:19 +00:00
Julien Fischer
7290c64875 This is the second part of Jon Morgan's change that adds support for
Estimated hours taken: 6
Branches: main

This is the second part of Jon Morgan's change that adds support for
IL foreign exports.  This part adds foreign_export declarations for IL
to the standard library.

configure.in:
	Require the installed compiler to support pragma foreign_export
	for IL.

library/*.m:
	Add a foreign_export("IL") for every existing foreign_export("C").

	Convert a couple of `pragma export' statements to `pragma
	foreign_export'.
2007-01-18 07:33:05 +00:00
Zoltan Somogyi
7b7dabb89a Extend this optimization to handle temporaries being both defined in
Estimated hours taken: 12
Branches: main

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

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

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

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

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

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

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

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

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

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

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

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

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

compiler/hlds_pred.m:
	Fix some comment rot.

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

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

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

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

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

tests/invalid/Mmakefile:
	Enable the new test case.
2007-01-15 02:24:04 +00:00
Julien Fischer
9cd94b5c72 Various minor cleanups and syntax updates for the standard library.
Estimated hours taken: 1
Branches: main

Various minor cleanups and syntax updates for the standard library.
There are no changes to any algorithms.

library/injection.m:
library/set.m:
library/sparse_bitset.m:
	Use promise_equivalent_clauses where appropriate.

library/set_ordlist.m:
library/set_unordlist.m:
	Convert these module to 4-space indentation:
		Convert these module to 4-space indentation

library/*.m:
	Convert some if-then-elses into switches.

	Remove unnecessary module qualification - this is related
	mainly to the breakup of std_util and the fact that on
	the 0.13 branche we had two versions of the all-solutions
	predicates.

	Various other style cleanups.

vim/syntax/mercury.vim:
	Highlight promise_equivalent_clauses appropriately.
2006-10-23 00:33:04 +00:00
Julien Fischer
576600811f Prepare for the 0.13 release and fix/update documentation.
Estimated hours taken: 1
Branches: main, release

Prepare for the 0.13 release and fix/update documentation.

NEWS:
HISTORY:
	Update the NEWS and HISTORY files for the 0.13 release.

RELEASE_NOTES:
	s/0.12/0.13/

	Add Linux/x86_64 to the list of architectures supported by this
	release.

	Remove Solaris 8/x86 from the same list.

.README.in:
extras/README:
	Remove references to the clp(r) binding.  We no longer support it.

bindist/bindist.README:
	Update the year in the copyright message.

	Fix the gc version; 0.13 uses 6.5.

BUGS:
README.DotNet:
README.Java:
README.gcc-backend:
doc/faq.texi:
doc/make_manpage:
doc/mercury.html.in:
doc/mercury.info.in:
	s/.cs.mu.oz.au/.csse.unimelb.edu.au/

library/array.m:
library/builtin.m:
library/eqvclass.m:
library/graph.m:
samples/README:
	Fix typos.
2006-09-07 08:32:20 +00:00
Julien Fischer
553fb3f7d9 Use pragma foreign_export' in preference to pragma export' throughout
Estimated hours taken: 1
Branches: main

Use `pragma foreign_export' in preference to `pragma export' throughout
the Mercury distribution.

Convert more of the extras distribution to four-space indentation and
other minor cleanups.

browser/*.m:
library/*.m:
samples/*:
extras/*:
	As above.
2006-08-31 11:09:54 +00:00
Julien Fischer
e0f5ac47db Make it easier for vi to jump past the initial comments
Estimated hours taken: 0.1
Branches: main

library/*.m:
	Make it easier for vi to jump past the initial comments
	at the head of a module.
2006-04-19 05:18:00 +00:00
Julien Fischer
5e92224eec Improve the library reference manual by formatting the beginning of
Estimated hours taken: 0.2
Branches: main, release

library/*.m:
	Improve the library reference manual by formatting the beginning of
	library modules consistently.

library/integer.m:
	Fix some bad indentation.
2006-04-13 06:08:05 +00:00
Julien Fischer
459847a064 Move the univ, maybe, pair and unit types from std_util into their own
Estimated hours taken: 18
Branches: main

Move the univ, maybe, pair and unit types from std_util into their own
modules.  std_util still contains the general purpose higher-order programming
constructs.

library/std_util.m:
	Move univ, maybe, pair and unit (plus any other related types
	and procedures) into their own modules.

library/maybe.m:
	New module.  This contains the maybe and maybe_error types and
	the associated procedures.

library/pair.m:
	New module.  This contains the pair type and associated procedures.

library/unit.m:
	New module. This contains the types unit/0 and unit/1.

library/univ.m:
	New module. This contains the univ type and associated procedures.

library/library.m:
	Add the new modules.

library/private_builtin.m:
	Update the declaration of the type_ctor_info struct for univ.

runtime/mercury.h:
	Update the declaration for the type_ctor_info struct for univ.

runtime/mercury_mcpp.h:
runtime/mercury_hlc_types.h:
	Update the definition of MR_Univ.

runtime/mercury_init.h:
	Fix a comment: ML_type_name is now exported from type_desc.m.

compiler/mlds_to_il.m:
	Update the the name of the module that defines univs (which are
	handled specially by the il code generator.)

library/*.m:
compiler/*.m:
browser/*.m:
mdbcomp/*.m:
profiler/*.m:
deep_profiler/*.m:
	Conform to the above changes.  Import the new modules where they
	are needed; don't import std_util where it isn't needed.

	Fix formatting in lots of modules.  Delete duplicate module
	imports.

tests/*:
	Update the test suite to confrom to the above changes.
2006-03-29 08:09:58 +00:00
Zoltan Somogyi
b293bd999d Replace __ with . as the module qualifier everywhere.
Estimated hours taken: 1
Branches: main

library/*.m:
	Replace __ with . as the module qualifier everywhere.

tests/hard_coded/test_injection.exp:
	Replace __ with . as the module qualifier in expected exceptions.
2006-03-07 22:23:58 +00:00
Julien Fischer
7a8681f774 Annotate foreign_procs with trail usage information throughout most of
Estimated hours taken: 0.5
Branches: main

library/*.m:
	Annotate foreign_procs with trail usage information throughout most of
	the standard library.

	Fix an out of date comment in string.m.

	Fix some minor formatting problems.
2005-12-14 10:33:56 +00:00
Zoltan Somogyi
9cabcbccfa Convert these modules to four space indentation.
Estimated hours taken: 0.2
Branches: main

library/array.m:
library/dir.m:
	Convert these modules to four space indentation.
2005-09-05 07:24:10 +00:00
Zoltan Somogyi
88c7539230 Import only one module per line, as we already do in the compiler
Estimated hours taken: 0.3
Branches: main

library/*.m:
	Import only one module per line, as we already do in the compiler
	directory.
2005-06-16 04:08:07 +00:00
Zoltan Somogyi
4d6975a6fd Fix style.
Estimated hours taken: 0.1
Branches: main

library/array.m:
	Fix style.
2005-04-19 08:38:13 +00:00
Julien Fischer
be08ab4736 Add some synonyms for various functions in the string module
Estimated hours taken: 1
Branches: main, release

Add some synonyms for various functions in the string module
and make some more general cleanups to parts of the standard library.

library/array.m:
	s/applys/applies/

library/list.m:
	Position descriptive comments according to our coding
	standard.

	Fix a cut and paste error.  list.foldl6 has six accumulators
	not five.

library/parser.m:
library/pqueue.m:
library/set_bbbtree.m:
library/set_ctree234.m:
	Fix minor formatting problems and spelling mistakes.

library/string.m:
	Add functions string.from_int/1, string.from_char/1
	and string.from_float/1 as synonyms for string.int_to_string/1
	etc.

library/version_types.m:
	s/incurrs/incurs/
2005-02-28 03:39:38 +00:00
Ralph Becket
d0bd460b8f Minor reformatting; added some renamed preds and funcs to improve
Estimated hours taken: 3
Branches: main, version-0_12-branch

library/array.m:
library/array2d.m:
library/assoc_list.m:
library/bag.m:
library/benchmarking.m:
library/bimap.m:
library/bintree_set.m:
library/bitmap.m:
library/bool.m:
library/builtin.m:
library/cord.m:
library/float.m:
library/graph.m:
library/group.m:
library/hash_table.m:
library/int.m:
library/lexer.m:
library/list.m:
library/map.m:
library/math.m:
library/multi_map.m:
library/ops.m:
library/parser.m:
library/rbtree.m:
library/set.m:
library/stack.m:
library/store.m:
library/string.m:
library/time.m:
	Minor reformatting; added some renamed preds and funcs to improve
	consistency of naming in the library; removed some preds and types that
	have been marked obsolete since 0.11.
2005-02-02 04:28:50 +00:00
Julien Fischer
b13a50c7f6 Make the positioning of descriptive comments conform
Estimated hours taken: 3.5
Branches: main

Make the positioning of descriptive comments conform
to the coding standard for the following library modules.

Convert preds to predmode syntax where possible.

Make the ordering of related predicates and functions
conform to the coding standard, where the descriptive
comment makes it possible to do that.

Other minor changes are listed below.

library/bimap.m:
	Fix capitalisation of a few comments.

library/dir.m:
	s/throw an exception/throws an exception/.

library/exception.m:
	Fix the comment about the exception_result/1 type.
	There is only one type and an inst following the comment.

library/map.m:
	Remove the unique modes for map.set/4, map.delete/3 and
	map.delete_list/3.

library/rbtree.m:
	Remove the unique modes for rbtree.set/4, rbtree.delete/3,
	rbtree.remove/4, rbtree.remove_smallest/4 and rbtree.remove_largest/4.

library/tree234.m:
	Remove left over unique modes for preds.

library/set.m:
	XXX the ordering of procedures in this module is a bit strange.
library/set_bbbtree.m:
library/set_unordlist.m:
	Remove various unique modes for set operations like
	delete/3.  (Some of these were commented out anyway).

library/term_to_xml.m:
	Fix a spot where line width exceeded 79 characters.

library/array.m:
library/assoc_list.m:
library/random.m:
library/multi_map.m:
library/pqueue.m:
library/queue.m:
library/bool.m:
library/char.m:
library/construct.m:
library/counter.m:
library/deconstruct.m:
library/eqvclass.m:
library/gc.m:
library/io.m:
library/sparse_bitset.m:
library/stack.m:
library/std_util.m:
library/store.m:
library/string.m:
library/term.m:
library/term_io.m:
library/type_desc.m:
library/varset.m:
	As above.
2005-01-24 23:16:40 +00:00
Julien Fischer
3e19c2fad6 Improve the termination analyser's handling of user-defined
Estimated hours taken: 20
Branches: main

Improve the termination analyser's handling of user-defined
special predicates.

Currently termination analysis assumes that all calls
to special predicates terminate.  For those that are
user-defined this is not necessarily true.

This diff adds a new pass to the compiler that is run after
the main termination analysis pass. It checks any user-defined
special predicates and emits a warning if their termination
can not be proved.

Add a new option, `--no-warn-non-term-special-preds' that
disables this warning.  The warning is only emitted when
termination analysis is enabled.  The new option has
no effect if termination analysis is not enabled.

compiler/post_term_analysis.m:
	New file.  Add an additional pass that runs after the main
	termination analysis and makes use of the information obtained
	then to perform further semantic checks and optimizations.

compiler/termination.m:
	Run the new pass after the main analysis.

	Update the comment about the termination analyser doing the
	wrong thing for user-defined special predicates.

compiler/options.m:
	Parse the new option.

	Update the special handler for the inhibit_warning
	option so that it handles `--warn-table-with-inline'
	and the new option correctly.

	Fix some typos.

compiler/transform_hlds.m:
	Include the new module.

compiler/notes/compiler_design.html:
	Mention the new module.

doc/user_guide.texi:
	Document the new option.

	Fix some typos: s/occured/occurred/,
	s/interative/interactive/, s/exlained/explained/
	and /currect/current/

library/array.m:
library/version_array.m:
	Add pragma terminates declarations to the user-defined
	equality and comparison predicates for the array/1
	and version_array/1 types.  The termination analyser
	cannot (yet) prove termination in these cases because
	it cannot reason about iteration over arrays.

tests/warnings/Mercury.options:
tests/warnings/Mmakefile:
tests/warnings/warn_non_term_user_special.m:
tests/warnings/warn_non_term_user_special.exp:
	Test the new option.
2005-01-22 06:10:55 +00:00
Zoltan Somogyi
c11cc1eba7 Fix formatting.
Estimated hours taken: 0.1
Branches: main

library/array.m:
library/list.m:
library/tree234.m:
	Fix formatting.
2004-09-28 02:09:14 +00:00
Julien Fischer
57bfcbfc65 Replace the deprecated syntax for :- inst and :- mode
Estimated hours taken: 0.5
Branches: main

library/array.m:
library/builtin.m:
library/getopt.m:
library/io.m:
library/list.m:
library/tree234.m:
	Replace the deprecated syntax for :- inst and :- mode
	declarations.
2004-07-19 04:36:13 +00:00
Julien Fischer
2f6b963ed5 Remove a redundant promise_pure pragma on array.max/2.
Estimated hours taken: 0.1
Branches: main

library/array.m:
	Remove a redundant promise_pure pragma on array.max/2.
	All the foreign clauses are promised pure anyway.
2004-07-08 05:03:06 +00:00
Zoltan Somogyi
8190c16181 Get Mercury to work with gcc 3.4. This required fixing several problems.
Estimated hours taken: 16
Branches: main

Get Mercury to work with gcc 3.4. This required fixing several problems.

One problem that caused errors is that gcc 3.4 is smart enough to figure out
that in LLDS grades with gcc gotos, the C functions containing our code are
not referred to, and so it optimizes them away. The fix is to ensure that
mercury_<module>_init is defined always to call those functions, even if
the macro that usually controls this, MR_MAY_NEED_INITIALIZATION, is not
defined. The mercury_<module>_init won't be called from the init_modules
function in the program's _init.c file, so there is no impact on initialization
time, but gcc doesn't know this when compiling a module's .c file, so
it doesn't optimize away the code we need. The cost of this change is thus
only a small amount of code space. It is worth paying this cost even with
compilers other than gcc 3.4 for simplicity. Actually, this size increase seems
to be slightly smaller than the size reduction due to the better optimization
capabilities of gcc 3.4 compared to gcc 3.2.2.

A second problem is that gcc 3.4 warns about casts in lvalues being a
deprecated feature. This gave lots of warnings, since we used to define
several Mercury abstract machine registers, including MR_succip, MR_hp, MR_sp,
MR_maxfr and MR_curfr using lvalue casts. The fix is to have two macros
for each of these abstract machine registers, one of type MR_Word that you can
assign to (e.g. MR_sp_word), and one of the original type that is of the right
type but not an lvalue (e.g. MR_sp). The lvalue itself can't be made the right
type, because MR_sp isn't a variable in its own right, but possibly defined
to be a machine register. The machine register could made the right type,
but only at the cost of a lot of complexity.

This problem doesn't apply to the special-purpose Mercury abstract machine
registers that can't be allocated to machine registers. Instead of #defining
these to slots in MR_fake_reg, we make them global variables of the natural
type. This should also make it easier to debug code using these registers.
We treat these global variables as if they were machine registers in that
MR_save_registers copies values from these global variables to slots reserved
for them in the MR_fake_reg array, to allow code to loop over all Mercury
abstract machine registers. These saved slots must of course be of type
MR_Word, so we again need two macros to refer to them, a lvalue of type
MR_Word and an rvalue with the right type.

A third problem is that gcc 3.4 warns about conditionals in lvalues being a
deprecated feature. This gave a few warnings, since we used to define
MR_virtual_reg and MR_saved_reg using lvalues using conditionals. The fix
is to have one macro (MR_virtual_reg_value) for use in rvalues and a
separate macro which uses an if-then-else instead of a conditional
expression (MR_virtual_reg_assign), for assignments.

A fourth problem is that gcc 3.4 warns about comma operators in lvalues
being a deprecated feature. This gave warnings in the few places where
we refer to MR_r(N) for values of N that can map to fake registers directly,
since in those cases we preceded the reference to the fake_reg array with
a range check of the array index. The fix to this is to move the test to
compile time for compiler-generated code. Hand-written code never refers
to MR_r(N) for these values, and is very unlikely to do so in the future;
instead, it refers to the underlying fake_reg array directly, since that way
it doesn't have to worry about which fake registers have their own MR_rN macro
and which don't. Therefore no check mechanism for hand-written code is
necessary. This change mean that changing the number of MR_rN registers
now requires change to the compiler as well as to the runtime system.

A fifth problem is that gcc 3.4 by default assumes -fstrict-aliasing at -O2.
Since we cast between integers and pointers of different types all the time,
and changing that is not practical, at least in the short term, we need to
disable -fstrict-aliasing when we enable -O2.

NEWS:
	Note that Mercury now works with gcc 3.4.

configure.in:
scripts/mgnuc.in:
	Detect whether the compiler supports -fstrict-aliasing, and if so,
	whether it assumes it by default with -O2. If the answer is yes to
	both, make mgnuc specify -fno-strict-aliasing when it specifies -O2.
	By including it in CFLAGS_FOR_OPT, which gets put into Mercury.config,
	we also get -f-no-strict-aliasing when mmc invokes the C compiler
	directly.

compiler/llds_out.m:
	Don't generate #ifdef MR_MAY_NEED_INITIALIZATION around the definitions
	and calls to the bunch functions, which call the functions we don't
	want the C compiler to optimize away.

	Generate the newly required lvalues on the left sides of assignments.

	We still have code to generate LVALUE_CASTs in some cases, but I don't
	think those cases ever arise.

	Add a compile-time check of register numbers. Ideally, the code
	generator should use stack slots instead of registers beyond the max
	number, but I don't recall us ever bumping into this limit by accident.

compiler/fact_table.m:
	Use the newly required lvalues on the left sides of assignments
	in some hand-written C code included in generated .c files.

runtime/mercury_regs.h:
	Make the changes described above to fix the second, third and fourth
	problems. We still use comma operators in lvalues when counting
	references to registers, but it is OK to require anyone who wants
	to enable this feature to use a compiler version that supports comma
	operators in lvalues or to ignore the warnings.

	Use the same mapping from Mercury abstract machine registers to
	the register count array as to the MR_fake_reg array.

	Have this mapping depend as little as possible on whether we need a
	real machine register to store MR_engine base, even if it costs a
	wasted slot in MR_fake_reg.

	Fix an old inconsistency: treat the Mercury abstract machine registers
	used for trailing the same way as the other Mercury abstract machine
	registers, by making MR_save_registers/MR_restore_registers copy them
	to and from their global variable homes.

	Document the requirement for the match between the runtime's and the
	compiler's notions of the maximum MR_rN register number. This
	requirement makes it harder for users to increase the number of
	virtual registers, but as far as I know noone has wanted to do this.

	Change the names of some of the macros to make them clearer.

	Reorder some parts of this file, and add some documentation, also
	in the interest of clarity.

runtime/mercury_regorder.h:
	Delete this file after moving its contents, in much modified form,
	to mercury_regs.h. mercury_regorder.h was always logically part of
	mercury_regs.h, but was separated out to make it easier to change
	the mapping from Mercury abstract machine registers to machine
	registers. However, the cost of incompatibility caused by any such
	changes would be much greater that any likely performance benefit.

runtime/Mmakefile:
	Remove the reference to mercury_regorder.h.

runtime/mercury_regs.[ch]:
runtime/mercury_memory_zones.[ch]:
	Move some functionality dealing with registers from
	mercury_memory_zones to mercury_regs, since it belongs there.

runtime/mercury_regs.[ch]:
	Add a function to make it easiler to debug changes to map from
	Mercury abstract machine to MR_fake_reg slots.

runtime/mercury_regs.[ch]:
runtime/mercury_wrapper.c:
	Move the code to print counts of register uses from mercury_wrapper.c
	to mercury_regs.c.

	Make mercury_wrapper.c call the debugging function in mercury_regs.c
	if -X is specified in MERCURY_OPTIONS.

runtime/mercury_bootstrap.h:
	Move the old MR_saved_reg and MR_virtual_reg macros from mercury_regs.h
	to mercury_bootstrap.h to prevent their accidental use. Since
	they shouldn't be used by user code, move them to the section
	that is not enabled by default.

runtime/mercury_stacks.[ch]:
	Add _word versions of the macros for stack slots, for the same reason
	why we need them for Mercury abstract machine registers, and use them.

	Add global variables for the Mercury abstract machine registers
	for the gen, cut and pneg stacks.

runtime/mercury_heap.h:
	Change the macros for allocating memory to assign to MR_hp_word instead
	of MR_hp.

runtime/mercury_string.h:
	Change the macros for allocating strings to accomodate the updates to
	mercury_heap.h. Also change the expected type of the target to make it
	MR_String instead of MR_ConstString, since the latter requires casts in
	the caller.

runtime/mercury_trail.h:
runtime/mercury_types.h:
	Move the definition of the type MR_TrailEntry from mercury_trail.h
	to mercury_types.h, since it is now used in mercury_regs.h.

runtime/mercury_accurate_gc.c:
runtime/mercury_agc_debug.c:
runtime/mercury_calls.h:
runtime/mercury_context.[ch]:
runtime/mercury_deconstruct_macros.h:
runtime/mercury_deep_copy_body.h:
runtime/mercury_engine.[ch]:
runtime/mercury_hand_compare_body.h:
runtime/mercury_hand_unify_body.h:
runtime/mercury_ho_call.c:
runtime/mercury_layout_util.c:
runtime/mercury_make_type_info_body.h:
runtime/mercury_minimal_model.c:
runtime/mercury_ml_deconstruct_body.h:
runtime/mercury_ml_functor_body.h:
runtime/mercury_stack_layout.h:
runtime/mercury_type_desc.c:
runtime/mercury_type_info.c:
runtime/mercury_unify_compare_body.h:
runtime/mercury_wrapper.c:
	Conform to the changes in the rest of the runtime.

	In some cases, fix inconsistencies in indentation.

runtime/mercury_stack_trace.c:
	Add some conditionally compiled debugging code controlled by the macro
	MR_ADDR_DEBUG, to help debug some problems with stored stack pointers.

runtime/mercury_grade.h:
	Increment the binary compatibility version number. This is needed to
	avoid potential problems when a Mercury module and the debugger are
	compiled with different versions of the macros in mercury_regs.h.

library/exception.m:
	Update the code that assigns to abstract machine registers.

library/array.m:
library/construct.m:
library/dir.m:
library/io.m:
library/string.m:
	Conform to the new definitions of allocation macros.

library/time.m:
	Delete an unnecessary #include.

trace/mercury_trace.c:
trace/mercury_trace_declarative.c:
trace/mercury_trace_util.c:
	Conform to the changes in the rest of the runtime.

tests/hard_coded/qual_test_is_imported.m:
tests/hard_coded/aditi_private_builtin.m:
	Remove an unnecessary import to avoid a warning.

tools/makebatch:
	Add an option --save-stage2-on-error, that saves the stage2 directory
	if a bootcheck fails.

scripts/ml.in:
	Make ml more robust in the face of garbage files.
2004-07-07 07:11:22 +00:00
Zoltan Somogyi
6909674f14 Bring these modules up to date with our current style guidelines.
Estimated hours taken: 8
Branches: main

library/*.m:
	Bring these modules up to date with our current style guidelines.
	Use predmode declarations where appropriate. Use state variable syntax
	where appropriate. Reorder arguments where this makes it possible to
	to use state variable syntax. Standardize format of predicate
	description comments. Standardize indentation.
2004-03-15 23:49:36 +00:00
James Goddard
6b6c5e9c65 Implement some library procedures for the Java back end.
Estimated hours taken: 5
Branches: main

Implement some library procedures for the Java back end.

library/array.m:
	Implement the following procedures:
		bounds_checks/0
		array__init_2/3
		array__make_empty_array/1
		array__min/2
		array__max/2
		array__size/2
		array__unsafe_lookup/3
		array__unsafe_set/4
		array__resize/4
		array__shrink_2/3
		array__copy/2
2004-01-09 03:16:58 +00:00
Fergus Henderson
aabf9e0d5b Provide Java `pragma foreign_type' declarations for the types
Estimated hours taken: 0.5
Branches: main

library/array.m:
library/io.m:
	Provide Java `pragma foreign_type' declarations for the types
	array.array(T) and io.system_error.  This is needed to avoid
	compilation errors when building in grade `java'.
2003-11-27 13:27:03 +00:00
Peter Ross
d28ac0ec53 Begin porting the the library just to use C# as its foreign_proc
Estimated hours taken: 2
Branches: main

Begin porting the the library just to use C# as its foreign_proc
language.

library/array.m:
library/char.m:
library/exception.m:
library/float.m:
library/int.m:
library/math.m:
library/private_builtin.m:
library/rtti_implementation.m:
library/std_util.m:
	Trivial changes to convert MC++ to C#.

library/table_builtin.m:
	Delete some unused MC++ functions.
2003-11-07 16:51:36 +00:00
Zoltan Somogyi
f007b45df8 Implement the infrastructure for term size profiling.
Estimated hours taken: 400
Branches: main

Implement the infrastructure for term size profiling. This means adding two
new grade components, tsw and tsc, and implementing them in the LLDS code
generator. In grades including tsw (term size words), each term is augmented
with an extra word giving the number of heap words it contains; in grades
including tsc (term size cells), each term is augmented with an extra word
giving the number of heap cells it contains. The extra word is at the start,
at offset -1, to leave almost all of the machinery for accessing the heap
unchanged.

For now, the only way to access term sizes is with a new mdb command,
"term_size <varspec>". Later, we will use term sizes in conjunction with
deep profiling to do experimental complexity analysis, but that requires
a lot more research. This diff is a necessary first step.

The implementation of term size profiling consists of three main parts:

- a source-to-source transform that computes the size of each heap cell
  when it is constructed (and increments it in the rare cases when a free
  argument of an existing heap cell is bound),

- a relatively small change to the code generator that reserves the extra
  slot in new heap cells, and

- extensions to the facilities for creating cells from C code to record
  the extra information we now need.

The diff overhauls polymorphism.m to make the source-to-source transform
possible. This overhaul includes separating type_ctor_infos and type_infos
as strictly as possible from each other, converting type_ctor_infos into
type_infos only as necessary. It also includes separating type_ctor_infos,
type_infos, base_typeclass_infos and typeclass_infos (as well as voids,
for clarity) from plain user-defined type constructors in type categorizations.
This change needs this separation because values of those four types do not
have size slots, but they ought to be treated specially in other situations
as well (e.g. by tabling).

The diff adds a new mdb command, term_size. It also replaces the proc_body
mdb command with new ways of using the existing print and browse commands
("print proc_body" and "browse proc_body") in order to make looking at
procedure bodies more controllable. This was useful in debugging the effect
of term size profiling on some test case outputs. It is not strictly tied
to term size profiling, but turns out to be difficult to disentangle.

compiler/size_prof.m:
	A new module implementing the source-to-source transform.

compiler/notes/compiler_design.html:
	Mention the new module.

compiler/transform_hlds.m:
	Include size_prof as a submodule of transform_hlds.

compiler/mercury_compile.m:
	If term size profiling is enabled, invoke its source-to-source
	transform.

compiler/hlds_goal.m:
	Extend construction unifications with an optional slot for recording
	the size of the term if the size is a constant, or the identity of the
	variable holding the size, if the size is not constant. This is
	needed by the source-to-source transform.

compiler/quantification.m:
	Treat the variable reference that may be in this slot as a nonlocal
	variable of construction unifications, since the code generator needs
	this.

compiler/compile_target_code.m:
	Handle the new grade components.

compiler/options.m:
	Implement the options that control term size profiling.

doc/user_guide.texi:
	Document the options and grade components that control term size
	profiling, and the term_size mdb command. The documentation is
	commented out for now.

	Modify the wording of the 'u' HLDS dump flag to include other details
	of unifications (e.g. term size info) rather than just unification
	categories.

	Document the new alternatives of the print and browse commands. Since
	they are for developers only, the documentation is commented out.

compiler/handle_options.m:
	Handle the implications of term size profiling grades.

	Add a -D flag value to print HLDS components relevant to HLDS
	transformations.

compiler/modules.m:
	Import the new builtin library module that implements the operations
	needed by term size profiling automatically in term size profiling
	grades.

	Switch the predicate involved to use state var syntax.

compiler/prog_util.m:
	Add predicates and functions that return the sym_names of the modules
	needed by term size profiling.

compiler/code_info.m:
compiler/unify_gen.m:
compiler/var_locn.m:
 	Reserve an extra slot in heap cells and fill them in in unifications
	marked by size_prof.

compiler/builtin_ops.m:
	Add term_size_prof_builtin.term_size_plus as a builtin, with the same
	implementation as int.+.

compiler/make_hlds.m:
	Disable warnings about clauses for builtins while the change to
	builtin_ops is bootstrapped.

compiler/polymorphism.m:
	Export predicates that generate goals to create type_infos and
	type_ctor_infos to add_to_construct.m. Rewrite their documentation
	to make it more detailed.

	Make orders of arguments amenable to the use of state variable syntax.

	Consolidate knowledge of which type categories have builtin unify and
	compare predicates in one place.

	Add code to leave the types of type_ctor_infos alone: instead of
	changing their types to type_info when used as arguments of other
	type_infos, create a new variable of type type_info instead, and
	use an unsafe_cast. This would make the HLDS closer to being type
	correct, but this new code is currently commented out, for two
	reasons. First, common.m is currently not smart enough to figure out
	that if X and Y are equal, then similar unsafe_casts of X and Y
	are also equal, and this causes the compiler do not detect some
	duplicate calls it used to detect. Second, the code generators
	are also not smart enough to know that if Z is an unsafe_cast of X,
	then X and Z do not need separate stack slots, but can use the same
	slot.

compiler/type_util.m:
	Add utility predicates for returning the types of type_infos and
	type_ctor_infos, for use by new code in polymorphism.m.

	Move some utility predicates here from other modules, since they
	are now used by more than one module.

	Rename the type `builtin_type' as `type_category', to better reflect
	what it does. Extend it to put the type_info, type_ctor_info,
	typeclass_info, base_typeclass_info and void types into categories
	of their own: treating these types as if they were a user-defined
	type (which is how they used to be classified) is not always correct.
	Rename the functor polymorphic_type to variable_type, since types
	such as list(T) are polymorphic, but they fall into the user-defined
	category. Rename user_type as user_ctor_type, since list(int) is not
	wholly user-defined but falls into this category. Rename pred_type
	as higher_order_type, since it also encompasses functions.

	Replace code that used to check for a few of the alternatives
	of this type with code that does a full switch on the type,
	to ensure that they are updated if the type definition ever
	changes again.

compiler/pseudo_type_info.m:
	Delete a predicate whose updated implementation is now in type_util.m.

compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
	Still treat type_infos, type_ctor_infos, typeclass_infos and
	base_typeclass_infos as user-defined types, but prepare for when
	they won't be.

compiler/hlds_pred.m:
	Require interface typeinfo liveness when term size profiling is
	enabled.

	Add term_size_profiling_builtin.increase_size as a
	no_type_info_builtin.

compiler/hlds_out.m:
	Print the size annotations on unifications if HLDS dump flags call
	for unification details. (The flag test is in the caller of the
	modified predicate.)

compiler/llds.m:
	Extend incr_hp instructions and data_addr_consts with optional fields
	that allow the code generator to refer to N words past the start of
	a static or dynamic cell. Term size profiling uses this with N=1.

compiler/llds_out.m:
	When allocating memory on the heap, use the macro variants that
	specify an optional offset, and specify the offset when required.

compiler/bytecode_gen.m:
compiler/dense_switch.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/goal_form.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/inst_match.m:
compiler/intermod.m:
compiler/jumpopt.m:
compiler/lambda.m:
compiler/livemap.m:
compiler/ll_pseudo_type_info.m:
compiler/lookup_switch.m:
compiler/magic_util.m:
compiler/middle_rec.m:
compiler/ml_code_util.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/modecheck_unify.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/par_conj_gen.m:
compiler/post_typecheck.m:
compiler/reassign.m:
compiler/rl.m:
compiler/rl_key.m:
compiler/special_pred.m:
compiler/stack_layout.m:
compiler/static_term.m:
compiler/string_switch.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unused_args.m:
compiler/use_local_vars.m:
	Minor updates to conform to the changes above.

library/term_size_prof_builtin.m:
	New module containing helper predicates for term size profiling.
	size_prof.m generates call to these predicates.

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

doc/Mmakefile:
	Do not include the term_size_prof_builtin module in the library
	documentation.

library/array.m:
library/benchmarking.m:
library/construct.m:
library/deconstruct.m:
library/io.m:
library/sparse_bitset.m:
library/store.m:
library/string.m:
	Replace all uses of MR_incr_hp with MR_offset_incr_hp, to ensure
	that we haven't overlooked any places where offsets may need to be
	specified.

	Fix formatting of foreign_procs.

	Use new macros defined by the runtime system when constructing
	terms (which all happen to be lists) in C code. These new macros
	specify the types of the cell arguments, allowing the implementation
	to figure out the size of the new cell based on the sizes of its
	fields.

library/private_builtin.m:
	Define some constant type_info structures for use by these macros.
	They cannot be defined in the runtime, since they refer to types
	defined in the library (list.list and std_util.univ).

util/mkinit.c:
	Make the addresses of these type_info structures available to the
	runtime.

runtime/mercury_init.h:
	Declare these type_info structures, for use in mkinit-generated
	*_init.c files.

runtime/mercury_wrapper.[ch]:
	Declare and define the variables that hold these addresses, for use
	in the new macros for constructing typed lists.

	Since term size profiling can refer to a memory cell by a pointer
	that is offset by one word, register the extra offsets with the Boehm
	collector if is being used.

	Document the incompatibility of MR_HIGHTAGS and the Boehm collector.

runtime/mercury_tags.h:
	Define new macros for constructing typed lists.

	Provide macros for preserving the old interface presented by this file
	to the extent possible. Uses of the old MR_list_cons macro will
	continue to work in grades without term size profiling. In term
	size profiling grades, their use will get a C compiler error.

	Fix a bug caused by a missing backslash.

runtime/mercury_heap.h:
	Change the basic macros for allocating new heap cells to take
	an optional offset argument. If this is nonzero, the macros
	increment the returned address by the given number of words.
	Term size profiling specifies offset=1, reserving the extra
	word at the start (which is ignored by all components of the
	system except term size profiling) for holding the size of the term.

	Provide macros for preserving the old interface presented by this file
	to the extent possible. Since the old MR_create[123] and MR_list_cons
	macros did not specify type information, they had to be changed
	to take additional arguments. This affects only hand-written C code.

	Call new diagnostic macros that can help debug heap allocations.

	Document why the macros in this files must expand to expressions
	instead of statements, evn though the latter would be preferable
	(e.g. by allowing them to declare and use local variables without
	depending on gcc extensions).

runtime/mercury_debug.[ch]:
	Add diagnostic macros to debug heap allocations, and the functions
	behind them if MR_DEBUG_HEAP_ALLOC is defined.

	Update the debugging routines for hand-allocated cells to print the
	values of the term size slot as well as the other slots in the relevant
	grades.

runtime/mercury_string.h:
	Provide some needed variants of the macro for copying strings.

runtime/mercury_deconstruct_macros.h:
runtime/mercury_type_info.c:
	Supply type information when constructing terms.

runtime/mercury_deep_copy_body.h:
	Preserve the term size slot when copying terms.

runtime/mercury_deep_copy_body.h:
runtime/mercury_ho_call.c:
runtime/mercury_ml_expand_body.h:
	Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
	that allocate cells also allocate space for the term size slot if
	necessary.

	Reduce code duplication by using a now standard macro for copying
	strings.

runtime/mercury_grade.h:
	Handle the two new grade components.

runtime/mercury_conf_param.h:
	Document the C macros used to control the two new grade components,
	as well as MR_DEBUG_HEAP_ALLOC.

	Detect incompatibilities between high level code and profiling.

runtime/mercury_term_size.[ch]:
	A new module to house a function to find and return term sizes
	stored in heap cells.

runtime/mercury_proc_id.h:
runtime/mercury_univ.h:
	New header files. mercury_proc_id.h contains the (unchanged)
	definition of MR_Proc_Id, while mercury_univ.h contains the
	definitions of the macros for manipulating univs that used to be
	in mercury_type_info.h, updated to use the new macros for allocating
	memory.

	In the absence of these header files, the following circularity
	would ensue:

	mercury_deep_profiling.h includes mercury_stack_layout.h
		- needs definition of MR_Proc_Id
	mercury_stack_layout.h needs mercury_type_info.h
		- needs definition of MR_PseudoTypeInfo
	mercury_type_info.h needs mercury_heap.h
		- needs heap allocation macros for MR_new_univ_on_hp
	mercury_heap.h includes mercury_deep_profiling.h
		- needs MR_current_call_site_dynamic for recording allocations

	Breaking the circular dependency in two places, not just one, is to
	minimize similar problems in the future.

runtime/mercury_stack_layout.h:
	Delete the definition of MR_Proc_Id, which is now in mercury_proc_id.h.

runtime/mercury_type_info.h:
	Delete the macros for manipulating univs, which are now in
	mercury_univ.h.

runtime/Mmakefile:
	Mention the new files.

runtime/mercury_imp.h:
runtime/mercury.h:
runtime/mercury_construct.c:
runtime/mercury_deep_profiling.h:
	Include the new files at appropriate points.

runtime/mercury.c:
	Change the names of the functions that create heap cells for
	hand-written code, since the interface to hand-written code has
	changed to include type information.

runtime/mercury_tabling.h:
	Delete some unused macros.

runtime/mercury_trace_base.c:
runtime/mercury_type_info.c:
	Use the new macros supplying type information when constructing lists.

scripts/canonical_grade_options.sh-subr:
	Fix an undefined sh variable bug that could cause error messages
	to come out without identifying the program they were from.

scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/canonical_grade_options.sh-subr:
scripts/mgnuc.in:
	Handle the new grade components and the options controlling them.

trace/mercury_trace_internal.c:
	Implement the mdb command "term_size <varspec>", which is like
	"print <varspec>", but prints the size of a term instead of its value.
	In non-term-size-profiling grades, it prints an error message.

	Replace the "proc_body" command with optional arguments to the "print"
	and "browse" commands.

doc/user_guide.tex:
	Add documentation of the term_size mdb command. Since the command is
	for implementors only, and works only in grades that are not yet ready
	for public consumption, the documentation is commented out.

	Add documentation of the new arguments of the print and browse mdb
	commands. Since they are for implementors only, the documentation
	is commented out.

trace/mercury_trace_vars.[ch]:
	Add the functions needed to implement the term_size command, and
	factor out the code common to the "size" and "print"/"browse" commands.

	Decide whether to print the name of a variable before invoking the
	supplied print or browse predicate on it based on a flag design for
	this purpose, instead of overloading the meaning of the output FILE *
	variable. This arrangement is much clearer.

trace/mercury_trace_browse.c:
trace/mercury_trace_external.c:
trace/mercury_trace_help.c:
	Supply type information when constructing terms.

browser/program_representation.m:
	Since the new library module term_size_prof_builtin never generates
	any events, mark it as such, so that the declarative debugger doesn't
	expect it to generate any.

	Do the same for the deep profiling builtin module.

tests/debugger/term_size_words.{m,inp,exp}:
tests/debugger/term_size_cells.{m,inp,exp}:
	Two new test cases, each testing one of the new grades.

tests/debugger/Mmakefile:
	Enable the two new test cases in their grades.

	Disable the tests sensitive to stack frame sizes in term size profiling
	grades.

tests/debugger/completion.exp:
	Add the new "term_size" mdb command to the list of command completions,
	and delete "proc_body".

tests/debugger/declarative/dependency.{inp,exp}:
	Use "print proc_body" instead of "proc_body".

tests/hard_coded/nondet_c.m:
tests/hard_coded/pragma_inline.m:
	Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
	that allocate cells also allocate space for the term size slot if
	necessary.

tests/valid/Mmakefile:
	Disable the IL tests in term size profiling grades, since the term size
	profiling primitives haven't been (and probably won't be) implemented
	for the MLDS backends, and handle_options causes a compiler abort
	for grades that combine term size profiling and any one of IL, Java
	and high level C.
2003-10-20 07:29:59 +00:00
Julien Fischer
0361ac54fa Fix some spelling errors in documentation/comments.
Estimated hours taken: 0.1
Branches: main

library/array.m:
library/bt_array.m:
library/io.m:
library/math.m:
library/store.m:
	Fix some spelling errors in documentation/comments.
2003-08-28 06:56:51 +00:00
Peter Moulder
e367fd11f2 Improve completeness guarantees by using if-then-else's to ensure that
Estimated hours taken: 0.5

library/array.m:
	Improve completeness guarantees by using if-then-else's to ensure that
	operations that can throw an exception are really conditional on bounds
	checks.
	This also allows us to call the `unsafe' (unchecked) versions directly.
2003-08-18 05:17:45 +00:00
Zoltan Somogyi
70d2f0d8c2 Have the compiler define the RTTI of the array type, instead of having
Estimated hours taken: 3
Branches: main

Have the compiler define the RTTI of the array type, instead of having
it be handwritten.

library/array.m:
	Add a type definition for the array type, making it a foreign type
	(MR_ArrayPtr) with the existing predicates array_equal and
	array_compare as its unify and compare preds.

	Change array_compare to return the result as uo, not out,
	to make this possible.

	Delete all the hand-written code and data structures needed by
	RTTI, since they are now compiler-generated.

	Delete the old casts from MR_Word to MR_ArrayType *, since
	they are now not needed (MR_ArrayPtr is defined as MR_ArrayType *).

	Add a macro to centralize the LVALUE_CAST we now need when calling
	MR_incr_hp_msg (which assumes that it assigning to an MR_Word).

compiler/mlds_to_c.m:
	Generate MR_ArrayPtr instead of MR_Array for array/1.

compiler/mlds.m:
	Back out my earlier change to mlds.m, since it isn't needed for
	bootstrapping anymore.

runtime/mercury_library_types.h:
runtime/mercury_types.h:
	Move the definitions of MR_ArrayType, MR_ArrayPtr and MR_ConstArrayPtr
	from mercury_library_types to mercury_types, since they can now be
	referred to from any compiler-generated C file in high level C grades.
2003-06-11 12:55:59 +00:00