Prior to 2009 some of the standard library predicates were implemented using
Java native methods. These were disabled or replaced by commit 9fc47f5c in
order to give us pure Java versions of the runtime and standard libraries.
However, the machinery for supporting native methods was left in place. This
change deletes that machinery. We are not going to use it again.
library/Mmakefile:
Do not build Native.so. (From the looks of it we never installed it
anyway.)
java/runtime/Native.c:
Delete the C implementations of the native methods ...
java/runtime/Native.java.in:
... and the corresponding Java support for them.
java/runtime/Mmakefile:
Delete this Mmakefile, there is no longer anything for it to do.
configure.ac:
Do not create Native.java.
library/thread.m:
Implement spawn_native_joinable and join_thread for C# and Java.
Rename the existing Java helper class RunGoal to RunGoalDetached.
Add RunGoalJoinable.
Rename the C# helper MercuryThread to RunGoalDetached, to match the
Java backend. Add RunGoalJoinable.
java/runtime/MercuryThreadPool.java:
Replace submitExclusiveThread() method with createExclusiveThread(),
which returns the newly created thread, without starting it.
Add MercuryFatalError, a new Java exception that is intended to be used for a
similar purpose to the C runtime's MR_fatal_error() function.
Throw a MercuryFatalError exception instead of calling System.exit() in a spot.
Calling exit() is fine for executables, but for code that is deployed in an
application server calling exit() may shut down the entire server.
java/runtime/MercuryFatalError.java:
Add the new exception.
java/runtime/MercuryOptions.java:
Do not call System.exit() when we encounter an unrecognized
option in MERCURY_OPTIONS, throw a MercuryFatalError exception
instead.
Refactor the process() method in order to avoid indentation.
Catch NumberFormatExceptions thrown when attempting to convert
integer option values; rethrow them as MercuryFatalErrors.
(XXX the C version of the runtime just ignores this error.)
java/runtime/JavaInternal.java:
Catch and report MercuryFatalErrors in the runMain() method.
java/runtime/MercuryWorkerThread.java:
Add an XXX about a call to System.exit() here.
Add a new configure option, ---with-pkgversion, that allows those packaging
Mercury to include additional version information specific to their package in
the output of mmc --version etc.
Omit version and copyright information from the short usage messages for mmc, mprof
and mcov. The result is less cluttered and more direct.
Omit version information from the long usage (i.e. --help) message for the
above programs. This is to save space on the first line of the output and also
brings the man pages for mmc, mprof and mcov into line with the other man
pages, which do *not* have version information in their NAME section.
configure.ac:
Add the new --with-pkgversion option.
runtime/mercury_conf.h.in:
runtime/mercury_dotnet.cs.in:
java/runtime/Constants.java.in:
Define a constant for the package version.
library/library.m:
Add the function package_version/0, which returns the package
version string.
compiler/handle_options.m:
profiler/mercury_profile.m:
slice/mcov.m:
Include a non-empty package version in the output of --version.
Make the above changes to the short and long usage messages.
Add an XXX about mprof's short usage message.
In the high-level data representation, make a subtype term be
represented using the class corresponding to the base type constructor
instead of its own class. This is necessary to be able to downcast
a term from a type to a subtype in Java and C#.
compiler/du_type_layout.m:
Move get_base_type_ctor predicate to type_util.m.
Abort in a couple of places that should not occur.
compiler/type_util.m:
Add get_base_type_ctor predicate.
compiler/globals.m:
Add compilation_target_high_level_data predicate.
compiler/lco.m:
Use compilation_target_high_level_data predicate.
compiler/ml_type_gen.m:
When using the high-level data representation,
don't generate a MLDS type definition (class) for a subtype.
compiler/mlds.m:
When using the high-level data representation,
replace a Mercury subtype with its base type in an mlds_type.
Move foreign_type_to_mlds_type.
compiler/ml_unify_gen_util.m:
To access a field when using the high-level data representation,
use field names from the base type constructor of a subtype.
compiler/unify_proc.m:
When using the high-level data representation,
generate unify/compare procs for subtypes that just call the
unify/compare proc for the base type constructor.
compiler/options.m:
Delete references to --high-level and --high-level-data.
---------------
runtime/mercury_type_info.h:
Document a new field MR_type_ctor_base in MR_TypeCtorInfo_Struct.
The field is unnecessary and does not exist in the
MR_TypeCtorInfo_Struct for C.
runtime/mercury_dotnet.cs.in:
Add type_ctor_base member to MR_TypeCtorInfo_Struct for C#.
java/runtime/TypeCtorInfo_Struct.java
Add type_ctor_base member to MR_TypeCtorInfo_Struct for Java.
compiler/rtti.m:
compiler/type_ctor_info.m:
Add field corresponding to MR_type_ctor_base in type_ctor_details
for enum, notag and general du types.
compiler/rtti_to_mlds.m:
Initialize the MR_type_ctor_base field in type_ctor_infos
for high-level data grades.
compiler/rtti_out.m:
Don't write out the MR_type_ctor_base field when using
the low-level data representation.
library/rtti_implementation.m:
In Java and C# grades (high-level data grades), use the
MR_type_ctor_base field to get the type_ctor_info of the base type
ctor when constructing or deconstructing terms of a subtype.
It is necessary to perform reflection using class and field names
from the base type constructor since there are no classes
corresponding to subtypes.
Clean up some code.
---------------
tests/hard_coded/Mmakefile:
tests/hard_coded/subtype_abstract.m:
tests/hard_coded/subtype_abstract_2.m:
tests/hard_coded/subtype_abstract.exp:
Add a test case.
tests/hard_coded/subtype_rtti.m:
tests/hard_coded/subtype_rtti.exp2:
Enable a test that was previously skipped in Java and C# grades.
Make subtypes share data representation with base type when using
low-level data. High-level data grades are unchanged, so subtypes
are still represented with distinct classes from their base types.
----------------
compiler/prog_data.m:
Add abstract_subtype option for type_details_abstract.
Correct XXX comment.
compiler/prog_item.m:
Add type item_type_repn_info_subtype.
Add tcrepn_is_subtype_of option for type_ctor_repn_info.
compiler/equiv_type.m:
Replace equivalences in tcrepn_is_subtype_of.
compiler/module_qual.qualify_items.m:
Module qualify in tcrepn_is_subtype_of.
compiler/prog_type.m:
Rename some predicates that can only work on non-subtype du types.
Update comments.
compiler/check_parse_tree_type_defns.m:
Classify subtype type definitions as std_mer_type_du_subtype
instead of std_mer_type_du_all_plain_constants or
std_mer_type_du_not_all_plain_constants.
Update some comments.
compiler/du_type_layout.m:
Add two sub-passes to handle subtypes.
compiler/comp_unit_interface.m:
Extend this module to handle subtype type definitions,
analogous to the way equivalence type definitions are handled.
Rename some predicates to clarify that they must not be used
to test subtypes.
Record an abstract version of a subtype type definition using
the abstract_subtype option in type_details_abstract.
This allows the super type ctor of the subtype to be known,
and hence the base type ctor, when a subtype is abstract exported.
Update comments.
compiler/decide_type_repn.m:
Extend this module to handle subtype type definitions.
Generate type_representation items for subtype type definitions
which include the super type ctor of the subtype.
compiler/parse_tree_out.m:
Write out abstract_subtype as
"where type_is_abstract_subtype(Name/Arity)" on type definitions.
compiler/parse_type_defn.m:
Parse "type_is_abstract_subtype(Name/Arity)" declarations.
compiler/parse_tree_out_type_repn.m:
Write type_representation items with "is_subtype_of(TypeCtor/Arity)".
compiler/parse_type_repn.m:
Parse "is_subtype_of(TypeCtor/Arity)" in type_representation items.
compiler/add_type.m:
compiler/convert_parse_tree.m:
compiler/opt_debug.m:
compiler/type_util.m:
Conform to changes.
Update comments.
compiler/direct_arg_in_out.m:
Delete XXX, nothing to do.
compiler/parse_util.m:
Rename overly specific variable.
----------------
runtime/mercury_type_info.h:
Add a flag in MR_TypeCtorInfo to indicate if the enum/du layout
array may be indexed by an enum value or du ptag value.
Subtypes break the invariant that the layout array contains entries
for every enum/ptag value from 0 up to the maximum value.
The presence of the flag MR_TYPE_CTOR_FLAG_LAYOUT_INDEXABLE tells
the runtime that it can directly index the layout array instead of
searching through it (which is the common case, for non-subtypes).
Add a field MR_du_ptag to MR_DuPtagLayout. This is necessary to find
an entry for a given primary tag value in a MR_DuPtagLayout array.
Add a field MR_du_ptag_flags to MR_DuPtagLayout, currently with one
possible flag MR_DU_PTAG_FLAG_SECTAG_ALTERNATIVES_INDEXABLE.
As with primary tags, subtypes break the invariant that the
sectag_alternatives array contains entries for every secondary tag
value from 0 up to the maximum value. The presence of the flag tells
the runtime that it can directly index the sectag_alternatives array
(which is the common case, for non-subtypes).
The two fields added to MR_DuPtagLayout occupy space that was
previously padding, so the size of MR_DuPtagLayout is unchanged.
In MR_EnumFunctorDesc, replace the MR_enum_functor_ordinal field by
MR_enum_functor_value, i.e. the integer value representing the
functor in memory. Storing *both* the functor ordinal and enum value
would increase the size of the MR_EnumFunctorDesc struct, and would
be redundant in the common case of non-subtype enums (both fields
would contain equal values). We forgo having the functor ordinal
directly available, at the cost of needing to search through an
MR_EnumFunctorDesc array when a functor ordinal is required for a
subtype enum, which should be rare.
compiler/rtti.m:
Swap enum "functor ordinal" and "value" in places.
Use a type 'enum_value' to try to ensure we do not mix up enum
functor ordinals and enum values.
Add code to encode the MR_TYPE_CTOR_FLAG_LAYOUT_INDEXABLE flag.
Add code to encode the MR_DU_PTAG_FLAG_SECTAG_ALTERNATIVES_INDEXABLE
flag.
compiler/rtti_out.m:
Write out "enum_ordinal_ordered_tables" ordered by functor ordinals
instead of "enum_value_ordered_tables" ordered by enum values.
Output the enum value for MR_EnumFunctorDesc instead of functor
ordinal.
Output the MR_du_ptag and MR_du_ptag_flags fields for
MR_DuPtagLayout.
Relax sanity check on primary tags. A subtype may not necessarily
use ptag 0, and may skip ptag values.
compiler/rtti_to_mlds.m:
Generate "enum_ordinal_ordered_tables" instead of
"enum_value_ordered_tables".
Fill in the enum value for a MR_EnumFunctorDesc instead of
the functor ordinal.
compiler/type_ctor_info.m:
Add predicate to generate the MR_du_ptag_flags field.
Add the MR_TYPE_CTOR_FLAG_LAYOUT_INDEXABLE flag to type_ctor_infos
when appropriate.
Bump the type_ctor_info_rtti_version.
----------------
runtime/mercury_ml_expand_body.h:
Search through an enum layout array to find the matching enum value,
unless the array can be indexed.
Search through a ptag layout array to find the matching ptag value,
unless the array can be indexed.
Search through a sectag_alternatives array to find the matching
secondary tag value, unless the array can be indexed.
Factor out the code to search through a foreign enum layout array
into a separate macro.
runtime/mercury_construct.c:
runtime/mercury_construct.h:
Add a functor_ordinal field to the MR_Construct_Info_Struct.
This will hold the functor ordinal now that it is not available in
MR_EnumFunctorDesc.
Make MR_get_functors_check_range take an argument to indicate if the
functor_ordinal field needs to be filled in properly. Most callers
do not need the field.
library/construct.m:
Conform to changes to MR_get_functors_check_range and
MR_EnumFunctorDesc.
-------------------
runtime/mercury_dotnet.cs.in:
Modify RTTI classes for C# backend, analogous to the changes for the
C runtime.
Add methods to index/search through enum layout arrays, ptag layout
arrays, and sectag_alternatives arrays.
java/runtime/DuPtagLayout.java:
java/runtime/EnumFunctorDesc.java:
java/runtime/TypeCtorInfo_Struct.java:
Modify RTTI classes for Java backend, analogous to the changes for the
C runtime.
Add methods to index/search through enum layout arrays, ptag layout
arrays, and sectag_alternatives arrays.
library/rtti_implementation.m:
Conform to MR_EnumFunctorDesc field change.
Index or search through the enum layout array or ptag layout array
based on the MR_TYPE_CTOR_FLAG_LAYOUT_INDEXABLE flag.
Index or search through the sectag_alternatives array depending on
the MR_DU_PTAG_FLAG_SECTAG_ALTERNATIVES_INDEXABLE flag.
Add separator lines.
Slightly reorder some code.
----------------
tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/subtype_pack.m:
tests/hard_coded/subtype_pack_2.m:
tests/hard_coded/subtype_pack.exp:
tests/hard_coded/subtype_rtti.m:
tests/hard_coded/subtype_rtti.exp:
tests/hard_coded/subtype_rtti.exp2:
Add test cases.
runtime/mercury_type_info.h:
Use unsigned integer types for a few RTTI structure fields that
are known to hold non-negative values.
Add comments for other field types that could be changed later.
compiler/rtti.m:
Use fixed size integer types for fields matching the size
and signedness of the corresponding C RTTI structure fields.
Encode type ctor flags in a uint16 instead of int.
Make type_ctor_details_num_ptags and type_ctor_details_num_functors
return a maybe value, instead of a negative value to represent no
primary tags or no function symbols, respectively.
compiler/type_ctor_info.m:
Conform to type changes.
Use uint16 to represent the "contains var" bit vector.
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
Conform to type changes.
Add comments to make it easier to find the code that writes out
each particular RTTI structure field.
compiler/ml_util.m:
Add helper functions.
compiler/add_special_pred.m:
compiler/du_type_layout.m:
compiler/erl_rtti.m:
compiler/erlang_rtti.m:
compiler/hlds_data.m:
compiler/llds_out_data.m:
compiler/ml_unify_gen_construct.m:
compiler/opt_debug.m:
compiler/pseudo_type_info.m:
compiler/stack_layout.m:
compiler/unify_gen_construct.m:
Conform to type changes.
compiler/parse_type_defn.m:
compiler/prog_data.m:
Use uint32 for functor ordinal numbers.
library/rtti_implementation.m:
Use fixed size integer types for RTTI field accessor functions,
and update callers.
java/runtime/DuArgLocn.java:
java/runtime/DuExistInfo.java:
java/runtime/DuExistLocn.java:
java/runtime/DuFunctorDesc.java:
java/runtime/TypeCtorInfo_Struct.java:
Use integer types in RTTI structure definitions for Java that match
the types in the C versions of the same structures.
runtime/mercury_dotnet.cs.in:
Use integer types in RTTI structure definitions for C# that match
the types in the C versions of the same structures.
compiler/du_type_layout.m:
If the --allow-packing-remote-sectag option is set, then try to pack
an initial subsequence of subword-sized arguments next to remote sectags.
To allow the polymorphism transformation to put the type_infos and/or
typeclass_infos it adds to a function symbol's argument list at the
*front* of that argument list, pack arguments next to remote sectags
only in function symbols that won't have any such extra arguments
added to them.
Do not write all new code for the new optimization; instead, generalize
the code that already does a very similar job for packing args next to
local sectags.
Delete the code we used to have that picked the packed representation
over the base unpacked representation only if it reduced the
"rounded-to-even" number of words. A case could be made for its usefulness,
but in the presence of the new optimization the extra code complexity
it requires is not worth it (in my opinion).
Extend the code that informs users about possible argument order
rearrangements that yield better packing to take packing next to sectags
into account.
compiler/hlds_data.m:
Provide a representation for cons_tags that use the new optimization.
Instead of adding a new cons_tag, we do this by replacing several old
cons_tags that all represent pointers to memory cells with a single
cons_tag named remote_args_tag with an argument that selects among
the old cons_tags being replaced, and adding a new alternative inside
this new type. The new alternative is remote_args_shared with a
remote_sectag whose size is rsectag_subword(...).
Instead of representing the value of the "data" field in classes
on the Java and C# backends as a strange kind of secondary tag
that is added to a memory cell by a class constructor instead of
having to be explicitly added to the front of the argument vector
by the code of a unification, represent it more directly as separate
kind of remote_args_tag. Continuing to treat it as a sectag would have
been very confusing to readers of the code of ml_unify_gen_*.m in the
presence of the new optimization.
Replacing several cons_tags that were usually treated similarly with
one cons_tag simplifies many switches. Instead of an switch with that
branches to the same switch arm for single_functor_tag, unshared_tag
and shared_remote_tag, and then switches on these three tags again
to get e.g. the primary tag of each, the new code of the switch arm
is executed for just cons_tag value (remote_args_tag), and switches
on the various kinds of remote args tags only when it needs to.
In is also more natural to pass around the argument of remote_args_tag
than to pass around a variable of type cons_tag that can be bound to only
single_functor_tag, unshared_tag or shared_remote_tag.
Add an XXX about possible further steps along these lines, such as
making a new cons_tag named something like "user_const_tag" represent
all user-visible constants.
compiler/unify_gen_construct.m:
compiler/unify_gen_deconstruct.m:
compiler/unify_gen_test.m:
compiler/unify_gen_util.m:
compiler/ml_unify_gen_construct.m:
compiler/ml_unify_gen_deconstruct.m:
compiler/ml_unify_gen_test.m:
compiler/ml_unify_gen_util.m:
Implement X = f(Yi) unifications where f uses the new representation,
i.e. some of its arguments are stored next to a remote sectag.
Some of the Yi are stored in a tagword (a word that also contains a tag,
in this case the remote secondary tag), while some are stored in other
words in a memory cell. This means that such unifications have similarities
both to unifications involving arguments being packed next to local
sectags, and to unifications involving ordinary arguments in memory cells.
Therefore wherever possible, their implemenation uses suitably generalized
versions of existing code that did those two jobs for two separate kinds of
cons_tags.
Making such generalizations possible in some cases required shifting the
boundary between predicates, moving work from a caller to a callee
or vice versa.
In unify_gen_deconstruct.m, stop using uni_vals to represent *either* a var
*or* a word in a memory cell. While this enabled us to factor out some
common code, the predicate boundaries it lead to are unsuitable for the
generalizations we now need.
Consistently use unsigned ints to represent both the whole and the parts
of words containing packed arguments (and maybe sectags), except when
comparing ptag constants with the result of applying the "tag" unop
to a word, (since that unop returns an int, at least for now).
In a few cases, avoid the recomputation of some information that we
already know. The motivation is not efficiency, since the recomputation
we avoid is usually cheap, but the simplification of the code's correctness
argument.
Use more consistent terminology in things such as variable names.
Note the possibility of further future improvements in several places.
compiler/ml_foreign_proc_gen.m:
Delete a long unused predicate.
compiler/mlds.m:
Add an XXX documenting a possible improvement.
compiler/rtti.m:
Update the compiler's internal representation of RTTI data structures
to make them able to describe secondary tags that are smaller than
a full word.
compiler/rtti_out.m:
Conform to the changes above, and delete a long-unused predicate.
compiler/type_ctor_info.m:
Use the RTTI's du_hl_rep to represent cons_tags that distinguish
between function symbols using a field in a class.
compiler/ml_type_gen.m:
Provide a specialized form of a function for code in ml_unify_gen_*.m.
Conform to the changes above.
compiler/add_special_pred.m:
compiler/bytecode_gen.m:
compiler/export.m:
compiler/hlds_code_util.m:
compiler/lco.m:
compiler/ml_closure_gen.m:
compiler/ml_switch_gen.m:
compiler/ml_tag_switch.m:
compiler/rtti_to_mlds.m:
compiler/switch_util.m:
compiler/tag_switch.m:
Conform to the changes above.
runtime/mercury_type_info.h:
Update the runtime's representation of RTTI data structures to make them
able to describe remote secondary tags that are smaller than a full word.
runtime/mercury_deconstruct.[ch]:
runtime/mercury_deconstruct.h:
runtime/mercury_deconstruct_macros.h:
runtime/mercury_ml_expand_body.h:
runtime/mercury_ml_arg_body.h:
runtime/mercury_ml_deconstruct_body.h:
runtime/mercury_ml_functor_body.h:
These modules collectively implement the predicates in deconstruct.m
in the library, and provide access to its functionality to other C code,
e.g. in the debugger. Update these to be able to handle terms with the
new data representation optimization.
This update requires a significant change in the distribution of work
between these files for the predicates deconstruct.deconstruct and
deconstruct.limited_deconstruct. We used to have mercury_ml_expand_body.h
fill in the fields of their expand_info structures (whose types are
defined in mercury_deconstruct.h) with pointers to three vectors:
(a) a vector of arg_locns with one element per argument, with a NULL
pointer being equivalent to a vector with a given element in every slot;
(b) a vector of type_infos with one element per argument, constructed
dynamically (and later freed) if necessary; and (c) a vector of argument
words. Once upon a time, before double-word and sub-word arguments,
vector (c) also had one word per argument, but that hasn't been true
for a while; we added vector (a) help the consumers of the expand_info
decode the difference. The consumers of this info always used these
vectors to build up a Mercury term containing a list of univs,
with one univ for each argument.
This structure could be stretched to handle function symbols that store
*all* their arguments in a tagword next to a local sectag, but I found
that stretching it to cover function symbols that have *some* of their
arguments packed next to a remote sectag and *some other* of their
arguments in a memory cell as usual would have required a well-nigh
incomprehensibly complex, and therefore almost undebuggable, interface
between mercury_ml_expand_body.h and the other files above. This diff
therefore changes the interface to have mercury_ml_expand_body.h
build the list of univs directly. This make its code relatively simple
and self-contained, and it should be somewhat faster then the old code
as well, since it never needs to allocate, fill in and then free
vectors of type_infos (each such typeinfo now gets put into a univ
as soon as it is constructed). The downside is that if we ever wanted
to get all the arguments at once for a purpose other than constructing
a list of univs from them, it would nevertheless require constructing
that list of univs anyway as an intermediate data structure. I don't see
this downside is significant, because (a) I don't think such a use case
is very likely, and (b) even if one arises, debuggable but a bit slow
is probably preferable to faster but very hard to debug.
Reduce the level of indentation of some of these files to make the code
easier to edit. Do this by
- not adding an indent level from switch statements to their cases; and
- not adding an indent level when a case in a switch has a local block.
Move the break or return ending a case inside that case's block,
if it has one.
runtime/mercury_deep_copy_body.h:
runtime/mercury_table_type_body.h:
Update these to enable the copying or tabling of terms whose
representations uses the new optimization.
Use the techniques listed above to reduce the level of indentation
make the code easier to edit.
runtime/mercury_tabling.c:
runtime/mercury_term_size.c:
Conform to the changes above.
runtime/mercury_unify_compare_body.h:
Make this code compile after the changes above. It does need to work
correctly, since we only ever used this code to compare the speed
of unify-by-rtti with the speed of unify-by-compiler-generated-code,
and in real life, we always use the latter. (It hasn't been updated
to work right with previous arg packing changes either.)
library/construct.m:
Update to enable the code to construct terms whose representations
uses the new optimization.
Add some sanity checks.
library/private_builtin.m:
runtime/mercury_dotnet.cs.in:
java/runtime/Sectag_Locn.java:
Update the list of possible sectag kinds.
library/store.m:
Conform to the changes above.
trace/mercury_trace_vars.c:
Conform to the changes above.
tests/hard_coded/deconstruct_arg.{m,exp,exp2}:
Extend this test to test the deconstruction of terms whose
representations uses the new optimization.
Modify some of the existing terms being tested to make them more diverse,
in order to make the output easier to navigate.
tests/hard_coded/construct_packed.{m,exp}:
A new test case to test the construction of terms whose
representations uses the new optimization.
tests/debugger/browse_packed.{m,exp}:
A new test case to test access to the fields of terms whose
representations uses the new optimization.
tests/tabling/test_packed.{m,exp}:
A new test case to test the tabling of terms whose
representations uses the new optimization.
tests/debugger/Mmakefile:
tests/hard_coded/Mmakefile:
tests/tabling/Mmakefile:
Enable the new test cases.
... after my recent changes.
java/runtime/DuFunctorDesc.java:
java/runtime/DuPtagLayout.java:
Add the new field to the Java equivalents of the two C structures
affected by the recent change to support packing arguments next to
local secondary tags.
runtime/mercury_dotnet.cs.in:
Add the new field to the C# equivalent of one of two C structures
affected by the recent change to support packing arguments next to
local secondary tags; the other was done earlier.
runtime/mercury_type_info.h:
Include java/runtime/* among the files that may need to be updated
after a change in this file.
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.
Add the new builtin types: int64 and uint64.
Support for these new types will need to be bootstrapped over several changes.
This is the first such change and does the following:
- Extends the compiler to recognise 'int64' and 'uint64' as builtin types.
- Extends the set of builtin arithmetic, bitwise and relational operators
to cover the new types.
- Adds the new internal option '--unboxed-int64s' to the compiler; this will be
used to control whether 64-bit integer types are boxed or not.
- Extends all of the code generators to handle the new types.
- Extends the runtimes to support the new types.
- Adds new modules to the standard library intend to contain basic operations
on the new types. (These are currently empty and not documented.)
There are bunch of limitations marks with "XXX INT64"; these will be lifted in
part 2 of this change. Also, 64-bit integer types are currently always boxed,
again this limitation will be lifted in later changes.
compiler/options.m:
Add the new option --unboxed-int64s.
compiler/prog_type.m:
compiler/prog_data.m:
compiler/builtin_lib_types.m:
Recognise int64 and uint64 as builtin types.
compiler/builtin_ops.m:
Add builtin operations for the new types.
compiler/hlds_data.m:
Add new tag types for the new types.
compiler/ctgc.selector.m:
compiler/dead_proc_elim.m:
compiler/export.m:
compiler/foreign.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_code_util.m:
compiler/hlds_dependency_graph.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/implementation_defined_literals.m:
compiler/inst_check.m:
compiler/mercury_to_mercury.m:
compiler/mode_util.m:
compiler/module_qual.qualify_items.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_name.m:
compiler/polymorphism.m:
compiler/prog_out.m:
compiler/prog_util.m:
compiler/rbmm.execution_path.m:
compiler/rtti.m:
compiler/table_gen.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
Conform to the above changes to the parse tree and HLDS.
compiler/c_util.m:
Support writing out constants of the new types.
compiler/llds.m:
Add a representation for constants of the new types to the LLDS.
compiler/stack_layout.m:
Add a new field to the stack layout params that records whether
64-bit integers are boxed or not.
compiler/call_gen.:m
compiler/code_info.m:
compiler/disj_gen.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/llds_out_data.m:
compiler/llds_out_instr.m:
compiler/lookup_switch.m:
compiler/mercury_compile_llds_back_end.m:
compiler/prog_rep.m:
compiler/prog_rep_tables.m:
compiler/var_locn.m b/compiler/var_locn.m:
Support the new types in the LLDS code generator.
compiler/mlds.m:
Support constants of the new types in the MLDS.
compiler/ml_call_gen.m:
compiler/ml_code_util.m:
compiler/ml_global_data.m:
compiler/ml_rename_classes.m:
compiler/ml_top_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_target_util.m:
compiler/rtti_to_mlds.m:
Conform to the above changes to the MLDS.
compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
Generate the appropriate target code for constants of the new types
and operations involving them.
compiler/bytecode.m:
compiler/bytecode_gen.m:
Handle the new types in the bytecode generator; we just abort if we
encounter them for now.
compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_call_gen.m:
compiler/erl_code_util.m:
compiler/erl_unify_gen.m:
Handle the new types in the Erlang code generator.
library/private_builtin.m:
Add placeholders for the builtin unify and compare operations for
the new types. Since the bootstrapping compiler will not recognise
the new types we give them polymorphic arguments. These can be
replaced after this change has bootstrapped.
Update the Java list of TypeCtorRep constants here.
library/int64.m:
library/uint64.m:
New modules that will eventually contain builtin operations on the new
types.
library/library.m:
library/MODULES_UNDOC:
Do not include the above modules in the library documentation for now.
library/construct.m:
library/erlang_rtti_implementation.m:
library/rtti_implementation.m:
library/table_statistics.m:
deep_profiler/program_representation_utils.m:
mdbcomp/program_representation.m:
Handle the new types.
configure.ac:
runtime/mercury_conf.h.in:
Define the macro MR_BOXED_INT64S. For now it is always defined, support for
unboxed 64-bit integers will be enabled in a later change.
runtime/mercury_dotnet.cs.in:
java/runtime/TypeCtorRep.java:
runtime/mercury_type_info.h:
Update the list of type_ctor reps.
runtime/mercury.h:
runtime/mercury_int.[ch]:
Add macros for int64 / uint64 -> MR_Word conversion, boxing and
unboxing.
Add functions for hashing 64-bit integer types suitable for use
with the tabling mechanism.
runtime/mercury_tabling.[ch]:
Add additional HashTableSlot structs for 64-bit integer types.
Omit the '%' character from the conversion specifiers we pass via
the 'key_format' argument to the macros that generate the table lookup
function. This is so we can use the C99 exact size integer conversion
specifiers (e.g. PRIu64 etc.) directly here.
runtime/mercury_hash_lookup_or_add_body.h:
Add the '%' character that was omitted above to the call to debug_key_msg.
runtime/mercury_memory.h:
Add new builtin allocation sites for boxed 64-bit integer types.
runtime/mercury_builtin_types.[ch]:
runtime/mercury_builitn_types_proc_layouts.h:
runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_ml_expand_body.h:
runtime/mercury_table_type_body.h:
runtime/mercury_tabling_macros.h:
runtime/mercury_tabling_preds.h:
runtime/mercury_term_size.c:
runtime/mercury_unify_compare_body.h:
Add the new builtin types and handle them throughout the runtime.
runtime/Mmakefile:
Add mercury_int.c to the list of .c files.
doc/reference_manual.texi:
Add the new types to the list of reserved type names.
Add the mapping from the new types to their target language types.
These are commented out for now.
In the Java grade, the type_ctor_rep constants are currently defined in the
private_builtin module of the standard library. The Java version of the
runtime currently duplicates some of these constants for its own use (since it
cannot refer to the library ones). This means changes to the set of
type_ctor_reps need to potentially occur in two places, which is a maintenance
headache.
This changes shifts the definitions of all the type_ctor_rep constants in the
Java grade into the runtime and updates the compiler to generate code that
uses these new definitions.
library/private_builtin.m:
Add a note mentioning that the type_ctor_rep constants defined here
will eventually be removed.
java/runtime/TypeCtorRep.java:
Define constants for *all* of the type_ctor_reps in this class.
library/rtti_implementation.m:
library/type_desc.m:
Update code to refer to the new version of the type_ctor_rep constants.
compiler/rtti.m:
Update the compiler to generate references to the new version of the
type_ctor_rep constants.
Add a new builtin type: uint, which is an unsigned word sized integer type.
Support for this new type will need be bootstrapped over several changes.
This is the first such change and does the following:
- Extends the compiler to recognize 'uint' as a builtin type.
- Extends the set of builtin operations to include relational and (some)
arithmetic operations on uints.
- Extends all of the code generators to handle the above. There are some
limitations currently marked by 'XXX UINT'. These will be lifted once
the compiler recognised uint and additional library support becomes
available.
- Extends the runtime to support uints.
compiler/prog_type.m:
compiler/prog_data.m:
compiler/builtin_lib_types.m:
Recognize uint as a builtin type.
Add a new alternative to the cons_id/0 type corresponding to the uint type
-- for bootstrapping purposes its argument is currently an int.
compiler/builtin_ops.m:
Add builtin relational and arithmetic operations on uints. Note that the
existing 'unsigned_le' operation is actually intended for use with signed
values. Rather than attempt to modify its meaning, I have just added new
operations specific to the uint type.
compiler/hlds_data.m:
Add a new tag type for uints.
compiler/type_ctor_info.m:
Recognise uint as a builtin.
Bump the RTTI version number here.
compiler/ctgc.selector.m:
compiler/dead_proc_elim.m:
compiler/dependency_graph.m:
compiler/export.m:
compiler/foreign.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_code_util.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/hlds_pred.m:
compiler/implementation_defined_literals.m:
compiler/inst_check.m:
compiler/mercury_to_mercury.m:
compiler/mode_util.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_name.m:
compiler/polymorphism.m:
compiler/prog_out.m:
compiler/prog_rep.m:
compiler/prog_rep_tables.m:
compiler/prog_util.m:
compiler/rbmm.execution_path.m:
compiler/rtti.m:
compiler/special_pred.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/type_constraints.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/unused_imports.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
Conform to the above changes to the parse tree and HLDS.
compiler/c_util.m:
Support generating builtin operations for uints.
compiler/llds.m:
Add a representation for uint constants to the LLDS.
Map uints onto MR_Unsigned.
compiler/call_gen.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/llds_out_data.m:
compiler/llds_out_instr.m:
compiler/opt_debug.m:
compiler/opt_util.m:
Support uints in the LLDS code generator.
compiler/mlds.m:
Support uint constants in the MLDS.
compiler/ml_accurate_gc.m:
compiler/ml_call_gen.m:
compiler/ml_global_data.m:
compiler/ml_simplify_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/rtti_to_mlds.m:
Conform to the above change to the MLDS.
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
compiler/mlds_to_cs.m:
Generate the appropriate target code for uint constants and uint
relational operations.
compiler/bytecode.m:
compiler/bytecode_gen.m:
Handle uints in the bytecode generator: we just abort if we
encounter them for now.
compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_call_gen.m:
compiler/erl_code_util.m:
compiler/erl_rtti.m:
compiler/erl_unify_gen.m:
Handle uints in the Erlang code generator.
library/private_builtin.m:
Add placeholders for builtin_{unify,compare}_uint. Since the
bootstrapping compiler will not recognize uint as a type, we
give them polymorphic arguments. These can be replaced after
this change has bootstrapped.
Update the Java list of TypeCtorRep constants, which for some
reason is defined here.
library/uint.m:
New module that will eventually contain operations on uints.
library/MODULES_DOCS:
library/library.m:
Add the uint module.
library/construct.m:
library/erlang_rtti_implementation.m:
library/rtti_implementation.m:
mdbcomp/program_representation.m:
Handle uints.
deep_profiler/program_representation_utils.m:
Conform to the above change.
runtime/mercury_dotnet.cs.in:
Update the list of TypeCtorReps for C#
java/runtime/TypeCtorRep.java:
Update this, although the actual TypeCtorRep constants
are defined the library.
runtime/mercury_type_info.h:
Bump the RTTI version number.
Add an alternative for uints to the tyepctor rep enum.
runtime/mercury_builtin_types.{h,c}:
runtime/mercury_builtin_types_proc_layouts.h:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_table_type_body.h:
runtime/mercury_tabling.h:
runtime/mercury_tabling_macros.h:
runtime/mercury_unify_compare_body.h:
Add uint as a builtin type and handle it throughout the runtime.
runtime/mercury_grade.h:
Bump the binary compatibility version.
runtime/mercury_term_size.c:
runtime/mercury_ml_expand_body.h:
Handle uint and fix probable bugs with the handling of ints on
64-bit Windows.
I noticed this bug when accidentally throwing a Mercury exception containing
some malformed Mercury data (a Java null pointer). The Java worker thread
tried to report the exception, by calling back into Mercury but this
encountered a null pointer exception itself due to the bad data and failed
to de-register itself from the thread pool. This caused the thread pool to
mistakingly think that a thread was still alive and it failed to terminate
the program.
The solution is tu ensure that the pool knows the thread has shutdown if any
exception occurs.
This bug isn't likely to occur in practice, throwing exceptions whose
message is null is unusual.
java/runtime/MercuryWorkerThread.java:
As above.
These allow types to be defined in the following manner:
:- type job ---> job(pred(int::out, io::di, io::uo) is det).
For any construction unification using this functor the argument must
have the required higher-order inst; it is a mode error if it does not.
When terms of type job with inst ground are deconstructed, the argument
is inferred to have the given inst, allowing a higher-order call in that
mode.
The new type syntax is currently only permitted as the direct argument of
a functor in a du type definition. In future it would be meaningful to
support this syntax in other locations, but that is left for a separate
change.
In order to correctly implement the construct/3 library predicate, we
need to be able to dynamically check that arguments do not violate
any constraints on the argument insts. At the moment, we conservatively
abort if any such constraints are present irrespective of whether they
are satisfied or not. Since these constraints are a new feature, no
existing code will abort in this way.
The implementation refers to the inst information associated with types
as "subtype information". This is because, generally, we think of the
combination of a type with a fully bound inst (i.e., one that describes
terms that contain no unbound variables) describes a subtype of that type.
compiler/inst_util.m:
Ensure that arguments have the necessary insts in construction
unifications.
Where available, propagate the insts into arguments rather than
using ground(shared, none).
compiler/prog_io_type_name.m:
Parse the new form of types.
compiler/unparse.m:
Unparse the new form of types.
compiler/prog_io_type_defn.m:
Allow the new form of types in functor arguments.
compiler/prog_ctgc.m:
compiler/prog_io_item.m:
compiler/prog_io_mutable.m:
compiler/prog_io_pragma.m:
compiler/prog_io_typeclass.m:
compiler/superhomogeneous.m:
Disallow the new form of types in places other than functor
arguments.
compiler/prog_data.m:
Go back to representing function types with result type appended
to the arguments. In most case this now results in simpler code.
compiler/prog_type.m:
Abstract away the representation of predicate vs function arguments
by using a predicate to construct these types.
compiler/rtti.m:
compiler/type_ctor_info.m:
Include subtype information about the arguments of a du functor
and about the argument of a notag functor. Generate this
information from the argument types.
Currently, the information is one bit which says whether or not
any subtypes exist in the arguments.
Bump the RTTI version number from the compiler side.
compiler/rtti_out.m:
Output functor subtype information for the low-level C backend.
compiler/rtti_to_mlds.m:
Include functor subtype information in the MLDS.
compiler/mlds_to_cs.m:
Add the new runtime type to the special cases.
compiler/erl_rtti.m:
compiler/erlang_rtti.m:
library/erlang_rtti_implementation.m:
Include functor subtype info in the erlang RTTI.
java/runtime/DuFunctorDesc.java:
java/runtime/FunctorSubtypeInfo.java:
Include functor subtype information in the Java runtime.
runtime/mercury_dotnet.cs.in:
Include functor subtype information in the C# runtime.
runtime/mercury_type_info.h:
Include functor subtype information in the C runtime.
Bump the RTTI version number in the runtime.
Define macros to access the new field. These macros can correctly
handle the previous RTTI version, therefore we do not need to
change the minimum version at this time.
library/private_builtin.m:
Define constants for use by the Java backend.
library/construct.m:
library/rtti_implementation.m:
Use the new RTTI to ensure we don't attempt to construct terms
that violate the new insts.
compiler/prog_rep_tables.m:
Ignore the new inst info for now.
compiler/*.m:
Changes to conform to above.
doc/reference_manual.texi:
Document the new feature.
tests/hard_coded/functor_ho_inst.{m,exp}:
tests/hard_coded/functor_ho_inst_2.{m,exp}:
tests/hard_coded/functor_ho_inst_excp.{m,exp}:
tests/hard_coded/functor_ho_inst_excp_2.{m,exp}:
Test the new functionality.
tests/invalid/combined_ho_type_inst.{m,err_exp}:
tests/invalid/combined_ho_type_inst_2.{m,err_exp}:
Test that we don't allow the new types where they are not permitted,
or are incomplete.
tests/invalid/functor_ho_inst_bad.{m,err_exp}:
tests/invalid/functor_ho_inst_bad_2.{m,err_exp}:
tests/invalid/functor_ho_inst_bad_3.{m,err_exp}:
Test that the argument inst information is enforced as required.
tests/hard_coded/Mmakefile:
tests/invalid/Mmakefile:
Run the new test cases.
This file-specific setting will override a default setting of expandtabs
in $HOME/.vimrc.
*/Makefile:
*/Mmakefile:
As above.
tests/hard_coded/.gitignore:
Don't ignore the purity subdir. This ignore must have been left over
from when purity.m was a test in hard_coded, not hard_coded/purity,
and it ignored an executable, not a directory.
finalisers should be executed only if main/2 returns normally, it does not
throw an exception. The C backends already do this correctly but the Java
backend did not. The C# backend has the same bug, this patch does not fix
the C# backend.
java/runtime/MercuryThreadPool.java:
Add a parameter to the shutdown() method to specify whether the backend
is aborting.
In runMain(), run finalisers only if the runtime is exiting normally.
java/runtime/MercuryRuntime.java:
Add a new finalise() method that takes a parameter allowing standalone
Java applications to specify whether or not they are aborting when the
finalise the RTS.
doc/reference_manual.texi:
Specify the behaviour of finalise directives if main/2 terminates
with an uncaught exception.
samples/java_interface/standalone_java/JavaMain.java:
Conform to changes in MercuryRuntime.java.
When main/2 throws an exception we did not properly shutdown the thread pool
and therefore the JVM would not shut down. Simply calling shutdown() in a
finally block is insufficient because then the primordial thread may finish
before the worker thread is able to report the exception thrown by main/2.
This doesn't seem right because the JVM is supposed to wait for all the
non-daemon threads to finish before it exits. I suspect that the primordial
thread is closing stdout and stderr as it exits and therefore the exception
is never seen, but I don't know.
This change fixes the issue by ensuring that shutdown() is always called (in
a finally block) and that the main thread waits for the thread pool to
shutdown before it exits.
java/runtime/MercuryThreadPool.java:
runMain() will not exit until the worker threads have exited.
Create a new method waitForShutdown() that will wait for the thread pool
to shutdown.
Signal the main thread when a worker thread exits.
java/runtime/MercuryWorkerThread.java:
Worker threads now exit if their task raises an unhanded exception.
java/runtime/MercuryRuntime.java:
Allow standalone programs to have the same behavour as programs whose
entrypoint is written in Mercury.
The thread pool code used in the Java backend was tied the execution of
main/2. However if Mercury is used as a library the thread pool won't have
been started and threads created with thread.spawn would not be executed.
This patch makes it possible to start and stop the thread pool independently of
main/2 by calling startup() and shutdown(). These calls are called
implicitly by calling runMain(). The thread pool can also be started on
demand.
This patch also adds the MercuryRuntime class, which now contains methods
that may be called by users' Java code to interact with the Mercury runtime
system, including a new finalise() method.
java/runtime/MercuryThreadPool.java:
Add startup() method.
shutdown() method is now public and it's meaning has changed, it now
requests the shutdown rather than performing it.
Renamed some variables to make their meanings clearer.
java/runtime/JavaInternal.java:
Initialise the ThreadPool and MercuryOptions objects on demand.
Make all members of this class static to avoid confusion.
Add a private constructor.
java/runtime/MercuryRuntime.java:
Add methods that can be called by Mercury users to interact with the
runtime system. Including a convenient finalise() method that does all
the finalisation.
samples/java_interface/standalone_java/mercury_lib.m:
samples/java_interface/standalone_java/JavaMain.java:
Extend the standalone Java example so that it makes use of threads: Add
a fibs function in Mercury that uses concurrency and therefore starts
the thread pool; call it from the Java code.
Use the new finalise() method from the MercuryRuntime class inside of a
finally block.
samples/java_interface/standalone_java/Makefile:
Fix a minor error.
Fix a bug that made it possible that the tasks_lock could be locked but
never unlocked if an exception was thrown.
java/runtime/MercuryThreadPool.java:
As above.
If threads are blocked while there is work in the queue extra threads may be
spawned to keep the processors busy.
Beginning now, tasks created with thread.spawn are use the thread pool.
(thread.spawn_native does not use the thread pool.)
java/runtime/Semaphore.java:
Wrap Java's Semaphore class which call the current thread's blocked()
and running() methods when a thread blocks and then runs after being
blocked.
library/thread.semaphore.m:
Use our own Semaphore class.
java/runtime/MercuryThread.java:
java/runtime/MercuryWorkerThread.java:
Define blocked() and running() on our threads.
java/runtime/NativeThread.java:
This class is used by spawn_native/4 and is required to define blocked()
and running(), however it implements them as no-ops as it isn't included
in the thread pool.
java/runtime/ThreadStatus.java:
Define the BLOCKED status.
java/runtime/MercuryThreadPool.java:
Count blocked threads seperatly and allow the creation of new threads
when existing threads become blocked.
Add some tracing code to help debug the thread management code. This is
disabled by default.
library/thread.m:
Implement spawn for Java using the thread pool. This was not enabled
earlier because without using java/runtime/Semaphore.java it was
possible to deadlock the system.
java/runtime/Task.java:
Add some tracing code to debug thread state changes, this is disabled by
default.
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.
Thread pools are often used to reduce poor performance on embarrassingly
parallel work loads. This isn't immediately necessary on the Java backend
however I've implemented it because:
+ It will be required when we implement parallel conjunctions for the
Java backend.
+ I want to implement parallel profiling on the Java backend and don't
want to have to implement this once now, and then re-implement it after
introducing thread pools later.
We want the thread pool to generally restrict the number of threads that are
in use, this reduces overheads. However, when one or more tasks become
blocked then it can be desirable to create extra threads, this helps ensure
that all processors are kept busy and that thread pooling doesn't contribute
to any deadlocks itself. The implementation is a work in prograss and
currently does not implement this second feature.
Java's API provides several different thread pools, see
java.util.concurrent.Executors, none of which are suitable. Specifically
the fixed thread pool is unsuitable as we want to be able to temporarily
exceed the normal number of threads as explained above; and the cached
thread pools, which are also very similar to the ThreadPoolExecutor class,
do not implement the correct algorithm for determining when a new thread
should be created (they can still perform poorly for embarassingly parallel
workloads). Additionally we cannot instrument this code as easily for
parallel profiling.
These changes alter the behaviour of Mercury threads on the Java backend in
two ways, they now behave more correctly and more like threads on the C
backends.
+ If a thread throws an exception it is now reported and the program is
aborted. Previously it was ignored and let pass to the Java runtime
where I assume it was reported.
+ The program now exits only after all threads have exited.
The ThreadPool will automatically detect the number of threads to use, or if
the -P flag is given in the MERCURY_OPTIONS environment variable it will
honor that.
java/runtime/MercuryThread.java:
java/runtime/MercuryThreadPool.java:
java/runtime/MercuryWorkerThread.java:
java/runtime/Task.java:
java/runtime/ThreadStatus.java:
These new classes make up the thread pool. A MercuryThread is an
abstract class for Mercury threads, MercuryWorkerThread is a concrete
subclass of MercuryThread which includes the worker thread behaviour.
A Task is a computation/closure that has not yet been started, it
provides some methods not available in Java's generic Runnable and
Callable classes. The others should be self-explanatory and all files
contain documentation.
java/runtime/Getopt.java:
java/runtime/MercuryOptions.java:
Parse the MERCURY_OPTIONS environment variable for the -P flag.
java/runtime/JavaInternal.java:
Add support for handling Mercury exceptions, this is used in case a
worker thread's task (a Mercury thread) throws an exception.
compiler/mlds_to_java.m:
The main method of the main Java class of an application now starts and
uses the thread pool to execute main/2.
library/exception.m:
Export exception reporting code to the Java runtime system.
library/thread.m:
Use the thread pool for thread.spawn.
This change enables constant structure support for the Java backend for the
structures introduced by the polymorphism pass.
compiler/const_struct.m:
compiler/ml_unify_gen.m:
Enable constant structure support
java/runtime/TypeInfo_Struct.java:
Add a constructor to the TypeInfo structure for Java. This constructor
has the interface expected by the polymorphism code.
Never expect to be passed the arity to the varargs constructor.
compiler/polymorphism.m:
compiler/ml_unify_gen.m:
Change how we avoid creating TypeInfos with an explicit arity argument
for Java
We never specify the arity for a TypeInfo_Struct in a Java grade. There
are two reasons: this is a little difficult to handle due to overloading
rules and it is not necessary.
This is handled by removing these arguments in the MLDS backend.
However, the current solution does not work when we create TypeInfos as
constant structures. Therefore this change removes the special case
from the MLDS backend and instead never creates the arity arguments
during the polymorphism pass. rtti_to_mlds.m didn't need updating as it
already had the correct behaviour.
compiler/rtti_to_mlds.m:
Update a comment.
Delete the empty lazy_evaluation directory from extras.
*/.cvsignore:
Make this into .gitignore files.
(Update them where necessary.)
extra/lazy_evalution:
Delete this directory; its former contents were moved
elsewhere some time ago.
Branches: main, 11.07
Fix a problem that prevents Java 1.7 from compiling the Java code generated by
the Mercury compiler. Previously, the TypeInfo_Struct class in the Java
version of Mercury's runtime defined the following constructors:
public TypeInfo_Struct(TypeInfoStruct ti, int arity, Object... as)
public TypeInfo_Struct(TypeInfoStruct ti, Object... as)
Changes to the way most specific varargs method selection works in Java 1.7
means the above is now rejected by the Java compiler. (It should apparently
have never been allowed in the first place.)
The fix is to delete the first constructor above from the runtime and not
generate code that provides the arity. (The arity argument was only ever used
as a sanity check on the number of the following arguments.)
java/runtime/TypeInfo_Struct.java
Delete one of the ambiguous constructors from this class.
compiler/rtti_to_mlds.m:
Don't pass an arity argument to the constructor for TypeInfo_Struct
objects.
Branches: main
Pack consecutive enumeration arguments in discriminated union types into a
single word to reduce cell sizes. Argument packing is only enabled on C
back-ends with low-level data, and reordering arguments to improve
opportunities for packing is not yet attempted. The RTTI implementations for
other back-ends will need to be updated, but that is best left until after any
argument reordering change.
Modules which import abstract enumeration types are notified so by writing
declarations of the form:
:- type foo where type_is_abstract_enum(NumBits).
into the interface file for the module which defines the type.
compiler/prog_data.m:
Add an `arg_width' argument to constructor arguments.
Replace `is_solver_type' by `abstract_type_details', with an extra
option for abstract exported enumeration types.
compiler/handle_options.m:
compiler/options.m:
Add an internal option `--allow-argument-packing'.
compiler/make_hlds_passes.m:
Determine whether and how to pack enumeration arguments, updating the
`arg_width' fields of constructor arguments before constructors are
added to the HLDS.
compiler/mercury_to_mercury.m:
compiler/modules.m:
Write `where type_is_abstract_enum(NumBits)' to interface files
for abstract exported enumeration types.
compiler/prog_io_type_defn.m:
Parse `where type_is_abstract_enum(NumBits)' attributes on type
definitions.
compiler/arg_pack.m:
compiler/backend_libs.m:
Add a new module. This mainly contains a predicate which packs rvals
according to arg_widths, which is used by both LLDS and MLDS back-ends.
compiler/ml_unify_gen.m:
compiler/unify_gen.m:
Take argument packing into account when generating code for
constructions and deconstructions. Only a relatively small part of the
compiler actually needs to understand argument packing. The rest works
at the HLDS level with constructor arguments and variables, or at the
LLDS and MLDS levels with structure fields.
compiler/code_info.m:
compiler/var_locn.m:
Add assign_field_lval_expr_to_var and
var_locn_assign_field_lval_expr_to_var.
Allow more kinds of rvals in assign_cell_arg. I do not know why it was
previously restricted, except that the other kinds of rvals were not
encountered as cell arguments before.
compiler/mlds.m:
We can now rely on the compiler to pack arguments in the
mlds_decl_flags type instead of doing it manually. A slight downside
is that though the type is packed down to a single word cell, it will
still incur a memory allocation per cell. However, I did not notice
any difference in compiler speed.
compiler/rtti.m:
compiler/rtti_out.m:
Add and output a new field for MR_DuFunctorDesc instances, which, if
any arguments are packed, points to an array of MR_DuArgLocn. Each
array element describes the offset in the cell at which the argument's
value is held, and which bits of the word it occupies. In the more
common case where no arguments are packed, the new field is simply
null.
compiler/rtti_to_mlds.m:
Generate the new field to MR_DuFunctorDesc.
compiler/structure_reuse.direct.choose_reuse.m:
For now, prevent structure reuse reusing a dead cell which has a
different constructor to the new cell. The code to determine whether a
dead cell will hold the arguments of a new cell with a different
constructor will need to be updated to account for argument packing.
compiler/type_ctor_info.m:
Bump RTTI version number.
Conform to changes.
compiler/add_type.m:
compiler/check_typeclass.m:
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/erl_rtti.m:
compiler/hlds_data.m:
compiler/hlds_out_module.m:
compiler/intermod.m:
compiler/make_tags.m:
compiler/mlds_to_gcc.m:
compiler/opt_debug.m:
compiler/prog_type.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/special_pred.m:
compiler/type_constraints.m:
compiler/type_util.m:
compiler/unify_proc.m:
compiler/xml_documentation.m:
Conform to changes.
Reduce code duplication in classify_type_defn.
compiler/hlds_goal.m:
Clarify a comment.
library/construct.m:
Make `construct' pack arguments when necessary.
Remove an old RTTI version number check as recommended in
mercury_grade.h.
library/store.m:
Deal with packed arguments in this module.
runtime/mercury_grade.h:
Bump binary compatibility version number.
runtime/mercury_type_info.c:
runtime/mercury_type_info.h:
Bump RTTI version number.
Add MR_DuArgLocn structure definition.
Add a macro to unpack an argument as described by MR_DuArgLocn.
Add a function to determine a cell's size, since the number of
arguments is no longer correct.
runtime/mercury_deconstruct.c:
runtime/mercury_deconstruct.h:
runtime/mercury_deconstruct_macros.h:
runtime/mercury_ml_arg_body.h:
runtime/mercury_ml_expand_body.h:
Deal with packed arguments when deconstructing.
Remove an old RTTI version number check as recommended in
mercury_grade.h.
runtime/mercury_deep_copy_body.h:
Deal with packed arguments when copying.
runtime/mercury_table_type_body.h:
Deal with packed arguments in tabling.
runtime/mercury_dotnet.cs.in:
Add DuArgLocn field to DuFunctorDesc. Argument packing is not enabled
for the C# back-end yet so this is unused.
trace/mercury_trace_vars.c:
Deal with packed arguments in MR_select_specified_subterm,
use for the `hold' command.
java/runtime/DuArgLocn.java:
java/runtime/DuFunctorDesc.java:
Add DuArgLocn field to DuFunctorDesc. Argument packing is not enabled
for the Java back-end yet so this is unused.
extras/trailed_update/tr_store.m:
Deal with packed arguments in this module (untested).
extras/trailed_update/samples/interpreter.m:
extras/trailed_update/tr_array.m:
Conform to argument reordering in the array, map and other modules in
previous changes.
tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/lco_pack_args.exp:
tests/hard_coded/lco_pack_args.m:
tests/hard_coded/pack_args.exp:
tests/hard_coded/pack_args.m:
tests/hard_coded/pack_args_copy.exp:
tests/hard_coded/pack_args_copy.m:
tests/hard_coded/pack_args_intermod1.exp:
tests/hard_coded/pack_args_intermod1.m:
tests/hard_coded/pack_args_intermod2.m:
tests/hard_coded/pack_args_reuse.exp:
tests/hard_coded/pack_args_reuse.m:
tests/hard_coded/store_ref.exp:
tests/hard_coded/store_ref.m:
tests/invalid/Mmakefile:
tests/invalid/where_abstract_enum.err_exp:
tests/invalid/where_abstract_enum.m:
tests/tabling/Mmakefile:
tests/tabling/pack_args_memo.exp:
tests/tabling/pack_args_memo.m:
Add new test cases.
tests/hard_coded/deconstruct_arg.exp:
tests/hard_coded/deconstruct_arg.exp2:
tests/hard_coded/deconstruct_arg.m:
Add constructors with packed arguments to these cases.
tests/invalid/where_direct_arg.err_exp:
Update expected output.
Branches: main
The direct argument functor change added the constant MR_SECTAG_NONE_DIRECT_ARG
in some places but not others, breaking deconstruct on C# and Java back-ends.
compiler/mlds_to_gcc.m:
java/runtime/Sectag_Locn.java:
library/rtti_implementation.m:
runtime/mercury_dotnet.cs.in:
Add missing constants.
Branches: main
java/runtime/TypeInfo_Struct.java:
runtime/mercury_dotnet.cs.in:
Add overloads of `TypeInfo_Struct.maybe_new' so the C# and Java
compilers can pick the more appropriate version at compile time,
as they know the type of the argument.
Simplify the code.
Branches: main, 10.04
java/runtime/TypeInfo_Struct.java:
Collapse equivalences when comparing type_infos for equality.
java/runtime/TypeCtorRep.java:
Duplicate the required constants which otherwise are in
private_builtin.m. They should all be moved here but I don't want to
make that change on the 10.04 branch.
library/rtti_implementation.m:
Collapse equivalences in type_info_num_functors.
tests/hard_coded/construct_bug.m:
Use text streams in this test case, as the current hacky implementation
of `io.write_binary' doesn't work on the Java backend.
Branches: main
java/runtime/TypeInfo_Struct.java:
Make TypeInfo_Struct.unify() method compare correctly two type_infos
where one type_info has a null `args' field and another has a
zero-length `args' array.
Branches: main
Implement some RTTI procedures for Java:
get_functor_ordinal/2,
get_functor_lex/2,
type_ctor/2,
pseudo_type_ctor_and_args/3,
make_type/2
Make type_desc/type_ctor_desc/pseudo_type_desc into synonyms for type_info/etc.,
mainly to simplify the hand-written RTTI handling functions. Previously the
*_desc types were represented by *Desc wrapper classes.
compiler/mlds_to_java.m:
compiler/builtin_lib_types.m:
Map *_desc types to TypeInfo_Struct, TypeCtorInfo_Struct,
PseudoTypeInfo_Struct. We cannot simply use
`:- pragma foreign_type("Java", ...)' in the library as the compiler
will complain about missing type definitions for other language
backends.
library/construct.m:
Implement get_functor_ordinal, get_functor_lex for Java backend.
Conform to removal of *Desc classes.
library/rtti_implementation.m:
Implement get_functor_ordinal, get_functor_lex,
pseudo_type_ctor_and_args for Java backend.
Handle existentially quantified arguments in get_functor_du.
Make type_info/type_ctor_info comparison procedures compare module
names before constructor names, to match MR_compare_type_info,
MR_compare_type_ctor_info.
library/type_desc.m:
Implement type_ctor, pseudo_type_ctor_and_args, make_type on Java
backend.
Conform to removal of *Desc wrapper classes.
java/runtime/TypeCtorInfo_Struct.java:
Add constructor for variable arity type constructors.
java/runtime/TypeCtorRep.java:
Delete unused constants.
Branches: main
Add a new calling convention for Mercury procedures exported to Java with
`:- pragma foreign_export'. When the procedure has multiple output arguments,
require the caller to pass instances of a `Ref<T>' class which contain a field
to hold the output value. This is more verbose than returning an `Object[]'
array, and requires extra memory allocations, but is more type-safe. Another
advantage is that the Ref arguments will appear at the same positions as the
output arguments in the Mercury procedure.
The new convention must be enabled with `--java-export-ref-out'. The plan is
to enable it by default in the future.
compiler/options.m:
doc/reference_manual.texi:
Add the option.
compiler/ml_proc_gen.m:
When the option is set, disable `--det-copy-out' and generate the
function parameters assuming pass-by-reference for outputs.
Only use the new convention when necessary.
compiler/mlds_to_java.m:
Make the code to generate the exported forwarding methods account for
`mlds_ptr_type' parameters. These are converted to `Ref<T>' arguments.
java/runtime/Ref.java:
Add the reference class.
Estimated hours taken: 2
Branches: main
Override Object#equals for Mercury enumerations in the Java grades
and document that this should be used for equality testing in Java
code. The problem with using == is that instances might not have
the same addresses if they are serialized and then deserialized.
MercuryEnum is now a class and not an interface.
compiler/ml_type_gen.m:
Inherit the MercuryEnum class in Mercury enumerations
instead of implementing the MercuryEnum interface.
compiler/mlds_to_java.m:
Don't output the MR_value member in Java classes that correspond to
Mercury enumerations. This member is now inherited from MercuryEnum.
Don't mangle classes in the Mercury runtime.
doc/reference_manual.texi:
Document that the equals method should be used for exported
Mercury enumerations.
java/runtime/MercuryEnum.java:
Make MercuryEnum a class and implement the equals method.
Also implement the hashcode method.
Branches: main
Mark Java RTTI classes as implementing java.io.Serializable to
enable serialization of existentially typed values.
java/runtime/DuExistInfo.java:
java/runtime/DuExistLocn.java:
java/runtime/DuFunctorDesc.java:
java/runtime/DuPtagLayout.java:
java/runtime/EnumFunctorDesc.java:
java/runtime/ForeignEnumFunctorDesc.java:
java/runtime/MethodPtr.java:
java/runtime/NotagFunctorDesc.java:
java/runtime/PseudoTypeInfo.java:
java/runtime/ReservedAddrFunctorDesc.java:
java/runtime/Sectag_Locn.java:
java/runtime/TypeClassConstraint.java:
java/runtime/TypeClassDeclStruct.java:
java/runtime/TypeClassId.java:
java/runtime/TypeClassMethod.java:
java/runtime/TypeCtorInfo_Struct.java:
java/runtime/TypeCtorRep.java:
java/runtime/TypeFunctors.java:
java/runtime/TypeInfo_Struct.java:
java/runtime/TypeLayout.java:
As above.
TypeCtorInfo_Struct.unify() cannot rely on the uniqueness of
TypeCtorInfo_Struct instances, as deserialisation will create new
copies.
Branches: main
On the Java backend, use specialised MethodPtr interfaces so that when calling
a method pointer input arguments do not have to be passed via a temporary
array, for arities up to 15. For higher arities the temporary array is still
used.
java/runtime/MethodPtr.java:
java/runtime/MethodPtr1.java:
java/runtime/MethodPtr10.java:
java/runtime/MethodPtr11.java:
java/runtime/MethodPtr12.java:
java/runtime/MethodPtr13.java:
java/runtime/MethodPtr14.java:
java/runtime/MethodPtr15.java:
java/runtime/MethodPtr2.java:
java/runtime/MethodPtr3.java:
java/runtime/MethodPtr4.java:
java/runtime/MethodPtr5.java:
java/runtime/MethodPtr6.java:
java/runtime/MethodPtr7.java:
java/runtime/MethodPtr8.java:
java/runtime/MethodPtr9.java:
java/runtime/MethodPtrN.java:
Add specialised MethodPtr interfaces and MethodPtrN for any higher
arities.
compiler/mlds_to_java.m:
Make the code generator use the specialised MethodPtr interfaces.
library/Mmakefile:
Compile java/runtime/*.java files explicitly as some MethodPtr*.java
files won't be compiled implicitly when compiling the standard library.
library/exception.m:
java/runtime/Exception.java:
library/rtti_implementation.m:
Conform to changes.
Branches: main
compiler/make_hlds_passes.m:
Support `thread_local' mutables on Java backend.
Add some newlines in generated code for mutables.
compiler/prog_mutable.m:
Update documentation.
java/runtime/JavaInternal.java:
Avoid a warning.